Commit e0e6398e authored by Stefan Popa's avatar Stefan Popa Committed by Jonathan Cameron

iio: imu: adis16480: Calculate the sampling frequency in a generic way

The adis1648x devices have an internal clock of 2.46 kSPS. The sampling
frequency is calculated by applying a decimation rate which can take the
maximum value of 2047.

Although all adis1648x devices are similar in this regard, devices that
will use this feature will be added in the future.
Signed-off-by: default avatarStefan Popa <stefan.popa@analog.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 6cf7b866
...@@ -125,6 +125,8 @@ struct adis16480_chip_info { ...@@ -125,6 +125,8 @@ struct adis16480_chip_info {
unsigned int accel_max_val; unsigned int accel_max_val;
unsigned int accel_max_scale; unsigned int accel_max_scale;
unsigned int temp_scale; unsigned int temp_scale;
unsigned int int_clk;
unsigned int max_dec_rate;
}; };
enum adis16480_int_pin { enum adis16480_int_pin {
...@@ -299,9 +301,9 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2) ...@@ -299,9 +301,9 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
if (t <= 0) if (t <= 0)
return -EINVAL; return -EINVAL;
t = 2460000 / t; t = st->chip_info->int_clk / t;
if (t > 2048) if (t > st->chip_info->max_dec_rate)
t = 2048; t = st->chip_info->max_dec_rate;
if (t != 0) if (t != 0)
t--; t--;
...@@ -320,7 +322,7 @@ static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2) ...@@ -320,7 +322,7 @@ static int adis16480_get_freq(struct iio_dev *indio_dev, int *val, int *val2)
if (ret < 0) if (ret < 0)
return ret; return ret;
freq = 2460000 / (t + 1); freq = st->chip_info->int_clk / (t + 1);
*val = freq / 1000; *val = freq / 1000;
*val2 = (freq % 1000) * 1000; *val2 = (freq % 1000) * 1000;
...@@ -726,6 +728,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -726,6 +728,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(21973), .accel_max_val = IIO_M_S_2_TO_G(21973),
.accel_max_scale = 18, .accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000,
.max_dec_rate = 2048,
}, },
[ADIS16480] = { [ADIS16480] = {
.channels = adis16480_channels, .channels = adis16480_channels,
...@@ -735,6 +739,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -735,6 +739,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(12500), .accel_max_val = IIO_M_S_2_TO_G(12500),
.accel_max_scale = 10, .accel_max_scale = 10,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000,
.max_dec_rate = 2048,
}, },
[ADIS16485] = { [ADIS16485] = {
.channels = adis16485_channels, .channels = adis16485_channels,
...@@ -744,6 +750,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -744,6 +750,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(20000), .accel_max_val = IIO_M_S_2_TO_G(20000),
.accel_max_scale = 5, .accel_max_scale = 5,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000,
.max_dec_rate = 2048,
}, },
[ADIS16488] = { [ADIS16488] = {
.channels = adis16480_channels, .channels = adis16480_channels,
...@@ -753,6 +761,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = { ...@@ -753,6 +761,8 @@ static const struct adis16480_chip_info adis16480_chip_info[] = {
.accel_max_val = IIO_M_S_2_TO_G(22500), .accel_max_val = IIO_M_S_2_TO_G(22500),
.accel_max_scale = 18, .accel_max_scale = 18,
.temp_scale = 5650, /* 5.65 milli degree Celsius */ .temp_scale = 5650, /* 5.65 milli degree Celsius */
.int_clk = 2460000,
.max_dec_rate = 2048,
}, },
}; };
......
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