54e8feb8a964426ad57cc2a749080ea2604523c8
[cascardo/linux.git] / drivers / usb / host / ohci-at91.c
1 /*
2  * OHCI HCD (Host Controller Driver) for USB.
3  *
4  *  Copyright (C) 2004 SAN People (Pty) Ltd.
5  *  Copyright (C) 2005 Thibaut VARENE <varenet@parisc-linux.org>
6  *
7  * AT91 Bus Glue
8  *
9  * Based on fragments of 2.4 driver by Rick Bronson.
10  * Based on ohci-omap.c
11  *
12  * This file is licenced under the GPL.
13  */
14
15 #include <linux/clk.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/of_platform.h>
18 #include <linux/of_gpio.h>
19 #include <linux/platform_device.h>
20 #include <linux/platform_data/atmel.h>
21 #include <linux/io.h>
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/mfd/syscon.h>
25 #include <linux/regmap.h>
26 #include <linux/usb.h>
27 #include <linux/usb/hcd.h>
28 #include <soc/at91/at91_sfr.h>
29
30 #include "ohci.h"
31
32 #define valid_port(index)       ((index) >= 0 && (index) < AT91_MAX_USBH_PORTS)
33 #define at91_for_each_port(index)       \
34                 for ((index) = 0; (index) < AT91_MAX_USBH_PORTS; (index)++)
35
36 /* interface, function and usb clocks; sometimes also an AHB clock */
37 #define hcd_to_ohci_at91_priv(h) \
38         ((struct ohci_at91_priv *)hcd_to_ohci(h)->priv)
39
40 #define AT91_MAX_USBH_PORTS     3
41 struct at91_usbh_data {
42         int vbus_pin[AT91_MAX_USBH_PORTS];      /* port power-control pin */
43         int overcurrent_pin[AT91_MAX_USBH_PORTS];
44         u8 ports;                               /* number of ports on root hub */
45         u8 overcurrent_supported;
46         u8 vbus_pin_active_low[AT91_MAX_USBH_PORTS];
47         u8 overcurrent_status[AT91_MAX_USBH_PORTS];
48         u8 overcurrent_changed[AT91_MAX_USBH_PORTS];
49 };
50
51 struct ohci_at91_caps {
52         bool suspend_ctrl;
53 };
54
55 struct ohci_at91_priv {
56         struct clk *iclk;
57         struct clk *fclk;
58         struct clk *hclk;
59         bool clocked;
60         bool wakeup;            /* Saved wake-up state for resume */
61         const struct ohci_at91_caps *caps;
62         struct regmap *sfr_regmap;
63 };
64 /* interface and function clocks; sometimes also an AHB clock */
65
66 #define DRIVER_DESC "OHCI Atmel driver"
67
68 static const char hcd_name[] = "ohci-atmel";
69
70 static struct hc_driver __read_mostly ohci_at91_hc_driver;
71
72 static const struct ohci_driver_overrides ohci_at91_drv_overrides __initconst = {
73         .extra_priv_size = sizeof(struct ohci_at91_priv),
74 };
75
76 extern int usb_disabled(void);
77
78 /*-------------------------------------------------------------------------*/
79
80 static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
81 {
82         if (ohci_at91->clocked)
83                 return;
84
85         clk_set_rate(ohci_at91->fclk, 48000000);
86         clk_prepare_enable(ohci_at91->hclk);
87         clk_prepare_enable(ohci_at91->iclk);
88         clk_prepare_enable(ohci_at91->fclk);
89         ohci_at91->clocked = true;
90 }
91
92 static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
93 {
94         if (!ohci_at91->clocked)
95                 return;
96
97         clk_disable_unprepare(ohci_at91->fclk);
98         clk_disable_unprepare(ohci_at91->iclk);
99         clk_disable_unprepare(ohci_at91->hclk);
100         ohci_at91->clocked = false;
101 }
102
103 static void at91_start_hc(struct platform_device *pdev)
104 {
105         struct usb_hcd *hcd = platform_get_drvdata(pdev);
106         struct ohci_regs __iomem *regs = hcd->regs;
107         struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
108
109         dev_dbg(&pdev->dev, "start\n");
110
111         /*
112          * Start the USB clocks.
113          */
114         at91_start_clock(ohci_at91);
115
116         /*
117          * The USB host controller must remain in reset.
118          */
119         writel(0, &regs->control);
120 }
121
122 static void at91_stop_hc(struct platform_device *pdev)
123 {
124         struct usb_hcd *hcd = platform_get_drvdata(pdev);
125         struct ohci_regs __iomem *regs = hcd->regs;
126         struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
127
128         dev_dbg(&pdev->dev, "stop\n");
129
130         /*
131          * Put the USB host controller into reset.
132          */
133         writel(0, &regs->control);
134
135         /*
136          * Stop the USB clocks.
137          */
138         at91_stop_clock(ohci_at91);
139 }
140
141
142 /*-------------------------------------------------------------------------*/
143
144 struct regmap *at91_dt_syscon_sfr(void)
145 {
146         struct regmap *regmap;
147
148         regmap = syscon_regmap_lookup_by_compatible("atmel,sama5d2-sfr");
149         if (IS_ERR(regmap))
150                 regmap = NULL;
151
152         return regmap;
153 }
154
155 static void usb_hcd_at91_remove (struct usb_hcd *, struct platform_device *);
156
157 /* configure so an HC device and id are always provided */
158 /* always called with process context; sleeping is OK */
159
160
161 /**
162  * usb_hcd_at91_probe - initialize AT91-based HCDs
163  * Context: !in_interrupt()
164  *
165  * Allocates basic resources for this USB host controller, and
166  * then invokes the start() method for the HCD associated with it
167  * through the hotplug entry's driver_data.
168  */
169 static int usb_hcd_at91_probe(const struct hc_driver *driver,
170                         struct platform_device *pdev)
171 {
172         struct at91_usbh_data *board;
173         struct ohci_hcd *ohci;
174         int retval;
175         struct usb_hcd *hcd;
176         struct ohci_at91_priv *ohci_at91;
177         struct device *dev = &pdev->dev;
178         struct resource *res;
179         int irq;
180
181         irq = platform_get_irq(pdev, 0);
182         if (irq < 0) {
183                 dev_dbg(dev, "hcd probe: missing irq resource\n");
184                 return irq;
185         }
186
187         hcd = usb_create_hcd(driver, dev, "at91");
188         if (!hcd)
189                 return -ENOMEM;
190         ohci_at91 = hcd_to_ohci_at91_priv(hcd);
191
192         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
193         hcd->regs = devm_ioremap_resource(dev, res);
194         if (IS_ERR(hcd->regs)) {
195                 retval = PTR_ERR(hcd->regs);
196                 goto err;
197         }
198         hcd->rsrc_start = res->start;
199         hcd->rsrc_len = resource_size(res);
200
201         ohci_at91->iclk = devm_clk_get(dev, "ohci_clk");
202         if (IS_ERR(ohci_at91->iclk)) {
203                 dev_err(dev, "failed to get ohci_clk\n");
204                 retval = PTR_ERR(ohci_at91->iclk);
205                 goto err;
206         }
207         ohci_at91->fclk = devm_clk_get(dev, "uhpck");
208         if (IS_ERR(ohci_at91->fclk)) {
209                 dev_err(dev, "failed to get uhpck\n");
210                 retval = PTR_ERR(ohci_at91->fclk);
211                 goto err;
212         }
213         ohci_at91->hclk = devm_clk_get(dev, "hclk");
214         if (IS_ERR(ohci_at91->hclk)) {
215                 dev_err(dev, "failed to get hclk\n");
216                 retval = PTR_ERR(ohci_at91->hclk);
217                 goto err;
218         }
219
220         ohci_at91->caps = (const struct ohci_at91_caps *)
221                           of_device_get_match_data(&pdev->dev);
222         if (!ohci_at91->caps)
223                 return -ENODEV;
224
225         if (ohci_at91->caps->suspend_ctrl) {
226                 ohci_at91->sfr_regmap = at91_dt_syscon_sfr();
227                 if (!ohci_at91->sfr_regmap)
228                         dev_warn(dev, "failed to find sfr node\n");
229         }
230
231         board = hcd->self.controller->platform_data;
232         ohci = hcd_to_ohci(hcd);
233         ohci->num_ports = board->ports;
234         at91_start_hc(pdev);
235
236         retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
237         if (retval == 0) {
238                 device_wakeup_enable(hcd->self.controller);
239                 return retval;
240         }
241
242         /* Error handling */
243         at91_stop_hc(pdev);
244
245  err:
246         usb_put_hcd(hcd);
247         return retval;
248 }
249
250
251 /* may be called with controller, bus, and devices active */
252
253 /**
254  * usb_hcd_at91_remove - shutdown processing for AT91-based HCDs
255  * @dev: USB Host Controller being removed
256  * Context: !in_interrupt()
257  *
258  * Reverses the effect of usb_hcd_at91_probe(), first invoking
259  * the HCD's stop() method.  It is always called from a thread
260  * context, "rmmod" or something similar.
261  *
262  */
263 static void usb_hcd_at91_remove(struct usb_hcd *hcd,
264                                 struct platform_device *pdev)
265 {
266         usb_remove_hcd(hcd);
267         at91_stop_hc(pdev);
268         usb_put_hcd(hcd);
269 }
270
271 /*-------------------------------------------------------------------------*/
272 static void ohci_at91_usb_set_power(struct at91_usbh_data *pdata, int port, int enable)
273 {
274         if (!valid_port(port))
275                 return;
276
277         if (!gpio_is_valid(pdata->vbus_pin[port]))
278                 return;
279
280         gpio_set_value(pdata->vbus_pin[port],
281                        pdata->vbus_pin_active_low[port] ^ enable);
282 }
283
284 static int ohci_at91_usb_get_power(struct at91_usbh_data *pdata, int port)
285 {
286         if (!valid_port(port))
287                 return -EINVAL;
288
289         if (!gpio_is_valid(pdata->vbus_pin[port]))
290                 return -EINVAL;
291
292         return gpio_get_value(pdata->vbus_pin[port]) ^
293                 pdata->vbus_pin_active_low[port];
294 }
295
296 /*
297  * Update the status data from the hub with the over-current indicator change.
298  */
299 static int ohci_at91_hub_status_data(struct usb_hcd *hcd, char *buf)
300 {
301         struct at91_usbh_data *pdata = hcd->self.controller->platform_data;
302         int length = ohci_hub_status_data(hcd, buf);
303         int port;
304
305         at91_for_each_port(port) {
306                 if (pdata->overcurrent_changed[port]) {
307                         if (!length)
308                                 length = 1;
309                         buf[0] |= 1 << (port + 1);
310                 }
311         }
312
313         return length;
314 }
315
316 /*
317  * Look at the control requests to the root hub and see if we need to override.
318  */
319 static int ohci_at91_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
320                                  u16 wIndex, char *buf, u16 wLength)
321 {
322         struct at91_usbh_data *pdata = dev_get_platdata(hcd->self.controller);
323         struct usb_hub_descriptor *desc;
324         int ret = -EINVAL;
325         u32 *data = (u32 *)buf;
326
327         dev_dbg(hcd->self.controller,
328                 "ohci_at91_hub_control(%p,0x%04x,0x%04x,0x%04x,%p,%04x)\n",
329                 hcd, typeReq, wValue, wIndex, buf, wLength);
330
331         wIndex--;
332
333         switch (typeReq) {
334         case SetPortFeature:
335                 if (wValue == USB_PORT_FEAT_POWER) {
336                         dev_dbg(hcd->self.controller, "SetPortFeat: POWER\n");
337                         if (valid_port(wIndex)) {
338                                 ohci_at91_usb_set_power(pdata, wIndex, 1);
339                                 ret = 0;
340                         }
341
342                         goto out;
343                 }
344                 break;
345
346         case ClearPortFeature:
347                 switch (wValue) {
348                 case USB_PORT_FEAT_C_OVER_CURRENT:
349                         dev_dbg(hcd->self.controller,
350                                 "ClearPortFeature: C_OVER_CURRENT\n");
351
352                         if (valid_port(wIndex)) {
353                                 pdata->overcurrent_changed[wIndex] = 0;
354                                 pdata->overcurrent_status[wIndex] = 0;
355                         }
356
357                         goto out;
358
359                 case USB_PORT_FEAT_OVER_CURRENT:
360                         dev_dbg(hcd->self.controller,
361                                 "ClearPortFeature: OVER_CURRENT\n");
362
363                         if (valid_port(wIndex))
364                                 pdata->overcurrent_status[wIndex] = 0;
365
366                         goto out;
367
368                 case USB_PORT_FEAT_POWER:
369                         dev_dbg(hcd->self.controller,
370                                 "ClearPortFeature: POWER\n");
371
372                         if (valid_port(wIndex)) {
373                                 ohci_at91_usb_set_power(pdata, wIndex, 0);
374                                 return 0;
375                         }
376                 }
377                 break;
378         }
379
380         ret = ohci_hub_control(hcd, typeReq, wValue, wIndex + 1, buf, wLength);
381         if (ret)
382                 goto out;
383
384         switch (typeReq) {
385         case GetHubDescriptor:
386
387                 /* update the hub's descriptor */
388
389                 desc = (struct usb_hub_descriptor *)buf;
390
391                 dev_dbg(hcd->self.controller, "wHubCharacteristics 0x%04x\n",
392                         desc->wHubCharacteristics);
393
394                 /* remove the old configurations for power-switching, and
395                  * over-current protection, and insert our new configuration
396                  */
397
398                 desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_LPSM);
399                 desc->wHubCharacteristics |=
400                         cpu_to_le16(HUB_CHAR_INDV_PORT_LPSM);
401
402                 if (pdata->overcurrent_supported) {
403                         desc->wHubCharacteristics &= ~cpu_to_le16(HUB_CHAR_OCPM);
404                         desc->wHubCharacteristics |=
405                                 cpu_to_le16(HUB_CHAR_INDV_PORT_OCPM);
406                 }
407
408                 dev_dbg(hcd->self.controller, "wHubCharacteristics after 0x%04x\n",
409                         desc->wHubCharacteristics);
410
411                 return ret;
412
413         case GetPortStatus:
414                 /* check port status */
415
416                 dev_dbg(hcd->self.controller, "GetPortStatus(%d)\n", wIndex);
417
418                 if (valid_port(wIndex)) {
419                         if (!ohci_at91_usb_get_power(pdata, wIndex))
420                                 *data &= ~cpu_to_le32(RH_PS_PPS);
421
422                         if (pdata->overcurrent_changed[wIndex])
423                                 *data |= cpu_to_le32(RH_PS_OCIC);
424
425                         if (pdata->overcurrent_status[wIndex])
426                                 *data |= cpu_to_le32(RH_PS_POCI);
427                 }
428         }
429
430  out:
431         return ret;
432 }
433
434 /*-------------------------------------------------------------------------*/
435
436 static irqreturn_t ohci_hcd_at91_overcurrent_irq(int irq, void *data)
437 {
438         struct platform_device *pdev = data;
439         struct at91_usbh_data *pdata = dev_get_platdata(&pdev->dev);
440         int val, gpio, port;
441
442         /* From the GPIO notifying the over-current situation, find
443          * out the corresponding port */
444         at91_for_each_port(port) {
445                 if (gpio_is_valid(pdata->overcurrent_pin[port]) &&
446                                 gpio_to_irq(pdata->overcurrent_pin[port]) == irq) {
447                         gpio = pdata->overcurrent_pin[port];
448                         break;
449                 }
450         }
451
452         if (port == AT91_MAX_USBH_PORTS) {
453                 dev_err(& pdev->dev, "overcurrent interrupt from unknown GPIO\n");
454                 return IRQ_HANDLED;
455         }
456
457         val = gpio_get_value(gpio);
458
459         /* When notified of an over-current situation, disable power
460            on the corresponding port, and mark this port in
461            over-current. */
462         if (!val) {
463                 ohci_at91_usb_set_power(pdata, port, 0);
464                 pdata->overcurrent_status[port]  = 1;
465                 pdata->overcurrent_changed[port] = 1;
466         }
467
468         dev_dbg(& pdev->dev, "overcurrent situation %s\n",
469                 val ? "exited" : "notified");
470
471         return IRQ_HANDLED;
472 }
473
474 static const struct ohci_at91_caps at91rm9200_caps = {
475         .suspend_ctrl = false,
476 };
477
478 static const struct ohci_at91_caps sama5d2_caps = {
479         .suspend_ctrl = true,
480 };
481
482 static const struct of_device_id at91_ohci_dt_ids[] = {
483         { .compatible = "atmel,at91rm9200-ohci", .data = &at91rm9200_caps },
484         { .compatible = "atmel,sama5d2-ohci", .data = &sama5d2_caps },
485         { /* sentinel */ }
486 };
487
488 MODULE_DEVICE_TABLE(of, at91_ohci_dt_ids);
489
490 /*-------------------------------------------------------------------------*/
491
492 static int ohci_hcd_at91_drv_probe(struct platform_device *pdev)
493 {
494         struct device_node *np = pdev->dev.of_node;
495         struct at91_usbh_data   *pdata;
496         int                     i;
497         int                     gpio;
498         int                     ret;
499         enum of_gpio_flags      flags;
500         u32                     ports;
501
502         /* Right now device-tree probed devices don't get dma_mask set.
503          * Since shared usb code relies on it, set it here for now.
504          * Once we have dma capability bindings this can go away.
505          */
506         ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
507         if (ret)
508                 return ret;
509
510         pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
511         if (!pdata)
512                 return -ENOMEM;
513
514         pdev->dev.platform_data = pdata;
515
516         if (!of_property_read_u32(np, "num-ports", &ports))
517                 pdata->ports = ports;
518
519         at91_for_each_port(i) {
520                 /*
521                  * do not configure PIO if not in relation with
522                  * real USB port on board
523                  */
524                 if (i >= pdata->ports) {
525                         pdata->vbus_pin[i] = -EINVAL;
526                         pdata->overcurrent_pin[i] = -EINVAL;
527                         continue;
528                 }
529
530                 gpio = of_get_named_gpio_flags(np, "atmel,vbus-gpio", i,
531                                                &flags);
532                 pdata->vbus_pin[i] = gpio;
533                 if (!gpio_is_valid(gpio))
534                         continue;
535                 pdata->vbus_pin_active_low[i] = flags & OF_GPIO_ACTIVE_LOW;
536
537                 ret = gpio_request(gpio, "ohci_vbus");
538                 if (ret) {
539                         dev_err(&pdev->dev,
540                                 "can't request vbus gpio %d\n", gpio);
541                         continue;
542                 }
543                 ret = gpio_direction_output(gpio,
544                                         !pdata->vbus_pin_active_low[i]);
545                 if (ret) {
546                         dev_err(&pdev->dev,
547                                 "can't put vbus gpio %d as output %d\n",
548                                 gpio, !pdata->vbus_pin_active_low[i]);
549                         gpio_free(gpio);
550                         continue;
551                 }
552
553                 ohci_at91_usb_set_power(pdata, i, 1);
554         }
555
556         at91_for_each_port(i) {
557                 if (i >= pdata->ports)
558                         break;
559
560                 pdata->overcurrent_pin[i] =
561                         of_get_named_gpio_flags(np, "atmel,oc-gpio", i, &flags);
562
563                 if (!gpio_is_valid(pdata->overcurrent_pin[i]))
564                         continue;
565                 gpio = pdata->overcurrent_pin[i];
566
567                 ret = gpio_request(gpio, "ohci_overcurrent");
568                 if (ret) {
569                         dev_err(&pdev->dev,
570                                 "can't request overcurrent gpio %d\n",
571                                 gpio);
572                         continue;
573                 }
574
575                 ret = gpio_direction_input(gpio);
576                 if (ret) {
577                         dev_err(&pdev->dev,
578                                 "can't configure overcurrent gpio %d as input\n",
579                                 gpio);
580                         gpio_free(gpio);
581                         continue;
582                 }
583
584                 ret = request_irq(gpio_to_irq(gpio),
585                                   ohci_hcd_at91_overcurrent_irq,
586                                   IRQF_SHARED, "ohci_overcurrent", pdev);
587                 if (ret) {
588                         gpio_free(gpio);
589                         dev_err(&pdev->dev,
590                                 "can't get gpio IRQ for overcurrent\n");
591                 }
592         }
593
594         device_init_wakeup(&pdev->dev, 1);
595         return usb_hcd_at91_probe(&ohci_at91_hc_driver, pdev);
596 }
597
598 static int ohci_hcd_at91_drv_remove(struct platform_device *pdev)
599 {
600         struct at91_usbh_data   *pdata = dev_get_platdata(&pdev->dev);
601         int                     i;
602
603         if (pdata) {
604                 at91_for_each_port(i) {
605                         if (!gpio_is_valid(pdata->vbus_pin[i]))
606                                 continue;
607                         ohci_at91_usb_set_power(pdata, i, 0);
608                         gpio_free(pdata->vbus_pin[i]);
609                 }
610
611                 at91_for_each_port(i) {
612                         if (!gpio_is_valid(pdata->overcurrent_pin[i]))
613                                 continue;
614                         free_irq(gpio_to_irq(pdata->overcurrent_pin[i]), pdev);
615                         gpio_free(pdata->overcurrent_pin[i]);
616                 }
617         }
618
619         device_init_wakeup(&pdev->dev, 0);
620         usb_hcd_at91_remove(platform_get_drvdata(pdev), pdev);
621         return 0;
622 }
623
624 static int ohci_at91_port_ctrl(struct regmap *regmap, bool enable)
625 {
626         u32 regval;
627         int ret;
628
629         if (!regmap)
630                 return -EINVAL;
631
632         ret = regmap_read(regmap, SFR_OHCIICR, &regval);
633         if (ret)
634                 return ret;
635
636         if (enable)
637                 regval &= ~SFR_OHCIICR_USB_SUSPEND;
638         else
639                 regval |= SFR_OHCIICR_USB_SUSPEND;
640
641         regmap_write(regmap, SFR_OHCIICR, regval);
642
643         return 0;
644 }
645
646 static int ohci_at91_port_suspend(struct regmap *regmap)
647 {
648         return ohci_at91_port_ctrl(regmap, false);
649 }
650
651 static int ohci_at91_port_resume(struct regmap *regmap)
652 {
653         return ohci_at91_port_ctrl(regmap, true);
654 }
655
656 static int __maybe_unused
657 ohci_hcd_at91_drv_suspend(struct device *dev)
658 {
659         struct usb_hcd  *hcd = dev_get_drvdata(dev);
660         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
661         struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
662         int             ret;
663
664         /*
665          * Disable wakeup if we are going to sleep with slow clock mode
666          * enabled.
667          */
668         ohci_at91->wakeup = device_may_wakeup(dev)
669                         && !at91_suspend_entering_slow_clock();
670
671         if (ohci_at91->wakeup)
672                 enable_irq_wake(hcd->irq);
673
674         ret = ohci_suspend(hcd, ohci_at91->wakeup);
675         if (ret) {
676                 if (ohci_at91->wakeup)
677                         disable_irq_wake(hcd->irq);
678                 return ret;
679         }
680         /*
681          * The integrated transceivers seem unable to notice disconnect,
682          * reconnect, or wakeup without the 48 MHz clock active.  so for
683          * correctness, always discard connection state (using reset).
684          *
685          * REVISIT: some boards will be able to turn VBUS off...
686          */
687         if (!ohci_at91->wakeup) {
688                 ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
689                 ohci->hc_control &= OHCI_CTRL_RWC;
690                 ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
691                 ohci->rh_state = OHCI_RH_HALTED;
692
693                 if (ohci_at91->caps->suspend_ctrl)
694                         ohci_at91_port_suspend(ohci_at91->sfr_regmap);
695
696                 /* flush the writes */
697                 (void) ohci_readl (ohci, &ohci->regs->control);
698                 at91_stop_clock(ohci_at91);
699         }
700
701         return ret;
702 }
703
704 static int __maybe_unused
705 ohci_hcd_at91_drv_resume(struct device *dev)
706 {
707         struct usb_hcd  *hcd = dev_get_drvdata(dev);
708         struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);
709
710         if (ohci_at91->wakeup)
711                 disable_irq_wake(hcd->irq);
712
713         at91_start_clock(ohci_at91);
714
715         if (ohci_at91->caps->suspend_ctrl)
716                 ohci_at91_port_resume(ohci_at91->sfr_regmap);
717
718         ohci_resume(hcd, false);
719         return 0;
720 }
721
722 static SIMPLE_DEV_PM_OPS(ohci_hcd_at91_pm_ops, ohci_hcd_at91_drv_suspend,
723                                         ohci_hcd_at91_drv_resume);
724
725 static struct platform_driver ohci_hcd_at91_driver = {
726         .probe          = ohci_hcd_at91_drv_probe,
727         .remove         = ohci_hcd_at91_drv_remove,
728         .shutdown       = usb_hcd_platform_shutdown,
729         .driver         = {
730                 .name   = "at91_ohci",
731                 .pm     = &ohci_hcd_at91_pm_ops,
732                 .of_match_table = at91_ohci_dt_ids,
733         },
734 };
735
736 static int __init ohci_at91_init(void)
737 {
738         if (usb_disabled())
739                 return -ENODEV;
740
741         pr_info("%s: " DRIVER_DESC "\n", hcd_name);
742         ohci_init_driver(&ohci_at91_hc_driver, &ohci_at91_drv_overrides);
743
744         /*
745          * The Atmel HW has some unusual quirks, which require Atmel-specific
746          * workarounds. We override certain hc_driver functions here to
747          * achieve that. We explicitly do not enhance ohci_driver_overrides to
748          * allow this more easily, since this is an unusual case, and we don't
749          * want to encourage others to override these functions by making it
750          * too easy.
751          */
752
753         ohci_at91_hc_driver.hub_status_data     = ohci_at91_hub_status_data;
754         ohci_at91_hc_driver.hub_control         = ohci_at91_hub_control;
755
756         return platform_driver_register(&ohci_hcd_at91_driver);
757 }
758 module_init(ohci_at91_init);
759
760 static void __exit ohci_at91_cleanup(void)
761 {
762         platform_driver_unregister(&ohci_hcd_at91_driver);
763 }
764 module_exit(ohci_at91_cleanup);
765
766 MODULE_DESCRIPTION(DRIVER_DESC);
767 MODULE_LICENSE("GPL");
768 MODULE_ALIAS("platform:at91_ohci");