diff options
author | Peter Ujfalusi <peter.ujfalusi@ti.com> | 2013-01-25 03:03:50 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2013-01-25 03:06:48 -0500 |
commit | b2ebcc1be96ee6dd5481697b421447e5a3f61d76 (patch) | |
tree | 81759c27955e0be4f0b96668d4919bafda0f8c6e /drivers/input/misc/twl6040-vibra.c | |
parent | 6f2ac009f29bcbd468a7a2017912dd090abd1348 (diff) |
Input: twl6040-vibra - code cleanup in probe with devm_* conversion
Convert the probe to use devm_*. At the same time reorder the calls
so we will register the input device as the last step when the driver
is loaded.
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc/twl6040-vibra.c')
-rw-r--r-- | drivers/input/misc/twl6040-vibra.c | 99 |
1 files changed, 45 insertions, 54 deletions
diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c index 71a28ee699f3..d1e31b8eb121 100644 --- a/drivers/input/misc/twl6040-vibra.c +++ b/drivers/input/misc/twl6040-vibra.c | |||
@@ -275,7 +275,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
275 | return -EINVAL; | 275 | return -EINVAL; |
276 | } | 276 | } |
277 | 277 | ||
278 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 278 | info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); |
279 | if (!info) { | 279 | if (!info) { |
280 | dev_err(&pdev->dev, "couldn't allocate memory\n"); | 280 | dev_err(&pdev->dev, "couldn't allocate memory\n"); |
281 | return -ENOMEM; | 281 | return -ENOMEM; |
@@ -309,53 +309,23 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
309 | if ((!info->vibldrv_res && !info->viblmotor_res) || | 309 | if ((!info->vibldrv_res && !info->viblmotor_res) || |
310 | (!info->vibrdrv_res && !info->vibrmotor_res)) { | 310 | (!info->vibrdrv_res && !info->vibrmotor_res)) { |
311 | dev_err(info->dev, "invalid vibra driver/motor resistance\n"); | 311 | dev_err(info->dev, "invalid vibra driver/motor resistance\n"); |
312 | ret = -EINVAL; | 312 | return -EINVAL; |
313 | goto err_kzalloc; | ||
314 | } | 313 | } |
315 | 314 | ||
316 | info->irq = platform_get_irq(pdev, 0); | 315 | info->irq = platform_get_irq(pdev, 0); |
317 | if (info->irq < 0) { | 316 | if (info->irq < 0) { |
318 | dev_err(info->dev, "invalid irq\n"); | 317 | dev_err(info->dev, "invalid irq\n"); |
319 | ret = -EINVAL; | 318 | return -EINVAL; |
320 | goto err_kzalloc; | ||
321 | } | 319 | } |
322 | 320 | ||
323 | mutex_init(&info->mutex); | 321 | mutex_init(&info->mutex); |
324 | 322 | ||
325 | info->input_dev = input_allocate_device(); | 323 | ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, |
326 | if (info->input_dev == NULL) { | 324 | twl6040_vib_irq_handler, 0, |
327 | dev_err(info->dev, "couldn't allocate input device\n"); | 325 | "twl6040_irq_vib", info); |
328 | ret = -ENOMEM; | ||
329 | goto err_kzalloc; | ||
330 | } | ||
331 | |||
332 | input_set_drvdata(info->input_dev, info); | ||
333 | |||
334 | info->input_dev->name = "twl6040:vibrator"; | ||
335 | info->input_dev->id.version = 1; | ||
336 | info->input_dev->dev.parent = pdev->dev.parent; | ||
337 | info->input_dev->close = twl6040_vibra_close; | ||
338 | __set_bit(FF_RUMBLE, info->input_dev->ffbit); | ||
339 | |||
340 | ret = input_ff_create_memless(info->input_dev, NULL, vibra_play); | ||
341 | if (ret < 0) { | ||
342 | dev_err(info->dev, "couldn't register vibrator to FF\n"); | ||
343 | goto err_ialloc; | ||
344 | } | ||
345 | |||
346 | ret = input_register_device(info->input_dev); | ||
347 | if (ret < 0) { | ||
348 | dev_err(info->dev, "couldn't register input device\n"); | ||
349 | goto err_iff; | ||
350 | } | ||
351 | |||
352 | platform_set_drvdata(pdev, info); | ||
353 | |||
354 | ret = request_threaded_irq(info->irq, NULL, twl6040_vib_irq_handler, 0, | ||
355 | "twl6040_irq_vib", info); | ||
356 | if (ret) { | 326 | if (ret) { |
357 | dev_err(info->dev, "VIB IRQ request failed: %d\n", ret); | 327 | dev_err(info->dev, "VIB IRQ request failed: %d\n", ret); |
358 | goto err_irq; | 328 | return ret; |
359 | } | 329 | } |
360 | 330 | ||
361 | info->supplies[0].supply = "vddvibl"; | 331 | info->supplies[0].supply = "vddvibl"; |
@@ -368,7 +338,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
368 | ARRAY_SIZE(info->supplies), info->supplies); | 338 | ARRAY_SIZE(info->supplies), info->supplies); |
369 | if (ret) { | 339 | if (ret) { |
370 | dev_err(info->dev, "couldn't get regulators %d\n", ret); | 340 | dev_err(info->dev, "couldn't get regulators %d\n", ret); |
371 | goto err_regulator; | 341 | return ret; |
372 | } | 342 | } |
373 | 343 | ||
374 | if (vddvibl_uV) { | 344 | if (vddvibl_uV) { |
@@ -377,7 +347,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
377 | if (ret) { | 347 | if (ret) { |
378 | dev_err(info->dev, "failed to set VDDVIBL volt %d\n", | 348 | dev_err(info->dev, "failed to set VDDVIBL volt %d\n", |
379 | ret); | 349 | ret); |
380 | goto err_voltage; | 350 | goto err_regulator; |
381 | } | 351 | } |
382 | } | 352 | } |
383 | 353 | ||
@@ -387,7 +357,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
387 | if (ret) { | 357 | if (ret) { |
388 | dev_err(info->dev, "failed to set VDDVIBR volt %d\n", | 358 | dev_err(info->dev, "failed to set VDDVIBR volt %d\n", |
389 | ret); | 359 | ret); |
390 | goto err_voltage; | 360 | goto err_regulator; |
391 | } | 361 | } |
392 | } | 362 | } |
393 | 363 | ||
@@ -395,26 +365,49 @@ static int twl6040_vibra_probe(struct platform_device *pdev) | |||
395 | if (info->workqueue == NULL) { | 365 | if (info->workqueue == NULL) { |
396 | dev_err(info->dev, "couldn't create workqueue\n"); | 366 | dev_err(info->dev, "couldn't create workqueue\n"); |
397 | ret = -ENOMEM; | 367 | ret = -ENOMEM; |
398 | goto err_voltage; | 368 | goto err_regulator; |
399 | } | 369 | } |
400 | INIT_WORK(&info->play_work, vibra_play_work); | 370 | INIT_WORK(&info->play_work, vibra_play_work); |
401 | 371 | ||
372 | info->input_dev = input_allocate_device(); | ||
373 | if (info->input_dev == NULL) { | ||
374 | dev_err(info->dev, "couldn't allocate input device\n"); | ||
375 | ret = -ENOMEM; | ||
376 | goto err_wq; | ||
377 | } | ||
378 | |||
379 | input_set_drvdata(info->input_dev, info); | ||
380 | |||
381 | info->input_dev->name = "twl6040:vibrator"; | ||
382 | info->input_dev->id.version = 1; | ||
383 | info->input_dev->dev.parent = pdev->dev.parent; | ||
384 | info->input_dev->close = twl6040_vibra_close; | ||
385 | __set_bit(FF_RUMBLE, info->input_dev->ffbit); | ||
386 | |||
387 | ret = input_ff_create_memless(info->input_dev, NULL, vibra_play); | ||
388 | if (ret < 0) { | ||
389 | dev_err(info->dev, "couldn't register vibrator to FF\n"); | ||
390 | goto err_ialloc; | ||
391 | } | ||
392 | |||
393 | ret = input_register_device(info->input_dev); | ||
394 | if (ret < 0) { | ||
395 | dev_err(info->dev, "couldn't register input device\n"); | ||
396 | goto err_iff; | ||
397 | } | ||
398 | |||
399 | platform_set_drvdata(pdev, info); | ||
400 | |||
402 | return 0; | 401 | return 0; |
403 | 402 | ||
404 | err_voltage: | ||
405 | regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies); | ||
406 | err_regulator: | ||
407 | free_irq(info->irq, info); | ||
408 | err_irq: | ||
409 | input_unregister_device(info->input_dev); | ||
410 | info->input_dev = NULL; | ||
411 | err_iff: | 403 | err_iff: |
412 | if (info->input_dev) | 404 | input_ff_destroy(info->input_dev); |
413 | input_ff_destroy(info->input_dev); | ||
414 | err_ialloc: | 405 | err_ialloc: |
415 | input_free_device(info->input_dev); | 406 | input_free_device(info->input_dev); |
416 | err_kzalloc: | 407 | err_wq: |
417 | kfree(info); | 408 | destroy_workqueue(info->workqueue); |
409 | err_regulator: | ||
410 | regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies); | ||
418 | return ret; | 411 | return ret; |
419 | } | 412 | } |
420 | 413 | ||
@@ -423,10 +416,8 @@ static int twl6040_vibra_remove(struct platform_device *pdev) | |||
423 | struct vibra_info *info = platform_get_drvdata(pdev); | 416 | struct vibra_info *info = platform_get_drvdata(pdev); |
424 | 417 | ||
425 | input_unregister_device(info->input_dev); | 418 | input_unregister_device(info->input_dev); |
426 | free_irq(info->irq, info); | ||
427 | regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies); | 419 | regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies); |
428 | destroy_workqueue(info->workqueue); | 420 | destroy_workqueue(info->workqueue); |
429 | kfree(info); | ||
430 | 421 | ||
431 | return 0; | 422 | return 0; |
432 | } | 423 | } |