OSDN Git Service

iio: adis16475: improve sync scale mode handling
authorNuno Sa <nuno.sa@analog.com>
Thu, 18 Feb 2021 11:40:37 +0000 (12:40 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Thu, 11 Mar 2021 20:47:12 +0000 (20:47 +0000)
commit39c024b51b5607e9d2fc6c04c2573e4a778c728d
tree224235e41668b520d5ffe5eb0642cbf5577ea0a7
parent0463e60f087069adf25a815cd88753946aca2565
iio: adis16475: improve sync scale mode handling

With this patch, we don't force users to define the IMU scaled internal
sampling rate once in the devicetree. Now it's dynamically calculated
at runtime depending on the desired output rate given by users.

Calculating the sync_scale dynamically gives us better chances of
achieving a perfect/integer value for DEC_RATE (thus giving more
flexibility). The math is:
 1. lcm of the input clock and the desired output rate.
 2. get the highest multiple of the previous result lower than the adis
    max rate.
 3. The last result becomes the IMU sample rate. Use that to calculate
    SYNC_SCALE and DEC_RATE (to get the user output rate).

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20210218114039.216091-3-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/imu/adis16475.c