Commit f0aef2d0 authored by Lars-Peter Clausen's avatar Lars-Peter Clausen Committed by Jonathan Cameron

iio: ad_sigma_delta: Allow to provide custom data register address

Some newer devices from the Sigma-Delta ADC family do have their data
register at a different address than the current default address. Add a
parameter to the ad_sigma_delta_info struct which allows to override the
default address.
Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarStefan Popa <stefan.popa@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent c24a4173
...@@ -278,6 +278,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, ...@@ -278,6 +278,7 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
{ {
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int sample, raw_sample; unsigned int sample, raw_sample;
unsigned int data_reg;
int ret = 0; int ret = 0;
if (iio_buffer_enabled(indio_dev)) if (iio_buffer_enabled(indio_dev))
...@@ -305,7 +306,12 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev, ...@@ -305,7 +306,12 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = ad_sd_read_reg(sigma_delta, AD_SD_REG_DATA, if (sigma_delta->info->data_reg != 0)
data_reg = sigma_delta->info->data_reg;
else
data_reg = AD_SD_REG_DATA;
ret = ad_sd_read_reg(sigma_delta, data_reg,
DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8), DIV_ROUND_UP(chan->scan_type.realbits + chan->scan_type.shift, 8),
&raw_sample); &raw_sample);
...@@ -392,6 +398,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) ...@@ -392,6 +398,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev; struct iio_dev *indio_dev = pf->indio_dev;
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev); struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
unsigned int reg_size; unsigned int reg_size;
unsigned int data_reg;
uint8_t data[16]; uint8_t data[16];
int ret; int ret;
...@@ -401,18 +408,23 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p) ...@@ -401,18 +408,23 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
indio_dev->channels[0].scan_type.shift; indio_dev->channels[0].scan_type.shift;
reg_size = DIV_ROUND_UP(reg_size, 8); reg_size = DIV_ROUND_UP(reg_size, 8);
if (sigma_delta->info->data_reg != 0)
data_reg = sigma_delta->info->data_reg;
else
data_reg = AD_SD_REG_DATA;
switch (reg_size) { switch (reg_size) {
case 4: case 4:
case 2: case 2:
case 1: case 1:
ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA, ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
reg_size, &data[0]); &data[0]);
break; break;
case 3: case 3:
/* We store 24 bit samples in a 32 bit word. Keep the upper /* We store 24 bit samples in a 32 bit word. Keep the upper
* byte set to zero. */ * byte set to zero. */
ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA, ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
reg_size, &data[1]); &data[1]);
break; break;
} }
......
...@@ -39,6 +39,8 @@ struct iio_dev; ...@@ -39,6 +39,8 @@ struct iio_dev;
* if there is just one read-only sample data shift register. * if there is just one read-only sample data shift register.
* @addr_shift: Shift of the register address in the communications register. * @addr_shift: Shift of the register address in the communications register.
* @read_mask: Mask for the communications register having the read bit set. * @read_mask: Mask for the communications register having the read bit set.
* @data_reg: Address of the data register, if 0 the default address of 0x3 will
* be used.
*/ */
struct ad_sigma_delta_info { struct ad_sigma_delta_info {
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel); int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
...@@ -47,6 +49,7 @@ struct ad_sigma_delta_info { ...@@ -47,6 +49,7 @@ struct ad_sigma_delta_info {
bool has_registers; bool has_registers;
unsigned int addr_shift; unsigned int addr_shift;
unsigned int read_mask; unsigned int read_mask;
unsigned int data_reg;
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment