Skip to content

Commit a14e84d

Browse files
linuswHans Verkuil
authored andcommitted
media: s5c73m3: Switch to GPIO descriptors
The driver has an option to pass in GPIO numbers from platform data but this is not used in the kernel so delete this. Get GPIO descriptors using the standard API and simplify the code, gpiolib will handle any inversions. Cc: Sylwester Nawrocki <[email protected]> Cc: Andrzej Hajda <[email protected]> Cc: Alim Akhtar <[email protected]> Reviewed-by: Andrzej Hajda <[email protected]> Acked-by: Krzysztof Kozlowski <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Signed-off-by: Hans Verkuil <[email protected]>
1 parent 4220dd6 commit a14e84d

File tree

4 files changed

+23
-110
lines changed

4 files changed

+23
-110
lines changed

drivers/media/i2c/s5c73m3/s5c73m3-core.c

Lines changed: 20 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
#include <linux/clk.h>
1111
#include <linux/delay.h>
1212
#include <linux/firmware.h>
13-
#include <linux/gpio.h>
13+
#include <linux/gpio/consumer.h>
1414
#include <linux/i2c.h>
1515
#include <linux/init.h>
1616
#include <linux/media.h>
1717
#include <linux/module.h>
18-
#include <linux/of_gpio.h>
1918
#include <linux/of_graph.h>
2019
#include <linux/regulator/consumer.h>
2120
#include <linux/sizes.h>
@@ -1347,24 +1346,6 @@ static int s5c73m3_oif_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
13471346
return 0;
13481347
}
13491348

1350-
static int s5c73m3_gpio_set_value(struct s5c73m3 *priv, int id, u32 val)
1351-
{
1352-
if (!gpio_is_valid(priv->gpio[id].gpio))
1353-
return 0;
1354-
gpio_set_value(priv->gpio[id].gpio, !!val);
1355-
return 1;
1356-
}
1357-
1358-
static int s5c73m3_gpio_assert(struct s5c73m3 *priv, int id)
1359-
{
1360-
return s5c73m3_gpio_set_value(priv, id, priv->gpio[id].level);
1361-
}
1362-
1363-
static int s5c73m3_gpio_deassert(struct s5c73m3 *priv, int id)
1364-
{
1365-
return s5c73m3_gpio_set_value(priv, id, !priv->gpio[id].level);
1366-
}
1367-
13681349
static int __s5c73m3_power_on(struct s5c73m3 *state)
13691350
{
13701351
int i, ret;
@@ -1386,10 +1367,9 @@ static int __s5c73m3_power_on(struct s5c73m3 *state)
13861367
v4l2_dbg(1, s5c73m3_dbg, &state->oif_sd, "clock frequency: %ld\n",
13871368
clk_get_rate(state->clock));
13881369

1389-
s5c73m3_gpio_deassert(state, STBY);
1370+
gpiod_set_value(state->stby, 0);
13901371
usleep_range(100, 200);
1391-
1392-
s5c73m3_gpio_deassert(state, RSET);
1372+
gpiod_set_value(state->reset, 0);
13931373
usleep_range(50, 100);
13941374

13951375
return 0;
@@ -1404,11 +1384,10 @@ static int __s5c73m3_power_off(struct s5c73m3 *state)
14041384
{
14051385
int i, ret;
14061386

1407-
if (s5c73m3_gpio_assert(state, RSET))
1408-
usleep_range(10, 50);
1409-
1410-
if (s5c73m3_gpio_assert(state, STBY))
1411-
usleep_range(100, 200);
1387+
gpiod_set_value(state->reset, 1);
1388+
usleep_range(10, 50);
1389+
gpiod_set_value(state->stby, 1);
1390+
usleep_range(100, 200);
14121391

14131392
clk_disable_unprepare(state->clock);
14141393

@@ -1543,58 +1522,10 @@ static const struct v4l2_subdev_ops oif_subdev_ops = {
15431522
.video = &s5c73m3_oif_video_ops,
15441523
};
15451524

1546-
static int s5c73m3_configure_gpios(struct s5c73m3 *state)
1547-
{
1548-
static const char * const gpio_names[] = {
1549-
"S5C73M3_STBY", "S5C73M3_RST"
1550-
};
1551-
struct i2c_client *c = state->i2c_client;
1552-
struct s5c73m3_gpio *g = state->gpio;
1553-
int ret, i;
1554-
1555-
for (i = 0; i < GPIO_NUM; ++i) {
1556-
unsigned int flags = GPIOF_DIR_OUT;
1557-
if (g[i].level)
1558-
flags |= GPIOF_INIT_HIGH;
1559-
ret = devm_gpio_request_one(&c->dev, g[i].gpio, flags,
1560-
gpio_names[i]);
1561-
if (ret) {
1562-
v4l2_err(c, "failed to request gpio %s\n",
1563-
gpio_names[i]);
1564-
return ret;
1565-
}
1566-
}
1567-
return 0;
1568-
}
1569-
1570-
static int s5c73m3_parse_gpios(struct s5c73m3 *state)
1571-
{
1572-
static const char * const prop_names[] = {
1573-
"standby-gpios", "xshutdown-gpios",
1574-
};
1575-
struct device *dev = &state->i2c_client->dev;
1576-
struct device_node *node = dev->of_node;
1577-
int ret, i;
1578-
1579-
for (i = 0; i < GPIO_NUM; ++i) {
1580-
enum of_gpio_flags of_flags;
1581-
1582-
ret = of_get_named_gpio_flags(node, prop_names[i],
1583-
0, &of_flags);
1584-
if (ret < 0) {
1585-
dev_err(dev, "failed to parse %s DT property\n",
1586-
prop_names[i]);
1587-
return -EINVAL;
1588-
}
1589-
state->gpio[i].gpio = ret;
1590-
state->gpio[i].level = !(of_flags & OF_GPIO_ACTIVE_LOW);
1591-
}
1592-
return 0;
1593-
}
1594-
15951525
static int s5c73m3_get_platform_data(struct s5c73m3 *state)
15961526
{
1597-
struct device *dev = &state->i2c_client->dev;
1527+
struct i2c_client *c = state->i2c_client;
1528+
struct device *dev = &c->dev;
15981529
const struct s5c73m3_platform_data *pdata = dev->platform_data;
15991530
struct device_node *node = dev->of_node;
16001531
struct device_node *node_ep;
@@ -1608,8 +1539,6 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
16081539
}
16091540

16101541
state->mclk_frequency = pdata->mclk_frequency;
1611-
state->gpio[STBY] = pdata->gpio_stby;
1612-
state->gpio[RSET] = pdata->gpio_reset;
16131542
return 0;
16141543
}
16151544

@@ -1624,9 +1553,17 @@ static int s5c73m3_get_platform_data(struct s5c73m3 *state)
16241553
state->mclk_frequency);
16251554
}
16261555

