aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2015-01-20 17:55:44 -0500
committerFelipe Balbi <balbi@ti.com>2015-01-27 10:38:21 -0500
commitc3cc40ccea2cd3533a90d915b40f304843642df9 (patch)
tree858718794715e05c26156e66e06b616e3d7c679d /drivers/usb/host
parent5324713c998d6615d858606188fe69a23d1de9d8 (diff)
usb: isp1760: Merge platform and OF glue codes
Both handle platform devices, merge them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/isp1760-if.c190
1 files changed, 55 insertions, 135 deletions
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 730caa18cbd2..3db98daa16d5 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -12,121 +12,18 @@
12#include <linux/usb.h> 12#include <linux/usb.h>
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/of.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/slab.h>
16#include <linux/usb/isp1760.h> 18#include <linux/usb/isp1760.h>
17#include <linux/usb/hcd.h> 19#include <linux/usb/hcd.h>
18 20
19#include "isp1760-hcd.h" 21#include "isp1760-hcd.h"
20 22
21#if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
22#include <linux/slab.h>
23#include <linux/of.h>
24#include <linux/of_platform.h>
25#include <linux/of_address.h>
26#include <linux/of_irq.h>
27#endif
28
29#ifdef CONFIG_PCI 23#ifdef CONFIG_PCI
30#include <linux/pci.h> 24#include <linux/pci.h>
31#endif 25#endif
32 26
33#if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
34static int of_isp1760_probe(struct platform_device *dev)
35{
36 struct usb_hcd *hcd;
37 struct device_node *dp = dev->dev.of_node;
38 struct resource *res;
39 struct resource memory;
40 int virq;
41 resource_size_t res_len;
42 int ret;
43 unsigned int devflags = 0;
44 u32 bus_width = 0;
45
46 ret = of_address_to_resource(dp, 0, &memory);
47 if (ret)
48 return -ENXIO;
49
50 res_len = resource_size(&memory);
51
52 res = request_mem_region(memory.start, res_len, dev_name(&dev->dev));
53 if (!res)
54 return -EBUSY;
55
56 virq = irq_of_parse_and_map(dp, 0);
57 if (!virq) {
58 ret = -ENODEV;
59 goto release_reg;
60 }
61
62 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
63 devflags |= ISP1760_FLAG_ISP1761;
64
65 /* Some systems wire up only 16 of the 32 data lines */
66 of_property_read_u32(dp, "bus-width", &bus_width);
67 if (bus_width == 16)
68 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
69
70 if (of_get_property(dp, "port1-otg", NULL) != NULL)
71 devflags |= ISP1760_FLAG_OTG_EN;
72
73 if (of_get_property(dp, "analog-oc", NULL) != NULL)
74 devflags |= ISP1760_FLAG_ANALOG_OC;
75
76 if (of_get_property(dp, "dack-polarity", NULL) != NULL)
77 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
78
79 if (of_get_property(dp, "dreq-polarity", NULL) != NULL)
80 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
81
82 hcd = isp1760_register(memory.start, res_len, virq, IRQF_SHARED,
83 &dev->dev, dev_name(&dev->dev), devflags);
84 if (IS_ERR(hcd)) {
85 ret = PTR_ERR(hcd);
86 goto release_reg;
87 }
88
89 platform_set_drvdata(dev, hcd);
90 return ret;
91
92release_reg:
93 release_mem_region(memory.start, res_len);
94 return ret;
95}
96
97static int of_isp1760_remove(struct platform_device *dev)
98{
99 struct usb_hcd *hcd = platform_get_drvdata(dev);
100
101 usb_remove_hcd(hcd);
102 iounmap(hcd->regs);
103 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
104 usb_put_hcd(hcd);
105
106 return 0;
107}
108
109static const struct of_device_id of_isp1760_match[] = {
110 {
111 .compatible = "nxp,usb-isp1760",
112 },
113 {
114 .compatible = "nxp,usb-isp1761",
115 },
116 { },
117};
118MODULE_DEVICE_TABLE(of, of_isp1760_match);
119
120static struct platform_driver isp1760_of_driver = {
121 .driver = {
122 .name = "nxp-isp1760",
123 .of_match_table = of_isp1760_match,
124 },
125 .probe = of_isp1760_probe,
126 .remove = of_isp1760_remove,
127};
128#endif
129
130#ifdef CONFIG_PCI 27#ifdef CONFIG_PCI
131static int isp1761_pci_probe(struct pci_dev *dev, 28static int isp1761_pci_probe(struct pci_dev *dev,
132 const struct pci_device_id *id) 29 const struct pci_device_id *id)
@@ -304,26 +201,23 @@ static struct pci_driver isp1761_pci_driver = {
304 201
305static int isp1760_plat_probe(struct platform_device *pdev) 202static int isp1760_plat_probe(struct platform_device *pdev)
306{ 203{
307 int ret = 0; 204 unsigned long irqflags = IRQF_SHARED;
308 struct usb_hcd *hcd; 205 unsigned int devflags = 0;
309 struct resource *mem_res; 206 struct resource *mem_res;
310 struct resource *irq_res; 207 struct resource *irq_res;
311 resource_size_t mem_size; 208 resource_size_t mem_size;
312 struct isp1760_platform_data *priv = dev_get_platdata(&pdev->dev); 209 struct usb_hcd *hcd;
313 unsigned int devflags = 0; 210 int ret;
314 unsigned long irqflags = IRQF_SHARED;
315 211
316 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 212 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
317 if (!mem_res) { 213 if (!mem_res) {
318 pr_warning("isp1760: Memory resource not available\n"); 214 pr_warning("isp1760: Memory resource not available\n");
319 ret = -ENODEV; 215 return -ENODEV;
320 goto out;
321 } 216 }
322 mem_size = resource_size(mem_res); 217 mem_size = resource_size(mem_res);
323 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) { 218 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) {
324 pr_warning("isp1760: Cannot reserve the memory resource\n"); 219 pr_warning("isp1760: Cannot reserve the memory resource\n");
325 ret = -EBUSY; 220 return -EBUSY;
326 goto out;
327 } 221 }
328 222
329 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 223 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -335,39 +229,63 @@ static int isp1760_plat_probe(struct platform_device *pdev)
335 229
336 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK; 230 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
337 231
338 if (priv) { 232 if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node) {
339 if (priv->is_isp1761) 233 struct device_node *dp = pdev->dev.of_node;
234 u32 bus_width = 0;
235
236 if (of_device_is_compatible(dp, "nxp,usb-isp1761"))
340 devflags |= ISP1760_FLAG_ISP1761; 237 devflags |= ISP1760_FLAG_ISP1761;
341 if (priv->bus_width_16) 238
239 /* Some systems wire up only 16 of the 32 data lines */
240 of_property_read_u32(dp, "bus-width", &bus_width);
241 if (bus_width == 16)
342 devflags |= ISP1760_FLAG_BUS_WIDTH_16; 242 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
343 if (priv->port1_otg) 243
244 if (of_property_read_bool(dp, "port1-otg"))
344 devflags |= ISP1760_FLAG_OTG_EN; 245 devflags |= ISP1760_FLAG_OTG_EN;
345 if (priv->analog_oc) 246
247 if (of_property_read_bool(dp, "analog-oc"))
346 devflags |= ISP1760_FLAG_ANALOG_OC; 248 devflags |= ISP1760_FLAG_ANALOG_OC;
347 if (priv->dack_polarity_high) 249
250 if (of_property_read_bool(dp, "dack-polarity"))
348 devflags |= ISP1760_FLAG_DACK_POL_HIGH; 251 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
349 if (priv->dreq_polarity_high) 252
253 if (of_property_read_bool(dp, "dreq-polarity"))
254 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
255 } else if (dev_get_platdata(&pdev->dev)) {
256 struct isp1760_platform_data *pdata =
257 dev_get_platdata(&pdev->dev);
258
259 if (pdata->is_isp1761)
260 devflags |= ISP1760_FLAG_ISP1761;
261 if (pdata->bus_width_16)
262 devflags |= ISP1760_FLAG_BUS_WIDTH_16;
263 if (pdata->port1_otg)
264 devflags |= ISP1760_FLAG_OTG_EN;
265 if (pdata->analog_oc)
266 devflags |= ISP1760_FLAG_ANALOG_OC;
267 if (pdata->dack_polarity_high)
268 devflags |= ISP1760_FLAG_DACK_POL_HIGH;
269 if (pdata->dreq_polarity_high)
350 devflags |= ISP1760_FLAG_DREQ_POL_HIGH; 270 devflags |= ISP1760_FLAG_DREQ_POL_HIGH;
351 } 271 }
352 272
353 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start, 273 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
354 irqflags, &pdev->dev, dev_name(&pdev->dev), 274 irqflags, &pdev->dev, dev_name(&pdev->dev),
355 devflags); 275 devflags);
356
357 platform_set_drvdata(pdev, hcd);
358
359 if (IS_ERR(hcd)) { 276 if (IS_ERR(hcd)) {
360 pr_warning("isp1760: Failed to register the HCD device\n"); 277 pr_warning("isp1760: Failed to register the HCD device\n");
361 ret = -ENODEV; 278 ret = PTR_ERR(hcd);
362 goto cleanup; 279 goto cleanup;
363 } 280 }
364 281
282 platform_set_drvdata(pdev, hcd);
283
365 pr_info("ISP1760 USB device initialised\n"); 284 pr_info("ISP1760 USB device initialised\n");
366 return ret; 285 return 0;
367 286
368cleanup: 287cleanup:
369 release_mem_region(mem_res->start, mem_size); 288 release_mem_region(mem_res->start, mem_size);
370out:
371 return ret; 289 return ret;
372} 290}
373 291
@@ -383,11 +301,21 @@ static int isp1760_plat_remove(struct platform_device *pdev)
383 return 0; 301 return 0;
384} 302}
385 303
304#ifdef CONFIG_OF
305static const struct of_device_id isp1760_of_match[] = {
306 { .compatible = "nxp,usb-isp1760", },
307 { .compatible = "nxp,usb-isp1761", },
308 { },
309};
310MODULE_DEVICE_TABLE(of, isp1760_of_match);
311#endif
312
386static struct platform_driver isp1760_plat_driver = { 313static struct platform_driver isp1760_plat_driver = {
387 .probe = isp1760_plat_probe, 314 .probe = isp1760_plat_probe,
388 .remove = isp1760_plat_remove, 315 .remove = isp1760_plat_remove,
389 .driver = { 316 .driver = {
390 .name = "isp1760", 317 .name = "isp1760",
318 .of_match_table = of_match_ptr(isp1760_of_match),
391 }, 319 },
392}; 320};
393 321
@@ -400,11 +328,6 @@ static int __init isp1760_init(void)
400 ret = platform_driver_register(&isp1760_plat_driver); 328 ret = platform_driver_register(&isp1760_plat_driver);
401 if (!ret) 329 if (!ret)
402 any_ret = 0; 330 any_ret = 0;
403#if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
404 ret = platform_driver_register(&isp1760_of_driver);
405 if (!ret)
406 any_ret = 0;
407#endif
408#ifdef CONFIG_PCI 331#ifdef CONFIG_PCI
409 ret = pci_register_driver(&isp1761_pci_driver); 332 ret = pci_register_driver(&isp1761_pci_driver);
410 if (!ret) 333 if (!ret)
@@ -420,9 +343,6 @@ module_init(isp1760_init);
420static void __exit isp1760_exit(void) 343static void __exit isp1760_exit(void)
421{ 344{
422 platform_driver_unregister(&isp1760_plat_driver); 345 platform_driver_unregister(&isp1760_plat_driver);
423#if defined(CONFIG_OF) && defined(CONFIG_OF_IRQ)
424 platform_driver_unregister(&isp1760_of_driver);
425#endif
426#ifdef CONFIG_PCI 346#ifdef CONFIG_PCI
427 pci_unregister_driver(&isp1761_pci_driver); 347 pci_unregister_driver(&isp1761_pci_driver);
428#endif 348#endif