15
15
#define OMNIA_BOARD_LEDS 12
16
16
#define OMNIA_LED_NUM_CHANNELS 3
17
17
18
- /* MCU controller commands at I2C address 0x2a */
19
- #define OMNIA_MCU_I2C_ADDR 0x2a
20
-
21
- #define CMD_GET_STATUS_WORD 0x01
22
- #define STS_FEATURES_SUPPORTED BIT(2)
23
-
24
- #define CMD_GET_FEATURES 0x10
25
- #define FEAT_LED_GAMMA_CORRECTION BIT(5)
26
-
27
- /* LED controller commands at I2C address 0x2b */
28
- #define CMD_LED_MODE 0x03
29
- #define CMD_LED_MODE_LED (l ) ((l) & 0x0f)
30
- #define CMD_LED_MODE_USER 0x10
31
-
32
- #define CMD_LED_STATE 0x04
33
- #define CMD_LED_STATE_LED (l ) ((l) & 0x0f)
34
- #define CMD_LED_STATE_ON 0x10
35
-
36
- #define CMD_LED_COLOR 0x05
37
- #define CMD_LED_SET_BRIGHTNESS 0x07
38
- #define CMD_LED_GET_BRIGHTNESS 0x08
39
-
40
- #define CMD_SET_GAMMA_CORRECTION 0x30
41
- #define CMD_GET_GAMMA_CORRECTION 0x31
18
+ /* MCU controller I2C address 0x2a, needed for detecting MCU features */
19
+ #define OMNIA_MCU_I2C_ADDR 0x2a
42
20
43
21
struct omnia_led {
44
22
struct led_classdev_mc mc_cdev ;
@@ -59,7 +37,7 @@ struct omnia_leds {
59
37
60
38
static int omnia_cmd_set_color (const struct i2c_client * client , u8 led , u8 r , u8 g , u8 b )
61
39
{
62
- u8 buf [5 ] = { CMD_LED_COLOR , led , r , g , b };
40
+ u8 buf [5 ] = { OMNIA_CMD_LED_COLOR , led , r , g , b };
63
41
64
42
return omnia_cmd_write (client , buf , sizeof (buf ));
65
43
}
@@ -126,12 +104,12 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev,
126
104
* is not being blinked by HW.
127
105
*/
128
106
if (!err && !led -> hwtrig && !brightness != !led -> on ) {
129
- u8 state = CMD_LED_STATE_LED (led -> reg );
107
+ u8 state = OMNIA_CMD_LED_STATE_LED (led -> reg );
130
108
131
109
if (brightness )
132
- state |= CMD_LED_STATE_ON ;
110
+ state |= OMNIA_CMD_LED_STATE_ON ;
133
111
134
- err = omnia_cmd_write_u8 (leds -> client , CMD_LED_STATE , state );
112
+ err = omnia_cmd_write_u8 (leds -> client , OMNIA_CMD_LED_STATE , state );
135
113
if (!err )
136
114
led -> on = !!brightness ;
137
115
}
@@ -166,8 +144,8 @@ static int omnia_hwtrig_activate(struct led_classdev *cdev)
166
144
167
145
if (!err ) {
168
146
/* Put the LED into MCU controlled mode */
169
- err = omnia_cmd_write_u8 (leds -> client , CMD_LED_MODE ,
170
- CMD_LED_MODE_LED (led -> reg ));
147
+ err = omnia_cmd_write_u8 (leds -> client , OMNIA_CMD_LED_MODE ,
148
+ OMNIA_CMD_LED_MODE_LED (led -> reg ));
171
149
if (!err )
172
150
led -> hwtrig = true;
173
151
}
@@ -188,9 +166,8 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
188
166
led -> hwtrig = false;
189
167
190
168
/* Put the LED into software mode */
191
- err = omnia_cmd_write_u8 (leds -> client , CMD_LED_MODE ,
192
- CMD_LED_MODE_LED (led -> reg ) |
193
- CMD_LED_MODE_USER );
169
+ err = omnia_cmd_write_u8 (leds -> client , OMNIA_CMD_LED_MODE ,
170
+ OMNIA_CMD_LED_MODE_LED (led -> reg ) | OMNIA_CMD_LED_MODE_USER );
194
171
195
172
mutex_unlock (& leds -> lock );
196
173
@@ -257,18 +234,16 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
257
234
cdev -> default_trigger = omnia_hw_trigger .name ;
258
235
259
236
/* put the LED into software mode */
260
- ret = omnia_cmd_write_u8 (client , CMD_LED_MODE ,
261
- CMD_LED_MODE_LED (led -> reg ) |
262
- CMD_LED_MODE_USER );
237
+ ret = omnia_cmd_write_u8 (client , OMNIA_CMD_LED_MODE , OMNIA_CMD_LED_MODE_LED (led -> reg ) |
238
+ OMNIA_CMD_LED_MODE_USER );
263
239
if (ret ) {
264
240
dev_err (dev , "Cannot set LED %pOF to software mode: %i\n" , np ,
265
241
ret );
266
242
return ret ;
267
243
}
268
244
269
245
/* disable the LED */
270
- ret = omnia_cmd_write_u8 (client , CMD_LED_STATE ,
271
- CMD_LED_STATE_LED (led -> reg ));
246
+ ret = omnia_cmd_write_u8 (client , OMNIA_CMD_LED_STATE , OMNIA_CMD_LED_STATE_LED (led -> reg ));
272
247
if (ret ) {
273
248
dev_err (dev , "Cannot set LED %pOF brightness: %i\n" , np , ret );
274
249
return ret ;
@@ -310,7 +285,7 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a,
310
285
u8 reply ;
311
286
int err ;
312
287
313
- err = omnia_cmd_read_u8 (client , CMD_LED_GET_BRIGHTNESS , & reply );
288
+ err = omnia_cmd_read_u8 (client , OMNIA_CMD_GET_BRIGHTNESS , & reply );
314
289
if (err < 0 )
315
290
return err ;
316
291
@@ -330,7 +305,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a,
330
305
if (brightness > 100 )
331
306
return - EINVAL ;
332
307
333
- err = omnia_cmd_write_u8 (client , CMD_LED_SET_BRIGHTNESS , brightness );
308
+ err = omnia_cmd_write_u8 (client , OMNIA_CMD_SET_BRIGHTNESS , brightness );
334
309
335
310
return err ?: count ;
336
311
}
@@ -345,7 +320,7 @@ static ssize_t gamma_correction_show(struct device *dev,
345
320
int err ;
346
321
347
322
if (leds -> has_gamma_correction ) {
348
- err = omnia_cmd_read_u8 (client , CMD_GET_GAMMA_CORRECTION , & reply );
323
+ err = omnia_cmd_read_u8 (client , OMNIA_CMD_GET_GAMMA_CORRECTION , & reply );
349
324
if (err < 0 )
350
325
return err ;
351
326
}
@@ -368,7 +343,7 @@ static ssize_t gamma_correction_store(struct device *dev,
368
343
if (kstrtobool (buf , & val ) < 0 )
369
344
return - EINVAL ;
370
345
371
- err = omnia_cmd_write_u8 (client , CMD_SET_GAMMA_CORRECTION , val );
346
+ err = omnia_cmd_write_u8 (client , OMNIA_CMD_SET_GAMMA_CORRECTION , val );
372
347
373
348
return err ?: count ;
374
349
}
@@ -386,15 +361,15 @@ static int omnia_mcu_get_features(const struct i2c_client *mcu_client)
386
361
u16 reply ;
387
362
int err ;
388
363
389
- err = omnia_cmd_read_u16 (mcu_client , CMD_GET_STATUS_WORD , & reply );
364
+ err = omnia_cmd_read_u16 (mcu_client , OMNIA_CMD_GET_STATUS_WORD , & reply );
390
365
if (err )
391
366
return err ;
392
367
393
- /* Check whether MCU firmware supports the CMD_GET_FEAUTRES command */
394
- if (!(reply & STS_FEATURES_SUPPORTED ))
368
+ /* Check whether MCU firmware supports the OMNIA_CMD_GET_FEAUTRES command */
369
+ if (!(reply & OMNIA_STS_FEATURES_SUPPORTED ))
395
370
return 0 ;
396
371
397
- err = omnia_cmd_read_u16 (mcu_client , CMD_GET_FEATURES , & reply );
372
+ err = omnia_cmd_read_u16 (mcu_client , OMNIA_CMD_GET_FEATURES , & reply );
398
373
if (err )
399
374
return err ;
400
375
@@ -459,7 +434,7 @@ static int omnia_leds_probe(struct i2c_client *client)
459
434
return ret ;
460
435
}
461
436
462
- leds -> has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION ;
437
+ leds -> has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION ;
463
438
if (!leds -> has_gamma_correction ) {
464
439
dev_info (dev ,
465
440
"Your board's MCU firmware does not support the LED gamma correction feature.\n" );
@@ -490,7 +465,7 @@ static int omnia_leds_probe(struct i2c_client *client)
490
465
static void omnia_leds_remove (struct i2c_client * client )
491
466
{
492
467
/* put all LEDs into default (HW triggered) mode */
493
- omnia_cmd_write_u8 (client , CMD_LED_MODE , CMD_LED_MODE_LED (OMNIA_BOARD_LEDS ));
468
+ omnia_cmd_write_u8 (client , OMNIA_CMD_LED_MODE , OMNIA_CMD_LED_MODE_LED (OMNIA_BOARD_LEDS ));
494
469
495
470
/* set all LEDs color to [255, 255, 255] */
496
471
omnia_cmd_set_color (client , OMNIA_BOARD_LEDS , 255 , 255 , 255 );
0 commit comments