Re: [PATCH V3] Adds support for Texas Instruments ADS1110 adc.

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

 



On 01/04/2012 02:36 PM, Pirmin Duss wrote:
> From: Duss Pirmin <pirmin.duss@xxxxxxxxx>
[...]

> +static const struct iio_chan_spec ads1110_channels[] = {
> +	IIO_CHAN(IIO_VOLTAGE, 0, 1, 0, NULL, 0, 0,
> +		(1 << IIO_CHAN_INFO_SCALE_SEPARATE), 0, 0,

We changed this recently. (1 << IIO_CHAN_INFO_SCALE_SEPARATE) should be
IIO_CHAN_INFO_SCALE_SEPARATE_BIT

> +		IIO_ST('s', 16, 16, 0), 0),
> +};
> +
> +static int ads1110_i2c_read_config(struct ads1110_chip_info *chip, u8 *data)
> +{
> +	int ret = 0;
> +	u8 tmp[ADS1110_CONFIG_BYTES];
> +
> +	ret = i2c_master_recv(chip->client, tmp, ADS1110_CONFIG_BYTES);
> +	if (ret < ADS1110_CONFIG_BYTES) {
> +		dev_err(&chip->client->dev, "I2C read error\n");
> +		return ret;

This could be a bit cleaner if you translate return codes >= 0 and <
ADS1110_CONFIG_BYTES to -EIO ...

> +	}
> +
> +	*data = tmp[2];
> +
> +	return ret;

... and return 0 here and let the caller just check for ret < 0

> +}
> +
> +static int ads1110_i2c_read_data(struct ads1110_chip_info *chip, int *data)
> +{
> +	int ret = 0;
> +	__be16 tmp;
> +
> +	ret = i2c_master_recv(chip->client, (char *)&tmp, ADS1110_DATA_BYTES);
> +	if (ret < ADS1110_DATA_BYTES) {
> +		dev_err(&chip->client->dev, "I2C read error\n");
> +		return ret;

same here


> +	}
> +
> +	*data = be16_to_cpu(tmp);
> +
> +	return ret;
> +}
> +
[...]
> +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 != ADS1110_DATA_BYTES)
> +			return -EIO;
> +
> +		mutex_unlock(&indio_dev->mlock);
> +
> +		*val = data;
> +
> +		return IIO_VAL_INT;
> +
> +	case (1 << IIO_CHAN_INFO_SCALE_SHARED):
> +

Just IIO_CHAN_INFO_SCALE

> +		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_SHARED):

Same here: Just IIO_CHAN_INFO_SCALE

> +		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 struct attribute *ads1110_attributes[] = {
> +	&iio_const_attr_sampling_frequency_available.dev_attr.attr,
> +	&iio_dev_attr_sampling_frequency.dev_attr.attr,
> +	&iio_const_attr_in_in_scale_available.dev_attr.attr,
> +	NULL,
> +};
> +
> +static const struct attribute_group ads1110_attribute_group = {
> +	.attrs = ads1110_attributes,
> +};
> +
> +static const struct iio_info ads1110_info = {
> +	.attrs = &ads1110_attribute_group,
> +	.read_raw = &ads1110_read_raw,
> +	.write_raw = &ads1110_write_raw,
> +	.driver_module = THIS_MODULE,
> +};
> +
> +static int __devinit ads1110_probe(struct i2c_client *client,
> +		const struct i2c_device_id *id)
> +{
> +	int ret = 0;

The initialization to 0 is to needed.

> +	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);
> +

> +
[...]
--
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