iio: adc: ti-ads1015: add support for ADS1115 part
PATCH v2 1/1 iio: adc: ti-ads1015: add support for ADS1115 part
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
---
Changes from v1:
* remove magic value and replace with ARRAY_SIZE()
drivers/iio/adc/ti-ads1015.c | 78 ++++++++++++++++++++++++++++++++++++++++----
1 file changed, 72 insertions(+), 6 deletions(-)
drivers/iio/adc/ti-ads1015.c +72 -6
@@ -55,6 +55,11 @@#define ADS1015_DEFAULT_DATA_RATE 4#define ADS1015_DEFAULT_CHAN 0 +enum { +ADS1015 , +ADS1115 , +}; +enum ads1015_channels {ADS1015_AIN0_AIN1 =0 ,ADS1015_AIN0_AIN3 ,
@@ -123,6 +128,42 @@ static const struct { }, \ } +#define ADS1115_V_CHAN (_chan, _addr) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .address = _addr, \ + .channel = _chan, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _addr, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ +} + +#define ADS1115_V_DIFF_CHAN (_chan, _chan2, _addr) { \ + .type = IIO_VOLTAGE, \ + .differential = 1, \ + .indexed = 1, \ + .address = _addr, \ + .channel = _chan, \ + .channel2 = _chan2, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _addr, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ +} +struct ads1015_data {struct regmap *regmap;/*
@@ -157,6 +198,19 @@ static const struct iio_chan_spec ads1015_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; +static const struct iio_chan_spec ads1115_channels[] = { +ADS1115_V_DIFF_CHAN (0 ,1 ,ADS1015_AIN0_AIN1 ), +ADS1115_V_DIFF_CHAN (0 ,3 ,ADS1015_AIN0_AIN3 ), +ADS1115_V_DIFF_CHAN (1 ,3 ,ADS1015_AIN1_AIN3 ), +ADS1115_V_DIFF_CHAN (2 ,3 ,ADS1015_AIN2_AIN3 ), +ADS1115_V_CHAN (0 ,ADS1015_AIN0 ), +ADS1115_V_CHAN (1 ,ADS1015_AIN1 ), +ADS1115_V_CHAN (2 ,ADS1015_AIN2 ), +ADS1115_V_CHAN (3 ,ADS1015_AIN3 ), +IIO_CHAN_SOFT_TIMESTAMP (ADS1015_TIMESTAMP ), +}; + +static int ads1015_set_power_state (struct ads1015_data *data,bool on) {int ret;
@@ -291,7 +345,9 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,mutex_lock (&indio_dev->mlock);mutex_lock (&data->lock);switch (mask) { -case IIO_CHAN_INFO_RAW : +case IIO_CHAN_INFO_RAW : { +int shift = chan->scan_type.shift; +if (iio_buffer_enabled (indio_dev)) { ret = -EBUSY ;break ;
@@ -307,8 +363,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,break ; } -/* 12 bit res, D0 is bit 4 in conversion register */ - *val =sign_extend32 (*val >>4 ,11 ); + *val =sign_extend32 (*val >> shift,15 - shift); ret =ads1015_set_power_state (data, false);if (ret <0 )
@@ -316,6 +371,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, ret =IIO_VAL_INT ;break ; + }case IIO_CHAN_INFO_SCALE : idx = data->channel_data[chan->address].pga; *val = ads1015_scale[idx].scale;
@@ -502,8 +558,17 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->dev.parent = &client->dev; indio_dev->info = &ads1015_info; indio_dev->name =ADS1015_DRV_NAME ; - indio_dev->channels = ads1015_channels; - indio_dev->num_channels =ARRAY_SIZE (ads1015_channels); + +switch (id->driver_data) { +case ADS1015 : + indio_dev->channels = ads1015_channels; + indio_dev->num_channels =ARRAY_SIZE (ads1015_channels); +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; + indio_dev->num_channels =ARRAY_SIZE (ads1115_channels); +break ; + } indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */
@@ -590,7 +655,8 @@ static const struct dev_pm_ops ads1015_pm_ops = { };static const struct i2c_device_id ads1015_id[] = { - {"ads1015" ,0 }, + {"ads1015" ,ADS1015 }, + {"ads1115" ,ADS1115 }, {} };MODULE_DEVICE_TABLE (i2c, ads1015_id);
Signature · 1 line
1.9.1
Jonathan Cameron
maintainerQuoted 5 lines · Matt Ranostay
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
Signed-off-by Matt Ranostay <[email protected]>
Other than a trivial nitpick I'll 'fix' when applying I'm happy with this. Will leave some time for Daniel to have another look though as we aren't exactly in a rush at this point in the cycle.
Thanks,
Jonathan
Quoted 74 lines
---
Changes from v1:
* remove magic value and replace withARRAY_SIZE()
drivers/iio/adc/ti-ads1015.c| 78 ++++++++++++++++++++++++++++++++++++++++----1 file changed, 72 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +44
-0@@ -55,6 +55,11 @@#define ADS1015_DEFAULT_DATA_RATE 4#define ADS1015_DEFAULT_CHAN 0 +enum { +ADS1015 , +ADS1115 , +}; +enum ads1015_channels {ADS1015_AIN0_AIN1 =0 ,ADS1015_AIN0_AIN3 ,@@ -123,6 +128,42 @@ static const struct { }, \ } +#define ADS1115_V_CHAN (_chan, _addr) { \ + .type = IIO_VOLTAGE, \ + .indexed = 1, \ + .address = _addr, \ + .channel = _chan, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _addr, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ +} + +#define ADS1115_V_DIFF_CHAN (_chan, _chan2, _addr) { \ + .type = IIO_VOLTAGE, \ + .differential = 1, \ + .indexed = 1, \ + .address = _addr, \ + .channel = _chan, \ + .channel2 = _chan2, \ + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \ + BIT(IIO_CHAN_INFO_SCALE) | \ + BIT(IIO_CHAN_INFO_SAMP_FREQ), \ + .scan_index = _addr, \ + .scan_type = { \ + .sign = 's', \ + .realbits = 16, \ + .storagebits = 16, \ + .endianness = IIO_CPU, \ + }, \ +} +struct ads1015_data {struct regmap *regmap;/* @@ -157,6 +198,19 @@ static const struct iio_chan_spec ads1015_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), }; +static const struct iio_chan_spec ads1115_channels[] = { +ADS1115_V_DIFF_CHAN (0 ,1 ,ADS1015_AIN0_AIN1 ), +ADS1115_V_DIFF_CHAN (0 ,3 ,ADS1015_AIN0_AIN3 ),
drivers/iio/adc/ti-ads1015.c static const struct iio_chan_spec ads1015_channels[] = { · line 213
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ADS1115_V_DIFF_CHAN (1 ,3 ,ADS1015_AIN1_AIN3 ), +ADS1115_V_DIFF_CHAN (2 ,3 ,ADS1015_AIN2_AIN3 ), +ADS1115_V_CHAN (0 ,ADS1015_AIN0 ), +ADS1115_V_CHAN (1 ,ADS1015_AIN1 ), +ADS1115_V_CHAN (2 ,ADS1015_AIN2 ), +ADS1115_V_CHAN (3 ,ADS1015_AIN3 ), + IIO_CHAN_SOFT_TIMESTAMP(ADS1015_TIMESTAMP), +}; + +
One blank line is almost always enough ;)
Quoted 63 lines
drivers/iio/adc/ti-ads1015.c +18
-6static int ads1015_set_power_state (struct ads1015_data *data,bool on) {int ret;@@ -291,7 +345,9 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,mutex_lock (&indio_dev->mlock);mutex_lock (&data->lock);switch (mask) { -case IIO_CHAN_INFO_RAW : +case IIO_CHAN_INFO_RAW : { +int shift = chan->scan_type.shift; +if (iio_buffer_enabled (indio_dev)) { ret = -EBUSY ;break ;@@ -307,8 +363,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev,break ; } -/* 12 bit res, D0 is bit 4 in conversion register */ - *val =sign_extend32 (*val >>4 ,11 ); + *val =sign_extend32 (*val >> shift,15 - shift); ret =ads1015_set_power_state (data, false);if (ret <0 )@@ -316,6 +371,7 @@ static int ads1015_read_raw(struct iio_dev *indio_dev, ret =IIO_VAL_INT ;break ; + }case IIO_CHAN_INFO_SCALE : idx = data->channel_data[chan->address].pga; *val = ads1015_scale[idx].scale;@@ -502,8 +558,17 @@ static int ads1015_probe(struct i2c_client *client, indio_dev->dev.parent = &client->dev; indio_dev->info = &ads1015_info; indio_dev->name =ADS1015_DRV_NAME ; - indio_dev->channels = ads1015_channels; - indio_dev->num_channels =ARRAY_SIZE (ads1015_channels); + +switch (id->driver_data) { +case ADS1015 : + indio_dev->channels = ads1015_channels; + indio_dev->num_channels =ARRAY_SIZE (ads1015_channels); +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; + indio_dev->num_channels =ARRAY_SIZE (ads1115_channels); +break ; + } indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +655,8 @@ static const struct dev_pm_ops ads1015_pm_ops = { };static const struct i2c_device_id ads1015_id[] = { - {"ads1015" ,0 }, + {"ads1015" ,ADS1015 }, + {"ads1115" ,ADS1115 }, {} };MODULE_DEVICE_TABLE (i2c, ads1015_id);
Hi,
Quoted 6 lines · Matt Ranostay
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
Signed-off-by Matt Ranostay <[email protected]>---
I see no changes to the available data rates in ads1115 which are very different from the ones in ads1015. Am I missing something?
Lucas De Marchi
Quoted 6 lines · Lucas De Marchi
Hi,
Quoted 3 lines · Matt Ranostay
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Matt Ranostay <[email protected]>---
I see no changes to the available data rates in ads1115 which are very different from the ones in ads1015. Am I missing something?
Yikes! I totally missed that.. good catch..
Quoted 6 lines
Lucas De Marchi
--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html