iio: accel: bma220: make suspend state setting more robust
authorAlexandru Ardelean <aardelean@deviqon.com>
Fri, 25 Jun 2021 14:01:37 +0000 (17:01 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 19 Jul 2021 08:51:59 +0000 (09:51 +0100)
commit3ce868bb0595be1e4d75b0e1a055f2dc0867d335
tree53f26bf172c91fa6b5e2435e7fa902002634a46b
parentc336b611e9e48304589303b580292dd1bf6d4eb3
iio: accel: bma220: make suspend state setting more robust

The datasheet mentions that the suspend mode is toggled by reading the
suspend register. The reading returns value 0xFF if the system was in
suspend mode, otherwise it returns value 0x00.

The bma220_deinit() function does up to 2 reads, in case the device was in
suspend mode, which suggests a level of paranoia that makes the logic in
bma220_suspend() and bma220_resume() look insufficient.

This change implements a bma220_power() function which does up to 2 reads
of the suspend register to make sure that the chip enters a desired
(suspended or normal) mode.

If the transition fails, then -EBUSY is returned.

Since only a reference to SPI device is required, we can remove the
spi_set_drvdata() call and get the SPI device object from the base device
object in the suspend/resume routines.

Signed-off-by: Alexandru Ardelean <aardelean@deviqon.com>
Link: https://lore.kernel.org/r/20210625140137.362282-2-aardelean@deviqon.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/accel/bma220_spi.c