21
21
#include <zephyr/dt-bindings/led/led.h>
22
22
23
23
LOG_MODULE_REGISTER (is31fl319x , CONFIG_LED_LOG_LEVEL );
24
+ #define REG_NOT_DEFINED 0xff
25
+
26
+ struct is31f1319x_model {
27
+ const uint8_t prod_id_reg ;
28
+ const uint8_t shutdown_reg ;
29
+ const uint8_t conf_reg ;
30
+ const uint8_t current_reg ;
31
+ const uint8_t update_reg ;
32
+
33
+ const uint8_t prod_id_val ;
34
+ const uint8_t shutdown_reg_val ;
35
+ const uint8_t conf_enable ;
36
+ const uint8_t update_val ;
37
+
38
+ const uint8_t led_channels [];
39
+ };
40
+
24
41
25
42
#define IS31FL3194_PROD_ID_REG 0x00
26
43
#define IS31FL3194_CONF_REG 0x01
@@ -36,17 +53,30 @@ LOG_MODULE_REGISTER(is31fl319x, CONFIG_LED_LOG_LEVEL);
36
53
37
54
#define IS31FL3194_CHANNEL_COUNT 3
38
55
39
- static const uint8_t led_channels [] = {
40
- IS31FL3194_OUT1_REG ,
41
- IS31FL3194_OUT2_REG ,
42
- IS31FL3194_OUT3_REG
43
- };
56
+ static const struct is31f1319x_model is31f13194_model = {
57
+ /* register indexes */
58
+ .prod_id_reg = IS31FL3194_PROD_ID_REG ,
59
+ .shutdown_reg = REG_NOT_DEFINED ,
60
+ .conf_reg = IS31FL3194_CONF_REG ,
61
+ .current_reg = IS31FL3194_CURRENT_REG ,
62
+ .update_reg = IS31FL3194_UPDATE_REG ,
63
+
64
+ /* values for those registers */
65
+ .prod_id_val = IS31FL3194_PROD_ID_VAL ,
66
+ .shutdown_reg_val = 0 ,
67
+ .conf_enable = IS31FL3194_CONF_ENABLE ,
68
+ .update_val = IS31FL3194_UPDATE_VAL ,
69
+
70
+ /* channel output registers */
71
+ .led_channels = {IS31FL3194_OUT1_REG , IS31FL3194_OUT2_REG , IS31FL3194_OUT3_REG }};
44
72
45
73
struct is31fl319x_config {
46
74
struct i2c_dt_spec bus ;
75
+ uint8_t channel_count ;
47
76
uint8_t num_leds ;
48
77
const struct led_info * led_infos ;
49
78
const uint8_t * current_limits ;
79
+ const struct is31f1319x_model * regs ;
50
80
};
51
81
52
82
static const struct led_info * is31fl319x_led_to_info (const struct is31fl319x_config * config ,
@@ -79,21 +109,22 @@ static int is31fl319x_set_color(const struct device *dev, uint32_t led, uint8_t
79
109
{
80
110
const struct is31fl319x_config * config = dev -> config ;
81
111
const struct led_info * info = is31fl319x_led_to_info (config , led );
112
+ const struct is31f1319x_model * regs = config -> regs ;
82
113
int ret ;
83
114
84
115
if (info == NULL ) {
85
116
return - ENODEV ;
86
117
}
87
118
88
- if (info -> num_colors != 3 ) {
119
+ if (info -> num_colors > config -> channel_count ) {
89
120
return - ENOTSUP ;
90
121
}
91
122
92
- if (num_colors != 3 ) {
93
- return - EINVAL ;
123
+ if (num_colors > config -> channel_count ) {
124
+ return - ENOTSUP ;
94
125
}
95
126
96
- for (int i = 0 ; i < 3 ; i ++ ) {
127
+ for (int i = 0 ; i < num_colors ; i ++ ) {
97
128
uint8_t value ;
98
129
99
130
switch (info -> color_mapping [i ]) {
@@ -111,16 +142,16 @@ static int is31fl319x_set_color(const struct device *dev, uint32_t led, uint8_t
111
142
return - EINVAL ;
112
143
}
113
144
114
- ret = i2c_reg_write_byte_dt (& config -> bus , led_channels [i ], value );
145
+ ret = i2c_reg_write_byte_dt (& config -> bus , regs -> led_channels [i ], value );
115
146
if (ret != 0 ) {
116
147
break ;
117
148
}
118
149
}
119
150
120
151
if (ret == 0 ) {
121
152
ret = i2c_reg_write_byte_dt (& config -> bus ,
122
- IS31FL3194_UPDATE_REG ,
123
- IS31FL3194_UPDATE_VAL );
153
+ regs -> update_reg ,
154
+ regs -> update_val );
124
155
}
125
156
126
157
if (ret != 0 ) {
@@ -134,6 +165,8 @@ static int is31fl319x_set_brightness(const struct device *dev, uint32_t led, uin
134
165
{
135
166
const struct is31fl319x_config * config = dev -> config ;
136
167
const struct led_info * info = is31fl319x_led_to_info (config , led );
168
+ const struct is31f1319x_model * regs = config -> regs ;
169
+
137
170
int ret = 0 ;
138
171
139
172
if (info == NULL ) {
@@ -147,11 +180,11 @@ static int is31fl319x_set_brightness(const struct device *dev, uint32_t led, uin
147
180
/* Rescale 0..100 to 0..255 */
148
181
value = value * 255 / LED_BRIGHTNESS_MAX ;
149
182
150
- ret = i2c_reg_write_byte_dt (& config -> bus , led_channels [led ], value );
183
+ ret = i2c_reg_write_byte_dt (& config -> bus , regs -> led_channels [led ], value );
151
184
if (ret == 0 ) {
152
185
ret = i2c_reg_write_byte_dt (& config -> bus ,
153
- IS31FL3194_UPDATE_REG ,
154
- IS31FL3194_UPDATE_VAL );
186
+ regs -> update_reg ,
187
+ regs -> update_val );
155
188
}
156
189
157
190
if (ret != 0 ) {
@@ -246,6 +279,7 @@ static int is31fl319x_init(const struct device *dev)
246
279
{
247
280
const struct is31fl319x_config * config = dev -> config ;
248
281
const struct led_info * info = NULL ;
282
+ const struct is31f1319x_model * regs = config -> regs ;
249
283
int i , ret ;
250
284
uint8_t prod_id , band ;
251
285
uint8_t current_reg = 0 ;
@@ -260,15 +294,15 @@ static int is31fl319x_init(const struct device *dev)
260
294
return - ENODEV ;
261
295
}
262
296
263
- ret = i2c_reg_read_byte_dt (& config -> bus , IS31FL3194_PROD_ID_REG , & prod_id );
297
+ ret = i2c_reg_read_byte_dt (& config -> bus , regs -> prod_id_reg , & prod_id );
264
298
if (ret != 0 ) {
265
299
LOG_ERR ("%s: failed to read product ID" , dev -> name );
266
300
return ret ;
267
301
}
268
302
269
- if (prod_id != IS31FL3194_PROD_ID_VAL ) {
303
+ if (prod_id != regs -> prod_id_val ) {
270
304
LOG_ERR ("%s: invalid product ID 0x%02x (expected 0x%02x)" , dev -> name , prod_id ,
271
- IS31FL3194_PROD_ID_VAL );
305
+ regs -> prod_id_val );
272
306
return - ENODEV ;
273
307
}
274
308
@@ -295,7 +329,8 @@ static int is31fl319x_init(const struct device *dev)
295
329
}
296
330
297
331
/* enable device */
298
- return i2c_reg_write_byte_dt (& config -> bus , IS31FL3194_CONF_REG , IS31FL3194_CONF_ENABLE );
332
+ return i2c_reg_write_byte_dt (& config -> bus , regs -> conf_reg ,
333
+ regs -> conf_enable );
299
334
}
300
335
301
336
static DEVICE_API (led , is31fl319x_led_api ) = {
@@ -318,28 +353,31 @@ static DEVICE_API(led, is31fl319x_led_api) = {
318
353
#define LED_CURRENT (led_node_id ) \
319
354
DT_PROP(led_node_id, current_limit),
320
355
321
- #define IS31FL319X_DEVICE (n , id ) \
356
+ #define IS31FL319X_DEVICE (n , id , nchannels , pregs ) \
322
357
\
323
358
DT_INST_FOREACH_CHILD(n, COLOR_MAPPING) \
324
359
\
325
360
static const struct led_info is31fl319##id##_leds_##n[] = \
326
- { DT_INST_FOREACH_CHILD(n, LED_INFO) }; \
361
+ { DT_INST_FOREACH_CHILD(n, LED_INFO) }; \
327
362
\
328
363
static const uint8_t is31fl319##id##_currents_##n[] = \
329
364
{ DT_INST_FOREACH_CHILD(n, LED_CURRENT) }; \
330
365
BUILD_ASSERT(ARRAY_SIZE(is31fl319##id##_leds_##n) > 0, \
331
366
"No LEDs defined for " #n); \
332
367
\
333
368
static const struct is31fl319x_config is31fl319##id##_config_##n = { \
334
- .bus = I2C_DT_SPEC_INST_GET(n), \
369
+ .bus = I2C_DT_SPEC_INST_GET(n), \
370
+ .channel_count = nchannels, \
335
371
.num_leds = ARRAY_SIZE(is31fl319##id##_leds_##n), \
336
372
.led_infos = is31fl319##id##_leds_##n, \
337
373
.current_limits = is31fl319##id##_currents_##n, \
374
+ .regs = pregs, \
338
375
}; \
339
- DEVICE_DT_INST_DEFINE(n, &is31fl319x_init, NULL, NULL, \
340
- &is31fl319##id##_config_##n, POST_KERNEL, \
376
+ DEVICE_DT_INST_DEFINE(n, &is31fl319x_init, NULL, NULL, \
377
+ &is31fl319##id##_config_##n, POST_KERNEL, \
341
378
CONFIG_LED_INIT_PRIORITY, &is31fl319x_led_api);
342
379
343
380
#undef DT_DRV_COMPAT
344
381
#define DT_DRV_COMPAT issi_is31fl3194
345
- DT_INST_FOREACH_STATUS_OKAY_VARGS (IS31FL319X_DEVICE , 4 )
382
+ DT_INST_FOREACH_STATUS_OKAY_VARGS (IS31FL319X_DEVICE , 4 , IS31FL3194_CHANNEL_COUNT ,
383
+ & is31f13194_model )
0 commit comments