1627-
ret = s5c73m3_parse_gpios(state);
1628-
if (ret < 0)
1629-
return -EINVAL;
1556+
/* Request GPIO lines asserted */
1557+
state->stby = devm_gpiod_get(dev, "standby", GPIOD_OUT_HIGH);
1558+
if (IS_ERR(state->stby))
1559+
return dev_err_probe(dev, PTR_ERR(state->stby),
1560+
"failed to request gpio S5C73M3_STBY\n");
1561+
gpiod_set_consumer_name(state->stby, "S5C73M3_STBY");
1562+
state->reset = devm_gpiod_get(dev, "xshutdown", GPIOD_OUT_HIGH);
1563+
if (IS_ERR(state->reset))
1564+
return dev_err_probe(dev, PTR_ERR(state->reset),
1565+
"failed to request gpio S5C73M3_RST\n");
1566+
gpiod_set_consumer_name(state->reset, "S5C73M3_RST");
16301567

16311568
node_ep = of_graph_get_next_endpoint(node, NULL);
16321569
if (!node_ep) {
@@ -1708,10 +1645,6 @@ static int s5c73m3_probe(struct i2c_client *client)
17081645
if (ret < 0)
17091646
return ret;
17101647

1711-
ret = s5c73m3_configure_gpios(state);
1712-
if (ret)
1713-
goto out_err;
1714-
17151648
for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++)
17161649
state->supplies[i].supply = s5c73m3_supply_names[i];
17171650

drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/sizes.h>
1111
#include <linux/delay.h>
1212
#include <linux/firmware.h>
13-
#include <linux/gpio.h>
1413
#include <linux/i2c.h>
1514
#include <linux/init.h>
1615
#include <linux/media.h>

drivers/media/i2c/s5c73m3/s5c73m3.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/clk.h>
1313
#include <linux/kernel.h>
1414
#include <linux/regulator/consumer.h>
15+
#include <linux/gpio/consumer.h>
1516
#include <media/v4l2-common.h>
1617
#include <media/v4l2-ctrls.h>
1718
#include <media/v4l2-subdev.h>
@@ -351,12 +352,6 @@ struct s5c73m3_ctrls {
351352
struct v4l2_ctrl *scene_mode;
352353
};
353354

354-
enum s5c73m3_gpio_id {
355-
STBY,
356-
RSET,
357-
GPIO_NUM,
358-
};
359-
360355
enum s5c73m3_resolution_types {
361356
RES_ISP,
362357
RES_JPEG,
@@ -383,7 +378,8 @@ struct s5c73m3 {
383378
u32 i2c_read_address;
384379

385380
struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES];
386-
struct s5c73m3_gpio gpio[GPIO_NUM];
381+
struct gpio_desc *stby;
382+
struct gpio_desc *reset;
387383

388384
struct clk *clock;
389385

include/media/i2c/s5c73m3.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,9 @@
2020
#include <linux/videodev2.h>
2121
#include <media/v4l2-mediabus.h>
2222

23-
/**
24-
* struct s5c73m3_gpio - data structure describing a GPIO
25-
* @gpio: GPIO number
26-
* @level: indicates active state of the @gpio
27-
*/
28-
struct s5c73m3_gpio {
29-
int gpio;
30-
int level;
31-
};
32-
3323
/**
3424
* struct s5c73m3_platform_data - s5c73m3 driver platform data
3525
* @mclk_frequency: sensor's master clock frequency in Hz
36-
* @gpio_reset: GPIO driving RESET pin
37-
* @gpio_stby: GPIO driving STBY pin
3826
* @bus_type: bus type
3927
* @nlanes: maximum number of MIPI-CSI lanes used
4028
* @horiz_flip: default horizontal image flip value, non zero to enable
@@ -44,9 +32,6 @@ struct s5c73m3_gpio {
4432
struct s5c73m3_platform_data {
4533
unsigned long mclk_frequency;
4634

47-
struct s5c73m3_gpio gpio_reset;
48-
struct s5c73m3_gpio gpio_stby;
49-
5035
enum v4l2_mbus_type bus_type;
5136
u8 nlanes;
5237
u8 horiz_flip;

0 commit comments

Comments
 (0)