aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb
diff options
context:
space:
mode:
authorDmitry Torokhov <dtor@mail.ru>2007-11-21 10:45:23 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:29:27 -0500
commitb18b493f27bfb0d112a54ef24a1db32e898abff9 (patch)
tree1b4b69f643bb4705ffd105dfa00ac7aa987185aa /sound/usb
parentee6df2e1849403b5805018193a1454f6d39f9498 (diff)
[ALSA] caiaq - misc input handling fixes
- link input device with its parent so that it placed in proper spot in sysfs hierarchy - drivers that allow changing their keymaps should use private copy of the keymap so that one instance of a device does not affect another instance - it is preferred for drivers to properly set up input_dev->phys to help userspace locate devices - drivers should use usb_to_input_id(), or perform endianess conversion, themselves, otherwise ID is not correct on big-endian boxes - whitespace and formatting cleanup Acked-by: Daniel Mack <daniel@caiaq.de> Signed-off-by: Dmitry Torokhov <dtor@mail.ru> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/usb')
-rw-r--r--sound/usb/caiaq/caiaq-device.h10
-rw-r--r--sound/usb/caiaq/caiaq-input.c126
2 files changed, 71 insertions, 65 deletions
diff --git a/sound/usb/caiaq/caiaq-device.h b/sound/usb/caiaq/caiaq-device.h
index 79bc5be2df7a..685761279f1a 100644
--- a/sound/usb/caiaq/caiaq-device.h
+++ b/sound/usb/caiaq/caiaq-device.h
@@ -7,7 +7,7 @@
7 7
8#define USB_PID_RIGKONTROL2 0x1969 8#define USB_PID_RIGKONTROL2 0x1969
9#define USB_PID_RIGKONTROL3 0x1940 9#define USB_PID_RIGKONTROL3 0x1940
10#define USB_PID_KORECONTROLLER 0x4711 10#define USB_PID_KORECONTROLLER 0x4711
11#define USB_PID_AK1 0x0815 11#define USB_PID_AK1 0x0815
12#define USB_PID_AUDIO8DJ 0x1978 12#define USB_PID_AUDIO8DJ 0x1978
13 13
@@ -62,7 +62,7 @@ struct snd_usb_caiaqdev {
62 struct urb **data_urbs_in; 62 struct urb **data_urbs_in;
63 struct urb **data_urbs_out; 63 struct urb **data_urbs_out;
64 struct snd_usb_caiaq_cb_info *data_cb_info; 64 struct snd_usb_caiaq_cb_info *data_cb_info;
65 65
66 unsigned char ep1_in_buf[EP1_BUFSIZE]; 66 unsigned char ep1_in_buf[EP1_BUFSIZE];
67 unsigned char ep1_out_buf[EP1_BUFSIZE]; 67 unsigned char ep1_out_buf[EP1_BUFSIZE];
68 unsigned char midi_out_buf[EP1_BUFSIZE]; 68 unsigned char midi_out_buf[EP1_BUFSIZE];
@@ -72,7 +72,7 @@ struct snd_usb_caiaqdev {
72 wait_queue_head_t ep1_wait_queue; 72 wait_queue_head_t ep1_wait_queue;
73 wait_queue_head_t prepare_wait_queue; 73 wait_queue_head_t prepare_wait_queue;
74 int spec_received, audio_parm_answer; 74 int spec_received, audio_parm_answer;
75 75
76 char vendor_name[CAIAQ_USB_STR_LEN]; 76 char vendor_name[CAIAQ_USB_STR_LEN];
77 char product_name[CAIAQ_USB_STR_LEN]; 77 char product_name[CAIAQ_USB_STR_LEN];
78 char serial[CAIAQ_USB_STR_LEN]; 78 char serial[CAIAQ_USB_STR_LEN];
@@ -93,8 +93,10 @@ struct snd_usb_caiaqdev {
93 /* Linux input */ 93 /* Linux input */
94#ifdef CONFIG_SND_USB_CAIAQ_INPUT 94#ifdef CONFIG_SND_USB_CAIAQ_INPUT
95 struct input_dev *input_dev; 95 struct input_dev *input_dev;
96 char phys[64]; /* physical device path */
97 unsigned short keycode[10];
96#endif 98#endif
97 99
98 /* ALSA */ 100 /* ALSA */
99 struct snd_pcm *pcm; 101 struct snd_pcm *pcm;
100 struct snd_pcm_hardware pcm_info; 102 struct snd_pcm_hardware pcm_info;
diff --git a/sound/usb/caiaq/caiaq-input.c b/sound/usb/caiaq/caiaq-input.c
index cd536ca20e56..03bf4c63b5ef 100644
--- a/sound/usb/caiaq/caiaq-input.c
+++ b/sound/usb/caiaq/caiaq-input.c
@@ -21,6 +21,7 @@
21#include <linux/moduleparam.h> 21#include <linux/moduleparam.h>
22#include <linux/input.h> 22#include <linux/input.h>
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/usb/input.h>
24#include <linux/spinlock.h> 25#include <linux/spinlock.h>
25#include <sound/driver.h> 26#include <sound/driver.h>
26#include <sound/core.h> 27#include <sound/core.h>
@@ -31,18 +32,18 @@
31 32
32#ifdef CONFIG_SND_USB_CAIAQ_INPUT 33#ifdef CONFIG_SND_USB_CAIAQ_INPUT
33 34
34static unsigned char keycode_ak1[] = { KEY_C, KEY_B, KEY_A }; 35static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A };
35static unsigned char keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4, 36static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4,
36 KEY_5, KEY_6, KEY_7 }; 37 KEY_5, KEY_6, KEY_7 };
37static unsigned char keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4, 38static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4,
38 KEY_5, KEY_6, KEY_7, KEY_5, KEY_6 }; 39 KEY_5, KEY_6, KEY_7, KEY_5, KEY_6 };
39 40
40#define DEG90 (range/2) 41#define DEG90 (range / 2)
41#define DEG180 (range) 42#define DEG180 (range)
42#define DEG270 (DEG90 + DEG180) 43#define DEG270 (DEG90 + DEG180)
43#define DEG360 (DEG180 * 2) 44#define DEG360 (DEG180 * 2)
44#define HIGH_PEAK (268) 45#define HIGH_PEAK (268)
45#define LOW_PEAK (-7) 46#define LOW_PEAK (-7)
46 47
47/* some of these devices have endless rotation potentiometers 48/* some of these devices have endless rotation potentiometers
48 * built in which use two tapers, 90 degrees phase shifted. 49 * built in which use two tapers, 90 degrees phase shifted.
@@ -56,8 +57,8 @@ static unsigned int decode_erp(unsigned char a, unsigned char b)
56 int range = HIGH_PEAK - LOW_PEAK; 57 int range = HIGH_PEAK - LOW_PEAK;
57 int mid_value = (HIGH_PEAK + LOW_PEAK) / 2; 58 int mid_value = (HIGH_PEAK + LOW_PEAK) / 2;
58 59
59 weight_b = abs(mid_value-a) - (range/2 - 100)/2; 60 weight_b = abs(mid_value - a) - (range / 2 - 100) / 2;
60 61
61 if (weight_b < 0) 62 if (weight_b < 0)
62 weight_b = 0; 63 weight_b = 0;
63 64
@@ -93,7 +94,7 @@ static unsigned int decode_erp(unsigned char a, unsigned char b)
93 94
94 if (ret < 0) 95 if (ret < 0)
95 ret += 1000; 96 ret += 1000;
96 97
97 if (ret >= 1000) 98 if (ret >= 1000)
98 ret -= 1000; 99 ret -= 1000;
99 100
@@ -108,76 +109,80 @@ static unsigned int decode_erp(unsigned char a, unsigned char b)
108#undef LOW_PEAK 109#undef LOW_PEAK
109 110
110 111
111static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, 112static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev,
112 const unsigned char *buf, 113 const unsigned char *buf,
113 unsigned int len) 114 unsigned int len)
114{ 115{
115 switch(dev->input_dev->id.product) { 116 struct input_dev *input_dev = dev->input_dev;
117
118 switch (input_dev->id.product) {
116 case USB_PID_RIGKONTROL2: 119 case USB_PID_RIGKONTROL2:
117 input_report_abs(dev->input_dev, ABS_X, (buf[4] << 8) |buf[5]); 120 input_report_abs(input_dev, ABS_X, (buf[4] << 8) | buf[5]);
118 input_report_abs(dev->input_dev, ABS_Y, (buf[0] << 8) |buf[1]); 121 input_report_abs(input_dev, ABS_Y, (buf[0] << 8) | buf[1]);
119 input_report_abs(dev->input_dev, ABS_Z, (buf[2] << 8) |buf[3]); 122 input_report_abs(input_dev, ABS_Z, (buf[2] << 8) | buf[3]);
120 input_sync(dev->input_dev); 123 input_sync(input_dev);
121 break; 124 break;
122 case USB_PID_RIGKONTROL3: 125 case USB_PID_RIGKONTROL3:
123 input_report_abs(dev->input_dev, ABS_X, (buf[0] << 8) |buf[1]); 126 input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]);
124 input_report_abs(dev->input_dev, ABS_Y, (buf[2] << 8) |buf[3]); 127 input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]);
125 input_report_abs(dev->input_dev, ABS_Z, (buf[4] << 8) |buf[5]); 128 input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]);
126 input_sync(dev->input_dev); 129 input_sync(input_dev);
127 break; 130 break;
128 } 131 }
129} 132}
130 133
131static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, 134static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
132 const char *buf, unsigned int len) 135 const char *buf, unsigned int len)
133{ 136{
137 struct input_dev *input_dev = dev->input_dev;
134 int i; 138 int i;
135 139
136 switch(dev->input_dev->id.product) { 140 switch (input_dev->id.product) {
137 case USB_PID_AK1: 141 case USB_PID_AK1:
138 i = decode_erp(buf[0], buf[1]); 142 i = decode_erp(buf[0], buf[1]);
139 input_report_abs(dev->input_dev, ABS_X, i); 143 input_report_abs(input_dev, ABS_X, i);
140 input_sync(dev->input_dev); 144 input_sync(input_dev);
141 break; 145 break;
142 } 146 }
143} 147}
144 148
145static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev, 149static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev,
146 char *buf, unsigned int len) 150 char *buf, unsigned int len)
147{ 151{
152 struct input_dev *input_dev = dev->input_dev;
153 unsigned short *keycode = input_dev->keycode;
148 int i; 154 int i;
149 unsigned char *keycode = dev->input_dev->keycode;
150 155
151 if (!keycode) 156 if (!keycode)
152 return; 157 return;
153 158
154 if (dev->input_dev->id.product == USB_PID_RIGKONTROL2) 159 if (input_dev->id.product == USB_PID_RIGKONTROL2)
155 for (i=0; i<len; i++) 160 for (i = 0; i < len; i++)
156 buf[i] = ~buf[i]; 161 buf[i] = ~buf[i];
157 162
158 for (i=0; (i<dev->input_dev->keycodemax) && (i < len); i++) 163 for (i = 0; i < input_dev->keycodemax && i < len; i++)
159 input_report_key(dev->input_dev, keycode[i], 164 input_report_key(input_dev, keycode[i],
160 buf[i/8] & (1 << (i%8))); 165 buf[i / 8] & (1 << (i % 8)));
161 166
162 input_sync(dev->input_dev); 167 input_sync(input_dev);
163} 168}
164 169
165void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev, 170void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev,
166 char *buf, 171 char *buf,
167 unsigned int len) 172 unsigned int len)
168{ 173{
169 if (!dev->input_dev || (len < 1)) 174 if (!dev->input_dev || len < 1)
170 return; 175 return;
171 176
172 switch (buf[0]) { 177 switch (buf[0]) {
173 case EP1_CMD_READ_ANALOG: 178 case EP1_CMD_READ_ANALOG:
174 snd_caiaq_input_read_analog(dev, buf+1, len-1); 179 snd_caiaq_input_read_analog(dev, buf + 1, len - 1);
175 break; 180 break;
176 case EP1_CMD_READ_ERP: 181 case EP1_CMD_READ_ERP:
177 snd_caiaq_input_read_erp(dev, buf+1, len-1); 182 snd_caiaq_input_read_erp(dev, buf + 1, len - 1);
178 break; 183 break;
179 case EP1_CMD_READ_IO: 184 case EP1_CMD_READ_IO:
180 snd_caiaq_input_read_io(dev, buf+1, len-1); 185 snd_caiaq_input_read_io(dev, buf + 1, len - 1);
181 break; 186 break;
182 } 187 }
183} 188}
@@ -192,37 +197,34 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
192 if (!input) 197 if (!input)
193 return -ENOMEM; 198 return -ENOMEM;
194 199
200 usb_make_path(usb_dev, dev->phys, sizeof(dev->phys));
201 strlcat(dev->phys, "/input0", sizeof(dev->phys));
202
195 input->name = dev->product_name; 203 input->name = dev->product_name;
196 input->id.bustype = BUS_USB; 204 input->phys = dev->phys;
197 input->id.vendor = usb_dev->descriptor.idVendor; 205 usb_to_input_id(usb_dev, &input->id);
198 input->id.product = usb_dev->descriptor.idProduct; 206 input->dev.parent = &usb_dev->dev;
199 input->id.version = usb_dev->descriptor.bcdDevice;
200 207
201 switch (dev->chip.usb_id) { 208 switch (dev->chip.usb_id) {
202 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 209 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
203 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 210 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
204 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | 211 input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
205 BIT_MASK(ABS_Z); 212 BIT_MASK(ABS_Z);
206 input->keycode = keycode_rk2; 213 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk2));
207 input->keycodesize = sizeof(char); 214 memcpy(dev->keycode, keycode_rk2, sizeof(keycode_rk2));
208 input->keycodemax = ARRAY_SIZE(keycode_rk2); 215 input->keycodemax = ARRAY_SIZE(keycode_rk2);
209 for (i=0; i<ARRAY_SIZE(keycode_rk2); i++)
210 set_bit(keycode_rk2[i], input->keybit);
211
212 input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); 216 input_set_abs_params(input, ABS_X, 0, 4096, 0, 10);
213 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); 217 input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10);
214 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); 218 input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10);
215 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0); 219 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0);
216 break; 220 break;
221
217 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 222 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
218 input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 223 input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
219 input->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_Z); 224 input->absbit[0] = BIT(ABS_X) | BIT(ABS_Y) | BIT(ABS_Z);
220 input->keycode = keycode_rk3; 225 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk3));
221 input->keycodesize = sizeof(char); 226 memcpy(dev->keycode, keycode_rk3, sizeof(keycode_rk3));
222 input->keycodemax = ARRAY_SIZE(keycode_rk3); 227 input->keycodemax = ARRAY_SIZE(keycode_rk3);
223 for (i=0; i<ARRAY_SIZE(keycode_rk3); i++)
224 set_bit(keycode_rk3[i], input->keybit);
225
226 input_set_abs_params(input, ABS_X, 0, 1024, 0, 10); 228 input_set_abs_params(input, ABS_X, 0, 1024, 0, 10);
227 input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10); 229 input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10);
228 input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10); 230 input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10);
@@ -231,12 +233,9 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
231 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 233 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
232 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 234 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
233 input->absbit[0] = BIT_MASK(ABS_X); 235 input->absbit[0] = BIT_MASK(ABS_X);
234 input->keycode = keycode_ak1; 236 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_ak1));
235 input->keycodesize = sizeof(char); 237 memcpy(dev->keycode, keycode_ak1, sizeof(keycode_ak1));
236 input->keycodemax = ARRAY_SIZE(keycode_ak1); 238 input->keycodemax = ARRAY_SIZE(keycode_ak1);
237 for (i=0; i<ARRAY_SIZE(keycode_ak1); i++)
238 set_bit(keycode_ak1[i], input->keybit);
239
240 input_set_abs_params(input, ABS_X, 0, 999, 0, 10); 239 input_set_abs_params(input, ABS_X, 0, 999, 0, 10);
241 snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5); 240 snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5);
242 break; 241 break;
@@ -246,6 +245,11 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
246 return 0; 245 return 0;
247 } 246 }
248 247
248 input->keycode = dev->keycode;
249 input->keycodesize = sizeof(unsigned short);
250 for (i = 0; i < input->keycodemax; i++)
251 __set_bit(dev->keycode[i], input->keybit);
252
249 ret = input_register_device(input); 253 ret = input_register_device(input);
250 if (ret < 0) { 254 if (ret < 0) {
251 input_free_device(input); 255 input_free_device(input);