media: s5k5baf: switch to using gpiod API
Subsystems (4)
PATCH 1/3 media: s5k5baf: switch to using gpiod API
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of of_get_named_gpio_flags() which I want to make private to gpiolib.
--- drivers/media/i2c/s5k5baf.c | 64 +++++++++++-------------------------- 1 file changed, 18 insertions(+), 46 deletions(-)
drivers/media/i2c/s5k5baf.c +18 -46
@@ -13,11 +13,10 @@#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/media.h> #include <linux/module.h> -#include <linux/of_gpio.h> #include <linux/of_graph.h> #include <linux/regulator/consumer.h> #include <linux/slab.h>
@@ -228,11 +227,6 @@ static const char * const s5k5baf_supply_names[] = { };#define S5K5BAF_NUM_SUPPLIES ARRAY_SIZE(s5k5baf_supply_names) -struct s5k5baf_gpio { -int gpio; -int level; -}; -enum s5k5baf_gpio_id {STBY ,RSET ,
@@ -284,7 +278,7 @@ struct s5k5baf_fw { };struct s5k5baf { -struct s5k5baf_gpio gpios[NUM_GPIOS ]; +struct gpio_desc *gpios[NUM_GPIOS ];enum v4l2_mbus_type bus_type;u8 nlanes;struct regulator_bulk_data supplies[S5K5BAF_NUM_SUPPLIES ];
@@ -936,16 +930,12 @@ static void s5k5baf_hw_set_test_pattern(struct s5k5baf *state, int id)static void s5k5baf_gpio_assert (struct s5k5baf *state,int id) { -struct s5k5baf_gpio *gpio = &state->gpios[id]; - -gpio_set_value (gpio->gpio, gpio->level); +gpiod_set_value_cansleep (state->gpios[id],1 ); }static void s5k5baf_gpio_deassert (struct s5k5baf *state,int id) { -struct s5k5baf_gpio *gpio = &state->gpios[id]; - -gpio_set_value (gpio->gpio, !gpio->level); +gpiod_set_value_cansleep (state->gpios[id],0 ); }static int s5k5baf_power_on (struct s5k5baf *state)
@@ -1799,44 +1789,30 @@ static const struct v4l2_subdev_ops s5k5baf_subdev_ops = {static int s5k5baf_configure_gpios (struct s5k5baf *state) { -static const char *const name[] = {"S5K5BAF_STBY" ,"S5K5BAF_RST" }; +static const char *const name[] = {"stbyn" ,"rstn" }; +static const char *const label[] = {"S5K5BAF_STBY" ,"S5K5BAF_RST" };struct i2c_client *c =v4l2_get_subdevdata (&state->sd); -struct s5k5baf_gpio *g = state->gpios; +struct gpio_desc *gpio;int ret, i;for (i =0 ; i <NUM_GPIOS ; ++i) { -int flags =GPIOF_DIR_OUT ; -if (g[i].level) - flags |=GPIOF_INIT_HIGH ; - ret =devm_gpio_request_one (&c->dev, g[i].gpio, flags, name[i]); -if (ret <0 ) { -v4l2_err (c,"failed to request gpio %s\n" , name[i]); + gpio =devm_gpiod_get (&c->dev, name[i],GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (gpio); +if (ret) { +v4l2_err (c,"failed to request gpio %s: %d\n" , + name[i], ret);return ret; } - } -return 0 ; -} - -static int s5k5baf_parse_gpios (struct s5k5baf_gpio *gpios,struct device *dev) -{ -static const char *const names[] = { -"stbyn-gpios" , -"rstn-gpios" , - }; -struct device_node *node = dev->of_node; -enum of_gpio_flags flags; -int ret, i; -for (i =0 ; i <NUM_GPIOS ; ++i) { - ret =of_get_named_gpio_flags (node, names[i],0 , &flags); -if (ret <0 ) { -dev_err (dev,"no %s GPIO pin provided\n" , names[i]); + ret =gpiod_set_consumer_name (gpio, label[i]); +if (ret) { +v4l2_err (c,"failed to set up name for gpio %s: %d\n" , + name[i], ret);return ret; } - gpios[i].gpio = ret; - gpios[i].level = !(flags &OF_GPIO_ACTIVE_LOW ); - } + state->gpios[i] = gpio; + }return 0 ; }
@@ -1860,10 +1836,6 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev) state->mclk_frequency); } - ret =s5k5baf_parse_gpios (state->gpios, dev); -if (ret <0 ) -return ret; - node_ep =of_graph_get_next_endpoint (node,NULL );if (!node_ep) {dev_err (dev,"no endpoint defined at node %pOF\n" , node);
Signature · 1 line
2.37.2.789.g6183377224-goog
PATCH 2/3 media: i2c: s5c73m3: remove support for platform data
There are no existing users of s5c73m3_platform_data in the tree, and new users shoudl either be using device tree, ACPI, or static device properties, so let's remove it from the driver.
--- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 19 ++------ drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c | 2 - drivers/media/i2c/s5c73m3/s5c73m3.h | 6 ++- include/media/i2c/s5c73m3.h | 56 ----------------------- 4 files changed, 9 insertions(+), 74 deletions(-) delete mode 100644 include/media/i2c/s5c73m3.h
drivers/media/i2c/s5c73m3/s5c73m3-core.c +4 -15
@@ -27,7 +27,6 @@#include <media/v4l2-device.h> #include <media/v4l2-subdev.h> #include <media/v4l2-mediabus.h> -#include <media/i2c/s5c73m3.h> #include <media/v4l2-fwnode.h> #include "s5c73m3.h"
@@ -1592,26 +1591,16 @@ static int s5c73m3_parse_gpios(struct s5c73m3 *state)return 0 ; } -static int s5c73m3_get_platform_data (struct s5c73m3 *state) +static int s5c73m3_get_dt_data (struct s5c73m3 *state) {struct device *dev = &state->i2c_client->dev; -const struct s5c73m3_platform_data *pdata = dev->platform_data;struct device_node *node = dev->of_node;struct device_node *node_ep;struct v4l2_fwnode_endpoint ep = { .bus_type =0 };int ret; -if (!node) { -if (!pdata) { -dev_err (dev,"Platform data not specified\n" ); -return -EINVAL ; - } - - state->mclk_frequency = pdata->mclk_frequency; - state->gpio[STBY ] = pdata->gpio_stby; - state->gpio[RSET ] = pdata->gpio_reset; -return 0 ; - } +if (!node) +return -EINVAL ; state->clock =devm_clk_get (dev,S5C73M3_CLK_NAME );if (IS_ERR (state->clock))
@@ -1666,7 +1655,7 @@ static int s5c73m3_probe(struct i2c_client *client)return -ENOMEM ; state->i2c_client = client; - ret =s5c73m3_get_platform_data (state); + ret =s5c73m3_get_dt_data (state);if (ret <0 )return ret;
drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c +0 -2
@@ -10,7 +10,6 @@#include <linux/sizes.h> #include <linux/delay.h> #include <linux/firmware.h> -#include <linux/gpio.h> #include <linux/i2c.h> #include <linux/init.h> #include <linux/media.h>
@@ -24,7 +23,6 @@#include <media/v4l2-device.h> #include <media/v4l2-subdev.h> #include <media/v4l2-mediabus.h> -#include <media/i2c/s5c73m3.h> #include "s5c73m3.h"
drivers/media/i2c/s5c73m3/s5c73m3.h +5 -1
@@ -15,7 +15,6 @@#include <media/v4l2-common.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-subdev.h> -#include <media/i2c/s5c73m3.h> #define DRIVER_NAME "S5C73M3"
@@ -357,6 +356,11 @@ enum s5c73m3_gpio_id { GPIO_NUM, }; +struct s5c73m3_gpio { +int gpio; +int level; +}; +enum s5c73m3_resolution_types {RES_ISP ,RES_JPEG ,
include/media/i2c/s5c73m3.h deleted +0 -56
56 lines not on this page · raw message
Signature · 1 line
2.37.2.789.g6183377224-goog
Re: [PATCH 2/3] media: i2c: s5c73m3: remove support for platform data
Quoted 5 lines · Dmitry Torokhov
There are no existing users of
s5c73m3_platform_datain the tree, and new users shoudl either be using device tree, ACPI, or static device properties, so let's remove it from the driver.Signed-off-by Dmitry Torokhov <[email protected]>
Yours,
Linus Walleij
PATCH 3/3 media: i2c: s5c73m3: switch to using gpiod API
In reply to Dmitry TorokhovThis patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of of_get_named_gpio_flags() which I want to make private to gpiolib.
--- drivers/media/i2c/s5c73m3/s5c73m3-core.c | 63 +++++++----------------- drivers/media/i2c/s5c73m3/s5c73m3.h | 7 +-- 2 files changed, 20 insertions(+), 50 deletions(-)
drivers/media/i2c/s5c73m3/s5c73m3-core.c +19 -44
@@ -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>
@@ -1348,20 +1347,20 @@ static int s5c73m3_oif_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)static int s5c73m3_gpio_set_value (struct s5c73m3 *priv,int id,u32 val) { -if (!gpio_is_valid (priv->gpio[id].gpio)) +if (!priv->gpio[id])return 0 ; -gpio_set_value (priv->gpio[id].gpio, !!val); +gpiod_set_value_cansleep (priv->gpio[id], val);return 1 ; }static int s5c73m3_gpio_assert (struct s5c73m3 *priv,int id) { -return s5c73m3_gpio_set_value (priv, id, priv->gpio[id].level); +return s5c73m3_gpio_set_value (priv, id,1 ); }static int s5c73m3_gpio_deassert (struct s5c73m3 *priv,int id) { -return s5c73m3_gpio_set_value (priv, id, !priv->gpio[id].level); +return s5c73m3_gpio_set_value (priv, id,0 ); }static int __s5c73m3_power_on (struct s5c73m3 *state)
@@ -1544,49 +1543,29 @@ 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" - }; +static const char *const name[] = {"standby" ,"xshutdown" }; +static const char *const label[] = {"S5C73M3_STBY" ,"S5C73M3_RST" };struct i2c_client *c = state->i2c_client; -struct s5c73m3_gpio *g = state->gpio; +struct gpio_desc *gpio;int ret, i;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]); + gpio =devm_gpiod_get (&c->dev, name[i],GPIOD_OUT_HIGH ); + ret =PTR_ERR_OR_ZERO (gpio);if (ret) { -v4l2_err (c,"failed to request gpio %s\n" , - gpio_names[i]); +v4l2_err (c,"failed to request gpio %s: %d\n" , + name[i], ret);return ret; } - } -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; -for (i =0 ; i <GPIO_NUM ; ++i) { -enum of_gpio_flags of_flags; - - 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 ; + ret =gpiod_set_consumer_name (gpio, label[i]); +if (ret) { +v4l2_err (c,"failed to set up name for gpio %s: %d\n" , + name[i], ret); +return ret; } - state->gpio[i].gpio = ret; - state->gpio[i].level = !(of_flags &OF_GPIO_ACTIVE_LOW ); + + state->gpio[i] = gpio; }return 0 ; }
@@ -1613,10 +1592,6 @@ static int s5c73m3_get_dt_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 +1 -6
@@ -356,11 +356,6 @@ enum s5c73m3_gpio_id { GPIO_NUM, }; -struct s5c73m3_gpio { -int gpio; -int level; -}; -enum s5c73m3_resolution_types {RES_ISP ,RES_JPEG ,
@@ -387,7 +382,7 @@ struct s5c73m3 {u32 i2c_read_address;struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES ]; -struct s5c73m3_gpio gpio[GPIO_NUM ]; +struct gpio_desc *gpio[GPIO_NUM ];struct clk *clock;
Signature · 1 line
2.37.2.789.g6183377224-goog
Re: [PATCH 3/3] media: i2c: s5c73m3: switch to using gpiod API
Quoted 5 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>
I already converted this driver to gpiod:
https://lore.kernel.org/linux-media/[email protected]/
Already sent the patch twice too, I don't know what's up with media patches not getting applied.
Yours,
Linus Walleij
Quoted 5 lines · Dmitry Torokhov
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes use of
of_get_named_gpio_flags()which I want to make private to gpiolib.Signed-off-by Dmitry Torokhov <[email protected]>
Yours,
Linus Walleij