2 * Generic platform ohci driver
4 * Copyright 2007 Michael Buesch <m@bues.ch>
5 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * Derived from the OCHI-SSB driver
8 * Derived from the OHCI-PCI driver
9 * Copyright 1999 Roman Weissgaerber
10 * Copyright 2000-2002 David Brownell
11 * Copyright 1999 Linus Torvalds
12 * Copyright 1999 Gregory P. Smith
14 * Licensed under the GNU/GPL. See COPYING for details.
16 #include <linux/platform_device.h>
17 #include <linux/usb/ohci_pdriver.h>
19 static int ohci_platform_reset(struct usb_hcd
*hcd
)
21 struct platform_device
*pdev
= to_platform_device(hcd
->self
.controller
);
22 struct usb_ohci_pdata
*pdata
= pdev
->dev
.platform_data
;
23 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
26 if (pdata
->big_endian_desc
)
27 ohci
->flags
|= OHCI_QUIRK_BE_DESC
;
28 if (pdata
->big_endian_mmio
)
29 ohci
->flags
|= OHCI_QUIRK_BE_MMIO
;
30 if (pdata
->no_big_frame_no
)
31 ohci
->flags
|= OHCI_QUIRK_FRAME_NO
;
36 ohci
->num_ports
= pdata
->num_ports
;
38 err
= ohci_init(ohci
);
43 static int ohci_platform_start(struct usb_hcd
*hcd
)
45 struct ohci_hcd
*ohci
= hcd_to_ohci(hcd
);
50 ohci_err(ohci
, "can't start\n");
57 static const struct hc_driver ohci_platform_hc_driver
= {
58 .description
= hcd_name
,
59 .product_desc
= "Generic Platform OHCI Controller",
60 .hcd_priv_size
= sizeof(struct ohci_hcd
),
63 .flags
= HCD_MEMORY
| HCD_USB11
,
65 .reset
= ohci_platform_reset
,
66 .start
= ohci_platform_start
,
68 .shutdown
= ohci_shutdown
,
70 .urb_enqueue
= ohci_urb_enqueue
,
71 .urb_dequeue
= ohci_urb_dequeue
,
72 .endpoint_disable
= ohci_endpoint_disable
,
74 .get_frame_number
= ohci_get_frame
,
76 .hub_status_data
= ohci_hub_status_data
,
77 .hub_control
= ohci_hub_control
,
79 .bus_suspend
= ohci_bus_suspend
,
80 .bus_resume
= ohci_bus_resume
,
83 .start_port_reset
= ohci_start_port_reset
,
86 static int ohci_platform_probe(struct platform_device
*dev
)
89 struct resource
*res_mem
;
90 struct usb_ohci_pdata
*pdata
= dev
->dev
.platform_data
;
102 irq
= platform_get_irq(dev
, 0);
104 dev_err(&dev
->dev
, "no irq provided");
108 res_mem
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
110 dev_err(&dev
->dev
, "no memory resource provided");
114 if (pdata
->power_on
) {
115 err
= pdata
->power_on(dev
);
120 hcd
= usb_create_hcd(&ohci_platform_hc_driver
, &dev
->dev
,
121 dev_name(&dev
->dev
));
127 hcd
->rsrc_start
= res_mem
->start
;
128 hcd
->rsrc_len
= resource_size(res_mem
);
130 hcd
->regs
= devm_request_and_ioremap(&dev
->dev
, res_mem
);
135 err
= usb_add_hcd(hcd
, irq
, IRQF_SHARED
);
139 platform_set_drvdata(dev
, hcd
);
146 if (pdata
->power_off
)
147 pdata
->power_off(dev
);
152 static int ohci_platform_remove(struct platform_device
*dev
)
154 struct usb_hcd
*hcd
= platform_get_drvdata(dev
);
155 struct usb_ohci_pdata
*pdata
= dev
->dev
.platform_data
;
159 platform_set_drvdata(dev
, NULL
);
161 if (pdata
->power_off
)
162 pdata
->power_off(dev
);
169 static int ohci_platform_suspend(struct device
*dev
)
171 struct usb_ohci_pdata
*pdata
= dev
->platform_data
;
172 struct platform_device
*pdev
=
173 container_of(dev
, struct platform_device
, dev
);
175 if (pdata
->power_suspend
)
176 pdata
->power_suspend(pdev
);
181 static int ohci_platform_resume(struct device
*dev
)
183 struct usb_hcd
*hcd
= dev_get_drvdata(dev
);
184 struct usb_ohci_pdata
*pdata
= dev
->platform_data
;
185 struct platform_device
*pdev
=
186 container_of(dev
, struct platform_device
, dev
);
188 if (pdata
->power_on
) {
189 int err
= pdata
->power_on(pdev
);
194 ohci_resume(hcd
, false);
198 #else /* !CONFIG_PM */
199 #define ohci_platform_suspend NULL
200 #define ohci_platform_resume NULL
201 #endif /* CONFIG_PM */
203 static const struct platform_device_id ohci_platform_table
[] = {
204 { "ohci-platform", 0 },
207 MODULE_DEVICE_TABLE(platform
, ohci_platform_table
);
209 static const struct dev_pm_ops ohci_platform_pm_ops
= {
210 .suspend
= ohci_platform_suspend
,
211 .resume
= ohci_platform_resume
,
214 static struct platform_driver ohci_platform_driver
= {
215 .id_table
= ohci_platform_table
,
216 .probe
= ohci_platform_probe
,
217 .remove
= ohci_platform_remove
,
218 .shutdown
= usb_hcd_platform_shutdown
,
220 .owner
= THIS_MODULE
,
221 .name
= "ohci-platform",
222 .pm
= &ohci_platform_pm_ops
,