@@ -38,7 +38,16 @@ struct is31f1319x_model {
38
38
const uint8_t led_channels [];
39
39
};
40
40
41
+ struct is31fl319x_config {
42
+ struct i2c_dt_spec bus ;
43
+ uint8_t channel_count ;
44
+ uint8_t num_leds ;
45
+ const struct led_info * led_infos ;
46
+ const uint8_t * current_limits ;
47
+ const struct is31f1319x_model * regs ;
48
+ };
41
49
50
+ /* IS31FL3194 model registers and values */
42
51
#define IS31FL3194_PROD_ID_REG 0x00
43
52
#define IS31FL3194_CONF_REG 0x01
44
53
#define IS31FL3194_CURRENT_REG 0x03
@@ -53,6 +62,7 @@ struct is31f1319x_model {
53
62
54
63
#define IS31FL3194_CHANNEL_COUNT 3
55
64
65
+ #ifdef CONFIG_IS31FL3194
56
66
static const struct is31f1319x_model is31f13194_model = {
57
67
/* register indexes */
58
68
.prod_id_reg = IS31FL3194_PROD_ID_REG ,
@@ -69,15 +79,44 @@ static const struct is31f1319x_model is31f13194_model = {
69
79
70
80
/* channel output registers */
71
81
.led_channels = {IS31FL3194_OUT1_REG , IS31FL3194_OUT2_REG , IS31FL3194_OUT3_REG }};
82
+ #endif
83
+
84
+ /* IS31FL3197 model registers and values */
85
+ #define IS31FL3197_PROD_ID_REG 0x00
86
+ #define IS31FL3197_SHUTDOWN_REG 0x01
87
+ #define IS31FL3197_OPER_CONFIG_REG 0x02
88
+ #define IS31FL3197_OUT1_REG 0x10
89
+ #define IS31FL3197_OUT2_REG 0x11
90
+ #define IS31FL3197_OUT3_REG 0x12
91
+ #define IS31FL3197_OUT4_REG 0x13
92
+ #define IS31FL3197_UPDATE_REG 0x2b
93
+
94
+ #define IS31FL3197_SHUTDOWN_REG_VAL 0xf1 /* enable all channels */
95
+ #define IS31FL3197_OPER_CONFIG_REG_VAL 0xff /* set all to current level */
96
+ #define IS31FL3197_UPDATE_VAL 0xc5
97
+
98
+ #define IS31FL3197_CHANNEL_COUNT 4
99
+
100
+ #ifdef CONFIG_IS31FL3197
101
+ static const struct is31f1319x_model is31f13197_model = {
102
+ /* register indexes */
103
+ .prod_id_reg = IS31FL3197_PROD_ID_REG ,
104
+ .shutdown_reg = IS31FL3197_SHUTDOWN_REG ,
105
+ .conf_reg = IS31FL3197_OPER_CONFIG_REG ,
106
+ .current_reg = REG_NOT_DEFINED ,
107
+ .update_reg = IS31FL3197_UPDATE_REG ,
72
108
73
- struct is31fl319x_config {
74
- struct i2c_dt_spec bus ;
75
- uint8_t channel_count ;
76
- uint8_t num_leds ;
77
- const struct led_info * led_infos ;
78
- const uint8_t * current_limits ;
79
- const struct is31f1319x_model * regs ;
109
+ /* values for those registers */
110
+ .prod_id_val = 0xff ,
111
+ .shutdown_reg_val = IS31FL3197_SHUTDOWN_REG_VAL ,
112
+ .conf_enable = IS31FL3197_OPER_CONFIG_REG_VAL ,
113
+ .update_val = IS31FL3197_UPDATE_VAL ,
114
+
115
+ /* channel output registers */
116
+ .led_channels = {IS31FL3197_OUT1_REG , IS31FL3197_OUT2_REG , IS31FL3197_OUT3_REG ,
117
+ IS31FL3197_OUT4_REG }
80
118
};
119
+ #endif
81
120
82
121
static const struct led_info * is31fl319x_led_to_info (const struct is31fl319x_config * config ,
83
122
uint32_t led )
@@ -124,7 +163,7 @@ static int is31fl319x_write_channels(const struct device *dev, uint32_t start_ch
124
163
{
125
164
const struct is31fl319x_config * config = dev -> config ;
126
165
const struct is31f1319x_model * regs = config -> regs ;
127
- int ret ;
166
+ int ret = 0 ;
128
167
129
168
if ((start_channel + num_channels ) > config -> channel_count ) {
130
169
return - ENOTSUP ;
@@ -210,10 +249,9 @@ static int is31fl319x_check_config(const struct device *dev)
210
249
const struct is31fl319x_config * config = dev -> config ;
211
250
const struct led_info * info ;
212
251
uint8_t rgb_count = 0 ;
213
- uint8_t i ;
214
252
215
253
/* verify that number of leds defined is not > number of channels */
216
- for (i = 0 ; i < config -> num_leds ; i ++ ) {
254
+ for (int i = 0 ; i < config -> num_leds ; i ++ ) {
217
255
info = & config -> led_infos [i ];
218
256
rgb_count += info -> num_colors ;
219
257
}
@@ -230,7 +268,7 @@ static int is31fl319x_init(const struct device *dev)
230
268
const struct is31fl319x_config * config = dev -> config ;
231
269
const struct led_info * info = NULL ;
232
270
const struct is31f1319x_model * regs = config -> regs ;
233
- int i , j , ret ;
271
+ int ret ;
234
272
uint8_t prod_id , band , channel ;
235
273
uint8_t current_reg = 0 ;
236
274
@@ -250,20 +288,30 @@ static int is31fl319x_init(const struct device *dev)
250
288
return ret ;
251
289
}
252
290
253
- if (prod_id != regs -> prod_id_val ) {
254
- LOG_ERR ("%s: invalid product ID 0x%02x (expected 0x%02x)" , dev -> name , prod_id ,
255
- regs -> prod_id_val );
256
- return - ENODEV ;
291
+ if (regs -> prod_id_val != 0xff ) {
292
+ if (prod_id != regs -> prod_id_val ) {
293
+ LOG_ERR ("%s: invalid product ID 0x%02x (expected 0x%02x)" , dev -> name ,
294
+ prod_id , regs -> prod_id_val );
295
+ return - ENODEV ;
296
+ }
297
+ } else {
298
+
299
+ /* The product ID (8 bit) should be the I2C address(7 bit) */
300
+ if (prod_id != (config -> bus .addr << 1 )) {
301
+ LOG_ERR ("%s: invalid product ID 0x%02x (expected 0x%02x)" , dev -> name ,
302
+ prod_id , config -> bus .addr << 1 );
303
+ return - ENODEV ;
304
+ }
257
305
}
258
306
259
307
/* calc current limit register value */
260
308
if (regs -> current_reg != REG_NOT_DEFINED ) {
261
309
channel = 0 ;
262
- for (i = 0 ; i < config -> num_leds ; i ++ ) {
310
+ for (int i = 0 ; i < config -> num_leds ; i ++ ) {
263
311
info = & config -> led_infos [i ];
264
312
band = (config -> current_limits [i ] / 10 ) - 1 ;
265
313
266
- for (j = 0 ; j < info -> num_colors ; j ++ ) {
314
+ for (int j = 0 ; j < info -> num_colors ; j ++ ) {
267
315
current_reg |= band << (2 * channel );
268
316
channel ++ ;
269
317
}
@@ -275,6 +323,15 @@ static int is31fl319x_init(const struct device *dev)
275
323
return ret ;
276
324
}
277
325
}
326
+ if (regs -> shutdown_reg != REG_NOT_DEFINED ) {
327
+ ret = i2c_reg_write_byte_dt (& config -> bus , regs -> shutdown_reg ,
328
+ regs -> shutdown_reg_val );
329
+ if (ret != 0 ) {
330
+ LOG_ERR ("%s: failed to set current limit" , dev -> name );
331
+ return ret ;
332
+ }
333
+ }
334
+
278
335
/* enable device */
279
336
return i2c_reg_write_byte_dt (& config -> bus , regs -> conf_reg ,
280
337
regs -> conf_enable );
@@ -329,3 +386,8 @@ static DEVICE_API(led, is31fl319x_led_api) = {
329
386
#define DT_DRV_COMPAT issi_is31fl3194
330
387
DT_INST_FOREACH_STATUS_OKAY_VARGS (IS31FL319X_DEVICE , 4 , IS31FL3194_CHANNEL_COUNT ,
331
388
& is31f13194_model )
389
+ #undef DT_DRV_COMPAT
390
+ #define DT_DRV_COMPAT issi_is31fl3197
391
+ DT_INST_FOREACH_STATUS_OKAY_VARGS (IS31FL319X_DEVICE , 7 , IS31FL3194_CHANNEL_COUNT ,
392
+ & is31f13197_model )
393
+ #undef DT_DRV_COMPAT
0 commit comments