iio: adc: ti-ads1015: add support for ADS1115 part
PATCH 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.
--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)
drivers/iio/adc/ti-ads1015.c +71 -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,16 @@ 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; +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; +break ; + } + indio_dev->num_channels =9 ; indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */
@@ -590,7 +654,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
Quoted 32 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]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +8
-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, \
drivers/iio/adc/ti-ads1015.c static const struct { · line 143
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ .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, \
Noticed I missed a .shift = 0 here.
Will fix in v2 after other comments.
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c +9
-0+ .endianness = IIO_CPU, \ + }, \ +} + +#define ADS1115_V_DIFF_CHAN (_chan, _chan2, _addr) { \ + .type = IIO_VOLTAGE, \ + .differential = 1, \ + .indexed = 1, \ + .address = _addr, \
drivers/iio/adc/ti-ads1015.c static const struct { · line 162
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ .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, \
Same.
Quoted 92 lines
drivers/iio/adc/ti-ads1015.c +34
-7+ .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,16 @@ 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; +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; +break ; + } + indio_dev->num_channels =9 ; indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +654,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); --1.9.1
--
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
Quoted 31 lines · Matt Ranostay
Quoted 29 lines
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
Signed-off-by Matt Ranostay <[email protected]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +5
-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 { }, \ }
Quoted 15 lines
drivers/iio/adc/ti-ads1015.c static const struct { · line 143
Quoted 13 lines
drivers/iio/adc/ti-ads1015.c +13
-0+#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, \Noticed I missed a .shift = 0 here.
Will fix in v2 after other comments.
.shift = 0 is not needed, with courtesy of your compiler
Quoted 118 lines
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c +9
-0+ .endianness = IIO_CPU, \ + }, \ +} + +#define ADS1115_V_DIFF_CHAN (_chan, _chan2, _addr) { \ + .type = IIO_VOLTAGE, \ + .differential = 1, \ + .indexed = 1, \ + .address = _addr, \drivers/iio/adc/ti-ads1015.c static const struct { · line 162
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ .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, \Same.
Quoted 88 lines
drivers/iio/adc/ti-ads1015.c +34
-7+ .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,16 @@ 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; +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; +break ; + } + indio_dev->num_channels =9 ; indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +654,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); --1.9.1
Quoted 4 lines
--
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--
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
Signature · 2 lines
Peter Meerwald-Stadler +43-664-2444418 (mobile)
Quoted 47 lines · Peter Meerwald-Stadler
Quoted 31 lines · Matt Ranostay
Quoted 29 lines
TI ADS1115 is a 16-bit resolution ADC that is register map compatible with the ADS1015 device.
Signed-off-by Matt Ranostay <[email protected]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +5
-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 { }, \ }Quoted 15 lines
drivers/iio/adc/ti-ads1015.c static const struct { · line 143
Quoted 13 lines
drivers/iio/adc/ti-ads1015.c +13
-0+#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, \Noticed I missed a .shift = 0 here.
Will fix in v2 after other comments.
Quoted 2 lines
.shift = 0 is not needed, with courtesy of your compiler
Ah right forgot that global scope has it zeroed. Never mind then :)
Quoted 123 lines
Quoted 109 lines
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c +9
-0+ .endianness = IIO_CPU, \ + }, \ +} + +#define ADS1115_V_DIFF_CHAN (_chan, _chan2, _addr) { \ + .type = IIO_VOLTAGE, \ + .differential = 1, \ + .indexed = 1, \ + .address = _addr, \drivers/iio/adc/ti-ads1015.c static const struct { · line 162
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ .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, \Same.
Quoted 88 lines
drivers/iio/adc/ti-ads1015.c +34
-7+ .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,16 @@ 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; +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; +break ; + } + indio_dev->num_channels =9 ; indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +654,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); --1.9.1
Quoted 9 lines
Quoted 4 lines
--
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--
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--
Peter Meerwald-Stadler
+43-664-2444418 (mobile)
Quoted 123 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]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +59
-5@@ -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,16 @@ 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);
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 570
Quoted 10 lines
drivers/iio/adc/ti-ads1015.c +10
-0+ +switch (id->driver_data) { +case ADS1015 : + indio_dev->channels = ads1015_channels; +break ; +case ADS1115 : + indio_dev->channels = ads1115_channels; +break ; + } + indio_dev->num_channels =9 ;
I'm not comfortable with this magic number here.
One suggestion how I would fix the number of channels...
Quoted 118 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]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +59
-3@@ -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;
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 564
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c +4
-2@@ -502,8 +558,16 @@ 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);
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 567
Quoted 3 lines
drivers/iio/adc/ti-ads1015.c +3
-0+break ; +case ADS1115 : + indio_dev->channels = ads1115_channels;
indio_dev->num_channels = ARRAY_SIZE(ads1115_channels);
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 570
Quoted 3 lines
drivers/iio/adc/ti-ads1015.c +3
-0+break ; + } + indio_dev->num_channels =9 ;
remove this above line
Quoted 20 lines
drivers/iio/adc/ti-ads1015.c +2
-2indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +654,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); --1.9.1
--
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
Quoted 131 lines · Crt Mori
One suggestion how I would fix the number of channels...
Quoted 118 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]>--- drivers/iio/adc/ti-ads1015.c | 77 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 6 deletions(-)drivers/iio/adc/ti-ads1015.c +59
-3@@ -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;drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 564
Quoted 9 lines
drivers/iio/adc/ti-ads1015.c +4
-2@@ -502,8 +558,16 @@ 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);
Quoted 8 lines
drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 567
Quoted 3 lines
drivers/iio/adc/ti-ads1015.c +3
-0+break ; +case ADS1115 : + indio_dev->channels = ads1115_channels;
indio_dev->num_channels=ARRAY_SIZE(ads1115_channels);drivers/iio/adc/ti-ads1015.c static int ads1015_probe(struct i2c_client *client, · line 570
Quoted 3 lines
drivers/iio/adc/ti-ads1015.c +3
-0+break ; + } + indio_dev->num_channels =9 ;remove this above line
Yeah don't know why I didn't do this way initially will fix in v2
Quoted 24 lines
Quoted 16 lines
drivers/iio/adc/ti-ads1015.c +2
-2indio_dev->modes =INDIO_DIRECT_MODE ;/* we need to keep this ABI the same as used by hwmon ADS1015 driver */ @@ -590,7 +654,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); --1.9.1
Quoted 4 lines
--
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--
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