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 int ohci_rk_init(struct usb_hcd *hcd)
21 dev_dbg(hcd->self.controller, "starting OHCI controller\n");
23 return ohci_init(hcd_to_ohci(hcd));
26 static int ohci_rk_start(struct usb_hcd *hcd)
28 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
32 * RemoteWakeupConnected has to be set explicitly before
33 * calling ohci_run. The reset value of RWC is 0.
35 ohci->hc_control = OHCI_CTRL_RWC;
36 writel(OHCI_CTRL_RWC, &ohci->regs->control);
41 dev_err(hcd->self.controller, "can't start\n");
48 static const struct hc_driver ohci_rk_hc_driver = {
49 .description = hcd_name,
50 .product_desc = "RK OHCI Host Controller",
51 .hcd_priv_size = sizeof(struct ohci_hcd),
54 * generic hardware linkage
57 .flags = HCD_USB11 | HCD_MEMORY,
60 * basic lifecycle operations
62 .reset = ohci_rk_init,
63 .start = ohci_rk_start,
65 .shutdown = ohci_shutdown,
68 * managing i/o requests and associated device resources
70 .urb_enqueue = ohci_urb_enqueue,
71 .urb_dequeue = ohci_urb_dequeue,
72 .endpoint_disable = ohci_endpoint_disable,
77 .get_frame_number = ohci_get_frame,
82 .hub_status_data = ohci_hub_status_data,
83 .hub_control = ohci_hub_control,
85 .bus_suspend = ohci_bus_suspend,
86 .bus_resume = ohci_bus_resume,
88 .start_port_reset = ohci_start_port_reset,
91 static struct of_device_id rk_ohci_of_match[] = {
93 .compatible = "rockchip,rk3126_ohci",
94 .data = &usb20ohci_pdata_rk3126,
99 MODULE_DEVICE_TABLE(of, rk_ohci_of_match);
101 /* ohci_hcd_rk_probe - initialize RK-based HCDs
102 * Allocates basic resources for this USB host controller, and
103 * then invokes the start() method for the HCD associated with it
104 * through the hotplug entry's driver_data.
106 static int ohci_hcd_rk_probe(struct platform_device *pdev)
108 struct device *dev = &pdev->dev;
109 struct usb_hcd *hcd = NULL;
110 void __iomem *regs = NULL;
111 struct resource *res;
114 struct dwc_otg_platform_data *pldata;
115 const struct of_device_id *match;
117 dev_dbg(&pdev->dev, "ohci_hcd_rk_probe\n");
122 match = of_match_device(of_match_ptr(rk_ohci_of_match), &pdev->dev);
124 pldata = (struct dwc_otg_platform_data *)match->data;
126 dev_err(dev, "ohci_rk match failed\n");
131 dev->platform_data = pldata;
136 if (pldata->clock_init) {
137 pldata->clock_init(pldata);
138 pldata->clock_enable(pldata, 1);
141 irq = platform_get_irq(pdev, 0);
143 dev_err(dev, "OHCI irq failed\n");
148 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
150 dev_err(dev, "UHH OHCI get resource failed\n");
155 regs = devm_ioremap_resource(dev, res);
157 dev_err(dev, "UHH OHCI ioremap failed\n");
163 * Right now device-tree probed devices don't get dma_mask set.
164 * Since shared usb code relies on it, set it here for now.
165 * Once we have dma capability bindings this can go away.
168 dev->dma_mask = &dev->coherent_dma_mask;
169 if (!dev->coherent_dma_mask)
170 dev->coherent_dma_mask = DMA_BIT_MASK(32);
172 hcd = usb_create_hcd(&ohci_rk_hc_driver, dev, dev_name(dev));
174 dev_err(dev, "usb_create_hcd failed\n");
179 hcd->rsrc_start = res->start;
180 hcd->rsrc_len = resource_size(res);
183 ohci_hcd_init(hcd_to_ohci(hcd));
185 ret = usb_add_hcd(hcd, irq, 0);
187 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
197 if (pldata->clock_enable)
198 pldata->clock_enable(pldata, 0);
203 static int ohci_hcd_rk_remove(struct platform_device *pdev)
205 struct device *dev = &pdev->dev;
206 struct usb_hcd *hcd = dev_get_drvdata(dev);
213 static void ohci_hcd_rk_shutdown(struct platform_device *pdev)
215 struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
217 if (hcd->driver->shutdown)
218 hcd->driver->shutdown(hcd);
221 static struct platform_driver ohci_hcd_rk_driver = {
222 .probe = ohci_hcd_rk_probe,
223 .remove = ohci_hcd_rk_remove,
224 .shutdown = ohci_hcd_rk_shutdown,
226 .name = "ohci-rockchip",
227 .of_match_table = of_match_ptr(rk_ohci_of_match),
231 MODULE_ALIAS("platform:rockchip-ohci");