Commit 68b41aef authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:adc:ad7606 make gpio request failures more consistent

To my mind, if a gpio is specified in the board file, yet fails
to be successfully requested, that is an error condidtion and
the driver should not muddle on regardless.

This does mean unwinding the gpios on error. Also the free_gpios
function is reordered so that it is consistent with the request one
(reverse order obviously).

This patch is the category of not technically fixing anything, just
making the driver be more in line with what a reviewer will expect.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Acked-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 0b89525d
...@@ -75,11 +75,6 @@ struct ad7606_state { ...@@ -75,11 +75,6 @@ struct ad7606_state {
unsigned range; unsigned range;
unsigned oversampling; unsigned oversampling;
bool done; bool done;
bool have_frstdata;
bool have_os;
bool have_stby;
bool have_reset;
bool have_range;
void __iomem *base_address; void __iomem *base_address;
/* /*
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
int ad7606_reset(struct ad7606_state *st) int ad7606_reset(struct ad7606_state *st)
{ {
if (st->have_reset) { if (gpio_is_valid(st->pdata->gpio_reset)) {
gpio_set_value(st->pdata->gpio_reset, 1); gpio_set_value(st->pdata->gpio_reset, 1);
ndelay(100); /* t_reset >= 100ns */ ndelay(100); /* t_reset >= 100ns */
gpio_set_value(st->pdata->gpio_reset, 0); gpio_set_value(st->pdata->gpio_reset, 0);
...@@ -48,7 +48,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned ch) ...@@ -48,7 +48,7 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned ch)
if (ret) if (ret)
goto error_ret; goto error_ret;
if (st->have_frstdata) { if (gpio_is_valid(st->pdata->gpio_frstdata)) {
ret = st->bops->read_block(st->dev, 1, st->data); ret = st->bops->read_block(st->dev, 1, st->data);
if (ret) if (ret)
goto error_ret; goto error_ret;
...@@ -214,12 +214,14 @@ static mode_t ad7606_attr_is_visible(struct kobject *kobj, ...@@ -214,12 +214,14 @@ static mode_t ad7606_attr_is_visible(struct kobject *kobj,
mode_t mode = attr->mode; mode_t mode = attr->mode;
if (!st->have_os && if (!(gpio_is_valid(st->pdata->gpio_os0) &&
(attr == &iio_dev_attr_oversampling_ratio.dev_attr.attr || gpio_is_valid(st->pdata->gpio_os1) &&
attr == gpio_is_valid(st->pdata->gpio_os2)) &&
&iio_const_attr_oversampling_ratio_available.dev_attr.attr)) (attr == &iio_dev_attr_oversampling_ratio.dev_attr.attr ||
attr ==
&iio_const_attr_oversampling_ratio_available.dev_attr.attr))
mode = 0; mode = 0;
else if (!st->have_range && else if (!gpio_is_valid(st->pdata->gpio_range) &&
(attr == &iio_dev_attr_in_voltage_range.dev_attr.attr || (attr == &iio_dev_attr_in_voltage_range.dev_attr.attr ||
attr == attr ==
&iio_const_attr_in_voltage_range_available.dev_attr.attr)) &iio_const_attr_in_voltage_range_available.dev_attr.attr))
...@@ -321,63 +323,96 @@ static int ad7606_request_gpios(struct ad7606_state *st) ...@@ -321,63 +323,96 @@ static int ad7606_request_gpios(struct ad7606_state *st)
}; };
int ret; int ret;
ret = gpio_request_one(st->pdata->gpio_convst, GPIOF_OUT_INIT_LOW, if (gpio_is_valid(st->pdata->gpio_convst)) {
"AD7606_CONVST"); ret = gpio_request_one(st->pdata->gpio_convst,
if (ret) { GPIOF_OUT_INIT_LOW,
dev_err(st->dev, "failed to request GPIO CONVST\n"); "AD7606_CONVST");
return ret; if (ret) {
dev_err(st->dev, "failed to request GPIO CONVST\n");
goto error_ret;
}
} else {
ret = -EIO;
goto error_ret;
} }
ret = gpio_request_array(gpio_array, ARRAY_SIZE(gpio_array)); if (gpio_is_valid(st->pdata->gpio_os0) &&
if (!ret) gpio_is_valid(st->pdata->gpio_os1) &&
st->have_os = true; gpio_is_valid(st->pdata->gpio_os2)) {
ret = gpio_request_array(gpio_array, ARRAY_SIZE(gpio_array));
ret = gpio_request_one(st->pdata->gpio_reset, GPIOF_OUT_INIT_LOW, if (ret < 0)
"AD7606_RESET"); goto error_free_convst;
if (!ret) }
st->have_reset = true;
ret = gpio_request_one(st->pdata->gpio_range, GPIOF_DIR_OUT | if (gpio_is_valid(st->pdata->gpio_reset)) {
((st->range == 10000) ? GPIOF_INIT_HIGH : ret = gpio_request_one(st->pdata->gpio_reset,
GPIOF_INIT_LOW), "AD7606_RANGE"); GPIOF_OUT_INIT_LOW,
if (!ret) "AD7606_RESET");
st->have_range = true; if (ret < 0)
goto error_free_os;
}
ret = gpio_request_one(st->pdata->gpio_stby, GPIOF_OUT_INIT_HIGH, if (gpio_is_valid(st->pdata->gpio_range)) {
"AD7606_STBY"); ret = gpio_request_one(st->pdata->gpio_range, GPIOF_DIR_OUT |
if (!ret) ((st->range == 10000) ? GPIOF_INIT_HIGH :
st->have_stby = true; GPIOF_INIT_LOW), "AD7606_RANGE");
if (ret < 0)
goto error_free_reset;
}
if (gpio_is_valid(st->pdata->gpio_stby)) {
ret = gpio_request_one(st->pdata->gpio_stby,
GPIOF_OUT_INIT_HIGH,
"AD7606_STBY");
if (ret < 0)
goto error_free_range;
}
if (gpio_is_valid(st->pdata->gpio_frstdata)) { if (gpio_is_valid(st->pdata->gpio_frstdata)) {
ret = gpio_request_one(st->pdata->gpio_frstdata, GPIOF_IN, ret = gpio_request_one(st->pdata->gpio_frstdata, GPIOF_IN,
"AD7606_FRSTDATA"); "AD7606_FRSTDATA");
if (!ret) if (ret < 0)
st->have_frstdata = true; goto error_free_stby;
} }
return 0; return 0;
error_free_stby:
if (gpio_is_valid(st->pdata->gpio_stby))
gpio_free(st->pdata->gpio_stby);
error_free_range:
if (gpio_is_valid(st->pdata->gpio_range))
gpio_free(st->pdata->gpio_range);
error_free_reset:
if (gpio_is_valid(st->pdata->gpio_reset))
gpio_free(st->pdata->gpio_reset);
error_free_os:
if (gpio_is_valid(st->pdata->gpio_os0) &&
gpio_is_valid(st->pdata->gpio_os1) &&
gpio_is_valid(st->pdata->gpio_os2))
gpio_free_array(gpio_array, ARRAY_SIZE(gpio_array));
error_free_convst:
gpio_free(st->pdata->gpio_convst);
error_ret:
return ret;
} }
static void ad7606_free_gpios(struct ad7606_state *st) static void ad7606_free_gpios(struct ad7606_state *st)
{ {
if (st->have_range) if (gpio_is_valid(st->pdata->gpio_frstdata))
gpio_free(st->pdata->gpio_range); gpio_free(st->pdata->gpio_frstdata);
if (gpio_is_valid(st->pdata->gpio_stby))
if (st->have_stby)
gpio_free(st->pdata->gpio_stby); gpio_free(st->pdata->gpio_stby);
if (gpio_is_valid(st->pdata->gpio_range))
if (st->have_os) { gpio_free(st->pdata->gpio_range);
gpio_free(st->pdata->gpio_os0); if (gpio_is_valid(st->pdata->gpio_reset))
gpio_free(st->pdata->gpio_os1); gpio_free(st->pdata->gpio_reset);
if (gpio_is_valid(st->pdata->gpio_os0) &&
gpio_is_valid(st->pdata->gpio_os1) &&
gpio_is_valid(st->pdata->gpio_os2)) {
gpio_free(st->pdata->gpio_os2); gpio_free(st->pdata->gpio_os2);
gpio_free(st->pdata->gpio_os1);
gpio_free(st->pdata->gpio_os0);
} }
if (st->have_reset)
gpio_free(st->pdata->gpio_reset);
if (st->have_frstdata)
gpio_free(st->pdata->gpio_frstdata);
gpio_free(st->pdata->gpio_convst); gpio_free(st->pdata->gpio_convst);
} }
...@@ -531,8 +566,8 @@ void ad7606_suspend(struct iio_dev *indio_dev) ...@@ -531,8 +566,8 @@ void ad7606_suspend(struct iio_dev *indio_dev)
{ {
struct ad7606_state *st = iio_priv(indio_dev); struct ad7606_state *st = iio_priv(indio_dev);
if (st->have_stby) { if (gpio_is_valid(st->pdata->gpio_stby)) {
if (st->have_range) if (gpio_is_valid(st->pdata->gpio_range))
gpio_set_value(st->pdata->gpio_range, 1); gpio_set_value(st->pdata->gpio_range, 1);
gpio_set_value(st->pdata->gpio_stby, 0); gpio_set_value(st->pdata->gpio_stby, 0);
} }
...@@ -542,8 +577,8 @@ void ad7606_resume(struct iio_dev *indio_dev) ...@@ -542,8 +577,8 @@ void ad7606_resume(struct iio_dev *indio_dev)
{ {
struct ad7606_state *st = iio_priv(indio_dev); struct ad7606_state *st = iio_priv(indio_dev);
if (st->have_stby) { if (gpio_is_valid(st->pdata->gpio_stby)) {
if (st->have_range) if (gpio_is_valid(st->pdata->gpio_range))
gpio_set_value(st->pdata->gpio_range, gpio_set_value(st->pdata->gpio_range,
st->range == 10000); st->range == 10000);
......
...@@ -110,7 +110,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s) ...@@ -110,7 +110,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
if (buf == NULL) if (buf == NULL)
return; return;
if (st->have_frstdata) { if (gpio_is_valid(st->pdata->gpio_frstdata)) {
ret = st->bops->read_block(st->dev, 1, buf); ret = st->bops->read_block(st->dev, 1, buf);
if (ret) if (ret)
goto done; goto done;
......
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