Skip to content

Commit 409a9dc

Browse files
Ansuellag-linaro
authored andcommitted
leds: leds-lp55xx: Generalize load_engine_and_select_page function
Generalize load_engine_and_select_page by reworking the implementation and making it part of the generic load_engine function. Add a new option in device_config, pages_per_engine used to define pages assigned to each engine. With this option set, it's assumed LED chip supports pages and load_engine will correctly setup the write page. An equal amount of pages is assigned to each engine and they are assigned from page 0. Update any lp55xx based LED driver to define the option and use the new function. Suggested-by: Lee Jones <lee@kernel.org> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com> Link: https://lore.kernel.org/r/20240626160027.19703-7-ansuelsmth@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 4d310b9 commit 409a9dc

4 files changed

Lines changed: 21 additions & 33 deletions

File tree

drivers/leds/leds-lp5523.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* 0x40 engine 2 muxing info
3131
* 0x50 engine 3 muxing info
3232
*/
33+
#define LP5523_PAGES_PER_ENGINE 1
3334
#define LP5523_MAX_LEDS 9
3435

3536
/* Registers */
@@ -159,20 +160,6 @@ static int lp5523_post_init_device(struct lp55xx_chip *chip)
159160
return lp5523_init_program_engine(chip);
160161
}
161162

