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

[media] Add device tree support to adp1653 flash driver

Nokia N900 is switching to device tree, make sure we can use flash
there, too.

Signed-off-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Pavel Machek and committed by
Mauro Carvalho Chehab
b6100f10 09f50121

+118 -9
+37
Documentation/devicetree/bindings/media/i2c/adp1653.txt
··· 1 + * Analog Devices ADP1653 flash LED driver 2 + 3 + Required Properties: 4 + 5 + - compatible: Must contain be "adi,adp1653" 6 + 7 + - reg: I2C slave address 8 + 9 + - gpios: References to the GPIO that controls the power for the chip. 10 + 11 + There are two led outputs available - flash and indicator. One led is 12 + represented by one child node, nodes need to be named "flash" and "indicator". 13 + 14 + Required properties of the LED child node: 15 + - max-microamp : see Documentation/devicetree/bindings/leds/common.txt 16 + 17 + Required properties of the flash LED child node: 18 + 19 + - flash-max-microamp : see Documentation/devicetree/bindings/leds/common.txt 20 + - flash-timeout-us : see Documentation/devicetree/bindings/leds/common.txt 21 + 22 + Example: 23 + 24 + adp1653: led-controller@30 { 25 + compatible = "adi,adp1653"; 26 + reg = <0x30>; 27 + gpios = <&gpio3 24 GPIO_ACTIVE_HIGH>; /* 88 */ 28 + 29 + flash { 30 + flash-timeout-us = <500000>; 31 + flash-max-microamp = <320000>; 32 + max-microamp = <50000>; 33 + }; 34 + indicator { 35 + max-microamp = <17500>; 36 + }; 37 + };
+81 -9
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_gpio.h> 38 + #include <linux/gpio.h> 38 39 #include <media/adp1653.h> 39 40 #include <media/v4l2-device.h> 40 41 ··· 309 306 static int 310 307 __adp1653_set_power(struct adp1653_flash *flash, int on) 311 308 { 312 - int ret; 309 + int ret = 0; 313 310 314 - ret = flash->platform_data->power(&flash->subdev, on); 311 + if (flash->platform_data->power) { 312 + ret = flash->platform_data->power(&flash->subdev, on); 313 + } else { 314 + gpio_set_value(flash->platform_data->power_gpio, on); 315 + if (on) 316 + /* Some delay is apparently required. */ 317 + udelay(20); 318 + } 319 + 315 320 if (ret < 0) 316 321 return ret; 317 322 ··· 327 316 return 0; 328 317 329 318 ret = adp1653_init_device(flash); 330 - if (ret < 0) 319 + if (ret >= 0) 320 + return ret; 321 + 322 + if (flash->platform_data->power) 331 323 flash->platform_data->power(&flash->subdev, 0); 324 + else 325 + gpio_set_value(flash->platform_data->power_gpio, 0); 332 326 333 327 return ret; 334 328 } ··· 423 407 424 408 #endif /* CONFIG_PM */ 425 409 410 + static int adp1653_of_init(struct i2c_client *client, 411 + struct adp1653_flash *flash, 412 + struct device_node *node) 413 + { 414 + u32 val; 415 + struct adp1653_platform_data *pd; 416 + enum of_gpio_flags flags; 417 + int gpio; 418 + struct device_node *child; 419 + 420 + if (!node) 421 + return -EINVAL; 422 + 423 + pd = devm_kzalloc(&client->dev, sizeof(*pd), GFP_KERNEL); 424 + if (!pd) 425 + return -ENOMEM; 426 + flash->platform_data = pd; 427 + 428 + child = of_get_child_by_name(node, "flash"); 429 + if (!child) 430 + return -EINVAL; 431 + if (of_property_read_u32(child, "flash-timeout-microsec", &val)) 432 + return -EINVAL; 433 + 434 + pd->max_flash_timeout = val; 435 + if (of_property_read_u32(child, "flash-max-microamp", &val)) 436 + return -EINVAL; 437 + pd->max_flash_intensity = val/1000; 438 + 439 + if (of_property_read_u32(child, "max-microamp", &val)) 440 + return -EINVAL; 441 + pd->max_torch_intensity = val/1000; 442 + 443 + child = of_get_child_by_name(node, "indicator"); 444 + if (!child) 445 + return -EINVAL; 446 + if (of_property_read_u32(child, "max-microamp", &val)) 447 + return -EINVAL; 448 + pd->max_indicator_intensity = val; 449 + 450 + if (!of_find_property(node, "gpios", NULL)) { 451 + dev_err(&client->dev, "No gpio node\n"); 452 + return -EINVAL; 453 + } 454 + 455 + pd->power_gpio = of_get_gpio_flags(node, 0, &flags); 456 + if (pd->power_gpio < 0) { 457 + dev_err(&client->dev, "Error getting GPIO\n"); 458 + return -EINVAL; 459 + } 460 + 461 + return 0; 462 + } 463 + 464 + 426 465 static int adp1653_probe(struct i2c_client *client, 427 466 const struct i2c_device_id *devid) 428 467 { 429 468 struct adp1653_flash *flash; 430 469 int ret; 431 470 432 - /* we couldn't work without platform data */ 433 - if (client->dev.platform_data == NULL) 434 - return -ENODEV; 435 - 436 471 flash = devm_kzalloc(&client->dev, sizeof(*flash), GFP_KERNEL); 437 472 if (flash == NULL) 438 473 return -ENOMEM; 439 474 440 475 flash->platform_data = client->dev.platform_data; 476 + if (!flash->platform_data) { 477 + ret = adp1653_of_init(client, flash, client->dev.of_node); 478 + if (ret) 479 + return ret; 480 + } 441 481 442 482 mutex_init(&flash->power_lock); 443 483 ··· 510 438 goto free_and_quit; 511 439 512 440 flash->subdev.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_FLASH; 513 - 514 441 return 0; 515 442 516 443 free_and_quit: 444 + dev_err(&client->dev, "adp1653: failed to register device\n"); 517 445 v4l2_ctrl_handler_free(&flash->ctrls); 518 446 return ret; 519 447 } ··· 536 464 }; 537 465 MODULE_DEVICE_TABLE(i2c, adp1653_id_table); 538 466 539 - static struct dev_pm_ops adp1653_pm_ops = { 467 + static const struct dev_pm_ops adp1653_pm_ops = { 540 468 .suspend = adp1653_suspend, 541 469 .resume = adp1653_resume, 542 470 };