blob: e35a60ef1b2602475b4535cef583244257045b82 [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;
Rajkumar Raghupathy4b06ee92013-01-17 15:10:36 +05301309 struct msm_otg *dev = to_msm_otg(ui->xceiv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001310 unsigned n;
1311 unsigned long flags;
1312
Rajkumar Raghupathy4b06ee92013-01-17 15:10:36 +05301313 if (atomic_read(&dev->in_lpm))
1314 return IRQ_NONE;
1315
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001316 n = readl(USB_USBSTS);
1317 writel(n, USB_USBSTS);
1318
1319 /* somehow we got an IRQ while in the reset sequence: ignore it */
1320 if (!atomic_read(&ui->running))
1321 return IRQ_HANDLED;
1322
1323 if (n & STS_PCI) {
1324 msm_hsusb_set_speed(ui);
1325 if (atomic_read(&ui->configured)) {
1326 wake_lock(&ui->wlock);
1327
1328 spin_lock_irqsave(&ui->lock, flags);
1329 ui->usb_state = USB_STATE_CONFIGURED;
1330 ui->flags = USB_FLAG_CONFIGURED;
1331 spin_unlock_irqrestore(&ui->lock, flags);
1332
1333 ui->driver->resume(&ui->gadget);
1334 schedule_work(&ui->work);
1335 } else {
1336 msm_hsusb_set_state(USB_STATE_DEFAULT);
1337 }
1338
1339#ifdef CONFIG_USB_OTG
1340 /* notify otg to clear A_BIDL_ADIS timer */
1341 if (ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001342 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001343#endif
1344 }
1345
1346 if (n & STS_URI) {
1347 dev_dbg(&ui->pdev->dev, "reset\n");
1348 spin_lock_irqsave(&ui->lock, flags);
1349 ui->gadget.speed = USB_SPEED_UNKNOWN;
1350 spin_unlock_irqrestore(&ui->lock, flags);
1351#ifdef CONFIG_USB_OTG
1352 /* notify otg to clear A_BIDL_ADIS timer */
1353 if (ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001354 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001355 spin_lock_irqsave(&ui->lock, flags);
1356 /* Host request is persistent across reset */
1357 ui->gadget.b_hnp_enable = 0;
1358 ui->hnp_avail = 0;
1359 spin_unlock_irqrestore(&ui->lock, flags);
1360#endif
1361 msm_hsusb_set_state(USB_STATE_DEFAULT);
1362 atomic_set(&ui->remote_wakeup, 0);
1363 if (!ui->gadget.is_a_peripheral)
1364 schedule_delayed_work(&ui->chg_stop, 0);
1365
1366 writel(readl(USB_ENDPTSETUPSTAT), USB_ENDPTSETUPSTAT);
1367 writel(readl(USB_ENDPTCOMPLETE), USB_ENDPTCOMPLETE);
1368 writel(0xffffffff, USB_ENDPTFLUSH);
1369 writel(0, USB_ENDPTCTRL(1));
1370
1371 wake_lock(&ui->wlock);
1372 if (atomic_read(&ui->configured)) {
1373 /* marking us offline will cause ept queue attempts
1374 ** to fail
1375 */
1376 atomic_set(&ui->configured, 0);
1377 /* Defer sending offline uevent to userspace */
1378 atomic_set(&ui->offline_pending, 1);
1379
1380 /* XXX: we can't seem to detect going offline,
1381 * XXX: so deconfigure on reset for the time being
1382 */
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05301383 dev_dbg(&ui->pdev->dev,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001384 "usb: notify offline\n");
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05301385 ui->driver->disconnect(&ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001386 /* cancel pending ep0 transactions */
1387 flush_endpoint(&ui->ep0out);
1388 flush_endpoint(&ui->ep0in);
1389
1390 }
1391 /* Start phy stuck timer */
1392 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
1393 mod_timer(&phy_status_timer, PHY_STATUS_CHECK_DELAY);
1394 }
1395
1396 if (n & STS_SLI) {
1397 dev_dbg(&ui->pdev->dev, "suspend\n");
1398
1399 spin_lock_irqsave(&ui->lock, flags);
1400 ui->usb_state = USB_STATE_SUSPENDED;
1401 ui->flags = USB_FLAG_SUSPEND;
1402 spin_unlock_irqrestore(&ui->lock, flags);
1403
1404 ui->driver->suspend(&ui->gadget);
1405 schedule_work(&ui->work);
1406#ifdef CONFIG_USB_OTG
1407 /* notify otg for
1408 * 1. kicking A_BIDL_ADIS timer in case of A-peripheral
1409 * 2. disabling pull-up and kicking B_ASE0_RST timer
1410 */
1411 if (ui->gadget.b_hnp_enable || ui->gadget.is_a_peripheral)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001412 usb_phy_set_suspend(ui->xceiv, 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001413#endif
1414 }
1415
1416 if (n & STS_UI) {
1417 n = readl(USB_ENDPTSETUPSTAT);
1418 if (n & EPT_RX(0))
1419 handle_setup(ui);
1420
1421 n = readl(USB_ENDPTCOMPLETE);
1422 writel(n, USB_ENDPTCOMPLETE);
1423 while (n) {
1424 unsigned bit = __ffs(n);
1425 handle_endpoint(ui, bit);
1426 n = n & (~(1 << bit));
1427 }
1428 }
1429 return IRQ_HANDLED;
1430}
1431
1432static void usb_prepare(struct usb_info *ui)
1433{
1434 spin_lock_init(&ui->lock);
1435
1436 memset(ui->buf, 0, 4096);
1437 ui->head = (void *) (ui->buf + 0);
1438
1439 /* only important for reset/reinit */
1440 memset(ui->ept, 0, sizeof(ui->ept));
1441 ui->next_item = 0;
1442 ui->next_ifc_num = 0;
1443
1444 init_endpoints(ui);
1445
1446 ui->ep0in.ep.maxpacket = 64;
1447 ui->ep0out.ep.maxpacket = 64;
1448
1449 ui->setup_req =
1450 usb_ept_alloc_req(&ui->ep0in, SETUP_BUF_SIZE, GFP_KERNEL);
1451
1452 INIT_WORK(&ui->work, usb_do_work);
1453 INIT_DELAYED_WORK(&ui->chg_det, usb_chg_detect);
1454 INIT_DELAYED_WORK(&ui->chg_stop, usb_chg_stop);
1455 INIT_DELAYED_WORK(&ui->rw_work, usb_do_remote_wakeup);
1456 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
1457 INIT_WORK(&ui->phy_status_check, usb_phy_stuck_recover);
1458}
1459
1460static void usb_reset(struct usb_info *ui)
1461{
1462 struct msm_otg *otg = to_msm_otg(ui->xceiv);
1463
1464 dev_dbg(&ui->pdev->dev, "reset controller\n");
1465
1466 atomic_set(&ui->running, 0);
1467
1468 /*
1469 * PHY reset takes minimum 100 msec. Hence reset only link
1470 * during HNP. Reset PHY and link in B-peripheral mode.
1471 */
1472 if (ui->gadget.is_a_peripheral)
1473 otg->reset(ui->xceiv, 0);
1474 else
1475 otg->reset(ui->xceiv, 1);
1476
1477 /* set usb controller interrupt threshold to zero*/
1478 writel((readl(USB_USBCMD) & ~USBCMD_ITC_MASK) | USBCMD_ITC(0),
1479 USB_USBCMD);
1480
1481 writel(ui->dma, USB_ENDPOINTLISTADDR);
1482
1483 configure_endpoints(ui);
1484
1485 /* marking us offline will cause ept queue attempts to fail */
1486 atomic_set(&ui->configured, 0);
1487
1488 if (ui->driver) {
1489 dev_dbg(&ui->pdev->dev, "usb: notify offline\n");
1490 ui->driver->disconnect(&ui->gadget);
1491 }
1492
1493 /* cancel pending ep0 transactions */
1494 flush_endpoint(&ui->ep0out);
1495 flush_endpoint(&ui->ep0in);
1496
1497 /* enable interrupts */
1498 writel(STS_URI | STS_SLI | STS_UI | STS_PCI, USB_USBINTR);
1499
1500 /* Ensure that h/w RESET is completed before returning */
1501 mb();
1502
1503 atomic_set(&ui->running, 1);
1504}
1505
1506static void usb_start(struct usb_info *ui)
1507{
1508 unsigned long flags;
1509
1510 spin_lock_irqsave(&ui->lock, flags);
1511 ui->flags |= USB_FLAG_START;
1512 schedule_work(&ui->work);
1513 spin_unlock_irqrestore(&ui->lock, flags);
1514}
1515
1516static int usb_free(struct usb_info *ui, int ret)
1517{
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03001518 if (ret)
1519 dev_dbg(&ui->pdev->dev, "usb_free(%d)\n", ret);
1520
1521 usb_del_gadget_udc(&ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001522
1523 if (ui->xceiv)
Steve Mucklef132c6c2012-06-06 18:30:57 -07001524 usb_put_transceiver(ui->xceiv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001525
1526 if (ui->irq)
1527 free_irq(ui->irq, 0);
1528 if (ui->pool)
1529 dma_pool_destroy(ui->pool);
1530 if (ui->dma)
1531 dma_free_coherent(&ui->pdev->dev, 4096, ui->buf, ui->dma);
1532 kfree(ui);
1533 return ret;
1534}
1535
1536static void usb_do_work_check_vbus(struct usb_info *ui)
1537{
1538 unsigned long iflags;
1539
1540 spin_lock_irqsave(&ui->lock, iflags);
1541 if (is_usb_online(ui))
1542 ui->flags |= USB_FLAG_VBUS_ONLINE;
1543 else
1544 ui->flags |= USB_FLAG_VBUS_OFFLINE;
1545 spin_unlock_irqrestore(&ui->lock, iflags);
1546}
1547
1548static void usb_do_work(struct work_struct *w)
1549{
1550 struct usb_info *ui = container_of(w, struct usb_info, work);
1551 struct msm_otg *otg = to_msm_otg(ui->xceiv);
1552 unsigned long iflags;
1553 unsigned flags, _vbus;
1554
1555 for (;;) {
1556 spin_lock_irqsave(&ui->lock, iflags);
1557 flags = ui->flags;
1558 ui->flags = 0;
1559 _vbus = is_usb_online(ui);
1560 spin_unlock_irqrestore(&ui->lock, iflags);
1561
1562 /* give up if we have nothing to do */
1563 if (flags == 0)
1564 break;
1565
1566 switch (ui->state) {
1567 case USB_STATE_IDLE:
1568 if (flags & USB_FLAG_START) {
1569 int ret;
1570
1571 if (!_vbus) {
1572 ui->state = USB_STATE_OFFLINE;
1573 break;
1574 }
1575
1576 pm_runtime_get_noresume(&ui->pdev->dev);
1577 pm_runtime_resume(&ui->pdev->dev);
1578 dev_dbg(&ui->pdev->dev,
1579 "msm72k_udc: IDLE -> ONLINE\n");
1580 usb_reset(ui);
1581 ret = request_irq(otg->irq, usb_interrupt,
1582 IRQF_SHARED,
1583 ui->pdev->name, ui);
1584 /* FIXME: should we call BUG_ON when
1585 * requst irq fails
1586 */
1587 if (ret) {
1588 dev_err(&ui->pdev->dev,
1589 "hsusb: peripheral: request irq"
1590 " failed:(%d)", ret);
1591 break;
1592 }
1593 ui->irq = otg->irq;
1594 ui->state = USB_STATE_ONLINE;
1595 usb_do_work_check_vbus(ui);
1596
1597 if (!atomic_read(&ui->softconnect))
1598 break;
1599
1600 msm72k_pullup_internal(&ui->gadget, 1);
1601
1602 if (!ui->gadget.is_a_peripheral)
1603 schedule_delayed_work(
1604 &ui->chg_det,
1605 USB_CHG_DET_DELAY);
1606
1607 }
1608 break;
1609 case USB_STATE_ONLINE:
1610 if (atomic_read(&ui->offline_pending)) {
1611 switch_set_state(&ui->sdev, 0);
1612 atomic_set(&ui->offline_pending, 0);
1613 }
1614
1615 /* If at any point when we were online, we received
1616 * the signal to go offline, we must honor it
1617 */
1618 if (flags & USB_FLAG_VBUS_OFFLINE) {
1619
1620 ui->chg_current = 0;
1621 /* wait incase chg_detect is running */
1622 if (!ui->gadget.is_a_peripheral)
1623 cancel_delayed_work_sync(&ui->chg_det);
1624
1625 dev_dbg(&ui->pdev->dev,
1626 "msm72k_udc: ONLINE -> OFFLINE\n");
1627
1628 atomic_set(&ui->running, 0);
1629 atomic_set(&ui->remote_wakeup, 0);
1630 atomic_set(&ui->configured, 0);
1631
1632 if (ui->driver) {
1633 dev_dbg(&ui->pdev->dev,
1634 "usb: notify offline\n");
1635 ui->driver->disconnect(&ui->gadget);
1636 }
1637 /* cancel pending ep0 transactions */
1638 flush_endpoint(&ui->ep0out);
1639 flush_endpoint(&ui->ep0in);
1640
1641 /* synchronize with irq context */
1642 spin_lock_irqsave(&ui->lock, iflags);
1643#ifdef CONFIG_USB_OTG
1644 ui->gadget.host_request = 0;
1645 ui->gadget.b_hnp_enable = 0;
1646 ui->hnp_avail = 0;
1647#endif
1648 msm72k_pullup_internal(&ui->gadget, 0);
1649 spin_unlock_irqrestore(&ui->lock, iflags);
1650
1651
1652 /* if charger is initialized to known type
1653 * we must let modem know about charger
1654 * disconnection
1655 */
Steve Mucklef132c6c2012-06-06 18:30:57 -07001656 usb_phy_set_power(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001657
1658 if (ui->irq) {
Chiranjeevi Velempati2a9c1cb2012-12-21 18:26:23 +05301659 /* Disable and acknowledge all
1660 * USB interrupts before freeing
1661 * irq, so that no USB spurious
1662 * interrupt occurs during USB cable
1663 * disconnect which may lead to
1664 * IRQ nobody cared error.
1665 */
1666 writel_relaxed(0, USB_USBINTR);
1667 writel_relaxed(readl_relaxed(USB_USBSTS)
1668 , USB_USBSTS);
1669 /* Ensure that above STOREs are
1670 * completed before enabling
1671 * interrupts */
1672 wmb();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001673 free_irq(ui->irq, ui);
1674 ui->irq = 0;
1675 }
1676
1677
1678 switch_set_state(&ui->sdev, 0);
1679
1680 ui->state = USB_STATE_OFFLINE;
1681 usb_do_work_check_vbus(ui);
1682 pm_runtime_put_noidle(&ui->pdev->dev);
1683 pm_runtime_suspend(&ui->pdev->dev);
1684 wake_unlock(&ui->wlock);
1685 break;
1686 }
1687 if (flags & USB_FLAG_SUSPEND) {
1688 int maxpower = usb_get_max_power(ui);
1689
1690 if (maxpower < 0)
1691 break;
1692
Steve Mucklef132c6c2012-06-06 18:30:57 -07001693 usb_phy_set_power(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001694 /* To support TCXO during bus suspend
1695 * This might be dummy check since bus suspend
1696 * is not implemented as of now
1697 * */
1698 if (release_wlocks)
1699 wake_unlock(&ui->wlock);
1700
1701 /* TBD: Initiate LPM at usb bus suspend */
1702 break;
1703 }
1704 if (flags & USB_FLAG_CONFIGURED) {
1705 int maxpower = usb_get_max_power(ui);
1706
1707 /* We may come here even when no configuration
1708 * is selected. Send online/offline event
1709 * accordingly.
1710 */
1711 switch_set_state(&ui->sdev,
1712 atomic_read(&ui->configured));
1713
1714 if (maxpower < 0)
1715 break;
1716
1717 ui->chg_current = maxpower;
Steve Mucklef132c6c2012-06-06 18:30:57 -07001718 usb_phy_set_power(ui->xceiv, maxpower);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001719 break;
1720 }
1721 if (flags & USB_FLAG_RESET) {
1722 dev_dbg(&ui->pdev->dev,
1723 "msm72k_udc: ONLINE -> RESET\n");
1724 msm72k_pullup_internal(&ui->gadget, 0);
1725 usb_reset(ui);
1726 msm72k_pullup_internal(&ui->gadget, 1);
1727 dev_dbg(&ui->pdev->dev,
1728 "msm72k_udc: RESET -> ONLINE\n");
1729 break;
1730 }
1731 break;
1732 case USB_STATE_OFFLINE:
1733 /* If we were signaled to go online and vbus is still
1734 * present when we received the signal, go online.
1735 */
1736 if ((flags & USB_FLAG_VBUS_ONLINE) && _vbus) {
1737 int ret;
1738
1739 pm_runtime_get_noresume(&ui->pdev->dev);
1740 pm_runtime_resume(&ui->pdev->dev);
1741 dev_dbg(&ui->pdev->dev,
1742 "msm72k_udc: OFFLINE -> ONLINE\n");
1743
1744 usb_reset(ui);
1745 ui->state = USB_STATE_ONLINE;
1746 usb_do_work_check_vbus(ui);
1747 ret = request_irq(otg->irq, usb_interrupt,
1748 IRQF_SHARED,
1749 ui->pdev->name, ui);
1750 /* FIXME: should we call BUG_ON when
1751 * requst irq fails
1752 */
1753 if (ret) {
1754 dev_err(&ui->pdev->dev,
1755 "hsusb: peripheral: request irq"
1756 " failed:(%d)", ret);
1757 break;
1758 }
1759 ui->irq = otg->irq;
1760 enable_irq_wake(otg->irq);
1761
1762 if (!atomic_read(&ui->softconnect))
1763 break;
1764 msm72k_pullup_internal(&ui->gadget, 1);
1765
1766 if (!ui->gadget.is_a_peripheral)
1767 schedule_delayed_work(
1768 &ui->chg_det,
1769 USB_CHG_DET_DELAY);
1770 }
1771 break;
1772 }
1773 }
1774}
1775
1776/* FIXME - the callers of this function should use a gadget API instead.
1777 * This is called from htc_battery.c and board-halibut.c
1778 * WARNING - this can get called before this driver is initialized.
1779 */
1780void msm_hsusb_set_vbus_state(int online)
1781{
1782 unsigned long flags;
1783 struct usb_info *ui = the_usb_info;
1784
1785 if (!ui) {
1786 pr_err("%s called before driver initialized\n", __func__);
1787 return;
1788 }
1789
1790 spin_lock_irqsave(&ui->lock, flags);
1791
1792 if (is_usb_online(ui) == online)
1793 goto out;
1794
1795 if (online) {
1796 ui->usb_state = USB_STATE_POWERED;
1797 ui->flags |= USB_FLAG_VBUS_ONLINE;
1798 } else {
1799 ui->gadget.speed = USB_SPEED_UNKNOWN;
1800 ui->usb_state = USB_STATE_NOTATTACHED;
1801 ui->flags |= USB_FLAG_VBUS_OFFLINE;
Chiranjeevi Velempati18dda792012-07-16 17:02:32 +05301802 ui->chg_type_retry_cnt = 0;
1803 ui->proprietary_chg = false;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001804 }
1805 if (in_interrupt()) {
1806 schedule_work(&ui->work);
1807 } else {
1808 spin_unlock_irqrestore(&ui->lock, flags);
1809 usb_do_work(&ui->work);
1810 return;
1811 }
1812out:
1813 spin_unlock_irqrestore(&ui->lock, flags);
1814}
1815
1816#if defined(CONFIG_DEBUG_FS)
1817
1818void usb_function_reenumerate(void)
1819{
1820 struct usb_info *ui = the_usb_info;
1821
1822 /* disable and re-enable the D+ pullup */
1823 dev_dbg(&ui->pdev->dev, "disable pullup\n");
1824 writel(readl(USB_USBCMD) & ~USBCMD_RS, USB_USBCMD);
1825
1826 msleep(10);
1827
1828 dev_dbg(&ui->pdev->dev, "enable pullup\n");
1829 writel(readl(USB_USBCMD) | USBCMD_RS, USB_USBCMD);
1830}
1831
1832static char debug_buffer[PAGE_SIZE];
1833
1834static ssize_t debug_read_status(struct file *file, char __user *ubuf,
1835 size_t count, loff_t *ppos)
1836{
1837 struct usb_info *ui = file->private_data;
1838 char *buf = debug_buffer;
1839 unsigned long flags;
1840 struct msm_endpoint *ept;
1841 struct msm_request *req;
1842 int n;
1843 int i = 0;
1844
1845 spin_lock_irqsave(&ui->lock, flags);
1846
1847 i += scnprintf(buf + i, PAGE_SIZE - i,
1848 "regs: setup=%08x prime=%08x stat=%08x done=%08x\n",
1849 readl(USB_ENDPTSETUPSTAT),
1850 readl(USB_ENDPTPRIME),
1851 readl(USB_ENDPTSTAT),
1852 readl(USB_ENDPTCOMPLETE));
1853 i += scnprintf(buf + i, PAGE_SIZE - i,
1854 "regs: cmd=%08x sts=%08x intr=%08x port=%08x\n\n",
1855 readl(USB_USBCMD),
1856 readl(USB_USBSTS),
1857 readl(USB_USBINTR),
1858 readl(USB_PORTSC));
1859
1860
1861 for (n = 0; n < 32; n++) {
1862 ept = ui->ept + n;
1863 if (ept->ep.maxpacket == 0)
1864 continue;
1865
1866 i += scnprintf(buf + i, PAGE_SIZE - i,
1867 "ept%d %s cfg=%08x active=%08x next=%08x info=%08x\n",
1868 ept->num, (ept->flags & EPT_FLAG_IN) ? "in " : "out",
1869 ept->head->config, ept->head->active,
1870 ept->head->next, ept->head->info);
1871
1872 for (req = ept->req; req; req = req->next)
1873 i += scnprintf(buf + i, PAGE_SIZE - i,
1874 " req @%08x next=%08x info=%08x page0=%08x %c %c\n",
1875 req->item_dma, req->item->next,
1876 req->item->info, req->item->page0,
1877 req->busy ? 'B' : ' ',
1878 req->live ? 'L' : ' ');
1879 }
1880
1881 i += scnprintf(buf + i, PAGE_SIZE - i,
1882 "phy failure count: %d\n", ui->phy_fail_count);
1883
1884 spin_unlock_irqrestore(&ui->lock, flags);
1885
1886 return simple_read_from_buffer(ubuf, count, ppos, buf, i);
1887}
1888
1889static ssize_t debug_write_reset(struct file *file, const char __user *buf,
1890 size_t count, loff_t *ppos)
1891{
1892 struct usb_info *ui = file->private_data;
1893 unsigned long flags;
1894
1895 spin_lock_irqsave(&ui->lock, flags);
1896 ui->flags |= USB_FLAG_RESET;
1897 schedule_work(&ui->work);
1898 spin_unlock_irqrestore(&ui->lock, flags);
1899
1900 return count;
1901}
1902
1903static ssize_t debug_write_cycle(struct file *file, const char __user *buf,
1904 size_t count, loff_t *ppos)
1905{
1906 usb_function_reenumerate();
1907 return count;
1908}
1909
1910static int debug_open(struct inode *inode, struct file *file)
1911{
1912 file->private_data = inode->i_private;
1913 return 0;
1914}
1915
1916const struct file_operations debug_stat_ops = {
1917 .open = debug_open,
1918 .read = debug_read_status,
1919};
1920
1921const struct file_operations debug_reset_ops = {
1922 .open = debug_open,
1923 .write = debug_write_reset,
1924};
1925
1926const struct file_operations debug_cycle_ops = {
1927 .open = debug_open,
1928 .write = debug_write_cycle,
1929};
1930
1931static ssize_t debug_read_release_wlocks(struct file *file, char __user *ubuf,
1932 size_t count, loff_t *ppos)
1933{
1934 char kbuf[10];
1935 size_t c = 0;
1936
1937 memset(kbuf, 0, 10);
1938
1939 c = scnprintf(kbuf, 10, "%d", release_wlocks);
1940
1941 if (copy_to_user(ubuf, kbuf, c))
1942 return -EFAULT;
1943
1944 return c;
1945}
1946static ssize_t debug_write_release_wlocks(struct file *file,
1947 const char __user *buf, size_t count, loff_t *ppos)
1948{
1949 char kbuf[10];
1950 long temp;
1951
1952 memset(kbuf, 0, 10);
1953
1954 if (copy_from_user(kbuf, buf, count > 10 ? 10 : count))
1955 return -EFAULT;
1956
1957 if (strict_strtol(kbuf, 10, &temp))
1958 return -EINVAL;
1959
1960 if (temp)
1961 release_wlocks = 1;
1962 else
1963 release_wlocks = 0;
1964
1965 return count;
1966}
1967static int debug_wake_lock_open(struct inode *inode, struct file *file)
1968{
1969 file->private_data = inode->i_private;
1970 return 0;
1971}
1972const struct file_operations debug_wlocks_ops = {
1973 .open = debug_wake_lock_open,
1974 .read = debug_read_release_wlocks,
1975 .write = debug_write_release_wlocks,
1976};
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05301977
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05301978static ssize_t debug_reprime_ep(struct file *file, const char __user *ubuf,
1979 size_t count, loff_t *ppos)
1980{
1981 struct usb_info *ui = file->private_data;
1982 struct msm_endpoint *ept;
1983 char kbuf[10];
1984 unsigned int ep_num, dir;
1985 unsigned long flags;
1986 unsigned n, i;
1987
1988 memset(kbuf, 0, 10);
1989
1990 if (copy_from_user(kbuf, ubuf, count > 10 ? 10 : count))
1991 return -EFAULT;
1992
1993 if (sscanf(kbuf, "%u %u", &ep_num, &dir) != 2)
1994 return -EINVAL;
1995
1996 if (dir)
1997 i = ep_num + 16;
1998 else
1999 i = ep_num;
2000
2001 spin_lock_irqsave(&ui->lock, flags);
2002 ept = ui->ept + i;
2003 n = 1 << ept->bit;
2004
2005 if ((readl_relaxed(USB_ENDPTPRIME) & n))
2006 goto out;
2007
2008 if (readl_relaxed(USB_ENDPTSTAT) & n)
2009 goto out;
2010
2011 /* clear speculative loads on item->info */
2012 rmb();
2013 if (ept->req && (ept->req->item->info & INFO_ACTIVE)) {
2014 pr_err("%s(): ept%d%s prime failed. ept: config: %x"
2015 "active: %x next: %x info: %x\n",
2016 __func__, ept->num,
2017 ept->flags & EPT_FLAG_IN ? "in" : "out",
2018 ept->head->config, ept->head->active,
2019 ept->head->next, ept->head->info);
2020 writel_relaxed(n, USB_ENDPTPRIME);
2021 }
2022out:
2023 spin_unlock_irqrestore(&ui->lock, flags);
2024
2025 return count;
2026}
2027
2028static char buffer[512];
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302029static ssize_t debug_prime_fail_read(struct file *file, char __user *ubuf,
2030 size_t count, loff_t *ppos)
2031{
2032 struct usb_info *ui = file->private_data;
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302033 char *buf = buffer;
2034 unsigned long flags;
2035 struct msm_endpoint *ept;
2036 int n;
2037 int i = 0;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302038
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302039 spin_lock_irqsave(&ui->lock, flags);
2040 for (n = 0; n < 32; n++) {
2041 ept = ui->ept + n;
2042 if (ept->ep.maxpacket == 0)
2043 continue;
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302044
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302045 i += scnprintf(buf + i, PAGE_SIZE - i,
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302046 "ept%d %s false_prime_count=%lu prime_fail_count=%d "
2047 "dtd_fail_count=%lu "
2048 "dTD_workaround_fail_count=%lu\n",
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302049 ept->num, (ept->flags & EPT_FLAG_IN) ? "in " : "out",
2050 ept->false_prime_fail_count,
2051 ept->actual_prime_fail_count,
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302052 ept->dTD_update_fail_count,
2053 ept->dTD_workaround_fail_count);
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302054 }
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302055
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302056 i += scnprintf(buf + i, PAGE_SIZE - i,
2057 "dTD_update_fail count: %lu\n",
2058 ui->dTD_update_fail_count);
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302059
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302060 i += scnprintf(buf + i, PAGE_SIZE - i,
2061 "prime_fail count: %d\n", ui->prime_fail_count);
2062
Rajkumar Raghupathyf17772e2012-06-19 11:27:12 +05302063 i += scnprintf(buf + i, PAGE_SIZE - i,
2064 "dtd_workaround_fail count: %lu\n",
2065 ui->dTD_workaround_fail_count);
2066
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302067 spin_unlock_irqrestore(&ui->lock, flags);
2068
2069 return simple_read_from_buffer(ubuf, count, ppos, buf, i);
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302070}
2071
2072static int debug_prime_fail_open(struct inode *inode, struct file *file)
2073{
2074 file->private_data = inode->i_private;
2075 return 0;
2076}
2077
2078const struct file_operations prime_fail_ops = {
2079 .open = debug_prime_fail_open,
2080 .read = debug_prime_fail_read,
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302081 .write = debug_reprime_ep,
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302082};
2083
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +05302084static ssize_t debug_prop_chg_write(struct file *file,
2085 const char __user *buf, size_t count, loff_t *ppos)
2086{
2087 struct usb_info *ui = file->private_data;
2088 char kbuf[2];
2089
2090 memset(kbuf, 0, sizeof(kbuf));
2091
2092 if (copy_from_user(kbuf, buf, sizeof(kbuf)))
2093 return -EFAULT;
2094
2095 if (!strncmp(kbuf, "1", 1))
2096 ui->pdata->prop_chg = 1;
2097 else
2098 ui->pdata->prop_chg = 0;
2099
2100 return count;
2101}
2102
2103static ssize_t debug_prop_chg_read(struct file *file, char __user *ubuf,
2104 size_t count, loff_t *ppos)
2105{
2106 struct usb_info *ui = file->private_data;
2107 char kbuf[2];
2108 size_t c = 0;
2109
2110 memset(kbuf, 0, sizeof(kbuf));
2111
2112 c = scnprintf(kbuf, sizeof(kbuf), "%d\n", ui->pdata->prop_chg);
2113
2114 if (copy_to_user(ubuf, kbuf, c))
2115 return -EFAULT;
2116
2117 return simple_read_from_buffer(ubuf, count, ppos, kbuf, c);
2118}
2119
2120static int debug_prop_chg_open(struct inode *inode, struct file *file)
2121{
2122 file->private_data = inode->i_private;
2123 return 0;
2124}
2125
2126const struct file_operations debug_prop_chg_ops = {
2127 .open = debug_prop_chg_open,
2128 .read = debug_prop_chg_read,
2129 .write = debug_prop_chg_write,
2130};
2131
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002132static void usb_debugfs_init(struct usb_info *ui)
2133{
2134 struct dentry *dent;
2135 dent = debugfs_create_dir(dev_name(&ui->pdev->dev), 0);
2136 if (IS_ERR(dent))
2137 return;
2138
2139 debugfs_create_file("status", 0444, dent, ui, &debug_stat_ops);
2140 debugfs_create_file("reset", 0222, dent, ui, &debug_reset_ops);
2141 debugfs_create_file("cycle", 0222, dent, ui, &debug_cycle_ops);
2142 debugfs_create_file("release_wlocks", 0666, dent, ui,
2143 &debug_wlocks_ops);
Vijayavardhan Vennapusa23ee2892011-12-12 15:53:07 +05302144 debugfs_create_file("prime_fail_countt", 0666, dent, ui,
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302145 &prime_fail_ops);
Rajkumar Raghupathyc0e14a42012-09-17 16:35:47 +05302146 debugfs_create_file("proprietary_chg", 0666, dent, ui,
2147 &debug_prop_chg_ops);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002148}
2149#else
2150static void usb_debugfs_init(struct usb_info *ui) {}
2151#endif
2152
2153static int
2154msm72k_enable(struct usb_ep *_ep, const struct usb_endpoint_descriptor *desc)
2155{
Rajkumar Raghupathye3a95f72012-05-29 20:05:47 +05302156 struct msm_endpoint *ept;
2157 unsigned char ep_type;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002158
Rajkumar Raghupathye3a95f72012-05-29 20:05:47 +05302159 if (_ep == NULL || desc == NULL)
2160 return -EINVAL;
2161
2162 ept = to_msm_endpoint(_ep);
2163 ep_type = desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002164 _ep->maxpacket = le16_to_cpu(desc->wMaxPacketSize);
2165 config_ept(ept);
2166 ept->wedged = 0;
2167 usb_ept_enable(ept, 1, ep_type);
2168 return 0;
2169}
2170
2171static int msm72k_disable(struct usb_ep *_ep)
2172{
2173 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2174
2175 usb_ept_enable(ept, 0, 0);
2176 flush_endpoint(ept);
Pavankumar Kondeti2c968782012-04-12 15:16:39 +05302177 /*
2178 * Clear descriptors here. Otherwise previous descriptors
2179 * will be used by function drivers upon next enumeration.
2180 */
2181 _ep->desc = NULL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002182 return 0;
2183}
2184
2185static struct usb_request *
2186msm72k_alloc_request(struct usb_ep *_ep, gfp_t gfp_flags)
2187{
2188 return usb_ept_alloc_req(to_msm_endpoint(_ep), 0, gfp_flags);
2189}
2190
2191static void
2192msm72k_free_request(struct usb_ep *_ep, struct usb_request *_req)
2193{
2194 struct msm_request *req = to_msm_request(_req);
2195 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2196 struct usb_info *ui = ept->ui;
2197
2198 /* request should not be busy */
2199 BUG_ON(req->busy);
2200 if (req->alloced)
2201 kfree(req->req.buf);
2202 dma_pool_free(ui->pool, req->item, req->item_dma);
2203 kfree(req);
2204}
2205
2206static int
2207msm72k_queue(struct usb_ep *_ep, struct usb_request *req, gfp_t gfp_flags)
2208{
2209 struct msm_endpoint *ep = to_msm_endpoint(_ep);
2210 struct usb_info *ui = ep->ui;
2211
Rajkumar Raghupathy7233a152013-01-24 16:59:51 +05302212 if (!atomic_read(&ui->softconnect))
2213 return -ENODEV;
2214
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002215 if (ep == &ui->ep0in) {
2216 struct msm_request *r = to_msm_request(req);
2217 if (!req->length)
2218 goto ep_queue_done;
2219 r->gadget_complete = req->complete;
2220 /* ep0_queue_ack_complete queue a receive for ACK before
2221 ** calling req->complete
2222 */
2223 req->complete = ep0_queue_ack_complete;
2224 if (atomic_read(&ui->ep0_dir) == USB_DIR_OUT)
2225 ep = &ui->ep0out;
2226 goto ep_queue_done;
2227 }
2228
2229ep_queue_done:
2230 return usb_ept_queue_xfer(ep, req);
2231}
2232
2233static int msm72k_dequeue(struct usb_ep *_ep, struct usb_request *_req)
2234{
2235 struct msm_endpoint *ep = to_msm_endpoint(_ep);
2236 struct msm_request *req = to_msm_request(_req);
2237 struct usb_info *ui = ep->ui;
2238
2239 struct msm_request *temp_req;
2240 unsigned long flags;
2241
Rajkumar Raghupathy7233a152013-01-24 16:59:51 +05302242 if (ep->num == 0) {
2243 /* Flush both out and in control endpoints */
2244 flush_endpoint(&ui->ep0out);
2245 flush_endpoint(&ui->ep0in);
2246 return 0;
2247 }
2248
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002249 if (!(ui && req && ep->req))
2250 return -EINVAL;
2251
2252 spin_lock_irqsave(&ui->lock, flags);
2253 if (!req->busy) {
2254 dev_dbg(&ui->pdev->dev, "%s: !req->busy\n", __func__);
2255 spin_unlock_irqrestore(&ui->lock, flags);
2256 return -EINVAL;
2257 }
Pavankumar Kondeti9cb21752011-08-08 16:14:53 +05302258 del_timer(&ep->prime_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002259 /* Stop the transfer */
2260 do {
2261 writel((1 << ep->bit), USB_ENDPTFLUSH);
2262 while (readl(USB_ENDPTFLUSH) & (1 << ep->bit))
2263 udelay(100);
2264 } while (readl(USB_ENDPTSTAT) & (1 << ep->bit));
2265
2266 req->req.status = 0;
2267 req->busy = 0;
2268
2269 if (ep->req == req) {
2270 ep->req = req->next;
2271 ep->head->next = req->item->next;
2272 } else {
2273 req->prev->next = req->next;
2274 if (req->next)
2275 req->next->prev = req->prev;
2276 req->prev->item->next = req->item->next;
2277 }
2278
2279 if (!req->next)
2280 ep->last = req->prev;
2281
2282 /* initialize request to default */
2283 req->item->next = TERMINATE;
2284 req->item->info = 0;
2285 req->live = 0;
2286 dma_unmap_single(NULL, req->dma, req->req.length,
2287 (ep->flags & EPT_FLAG_IN) ?
2288 DMA_TO_DEVICE : DMA_FROM_DEVICE);
2289
2290 if (req->req.complete) {
2291 req->req.status = -ECONNRESET;
2292 spin_unlock_irqrestore(&ui->lock, flags);
2293 req->req.complete(&ep->ep, &req->req);
2294 spin_lock_irqsave(&ui->lock, flags);
2295 }
2296
2297 if (!req->live) {
2298 /* Reprime the endpoint for the remaining transfers */
2299 for (temp_req = ep->req ; temp_req ; temp_req = temp_req->next)
2300 temp_req->live = 0;
2301 if (ep->req)
2302 usb_ept_start(ep);
2303 spin_unlock_irqrestore(&ui->lock, flags);
2304 return 0;
2305 }
2306 spin_unlock_irqrestore(&ui->lock, flags);
2307 return 0;
2308}
2309
2310static int
2311usb_ept_set_halt(struct usb_ep *_ep, int value)
2312{
2313 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2314 struct usb_info *ui = ept->ui;
2315 unsigned int in = ept->flags & EPT_FLAG_IN;
2316 unsigned int n;
2317 unsigned long flags;
2318
2319 spin_lock_irqsave(&ui->lock, flags);
2320
2321 n = readl(USB_ENDPTCTRL(ept->num));
2322
2323 if (in) {
2324 if (value)
2325 n |= CTRL_TXS;
2326 else {
2327 n &= ~CTRL_TXS;
2328 n |= CTRL_TXR;
2329 }
2330 } else {
2331 if (value)
2332 n |= CTRL_RXS;
2333 else {
2334 n &= ~CTRL_RXS;
2335 n |= CTRL_RXR;
2336 }
2337 }
2338 writel(n, USB_ENDPTCTRL(ept->num));
2339 if (!value)
2340 ept->wedged = 0;
2341 spin_unlock_irqrestore(&ui->lock, flags);
2342
2343 return 0;
2344}
2345
2346static int
2347msm72k_set_halt(struct usb_ep *_ep, int value)
2348{
2349 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2350 unsigned int in = ept->flags & EPT_FLAG_IN;
2351
2352 if (value && in && ept->req)
2353 return -EAGAIN;
2354
2355 usb_ept_set_halt(_ep, value);
2356
2357 return 0;
2358}
2359
2360static int
2361msm72k_fifo_status(struct usb_ep *_ep)
2362{
2363 return -EOPNOTSUPP;
2364}
2365
2366static void
2367msm72k_fifo_flush(struct usb_ep *_ep)
2368{
2369 flush_endpoint(to_msm_endpoint(_ep));
2370}
2371static int msm72k_set_wedge(struct usb_ep *_ep)
2372{
2373 struct msm_endpoint *ept = to_msm_endpoint(_ep);
2374
2375 if (ept->num == 0)
2376 return -EINVAL;
2377
2378 ept->wedged = 1;
2379
2380 return msm72k_set_halt(_ep, 1);
2381}
2382
2383static const struct usb_ep_ops msm72k_ep_ops = {
2384 .enable = msm72k_enable,
2385 .disable = msm72k_disable,
2386
2387 .alloc_request = msm72k_alloc_request,
2388 .free_request = msm72k_free_request,
2389
2390 .queue = msm72k_queue,
2391 .dequeue = msm72k_dequeue,
2392
2393 .set_halt = msm72k_set_halt,
2394 .set_wedge = msm72k_set_wedge,
2395 .fifo_status = msm72k_fifo_status,
2396 .fifo_flush = msm72k_fifo_flush,
2397};
2398
2399static int msm72k_get_frame(struct usb_gadget *_gadget)
2400{
2401 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2402
2403 /* frame number is in bits 13:3 */
2404 return (readl(USB_FRINDEX) >> 3) & 0x000007FF;
2405}
2406
2407/* VBUS reporting logically comes from a transceiver */
2408static int msm72k_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
2409{
2410 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2411 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2412
2413 if (is_active || atomic_read(&otg->chg_type)
2414 == USB_CHG_TYPE__WALLCHARGER)
2415 wake_lock(&ui->wlock);
2416
2417 msm_hsusb_set_vbus_state(is_active);
2418 return 0;
2419}
2420
2421/* SW workarounds
2422Issue #1 - USB Spoof Disconnect Failure
2423Symptom - Writing 0 to run/stop bit of USBCMD doesn't cause disconnect
2424SW workaround - Making opmode non-driving and SuspendM set in function
2425 register of SMSC phy
2426*/
2427/* drivers may have software control over D+ pullup */
2428static int msm72k_pullup_internal(struct usb_gadget *_gadget, int is_active)
2429{
2430 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2431 unsigned long flags;
2432
2433 if (is_active) {
2434 spin_lock_irqsave(&ui->lock, flags);
2435 if (is_usb_online(ui) && ui->driver)
2436 writel(readl(USB_USBCMD) | USBCMD_RS, USB_USBCMD);
2437 spin_unlock_irqrestore(&ui->lock, flags);
2438 } else {
2439 writel(readl(USB_USBCMD) & ~USBCMD_RS, USB_USBCMD);
2440 /* S/W workaround, Issue#1 */
Steve Mucklef132c6c2012-06-06 18:30:57 -07002441 usb_phy_io_write(ui->xceiv, 0x48, 0x04);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002442 }
2443
2444 /* Ensure pull-up operation is completed before returning */
2445 mb();
2446
2447 return 0;
2448}
2449
2450static int msm72k_pullup(struct usb_gadget *_gadget, int is_active)
2451{
2452 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
Chiranjeevi Velempatif4fe1192012-05-14 09:39:08 +05302453 struct msm_otg *otg = to_msm_otg(ui->xceiv);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002454 unsigned long flags;
2455
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002456 atomic_set(&ui->softconnect, is_active);
2457
2458 spin_lock_irqsave(&ui->lock, flags);
Chiranjeevi Velempatif4fe1192012-05-14 09:39:08 +05302459 if (ui->usb_state == USB_STATE_NOTATTACHED || ui->driver == NULL ||
2460 atomic_read(&otg->chg_type) == USB_CHG_TYPE__WALLCHARGER) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002461 spin_unlock_irqrestore(&ui->lock, flags);
2462 return 0;
2463 }
2464 spin_unlock_irqrestore(&ui->lock, flags);
2465
2466 msm72k_pullup_internal(_gadget, is_active);
2467
2468 if (is_active && !ui->gadget.is_a_peripheral)
2469 schedule_delayed_work(&ui->chg_det, USB_CHG_DET_DELAY);
2470
2471 return 0;
2472}
2473
2474static int msm72k_wakeup(struct usb_gadget *_gadget)
2475{
2476 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2477 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2478
2479 if (!atomic_read(&ui->remote_wakeup)) {
2480 dev_err(&ui->pdev->dev,
2481 "%s: remote wakeup not supported\n", __func__);
2482 return -ENOTSUPP;
2483 }
2484
2485 if (!atomic_read(&ui->configured)) {
2486 dev_err(&ui->pdev->dev,
2487 "%s: device is not configured\n", __func__);
2488 return -ENODEV;
2489 }
Steve Mucklef132c6c2012-06-06 18:30:57 -07002490 usb_phy_set_suspend(ui->xceiv, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002491
2492 disable_irq(otg->irq);
2493
2494 if (!is_usb_active())
2495 writel(readl(USB_PORTSC) | PORTSC_FPR, USB_PORTSC);
2496
2497 /* Ensure that USB port is resumed before enabling the IRQ */
2498 mb();
2499
2500 enable_irq(otg->irq);
2501
2502 return 0;
2503}
2504
2505/* when Gadget is configured, it will indicate how much power
2506 * can be pulled from vbus, as specified in configuiration descriptor
2507 */
2508static int msm72k_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
2509{
2510 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2511 unsigned long flags;
2512
2513
2514 spin_lock_irqsave(&ui->lock, flags);
2515 ui->b_max_pow = mA;
2516 ui->flags = USB_FLAG_CONFIGURED;
2517 spin_unlock_irqrestore(&ui->lock, flags);
2518
2519 schedule_work(&ui->work);
2520
2521 return 0;
2522}
2523
2524static int msm72k_set_selfpowered(struct usb_gadget *_gadget, int set)
2525{
2526 struct usb_info *ui = container_of(_gadget, struct usb_info, gadget);
2527 unsigned long flags;
2528 int ret = 0;
2529
2530 spin_lock_irqsave(&ui->lock, flags);
2531 if (set) {
2532 if (ui->pdata && ui->pdata->self_powered)
2533 atomic_set(&ui->self_powered, 1);
2534 else
2535 ret = -EOPNOTSUPP;
2536 } else {
2537 /* We can always work as a bus powered device */
2538 atomic_set(&ui->self_powered, 0);
2539 }
2540 spin_unlock_irqrestore(&ui->lock, flags);
2541
2542 return ret;
2543
2544}
2545
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002546static int msm72k_gadget_start(struct usb_gadget_driver *driver,
2547 int (*bind)(struct usb_gadget *));
2548static int msm72k_gadget_stop(struct usb_gadget_driver *driver);
2549
2550
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002551static const struct usb_gadget_ops msm72k_ops = {
2552 .get_frame = msm72k_get_frame,
2553 .vbus_session = msm72k_udc_vbus_session,
2554 .vbus_draw = msm72k_udc_vbus_draw,
2555 .pullup = msm72k_pullup,
2556 .wakeup = msm72k_wakeup,
2557 .set_selfpowered = msm72k_set_selfpowered,
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002558 .start = msm72k_gadget_start,
2559 .stop = msm72k_gadget_stop
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002560};
2561
2562static void usb_do_remote_wakeup(struct work_struct *w)
2563{
2564 struct usb_info *ui = the_usb_info;
2565
2566 msm72k_wakeup(&ui->gadget);
2567}
2568
2569static ssize_t usb_remote_wakeup(struct device *dev,
2570 struct device_attribute *attr, const char *buf, size_t count)
2571{
2572 struct usb_info *ui = the_usb_info;
2573
2574 msm72k_wakeup(&ui->gadget);
2575
2576 return count;
2577}
2578
2579static ssize_t show_usb_state(struct device *dev, struct device_attribute *attr,
2580 char *buf)
2581{
2582 size_t i;
2583 char *state[] = {"USB_STATE_NOTATTACHED", "USB_STATE_ATTACHED",
2584 "USB_STATE_POWERED", "USB_STATE_UNAUTHENTICATED",
2585 "USB_STATE_RECONNECTING", "USB_STATE_DEFAULT",
2586 "USB_STATE_ADDRESS", "USB_STATE_CONFIGURED",
2587 "USB_STATE_SUSPENDED"
2588 };
2589
2590 i = scnprintf(buf, PAGE_SIZE, "%s\n", state[msm_hsusb_get_state()]);
2591 return i;
2592}
2593
2594static ssize_t show_usb_speed(struct device *dev, struct device_attribute *attr,
2595 char *buf)
2596{
2597 struct usb_info *ui = the_usb_info;
2598 size_t i;
2599 char *speed[] = {"USB_SPEED_UNKNOWN", "USB_SPEED_LOW",
2600 "USB_SPEED_FULL", "USB_SPEED_HIGH"};
2601
2602 i = scnprintf(buf, PAGE_SIZE, "%s\n", speed[ui->gadget.speed]);
2603 return i;
2604}
2605
2606static ssize_t store_usb_chg_current(struct device *dev,
2607 struct device_attribute *attr, const char *buf, size_t count)
2608{
2609 struct usb_info *ui = the_usb_info;
2610 unsigned long mA;
2611
2612 if (ui->gadget.is_a_peripheral)
2613 return -EINVAL;
2614
2615 if (strict_strtoul(buf, 10, &mA))
2616 return -EINVAL;
2617
2618 ui->chg_current = mA;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002619 usb_phy_set_power(ui->xceiv, mA);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002620
2621 return count;
2622}
2623
2624static ssize_t show_usb_chg_current(struct device *dev,
2625 struct device_attribute *attr, char *buf)
2626{
2627 struct usb_info *ui = the_usb_info;
2628 size_t count;
2629
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302630 count = snprintf(buf, PAGE_SIZE, "%d", ui->chg_current);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002631
2632 return count;
2633}
2634
2635static ssize_t show_usb_chg_type(struct device *dev,
2636 struct device_attribute *attr, char *buf)
2637{
2638 struct usb_info *ui = the_usb_info;
2639 struct msm_otg *otg = to_msm_otg(ui->xceiv);
2640 size_t count;
2641 char *chg_type[] = {"STD DOWNSTREAM PORT",
2642 "CARKIT",
2643 "DEDICATED CHARGER",
2644 "INVALID"};
2645
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302646 count = snprintf(buf, PAGE_SIZE, "%s",
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002647 chg_type[atomic_read(&otg->chg_type)]);
2648
2649 return count;
2650}
2651static DEVICE_ATTR(wakeup, S_IWUSR, 0, usb_remote_wakeup);
2652static DEVICE_ATTR(usb_state, S_IRUSR, show_usb_state, 0);
2653static DEVICE_ATTR(usb_speed, S_IRUSR, show_usb_speed, 0);
2654static DEVICE_ATTR(chg_type, S_IRUSR, show_usb_chg_type, 0);
2655static DEVICE_ATTR(chg_current, S_IWUSR | S_IRUSR,
2656 show_usb_chg_current, store_usb_chg_current);
2657
2658#ifdef CONFIG_USB_OTG
2659static ssize_t store_host_req(struct device *dev,
2660 struct device_attribute *attr, const char *buf, size_t count)
2661{
2662 struct usb_info *ui = the_usb_info;
2663 unsigned long val, flags;
2664
2665 if (strict_strtoul(buf, 10, &val))
2666 return -EINVAL;
2667
2668 dev_dbg(&ui->pdev->dev, "%s host request\n",
2669 val ? "set" : "clear");
2670
2671 spin_lock_irqsave(&ui->lock, flags);
2672 if (ui->hnp_avail)
2673 ui->gadget.host_request = !!val;
2674 spin_unlock_irqrestore(&ui->lock, flags);
2675
2676 return count;
2677}
2678static DEVICE_ATTR(host_request, S_IWUSR, NULL, store_host_req);
2679
2680/* How do we notify user space about HNP availability?
2681 * As we are compliant to Rev 2.0, Host will not set a_hnp_support.
2682 * Introduce hnp_avail flag and set when HNP polling request arrives.
2683 * The expectation is that user space checks hnp availability before
2684 * requesting host role via above sysfs node.
2685 */
2686static ssize_t show_host_avail(struct device *dev,
2687 struct device_attribute *attr, char *buf)
2688{
2689 struct usb_info *ui = the_usb_info;
2690 size_t count;
2691 unsigned long flags;
2692
2693 spin_lock_irqsave(&ui->lock, flags);
Pavankumar Kondetif0f95d82011-09-23 11:38:57 +05302694 count = snprintf(buf, PAGE_SIZE, "%d\n", ui->hnp_avail);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002695 spin_unlock_irqrestore(&ui->lock, flags);
2696
2697 return count;
2698}
2699static DEVICE_ATTR(host_avail, S_IRUSR, show_host_avail, NULL);
2700
2701static struct attribute *otg_attrs[] = {
2702 &dev_attr_host_request.attr,
2703 &dev_attr_host_avail.attr,
2704 NULL,
2705};
2706
2707static struct attribute_group otg_attr_grp = {
2708 .name = "otg",
2709 .attrs = otg_attrs,
2710};
2711#endif
2712
2713static int msm72k_probe(struct platform_device *pdev)
2714{
2715 struct usb_info *ui;
2716 struct msm_otg *otg;
2717 int retval;
2718
2719 dev_dbg(&pdev->dev, "msm72k_probe\n");
2720 ui = kzalloc(sizeof(struct usb_info), GFP_KERNEL);
2721 if (!ui)
2722 return -ENOMEM;
2723
2724 ui->pdev = pdev;
2725 ui->pdata = pdev->dev.platform_data;
2726
2727 ui->buf = dma_alloc_coherent(&pdev->dev, 4096, &ui->dma, GFP_KERNEL);
2728 if (!ui->buf)
2729 return usb_free(ui, -ENOMEM);
2730
2731 ui->pool = dma_pool_create("msm72k_udc", NULL, 32, 32, 0);
2732 if (!ui->pool)
2733 return usb_free(ui, -ENOMEM);
2734
Steve Mucklef132c6c2012-06-06 18:30:57 -07002735 ui->xceiv = usb_get_transceiver();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002736 if (!ui->xceiv)
2737 return usb_free(ui, -ENODEV);
2738
2739 otg = to_msm_otg(ui->xceiv);
2740 ui->addr = otg->regs;
2741
2742 ui->gadget.ops = &msm72k_ops;
Steve Mucklef132c6c2012-06-06 18:30:57 -07002743 ui->gadget.max_speed = USB_SPEED_HIGH;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002744 device_initialize(&ui->gadget.dev);
2745 dev_set_name(&ui->gadget.dev, "gadget");
2746 ui->gadget.dev.parent = &pdev->dev;
2747 ui->gadget.dev.dma_mask = pdev->dev.dma_mask;
2748
2749#ifdef CONFIG_USB_OTG
2750 ui->gadget.is_otg = 1;
2751#endif
2752
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002753 retval = usb_add_gadget_udc(&pdev->dev, &ui->gadget);
2754 if (retval)
2755 return usb_free(ui, retval);
2756
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002757 ui->sdev.name = DRIVER_NAME;
2758 ui->sdev.print_name = print_switch_name;
2759 ui->sdev.print_state = print_switch_state;
2760
2761 retval = switch_dev_register(&ui->sdev);
2762 if (retval)
2763 return usb_free(ui, retval);
2764
2765 the_usb_info = ui;
2766
2767 wake_lock_init(&ui->wlock,
2768 WAKE_LOCK_SUSPEND, "usb_bus_active");
2769
2770 usb_debugfs_init(ui);
2771
2772 usb_prepare(ui);
2773
2774#ifdef CONFIG_USB_OTG
2775 retval = sysfs_create_group(&pdev->dev.kobj, &otg_attr_grp);
2776 if (retval) {
2777 dev_err(&ui->pdev->dev,
2778 "failed to create otg sysfs directory:"
2779 "err:(%d)\n", retval);
2780 }
2781#endif
2782
Steve Mucklef132c6c2012-06-06 18:30:57 -07002783 retval = otg_set_peripheral(ui->xceiv->otg, &ui->gadget);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002784 if (retval) {
2785 dev_err(&ui->pdev->dev,
2786 "%s: Cannot bind the transceiver, retval:(%d)\n",
2787 __func__, retval);
2788 switch_dev_unregister(&ui->sdev);
2789 wake_lock_destroy(&ui->wlock);
2790 return usb_free(ui, retval);
2791 }
2792
2793 pm_runtime_enable(&pdev->dev);
2794
2795 /* Setup phy stuck timer */
2796 if (ui->pdata && ui->pdata->is_phy_status_timer_on)
2797 setup_timer(&phy_status_timer, usb_phy_status_check_timer, 0);
2798 return 0;
2799}
2800
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002801static int msm72k_gadget_start(struct usb_gadget_driver *driver,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002802 int (*bind)(struct usb_gadget *))
2803{
2804 struct usb_info *ui = the_usb_info;
2805 int retval, n;
2806
2807 if (!driver
Steve Mucklef132c6c2012-06-06 18:30:57 -07002808 || driver->max_speed < USB_SPEED_FULL
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002809 || !bind
2810 || !driver->disconnect
2811 || !driver->setup)
2812 return -EINVAL;
2813 if (!ui)
2814 return -ENODEV;
2815 if (ui->driver)
2816 return -EBUSY;
2817
2818 /* first hook up the driver ... */
2819 ui->driver = driver;
2820 ui->gadget.dev.driver = &driver->driver;
2821 ui->gadget.name = driver_name;
2822 INIT_LIST_HEAD(&ui->gadget.ep_list);
2823 ui->gadget.ep0 = &ui->ep0in.ep;
2824 INIT_LIST_HEAD(&ui->gadget.ep0->ep_list);
2825 ui->gadget.speed = USB_SPEED_UNKNOWN;
2826 atomic_set(&ui->softconnect, 1);
2827
2828 for (n = 1; n < 16; n++) {
2829 struct msm_endpoint *ept = ui->ept + n;
2830 list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
2831 ept->ep.maxpacket = 512;
2832 }
2833 for (n = 17; n < 32; n++) {
2834 struct msm_endpoint *ept = ui->ept + n;
2835 list_add_tail(&ept->ep.ep_list, &ui->gadget.ep_list);
2836 ept->ep.maxpacket = 512;
2837 }
2838
2839 retval = device_add(&ui->gadget.dev);
2840 if (retval)
2841 goto fail;
2842
2843 retval = bind(&ui->gadget);
2844 if (retval) {
2845 dev_err(&ui->pdev->dev, "bind to driver %s --> error %d\n",
2846 driver->driver.name, retval);
2847 device_del(&ui->gadget.dev);
2848 goto fail;
2849 }
2850
2851 retval = device_create_file(&ui->gadget.dev, &dev_attr_wakeup);
2852 if (retval != 0)
2853 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2854 "(wakeup) error: (%d)\n", retval);
2855 retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_state);
2856 if (retval != 0)
2857 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2858 " (usb_state) error: (%d)\n", retval);
2859
2860 retval = device_create_file(&ui->gadget.dev, &dev_attr_usb_speed);
2861 if (retval != 0)
2862 dev_err(&ui->pdev->dev, "failed to create sysfs entry:"
2863 " (usb_speed) error: (%d)\n", retval);
2864
2865 retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_type);
2866 if (retval != 0)
2867 dev_err(&ui->pdev->dev,
2868 "failed to create sysfs entry(chg_type): err:(%d)\n",
2869 retval);
2870 retval = device_create_file(&ui->gadget.dev, &dev_attr_chg_current);
2871 if (retval != 0)
2872 dev_err(&ui->pdev->dev,
2873 "failed to create sysfs entry(chg_current):"
2874 "err:(%d)\n", retval);
2875
2876 dev_dbg(&ui->pdev->dev, "registered gadget driver '%s'\n",
2877 driver->driver.name);
2878 usb_start(ui);
2879
2880 return 0;
2881
2882fail:
2883 ui->driver = NULL;
2884 ui->gadget.dev.driver = NULL;
2885 return retval;
2886}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002887
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002888static int msm72k_gadget_stop(struct usb_gadget_driver *driver)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002889{
2890 struct usb_info *dev = the_usb_info;
2891
2892 if (!dev)
2893 return -ENODEV;
2894 if (!driver || driver != dev->driver || !driver->unbind)
2895 return -EINVAL;
2896
2897 msm72k_pullup_internal(&dev->gadget, 0);
2898 if (dev->irq) {
2899 free_irq(dev->irq, dev);
2900 dev->irq = 0;
2901 }
2902 dev->state = USB_STATE_IDLE;
2903 atomic_set(&dev->configured, 0);
2904 switch_set_state(&dev->sdev, 0);
2905 /* cancel pending ep0 transactions */
2906 flush_endpoint(&dev->ep0out);
2907 flush_endpoint(&dev->ep0in);
2908
2909 device_remove_file(&dev->gadget.dev, &dev_attr_wakeup);
2910 device_remove_file(&dev->gadget.dev, &dev_attr_usb_state);
2911 device_remove_file(&dev->gadget.dev, &dev_attr_usb_speed);
2912 device_remove_file(&dev->gadget.dev, &dev_attr_chg_type);
2913 device_remove_file(&dev->gadget.dev, &dev_attr_chg_current);
2914 driver->disconnect(&dev->gadget);
2915 driver->unbind(&dev->gadget);
2916 dev->gadget.dev.driver = NULL;
2917 dev->driver = NULL;
2918
2919 device_del(&dev->gadget.dev);
2920
2921 dev_dbg(&dev->pdev->dev,
2922 "unregistered gadget driver '%s'\n", driver->driver.name);
2923 return 0;
2924}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002925
2926
2927static int msm72k_udc_runtime_suspend(struct device *dev)
2928{
2929 dev_dbg(dev, "pm_runtime: suspending...\n");
2930 return 0;
2931}
2932
2933static int msm72k_udc_runtime_resume(struct device *dev)
2934{
2935 dev_dbg(dev, "pm_runtime: resuming...\n");
2936 return 0;
2937}
2938
2939static int msm72k_udc_runtime_idle(struct device *dev)
2940{
2941 dev_dbg(dev, "pm_runtime: idling...\n");
2942 return 0;
2943}
2944
2945static struct dev_pm_ops msm72k_udc_dev_pm_ops = {
2946 .runtime_suspend = msm72k_udc_runtime_suspend,
2947 .runtime_resume = msm72k_udc_runtime_resume,
2948 .runtime_idle = msm72k_udc_runtime_idle
2949};
2950
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002951static int __exit msm72k_remove(struct platform_device *pdev)
2952{
2953 struct usb_info *ui = container_of(&pdev, struct usb_info, pdev);
2954
2955 return usb_free(ui, 0);
2956}
2957
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002958static struct platform_driver usb_driver = {
2959 .probe = msm72k_probe,
Sebastian Andrzej Siewiord23607a2011-06-28 16:33:47 +03002960 .remove = msm72k_remove,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002961 .driver = { .name = "msm_hsusb",
2962 .pm = &msm72k_udc_dev_pm_ops, },
2963};
2964
2965static int __init init(void)
2966{
2967 return platform_driver_register(&usb_driver);
2968}
2969module_init(init);
2970
2971static void __exit cleanup(void)
2972{
2973 platform_driver_unregister(&usb_driver);
2974}
2975module_exit(cleanup);
2976
2977MODULE_DESCRIPTION(DRIVER_DESC);
2978MODULE_AUTHOR("Mike Lockwood, Brian Swetland");
2979MODULE_LICENSE("GPL");