Skip to content

Commit

Permalink
HID: roccat: correction and cleanup of HID feature reports
Browse files Browse the repository at this point in the history
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: Stefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Stefan Achatz authored and Jiri Kosina committed Jun 13, 2011
1 parent 303f272 commit 1edd5b4
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 107 deletions.
16 changes: 8 additions & 8 deletions drivers/hid/hid-roccat-arvo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -225,15 +225,15 @@ 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,
struct kobject *kobj, struct bin_attribute *attr, char *buf,
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);
}


Expand Down
13 changes: 0 additions & 13 deletions drivers/hid/hid-roccat-arvo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions drivers/hid/hid-roccat-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,17 +31,18 @@ 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);
return ((len < 0) ? len : ((len != size) ? -EIO : 0));
}
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;
Expand All @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions drivers/hid/hid-roccat-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 47 additions & 6 deletions drivers/hid/hid-roccat-kone.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion drivers/hid/hid-roccat-kone.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ enum kone_mouse_events {
/* osd events are thought to be display on screen */
kone_mouse_event_osd_dpi = 0xa0,
kone_mouse_event_osd_profile = 0xb0,
/* TODO clarify meaning and occurrence of kone_mouse_event_calibration */
/* TODO clarify meaning and occurence of kone_mouse_event_calibration */
kone_mouse_event_calibration = 0xc0,
kone_mouse_event_call_overlong_macro = 0xe0,
/* switch events notify if user changed values with mousebutton click */
Expand Down
Loading

0 comments on commit 1edd5b4

Please sign in to comment.