Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] media: i2c/adp1653: Devicetree support for adp1653

Add device tree support for adp1653 flash LED driver.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Pavel Machek and committed by
Mauro Carvalho Chehab
074c57a2 b2dbde54

+95 -13
+90 -10
drivers/media/i2c/adp1653.c
··· 8 8 * Contributors: 9 9 * Sakari Ailus <sakari.ailus@iki.fi> 10 10 * Tuukka Toivonen <tuukkat76@gmail.com> 11 + * Pavel Machek <pavel@ucw.cz> 11 12 * 12 13 * This program is free software; you can redistribute it and/or 13 14 * modify it under the terms of the GNU General Public License ··· 35 34 #include <linux/module.h> 36 35 #include <linux/i2c.h> 37 36 #include <linux/slab.h> 37 + #include <linux/of.h> 38 + #include <linux/gpio/consumer.h> 38 39 #include <media/adp1653.h> 39 40 #include <media/v4l2-device.h> 40 41 ··· 311 308 { 312 309 int ret; 313 310 314 - ret = flash->platform_data->power(&flash->subdev, on); 315 - if (ret < 0) 316 - return ret; 311 + if (flash->platform_data->power) { 312 + ret = flash->platform_data->power(&flash->subdev, on); 313 + if (ret < 0) 314 + return ret; 315 + } else { 316 + gpiod_set_value(flash->platform_data->enable_gpio, on); 317 + if (on) 318 + /* Some delay is apparently required. */ 319 + udelay(20); 320 + } 317 321 318 322 if (!on) 319 323 return 0; 320 324 321 325 ret = adp1653_init_device(flash); 322 - if (ret < 0) 326 + if (ret >= 0) 327 + return ret; 328 + 329 + if (flash->platform_data->power) 323 330 flash->platform_data->power(&flash->subdev, 0); 331 + else 332 + gpiod_set_value(flash->platform_data->enable_gpio, 0); 324 333 325 334 return ret; 326 335 } ··· 422 407 423 408 #endif /* CONFIG_PM */ 424 409 410 + static int adp1653_of_init(struct i2c_client *client, 411 + struct adp1653_flash *flash, 412 + struct device_node *node) 413 + { 414 + struct adp1653_platform_data *pd; 415 + struct device_node *child; 416 + 417 + pd = devm_kzalloc(&client->dev, sizeof(*pd), GFP_KERNEL); 418 + if (!pd) 419 + return -ENOMEM; 420 + flash->platform_data = pd; 421 + 422 + child = of_get_child_by_name(node, "flash"); 423 + if (!child) 424 + return -EINVAL; 425 + 426 + if (of_property_read_u32(child, "flash-timeout-us", 427 + &pd->max_flash_timeout)) 428 + goto err; 429 + 430 + if (of_property_read_u32(child, "flash-max-microamp", 431 + &pd->max_flash_intensity)) 432 + goto err; 433 + 434 + pd->max_flash_intensity /= 1000; 435 + 436 + if (of_property_read_u32(child, "led-max-microamp", 437 + &pd->max_torch_intensity)) 438 + goto err; 439 + 440 + pd->max_torch_intensity /= 1000; 441 + of_node_put(child); 442 + 443 + child = of_get_child_by_name(node, "indicator"); 444 + if (!child) 445 + return -EINVAL; 446 + 447 + if (of_property_read_u32(child, "led-max-microamp", 448 + &pd->max_indicator_intensity)) 449 + goto err; 450 + 451 + of_node_put(child); 452 + 453 + pd->enable_gpio = devm_gpiod_get(&client->dev, "enable"); 454 + if (!pd->enable_gpio) { 455 + dev_err(&client->dev, "Error getting GPIO\n"); 456 + return -EINVAL; 457 + } 458 + 459 + return 0; 460 + err: 461 + dev_err(&client->dev, "Required property not found\n"); 462 + of_node_put(child); 463 + return -EINVAL; 464 + } 465 + 466 + 425 467 static int adp1653_probe(struct i2c_client *client, 426 468 const struct i2c_device_id *devid) 427 469 { 428 470 struct adp1653_flash *flash; 429 471 int ret; 430 472 431 - /* we couldn't work without platform data */ 432 - if (client->dev.platform_data == NULL) 433 - return -ENODEV; 434 - 435 473 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); 436 474 if (flash == NULL) 437 475 return -ENOMEM; 438 476 439 - flash->platform_data = client->dev.platform_data; 477 + if (client->dev.of_node) { 478 + ret = adp1653_of_init(client, flash, client->dev.of_node); 479 + if (ret) 480 + return ret; 481 + } else { 482 + if (!client->dev.platform_data) { 483 + dev_err(&client->dev, 484 + "Neither DT not platform data provided\n"); 485 + return EINVAL; 486 + } 487 + flash->platform_data = client->dev.platform_data; 488 + } 440 489 441 490 mutex_init(&flash->power_lock); 442 491 ··· 521 442 return 0; 522 443 523 444 free_and_quit: 445 + dev_err(&client->dev, "adp1653: failed to register device\n"); 524 446 v4l2_ctrl_handler_free(&flash->ctrls); 525 447 return ret; 526 448 } ··· 544 464 }; 545 465 MODULE_DEVICE_TABLE(i2c, adp1653_id_table); 546 466 547 - static struct dev_pm_ops adp1653_pm_ops = { 467 + static const struct dev_pm_ops adp1653_pm_ops = { 548 468 .suspend = adp1653_suspend, 549 469 .resume = adp1653_resume, 550 470 };
+5 -3
include/media/adp1653.h
··· 100 100 int (*power)(struct v4l2_subdev *sd, int on); 101 101 102 102 u32 max_flash_timeout; /* flash light timeout in us */ 103 - u32 max_flash_intensity; /* led intensity, flash mode */ 104 - u32 max_torch_intensity; /* led intensity, torch mode */ 105 - u32 max_indicator_intensity; /* indicator led intensity */ 103 + u32 max_flash_intensity; /* led intensity, flash mode, mA */ 104 + u32 max_torch_intensity; /* led intensity, torch mode, mA */ 105 + u32 max_indicator_intensity; /* indicator led intensity, uA */ 106 + 107 + struct gpio_desc *enable_gpio; /* for device-tree based boot */ 106 108 }; 107 109 108 110 #define to_adp1653_flash(sd) container_of(sd, struct adp1653_flash, subdev)