2 * ROCKCHIP USB HOST OHCI Controller
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
11 #include <linux/platform_device.h>
12 #include <linux/pm_runtime.h>
14 #include <linux/clk.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/of_platform.h>
17 #include "../dwc_otg_310/usbdev_rk.h"
19 static struct rkehci_pdata_id rkohci_pdata[] = {
21 .name = "rk3188-reserved",
25 .name = "rk3288-ohci",
26 .pdata = &rkohci_pdata_rk3288,
31 static int ohci_rk_init(struct usb_hcd *hcd)
33 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
35 return ohci_init(hcd_to_ohci(hcd));
38 static int ohci_rk_start(struct usb_hcd *hcd)
40 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
44 * RemoteWakeupConnected has to be set explicitly before
45 * calling ohci_run. The reset value of RWC is 0.
47 ohci->hc_control = OHCI_CTRL_RWC;
48 writel(OHCI_CTRL_RWC, &ohci->regs->control);
53 dev_err(hcd->self.controller, "can't start\n");
60 static const struct hc_driver ohci_rk_hc_driver = {
61 .description = hcd_name,
62 .product_desc = "RK OHCI Host Controller",
63 .hcd_priv_size = sizeof(struct ohci_hcd),
66 * generic hardware linkage
69 .flags = HCD_USB11 | HCD_MEMORY,
72 * basic lifecycle operations
74 .reset = ohci_rk_init,
75 .start = ohci_rk_start,
77 .shutdown = ohci_shutdown,
80 * managing i/o requests and associated device resources
82 .urb_enqueue = ohci_urb_enqueue,
83 .urb_dequeue = ohci_urb_dequeue,
84 .endpoint_disable = ohci_endpoint_disable,
89 .get_frame_number = ohci_get_frame,
94 .hub_status_data = ohci_hub_status_data,
95 .hub_control = ohci_hub_control,
97 .bus_suspend = ohci_bus_suspend,
98 .bus_resume = ohci_bus_resume,
100 .start_port_reset = ohci_start_port_reset,
103 static struct of_device_id rk_ohci_of_match[] = {
105 .compatible = "rockchip,rk3288_rk_ohci_host",
106 .data = &rkohci_pdata[RK3288_USB_CTLR],
111 MODULE_DEVICE_TABLE(of, rk_ohci_of_match);
113 /* ohci_hcd_rk_probe - initialize RK-based HCDs
114 * Allocates basic resources for this USB host controller, and
115 * then invokes the start() method for the HCD associated with it
116 * through the hotplug entry's driver_data.
118 static int ohci_hcd_rk_probe(struct platform_device *pdev)
120 struct device *dev = &pdev->dev;
121 struct usb_hcd *hcd = NULL;
122 void __iomem *regs = NULL;
123 struct resource *res;
126 struct rkehci_platform_data *pldata;
127 struct device_node *node = pdev->dev.of_node;
128 struct rkehci_pdata_id *p;
129 const struct of_device_id *match =
130 of_match_device(of_match_ptr(rk_ohci_of_match), &pdev->dev);
132 dev_dbg(&pdev->dev, "ohci_hcd_rk_probe\n");
138 p = (struct rkehci_pdata_id *)match->data;
140 dev_err(dev, "ohci_rk match failed\n");
144 dev->platform_data = p->pdata;
145 pldata = dev->platform_data;
149 dev_err(dev, "device node not found\n");
156 if (pldata->clock_init) {
157 pldata->clock_init(pldata);
158 pldata->clock_enable(pldata, 1);
161 if (pldata->soft_reset)
162 pldata->soft_reset();
164 irq = platform_get_irq(pdev, 0);
166 dev_err(dev, "OHCI irq failed\n");
171 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
173 dev_err(dev, "UHH OHCI get resource failed\n");
178 regs = devm_ioremap_resource(dev, res);
180 dev_err(dev, "UHH OHCI ioremap failed\n");
186 * Right now device-tree probed devices don't get dma_mask set.
187 * Since shared usb code relies on it, set it here for now.
188 * Once we have dma capability bindings this can go away.
191 dev->dma_mask = &dev->coherent_dma_mask;
192 if (!dev->coherent_dma_mask)
193 dev->coherent_dma_mask = DMA_BIT_MASK(32);
195 hcd = usb_create_hcd(&ohci_rk_hc_driver, dev, dev_name(dev));
197 dev_err(dev, "usb_create_hcd failed\n");
202 hcd->rsrc_start = res->start;
203 hcd->rsrc_len = resource_size(res);
206 ohci_hcd_init(hcd_to_ohci(hcd));
208 ret = usb_add_hcd(hcd, irq, 0);
210 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
220 if (pldata->clock_enable)
221 pldata->clock_enable(pldata, 0);
226 static int ohci_hcd_rk_remove(struct platform_device *pdev)
228 struct device *dev = &pdev->dev;
229 struct usb_hcd *hcd = dev_get_drvdata(dev);
236 static void ohci_hcd_rk_shutdown(struct platform_device *pdev)
238 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
240 if (hcd->driver->shutdown)
241 hcd->driver->shutdown(hcd);
244 static struct platform_driver ohci_hcd_rk_driver = {
245 .probe = ohci_hcd_rk_probe,
246 .remove = ohci_hcd_rk_remove,
247 .shutdown = ohci_hcd_rk_shutdown,
249 .name = "ohci-rockchip",
250 .of_match_table = of_match_ptr(rk_ohci_of_match),
254 MODULE_ALIAS("platform:rockchip-ohci");