Skip to content

Commit 87b5aee

Browse files
dtorHans Verkuil
authored andcommitted
media: i2c: s5k6a3: switch to using gpiod API
This patch switches the driver away from legacy gpio/of_gpio API to gpiod API, and removes one of the last uses of of_get_gpio_flags(). Signed-off-by: Dmitry Torokhov <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Reviewed-by: Tommaso Merciai <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 932d87c commit 87b5aee

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

drivers/media/i2c/s5k6a3.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include <linux/clk.h>
1010
#include <linux/delay.h>
1111
#include <linux/device.h>
12+
#include <linux/err.h>
1213
#include <linux/errno.h>
13-
#include <linux/gpio.h>
14+
#include <linux/gpio/consumer.h>
1415
#include <linux/i2c.h>
1516
#include <linux/kernel.h>
1617
#include <linux/module.h>
17-
#include <linux/of_gpio.h>
1818
#include <linux/pm_runtime.h>
1919
#include <linux/regulator/consumer.h>
2020
#include <linux/slab.h>
@@ -59,7 +59,7 @@ struct s5k6a3 {
5959
struct v4l2_subdev subdev;
6060
struct media_pad pad;
6161
struct regulator_bulk_data supplies[S5K6A3_NUM_SUPPLIES];
62-
int gpio_reset;
62+
struct gpio_desc *gpio_reset;
6363
struct mutex lock;
6464
struct v4l2_mbus_framefmt format;
6565
struct clk *clock;
@@ -216,11 +216,11 @@ static int __s5k6a3_power_on(struct s5k6a3 *sensor)
216216
goto error_clk;
217217
}
218218

219-
gpio_set_value(sensor->gpio_reset, 1);
219+
gpiod_set_value_cansleep(sensor->gpio_reset, 0);
220220
usleep_range(600, 800);
221-
gpio_set_value(sensor->gpio_reset, 0);
221+
gpiod_set_value_cansleep(sensor->gpio_reset, 1);
222222
usleep_range(600, 800);
223-
gpio_set_value(sensor->gpio_reset, 1);
223+
gpiod_set_value_cansleep(sensor->gpio_reset, 0);
224224

225225
/* Delay needed for the sensor initialization */
226226
msleep(20);
@@ -240,7 +240,7 @@ static int __s5k6a3_power_off(struct s5k6a3 *sensor)
240240
{
241241
int i;
242242

243-
gpio_set_value(sensor->gpio_reset, 0);
243+
gpiod_set_value_cansleep(sensor->gpio_reset, 1);
244244

245245
for (i = S5K6A3_NUM_SUPPLIES - 1; i >= 0; i--)
246246
regulator_disable(sensor->supplies[i].consumer);
@@ -285,32 +285,24 @@ static int s5k6a3_probe(struct i2c_client *client)
285285
struct device *dev = &client->dev;
286286
struct s5k6a3 *sensor;
287287
struct v4l2_subdev *sd;
288-
int gpio, i, ret;
288+
int i, ret;
289289

290290
sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
291291
if (!sensor)
292292
return -ENOMEM;
293293

294294
mutex_init(&sensor->lock);
295-
sensor->gpio_reset = -EINVAL;
296-
sensor->clock = ERR_PTR(-EINVAL);
297295
sensor->dev = dev;
298296

299297
sensor->clock = devm_clk_get(sensor->dev, S5K6A3_CLK_NAME);
300298
if (IS_ERR(sensor->clock))
301299
return PTR_ERR(sensor->clock);
302300

303-
gpio = of_get_gpio_flags(dev->of_node, 0, NULL);
304-
if (!gpio_is_valid(gpio))
305-
return gpio;
306-
307-
ret = devm_gpio_request_one(dev, gpio, GPIOF_OUT_INIT_LOW,
308-
S5K6A3_DRV_NAME);
309-
if (ret < 0)
301+
sensor->gpio_reset = devm_gpiod_get(dev, NULL, GPIOD_OUT_HIGH);
302+
ret = PTR_ERR_OR_ZERO(sensor->gpio_reset);
303+
if (ret)
310304
return ret;
311305

312-
sensor->gpio_reset = gpio;
313-
314306
if (of_property_read_u32(dev->of_node, "clock-frequency",
315307
&sensor->clock_frequency)) {
316308
sensor->clock_frequency = S5K6A3_DEFAULT_CLK_FREQ;

0 commit comments

Comments
 (0)