diff options
author | Vivek Gautam <gautam.vivek@samsung.com> | 2013-03-14 08:39:49 -0400 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2013-03-18 05:18:16 -0400 |
commit | adcf20dcd2629112c467f30a2c057479979ae64c (patch) | |
tree | 4aa1c3e7e62143efbcf87b8cc1e72f9f7fd12cb8 /drivers/usb/dwc3/dwc3-exynos.c | |
parent | b52767581765d3d1a1ba7106674791e540574704 (diff) |
usb: dwc3: exynos: Use of_platform API to create dwc3 core pdev
Used of_platform_populate() to create dwc3 core platform_device
from device tree data. Additionally some cleanup is also done.
Signed-off-by: Vivek Gautam <gautam.vivek@samsung.com>
CC: Felipe Balbi <balbi@ti.com>
CC: Kukjin Kim <kgene.kim@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/dwc3-exynos.c')
-rw-r--r-- | drivers/usb/dwc3/dwc3-exynos.c | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index e12e45248862..f77ec75e2d1e 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c | |||
@@ -22,9 +22,9 @@ | |||
22 | #include <linux/usb/otg.h> | 22 | #include <linux/usb/otg.h> |
23 | #include <linux/usb/nop-usb-xceiv.h> | 23 | #include <linux/usb/nop-usb-xceiv.h> |
24 | #include <linux/of.h> | 24 | #include <linux/of.h> |
25 | #include <linux/of_platform.h> | ||
25 | 26 | ||
26 | struct dwc3_exynos { | 27 | struct dwc3_exynos { |
27 | struct platform_device *dwc3; | ||
28 | struct platform_device *usb2_phy; | 28 | struct platform_device *usb2_phy; |
29 | struct platform_device *usb3_phy; | 29 | struct platform_device *usb3_phy; |
30 | struct device *dev; | 30 | struct device *dev; |
@@ -86,21 +86,30 @@ err1: | |||
86 | return ret; | 86 | return ret; |
87 | } | 87 | } |
88 | 88 | ||
89 | static int dwc3_exynos_remove_child(struct device *dev, void *unused) | ||
90 | { | ||
91 | struct platform_device *pdev = to_platform_device(dev); | ||
92 | |||
93 | platform_device_unregister(pdev); | ||
94 | |||
95 | return 0; | ||
96 | } | ||
97 | |||
89 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); | 98 | static u64 dwc3_exynos_dma_mask = DMA_BIT_MASK(32); |
90 | 99 | ||
91 | static int dwc3_exynos_probe(struct platform_device *pdev) | 100 | static int dwc3_exynos_probe(struct platform_device *pdev) |
92 | { | 101 | { |
93 | struct platform_device *dwc3; | ||
94 | struct dwc3_exynos *exynos; | 102 | struct dwc3_exynos *exynos; |
95 | struct clk *clk; | 103 | struct clk *clk; |
96 | struct device *dev = &pdev->dev; | 104 | struct device *dev = &pdev->dev; |
105 | struct device_node *node = dev->of_node; | ||
97 | 106 | ||
98 | int ret = -ENOMEM; | 107 | int ret = -ENOMEM; |
99 | 108 | ||
100 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); | 109 | exynos = devm_kzalloc(dev, sizeof(*exynos), GFP_KERNEL); |
101 | if (!exynos) { | 110 | if (!exynos) { |
102 | dev_err(dev, "not enough memory\n"); | 111 | dev_err(dev, "not enough memory\n"); |
103 | return -ENOMEM; | 112 | goto err1; |
104 | } | 113 | } |
105 | 114 | ||
106 | /* | 115 | /* |
@@ -108,21 +117,15 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
108 | * Since shared usb code relies on it, set it here for now. | 117 | * Since shared usb code relies on it, set it here for now. |
109 | * Once we move to full device tree support this will vanish off. | 118 | * Once we move to full device tree support this will vanish off. |
110 | */ | 119 | */ |
111 | if (!pdev->dev.dma_mask) | 120 | if (!dev->dma_mask) |
112 | pdev->dev.dma_mask = &dwc3_exynos_dma_mask; | 121 | dev->dma_mask = &dwc3_exynos_dma_mask; |
113 | 122 | ||
114 | platform_set_drvdata(pdev, exynos); | 123 | platform_set_drvdata(pdev, exynos); |
115 | 124 | ||
116 | ret = dwc3_exynos_register_phys(exynos); | 125 | ret = dwc3_exynos_register_phys(exynos); |
117 | if (ret) { | 126 | if (ret) { |
118 | dev_err(dev, "couldn't register PHYs\n"); | 127 | dev_err(dev, "couldn't register PHYs\n"); |
119 | return ret; | 128 | goto err1; |
120 | } | ||
121 | |||
122 | dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); | ||
123 | if (!dwc3) { | ||
124 | dev_err(dev, "couldn't allocate dwc3 device\n"); | ||
125 | return -ENOMEM; | ||
126 | } | 129 | } |
127 | 130 | ||
128 | clk = devm_clk_get(dev, "usbdrd30"); | 131 | clk = devm_clk_get(dev, "usbdrd30"); |
@@ -132,27 +135,20 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
132 | goto err1; | 135 | goto err1; |
133 | } | 136 | } |
134 | 137 | ||
135 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); | ||
136 | |||
137 | dwc3->dev.parent = dev; | ||
138 | dwc3->dev.dma_mask = dev->dma_mask; | ||
139 | dwc3->dev.dma_parms = dev->dma_parms; | ||
140 | exynos->dwc3 = dwc3; | ||
141 | exynos->dev = dev; | 138 | exynos->dev = dev; |
142 | exynos->clk = clk; | 139 | exynos->clk = clk; |
143 | 140 | ||
144 | clk_enable(exynos->clk); | 141 | clk_enable(exynos->clk); |
145 | 142 | ||
146 | ret = platform_device_add_resources(dwc3, pdev->resource, | 143 | if (node) { |
147 | pdev->num_resources); | 144 | ret = of_platform_populate(node, NULL, NULL, dev); |
148 | if (ret) { | 145 | if (ret) { |
149 | dev_err(dev, "couldn't add resources to dwc3 device\n"); | 146 | dev_err(dev, "failed to add dwc3 core\n"); |
150 | goto err2; | 147 | goto err2; |
151 | } | 148 | } |
152 | 149 | } else { | |
153 | ret = platform_device_add(dwc3); | 150 | dev_err(dev, "no device node, failed to add dwc3 core\n"); |
154 | if (ret) { | 151 | ret = -ENODEV; |
155 | dev_err(dev, "failed to register dwc3 device\n"); | ||
156 | goto err2; | 152 | goto err2; |
157 | } | 153 | } |
158 | 154 | ||
@@ -161,8 +157,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev) | |||
161 | err2: | 157 | err2: |
162 | clk_disable(clk); | 158 | clk_disable(clk); |
163 | err1: | 159 | err1: |
164 | platform_device_put(dwc3); | ||
165 | |||
166 | return ret; | 160 | return ret; |
167 | } | 161 | } |
168 | 162 | ||
@@ -170,9 +164,9 @@ static int dwc3_exynos_remove(struct platform_device *pdev) | |||
170 | { | 164 | { |
171 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); | 165 | struct dwc3_exynos *exynos = platform_get_drvdata(pdev); |
172 | 166 | ||
173 | platform_device_unregister(exynos->dwc3); | ||
174 | platform_device_unregister(exynos->usb2_phy); | 167 | platform_device_unregister(exynos->usb2_phy); |
175 | platform_device_unregister(exynos->usb3_phy); | 168 | platform_device_unregister(exynos->usb3_phy); |
169 | device_for_each_child(&pdev->dev, NULL, dwc3_exynos_remove_child); | ||
176 | 170 | ||
177 | clk_disable(exynos->clk); | 171 | clk_disable(exynos->clk); |
178 | 172 | ||