Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <s.nawrocki@samsung.com>
Cc: Andrzej Hajda <andrzej.hajda@intel.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>
Reviewed-by: Andrzej Hajda <andrzej.hajda@intel.com>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>

authored by

Linus Walleij and committed by
Hans Verkuil
a14e84db 4220dd61

+23 -110
+20 -87
drivers/media/i2c/s5c73m3/s5c73m3-core.c
··· 10 10 #include <linux/clk.h> 11 11 #include <linux/delay.h> 12 12 #include <linux/firmware.h> 13 - #include <linux/gpio.h> 13 + #include <linux/gpio/consumer.h> 14 14 #include <linux/i2c.h> 15 15 #include <linux/init.h> 16 16 #include <linux/media.h> 17 17 #include <linux/module.h> 18 - #include <linux/of_gpio.h> 19 18 #include <linux/of_graph.h> 20 19 #include <linux/regulator/consumer.h> 21 20 #include <linux/sizes.h> ··· 1346 1347 return 0; 1347 1348 } 1348 1349 1349 - static int s5c73m3_gpio_set_value(struct s5c73m3 *priv, int id, u32 val) 1350 - { 1351 - if (!gpio_is_valid(priv->gpio[id].gpio)) 1352 - return 0; 1353 - gpio_set_value(priv->gpio[id].gpio, !!val); 1354 - return 1; 1355 - } 1356 - 1357 - static int s5c73m3_gpio_assert(struct s5c73m3 *priv, int id) 1358 - { 1359 - return s5c73m3_gpio_set_value(priv, id, priv->gpio[id].level); 1360 - } 1361 - 1362 - static int s5c73m3_gpio_deassert(struct s5c73m3 *priv, int id) 1363 - { 1364 - return s5c73m3_gpio_set_value(priv, id, !priv->gpio[id].level); 1365 - } 1366 - 1367 1350 static int __s5c73m3_power_on(struct s5c73m3 *state) 1368 1351 { 1369 1352 int i, ret; ··· 1367 1386 v4l2_dbg(1, s5c73m3_dbg, &state->oif_sd, "clock frequency: %ld\n", 1368 1387 clk_get_rate(state->clock)); 1369 1388 1370 - s5c73m3_gpio_deassert(state, STBY); 1389 + gpiod_set_value(state->stby, 0); 1371 1390 usleep_range(100, 200); 1372 - 1373 - s5c73m3_gpio_deassert(state, RSET); 1391 + gpiod_set_value(state->reset, 0); 1374 1392 usleep_range(50, 100); 1375 1393 1376 1394 return 0; ··· 1384 1404 { 1385 1405 int i, ret; 1386 1406 1387 - if (s5c73m3_gpio_assert(state, RSET)) 1388 - usleep_range(10, 50); 1389 - 1390 - if (s5c73m3_gpio_assert(state, STBY)) 1391 - usleep_range(100, 200); 1407 + gpiod_set_value(state->reset, 1); 1408 + usleep_range(10, 50); 1409 + gpiod_set_value(state->stby, 1); 1410 + usleep_range(100, 200); 1392 1411 1393 1412 clk_disable_unprepare(state->clock); 1394 1413 ··· 1522 1543 .video = &s5c73m3_oif_video_ops, 1523 1544 }; 1524 1545 1525 - static int s5c73m3_configure_gpios(struct s5c73m3 *state) 1526 - { 1527 - static const char * const gpio_names[] = { 1528 - "S5C73M3_STBY", "S5C73M3_RST" 1529 - }; 1530 - struct i2c_client *c = state->i2c_client; 1531 - struct s5c73m3_gpio *g = state->gpio; 1532 - int ret, i; 1533 - 1534 - for (i = 0; i < GPIO_NUM; ++i) { 1535 - unsigned int flags = GPIOF_DIR_OUT; 1536 - if (g[i].level) 1537 - flags |= GPIOF_INIT_HIGH; 1538 - ret = devm_gpio_request_one(&c->dev, g[i].gpio, flags, 1539 - gpio_names[i]); 1540 - if (ret) { 1541 - v4l2_err(c, "failed to request gpio %s\n", 1542 - gpio_names[i]); 1543 - return ret; 1544 - } 1545 - } 1546 - return 0; 1547 - } 1548 - 1549 - static int s5c73m3_parse_gpios(struct s5c73m3 *state) 1550 - { 1551 - static const char * const prop_names[] = { 1552 - "standby-gpios", "xshutdown-gpios", 1553 - }; 1554 - struct device *dev = &state->i2c_client->dev; 1555 - struct device_node *node = dev->of_node; 1556 - int ret, i; 1557 - 1558 - for (i = 0; i < GPIO_NUM; ++i) { 1559 - enum of_gpio_flags of_flags; 1560 - 1561 - ret = of_get_named_gpio_flags(node, prop_names[i], 1562 - 0, &of_flags); 1563 - if (ret < 0) { 1564 - dev_err(dev, "failed to parse %s DT property\n", 1565 - prop_names[i]); 1566 - return -EINVAL; 1567 - } 1568 - state->gpio[i].gpio = ret; 1569 - state->gpio[i].level = !(of_flags & OF_GPIO_ACTIVE_LOW); 1570 - } 1571 - return 0; 1572 - } 1573 - 1574 1546 static int s5c73m3_get_platform_data(struct s5c73m3 *state) 1575 1547 { 1576 - struct device *dev = &state->i2c_client->dev; 1548 + struct i2c_client *c = state->i2c_client; 1549 + struct device *dev = &c->dev; 1577 1550 const struct s5c73m3_platform_data *pdata = dev->platform_data; 1578 1551 struct device_node *node = dev->of_node; 1579 1552 struct device_node *node_ep; ··· 1539 1608 } 1540 1609 1541 1610 state->mclk_frequency = pdata->mclk_frequency; 1542 - state->gpio[STBY] = pdata->gpio_stby; 1543 - state->gpio[RSET] = pdata->gpio_reset; 1544 1611 return 0; 1545 1612 } 1546 1613 ··· 1553 1624 state->mclk_frequency); 1554 1625 } 1555 1626 1556 - ret = s5c73m3_parse_gpios(state); 1557 - if (ret < 0) 1558 - return -EINVAL; 1627 + /* Request GPIO lines asserted */ 1628 + state->stby = devm_gpiod_get(dev, "standby", GPIOD_OUT_HIGH); 1629 + if (IS_ERR(state->stby)) 1630 + return dev_err_probe(dev, PTR_ERR(state->stby), 1631 + "failed to request gpio S5C73M3_STBY\n"); 1632 + gpiod_set_consumer_name(state->stby, "S5C73M3_STBY"); 1633 + state->reset = devm_gpiod_get(dev, "xshutdown", GPIOD_OUT_HIGH); 1634 + if (IS_ERR(state->reset)) 1635 + return dev_err_probe(dev, PTR_ERR(state->reset), 1636 + "failed to request gpio S5C73M3_RST\n"); 1637 + gpiod_set_consumer_name(state->reset, "S5C73M3_RST"); 1559 1638 1560 1639 node_ep = of_graph_get_next_endpoint(node, NULL); 1561 1640 if (!node_ep) { ··· 1644 1707 state->oif_pads); 1645 1708 if (ret < 0) 1646 1709 return ret; 1647 - 1648 - ret = s5c73m3_configure_gpios(state); 1649 - if (ret) 1650 - goto out_err; 1651 1710 1652 1711 for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++) 1653 1712 state->supplies[i].supply = s5c73m3_supply_names[i];
-1
drivers/media/i2c/s5c73m3/s5c73m3-ctrls.c
··· 10 10 #include <linux/sizes.h> 11 11 #include <linux/delay.h> 12 12 #include <linux/firmware.h> 13 - #include <linux/gpio.h> 14 13 #include <linux/i2c.h> 15 14 #include <linux/init.h> 16 15 #include <linux/media.h>
+3 -7
drivers/media/i2c/s5c73m3/s5c73m3.h
··· 12 12 #include <linux/clk.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/regulator/consumer.h> 15 + #include <linux/gpio/consumer.h> 15 16 #include <media/v4l2-common.h> 16 17 #include <media/v4l2-ctrls.h> 17 18 #include <media/v4l2-subdev.h> ··· 352 351 struct v4l2_ctrl *scene_mode; 353 352 }; 354 353 355 - enum s5c73m3_gpio_id { 356 - STBY, 357 - RSET, 358 - GPIO_NUM, 359 - }; 360 - 361 354 enum s5c73m3_resolution_types { 362 355 RES_ISP, 363 356 RES_JPEG, ··· 378 383 u32 i2c_read_address; 379 384 380 385 struct regulator_bulk_data supplies[S5C73M3_MAX_SUPPLIES]; 381 - struct s5c73m3_gpio gpio[GPIO_NUM]; 386 + struct gpio_desc *stby; 387 + struct gpio_desc *reset; 382 388 383 389 struct clk *clock; 384 390
-15
include/media/i2c/s5c73m3.h
··· 21 21 #include <media/v4l2-mediabus.h> 22 22 23 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 - 33 - /** 34 24 * struct s5c73m3_platform_data - s5c73m3 driver platform data 35 25 * @mclk_frequency: sensor's master clock frequency in Hz 36 - * @gpio_reset: GPIO driving RESET pin 37 - * @gpio_stby: GPIO driving STBY pin 38 26 * @bus_type: bus type 39 27 * @nlanes: maximum number of MIPI-CSI lanes used 40 28 * @horiz_flip: default horizontal image flip value, non zero to enable ··· 31 43 32 44 struct s5c73m3_platform_data { 33 45 unsigned long mclk_frequency; 34 - 35 - struct s5c73m3_gpio gpio_reset; 36 - struct s5c73m3_gpio gpio_stby; 37 46 38 47 enum v4l2_mbus_type bus_type; 39 48 u8 nlanes;