media: s5c73m3: replace legacy gpio interface for gpiod
Subsystems (2)
PATCH v2 1/1 media: s5c73m3: replace legacy gpio interface for gpiod
Considering the current transition of the GPIO subsystem, remove all dependencies of the legacy GPIO interface (linux/gpio.h and linux /of_gpio.h) and replace it with the descriptor-based GPIO approach.
---
V1 -> V2: As suggested by Andrzej, all s5c73m3 specific gpio code is completely removed.
--- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 95 ++++++++++-------------- drivers/media/i2c/s5c73m3/s5c73m3.h | 9 +-- include/media/i2c/s5c73m3.h | 15 +--- 3 files changed, 44 insertions(+), 75 deletions(-)
drivers/media/i2c/s5c73m3/s5c73m3-core.c +39 -56
@@ -10,12 +10,11 @@#include <linux/clk.h> #include <linux/delay.h> #include <linux/firmware.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/media.h> #include <linux/module.h> -#include <linux/of_gpio.h> #include <linux/of_graph.h> #include <linux/regulator/consumer.h> #include <linux/sizes.h>
@@ -1347,22 +1346,26 @@ static int s5c73m3_oif_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)return 0 ; } -static int s5c73m3_gpio_set_value (struct s5c73m3 *priv,int id,u32 val) +static int s5c73m3_gpio_set_value (struct gpio_desc *gpio,int val) { -if (!gpio_is_valid (priv->gpio[id].gpio)) +if (!gpio)return 0 ; -gpio_set_value (priv->gpio[id].gpio, !!val); +gpiod_set_value (gpio, !!val);return 1 ; } -static int s5c73m3_gpio_assert (struct s5c73m3 *priv,int id) +static int s5c73m3_gpio_assert (struct gpio_desc *gpio) { -return s5c73m3_gpio_set_value (priv, id, priv->gpio[id].level); +int val =gpiod_set_value (gpio); + +return s5c73m3_gpio_set_value (gpio, val); } -static int s5c73m3_gpio_deassert (struct s5c73m3 *priv,int id) +static int s5c73m3_gpio_deassert (struct gpio_desc *gpio) { -return s5c73m3_gpio_set_value (priv, id, !priv->gpio[id].level); +int val =gpiod_set_value (gpio); + +return s5c73m3_gpio_set_value (gpio, !val); }static int __s5c73m3_power_on (struct s5c73m3 *state)
@@ -1386,10 +1389,10 @@ static int __s5c73m3_power_on(struct s5c73m3 *state)v4l2_dbg (1 , s5c73m3_dbg, &state->oif_sd,"clock frequency: %ld\n" ,clk_get_rate (state->clock)); -s5c73m3_gpio_deassert (state,STBY ); +s5c73m3_gpio_deassert (state->gpio_stby);usleep_range (100 ,200 ); -s5c73m3_gpio_deassert (state,RSET ); +s5c73m3_gpio_deassert (state->gpio_reset);usleep_range (50 ,100 );return 0 ;
@@ -1404,10 +1407,10 @@ static int __s5c73m3_power_off(struct s5c73m3 *state) {int i, ret; -if (s5c73m3_gpio_assert (state,RSET )) +if (s5c73m3_gpio_assert (state->gpio_reset))usleep_range (10 ,50 ); -if (s5c73m3_gpio_assert (state,STBY )) +if (s5c73m3_gpio_assert (state->gpio_stby))usleep_range (100 ,200 );clk_disable_unprepare (state->clock);
@@ -1545,50 +1548,34 @@ static const struct v4l2_subdev_ops oif_subdev_ops = {static int s5c73m3_configure_gpios (struct s5c73m3 *state) { -static const char *const gpio_names[] = { -"S5C73M3_STBY" ,"S5C73M3_RST" - };struct i2c_client *c = state->i2c_client; -struct s5c73m3_gpio *g = state->gpio; -int ret, i; +struct device *dev = &c->dev; +struct device_node *np = dev->of_node; -for (i =0 ; i <GPIO_NUM ; ++i) { -unsigned int flags =GPIOF_DIR_OUT ; -if (g[i].level) - flags |=GPIOF_INIT_HIGH ; - ret =devm_gpio_request_one (&c->dev, g[i].gpio, flags, - gpio_names[i]); -if (ret) { -v4l2_err (c,"failed to request gpio %s\n" , - gpio_names[i]); -return ret; - } + state->gpio_stby =gpiod_get_from_of_node (np,"standby-gpios" ,0 ,GPIOD_ASIS , +"S5C73M3_STBY" ); + +if (IS_ERR (state->gpio_stby)) { +v4l2_err (c,"failed to request gpio S5C73M3_STBY" ); +return PTR_ERR (state->gpio_stby); } -return 0 ; -} -static int s5c73m3_parse_gpios (struct s5c73m3 *state) -{ -static const char *const prop_names[] = { -"standby-gpios" ,"xshutdown-gpios" , - }; -struct device *dev = &state->i2c_client->dev; -struct device_node *node = dev->of_node; -int ret, i; +if (state->gpio_stby) +gpiod_direction_output (state->gpio_stby, + !gpiod_is_active_low (state->gpio_stby)); -for (i =0 ; i <GPIO_NUM ; ++i) { -enum of_gpio_flags of_flags; + state->gpio_reset =gpiod_get_from_of_node (np,"xshutdown-gpios" ,0 ,GPIOD_ASIS , +"S5C73M3_RST" ); - ret =of_get_named_gpio_flags (node, prop_names[i], -0 , &of_flags); -if (ret <0 ) { -dev_err (dev,"failed to parse %s DT property\n" , - prop_names[i]); -return -EINVAL ; - } - state->gpio[i].gpio = ret; - state->gpio[i].level = !(of_flags &OF_GPIO_ACTIVE_LOW ); +if (IS_ERR (state->gpio_reset)) { +v4l2_err (c,"failed to request gpio S5C73M3_RST" ); +return PTR_ERR (state->gpio_reset); } + +if (state->gpio_reset) +gpiod_direction_output (state->gpio_reset, + !gpiod_is_active_low (state->gpio_reset)); +return 0 ; }
@@ -1608,8 +1595,8 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state) } state->mclk_frequency = pdata->mclk_frequency; - state->gpio[STBY ] = pdata->gpio_stby; - state->gpio[RSET ] = pdata->gpio_reset; + state->gpio_stby = pdata->gpio_stby; + state->gpio_reset = pdata->gpio_reset;return 0 ; }
@@ -1624,10 +1611,6 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state) state->mclk_frequency); } - ret =s5c73m3_parse_gpios (state); -if (ret <0 ) -return -EINVAL ; - node_ep =of_graph_get_next_endpoint (node,NULL );if (!node_ep) {dev_warn (dev,"no endpoint defined for node: %pOF\n" , node);
drivers/media/i2c/s5c73m3/s5c73m3.h +2 -7
@@ -351,12 +351,6 @@ struct s5c73m3_ctrls {struct v4l2_ctrl *scene_mode; }; -enum s5c73m3_gpio_id { -STBY , -RSET , -GPIO_NUM , -}; -enum s5c73m3_resolution_types {RES_ISP ,RES_JPEG ,
@@ -383,7 +377,8 @@ struct s5c73m3 {u32 i2c_read_address;struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES ]; -struct s5c73m3_gpio gpio[GPIO_NUM ]; +struct gpio_desc *gpio_stby; +struct gpio_desc *gpio_reset;struct clk *clock;
include/media/i2c/s5c73m3.h +3 -12
@@ -17,19 +17,10 @@#ifndef MEDIA_S5C73M3__ #define MEDIA_S5C73M3__ +#include <linux/gpio/consumer.h> #include <linux/videodev2.h> #include <media/v4l2-mediabus.h> -/** -* struct s5c73m3_gpio - data structure describing a GPIO -* @gpio: GPIO number -* @level: indicates active state of the @gpio -*/ -struct s5c73m3_gpio { -int gpio; -int level; -}; -/** * struct s5c73m3_platform_data - s5c73m3 driver platform data * @mclk_frequency: sensor's master clock frequency in Hz
@@ -44,8 +35,8 @@ struct s5c73m3_gpio {struct s5c73m3_platform_data {unsigned long mclk_frequency; -struct s5c73m3_gpio gpio_reset; -struct s5c73m3_gpio gpio_stby; +struct gpio_desc *gpio_reset; +struct gpio_desc *gpio_stby;enum v4l2_mbus_type bus_type;u8 nlanes;
Signature · 1 line
2.35.1
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi "Maíra,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on v5.18-rc4 next-20220428]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Ma-ra-Canal/media-s5c73m3-replace-legacy-gpio-interface-for-gpiod/20220429-081656 base: git://linuxtv.org/media_tree.git master config: arm64-randconfig-r022-20220428 (https://download.01.org/0day-ci/archive/20220429/[email protected]/config) compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project c59473aacce38cd7dd77eebceaf3c98c5707ab3b)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install arm64 cross compiling tool for clang build
# apt-get install binutils-aarch64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/427ae1b9cae644d199f9ffc260480dd1c32ec9d6
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Ma-ra-Canal/media-s5c73m3-replace-legacy-gpio-interface-for-gpiod/20220429-081656 git checkout 427ae1b9cae644d199f9ffc260480dd1c32ec9d6
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm64 SHELL=/bin/bash drivers/media/i2c/s5c73m3/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> drivers/media/i2c/s5c73m3/s5c73m3-core.c:1359:32: error: too few arguments to function call, expected 2, have 1
int val = gpiod_set_value(gpio);
~~~~~~~~~~~~~~~ ^
include/linux/gpio/consumer.h:119:6: note: 'gpiod_set_value' declared here
void gpiod_set_value(struct gpio_desc *desc, int value);
^
drivers/media/i2c/s5c73m3/s5c73m3-core.c:1366:32: error: too few arguments to function call, expected 2, have 1
int val = gpiod_set_value(gpio);
~~~~~~~~~~~~~~~ ^
include/linux/gpio/consumer.h:119:6: note: 'gpiod_set_value' declared here
void gpiod_set_value(struct gpio_desc *desc, int value);
^2 errors generated.
vim +1359 drivers/media/i2c/s5c73m3/s5c73m3-core.c
1356
1357 static int s5c73m3_gpio_assert(struct gpio_desc *gpio)
1358 {
> 1359 int val = gpiod_set_value(gpio);
1360
1361 return s5c73m3_gpio_set_value(gpio, val);
1362 }
1363
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi "Maíra,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on media-tree/master]
[also build test ERROR on v5.18-rc4 next-20220428]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Ma-ra-Canal/media-s5c73m3-replace-legacy-gpio-interface-for-gpiod/20220429-081656 base: git://linuxtv.org/media_tree.git master config: i386-randconfig-a003 (https://download.01.org/0day-ci/archive/20220429/[email protected]/config) compiler: gcc-11 (Debian 11.2.0-20) 11.2.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/427ae1b9cae644d199f9ffc260480dd1c32ec9d6 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Ma-ra-Canal/media-s5c73m3-replace-legacy-gpio-interface-for-gpiod/20220429-081656 git checkout 427ae1b9cae644d199f9ffc260480dd1c32ec9d6 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/media/i2c/s5c73m3/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
drivers/media/i2c/s5c73m3/s5c73m3-core.c: In function 's5c73m3_gpio_assert':
>> drivers/media/i2c/s5c73m3/s5c73m3-core.c:1359:19: error: too few arguments to function 'gpiod_set_value'
1359 | int val = gpiod_set_value(gpio);
| ^~~~~~~~~~~~~~~
In file included from drivers/media/i2c/s5c73m3/s5c73m3-core.c:13:
include/linux/gpio/consumer.h:119:6: note: declared here
119 | void gpiod_set_value(struct gpio_desc *desc, int value);
| ^~~~~~~~~~~~~~~
drivers/media/i2c/s5c73m3/s5c73m3-core.c: In function 's5c73m3_gpio_deassert':
drivers/media/i2c/s5c73m3/s5c73m3-core.c:1366:19: error: too few arguments to function 'gpiod_set_value'
1366 | int val = gpiod_set_value(gpio);
| ^~~~~~~~~~~~~~~
In file included from drivers/media/i2c/s5c73m3/s5c73m3-core.c:13:
include/linux/gpio/consumer.h:119:6: note: declared here
119 | void gpiod_set_value(struct gpio_desc *desc, int value);
| ^~~~~~~~~~~~~~~vim +/gpiod_set_value +1359 drivers/media/i2c/s5c73m3/s5c73m3-core.c
1356
1357 static int s5c73m3_gpio_assert(struct gpio_desc *gpio)
1358 {
> 1359 int val = gpiod_set_value(gpio);
1360
1361 return s5c73m3_gpio_set_value(gpio, val);
1362 }
1363
Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp