[PATCH v3 07/18] iio: accel: bma220: move bma220_power() fct

Petre Rodan posted 18 patches 2 weeks, 5 days ago
[PATCH v3 07/18] iio: accel: bma220: move bma220_power() fct
Posted by Petre Rodan 2 weeks, 5 days ago
Move bma220_power() fct before bma220_init() since it will make the
next patch cleaner.

Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
v2->v3 split from bigger patch (Krzysztof, Jonathan)
---
 drivers/iio/accel/bma220_core.c | 48 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index b6f1374a9cca52966c1055113710061a7284cf5a..dc156fcc1435ace9bda5fabc87864f38ae7bee05 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -203,6 +203,30 @@ static const struct iio_info bma220_info = {
 	.read_avail		= bma220_read_avail,
 };
 
+static int bma220_power(struct spi_device *spi, bool up)
+{
+	int i, ret;
+
+	/**
+	 * The chip can be suspended/woken up by a simple register read.
+	 * So, we need up to 2 register reads of the suspend register
+	 * to make sure that the device is in the desired state.
+	 */
+	for (i = 0; i < 2; i++) {
+		ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
+		if (ret < 0)
+			return ret;
+
+		if (up && ret == BMA220_SUSPEND_SLEEP)
+			return 0;
+
+		if (!up && ret == BMA220_SUSPEND_WAKE)
+			return 0;
+	}
+
+	return -EBUSY;
+}
+
 static int bma220_init(struct spi_device *spi)
 {
 	int ret;
@@ -230,30 +254,6 @@ static int bma220_init(struct spi_device *spi)
 	return 0;
 }
 
-static int bma220_power(struct spi_device *spi, bool up)
-{
-	int i, ret;
-
-	/**
-	 * The chip can be suspended/woken up by a simple register read.
-	 * So, we need up to 2 register reads of the suspend register
-	 * to make sure that the device is in the desired state.
-	 */
-	for (i = 0; i < 2; i++) {
-		ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
-		if (ret < 0)
-			return ret;
-
-		if (up && ret == BMA220_SUSPEND_SLEEP)
-			return 0;
-
-		if (!up && ret == BMA220_SUSPEND_WAKE)
-			return 0;
-	}
-
-	return -EBUSY;
-}
-
 static void bma220_deinit(void *spi)
 {
 	bma220_power(spi, false);

-- 
2.49.1
Re: [PATCH v3 07/18] iio: accel: bma220: move bma220_power() fct
Posted by Andy Shevchenko 2 weeks, 4 days ago
On Sat, Sep 13, 2025 at 6:40 PM Petre Rodan <petre.rodan@subdimension.ro> wrote:
>
> Move bma220_power() fct before bma220_init() since it will make the
> next patch cleaner.

...

> +static int bma220_power(struct spi_device *spi, bool up)
> +{
> +       int i, ret;
> +
> +       /**

It's not a kernel doc, do not inherit the mistakes from the past.

> +        * The chip can be suspended/woken up by a simple register read.
> +        * So, we need up to 2 register reads of the suspend register
> +        * to make sure that the device is in the desired state.
> +        */
> +       for (i = 0; i < 2; i++) {
> +               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
> +               if (ret < 0)
> +                       return ret;
> +
> +               if (up && ret == BMA220_SUSPEND_SLEEP)
> +                       return 0;
> +
> +               if (!up && ret == BMA220_SUSPEND_WAKE)
> +                       return 0;
> +       }
> +
> +       return -EBUSY;
> +}


-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 07/18] iio: accel: bma220: move bma220_power() fct
Posted by Jonathan Cameron 5 days, 2 hours ago
On Sun, 14 Sep 2025 15:05:47 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Sat, Sep 13, 2025 at 6:40 PM Petre Rodan <petre.rodan@subdimension.ro> wrote:
> >
> > Move bma220_power() fct before bma220_init() since it will make the
> > next patch cleaner.  
> 
> ...
> 
> > +static int bma220_power(struct spi_device *spi, bool up)
> > +{
> > +       int i, ret;
> > +
> > +       /**  
> 
> It's not a kernel doc, do not inherit the mistakes from the past.
Agreed.  To keep the series clean I'd do a cleanup of all incorrect instances
of this as a precursor patch.  Then these moves become cleaner.
Otherwise we have a whole load of patch descriptions with little
notes saying 'and fix incorrect kernel-doc markings' and that just
muddies the water!

Jonathan

> 
> > +        * The chip can be suspended/woken up by a simple register read.
> > +        * So, we need up to 2 register reads of the suspend register
> > +        * to make sure that the device is in the desired state.
> > +        */
> > +       for (i = 0; i < 2; i++) {
> > +               ret = bma220_read_reg(spi, BMA220_REG_SUSPEND);
> > +               if (ret < 0)
> > +                       return ret;
> > +
> > +               if (up && ret == BMA220_SUSPEND_SLEEP)
> > +                       return 0;
> > +
> > +               if (!up && ret == BMA220_SUSPEND_WAKE)
> > +                       return 0;
> > +       }
> > +
> > +       return -EBUSY;
> > +}  
> 
>