diff options
author | Chanho Park <chanho61.park@samsung.com> | 2012-02-15 04:27:55 -0500 |
---|---|---|
committer | Felipe Balbi <balbi@ti.com> | 2012-03-02 05:11:59 -0500 |
commit | 802ca85067e11cdeddeb34ef53de03e5a7d509da (patch) | |
tree | ff55f46e2e1586570e9e7b4a98b3c2c979c75c1f /drivers/usb/dwc3/dwc3-omap.c | |
parent | d28a9689c93195d39f91f35a9519876688605b65 (diff) |
usb: dwc3: use devm_xxx functions
This patch enables to use devm_xxx functions during probing driver.
The devm_xxx series functions are able to release resource when the
driver is detatched. We can remove several codes to release resources
in the probe function.
Signed-off-by: Chanho Park <chanho61.park@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/dwc3/dwc3-omap.c')
-rw-r--r-- | drivers/usb/dwc3/dwc3-omap.c | 85 |
1 files changed, 33 insertions, 52 deletions
diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c index 64e29c31df22..f2e6b050dab3 100644 --- a/drivers/usb/dwc3/dwc3-omap.c +++ b/drivers/usb/dwc3/dwc3-omap.c | |||
@@ -203,6 +203,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
203 | struct platform_device *dwc3; | 203 | struct platform_device *dwc3; |
204 | struct dwc3_omap *omap; | 204 | struct dwc3_omap *omap; |
205 | struct resource *res; | 205 | struct resource *res; |
206 | struct device *dev = &pdev->dev; | ||
206 | 207 | ||
207 | int devid; | 208 | int devid; |
208 | int size; | 209 | int size; |
@@ -215,59 +216,57 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
215 | void __iomem *base; | 216 | void __iomem *base; |
216 | void *context; | 217 | void *context; |
217 | 218 | ||
218 | omap = kzalloc(sizeof(*omap), GFP_KERNEL); | 219 | omap = devm_kzalloc(dev, sizeof(*omap), GFP_KERNEL); |
219 | if (!omap) { | 220 | if (!omap) { |
220 | dev_err(&pdev->dev, "not enough memory\n"); | 221 | dev_err(dev, "not enough memory\n"); |
221 | goto err0; | 222 | return -ENOMEM; |
222 | } | 223 | } |
223 | 224 | ||
224 | platform_set_drvdata(pdev, omap); | 225 | platform_set_drvdata(pdev, omap); |
225 | 226 | ||
226 | irq = platform_get_irq(pdev, 1); | 227 | irq = platform_get_irq(pdev, 1); |
227 | if (irq < 0) { | 228 | if (irq < 0) { |
228 | dev_err(&pdev->dev, "missing IRQ resource\n"); | 229 | dev_err(dev, "missing IRQ resource\n"); |
229 | ret = -EINVAL; | 230 | return -EINVAL; |
230 | goto err1; | ||
231 | } | 231 | } |
232 | 232 | ||
233 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); | 233 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
234 | if (!res) { | 234 | if (!res) { |
235 | dev_err(&pdev->dev, "missing memory base resource\n"); | 235 | dev_err(dev, "missing memory base resource\n"); |
236 | ret = -EINVAL; | 236 | return -EINVAL; |
237 | goto err1; | ||
238 | } | 237 | } |
239 | 238 | ||
240 | base = ioremap_nocache(res->start, resource_size(res)); | 239 | base = devm_ioremap_nocache(dev, res->start, resource_size(res)); |
241 | if (!base) { | 240 | if (!base) { |
242 | dev_err(&pdev->dev, "ioremap failed\n"); | 241 | dev_err(dev, "ioremap failed\n"); |
243 | goto err1; | 242 | return -ENOMEM; |
244 | } | 243 | } |
245 | 244 | ||
246 | devid = dwc3_get_device_id(); | 245 | devid = dwc3_get_device_id(); |
247 | if (devid < 0) | 246 | if (devid < 0) |
248 | goto err2; | 247 | return -ENODEV; |
249 | 248 | ||
250 | dwc3 = platform_device_alloc("dwc3", devid); | 249 | dwc3 = platform_device_alloc("dwc3", devid); |
251 | if (!dwc3) { | 250 | if (!dwc3) { |
252 | dev_err(&pdev->dev, "couldn't allocate dwc3 device\n"); | 251 | dev_err(dev, "couldn't allocate dwc3 device\n"); |
253 | goto err3; | 252 | goto err1; |
254 | } | 253 | } |
255 | 254 | ||
256 | context = kzalloc(resource_size(res), GFP_KERNEL); | 255 | context = devm_kzalloc(dev, resource_size(res), GFP_KERNEL); |
257 | if (!context) { | 256 | if (!context) { |
258 | dev_err(&pdev->dev, "couldn't allocate dwc3 context memory\n"); | 257 | dev_err(dev, "couldn't allocate dwc3 context memory\n"); |
259 | goto err4; | 258 | goto err2; |
260 | } | 259 | } |
261 | 260 | ||
262 | spin_lock_init(&omap->lock); | 261 | spin_lock_init(&omap->lock); |
263 | dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask); | 262 | dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask); |
264 | 263 | ||
265 | dwc3->dev.parent = &pdev->dev; | 264 | dwc3->dev.parent = dev; |
266 | dwc3->dev.dma_mask = pdev->dev.dma_mask; | 265 | dwc3->dev.dma_mask = dev->dma_mask; |
267 | dwc3->dev.dma_parms = pdev->dev.dma_parms; | 266 | dwc3->dev.dma_parms = dev->dma_parms; |
268 | omap->resource_size = resource_size(res); | 267 | omap->resource_size = resource_size(res); |
269 | omap->context = context; | 268 | omap->context = context; |
270 | omap->dev = &pdev->dev; | 269 | omap->dev = dev; |
271 | omap->irq = irq; | 270 | omap->irq = irq; |
272 | omap->base = base; | 271 | omap->base = base; |
273 | omap->dwc3 = dwc3; | 272 | omap->dwc3 = dwc3; |
@@ -279,7 +278,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
279 | reg |= *utmi_mode; | 278 | reg |= *utmi_mode; |
280 | } else { | 279 | } else { |
281 | if (!pdata) { | 280 | if (!pdata) { |
282 | dev_dbg(&pdev->dev, "missing platform data\n"); | 281 | dev_dbg(dev, "missing platform data\n"); |
283 | } else { | 282 | } else { |
284 | switch (pdata->utmi_mode) { | 283 | switch (pdata->utmi_mode) { |
285 | case DWC3_OMAP_UTMI_MODE_SW: | 284 | case DWC3_OMAP_UTMI_MODE_SW: |
@@ -289,7 +288,7 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
289 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; | 288 | reg &= ~USBOTGSS_UTMI_OTG_STATUS_SW_MODE; |
290 | break; | 289 | break; |
291 | default: | 290 | default: |
292 | dev_dbg(&pdev->dev, "UNKNOWN utmi mode %d\n", | 291 | dev_dbg(dev, "UNKNOWN utmi mode %d\n", |
293 | pdata->utmi_mode); | 292 | pdata->utmi_mode); |
294 | } | 293 | } |
295 | } | 294 | } |
@@ -310,12 +309,12 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
310 | 309 | ||
311 | dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg); | 310 | dwc3_writel(omap->base, USBOTGSS_SYSCONFIG, reg); |
312 | 311 | ||
313 | ret = request_irq(omap->irq, dwc3_omap_interrupt, 0, | 312 | ret = devm_request_irq(dev, omap->irq, dwc3_omap_interrupt, 0, |
314 | "dwc3-omap", omap); | 313 | "dwc3-omap", omap); |
315 | if (ret) { | 314 | if (ret) { |
316 | dev_err(&pdev->dev, "failed to request IRQ #%d --> %d\n", | 315 | dev_err(dev, "failed to request IRQ #%d --> %d\n", |
317 | omap->irq, ret); | 316 | omap->irq, ret); |
318 | goto err5; | 317 | goto err2; |
319 | } | 318 | } |
320 | 319 | ||
321 | /* enable all IRQs */ | 320 | /* enable all IRQs */ |
@@ -337,37 +336,24 @@ static int __devinit dwc3_omap_probe(struct platform_device *pdev) | |||
337 | ret = platform_device_add_resources(dwc3, pdev->resource, | 336 | ret = platform_device_add_resources(dwc3, pdev->resource, |
338 | pdev->num_resources); | 337 | pdev->num_resources); |
339 | if (ret) { | 338 | if (ret) { |
340 | dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n"); | 339 | dev_err(dev, "couldn't add resources to dwc3 device\n"); |
341 | goto err6; | 340 | goto err2; |
342 | } | 341 | } |
343 | 342 | ||
344 | ret = platform_device_add(dwc3); | 343 | ret = platform_device_add(dwc3); |
345 | if (ret) { | 344 | if (ret) { |
346 | dev_err(&pdev->dev, "failed to register dwc3 device\n"); | 345 | dev_err(dev, "failed to register dwc3 device\n"); |
347 | goto err6; | 346 | goto err2; |
348 | } | 347 | } |
349 | 348 | ||
350 | return 0; | 349 | return 0; |
351 | 350 | ||
352 | err6: | ||
353 | free_irq(omap->irq, omap); | ||
354 | |||
355 | err5: | ||
356 | kfree(omap->context); | ||
357 | |||
358 | err4: | ||
359 | platform_device_put(dwc3); | ||
360 | |||
361 | err3: | ||
362 | dwc3_put_device_id(devid); | ||
363 | |||
364 | err2: | 351 | err2: |
365 | iounmap(base); | 352 | platform_device_put(dwc3); |
366 | 353 | ||
367 | err1: | 354 | err1: |
368 | kfree(omap); | 355 | dwc3_put_device_id(devid); |
369 | 356 | ||
370 | err0: | ||
371 | return ret; | 357 | return ret; |
372 | } | 358 | } |
373 | 359 | ||
@@ -378,11 +364,6 @@ static int __devexit dwc3_omap_remove(struct platform_device *pdev) | |||
378 | platform_device_unregister(omap->dwc3); | 364 | platform_device_unregister(omap->dwc3); |
379 | 365 | ||
380 | dwc3_put_device_id(omap->dwc3->id); | 366 | dwc3_put_device_id(omap->dwc3->id); |
381 | free_irq(omap->irq, omap); | ||
382 | iounmap(omap->base); | ||
383 | |||
384 | kfree(omap->context); | ||
385 | kfree(omap); | ||
386 | 367 | ||
387 | return 0; | 368 | return 0; |
388 | } | 369 | } |