Commit 1edd5b42 authored by Stefan Achatz's avatar Stefan Achatz Committed by Jiri Kosina
Browse files

HID: roccat: correction and cleanup of HID feature reports



Removed analog feature report enums and modified code in roccat_common
to reflect this. Non standard conform Kone got its own copy of the old
code. That helps extracting more generalizations for newer devices.

Signed-off-by: default avatarStefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent 303f272c
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ static ssize_t arvo_sysfs_show_mode_key(struct device *dev,
	int retval;

	mutex_lock(&arvo->arvo_lock);
	retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
	retval = roccat_common_receive(usb_dev, ARVO_COMMAND_MODE_KEY,
			&temp_buf, sizeof(struct arvo_mode_key));
	mutex_unlock(&arvo->arvo_lock);
	if (retval)
@@ -67,7 +67,7 @@ static ssize_t arvo_sysfs_set_mode_key(struct device *dev,
	temp_buf.state = state;

	mutex_lock(&arvo->arvo_lock);
	retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_MODE_KEY,
	retval = roccat_common_send(usb_dev, ARVO_COMMAND_MODE_KEY,
			&temp_buf, sizeof(struct arvo_mode_key));
	mutex_unlock(&arvo->arvo_lock);
	if (retval)
@@ -87,7 +87,7 @@ static ssize_t arvo_sysfs_show_key_mask(struct device *dev,
	int retval;

	mutex_lock(&arvo->arvo_lock);
	retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
	retval = roccat_common_receive(usb_dev, ARVO_COMMAND_KEY_MASK,
			&temp_buf, sizeof(struct arvo_key_mask));
	mutex_unlock(&arvo->arvo_lock);
	if (retval)
@@ -115,7 +115,7 @@ static ssize_t arvo_sysfs_set_key_mask(struct device *dev,
	temp_buf.key_mask = key_mask;

	mutex_lock(&arvo->arvo_lock);
	retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_KEY_MASK,
	retval = roccat_common_send(usb_dev, ARVO_COMMAND_KEY_MASK,
			&temp_buf, sizeof(struct arvo_key_mask));
	mutex_unlock(&arvo->arvo_lock);
	if (retval)
@@ -130,7 +130,7 @@ static int arvo_get_actual_profile(struct usb_device *usb_dev)
	struct arvo_actual_profile temp_buf;
	int retval;

	retval = roccat_common_receive(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
	retval = roccat_common_receive(usb_dev, ARVO_COMMAND_ACTUAL_PROFILE,
			&temp_buf, sizeof(struct arvo_actual_profile));

	if (retval)
@@ -167,7 +167,7 @@ static ssize_t arvo_sysfs_set_actual_profile(struct device *dev,
	temp_buf.actual_profile = profile;

	mutex_lock(&arvo->arvo_lock);
	retval = roccat_common_send(usb_dev, ARVO_USB_COMMAND_ACTUAL_PROFILE,
	retval = roccat_common_send(usb_dev, ARVO_COMMAND_ACTUAL_PROFILE,
			&temp_buf, sizeof(struct arvo_actual_profile));
	if (!retval) {
		arvo->actual_profile = profile;
@@ -225,7 +225,7 @@ static ssize_t arvo_sysfs_write_button(struct file *fp,
		loff_t off, size_t count)
{
	return arvo_sysfs_write(fp, kobj, buf, off, count,
			sizeof(struct arvo_button), ARVO_USB_COMMAND_BUTTON);
			sizeof(struct arvo_button), ARVO_COMMAND_BUTTON);
}

static ssize_t arvo_sysfs_read_info(struct file *fp,
@@ -233,7 +233,7 @@ static ssize_t arvo_sysfs_read_info(struct file *fp,
		loff_t off, size_t count)
{
	return arvo_sysfs_read(fp, kobj, buf, off, count,
			sizeof(struct arvo_info), ARVO_USB_COMMAND_INFO);
			sizeof(struct arvo_info), ARVO_COMMAND_INFO);
}


+0 −13
Original line number Diff line number Diff line
@@ -46,19 +46,6 @@ enum arvo_commands {
	ARVO_COMMAND_ACTUAL_PROFILE = 0x7,
};

enum arvo_usb_commands {
	ARVO_USB_COMMAND_MODE_KEY = 0x303,
	/*
	 * read/write
	 * Read uses both index bytes as profile/key indexes
	 * Write has index 0, profile/key is determined by payload
	 */
	ARVO_USB_COMMAND_BUTTON = 0x304,
	ARVO_USB_COMMAND_INFO = 0x305,
	ARVO_USB_COMMAND_KEY_MASK = 0x306,
	ARVO_USB_COMMAND_ACTUAL_PROFILE = 0x307,
};

struct arvo_special_report {
	uint8_t unknown1; /* always 0x01 */
	uint8_t event;
+14 −6
Original line number Diff line number Diff line
@@ -11,10 +11,16 @@
 * any later version.
 */

#include <linux/hid.h>
#include <linux/slab.h>
#include "hid-roccat-common.h"

int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
static inline uint16_t roccat_common_feature_report(uint8_t report_id)
{
	return 0x300 | report_id;
}

int roccat_common_receive(struct usb_device *usb_dev, uint report_id,
		void *data, uint size)
{
	char *buf;
@@ -25,9 +31,10 @@ int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
		return -ENOMEM;

	len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
			USB_REQ_CLEAR_FEATURE,
			HID_REQ_GET_REPORT,
			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
			usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
			roccat_common_feature_report(report_id),
			0, buf, size, USB_CTRL_SET_TIMEOUT);

	memcpy(data, buf, size);
	kfree(buf);
@@ -35,7 +42,7 @@ int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
}
EXPORT_SYMBOL_GPL(roccat_common_receive);

int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
int roccat_common_send(struct usb_device *usb_dev, uint report_id,
		void const *data, uint size)
{
	char *buf;
@@ -48,9 +55,10 @@ int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
	memcpy(buf, data, size);

	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
			USB_REQ_SET_CONFIGURATION,
			HID_REQ_SET_REPORT,
			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
			usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);
			roccat_common_feature_report(report_id),
			0, buf, size, USB_CTRL_SET_TIMEOUT);

	kfree(buf);
	return ((len < 0) ? len : ((len != size) ? -EIO : 0));
+2 −2
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@
#include <linux/usb.h>
#include <linux/types.h>

int roccat_common_receive(struct usb_device *usb_dev, uint usb_command,
int roccat_common_receive(struct usb_device *usb_dev, uint report_id,
		void *data, uint size);
int roccat_common_send(struct usb_device *usb_dev, uint usb_command,
int roccat_common_send(struct usb_device *usb_dev, uint report_id,
		void const *data, uint size);

#endif
+47 −6
Original line number Diff line number Diff line
@@ -37,6 +37,47 @@

static uint profile_numbers[5] = {0, 1, 2, 3, 4};

static int kone_receive(struct usb_device *usb_dev, uint usb_command,
		void *data, uint size)
{
	char *buf;
	int len;

	buf = kmalloc(size, GFP_KERNEL);
	if (buf == NULL)
		return -ENOMEM;

	len = usb_control_msg(usb_dev, usb_rcvctrlpipe(usb_dev, 0),
			HID_REQ_GET_REPORT,
			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
			usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);

	memcpy(data, buf, size);
	kfree(buf);
	return ((len < 0) ? len : ((len != size) ? -EIO : 0));
}

static int kone_send(struct usb_device *usb_dev, uint usb_command,
		void const *data, uint size)
{
	char *buf;
	int len;

	buf = kmalloc(size, GFP_KERNEL);
	if (buf == NULL)
		return -ENOMEM;

	memcpy(buf, data, size);

	len = usb_control_msg(usb_dev, usb_sndctrlpipe(usb_dev, 0),
			HID_REQ_SET_REPORT,
			USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
			usb_command, 0, buf, size, USB_CTRL_SET_TIMEOUT);

	kfree(buf);
	return ((len < 0) ? len : ((len != size) ? -EIO : 0));
}

/* kone_class is used for creating sysfs attributes via roccat char device */
static struct class *kone_class;

@@ -68,7 +109,7 @@ static int kone_check_write(struct usb_device *usb_dev)
		 */
		msleep(80);

		retval = roccat_common_receive(usb_dev,
		retval = kone_receive(usb_dev,
				kone_command_confirm_write, &data, 1);
		if (retval)
			return retval;
@@ -96,7 +137,7 @@ static int kone_check_write(struct usb_device *usb_dev)
static int kone_get_settings(struct usb_device *usb_dev,
		struct kone_settings *buf)
{
	return roccat_common_receive(usb_dev, kone_command_settings, buf,
	return kone_receive(usb_dev, kone_command_settings, buf,
			sizeof(struct kone_settings));
}

@@ -109,7 +150,7 @@ static int kone_set_settings(struct usb_device *usb_dev,
		struct kone_settings const *settings)
{
	int retval;
	retval = roccat_common_send(usb_dev, kone_command_settings,
	retval = kone_send(usb_dev, kone_command_settings,
			settings, sizeof(struct kone_settings));
	if (retval)
		return retval;
@@ -182,7 +223,7 @@ static int kone_get_weight(struct usb_device *usb_dev, int *result)
	int retval;
	uint8_t data;

	retval = roccat_common_receive(usb_dev, kone_command_weight, &data, 1);
	retval = kone_receive(usb_dev, kone_command_weight, &data, 1);

	if (retval)
		return retval;
@@ -201,7 +242,7 @@ static int kone_get_firmware_version(struct usb_device *usb_dev, int *result)
	int retval;
	uint16_t data;

	retval = roccat_common_receive(usb_dev, kone_command_firmware_version,
	retval = kone_receive(usb_dev, kone_command_firmware_version,
			&data, 2);
	if (retval)
		return retval;
@@ -384,7 +425,7 @@ static int kone_tcu_command(struct usb_device *usb_dev, int number)
{
	unsigned char value;
	value = number;
	return roccat_common_send(usb_dev, kone_command_calibrate, &value, 1);
	return kone_send(usb_dev, kone_command_calibrate, &value, 1);
}

/*
Loading