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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Roccat Kova[+] driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2011 Stefan Achatz <erazor_de@users.sourceforge.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Roccat Kova[+] is a bigger version of the Pyra with two more side buttons.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/hid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/hid-roccat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "hid-ids.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "hid-roccat-common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "hid-roccat-kovaplus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static uint profile_numbers[5] = {0, 1, 2, 3, 4};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static struct class *kovaplus_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) static uint kovaplus_convert_event_cpi(uint value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	return (value == 7 ? 4 : (value == 4 ? 3 : value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) static void kovaplus_profile_activated(struct kovaplus_device *kovaplus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		uint new_profile_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (new_profile_index >= ARRAY_SIZE(kovaplus->profile_settings))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	kovaplus->actual_profile = new_profile_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	kovaplus->actual_cpi = kovaplus->profile_settings[new_profile_index].cpi_startup_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	kovaplus->actual_x_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	kovaplus->actual_y_sensitivity = kovaplus->profile_settings[new_profile_index].sensitivity_y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static int kovaplus_send_control(struct usb_device *usb_dev, uint value,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		enum kovaplus_control_requests request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	struct roccat_common2_control control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if ((request == KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			request == KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			value > 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	control.command = ROCCAT_COMMON_COMMAND_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	control.value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	control.request = request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	retval = roccat_common2_send(usb_dev, ROCCAT_COMMON_COMMAND_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 			&control, sizeof(struct roccat_common2_control));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static int kovaplus_select_profile(struct usb_device *usb_dev, uint number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		enum kovaplus_control_requests request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return kovaplus_send_control(usb_dev, number, request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int kovaplus_get_profile_settings(struct usb_device *usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		struct kovaplus_profile_settings *buf, uint number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	retval = kovaplus_select_profile(usb_dev, number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_SETTINGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			buf, KOVAPLUS_SIZE_PROFILE_SETTINGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int kovaplus_get_profile_buttons(struct usb_device *usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		struct kovaplus_profile_buttons *buf, int number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	retval = kovaplus_select_profile(usb_dev, number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_PROFILE_BUTTONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			buf, KOVAPLUS_SIZE_PROFILE_BUTTONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /* retval is 0-4 on success, < 0 on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static int kovaplus_get_actual_profile(struct usb_device *usb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct kovaplus_actual_profile buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	retval = roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_ACTUAL_PROFILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			&buf, sizeof(struct kovaplus_actual_profile));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return retval ? retval : buf.actual_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int kovaplus_set_actual_profile(struct usb_device *usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		int new_profile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct kovaplus_actual_profile buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	buf.command = KOVAPLUS_COMMAND_ACTUAL_PROFILE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	buf.size = sizeof(struct kovaplus_actual_profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	buf.actual_profile = new_profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return roccat_common2_send_with_status(usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			KOVAPLUS_COMMAND_ACTUAL_PROFILE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			&buf, sizeof(struct kovaplus_actual_profile));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static ssize_t kovaplus_sysfs_read(struct file *fp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		char *buf, loff_t off, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		size_t real_size, uint command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	struct device *dev = kobj_to_dev(kobj)->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (off >= real_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	if (off != 0 || count != real_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	mutex_lock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	retval = roccat_common2_receive(usb_dev, command, buf, real_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	mutex_unlock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return real_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static ssize_t kovaplus_sysfs_write(struct file *fp, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		void const *buf, loff_t off, size_t count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		size_t real_size, uint command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct device *dev = kobj_to_dev(kobj)->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct kovaplus_device *kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	if (off != 0 || count != real_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	mutex_lock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	retval = roccat_common2_send_with_status(usb_dev, command,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			buf, real_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	mutex_unlock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	return real_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #define KOVAPLUS_SYSFS_W(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static ssize_t kovaplus_sysfs_write_ ## thingy(struct file *fp, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		struct kobject *kobj, struct bin_attribute *attr, char *buf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		loff_t off, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	return kovaplus_sysfs_write(fp, kobj, buf, off, count, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 			KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define KOVAPLUS_SYSFS_R(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static ssize_t kovaplus_sysfs_read_ ## thingy(struct file *fp, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		struct kobject *kobj, struct bin_attribute *attr, char *buf, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		loff_t off, size_t count) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	return kovaplus_sysfs_read(fp, kobj, buf, off, count, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			KOVAPLUS_SIZE_ ## THINGY, KOVAPLUS_COMMAND_ ## THINGY); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define KOVAPLUS_SYSFS_RW(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) KOVAPLUS_SYSFS_W(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) KOVAPLUS_SYSFS_R(thingy, THINGY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #define KOVAPLUS_BIN_ATTRIBUTE_RW(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) KOVAPLUS_SYSFS_RW(thingy, THINGY); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static struct bin_attribute bin_attr_##thingy = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.attr = { .name = #thingy, .mode = 0660 }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	.size = KOVAPLUS_SIZE_ ## THINGY, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	.read = kovaplus_sysfs_read_ ## thingy, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	.write = kovaplus_sysfs_write_ ## thingy \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #define KOVAPLUS_BIN_ATTRIBUTE_W(thingy, THINGY) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) KOVAPLUS_SYSFS_W(thingy, THINGY); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static struct bin_attribute bin_attr_##thingy = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	.attr = { .name = #thingy, .mode = 0220 }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	.size = KOVAPLUS_SIZE_ ## THINGY, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.write = kovaplus_sysfs_write_ ## thingy \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) KOVAPLUS_BIN_ATTRIBUTE_W(control, CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) KOVAPLUS_BIN_ATTRIBUTE_RW(info, INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) KOVAPLUS_BIN_ATTRIBUTE_RW(profile_settings, PROFILE_SETTINGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) KOVAPLUS_BIN_ATTRIBUTE_RW(profile_buttons, PROFILE_BUTTONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static ssize_t kovaplus_sysfs_read_profilex_settings(struct file *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	struct device *dev = kobj_to_dev(kobj)->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	ssize_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			KOVAPLUS_CONTROL_REQUEST_PROFILE_SETTINGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	return kovaplus_sysfs_read(fp, kobj, buf, off, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			KOVAPLUS_SIZE_PROFILE_SETTINGS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 			KOVAPLUS_COMMAND_PROFILE_SETTINGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static ssize_t kovaplus_sysfs_read_profilex_buttons(struct file *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		struct kobject *kobj, struct bin_attribute *attr, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		loff_t off, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct device *dev = kobj_to_dev(kobj)->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct usb_device *usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	ssize_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	retval = kovaplus_select_profile(usb_dev, *(uint *)(attr->private),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 			KOVAPLUS_CONTROL_REQUEST_PROFILE_BUTTONS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return kovaplus_sysfs_read(fp, kobj, buf, off, count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 			KOVAPLUS_SIZE_PROFILE_BUTTONS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 			KOVAPLUS_COMMAND_PROFILE_BUTTONS);
^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) #define PROFILE_ATTR(number)						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static struct bin_attribute bin_attr_profile##number##_settings = {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	.attr = { .name = "profile" #number "_settings", .mode = 0440 },	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	.size = KOVAPLUS_SIZE_PROFILE_SETTINGS,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	.read = kovaplus_sysfs_read_profilex_settings,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	.private = &profile_numbers[number-1],				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };									\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static struct bin_attribute bin_attr_profile##number##_buttons = {	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	.attr = { .name = "profile" #number "_buttons", .mode = 0440 },	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	.size = KOVAPLUS_SIZE_PROFILE_BUTTONS,				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	.read = kovaplus_sysfs_read_profilex_buttons,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	.private = &profile_numbers[number-1],				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) PROFILE_ATTR(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) PROFILE_ATTR(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) PROFILE_ATTR(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) PROFILE_ATTR(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) PROFILE_ATTR(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static ssize_t kovaplus_sysfs_show_actual_profile(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	struct kovaplus_device *kovaplus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static ssize_t kovaplus_sysfs_set_actual_profile(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		struct device_attribute *attr, char const *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	struct kovaplus_device *kovaplus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct usb_device *usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	unsigned long profile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	struct kovaplus_roccat_report roccat_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	dev = dev->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	retval = kstrtoul(buf, 10, &profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	if (profile >= 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	mutex_lock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	retval = kovaplus_set_actual_profile(usb_dev, profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		mutex_unlock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	kovaplus_profile_activated(kovaplus, profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	roccat_report.type = KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	roccat_report.profile = profile + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	roccat_report.button = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	roccat_report.data1 = profile + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	roccat_report.data2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	roccat_report_event(kovaplus->chrdev_minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 			(uint8_t const *)&roccat_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	mutex_unlock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static DEVICE_ATTR(actual_profile, 0660,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		   kovaplus_sysfs_show_actual_profile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		   kovaplus_sysfs_set_actual_profile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) static ssize_t kovaplus_sysfs_show_actual_cpi(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	struct kovaplus_device *kovaplus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_cpi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static DEVICE_ATTR(actual_cpi, 0440, kovaplus_sysfs_show_actual_cpi, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static ssize_t kovaplus_sysfs_show_actual_sensitivity_x(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct kovaplus_device *kovaplus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_x_sensitivity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static DEVICE_ATTR(actual_sensitivity_x, 0440,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		   kovaplus_sysfs_show_actual_sensitivity_x, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static ssize_t kovaplus_sysfs_show_actual_sensitivity_y(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	struct kovaplus_device *kovaplus =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			hid_get_drvdata(dev_get_drvdata(dev->parent->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return snprintf(buf, PAGE_SIZE, "%d\n", kovaplus->actual_y_sensitivity);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static DEVICE_ATTR(actual_sensitivity_y, 0440,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		   kovaplus_sysfs_show_actual_sensitivity_y, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static ssize_t kovaplus_sysfs_show_firmware_version(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	struct kovaplus_device *kovaplus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	struct usb_device *usb_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct kovaplus_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	dev = dev->parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	kovaplus = hid_get_drvdata(dev_get_drvdata(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	usb_dev = interface_to_usbdev(to_usb_interface(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	mutex_lock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	roccat_common2_receive(usb_dev, KOVAPLUS_COMMAND_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 			&info, KOVAPLUS_SIZE_INFO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	mutex_unlock(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	return snprintf(buf, PAGE_SIZE, "%d\n", info.firmware_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static DEVICE_ATTR(firmware_version, 0440,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		   kovaplus_sysfs_show_firmware_version, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static struct attribute *kovaplus_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	&dev_attr_actual_cpi.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	&dev_attr_firmware_version.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	&dev_attr_actual_profile.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	&dev_attr_actual_sensitivity_x.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	&dev_attr_actual_sensitivity_y.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static struct bin_attribute *kovaplus_bin_attributes[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	&bin_attr_control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	&bin_attr_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	&bin_attr_profile_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	&bin_attr_profile_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	&bin_attr_profile1_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	&bin_attr_profile2_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	&bin_attr_profile3_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	&bin_attr_profile4_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	&bin_attr_profile5_settings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	&bin_attr_profile1_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	&bin_attr_profile2_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	&bin_attr_profile3_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	&bin_attr_profile4_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	&bin_attr_profile5_buttons,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) static const struct attribute_group kovaplus_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	.attrs = kovaplus_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	.bin_attrs = kovaplus_bin_attributes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static const struct attribute_group *kovaplus_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	&kovaplus_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) static int kovaplus_init_kovaplus_device_struct(struct usb_device *usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		struct kovaplus_device *kovaplus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	int retval, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	static uint wait = 70; /* device will freeze with just 60 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	mutex_init(&kovaplus->kovaplus_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	for (i = 0; i < 5; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		msleep(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		retval = kovaplus_get_profile_settings(usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 				&kovaplus->profile_settings[i], i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		msleep(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 		retval = kovaplus_get_profile_buttons(usb_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				&kovaplus->profile_buttons[i], i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 		if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 			return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	msleep(wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	retval = kovaplus_get_actual_profile(usb_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	kovaplus_profile_activated(kovaplus, retval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static int kovaplus_init_specials(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	struct usb_device *usb_dev = interface_to_usbdev(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct kovaplus_device *kovaplus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (intf->cur_altsetting->desc.bInterfaceProtocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 			== USB_INTERFACE_PROTOCOL_MOUSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		kovaplus = kzalloc(sizeof(*kovaplus), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		if (!kovaplus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 			hid_err(hdev, "can't alloc device descriptor\n");
^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) 		hid_set_drvdata(hdev, kovaplus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		retval = kovaplus_init_kovaplus_device_struct(usb_dev, kovaplus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			hid_err(hdev, "couldn't init struct kovaplus_device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			goto exit_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 		retval = roccat_connect(kovaplus_class, hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 				sizeof(struct kovaplus_roccat_report));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		if (retval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 			hid_err(hdev, "couldn't init char dev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 			kovaplus->chrdev_minor = retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			kovaplus->roccat_claimed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 		hid_set_drvdata(hdev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) exit_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	kfree(kovaplus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) static void kovaplus_remove_specials(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	struct kovaplus_device *kovaplus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	if (intf->cur_altsetting->desc.bInterfaceProtocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 			== USB_INTERFACE_PROTOCOL_MOUSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		kovaplus = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		if (kovaplus->roccat_claimed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			roccat_disconnect(kovaplus->chrdev_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		kfree(kovaplus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static int kovaplus_probe(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 		const struct hid_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	if (!hid_is_usb(hdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	retval = hid_parse(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 		hid_err(hdev, "parse failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		hid_err(hdev, "hw start failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	retval = kovaplus_init_specials(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		hid_err(hdev, "couldn't install mouse\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		goto exit_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) exit_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) static void kovaplus_remove(struct hid_device *hdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	kovaplus_remove_specials(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	hid_hw_stop(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static void kovaplus_keep_values_up_to_date(struct kovaplus_device *kovaplus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		u8 const *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	struct kovaplus_mouse_report_button const *button_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	button_report = (struct kovaplus_mouse_report_button const *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	switch (button_report->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		kovaplus_profile_activated(kovaplus, button_report->data1 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		kovaplus->actual_cpi = kovaplus_convert_event_cpi(button_report->data1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	case KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SENSITIVITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		kovaplus->actual_x_sensitivity = button_report->data1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		kovaplus->actual_y_sensitivity = button_report->data2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static void kovaplus_report_to_chrdev(struct kovaplus_device const *kovaplus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 		u8 const *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	struct kovaplus_roccat_report roccat_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	struct kovaplus_mouse_report_button const *button_report;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 	if (data[0] != KOVAPLUS_MOUSE_REPORT_NUMBER_BUTTON)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	button_report = (struct kovaplus_mouse_report_button const *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (button_report->type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_PROFILE_2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	roccat_report.type = button_report->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	roccat_report.profile = kovaplus->actual_profile + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_MACRO ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 			roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_SHORTCUT ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 			roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_QUICKLAUNCH ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 			roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_TIMER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		roccat_report.button = button_report->data1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 		roccat_report.button = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	if (roccat_report.type == KOVAPLUS_MOUSE_REPORT_BUTTON_TYPE_CPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		roccat_report.data1 = kovaplus_convert_event_cpi(button_report->data1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 		roccat_report.data1 = button_report->data1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	roccat_report.data2 = button_report->data2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	roccat_report_event(kovaplus->chrdev_minor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 			(uint8_t const *)&roccat_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) static int kovaplus_raw_event(struct hid_device *hdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		struct hid_report *report, u8 *data, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	struct kovaplus_device *kovaplus = hid_get_drvdata(hdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	if (intf->cur_altsetting->desc.bInterfaceProtocol
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 			!= USB_INTERFACE_PROTOCOL_MOUSE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	if (kovaplus == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	kovaplus_keep_values_up_to_date(kovaplus, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (kovaplus->roccat_claimed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 		kovaplus_report_to_chrdev(kovaplus, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static const struct hid_device_id kovaplus_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	{ HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KOVAPLUS) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) MODULE_DEVICE_TABLE(hid, kovaplus_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static struct hid_driver kovaplus_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 		.name = "kovaplus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		.id_table = kovaplus_devices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		.probe = kovaplus_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		.remove = kovaplus_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		.raw_event = kovaplus_raw_event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) static int __init kovaplus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	kovaplus_class = class_create(THIS_MODULE, "kovaplus");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	if (IS_ERR(kovaplus_class))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		return PTR_ERR(kovaplus_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 	kovaplus_class->dev_groups = kovaplus_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	retval = hid_register_driver(&kovaplus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 		class_destroy(kovaplus_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void __exit kovaplus_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	hid_unregister_driver(&kovaplus_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	class_destroy(kovaplus_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) module_init(kovaplus_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) module_exit(kovaplus_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) MODULE_AUTHOR("Stefan Achatz");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) MODULE_DESCRIPTION("USB Roccat Kova[+] driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) MODULE_LICENSE("GPL v2");