162-
static void lp5523_load_engine_and_select_page(struct lp55xx_chip *chip)
163-
{
164-
enum lp55xx_engine_index idx = chip->engine_idx;
165-
static const u8 page_sel[] = {
166-
[LP55XX_ENGINE_1] = LP5523_PAGE_ENG1,
167-
[LP55XX_ENGINE_2] = LP5523_PAGE_ENG2,
168-
[LP55XX_ENGINE_3] = LP5523_PAGE_ENG3,
169-
};
170-
171-
lp55xx_load_engine(chip);
172-
173-
lp55xx_write(chip, LP5523_REG_PROG_PAGE_SEL, page_sel[idx]);
174-
}
175-
176163
static void lp5523_stop_engine(struct lp55xx_chip *chip)
177164
{
178165
enum lp55xx_engine_index idx = chip->engine_idx;
@@ -272,7 +259,7 @@ static int lp5523_init_program_engine(struct lp55xx_chip *chip)
272259
/* write LED MUX address space for each engine */
273260
for (i = LP55XX_ENGINE_1; i <= LP55XX_ENGINE_3; i++) {
274261
chip->engine_idx = i;
275-
lp5523_load_engine_and_select_page(chip);
262+
lp55xx_load_engine(chip);
276263

277264
for (j = 0; j < LP5523_PROGRAM_LENGTH; j++) {
278265
ret = lp55xx_write(chip, LP5523_REG_PROG_MEM + j,
@@ -362,7 +349,7 @@ static void lp5523_firmware_loaded(struct lp55xx_chip *chip)
362349
* 2) write firmware data into program memory
363350
*/
364351

365-
lp5523_load_engine_and_select_page(chip);
352+
lp55xx_load_engine(chip);
366353
lp5523_update_program_memory(chip, fw->data, fw->size);
367354
}
368355

@@ -544,7 +531,7 @@ static ssize_t store_engine_load(struct device *dev,
544531
mutex_lock(&chip->lock);
545532

546533
chip->engine_idx = nr;
547-
lp5523_load_engine_and_select_page(chip);
534+
lp55xx_load_engine(chip);
548535
ret = lp5523_update_program_memory(chip, buf, len);
549536

550537
mutex_unlock(&chip->lock);
@@ -865,6 +852,7 @@ static struct lp55xx_device_config lp5523_cfg = {
865852
.addr = LP5523_REG_ENABLE,
866853
.val = LP5523_ENABLE,
867854
},
855+
.pages_per_engine = LP5523_PAGES_PER_ENGINE,
868856
.max_channel = LP5523_MAX_LEDS,
869857
.post_init_device = lp5523_post_init_device,
870858
.brightness_fn = lp5523_led_brightness,

drivers/leds/leds-lp55xx-common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
#define LP55xx_MODE_ENGn_GET(n, mode, shift) \
4747
(((mode) >> LP55xx_MODE_ENGn_SHIFT(n, shift)) & LP55xx_MODE_ENG_MASK)
4848

49+
/* Memory Page Selection */
50+
#define LP55xx_REG_PROG_PAGE_SEL 0x4f
51+
/* If supported, each ENGINE have an equal amount of pages offset from page 0 */
52+
#define LP55xx_PAGE_OFFSET(n, pages) (((n) - 1) * (pages))
53+
4954
/* External clock rate */
5055
#define LP55XX_CLK_32K 32768
5156

@@ -104,6 +109,11 @@ void lp55xx_load_engine(struct lp55xx_chip *chip)
104109

105110
lp55xx_update_bits(chip, cfg->reg_op_mode.addr, mask, val);
106111
lp55xx_wait_opmode_done(chip);
112+
113+
/* Setup PAGE if supported (pages_per_engine not 0)*/
114+
if (cfg->pages_per_engine)
115+
lp55xx_write(chip, LP55xx_REG_PROG_PAGE_SEL,
116+
LP55xx_PAGE_OFFSET(idx, cfg->pages_per_engine));
107117
}
108118
EXPORT_SYMBOL_GPL(lp55xx_load_engine);
109119

drivers/leds/leds-lp55xx-common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ struct lp55xx_reg {
9999
* (if not supported 153 us sleep)
100100
* @reset : Chip specific reset command
101101
* @enable : Chip specific enable command
102+
* @pages_per_engine : Assigned pages for each engine
103+
* (if not set chip doesn't support pages)
102104
* @max_channel : Maximum number of channels
103105
* @post_init_device : Chip specific initialization code
104106
* @brightness_fn : Brightness function
@@ -113,6 +115,7 @@ struct lp55xx_device_config {
113115
const struct lp55xx_reg engine_busy; /* addr, mask */
114116
const struct lp55xx_reg reset;
115117
const struct lp55xx_reg enable;
118+
const int pages_per_engine;
116119
const int max_channel;
117120

118121
/* define if the device has specific initialization process */

drivers/leds/leds-lp8501.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "leds-lp55xx-common.h"
2222

2323
#define LP8501_PROGRAM_LENGTH 32
24+
#define LP8501_PAGES_PER_ENGINE 1
2425
#define LP8501_MAX_LEDS 9
2526

2627
/* Registers */
@@ -116,21 +117,6 @@ static int lp8501_post_init_device(struct lp55xx_chip *chip)
116117
LP8501_PWR_CONFIG_M, chip->pdata->pwr_sel);
117118
}
118119

119-
static void lp8501_load_engine(struct lp55xx_chip *chip)
120-
{
121-
enum lp55xx_engine_index idx = chip->engine_idx;
122-
123-
static const u8 page_sel[] = {
124-
[LP55XX_ENGINE_1] = LP8501_PAGE_ENG1,
125-
[LP55XX_ENGINE_2] = LP8501_PAGE_ENG2,
126-
[LP55XX_ENGINE_3] = LP8501_PAGE_ENG3,
127-
};
128-
129-
lp55xx_load_engine(chip);
130-
131-
lp55xx_write(chip, LP8501_REG_PROG_PAGE_SEL, page_sel[idx]);
132-
}
133-
134120
static void lp8501_turn_off_channels(struct lp55xx_chip *chip)
135121
{
136122
int i;
@@ -250,7 +236,7 @@ static void lp8501_firmware_loaded(struct lp55xx_chip *chip)
250236
* 2) write firmware data into program memory
251237
*/
252238

253-
lp8501_load_engine(chip);
239+
lp55xx_load_engine(chip);
254240
lp8501_update_program_memory(chip, fw->data, fw->size);
255241
}
256242

@@ -284,6 +270,7 @@ static struct lp55xx_device_config lp8501_cfg = {
284270
.addr = LP8501_REG_ENABLE,
285271
.val = LP8501_ENABLE,
286272
},
273+
.pages_per_engine = LP8501_PAGES_PER_ENGINE,
287274
.max_channel = LP8501_MAX_LEDS,
288275
.post_init_device = lp8501_post_init_device,
289276
.brightness_fn = lp8501_led_brightness,

0 commit comments

Comments
 (0)