HID: roccat: Add support for Roccat Kone[+]
Subsystems (2)
Stefan Achatz
maintainerPATCH 1/1 HID: roccat: Add support for Roccat Kone[+]
This patch adds support for Roccat Kone[+] gaming mouse. Kone[+] is an enhanced version of the old Kone with more memory for macros, a better sensor and more functionality. This driver is conceptual similar to the existing Kone and Pyra drivers. Userland tools can soon be found at http://sourceforge.net/projects/roccat
--- .../ABI/testing/sysfs-driver-hid-roccat-koneplus | 108 ++ drivers/hid/Kconfig | 7 + drivers/hid/Makefile | 1 + drivers/hid/hid-core.c | 1 + drivers/hid/hid-ids.h | 1 + drivers/hid/hid-roccat-koneplus.c | 1053 ++++++++++++++++++++ drivers/hid/hid-roccat-koneplus.h | 229 +++++ 7 files changed, 1400 insertions(+), 0 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus create mode 100644 drivers/hid/hid-roccat-koneplus.c create mode 100644 drivers/hid/hid-roccat-koneplus.h
Documentation/ABI/testing/sysfs-driver-hid-roccat-koneplus new file +108 -0
@@ -0,0 +1,108 @@ +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/actual_profile +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: When read, this file returns the number of the actual profile in + range 0-4. + This file is readonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/firmware_version +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: When read, this file returns the raw integer version number of the + firmware reported by the mouse. Using the integer value eases + further usage in other programs. To receive the real version + number the decimal point has to be shifted 2 positions to the + left. E.g. a returned value of 121 means 1.21 + This file is readonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/macro +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse can store a macro with max 500 key/button strokes + internally. + When written, this file lets one set the sequence for a specific + button for a specific profile. Button and profile numbers are + included in written data. The data has to be 2082 bytes long. + This file is writeonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile_buttons +Date: August 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse can store 5 profiles which can be switched by the + press of a button. A profile is split in settings and buttons. + profile_buttons holds informations about button layout. + When written, this file lets one write the respective profile + buttons back to the mouse. The data has to be 77 bytes long. + The mouse will reject invalid data. + Which profile to write is determined by the profile number + contained in the data. + This file is writeonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile[1-5]_buttons +Date: August 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse can store 5 profiles which can be switched by the + press of a button. A profile is split in settings and buttons. + profile_buttons holds informations about button layout. + When read, these files return the respective profile buttons. + The returned data is 77 bytes in size. + This file is readonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile_settings +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse can store 5 profiles which can be switched by the + press of a button. A profile is split in settings and buttons. + profile_settings holds informations like resolution, sensitivity + and light effects. + When written, this file lets one write the respective profile + settings back to the mouse. The data has to be 43 bytes long. + The mouse will reject invalid data. + Which profile to write is determined by the profile number + contained in the data. + This file is writeonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/profile[1-5]_settings +Date: August 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse can store 5 profiles which can be switched by the + press of a button. A profile is split in settings and buttons. + profile_settings holds informations like resolution, sensitivity + and light effects. + When read, these files return the respective profile settings. + The returned data is 43 bytes in size. + This file is readonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/sensor +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: The mouse has a tracking- and a distance-control-unit. These + can be activated/deactivated and the lift-off distance can be + set. The data has to be 6 bytes long. + This file is writeonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/startup_profile +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: The integer value of this attribute ranges from 0-4. + When read, this attribute returns the number of the profile + that's active when the mouse is powered on. + When written, this file sets the number of the startup profile + and the mouse activates this profile immediately. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/tcu +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: When written a calibration process for the tracking control unit + can be initiated/cancelled. + The data has to be 3 bytes long. + This file is writeonly. + +What: /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/tcu_image +Date: October 2010 +Contact: Stefan Achatz <[email protected]> +Description: When read the mouse returns a 30x30 pixel image of the + sampled underground. This works only in the course of a + calibration process initiated with tcu. + The returned data is 1028 bytes in size. + This file is readonly.
drivers/hid/Kconfig +7 -0
@@ -376,6 +376,13 @@ config HID_ROCCAT_KONE ---help--- Support for Roccat Kone mouse. +config HID_ROCCAT_KONEPLUS + tristate "Roccat Kone[+] mouse support" + depends on USB_HID + select HID_ROCCAT + ---help--- + Support for Roccat Kone[+] mouse. + config HID_ROCCAT_PYRA tristate "Roccat Pyra mouse support" depends on USB_HID
drivers/hid/Makefile +1 -0
@@ -52,6 +52,7 @@ obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o obj-$(CONFIG_HID_PICOLCD) += hid-picolcd.o obj-$(CONFIG_HID_ROCCAT) += hid-roccat.o obj-$(CONFIG_HID_ROCCAT_KONE) += hid-roccat-kone.o +obj-$(CONFIG_HID_ROCCAT_KONEPLUS) += hid-roccat-koneplus.o obj-$(CONFIG_HID_ROCCAT_PYRA) += hid-roccat-pyra.o obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o obj-$(CONFIG_HID_SMARTJOYPLUS) += hid-sjoy.o
drivers/hid/hid-core.c +1 -0
@@ -1371,6 +1371,7 @@ static const struct hid_device_id hid_blacklist[] = { { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) }, { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA, USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) }, { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_KONEPLUS) }, { HID_USB_DEVICE(USB_VENDOR_ID_ROCCAT, USB_DEVICE_ID_ROCCAT_PYRA_WIRED) }, { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE) },
drivers/hid/hid-ids.h +1 -0
@@ -466,6 +466,7 @@#define USB_VENDOR_ID_ROCCAT 0x1e7d#define USB_DEVICE_ID_ROCCAT_KONE 0x2ced +#define USB_DEVICE_ID_ROCCAT_KONEPLUS 0x2d51#define USB_DEVICE_ID_ROCCAT_PYRA_WIRED 0x2c24#define USB_DEVICE_ID_ROCCAT_PYRA_WIRELESS 0x2cf6
drivers/hid/hid-roccat-koneplus.c new file +1053 -0
1,053 lines not on this page · raw message
drivers/hid/hid-roccat-koneplus.h new file +229 -0
229 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Quoted 4 lines · Stefan Achatz
This patch adds support for Roccat Kone[+] gaming mouse. Kone[+] is an enhanced version of the old Kone with more memory for macros, a better sensor and more functionality. This driver is conceptual similar to the existing Kone and Pyra drivers. Userland tools can soon be found at http://sourceforge.net/projects/roccat
Seems like there is a lot of duplicate code with Roccat Kone.
Quoted 199 lines
drivers/hid/hid-roccat-koneplus.c new file +199
-0+static int koneplus_send_control (struct usb_device *usb_dev,uint value, +enum koneplus_control_requests request) +{ +int len; +struct koneplus_control *control; + +if ((request ==KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS || + request ==KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS ) && + value >4 ) +return -EINVAL ; + + control =kmalloc (sizeof (struct koneplus_control ),GFP_KERNEL ); +if (!control) +return -ENOMEM ; + + control->command =KONEPLUS_COMMAND_CONTROL ; + control->value = value; + control->request = request; + + len =usb_control_msg (usb_dev,usb_sndctrlpipe (usb_dev,0 ), +USB_REQ_SET_CONFIGURATION , +USB_TYPE_CLASS |USB_RECIP_INTERFACE |USB_DIR_OUT , +KONEPLUS_USB_COMMAND_CONTROL ,0 , control, +sizeof (struct koneplus_control ), +USB_CTRL_SET_TIMEOUT ); + +kfree (control); + +if (len !=sizeof (struct koneplus_control )) +return len; + +return 0 ; +} + +static int koneplus_receive (struct usb_device *usb_dev,uint usb_command, +void *buf,uint size) { +int len; + + len =usb_control_msg (usb_dev,usb_rcvctrlpipe (usb_dev,0 ), +USB_REQ_CLEAR_FEATURE , +USB_TYPE_CLASS |USB_RECIP_INTERFACE |USB_DIR_IN , + usb_command,0 , buf, size,USB_CTRL_SET_TIMEOUT ); + +return (len != size) ? -EIO :0 ; +} + +static int koneplus_receive_control_status (struct usb_device *usb_dev) +{ +int retval; +struct koneplus_control *control; + + control =kmalloc (sizeof (struct koneplus_control ),GFP_KERNEL ); +if (!control) +return -ENOMEM ; + +do { + retval =koneplus_receive (usb_dev,KONEPLUS_USB_COMMAND_CONTROL , + control,sizeof (struct koneplus_control )); + +/* check if we get a completely wrong answer */ +if (retval) + goto out; + +if (control->value ==KONEPLUS_CONTROL_REQUEST_STATUS_OK ) { + retval =0 ; + goto out; + } + +/* indicates that hardware needs some more time to complete action */ +if (control->value ==KONEPLUS_CONTROL_REQUEST_STATUS_WAIT ) { +msleep (500 );/* windows driver uses 1000 */ +continue ; + } + +/* seems to be critical - replug necessary */ +if (control->value ==KONEPLUS_CONTROL_REQUEST_STATUS_OVERLOAD ) { + retval = -EINVAL ; + goto out; + } + +dev_err (&usb_dev->dev,"koneplus_receive_control_status: " +"unknown response value 0x%x\n" , control->value); + retval = -EINVAL ; + goto out; + + }while (1 ); +out: +kfree (control); +return retval; +} + +static int koneplus_send (struct usb_device *usb_dev,uint command, +void *buf,uint size) { +int len; + + len =usb_control_msg (usb_dev,usb_sndctrlpipe (usb_dev,0 ), +USB_REQ_SET_CONFIGURATION , +USB_TYPE_CLASS |USB_RECIP_INTERFACE |USB_DIR_OUT , + command,0 , buf, size,USB_CTRL_SET_TIMEOUT ); + +if (len != size) +return -EIO ; + +if (koneplus_receive_control_status (usb_dev)) +return -EIO ; + +return 0 ; +} + +static int koneplus_select_profile (struct usb_device *usb_dev,uint number, +enum koneplus_control_requests request) +{ +int retval; + + retval =koneplus_send_control (usb_dev, number, request); +if (retval) +return retval; + +/* allow time to settle things - windows driver uses 500 */ +msleep (100 ); + + retval =koneplus_receive_control_status (usb_dev); +if (retval) +return retval; + +return 0 ; +} + +static int koneplus_get_info (struct usb_device *usb_dev, +struct koneplus_info *buf) +{ +return koneplus_receive (usb_dev,KONEPLUS_USB_COMMAND_INFO , + buf,sizeof (struct koneplus_info )); +} + +static int koneplus_get_profile_settings (struct usb_device *usb_dev, +struct koneplus_profile_settings *buf,uint number) +{ +int retval; + + retval =koneplus_select_profile (usb_dev, number, +KONEPLUS_CONTROL_REQUEST_PROFILE_SETTINGS ); +if (retval) +return retval; + +return koneplus_receive (usb_dev,KONEPLUS_USB_COMMAND_PROFILE_SETTINGS , + buf,sizeof (struct koneplus_profile_settings )); +} + +static int koneplus_set_profile_settings (struct usb_device *usb_dev, +struct koneplus_profile_settings const *settings) +{ +return koneplus_send (usb_dev,KONEPLUS_USB_COMMAND_PROFILE_SETTINGS , + (void *)settings,sizeof (struct koneplus_profile_settings )); +} + +static int koneplus_get_profile_buttons (struct usb_device *usb_dev, +struct koneplus_profile_buttons *buf,int number) +{ +int retval; + + retval =koneplus_select_profile (usb_dev, number, +KONEPLUS_CONTROL_REQUEST_PROFILE_BUTTONS ); +if (retval) +return retval; + +return koneplus_receive (usb_dev,KONEPLUS_USB_COMMAND_PROFILE_BUTTONS , + buf,sizeof (struct koneplus_profile_buttons )); +} + +static int koneplus_set_profile_buttons (struct usb_device *usb_dev, +struct koneplus_profile_buttons const *buttons) +{ +return koneplus_send (usb_dev,KONEPLUS_USB_COMMAND_PROFILE_BUTTONS , + (void *)buttons,sizeof (struct koneplus_profile_buttons )); +} + +/* retval is 0-4 on success, < 0 on error */ +static int koneplus_get_startup_profile (struct usb_device *usb_dev) +{ +struct koneplus_startup_profile *buf; +int retval; + + buf =kmalloc (sizeof (struct koneplus_startup_profile ),GFP_KERNEL ); + + retval =koneplus_receive (usb_dev,KONEPLUS_USB_COMMAND_STARTUP_PROFILE , + buf,sizeof (struct koneplus_startup_profile )); + +if (retval) + goto out; + + retval = buf->startup_profile; +out: +kfree (buf); +return retval; +} + +static int koneplus_set_startup_profile (struct usb_device *usb_dev, +int startup_profile)
drivers/hid/hid-roccat-koneplus.c line 243
Quoted 10 lines
drivers/hid/hid-roccat-koneplus.c new file +10
-0+{ +struct koneplus_startup_profile buf; + + buf.command =KONEPLUS_COMMAND_STARTUP_PROFILE ; + buf.size =sizeof (struct koneplus_startup_profile ); + buf.startup_profile = startup_profile; + +return koneplus_send (usb_dev,KONEPLUS_USB_COMMAND_STARTUP_PROFILE , + (char *)&buf,sizeof (struct koneplus_profile_buttons )); +}
Is there any reason this couldn't be merged with the Roccat Kone counterparts?
Quoted 135 lines
drivers/hid/hid-roccat-koneplus.c new file +135
-0+static ssize_t koneplus_sysfs_read (struct file *fp,struct kobject *kobj, +char *buf,loff_t off,size_t count, +size_t real_size,uint command) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct koneplus_device *koneplus =hid_get_drvdata (dev_get_drvdata (dev)); +struct usb_device *usb_dev =interface_to_usbdev (to_usb_interface (dev)); +int retval; + +if (off !=0 || count != real_size) +return -EINVAL ; + +mutex_lock (&koneplus->koneplus_lock); + retval =koneplus_receive (usb_dev, command, buf, real_size); +mutex_unlock (&koneplus->koneplus_lock); + +if (retval) +return retval; + +return real_size; +} + +static ssize_t koneplus_sysfs_write (struct file *fp,struct kobject *kobj, +void const *buf,loff_t off,size_t count, +size_t real_size,uint command) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct koneplus_device *koneplus =hid_get_drvdata (dev_get_drvdata (dev)); +struct usb_device *usb_dev =interface_to_usbdev (to_usb_interface (dev)); +int retval; + +if (off !=0 || count != real_size) +return -EINVAL ; + +mutex_lock (&koneplus->koneplus_lock); + retval =koneplus_send (usb_dev, command, (void *)buf, real_size); +mutex_unlock (&koneplus->koneplus_lock); + +if (retval) +return retval; + +return real_size; +} + +static ssize_t koneplus_sysfs_write_macro (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_write (fp, kobj, buf, off, count, +sizeof (struct koneplus_macro ),KONEPLUS_USB_COMMAND_MACRO ); +} + +static ssize_t koneplus_sysfs_read_sensor (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read (fp, kobj, buf, off, count, +sizeof (struct koneplus_sensor ),KONEPLUS_USB_COMMAND_SENSOR ); +} + +static ssize_t koneplus_sysfs_write_sensor (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_write (fp, kobj, buf, off, count, +sizeof (struct koneplus_sensor ),KONEPLUS_USB_COMMAND_SENSOR ); +} + +static ssize_t koneplus_sysfs_write_tcu (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_write (fp, kobj, buf, off, count, +sizeof (struct koneplus_tcu ),KONEPLUS_USB_COMMAND_TCU ); +} + +static ssize_t koneplus_sysfs_read_tcu_image (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read (fp, kobj, buf, off, count, +sizeof (struct koneplus_tcu_image ),KONEPLUS_USB_COMMAND_TCU ); +} + +static ssize_t koneplus_sysfs_read_profilex_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count,uint number) +{ + struct device *dev = container_of(kobj, struct device, kobj); +struct koneplus_device *koneplus =hid_get_drvdata (dev_get_drvdata (dev)); + +if (off >=sizeof (struct koneplus_profile_settings )) +return 0 ; + +if (off + count >sizeof (struct koneplus_profile_settings )) + count =sizeof (struct koneplus_profile_settings ) - off; + +mutex_lock (&koneplus->koneplus_lock); +memcpy (buf, ((void const *)&koneplus->profile_settings[number]) + off, + count); +mutex_unlock (&koneplus->koneplus_lock); + +return count; +} + +static ssize_t koneplus_sysfs_read_profile1_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,0 ); +} + +static ssize_t koneplus_sysfs_read_profile2_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,1 ); +} + +static ssize_t koneplus_sysfs_read_profile3_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,2 ); +} + +static ssize_t koneplus_sysfs_read_profile4_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,3 );
drivers/hid/hid-roccat-koneplus.c line 389
Quoted 10 lines
drivers/hid/hid-roccat-koneplus.c new file +10
-0+} + +static ssize_t koneplus_sysfs_read_profile5_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,4 ); +} +
This is really ugly. Can't you have just one read() function and distuingish according to bin_attribute->private?
Quoted 14 lines
drivers/hid/hid-roccat-koneplus.h new file +8
-0@@ -0,0 +1,229 @@ +#ifndef __HID_ROCCAT_KONEPLUS_H +#define __HID_ROCCAT_KONEPLUS_H + +/* +* Copyright (c) 2010 Stefan Achatz <[email protected]> +*/ + +/*
drivers/hid/hid-roccat-koneplus.h line 18
Quoted 10 lines
drivers/hid/hid-roccat-koneplus.h new file +10
-0+* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. +*/ + +#include <linux/types.h> + +#pragma pack(push) +#pragma pack(1)
Why?
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Stefan Achatz
maintainerHello,
Am Donnerstag, den 04.11.2010, 14:25 -0400 schrieb Jiri Kosina:
Quoted 10 lines · Stefan Achatz
Quoted 5 lines
This patch adds support for Roccat Kone[+] gaming mouse. Kone[+] is an enhanced version of the old Kone with more memory for macros, a better sensor and more functionality. This driver is conceptual similar to the existing Kone and Pyra drivers. Userland tools can soon be found at http://sourceforge.net/projects/roccat
Seems like there is a lot of duplicate code with Roccat Kone. Is there any reason this couldn't be merged with the Roccat Kone counterparts?
In fact the Kone[+] seems to be nearer to the Pyra than the old Kone. Looks like the manufacturer changed the firmware programmer between some devices. I wanted to wait until I see more devices of this manufacturer if some kind of genealogy might be visible and remove code duplication based on that.
Quoted 11 lines
drivers/hid/hid-roccat-koneplus.c line 389
Quoted 8 lines
drivers/hid/hid-roccat-koneplus.c new file +8
-0+static ssize_t koneplus_sysfs_read_profile5_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,4 ); +} +This is really ugly. Can't you have just one
read()function and distuingish according tobin_attribute->private?
The patch comes in a view moments, if you like it I'll do the same for Kone and Pyra.
Quoted 19 lines
Quoted 19 lines
drivers/hid/hid-roccat-koneplus.h new file +12
-0@@ -0,0 +1,229 @@ +#ifndef __HID_ROCCAT_KONEPLUS_H +#define __HID_ROCCAT_KONEPLUS_H + +/* +* Copyright (c) 2010 Stefan Achatz <[email protected]> +*/ + +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version.
Quoted 8 lines
drivers/hid/hid-roccat-koneplus.h line 18
Quoted 6 lines
drivers/hid/hid-roccat-koneplus.h new file +6
-0+*/ + +#include <linux/types.h> + +#pragma pack(push) +#pragma pack(1)Why?
What?
Have a nice day,
Stefan
Quoted 9 lines · Stefan Achatz
Quoted 8 lines
Quoted 4 lines
This patch adds support for Roccat Kone[+] gaming mouse. Kone[+] is an enhanced version of the old Kone with more memory for macros, a better sensor and more functionality. This driver is conceptual similar to the existing Kone and Pyra drivers. Userland tools can soon be found at http://sourceforge.net/projects/roccat
Seems like there is a lot of duplicate code with Roccat Kone. Is there any reason this couldn't be merged with the Roccat Kone counterparts?
Quoted 5 lines
In fact the Kone[+] seems to be nearer to the Pyra than the old Kone. Looks like the manufacturer changed the firmware programmer between some devices. I wanted to wait until I see more devices of this manufacturer if some kind of genealogy might be visible and remove code duplication based on that.
It would be really nice, otherwise this gets into unmaintainable mess very quickly.
Quoted 12 lines
Quoted 11 lines
drivers/hid/hid-roccat-koneplus.c line 389
Quoted 8 lines
drivers/hid/hid-roccat-koneplus.c new file +8
-0+static ssize_t koneplus_sysfs_read_profile5_settings (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ +return koneplus_sysfs_read_profilex_settings (fp, kobj, + attr, buf, off, count,4 ); +} +This is really ugly. Can't you have just one
read()function and distuingish according tobin_attribute->private?
Quoted 2 lines
The patch comes in a view moments, if you like it I'll do the same for Kone and Pyra.
Would be nice, thanks for fixing it.
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
+ * Copyright (c) 2010 Stefan Achatz <[email protected]>
+ */drivers/hid/hid-roccat-koneplus.c new file +6
-0+ +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the Free +* Software Foundation; either version 2 of the License, or (at your option) +* any later version. Quoted 8 lines
drivers/hid/hid-roccat-koneplus.h line 18
Quoted 6 lines
+ */
drivers/hid/hid-roccat-koneplus.h new file +5
-0+ +#include <linux/types.h> + +#pragma pack(push) +#pragma pack(1)Why?
Quoted 1 line
What?
I would prefer to have comments there, explaining why those pragmas are necessary.
Thanks,
Signature · 2 lines
Jiri Kosina SUSE Labs, Novell Inc.
Stefan Achatz
maintainerPATCH 1/3 HID: roccat: Reducing number of functions in kone and pyra drivers
The profile number is now passed via bin_attribute->private instead of function parameter to reduce number of functions. This patch does for kone and pyra what a previous patch did for koneplus.
--- drivers/hid/hid-roccat-kone.c | 107 ++++++++++--------------------------- drivers/hid/hid-roccat-pyra.c | 120 +++++++++-------------------------------- 2 files changed, 54 insertions(+), 173 deletions(-)
drivers/hid/hid-roccat-kone.c +28 -79
@@ -35,6 +35,8 @@#include "hid-roccat.h" #include "hid-roccat-kone.h" +static uint profile_numbers[5 ] = {0 ,1 ,2 ,3 ,4 }; +static void kone_set_settings_checksum (struct kone_settings *settings) {uint16_t checksum =0 ;
@@ -319,9 +321,10 @@ static ssize_t kone_sysfs_write_settings(struct file *fp, struct kobject *kobj,return sizeof (struct kone_settings ); } -static ssize_t kone_sysfs_read_profilex (struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count,int number) { +static ssize_t kone_sysfs_read_profilex (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ struct device *dev = container_of(kobj, struct device, kobj);struct kone_device *kone =hid_get_drvdata (dev_get_drvdata (dev));
@@ -332,46 +335,17 @@ static ssize_t kone_sysfs_read_profilex(struct kobject *kobj, count =sizeof (struct kone_profile ) - off;mutex_lock (&kone->kone_lock); -memcpy (buf, ((char const *)&kone->profiles[number -1 ]) + off, count); +memcpy (buf, ((char const *)&kone->profiles[*(uint *)(attr->private)]) + off, count);mutex_unlock (&kone->kone_lock);return count; } -static ssize_t kone_sysfs_read_profile1 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_read_profilex (kobj, attr, buf, off, count,1 ); -} - -static ssize_t kone_sysfs_read_profile2 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_read_profilex (kobj, attr, buf, off, count,2 ); -} - -static ssize_t kone_sysfs_read_profile3 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_read_profilex (kobj, attr, buf, off, count,3 ); -} - -static ssize_t kone_sysfs_read_profile4 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_read_profilex (kobj, attr, buf, off, count,4 ); -} - -static ssize_t kone_sysfs_read_profile5 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_read_profilex (kobj, attr, buf, off, count,5 ); -} -/* Writes data only if different to stored data */ -static ssize_t kone_sysfs_write_profilex (struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count,int number) { +static ssize_t kone_sysfs_write_profilex (struct file *fp, +struct kobject *kobj,struct bin_attribute *attr,char *buf, +loff_t off,size_t count) +{ struct device *dev = container_of(kobj, struct device, kobj);struct kone_device *kone =hid_get_drvdata (dev_get_drvdata (dev));struct usb_device *usb_dev =interface_to_usbdev (to_usb_interface (dev));
@@ -382,13 +356,13 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,if (off !=0 || count !=sizeof (struct kone_profile ))return -EINVAL ; - profile = &kone->profiles[number -1 ]; + profile = &kone->profiles[*(uint *)(attr->private)];mutex_lock (&kone->kone_lock); difference =memcmp (buf, profile,sizeof (struct kone_profile ));if (difference) { retval =kone_set_profile (usb_dev, - (struct kone_profile const *)buf, number); + (struct kone_profile const *)buf, *(uint *)(attr->private) +1 );if (!retval)memcpy (profile, buf,sizeof (struct kone_profile )); }
@@ -400,36 +374,6 @@ static ssize_t kone_sysfs_write_profilex(struct kobject *kobj,return sizeof (struct kone_profile ); } -static ssize_t kone_sysfs_write_profile1 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_write_profilex (kobj, attr, buf, off, count,1 ); -} - -static ssize_t kone_sysfs_write_profile2 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_write_profilex (kobj, attr, buf, off, count,2 ); -} - -static ssize_t kone_sysfs_write_profile3 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_write_profilex (kobj, attr, buf, off, count,3 ); -} - -static ssize_t kone_sysfs_write_profile4 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_write_profilex (kobj, attr, buf, off, count,4 ); -} - -static ssize_t kone_sysfs_write_profile5 (struct file *fp,struct kobject *kobj, -struct bin_attribute *attr,char *buf, -loff_t off,size_t count) { -return kone_sysfs_write_profilex (kobj, attr, buf, off, count,5 ); -} -static ssize_t kone_sysfs_show_actual_profile (struct device *dev,struct device_attribute *attr,char *buf) {
@@ -678,36 +622,41 @@ static struct bin_attribute kone_settings_attr = {static struct bin_attribute kone_profile1_attr = { .attr = { .name ="profile1" , .mode =0660 }, .size =sizeof (struct kone_profile ), - .read = kone_sysfs_read_profile1, - .write = kone_sysfs_write_profile1 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[0 ] };static struct bin_attribute kone_profile2_attr = { .attr = { .name ="profile2" , .mode =0660 }, .size =sizeof (struct kone_profile ), - .read = kone_sysfs_read_profile2, - .write = kone_sysfs_write_profile2 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[1 ] };static struct bin_attribute kone_profile3_attr = { .attr = { .name ="profile3" , .mode =0660 }, .size =sizeof (struct kone_profile ), - .read = kone_sysfs_read_profile3, - .write = kone_sysfs_write_profile3 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[2 ] };static struct bin_attribute kone_profile4_attr = { .attr = { .name ="profile4" , .mode =0660 }, .size =sizeof (struct kone_profile ), - .read = kone_sysfs_read_profile4, - .write = kone_sysfs_write_profile4 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[3 ] };static struct bin_attribute kone_profile5_attr = { .attr = { .name ="profile5" , .mode =0660 }, .size =sizeof (struct kone_profile ), - .read = kone_sysfs_read_profile5, - .write = kone_sysfs_write_profile5 + .read = kone_sysfs_read_profilex, + .write = kone_sysfs_write_profilex, + .private = &profile_numbers[4 ] };static int kone_create_sysfs_attributes (struct usb_interface *intf)
drivers/hid/hid-roccat-pyra.c +26 -94
210 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Stefan Achatz
maintainerPATCH 2/3 HID: roccat: declaring meaning of pack pragma usage in koneplus driver
In reply to Jiri KosinaUsing pack pragma to prevent padding bytes in binary data structures used for hardware communication. Explanation of these pragmas was requested.
--- drivers/hid/hid-roccat-koneplus.h | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/hid/hid-roccat-koneplus.h +3 -0
@@ -14,6 +14,9 @@#include <linux/types.h> +/* +* Binary data structures for communication with hardware must have no padding. +*/ #pragma pack(push)#pragma pack(1)
Signature · 1 line
1.7.2.3
Stefan Achatz
maintainerPATCH 3/3 HID: roccat: declaring meaning of pack pragma usage in kone and pyra driver
In reply to Jiri KosinaUsing pack pragma to prevent padding bytes in binary data structures used for hardware communication. Explanation of these pragmas was requested. This patch does for kone and pyra what another patch does for koneplus.
--- drivers/hid/hid-roccat-kone.h | 3 +++ drivers/hid/hid-roccat-pyra.h | 3 +++ 2 files changed, 6 insertions(+), 0 deletions(-)
drivers/hid/hid-roccat-kone.h +3 -0
@@ -14,6 +14,9 @@#include <linux/types.h> +/* +* Binary data structures for communication with hardware must have no padding. +*/ #pragma pack(push)#pragma pack(1)
drivers/hid/hid-roccat-pyra.h +3 -0
@@ -14,6 +14,9 @@#include <linux/types.h> +/* +* Binary data structures for communication with hardware must have no padding. +*/ #pragma pack(push)#pragma pack(1)
Signature · 1 line
1.7.2.3
Stefan Achatz
maintainerAm Freitag, den 05.11.2010, 14:01 -0400 schrieb Jiri Kosina:
Quoted 11 lines · Stefan Achatz
Quoted 10 lines
Quoted 9 lines
Quoted 5 lines
This patch adds support for Roccat Kone[+] gaming mouse. Kone[+] is an enhanced version of the old Kone with more memory for macros, a better sensor and more functionality. This driver is conceptual similar to the existing Kone and Pyra drivers. Userland tools can soon be found at http://sourceforge.net/projects/roccat
Seems like there is a lot of duplicate code with Roccat Kone. Is there any reason this couldn't be merged with the Roccat Kone counterparts?
Quoted 8 lines
Quoted 5 lines
In fact the Kone[+] seems to be nearer to the Pyra than the old Kone. Looks like the manufacturer changed the firmware programmer between some devices. I wanted to wait until I see more devices of this manufacturer if some kind of genealogy might be visible and remove code duplication based on that.
It would be really nice, otherwise this gets into unmaintainable mess very quickly.
Just to clarify my words if someones waiting for a patch: That was meant in a longer term. I'm beginning a new device after I finish Kone[+] userland tools. That would be at the earliest in january. What I wanted to say was to please apply these patches in this state, the code duplication gets handled with the next device.
Thanks,
Stefan
Stefan Achatz
maintainerPATCH 1/1 HID: roccat: Using bin-attribute->private to reduce code duplication
In reply to Jiri KosinaThe profile number is now passed via bin-attribute->private instead of function parameter to reduce number of functions.
--- drivers/hid/hid-roccat-koneplus.c | 120 ++++++++----------------------------- 1 files changed, 26 insertions(+), 94 deletions(-)
drivers/hid/hid-roccat-koneplus.c +26 -94
@@ -26,6 +26,8 @@#include "hid-roccat.h" #include "hid-roccat-koneplus.h" +static uint profile_numbers[5 ] = {0 ,1 ,2 ,3 ,4 }; +static void koneplus_profile_activated (struct koneplus_device *koneplus,uint new_profile) {
@@ -328,7 +330,7 @@ static ssize_t koneplus_sysfs_read_tcu_image(struct file *fp,static ssize_t koneplus_sysfs_read_profilex_settings (struct file *fp,struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count,uint number) +loff_t off,size_t count) { struct device *dev = container_of(kobj, struct device, kobj);struct koneplus_device *koneplus =hid_get_drvdata (dev_get_drvdata (dev));
@@ -340,53 +342,13 @@ static ssize_t koneplus_sysfs_read_profilex_settings(struct file *fp, count =sizeof (struct koneplus_profile_settings ) - off;mutex_lock (&koneplus->koneplus_lock); -memcpy (buf, ((void const *)&koneplus->profile_settings[number]) + off, +memcpy (buf, ((void const *)&koneplus->profile_settings[*(uint *)(attr->private)]) + off, count);mutex_unlock (&koneplus->koneplus_lock);return count; } -static ssize_t koneplus_sysfs_read_profile1_settings (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_settings (fp, kobj, - attr, buf, off, count,0 ); -} - -static ssize_t koneplus_sysfs_read_profile2_settings (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_settings (fp, kobj, - attr, buf, off, count,1 ); -} - -static ssize_t koneplus_sysfs_read_profile3_settings (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_settings (fp, kobj, - attr, buf, off, count,2 ); -} - -static ssize_t koneplus_sysfs_read_profile4_settings (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_settings (fp, kobj, - attr, buf, off, count,3 ); -} - -static ssize_t koneplus_sysfs_read_profile5_settings (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_settings (fp, kobj, - attr, buf, off, count,4 ); -} -static ssize_t koneplus_sysfs_write_profile_settings (struct file *fp,struct kobject *kobj,struct bin_attribute *attr,char *buf,loff_t off,size_t count)
@@ -425,7 +387,7 @@ static ssize_t koneplus_sysfs_write_profile_settings(struct file *fp,static ssize_t koneplus_sysfs_read_profilex_buttons (struct file *fp,struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count,uint number) +loff_t off,size_t count) { struct device *dev = container_of(kobj, struct device, kobj);struct koneplus_device *koneplus =hid_get_drvdata (dev_get_drvdata (dev));
@@ -437,53 +399,13 @@ static ssize_t koneplus_sysfs_read_profilex_buttons(struct file *fp, count =sizeof (struct koneplus_profile_buttons ) - off;mutex_lock (&koneplus->koneplus_lock); -memcpy (buf, ((void const *)&koneplus->profile_buttons[number]) + off, +memcpy (buf, ((void const *)&koneplus->profile_buttons[*(uint *)(attr->private)]) + off, count);mutex_unlock (&koneplus->koneplus_lock);return count; } -static ssize_t koneplus_sysfs_read_profile1_buttons (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_buttons (fp, kobj, - attr, buf, off, count,0 ); -} - -static ssize_t koneplus_sysfs_read_profile2_buttons (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_buttons (fp, kobj, - attr, buf, off, count,1 ); -} - -static ssize_t koneplus_sysfs_read_profile3_buttons (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_buttons (fp, kobj, - attr, buf, off, count,2 ); -} - -static ssize_t koneplus_sysfs_read_profile4_buttons (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_buttons (fp, kobj, - attr, buf, off, count,3 ); -} - -static ssize_t koneplus_sysfs_read_profile5_buttons (struct file *fp, -struct kobject *kobj,struct bin_attribute *attr,char *buf, -loff_t off,size_t count) -{ -return koneplus_sysfs_read_profilex_buttons (fp, kobj, - attr, buf, off, count,4 ); -} -static ssize_t koneplus_sysfs_write_profile_buttons (struct file *fp,struct kobject *kobj,struct bin_attribute *attr,char *buf,loff_t off,size_t count)
@@ -611,31 +533,36 @@ static struct bin_attribute koneplus_profile_settings_attr = {static struct bin_attribute koneplus_profile1_settings_attr = { .attr = { .name ="profile1_settings" , .mode =0440 }, .size =sizeof (struct koneplus_profile_settings ), - .read = koneplus_sysfs_read_profile1_settings + .read = koneplus_sysfs_read_profilex_settings, + .private = &profile_numbers[0 ] };static struct bin_attribute koneplus_profile2_settings_attr = { .attr = { .name ="profile2_settings" , .mode =0440 }, .size =sizeof (struct koneplus_profile_settings ), - .read = koneplus_sysfs_read_profile2_settings + .read = koneplus_sysfs_read_profilex_settings, + .private = &profile_numbers[1 ] };static struct bin_attribute koneplus_profile3_settings_attr = { .attr = { .name ="profile3_settings" , .mode =0440 }, .size =sizeof (struct koneplus_profile_settings ), - .read = koneplus_sysfs_read_profile3_settings + .read = koneplus_sysfs_read_profilex_settings, + .private = &profile_numbers[2 ] };static struct bin_attribute koneplus_profile4_settings_attr = { .attr = { .name ="profile4_settings" , .mode =0440 }, .size =sizeof (struct koneplus_profile_settings ), - .read = koneplus_sysfs_read_profile4_settings + .read = koneplus_sysfs_read_profilex_settings, + .private = &profile_numbers[3 ] };static struct bin_attribute koneplus_profile5_settings_attr = { .attr = { .name ="profile5_settings" , .mode =0440 }, .size =sizeof (struct koneplus_profile_settings ), - .read = koneplus_sysfs_read_profile5_settings + .read = koneplus_sysfs_read_profilex_settings, + .private = &profile_numbers[4 ] };static struct bin_attribute koneplus_profile_buttons_attr = {
@@ -647,31 +574,36 @@ static struct bin_attribute koneplus_profile_buttons_attr = {static struct bin_attribute koneplus_profile1_buttons_attr = { .attr = { .name ="profile1_buttons" , .mode =0440 }, .size =sizeof (struct koneplus_profile_buttons ), - .read = koneplus_sysfs_read_profile1_buttons + .read = koneplus_sysfs_read_profilex_buttons, + .private = &profile_numbers[0 ] };static struct bin_attribute koneplus_profile2_buttons_attr = { .attr = { .name ="profile2_buttons" , .mode =0440 }, .size =sizeof (struct koneplus_profile_buttons ), - .read = koneplus_sysfs_read_profile2_buttons + .read = koneplus_sysfs_read_profilex_buttons, + .private = &profile_numbers[1 ] };static struct bin_attribute koneplus_profile3_buttons_attr = { .attr = { .name ="profile3_buttons" , .mode =0440 }, .size =sizeof (struct koneplus_profile_buttons ), - .read = koneplus_sysfs_read_profile3_buttons + .read = koneplus_sysfs_read_profilex_buttons, + .private = &profile_numbers[2 ] };static struct bin_attribute koneplus_profile4_buttons_attr = { .attr = { .name ="profile4_buttons" , .mode =0440 }, .size =sizeof (struct koneplus_profile_buttons ), - .read = koneplus_sysfs_read_profile4_buttons + .read = koneplus_sysfs_read_profilex_buttons, + .private = &profile_numbers[3 ] };static struct bin_attribute koneplus_profile5_buttons_attr = { .attr = { .name ="profile5_buttons" , .mode =0440 }, .size =sizeof (struct koneplus_profile_buttons ), - .read = koneplus_sysfs_read_profile5_buttons + .read = koneplus_sysfs_read_profilex_buttons, + .private = &profile_numbers[4 ] };static struct bin_attribute koneplus_macro_attr = {
Signature · 1 line
1.7.2.3
Hi Stefan,
Quoted 19 lines · Stefan Achatz
drivers/hid/hid-roccat-koneplus.c new file +19
-0+ +static int koneplus_create_sysfs_attributes (struct usb_interface *intf) +{ +int retval; + + retval =sysfs_create_group (&intf->dev.kobj, &koneplus_attribute_group); +if (retval) + goto exit_1; + + retval =sysfs_create_bin_file (&intf->dev.kobj, + &koneplus_profile_settings_attr); +if (retval) + goto exit_2; + + retval =sysfs_create_bin_file (&intf->dev.kobj, + &koneplus_profile1_settings_attr); +if (retval) + goto exit_3; +
...
drivers/hid/hid-roccat-koneplus.c line 770
Quoted 6 lines
drivers/hid/hid-roccat-koneplus.c new file +6
-0+ + retval =sysfs_create_bin_file (&intf->dev.kobj, + &koneplus_sensor_attr); +if (retval) + goto exit_17; +
I think we are ready to sysfs_binary_attribute_group ;) Please add it to sysfs code and send it to GregKH.
Thanks.
Signature · 1 line
Dmitry