1 From b9a0fdbf333b461682d5da8b9aaa42f4de91ffcf Mon Sep 17 00:00:00 2001
2 From: Dmitry Baryshkov <dbaryshkov@gmail.com>
3 Date: Sun, 10 Feb 2008 03:29:17 +0300
4 Subject: [PATCH 18/64] Fix the pxa2xx_udc to balance calls to clk_enable/clk_disable
6 Signed-off-by: Dmitry Baryshkov dbaryshkov@gmail.com
8 drivers/usb/gadget/pxa2xx_udc.c | 84 +++++++++++++++++++++++----------------
9 drivers/usb/gadget/pxa2xx_udc.h | 6 ++-
10 2 files changed, 54 insertions(+), 36 deletions(-)
12 diff --git a/drivers/usb/gadget/pxa2xx_udc.c b/drivers/usb/gadget/pxa2xx_udc.c
13 index 2900556..8e32d07 100644
14 --- a/drivers/usb/gadget/pxa2xx_udc.c
15 +++ b/drivers/usb/gadget/pxa2xx_udc.c
16 @@ -680,7 +680,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
18 /* kickstart this i/o queue? */
19 if (list_empty(&ep->queue) && !ep->stopped) {
20 - if (ep->desc == 0 /* ep0 */) {
21 + if (ep->desc == NULL /* ep0 */) {
22 unsigned length = _req->length;
24 switch (dev->ep0state) {
25 @@ -734,7 +734,7 @@ pxa2xx_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
28 /* pio or dma irq handler advances the queue. */
29 - if (likely (req != 0))
30 + if (likely (req != NULL))
31 list_add_tail(&req->queue, &ep->queue);
32 local_irq_restore(flags);
34 @@ -934,20 +934,35 @@ static void udc_disable(struct pxa2xx_udc *);
35 /* We disable the UDC -- and its 48 MHz clock -- whenever it's not
38 -static int pullup(struct pxa2xx_udc *udc, int is_active)
39 +static int pullup(struct pxa2xx_udc *udc)
41 - is_active = is_active && udc->vbus && udc->pullup;
42 + int is_active = udc->vbus && udc->pullup && ! udc->suspended;
43 DMSG("%s\n", is_active ? "active" : "inactive");
47 - if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
48 - DMSG("disconnect %s\n", udc->driver
49 - ? udc->driver->driver.name
51 - stop_activity(udc, udc->driver);
55 +#ifdef CONFIG_ARCH_PXA
56 + /* Enable clock for USB device */
57 + clk_enable(udc->clk);
64 + if (udc->gadget.speed != USB_SPEED_UNKNOWN) {
65 + DMSG("disconnect %s\n", udc->driver
66 + ? udc->driver->driver.name
68 + stop_activity(udc, udc->driver);
71 +#ifdef CONFIG_ARCH_PXA
72 + /* Disable clock for USB device */
73 + clk_disable(udc->clk);
81 @@ -958,9 +973,9 @@ static int pxa2xx_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
82 struct pxa2xx_udc *udc;
84 udc = container_of(_gadget, struct pxa2xx_udc, gadget);
85 - udc->vbus = is_active = (is_active != 0);
86 + udc->vbus = (is_active != 0);
87 DMSG("vbus %s\n", is_active ? "supplied" : "inactive");
88 - pullup(udc, is_active);
93 @@ -975,9 +990,8 @@ static int pxa2xx_udc_pullup(struct usb_gadget *_gadget, int is_active)
94 if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
97 - is_active = (is_active != 0);
98 - udc->pullup = is_active;
99 - pullup(udc, is_active);
100 + udc->pullup = (is_active != 0);
105 @@ -998,7 +1012,7 @@ static const struct usb_gadget_ops pxa2xx_udc_ops = {
107 static struct pxa2xx_udc memory;
109 -udc_seq_show(struct seq_file *m, void *d)
110 +udc_seq_show(struct seq_file *m, void *_d)
112 struct pxa2xx_udc *dev = m->private;
114 @@ -1145,11 +1159,6 @@ static void udc_disable(struct pxa2xx_udc *dev)
116 udc_clear_mask_UDCCR(UDCCR_UDE);
118 -#ifdef CONFIG_ARCH_PXA
119 - /* Disable clock for USB device */
120 - clk_disable(dev->clk);
124 dev->gadget.speed = USB_SPEED_UNKNOWN;
126 @@ -1190,11 +1199,6 @@ static void udc_enable (struct pxa2xx_udc *dev)
128 udc_clear_mask_UDCCR(UDCCR_UDE);
130 -#ifdef CONFIG_ARCH_PXA
131 - /* Enable clock for USB device */
132 - clk_enable(dev->clk);
135 /* try to clear these bits before we enable the udc */
136 udc_ack_int_UDCCR(UDCCR_SUSIR|/*UDCCR_RSTIR|*/UDCCR_RESIR);
138 @@ -1285,7 +1289,7 @@ fail:
139 * for set_configuration as well as eventual disconnect.
141 DMSG("registered gadget driver '%s'\n", driver->driver.name);
147 @@ -1328,7 +1332,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
154 stop_activity(dev, driver);
157 @@ -2267,7 +2272,9 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
165 remove_debug_files(dev);
168 @@ -2315,10 +2322,15 @@ static int __exit pxa2xx_udc_remove(struct platform_device *pdev)
169 static int pxa2xx_udc_suspend(struct platform_device *dev, pm_message_t state)
171 struct pxa2xx_udc *udc = platform_get_drvdata(dev);
172 + unsigned long flags;
174 if (!udc->mach->gpio_pullup && !udc->mach->udc_command)
175 WARN("USB host won't detect disconnect!\n");
177 + udc->suspended = 1;
179 + local_irq_save(flags);
181 + local_irq_restore(flags);
185 @@ -2326,8 +2338,12 @@ static int pxa2xx_udc_suspend(struct platform_device *dev, pm_message_t state)
186 static int pxa2xx_udc_resume(struct platform_device *dev)
188 struct pxa2xx_udc *udc = platform_get_drvdata(dev);
189 + unsigned long flags;
192 + udc->suspended = 0;
193 + local_irq_save(flags);
195 + local_irq_restore(flags);
199 diff --git a/drivers/usb/gadget/pxa2xx_udc.h b/drivers/usb/gadget/pxa2xx_udc.h
200 index c08b1a2..93586b2 100644
201 --- a/drivers/usb/gadget/pxa2xx_udc.h
202 +++ b/drivers/usb/gadget/pxa2xx_udc.h
203 @@ -119,7 +119,9 @@ struct pxa2xx_udc {
212 #define start_watchdog(dev) mod_timer(&dev->timer, jiffies + (HZ/200))
213 struct timer_list timer;
214 @@ -239,7 +241,7 @@ dump_state(struct pxa2xx_udc *dev)
215 dev->stats.read.bytes, dev->stats.read.ops);
217 for (i = 1; i < PXA_UDC_NUM_ENDPOINTS; i++) {
218 - if (dev->ep [i].desc == 0)
219 + if (dev->ep [i].desc == NULL)
221 DMSG ("udccs%d = %02x\n", i, *dev->ep->reg_udccs);