diff options
author | Stefan Achatz <erazor_de@users.sourceforge.net> | 2010-03-18 11:19:43 -0400 |
---|---|---|
committer | Jiri Kosina <jkosina@suse.cz> | 2010-03-22 11:31:42 -0400 |
commit | 14bf62cde79423a02a590e02664ed29a36facec1 (patch) | |
tree | 09f70b52f8e189659337e817bbc56577547bfc1a /drivers/hid/hid-roccat-kone.h | |
parent | 39710479303fd3affb3e204e9a7a75cc676977b5 (diff) |
HID: add driver for Roccat Kone gaming mouse
This Patch adds support for Kone gaming mouse from Roccat.
It provides access to profiles, settings, firmware, weight,
actual settings etc. through sysfs attributes.
Event handling of this mouse differs from standard hid behaviour
in that tilt button press is reported in each move event which
results in strange behaviour if not handled by the driver.
This is a heavily reworked version of the previously introduced driver.
The changes include most of the previously raised concerns,
memory leak and other fixes, code cleanups, adoption of additional
achieved knowlege about the hardware and is (IMHO) a much better version
than before even when I exchanged reduced USB-IO with a bigger memory
consumption.
I refused to implement one mentioned point:
Removing the 'just-because-we-can' attributes. Motivation:
Reading the clipped in weight: I'm no gamer and can't determine the
usefulness of this feature but if the manufacturer implements such a
feature it might make sense to someone and I would unwillingly limit the
functionality besides its such a small feature.
Reading the actual profile and dpi settings: Here I can testify that one
can get lost of the actual settings when switching back and forth.
The manufacturers windows driver has the ability for on-screen-display
of the values and there is a mouse in the market that has an lcd on the
underside of it to show these values. So I think this feature makes sense
not only for me and shouldn't be removed.
Signed-off-by: Stefan Achatz <erazor_de@users.sourceforge.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-roccat-kone.h')
-rw-r--r-- | drivers/hid/hid-roccat-kone.h | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/drivers/hid/hid-roccat-kone.h b/drivers/hid/hid-roccat-kone.h new file mode 100644 index 000000000000..ee6898c9d92c --- /dev/null +++ b/drivers/hid/hid-roccat-kone.h | |||
@@ -0,0 +1,214 @@ | |||
1 | #ifndef __HID_ROCCAT_KONE_H | ||
2 | #define __HID_ROCCAT_KONE_H | ||
3 | |||
4 | /* | ||
5 | * Copyright (c) 2010 Stefan Achatz <erazor_de@users.sourceforge.net> | ||
6 | */ | ||
7 | |||
8 | /* | ||
9 | * This program is free software; you can redistribute it and/or modify it | ||
10 | * under the terms of the GNU General Public License as published by the Free | ||
11 | * Software Foundation; either version 2 of the License, or (at your option) | ||
12 | * any later version. | ||
13 | */ | ||
14 | |||
15 | #include <linux/types.h> | ||
16 | |||
17 | #define DRIVER_VERSION "v0.3.0" | ||
18 | #define DRIVER_AUTHOR "Stefan Achatz" | ||
19 | #define DRIVER_DESC "USB Roccat Kone driver" | ||
20 | #define DRIVER_LICENSE "GPL v2" | ||
21 | |||
22 | #pragma pack(push) | ||
23 | #pragma pack(1) | ||
24 | |||
25 | struct kone_keystroke { | ||
26 | uint8_t key; | ||
27 | uint8_t action; | ||
28 | uint16_t period; /* in milliseconds */ | ||
29 | }; | ||
30 | |||
31 | enum kone_keystroke_buttons { | ||
32 | kone_keystroke_button_1 = 0xf0, /* left mouse button */ | ||
33 | kone_keystroke_button_2 = 0xf1, /* right mouse button */ | ||
34 | kone_keystroke_button_3 = 0xf2, /* wheel */ | ||
35 | kone_keystroke_button_9 = 0xf3, /* side button up */ | ||
36 | kone_keystroke_button_8 = 0xf4 /* side button down */ | ||
37 | }; | ||
38 | |||
39 | enum kone_keystroke_actions { | ||
40 | kone_keystroke_action_press = 0, | ||
41 | kone_keystroke_action_release = 1 | ||
42 | }; | ||
43 | |||
44 | struct kone_button_info { | ||
45 | uint8_t number; /* range 1-8 */ | ||
46 | uint8_t type; | ||
47 | uint8_t macro_type; /* 0 = short, 1 = overlong */ | ||
48 | uint8_t macro_set_name[16]; /* can be max 15 chars long */ | ||
49 | uint8_t macro_name[16]; /* can be max 15 chars long */ | ||
50 | uint8_t count; | ||
51 | struct kone_keystroke keystrokes[20]; | ||
52 | }; | ||
53 | |||
54 | enum kone_button_info_types { | ||
55 | /* valid button types until firmware 1.32 */ | ||
56 | kone_button_info_type_button_1 = 0x1, /* click (left mouse button) */ | ||
57 | kone_button_info_type_button_2 = 0x2, /* menu (right mouse button)*/ | ||
58 | kone_button_info_type_button_3 = 0x3, /* scroll (wheel) */ | ||
59 | kone_button_info_type_double_click = 0x4, | ||
60 | kone_button_info_type_key = 0x5, | ||
61 | kone_button_info_type_macro = 0x6, | ||
62 | kone_button_info_type_off = 0x7, | ||
63 | /* TODO clarify function and rename */ | ||
64 | kone_button_info_type_osd_xy_prescaling = 0x8, | ||
65 | kone_button_info_type_osd_dpi = 0x9, | ||
66 | kone_button_info_type_osd_profile = 0xa, | ||
67 | kone_button_info_type_button_9 = 0xb, /* ie forward */ | ||
68 | kone_button_info_type_button_8 = 0xc, /* ie backward */ | ||
69 | kone_button_info_type_dpi_up = 0xd, /* internal */ | ||
70 | kone_button_info_type_dpi_down = 0xe, /* internal */ | ||
71 | kone_button_info_type_button_7 = 0xf, /* tilt left */ | ||
72 | kone_button_info_type_button_6 = 0x10, /* tilt right */ | ||
73 | kone_button_info_type_profile_up = 0x11, /* internal */ | ||
74 | kone_button_info_type_profile_down = 0x12, /* internal */ | ||
75 | /* additional valid button types since firmware 1.38 */ | ||
76 | kone_button_info_type_multimedia_open_player = 0x20, | ||
77 | kone_button_info_type_multimedia_next_track = 0x21, | ||
78 | kone_button_info_type_multimedia_prev_track = 0x22, | ||
79 | kone_button_info_type_multimedia_play_pause = 0x23, | ||
80 | kone_button_info_type_multimedia_stop = 0x24, | ||
81 | kone_button_info_type_multimedia_mute = 0x25, | ||
82 | kone_button_info_type_multimedia_volume_up = 0x26, | ||
83 | kone_button_info_type_multimedia_volume_down = 0x27 | ||
84 | }; | ||
85 | |||
86 | struct kone_light_info { | ||
87 | uint8_t number; /* number of light 1-5 */ | ||
88 | uint8_t mod; /* 1 = on, 2 = off */ | ||
89 | uint8_t red; /* range 0x00-0xff */ | ||
90 | uint8_t green; /* range 0x00-0xff */ | ||
91 | uint8_t blue; /* range 0x00-0xff */ | ||
92 | }; | ||
93 | |||
94 | struct kone_profile { | ||
95 | uint16_t size; /* always 975 */ | ||
96 | uint16_t unused; /* always 0 */ | ||
97 | |||
98 | /* | ||
99 | * range 1-5 | ||
100 | * This number does not need to correspond with location where profile | ||
101 | * saved | ||
102 | */ | ||
103 | uint8_t profile; /* range 1-5 */ | ||
104 | |||
105 | uint16_t main_sensitivity; /* range 100-1000 */ | ||
106 | uint8_t xy_sensitivity_enabled; /* 1 = on, 2 = off */ | ||
107 | uint16_t x_sensitivity; /* range 100-1000 */ | ||
108 | uint16_t y_sensitivity; /* range 100-1000 */ | ||
109 | uint8_t dpi_rate; /* bit 1 = 800, ... */ | ||
110 | uint8_t startup_dpi; /* range 1-6 */ | ||
111 | uint8_t polling_rate; /* 1 = 125Hz, 2 = 500Hz, 3 = 1000Hz */ | ||
112 | /* kone has no dcu | ||
113 | * value is always 2 in firmwares <= 1.32 and | ||
114 | * 1 in firmwares > 1.32 | ||
115 | */ | ||
116 | uint8_t dcu_flag; | ||
117 | uint8_t light_effect_1; /* range 1-3 */ | ||
118 | uint8_t light_effect_2; /* range 1-5 */ | ||
119 | uint8_t light_effect_3; /* range 1-4 */ | ||
120 | uint8_t light_effect_speed; /* range 0-255 */ | ||
121 | |||
122 | struct kone_light_info light_infos[5]; | ||
123 | struct kone_button_info button_infos[8]; | ||
124 | |||
125 | uint16_t checksum; /* \brief holds checksum of struct */ | ||
126 | }; | ||
127 | |||
128 | enum kone_polling_rates { | ||
129 | kone_polling_rate_125 = 1, | ||
130 | kone_polling_rate_500 = 2, | ||
131 | kone_polling_rate_1000 = 3 | ||
132 | }; | ||
133 | |||
134 | struct kone_settings { | ||
135 | uint16_t size; /* always 36 */ | ||
136 | uint8_t startup_profile; /* 1-5 */ | ||
137 | uint8_t unknown1; | ||
138 | uint8_t tcu; /* 0 = off, 1 = on */ | ||
139 | uint8_t unknown2[23]; | ||
140 | uint8_t calibration_data[4]; | ||
141 | uint8_t unknown3[2]; | ||
142 | uint16_t checksum; | ||
143 | }; | ||
144 | |||
145 | /* | ||
146 | * 12 byte mouse event read by interrupt_read | ||
147 | */ | ||
148 | struct kone_mouse_event { | ||
149 | uint8_t report_number; /* always 1 */ | ||
150 | uint8_t button; | ||
151 | uint16_t x; | ||
152 | uint16_t y; | ||
153 | uint8_t wheel; /* up = 1, down = -1 */ | ||
154 | uint8_t tilt; /* right = 1, left = -1 */ | ||
155 | uint8_t unknown; | ||
156 | uint8_t event; | ||
157 | uint8_t value; /* press = 0, release = 1 */ | ||
158 | uint8_t macro_key; /* 0 to 8 */ | ||
159 | }; | ||
160 | |||
161 | enum kone_mouse_events { | ||
162 | /* osd events are thought to be display on screen */ | ||
163 | kone_mouse_event_osd_dpi = 0xa0, | ||
164 | kone_mouse_event_osd_profile = 0xb0, | ||
165 | /* TODO clarify meaning and occurence of kone_mouse_event_calibration */ | ||
166 | kone_mouse_event_calibration = 0xc0, | ||
167 | kone_mouse_event_call_overlong_macro = 0xe0, | ||
168 | /* switch events notify if user changed values wiht mousebutton click */ | ||
169 | kone_mouse_event_switch_dpi = 0xf0, | ||
170 | kone_mouse_event_switch_profile = 0xf1 | ||
171 | }; | ||
172 | |||
173 | enum kone_commands { | ||
174 | kone_command_profile = 0x5a, | ||
175 | kone_command_settings = 0x15a, | ||
176 | kone_command_firmware_version = 0x25a, | ||
177 | kone_command_weight = 0x45a, | ||
178 | kone_command_calibrate = 0x55a, | ||
179 | kone_command_confirm_write = 0x65a, | ||
180 | kone_command_firmware = 0xe5a | ||
181 | }; | ||
182 | |||
183 | #pragma pack(pop) | ||
184 | |||
185 | struct kone_device { | ||
186 | /* | ||
187 | * Storing actual values when we get informed about changes since there | ||
188 | * is no way of getting this information from the device on demand | ||
189 | */ | ||
190 | int actual_profile, actual_dpi; | ||
191 | /* Used for neutralizing abnormal tilt button behaviour */ | ||
192 | int last_tilt_state; | ||
193 | /* | ||
194 | * It's unlikely that multiple sysfs attributes are accessed at a time, | ||
195 | * so only one mutex is used to secure hardware access and profiles and | ||
196 | * settings of this struct. | ||
197 | */ | ||
198 | struct mutex kone_lock; | ||
199 | |||
200 | /* | ||
201 | * Storing the data here reduces IO and ensures that data is available | ||
202 | * when its needed (E.g. interrupt handler). | ||
203 | */ | ||
204 | struct kone_profile profiles[5]; | ||
205 | struct kone_settings settings; | ||
206 | |||
207 | /* | ||
208 | * firmware doesn't change unless firmware update is implemented, | ||
209 | * so it's read only once | ||
210 | */ | ||
211 | int firmware_version; | ||
212 | }; | ||
213 | |||
214 | #endif | ||