USB: fix Coding Style.
[firefly-linux-kernel-4.4.55.git] / drivers / usb / host / ohci-rockchip.c
1 /*
2  * ROCKCHIP USB HOST OHCI Controller
3  *
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.
8  *
9  */
10
11 #include <linux/platform_device.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/of.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"
18
19 static struct rkehci_pdata_id rkohci_pdata[] = {
20         {
21          .name = "rk3188-reserved",
22          .pdata = NULL,
23          },
24         {
25          .name = "rk3288-ohci",
26          .pdata = &rkohci_pdata_rk3288,
27          },
28         {},
29 };
30
31 static int ohci_rk_init(struct usb_hcd *hcd)
32 {
33         dev_dbg(hcd->self.controller, "starting OHCI controller\n");
34
35         return ohci_init(hcd_to_ohci(hcd));
36 }
37
38 static int ohci_rk_start(struct usb_hcd *hcd)
39 {
40         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
41         int ret;
42
43         /*
44          * RemoteWakeupConnected has to be set explicitly before
45          * calling ohci_run. The reset value of RWC is 0.
46          */
47         ohci->hc_control = OHCI_CTRL_RWC;
48         writel(OHCI_CTRL_RWC, &ohci->regs->control);
49
50         ret = ohci_run(ohci);
51
52         if (ret < 0) {
53                 dev_err(hcd->self.controller, "can't start\n");
54                 ohci_stop(hcd);
55         }
56
57         return ret;
58 }
59
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),
64
65         /*
66          * generic hardware linkage
67          */
68         .irq = ohci_irq,
69         .flags = HCD_USB11 | HCD_MEMORY,
70
71         /*
72          * basic lifecycle operations
73          */
74         .reset = ohci_rk_init,
75         .start = ohci_rk_start,
76         .stop = ohci_stop,
77         .shutdown = ohci_shutdown,
78
79         /*
80          * managing i/o requests and associated device resources
81          */
82         .urb_enqueue = ohci_urb_enqueue,
83         .urb_dequeue = ohci_urb_dequeue,
84         .endpoint_disable = ohci_endpoint_disable,
85
86         /*
87          * scheduling support
88          */
89         .get_frame_number = ohci_get_frame,
90
91         /*
92          * root hub support
93          */
94         .hub_status_data = ohci_hub_status_data,
95         .hub_control = ohci_hub_control,
96 #ifdef  CONFIG_PM
97         .bus_suspend = ohci_bus_suspend,
98         .bus_resume = ohci_bus_resume,
99 #endif
100         .start_port_reset = ohci_start_port_reset,
101 };
102
103 static struct of_device_id rk_ohci_of_match[] = {
104         {
105          .compatible = "rockchip,rk3288_rk_ohci_host",
106          .data = &rkohci_pdata[RK3288_USB_CTLR],
107          },
108         {},
109 };
110
111 MODULE_DEVICE_TABLE(of, rk_ohci_of_match);
112
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.
117  */
118 static int ohci_hcd_rk_probe(struct platform_device *pdev)
119 {
120         struct device *dev = &pdev->dev;
121         struct usb_hcd *hcd = NULL;
122         void __iomem *regs = NULL;
123         struct resource *res;
124         int ret = -ENODEV;
125         int irq;
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);
131
132         dev_dbg(&pdev->dev, "ohci_hcd_rk_probe\n");
133
134         if (usb_disabled())
135                 return -ENODEV;
136
137         if (match) {
138                 p = (struct rkehci_pdata_id *)match->data;
139         } else {
140                 dev_err(dev, "ohci_rk match failed\n");
141                 return -EINVAL;
142         }
143
144         dev->platform_data = p->pdata;
145         pldata = dev->platform_data;
146         pldata->dev = dev;
147
148         if (!node) {
149                 dev_err(dev, "device node not found\n");
150                 return -EINVAL;
151         }
152
153         if (pldata->hw_init)
154                 pldata->hw_init();
155
156         if (pldata->clock_init) {
157                 pldata->clock_init(pldata);
158                 pldata->clock_enable(pldata, 1);
159         }
160
161         if (pldata->soft_reset)
162                 pldata->soft_reset();
163
164         irq = platform_get_irq(pdev, 0);
165         if (irq < 0) {
166                 dev_err(dev, "OHCI irq failed\n");
167                 ret = irq;
168                 goto clk_disable;
169         }
170
171         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
172         if (!res) {
173                 dev_err(dev, "UHH OHCI get resource failed\n");
174                 ret = -ENOMEM;
175                 goto clk_disable;
176         }
177
178         regs = devm_ioremap_resource(dev, res);
179         if (!regs) {
180                 dev_err(dev, "UHH OHCI ioremap failed\n");
181                 ret = -ENOMEM;
182                 goto clk_disable;
183         }
184
185         /*
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.
189          */
190         if (!dev->dma_mask)
191                 dev->dma_mask = &dev->coherent_dma_mask;
192         if (!dev->coherent_dma_mask)
193                 dev->coherent_dma_mask = DMA_BIT_MASK(32);
194
195         hcd = usb_create_hcd(&ohci_rk_hc_driver, dev, dev_name(dev));
196         if (!hcd) {
197                 dev_err(dev, "usb_create_hcd failed\n");
198                 ret = -ENOMEM;
199                 goto clk_disable;
200         }
201
202         hcd->rsrc_start = res->start;
203         hcd->rsrc_len = resource_size(res);
204         hcd->regs = regs;
205
206         ohci_hcd_init(hcd_to_ohci(hcd));
207
208         ret = usb_add_hcd(hcd, irq, 0);
209         if (ret) {
210                 dev_dbg(dev, "failed to add hcd with err %d\n", ret);
211                 goto err_add_hcd;
212         }
213
214         return 0;
215
216 err_add_hcd:
217         usb_put_hcd(hcd);
218
219 clk_disable:
220         if (pldata->clock_enable)
221                 pldata->clock_enable(pldata, 0);
222
223         return ret;
224 }
225
226 static int ohci_hcd_rk_remove(struct platform_device *pdev)
227 {
228         struct device *dev = &pdev->dev;
229         struct usb_hcd *hcd = dev_get_drvdata(dev);
230
231         usb_remove_hcd(hcd);
232         usb_put_hcd(hcd);
233         return 0;
234 }
235
236 static void ohci_hcd_rk_shutdown(struct platform_device *pdev)
237 {
238         struct usb_hcd *hcd = dev_get_drvdata(&pdev->dev);
239
240         if (hcd->driver->shutdown)
241                 hcd->driver->shutdown(hcd);
242 }
243
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,
248         .driver = {
249                    .name = "ohci-rockchip",
250                    .of_match_table = of_match_ptr(rk_ohci_of_match),
251                    },
252 };
253
254 MODULE_ALIAS("platform:rockchip-ohci");