diff options
Diffstat (limited to 'drivers/usb/dwc3/core.c')
-rw-r--r-- | drivers/usb/dwc3/core.c | 96 |
1 files changed, 25 insertions, 71 deletions
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index c14ebc975ba4..3a4004a620ad 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c | |||
@@ -66,45 +66,6 @@ MODULE_PARM_DESC(maximum_speed, "Maximum supported speed."); | |||
66 | 66 | ||
67 | /* -------------------------------------------------------------------------- */ | 67 | /* -------------------------------------------------------------------------- */ |
68 | 68 | ||
69 | #define DWC3_DEVS_POSSIBLE 32 | ||
70 | |||
71 | static DECLARE_BITMAP(dwc3_devs, DWC3_DEVS_POSSIBLE); | ||
72 | |||
73 | int dwc3_get_device_id(void) | ||
74 | { | ||
75 | int id; | ||
76 | |||
77 | again: | ||
78 | id = find_first_zero_bit(dwc3_devs, DWC3_DEVS_POSSIBLE); | ||
79 | if (id < DWC3_DEVS_POSSIBLE) { | ||
80 | int old; | ||
81 | |||
82 | old = test_and_set_bit(id, dwc3_devs); | ||
83 | if (old) | ||
84 | goto again; | ||
85 | } else { | ||
86 | pr_err("dwc3: no space for new device\n"); | ||
87 | id = -ENOMEM; | ||
88 | } | ||
89 | |||
90 | return id; | ||
91 | } | ||
92 | EXPORT_SYMBOL_GPL(dwc3_get_device_id); | ||
93 | |||
94 | void dwc3_put_device_id(int id) | ||
95 | { | ||
96 | int ret; | ||
97 | |||
98 | if (id < 0) | ||
99 | return; | ||
100 | |||
101 | ret = test_bit(id, dwc3_devs); | ||
102 | WARN(!ret, "dwc3: ID %d not in use\n", id); | ||
103 | smp_mb__before_clear_bit(); | ||
104 | clear_bit(id, dwc3_devs); | ||
105 | } | ||
106 | EXPORT_SYMBOL_GPL(dwc3_put_device_id); | ||
107 | |||
108 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) | 69 | void dwc3_set_mode(struct dwc3 *dwc, u32 mode) |
109 | { | 70 | { |
110 | u32 reg; | 71 | u32 reg; |
@@ -169,7 +130,6 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc, | |||
169 | struct dwc3_event_buffer *evt) | 130 | struct dwc3_event_buffer *evt) |
170 | { | 131 | { |
171 | dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); | 132 | dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); |
172 | kfree(evt); | ||
173 | } | 133 | } |
174 | 134 | ||
175 | /** | 135 | /** |
@@ -180,12 +140,11 @@ static void dwc3_free_one_event_buffer(struct dwc3 *dwc, | |||
180 | * Returns a pointer to the allocated event buffer structure on success | 140 | * Returns a pointer to the allocated event buffer structure on success |
181 | * otherwise ERR_PTR(errno). | 141 | * otherwise ERR_PTR(errno). |
182 | */ | 142 | */ |
183 | static struct dwc3_event_buffer *__devinit | 143 | static struct dwc3_event_buffer *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) |
184 | dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) | ||
185 | { | 144 | { |
186 | struct dwc3_event_buffer *evt; | 145 | struct dwc3_event_buffer *evt; |
187 | 146 | ||
188 | evt = kzalloc(sizeof(*evt), GFP_KERNEL); | 147 | evt = devm_kzalloc(dwc->dev, sizeof(*evt), GFP_KERNEL); |
189 | if (!evt) | 148 | if (!evt) |
190 | return ERR_PTR(-ENOMEM); | 149 | return ERR_PTR(-ENOMEM); |
191 | 150 | ||
@@ -193,10 +152,8 @@ dwc3_alloc_one_event_buffer(struct dwc3 *dwc, unsigned length) | |||
193 | evt->length = length; | 152 | evt->length = length; |
194 | evt->buf = dma_alloc_coherent(dwc->dev, length, | 153 | evt->buf = dma_alloc_coherent(dwc->dev, length, |
195 | &evt->dma, GFP_KERNEL); | 154 | &evt->dma, GFP_KERNEL); |
196 | if (!evt->buf) { | 155 | if (!evt->buf) |
197 | kfree(evt); | ||
198 | return ERR_PTR(-ENOMEM); | 156 | return ERR_PTR(-ENOMEM); |
199 | } | ||
200 | 157 | ||
201 | return evt; | 158 | return evt; |
202 | } | 159 | } |
@@ -215,8 +172,6 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc) | |||
215 | if (evt) | 172 | if (evt) |
216 | dwc3_free_one_event_buffer(dwc, evt); | 173 | dwc3_free_one_event_buffer(dwc, evt); |
217 | } | 174 | } |
218 | |||
219 | kfree(dwc->ev_buffs); | ||
220 | } | 175 | } |
221 | 176 | ||
222 | /** | 177 | /** |
@@ -227,7 +182,7 @@ static void dwc3_free_event_buffers(struct dwc3 *dwc) | |||
227 | * Returns 0 on success otherwise negative errno. In the error case, dwc | 182 | * Returns 0 on success otherwise negative errno. In the error case, dwc |
228 | * may contain some buffers allocated but not all which were requested. | 183 | * may contain some buffers allocated but not all which were requested. |
229 | */ | 184 | */ |
230 | static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) | 185 | static int dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) |
231 | { | 186 | { |
232 | int num; | 187 | int num; |
233 | int i; | 188 | int i; |
@@ -235,7 +190,8 @@ static int __devinit dwc3_alloc_event_buffers(struct dwc3 *dwc, unsigned length) | |||
235 | num = DWC3_NUM_INT(dwc->hwparams.hwparams1); | 190 | num = DWC3_NUM_INT(dwc->hwparams.hwparams1); |
236 | dwc->num_event_buffers = num; | 191 | dwc->num_event_buffers = num; |
237 | 192 | ||
238 | dwc->ev_buffs = kzalloc(sizeof(*dwc->ev_buffs) * num, GFP_KERNEL); | 193 | dwc->ev_buffs = devm_kzalloc(dwc->dev, sizeof(*dwc->ev_buffs) * num, |
194 | GFP_KERNEL); | ||
239 | if (!dwc->ev_buffs) { | 195 | if (!dwc->ev_buffs) { |
240 | dev_err(dwc->dev, "can't allocate event buffers array\n"); | 196 | dev_err(dwc->dev, "can't allocate event buffers array\n"); |
241 | return -ENOMEM; | 197 | return -ENOMEM; |
@@ -303,7 +259,7 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc) | |||
303 | } | 259 | } |
304 | } | 260 | } |
305 | 261 | ||
306 | static void __devinit dwc3_cache_hwparams(struct dwc3 *dwc) | 262 | static void dwc3_cache_hwparams(struct dwc3 *dwc) |
307 | { | 263 | { |
308 | struct dwc3_hwparams *parms = &dwc->hwparams; | 264 | struct dwc3_hwparams *parms = &dwc->hwparams; |
309 | 265 | ||
@@ -324,7 +280,7 @@ static void __devinit dwc3_cache_hwparams(struct dwc3 *dwc) | |||
324 | * | 280 | * |
325 | * Returns 0 on success otherwise negative errno. | 281 | * Returns 0 on success otherwise negative errno. |
326 | */ | 282 | */ |
327 | static int __devinit dwc3_core_init(struct dwc3 *dwc) | 283 | static int dwc3_core_init(struct dwc3 *dwc) |
328 | { | 284 | { |
329 | unsigned long timeout; | 285 | unsigned long timeout; |
330 | u32 reg; | 286 | u32 reg; |
@@ -358,8 +314,6 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc) | |||
358 | 314 | ||
359 | dwc3_core_soft_reset(dwc); | 315 | dwc3_core_soft_reset(dwc); |
360 | 316 | ||
361 | dwc3_cache_hwparams(dwc); | ||
362 | |||
363 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); | 317 | reg = dwc3_readl(dwc->regs, DWC3_GCTL); |
364 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; | 318 | reg &= ~DWC3_GCTL_SCALEDOWN_MASK; |
365 | reg &= ~DWC3_GCTL_DISSCRAMBLE; | 319 | reg &= ~DWC3_GCTL_DISSCRAMBLE; |
@@ -383,24 +337,14 @@ static int __devinit dwc3_core_init(struct dwc3 *dwc) | |||
383 | 337 | ||
384 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); | 338 | dwc3_writel(dwc->regs, DWC3_GCTL, reg); |
385 | 339 | ||
386 | ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); | ||
387 | if (ret) { | ||
388 | dev_err(dwc->dev, "failed to allocate event buffers\n"); | ||
389 | ret = -ENOMEM; | ||
390 | goto err1; | ||
391 | } | ||
392 | |||
393 | ret = dwc3_event_buffers_setup(dwc); | 340 | ret = dwc3_event_buffers_setup(dwc); |
394 | if (ret) { | 341 | if (ret) { |
395 | dev_err(dwc->dev, "failed to setup event buffers\n"); | 342 | dev_err(dwc->dev, "failed to setup event buffers\n"); |
396 | goto err1; | 343 | goto err0; |
397 | } | 344 | } |
398 | 345 | ||
399 | return 0; | 346 | return 0; |
400 | 347 | ||
401 | err1: | ||
402 | dwc3_free_event_buffers(dwc); | ||
403 | |||
404 | err0: | 348 | err0: |
405 | return ret; | 349 | return ret; |
406 | } | 350 | } |
@@ -408,16 +352,14 @@ err0: | |||
408 | static void dwc3_core_exit(struct dwc3 *dwc) | 352 | static void dwc3_core_exit(struct dwc3 *dwc) |
409 | { | 353 | { |
410 | dwc3_event_buffers_cleanup(dwc); | 354 | dwc3_event_buffers_cleanup(dwc); |
411 | dwc3_free_event_buffers(dwc); | ||
412 | 355 | ||
413 | usb_phy_shutdown(dwc->usb2_phy); | 356 | usb_phy_shutdown(dwc->usb2_phy); |
414 | usb_phy_shutdown(dwc->usb3_phy); | 357 | usb_phy_shutdown(dwc->usb3_phy); |
415 | |||
416 | } | 358 | } |
417 | 359 | ||
418 | #define DWC3_ALIGN_MASK (16 - 1) | 360 | #define DWC3_ALIGN_MASK (16 - 1) |
419 | 361 | ||
420 | static int __devinit dwc3_probe(struct platform_device *pdev) | 362 | static int dwc3_probe(struct platform_device *pdev) |
421 | { | 363 | { |
422 | struct device_node *node = pdev->dev.of_node; | 364 | struct device_node *node = pdev->dev.of_node; |
423 | struct resource *res; | 365 | struct resource *res; |
@@ -515,10 +457,19 @@ static int __devinit dwc3_probe(struct platform_device *pdev) | |||
515 | pm_runtime_get_sync(dev); | 457 | pm_runtime_get_sync(dev); |
516 | pm_runtime_forbid(dev); | 458 | pm_runtime_forbid(dev); |
517 | 459 | ||
460 | dwc3_cache_hwparams(dwc); | ||
461 | |||
462 | ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE); | ||
463 | if (ret) { | ||
464 | dev_err(dwc->dev, "failed to allocate event buffers\n"); | ||
465 | ret = -ENOMEM; | ||
466 | goto err0; | ||
467 | } | ||
468 | |||
518 | ret = dwc3_core_init(dwc); | 469 | ret = dwc3_core_init(dwc); |
519 | if (ret) { | 470 | if (ret) { |
520 | dev_err(dev, "failed to initialize core\n"); | 471 | dev_err(dev, "failed to initialize core\n"); |
521 | return ret; | 472 | goto err0; |
522 | } | 473 | } |
523 | 474 | ||
524 | mode = DWC3_MODE(dwc->hwparams.hwparams0); | 475 | mode = DWC3_MODE(dwc->hwparams.hwparams0); |
@@ -590,10 +541,13 @@ err2: | |||
590 | err1: | 541 | err1: |
591 | dwc3_core_exit(dwc); | 542 | dwc3_core_exit(dwc); |
592 | 543 | ||
544 | err0: | ||
545 | dwc3_free_event_buffers(dwc); | ||
546 | |||
593 | return ret; | 547 | return ret; |
594 | } | 548 | } |
595 | 549 | ||
596 | static int __devexit dwc3_remove(struct platform_device *pdev) | 550 | static int dwc3_remove(struct platform_device *pdev) |
597 | { | 551 | { |
598 | struct dwc3 *dwc = platform_get_drvdata(pdev); | 552 | struct dwc3 *dwc = platform_get_drvdata(pdev); |
599 | struct resource *res; | 553 | struct resource *res; |
@@ -628,7 +582,7 @@ static int __devexit dwc3_remove(struct platform_device *pdev) | |||
628 | 582 | ||
629 | static struct platform_driver dwc3_driver = { | 583 | static struct platform_driver dwc3_driver = { |
630 | .probe = dwc3_probe, | 584 | .probe = dwc3_probe, |
631 | .remove = __devexit_p(dwc3_remove), | 585 | .remove = dwc3_remove, |
632 | .driver = { | 586 | .driver = { |
633 | .name = "dwc3", | 587 | .name = "dwc3", |
634 | }, | 588 | }, |