Skip to content

Commit 4220dd6

Browse files
dtorHans Verkuil
authored andcommitted
media: i2c: 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. Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> Reviewed-by: Tommaso Merciai <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 87b5aee commit 4220dd6

File tree

1 file changed

+18
-46
lines changed

1 file changed

+18
-46
lines changed

drivers/media/i2c/s5k5baf.c

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
#include <linux/clk.h>
1414
#include <linux/delay.h>
1515
#include <linux/firmware.h>
16-
#include <linux/gpio.h>
16+
#include <linux/gpio/consumer.h>
1717
#include <linux/i2c.h>
1818
#include <linux/media.h>
1919
#include <linux/module.h>
20-
#include <linux/of_gpio.h>
2120
#include <linux/of_graph.h>
2221
#include <linux/regulator/consumer.h>
2322
#include <linux/slab.h>
@@ -228,11 +227,6 @@ static const char * const s5k5baf_supply_names[] = {
228227
};
229228
#define S5K5BAF_NUM_SUPPLIES ARRAY_SIZE(s5k5baf_supply_names)
230229

231-
struct s5k5baf_gpio {
232-
int gpio;
233-
int level;
234-
};
235-
236230
enum s5k5baf_gpio_id {
237231
STBY,
238232
RSET,
@@ -284,7 +278,7 @@ struct s5k5baf_fw {
284278
};
285279

286280
struct s5k5baf {
287-
struct s5k5baf_gpio gpios[NUM_GPIOS];
281+
struct gpio_desc *gpios[NUM_GPIOS];
288282
enum v4l2_mbus_type bus_type;
289283
u8 nlanes;
290284
struct regulator_bulk_data supplies[S5K5BAF_NUM_SUPPLIES];
@@ -936,16 +930,12 @@ static void s5k5baf_hw_set_test_pattern(struct s5k5baf *state, int id)
936930

937931
static void s5k5baf_gpio_assert(struct s5k5baf *state, int id)
938932
{
939-
struct s5k5baf_gpio *gpio = &state->gpios[id];
940-
941-
gpio_set_value(gpio->gpio, gpio->level);
933+
gpiod_set_value_cansleep(state->gpios[id], 1);
942934
}
943935

944936
static void s5k5baf_gpio_deassert(struct s5k5baf *state, int id)
945937
{
946-
struct s5k5baf_gpio *gpio = &state->gpios[id];
947-
948-
gpio_set_value(gpio->gpio, !gpio->level);
938+
gpiod_set_value_cansleep(state->gpios[id], 0);
949939
}
950940

951941
static int s5k5baf_power_on(struct s5k5baf *state)
@@ -1799,44 +1789,30 @@ static const struct v4l2_subdev_ops s5k5baf_subdev_ops = {
17991789

18001790
static int s5k5baf_configure_gpios(struct s5k5baf *state)
18011791
{
1802-
static const char * const name[] = { "S5K5BAF_STBY", "S5K5BAF_RST" };
1792+
static const char * const name[] = { "stbyn", "rstn" };
1793+
static const char * const label[] = { "S5K5BAF_STBY", "S5K5BAF_RST" };
18031794
struct i2c_client *c = v4l2_get_subdevdata(&state->sd);
1804-
struct s5k5baf_gpio *g = state->gpios;
1795+
struct gpio_desc *gpio;
18051796
int ret, i;
18061797

18071798
for (i = 0; i < NUM_GPIOS; ++i) {
1808-
int flags = GPIOF_DIR_OUT;
1809-
if (g[i].level)
1810-
flags |= GPIOF_INIT_HIGH;
1811-
ret = devm_gpio_request_one(&c->dev, g[i].gpio, flags, name[i]);
1812-
if (ret < 0) {
1813-
v4l2_err(c, "failed to request gpio %s\n", name[i]);
1799+
gpio = devm_gpiod_get(&c->dev, name[i], GPIOD_OUT_HIGH);
1800+
ret = PTR_ERR_OR_ZERO(gpio);
1801+
if (ret) {
1802+
v4l2_err(c, "failed to request gpio %s: %d\n",
1803+
name[i], ret);
18141804
return ret;
18151805
}
1816-
}
1817-
return 0;
1818-
}
1819-
1820-
static int s5k5baf_parse_gpios(struct s5k5baf_gpio *gpios, struct device *dev)
1821-
{
1822-
static const char * const names[] = {
1823-
"stbyn-gpios",
1824-
"rstn-gpios",
1825-
};
1826-
struct device_node *node = dev->of_node;
1827-
enum of_gpio_flags flags;
1828-
int ret, i;
18291806

1830-
for (i = 0; i < NUM_GPIOS; ++i) {
1831-
ret = of_get_named_gpio_flags(node, names[i], 0, &flags);
1832-
if (ret < 0) {
1833-
dev_err(dev, "no %s GPIO pin provided\n", names[i]);
1807+
ret = gpiod_set_consumer_name(gpio, label[i]);
1808+
if (ret) {
1809+
v4l2_err(c, "failed to set up name for gpio %s: %d\n",
1810+
name[i], ret);
18341811
return ret;
18351812
}
1836-
gpios[i].gpio = ret;
1837-
gpios[i].level = !(flags & OF_GPIO_ACTIVE_LOW);
1838-
}
18391813

1814+
state->gpios[i] = gpio;
1815+
}
18401816
return 0;
18411817
}
18421818

@@ -1860,10 +1836,6 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
18601836
state->mclk_frequency);
18611837
}
18621838

1863-
ret = s5k5baf_parse_gpios(state->gpios, dev);
1864-
if (ret < 0)
1865-
return ret;
1866-
18671839
node_ep = of_graph_get_next_endpoint(node, NULL);
18681840
if (!node_ep) {
18691841
dev_err(dev, "no endpoint defined at node %pOF\n", node);

0 commit comments

Comments
 (0)