Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006,2007 Daniel Mack, Tim Ruetz |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/input.h> |
| 23 | #include <linux/usb.h> |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 24 | #include <linux/usb/input.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include <sound/rawmidi.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include "caiaq-device.h" |
| 30 | #include "caiaq-input.h" |
| 31 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 32 | static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A }; |
| 33 | static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4, |
| 34 | KEY_5, KEY_6, KEY_7 }; |
| 35 | static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4, |
| 36 | KEY_5, KEY_6, KEY_7, KEY_5, KEY_6 }; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 37 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 38 | static unsigned short keycode_kore[] = { |
| 39 | KEY_FN_F1, /* "menu" */ |
| 40 | KEY_FN_F7, /* "lcd backlight */ |
| 41 | KEY_FN_F2, /* "control" */ |
| 42 | KEY_FN_F3, /* "enter" */ |
| 43 | KEY_FN_F4, /* "view" */ |
| 44 | KEY_FN_F5, /* "esc" */ |
| 45 | KEY_FN_F6, /* "sound" */ |
| 46 | KEY_FN_F8, /* array spacer, never triggered. */ |
| 47 | KEY_RIGHT, |
| 48 | KEY_DOWN, |
| 49 | KEY_UP, |
| 50 | KEY_LEFT, |
| 51 | KEY_SOUND, /* "listen" */ |
| 52 | KEY_RECORD, |
| 53 | KEY_PLAYPAUSE, |
| 54 | KEY_STOP, |
| 55 | BTN_4, /* 8 softkeys */ |
| 56 | BTN_3, |
| 57 | BTN_2, |
| 58 | BTN_1, |
| 59 | BTN_8, |
| 60 | BTN_7, |
| 61 | BTN_6, |
| 62 | BTN_5, |
| 63 | KEY_BRL_DOT4, /* touch sensitive knobs */ |
| 64 | KEY_BRL_DOT3, |
| 65 | KEY_BRL_DOT2, |
| 66 | KEY_BRL_DOT1, |
| 67 | KEY_BRL_DOT8, |
| 68 | KEY_BRL_DOT7, |
| 69 | KEY_BRL_DOT6, |
| 70 | KEY_BRL_DOT5 |
| 71 | }; |
| 72 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 73 | #define DEG90 (range / 2) |
| 74 | #define DEG180 (range) |
| 75 | #define DEG270 (DEG90 + DEG180) |
| 76 | #define DEG360 (DEG180 * 2) |
| 77 | #define HIGH_PEAK (268) |
| 78 | #define LOW_PEAK (-7) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 79 | |
| 80 | /* some of these devices have endless rotation potentiometers |
| 81 | * built in which use two tapers, 90 degrees phase shifted. |
| 82 | * this algorithm decodes them to one single value, ranging |
| 83 | * from 0 to 999 */ |
| 84 | static unsigned int decode_erp(unsigned char a, unsigned char b) |
| 85 | { |
| 86 | int weight_a, weight_b; |
| 87 | int pos_a, pos_b; |
| 88 | int ret; |
| 89 | int range = HIGH_PEAK - LOW_PEAK; |
| 90 | int mid_value = (HIGH_PEAK + LOW_PEAK) / 2; |
| 91 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 92 | weight_b = abs(mid_value - a) - (range / 2 - 100) / 2; |
| 93 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 94 | if (weight_b < 0) |
| 95 | weight_b = 0; |
| 96 | |
| 97 | if (weight_b > 100) |
| 98 | weight_b = 100; |
| 99 | |
| 100 | weight_a = 100 - weight_b; |
| 101 | |
| 102 | if (a < mid_value) { |
| 103 | /* 0..90 and 270..360 degrees */ |
| 104 | pos_b = b - LOW_PEAK + DEG270; |
| 105 | if (pos_b >= DEG360) |
| 106 | pos_b -= DEG360; |
| 107 | } else |
| 108 | /* 90..270 degrees */ |
| 109 | pos_b = HIGH_PEAK - b + DEG90; |
| 110 | |
| 111 | |
| 112 | if (b > mid_value) |
| 113 | /* 0..180 degrees */ |
| 114 | pos_a = a - LOW_PEAK; |
| 115 | else |
| 116 | /* 180..360 degrees */ |
| 117 | pos_a = HIGH_PEAK - a + DEG180; |
| 118 | |
| 119 | /* interpolate both slider values, depending on weight factors */ |
| 120 | /* 0..99 x DEG360 */ |
| 121 | ret = pos_a * weight_a + pos_b * weight_b; |
| 122 | |
| 123 | /* normalize to 0..999 */ |
| 124 | ret *= 10; |
| 125 | ret /= DEG360; |
| 126 | |
| 127 | if (ret < 0) |
| 128 | ret += 1000; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 129 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 130 | if (ret >= 1000) |
| 131 | ret -= 1000; |
| 132 | |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | #undef DEG90 |
| 137 | #undef DEG180 |
| 138 | #undef DEG270 |
| 139 | #undef DEG360 |
| 140 | #undef HIGH_PEAK |
| 141 | #undef LOW_PEAK |
| 142 | |
| 143 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 144 | static void snd_caiaq_input_read_analog(struct snd_usb_caiaqdev *dev, |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 145 | const unsigned char *buf, |
| 146 | unsigned int len) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 147 | { |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 148 | struct input_dev *input_dev = dev->input_dev; |
| 149 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 150 | switch (dev->chip.usb_id) { |
| 151 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 152 | input_report_abs(input_dev, ABS_X, (buf[4] << 8) | buf[5]); |
| 153 | input_report_abs(input_dev, ABS_Y, (buf[0] << 8) | buf[1]); |
| 154 | input_report_abs(input_dev, ABS_Z, (buf[2] << 8) | buf[3]); |
| 155 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 156 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 157 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
| 158 | input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]); |
| 159 | input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]); |
| 160 | input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); |
| 161 | input_sync(input_dev); |
| 162 | break; |
| 163 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 164 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 165 | input_report_abs(input_dev, ABS_X, (buf[0] << 8) | buf[1]); |
| 166 | input_report_abs(input_dev, ABS_Y, (buf[2] << 8) | buf[3]); |
| 167 | input_report_abs(input_dev, ABS_Z, (buf[4] << 8) | buf[5]); |
| 168 | input_sync(input_dev); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 169 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 173 | static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 174 | const char *buf, unsigned int len) |
| 175 | { |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 176 | struct input_dev *input_dev = dev->input_dev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 177 | int i; |
| 178 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 179 | switch (dev->chip.usb_id) { |
| 180 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 181 | i = decode_erp(buf[0], buf[1]); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 182 | input_report_abs(input_dev, ABS_X, i); |
| 183 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 184 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 185 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 186 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 187 | i = decode_erp(buf[7], buf[5]); |
| 188 | input_report_abs(input_dev, ABS_HAT0X, i); |
| 189 | i = decode_erp(buf[12], buf[14]); |
| 190 | input_report_abs(input_dev, ABS_HAT0Y, i); |
| 191 | i = decode_erp(buf[15], buf[13]); |
| 192 | input_report_abs(input_dev, ABS_HAT1X, i); |
| 193 | i = decode_erp(buf[0], buf[2]); |
| 194 | input_report_abs(input_dev, ABS_HAT1Y, i); |
| 195 | i = decode_erp(buf[3], buf[1]); |
| 196 | input_report_abs(input_dev, ABS_HAT2X, i); |
| 197 | i = decode_erp(buf[8], buf[10]); |
| 198 | input_report_abs(input_dev, ABS_HAT2Y, i); |
| 199 | i = decode_erp(buf[11], buf[9]); |
| 200 | input_report_abs(input_dev, ABS_HAT3X, i); |
| 201 | i = decode_erp(buf[4], buf[6]); |
| 202 | input_report_abs(input_dev, ABS_HAT3Y, i); |
| 203 | input_sync(input_dev); |
| 204 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 208 | static void snd_caiaq_input_read_io(struct snd_usb_caiaqdev *dev, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 209 | char *buf, unsigned int len) |
| 210 | { |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 211 | struct input_dev *input_dev = dev->input_dev; |
| 212 | unsigned short *keycode = input_dev->keycode; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 213 | int i; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 214 | |
| 215 | if (!keycode) |
| 216 | return; |
| 217 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 218 | if (input_dev->id.product == USB_PID_RIGKONTROL2) |
| 219 | for (i = 0; i < len; i++) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 220 | buf[i] = ~buf[i]; |
| 221 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 222 | for (i = 0; i < input_dev->keycodemax && i < len * 8; i++) |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 223 | input_report_key(input_dev, keycode[i], |
| 224 | buf[i / 8] & (1 << (i % 8))); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 225 | |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 226 | if (dev->chip.usb_id == |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 227 | USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER) || |
| 228 | dev->chip.usb_id == |
| 229 | USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2)) |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 230 | input_report_abs(dev->input_dev, ABS_MISC, 255 - buf[4]); |
| 231 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 232 | input_sync(input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 233 | } |
| 234 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 235 | void snd_usb_caiaq_input_dispatch(struct snd_usb_caiaqdev *dev, |
| 236 | char *buf, |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 237 | unsigned int len) |
| 238 | { |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 239 | if (!dev->input_dev || len < 1) |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 240 | return; |
| 241 | |
| 242 | switch (buf[0]) { |
| 243 | case EP1_CMD_READ_ANALOG: |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 244 | snd_caiaq_input_read_analog(dev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 245 | break; |
| 246 | case EP1_CMD_READ_ERP: |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 247 | snd_caiaq_input_read_erp(dev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 248 | break; |
| 249 | case EP1_CMD_READ_IO: |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 250 | snd_caiaq_input_read_io(dev, buf + 1, len - 1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 251 | break; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev) |
| 256 | { |
| 257 | struct usb_device *usb_dev = dev->chip.dev; |
| 258 | struct input_dev *input; |
| 259 | int i, ret; |
| 260 | |
| 261 | input = input_allocate_device(); |
| 262 | if (!input) |
| 263 | return -ENOMEM; |
| 264 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 265 | usb_make_path(usb_dev, dev->phys, sizeof(dev->phys)); |
| 266 | strlcat(dev->phys, "/input0", sizeof(dev->phys)); |
| 267 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 268 | input->name = dev->product_name; |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 269 | input->phys = dev->phys; |
| 270 | usb_to_input_id(usb_dev, &input->id); |
| 271 | input->dev.parent = &usb_dev->dev; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 272 | |
| 273 | switch (dev->chip.usb_id) { |
| 274 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 275 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 276 | input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 277 | BIT_MASK(ABS_Z); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 278 | BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk2)); |
| 279 | memcpy(dev->keycode, keycode_rk2, sizeof(keycode_rk2)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 280 | input->keycodemax = ARRAY_SIZE(keycode_rk2); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 281 | input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); |
| 282 | input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); |
| 283 | input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); |
| 284 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0); |
| 285 | break; |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 286 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 287 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 288 | input->absbit[0] = BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 289 | BIT_MASK(ABS_Z); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 290 | BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_rk3)); |
| 291 | memcpy(dev->keycode, keycode_rk3, sizeof(keycode_rk3)); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 292 | input->keycodemax = ARRAY_SIZE(keycode_rk3); |
Daniel Mack | ad1e34b | 2007-09-17 14:45:14 +0200 | [diff] [blame] | 293 | input_set_abs_params(input, ABS_X, 0, 1024, 0, 10); |
| 294 | input_set_abs_params(input, ABS_Y, 0, 1024, 0, 10); |
| 295 | input_set_abs_params(input, ABS_Z, 0, 1024, 0, 10); |
| 296 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 0); |
| 297 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 298 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): |
Jiri Slaby | 7b19ada | 2007-10-18 23:40:32 -0700 | [diff] [blame] | 299 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 300 | input->absbit[0] = BIT_MASK(ABS_X); |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 301 | BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_ak1)); |
| 302 | memcpy(dev->keycode, keycode_ak1, sizeof(keycode_ak1)); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 303 | input->keycodemax = ARRAY_SIZE(keycode_ak1); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 304 | input_set_abs_params(input, ABS_X, 0, 999, 0, 10); |
| 305 | snd_usb_caiaq_set_auto_msg(dev, 1, 0, 5); |
| 306 | break; |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 307 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): |
Daniel Mack | 7829d0e | 2007-11-26 09:00:56 +0100 | [diff] [blame] | 308 | case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): |
Daniel Mack | 8e3cd08 | 2007-11-22 11:40:04 +0100 | [diff] [blame] | 309 | input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 310 | input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) | |
| 311 | BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) | |
| 312 | BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) | |
| 313 | BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) | |
| 314 | BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) | |
| 315 | BIT_MASK(ABS_Z); |
| 316 | input->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC); |
| 317 | BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_kore)); |
| 318 | memcpy(dev->keycode, keycode_kore, sizeof(keycode_kore)); |
| 319 | input->keycodemax = ARRAY_SIZE(keycode_kore); |
| 320 | input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10); |
| 321 | input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10); |
| 322 | input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10); |
| 323 | input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10); |
| 324 | input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10); |
| 325 | input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10); |
| 326 | input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10); |
| 327 | input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10); |
| 328 | input_set_abs_params(input, ABS_X, 0, 4096, 0, 10); |
| 329 | input_set_abs_params(input, ABS_Y, 0, 4096, 0, 10); |
| 330 | input_set_abs_params(input, ABS_Z, 0, 4096, 0, 10); |
| 331 | input_set_abs_params(input, ABS_MISC, 0, 255, 0, 1); |
| 332 | snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5); |
| 333 | break; |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 334 | default: |
| 335 | /* no input methods supported on this device */ |
| 336 | input_free_device(input); |
| 337 | return 0; |
| 338 | } |
| 339 | |
Dmitry Torokhov | b18b493 | 2007-11-21 16:45:23 +0100 | [diff] [blame] | 340 | input->keycode = dev->keycode; |
| 341 | input->keycodesize = sizeof(unsigned short); |
| 342 | for (i = 0; i < input->keycodemax; i++) |
| 343 | __set_bit(dev->keycode[i], input->keybit); |
| 344 | |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 345 | ret = input_register_device(input); |
| 346 | if (ret < 0) { |
| 347 | input_free_device(input); |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | dev->input_dev = input; |
| 352 | return 0; |
| 353 | } |
| 354 | |
| 355 | void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev) |
| 356 | { |
| 357 | if (!dev || !dev->input_dev) |
| 358 | return; |
| 359 | |
| 360 | input_unregister_device(dev->input_dev); |
Daniel Mack | 523f1dc | 2007-03-26 19:11:24 +0200 | [diff] [blame] | 361 | dev->input_dev = NULL; |
| 362 | } |
| 363 | |