Lines Matching +full:led +full:- +full:6

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Simple USB RGB LED driver
6 * Based on drivers/hid/hid-thingm.c and
16 #include "hid-ids.h"
32 /* R+2G+4B -> riso kagaku color index */
38 [5] = 6, /* magenta */
39 [6] = 4, /* cyan */
117 mutex_lock(&ldev->lock); in hidled_send()
123 memcpy(ldev->buf, buf, ldev->config->report_size); in hidled_send()
125 if (ldev->config->report_type == RAW_REQUEST) in hidled_send()
126 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf, in hidled_send()
127 ldev->config->report_size, in hidled_send()
130 else if (ldev->config->report_type == OUTPUT_REPORT) in hidled_send()
131 ret = hid_hw_output_report(ldev->hdev, ldev->buf, in hidled_send()
132 ldev->config->report_size); in hidled_send()
134 ret = -EINVAL; in hidled_send()
136 mutex_unlock(&ldev->lock); in hidled_send()
141 return ret == ldev->config->report_size ? 0 : -EMSGSIZE; in hidled_send()
149 if (ldev->config->report_type != RAW_REQUEST) in hidled_recv()
150 return -EINVAL; in hidled_recv()
152 mutex_lock(&ldev->lock); in hidled_recv()
154 memcpy(ldev->buf, buf, ldev->config->report_size); in hidled_recv()
156 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf, in hidled_recv()
157 ldev->config->report_size, in hidled_recv()
163 ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf, in hidled_recv()
164 ldev->config->report_size, in hidled_recv()
168 memcpy(buf, ldev->buf, ldev->config->report_size); in hidled_recv()
170 mutex_unlock(&ldev->lock); in hidled_recv()
179 r = rgb->red.cdev.brightness; in riso_kagaku_index()
180 g = rgb->green.cdev.brightness; in riso_kagaku_index()
181 b = rgb->blue.cdev.brightness; in riso_kagaku_index()
191 struct hidled_led *led = to_hidled_led(cdev); in riso_kagaku_write() local
192 struct hidled_rgb *rgb = led->rgb; in riso_kagaku_write()
197 return hidled_send(rgb->ldev, buf); in riso_kagaku_write()
202 struct hidled_led *led = to_hidled_led(cdev); in dream_cheeky_write() local
203 struct hidled_rgb *rgb = led->rgb; in dream_cheeky_write()
206 buf[1] = rgb->red.cdev.brightness; in dream_cheeky_write()
207 buf[2] = rgb->green.cdev.brightness; in dream_cheeky_write()
208 buf[3] = rgb->blue.cdev.brightness; in dream_cheeky_write()
212 return hidled_send(rgb->ldev, buf); in dream_cheeky_write()
232 struct hidled_led *led = to_hidled_led(cdev); in _thingm_write() local
235 buf[2] = led->rgb->red.cdev.brightness; in _thingm_write()
236 buf[3] = led->rgb->green.cdev.brightness; in _thingm_write()
237 buf[4] = led->rgb->blue.cdev.brightness; in _thingm_write()
238 buf[7] = led->rgb->num + offset; in _thingm_write()
240 return hidled_send(led->rgb->ldev, buf); in _thingm_write()
274 ldev->config = &hidled_config_thingm_v1; in thingm_init()
279 static inline int delcom_get_lednum(const struct hidled_led *led) in delcom_get_lednum() argument
281 if (led == &led->rgb->red) in delcom_get_lednum()
283 else if (led == &led->rgb->green) in delcom_get_lednum()
289 static int delcom_enable_led(struct hidled_led *led) in delcom_enable_led() argument
293 dp.tx.data_lsb = 1 << delcom_get_lednum(led); in delcom_enable_led()
296 return hidled_send(led->rgb->ldev, dp.data); in delcom_enable_led()
299 static int delcom_set_pwm(struct hidled_led *led) in delcom_set_pwm() argument
303 dp.tx.data_lsb = delcom_get_lednum(led); in delcom_set_pwm()
304 dp.tx.data_msb = led->cdev.brightness; in delcom_set_pwm()
306 return hidled_send(led->rgb->ldev, dp.data); in delcom_set_pwm()
311 struct hidled_led *led = to_hidled_led(cdev); in delcom_write() local
315 * enable LED in delcom_write()
319 ret = delcom_enable_led(led); in delcom_write()
323 return delcom_set_pwm(led); in delcom_write()
338 return le16_to_cpu(dp.fw.family_code) == 2 ? 0 : -ENODEV; in delcom_init()
343 struct hidled_led *led = to_hidled_led(cdev); in luxafor_write() local
346 buf[2] = led->rgb->num + 1; in luxafor_write()
347 buf[3] = led->rgb->red.cdev.brightness; in luxafor_write()
348 buf[4] = led->rgb->green.cdev.brightness; in luxafor_write()
349 buf[5] = led->rgb->blue.cdev.brightness; in luxafor_write()
351 return hidled_send(led->rgb->ldev, buf); in luxafor_write()
361 .report_size = 6,
403 .num_leds = 6,
410 static int hidled_init_led(struct hidled_led *led, const char *color_name, in hidled_init_led() argument
413 const struct hidled_config *config = rgb->ldev->config; in hidled_init_led()
415 if (config->num_leds > 1) in hidled_init_led()
416 snprintf(led->name, sizeof(led->name), "%s%u:%s:led%u", in hidled_init_led()
417 config->short_name, minor, color_name, rgb->num); in hidled_init_led()
419 snprintf(led->name, sizeof(led->name), "%s%u:%s", in hidled_init_led()
420 config->short_name, minor, color_name); in hidled_init_led()
421 led->cdev.name = led->name; in hidled_init_led()
422 led->cdev.max_brightness = config->max_brightness; in hidled_init_led()
423 led->cdev.brightness_set_blocking = config->write; in hidled_init_led()
424 led->cdev.flags = LED_HW_PLUGGABLE; in hidled_init_led()
425 led->rgb = rgb; in hidled_init_led()
427 return devm_led_classdev_register(&rgb->ldev->hdev->dev, &led->cdev); in hidled_init_led()
435 ret = hidled_init_led(&rgb->red, "red", rgb, minor); in hidled_init_rgb()
440 ret = hidled_init_led(&rgb->green, "green", rgb, minor); in hidled_init_rgb()
445 return hidled_init_led(&rgb->blue, "blue", rgb, minor); in hidled_init_rgb()
454 ldev = devm_kzalloc(&hdev->dev, sizeof(*ldev), GFP_KERNEL); in hidled_probe()
456 return -ENOMEM; in hidled_probe()
458 ldev->buf = devm_kmalloc(&hdev->dev, MAX_REPORT_SIZE, GFP_KERNEL); in hidled_probe()
459 if (!ldev->buf) in hidled_probe()
460 return -ENOMEM; in hidled_probe()
466 ldev->hdev = hdev; in hidled_probe()
467 mutex_init(&ldev->lock); in hidled_probe()
469 for (i = 0; !ldev->config && i < ARRAY_SIZE(hidled_configs); i++) in hidled_probe()
470 if (hidled_configs[i].type == id->driver_data) in hidled_probe()
471 ldev->config = &hidled_configs[i]; in hidled_probe()
473 if (!ldev->config) in hidled_probe()
474 return -EINVAL; in hidled_probe()
476 if (ldev->config->init) { in hidled_probe()
477 ret = ldev->config->init(ldev); in hidled_probe()
482 ldev->rgb = devm_kcalloc(&hdev->dev, ldev->config->num_leds, in hidled_probe()
484 if (!ldev->rgb) in hidled_probe()
485 return -ENOMEM; in hidled_probe()
491 minor = ((struct hidraw *) hdev->hidraw)->minor; in hidled_probe()
493 for (i = 0; i < ldev->config->num_leds; i++) { in hidled_probe()
494 ldev->rgb[i].ldev = ldev; in hidled_probe()
495 ldev->rgb[i].num = i; in hidled_probe()
496 ret = hidled_init_rgb(&ldev->rgb[i], minor); in hidled_probe()
503 hid_info(hdev, "%s initialized\n", ldev->config->name); in hidled_probe()
526 .name = "hid-led",
535 MODULE_DESCRIPTION("Simple USB RGB LED driver");