mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-15 21:26:40 +07:00
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: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Stefan Popa <stefan.popa@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
c24a4173f6
commit
f0aef2d018
@ -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);
|
||||
unsigned int sample, raw_sample;
|
||||
unsigned int data_reg;
|
||||
int ret = 0;
|
||||
|
||||
if (iio_buffer_enabled(indio_dev))
|
||||
@ -305,7 +306,12 @@ int ad_sigma_delta_single_conversion(struct iio_dev *indio_dev,
|
||||
if (ret < 0)
|
||||
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),
|
||||
&raw_sample);
|
||||
|
||||
@ -392,6 +398,7 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
|
||||
struct iio_dev *indio_dev = pf->indio_dev;
|
||||
struct ad_sigma_delta *sigma_delta = iio_device_get_drvdata(indio_dev);
|
||||
unsigned int reg_size;
|
||||
unsigned int data_reg;
|
||||
uint8_t data[16];
|
||||
int ret;
|
||||
|
||||
@ -401,18 +408,23 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
|
||||
indio_dev->channels[0].scan_type.shift;
|
||||
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) {
|
||||
case 4:
|
||||
case 2:
|
||||
case 1:
|
||||
ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
|
||||
reg_size, &data[0]);
|
||||
ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
|
||||
&data[0]);
|
||||
break;
|
||||
case 3:
|
||||
/* We store 24 bit samples in a 32 bit word. Keep the upper
|
||||
* byte set to zero. */
|
||||
ret = ad_sd_read_reg_raw(sigma_delta, AD_SD_REG_DATA,
|
||||
reg_size, &data[1]);
|
||||
ret = ad_sd_read_reg_raw(sigma_delta, data_reg, reg_size,
|
||||
&data[1]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,8 @@ struct iio_dev;
|
||||
* if there is just one read-only sample data shift register.
|
||||
* @addr_shift: Shift of the register address in the communications register.
|
||||
* @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 {
|
||||
int (*set_channel)(struct ad_sigma_delta *, unsigned int channel);
|
||||
@ -47,6 +49,7 @@ struct ad_sigma_delta_info {
|
||||
bool has_registers;
|
||||
unsigned int addr_shift;
|
||||
unsigned int read_mask;
|
||||
unsigned int data_reg;
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user