From: Christian Marangi <ansuelsmth@gmail.com>
To: Pavel Machek <pavel@ucw.cz>, Lee Jones <lee@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Christian Marangi <ansuelsmth@gmail.com>
Subject: [PATCH v6 18/20] leds: leds-lp55xx: support ENGINE program up to 128 bytes
Date: Sun, 16 Jun 2024 23:52:17 +0200 [thread overview]
Message-ID: <20240616215226.2112-19-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20240616215226.2112-1-ansuelsmth@gmail.com>
Some LED chip supports up to 16 pages and with some magic they can be
divided in 4 page for each ENGINE + 1 for each MUX. Following this we
can support bigger programs up to 128 bytes.
Rework the update_program_memory function to support program of multiple
pages instead of hardcoding it to one page per programs.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/leds/leds-lp5523.c | 5 ++-
drivers/leds/leds-lp5562.c | 7 ++--
drivers/leds/leds-lp55xx-common.c | 54 ++++++++++++++++++++++++-------
drivers/leds/leds-lp55xx-common.h | 2 ++
4 files changed, 49 insertions(+), 19 deletions(-)
diff --git a/drivers/leds/leds-lp5523.c b/drivers/leds/leds-lp5523.c
index 6f25a6c32869..1d00c6cc4174 100644
--- a/drivers/leds/leds-lp5523.c
+++ b/drivers/leds/leds-lp5523.c
@@ -21,7 +21,6 @@
#include "leds-lp55xx-common.h"
-#define LP5523_PROGRAM_LENGTH 32 /* bytes */
/* Memory is used like this:
* 0x00 engine 1 program
* 0x10 engine 2 program
@@ -172,7 +171,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
int ret;
u8 status;
/* one pattern per engine setting LED MUX start and stop addresses */
- static const u8 pattern[][LP5523_PROGRAM_LENGTH] = {
+ static const u8 pattern[][LP55xx_BYTES_PER_PAGE] = {
{ 0x9c, 0x30, 0x9c, 0xb0, 0x9d, 0x80, 0xd8, 0x00, 0},
{ 0x9c, 0x40, 0x9c, 0xc0, 0x9d, 0x80, 0xd8, 0x00, 0},
{ 0x9c, 0x50, 0x9c, 0xd0, 0x9d, 0x80, 0xd8, 0x00, 0},
@@ -196,7 +195,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
chip->engine_idx = i;
lp55xx_load_engine(chip);
- for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) {
+ for (j = 0; j < LP55xx_BYTES_PER_PAGE; j++) {
ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j,
pattern[i - 1][j]);
if (ret)
diff --git a/drivers/leds/leds-lp5562.c b/drivers/leds/leds-lp5562.c
index e50b68c9ccf3..109162f1720f 100644
--- a/drivers/leds/leds-lp5562.c
+++ b/drivers/leds/leds-lp5562.c
@@ -19,7 +19,6 @@
#include "leds-lp55xx-common.h"
-#define LP5562_PROGRAM_LENGTH 32
#define LP5562_MAX_LEDS 4
/* ENABLE Register 00h */
@@ -212,9 +211,9 @@ static void lp5562_write_program_memory(struct lp55xx_chip *chip,
/* check the size of program count */
static inline bool _is_pc_overflow(struct lp55xx_predef_pattern *ptn)
{
- return ptn->size_r >= LP5562_PROGRAM_LENGTH ||
- ptn->size_g >= LP5562_PROGRAM_LENGTH ||
- ptn->size_b >= LP5562_PROGRAM_LENGTH;
+ return ptn->size_r >= LP55xx_BYTES_PER_PAGE ||
+ ptn->size_g >= LP55xx_BYTES_PER_PAGE ||
+ ptn->size_b >= LP55xx_BYTES_PER_PAGE;
}
static int lp5562_run_predef_led_pattern(struct lp55xx_chip *chip, int mode)
diff --git a/drivers/leds/leds-lp55xx-common.c b/drivers/leds/leds-lp55xx-common.c
index 62f5d6e8087c..04c713e7fb00 100644
--- a/drivers/leds/leds-lp55xx-common.c
+++ b/drivers/leds/leds-lp55xx-common.c
@@ -27,7 +27,8 @@
/* OP MODE require at least 153 us to clear regs */
#define LP55XX_CMD_SLEEP 200
-#define LP55xx_PROGRAM_LENGTH 32
+#define LP55xx_PROGRAM_PAGES 16
+#define LP55xx_MAX_PROGRAM_LENGTH (LP55xx_BYTES_PER_PAGE * 4) /* 128 bytes (4 pages) */
/*
* Program Memory Operations
@@ -174,12 +175,16 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip,
{
enum lp55xx_engine_index idx = chip->engine_idx;
const struct lp55xx_device_config *cfg = chip->cfg;
- u8 pattern[LP55xx_PROGRAM_LENGTH] = { };
+ u8 pattern[LP55xx_MAX_PROGRAM_LENGTH] = { };
u8 start_addr = cfg->prog_mem_base.addr;
- int i = 0, offset = 0;
- int ret;
+ int page, i = 0, offset = 0;
+ int program_length, ret;
+
+ program_length = LP55xx_BYTES_PER_PAGE;
+ if (cfg->pages_per_engine)
+ program_length *= cfg->pages_per_engine;
- while ((offset < size - 1) && (i < LP55xx_PROGRAM_LENGTH)) {
+ while ((offset < size - 1) && (i < program_length)) {
unsigned int cmd;
int nrchars;
char c[3];
@@ -208,12 +213,20 @@ int lp55xx_update_program_memory(struct lp55xx_chip *chip,
* For LED chip that support page, PAGE is already set in load_engine.
*/
if (!cfg->pages_per_engine)
- start_addr += LP55xx_PROGRAM_LENGTH * idx;
+ start_addr += LP55xx_BYTES_PER_PAGE * idx;
- for (i = 0; i < LP55xx_PROGRAM_LENGTH; i++) {
- ret = lp55xx_write(chip, start_addr + i, pattern[i]);
- if (ret)
- return -EINVAL;
+ for (page = 0; page < program_length / LP55xx_BYTES_PER_PAGE; page++) {
+ /* Write to the next page each 32 bytes (if supported) */
+ if (cfg->pages_per_engine)
+ lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL,
+ LP55xx_PAGE_OFFSET(idx, cfg->pages_per_engine) + page);
+
+ for (i = 0; i < LP55xx_BYTES_PER_PAGE; i++) {
+ ret = lp55xx_write(chip, start_addr + i,
+ pattern[i + (page * LP55xx_BYTES_PER_PAGE)]);
+ if (ret)
+ return -EINVAL;
+ }
}
return size;
@@ -226,13 +239,19 @@ EXPORT_SYMBOL_GPL(lp55xx_update_program_memory);
void lp55xx_firmware_loaded_cb(struct lp55xx_chip *chip)
{
+ const struct lp55xx_device_config *cfg = chip->cfg;
const struct firmware *fw = chip->fw;
+ int program_length;
+
+ program_length = LP55xx_BYTES_PER_PAGE;
+ if (cfg->pages_per_engine)
+ program_length *= cfg->pages_per_engine;
/*
* the firmware is encoded in ascii hex character, with 2 chars
* per byte
*/
- if (fw->size > LP55xx_PROGRAM_LENGTH * 2) {
+ if (fw->size > program_length * 2) {
dev_err(&chip->cl->dev, "firmware data size overflow: %zu\n",
fw->size);
return;
@@ -1283,7 +1302,7 @@ static struct lp55xx_platform_data *lp55xx_of_populate_pdata(struct device *dev,
int lp55xx_probe(struct i2c_client *client)
{
const struct i2c_device_id *id = i2c_client_get_device_id(client);
- int ret;
+ int program_length, ret;
struct lp55xx_chip *chip;
struct lp55xx_led *led;
struct lp55xx_platform_data *pdata = dev_get_platdata(&client->dev);
@@ -1307,6 +1326,17 @@ int lp55xx_probe(struct i2c_client *client)
}
}
+ /* Validate max program page */
+ program_length = LP55xx_BYTES_PER_PAGE;
+ if (chip->cfg->pages_per_engine)
+ program_length *= chip->cfg->pages_per_engine;
+
+ /* support a max of 128bytes */
+ if (program_length > LP55xx_MAX_PROGRAM_LENGTH) {
+ dev_err(&client->dev, "invalid pages_per_engine configured\n");
+ return -EINVAL;
+ }
+
led = devm_kcalloc(&client->dev,
pdata->num_channels, sizeof(*led), GFP_KERNEL);
if (!led)
diff --git a/drivers/leds/leds-lp55xx-common.h b/drivers/leds/leds-lp55xx-common.h
index 063d7392b6a2..5e1f7fea5985 100644
--- a/drivers/leds/leds-lp55xx-common.h
+++ b/drivers/leds/leds-lp55xx-common.h
@@ -14,6 +14,8 @@
#include <linux/led-class-multicolor.h>
+#define LP55xx_BYTES_PER_PAGE 32 /* bytes */
+
enum lp55xx_engine_index {
LP55XX_ENGINE_INVALID,
LP55XX_ENGINE_1,
--
2.43.0
next prev parent reply other threads:[~2024-06-16 21:56 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-16 21:51 [PATCH v6 00/20] leds: leds-lp55xx: overhaul driver Christian Marangi
2024-06-16 21:52 ` [PATCH v6 01/20] dt-bindings: leds-lp55xx: limit pwr-sel property to ti,lp8501 Christian Marangi
2024-06-16 21:52 ` [PATCH v6 02/20] dt-bindings: leds-lp55xx: Add new ti,lp5569 compatible Christian Marangi
2024-06-16 21:52 ` [PATCH v6 03/20] leds: leds-lp55xx: generalize stop_all_engine OP Christian Marangi
2024-06-16 21:52 ` [PATCH v6 04/20] leds: leds-lp55xx: generalize probe/remove functions Christian Marangi
2024-06-20 15:38 ` Lee Jones
2024-06-16 21:52 ` [PATCH v6 05/20] leds: leds-lp55xx: generalize load_engine function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 06/20] leds: leds-lp55xx: generalize load_engine_and_select_page function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 07/20] leds: leds-lp55xx: generalize run_engine function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 08/20] leds: leds-lp55xx: generalize update_program_memory function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 09/20] leds: leds-lp55xx: generalize firmware_loaded function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 10/20] leds: leds-lp55xx: generalize led_brightness function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 11/20] leds: leds-lp55xx: generalize multicolor_brightness function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 12/20] leds: leds-lp55xx: generalize set_led_current function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 13/20] leds: leds-lp55xx: generalize turn_off_channels function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 14/20] leds: leds-lp55xx: generalize stop_engine function Christian Marangi
2024-06-16 21:52 ` [PATCH v6 15/20] leds: leds-lp55xx: generalize sysfs engine_load and engine_mode Christian Marangi
2024-06-16 21:52 ` [PATCH v6 16/20] leds: leds-lp55xx: generalize sysfs engine_leds Christian Marangi
2024-06-16 21:52 ` [PATCH v6 17/20] leds: leds-lp55xx: generalize sysfs master_fader Christian Marangi
2024-06-16 21:52 ` Christian Marangi [this message]
2024-06-16 21:52 ` [PATCH v6 19/20] leds: leds-lp55xx: drop deprecated defines Christian Marangi
2024-06-16 21:52 ` [PATCH v6 20/20] leds: leds-lp5569: Add support for Texas Instruments LP5569 Christian Marangi
2024-06-20 16:03 ` Lee Jones
2024-06-20 16:09 ` [PATCH v6 00/20] leds: leds-lp55xx: overhaul driver Lee Jones
2024-06-20 15:15 ` Christian Marangi
2024-06-20 16:57 ` Lee Jones
2024-06-20 16:49 ` Lee Jones
2024-06-20 15:57 ` Christian Marangi
2024-06-20 17:30 ` 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=20240616215226.2112-19-ansuelsmth@gmail.com \
--to=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jacek.anaszewski@gmail.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=robh@kernel.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).