IIO: Ingenic JZ47xx: Set clock divider on probe
authorMaarten ter Huurne <maarten@treewalker.org>
Thu, 4 Jul 2019 17:36:56 +0000 (19:36 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 14 Jul 2019 15:02:08 +0000 (16:02 +0100)
commit5a304e1a4ea000177cf25f5ecf26e786dda25b98
tree96f6940581418d915583d7c0791fd2700a7d93d8
parentae8cc91a7d85e018c0c267f580820b2bb558cd48
IIO: Ingenic JZ47xx: Set clock divider on probe

The SADC component can run at up to 8 MHz on JZ4725B, but is fed
a 12 MHz input clock (EXT). Divide it by two to get 6 MHz, then
set up another divider to match, to produce a 10us clock.

If the clock dividers are left on their power-on defaults (a divider
of 1), the SADC mostly works, but will occasionally produce erroneous
readings. This led to button presses being detected out of nowhere on
the RS90 every few minutes. With this change, no ghost button presses
were logged in almost a day worth of testing.

The ADCLK register for configuring clock dividers doesn't exist on
JZ4740, so avoid writing it there.

A function has been introduced rather than a flag because there is a lot
of variation between the ADCLK registers on JZ47xx SoCs, both in
the internal layout of the register and in the frequency range
supported by the SADC. So this solution should make it easier
to add support for other JZ47xx SoCs later.

Fixes: 1a78daea107d ("iio: adc: probe should set clock divider")
Signed-off-by: Maarten ter Huurne <maarten@treewalker.org>
Signed-off-by: Artur Rojek <contact@artur-rojek.eu>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ingenic-adc.c