Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Simple USB RGB LED driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2016 Heiner Kallweit <hkallweit1@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Based on drivers/hid/hid-thingm.c and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * drivers/usb/misc/usbled.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/hidraw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/leds.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) enum hidled_report_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	RAW_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	OUTPUT_REPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) enum hidled_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	RISO_KAGAKU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	DREAM_CHEEKY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	THINGM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	DELCOM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	LUXAFOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static unsigned const char riso_kagaku_tbl[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /* R+2G+4B -> riso kagaku color index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	[0] = 0, /* black   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	[1] = 2, /* red     */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	[2] = 1, /* green   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	[3] = 5, /* yellow  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	[4] = 3, /* blue    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	[5] = 6, /* magenta */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	[6] = 4, /* cyan    */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	[7] = 7  /* white   */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define RISO_KAGAKU_IX(r, g, b) riso_kagaku_tbl[((r)?1:0)+((g)?2:0)+((b)?4:0)]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) union delcom_packet {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	__u8 data[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		__u8 major_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		__u8 minor_cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		__u8 data_lsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		__u8 data_msb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	} tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		__u8 cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	} rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		__le16 family_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		__le16 security_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		__u8 fw_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	} fw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #define DELCOM_GREEN_LED	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define DELCOM_RED_LED		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #define DELCOM_BLUE_LED		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) struct hidled_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) struct hidled_rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) struct hidled_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	enum hidled_type	type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	const char		*name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	const char		*short_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	enum led_brightness	max_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int			num_leds;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	size_t			report_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	enum hidled_report_type	report_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	int (*init)(struct hidled_device *ldev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	int (*write)(struct led_classdev *cdev, enum led_brightness br);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) struct hidled_led {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct led_classdev	cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	struct hidled_rgb	*rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	char			name[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) struct hidled_rgb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	struct hidled_device	*ldev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct hidled_led	red;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct hidled_led	green;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct hidled_led	blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	u8			num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) struct hidled_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	const struct hidled_config *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	struct hid_device       *hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct hidled_rgb	*rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	u8			*buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct mutex		lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define MAX_REPORT_SIZE		16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #define to_hidled_led(arg) container_of(arg, struct hidled_led, cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static bool riso_kagaku_switch_green_blue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) module_param(riso_kagaku_switch_green_blue, bool, S_IRUGO | S_IWUSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) MODULE_PARM_DESC(riso_kagaku_switch_green_blue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	"switch green and blue RGB component for Riso Kagaku devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int hidled_send(struct hidled_device *ldev, __u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	mutex_lock(&ldev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	 * buffer provided to hid_hw_raw_request must not be on the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	 * and must not be part of a data structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	memcpy(ldev->buf, buf, ldev->config->report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (ldev->config->report_type == RAW_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 					 ldev->config->report_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 					 HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 					 HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	else if (ldev->config->report_type == OUTPUT_REPORT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ret = hid_hw_output_report(ldev->hdev, ldev->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 					   ldev->config->report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	mutex_unlock(&ldev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	return ret == ldev->config->report_size ? 0 : -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* reading data is supported for report type RAW_REQUEST only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static int hidled_recv(struct hidled_device *ldev, __u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (ldev->config->report_type != RAW_REQUEST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	mutex_lock(&ldev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	memcpy(ldev->buf, buf, ldev->config->report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				 ldev->config->report_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				 HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				 HID_REQ_SET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	ret = hid_hw_raw_request(ldev->hdev, buf[0], ldev->buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				 ldev->config->report_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 				 HID_FEATURE_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				 HID_REQ_GET_REPORT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	memcpy(buf, ldev->buf, ldev->config->report_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	mutex_unlock(&ldev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return ret < 0 ? ret : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static u8 riso_kagaku_index(struct hidled_rgb *rgb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	enum led_brightness r, g, b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	r = rgb->red.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	g = rgb->green.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	b = rgb->blue.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (riso_kagaku_switch_green_blue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return RISO_KAGAKU_IX(r, b, g);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return RISO_KAGAKU_IX(r, g, b);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static int riso_kagaku_write(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct hidled_led *led = to_hidled_led(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct hidled_rgb *rgb = led->rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	__u8 buf[MAX_REPORT_SIZE] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	buf[1] = riso_kagaku_index(rgb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	return hidled_send(rgb->ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) static int dream_cheeky_write(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	struct hidled_led *led = to_hidled_led(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	struct hidled_rgb *rgb = led->rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	__u8 buf[MAX_REPORT_SIZE] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	buf[1] = rgb->red.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	buf[2] = rgb->green.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	buf[3] = rgb->blue.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	buf[7] = 0x1a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	buf[8] = 0x05;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return hidled_send(rgb->ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) static int dream_cheeky_init(struct hidled_device *ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	__u8 buf[MAX_REPORT_SIZE] = {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* Dream Cheeky magic */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	buf[1] = 0x1f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	buf[2] = 0x02;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	buf[4] = 0x5f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	buf[7] = 0x1a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	buf[8] = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return hidled_send(ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static int _thingm_write(struct led_classdev *cdev, enum led_brightness br,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			 u8 offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct hidled_led *led = to_hidled_led(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	__u8 buf[MAX_REPORT_SIZE] = { 1, 'c' };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	buf[2] = led->rgb->red.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	buf[3] = led->rgb->green.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	buf[4] = led->rgb->blue.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	buf[7] = led->rgb->num + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	return hidled_send(led->rgb->ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static int thingm_write_v1(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	return _thingm_write(cdev, br, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int thingm_write(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	return _thingm_write(cdev, br, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static const struct hidled_config hidled_config_thingm_v1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	.name = "ThingM blink(1) v1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	.short_name = "thingm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	.max_brightness = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	.num_leds = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	.report_size = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	.report_type = RAW_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	.write = thingm_write_v1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static int thingm_init(struct hidled_device *ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	__u8 buf[MAX_REPORT_SIZE] = { 1, 'v' };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	ret = hidled_recv(ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* Check for firmware major version 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	if (buf[3] == '1')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		ldev->config = &hidled_config_thingm_v1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) static inline int delcom_get_lednum(const struct hidled_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	if (led == &led->rgb->red)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		return DELCOM_RED_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	else if (led == &led->rgb->green)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		return DELCOM_GREEN_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		return DELCOM_BLUE_LED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) static int delcom_enable_led(struct hidled_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	union delcom_packet dp = { .tx.major_cmd = 101, .tx.minor_cmd = 12 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	dp.tx.data_lsb = 1 << delcom_get_lednum(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	dp.tx.data_msb = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return hidled_send(led->rgb->ldev, dp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int delcom_set_pwm(struct hidled_led *led)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	union delcom_packet dp = { .tx.major_cmd = 101, .tx.minor_cmd = 34 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	dp.tx.data_lsb = delcom_get_lednum(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	dp.tx.data_msb = led->cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	return hidled_send(led->rgb->ldev, dp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) static int delcom_write(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	struct hidled_led *led = to_hidled_led(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	 * enable LED
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	 * We can't do this in the init function already because the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	 * is internally reset later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	ret = delcom_enable_led(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	return delcom_set_pwm(led);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) static int delcom_init(struct hidled_device *ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	union delcom_packet dp = { .rx.cmd = 104 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ret = hidled_recv(ldev, dp.data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 * Several Delcom devices share the same USB VID/PID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * Check for family id 2 for Visual Signal Indicator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	return le16_to_cpu(dp.fw.family_code) == 2 ? 0 : -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static int luxafor_write(struct led_classdev *cdev, enum led_brightness br)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	struct hidled_led *led = to_hidled_led(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	__u8 buf[MAX_REPORT_SIZE] = { [1] = 1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	buf[2] = led->rgb->num + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	buf[3] = led->rgb->red.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	buf[4] = led->rgb->green.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	buf[5] = led->rgb->blue.cdev.brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return hidled_send(led->rgb->ldev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static const struct hidled_config hidled_configs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		.type = RISO_KAGAKU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		.name = "Riso Kagaku Webmail Notifier",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		.short_name = "riso_kagaku",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		.max_brightness = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		.num_leds = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		.report_size = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		.report_type = OUTPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		.write = riso_kagaku_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		.type = DREAM_CHEEKY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		.name = "Dream Cheeky Webmail Notifier",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		.short_name = "dream_cheeky",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		.max_brightness = 31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		.num_leds = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		.report_size = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		.report_type = RAW_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		.init = dream_cheeky_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		.write = dream_cheeky_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 		.type = THINGM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		.name = "ThingM blink(1)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		.short_name = "thingm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		.max_brightness = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		.num_leds = 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		.report_size = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		.report_type = RAW_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		.init = thingm_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		.write = thingm_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		.type = DELCOM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		.name = "Delcom Visual Signal Indicator G2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		.short_name = "delcom",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 		.max_brightness = 100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		.num_leds = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		.report_size = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		.report_type = RAW_REQUEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		.init = delcom_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		.write = delcom_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		.type = LUXAFOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		.name = "Greynut Luxafor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		.short_name = "luxafor",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		.max_brightness = 255,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		.num_leds = 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		.report_size = 9,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		.report_type = OUTPUT_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		.write = luxafor_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) static int hidled_init_led(struct hidled_led *led, const char *color_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 			   struct hidled_rgb *rgb, unsigned int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	const struct hidled_config *config = rgb->ldev->config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (config->num_leds > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		snprintf(led->name, sizeof(led->name), "%s%u:%s:led%u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 			 config->short_name, minor, color_name, rgb->num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		snprintf(led->name, sizeof(led->name), "%s%u:%s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			 config->short_name, minor, color_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	led->cdev.name = led->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	led->cdev.max_brightness = config->max_brightness;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	led->cdev.brightness_set_blocking = config->write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	led->cdev.flags = LED_HW_PLUGGABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	led->rgb = rgb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	return devm_led_classdev_register(&rgb->ldev->hdev->dev, &led->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static int hidled_init_rgb(struct hidled_rgb *rgb, unsigned int minor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	/* Register the red diode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	ret = hidled_init_led(&rgb->red, "red", rgb, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	/* Register the green diode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	ret = hidled_init_led(&rgb->green, "green", rgb, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	/* Register the blue diode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	return hidled_init_led(&rgb->blue, "blue", rgb, minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) static int hidled_probe(struct hid_device *hdev, const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	struct hidled_device *ldev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	unsigned int minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	ldev = devm_kzalloc(&hdev->dev, sizeof(*ldev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (!ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	ldev->buf = devm_kmalloc(&hdev->dev, MAX_REPORT_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	if (!ldev->buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	ret = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	ldev->hdev = hdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	mutex_init(&ldev->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	for (i = 0; !ldev->config && i < ARRAY_SIZE(hidled_configs); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		if (hidled_configs[i].type == id->driver_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			ldev->config = &hidled_configs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	if (!ldev->config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	if (ldev->config->init) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		ret = ldev->config->init(ldev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	ldev->rgb = devm_kcalloc(&hdev->dev, ldev->config->num_leds,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 				 sizeof(struct hidled_rgb), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (!ldev->rgb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	minor = ((struct hidraw *) hdev->hidraw)->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	for (i = 0; i < ldev->config->num_leds; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		ldev->rgb[i].ldev = ldev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		ldev->rgb[i].num = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		ret = hidled_init_rgb(&ldev->rgb[i], minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 			hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	hid_info(hdev, "%s initialized\n", ldev->config->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) static const struct hid_device_id hidled_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	{ HID_USB_DEVICE(USB_VENDOR_ID_RISO_KAGAKU,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	  USB_DEVICE_ID_RI_KA_WEBMAIL), .driver_data = RISO_KAGAKU },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	  USB_DEVICE_ID_DREAM_CHEEKY_WN), .driver_data = DREAM_CHEEKY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	{ HID_USB_DEVICE(USB_VENDOR_ID_DREAM_CHEEKY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	  USB_DEVICE_ID_DREAM_CHEEKY_FA), .driver_data = DREAM_CHEEKY },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	{ HID_USB_DEVICE(USB_VENDOR_ID_THINGM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	  USB_DEVICE_ID_BLINK1), .driver_data = THINGM },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	{ HID_USB_DEVICE(USB_VENDOR_ID_DELCOM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	  USB_DEVICE_ID_DELCOM_VISUAL_IND), .driver_data = DELCOM },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	{ HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	  USB_DEVICE_ID_LUXAFOR), .driver_data = LUXAFOR },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) MODULE_DEVICE_TABLE(hid, hidled_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static struct hid_driver hidled_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	.name = "hid-led",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	.probe = hidled_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	.id_table = hidled_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) module_hid_driver(hidled_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) MODULE_AUTHOR("Heiner Kallweit <hkallweit1@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) MODULE_DESCRIPTION("Simple USB RGB LED driver");