Lines Matching +full:led +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/led-class-multicolor.h>
27 /* LED controller commands at I2C address 0x2b */
91 return -EIO; in omnia_cmd_read_raw()
99 err = omnia_cmd_read_raw(client->adapter, client->addr, cmd, &reply, 1); in omnia_cmd_read_u8()
107 struct omnia_led *led) in omnia_led_send_color_cmd() argument
113 cmd[1] = led->reg; in omnia_led_send_color_cmd()
114 cmd[2] = led->subled_info[0].brightness; in omnia_led_send_color_cmd()
115 cmd[3] = led->subled_info[1].brightness; in omnia_led_send_color_cmd()
116 cmd[4] = led->subled_info[2].brightness; in omnia_led_send_color_cmd()
125 led->cached_channels[i] = led->subled_info[i].brightness; in omnia_led_send_color_cmd()
131 static bool omnia_led_channels_changed(struct omnia_led *led) in omnia_led_channels_changed() argument
134 if (led->subled_info[i].brightness != led->cached_channels[i]) in omnia_led_channels_changed()
144 struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); in omnia_led_brightness_set_blocking()
145 struct omnia_led *led = to_omnia_led(mc_cdev); in omnia_led_brightness_set_blocking() local
148 mutex_lock(&leds->lock); in omnia_led_brightness_set_blocking()
152 * non-zero (if it is zero and the LED is in HW blinking mode, we use in omnia_led_brightness_set_blocking()
157 if (brightness || led->hwtrig) { in omnia_led_brightness_set_blocking()
159 cdev->max_brightness); in omnia_led_brightness_set_blocking()
162 * Send color command only if brightness is non-zero and the RGB in omnia_led_brightness_set_blocking()
165 if (omnia_led_channels_changed(led)) in omnia_led_brightness_set_blocking()
166 err = omnia_led_send_color_cmd(leds->client, led); in omnia_led_brightness_set_blocking()
170 * Send on/off state change only if (bool)brightness changed and the LED in omnia_led_brightness_set_blocking()
173 if (!err && !led->hwtrig && !brightness != !led->on) { in omnia_led_brightness_set_blocking()
174 u8 state = CMD_LED_STATE_LED(led->reg); in omnia_led_brightness_set_blocking()
179 err = omnia_cmd_write_u8(leds->client, CMD_LED_STATE, state); in omnia_led_brightness_set_blocking()
181 led->on = !!brightness; in omnia_led_brightness_set_blocking()
184 mutex_unlock(&leds->lock); in omnia_led_brightness_set_blocking()
194 struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); in omnia_hwtrig_activate()
195 struct omnia_led *led = to_omnia_led(mc_cdev); in omnia_hwtrig_activate() local
198 mutex_lock(&leds->lock); in omnia_hwtrig_activate()
200 if (!led->on) { in omnia_hwtrig_activate()
202 * If the LED is off (brightness was set to 0), the last in omnia_hwtrig_activate()
206 led_mc_calc_color_components(mc_cdev, cdev->max_brightness); in omnia_hwtrig_activate()
208 if (omnia_led_channels_changed(led)) in omnia_hwtrig_activate()
209 err = omnia_led_send_color_cmd(leds->client, led); in omnia_hwtrig_activate()
213 /* Put the LED into MCU controlled mode */ in omnia_hwtrig_activate()
214 err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, in omnia_hwtrig_activate()
215 CMD_LED_MODE_LED(led->reg)); in omnia_hwtrig_activate()
217 led->hwtrig = true; in omnia_hwtrig_activate()
220 mutex_unlock(&leds->lock); in omnia_hwtrig_activate()
227 struct omnia_leds *leds = dev_get_drvdata(cdev->dev->parent); in omnia_hwtrig_deactivate()
228 struct omnia_led *led = to_omnia_led(lcdev_to_mccdev(cdev)); in omnia_hwtrig_deactivate() local
231 mutex_lock(&leds->lock); in omnia_hwtrig_deactivate()
233 led->hwtrig = false; in omnia_hwtrig_deactivate()
235 /* Put the LED into software mode */ in omnia_hwtrig_deactivate()
236 err = omnia_cmd_write_u8(leds->client, CMD_LED_MODE, in omnia_hwtrig_deactivate()
237 CMD_LED_MODE_LED(led->reg) | in omnia_hwtrig_deactivate()
240 mutex_unlock(&leds->lock); in omnia_hwtrig_deactivate()
243 dev_err(cdev->dev, "Cannot put LED to software mode: %i\n", in omnia_hwtrig_deactivate()
248 .name = "omnia-mcu",
254 static int omnia_led_register(struct i2c_client *client, struct omnia_led *led, in omnia_led_register() argument
258 struct device *dev = &client->dev; in omnia_led_register()
262 ret = of_property_read_u32(np, "reg", &led->reg); in omnia_led_register()
263 if (ret || led->reg >= OMNIA_BOARD_LEDS) { in omnia_led_register()
266 np, OMNIA_BOARD_LEDS - 1); in omnia_led_register()
278 led->subled_info[0].color_index = LED_COLOR_ID_RED; in omnia_led_register()
279 led->subled_info[1].color_index = LED_COLOR_ID_GREEN; in omnia_led_register()
280 led->subled_info[2].color_index = LED_COLOR_ID_BLUE; in omnia_led_register()
284 led->subled_info[i].intensity = 255; in omnia_led_register()
285 led->subled_info[i].brightness = 255; in omnia_led_register()
286 led->subled_info[i].channel = i; in omnia_led_register()
289 led->mc_cdev.subled_info = led->subled_info; in omnia_led_register()
290 led->mc_cdev.num_colors = OMNIA_LED_NUM_CHANNELS; in omnia_led_register()
292 init_data.fwnode = &np->fwnode; in omnia_led_register()
294 cdev = &led->mc_cdev.led_cdev; in omnia_led_register()
295 cdev->max_brightness = 255; in omnia_led_register()
296 cdev->brightness_set_blocking = omnia_led_brightness_set_blocking; in omnia_led_register()
297 cdev->trigger_type = &omnia_hw_trigger_type; in omnia_led_register()
299 * Use the omnia-mcu trigger as the default trigger. It may be rewritten in omnia_led_register()
300 * by LED class from the linux,default-trigger property. in omnia_led_register()
302 cdev->default_trigger = omnia_hw_trigger.name; in omnia_led_register()
304 /* put the LED into software mode */ in omnia_led_register()
306 CMD_LED_MODE_LED(led->reg) | in omnia_led_register()
309 dev_err(dev, "Cannot set LED %pOF to software mode: %i\n", np, in omnia_led_register()
314 /* disable the LED */ in omnia_led_register()
316 CMD_LED_STATE_LED(led->reg)); in omnia_led_register()
318 dev_err(dev, "Cannot set LED %pOF brightness: %i\n", np, ret); in omnia_led_register()
323 ret = omnia_led_send_color_cmd(client, led); in omnia_led_register()
325 dev_err(dev, "Cannot set LED %pOF initial color: %i\n", np, in omnia_led_register()
330 ret = devm_led_classdev_multicolor_register_ext(dev, &led->mc_cdev, in omnia_led_register()
333 dev_err(dev, "Cannot register LED %pOF: %i\n", np, ret); in omnia_led_register()
348 * file lives in the device directory of the LED controller, not an individual
349 * LED, so it should not confuse users.
373 return -EINVAL; in brightness_store()
376 return -EINVAL; in brightness_store()
391 if (leds->has_gamma_correction) { in gamma_correction_show()
411 if (!leds->has_gamma_correction) in gamma_correction_store()
412 return -EOPNOTSUPP; in gamma_correction_store()
415 return -EINVAL; in gamma_correction_store()
435 err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, in omnia_mcu_get_features()
444 err = omnia_cmd_read_raw(client->adapter, OMNIA_MCU_I2C_ADDR, in omnia_mcu_get_features()
454 struct device *dev = &client->dev; in omnia_leds_probe()
457 struct omnia_led *led; in omnia_leds_probe() local
463 return -ENODEV; in omnia_leds_probe()
466 return -EINVAL; in omnia_leds_probe()
471 return -ENOMEM; in omnia_leds_probe()
473 leds->client = client; in omnia_leds_probe()
483 leds->has_gamma_correction = ret & FEAT_LED_GAMMA_CORRECTION; in omnia_leds_probe()
484 if (!leds->has_gamma_correction) { in omnia_leds_probe()
486 "Your board's MCU firmware does not support the LED gamma correction feature.\n"); in omnia_leds_probe()
488 "Consider upgrading MCU firmware with the omnia-mcutool utility.\n"); in omnia_leds_probe()
491 mutex_init(&leds->lock); in omnia_leds_probe()
495 dev_err(dev, "Cannot register private LED trigger: %d\n", ret); in omnia_leds_probe()
499 led = &leds->leds[0]; in omnia_leds_probe()
501 ret = omnia_led_register(client, led, child); in omnia_leds_probe()
505 led += ret; in omnia_leds_probe()
515 /* put all LEDs into default (HW triggered) mode */ in omnia_leds_remove()
530 { .compatible = "cznic,turris-omnia-leds", },
546 .name = "leds-turris-omnia",