aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/misc
diff options
context:
space:
mode:
authorFabio Estevam <fabio.estevam@freescale.com>2014-04-25 12:21:12 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2014-05-14 19:39:47 -0400
commit1f9e1470ab34fe7e523014ae30dd3b2e65177ae4 (patch)
tree1b673cc5b2401658dbb1d0db2de94d6962cff602 /drivers/input/misc
parentc728601ea3531dc1f0dcd74c1db1e85e59f2be68 (diff)
Input: twl6040-vibra - use devm functions
Using devm_regulator_bulk_get() and devm_input_allocate_device() can make the code cleaner and smaller as we do not need to manually free resources the error and remove paths. Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Diffstat (limited to 'drivers/input/misc')
-rw-r--r--drivers/input/misc/twl6040-vibra.c83
1 files changed, 32 insertions, 51 deletions
diff --git a/drivers/input/misc/twl6040-vibra.c b/drivers/input/misc/twl6040-vibra.c
index 77dc23b94eb1..6d26eecc278c 100644
--- a/drivers/input/misc/twl6040-vibra.c
+++ b/drivers/input/misc/twl6040-vibra.c
@@ -262,7 +262,7 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
262 struct vibra_info *info; 262 struct vibra_info *info;
263 int vddvibl_uV = 0; 263 int vddvibl_uV = 0;
264 int vddvibr_uV = 0; 264 int vddvibr_uV = 0;
265 int ret; 265 int error;
266 266
267 twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node, 267 twl6040_core_node = of_find_node_by_name(twl6040_core_dev->of_node,
268 "vibra"); 268 "vibra");
@@ -309,12 +309,12 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
309 309
310 mutex_init(&info->mutex); 310 mutex_init(&info->mutex);
311 311
312 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, 312 error = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
313 twl6040_vib_irq_handler, 0, 313 twl6040_vib_irq_handler, 0,
314 "twl6040_irq_vib", info); 314 "twl6040_irq_vib", info);
315 if (ret) { 315 if (error) {
316 dev_err(info->dev, "VIB IRQ request failed: %d\n", ret); 316 dev_err(info->dev, "VIB IRQ request failed: %d\n", error);
317 return ret; 317 return error;
318 } 318 }
319 319
320 info->supplies[0].supply = "vddvibl"; 320 info->supplies[0].supply = "vddvibl";
@@ -323,40 +323,40 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
323 * When booted with Device tree the regulators are attached to the 323 * When booted with Device tree the regulators are attached to the
324 * parent device (twl6040 MFD core) 324 * parent device (twl6040 MFD core)
325 */ 325 */
326 ret = regulator_bulk_get(twl6040_core_dev, ARRAY_SIZE(info->supplies), 326 error = devm_regulator_bulk_get(twl6040_core_dev,
327 info->supplies); 327 ARRAY_SIZE(info->supplies),
328 if (ret) { 328 info->supplies);
329 dev_err(info->dev, "couldn't get regulators %d\n", ret); 329 if (error) {
330 return ret; 330 dev_err(info->dev, "couldn't get regulators %d\n", error);
331 return error;
331 } 332 }
332 333
333 if (vddvibl_uV) { 334 if (vddvibl_uV) {
334 ret = regulator_set_voltage(info->supplies[0].consumer, 335 error = regulator_set_voltage(info->supplies[0].consumer,
335 vddvibl_uV, vddvibl_uV); 336 vddvibl_uV, vddvibl_uV);
336 if (ret) { 337 if (error) {
337 dev_err(info->dev, "failed to set VDDVIBL volt %d\n", 338 dev_err(info->dev, "failed to set VDDVIBL volt %d\n",
338 ret); 339 error);
339 goto err_regulator; 340 return error;
340 } 341 }
341 } 342 }
342 343
343 if (vddvibr_uV) { 344 if (vddvibr_uV) {
344 ret = regulator_set_voltage(info->supplies[1].consumer, 345 error = regulator_set_voltage(info->supplies[1].consumer,
345 vddvibr_uV, vddvibr_uV); 346 vddvibr_uV, vddvibr_uV);
346 if (ret) { 347 if (error) {
347 dev_err(info->dev, "failed to set VDDVIBR volt %d\n", 348 dev_err(info->dev, "failed to set VDDVIBR volt %d\n",
348 ret); 349 error);
349 goto err_regulator; 350 return error;
350 } 351 }
351 } 352 }
352 353
353 INIT_WORK(&info->play_work, vibra_play_work); 354 INIT_WORK(&info->play_work, vibra_play_work);
354 355
355 info->input_dev = input_allocate_device(); 356 info->input_dev = devm_input_allocate_device(&pdev->dev);
356 if (info->input_dev == NULL) { 357 if (!info->input_dev) {
357 dev_err(info->dev, "couldn't allocate input device\n"); 358 dev_err(info->dev, "couldn't allocate input device\n");
358 ret = -ENOMEM; 359 return -ENOMEM;
359 goto err_regulator;
360 } 360 }
361 361
362 input_set_drvdata(info->input_dev, info); 362 input_set_drvdata(info->input_dev, info);
@@ -367,44 +367,25 @@ static int twl6040_vibra_probe(struct platform_device *pdev)
367 info->input_dev->close = twl6040_vibra_close; 367 info->input_dev->close = twl6040_vibra_close;
368 __set_bit(FF_RUMBLE, info->input_dev->ffbit); 368 __set_bit(FF_RUMBLE, info->input_dev->ffbit);
369 369
370 ret = input_ff_create_memless(info->input_dev, NULL, vibra_play); 370 error = input_ff_create_memless(info->input_dev, NULL, vibra_play);
371 if (ret < 0) { 371 if (error) {
372 dev_err(info->dev, "couldn't register vibrator to FF\n"); 372 dev_err(info->dev, "couldn't register vibrator to FF\n");
373 goto err_ialloc; 373 return error;
374 } 374 }
375 375
376 ret = input_register_device(info->input_dev); 376 error = input_register_device(info->input_dev);
377 if (ret < 0) { 377 if (error) {
378 dev_err(info->dev, "couldn't register input device\n"); 378 dev_err(info->dev, "couldn't register input device\n");
379 goto err_iff; 379 return error;
380 } 380 }
381 381
382 platform_set_drvdata(pdev, info); 382 platform_set_drvdata(pdev, info);
383 383
384 return 0; 384 return 0;
385
386err_iff:
387 input_ff_destroy(info->input_dev);
388err_ialloc:
389 input_free_device(info->input_dev);
390err_regulator:
391 regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
392 return ret;
393}
394
395static int twl6040_vibra_remove(struct platform_device *pdev)
396{
397 struct vibra_info *info = platform_get_drvdata(pdev);
398
399 input_unregister_device(info->input_dev);
400 regulator_bulk_free(ARRAY_SIZE(info->supplies), info->supplies);
401
402 return 0;
403} 385}
404 386
405static struct platform_driver twl6040_vibra_driver = { 387static struct platform_driver twl6040_vibra_driver = {
406 .probe = twl6040_vibra_probe, 388 .probe = twl6040_vibra_probe,
407 .remove = twl6040_vibra_remove,
408 .driver = { 389 .driver = {
409 .name = "twl6040-vibra", 390 .name = "twl6040-vibra",
410 .owner = THIS_MODULE, 391 .owner = THIS_MODULE,