From: Eddie James <eajames@linux.ibm.com>
To: joel@jms.id.au
Cc: openbmc@lists.ozlabs.org
Subject: [PATCH linux dev-5.10 4/7] leds: pca955x: Add brightness_get function
Date: Thu, 16 Sep 2021 16:21:37 -0500 [thread overview]
Message-ID: <20210916212140.33915-5-eajames@linux.ibm.com> (raw)
In-Reply-To: <20210916212140.33915-1-eajames@linux.ibm.com>
Add a function to fetch the state of the hardware LED.
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
---
drivers/leds/leds-pca955x.c | 52 +++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/drivers/leds/leds-pca955x.c b/drivers/leds/leds-pca955x.c
index f0d841cb59fc..e47ba7c3b7c7 100644
--- a/drivers/leds/leds-pca955x.c
+++ b/drivers/leds/leds-pca955x.c
@@ -233,6 +233,57 @@ static int pca955x_read_ls(struct i2c_client *client, int n, u8 *val)
return 0;
}
+static int pca955x_read_pwm(struct i2c_client *client, int n, u8 *val)
+{
+ struct pca955x *pca955x = i2c_get_clientdata(client);
+ u8 cmd = pca95xx_num_input_regs(pca955x->chipdef->bits) + 1 + (2 * n);
+ int ret;
+
+ ret = i2c_smbus_read_byte_data(client, cmd);
+ if (ret < 0) {
+ dev_err(&client->dev, "%s: reg 0x%x, err %d\n",
+ __func__, n, ret);
+ return ret;
+ }
+ *val = (u8)ret;
+ return 0;
+}
+
+static enum led_brightness pca955x_led_get(struct led_classdev *led_cdev)
+{
+ struct pca955x_led *pca955x_led = container_of(led_cdev,
+ struct pca955x_led,
+ led_cdev);
+ struct pca955x *pca955x = pca955x_led->pca955x;
+ u8 ls, pwm;
+ int ret;
+
+ ret = pca955x_read_ls(pca955x->client, pca955x_led->led_num / 4, &ls);
+ if (ret)
+ return ret;
+
+ ls = (ls >> ((pca955x_led->led_num % 4) << 1)) & 0x3;
+ switch (ls) {
+ case PCA955X_LS_LED_ON:
+ ret = LED_FULL;
+ break;
+ case PCA955X_LS_LED_OFF:
+ ret = LED_OFF;
+ break;
+ case PCA955X_LS_BLINK0:
+ ret = LED_HALF;
+ break;
+ case PCA955X_LS_BLINK1:
+ ret = pca955x_read_pwm(pca955x->client, 1, &pwm);
+ if (ret)
+ return ret;
+ ret = 255 - pwm;
+ break;
+ }
+
+ return ret;
+}
+
static int pca955x_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
@@ -512,6 +563,7 @@ static int pca955x_probe(struct i2c_client *client,
led->name = pca955x_led->name;
led->brightness_set_blocking = pca955x_led_set;
+ led->brightness_get = pca955x_led_get;
err = devm_led_classdev_register(&client->dev, led);
if (err)
--
2.27.0
next prev parent reply other threads:[~2021-09-16 21:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-16 21:21 [PATCH linux dev-5.10 0/7] leds: Support retaining state for the PCA955x Eddie James
2021-09-16 21:21 ` [PATCH linux dev-5.10 1/7] dt-bindings: leds: Add retain-state-shutdown boolean Eddie James
2021-09-16 21:21 ` [PATCH linux dev-5.10 2/7] leds: leds-core: Implement the retain-state-shutdown property Eddie James
2021-09-16 21:21 ` [PATCH linux dev-5.10 3/7] leds: pca955x: Clean up code formatting Eddie James
2021-09-16 21:21 ` Eddie James [this message]
2021-09-16 21:21 ` [PATCH linux dev-5.10 5/7] leds: pca955x: Implement the default-state property Eddie James
2021-09-16 21:21 ` [PATCH linux dev-5.10 6/7] leds: pca955x: Let the core process the fwnode Eddie James
2021-09-16 21:21 ` [PATCH linux dev-5.10 7/7] leds: pca955x: Switch to i2c probe_new Eddie James
2021-09-22 2:21 ` [PATCH linux dev-5.10 0/7] leds: Support retaining state for the PCA955x Joel Stanley
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=20210916212140.33915-5-eajames@linux.ibm.com \
--to=eajames@linux.ibm.com \
--cc=joel@jms.id.au \
--cc=openbmc@lists.ozlabs.org \
/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;
as well as URLs for NNTP newsgroup(s).