public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Christian Marangi <ansuelsmth@gmail.com>
Subject: [PATCH 3/3] leds: leds-lp5569: Enable chip after chip configuration
Date: Thu,  4 Jul 2024 03:55:42 +0200	[thread overview]
Message-ID: <20240704015543.14495-3-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20240704015543.14495-1-ansuelsmth@gmail.com>

Documentation say that clock internal config needs to be set BEFORE chip
is enabled. Align code to this and move the CHIP enable after the CHIP
is configured.

While at it also make use of STATUS reg and check when STARTUP is
completed instead of sleep for 1-2 ms.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 drivers/leds/leds-lp5569.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-lp5569.c b/drivers/leds/leds-lp5569.c
index 2b4f358bc63a..cd1a189c542f 100644
--- a/drivers/leds/leds-lp5569.c
+++ b/drivers/leds/leds-lp5569.c
@@ -7,6 +7,7 @@
 #include <linux/delay.h>
 #include <linux/firmware.h>
 #include <linux/i2c.h>
+#include <linux/iopoll.h>
 #include <linux/leds.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
@@ -91,6 +92,8 @@
 #define LP5569_ENG2_MUX_ADDR		0xd0
 #define LP5569_ENG3_MUX_ADDR		0xe0
 
+#define LP5569_STARTUP_SLEEP		500
+
 #define LEDn_STATUS_FAULT(n, status)	((status) >> (n) & BIT(0))
 
 #define LP5569_DEFAULT_CONFIG \
@@ -170,13 +173,6 @@ static int lp5569_post_init_device(struct lp55xx_chip *chip)
 	int ret;
 	int val;
 
-	ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
-	if (ret)
-		return ret;
-
-	/* Chip startup time is 500 us, 1 - 2 ms gives some margin */
-	usleep_range(1000, 2000);
-
 	val = LP5569_DEFAULT_CONFIG;
 	val |= FIELD_PREP(LP5569_CP_MODE_MASK, chip->pdata->charge_pump_mode);
 	ret = lp55xx_write(chip, LP5569_REG_MISC, val);
@@ -198,6 +194,13 @@ static int lp5569_post_init_device(struct lp55xx_chip *chip)
 			return ret;
 	}
 
+	ret = lp55xx_write(chip, LP5569_REG_ENABLE, LP5569_ENABLE);
+	if (ret)
+		return ret;
+
+	read_poll_timeout(lp55xx_read, ret, !(val & LP5569_STARTUP_BUSY),
+			  LP5569_STARTUP_SLEEP, LP5569_STARTUP_SLEEP * 10, false,
+			  chip, LP5569_REG_STATUS, &val);
 
 	return lp5569_init_program_engine(chip);
 }
-- 
2.45.2


  parent reply	other threads:[~2024-07-04  1:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-04  1:55 [PATCH 1/3] leds: leds-lp5569: Fix typo in driver name Christian Marangi
2024-07-04  1:55 ` [PATCH 2/3] leds: leds-lp5569: Better handle enabling clock internal setting Christian Marangi
2024-07-04  1:55 ` Christian Marangi [this message]
2024-07-11 15:51 ` [PATCH 1/3] leds: leds-lp5569: Fix typo in driver name Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240704015543.14495-3-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox