static int __devinit adis16201_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16201_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
adis16201_channels,
ARRAY_SIZE(adis16201_channels));
ret = adis16201_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+
+ ret = iio_device_register(indio_dev);
+ if (ret < 0)
+ goto error_remove_trigger;
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16201_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit adis16203_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct iio_dev *indio_dev;
struct adis16203_state *st;
if (ret)
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,
adis16203_channels,
ARRAY_SIZE(adis16203_channels));
ret = adis16203_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16203_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit adis16204_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16204_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
adis16204_channels,
ARRAY_SIZE(adis16204_channels));
ret = adis16204_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16204_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit adis16209_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16209_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
adis16209_channels,
ARRAY_SIZE(adis16209_channels));
ret = adis16209_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16209_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit adis16240_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16240_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
adis16240_channels,
ARRAY_SIZE(adis16240_channels));
/* Get the device into a sane initial state */
ret = adis16240_initial_setup(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+ ret = iio_device_register(indio_dev);
if (ret)
goto error_remove_trigger;
return 0;
error_unreg_ring_funcs:
adis16240_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit lis3l02dq_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct lis3l02dq_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
lis3l02dq_channels,
ARRAY_SIZE(lis3l02dq_channels));
ret = lis3l02dq_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
lis3l02dq_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
iio_free_device(indio_dev);
error_ret:
return ret;
lis3l02dq_remove_trigger(indio_dev);
iio_ring_buffer_unregister(indio_dev);
lis3l02dq_unconfigure_ring(indio_dev);
- iio_device_unregister(indio_dev);
- return 0;
+ iio_device_unregister(indio_dev);
err_ret:
return ret;
static int __devinit ad7150_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- int ret = 0, regdone = 0;
+ int ret;
struct ad7150_chip_info *chip;
struct iio_dev *indio_dev;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
- regdone = 1;
-
if (client->irq) {
ret = request_threaded_irq(client->irq,
NULL,
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);
return 0;
+error_free_irq:
+ if (client->irq)
+ free_irq(client->irq, indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
indio_dev->info = &ad7291_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
if (client->irq > 0) {
ret = request_threaded_irq(client->irq,
NULL,
id->name,
indio_dev);
if (ret)
- goto error_unreg_dev;
+ goto error_free_dev;
/* set irq polarity low level */
chip->command |= AD7291_ALART_POLARITY;
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",
id->name);
error_unreg_irq:
free_irq(client->irq, indio_dev);
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
{
struct ad7298_platform_data *pdata = spi->dev.platform_data;
struct ad7298_state *st;
- int ret, regdone = 0;
+ int ret;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL)
if (ret)
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,
&ad7298_channels[1], /* skip temp0 */
ARRAY_SIZE(ad7298_channels) - 1);
if (ret)
goto error_cleanup_ring;
+ 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:
ad7298_ring_cleanup(indio_dev);
error_disable_reg:
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
-
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
struct ad7476_state *st;
struct iio_dev *indio_dev;
int ret, voltage_uv = 0;
- bool reg_done = false;
indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
if (ret)
goto error_disable_reg;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_disable_reg;
-
ret = iio_ring_buffer_register(indio_dev,
st->chip_info->channel,
ARRAY_SIZE(st->chip_info->channel));
if (ret)
goto error_cleanup_ring;
+
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_ring_unregister;
return 0;
+error_ring_unregister:
+ iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring:
ad7476_ring_cleanup(indio_dev);
- iio_device_unregister(indio_dev);
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (!reg_done)
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
+
error_ret:
return ret;
}
{
struct ad7606_platform_data *pdata = dev->platform_data;
struct ad7606_state *st;
- int ret, regdone = 0;
+ int ret;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
if (ret)
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,
indio_dev->channels,
indio_dev->num_channels);
if (ret)
goto error_cleanup_ring;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_unregister_ring;
return indio_dev;
+error_unregister_ring:
+ iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring:
ad7606_ring_cleanup(indio_dev);
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ERR_PTR(ret);
}
static int __devinit ad774x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- int ret = 0, regdone = 0;
+ int ret;
struct ad774x_chip_info *chip;
struct iio_dev *indio_dev;
indio_dev->info = &ad774x_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
- regdone = 1;
-
if (client->irq) {
ret = request_threaded_irq(client->irq,
NULL,
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);
return 0;
+error_free_irq:
+ free_irq(client->irq, indio_dev);
error_free_dev:
- if (regdone)
- free_irq(client->irq, indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
struct ad7793_platform_data *pdata = spi->dev.platform_data;
struct ad7793_state *st;
struct iio_dev *indio_dev;
- int ret, i, voltage_uv = 0, regdone = 0;
+ int ret, i, voltage_uv = 0;
if (!pdata) {
dev_err(&spi->dev, "no platform data?\n");
if (ret)
goto error_disable_reg;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_unreg_ring;
- regdone = 1;
-
ret = ad7793_probe_trigger(indio_dev);
if (ret)
goto error_unreg_ring;
if (ret)
goto error_uninitialize_ring;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_uninitialize_ring;
+
return 0;
error_uninitialize_ring:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
indio_dev->info = &ad7816_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_gpio;
-
if (spi_dev->irq) {
/* Only low trigger is supported in ad7816/7/8 */
ret = request_threaded_irq(spi_dev->irq,
indio_dev->name,
indio_dev);
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",
indio_dev->name);
return 0;
-
-error_unreg_dev:
- iio_device_unregister(indio_dev);
+error_free_irq:
+ free_irq(spi_dev->irq, indio_dev);
error_free_gpio:
gpio_free(chip->busy_pin);
error_free_gpio_convert:
{
struct ad7887_platform_data *pdata = spi->dev.platform_data;
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));
if (indio_dev == NULL)
if (ret)
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,
indio_dev->channels,
indio_dev->num_channels);
if (ret)
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:
ad7887_ring_cleanup(indio_dev);
error_disable_reg:
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
static int __devinit ad799x_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- int ret, regdone = 0;
+ int ret;
struct ad799x_platform_data *pdata = client->dev.platform_data;
struct ad799x_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (ret)
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,
indio_dev->channels,
indio_dev->num_channels);
if (ret)
goto error_cleanup_ring;
}
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_free_irq;
return 0;
+error_free_irq:
+ free_irq(client->irq, indio_dev);
error_cleanup_ring:
ad799x_ring_cleanup(indio_dev);
error_disable_reg:
error_put_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
indio_dev->info = &adt7310_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
/* CT critcal temperature event. line 0 */
if (spi_dev->irq) {
if (adt7310_platform_data[2])
indio_dev->name,
indio_dev);
if (ret)
- goto error_unreg_dev;
+ goto error_free_dev;
}
/* INT bound temperature alarm event. line 1 */
}
}
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_unreg_int_irq;
+
dev_info(&spi_dev->dev, "%s temperature sensor registered.\n",
indio_dev->name);
free_irq(adt7310_platform_data[0], indio_dev);
error_unreg_ct_irq:
free_irq(spi_dev->irq, indio_dev);
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
indio_dev->info = &adt7410_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
/* CT critcal temperature event. line 0 */
if (client->irq) {
ret = request_threaded_irq(client->irq,
id->name,
indio_dev);
if (ret)
- goto error_unreg_dev;
+ goto error_free_dev;
}
/* INT bound temperature alarm event. line 1 */
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",
id->name);
free_irq(adt7410_platform_data[0], indio_dev);
error_unreg_ct_irq:
free_irq(client->irq, indio_dev);
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
indio_dev->info = &adt75_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
if (client->irq > 0) {
ret = request_threaded_irq(client->irq,
NULL,
indio_dev->name,
indio_dev);
if (ret)
- goto error_unreg_dev;
+ goto error_free_dev;
ret = adt75_i2c_read(indio_dev, ADT75_CONFIG, &chip->config);
if (ret) {
}
}
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_unreg_irq;
+
dev_info(&client->dev, "%s temperature sensor registered.\n",
indio_dev->name);
return 0;
error_unreg_irq:
free_irq(client->irq, indio_dev);
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
static int __devinit max1363_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
- int ret, i, regdone = 0;
+ int ret, i;
struct max1363_state *st;
struct iio_dev *indio_dev;
struct regulator *reg;
if (ret)
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,
st->chip_info->channels,
st->chip_info->num_channels);
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:
iio_ring_buffer_unregister(indio_dev);
error_cleanup_ring:
error_free_available_scan_masks:
kfree(indio_dev->available_scan_masks);
error_free_device:
- if (!regdone)
- iio_free_device(indio_dev);
- else
- iio_device_unregister(indio_dev);
+ iio_free_device(indio_dev);
error_disable_reg:
regulator_disable(reg);
error_put_reg:
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
if (chip->bus.irq > 0) {
if (adt7316_platform_data[0])
chip->bus.irq_flags = adt7316_platform_data[0];
indio_dev->name,
indio_dev);
if (ret)
- goto error_unreg_dev;
+ goto error_free_dev;
if (chip->bus.irq_flags & IRQF_TRIGGER_HIGH)
chip->config1 |= ADT7316_INT_POLARITY;
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",
indio_dev->name);
error_unreg_irq:
free_irq(chip->bus.irq, indio_dev);
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct adt7316_chip_info *chip = iio_priv(indio_dev);
- dev_set_drvdata(dev, NULL);
if (chip->bus.irq)
free_irq(chip->bus.irq, indio_dev);
iio_device_unregister(indio_dev);
struct regulator *reg;
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");
if (!IS_ERR(reg)) {
ret = regulator_enable(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);
st = iio_priv(indio_dev);
if (voltage_uv)
indio_dev->info = &ad5504_info;
indio_dev->modes = INDIO_DIRECT_MODE;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_free_dev;
-
if (spi->irq) {
ret = request_threaded_irq(spi->irq,
NULL,
spi_get_device_id(st->spi)->name,
indio_dev);
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;
-error_unreg_iio_device:
- iio_device_unregister(indio_dev);
-error_free_dev:
- iio_free_device(indio_dev);
+error_free_irq:
+ free_irq(spi->irq, indio_dev);
error_disable_reg:
if (!IS_ERR(reg))
regulator_disable(reg);
if (!IS_ERR(reg))
regulator_put(reg);
+ iio_free_device(indio_dev);
+error_ret:
return ret;
}
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad5504_state *st = iio_priv(indio_dev);
- struct regulator *reg = st->reg;
+
if (spi->irq)
free_irq(spi->irq, indio_dev);
- iio_device_unregister(indio_dev);
-
- if (!IS_ERR(reg)) {
- regulator_disable(reg);
- regulator_put(reg);
+ if (!IS_ERR(st->reg)) {
+ regulator_disable(st->reg);
+ regulator_put(st->reg);
}
+ iio_device_unregister(indio_dev);
+
return 0;
}
return 0;
-
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
indio_dev->channels = st->chip_info->channel;
indio_dev->num_channels = AD5686_DAC_CHANNELS;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto error_disable_reg;
-
regdone = 1;
ret = ad5686_spi_write(st, AD5686_CMD_INTERNAL_REFER_SETUP, 0,
!!voltage_uv, 0);
if (ret)
goto error_disable_reg;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_disable_reg;
+
return 0;
error_disable_reg:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
}
iio_device_unregister(indio_dev);
+ iio_device_unregister(indio_dev);
+
return 0;
}
static int __devinit adis16060_r_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16060_state *st;
struct iio_dev *indio_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
- regdone = 1;
adis16060_iio_dev = indio_dev;
return 0;
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
static int __devinit adis16080_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16080_state *st;
struct iio_dev *indio_dev;
ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
- regdone = 1;
-
return 0;
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
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_state *st;
struct iio_dev *indio_dev;
if (ret)
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,
indio_dev->channels,
ARRAY_SIZE(adis16260_channels_x));
ret = adis16260_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16260_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
* @num_channels: [DRIVER] number of chanels specified in @channels.
* @channel_attr_list: [INTERN] keep track of automatically created channel
* attributes
+ * @chan_attr_group: [INTERN] group for all attrs in base directory
* @name: [DRIVER] name of the device.
* @info: [DRIVER] callbacks and constant info from driver
* @chrdev: [INTERN] associated character device
+ * @groups: [INTERN] attribute groups
+ * @groupcounter: [INTERN] index of next attribute group
**/
struct iio_dev {
int id;
int num_channels;
struct list_head channel_attr_list;
+ struct attribute_group chan_attr_group;
const char *name;
const struct iio_info *info;
struct cdev chrdev;
+#define IIO_MAX_GROUPS 6
+ const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
+ int groupcounter;
};
/**
#define _IIO_CORE_H_
int __iio_add_chan_devattr(const char *postfix,
- const char *group,
struct iio_chan_spec const *chan,
ssize_t (*func)(struct device *dev,
struct device_attribute *attr,
static int __devinit ad5933_probe(struct i2c_client *client,
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_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (ret)
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 */
ret = iio_ring_buffer_register(indio_dev, &ad5933_channels[1], 2);
if (ret)
if (ret)
goto error_uninitialize_ring;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_uninitialize_ring;
+
return 0;
error_uninitialize_ring:
if (!IS_ERR(st->reg))
regulator_put(st->reg);
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
return ret;
}
static int __devinit adis16400_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct adis16400_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (indio_dev == NULL) {
if (ret)
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,
st->variant->channels,
st->variant->num_channels);
ret = adis16400_initial_setup(indio_dev);
if (ret)
goto error_remove_trigger;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_unreg_ring_funcs:
adis16400_unconfigure_ring(indio_dev);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
int current_events;
struct list_head dev_attr_list;
unsigned long flags;
+ struct attribute_group group;
};
int iio_push_event(struct iio_dev *dev_info, u64 ev_code, s64 timestamp)
}
int __iio_add_chan_devattr(const char *postfix,
- const char *group,
struct iio_chan_spec const *chan,
ssize_t (*readfunc)(struct device *dev,
struct device_attribute *attr,
ret = -EBUSY;
goto error_device_attr_deinit;
}
-
- ret = sysfs_add_file_to_group(&dev->kobj,
- &iio_attr->dev_attr.attr, group);
- if (ret < 0)
- goto error_device_attr_deinit;
-
list_add(&iio_attr->l, attr_list);
return 0;
static int iio_device_add_channel_sysfs(struct iio_dev *dev_info,
struct iio_chan_spec const *chan)
{
- int ret, i;
+ int ret, i, attrcount = 0;
if (chan->channel < 0)
return 0;
ret = __iio_add_chan_devattr(iio_data_type_name[chan->processed_val],
- NULL, chan,
+ chan,
&iio_read_channel_info,
(chan->output ?
&iio_write_channel_info : NULL),
&dev_info->channel_attr_list);
if (ret)
goto error_ret;
+ attrcount++;
for_each_set_bit(i, &chan->info_mask, sizeof(long)*8) {
ret = __iio_add_chan_devattr(iio_chan_info_postfix[i/2],
- NULL, chan,
+ chan,
&iio_read_channel_info,
&iio_write_channel_info,
(1 << i),
}
if (ret < 0)
goto error_ret;
+ attrcount++;
}
+ ret = attrcount;
error_ret:
return ret;
}
static void iio_device_remove_and_free_read_attr(struct iio_dev *dev_info,
struct iio_dev_attr *p)
{
- sysfs_remove_file_from_group(&dev_info->dev.kobj,
- &p->dev_attr.attr, NULL);
kfree(p->dev_attr.attr.name);
kfree(p);
}
static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
-static struct attribute *iio_base_dummy_attrs[] = {
- NULL
-};
-static struct attribute_group iio_base_dummy_group = {
- .attrs = iio_base_dummy_attrs,
-};
-
static int iio_device_register_sysfs(struct iio_dev *dev_info)
{
- int i, ret = 0;
+ int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
struct iio_dev_attr *p, *n;
+ struct attribute **attr;
- if (dev_info->info->attrs)
- ret = sysfs_create_group(&dev_info->dev.kobj,
- dev_info->info->attrs);
- else
- ret = sysfs_create_group(&dev_info->dev.kobj,
- &iio_base_dummy_group);
-
- if (ret) {
- dev_err(dev_info->dev.parent,
- "Failed to register sysfs hooks\n");
- goto error_ret;
+ /* First count elements in any existing group */
+ if (dev_info->info->attrs) {
+ attr = dev_info->info->attrs->attrs;
+ while (*attr++ != NULL)
+ attrcount_orig++;
}
-
+ attrcount = attrcount_orig;
/*
* New channel registration method - relies on the fact a group does
* not need to be initialized if it is name is NULL.
->channels[i]);
if (ret < 0)
goto error_clear_attrs;
+ attrcount += ret;
}
- if (dev_info->name) {
- ret = sysfs_add_file_to_group(&dev_info->dev.kobj,
- &dev_attr_name.attr,
- NULL);
- if (ret)
- goto error_clear_attrs;
+
+ if (dev_info->name)
+ attrcount++;
+
+ dev_info->chan_attr_group.attrs
+ = kzalloc(sizeof(dev_info->chan_attr_group.attrs[0])*
+ (attrcount + 1),
+ GFP_KERNEL);
+ if (dev_info->chan_attr_group.attrs == NULL) {
+ ret = -ENOMEM;
+ goto error_clear_attrs;
}
+ /* Copy across original attributes */
+ if (dev_info->info->attrs)
+ memcpy(dev_info->chan_attr_group.attrs,
+ dev_info->info->attrs->attrs,
+ sizeof(dev_info->chan_attr_group.attrs[0])
+ *attrcount_orig);
+ attrn = attrcount_orig;
+ /* Add all elements from the list. */
+ list_for_each_entry(p, &dev_info->channel_attr_list, l)
+ dev_info->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
+ if (dev_info->name)
+ dev_info->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
+
+ dev_info->groups[dev_info->groupcounter++] =
+ &dev_info->chan_attr_group;
+
return 0;
error_clear_attrs:
list_del(&p->l);
iio_device_remove_and_free_read_attr(dev_info, p);
}
- if (dev_info->info->attrs)
- sysfs_remove_group(&dev_info->dev.kobj, dev_info->info->attrs);
- else
- sysfs_remove_group(&dev_info->dev.kobj, &iio_base_dummy_group);
-error_ret:
- return ret;
+ return ret;
}
static void iio_device_unregister_sysfs(struct iio_dev *dev_info)
{
struct iio_dev_attr *p, *n;
- if (dev_info->name)
- sysfs_remove_file_from_group(&dev_info->dev.kobj,
- &dev_attr_name.attr,
- NULL);
+
list_for_each_entry_safe(p, n, &dev_info->channel_attr_list, l) {
list_del(&p->l);
iio_device_remove_and_free_read_attr(dev_info, p);
}
-
- if (dev_info->info->attrs)
- sysfs_remove_group(&dev_info->dev.kobj, dev_info->info->attrs);
- else
- sysfs_remove_group(&dev_info->dev.kobj, &iio_base_dummy_group);
+ kfree(dev_info->chan_attr_group.attrs);
}
static const char * const iio_ev_type_text[] = {
static int iio_device_add_event_sysfs(struct iio_dev *dev_info,
struct iio_chan_spec const *chan)
{
- int ret = 0, i, mask = 0;
+ int ret = 0, i, mask = 0, attrcount = 0;
char *postfix;
if (!chan->event_mask)
return 0;
i%IIO_EV_TYPE_MAX);
ret = __iio_add_chan_devattr(postfix,
- "events",
chan,
&iio_ev_state_show,
iio_ev_state_store,
kfree(postfix);
if (ret)
goto error_ret;
-
+ attrcount++;
postfix = kasprintf(GFP_KERNEL, "%s_%s_value",
iio_ev_type_text[i/IIO_EV_TYPE_MAX],
iio_ev_dir_text[i%IIO_EV_TYPE_MAX]);
ret = -ENOMEM;
goto error_ret;
}
- ret = __iio_add_chan_devattr(postfix, "events", chan,
+ ret = __iio_add_chan_devattr(postfix, chan,
iio_ev_value_show,
iio_ev_value_store,
mask,
kfree(postfix);
if (ret)
goto error_ret;
-
+ attrcount++;
}
-
+ ret = attrcount;
error_ret:
return ret;
}
list_for_each_entry_safe(p, n,
&dev_info->event_interface->
dev_attr_list, l) {
- sysfs_remove_file_from_group(&dev_info->dev.kobj,
- &p->dev_attr.attr,
- NULL);
kfree(p->dev_attr.attr.name);
kfree(p);
}
static inline int __iio_add_event_config_attrs(struct iio_dev *dev_info)
{
- int j;
- int ret;
+ int j, ret, attrcount = 0;
INIT_LIST_HEAD(&dev_info->event_interface->dev_attr_list);
/* Dynically created from the channels array */
for (j = 0; j < dev_info->num_channels; j++) {
ret = iio_device_add_event_sysfs(dev_info,
&dev_info->channels[j]);
- if (ret)
+ if (ret < 0)
goto error_clear_attrs;
+ attrcount += ret;
}
- return 0;
+ return attrcount;
error_clear_attrs:
__iio_remove_event_config_attrs(dev_info);
return ret;
}
-static struct attribute *iio_events_dummy_attrs[] = {
- NULL
-};
-
-static struct attribute_group iio_events_dummy_group = {
- .name = "events",
- .attrs = iio_events_dummy_attrs
-};
-
static bool iio_check_for_dynamic_events(struct iio_dev *dev_info)
{
int j;
init_waitqueue_head(&ev_int->wait);
}
+static const char *iio_event_group_name = "events";
static int iio_device_register_eventset(struct iio_dev *dev_info)
{
- int ret = 0;
+ struct iio_dev_attr *p;
+ int ret = 0, attrcount_orig = 0, attrcount, attrn;
+ struct attribute **attr;
if (!(dev_info->info->event_attrs ||
iio_check_for_dynamic_events(dev_info)))
}
iio_setup_ev_int(dev_info->event_interface);
- if (dev_info->info->event_attrs != NULL)
- ret = sysfs_create_group(&dev_info->dev.kobj,
- dev_info->info->event_attrs);
- else
- ret = sysfs_create_group(&dev_info->dev.kobj,
- &iio_events_dummy_group);
- if (ret) {
- dev_err(&dev_info->dev,
- "Failed to register sysfs for event attrs");
- goto error_free_setup_event_lines;
+ if (dev_info->info->event_attrs != NULL) {
+ attr = dev_info->info->event_attrs->attrs;
+ while (*attr++ != NULL)
+ attrcount_orig++;
}
+ attrcount = attrcount_orig;
if (dev_info->channels) {
ret = __iio_add_event_config_attrs(dev_info);
- if (ret) {
- if (dev_info->info->event_attrs != NULL)
- sysfs_remove_group(&dev_info->dev.kobj,
- dev_info->info
- ->event_attrs);
- else
- sysfs_remove_group(&dev_info->dev.kobj,
- &iio_events_dummy_group);
+ if (ret < 0)
goto error_free_setup_event_lines;
- }
+ attrcount += ret;
}
+ dev_info->event_interface->group.name = iio_event_group_name;
+ dev_info->event_interface->group.attrs =
+ kzalloc(sizeof(dev_info->event_interface->group.attrs[0])
+ *(attrcount + 1),
+ GFP_KERNEL);
+ if (dev_info->event_interface->group.attrs == NULL) {
+ ret = -ENOMEM;
+ goto error_free_setup_event_lines;
+ }
+ if (dev_info->info->event_attrs)
+ memcpy(dev_info->event_interface->group.attrs,
+ dev_info->info->event_attrs->attrs,
+ sizeof(dev_info->event_interface->group.attrs[0])
+ *attrcount_orig);
+ attrn = attrcount_orig;
+ /* Add all elements from the list. */
+ list_for_each_entry(p,
+ &dev_info->event_interface->dev_attr_list,
+ l)
+ dev_info->event_interface->group.attrs[attrn++] =
+ &p->dev_attr.attr;
+
+ dev_info->groups[dev_info->groupcounter++] =
+ &dev_info->event_interface->group;
+
return 0;
error_free_setup_event_lines:
__iio_remove_event_config_attrs(dev_info);
- if (dev_info->info->event_attrs != NULL)
- sysfs_remove_group(&dev_info->dev.kobj,
- dev_info->info->event_attrs);
- else
- sysfs_remove_group(&dev_info->dev.kobj,
- &iio_events_dummy_group);
kfree(dev_info->event_interface);
error_ret:
if (dev_info->event_interface == NULL)
return;
__iio_remove_event_config_attrs(dev_info);
- if (dev_info->info->event_attrs != NULL)
- sysfs_remove_group(&dev_info->dev.kobj,
- dev_info->info->event_attrs);
- else
- sysfs_remove_group(&dev_info->dev.kobj,
- &iio_events_dummy_group);
+ kfree(dev_info->event_interface->group.attrs);
kfree(dev_info->event_interface);
}
{
struct iio_dev *dev_info = container_of(device, struct iio_dev, dev);
cdev_del(&dev_info->chrdev);
+ if (dev_info->modes & INDIO_RING_TRIGGERED)
+ iio_device_unregister_trigger_consumer(dev_info);
+ iio_device_unregister_eventset(dev_info);
+ iio_device_unregister_sysfs(dev_info);
+ ida_simple_remove(&iio_ida, dev_info->id);
kfree(dev_info);
}
dev = kzalloc(alloc_size, GFP_KERNEL);
if (dev) {
+ dev->dev.groups = dev->groups;
dev->dev.type = &iio_dev_type;
dev->dev.bus = &iio_bus_type;
device_initialize(&dev->dev);
/* configure elements for the chrdev */
dev_info->dev.devt = MKDEV(MAJOR(iio_devt), dev_info->id);
- ret = device_add(&dev_info->dev);
- if (ret)
- goto error_free_ida;
ret = iio_device_register_sysfs(dev_info);
if (ret) {
dev_err(dev_info->dev.parent,
"Failed to register sysfs interfaces\n");
- goto error_del_device;
+ goto error_free_ida;
}
ret = iio_device_register_eventset(dev_info);
if (ret) {
if (dev_info->modes & INDIO_RING_TRIGGERED)
iio_device_register_trigger_consumer(dev_info);
+ ret = device_add(&dev_info->dev);
+ if (ret < 0)
+ goto error_unreg_eventset;
cdev_init(&dev_info->chrdev, &iio_ring_fileops);
dev_info->chrdev.owner = dev_info->info->driver_module;
ret = cdev_add(&dev_info->chrdev, dev_info->dev.devt, 1);
+ if (ret < 0)
+ goto error_del_device;
return 0;
-error_free_sysfs:
- iio_device_unregister_sysfs(dev_info);
error_del_device:
device_del(&dev_info->dev);
+error_unreg_eventset:
+ iio_device_unregister_eventset(dev_info);
+error_free_sysfs:
+ iio_device_unregister_sysfs(dev_info);
error_free_ida:
ida_simple_remove(&iio_ida, dev_info->id);
error_ret:
void iio_device_unregister(struct iio_dev *dev_info)
{
- if (dev_info->modes & INDIO_RING_TRIGGERED)
- iio_device_unregister_trigger_consumer(dev_info);
- iio_device_unregister_eventset(dev_info);
- iio_device_unregister_sysfs(dev_info);
- ida_simple_remove(&iio_ida, dev_info->id);
device_unregister(&dev_info->dev);
}
EXPORT_SYMBOL(iio_device_unregister);
static int iio_ring_add_channel_sysfs(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan)
{
- int ret;
+ int ret, attrcount = 0;
struct iio_ring_buffer *ring = indio_dev->ring;
- ret = __iio_add_chan_devattr("index", "scan_elements",
+ ret = __iio_add_chan_devattr("index",
chan,
&iio_show_scan_index,
NULL,
&ring->scan_el_dev_attr_list);
if (ret)
goto error_ret;
-
- ret = __iio_add_chan_devattr("type", "scan_elements",
+ attrcount++;
+ ret = __iio_add_chan_devattr("type",
chan,
&iio_show_fixed_type,
NULL,
&ring->scan_el_dev_attr_list);
if (ret)
goto error_ret;
-
+ attrcount++;
if (chan->type != IIO_TIMESTAMP)
- ret = __iio_add_chan_devattr("en", "scan_elements",
+ ret = __iio_add_chan_devattr("en",
chan,
&iio_scan_el_show,
&iio_scan_el_store,
&indio_dev->dev,
&ring->scan_el_dev_attr_list);
else
- ret = __iio_add_chan_devattr("en", "scan_elements",
+ ret = __iio_add_chan_devattr("en",
chan,
&iio_scan_el_ts_show,
&iio_scan_el_ts_store,
0,
&indio_dev->dev,
&ring->scan_el_dev_attr_list);
+ attrcount++;
+ ret = attrcount;
error_ret:
return ret;
}
static void iio_ring_remove_and_free_scan_dev_attr(struct iio_dev *indio_dev,
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);
}
-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)
{
struct iio_dev_attr *p, *n;
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,
&ring->scan_el_dev_attr_list, l)
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,
const struct iio_chan_spec *channels,
int num_channels)
{
+ struct iio_dev_attr *p;
+ struct attribute **attr;
struct iio_ring_buffer *ring = indio_dev->ring;
- int ret, i;
-
- if (ring->scan_el_attrs) {
- ret = sysfs_create_group(&indio_dev->dev.kobj,
- 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;
- }
+ int ret, i, attrn, attrcount, attrcount_orig = 0;
+
+ if (ring->attrs)
+ indio_dev->groups[indio_dev->groupcounter++] = ring->attrs;
+ 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);
if (channels) {
/* new magic */
ret = iio_ring_add_channel_sysfs(indio_dev,
&channels[i]);
if (ret < 0)
- goto error_cleanup_group;
+ goto error_cleanup_dynamic;
+ attrcount += ret;
}
if (indio_dev->masklength && ring->scan_mask == NULL) {
ring->scan_mask
GFP_KERNEL);
if (ring->scan_mask == NULL) {
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;
-error_cleanup_group:
- if (ring->attrs)
- sysfs_remove_group(&indio_dev->dev.kobj, ring->attrs);
+
+error_free_scan_mask:
+ kfree(ring->scan_mask);
error_cleanup_dynamic:
__iio_ring_attr_cleanup(indio_dev);
-error_ret:
+
return ret;
}
EXPORT_SYMBOL(iio_ring_buffer_register);
void iio_ring_buffer_unregister(struct iio_dev *indio_dev)
{
kfree(indio_dev->ring->scan_mask);
- if (indio_dev->ring->attrs)
- sysfs_remove_group(&indio_dev->dev.kobj,
- indio_dev->ring->attrs);
+ kfree(indio_dev->ring->scan_el_group.attrs);
__iio_ring_attr_cleanup(indio_dev);
}
EXPORT_SYMBOL(iio_ring_buffer_unregister);
int iio_device_register_trigger_consumer(struct iio_dev *dev_info)
{
- return sysfs_create_group(&dev_info->dev.kobj,
- &iio_trigger_consumer_attr_group);
+ dev_info->groups[dev_info->groupcounter++] =
+ &iio_trigger_consumer_attr_group;
+
+ return 0;
}
void iio_device_unregister_trigger_consumer(struct iio_dev *dev_info)
/* Clean up and associated but not attached triggers references */
if (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)
indio_dev->info = &tsl2563_info;
else
indio_dev->info = &tsl2563_info_no_irq;
- ret = iio_device_register(indio_dev);
- if (ret)
- goto fail1;
if (client->irq) {
ret = request_threaded_irq(client->irq,
NULL,
/* The interrupt cannot yet be enabled so this is fine without lock */
schedule_delayed_work(&chip->poweroff_work, 5 * HZ);
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto fail3;
+
return 0;
fail3:
if (client->irq)
free_irq(client->irq, indio_dev);
fail2:
- iio_device_unregister(indio_dev);
+ iio_free_device(indio_dev);
fail1:
kfree(chip);
return err;
static int __devinit ade7753_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct ade7753_state *st;
struct iio_dev *indio_dev;
indio_dev->info = &ade7753_info;
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)
goto error_free_dev;
- regdone = 1;
- /* Get the device into a sane initial state */
- ret = ade7753_initial_setup(indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
goto error_free_dev;
+
return 0;
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
static int __devinit ade7754_probe(struct spi_device *spi)
{
- int ret, regdone = 0;
+ int ret;
struct ade7754_state *st;
struct iio_dev *indio_dev;
indio_dev->info = &ade7754_info;
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 */
ret = ade7754_initial_setup(indio_dev);
if (ret)
goto error_free_dev;
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_free_dev;
+
return 0;
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
static int __devinit ade7758_probe(struct spi_device *spi)
{
- int i, ret, regdone = 0;
+ int i, ret;
struct ade7758_state *st;
struct iio_dev *indio_dev = iio_allocate_device(sizeof(*st));
if (ret)
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,
&ade7758_channels[0],
ARRAY_SIZE(ade7758_channels));
if (spi->irq) {
ret = ade7758_probe_trigger(indio_dev);
if (ret)
- goto error_remove_trigger;
+ goto error_uninitialize_ring;
}
+ ret = iio_device_register(indio_dev);
+ if (ret)
+ goto error_remove_trigger;
+
return 0;
error_remove_trigger:
error_free_rx:
kfree(st->rx);
error_free_dev:
- if (regdone)
- iio_device_unregister(indio_dev);
- else
- iio_free_device(indio_dev);
+ iio_free_device(indio_dev);
error_ret:
return ret;
}
indio_dev->info = &ade7759_info;
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)
goto error_free_dev;
- /* Get the device into a sane initial state */
- ret = ade7759_initial_setup(indio_dev);
+ ret = iio_device_register(indio_dev);
if (ret)
- goto error_unreg_dev;
- return 0;
+ goto error_free_dev;
+ return 0;
-error_unreg_dev:
- iio_device_unregister(indio_dev);
error_free_dev:
iio_free_device(indio_dev);
error_ret:
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ad2s1210_state *st = iio_priv(indio_dev);
+
ad2s1210_free_gpios(st);
iio_device_unregister(indio_dev);
#ifndef _IIO_RING_GENERIC_H_
#define _IIO_RING_GENERIC_H_
+#include <linux/sysfs.h>
#include "iio.h"
#include "chrdev.h"
const struct iio_ring_access_funcs *access;
const struct iio_ring_setup_ops *setup_ops;
struct list_head scan_el_dev_attr_list;
-
+ struct attribute_group scan_el_group;
wait_queue_head_t pollq;
bool stufftoread;
unsigned long flags;