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

media: noon010p30: Convert to use GPIO descriptors

The noon010pc30 sensor driver is using legacy gpio numbers passed
through platform data and open coding reverse polarity on the
GPIOs used for reset and standby.

Nothing in the kernel defines any platform data for this driver
so we can just convert the driver to use GPIO descriptors and
requires that these specify the correct polarity instead.

Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

authored by

Linus Walleij and committed by
Sakari Ailus
b70f5cd8 200ae4b5

+35 -44
+35 -40
drivers/media/i2c/noon010pc30.c
··· 10 10 */ 11 11 12 12 #include <linux/delay.h> 13 - #include <linux/gpio.h> 13 + #include <linux/gpio/consumer.h> 14 14 #include <linux/i2c.h> 15 15 #include <linux/slab.h> 16 16 #include <linux/regulator/consumer.h> ··· 130 130 struct media_pad pad; 131 131 struct v4l2_ctrl_handler hdl; 132 132 struct regulator_bulk_data supply[NOON010_NUM_SUPPLIES]; 133 - u32 gpio_nreset; 134 - u32 gpio_nstby; 133 + struct gpio_desc *reset; 134 + struct gpio_desc *stby; 135 135 136 136 /* Protects the struct members below */ 137 137 struct mutex lock; ··· 393 393 return 0; 394 394 } 395 395 396 - if (gpio_is_valid(info->gpio_nstby)) 397 - gpio_set_value(info->gpio_nstby, 0); 396 + /* Assert standby: line should be flagged active low in descriptor */ 397 + if (info->stby) 398 + gpiod_set_value(info->stby, 1); 398 399 399 - if (gpio_is_valid(info->gpio_nreset)) 400 - gpio_set_value(info->gpio_nreset, 0); 400 + /* Assert reset: line should be flagged active low in descriptor */ 401 + if (info->reset) 402 + gpiod_set_value(info->reset, 1); 401 403 402 404 ret = regulator_bulk_enable(NOON010_NUM_SUPPLIES, info->supply); 403 405 if (ret) 404 406 return ret; 405 407 406 - if (gpio_is_valid(info->gpio_nreset)) { 408 + /* De-assert reset and standby */ 409 + if (info->reset) { 407 410 msleep(50); 408 - gpio_set_value(info->gpio_nreset, 1); 411 + gpiod_set_value(info->reset, 0); 409 412 } 410 - if (gpio_is_valid(info->gpio_nstby)) { 413 + if (info->stby) { 411 414 udelay(1000); 412 - gpio_set_value(info->gpio_nstby, 1); 415 + gpiod_set_value(info->stby, 0); 413 416 } 414 - if (gpio_is_valid(info->gpio_nreset)) { 417 + /* Cycle reset: assert and deassert */ 418 + if (info->reset) { 415 419 udelay(1000); 416 - gpio_set_value(info->gpio_nreset, 0); 420 + gpiod_set_value(info->reset, 1); 417 421 msleep(100); 418 - gpio_set_value(info->gpio_nreset, 1); 422 + gpiod_set_value(info->reset, 0); 419 423 msleep(20); 420 424 } 421 425 info->power = 1; ··· 442 438 if (ret) 443 439 return ret; 444 440 445 - if (gpio_is_valid(info->gpio_nstby)) 446 - gpio_set_value(info->gpio_nstby, 0); 441 + /* Assert standby and reset */ 442 + if (info->stby) 443 + gpiod_set_value(info->stby, 1); 447 444 448 - if (gpio_is_valid(info->gpio_nreset)) 449 - gpio_set_value(info->gpio_nreset, 0); 445 + if (info->reset) 446 + gpiod_set_value(info->reset, 1); 450 447 451 448 info->power = 0; 452 449 ··· 746 741 goto np_err; 747 742 748 743 info->i2c_reg_page = -1; 749 - info->gpio_nreset = -EINVAL; 750 - info->gpio_nstby = -EINVAL; 751 744 info->curr_fmt = &noon010_formats[0]; 752 745 info->curr_win = &noon010_sizes[0]; 753 746 754 - if (gpio_is_valid(pdata->gpio_nreset)) { 755 - ret = devm_gpio_request_one(&client->dev, pdata->gpio_nreset, 756 - GPIOF_OUT_INIT_LOW, 757 - "NOON010PC30 NRST"); 758 - if (ret) { 759 - dev_err(&client->dev, "GPIO request error: %d\n", ret); 760 - goto np_err; 761 - } 762 - info->gpio_nreset = pdata->gpio_nreset; 763 - gpio_export(info->gpio_nreset, 0); 747 + /* Request reset asserted so we get put into reset */ 748 + info->reset = devm_gpiod_get(&client->dev, "reset", GPIOD_OUT_HIGH); 749 + if (IS_ERR(info->reset)) { 750 + ret = PTR_ERR(info->reset); 751 + goto np_err; 764 752 } 753 + gpiod_set_consumer_name(info->reset, "NOON010PC30 NRST"); 765 754 766 - if (gpio_is_valid(pdata->gpio_nstby)) { 767 - ret = devm_gpio_request_one(&client->dev, pdata->gpio_nstby, 768 - GPIOF_OUT_INIT_LOW, 769 - "NOON010PC30 NSTBY"); 770 - if (ret) { 771 - dev_err(&client->dev, "GPIO request error: %d\n", ret); 772 - goto np_err; 773 - } 774 - info->gpio_nstby = pdata->gpio_nstby; 775 - gpio_export(info->gpio_nstby, 0); 755 + /* Request standby asserted so we get put into standby */ 756 + info->stby = devm_gpiod_get(&client->dev, "standby", GPIOD_OUT_HIGH); 757 + if (IS_ERR(info->stby)) { 758 + ret = PTR_ERR(info->stby); 759 + goto np_err; 776 760 } 761 + gpiod_set_consumer_name(info->reset, "NOON010PC30 STBY"); 777 762 778 763 for (i = 0; i < NOON010_NUM_SUPPLIES; i++) 779 764 info->supply[i].supply = noon010_supply_name[i];
-4
include/media/i2c/noon010pc30.h
··· 12 12 /** 13 13 * struct noon010pc30_platform_data - platform data 14 14 * @clk_rate: the clock frequency in Hz 15 - * @gpio_nreset: GPIO driving nRESET pin 16 - * @gpio_nstby: GPIO driving nSTBY pin 17 15 */ 18 16 19 17 struct noon010pc30_platform_data { 20 18 unsigned long clk_rate; 21 - int gpio_nreset; 22 - int gpio_nstby; 23 19 }; 24 20 25 21 #endif /* NOON010PC30_H */