aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/dwc3
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2012-02-15 04:27:55 -0500
committerFelipe Balbi <balbi@ti.com>2012-03-02 05:11:59 -0500
commit802ca85067e11cdeddeb34ef53de03e5a7d509da (patch)
treeff55f46e2e1586570e9e7b4a98b3c2c979c75c1f /drivers/usb/dwc3
parentd28a9689c93195d39f91f35a9519876688605b65 (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')
-rw-r--r--drivers/usb/dwc3/core.c84
-rw-r--r--drivers/usb/dwc3/dwc3-omap.c85
-rw-r--r--drivers/usb/dwc3/dwc3-pci.c46
3 files changed, 90 insertions, 125 deletions
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index d119a1fbf946..c181f3e84cfa 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -408,6 +408,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
408 struct device_node *node = pdev->dev.of_node; 408 struct device_node *node = pdev->dev.of_node;
409 struct resource *res; 409 struct resource *res;
410 struct dwc3 *dwc; 410 struct dwc3 *dwc;
411 struct device *dev = &pdev->dev;
411 412
412 int ret = -ENOMEM; 413 int ret = -ENOMEM;
413 int irq; 414 int irq;
@@ -417,39 +418,39 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
417 418
418 u8 mode; 419 u8 mode;
419 420
420 mem = kzalloc(sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL); 421 mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
421 if (!mem) { 422 if (!mem) {
422 dev_err(&pdev->dev, "not enough memory\n"); 423 dev_err(dev, "not enough memory\n");
423 goto err0; 424 return -ENOMEM;
424 } 425 }
425 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1); 426 dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
426 dwc->mem = mem; 427 dwc->mem = mem;
427 428
428 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 429 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
429 if (!res) { 430 if (!res) {
430 dev_err(&pdev->dev, "missing resource\n"); 431 dev_err(dev, "missing resource\n");
431 goto err1; 432 return -ENODEV;
432 } 433 }
433 434
434 dwc->res = res; 435 dwc->res = res;
435 436
436 res = request_mem_region(res->start, resource_size(res), 437 res = devm_request_mem_region(dev, res->start, resource_size(res),
437 dev_name(&pdev->dev)); 438 dev_name(dev));
438 if (!res) { 439 if (!res) {
439 dev_err(&pdev->dev, "can't request mem region\n"); 440 dev_err(dev, "can't request mem region\n");
440 goto err1; 441 return -ENOMEM;
441 } 442 }
442 443
443 regs = ioremap(res->start, resource_size(res)); 444 regs = devm_ioremap(dev, res->start, resource_size(res));
444 if (!regs) { 445 if (!regs) {
445 dev_err(&pdev->dev, "ioremap failed\n"); 446 dev_err(dev, "ioremap failed\n");
446 goto err2; 447 return -ENOMEM;
447 } 448 }
448 449
449 irq = platform_get_irq(pdev, 0); 450 irq = platform_get_irq(pdev, 0);
450 if (irq < 0) { 451 if (irq < 0) {
451 dev_err(&pdev->dev, "missing IRQ\n"); 452 dev_err(dev, "missing IRQ\n");
452 goto err3; 453 return -ENODEV;
453 } 454 }
454 455
455 spin_lock_init(&dwc->lock); 456 spin_lock_init(&dwc->lock);
@@ -457,7 +458,7 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
457 458
458 dwc->regs = regs; 459 dwc->regs = regs;
459 dwc->regs_size = resource_size(res); 460 dwc->regs_size = resource_size(res);
460 dwc->dev = &pdev->dev; 461 dwc->dev = dev;
461 dwc->irq = irq; 462 dwc->irq = irq;
462 463
463 if (!strncmp("super", maximum_speed, 5)) 464 if (!strncmp("super", maximum_speed, 5))
@@ -474,14 +475,14 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
474 if (of_get_property(node, "tx-fifo-resize", NULL)) 475 if (of_get_property(node, "tx-fifo-resize", NULL))
475 dwc->needs_fifo_resize = true; 476 dwc->needs_fifo_resize = true;
476 477
477 pm_runtime_enable(&pdev->dev); 478 pm_runtime_enable(dev);
478 pm_runtime_get_sync(&pdev->dev); 479 pm_runtime_get_sync(dev);
479 pm_runtime_forbid(&pdev->dev); 480 pm_runtime_forbid(dev);
480 481
481 ret = dwc3_core_init(dwc); 482 ret = dwc3_core_init(dwc);
482 if (ret) { 483 if (ret) {
483 dev_err(&pdev->dev, "failed to initialize core\n"); 484 dev_err(dev, "failed to initialize core\n");
484 goto err3; 485 return ret;
485 } 486 }
486 487
487 mode = DWC3_MODE(dwc->hwparams.hwparams0); 488 mode = DWC3_MODE(dwc->hwparams.hwparams0);
@@ -491,49 +492,49 @@ static int __devinit dwc3_probe(struct platform_device *pdev)
491 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE); 492 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_DEVICE);
492 ret = dwc3_gadget_init(dwc); 493 ret = dwc3_gadget_init(dwc);
493 if (ret) { 494 if (ret) {
494 dev_err(&pdev->dev, "failed to initialize gadget\n"); 495 dev_err(dev, "failed to initialize gadget\n");
495 goto err4; 496 goto err1;
496 } 497 }
497 break; 498 break;
498 case DWC3_MODE_HOST: 499 case DWC3_MODE_HOST:
499 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST); 500 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_HOST);
500 ret = dwc3_host_init(dwc); 501 ret = dwc3_host_init(dwc);
501 if (ret) { 502 if (ret) {
502 dev_err(&pdev->dev, "failed to initialize host\n"); 503 dev_err(dev, "failed to initialize host\n");
503 goto err4; 504 goto err1;
504 } 505 }
505 break; 506 break;
506 case DWC3_MODE_DRD: 507 case DWC3_MODE_DRD:
507 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG); 508 dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
508 ret = dwc3_host_init(dwc); 509 ret = dwc3_host_init(dwc);
509 if (ret) { 510 if (ret) {
510 dev_err(&pdev->dev, "failed to initialize host\n"); 511 dev_err(dev, "failed to initialize host\n");
511 goto err4; 512 goto err1;
512 } 513 }
513 514
514 ret = dwc3_gadget_init(dwc); 515 ret = dwc3_gadget_init(dwc);
515 if (ret) { 516 if (ret) {
516 dev_err(&pdev->dev, "failed to initialize gadget\n"); 517 dev_err(dev, "failed to initialize gadget\n");
517 goto err4; 518 goto err1;
518 } 519 }
519 break; 520 break;
520 default: 521 default:
521 dev_err(&pdev->dev, "Unsupported mode of operation %d\n", mode); 522 dev_err(dev, "Unsupported mode of operation %d\n", mode);
522 goto err4; 523 goto err1;
523 } 524 }
524 dwc->mode = mode; 525 dwc->mode = mode;
525 526
526 ret = dwc3_debugfs_init(dwc); 527 ret = dwc3_debugfs_init(dwc);
527 if (ret) { 528 if (ret) {
528 dev_err(&pdev->dev, "failed to initialize debugfs\n"); 529 dev_err(dev, "failed to initialize debugfs\n");
529 goto err5; 530 goto err2;
530 } 531 }
531 532
532 pm_runtime_allow(&pdev->dev); 533 pm_runtime_allow(dev);
533 534
534 return 0; 535 return 0;
535 536
536err5: 537err2:
537 switch (mode) { 538 switch (mode) {
538 case DWC3_MODE_DEVICE: 539 case DWC3_MODE_DEVICE:
539 dwc3_gadget_exit(dwc); 540 dwc3_gadget_exit(dwc);
@@ -550,19 +551,9 @@ err5:
550 break; 551 break;
551 } 552 }
552 553
553err4:
554 dwc3_core_exit(dwc);
555
556err3:
557 iounmap(regs);
558
559err2:
560 release_mem_region(res->start, resource_size(res));
561
562err1: 554err1:
563 kfree(dwc->mem); 555 dwc3_core_exit(dwc);
564 556
565err0:
566 return ret; 557 return ret;
567} 558}
568 559
@@ -595,9 +586,6 @@ static int __devexit dwc3_remove(struct platform_device *pdev)
595 } 586 }
596 587
597 dwc3_core_exit(dwc); 588 dwc3_core_exit(dwc);
598 release_mem_region(res->start, resource_size(res));
599 iounmap(dwc->regs);
600 kfree(dwc->mem);
601 589
602 return 0; 590 return 0;
603} 591}
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
352err6:
353 free_irq(omap->irq, omap);
354
355err5:
356 kfree(omap->context);
357
358err4:
359 platform_device_put(dwc3);
360
361err3:
362 dwc3_put_device_id(devid);
363
364err2: 351err2:
365 iounmap(base); 352 platform_device_put(dwc3);
366 353
367err1: 354err1:
368 kfree(omap); 355 dwc3_put_device_id(devid);
369 356
370err0:
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}
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 64e1f7c67b08..05d3a3efbc15 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -61,19 +61,20 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
61 struct dwc3_pci *glue; 61 struct dwc3_pci *glue;
62 int ret = -ENOMEM; 62 int ret = -ENOMEM;
63 int devid; 63 int devid;
64 struct device *dev = &pci->dev;
64 65
65 glue = kzalloc(sizeof(*glue), GFP_KERNEL); 66 glue = devm_kzalloc(dev, sizeof(*glue), GFP_KERNEL);
66 if (!glue) { 67 if (!glue) {
67 dev_err(&pci->dev, "not enough memory\n"); 68 dev_err(dev, "not enough memory\n");
68 goto err0; 69 return -ENOMEM;
69 } 70 }
70 71
71 glue->dev = &pci->dev; 72 glue->dev = dev;
72 73
73 ret = pci_enable_device(pci); 74 ret = pci_enable_device(pci);
74 if (ret) { 75 if (ret) {
75 dev_err(&pci->dev, "failed to enable pci device\n"); 76 dev_err(dev, "failed to enable pci device\n");
76 goto err1; 77 return -ENODEV;
77 } 78 }
78 79
79 pci_set_power_state(pci, PCI_D0); 80 pci_set_power_state(pci, PCI_D0);
@@ -81,12 +82,12 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
81 82
82 devid = dwc3_get_device_id(); 83 devid = dwc3_get_device_id();
83 if (devid < 0) 84 if (devid < 0)
84 goto err2; 85 goto err1;
85 86
86 dwc3 = platform_device_alloc("dwc3", devid); 87 dwc3 = platform_device_alloc("dwc3", devid);
87 if (!dwc3) { 88 if (!dwc3) {
88 dev_err(&pci->dev, "couldn't allocate dwc3 device\n"); 89 dev_err(dev, "couldn't allocate dwc3 device\n");
89 goto err3; 90 goto err1;
90 } 91 }
91 92
92 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res)); 93 memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
@@ -102,41 +103,37 @@ static int __devinit dwc3_pci_probe(struct pci_dev *pci,
102 103
103 ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res)); 104 ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
104 if (ret) { 105 if (ret) {
105 dev_err(&pci->dev, "couldn't add resources to dwc3 device\n"); 106 dev_err(dev, "couldn't add resources to dwc3 device\n");
106 goto err4; 107 goto err2;
107 } 108 }
108 109
109 pci_set_drvdata(pci, glue); 110 pci_set_drvdata(pci, glue);
110 111
111 dma_set_coherent_mask(&dwc3->dev, pci->dev.coherent_dma_mask); 112 dma_set_coherent_mask(&dwc3->dev, dev->coherent_dma_mask);
112 113
113 dwc3->dev.dma_mask = pci->dev.dma_mask; 114 dwc3->dev.dma_mask = dev->dma_mask;
114 dwc3->dev.dma_parms = pci->dev.dma_parms; 115 dwc3->dev.dma_parms = dev->dma_parms;
115 dwc3->dev.parent = &pci->dev; 116 dwc3->dev.parent = dev;
116 glue->dwc3 = dwc3; 117 glue->dwc3 = dwc3;
117 118
118 ret = platform_device_add(dwc3); 119 ret = platform_device_add(dwc3);
119 if (ret) { 120 if (ret) {
120 dev_err(&pci->dev, "failed to register dwc3 device\n"); 121 dev_err(dev, "failed to register dwc3 device\n");
121 goto err4; 122 goto err3;
122 } 123 }
123 124
124 return 0; 125 return 0;
125 126
126err4: 127err3:
127 pci_set_drvdata(pci, NULL); 128 pci_set_drvdata(pci, NULL);
128 platform_device_put(dwc3); 129 platform_device_put(dwc3);
129 130
130err3:
131 dwc3_put_device_id(devid);
132
133err2: 131err2:
134 pci_disable_device(pci); 132 dwc3_put_device_id(devid);
135 133
136err1: 134err1:
137 kfree(glue); 135 pci_disable_device(pci);
138 136
139err0:
140 return ret; 137 return ret;
141} 138}
142 139
@@ -148,7 +145,6 @@ static void __devexit dwc3_pci_remove(struct pci_dev *pci)
148 platform_device_unregister(glue->dwc3); 145 platform_device_unregister(glue->dwc3);
149 pci_set_drvdata(pci, NULL); 146 pci_set_drvdata(pci, NULL);
150 pci_disable_device(pci); 147 pci_disable_device(pci);
151 kfree(glue);
152} 148}
153 149
154static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = { 150static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {