aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Zhao <richard.zhao@freescale.com>2012-07-07 10:56:41 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-09 12:53:44 -0400
commitcbc6dc2af39e1395564445fd71cfcc1c70a96277 (patch)
tree24312066e797d7ae29bd84725c1b1994d4f5d6ba
parent26c696c678c4ce180599330999e895cded0f625b (diff)
USB: Chipidea: add unified ci13xxx_{add,remove}_device for platform drivers
Platform drivers do the similar things to add/remove ci13xxx device, so create a unified one. Signed-off-by: Richard Zhao <richard.zhao@freescale.com> Reviewed-by: Felipe Balbi <balbi@ti.com> Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/chipidea/ci13xxx_msm.c34
-rw-r--r--drivers/usb/chipidea/ci13xxx_pci.c34
-rw-r--r--drivers/usb/chipidea/core.c43
-rw-r--r--include/linux/usb/chipidea.h7
4 files changed, 63 insertions, 55 deletions
diff --git a/drivers/usb/chipidea/ci13xxx_msm.c b/drivers/usb/chipidea/ci13xxx_msm.c
index 5a2fe5f9b6c3..b01feb3be92e 100644
--- a/drivers/usb/chipidea/ci13xxx_msm.c
+++ b/drivers/usb/chipidea/ci13xxx_msm.c
@@ -58,43 +58,23 @@ static struct ci13xxx_platform_data ci13xxx_msm_platdata = {
58static int __devinit ci13xxx_msm_probe(struct platform_device *pdev) 58static int __devinit ci13xxx_msm_probe(struct platform_device *pdev)
59{ 59{
60 struct platform_device *plat_ci; 60 struct platform_device *plat_ci;
61 int ret;
62 61
63 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n"); 62 dev_dbg(&pdev->dev, "ci13xxx_msm_probe\n");
64 63
65 plat_ci = platform_device_alloc("ci_hdrc", -1); 64 plat_ci = ci13xxx_add_device(&pdev->dev,
66 if (!plat_ci) { 65 pdev->resource, pdev->num_resources,
67 dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n"); 66 &ci13xxx_msm_platdata);
68 return -ENOMEM; 67 if (IS_ERR(plat_ci)) {
68 dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
69 return PTR_ERR(plat_ci);
69 } 70 }
70 71
71 ret = platform_device_add_resources(plat_ci, pdev->resource,
72 pdev->num_resources);
73 if (ret) {
74 dev_err(&pdev->dev, "can't add resources to platform device\n");
75 goto put_platform;
76 }
77
78 ret = platform_device_add_data(plat_ci, &ci13xxx_msm_platdata,
79 sizeof(ci13xxx_msm_platdata));
80 if (ret)
81 goto put_platform;
82
83 ret = platform_device_add(plat_ci);
84 if (ret)
85 goto put_platform;
86
87 platform_set_drvdata(pdev, plat_ci); 72 platform_set_drvdata(pdev, plat_ci);
88 73
89 pm_runtime_no_callbacks(&pdev->dev); 74 pm_runtime_no_callbacks(&pdev->dev);
90 pm_runtime_enable(&pdev->dev); 75 pm_runtime_enable(&pdev->dev);
91 76
92 return 0; 77 return 0;
93
94put_platform:
95 platform_device_put(plat_ci);
96
97 return ret;
98} 78}
99 79
100static int __devexit ci13xxx_msm_remove(struct platform_device *pdev) 80static int __devexit ci13xxx_msm_remove(struct platform_device *pdev)
@@ -102,7 +82,7 @@ static int __devexit ci13xxx_msm_remove(struct platform_device *pdev)
102 struct platform_device *plat_ci = platform_get_drvdata(pdev); 82 struct platform_device *plat_ci = platform_get_drvdata(pdev);
103 83
104 pm_runtime_disable(&pdev->dev); 84 pm_runtime_disable(&pdev->dev);
105 platform_device_unregister(plat_ci); 85 ci13xxx_remove_device(plat_ci);
106 86
107 return 0; 87 return 0;
108} 88}
diff --git a/drivers/usb/chipidea/ci13xxx_pci.c b/drivers/usb/chipidea/ci13xxx_pci.c
index cdcac3a0e94d..918e14971f2b 100644
--- a/drivers/usb/chipidea/ci13xxx_pci.c
+++ b/drivers/usb/chipidea/ci13xxx_pci.c
@@ -75,13 +75,6 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
75 pci_set_master(pdev); 75 pci_set_master(pdev);
76 pci_try_set_mwi(pdev); 76 pci_try_set_mwi(pdev);
77 77
78 plat_ci = platform_device_alloc("ci_hdrc", -1);
79 if (!plat_ci) {
80 dev_err(&pdev->dev, "can't allocate ci_hdrc platform device\n");
81 retval = -ENOMEM;
82 goto disable_device;
83 }
84
85 memset(res, 0, sizeof(res)); 78 memset(res, 0, sizeof(res));
86 res[0].start = pci_resource_start(pdev, 0); 79 res[0].start = pci_resource_start(pdev, 0);
87 res[0].end = pci_resource_end(pdev, 0); 80 res[0].end = pci_resource_end(pdev, 0);
@@ -89,32 +82,17 @@ static int __devinit ci13xxx_pci_probe(struct pci_dev *pdev,
89 res[1].start = pdev->irq; 82 res[1].start = pdev->irq;
90 res[1].flags = IORESOURCE_IRQ; 83 res[1].flags = IORESOURCE_IRQ;
91 84
92 retval = platform_device_add_resources(plat_ci, res, nres); 85 plat_ci = ci13xxx_add_device(&pdev->dev, res, nres, platdata);
93 if (retval) { 86 if (IS_ERR(plat_ci)) {
94 dev_err(&pdev->dev, "can't add resources to platform device\n"); 87 dev_err(&pdev->dev, "ci13xxx_add_device failed!\n");
95 goto put_platform; 88 retval = PTR_ERR(plat_ci);
89 goto disable_device;
96 } 90 }
97 91
98 retval = platform_device_add_data(plat_ci, platdata, sizeof(*platdata));
99 if (retval)
100 goto put_platform;
101
102 dma_set_coherent_mask(&plat_ci->dev, pdev->dev.coherent_dma_mask);
103 plat_ci->dev.dma_mask = pdev->dev.dma_mask;
104 plat_ci->dev.dma_parms = pdev->dev.dma_parms;
105 plat_ci->dev.parent = &pdev->dev;
106
107 pci_set_drvdata(pdev, plat_ci); 92 pci_set_drvdata(pdev, plat_ci);
108 93
109 retval = platform_device_add(plat_ci);
110 if (retval)
111 goto put_platform;
112
113 return 0; 94 return 0;
114 95
115 put_platform:
116 pci_set_drvdata(pdev, NULL);
117 platform_device_put(plat_ci);
118 disable_device: 96 disable_device:
119 pci_disable_device(pdev); 97 pci_disable_device(pdev);
120 done: 98 done:
@@ -133,7 +111,7 @@ static void __devexit ci13xxx_pci_remove(struct pci_dev *pdev)
133{ 111{
134 struct platform_device *plat_ci = pci_get_drvdata(pdev); 112 struct platform_device *plat_ci = pci_get_drvdata(pdev);
135 113
136 platform_device_unregister(plat_ci); 114 ci13xxx_remove_device(plat_ci);
137 pci_set_drvdata(pdev, NULL); 115 pci_set_drvdata(pdev, NULL);
138 pci_disable_device(pdev); 116 pci_disable_device(pdev);
139} 117}
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 9a883bd5e113..8b9d06fd0325 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -332,6 +332,49 @@ static irqreturn_t ci_irq(int irq, void *data)
332 return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci); 332 return ci->role == CI_ROLE_END ? ret : ci_role(ci)->irq(ci);
333} 333}
334 334
335struct platform_device *ci13xxx_add_device(struct device *dev,
336 struct resource *res, int nres,
337 struct ci13xxx_platform_data *platdata)
338{
339 struct platform_device *pdev;
340 int ret;
341
342 /* FIXME: find a way to choose id */
343 pdev = platform_device_alloc("ci_hdrc", -1);
344 if (!pdev)
345 return ERR_PTR(-ENOMEM);
346
347 pdev->dev.parent = dev;
348 pdev->dev.dma_mask = dev->dma_mask;
349 pdev->dev.dma_parms = dev->dma_parms;
350 dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
351
352 ret = platform_device_add_resources(pdev, res, nres);
353 if (ret)
354 goto err;
355
356 ret = platform_device_add_data(pdev, platdata, sizeof(*platdata));
357 if (ret)
358 goto err;
359
360 ret = platform_device_add(pdev);
361 if (ret)
362 goto err;
363
364 return pdev;
365
366err:
367 platform_device_put(pdev);
368 return ERR_PTR(ret);
369}
370EXPORT_SYMBOL_GPL(ci13xxx_add_device);
371
372void ci13xxx_remove_device(struct platform_device *pdev)
373{
374 platform_device_unregister(pdev);
375}
376EXPORT_SYMBOL_GPL(ci13xxx_remove_device);
377
335static int __devinit ci_hdrc_probe(struct platform_device *pdev) 378static int __devinit ci_hdrc_probe(struct platform_device *pdev)
336{ 379{
337 struct device *dev = &pdev->dev; 380 struct device *dev = &pdev->dev;
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index d2f7e494f5c0..be078f0bfde2 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -25,4 +25,11 @@ struct ci13xxx_platform_data {
25/* Default offset of capability registers */ 25/* Default offset of capability registers */
26#define DEF_CAPOFFSET 0x100 26#define DEF_CAPOFFSET 0x100
27 27
28/* Add ci13xxx device */
29struct platform_device *ci13xxx_add_device(struct device *dev,
30 struct resource *res, int nres,
31 struct ci13xxx_platform_data *platdata);
32/* Remove ci13xxx device */
33void ci13xxx_remove_device(struct platform_device *pdev);
34
28#endif 35#endif