Linux 4.2.1
[linux/fpc-iii.git] / drivers / usb / host / ehci-pmcmsp.c
blob342816a7f8b148956897f866e28671de0f4923f7
1 /*
2 * PMC MSP EHCI (Host Controller Driver) for USB.
4 * (C) Copyright 2006-2010 PMC-Sierra Inc
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
12 /* includes */
13 #include <linux/platform_device.h>
14 #include <linux/gpio.h>
15 #include <linux/usb.h>
16 #include <msp_usb.h>
18 /* stream disable*/
19 #define USB_CTRL_MODE_STREAM_DISABLE 0x10
21 /* threshold */
22 #define USB_CTRL_FIFO_THRESH 0x00300000
24 /* register offset for usb_mode */
25 #define USB_EHCI_REG_USB_MODE 0x68
27 /* register offset for usb fifo */
28 #define USB_EHCI_REG_USB_FIFO 0x24
30 /* register offset for usb status */
31 #define USB_EHCI_REG_USB_STATUS 0x44
33 /* serial/parallel transceiver */
34 #define USB_EHCI_REG_BIT_STAT_STS (1<<29)
36 /* TWI USB0 host device pin */
37 #define MSP_PIN_USB0_HOST_DEV 49
39 /* TWI USB1 host device pin */
40 #define MSP_PIN_USB1_HOST_DEV 50
43 static void usb_hcd_tdi_set_mode(struct ehci_hcd *ehci)
45 u8 *base;
46 u8 *statreg;
47 u8 *fiforeg;
48 u32 val;
49 struct ehci_regs *reg_base = ehci->regs;
51 /* get register base */
52 base = (u8 *)reg_base + USB_EHCI_REG_USB_MODE;
53 statreg = (u8 *)reg_base + USB_EHCI_REG_USB_STATUS;
54 fiforeg = (u8 *)reg_base + USB_EHCI_REG_USB_FIFO;
56 /* Disable controller mode stream */
57 val = ehci_readl(ehci, (u32 *)base);
58 ehci_writel(ehci, (val | USB_CTRL_MODE_STREAM_DISABLE),
59 (u32 *)base);
61 /* clear STS to select parallel transceiver interface */
62 val = ehci_readl(ehci, (u32 *)statreg);
63 val = val & ~USB_EHCI_REG_BIT_STAT_STS;
64 ehci_writel(ehci, val, (u32 *)statreg);
66 /* write to set the proper fifo threshold */
67 ehci_writel(ehci, USB_CTRL_FIFO_THRESH, (u32 *)fiforeg);
69 /* set TWI GPIO USB_HOST_DEV pin high */
70 gpio_direction_output(MSP_PIN_USB0_HOST_DEV, 1);
73 /* called during probe() after chip reset completes */
74 static int ehci_msp_setup(struct usb_hcd *hcd)
76 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
77 int retval;
79 ehci->big_endian_mmio = 1;
80 ehci->big_endian_desc = 1;
82 ehci->caps = hcd->regs;
83 hcd->has_tt = 1;
85 retval = ehci_setup(hcd);
86 if (retval)
87 return retval;
89 usb_hcd_tdi_set_mode(ehci);
91 return retval;
95 /* configure so an HC device and id are always provided
96 * always called with process context; sleeping is OK
99 static int usb_hcd_msp_map_regs(struct mspusb_device *dev)
101 struct resource *res;
102 struct platform_device *pdev = &dev->dev;
103 u32 res_len;
104 int retval;
106 /* MAB register space */
107 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
108 if (res == NULL)
109 return -ENOMEM;
110 res_len = resource_size(res);
111 if (!request_mem_region(res->start, res_len, "mab regs"))
112 return -EBUSY;
114 dev->mab_regs = ioremap_nocache(res->start, res_len);
115 if (dev->mab_regs == NULL) {
116 retval = -ENOMEM;
117 goto err1;
120 /* MSP USB register space */
121 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
122 if (res == NULL) {
123 retval = -ENOMEM;
124 goto err2;
126 res_len = resource_size(res);
127 if (!request_mem_region(res->start, res_len, "usbid regs")) {
128 retval = -EBUSY;
129 goto err2;
131 dev->usbid_regs = ioremap_nocache(res->start, res_len);
132 if (dev->usbid_regs == NULL) {
133 retval = -ENOMEM;
134 goto err3;
137 return 0;
138 err3:
139 res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
140 res_len = resource_size(res);
141 release_mem_region(res->start, res_len);
142 err2:
143 iounmap(dev->mab_regs);
144 err1:
145 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
146 res_len = resource_size(res);
147 release_mem_region(res->start, res_len);
148 dev_err(&pdev->dev, "Failed to map non-EHCI regs.\n");
149 return retval;
153 * usb_hcd_msp_probe - initialize PMC MSP-based HCDs
154 * Context: !in_interrupt()
156 * Allocates basic resources for this USB host controller, and
157 * then invokes the start() method for the HCD associated with it
158 * through the hotplug entry's driver_data.
161 int usb_hcd_msp_probe(const struct hc_driver *driver,
162 struct platform_device *dev)
164 int retval;
165 struct usb_hcd *hcd;
166 struct resource *res;
167 struct ehci_hcd *ehci ;
169 hcd = usb_create_hcd(driver, &dev->dev, "pmcmsp");
170 if (!hcd)
171 return -ENOMEM;
173 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
174 if (res == NULL) {
175 pr_debug("No IOMEM resource info for %s.\n", dev->name);
176 retval = -ENOMEM;
177 goto err1;
179 hcd->rsrc_start = res->start;
180 hcd->rsrc_len = resource_size(res);
181 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, dev->name)) {
182 retval = -EBUSY;
183 goto err1;
185 hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
186 if (!hcd->regs) {
187 pr_debug("ioremap failed");
188 retval = -ENOMEM;
189 goto err2;
192 res = platform_get_resource(dev, IORESOURCE_IRQ, 0);
193 if (res == NULL) {
194 dev_err(&dev->dev, "No IRQ resource info for %s.\n", dev->name);
195 retval = -ENOMEM;
196 goto err3;
199 /* Map non-EHCI register spaces */
200 retval = usb_hcd_msp_map_regs(to_mspusb_device(dev));
201 if (retval != 0)
202 goto err3;
204 ehci = hcd_to_ehci(hcd);
205 ehci->big_endian_mmio = 1;
206 ehci->big_endian_desc = 1;
209 retval = usb_add_hcd(hcd, res->start, IRQF_SHARED);
210 if (retval == 0) {
211 device_wakeup_enable(hcd->self.controller);
212 return 0;
215 usb_remove_hcd(hcd);
216 err3:
217 iounmap(hcd->regs);
218 err2:
219 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
220 err1:
221 usb_put_hcd(hcd);
223 return retval;
229 * usb_hcd_msp_remove - shutdown processing for PMC MSP-based HCDs
230 * @dev: USB Host Controller being removed
231 * Context: !in_interrupt()
233 * Reverses the effect of usb_hcd_msp_probe(), first invoking
234 * the HCD's stop() method. It is always called from a thread
235 * context, normally "rmmod", "apmd", or something similar.
237 * may be called without controller electrically present
238 * may be called with controller, bus, and devices active
240 void usb_hcd_msp_remove(struct usb_hcd *hcd, struct platform_device *dev)
242 usb_remove_hcd(hcd);
243 iounmap(hcd->regs);
244 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
245 usb_put_hcd(hcd);
248 static const struct hc_driver ehci_msp_hc_driver = {
249 .description = hcd_name,
250 .product_desc = "PMC MSP EHCI",
251 .hcd_priv_size = sizeof(struct ehci_hcd),
254 * generic hardware linkage
256 .irq = ehci_irq,
257 .flags = HCD_MEMORY | HCD_USB2 | HCD_BH,
260 * basic lifecycle operations
262 .reset = ehci_msp_setup,
263 .shutdown = ehci_shutdown,
264 .start = ehci_run,
265 .stop = ehci_stop,
268 * managing i/o requests and associated device resources
270 .urb_enqueue = ehci_urb_enqueue,
271 .urb_dequeue = ehci_urb_dequeue,
272 .endpoint_disable = ehci_endpoint_disable,
273 .endpoint_reset = ehci_endpoint_reset,
276 * scheduling support
278 .get_frame_number = ehci_get_frame,
281 * root hub support
283 .hub_status_data = ehci_hub_status_data,
284 .hub_control = ehci_hub_control,
285 .bus_suspend = ehci_bus_suspend,
286 .bus_resume = ehci_bus_resume,
287 .relinquish_port = ehci_relinquish_port,
288 .port_handed_over = ehci_port_handed_over,
290 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
293 static int ehci_hcd_msp_drv_probe(struct platform_device *pdev)
295 int ret;
297 pr_debug("In ehci_hcd_msp_drv_probe");
299 if (usb_disabled())
300 return -ENODEV;
302 gpio_request(MSP_PIN_USB0_HOST_DEV, "USB0_HOST_DEV_GPIO");
304 ret = usb_hcd_msp_probe(&ehci_msp_hc_driver, pdev);
306 return ret;
309 static int ehci_hcd_msp_drv_remove(struct platform_device *pdev)
311 struct usb_hcd *hcd = platform_get_drvdata(pdev);
313 usb_hcd_msp_remove(hcd, pdev);
315 /* free TWI GPIO USB_HOST_DEV pin */
316 gpio_free(MSP_PIN_USB0_HOST_DEV);
318 return 0;
321 MODULE_ALIAS("pmcmsp-ehci");
323 static struct platform_driver ehci_hcd_msp_driver = {
324 .probe = ehci_hcd_msp_drv_probe,
325 .remove = ehci_hcd_msp_drv_remove,
326 .driver = {
327 .name = "pmcmsp-ehci",