1 // SPDX-License-Identifier: GPL-2.0
3 * PMC MSP EHCI (Host Controller Driver) for USB.
5 * (C) Copyright 2006-2010 PMC-Sierra Inc
9 #include <linux/platform_device.h>
10 #include <linux/gpio.h>
11 #include <linux/usb.h>
15 #define USB_CTRL_MODE_STREAM_DISABLE 0x10
18 #define USB_CTRL_FIFO_THRESH 0x00300000
20 /* register offset for usb_mode */
21 #define USB_EHCI_REG_USB_MODE 0x68
23 /* register offset for usb fifo */
24 #define USB_EHCI_REG_USB_FIFO 0x24
26 /* register offset for usb status */
27 #define USB_EHCI_REG_USB_STATUS 0x44
29 /* serial/parallel transceiver */
30 #define USB_EHCI_REG_BIT_STAT_STS (1<<29)
32 /* TWI USB0 host device pin */
33 #define MSP_PIN_USB0_HOST_DEV 49
35 /* TWI USB1 host device pin */
36 #define MSP_PIN_USB1_HOST_DEV 50
39 static void usb_hcd_tdi_set_mode(struct ehci_hcd
*ehci
)
45 struct ehci_regs
*reg_base
= ehci
->regs
;
47 /* get register base */
48 base
= (u8
*)reg_base
+ USB_EHCI_REG_USB_MODE
;
49 statreg
= (u8
*)reg_base
+ USB_EHCI_REG_USB_STATUS
;
50 fiforeg
= (u8
*)reg_base
+ USB_EHCI_REG_USB_FIFO
;
52 /* Disable controller mode stream */
53 val
= ehci_readl(ehci
, (u32
*)base
);
54 ehci_writel(ehci
, (val
| USB_CTRL_MODE_STREAM_DISABLE
),
57 /* clear STS to select parallel transceiver interface */
58 val
= ehci_readl(ehci
, (u32
*)statreg
);
59 val
= val
& ~USB_EHCI_REG_BIT_STAT_STS
;
60 ehci_writel(ehci
, val
, (u32
*)statreg
);
62 /* write to set the proper fifo threshold */
63 ehci_writel(ehci
, USB_CTRL_FIFO_THRESH
, (u32
*)fiforeg
);
65 /* set TWI GPIO USB_HOST_DEV pin high */
66 gpio_direction_output(MSP_PIN_USB0_HOST_DEV
, 1);
69 /* called during probe() after chip reset completes */
70 static int ehci_msp_setup(struct usb_hcd
*hcd
)
72 struct ehci_hcd
*ehci
= hcd_to_ehci(hcd
);
75 ehci
->big_endian_mmio
= 1;
76 ehci
->big_endian_desc
= 1;
78 ehci
->caps
= hcd
->regs
;
81 retval
= ehci_setup(hcd
);
85 usb_hcd_tdi_set_mode(ehci
);
91 /* configure so an HC device and id are always provided
92 * always called with process context; sleeping is OK
95 static int usb_hcd_msp_map_regs(struct mspusb_device
*dev
)
98 struct platform_device
*pdev
= &dev
->dev
;
102 /* MAB register space */
103 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
106 res_len
= resource_size(res
);
107 if (!request_mem_region(res
->start
, res_len
, "mab regs"))
110 dev
->mab_regs
= ioremap_nocache(res
->start
, res_len
);
111 if (dev
->mab_regs
== NULL
) {
116 /* MSP USB register space */
117 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 2);
122 res_len
= resource_size(res
);
123 if (!request_mem_region(res
->start
, res_len
, "usbid regs")) {
127 dev
->usbid_regs
= ioremap_nocache(res
->start
, res_len
);
128 if (dev
->usbid_regs
== NULL
) {
135 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 2);
136 res_len
= resource_size(res
);
137 release_mem_region(res
->start
, res_len
);
139 iounmap(dev
->mab_regs
);
141 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
142 res_len
= resource_size(res
);
143 release_mem_region(res
->start
, res_len
);
144 dev_err(&pdev
->dev
, "Failed to map non-EHCI regs.\n");
149 * usb_hcd_msp_probe - initialize PMC MSP-based HCDs
150 * Context: !in_interrupt()
152 * Allocates basic resources for this USB host controller, and
153 * then invokes the start() method for the HCD associated with it
154 * through the hotplug entry's driver_data.
157 int usb_hcd_msp_probe(const struct hc_driver
*driver
,
158 struct platform_device
*dev
)
162 struct resource
*res
;
163 struct ehci_hcd
*ehci
;
165 hcd
= usb_create_hcd(driver
, &dev
->dev
, "pmcmsp");
169 res
= platform_get_resource(dev
, IORESOURCE_MEM
, 0);
171 pr_debug("No IOMEM resource info for %s.\n", dev
->name
);
175 hcd
->rsrc_start
= res
->start
;
176 hcd
->rsrc_len
= resource_size(res
);
177 if (!request_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
, dev
->name
)) {
181 hcd
->regs
= ioremap_nocache(hcd
->rsrc_start
, hcd
->rsrc_len
);
183 pr_debug("ioremap failed");
188 res
= platform_get_resource(dev
, IORESOURCE_IRQ
, 0);
190 dev_err(&dev
->dev
, "No IRQ resource info for %s.\n", dev
->name
);
195 /* Map non-EHCI register spaces */
196 retval
= usb_hcd_msp_map_regs(to_mspusb_device(dev
));
200 ehci
= hcd_to_ehci(hcd
);
201 ehci
->big_endian_mmio
= 1;
202 ehci
->big_endian_desc
= 1;
205 retval
= usb_add_hcd(hcd
, res
->start
, IRQF_SHARED
);
207 device_wakeup_enable(hcd
->self
.controller
);
215 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
225 * usb_hcd_msp_remove - shutdown processing for PMC MSP-based HCDs
226 * @dev: USB Host Controller being removed
227 * Context: !in_interrupt()
229 * Reverses the effect of usb_hcd_msp_probe(), first invoking
230 * the HCD's stop() method. It is always called from a thread
231 * context, normally "rmmod", "apmd", or something similar.
233 * may be called without controller electrically present
234 * may be called with controller, bus, and devices active
236 void usb_hcd_msp_remove(struct usb_hcd
*hcd
, struct platform_device
*dev
)
240 release_mem_region(hcd
->rsrc_start
, hcd
->rsrc_len
);
244 static const struct hc_driver ehci_msp_hc_driver
= {
245 .description
= hcd_name
,
246 .product_desc
= "PMC MSP EHCI",
247 .hcd_priv_size
= sizeof(struct ehci_hcd
),
250 * generic hardware linkage
253 .flags
= HCD_MEMORY
| HCD_USB2
| HCD_BH
,
256 * basic lifecycle operations
258 .reset
= ehci_msp_setup
,
259 .shutdown
= ehci_shutdown
,
264 * managing i/o requests and associated device resources
266 .urb_enqueue
= ehci_urb_enqueue
,
267 .urb_dequeue
= ehci_urb_dequeue
,
268 .endpoint_disable
= ehci_endpoint_disable
,
269 .endpoint_reset
= ehci_endpoint_reset
,
274 .get_frame_number
= ehci_get_frame
,
279 .hub_status_data
= ehci_hub_status_data
,
280 .hub_control
= ehci_hub_control
,
281 .bus_suspend
= ehci_bus_suspend
,
282 .bus_resume
= ehci_bus_resume
,
283 .relinquish_port
= ehci_relinquish_port
,
284 .port_handed_over
= ehci_port_handed_over
,
286 .clear_tt_buffer_complete
= ehci_clear_tt_buffer_complete
,
289 static int ehci_hcd_msp_drv_probe(struct platform_device
*pdev
)
293 pr_debug("In ehci_hcd_msp_drv_probe");
298 gpio_request(MSP_PIN_USB0_HOST_DEV
, "USB0_HOST_DEV_GPIO");
300 ret
= usb_hcd_msp_probe(&ehci_msp_hc_driver
, pdev
);
305 static int ehci_hcd_msp_drv_remove(struct platform_device
*pdev
)
307 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
309 usb_hcd_msp_remove(hcd
, pdev
);
311 /* free TWI GPIO USB_HOST_DEV pin */
312 gpio_free(MSP_PIN_USB0_HOST_DEV
);
317 MODULE_ALIAS("pmcmsp-ehci");
319 static struct platform_driver ehci_hcd_msp_driver
= {
320 .probe
= ehci_hcd_msp_drv_probe
,
321 .remove
= ehci_hcd_msp_drv_remove
,
323 .name
= "pmcmsp-ehci",