Re: [PATCH V3.1] adds support for Texas Instruments ads1110 adc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/06/2012 10:35 AM, Pirmin Duss wrote:
> From: Pirmin Duss (Flytec) <pirmin.duss@xxxxxxxxx>
> 
> Now against staging-next.
> 
> Signed-off-by: Pirmin Duss (Flytec) <pirmin.duss@xxxxxxxxx>
> ---
>  drivers/staging/iio/adc/Kconfig   |   10 +
>  drivers/staging/iio/adc/Makefile  |    1 +
>  drivers/staging/iio/adc/ads1110.c |  332 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 343 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/staging/iio/adc/ads1110.c
> 
> [...]
> diff --git a/drivers/staging/iio/adc/ads1110.c b/drivers/staging/iio/adc/ads1110.c
> new file mode 100644
> index 0000000..819a095
> --- /dev/null
> +++ b/drivers/staging/iio/adc/ads1110.c
> @@ -0,0 +1,332 @@
> [...]
> +static const struct iio_chan_spec ads1110_channels[] = {
> +	IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0,
> +		(1 << IIO_CHAN_INFO_SCALE_SEPARATE_BIT), 0, 0,

Just IIO_CHAN_INFO_SCALE_SEPARATE_BIT without the '1 <<'

> +		IIO_ST('s', 16, 16, 0), 0),
> +};
> +
[...]
> +
> +static int ads1110_read_raw(struct iio_dev *indio_dev,
> +			   struct iio_chan_spec const *chan,
> +			   int *val,
> +			   int *val2,
> +			   long mask)
> +{
> +	struct ads1110_chip_info *st = iio_priv(indio_dev);
> +	int ret, data, gain;
> +
> +	switch (mask) {
> +	case 0:
> +		mutex_lock(&indio_dev->mlock);
> +		ret = ads1110_i2c_read_data(st, &data);
> +		if (ret < 0)
> +			return -EIO;
> +
> +		mutex_unlock(&indio_dev->mlock);
> +
> +		*val = data;
> +
> +		return IIO_VAL_INT;
> +
> +	case (1 << IIO_CHAN_INFO_SCALE):

Same here: Without the '1 <<'

> +
> +		mutex_lock(&indio_dev->mlock);
> +		gain = 1 << (st->config & ADS1110_PGA_MASK);
> +		mutex_unlock(&indio_dev->mlock);
> +
> +		*val = gain;
> +
> +		return IIO_VAL_INT;
> +	}
> +	return -EINVAL;
> +}
> +
> +static int ads1110_write_raw(struct iio_dev *indio_dev,
> +			struct iio_chan_spec const *chan,
> +			int val,
> +			int val2,
> +			long mask)
> +{
> +	struct ads1110_chip_info *st = iio_priv(indio_dev);
> +	int ret, i;
> +	unsigned int tmp;
> +
> +	mutex_lock(&indio_dev->mlock);
> +	switch (mask) {
> +	case (1 << IIO_CHAN_INFO_SCALE):

And here.

> +		ret = -EINVAL;
> +		for (i = 0; i < ADS1110_PGA_COUNT; i++) {
> +			if (val == (1 << i)) {
> +				tmp = st->config;
> +
> +				st->config &= ~ADS1110_PGA_MASK;
> +				st->config |= i;
> +
> +				if (tmp != st->config) {
> +					ret = i2c_master_send(st->client,
> +						&st->config, 1);
> +					if (ret < 0) {
> +						ret = -EIO;
> +						dev_err(&st->client->dev,
> +							"I2C write error\n");
> +						goto out;
> +					}
> +				}
> +				ret = 0;
> +
> +				break;
> +			}
> +		}
> +		break;
> +	default:
> +		ret = -EINVAL;
> +	}
> +out:
> +	mutex_unlock(&indio_dev->mlock);
> +	return ret;
> +}
> +
> [...]
> +
> +static int __devinit ads1110_probe(struct i2c_client *client,
> +		const struct i2c_device_id *id)
> +{
> +	int ret;
> +	struct ads1110_chip_info *chip;
> +	struct iio_dev *indio_dev;
> +
> +	indio_dev = iio_allocate_device(sizeof(*chip));
> +	if (indio_dev == NULL) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +	chip = iio_priv(indio_dev);
> +
> +	/* this is only used for device removal purposes  */
> +	i2c_set_clientdata(client, indio_dev);
> +
> +	chip->client = client;
> +
> +	/* Establish that the iio_dev is a child of the i2c device */
> +	indio_dev->name = id->name;
> +	indio_dev->dev.parent = &client->dev;
> +	indio_dev->info = &ads1110_info;
> +	indio_dev->modes = INDIO_DIRECT_MODE;
> +	indio_dev->channels = ads1110_channels;
> +	indio_dev->num_channels = ARRAY_SIZE(ads1110_channels);
> +
> +	ret = iio_device_register(indio_dev);
> +	if (ret)
> +		goto error_free_dev;
> +
> +	/* read the config register from the chip */
> +	ret = ads1110_i2c_read_config(chip, &chip->config);
> +	if (ret < 0)
> +		goto error_free_dev;

Move the ads1110_i2c_read_config before you register the device. On one hand
this avoids race condition on the other you don't have to unregister the device
(Which you don't do right now).

> +
> +	dev_err(&client->dev, "%s ADC registered.\n", id->name);
> +
> +	return 0;
> +
> +error_free_dev:
> +	iio_free_device(indio_dev);
> +	kfree(chip);
> +error_ret:
> +	return ret;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux