diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2013-05-02 07:29:43 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-05-21 06:55:45 -0400 |
commit | 31857e54fa5a6e39d2d24dc912135bb0d26a6db9 (patch) | |
tree | 0559679c0405868ed2036265bec56ef7e208df32 /drivers/media/i2c/s5k6aa.c | |
parent | 598d8d1e4c0bd21a992c52fe0adc69e0b3117a41 (diff) |
[media] s5k6aa: Convert to devm_gpio_request_one()
Use the devm_gpio_request_one() managed function to simplify cleanup
code paths.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/i2c/s5k6aa.c')
-rw-r--r-- | drivers/media/i2c/s5k6aa.c | 73 |
1 files changed, 26 insertions, 47 deletions
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c index bdf5e3db31d1..789c02a6ca1a 100644 --- a/drivers/media/i2c/s5k6aa.c +++ b/drivers/media/i2c/s5k6aa.c | |||
@@ -1491,58 +1491,41 @@ static const struct v4l2_subdev_ops s5k6aa_subdev_ops = { | |||
1491 | /* | 1491 | /* |
1492 | * GPIO setup | 1492 | * GPIO setup |
1493 | */ | 1493 | */ |
1494 | static int s5k6aa_configure_gpio(int nr, int val, const char *name) | ||
1495 | { | ||
1496 | unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW; | ||
1497 | int ret; | ||
1498 | |||
1499 | if (!gpio_is_valid(nr)) | ||
1500 | return 0; | ||
1501 | ret = gpio_request_one(nr, flags, name); | ||
1502 | if (!ret) | ||
1503 | gpio_export(nr, 0); | ||
1504 | return ret; | ||
1505 | } | ||
1506 | |||
1507 | static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa) | ||
1508 | { | ||
1509 | int i; | ||
1510 | |||
1511 | for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) { | ||
1512 | if (!gpio_is_valid(s5k6aa->gpio[i].gpio)) | ||
1513 | continue; | ||
1514 | gpio_free(s5k6aa->gpio[i].gpio); | ||
1515 | s5k6aa->gpio[i].gpio = -EINVAL; | ||
1516 | } | ||
1517 | } | ||
1518 | 1494 | ||
1519 | static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa, | 1495 | static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa, |
1520 | const struct s5k6aa_platform_data *pdata) | 1496 | const struct s5k6aa_platform_data *pdata) |
1521 | { | 1497 | { |
1522 | const struct s5k6aa_gpio *gpio = &pdata->gpio_stby; | 1498 | struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd); |
1499 | const struct s5k6aa_gpio *gpio; | ||
1500 | unsigned long flags; | ||
1523 | int ret; | 1501 | int ret; |
1524 | 1502 | ||
1525 | s5k6aa->gpio[STBY].gpio = -EINVAL; | 1503 | s5k6aa->gpio[STBY].gpio = -EINVAL; |
1526 | s5k6aa->gpio[RST].gpio = -EINVAL; | 1504 | s5k6aa->gpio[RST].gpio = -EINVAL; |
1527 | 1505 | ||
1528 | ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY"); | 1506 | gpio = &pdata->gpio_stby; |
1529 | if (ret) { | 1507 | if (gpio_is_valid(gpio->gpio)) { |
1530 | s5k6aa_free_gpios(s5k6aa); | 1508 | flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW) |
1531 | return ret; | 1509 | | GPIOF_EXPORT; |
1510 | ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags, | ||
1511 | "S5K6AA_STBY"); | ||
1512 | if (ret < 0) | ||
1513 | return ret; | ||
1514 | |||
1515 | s5k6aa->gpio[STBY] = *gpio; | ||
1532 | } | 1516 | } |
1533 | s5k6aa->gpio[STBY] = *gpio; | ||
1534 | if (gpio_is_valid(gpio->gpio)) | ||
1535 | gpio_set_value(gpio->gpio, 0); | ||
1536 | 1517 | ||
1537 | gpio = &pdata->gpio_reset; | 1518 | gpio = &pdata->gpio_reset; |
1538 | ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST"); | 1519 | if (gpio_is_valid(gpio->gpio)) { |
1539 | if (ret) { | 1520 | flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW) |
1540 | s5k6aa_free_gpios(s5k6aa); | 1521 | | GPIOF_EXPORT; |
1541 | return ret; | 1522 | ret = devm_gpio_request_one(&client->dev, gpio->gpio, flags, |
1523 | "S5K6AA_RST"); | ||
1524 | if (ret < 0) | ||
1525 | return ret; | ||
1526 | |||
1527 | s5k6aa->gpio[RST] = *gpio; | ||
1542 | } | 1528 | } |
1543 | s5k6aa->gpio[RST] = *gpio; | ||
1544 | if (gpio_is_valid(gpio->gpio)) | ||
1545 | gpio_set_value(gpio->gpio, 0); | ||
1546 | 1529 | ||
1547 | return 0; | 1530 | return 0; |
1548 | } | 1531 | } |
@@ -1593,7 +1576,7 @@ static int s5k6aa_probe(struct i2c_client *client, | |||
1593 | 1576 | ||
1594 | ret = s5k6aa_configure_gpios(s5k6aa, pdata); | 1577 | ret = s5k6aa_configure_gpios(s5k6aa, pdata); |
1595 | if (ret) | 1578 | if (ret) |
1596 | goto out_err2; | 1579 | goto out_err; |
1597 | 1580 | ||
1598 | for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++) | 1581 | for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++) |
1599 | s5k6aa->supplies[i].supply = s5k6aa_supply_names[i]; | 1582 | s5k6aa->supplies[i].supply = s5k6aa_supply_names[i]; |
@@ -1602,12 +1585,12 @@ static int s5k6aa_probe(struct i2c_client *client, | |||
1602 | s5k6aa->supplies); | 1585 | s5k6aa->supplies); |
1603 | if (ret) { | 1586 | if (ret) { |
1604 | dev_err(&client->dev, "Failed to get regulators\n"); | 1587 | dev_err(&client->dev, "Failed to get regulators\n"); |
1605 | goto out_err3; | 1588 | goto out_err; |
1606 | } | 1589 | } |
1607 | 1590 | ||
1608 | ret = s5k6aa_initialize_ctrls(s5k6aa); | 1591 | ret = s5k6aa_initialize_ctrls(s5k6aa); |
1609 | if (ret) | 1592 | if (ret) |
1610 | goto out_err3; | 1593 | goto out_err; |
1611 | 1594 | ||
1612 | s5k6aa_presets_data_init(s5k6aa); | 1595 | s5k6aa_presets_data_init(s5k6aa); |
1613 | 1596 | ||
@@ -1618,9 +1601,7 @@ static int s5k6aa_probe(struct i2c_client *client, | |||
1618 | 1601 | ||
1619 | return 0; | 1602 | return 0; |
1620 | 1603 | ||
1621 | out_err3: | 1604 | out_err: |
1622 | s5k6aa_free_gpios(s5k6aa); | ||
1623 | out_err2: | ||
1624 | media_entity_cleanup(&s5k6aa->sd.entity); | 1605 | media_entity_cleanup(&s5k6aa->sd.entity); |
1625 | return ret; | 1606 | return ret; |
1626 | } | 1607 | } |
@@ -1628,12 +1609,10 @@ out_err2: | |||
1628 | static int s5k6aa_remove(struct i2c_client *client) | 1609 | static int s5k6aa_remove(struct i2c_client *client) |
1629 | { | 1610 | { |
1630 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | 1611 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
1631 | struct s5k6aa *s5k6aa = to_s5k6aa(sd); | ||
1632 | 1612 | ||
1633 | v4l2_device_unregister_subdev(sd); | 1613 | v4l2_device_unregister_subdev(sd); |
1634 | v4l2_ctrl_handler_free(sd->ctrl_handler); | 1614 | v4l2_ctrl_handler_free(sd->ctrl_handler); |
1635 | media_entity_cleanup(&sd->entity); | 1615 | media_entity_cleanup(&sd->entity); |
1636 | s5k6aa_free_gpios(s5k6aa); | ||
1637 | 1616 | ||
1638 | return 0; | 1617 | return 0; |
1639 | } | 1618 | } |