blob: fbf37eb0b5a97c5201109d8bb99eaf4d148841f4 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/*
2 * Driver for HighSpeed USB Client Controller in MSM7K
3 *
4 * Copyright (C) 2008 Google, Inc.
Chiranjeevi Velempati2a9c1cb2012-12-21 18:26:23 +05305 * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07006 * Author: Mike Lockwood <lockwood@android.com>
7 * Brian Swetland <swetland@google.com>
8 *
9 * This software is licensed under the terms of the GNU General Public
10 * License version 2, as published by the Free Software Foundation, and
11 * may be copied, distributed, and modified under those terms.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/list.h>
24
25#include <linux/delay.h>
26#include <linux/timer.h>
27#include <linux/interrupt.h>
28#include <linux/dma-mapping.h>
29#include <linux/dmapool.h>
30#include <linux/platform_device.h>
31#include <linux/debugfs.h>
32#include <linux/workqueue.h>
33#include <linux/switch.h>
34#include <linux/pm_runtime.h>
35
36#include <mach/msm72k_otg.h>
37#include <linux/io.h>
38
39#include <asm/mach-types.h>
40
41#include <mach/board.h>
42#include <mach/msm_hsusb.h>
43#include <linux/device.h>
44#include <mach/msm_hsusb_hw.h>
45#include <mach/clk.h>
46#include <linux/uaccess.h>
47#include <linux/wakelock.h>
48
49static const char driver_name[] = "msm72k_udc";
50
51/* #define DEBUG */
52/* #define VERBOSE */
53
54#define MSM_USB_BASE ((unsigned) ui->addr)
55
56#define DRIVER_DESC "MSM 72K USB Peripheral Controller"
57#define DRIVER_NAME "MSM72K_UDC"
58
59#define EPT_FLAG_IN 0x0001
60
61#define SETUP_BUF_SIZE 8
62
63
64static const char *const ep_name[] = {
65 "ep0out", "ep1out", "ep2out", "ep3out",
66 "ep4out", "ep5out", "ep6out", "ep7out",
67 "ep8out", "ep9out", "ep10out", "ep11out",
68 "ep12out", "ep13out", "ep14out", "ep15out",
69 "ep0in", "ep1in", "ep2in", "ep3in",
70 "ep4in", "ep5in", "ep6in", "ep7in",
71 "ep8in", "ep9in", "ep10in", "ep11in",
72 "ep12in", "ep13in", "ep14in", "ep15in"
73};
74
75/*To release the wakelock from debugfs*/
76static int release_wlocks;
77
78struct msm_request {
79 struct usb_request req;
80
81 /* saved copy of req.complete */
82 void (*gadget_complete)(struct usb_ep *ep,
83 struct usb_request *req);
84
85
86 struct usb_info *ui;
87 struct msm_request *next;
88 struct msm_request *prev;
89
90 unsigned busy:1;
91 unsigned live:1;
92 unsigned alloced:1;
93
94 dma_addr_t dma;
95 dma_addr_t item_dma;
96
97 struct ept_queue_item *item;
98};
99
100#define to_msm_request(r) container_of(r, struct msm_request, req)
101#define to_msm_endpoint(r) container_of(r, struct msm_endpoint, ep)
Steve Mucklef132c6c2012-06-06 18:30:57 -0700102#define to_msm_otg(xceiv) container_of(xceiv, struct msm_otg, phy)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700103#define is_b_sess_vld() ((OTGSC_BSV & readl(USB_OTGSC)) ? 1 : 0)
104#define is_usb_online(ui) (ui->usb_state != USB_STATE_NOTATTACHED)
105
106struct msm_endpoint {
107 struct usb_ep ep;
108 struct usb_info *ui;
109 struct msm_request *req; /* head of pending requests */
110 struct msm_request *last;
111 unsigned flags;
112
113 /* bit number (0-31) in various status registers
114 ** as well as the index into the usb_info's array
115 ** of all endpoints
116 */
117 unsigned char bit;
118 unsigned char num;
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +0530119 unsigned long dTD_update_fail_count;
120 unsigned long false_prime_fail_count;
121 unsigned actual_prime_fail_count;
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +0530122 unsigned long dTD_workaround_fail_count;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700123
124 unsigned wedged:1;
125 /* pointers to DMA transfer list area */
126 /* these are allocated from the usb_info dma space */
127 struct ept_queue_head *head;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530128 struct timer_list prime_timer;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129};
130
131/* PHY status check timer to monitor phy stuck up on reset */
132static struct timer_list phy_status_timer;
133
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530134static void ept_prime_timer_func(unsigned long data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700135static void usb_do_work(struct work_struct *w);
136static void usb_do_remote_wakeup(struct work_struct *w);
137
138
139#define USB_STATE_IDLE 0
140#define USB_STATE_ONLINE 1
141#define USB_STATE_OFFLINE 2
142
143#define USB_FLAG_START 0x0001
144#define USB_FLAG_VBUS_ONLINE 0x0002
145#define USB_FLAG_VBUS_OFFLINE 0x0004
146#define USB_FLAG_RESET 0x0008
147#define USB_FLAG_SUSPEND 0x0010
148#define USB_FLAG_CONFIGURED 0x0020
149
150#define USB_CHG_DET_DELAY msecs_to_jiffies(1000)
151#define REMOTE_WAKEUP_DELAY msecs_to_jiffies(1000)
152#define PHY_STATUS_CHECK_DELAY (jiffies + msecs_to_jiffies(1000))
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530153#define EPT_PRIME_CHECK_DELAY (jiffies + msecs_to_jiffies(1000))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154
155struct usb_info {
156 /* lock for register/queue/device state changes */
157 spinlock_t lock;
158
159 /* single request used for handling setup transactions */
160 struct usb_request *setup_req;
161
162 struct platform_device *pdev;
163 int irq;
164 void *addr;
165
166 unsigned state;
167 unsigned flags;
168
169 atomic_t configured;
170 atomic_t running;
171
172 struct dma_pool *pool;
173
174 /* dma page to back the queue heads and items */
175 unsigned char *buf;
176 dma_addr_t dma;
177
178 struct ept_queue_head *head;
179
180 /* used for allocation */
181 unsigned next_item;
182 unsigned next_ifc_num;
183
184 /* endpoints are ordered based on their status bits,
185 ** so they are OUT0, OUT1, ... OUT15, IN0, IN1, ... IN15
186 */
187 struct msm_endpoint ept[32];
188
189
190 /* max power requested by selected configuration */
191 unsigned b_max_pow;
192 unsigned chg_current;
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530193 unsigned chg_type_retry_cnt;
194 bool proprietary_chg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700195 struct delayed_work chg_det;
196 struct delayed_work chg_stop;
197 struct msm_hsusb_gadget_platform_data *pdata;
198 struct work_struct phy_status_check;
199
200 struct work_struct work;
201 unsigned phy_status;
202 unsigned phy_fail_count;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530203 unsigned prime_fail_count;
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +0530204 unsigned long dTD_update_fail_count;
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +0530205 unsigned long dTD_workaround_fail_count;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206
207 struct usb_gadget gadget;
208 struct usb_gadget_driver *driver;
209 struct switch_dev sdev;
210
211#define ep0out ept[0]
212#define ep0in ept[16]
213
214 atomic_t ep0_dir;
215 atomic_t test_mode;
216 atomic_t offline_pending;
217 atomic_t softconnect;
218#ifdef CONFIG_USB_OTG
219 u8 hnp_avail;
220#endif
221
222 atomic_t remote_wakeup;
223 atomic_t self_powered;
224 struct delayed_work rw_work;
225
Steve Mucklef132c6c2012-06-06 18:30:57 -0700226 struct usb_phy *xceiv;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 enum usb_device_state usb_state;
228 struct wake_lock wlock;
229};
230
231static const struct usb_ep_ops msm72k_ep_ops;
232static struct usb_info *the_usb_info;
233
234static int msm72k_wakeup(struct usb_gadget *_gadget);
235static int msm72k_pullup_internal(struct usb_gadget *_gadget, int is_active);
236static int msm72k_set_halt(struct usb_ep *_ep, int value);
237static void flush_endpoint(struct msm_endpoint *ept);
238static void usb_reset(struct usb_info *ui);
239static int usb_ept_set_halt(struct usb_ep *_ep, int value);
240
241static void msm_hsusb_set_speed(struct usb_info *ui)
242{
243 unsigned long flags;
244
245 spin_lock_irqsave(&ui->lock, flags);
246 switch (readl(USB_PORTSC) & PORTSC_PSPD_MASK) {
247 case PORTSC_PSPD_FS:
248 dev_dbg(&ui->pdev->dev, "portchange USB_SPEED_FULL\n");
249 ui->gadget.speed = USB_SPEED_FULL;
250 break;
251 case PORTSC_PSPD_LS:
252 dev_dbg(&ui->pdev->dev, "portchange USB_SPEED_LOW\n");
253 ui->gadget.speed = USB_SPEED_LOW;
254 break;
255 case PORTSC_PSPD_HS:
256 dev_dbg(&ui->pdev->dev, "portchange USB_SPEED_HIGH\n");
257 ui->gadget.speed = USB_SPEED_HIGH;
258 break;
259 }
260 spin_unlock_irqrestore(&ui->lock, flags);
261}
262
263static void msm_hsusb_set_state(enum usb_device_state state)
264{
265 unsigned long flags;
266
267 spin_lock_irqsave(&the_usb_info->lock, flags);
268 the_usb_info->usb_state = state;
269 spin_unlock_irqrestore(&the_usb_info->lock, flags);
270}
271
272static enum usb_device_state msm_hsusb_get_state(void)
273{
274 unsigned long flags;
275 enum usb_device_state state;
276
277 spin_lock_irqsave(&the_usb_info->lock, flags);
278 state = the_usb_info->usb_state;
279 spin_unlock_irqrestore(&the_usb_info->lock, flags);
280
281 return state;
282}
283
284static ssize_t print_switch_name(struct switch_dev *sdev, char *buf)
285{
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +0530286 return snprintf(buf, PAGE_SIZE, "%s\n", DRIVER_NAME);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700287}
288
289static ssize_t print_switch_state(struct switch_dev *sdev, char *buf)
290{
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +0530291 return snprintf(buf, PAGE_SIZE, "%s\n",
292 sdev->state ? "online" : "offline");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293}
294
295static inline enum chg_type usb_get_chg_type(struct usb_info *ui)
296{
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +0530297 if ((readl_relaxed(USB_PORTSC) & PORTSC_LS) == PORTSC_LS) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 return USB_CHG_TYPE__WALLCHARGER;
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +0530299 } else if (ui->pdata->prop_chg) {
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530300 if (ui->gadget.speed == USB_SPEED_LOW ||
301 ui->gadget.speed == USB_SPEED_FULL ||
302 ui->gadget.speed == USB_SPEED_HIGH)
303 return USB_CHG_TYPE__SDP;
304 else
305 return USB_CHG_TYPE__INVALID;
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +0530306 } else {
307 return USB_CHG_TYPE__SDP;
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530308 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309}
310
311#define USB_WALLCHARGER_CHG_CURRENT 1800
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530312#define USB_PROPRIETARY_CHG_CURRENT 500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700313static int usb_get_max_power(struct usb_info *ui)
314{
315 struct msm_otg *otg = to_msm_otg(ui->xceiv);
316 unsigned long flags;
317 enum chg_type temp;
318 int suspended;
319 int configured;
320 unsigned bmaxpow;
321
322 if (ui->gadget.is_a_peripheral)
323 return -EINVAL;
324
325 temp = atomic_read(&otg->chg_type);
326 spin_lock_irqsave(&ui->lock, flags);
327 suspended = ui->usb_state == USB_STATE_SUSPENDED ? 1 : 0;
328 configured = atomic_read(&ui->configured);
329 bmaxpow = ui->b_max_pow;
330 spin_unlock_irqrestore(&ui->lock, flags);
331
332 if (temp == USB_CHG_TYPE__INVALID)
333 return -ENODEV;
334
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530335 if (temp == USB_CHG_TYPE__WALLCHARGER && !ui->proprietary_chg)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336 return USB_WALLCHARGER_CHG_CURRENT;
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +0530337 else if (ui->pdata->prop_chg)
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530338 return USB_PROPRIETARY_CHG_CURRENT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700339
340 if (suspended || !configured)
341 return 0;
342
343 return bmaxpow;
344}
345
346static int usb_phy_stuck_check(struct usb_info *ui)
347{
348 /*
349 * write some value (0xAA) into scratch reg (0x16) and read it back,
350 * If the read value is same as written value, means PHY is normal
351 * otherwise, PHY seems to have stuck.
352 */
353
Steve Mucklef132c6c2012-06-06 18:30:57 -0700354 if (usb_phy_io_write(ui->xceiv, 0xAA, 0x16) == -1) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700355 dev_dbg(&ui->pdev->dev,
356 "%s(): ulpi write timeout\n", __func__);
357 return -EIO;
358 }
359
Steve Mucklef132c6c2012-06-06 18:30:57 -0700360 if (usb_phy_io_read(ui->xceiv, 0x16) != 0xAA) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700361 dev_dbg(&ui->pdev->dev,
362 "%s(): read value is incorrect\n", __func__);
363 return -EIO;
364 }
365
366 return 0;
367}
368
369/*
370 * This function checks the phy status by reading/writing to the
371 * phy scratch register. If the phy is stuck resets the HW
372 * */
373static void usb_phy_stuck_recover(struct work_struct *w)
374{
375 struct usb_info *ui = the_usb_info;
376 struct msm_otg *otg = to_msm_otg(ui->xceiv);
377 unsigned long flags;
378
379 spin_lock_irqsave(&ui->lock, flags);
380 if (ui->gadget.speed != USB_SPEED_UNKNOWN ||
381 ui->usb_state == USB_STATE_NOTATTACHED ||
382 ui->driver == NULL) {
383 spin_unlock_irqrestore(&ui->lock, flags);
384 return;
385 }
386 spin_unlock_irqrestore(&ui->lock, flags);
387
388 disable_irq(otg->irq);
389 if (usb_phy_stuck_check(ui)) {
390#ifdef CONFIG_USB_MSM_ACA
391 del_timer_sync(&otg->id_timer);
392#endif
393 ui->phy_fail_count++;
394 dev_err(&ui->pdev->dev,
395 "%s():PHY stuck, resetting HW\n", __func__);
396 /*
397 * PHY seems to have stuck,
398 * reset the PHY and HW link to recover the PHY
399 */
400 usb_reset(ui);
401#ifdef CONFIG_USB_MSM_ACA
402 mod_timer(&otg->id_timer, jiffies +
403 msecs_to_jiffies(OTG_ID_POLL_MS));
404#endif
405 msm72k_pullup_internal(&ui->gadget, 1);
406 }
407 enable_irq(otg->irq);
408}
409
410static void usb_phy_status_check_timer(unsigned long data)
411{
412 struct usb_info *ui = the_usb_info;
413
414 schedule_work(&ui->phy_status_check);
415}
416
417static void usb_chg_stop(struct work_struct *w)
418{
419 struct usb_info *ui = container_of(w, struct usb_info, chg_stop.work);
420 struct msm_otg *otg = to_msm_otg(ui->xceiv);
421 enum chg_type temp;
422
423 temp = atomic_read(&otg->chg_type);
424
425 if (temp == USB_CHG_TYPE__SDP)
Steve Mucklef132c6c2012-06-06 18:30:57 -0700426 usb_phy_set_power(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700427}
428
429static void usb_chg_detect(struct work_struct *w)
430{
431 struct usb_info *ui = container_of(w, struct usb_info, chg_det.work);
432 struct msm_otg *otg = to_msm_otg(ui->xceiv);
433 enum chg_type temp = USB_CHG_TYPE__INVALID;
434 unsigned long flags;
435 int maxpower;
436
437 spin_lock_irqsave(&ui->lock, flags);
438 if (ui->usb_state == USB_STATE_NOTATTACHED) {
439 spin_unlock_irqrestore(&ui->lock, flags);
440 return;
441 }
442
443 temp = usb_get_chg_type(ui);
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +0530444 if (temp != USB_CHG_TYPE__WALLCHARGER && temp != USB_CHG_TYPE__SDP
445 && !ui->chg_type_retry_cnt) {
446 schedule_delayed_work(&ui->chg_det, USB_CHG_DET_DELAY);
447 ui->chg_type_retry_cnt++;
448 spin_unlock_irqrestore(&ui->lock, flags);
449 return;
450 }
451 if (temp == USB_CHG_TYPE__INVALID) {
452 temp = USB_CHG_TYPE__WALLCHARGER;
453 ui->proprietary_chg = true;
454 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700455 spin_unlock_irqrestore(&ui->lock, flags);
456
457 atomic_set(&otg->chg_type, temp);
458 maxpower = usb_get_max_power(ui);
459 if (maxpower > 0)
Steve Mucklef132c6c2012-06-06 18:30:57 -0700460 usb_phy_set_power(ui->xceiv, maxpower);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700461
462 /* USB driver prevents idle and suspend power collapse(pc)
463 * while USB cable is connected. But when dedicated charger is
464 * connected, driver can vote for idle and suspend pc.
Steve Mucklef132c6c2012-06-06 18:30:57 -0700465 * OTG driver handles idle pc as part of above usb_phy_set_power call
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700466 * when wallcharger is attached. To allow suspend pc, release the
467 * wakelock which will be re-acquired for any sub-sequent usb interrupts
468 * */
469 if (temp == USB_CHG_TYPE__WALLCHARGER) {
470 pm_runtime_put_sync(&ui->pdev->dev);
471 wake_unlock(&ui->wlock);
472 }
473}
474
475static int usb_ep_get_stall(struct msm_endpoint *ept)
476{
477 unsigned int n;
478 struct usb_info *ui = ept->ui;
479
480 n = readl(USB_ENDPTCTRL(ept->num));
481 if (ept->flags & EPT_FLAG_IN)
482 return (CTRL_TXS & n) ? 1 : 0;
483 else
484 return (CTRL_RXS & n) ? 1 : 0;
485}
486
487static void init_endpoints(struct usb_info *ui)
488{
489 unsigned n;
490
491 for (n = 0; n < 32; n++) {
492 struct msm_endpoint *ept = ui->ept + n;
493
494 ept->ui = ui;
495 ept->bit = n;
496 ept->num = n & 15;
497 ept->ep.name = ep_name[n];
498 ept->ep.ops = &msm72k_ep_ops;
499
500 if (ept->bit > 15) {
501 /* IN endpoint */
502 ept->head = ui->head + (ept->num << 1) + 1;
503 ept->flags = EPT_FLAG_IN;
504 } else {
505 /* OUT endpoint */
506 ept->head = ui->head + (ept->num << 1);
507 ept->flags = 0;
508 }
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530509 setup_timer(&ept->prime_timer, ept_prime_timer_func,
510 (unsigned long) ept);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700511
512 }
513}
514
515static void config_ept(struct msm_endpoint *ept)
516{
517 struct usb_info *ui = ept->ui;
518 unsigned cfg = CONFIG_MAX_PKT(ept->ep.maxpacket) | CONFIG_ZLT;
Vijayavardhan Vennapusa48986d12012-09-12 11:51:27 +0530519 const struct usb_endpoint_descriptor *desc = ept->ep.desc;
520 unsigned mult = 0;
521
522 if (desc && ((desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
523 == USB_ENDPOINT_XFER_ISOC)) {
524 cfg &= ~(CONFIG_MULT);
525 mult = ((ept->ep.maxpacket >> CONFIG_MULT_SHIFT) + 1) & 0x03;
526 cfg |= (mult << (ffs(CONFIG_MULT) - 1));
527 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700528
529 /* ep0 out needs interrupt-on-setup */
530 if (ept->bit == 0)
531 cfg |= CONFIG_IOS;
532
533 ept->head->config = cfg;
534 ept->head->next = TERMINATE;
535
536 if (ept->ep.maxpacket)
537 dev_dbg(&ui->pdev->dev,
538 "ept #%d %s max:%d head:%p bit:%d\n",
539 ept->num,
540 (ept->flags & EPT_FLAG_IN) ? "in" : "out",
541 ept->ep.maxpacket, ept->head, ept->bit);
542}
543
544static void configure_endpoints(struct usb_info *ui)
545{
546 unsigned n;
547
548 for (n = 0; n < 32; n++)
549 config_ept(ui->ept + n);
550}
551
552struct usb_request *usb_ept_alloc_req(struct msm_endpoint *ept,
553 unsigned bufsize, gfp_t gfp_flags)
554{
555 struct usb_info *ui = ept->ui;
556 struct msm_request *req;
557
558 req = kzalloc(sizeof(*req), gfp_flags);
559 if (!req)
560 goto fail1;
561
562 req->item = dma_pool_alloc(ui->pool, gfp_flags, &req->item_dma);
563 if (!req->item)
564 goto fail2;
565
566 if (bufsize) {
567 req->req.buf = kmalloc(bufsize, gfp_flags);
568 if (!req->req.buf)
569 goto fail3;
570 req->alloced = 1;
571 }
572
573 return &req->req;
574
575fail3:
576 dma_pool_free(ui->pool, req->item, req->item_dma);
577fail2:
578 kfree(req);
579fail1:
580 return 0;
581}
582
583static void usb_ept_enable(struct msm_endpoint *ept, int yes,
584 unsigned char ep_type)
585{
586 struct usb_info *ui = ept->ui;
587 int in = ept->flags & EPT_FLAG_IN;
588 unsigned n;
589
590 n = readl(USB_ENDPTCTRL(ept->num));
591
592 if (in) {
593 if (yes) {
594 n = (n & (~CTRL_TXT_MASK)) |
595 (ep_type << CTRL_TXT_EP_TYPE_SHIFT);
596 n |= CTRL_TXE | CTRL_TXR;
597 } else
598 n &= (~CTRL_TXE);
599 } else {
600 if (yes) {
601 n = (n & (~CTRL_RXT_MASK)) |
602 (ep_type << CTRL_RXT_EP_TYPE_SHIFT);
603 n |= CTRL_RXE | CTRL_RXR;
604 } else
605 n &= ~(CTRL_RXE);
606 }
607 /* complete all the updates to ept->head before enabling endpoint*/
608 mb();
609 writel(n, USB_ENDPTCTRL(ept->num));
610
611 /* Ensure endpoint is enabled before returning */
612 mb();
613
614 dev_dbg(&ui->pdev->dev, "ept %d %s %s\n",
615 ept->num, in ? "in" : "out", yes ? "enabled" : "disabled");
616}
617
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530618static void ept_prime_timer_func(unsigned long data)
619{
620 struct msm_endpoint *ept = (struct msm_endpoint *)data;
621 struct usb_info *ui = ept->ui;
622 unsigned n = 1 << ept->bit;
623 unsigned long flags;
624
625 spin_lock_irqsave(&ui->lock, flags);
626
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +0530627 ept->false_prime_fail_count++;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530628 if ((readl_relaxed(USB_ENDPTPRIME) & n)) {
629 /*
630 * ---- UNLIKELY ---
631 * May be hardware is taking long time to process the
632 * prime request. Or could be intermittent priming and
633 * previous dTD is not fired yet.
634 */
635 mod_timer(&ept->prime_timer, EPT_PRIME_CHECK_DELAY);
636 goto out;
637 }
638 if (readl_relaxed(USB_ENDPTSTAT) & n)
639 goto out;
640
641 /* clear speculative loads on item->info */
642 rmb();
643 if (ept->req && (ept->req->item->info & INFO_ACTIVE)) {
644 ui->prime_fail_count++;
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +0530645 ept->actual_prime_fail_count++;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530646 pr_err("%s(): ept%d%s prime failed. ept: config: %x"
647 "active: %x next: %x info: %x\n",
648 __func__, ept->num,
649 ept->flags & EPT_FLAG_IN ? "in" : "out",
650 ept->head->config, ept->head->active,
651 ept->head->next, ept->head->info);
652 writel_relaxed(n, USB_ENDPTPRIME);
653 mod_timer(&ept->prime_timer, EPT_PRIME_CHECK_DELAY);
654 }
655out:
656 spin_unlock_irqrestore(&ui->lock, flags);
657}
658
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700659static void usb_ept_start(struct msm_endpoint *ept)
660{
661 struct usb_info *ui = ept->ui;
662 struct msm_request *req = ept->req;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700663 unsigned n = 1 << ept->bit;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700664
665 BUG_ON(req->live);
666
667 while (req) {
668 req->live = 1;
669 /* prepare the transaction descriptor item for the hardware */
670 req->item->info =
671 INFO_BYTES(req->req.length) | INFO_IOC | INFO_ACTIVE;
672 req->item->page0 = req->dma;
673 req->item->page1 = (req->dma + 0x1000) & 0xfffff000;
674 req->item->page2 = (req->dma + 0x2000) & 0xfffff000;
675 req->item->page3 = (req->dma + 0x3000) & 0xfffff000;
676
677 if (req->next == NULL) {
678 req->item->next = TERMINATE;
679 break;
680 }
681 req->item->next = req->next->item_dma;
682 req = req->next;
683 }
684
685 rmb();
686 /* link the hw queue head to the request's transaction item */
687 ept->head->next = ept->req->item_dma;
688 ept->head->info = 0;
689
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700690 /* flush buffers before priming ept */
691 mb();
692 /* during high throughput testing it is observed that
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530693 * ept stat bit is not set even though all the data
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700694 * structures are updated properly and ept prime bit
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530695 * is set. To workaround the issue, kick a timer and
696 * make decision on re-prime. We can do a busy loop here
697 * but it leads to high cpu usage.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 */
699 writel_relaxed(n, USB_ENDPTPRIME);
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +0530700 mod_timer(&ept->prime_timer, EPT_PRIME_CHECK_DELAY);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700701}
702
703int usb_ept_queue_xfer(struct msm_endpoint *ept, struct usb_request *_req)
704{
705 unsigned long flags;
706 struct msm_request *req = to_msm_request(_req);
707 struct msm_request *last;
708 struct usb_info *ui = ept->ui;
709 unsigned length = req->req.length;
710
711 if (length > 0x4000)
712 return -EMSGSIZE;
713
714 spin_lock_irqsave(&ui->lock, flags);
715
Rajkumar Raghupathy7c3c45b2012-07-24 16:13:36 +0530716 if (ept->num != 0 && ept->ep.desc == NULL) {
717 req->req.status = -EINVAL;
718 spin_unlock_irqrestore(&ui->lock, flags);
719 dev_err(&ui->pdev->dev,
720 "%s: called for disabled endpoint\n", __func__);
721 return -EINVAL;
722 }
723
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700724 if (req->busy) {
725 req->req.status = -EBUSY;
726 spin_unlock_irqrestore(&ui->lock, flags);
727 dev_err(&ui->pdev->dev,
728 "usb_ept_queue_xfer() tried to queue busy request\n");
729 return -EBUSY;
730 }
731
732 if (!atomic_read(&ui->configured) && (ept->num != 0)) {
733 req->req.status = -ESHUTDOWN;
734 spin_unlock_irqrestore(&ui->lock, flags);
735 if (printk_ratelimit())
736 dev_err(&ui->pdev->dev,
737 "%s: called while offline\n", __func__);
738 return -ESHUTDOWN;
739 }
740
741 if (ui->usb_state == USB_STATE_SUSPENDED) {
742 if (!atomic_read(&ui->remote_wakeup)) {
743 req->req.status = -EAGAIN;
744 spin_unlock_irqrestore(&ui->lock, flags);
745 if (printk_ratelimit())
746 dev_err(&ui->pdev->dev,
747 "%s: cannot queue as bus is suspended "
748 "ept #%d %s max:%d head:%p bit:%d\n",
749 __func__, ept->num,
750 (ept->flags & EPT_FLAG_IN) ? "in" : "out",
751 ept->ep.maxpacket, ept->head, ept->bit);
752
753 return -EAGAIN;
754 }
755
756 wake_lock(&ui->wlock);
Steve Mucklef132c6c2012-06-06 18:30:57 -0700757 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700758 schedule_delayed_work(&ui->rw_work, REMOTE_WAKEUP_DELAY);
759 }
760
761 req->busy = 1;
762 req->live = 0;
763 req->next = 0;
764 req->req.status = -EBUSY;
765
766 req->dma = dma_map_single(NULL, req->req.buf, length,
767 (ept->flags & EPT_FLAG_IN) ?
768 DMA_TO_DEVICE : DMA_FROM_DEVICE);
769
770
771 /* Add the new request to the end of the queue */
772 last = ept->last;
773 if (last) {
774 /* Already requests in the queue. add us to the
775 * end, but let the completion interrupt actually
776 * start things going, to avoid hw issues
777 */
778 last->next = req;
779 req->prev = last;
780
781 } else {
782 /* queue was empty -- kick the hardware */
783 ept->req = req;
784 req->prev = NULL;
785 usb_ept_start(ept);
786 }
787 ept->last = req;
788
789 spin_unlock_irqrestore(&ui->lock, flags);
790 return 0;
791}
792
793/* --- endpoint 0 handling --- */
794
795static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
796{
797 struct msm_request *r = to_msm_request(req);
798 struct msm_endpoint *ept = to_msm_endpoint(ep);
799 struct usb_info *ui = ept->ui;
800
801 req->complete = r->gadget_complete;
802 r->gadget_complete = 0;
803 if (req->complete)
804 req->complete(&ui->ep0in.ep, req);
805}
806
807static void ep0_status_complete(struct usb_ep *ep, struct usb_request *_req)
808{
809 struct usb_request *req = _req->context;
810 struct msm_request *r;
811 struct msm_endpoint *ept;
812 struct usb_info *ui;
813
814 pr_debug("%s:\n", __func__);
815 if (!req)
816 return;
817
818 r = to_msm_request(req);
819 ept = to_msm_endpoint(ep);
820 ui = ept->ui;
821 _req->context = 0;
822
823 req->complete = r->gadget_complete;
824 req->zero = 0;
825 r->gadget_complete = 0;
826 if (req->complete)
827 req->complete(&ui->ep0in.ep, req);
828
829}
830
831static void ep0_status_phase(struct usb_ep *ep, struct usb_request *req)
832{
833 struct msm_endpoint *ept = to_msm_endpoint(ep);
834 struct usb_info *ui = ept->ui;
835
836 pr_debug("%s:\n", __func__);
837
838 req->length = 0;
839 req->complete = ep0_status_complete;
840
841 /* status phase */
842 if (atomic_read(&ui->ep0_dir) == USB_DIR_IN)
843 usb_ept_queue_xfer(&ui->ep0out, req);
844 else
845 usb_ept_queue_xfer(&ui->ep0in, req);
846}
847
848static void ep0in_send_zero_leng_pkt(struct msm_endpoint *ept)
849{
850 struct usb_info *ui = ept->ui;
851 struct usb_request *req = ui->setup_req;
852
853 pr_debug("%s:\n", __func__);
854
855 req->length = 0;
856 req->complete = ep0_status_phase;
857 usb_ept_queue_xfer(&ui->ep0in, req);
858}
859
860static void ep0_queue_ack_complete(struct usb_ep *ep,
861 struct usb_request *_req)
862{
863 struct msm_endpoint *ept = to_msm_endpoint(ep);
864 struct usb_info *ui = ept->ui;
865 struct usb_request *req = ui->setup_req;
866
867 pr_debug("%s: _req:%p actual:%d length:%d zero:%d\n",
868 __func__, _req, _req->actual,
869 _req->length, _req->zero);
870
871 /* queue up the receive of the ACK response from the host */
872 if (_req->status == 0 && _req->actual == _req->length) {
873 req->context = _req;
874 if (atomic_read(&ui->ep0_dir) == USB_DIR_IN) {
875 if (_req->zero && _req->length &&
876 !(_req->length % ep->maxpacket)) {
877 ep0in_send_zero_leng_pkt(&ui->ep0in);
878 return;
879 }
880 }
881 ep0_status_phase(ep, req);
882 } else
883 ep0_complete(ep, _req);
884}
885
886static void ep0_setup_ack_complete(struct usb_ep *ep, struct usb_request *req)
887{
888 struct msm_endpoint *ept = to_msm_endpoint(ep);
889 struct usb_info *ui = ept->ui;
890 unsigned int temp;
891 int test_mode = atomic_read(&ui->test_mode);
892
893 if (!test_mode)
894 return;
895
896 switch (test_mode) {
897 case J_TEST:
898 dev_info(&ui->pdev->dev, "usb electrical test mode: (J)\n");
899 temp = readl(USB_PORTSC) & (~PORTSC_PTC);
900 writel(temp | PORTSC_PTC_J_STATE, USB_PORTSC);
901 break;
902
903 case K_TEST:
904 dev_info(&ui->pdev->dev, "usb electrical test mode: (K)\n");
905 temp = readl(USB_PORTSC) & (~PORTSC_PTC);
906 writel(temp | PORTSC_PTC_K_STATE, USB_PORTSC);
907 break;
908
909 case SE0_NAK_TEST:
910 dev_info(&ui->pdev->dev,
911 "usb electrical test mode: (SE0-NAK)\n");
912 temp = readl(USB_PORTSC) & (~PORTSC_PTC);
913 writel(temp | PORTSC_PTC_SE0_NAK, USB_PORTSC);
914 break;
915
916 case TST_PKT_TEST:
917 dev_info(&ui->pdev->dev,
918 "usb electrical test mode: (TEST_PKT)\n");
919 temp = readl(USB_PORTSC) & (~PORTSC_PTC);
920 writel(temp | PORTSC_PTC_TST_PKT, USB_PORTSC);
921 break;
922 }
923}
924
925static void ep0_setup_ack(struct usb_info *ui)
926{
927 struct usb_request *req = ui->setup_req;
928 req->length = 0;
929 req->complete = ep0_setup_ack_complete;
930 usb_ept_queue_xfer(&ui->ep0in, req);
931}
932
933static void ep0_setup_stall(struct usb_info *ui)
934{
935 writel((1<<16) | (1<<0), USB_ENDPTCTRL(0));
936}
937
938static void ep0_setup_send(struct usb_info *ui, unsigned length)
939{
940 struct usb_request *req = ui->setup_req;
941 struct msm_request *r = to_msm_request(req);
942 struct msm_endpoint *ept = &ui->ep0in;
943
944 req->length = length;
945 req->complete = ep0_queue_ack_complete;
946 r->gadget_complete = 0;
947 usb_ept_queue_xfer(ept, req);
948}
949
950static void handle_setup(struct usb_info *ui)
951{
952 struct usb_ctrlrequest ctl;
953 struct usb_request *req = ui->setup_req;
954 int ret;
955#ifdef CONFIG_USB_OTG
956 u8 hnp;
957 unsigned long flags;
958#endif
Vijayavardhan Vennapusa09bbcb32011-08-30 02:13:26 +0530959 /* USB hardware sometimes generate interrupt before
960 * 8 bytes of SETUP packet are written to system memory.
961 * This results in fetching wrong setup_data sometimes.
962 * TODO: Remove below workaround of adding 1us delay once
963 * it gets fixed in hardware.
964 */
965 udelay(10);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700966
967 memcpy(&ctl, ui->ep0out.head->setup_data, sizeof(ctl));
968 /* Ensure buffer is read before acknowledging to h/w */
969 mb();
970
971 writel(EPT_RX(0), USB_ENDPTSETUPSTAT);
972
973 if (ctl.bRequestType & USB_DIR_IN)
974 atomic_set(&ui->ep0_dir, USB_DIR_IN);
975 else
976 atomic_set(&ui->ep0_dir, USB_DIR_OUT);
977
978 /* any pending ep0 transactions must be canceled */
979 flush_endpoint(&ui->ep0out);
980 flush_endpoint(&ui->ep0in);
981
982 dev_dbg(&ui->pdev->dev,
983 "setup: type=%02x req=%02x val=%04x idx=%04x len=%04x\n",
984 ctl.bRequestType, ctl.bRequest, ctl.wValue,
985 ctl.wIndex, ctl.wLength);
986
987 if ((ctl.bRequestType & (USB_DIR_IN | USB_TYPE_MASK)) ==
988 (USB_DIR_IN | USB_TYPE_STANDARD)) {
989 if (ctl.bRequest == USB_REQ_GET_STATUS) {
990 /* OTG supplement Rev 2.0 introduces another device
991 * GET_STATUS request for HNP polling with length = 1.
992 */
993 u8 len = 2;
994 switch (ctl.bRequestType & USB_RECIP_MASK) {
995 case USB_RECIP_ENDPOINT:
996 {
997 struct msm_endpoint *ept;
998 unsigned num =
999 ctl.wIndex & USB_ENDPOINT_NUMBER_MASK;
1000 u16 temp = 0;
1001
1002 if (num == 0) {
1003 memset(req->buf, 0, 2);
1004 break;
1005 }
1006 if (ctl.wIndex & USB_ENDPOINT_DIR_MASK)
1007 num += 16;
1008 ept = &ui->ep0out + num;
1009 temp = usb_ep_get_stall(ept);
1010 temp = temp << USB_ENDPOINT_HALT;
1011 memcpy(req->buf, &temp, 2);
1012 break;
1013 }
1014 case USB_RECIP_DEVICE:
1015 {
1016 u16 temp = 0;
1017
1018 if (ctl.wIndex == OTG_STATUS_SELECTOR) {
1019#ifdef CONFIG_USB_OTG
1020 spin_lock_irqsave(&ui->lock, flags);
1021 hnp = (ui->gadget.host_request <<
1022 HOST_REQUEST_FLAG);
1023 ui->hnp_avail = 1;
1024 spin_unlock_irqrestore(&ui->lock,
1025 flags);
1026 memcpy(req->buf, &hnp, 1);
1027 len = 1;
1028#else
1029 goto stall;
1030#endif
1031 } else {
1032 temp = (atomic_read(&ui->self_powered)
1033 << USB_DEVICE_SELF_POWERED);
1034 temp |= (atomic_read(&ui->remote_wakeup)
1035 << USB_DEVICE_REMOTE_WAKEUP);
1036 memcpy(req->buf, &temp, 2);
1037 }
1038 break;
1039 }
1040 case USB_RECIP_INTERFACE:
1041 memset(req->buf, 0, 2);
1042 break;
1043 default:
1044 goto stall;
1045 }
1046 ep0_setup_send(ui, len);
1047 return;
1048 }
1049 }
1050 if (ctl.bRequestType ==
1051 (USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_ENDPOINT)) {
1052 if ((ctl.bRequest == USB_REQ_CLEAR_FEATURE) ||
1053 (ctl.bRequest == USB_REQ_SET_FEATURE)) {
1054 if ((ctl.wValue == 0) && (ctl.wLength == 0)) {
1055 unsigned num = ctl.wIndex & 0x0f;
1056
1057 if (num != 0) {
1058 struct msm_endpoint *ept;
1059
1060 if (ctl.wIndex & 0x80)
1061 num += 16;
1062 ept = &ui->ep0out + num;
1063
1064 if (ept->wedged)
1065 goto ack;
1066 if (ctl.bRequest == USB_REQ_SET_FEATURE)
1067 usb_ept_set_halt(&ept->ep, 1);
1068 else
1069 usb_ept_set_halt(&ept->ep, 0);
1070 }
1071 goto ack;
1072 }
1073 }
1074 }
1075 if (ctl.bRequestType == (USB_DIR_OUT | USB_TYPE_STANDARD)) {
1076 if (ctl.bRequest == USB_REQ_SET_CONFIGURATION) {
1077 atomic_set(&ui->configured, !!ctl.wValue);
1078 msm_hsusb_set_state(USB_STATE_CONFIGURED);
1079 } else if (ctl.bRequest == USB_REQ_SET_ADDRESS) {
1080 /*
1081 * Gadget speed should be set when PCI interrupt
1082 * occurs. But sometimes, PCI interrupt is not
1083 * occuring after reset. Hence update the gadget
1084 * speed here.
1085 */
1086 if (ui->gadget.speed == USB_SPEED_UNKNOWN) {
1087 dev_info(&ui->pdev->dev,
1088 "PCI intr missed"
1089 "set speed explictly\n");
1090 msm_hsusb_set_speed(ui);
1091 }
1092 msm_hsusb_set_state(USB_STATE_ADDRESS);
1093
1094 /* write address delayed (will take effect
1095 ** after the next IN txn)
1096 */
1097 writel((ctl.wValue << 25) | (1 << 24), USB_DEVICEADDR);
1098 goto ack;
1099 } else if (ctl.bRequest == USB_REQ_SET_FEATURE) {
1100 switch (ctl.wValue) {
1101 case USB_DEVICE_TEST_MODE:
1102 switch (ctl.wIndex) {
1103 case J_TEST:
1104 case K_TEST:
1105 case SE0_NAK_TEST:
1106 case TST_PKT_TEST:
1107 atomic_set(&ui->test_mode, ctl.wIndex);
1108 goto ack;
1109 }
1110 goto stall;
1111 case USB_DEVICE_REMOTE_WAKEUP:
1112 atomic_set(&ui->remote_wakeup, 1);
1113 goto ack;
1114#ifdef CONFIG_USB_OTG
1115 case USB_DEVICE_B_HNP_ENABLE:
1116 ui->gadget.b_hnp_enable = 1;
1117 goto ack;
1118 case USB_DEVICE_A_HNP_SUPPORT:
1119 case USB_DEVICE_A_ALT_HNP_SUPPORT:
1120 /* B-devices compliant to OTG spec
1121 * Rev 2.0 are not required to
1122 * suppport these features.
1123 */
1124 goto stall;
1125#endif
1126 }
1127 } else if ((ctl.bRequest == USB_REQ_CLEAR_FEATURE) &&
1128 (ctl.wValue == USB_DEVICE_REMOTE_WAKEUP)) {
1129 atomic_set(&ui->remote_wakeup, 0);
1130 goto ack;
1131 }
1132 }
1133
1134 /* delegate if we get here */
1135 if (ui->driver) {
1136 ret = ui->driver->setup(&ui->gadget, &ctl);
1137 if (ret >= 0)
1138 return;
1139 }
1140
1141stall:
1142 /* stall ep0 on error */
1143 ep0_setup_stall(ui);
1144 return;
1145
1146ack:
1147 ep0_setup_ack(ui);
1148}
1149
1150static void handle_endpoint(struct usb_info *ui, unsigned bit)
1151{
1152 struct msm_endpoint *ept = ui->ept + bit;
1153 struct msm_request *req;
1154 unsigned long flags;
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301155 int req_dequeue = 1;
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05301156 int dtd_update_fail_count_chk = 10;
1157 int check_bit = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001158 unsigned info;
1159
1160 /*
1161 INFO("handle_endpoint() %d %s req=%p(%08x)\n",
1162 ept->num, (ept->flags & EPT_FLAG_IN) ? "in" : "out",
1163 ept->req, ept->req ? ept->req->item_dma : 0);
1164 */
1165
1166 /* expire all requests that are no longer active */
1167 spin_lock_irqsave(&ui->lock, flags);
1168 while ((req = ept->req)) {
1169 /* if we've processed all live requests, time to
1170 * restart the hardware on the next non-live request
1171 */
1172 if (!req->live) {
1173 usb_ept_start(ept);
1174 break;
1175 }
1176
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301177dequeue:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001178 /* clean speculative fetches on req->item->info */
1179 dma_coherent_post_ops();
1180 info = req->item->info;
1181 /* if the transaction is still in-flight, stop here */
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301182 if (info & INFO_ACTIVE) {
1183 if (req_dequeue) {
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301184 ui->dTD_update_fail_count++;
1185 ept->dTD_update_fail_count++;
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05301186 udelay(1);
1187 if (!dtd_update_fail_count_chk--) {
1188 req_dequeue = 0;
1189 check_bit = 1;
1190 }
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301191 goto dequeue;
1192 } else {
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05301193 if (check_bit) {
1194 pr_debug("%s: Delay Workaround Failed\n",
1195 __func__);
1196 check_bit = 0;
1197 ui->dTD_workaround_fail_count++;
1198 ept->dTD_workaround_fail_count++;
1199 }
Chiranjeevi Velempatifbd057d2012-05-14 16:11:35 +05301200 break;
1201 }
1202 }
1203 req_dequeue = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001204
Vijayavardhan Vennapusafd8df252011-12-08 16:19:37 +05301205 del_timer(&ept->prime_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001206 /* advance ept queue to the next request */
1207 ept->req = req->next;
1208 if (ept->req == 0)
1209 ept->last = 0;
1210
1211 dma_unmap_single(NULL, req->dma, req->req.length,
1212 (ept->flags & EPT_FLAG_IN) ?
1213 DMA_TO_DEVICE : DMA_FROM_DEVICE);
1214
1215 if (info & (INFO_HALTED | INFO_BUFFER_ERROR | INFO_TXN_ERROR)) {
1216 /* XXX pass on more specific error code */
1217 req->req.status = -EIO;
1218 req->req.actual = 0;
1219 dev_err(&ui->pdev->dev,
1220 "ept %d %s error. info=%08x\n",
1221 ept->num,
1222 (ept->flags & EPT_FLAG_IN) ? "in" : "out",
1223 info);
1224 } else {
1225 req->req.status = 0;
1226 req->req.actual =
1227 req->req.length - ((info >> 16) & 0x7FFF);
1228 }
1229 req->busy = 0;
1230 req->live = 0;
1231
1232 if (req->req.complete) {
1233 spin_unlock_irqrestore(&ui->lock, flags);
1234 req->req.complete(&ept->ep, &req->req);
1235 spin_lock_irqsave(&ui->lock, flags);
1236 }
1237 }
1238 spin_unlock_irqrestore(&ui->lock, flags);
1239}
1240
1241static void flush_endpoint_hw(struct usb_info *ui, unsigned bits)
1242{
1243 /* flush endpoint, canceling transactions
1244 ** - this can take a "large amount of time" (per databook)
1245 ** - the flush can fail in some cases, thus we check STAT
1246 ** and repeat if we're still operating
1247 ** (does the fact that this doesn't use the tripwire matter?!)
1248 */
1249 do {
1250 writel(bits, USB_ENDPTFLUSH);
1251 while (readl(USB_ENDPTFLUSH) & bits)
1252 udelay(100);
1253 } while (readl(USB_ENDPTSTAT) & bits);
1254}
1255
1256static void flush_endpoint_sw(struct msm_endpoint *ept)
1257{
1258 struct usb_info *ui = ept->ui;
1259 struct msm_request *req, *next_req = NULL;
1260 unsigned long flags;
1261
Rajkumar Raghupathy7233a152013-01-24 16:59:51 +05301262 if (!ept->req)
1263 return;
1264
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001265 /* inactive endpoints have nothing to do here */
1266 if (ept->ep.maxpacket == 0)
1267 return;
1268
1269 /* put the queue head in a sane state */
1270 ept->head->info = 0;
1271 ept->head->next = TERMINATE;
1272
1273 /* cancel any pending requests */
1274 spin_lock_irqsave(&ui->lock, flags);
1275 req = ept->req;
1276 ept->req = 0;
1277 ept->last = 0;
1278 while (req != 0) {
1279 req->busy = 0;
1280 req->live = 0;
1281 req->req.status = -ESHUTDOWN;
1282 req->req.actual = 0;
1283
1284 /* Gadget driver may free the request in completion
1285 * handler. So keep a copy of next req pointer
1286 * before calling completion handler.
1287 */
1288 next_req = req->next;
1289 if (req->req.complete) {
1290 spin_unlock_irqrestore(&ui->lock, flags);
1291 req->req.complete(&ept->ep, &req->req);
1292 spin_lock_irqsave(&ui->lock, flags);
1293 }
1294 req = next_req;
1295 }
1296 spin_unlock_irqrestore(&ui->lock, flags);
1297}
1298
1299static void flush_endpoint(struct msm_endpoint *ept)
1300{
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05301301 del_timer(&ept->prime_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001302 flush_endpoint_hw(ept->ui, (1 << ept->bit));
1303 flush_endpoint_sw(ept);
1304}
1305
1306static irqreturn_t usb_interrupt(int irq, void *data)
1307{
1308 struct usb_info *ui = data;
1309 unsigned n;
1310 unsigned long flags;
1311
1312 n = readl(USB_USBSTS);
1313 writel(n, USB_USBSTS);
1314
1315 /* somehow we got an IRQ while in the reset sequence: ignore it */
1316 if (!atomic_read(&ui->running))
1317 return IRQ_HANDLED;
1318
1319 if (n & STS_PCI) {
1320 msm_hsusb_set_speed(ui);
1321 if (atomic_read(&ui->configured)) {
1322 wake_lock(&ui->wlock);
1323
1324 spin_lock_irqsave(&ui->lock, flags);
1325 ui->usb_state = USB_STATE_CONFIGURED;
1326 ui->flags = USB_FLAG_CONFIGURED;
1327 spin_unlock_irqrestore(&ui->lock, flags);
1328
1329 ui->driver->resume(&ui->gadget);
1330 schedule_work(&ui->work);
1331 } else {
1332 msm_hsusb_set_state(USB_STATE_DEFAULT);
1333 }
1334
1335#ifdef CONFIG_USB_OTG
1336 /* notify otg to clear A_BIDL_ADIS timer */
1337 if (ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001338 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001339#endif
1340 }
1341
1342 if (n & STS_URI) {
1343 dev_dbg(&ui->pdev->dev, "reset\n");
1344 spin_lock_irqsave(&ui->lock, flags);
1345 ui->gadget.speed = USB_SPEED_UNKNOWN;
1346 spin_unlock_irqrestore(&ui->lock, flags);
1347#ifdef CONFIG_USB_OTG
1348 /* notify otg to clear A_BIDL_ADIS timer */
1349 if (ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001350 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001351 spin_lock_irqsave(&ui->lock, flags);
1352 /* Host request is persistent across reset */
1353 ui->gadget.b_hnp_enable = 0;
1354 ui->hnp_avail = 0;
1355 spin_unlock_irqrestore(&ui->lock, flags);
1356#endif
1357 msm_hsusb_set_state(USB_STATE_DEFAULT);
1358 atomic_set(&ui->remote_wakeup, 0);
1359 if (!ui->gadget.is_a_peripheral)
1360 schedule_delayed_work(&ui->chg_stop, 0);
1361
1362 writel(readl(USB_ENDPTSETUPSTAT), USB_ENDPTSETUPSTAT);
1363 writel(readl(USB_ENDPTCOMPLETE), USB_ENDPTCOMPLETE);
1364 writel(0xffffffff, USB_ENDPTFLUSH);
1365 writel(0, USB_ENDPTCTRL(1));
1366
1367 wake_lock(&ui->wlock);
1368 if (atomic_read(&ui->configured)) {
1369 /* marking us offline will cause ept queue attempts
1370 ** to fail
1371 */
1372 atomic_set(&ui->configured, 0);
1373 /* Defer sending offline uevent to userspace */
1374 atomic_set(&ui->offline_pending, 1);
1375
1376 /* XXX: we can't seem to detect going offline,
1377 * XXX: so deconfigure on reset for the time being
1378 */
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05301379 dev_dbg(&ui->pdev->dev,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001380 "usb: notify offline\n");
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05301381 ui->driver->disconnect(&ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001382 /* cancel pending ep0 transactions */
1383 flush_endpoint(&ui->ep0out);
1384 flush_endpoint(&ui->ep0in);
1385
1386 }
1387 /* Start phy stuck timer */
1388 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
1389 mod_timer(&phy_status_timer, PHY_STATUS_CHECK_DELAY);
1390 }
1391
1392 if (n & STS_SLI) {
1393 dev_dbg(&ui->pdev->dev, "suspend\n");
1394
1395 spin_lock_irqsave(&ui->lock, flags);
1396 ui->usb_state = USB_STATE_SUSPENDED;
1397 ui->flags = USB_FLAG_SUSPEND;
1398 spin_unlock_irqrestore(&ui->lock, flags);
1399
1400 ui->driver->suspend(&ui->gadget);
1401 schedule_work(&ui->work);
1402#ifdef CONFIG_USB_OTG
1403 /* notify otg for
1404 * 1. kicking A_BIDL_ADIS timer in case of A-peripheral
1405 * 2. disabling pull-up and kicking B_ASE0_RST timer
1406 */
1407 if (ui->gadget.b_hnp_enable || ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001408 usb_phy_set_suspend(ui->xceiv, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001409#endif
1410 }
1411
1412 if (n & STS_UI) {
1413 n = readl(USB_ENDPTSETUPSTAT);
1414 if (n & EPT_RX(0))
1415 handle_setup(ui);
1416
1417 n = readl(USB_ENDPTCOMPLETE);
1418 writel(n, USB_ENDPTCOMPLETE);
1419 while (n) {
1420 unsigned bit = __ffs(n);
1421 handle_endpoint(ui, bit);
1422 n = n & (~(1 << bit));
1423 }
1424 }
1425 return IRQ_HANDLED;
1426}
1427
1428static void usb_prepare(struct usb_info *ui)
1429{
1430 spin_lock_init(&ui->lock);
1431
1432 memset(ui->buf, 0, 4096);
1433 ui->head = (void *) (ui->buf + 0);
1434
1435 /* only important for reset/reinit */
1436 memset(ui->ept, 0, sizeof(ui->ept));
1437 ui->next_item = 0;
1438 ui->next_ifc_num = 0;
1439
1440 init_endpoints(ui);
1441
1442 ui->ep0in.ep.maxpacket = 64;
1443 ui->ep0out.ep.maxpacket = 64;
1444
1445 ui->setup_req =
1446 usb_ept_alloc_req(&ui->ep0in, SETUP_BUF_SIZE, GFP_KERNEL);
1447
1448 INIT_WORK(&ui->work, usb_do_work);
1449 INIT_DELAYED_WORK(&ui->chg_det, usb_chg_detect);
1450 INIT_DELAYED_WORK(&ui->chg_stop, usb_chg_stop);
1451 INIT_DELAYED_WORK(&ui->rw_work, usb_do_remote_wakeup);
1452 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
1453 INIT_WORK(&ui->phy_status_check, usb_phy_stuck_recover);
1454}
1455
1456static void usb_reset(struct usb_info *ui)
1457{
1458 struct msm_otg *otg = to_msm_otg(ui->xceiv);
1459
1460 dev_dbg(&ui->pdev->dev, "reset controller\n");
1461
1462 atomic_set(&ui->running, 0);
1463
1464 /*
1465 * PHY reset takes minimum 100 msec. Hence reset only link
1466 * during HNP. Reset PHY and link in B-peripheral mode.
1467 */
1468 if (ui->gadget.is_a_peripheral)
1469 otg->reset(ui->xceiv, 0);
1470 else
1471 otg->reset(ui->xceiv, 1);
1472
1473 /* set usb controller interrupt threshold to zero*/
1474 writel((readl(USB_USBCMD) & ~USBCMD_ITC_MASK) | USBCMD_ITC(0),
1475 USB_USBCMD);
1476
1477 writel(ui->dma, USB_ENDPOINTLISTADDR);
1478
1479 configure_endpoints(ui);
1480
1481 /* marking us offline will cause ept queue attempts to fail */
1482 atomic_set(&ui->configured, 0);
1483
1484 if (ui->driver) {
1485 dev_dbg(&ui->pdev->dev, "usb: notify offline\n");
1486 ui->driver->disconnect(&ui->gadget);
1487 }
1488
1489 /* cancel pending ep0 transactions */
1490 flush_endpoint(&ui->ep0out);
1491 flush_endpoint(&ui->ep0in);
1492
1493 /* enable interrupts */
1494 writel(STS_URI | STS_SLI | STS_UI | STS_PCI, USB_USBINTR);
1495
1496 /* Ensure that h/w RESET is completed before returning */
1497 mb();
1498
1499 atomic_set(&ui->running, 1);
1500}
1501
1502static void usb_start(struct usb_info *ui)
1503{
1504 unsigned long flags;
1505
1506 spin_lock_irqsave(&ui->lock, flags);
1507 ui->flags |= USB_FLAG_START;
1508 schedule_work(&ui->work);
1509 spin_unlock_irqrestore(&ui->lock, flags);
1510}
1511
1512static int usb_free(struct usb_info *ui, int ret)
1513{
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03001514 if (ret)
1515 dev_dbg(&ui->pdev->dev, "usb_free(%d)\n", ret);
1516
1517 usb_del_gadget_udc(&ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001518
1519 if (ui->xceiv)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001520 usb_put_transceiver(ui->xceiv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001521
1522 if (ui->irq)
1523 free_irq(ui->irq, 0);
1524 if (ui->pool)
1525 dma_pool_destroy(ui->pool);
1526 if (ui->dma)
1527 dma_free_coherent(&ui->pdev->dev, 4096, ui->buf, ui->dma);
1528 kfree(ui);
1529 return ret;
1530}
1531
1532static void usb_do_work_check_vbus(struct usb_info *ui)
1533{
1534 unsigned long iflags;
1535
1536 spin_lock_irqsave(&ui->lock, iflags);
1537 if (is_usb_online(ui))
1538 ui->flags |= USB_FLAG_VBUS_ONLINE;
1539 else
1540 ui->flags |= USB_FLAG_VBUS_OFFLINE;
1541 spin_unlock_irqrestore(&ui->lock, iflags);
1542}
1543
1544static void usb_do_work(struct work_struct *w)
1545{
1546 struct usb_info *ui = container_of(w, struct usb_info, work);
1547 struct msm_otg *otg = to_msm_otg(ui->xceiv);
1548 unsigned long iflags;
1549 unsigned flags, _vbus;
1550
1551 for (;;) {
1552 spin_lock_irqsave(&ui->lock, iflags);
1553 flags = ui->flags;
1554 ui->flags = 0;
1555 _vbus = is_usb_online(ui);
1556 spin_unlock_irqrestore(&ui->lock, iflags);
1557
1558 /* give up if we have nothing to do */
1559 if (flags == 0)
1560 break;
1561
1562 switch (ui->state) {
1563 case USB_STATE_IDLE:
1564 if (flags & USB_FLAG_START) {
1565 int ret;
1566
1567 if (!_vbus) {
1568 ui->state = USB_STATE_OFFLINE;
1569 break;
1570 }
1571
1572 pm_runtime_get_noresume(&ui->pdev->dev);
1573 pm_runtime_resume(&ui->pdev->dev);
1574 dev_dbg(&ui->pdev->dev,
1575 "msm72k_udc: IDLE -> ONLINE\n");
1576 usb_reset(ui);
1577 ret = request_irq(otg->irq, usb_interrupt,
1578 IRQF_SHARED,
1579 ui->pdev->name, ui);
1580 /* FIXME: should we call BUG_ON when
1581 * requst irq fails
1582 */
1583 if (ret) {
1584 dev_err(&ui->pdev->dev,
1585 "hsusb: peripheral: request irq"
1586 " failed:(%d)", ret);
1587 break;
1588 }
1589 ui->irq = otg->irq;
1590 ui->state = USB_STATE_ONLINE;
1591 usb_do_work_check_vbus(ui);
1592
1593 if (!atomic_read(&ui->softconnect))
1594 break;
1595
1596 msm72k_pullup_internal(&ui->gadget, 1);
1597
1598 if (!ui->gadget.is_a_peripheral)
1599 schedule_delayed_work(
1600 &ui->chg_det,
1601 USB_CHG_DET_DELAY);
1602
1603 }
1604 break;
1605 case USB_STATE_ONLINE:
1606 if (atomic_read(&ui->offline_pending)) {
1607 switch_set_state(&ui->sdev, 0);
1608 atomic_set(&ui->offline_pending, 0);
1609 }
1610
1611 /* If at any point when we were online, we received
1612 * the signal to go offline, we must honor it
1613 */
1614 if (flags & USB_FLAG_VBUS_OFFLINE) {
1615
1616 ui->chg_current = 0;
1617 /* wait incase chg_detect is running */
1618 if (!ui->gadget.is_a_peripheral)
1619 cancel_delayed_work_sync(&ui->chg_det);
1620
1621 dev_dbg(&ui->pdev->dev,
1622 "msm72k_udc: ONLINE -> OFFLINE\n");
1623
1624 atomic_set(&ui->running, 0);
1625 atomic_set(&ui->remote_wakeup, 0);
1626 atomic_set(&ui->configured, 0);
1627
1628 if (ui->driver) {
1629 dev_dbg(&ui->pdev->dev,
1630 "usb: notify offline\n");
1631 ui->driver->disconnect(&ui->gadget);
1632 }
1633 /* cancel pending ep0 transactions */
1634 flush_endpoint(&ui->ep0out);
1635 flush_endpoint(&ui->ep0in);
1636
1637 /* synchronize with irq context */
1638 spin_lock_irqsave(&ui->lock, iflags);
1639#ifdef CONFIG_USB_OTG
1640 ui->gadget.host_request = 0;
1641 ui->gadget.b_hnp_enable = 0;
1642 ui->hnp_avail = 0;
1643#endif
1644 msm72k_pullup_internal(&ui->gadget, 0);
1645 spin_unlock_irqrestore(&ui->lock, iflags);
1646
1647
1648 /* if charger is initialized to known type
1649 * we must let modem know about charger
1650 * disconnection
1651 */
Steve Mucklef132c6c2012-06-06 18:30:57 -07001652 usb_phy_set_power(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001653
1654 if (ui->irq) {
Chiranjeevi Velempati2a9c1cb2012-12-21 18:26:23 +05301655 /* Disable and acknowledge all
1656 * USB interrupts before freeing
1657 * irq, so that no USB spurious
1658 * interrupt occurs during USB cable
1659 * disconnect which may lead to
1660 * IRQ nobody cared error.
1661 */
1662 writel_relaxed(0, USB_USBINTR);
1663 writel_relaxed(readl_relaxed(USB_USBSTS)
1664 , USB_USBSTS);
1665 /* Ensure that above STOREs are
1666 * completed before enabling
1667 * interrupts */
1668 wmb();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001669 free_irq(ui->irq, ui);
1670 ui->irq = 0;
1671 }
1672
1673
1674 switch_set_state(&ui->sdev, 0);
1675
1676 ui->state = USB_STATE_OFFLINE;
1677 usb_do_work_check_vbus(ui);
1678 pm_runtime_put_noidle(&ui->pdev->dev);
1679 pm_runtime_suspend(&ui->pdev->dev);
1680 wake_unlock(&ui->wlock);
1681 break;
1682 }
1683 if (flags & USB_FLAG_SUSPEND) {
1684 int maxpower = usb_get_max_power(ui);
1685
1686 if (maxpower < 0)
1687 break;
1688
Steve Mucklef132c6c2012-06-06 18:30:57 -07001689 usb_phy_set_power(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001690 /* To support TCXO during bus suspend
1691 * This might be dummy check since bus suspend
1692 * is not implemented as of now
1693 * */
1694 if (release_wlocks)
1695 wake_unlock(&ui->wlock);
1696
1697 /* TBD: Initiate LPM at usb bus suspend */
1698 break;
1699 }
1700 if (flags & USB_FLAG_CONFIGURED) {
1701 int maxpower = usb_get_max_power(ui);
1702
1703 /* We may come here even when no configuration
1704 * is selected. Send online/offline event
1705 * accordingly.
1706 */
1707 switch_set_state(&ui->sdev,
1708 atomic_read(&ui->configured));
1709
1710 if (maxpower < 0)
1711 break;
1712
1713 ui->chg_current = maxpower;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001714 usb_phy_set_power(ui->xceiv, maxpower);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001715 break;
1716 }
1717 if (flags & USB_FLAG_RESET) {
1718 dev_dbg(&ui->pdev->dev,
1719 "msm72k_udc: ONLINE -> RESET\n");
1720 msm72k_pullup_internal(&ui->gadget, 0);
1721 usb_reset(ui);
1722 msm72k_pullup_internal(&ui->gadget, 1);
1723 dev_dbg(&ui->pdev->dev,
1724 "msm72k_udc: RESET -> ONLINE\n");
1725 break;
1726 }
1727 break;
1728 case USB_STATE_OFFLINE:
1729 /* If we were signaled to go online and vbus is still
1730 * present when we received the signal, go online.
1731 */
1732 if ((flags & USB_FLAG_VBUS_ONLINE) && _vbus) {
1733 int ret;
1734
1735 pm_runtime_get_noresume(&ui->pdev->dev);
1736 pm_runtime_resume(&ui->pdev->dev);
1737 dev_dbg(&ui->pdev->dev,
1738 "msm72k_udc: OFFLINE -> ONLINE\n");
1739
1740 usb_reset(ui);
1741 ui->state = USB_STATE_ONLINE;
1742 usb_do_work_check_vbus(ui);
1743 ret = request_irq(otg->irq, usb_interrupt,
1744 IRQF_SHARED,
1745 ui->pdev->name, ui);
1746 /* FIXME: should we call BUG_ON when
1747 * requst irq fails
1748 */
1749 if (ret) {
1750 dev_err(&ui->pdev->dev,
1751 "hsusb: peripheral: request irq"
1752 " failed:(%d)", ret);
1753 break;
1754 }
1755 ui->irq = otg->irq;
1756 enable_irq_wake(otg->irq);
1757
1758 if (!atomic_read(&ui->softconnect))
1759 break;
1760 msm72k_pullup_internal(&ui->gadget, 1);
1761
1762 if (!ui->gadget.is_a_peripheral)
1763 schedule_delayed_work(
1764 &ui->chg_det,
1765 USB_CHG_DET_DELAY);
1766 }
1767 break;
1768 }
1769 }
1770}
1771
1772/* FIXME - the callers of this function should use a gadget API instead.
1773 * This is called from htc_battery.c and board-halibut.c
1774 * WARNING - this can get called before this driver is initialized.
1775 */
1776void msm_hsusb_set_vbus_state(int online)
1777{
1778 unsigned long flags;
1779 struct usb_info *ui = the_usb_info;
1780
1781 if (!ui) {
1782 pr_err("%s called before driver initialized\n", __func__);
1783 return;
1784 }
1785
1786 spin_lock_irqsave(&ui->lock, flags);
1787
1788 if (is_usb_online(ui) == online)
1789 goto out;
1790
1791 if (online) {
1792 ui->usb_state = USB_STATE_POWERED;
1793 ui->flags |= USB_FLAG_VBUS_ONLINE;
1794 } else {
1795 ui->gadget.speed = USB_SPEED_UNKNOWN;
1796 ui->usb_state = USB_STATE_NOTATTACHED;
1797 ui->flags |= USB_FLAG_VBUS_OFFLINE;
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +05301798 ui->chg_type_retry_cnt = 0;
1799 ui->proprietary_chg = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001800 }
1801 if (in_interrupt()) {
1802 schedule_work(&ui->work);
1803 } else {
1804 spin_unlock_irqrestore(&ui->lock, flags);
1805 usb_do_work(&ui->work);
1806 return;
1807 }
1808out:
1809 spin_unlock_irqrestore(&ui->lock, flags);
1810}
1811
1812#if defined(CONFIG_DEBUG_FS)
1813
1814void usb_function_reenumerate(void)
1815{
1816 struct usb_info *ui = the_usb_info;
1817
1818 /* disable and re-enable the D+ pullup */
1819 dev_dbg(&ui->pdev->dev, "disable pullup\n");
1820 writel(readl(USB_USBCMD) & ~USBCMD_RS, USB_USBCMD);
1821
1822 msleep(10);
1823
1824 dev_dbg(&ui->pdev->dev, "enable pullup\n");
1825 writel(readl(USB_USBCMD) | USBCMD_RS, USB_USBCMD);
1826}
1827
1828static char debug_buffer[PAGE_SIZE];
1829
1830static ssize_t debug_read_status(struct file *file, char __user *ubuf,
1831 size_t count, loff_t *ppos)
1832{
1833 struct usb_info *ui = file->private_data;
1834 char *buf = debug_buffer;
1835 unsigned long flags;
1836 struct msm_endpoint *ept;
1837 struct msm_request *req;
1838 int n;
1839 int i = 0;
1840
1841 spin_lock_irqsave(&ui->lock, flags);
1842
1843 i += scnprintf(buf + i, PAGE_SIZE - i,
1844 "regs: setup=%08x prime=%08x stat=%08x done=%08x\n",
1845 readl(USB_ENDPTSETUPSTAT),
1846 readl(USB_ENDPTPRIME),
1847 readl(USB_ENDPTSTAT),
1848 readl(USB_ENDPTCOMPLETE));
1849 i += scnprintf(buf + i, PAGE_SIZE - i,
1850 "regs: cmd=%08x sts=%08x intr=%08x port=%08x\n\n",
1851 readl(USB_USBCMD),
1852 readl(USB_USBSTS),
1853 readl(USB_USBINTR),
1854 readl(USB_PORTSC));
1855
1856
1857 for (n = 0; n < 32; n++) {
1858 ept = ui->ept + n;
1859 if (ept->ep.maxpacket == 0)
1860 continue;
1861
1862 i += scnprintf(buf + i, PAGE_SIZE - i,
1863 "ept%d %s cfg=%08x active=%08x next=%08x info=%08x\n",
1864 ept->num, (ept->flags & EPT_FLAG_IN) ? "in " : "out",
1865 ept->head->config, ept->head->active,
1866 ept->head->next, ept->head->info);
1867
1868 for (req = ept->req; req; req = req->next)
1869 i += scnprintf(buf + i, PAGE_SIZE - i,
1870 " req @%08x next=%08x info=%08x page0=%08x %c %c\n",
1871 req->item_dma, req->item->next,
1872 req->item->info, req->item->page0,
1873 req->busy ? 'B' : ' ',
1874 req->live ? 'L' : ' ');
1875 }
1876
1877 i += scnprintf(buf + i, PAGE_SIZE - i,
1878 "phy failure count: %d\n", ui->phy_fail_count);
1879
1880 spin_unlock_irqrestore(&ui->lock, flags);
1881
1882 return simple_read_from_buffer(ubuf, count, ppos, buf, i);
1883}
1884
1885static ssize_t debug_write_reset(struct file *file, const char __user *buf,
1886 size_t count, loff_t *ppos)
1887{
1888 struct usb_info *ui = file->private_data;
1889 unsigned long flags;
1890
1891 spin_lock_irqsave(&ui->lock, flags);
1892 ui->flags |= USB_FLAG_RESET;
1893 schedule_work(&ui->work);
1894 spin_unlock_irqrestore(&ui->lock, flags);
1895
1896 return count;
1897}
1898
1899static ssize_t debug_write_cycle(struct file *file, const char __user *buf,
1900 size_t count, loff_t *ppos)
1901{
1902 usb_function_reenumerate();
1903 return count;
1904}
1905
1906static int debug_open(struct inode *inode, struct file *file)
1907{
1908 file->private_data = inode->i_private;
1909 return 0;
1910}
1911
1912const struct file_operations debug_stat_ops = {
1913 .open = debug_open,
1914 .read = debug_read_status,
1915};
1916
1917const struct file_operations debug_reset_ops = {
1918 .open = debug_open,
1919 .write = debug_write_reset,
1920};
1921
1922const struct file_operations debug_cycle_ops = {
1923 .open = debug_open,
1924 .write = debug_write_cycle,
1925};
1926
1927static ssize_t debug_read_release_wlocks(struct file *file, char __user *ubuf,
1928 size_t count, loff_t *ppos)
1929{
1930 char kbuf[10];
1931 size_t c = 0;
1932
1933 memset(kbuf, 0, 10);
1934
1935 c = scnprintf(kbuf, 10, "%d", release_wlocks);
1936
1937 if (copy_to_user(ubuf, kbuf, c))
1938 return -EFAULT;
1939
1940 return c;
1941}
1942static ssize_t debug_write_release_wlocks(struct file *file,
1943 const char __user *buf, size_t count, loff_t *ppos)
1944{
1945 char kbuf[10];
1946 long temp;
1947
1948 memset(kbuf, 0, 10);
1949
1950 if (copy_from_user(kbuf, buf, count > 10 ? 10 : count))
1951 return -EFAULT;
1952
1953 if (strict_strtol(kbuf, 10, &temp))
1954 return -EINVAL;
1955
1956 if (temp)
1957 release_wlocks = 1;
1958 else
1959 release_wlocks = 0;
1960
1961 return count;
1962}
1963static int debug_wake_lock_open(struct inode *inode, struct file *file)
1964{
1965 file->private_data = inode->i_private;
1966 return 0;
1967}
1968const struct file_operations debug_wlocks_ops = {
1969 .open = debug_wake_lock_open,
1970 .read = debug_read_release_wlocks,
1971 .write = debug_write_release_wlocks,
1972};
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05301973
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05301974static ssize_t debug_reprime_ep(struct file *file, const char __user *ubuf,
1975 size_t count, loff_t *ppos)
1976{
1977 struct usb_info *ui = file->private_data;
1978 struct msm_endpoint *ept;
1979 char kbuf[10];
1980 unsigned int ep_num, dir;
1981 unsigned long flags;
1982 unsigned n, i;
1983
1984 memset(kbuf, 0, 10);
1985
1986 if (copy_from_user(kbuf, ubuf, count > 10 ? 10 : count))
1987 return -EFAULT;
1988
1989 if (sscanf(kbuf, "%u %u", &ep_num, &dir) != 2)
1990 return -EINVAL;
1991
1992 if (dir)
1993 i = ep_num + 16;
1994 else
1995 i = ep_num;
1996
1997 spin_lock_irqsave(&ui->lock, flags);
1998 ept = ui->ept + i;
1999 n = 1 << ept->bit;
2000
2001 if ((readl_relaxed(USB_ENDPTPRIME) & n))
2002 goto out;
2003
2004 if (readl_relaxed(USB_ENDPTSTAT) & n)
2005 goto out;
2006
2007 /* clear speculative loads on item->info */
2008 rmb();
2009 if (ept->req && (ept->req->item->info & INFO_ACTIVE)) {
2010 pr_err("%s(): ept%d%s prime failed. ept: config: %x"
2011 "active: %x next: %x info: %x\n",
2012 __func__, ept->num,
2013 ept->flags & EPT_FLAG_IN ? "in" : "out",
2014 ept->head->config, ept->head->active,
2015 ept->head->next, ept->head->info);
2016 writel_relaxed(n, USB_ENDPTPRIME);
2017 }
2018out:
2019 spin_unlock_irqrestore(&ui->lock, flags);
2020
2021 return count;
2022}
2023
2024static char buffer[512];
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302025static ssize_t debug_prime_fail_read(struct file *file, char __user *ubuf,
2026 size_t count, loff_t *ppos)
2027{
2028 struct usb_info *ui = file->private_data;
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302029 char *buf = buffer;
2030 unsigned long flags;
2031 struct msm_endpoint *ept;
2032 int n;
2033 int i = 0;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302034
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302035 spin_lock_irqsave(&ui->lock, flags);
2036 for (n = 0; n < 32; n++) {
2037 ept = ui->ept + n;
2038 if (ept->ep.maxpacket == 0)
2039 continue;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302040
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302041 i += scnprintf(buf + i, PAGE_SIZE - i,
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302042 "ept%d %s false_prime_count=%lu prime_fail_count=%d "
2043 "dtd_fail_count=%lu "
2044 "dTD_workaround_fail_count=%lu\n",
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302045 ept->num, (ept->flags & EPT_FLAG_IN) ? "in " : "out",
2046 ept->false_prime_fail_count,
2047 ept->actual_prime_fail_count,
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302048 ept->dTD_update_fail_count,
2049 ept->dTD_workaround_fail_count);
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302050 }
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302051
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302052 i += scnprintf(buf + i, PAGE_SIZE - i,
2053 "dTD_update_fail count: %lu\n",
2054 ui->dTD_update_fail_count);
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302055
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302056 i += scnprintf(buf + i, PAGE_SIZE - i,
2057 "prime_fail count: %d\n", ui->prime_fail_count);
2058
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302059 i += scnprintf(buf + i, PAGE_SIZE - i,
2060 "dtd_workaround_fail count: %lu\n",
2061 ui->dTD_workaround_fail_count);
2062
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302063 spin_unlock_irqrestore(&ui->lock, flags);
2064
2065 return simple_read_from_buffer(ubuf, count, ppos, buf, i);
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302066}
2067
2068static int debug_prime_fail_open(struct inode *inode, struct file *file)
2069{
2070 file->private_data = inode->i_private;
2071 return 0;
2072}
2073
2074const struct file_operations prime_fail_ops = {
2075 .open = debug_prime_fail_open,
2076 .read = debug_prime_fail_read,
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302077 .write = debug_reprime_ep,
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302078};
2079
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +05302080static ssize_t debug_prop_chg_write(struct file *file,
2081 const char __user *buf, size_t count, loff_t *ppos)
2082{
2083 struct usb_info *ui = file->private_data;
2084 char kbuf[2];
2085
2086 memset(kbuf, 0, sizeof(kbuf));
2087
2088 if (copy_from_user(kbuf, buf, sizeof(kbuf)))
2089 return -EFAULT;
2090
2091 if (!strncmp(kbuf, "1", 1))
2092 ui->pdata->prop_chg = 1;
2093 else
2094 ui->pdata->prop_chg = 0;
2095
2096 return count;
2097}
2098
2099static ssize_t debug_prop_chg_read(struct file *file, char __user *ubuf,
2100 size_t count, loff_t *ppos)
2101{
2102 struct usb_info *ui = file->private_data;
2103 char kbuf[2];
2104 size_t c = 0;
2105
2106 memset(kbuf, 0, sizeof(kbuf));
2107
2108 c = scnprintf(kbuf, sizeof(kbuf), "%d\n", ui->pdata->prop_chg);
2109
2110 if (copy_to_user(ubuf, kbuf, c))
2111 return -EFAULT;
2112
2113 return simple_read_from_buffer(ubuf, count, ppos, kbuf, c);
2114}
2115
2116static int debug_prop_chg_open(struct inode *inode, struct file *file)
2117{
2118 file->private_data = inode->i_private;
2119 return 0;
2120}
2121
2122const struct file_operations debug_prop_chg_ops = {
2123 .open = debug_prop_chg_open,
2124 .read = debug_prop_chg_read,
2125 .write = debug_prop_chg_write,
2126};
2127
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002128static void usb_debugfs_init(struct usb_info *ui)
2129{
2130 struct dentry *dent;
2131 dent = debugfs_create_dir(dev_name(&ui->pdev->dev), 0);
2132 if (IS_ERR(dent))
2133 return;
2134
2135 debugfs_create_file("status", 0444, dent, ui, &debug_stat_ops);
2136 debugfs_create_file("reset", 0222, dent, ui, &debug_reset_ops);
2137 debugfs_create_file("cycle", 0222, dent, ui, &debug_cycle_ops);
2138 debugfs_create_file("release_wlocks", 0666, dent, ui,
2139 &debug_wlocks_ops);
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302140 debugfs_create_file("prime_fail_countt", 0666, dent, ui,
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302141 &prime_fail_ops);
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +05302142 debugfs_create_file("proprietary_chg", 0666, dent, ui,
2143 &debug_prop_chg_ops);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002144}
2145#else
2146static void usb_debugfs_init(struct usb_info *ui) {}
2147#endif
2148
2149static int
2150msm72k_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
2151{
Rajkumar Raghupathye3a95f72012-05-29 20:05:47 +05302152 struct msm_endpoint *ept;
2153 unsigned char ep_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002154
Rajkumar Raghupathye3a95f72012-05-29 20:05:47 +05302155 if (_ep == NULL || desc == NULL)
2156 return -EINVAL;
2157
2158 ept = to_msm_endpoint(_ep);
2159 ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002160 _ep->maxpacket = le16_to_cpu(desc->wMaxPacketSize);
2161 config_ept(ept);
2162 ept->wedged = 0;
2163 usb_ept_enable(ept, 1, ep_type);
2164 return 0;
2165}
2166
2167static int msm72k_disable(struct usb_ep *_ep)
2168{
2169 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2170
2171 usb_ept_enable(ept, 0, 0);
2172 flush_endpoint(ept);
Pavankumar Kondeti2c968782012-04-12 15:16:39 +05302173 /*
2174 * Clear descriptors here. Otherwise previous descriptors
2175 * will be used by function drivers upon next enumeration.
2176 */
2177 _ep->desc = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002178 return 0;
2179}
2180
2181static struct usb_request *
2182msm72k_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
2183{
2184 return usb_ept_alloc_req(to_msm_endpoint(_ep), 0, gfp_flags);
2185}
2186
2187static void
2188msm72k_free_request(struct usb_ep *_ep, struct usb_request *_req)
2189{
2190 struct msm_request *req = to_msm_request(_req);
2191 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2192 struct usb_info *ui = ept->ui;
2193
2194 /* request should not be busy */
2195 BUG_ON(req->busy);
2196 if (req->alloced)
2197 kfree(req->req.buf);
2198 dma_pool_free(ui->pool, req->item, req->item_dma);
2199 kfree(req);
2200}
2201
2202static int
2203msm72k_queue(struct usb_ep *_ep, struct usb_request *req, gfp_t gfp_flags)
2204{
2205 struct msm_endpoint *ep = to_msm_endpoint(_ep);
2206 struct usb_info *ui = ep->ui;
2207
Rajkumar Raghupathy7233a152013-01-24 16:59:51 +05302208 if (!atomic_read(&ui->softconnect))
2209 return -ENODEV;
2210
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002211 if (ep == &ui->ep0in) {
2212 struct msm_request *r = to_msm_request(req);
2213 if (!req->length)
2214 goto ep_queue_done;
2215 r->gadget_complete = req->complete;
2216 /* ep0_queue_ack_complete queue a receive for ACK before
2217 ** calling req->complete
2218 */
2219 req->complete = ep0_queue_ack_complete;
2220 if (atomic_read(&ui->ep0_dir) == USB_DIR_OUT)
2221 ep = &ui->ep0out;
2222 goto ep_queue_done;
2223 }
2224
2225ep_queue_done:
2226 return usb_ept_queue_xfer(ep, req);
2227}
2228
2229static int msm72k_dequeue(struct usb_ep *_ep, struct usb_request *_req)
2230{
2231 struct msm_endpoint *ep = to_msm_endpoint(_ep);
2232 struct msm_request *req = to_msm_request(_req);
2233 struct usb_info *ui = ep->ui;
2234
2235 struct msm_request *temp_req;
2236 unsigned long flags;
2237
Rajkumar Raghupathy7233a152013-01-24 16:59:51 +05302238 if (ep->num == 0) {
2239 /* Flush both out and in control endpoints */
2240 flush_endpoint(&ui->ep0out);
2241 flush_endpoint(&ui->ep0in);
2242 return 0;
2243 }
2244
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002245 if (!(ui && req && ep->req))
2246 return -EINVAL;
2247
2248 spin_lock_irqsave(&ui->lock, flags);
2249 if (!req->busy) {
2250 dev_dbg(&ui->pdev->dev, "%s: !req->busy\n", __func__);
2251 spin_unlock_irqrestore(&ui->lock, flags);
2252 return -EINVAL;
2253 }
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302254 del_timer(&ep->prime_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002255 /* Stop the transfer */
2256 do {
2257 writel((1 << ep->bit), USB_ENDPTFLUSH);
2258 while (readl(USB_ENDPTFLUSH) & (1 << ep->bit))
2259 udelay(100);
2260 } while (readl(USB_ENDPTSTAT) & (1 << ep->bit));
2261
2262 req->req.status = 0;
2263 req->busy = 0;
2264
2265 if (ep->req == req) {
2266 ep->req = req->next;
2267 ep->head->next = req->item->next;
2268 } else {
2269 req->prev->next = req->next;
2270 if (req->next)
2271 req->next->prev = req->prev;
2272 req->prev->item->next = req->item->next;
2273 }
2274
2275 if (!req->next)
2276 ep->last = req->prev;
2277
2278 /* initialize request to default */
2279 req->item->next = TERMINATE;
2280 req->item->info = 0;
2281 req->live = 0;
2282 dma_unmap_single(NULL, req->dma, req->req.length,
2283 (ep->flags & EPT_FLAG_IN) ?
2284 DMA_TO_DEVICE : DMA_FROM_DEVICE);
2285
2286 if (req->req.complete) {
2287 req->req.status = -ECONNRESET;
2288 spin_unlock_irqrestore(&ui->lock, flags);
2289 req->req.complete(&ep->ep, &req->req);
2290 spin_lock_irqsave(&ui->lock, flags);
2291 }
2292
2293 if (!req->live) {
2294 /* Reprime the endpoint for the remaining transfers */
2295 for (temp_req = ep->req ; temp_req ; temp_req = temp_req->next)
2296 temp_req->live = 0;
2297 if (ep->req)
2298 usb_ept_start(ep);
2299 spin_unlock_irqrestore(&ui->lock, flags);
2300 return 0;
2301 }
2302 spin_unlock_irqrestore(&ui->lock, flags);
2303 return 0;
2304}
2305
2306static int
2307usb_ept_set_halt(struct usb_ep *_ep, int value)
2308{
2309 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2310 struct usb_info *ui = ept->ui;
2311 unsigned int in = ept->flags & EPT_FLAG_IN;
2312 unsigned int n;
2313 unsigned long flags;
2314
2315 spin_lock_irqsave(&ui->lock, flags);
2316
2317 n = readl(USB_ENDPTCTRL(ept->num));
2318
2319 if (in) {
2320 if (value)
2321 n |= CTRL_TXS;
2322 else {
2323 n &= ~CTRL_TXS;
2324 n |= CTRL_TXR;
2325 }
2326 } else {
2327 if (value)
2328 n |= CTRL_RXS;
2329 else {
2330 n &= ~CTRL_RXS;
2331 n |= CTRL_RXR;
2332 }
2333 }
2334 writel(n, USB_ENDPTCTRL(ept->num));
2335 if (!value)
2336 ept->wedged = 0;
2337 spin_unlock_irqrestore(&ui->lock, flags);
2338
2339 return 0;
2340}
2341
2342static int
2343msm72k_set_halt(struct usb_ep *_ep, int value)
2344{
2345 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2346 unsigned int in = ept->flags & EPT_FLAG_IN;
2347
2348 if (value && in && ept->req)
2349 return -EAGAIN;
2350
2351 usb_ept_set_halt(_ep, value);
2352
2353 return 0;
2354}
2355
2356static int
2357msm72k_fifo_status(struct usb_ep *_ep)
2358{
2359 return -EOPNOTSUPP;
2360}
2361
2362static void
2363msm72k_fifo_flush(struct usb_ep *_ep)
2364{
2365 flush_endpoint(to_msm_endpoint(_ep));
2366}
2367static int msm72k_set_wedge(struct usb_ep *_ep)
2368{
2369 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2370
2371 if (ept->num == 0)
2372 return -EINVAL;
2373
2374 ept->wedged = 1;
2375
2376 return msm72k_set_halt(_ep, 1);
2377}
2378
2379static const struct usb_ep_ops msm72k_ep_ops = {
2380 .enable = msm72k_enable,
2381 .disable = msm72k_disable,
2382
2383 .alloc_request = msm72k_alloc_request,
2384 .free_request = msm72k_free_request,
2385
2386 .queue = msm72k_queue,
2387 .dequeue = msm72k_dequeue,
2388
2389 .set_halt = msm72k_set_halt,
2390 .set_wedge = msm72k_set_wedge,
2391 .fifo_status = msm72k_fifo_status,
2392 .fifo_flush = msm72k_fifo_flush,
2393};
2394
2395static int msm72k_get_frame(struct usb_gadget *_gadget)
2396{
2397 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2398
2399 /* frame number is in bits 13:3 */
2400 return (readl(USB_FRINDEX) >> 3) & 0x000007FF;
2401}
2402
2403/* VBUS reporting logically comes from a transceiver */
2404static int msm72k_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
2405{
2406 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2407 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2408
2409 if (is_active || atomic_read(&otg->chg_type)
2410 == USB_CHG_TYPE__WALLCHARGER)
2411 wake_lock(&ui->wlock);
2412
2413 msm_hsusb_set_vbus_state(is_active);
2414 return 0;
2415}
2416
2417/* SW workarounds
2418Issue #1 - USB Spoof Disconnect Failure
2419Symptom - Writing 0 to run/stop bit of USBCMD doesn't cause disconnect
2420SW workaround - Making opmode non-driving and SuspendM set in function
2421 register of SMSC phy
2422*/
2423/* drivers may have software control over D+ pullup */
2424static int msm72k_pullup_internal(struct usb_gadget *_gadget, int is_active)
2425{
2426 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2427 unsigned long flags;
2428
2429 if (is_active) {
2430 spin_lock_irqsave(&ui->lock, flags);
2431 if (is_usb_online(ui) && ui->driver)
2432 writel(readl(USB_USBCMD) | USBCMD_RS, USB_USBCMD);
2433 spin_unlock_irqrestore(&ui->lock, flags);
2434 } else {
2435 writel(readl(USB_USBCMD) & ~USBCMD_RS, USB_USBCMD);
2436 /* S/W workaround, Issue#1 */
Steve Mucklef132c6c2012-06-06 18:30:57 -07002437 usb_phy_io_write(ui->xceiv, 0x48, 0x04);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002438 }
2439
2440 /* Ensure pull-up operation is completed before returning */
2441 mb();
2442
2443 return 0;
2444}
2445
2446static int msm72k_pullup(struct usb_gadget *_gadget, int is_active)
2447{
2448 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
Chiranjeevi Velempatif4fe1192012-05-14 09:39:08 +05302449 struct msm_otg *otg = to_msm_otg(ui->xceiv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002450 unsigned long flags;
2451
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002452 atomic_set(&ui->softconnect, is_active);
2453
2454 spin_lock_irqsave(&ui->lock, flags);
Chiranjeevi Velempatif4fe1192012-05-14 09:39:08 +05302455 if (ui->usb_state == USB_STATE_NOTATTACHED || ui->driver == NULL ||
2456 atomic_read(&otg->chg_type) == USB_CHG_TYPE__WALLCHARGER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002457 spin_unlock_irqrestore(&ui->lock, flags);
2458 return 0;
2459 }
2460 spin_unlock_irqrestore(&ui->lock, flags);
2461
2462 msm72k_pullup_internal(_gadget, is_active);
2463
2464 if (is_active && !ui->gadget.is_a_peripheral)
2465 schedule_delayed_work(&ui->chg_det, USB_CHG_DET_DELAY);
2466
2467 return 0;
2468}
2469
2470static int msm72k_wakeup(struct usb_gadget *_gadget)
2471{
2472 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2473 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2474
2475 if (!atomic_read(&ui->remote_wakeup)) {
2476 dev_err(&ui->pdev->dev,
2477 "%s: remote wakeup not supported\n", __func__);
2478 return -ENOTSUPP;
2479 }
2480
2481 if (!atomic_read(&ui->configured)) {
2482 dev_err(&ui->pdev->dev,
2483 "%s: device is not configured\n", __func__);
2484 return -ENODEV;
2485 }
Steve Mucklef132c6c2012-06-06 18:30:57 -07002486 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002487
2488 disable_irq(otg->irq);
2489
2490 if (!is_usb_active())
2491 writel(readl(USB_PORTSC) | PORTSC_FPR, USB_PORTSC);
2492
2493 /* Ensure that USB port is resumed before enabling the IRQ */
2494 mb();
2495
2496 enable_irq(otg->irq);
2497
2498 return 0;
2499}
2500
2501/* when Gadget is configured, it will indicate how much power
2502 * can be pulled from vbus, as specified in configuiration descriptor
2503 */
2504static int msm72k_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2505{
2506 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2507 unsigned long flags;
2508
2509
2510 spin_lock_irqsave(&ui->lock, flags);
2511 ui->b_max_pow = mA;
2512 ui->flags = USB_FLAG_CONFIGURED;
2513 spin_unlock_irqrestore(&ui->lock, flags);
2514
2515 schedule_work(&ui->work);
2516
2517 return 0;
2518}
2519
2520static int msm72k_set_selfpowered(struct usb_gadget *_gadget, int set)
2521{
2522 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2523 unsigned long flags;
2524 int ret = 0;
2525
2526 spin_lock_irqsave(&ui->lock, flags);
2527 if (set) {
2528 if (ui->pdata && ui->pdata->self_powered)
2529 atomic_set(&ui->self_powered, 1);
2530 else
2531 ret = -EOPNOTSUPP;
2532 } else {
2533 /* We can always work as a bus powered device */
2534 atomic_set(&ui->self_powered, 0);
2535 }
2536 spin_unlock_irqrestore(&ui->lock, flags);
2537
2538 return ret;
2539
2540}
2541
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002542static int msm72k_gadget_start(struct usb_gadget_driver *driver,
2543 int (*bind)(struct usb_gadget *));
2544static int msm72k_gadget_stop(struct usb_gadget_driver *driver);
2545
2546
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002547static const struct usb_gadget_ops msm72k_ops = {
2548 .get_frame = msm72k_get_frame,
2549 .vbus_session = msm72k_udc_vbus_session,
2550 .vbus_draw = msm72k_udc_vbus_draw,
2551 .pullup = msm72k_pullup,
2552 .wakeup = msm72k_wakeup,
2553 .set_selfpowered = msm72k_set_selfpowered,
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002554 .start = msm72k_gadget_start,
2555 .stop = msm72k_gadget_stop
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002556};
2557
2558static void usb_do_remote_wakeup(struct work_struct *w)
2559{
2560 struct usb_info *ui = the_usb_info;
2561
2562 msm72k_wakeup(&ui->gadget);
2563}
2564
2565static ssize_t usb_remote_wakeup(struct device *dev,
2566 struct device_attribute *attr, const char *buf, size_t count)
2567{
2568 struct usb_info *ui = the_usb_info;
2569
2570 msm72k_wakeup(&ui->gadget);
2571
2572 return count;
2573}
2574
2575static ssize_t show_usb_state(struct device *dev, struct device_attribute *attr,
2576 char *buf)
2577{
2578 size_t i;
2579 char *state[] = {"USB_STATE_NOTATTACHED", "USB_STATE_ATTACHED",
2580 "USB_STATE_POWERED", "USB_STATE_UNAUTHENTICATED",
2581 "USB_STATE_RECONNECTING", "USB_STATE_DEFAULT",
2582 "USB_STATE_ADDRESS", "USB_STATE_CONFIGURED",
2583 "USB_STATE_SUSPENDED"
2584 };
2585
2586 i = scnprintf(buf, PAGE_SIZE, "%s\n", state[msm_hsusb_get_state()]);
2587 return i;
2588}
2589
2590static ssize_t show_usb_speed(struct device *dev, struct device_attribute *attr,
2591 char *buf)
2592{
2593 struct usb_info *ui = the_usb_info;
2594 size_t i;
2595 char *speed[] = {"USB_SPEED_UNKNOWN", "USB_SPEED_LOW",
2596 "USB_SPEED_FULL", "USB_SPEED_HIGH"};
2597
2598 i = scnprintf(buf, PAGE_SIZE, "%s\n", speed[ui->gadget.speed]);
2599 return i;
2600}
2601
2602static ssize_t store_usb_chg_current(struct device *dev,
2603 struct device_attribute *attr, const char *buf, size_t count)
2604{
2605 struct usb_info *ui = the_usb_info;
2606 unsigned long mA;
2607
2608 if (ui->gadget.is_a_peripheral)
2609 return -EINVAL;
2610
2611 if (strict_strtoul(buf, 10, &mA))
2612 return -EINVAL;
2613
2614 ui->chg_current = mA;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002615 usb_phy_set_power(ui->xceiv, mA);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002616
2617 return count;
2618}
2619
2620static ssize_t show_usb_chg_current(struct device *dev,
2621 struct device_attribute *attr, char *buf)
2622{
2623 struct usb_info *ui = the_usb_info;
2624 size_t count;
2625
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302626 count = snprintf(buf, PAGE_SIZE, "%d", ui->chg_current);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002627
2628 return count;
2629}
2630
2631static ssize_t show_usb_chg_type(struct device *dev,
2632 struct device_attribute *attr, char *buf)
2633{
2634 struct usb_info *ui = the_usb_info;
2635 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2636 size_t count;
2637 char *chg_type[] = {"STD DOWNSTREAM PORT",
2638 "CARKIT",
2639 "DEDICATED CHARGER",
2640 "INVALID"};
2641
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302642 count = snprintf(buf, PAGE_SIZE, "%s",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002643 chg_type[atomic_read(&otg->chg_type)]);
2644
2645 return count;
2646}
2647static DEVICE_ATTR(wakeup, S_IWUSR, 0, usb_remote_wakeup);
2648static DEVICE_ATTR(usb_state, S_IRUSR, show_usb_state, 0);
2649static DEVICE_ATTR(usb_speed, S_IRUSR, show_usb_speed, 0);
2650static DEVICE_ATTR(chg_type, S_IRUSR, show_usb_chg_type, 0);
2651static DEVICE_ATTR(chg_current, S_IWUSR | S_IRUSR,
2652 show_usb_chg_current, store_usb_chg_current);
2653
2654#ifdef CONFIG_USB_OTG
2655static ssize_t store_host_req(struct device *dev,
2656 struct device_attribute *attr, const char *buf, size_t count)
2657{
2658 struct usb_info *ui = the_usb_info;
2659 unsigned long val, flags;
2660
2661 if (strict_strtoul(buf, 10, &val))
2662 return -EINVAL;
2663
2664 dev_dbg(&ui->pdev->dev, "%s host request\n",
2665 val ? "set" : "clear");
2666
2667 spin_lock_irqsave(&ui->lock, flags);
2668 if (ui->hnp_avail)
2669 ui->gadget.host_request = !!val;
2670 spin_unlock_irqrestore(&ui->lock, flags);
2671
2672 return count;
2673}
2674static DEVICE_ATTR(host_request, S_IWUSR, NULL, store_host_req);
2675
2676/* How do we notify user space about HNP availability?
2677 * As we are compliant to Rev 2.0, Host will not set a_hnp_support.
2678 * Introduce hnp_avail flag and set when HNP polling request arrives.
2679 * The expectation is that user space checks hnp availability before
2680 * requesting host role via above sysfs node.
2681 */
2682static ssize_t show_host_avail(struct device *dev,
2683 struct device_attribute *attr, char *buf)
2684{
2685 struct usb_info *ui = the_usb_info;
2686 size_t count;
2687 unsigned long flags;
2688
2689 spin_lock_irqsave(&ui->lock, flags);
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302690 count = snprintf(buf, PAGE_SIZE, "%d\n", ui->hnp_avail);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002691 spin_unlock_irqrestore(&ui->lock, flags);
2692
2693 return count;
2694}
2695static DEVICE_ATTR(host_avail, S_IRUSR, show_host_avail, NULL);
2696
2697static struct attribute *otg_attrs[] = {
2698 &dev_attr_host_request.attr,
2699 &dev_attr_host_avail.attr,
2700 NULL,
2701};
2702
2703static struct attribute_group otg_attr_grp = {
2704 .name = "otg",
2705 .attrs = otg_attrs,
2706};
2707#endif
2708
2709static int msm72k_probe(struct platform_device *pdev)
2710{
2711 struct usb_info *ui;
2712 struct msm_otg *otg;
2713 int retval;
2714
2715 dev_dbg(&pdev->dev, "msm72k_probe\n");
2716 ui = kzalloc(sizeof(struct usb_info), GFP_KERNEL);
2717 if (!ui)
2718 return -ENOMEM;
2719
2720 ui->pdev = pdev;
2721 ui->pdata = pdev->dev.platform_data;
2722
2723 ui->buf = dma_alloc_coherent(&pdev->dev, 4096, &ui->dma, GFP_KERNEL);
2724 if (!ui->buf)
2725 return usb_free(ui, -ENOMEM);
2726
2727 ui->pool = dma_pool_create("msm72k_udc", NULL, 32, 32, 0);
2728 if (!ui->pool)
2729 return usb_free(ui, -ENOMEM);
2730
Steve Mucklef132c6c2012-06-06 18:30:57 -07002731 ui->xceiv = usb_get_transceiver();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002732 if (!ui->xceiv)
2733 return usb_free(ui, -ENODEV);
2734
2735 otg = to_msm_otg(ui->xceiv);
2736 ui->addr = otg->regs;
2737
2738 ui->gadget.ops = &msm72k_ops;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002739 ui->gadget.max_speed = USB_SPEED_HIGH;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002740 device_initialize(&ui->gadget.dev);
2741 dev_set_name(&ui->gadget.dev, "gadget");
2742 ui->gadget.dev.parent = &pdev->dev;
2743 ui->gadget.dev.dma_mask = pdev->dev.dma_mask;
2744
2745#ifdef CONFIG_USB_OTG
2746 ui->gadget.is_otg = 1;
2747#endif
2748
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002749 retval = usb_add_gadget_udc(&pdev->dev, &ui->gadget);
2750 if (retval)
2751 return usb_free(ui, retval);
2752
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002753 ui->sdev.name = DRIVER_NAME;
2754 ui->sdev.print_name = print_switch_name;
2755 ui->sdev.print_state = print_switch_state;
2756
2757 retval = switch_dev_register(&ui->sdev);
2758 if (retval)
2759 return usb_free(ui, retval);
2760
2761 the_usb_info = ui;
2762
2763 wake_lock_init(&ui->wlock,
2764 WAKE_LOCK_SUSPEND, "usb_bus_active");
2765
2766 usb_debugfs_init(ui);
2767
2768 usb_prepare(ui);
2769
2770#ifdef CONFIG_USB_OTG
2771 retval = sysfs_create_group(&pdev->dev.kobj, &otg_attr_grp);
2772 if (retval) {
2773 dev_err(&ui->pdev->dev,
2774 "failed to create otg sysfs directory:"
2775 "err:(%d)\n", retval);
2776 }
2777#endif
2778
Steve Mucklef132c6c2012-06-06 18:30:57 -07002779 retval = otg_set_peripheral(ui->xceiv->otg, &ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002780 if (retval) {
2781 dev_err(&ui->pdev->dev,
2782 "%s: Cannot bind the transceiver, retval:(%d)\n",
2783 __func__, retval);
2784 switch_dev_unregister(&ui->sdev);
2785 wake_lock_destroy(&ui->wlock);
2786 return usb_free(ui, retval);
2787 }
2788
2789 pm_runtime_enable(&pdev->dev);
2790
2791 /* Setup phy stuck timer */
2792 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
2793 setup_timer(&phy_status_timer, usb_phy_status_check_timer, 0);
2794 return 0;
2795}
2796
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002797static int msm72k_gadget_start(struct usb_gadget_driver *driver,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002798 int (*bind)(struct usb_gadget *))
2799{
2800 struct usb_info *ui = the_usb_info;
2801 int retval, n;
2802
2803 if (!driver
Steve Mucklef132c6c2012-06-06 18:30:57 -07002804 || driver->max_speed < USB_SPEED_FULL
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002805 || !bind
2806 || !driver->disconnect
2807 || !driver->setup)
2808 return -EINVAL;
2809 if (!ui)
2810 return -ENODEV;
2811 if (ui->driver)
2812 return -EBUSY;
2813
2814 /* first hook up the driver ... */
2815 ui->driver = driver;
2816 ui->gadget.dev.driver = &driver->driver;
2817 ui->gadget.name = driver_name;
2818 INIT_LIST_HEAD(&ui->gadget.ep_list);
2819 ui->gadget.ep0 = &ui->ep0in.ep;
2820 INIT_LIST_HEAD(&ui->gadget.ep0->ep_list);
2821 ui->gadget.speed = USB_SPEED_UNKNOWN;
2822 atomic_set(&ui->softconnect, 1);
2823
2824 for (n = 1; n < 16; n++) {
2825 struct msm_endpoint *ept = ui->ept + n;
2826 list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
2827 ept->ep.maxpacket = 512;
2828 }
2829 for (n = 17; n < 32; n++) {
2830 struct msm_endpoint *ept = ui->ept + n;
2831 list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
2832 ept->ep.maxpacket = 512;
2833 }
2834
2835 retval = device_add(&ui->gadget.dev);
2836 if (retval)
2837 goto fail;
2838
2839 retval = bind(&ui->gadget);
2840 if (retval) {
2841 dev_err(&ui->pdev->dev, "bind to driver %s --> error %d\n",
2842 driver->driver.name, retval);
2843 device_del(&ui->gadget.dev);
2844 goto fail;
2845 }
2846
2847 retval = device_create_file(&ui->gadget.dev, &dev_attr_wakeup);
2848 if (retval != 0)
2849 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2850 "(wakeup) error: (%d)\n", retval);
2851 retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_state);
2852 if (retval != 0)
2853 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2854 " (usb_state) error: (%d)\n", retval);
2855
2856 retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_speed);
2857 if (retval != 0)
2858 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2859 " (usb_speed) error: (%d)\n", retval);
2860
2861 retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_type);
2862 if (retval != 0)
2863 dev_err(&ui->pdev->dev,
2864 "failed to create sysfs entry(chg_type): err:(%d)\n",
2865 retval);
2866 retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_current);
2867 if (retval != 0)
2868 dev_err(&ui->pdev->dev,
2869 "failed to create sysfs entry(chg_current):"
2870 "err:(%d)\n", retval);
2871
2872 dev_dbg(&ui->pdev->dev, "registered gadget driver '%s'\n",
2873 driver->driver.name);
2874 usb_start(ui);
2875
2876 return 0;
2877
2878fail:
2879 ui->driver = NULL;
2880 ui->gadget.dev.driver = NULL;
2881 return retval;
2882}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002883
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002884static int msm72k_gadget_stop(struct usb_gadget_driver *driver)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002885{
2886 struct usb_info *dev = the_usb_info;
2887
2888 if (!dev)
2889 return -ENODEV;
2890 if (!driver || driver != dev->driver || !driver->unbind)
2891 return -EINVAL;
2892
2893 msm72k_pullup_internal(&dev->gadget, 0);
2894 if (dev->irq) {
2895 free_irq(dev->irq, dev);
2896 dev->irq = 0;
2897 }
2898 dev->state = USB_STATE_IDLE;
2899 atomic_set(&dev->configured, 0);
2900 switch_set_state(&dev->sdev, 0);
2901 /* cancel pending ep0 transactions */
2902 flush_endpoint(&dev->ep0out);
2903 flush_endpoint(&dev->ep0in);
2904
2905 device_remove_file(&dev->gadget.dev, &dev_attr_wakeup);
2906 device_remove_file(&dev->gadget.dev, &dev_attr_usb_state);
2907 device_remove_file(&dev->gadget.dev, &dev_attr_usb_speed);
2908 device_remove_file(&dev->gadget.dev, &dev_attr_chg_type);
2909 device_remove_file(&dev->gadget.dev, &dev_attr_chg_current);
2910 driver->disconnect(&dev->gadget);
2911 driver->unbind(&dev->gadget);
2912 dev->gadget.dev.driver = NULL;
2913 dev->driver = NULL;
2914
2915 device_del(&dev->gadget.dev);
2916
2917 dev_dbg(&dev->pdev->dev,
2918 "unregistered gadget driver '%s'\n", driver->driver.name);
2919 return 0;
2920}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002921
2922
2923static int msm72k_udc_runtime_suspend(struct device *dev)
2924{
2925 dev_dbg(dev, "pm_runtime: suspending...\n");
2926 return 0;
2927}
2928
2929static int msm72k_udc_runtime_resume(struct device *dev)
2930{
2931 dev_dbg(dev, "pm_runtime: resuming...\n");
2932 return 0;
2933}
2934
2935static int msm72k_udc_runtime_idle(struct device *dev)
2936{
2937 dev_dbg(dev, "pm_runtime: idling...\n");
2938 return 0;
2939}
2940
2941static struct dev_pm_ops msm72k_udc_dev_pm_ops = {
2942 .runtime_suspend = msm72k_udc_runtime_suspend,
2943 .runtime_resume = msm72k_udc_runtime_resume,
2944 .runtime_idle = msm72k_udc_runtime_idle
2945};
2946
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002947static int __exit msm72k_remove(struct platform_device *pdev)
2948{
2949 struct usb_info *ui = container_of(&pdev, struct usb_info, pdev);
2950
2951 return usb_free(ui, 0);
2952}
2953
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002954static struct platform_driver usb_driver = {
2955 .probe = msm72k_probe,
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002956 .remove = msm72k_remove,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002957 .driver = { .name = "msm_hsusb",
2958 .pm = &msm72k_udc_dev_pm_ops, },
2959};
2960
2961static int __init init(void)
2962{
2963 return platform_driver_register(&usb_driver);
2964}
2965module_init(init);
2966
2967static void __exit cleanup(void)
2968{
2969 platform_driver_unregister(&usb_driver);
2970}
2971module_exit(cleanup);
2972
2973MODULE_DESCRIPTION(DRIVER_DESC);
2974MODULE_AUTHOR("Mike Lockwood, Brian Swetland");
2975MODULE_LICENSE("GPL");