Commit 598d8d1e authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] s5c73m3: Convert to devm_gpio_request_one()

Use the devm_gpio_request_one() managed function to simplify cleanup
code paths.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: default avatarSylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 736db646
...@@ -1511,59 +1511,40 @@ static const struct v4l2_subdev_ops oif_subdev_ops = { ...@@ -1511,59 +1511,40 @@ static const struct v4l2_subdev_ops oif_subdev_ops = {
.video = &s5c73m3_oif_video_ops, .video = &s5c73m3_oif_video_ops,
}; };
static int s5c73m3_configure_gpio(int nr, int val, const char *name)
{
unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
int ret;
if (!gpio_is_valid(nr))
return 0;
ret = gpio_request_one(nr, flags, name);
if (!ret)
gpio_export(nr, 0);
return ret;
}
static int s5c73m3_free_gpios(struct s5c73m3 *state)
{
int i;
for (i = 0; i < ARRAY_SIZE(state->gpio); i++) {
if (!gpio_is_valid(state->gpio[i].gpio))
continue;
gpio_free(state->gpio[i].gpio);
state->gpio[i].gpio = -EINVAL;
}
return 0;
}
static int s5c73m3_configure_gpios(struct s5c73m3 *state, static int s5c73m3_configure_gpios(struct s5c73m3 *state,
const struct s5c73m3_platform_data *pdata) const struct s5c73m3_platform_data *pdata)
{ {
const struct s5c73m3_gpio *gpio = &pdata->gpio_stby; struct device *dev = &state->i2c_client->dev;
const struct s5c73m3_gpio *gpio;
unsigned long flags;
int ret; int ret;
state->gpio[STBY].gpio = -EINVAL; state->gpio[STBY].gpio = -EINVAL;
state->gpio[RST].gpio = -EINVAL; state->gpio[RST].gpio = -EINVAL;
ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_STBY"); gpio = &pdata->gpio_stby;
if (ret) { if (gpio_is_valid(gpio->gpio)) {
s5c73m3_free_gpios(state); flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
return ret; | GPIOF_EXPORT;
ret = devm_gpio_request_one(dev, gpio->gpio, flags,
"S5C73M3_STBY");
if (ret < 0)
return ret;
state->gpio[STBY] = *gpio;
} }
state->gpio[STBY] = *gpio;
if (gpio_is_valid(gpio->gpio))
gpio_set_value(gpio->gpio, 0);
gpio = &pdata->gpio_reset; gpio = &pdata->gpio_reset;
ret = s5c73m3_configure_gpio(gpio->gpio, gpio->level, "S5C73M3_RST"); if (gpio_is_valid(gpio->gpio)) {
if (ret) { flags = (gpio->level ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW)
s5c73m3_free_gpios(state); | GPIOF_EXPORT;
return ret; ret = devm_gpio_request_one(dev, gpio->gpio, flags,
"S5C73M3_RST");
if (ret < 0)
return ret;
state->gpio[RST] = *gpio;
} }
state->gpio[RST] = *gpio;
if (gpio_is_valid(gpio->gpio))
gpio_set_value(gpio->gpio, 0);
return 0; return 0;
} }
...@@ -1626,10 +1607,11 @@ static int s5c73m3_probe(struct i2c_client *client, ...@@ -1626,10 +1607,11 @@ static int s5c73m3_probe(struct i2c_client *client,
state->mclk_frequency = pdata->mclk_frequency; state->mclk_frequency = pdata->mclk_frequency;
state->bus_type = pdata->bus_type; state->bus_type = pdata->bus_type;
state->i2c_client = client;
ret = s5c73m3_configure_gpios(state, pdata); ret = s5c73m3_configure_gpios(state, pdata);
if (ret) if (ret)
goto out_err1; goto out_err;
for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++) for (i = 0; i < S5C73M3_MAX_SUPPLIES; i++)
state->supplies[i].supply = s5c73m3_supply_names[i]; state->supplies[i].supply = s5c73m3_supply_names[i];
...@@ -1638,12 +1620,12 @@ static int s5c73m3_probe(struct i2c_client *client, ...@@ -1638,12 +1620,12 @@ static int s5c73m3_probe(struct i2c_client *client,
state->supplies); state->supplies);
if (ret) { if (ret) {
dev_err(dev, "failed to get regulators\n"); dev_err(dev, "failed to get regulators\n");
goto out_err2; goto out_err;
} }
ret = s5c73m3_init_controls(state); ret = s5c73m3_init_controls(state);
if (ret) if (ret)
goto out_err2; goto out_err;
state->sensor_pix_size[RES_ISP] = &s5c73m3_isp_resolutions[1]; state->sensor_pix_size[RES_ISP] = &s5c73m3_isp_resolutions[1];
state->sensor_pix_size[RES_JPEG] = &s5c73m3_jpeg_resolutions[1]; state->sensor_pix_size[RES_JPEG] = &s5c73m3_jpeg_resolutions[1];
...@@ -1659,16 +1641,12 @@ static int s5c73m3_probe(struct i2c_client *client, ...@@ -1659,16 +1641,12 @@ static int s5c73m3_probe(struct i2c_client *client,
ret = s5c73m3_register_spi_driver(state); ret = s5c73m3_register_spi_driver(state);
if (ret < 0) if (ret < 0)
goto out_err2; goto out_err;
state->i2c_client = client;
v4l2_info(sd, "%s: completed succesfully\n", __func__); v4l2_info(sd, "%s: completed succesfully\n", __func__);
return 0; return 0;
out_err2: out_err:
s5c73m3_free_gpios(state);
out_err1:
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
return ret; return ret;
} }
...@@ -1688,7 +1666,6 @@ static int s5c73m3_remove(struct i2c_client *client) ...@@ -1688,7 +1666,6 @@ static int s5c73m3_remove(struct i2c_client *client)
media_entity_cleanup(&sensor_sd->entity); media_entity_cleanup(&sensor_sd->entity);
s5c73m3_unregister_spi_driver(state); s5c73m3_unregister_spi_driver(state);
s5c73m3_free_gpios(state);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment