Skip to content

Commit 5d2f883

Browse files
elkablolag-linaro
authored andcommitted
leds: turris-omnia: Use global header for MCU command definitions
The global turris-omnia-mcu-interface.h header file contains the definitions for MCU commands. Drop the driver-internal definitions and use the global ones. Signed-off-by: Marek Behún <kabel@kernel.org> Link: https://lore.kernel.org/r/20241111100355.6978-5-kabel@kernel.org Signed-off-by: Lee Jones <lee@kernel.org>
1 parent d665d7f commit 5d2f883

File tree

1 file changed

+23
-48
lines changed

1 file changed

+23
-48
lines changed

drivers/leds/leds-turris-omnia.c

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,8 @@
1515
#define OMNIA_BOARD_LEDS 12
1616
#define OMNIA_LED_NUM_CHANNELS 3
1717

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
4220

4321
struct omnia_led {
4422
struct led_classdev_mc mc_cdev;
@@ -59,7 +37,7 @@ struct omnia_leds {
5937

6038
static int omnia_cmd_set_color(const struct i2c_client *client, u8 led, u8 r, u8 g, u8 b)
6139
{
62-
u8 buf[5] = { CMD_LED_COLOR, led, r, g, b };
40+
u8 buf[5] = { OMNIA_CMD_LED_COLOR, led, r, g, b };
6341

6442
return omnia_cmd_write(client, buf, sizeof(buf));
6543
}
@@ -126,12 +104,12 @@ static int omnia_led_brightness_set_blocking(struct led_classdev *cdev,
126104
* is not being blinked by HW.
127105
*/
128106
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);
130108

131109
if (brightness)
132-
state |= CMD_LED_STATE_ON;
110+
state |= OMNIA_CMD_LED_STATE_ON;
133111

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);
135113
if (!err)
136114
led->on = !!brightness;
137115
}
@@ -166,8 +144,8 @@ static int omnia_hwtrig_activate(struct led_classdev *cdev)
166144

167145
if (!err) {
168146
/* 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));
171149
if (!err)
172150
led->hwtrig = true;
173151
}
@@ -188,9 +166,8 @@ static void omnia_hwtrig_deactivate(struct led_classdev *cdev)
188166
led->hwtrig = false;
189167

190168
/* 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);
194171

195172
mutex_unlock(&leds->lock);
196173

@@ -257,18 +234,16 @@ static int omnia_led_register(struct i2c_client *client, struct omnia_led *led,
257234
cdev->default_trigger = omnia_hw_trigger.name;
258235

259236
/* 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);
263239
if (ret) {
264240
dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np,
265241
ret);
266242
return ret;
267243
}
268244

269245
/* 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));
272247
if (ret) {
273248
dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret);
274249
return ret;
@@ -310,7 +285,7 @@ static ssize_t brightness_show(struct device *dev, struct device_attribute *a,
310285
u8 reply;
311286
int err;
312287

313-
err = omnia_cmd_read_u8(client, CMD_LED_GET_BRIGHTNESS, &reply);
288+
err = omnia_cmd_read_u8(client, OMNIA_CMD_GET_BRIGHTNESS, &reply);
314289
if (err < 0)
315290
return err;
316291

@@ -330,7 +305,7 @@ static ssize_t brightness_store(struct device *dev, struct device_attribute *a,
330305
if (brightness > 100)
331306
return -EINVAL;
332307

333-
err = omnia_cmd_write_u8(client, CMD_LED_SET_BRIGHTNESS, brightness);
308+
err = omnia_cmd_write_u8(client, OMNIA_CMD_SET_BRIGHTNESS, brightness);
334309

335310
return err ?: count;
336311
}
@@ -345,7 +320,7 @@ static ssize_t gamma_correction_show(struct device *dev,
345320
int err;
346321

347322
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);
349324
if (err < 0)
350325
return err;
351326
}
@@ -368,7 +343,7 @@ static ssize_t gamma_correction_store(struct device *dev,
368343
if (kstrtobool(buf, &val) < 0)
369344
return -EINVAL;
370345

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);
372347

373348
return err ?: count;
374349
}
@@ -386,15 +361,15 @@ static int omnia_mcu_get_features(const struct i2c_client *mcu_client)
386361
u16 reply;
387362
int err;
388363

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);
390365
if (err)
391366
return err;
392367

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))
395370
return 0;
396371

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);
398373
if (err)
399374
return err;
400375

@@ -459,7 +434,7 @@ static int omnia_leds_probe(struct i2c_client *client)
459434
return ret;
460435
}
461436

462-
leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION;
437+
leds->has_gamma_correction = ret & OMNIA_FEAT_LED_GAMMA_CORRECTION;
463438
if (!leds->has_gamma_correction) {
464439
dev_info(dev,
465440
"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)
490465
static void omnia_leds_remove(struct i2c_client *client)
491466
{
492467
/* 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));
494469

495470
/* set all LEDs color to [255, 255, 255] */
496471
omnia_cmd_set_color(client, OMNIA_BOARD_LEDS, 255, 255, 255);

0 commit comments

Comments
 (0)