Lines Matching +full:1 +full:br +full:- +full:100
1 // SPDX-License-Identifier: GPL-2.0-only
6 * Based on drivers/hid/hid-thingm.c and
16 #include "hid-ids.h"
32 /* R+2G+4B -> riso kagaku color index */
34 [1] = 2, /* red */
35 [2] = 1, /* green */
43 #define RISO_KAGAKU_IX(r, g, b) riso_kagaku_tbl[((r)?1:0)+((g)?2:0)+((b)?4:0)]
64 #define DELCOM_RED_LED 1
79 int (*write)(struct led_classdev *cdev, enum led_brightness br);
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()
189 static int riso_kagaku_write(struct led_classdev *cdev, enum led_brightness br) in riso_kagaku_write() argument
192 struct hidled_rgb *rgb = led->rgb; in riso_kagaku_write()
195 buf[1] = riso_kagaku_index(rgb); in riso_kagaku_write()
197 return hidled_send(rgb->ldev, buf); in riso_kagaku_write()
200 static int dream_cheeky_write(struct led_classdev *cdev, enum led_brightness br) in dream_cheeky_write() argument
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()
220 buf[1] = 0x1f; in dream_cheeky_init()
229 static int _thingm_write(struct led_classdev *cdev, enum led_brightness br, in _thingm_write() argument
233 __u8 buf[MAX_REPORT_SIZE] = { 1, 'c' }; in _thingm_write()
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()
243 static int thingm_write_v1(struct led_classdev *cdev, enum led_brightness br) in thingm_write_v1() argument
245 return _thingm_write(cdev, br, 0); in thingm_write_v1()
248 static int thingm_write(struct led_classdev *cdev, enum led_brightness br) in thingm_write() argument
250 return _thingm_write(cdev, br, 1); in thingm_write()
254 .name = "ThingM blink(1) v1",
257 .num_leds = 1,
265 __u8 buf[MAX_REPORT_SIZE] = { 1, 'v' }; in thingm_init()
272 /* Check for firmware major version 1 */ in thingm_init()
273 if (buf[3] == '1') in thingm_init()
274 ldev->config = &hidled_config_thingm_v1; in thingm_init()
281 if (led == &led->rgb->red) in delcom_get_lednum()
283 else if (led == &led->rgb->green) in delcom_get_lednum()
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()
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()
309 static int delcom_write(struct led_classdev *cdev, enum led_brightness br) in delcom_write() argument
338 return le16_to_cpu(dp.fw.family_code) == 2 ? 0 : -ENODEV; in delcom_init()
341 static int luxafor_write(struct led_classdev *cdev, enum led_brightness br) in luxafor_write() argument
344 __u8 buf[MAX_REPORT_SIZE] = { [1] = 1 }; in luxafor_write()
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()
359 .max_brightness = 1,
360 .num_leds = 1,
370 .num_leds = 1,
378 .name = "ThingM blink(1)",
391 .max_brightness = 100,
392 .num_leds = 1,
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",