Commit 26d25ae3 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio: rework of attribute registration.

This set also includes quite a number of bug fixes of particularly
remove functions.

Necessary due to issue pointed out in Bart Van Assche's patch:
docs/driver-model: Document device.groups

V2: Rebase due to patch reordering.
V3: Pull various error fixes and cleanups out into their own patches.
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 330c6c57
...@@ -463,7 +463,7 @@ static const struct iio_info adis16201_info = { ...@@ -463,7 +463,7 @@ static const struct iio_info adis16201_info = {
static int __devinit adis16201_probe(struct spi_device *spi) static int __devinit adis16201_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16201_state *st; struct adis16201_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -492,11 +492,6 @@ static int __devinit adis16201_probe(struct spi_device *spi) ...@@ -492,11 +492,6 @@ static int __devinit adis16201_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
adis16201_channels, adis16201_channels,
ARRAY_SIZE(adis16201_channels)); ARRAY_SIZE(adis16201_channels));
...@@ -515,6 +510,10 @@ static int __devinit adis16201_probe(struct spi_device *spi) ...@@ -515,6 +510,10 @@ static int __devinit adis16201_probe(struct spi_device *spi)
ret = adis16201_initial_setup(indio_dev); ret = adis16201_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret < 0)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -524,10 +523,7 @@ static int __devinit adis16201_probe(struct spi_device *spi) ...@@ -524,10 +523,7 @@ static int __devinit adis16201_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16201_unconfigure_ring(indio_dev); adis16201_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -419,7 +419,7 @@ static const struct iio_info adis16203_info = { ...@@ -419,7 +419,7 @@ static const struct iio_info adis16203_info = {
static int __devinit adis16203_probe(struct spi_device *spi) static int __devinit adis16203_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct adis16203_state *st; struct adis16203_state *st;
...@@ -446,11 +446,6 @@ static int __devinit adis16203_probe(struct spi_device *spi) ...@@ -446,11 +446,6 @@ static int __devinit adis16203_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
adis16203_channels, adis16203_channels,
ARRAY_SIZE(adis16203_channels)); ARRAY_SIZE(adis16203_channels));
...@@ -469,6 +464,11 @@ static int __devinit adis16203_probe(struct spi_device *spi) ...@@ -469,6 +464,11 @@ static int __devinit adis16203_probe(struct spi_device *spi)
ret = adis16203_initial_setup(indio_dev); ret = adis16203_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -478,10 +478,7 @@ static int __devinit adis16203_probe(struct spi_device *spi) ...@@ -478,10 +478,7 @@ static int __devinit adis16203_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16203_unconfigure_ring(indio_dev); adis16203_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -494,7 +494,7 @@ static const struct iio_info adis16204_info = { ...@@ -494,7 +494,7 @@ static const struct iio_info adis16204_info = {
static int __devinit adis16204_probe(struct spi_device *spi) static int __devinit adis16204_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16204_state *st; struct adis16204_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -521,11 +521,6 @@ static int __devinit adis16204_probe(struct spi_device *spi) ...@@ -521,11 +521,6 @@ static int __devinit adis16204_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
adis16204_channels, adis16204_channels,
ARRAY_SIZE(adis16204_channels)); ARRAY_SIZE(adis16204_channels));
...@@ -544,6 +539,10 @@ static int __devinit adis16204_probe(struct spi_device *spi) ...@@ -544,6 +539,10 @@ static int __devinit adis16204_probe(struct spi_device *spi)
ret = adis16204_initial_setup(indio_dev); ret = adis16204_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -553,10 +552,7 @@ static int __devinit adis16204_probe(struct spi_device *spi) ...@@ -553,10 +552,7 @@ static int __devinit adis16204_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16204_unconfigure_ring(indio_dev); adis16204_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -467,7 +467,7 @@ static const struct iio_info adis16209_info = { ...@@ -467,7 +467,7 @@ static const struct iio_info adis16209_info = {
static int __devinit adis16209_probe(struct spi_device *spi) static int __devinit adis16209_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16209_state *st; struct adis16209_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -494,11 +494,6 @@ static int __devinit adis16209_probe(struct spi_device *spi) ...@@ -494,11 +494,6 @@ static int __devinit adis16209_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
adis16209_channels, adis16209_channels,
ARRAY_SIZE(adis16209_channels)); ARRAY_SIZE(adis16209_channels));
...@@ -517,6 +512,10 @@ static int __devinit adis16209_probe(struct spi_device *spi) ...@@ -517,6 +512,10 @@ static int __devinit adis16209_probe(struct spi_device *spi)
ret = adis16209_initial_setup(indio_dev); ret = adis16209_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -526,10 +525,7 @@ static int __devinit adis16209_probe(struct spi_device *spi) ...@@ -526,10 +525,7 @@ static int __devinit adis16209_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16209_unconfigure_ring(indio_dev); adis16209_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -519,7 +519,7 @@ static const struct iio_info adis16240_info = { ...@@ -519,7 +519,7 @@ static const struct iio_info adis16240_info = {
static int __devinit adis16240_probe(struct spi_device *spi) static int __devinit adis16240_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16240_state *st; struct adis16240_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -547,11 +547,6 @@ static int __devinit adis16240_probe(struct spi_device *spi) ...@@ -547,11 +547,6 @@ static int __devinit adis16240_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
adis16240_channels, adis16240_channels,
ARRAY_SIZE(adis16240_channels)); ARRAY_SIZE(adis16240_channels));
...@@ -568,6 +563,9 @@ static int __devinit adis16240_probe(struct spi_device *spi) ...@@ -568,6 +563,9 @@ static int __devinit adis16240_probe(struct spi_device *spi)
/* Get the device into a sane initial state */ /* Get the device into a sane initial state */
ret = adis16240_initial_setup(indio_dev); ret = adis16240_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
return 0; return 0;
...@@ -579,10 +577,7 @@ static int __devinit adis16240_probe(struct spi_device *spi) ...@@ -579,10 +577,7 @@ static int __devinit adis16240_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16240_unconfigure_ring(indio_dev); adis16240_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -663,7 +663,7 @@ static const struct iio_info lis3l02dq_info = { ...@@ -663,7 +663,7 @@ static const struct iio_info lis3l02dq_info = {
static int __devinit lis3l02dq_probe(struct spi_device *spi) static int __devinit lis3l02dq_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct lis3l02dq_state *st; struct lis3l02dq_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -690,11 +690,6 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) ...@@ -690,11 +690,6 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
lis3l02dq_channels, lis3l02dq_channels,
ARRAY_SIZE(lis3l02dq_channels)); ARRAY_SIZE(lis3l02dq_channels));
...@@ -722,6 +717,11 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) ...@@ -722,6 +717,11 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
ret = lis3l02dq_initial_setup(indio_dev); ret = lis3l02dq_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -735,9 +735,6 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi) ...@@ -735,9 +735,6 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
lis3l02dq_unconfigure_ring(indio_dev); lis3l02dq_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone)
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
...@@ -790,9 +787,8 @@ static int lis3l02dq_remove(struct spi_device *spi) ...@@ -790,9 +787,8 @@ static int lis3l02dq_remove(struct spi_device *spi)
lis3l02dq_remove_trigger(indio_dev); lis3l02dq_remove_trigger(indio_dev);
iio_ring_buffer_unregister(indio_dev); iio_ring_buffer_unregister(indio_dev);
lis3l02dq_unconfigure_ring(indio_dev); lis3l02dq_unconfigure_ring(indio_dev);
iio_device_unregister(indio_dev);
return 0; iio_device_unregister(indio_dev);
err_ret: err_ret:
return ret; return ret;
......
...@@ -719,7 +719,7 @@ static const struct iio_info ad7150_info = { ...@@ -719,7 +719,7 @@ static const struct iio_info ad7150_info = {
static int __devinit ad7150_probe(struct i2c_client *client, static int __devinit ad7150_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret = 0, regdone = 0; int ret;
struct ad7150_chip_info *chip; struct ad7150_chip_info *chip;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -742,11 +742,6 @@ static int __devinit ad7150_probe(struct i2c_client *client, ...@@ -742,11 +742,6 @@ static int __devinit ad7150_probe(struct i2c_client *client,
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
regdone = 1;
if (client->irq) { if (client->irq) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
NULL, NULL,
...@@ -759,15 +754,20 @@ static int __devinit ad7150_probe(struct i2c_client *client, ...@@ -759,15 +754,20 @@ static int __devinit ad7150_probe(struct i2c_client *client,
goto error_free_dev; goto error_free_dev;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq); dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);
return 0; return 0;
error_free_irq:
if (client->irq)
free_irq(client->irq, indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -811,10 +811,6 @@ static int __devinit ad7291_probe(struct i2c_client *client, ...@@ -811,10 +811,6 @@ static int __devinit ad7291_probe(struct i2c_client *client,
indio_dev->info = &ad7291_info; indio_dev->info = &ad7291_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
if (client->irq > 0) { if (client->irq > 0) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
NULL, NULL,
...@@ -823,7 +819,7 @@ static int __devinit ad7291_probe(struct i2c_client *client, ...@@ -823,7 +819,7 @@ static int __devinit ad7291_probe(struct i2c_client *client,
id->name, id->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
/* set irq polarity low level */ /* set irq polarity low level */
chip->command |= AD7291_ALART_POLARITY; chip->command |= AD7291_ALART_POLARITY;
...@@ -835,6 +831,10 @@ static int __devinit ad7291_probe(struct i2c_client *client, ...@@ -835,6 +831,10 @@ static int __devinit ad7291_probe(struct i2c_client *client,
goto error_unreg_irq; goto error_unreg_irq;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_irq;
dev_info(&client->dev, "%s temperature sensor registered.\n", dev_info(&client->dev, "%s temperature sensor registered.\n",
id->name); id->name);
...@@ -842,8 +842,6 @@ static int __devinit ad7291_probe(struct i2c_client *client, ...@@ -842,8 +842,6 @@ static int __devinit ad7291_probe(struct i2c_client *client,
error_unreg_irq: error_unreg_irq:
free_irq(client->irq, indio_dev); free_irq(client->irq, indio_dev);
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
......
...@@ -165,7 +165,7 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -165,7 +165,7 @@ static int __devinit ad7298_probe(struct spi_device *spi)
{ {
struct ad7298_platform_data *pdata = spi->dev.platform_data; struct ad7298_platform_data *pdata = spi->dev.platform_data;
struct ad7298_state *st; struct ad7298_state *st;
int ret, regdone = 0; int ret;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) if (indio_dev == NULL)
...@@ -218,19 +218,19 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -218,19 +218,19 @@ static int __devinit ad7298_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_disable_reg;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
&ad7298_channels[1], /* skip temp0 */ &ad7298_channels[1], /* skip temp0 */
ARRAY_SIZE(ad7298_channels) - 1); ARRAY_SIZE(ad7298_channels) - 1);
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unregister_ring;
return 0; return 0;
error_unregister_ring:
iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad7298_ring_cleanup(indio_dev); ad7298_ring_cleanup(indio_dev);
error_disable_reg: error_disable_reg:
...@@ -239,11 +239,7 @@ static int __devinit ad7298_probe(struct spi_device *spi) ...@@ -239,11 +239,7 @@ static int __devinit ad7298_probe(struct spi_device *spi)
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
iio_free_device(indio_dev);
if (regdone)
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -129,7 +129,6 @@ static int __devinit ad7476_probe(struct spi_device *spi) ...@@ -129,7 +129,6 @@ static int __devinit ad7476_probe(struct spi_device *spi)
struct ad7476_state *st; struct ad7476_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret, voltage_uv = 0; int ret, voltage_uv = 0;
bool reg_done = false;
indio_dev = iio_allocate_device(sizeof(*st)); indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) { if (indio_dev == NULL) {
...@@ -180,28 +179,29 @@ static int __devinit ad7476_probe(struct spi_device *spi) ...@@ -180,28 +179,29 @@ static int __devinit ad7476_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_disable_reg;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
st->chip_info->channel, st->chip_info->channel,
ARRAY_SIZE(st->chip_info->channel)); ARRAY_SIZE(st->chip_info->channel));
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
ret = iio_device_register(indio_dev);
if (ret)
goto error_ring_unregister;
return 0; return 0;
error_ring_unregister:
iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad7476_ring_cleanup(indio_dev); ad7476_ring_cleanup(indio_dev);
iio_device_unregister(indio_dev);
error_disable_reg: error_disable_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_disable(st->reg); regulator_disable(st->reg);
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (!reg_done) iio_free_device(indio_dev);
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -439,7 +439,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq, ...@@ -439,7 +439,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
{ {
struct ad7606_platform_data *pdata = dev->platform_data; struct ad7606_platform_data *pdata = dev->platform_data;
struct ad7606_state *st; struct ad7606_state *st;
int ret, regdone = 0; int ret;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) { if (indio_dev == NULL) {
...@@ -501,18 +501,18 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq, ...@@ -501,18 +501,18 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
if (ret) if (ret)
goto error_free_irq; goto error_free_irq;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
indio_dev->channels, indio_dev->channels,
indio_dev->num_channels); indio_dev->num_channels);
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unregister_ring;
return indio_dev; return indio_dev;
error_unregister_ring:
iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad7606_ring_cleanup(indio_dev); ad7606_ring_cleanup(indio_dev);
...@@ -529,10 +529,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq, ...@@ -529,10 +529,7 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ERR_PTR(ret); return ERR_PTR(ret);
} }
......
...@@ -578,7 +578,7 @@ static const struct iio_info ad774x_info = { ...@@ -578,7 +578,7 @@ static const struct iio_info ad774x_info = {
static int __devinit ad774x_probe(struct i2c_client *client, static int __devinit ad774x_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret = 0, regdone = 0; int ret;
struct ad774x_chip_info *chip; struct ad774x_chip_info *chip;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -599,11 +599,6 @@ static int __devinit ad774x_probe(struct i2c_client *client, ...@@ -599,11 +599,6 @@ static int __devinit ad774x_probe(struct i2c_client *client,
indio_dev->info = &ad774x_info; indio_dev->info = &ad774x_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
regdone = 1;
if (client->irq) { if (client->irq) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
NULL, NULL,
...@@ -615,15 +610,18 @@ static int __devinit ad774x_probe(struct i2c_client *client, ...@@ -615,15 +610,18 @@ static int __devinit ad774x_probe(struct i2c_client *client,
goto error_free_dev; goto error_free_dev;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq); dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);
return 0; return 0;
error_free_irq:
free_irq(client->irq, indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
free_irq(client->irq, indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -827,7 +827,7 @@ static int __devinit ad7793_probe(struct spi_device *spi) ...@@ -827,7 +827,7 @@ static int __devinit ad7793_probe(struct spi_device *spi)
struct ad7793_platform_data *pdata = spi->dev.platform_data; struct ad7793_platform_data *pdata = spi->dev.platform_data;
struct ad7793_state *st; struct ad7793_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
int ret, i, voltage_uv = 0, regdone = 0; int ret, i, voltage_uv = 0;
if (!pdata) { if (!pdata) {
dev_err(&spi->dev, "no platform data?\n"); dev_err(&spi->dev, "no platform data?\n");
...@@ -890,11 +890,6 @@ static int __devinit ad7793_probe(struct spi_device *spi) ...@@ -890,11 +890,6 @@ static int __devinit ad7793_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring;
regdone = 1;
ret = ad7793_probe_trigger(indio_dev); ret = ad7793_probe_trigger(indio_dev);
if (ret) if (ret)
goto error_unreg_ring; goto error_unreg_ring;
...@@ -909,6 +904,10 @@ static int __devinit ad7793_probe(struct spi_device *spi) ...@@ -909,6 +904,10 @@ static int __devinit ad7793_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_uninitialize_ring; goto error_uninitialize_ring;
ret = iio_device_register(indio_dev);
if (ret)
goto error_uninitialize_ring;
return 0; return 0;
error_uninitialize_ring: error_uninitialize_ring:
...@@ -924,10 +923,7 @@ static int __devinit ad7793_probe(struct spi_device *spi) ...@@ -924,10 +923,7 @@ static int __devinit ad7793_probe(struct spi_device *spi)
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -396,10 +396,6 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) ...@@ -396,10 +396,6 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
indio_dev->info = &ad7816_info; indio_dev->info = &ad7816_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_gpio;
if (spi_dev->irq) { if (spi_dev->irq) {
/* Only low trigger is supported in ad7816/7/8 */ /* Only low trigger is supported in ad7816/7/8 */
ret = request_threaded_irq(spi_dev->irq, ret = request_threaded_irq(spi_dev->irq,
...@@ -409,16 +405,19 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev) ...@@ -409,16 +405,19 @@ static int __devinit ad7816_probe(struct spi_device *spi_dev)
indio_dev->name, indio_dev->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_gpio;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n", dev_info(&spi_dev->dev, "%s temperature sensor and ADC registered.\n",
indio_dev->name); indio_dev->name);
return 0; return 0;
error_free_irq:
error_unreg_dev: free_irq(spi_dev->irq, indio_dev);
iio_device_unregister(indio_dev);
error_free_gpio: error_free_gpio:
gpio_free(chip->busy_pin); gpio_free(chip->busy_pin);
error_free_gpio_convert: error_free_gpio_convert:
......
...@@ -93,7 +93,7 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -93,7 +93,7 @@ static int __devinit ad7887_probe(struct spi_device *spi)
{ {
struct ad7887_platform_data *pdata = spi->dev.platform_data; struct ad7887_platform_data *pdata = spi->dev.platform_data;
struct ad7887_state *st; struct ad7887_state *st;
int ret, voltage_uv = 0, regdone = 0; int ret, voltage_uv = 0;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) if (indio_dev == NULL)
...@@ -189,18 +189,19 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -189,18 +189,19 @@ static int __devinit ad7887_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_disable_reg;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
indio_dev->channels, indio_dev->channels,
indio_dev->num_channels); indio_dev->num_channels);
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
return 0;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unregister_ring;
return 0;
error_unregister_ring:
iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad7887_ring_cleanup(indio_dev); ad7887_ring_cleanup(indio_dev);
error_disable_reg: error_disable_reg:
...@@ -209,10 +210,7 @@ static int __devinit ad7887_probe(struct spi_device *spi) ...@@ -209,10 +210,7 @@ static int __devinit ad7887_probe(struct spi_device *spi)
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -657,7 +657,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { ...@@ -657,7 +657,7 @@ static const struct ad799x_chip_info ad799x_chip_info_tbl[] = {
static int __devinit ad799x_probe(struct i2c_client *client, static int __devinit ad799x_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret, regdone = 0; int ret;
struct ad799x_platform_data *pdata = client->dev.platform_data; struct ad799x_platform_data *pdata = client->dev.platform_data;
struct ad799x_state *st; struct ad799x_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
...@@ -701,11 +701,6 @@ static int __devinit ad799x_probe(struct i2c_client *client, ...@@ -701,11 +701,6 @@ static int __devinit ad799x_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_cleanup_ring;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
indio_dev->channels, indio_dev->channels,
indio_dev->num_channels); indio_dev->num_channels);
...@@ -723,9 +718,14 @@ static int __devinit ad799x_probe(struct i2c_client *client, ...@@ -723,9 +718,14 @@ static int __devinit ad799x_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_cleanup_ring; goto error_cleanup_ring;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
return 0; return 0;
error_free_irq:
free_irq(client->irq, indio_dev);
error_cleanup_ring: error_cleanup_ring:
ad799x_ring_cleanup(indio_dev); ad799x_ring_cleanup(indio_dev);
error_disable_reg: error_disable_reg:
...@@ -734,10 +734,7 @@ static int __devinit ad799x_probe(struct i2c_client *client, ...@@ -734,10 +734,7 @@ static int __devinit ad799x_probe(struct i2c_client *client,
error_put_reg: error_put_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -782,10 +782,6 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -782,10 +782,6 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
indio_dev->info = &adt7310_info; indio_dev->info = &adt7310_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
/* CT critcal temperature event. line 0 */ /* CT critcal temperature event. line 0 */
if (spi_dev->irq) { if (spi_dev->irq) {
if (adt7310_platform_data[2]) if (adt7310_platform_data[2])
...@@ -799,7 +795,7 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -799,7 +795,7 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
indio_dev->name, indio_dev->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
} }
/* INT bound temperature alarm event. line 1 */ /* INT bound temperature alarm event. line 1 */
...@@ -836,6 +832,10 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -836,6 +832,10 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
} }
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_int_irq;
dev_info(&spi_dev->dev, "%s temperature sensor registered.\n", dev_info(&spi_dev->dev, "%s temperature sensor registered.\n",
indio_dev->name); indio_dev->name);
...@@ -845,8 +845,6 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev) ...@@ -845,8 +845,6 @@ static int __devinit adt7310_probe(struct spi_device *spi_dev)
free_irq(adt7310_platform_data[0], indio_dev); free_irq(adt7310_platform_data[0], indio_dev);
error_unreg_ct_irq: error_unreg_ct_irq:
free_irq(spi_dev->irq, indio_dev); free_irq(spi_dev->irq, indio_dev);
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
......
...@@ -749,10 +749,6 @@ static int __devinit adt7410_probe(struct i2c_client *client, ...@@ -749,10 +749,6 @@ static int __devinit adt7410_probe(struct i2c_client *client,
indio_dev->info = &adt7410_info; indio_dev->info = &adt7410_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
/* CT critcal temperature event. line 0 */ /* CT critcal temperature event. line 0 */
if (client->irq) { if (client->irq) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
...@@ -762,7 +758,7 @@ static int __devinit adt7410_probe(struct i2c_client *client, ...@@ -762,7 +758,7 @@ static int __devinit adt7410_probe(struct i2c_client *client,
id->name, id->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
} }
/* INT bound temperature alarm event. line 1 */ /* INT bound temperature alarm event. line 1 */
...@@ -799,6 +795,9 @@ static int __devinit adt7410_probe(struct i2c_client *client, ...@@ -799,6 +795,9 @@ static int __devinit adt7410_probe(struct i2c_client *client,
goto error_unreg_int_irq; goto error_unreg_int_irq;
} }
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_int_irq;
dev_info(&client->dev, "%s temperature sensor registered.\n", dev_info(&client->dev, "%s temperature sensor registered.\n",
id->name); id->name);
...@@ -809,8 +808,6 @@ static int __devinit adt7410_probe(struct i2c_client *client, ...@@ -809,8 +808,6 @@ static int __devinit adt7410_probe(struct i2c_client *client,
free_irq(adt7410_platform_data[0], indio_dev); free_irq(adt7410_platform_data[0], indio_dev);
error_unreg_ct_irq: error_unreg_ct_irq:
free_irq(client->irq, indio_dev); free_irq(client->irq, indio_dev);
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
......
...@@ -567,10 +567,6 @@ static int __devinit adt75_probe(struct i2c_client *client, ...@@ -567,10 +567,6 @@ static int __devinit adt75_probe(struct i2c_client *client,
indio_dev->info = &adt75_info; indio_dev->info = &adt75_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
if (client->irq > 0) { if (client->irq > 0) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
NULL, NULL,
...@@ -579,7 +575,7 @@ static int __devinit adt75_probe(struct i2c_client *client, ...@@ -579,7 +575,7 @@ static int __devinit adt75_probe(struct i2c_client *client,
indio_dev->name, indio_dev->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
ret = adt75_i2c_read(indio_dev, ADT75_CONFIG, &chip->config); ret = adt75_i2c_read(indio_dev, ADT75_CONFIG, &chip->config);
if (ret) { if (ret) {
...@@ -597,14 +593,16 @@ static int __devinit adt75_probe(struct i2c_client *client, ...@@ -597,14 +593,16 @@ static int __devinit adt75_probe(struct i2c_client *client,
} }
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_irq;
dev_info(&client->dev, "%s temperature sensor registered.\n", dev_info(&client->dev, "%s temperature sensor registered.\n",
indio_dev->name); indio_dev->name);
return 0; return 0;
error_unreg_irq: error_unreg_irq:
free_irq(client->irq, indio_dev); free_irq(client->irq, indio_dev);
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
......
...@@ -1254,7 +1254,7 @@ static int max1363_initial_setup(struct max1363_state *st) ...@@ -1254,7 +1254,7 @@ static int max1363_initial_setup(struct max1363_state *st)
static int __devinit max1363_probe(struct i2c_client *client, static int __devinit max1363_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret, i, regdone = 0; int ret, i;
struct max1363_state *st; struct max1363_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct regulator *reg; struct regulator *reg;
...@@ -1312,10 +1312,6 @@ static int __devinit max1363_probe(struct i2c_client *client, ...@@ -1312,10 +1312,6 @@ static int __devinit max1363_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_free_available_scan_masks; goto error_free_available_scan_masks;
ret = iio_device_register(indio_dev);
if (ret)
goto error_cleanup_ring;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
st->chip_info->channels, st->chip_info->channels,
st->chip_info->num_channels); st->chip_info->num_channels);
...@@ -1334,8 +1330,13 @@ static int __devinit max1363_probe(struct i2c_client *client, ...@@ -1334,8 +1330,13 @@ static int __devinit max1363_probe(struct i2c_client *client,
goto error_uninit_ring; goto error_uninit_ring;
} }
return 0; ret = iio_device_register(indio_dev);
if (ret < 0)
goto error_free_irq;
return 0;
error_free_irq:
free_irq(st->client->irq, indio_dev);
error_uninit_ring: error_uninit_ring:
iio_ring_buffer_unregister(indio_dev); iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring: error_cleanup_ring:
...@@ -1343,10 +1344,7 @@ static int __devinit max1363_probe(struct i2c_client *client, ...@@ -1343,10 +1344,7 @@ static int __devinit max1363_probe(struct i2c_client *client,
error_free_available_scan_masks: error_free_available_scan_masks:
kfree(indio_dev->available_scan_masks); kfree(indio_dev->available_scan_masks);
error_free_device: error_free_device:
if (!regdone) iio_free_device(indio_dev);
iio_free_device(indio_dev);
else
iio_device_unregister(indio_dev);
error_disable_reg: error_disable_reg:
regulator_disable(reg); regulator_disable(reg);
error_put_reg: error_put_reg:
......
...@@ -2167,10 +2167,6 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus, ...@@ -2167,10 +2167,6 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
indio_dev->name = name; indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
if (chip->bus.irq > 0) { if (chip->bus.irq > 0) {
if (adt7316_platform_data[0]) if (adt7316_platform_data[0])
chip->bus.irq_flags = adt7316_platform_data[0]; chip->bus.irq_flags = adt7316_platform_data[0];
...@@ -2182,7 +2178,7 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus, ...@@ -2182,7 +2178,7 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
indio_dev->name, indio_dev->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH) if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH)
chip->config1 |= ADT7316_INT_POLARITY; chip->config1 |= ADT7316_INT_POLARITY;
...@@ -2200,6 +2196,10 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus, ...@@ -2200,6 +2196,10 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
goto error_unreg_irq; goto error_unreg_irq;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_irq;
dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n", dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n",
indio_dev->name); indio_dev->name);
...@@ -2207,8 +2207,6 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus, ...@@ -2207,8 +2207,6 @@ int __devinit adt7316_probe(struct device *dev, struct adt7316_bus *bus,
error_unreg_irq: error_unreg_irq:
free_irq(chip->bus.irq, indio_dev); free_irq(chip->bus.irq, indio_dev);
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
...@@ -2221,7 +2219,6 @@ int __devexit adt7316_remove(struct device *dev) ...@@ -2221,7 +2219,6 @@ int __devexit adt7316_remove(struct device *dev)
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adt7316_chip_info *chip = iio_priv(indio_dev); struct adt7316_chip_info *chip = iio_priv(indio_dev);
dev_set_drvdata(dev, NULL);
if (chip->bus.irq) if (chip->bus.irq)
free_irq(chip->bus.irq, indio_dev); free_irq(chip->bus.irq, indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
......
...@@ -282,6 +282,11 @@ static int __devinit ad5504_probe(struct spi_device *spi) ...@@ -282,6 +282,11 @@ static int __devinit ad5504_probe(struct spi_device *spi)
struct regulator *reg; struct regulator *reg;
int ret, voltage_uv = 0; int ret, voltage_uv = 0;
indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_ret;
}
reg = regulator_get(&spi->dev, "vcc"); reg = regulator_get(&spi->dev, "vcc");
if (!IS_ERR(reg)) { if (!IS_ERR(reg)) {
ret = regulator_enable(reg); ret = regulator_enable(reg);
...@@ -291,11 +296,6 @@ static int __devinit ad5504_probe(struct spi_device *spi) ...@@ -291,11 +296,6 @@ static int __devinit ad5504_probe(struct spi_device *spi)
voltage_uv = regulator_get_voltage(reg); voltage_uv = regulator_get_voltage(reg);
} }
indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
ret = -ENOMEM;
goto error_disable_reg;
}
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
if (voltage_uv) if (voltage_uv)
...@@ -315,10 +315,6 @@ static int __devinit ad5504_probe(struct spi_device *spi) ...@@ -315,10 +315,6 @@ static int __devinit ad5504_probe(struct spi_device *spi)
indio_dev->info = &ad5504_info; indio_dev->info = &ad5504_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
if (spi->irq) { if (spi->irq) {
ret = request_threaded_irq(spi->irq, ret = request_threaded_irq(spi->irq,
NULL, NULL,
...@@ -327,15 +323,17 @@ static int __devinit ad5504_probe(struct spi_device *spi) ...@@ -327,15 +323,17 @@ static int __devinit ad5504_probe(struct spi_device *spi)
spi_get_device_id(st->spi)->name, spi_get_device_id(st->spi)->name,
indio_dev); indio_dev);
if (ret) if (ret)
goto error_unreg_iio_device; goto error_disable_reg;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_irq;
return 0; return 0;
error_unreg_iio_device: error_free_irq:
iio_device_unregister(indio_dev); free_irq(spi->irq, indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_disable_reg: error_disable_reg:
if (!IS_ERR(reg)) if (!IS_ERR(reg))
regulator_disable(reg); regulator_disable(reg);
...@@ -343,6 +341,8 @@ static int __devinit ad5504_probe(struct spi_device *spi) ...@@ -343,6 +341,8 @@ static int __devinit ad5504_probe(struct spi_device *spi)
if (!IS_ERR(reg)) if (!IS_ERR(reg))
regulator_put(reg); regulator_put(reg);
iio_free_device(indio_dev);
error_ret:
return ret; return ret;
} }
...@@ -350,17 +350,17 @@ static int __devexit ad5504_remove(struct spi_device *spi) ...@@ -350,17 +350,17 @@ static int __devexit ad5504_remove(struct spi_device *spi)
{ {
struct iio_dev *indio_dev = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad5504_state *st = iio_priv(indio_dev); struct ad5504_state *st = iio_priv(indio_dev);
struct regulator *reg = st->reg;
if (spi->irq) if (spi->irq)
free_irq(spi->irq, indio_dev); free_irq(spi->irq, indio_dev);
iio_device_unregister(indio_dev); if (!IS_ERR(st->reg)) {
regulator_disable(st->reg);
if (!IS_ERR(reg)) { regulator_put(st->reg);
regulator_disable(reg);
regulator_put(reg);
} }
iio_device_unregister(indio_dev);
return 0; return 0;
} }
......
...@@ -272,7 +272,6 @@ static int __devinit ad5624r_probe(struct spi_device *spi) ...@@ -272,7 +272,6 @@ static int __devinit ad5624r_probe(struct spi_device *spi)
return 0; return 0;
error_disable_reg: error_disable_reg:
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_disable(st->reg); regulator_disable(st->reg);
......
...@@ -393,16 +393,16 @@ static int __devinit ad5686_probe(struct spi_device *spi) ...@@ -393,16 +393,16 @@ static int __devinit ad5686_probe(struct spi_device *spi)
indio_dev->channels = st->chip_info->channel; indio_dev->channels = st->chip_info->channel;
indio_dev->num_channels = AD5686_DAC_CHANNELS; indio_dev->num_channels = AD5686_DAC_CHANNELS;
ret = iio_device_register(indio_dev);
if (ret)
goto error_disable_reg;
regdone = 1; regdone = 1;
ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0, ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
!!voltage_uv, 0); !!voltage_uv, 0);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_disable_reg;
return 0; return 0;
error_disable_reg: error_disable_reg:
...@@ -412,10 +412,7 @@ static int __devinit ad5686_probe(struct spi_device *spi) ...@@ -412,10 +412,7 @@ static int __devinit ad5686_probe(struct spi_device *spi)
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -396,6 +396,8 @@ static int __devexit ad5791_remove(struct spi_device *spi) ...@@ -396,6 +396,8 @@ static int __devexit ad5791_remove(struct spi_device *spi)
} }
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_device_unregister(indio_dev);
return 0; return 0;
} }
......
...@@ -143,7 +143,7 @@ static const struct iio_chan_spec adis16060_channels[] = { ...@@ -143,7 +143,7 @@ static const struct iio_chan_spec adis16060_channels[] = {
static int __devinit adis16060_r_probe(struct spi_device *spi) static int __devinit adis16060_r_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16060_state *st; struct adis16060_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -169,16 +169,12 @@ static int __devinit adis16060_r_probe(struct spi_device *spi) ...@@ -169,16 +169,12 @@ static int __devinit adis16060_r_probe(struct spi_device *spi)
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
regdone = 1;
adis16060_iio_dev = indio_dev; adis16060_iio_dev = indio_dev;
return 0; return 0;
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -137,7 +137,7 @@ static const struct iio_info adis16080_info = { ...@@ -137,7 +137,7 @@ static const struct iio_info adis16080_info = {
static int __devinit adis16080_probe(struct spi_device *spi) static int __devinit adis16080_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16080_state *st; struct adis16080_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -165,15 +165,10 @@ static int __devinit adis16080_probe(struct spi_device *spi) ...@@ -165,15 +165,10 @@ static int __devinit adis16080_probe(struct spi_device *spi)
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
regdone = 1;
return 0; return 0;
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -577,7 +577,7 @@ static const struct iio_info adis16260_info = { ...@@ -577,7 +577,7 @@ static const struct iio_info adis16260_info = {
static int __devinit adis16260_probe(struct spi_device *spi) static int __devinit adis16260_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16260_platform_data *pd = spi->dev.platform_data; struct adis16260_platform_data *pd = spi->dev.platform_data;
struct adis16260_state *st; struct adis16260_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -625,10 +625,6 @@ static int __devinit adis16260_probe(struct spi_device *spi) ...@@ -625,10 +625,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
indio_dev->channels, indio_dev->channels,
ARRAY_SIZE(adis16260_channels_x)); ARRAY_SIZE(adis16260_channels_x));
...@@ -654,6 +650,10 @@ static int __devinit adis16260_probe(struct spi_device *spi) ...@@ -654,6 +650,10 @@ static int __devinit adis16260_probe(struct spi_device *spi)
ret = adis16260_initial_setup(indio_dev); ret = adis16260_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -663,10 +663,7 @@ static int __devinit adis16260_probe(struct spi_device *spi) ...@@ -663,10 +663,7 @@ static int __devinit adis16260_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16260_unconfigure_ring(indio_dev); adis16260_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -283,9 +283,12 @@ struct iio_info { ...@@ -283,9 +283,12 @@ struct iio_info {
* @num_channels: [DRIVER] number of chanels specified in @channels. * @num_channels: [DRIVER] number of chanels specified in @channels.
* @channel_attr_list: [INTERN] keep track of automatically created channel * @channel_attr_list: [INTERN] keep track of automatically created channel
* attributes * attributes
* @chan_attr_group: [INTERN] group for all attrs in base directory
* @name: [DRIVER] name of the device. * @name: [DRIVER] name of the device.
* @info: [DRIVER] callbacks and constant info from driver * @info: [DRIVER] callbacks and constant info from driver
* @chrdev: [INTERN] associated character device * @chrdev: [INTERN] associated character device
* @groups: [INTERN] attribute groups
* @groupcounter: [INTERN] index of next attribute group
**/ **/
struct iio_dev { struct iio_dev {
int id; int id;
...@@ -308,9 +311,13 @@ struct iio_dev { ...@@ -308,9 +311,13 @@ struct iio_dev {
int num_channels; int num_channels;
struct list_head channel_attr_list; struct list_head channel_attr_list;
struct attribute_group chan_attr_group;
const char *name; const char *name;
const struct iio_info *info; const struct iio_info *info;
struct cdev chrdev; struct cdev chrdev;
#define IIO_MAX_GROUPS 6
const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
int groupcounter;
}; };
/** /**
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#define _IIO_CORE_H_ #define _IIO_CORE_H_
int __iio_add_chan_devattr(const char *postfix, int __iio_add_chan_devattr(const char *postfix,
const char *group,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
ssize_t (*func)(struct device *dev, ssize_t (*func)(struct device *dev,
struct device_attribute *attr, struct device_attribute *attr,
......
...@@ -675,7 +675,7 @@ static void ad5933_work(struct work_struct *work) ...@@ -675,7 +675,7 @@ static void ad5933_work(struct work_struct *work)
static int __devinit ad5933_probe(struct i2c_client *client, static int __devinit ad5933_probe(struct i2c_client *client,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret, regdone = 0, voltage_uv = 0; int ret, voltage_uv = 0;
struct ad5933_platform_data *pdata = client->dev.platform_data; struct ad5933_platform_data *pdata = client->dev.platform_data;
struct ad5933_state *st; struct ad5933_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
...@@ -727,11 +727,6 @@ static int __devinit ad5933_probe(struct i2c_client *client, ...@@ -727,11 +727,6 @@ static int __devinit ad5933_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_disable_reg; goto error_disable_reg;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring;
regdone = 1;
/* skip temp0_input, register in0_(real|imag)_raw */ /* skip temp0_input, register in0_(real|imag)_raw */
ret = iio_ring_buffer_register(indio_dev, &ad5933_channels[1], 2); ret = iio_ring_buffer_register(indio_dev, &ad5933_channels[1], 2);
if (ret) if (ret)
...@@ -745,6 +740,10 @@ static int __devinit ad5933_probe(struct i2c_client *client, ...@@ -745,6 +740,10 @@ static int __devinit ad5933_probe(struct i2c_client *client,
if (ret) if (ret)
goto error_uninitialize_ring; goto error_uninitialize_ring;
ret = iio_device_register(indio_dev);
if (ret)
goto error_uninitialize_ring;
return 0; return 0;
error_uninitialize_ring: error_uninitialize_ring:
...@@ -758,10 +757,7 @@ static int __devinit ad5933_probe(struct i2c_client *client, ...@@ -758,10 +757,7 @@ static int __devinit ad5933_probe(struct i2c_client *client,
if (!IS_ERR(st->reg)) if (!IS_ERR(st->reg))
regulator_put(st->reg); regulator_put(st->reg);
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
return ret; return ret;
} }
......
...@@ -821,7 +821,7 @@ static const struct iio_info adis16400_info = { ...@@ -821,7 +821,7 @@ static const struct iio_info adis16400_info = {
static int __devinit adis16400_probe(struct spi_device *spi) static int __devinit adis16400_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct adis16400_state *st; struct adis16400_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) { if (indio_dev == NULL) {
...@@ -848,11 +848,6 @@ static int __devinit adis16400_probe(struct spi_device *spi) ...@@ -848,11 +848,6 @@ static int __devinit adis16400_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
st->variant->channels, st->variant->channels,
st->variant->num_channels); st->variant->num_channels);
...@@ -871,6 +866,10 @@ static int __devinit adis16400_probe(struct spi_device *spi) ...@@ -871,6 +866,10 @@ static int __devinit adis16400_probe(struct spi_device *spi)
ret = adis16400_initial_setup(indio_dev); ret = adis16400_initial_setup(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_remove_trigger;
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -881,10 +880,7 @@ static int __devinit adis16400_probe(struct spi_device *spi) ...@@ -881,10 +880,7 @@ static int __devinit adis16400_probe(struct spi_device *spi)
error_unreg_ring_funcs: error_unreg_ring_funcs:
adis16400_unconfigure_ring(indio_dev); adis16400_unconfigure_ring(indio_dev);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
This diff is collapsed.
...@@ -207,10 +207,10 @@ static ssize_t iio_scan_el_ts_store(struct device *dev, ...@@ -207,10 +207,10 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan) const struct iio_chan_spec *chan)
{ {
int ret; int ret, attrcount = 0;
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
ret = __iio_add_chan_devattr("index", "scan_elements", ret = __iio_add_chan_devattr("index",
chan, chan,
&iio_show_scan_index, &iio_show_scan_index,
NULL, NULL,
...@@ -220,8 +220,8 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -220,8 +220,8 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
&ring->scan_el_dev_attr_list); &ring->scan_el_dev_attr_list);
if (ret) if (ret)
goto error_ret; goto error_ret;
attrcount++;
ret = __iio_add_chan_devattr("type", "scan_elements", ret = __iio_add_chan_devattr("type",
chan, chan,
&iio_show_fixed_type, &iio_show_fixed_type,
NULL, NULL,
...@@ -231,9 +231,9 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -231,9 +231,9 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
&ring->scan_el_dev_attr_list); &ring->scan_el_dev_attr_list);
if (ret) if (ret)
goto error_ret; goto error_ret;
attrcount++;
if (chan->type != IIO_TIMESTAMP) if (chan->type != IIO_TIMESTAMP)
ret = __iio_add_chan_devattr("en", "scan_elements", ret = __iio_add_chan_devattr("en",
chan, chan,
&iio_scan_el_show, &iio_scan_el_show,
&iio_scan_el_store, &iio_scan_el_store,
...@@ -242,7 +242,7 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -242,7 +242,7 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
&indio_dev->dev, &indio_dev->dev,
&ring->scan_el_dev_attr_list); &ring->scan_el_dev_attr_list);
else else
ret = __iio_add_chan_devattr("en", "scan_elements", ret = __iio_add_chan_devattr("en",
chan, chan,
&iio_scan_el_ts_show, &iio_scan_el_ts_show,
&iio_scan_el_ts_store, &iio_scan_el_ts_store,
...@@ -250,6 +250,8 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -250,6 +250,8 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
0, 0,
&indio_dev->dev, &indio_dev->dev,
&ring->scan_el_dev_attr_list); &ring->scan_el_dev_attr_list);
attrcount++;
ret = attrcount;
error_ret: error_ret:
return ret; return ret;
} }
...@@ -257,66 +259,40 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev, ...@@ -257,66 +259,40 @@ static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
static void iio_ring_remove_and_free_scan_dev_attr(struct iio_dev *indio_dev, static void iio_ring_remove_and_free_scan_dev_attr(struct iio_dev *indio_dev,
struct iio_dev_attr *p) struct iio_dev_attr *p)
{ {
sysfs_remove_file_from_group(&indio_dev->dev.kobj,
&p->dev_attr.attr, "scan_elements");
kfree(p->dev_attr.attr.name); kfree(p->dev_attr.attr.name);
kfree(p); kfree(p);
} }
static struct attribute *iio_scan_el_dummy_attrs[] = {
NULL
};
static struct attribute_group iio_scan_el_dummy_group = {
.name = "scan_elements",
.attrs = iio_scan_el_dummy_attrs
};
static void __iio_ring_attr_cleanup(struct iio_dev *indio_dev) static void __iio_ring_attr_cleanup(struct iio_dev *indio_dev)
{ {
struct iio_dev_attr *p, *n; struct iio_dev_attr *p, *n;
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
int anydynamic = !list_empty(&ring->scan_el_dev_attr_list);
list_for_each_entry_safe(p, n, list_for_each_entry_safe(p, n,
&ring->scan_el_dev_attr_list, l) &ring->scan_el_dev_attr_list, l)
iio_ring_remove_and_free_scan_dev_attr(indio_dev, p); iio_ring_remove_and_free_scan_dev_attr(indio_dev, p);
if (ring->scan_el_attrs)
sysfs_remove_group(&indio_dev->dev.kobj,
ring->scan_el_attrs);
else if (anydynamic)
sysfs_remove_group(&indio_dev->dev.kobj,
&iio_scan_el_dummy_group);
} }
static const char * const iio_scan_elements_group_name = "scan_elements";
int iio_ring_buffer_register(struct iio_dev *indio_dev, int iio_ring_buffer_register(struct iio_dev *indio_dev,
const struct iio_chan_spec *channels, const struct iio_chan_spec *channels,
int num_channels) int num_channels)
{ {
struct iio_dev_attr *p;
struct attribute **attr;
struct iio_ring_buffer *ring = indio_dev->ring; struct iio_ring_buffer *ring = indio_dev->ring;
int ret, i; int ret, i, attrn, attrcount, attrcount_orig = 0;
if (ring->scan_el_attrs) { if (ring->attrs)
ret = sysfs_create_group(&indio_dev->dev.kobj, indio_dev->groups[indio_dev->groupcounter++] = ring->attrs;
ring->scan_el_attrs);
if (ret) {
dev_err(&indio_dev->dev,
"Failed to add sysfs scan elements\n");
goto error_ret;
}
} else if (channels) {
ret = sysfs_create_group(&indio_dev->dev.kobj,
&iio_scan_el_dummy_group);
if (ret)
goto error_ret;
}
if (ring->attrs) {
ret = sysfs_create_group(&indio_dev->dev.kobj,
ring->attrs);
if (ret)
goto error_cleanup_dynamic;
}
if (ring->scan_el_attrs != NULL) {
attr = ring->scan_el_attrs->attrs;
while (*attr++ != NULL)
attrcount_orig++;
}
attrcount = attrcount_orig;
INIT_LIST_HEAD(&ring->scan_el_dev_attr_list); INIT_LIST_HEAD(&ring->scan_el_dev_attr_list);
if (channels) { if (channels) {
/* new magic */ /* new magic */
...@@ -330,7 +306,8 @@ int iio_ring_buffer_register(struct iio_dev *indio_dev, ...@@ -330,7 +306,8 @@ int iio_ring_buffer_register(struct iio_dev *indio_dev,
ret = iio_ring_add_channel_sysfs(indio_dev, ret = iio_ring_add_channel_sysfs(indio_dev,
&channels[i]); &channels[i]);
if (ret < 0) if (ret < 0)
goto error_cleanup_group; goto error_cleanup_dynamic;
attrcount += ret;
} }
if (indio_dev->masklength && ring->scan_mask == NULL) { if (indio_dev->masklength && ring->scan_mask == NULL) {
ring->scan_mask ring->scan_mask
...@@ -339,18 +316,36 @@ int iio_ring_buffer_register(struct iio_dev *indio_dev, ...@@ -339,18 +316,36 @@ int iio_ring_buffer_register(struct iio_dev *indio_dev,
GFP_KERNEL); GFP_KERNEL);
if (ring->scan_mask == NULL) { if (ring->scan_mask == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_cleanup_group; goto error_cleanup_dynamic;
} }
} }
} }
ring->scan_el_group.name = iio_scan_elements_group_name;
ring->scan_el_group.attrs
= kzalloc(sizeof(ring->scan_el_group.attrs[0])*(attrcount + 1),
GFP_KERNEL);
if (ring->scan_el_group.attrs == NULL) {
ret = -ENOMEM;
goto error_free_scan_mask;
}
if (ring->scan_el_attrs)
memcpy(ring->scan_el_group.attrs, ring->scan_el_attrs,
sizeof(ring->scan_el_group.attrs[0])*attrcount_orig);
attrn = attrcount_orig;
list_for_each_entry(p, &ring->scan_el_dev_attr_list, l)
ring->scan_el_group.attrs[attrn++] = &p->dev_attr.attr;
indio_dev->groups[indio_dev->groupcounter++] = &ring->scan_el_group;
return 0; return 0;
error_cleanup_group:
if (ring->attrs) error_free_scan_mask:
sysfs_remove_group(&indio_dev->dev.kobj, ring->attrs); kfree(ring->scan_mask);
error_cleanup_dynamic: error_cleanup_dynamic:
__iio_ring_attr_cleanup(indio_dev); __iio_ring_attr_cleanup(indio_dev);
error_ret:
return ret; return ret;
} }
EXPORT_SYMBOL(iio_ring_buffer_register); EXPORT_SYMBOL(iio_ring_buffer_register);
...@@ -358,9 +353,7 @@ EXPORT_SYMBOL(iio_ring_buffer_register); ...@@ -358,9 +353,7 @@ EXPORT_SYMBOL(iio_ring_buffer_register);
void iio_ring_buffer_unregister(struct iio_dev *indio_dev) void iio_ring_buffer_unregister(struct iio_dev *indio_dev)
{ {
kfree(indio_dev->ring->scan_mask); kfree(indio_dev->ring->scan_mask);
if (indio_dev->ring->attrs) kfree(indio_dev->ring->scan_el_group.attrs);
sysfs_remove_group(&indio_dev->dev.kobj,
indio_dev->ring->attrs);
__iio_ring_attr_cleanup(indio_dev); __iio_ring_attr_cleanup(indio_dev);
} }
EXPORT_SYMBOL(iio_ring_buffer_unregister); EXPORT_SYMBOL(iio_ring_buffer_unregister);
......
...@@ -475,8 +475,10 @@ EXPORT_SYMBOL(iio_free_trigger); ...@@ -475,8 +475,10 @@ EXPORT_SYMBOL(iio_free_trigger);
int iio_device_register_trigger_consumer(struct iio_dev *dev_info) int iio_device_register_trigger_consumer(struct iio_dev *dev_info)
{ {
return sysfs_create_group(&dev_info->dev.kobj, dev_info->groups[dev_info->groupcounter++] =
&iio_trigger_consumer_attr_group); &iio_trigger_consumer_attr_group;
return 0;
} }
void iio_device_unregister_trigger_consumer(struct iio_dev *dev_info) void iio_device_unregister_trigger_consumer(struct iio_dev *dev_info)
...@@ -484,8 +486,6 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *dev_info) ...@@ -484,8 +486,6 @@ void iio_device_unregister_trigger_consumer(struct iio_dev *dev_info)
/* Clean up and associated but not attached triggers references */ /* Clean up and associated but not attached triggers references */
if (dev_info->trig) if (dev_info->trig)
iio_put_trigger(dev_info->trig); iio_put_trigger(dev_info->trig);
sysfs_remove_group(&dev_info->dev.kobj,
&iio_trigger_consumer_attr_group);
} }
int iio_triggered_ring_postenable(struct iio_dev *indio_dev) int iio_triggered_ring_postenable(struct iio_dev *indio_dev)
......
...@@ -751,9 +751,6 @@ static int __devinit tsl2563_probe(struct i2c_client *client, ...@@ -751,9 +751,6 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
indio_dev->info = &tsl2563_info; indio_dev->info = &tsl2563_info;
else else
indio_dev->info = &tsl2563_info_no_irq; indio_dev->info = &tsl2563_info_no_irq;
ret = iio_device_register(indio_dev);
if (ret)
goto fail1;
if (client->irq) { if (client->irq) {
ret = request_threaded_irq(client->irq, ret = request_threaded_irq(client->irq,
NULL, NULL,
...@@ -772,12 +769,16 @@ static int __devinit tsl2563_probe(struct i2c_client *client, ...@@ -772,12 +769,16 @@ static int __devinit tsl2563_probe(struct i2c_client *client,
/* The interrupt cannot yet be enabled so this is fine without lock */ /* The interrupt cannot yet be enabled so this is fine without lock */
schedule_delayed_work(&chip->poweroff_work, 5 * HZ); schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
ret = iio_device_register(indio_dev);
if (ret)
goto fail3;
return 0; return 0;
fail3: fail3:
if (client->irq) if (client->irq)
free_irq(client->irq, indio_dev); free_irq(client->irq, indio_dev);
fail2: fail2:
iio_device_unregister(indio_dev); iio_free_device(indio_dev);
fail1: fail1:
kfree(chip); kfree(chip);
return err; return err;
......
...@@ -513,7 +513,7 @@ static const struct iio_info ade7753_info = { ...@@ -513,7 +513,7 @@ static const struct iio_info ade7753_info = {
static int __devinit ade7753_probe(struct spi_device *spi) static int __devinit ade7753_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct ade7753_state *st; struct ade7753_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -535,22 +535,19 @@ static int __devinit ade7753_probe(struct spi_device *spi) ...@@ -535,22 +535,19 @@ static int __devinit ade7753_probe(struct spi_device *spi)
indio_dev->info = &ade7753_info; indio_dev->info = &ade7753_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev); /* Get the device into a sane initial state */
ret = ade7753_initial_setup(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
regdone = 1;
/* Get the device into a sane initial state */ ret = iio_device_register(indio_dev);
ret = ade7753_initial_setup(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
return 0; return 0;
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
......
...@@ -536,7 +536,7 @@ static const struct iio_info ade7754_info = { ...@@ -536,7 +536,7 @@ static const struct iio_info ade7754_info = {
static int __devinit ade7754_probe(struct spi_device *spi) static int __devinit ade7754_probe(struct spi_device *spi)
{ {
int ret, regdone = 0; int ret;
struct ade7754_state *st; struct ade7754_state *st;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
...@@ -558,22 +558,18 @@ static int __devinit ade7754_probe(struct spi_device *spi) ...@@ -558,22 +558,18 @@ static int __devinit ade7754_probe(struct spi_device *spi)
indio_dev->info = &ade7754_info; indio_dev->info = &ade7754_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
regdone = 1;
/* Get the device into a sane initial state */ /* Get the device into a sane initial state */
ret = ade7754_initial_setup(indio_dev); ret = ade7754_initial_setup(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
return 0; return 0;
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
......
...@@ -733,7 +733,7 @@ static const struct iio_info ade7758_info = { ...@@ -733,7 +733,7 @@ static const struct iio_info ade7758_info = {
static int __devinit ade7758_probe(struct spi_device *spi) static int __devinit ade7758_probe(struct spi_device *spi)
{ {
int i, ret, regdone = 0; int i, ret;
struct ade7758_state *st; struct ade7758_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st)); struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
...@@ -775,11 +775,6 @@ static int __devinit ade7758_probe(struct spi_device *spi) ...@@ -775,11 +775,6 @@ static int __devinit ade7758_probe(struct spi_device *spi)
if (ret) if (ret)
goto error_free_tx; goto error_free_tx;
ret = iio_device_register(indio_dev);
if (ret)
goto error_unreg_ring_funcs;
regdone = 1;
ret = iio_ring_buffer_register(indio_dev, ret = iio_ring_buffer_register(indio_dev,
&ade7758_channels[0], &ade7758_channels[0],
ARRAY_SIZE(ade7758_channels)); ARRAY_SIZE(ade7758_channels));
...@@ -796,9 +791,13 @@ static int __devinit ade7758_probe(struct spi_device *spi) ...@@ -796,9 +791,13 @@ static int __devinit ade7758_probe(struct spi_device *spi)
if (spi->irq) { if (spi->irq) {
ret = ade7758_probe_trigger(indio_dev); ret = ade7758_probe_trigger(indio_dev);
if (ret) if (ret)
goto error_remove_trigger; goto error_uninitialize_ring;
} }
ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0; return 0;
error_remove_trigger: error_remove_trigger:
...@@ -813,10 +812,7 @@ static int __devinit ade7758_probe(struct spi_device *spi) ...@@ -813,10 +812,7 @@ static int __devinit ade7758_probe(struct spi_device *spi)
error_free_rx: error_free_rx:
kfree(st->rx); kfree(st->rx);
error_free_dev: error_free_dev:
if (regdone) iio_free_device(indio_dev);
iio_device_unregister(indio_dev);
else
iio_free_device(indio_dev);
error_ret: error_ret:
return ret; return ret;
} }
......
...@@ -480,19 +480,17 @@ static int __devinit ade7759_probe(struct spi_device *spi) ...@@ -480,19 +480,17 @@ static int __devinit ade7759_probe(struct spi_device *spi)
indio_dev->info = &ade7759_info; indio_dev->info = &ade7759_info;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
ret = iio_device_register(indio_dev); /* Get the device into a sane initial state */
ret = ade7759_initial_setup(indio_dev);
if (ret) if (ret)
goto error_free_dev; goto error_free_dev;
/* Get the device into a sane initial state */ ret = iio_device_register(indio_dev);
ret = ade7759_initial_setup(indio_dev);
if (ret) if (ret)
goto error_unreg_dev; goto error_free_dev;
return 0;
return 0;
error_unreg_dev:
iio_device_unregister(indio_dev);
error_free_dev: error_free_dev:
iio_free_device(indio_dev); iio_free_device(indio_dev);
error_ret: error_ret:
......
...@@ -784,6 +784,7 @@ static int __devexit ad2s1210_remove(struct spi_device *spi) ...@@ -784,6 +784,7 @@ static int __devexit ad2s1210_remove(struct spi_device *spi)
{ {
struct iio_dev *indio_dev = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad2s1210_state *st = iio_priv(indio_dev); struct ad2s1210_state *st = iio_priv(indio_dev);
ad2s1210_free_gpios(st); ad2s1210_free_gpios(st);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#ifndef _IIO_RING_GENERIC_H_ #ifndef _IIO_RING_GENERIC_H_
#define _IIO_RING_GENERIC_H_ #define _IIO_RING_GENERIC_H_
#include <linux/sysfs.h>
#include "iio.h" #include "iio.h"
#include "chrdev.h" #include "chrdev.h"
...@@ -109,7 +110,7 @@ struct iio_ring_buffer { ...@@ -109,7 +110,7 @@ struct iio_ring_buffer {
const struct iio_ring_access_funcs *access; const struct iio_ring_access_funcs *access;
const struct iio_ring_setup_ops *setup_ops; const struct iio_ring_setup_ops *setup_ops;
struct list_head scan_el_dev_attr_list; struct list_head scan_el_dev_attr_list;
struct attribute_group scan_el_group;
wait_queue_head_t pollq; wait_queue_head_t pollq;
bool stufftoread; bool stufftoread;
unsigned long flags; unsigned long flags;
......
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