1 /* 2 * Copyright (c) 2007 Daniel Mack 3 * friendly supported by NI. 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #include <linux/init.h> 21 #include <linux/usb.h> 22 #include <sound/control.h> 23 #include <sound/core.h> 24 #include <sound/pcm.h> 25 26 #include "device.h" 27 #include "control.h" 28 29 #define CNT_INTVAL 0x10000 30 31 static int control_info(struct snd_kcontrol *kcontrol, 32 struct snd_ctl_elem_info *uinfo) 33 { 34 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 35 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 36 int pos = kcontrol->private_value; 37 int is_intval = pos & CNT_INTVAL; 38 unsigned int id = dev->chip.usb_id; 39 40 uinfo->count = 1; 41 pos &= ~CNT_INTVAL; 42 43 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ) 44 && (pos == 0)) { 45 /* current input mode of A8DJ */ 46 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 47 uinfo->value.integer.min = 0; 48 uinfo->value.integer.max = 2; 49 return 0; 50 } 51 52 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ) 53 && (pos == 0)) { 54 /* current input mode of A4DJ */ 55 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 56 uinfo->value.integer.min = 0; 57 uinfo->value.integer.max = 1; 58 return 0; 59 } 60 61 if (is_intval) { 62 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 63 uinfo->value.integer.min = 0; 64 uinfo->value.integer.max = 64; 65 } else { 66 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 67 uinfo->value.integer.min = 0; 68 uinfo->value.integer.max = 1; 69 } 70 71 return 0; 72 } 73 74 static int control_get(struct snd_kcontrol *kcontrol, 75 struct snd_ctl_elem_value *ucontrol) 76 { 77 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 78 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 79 int pos = kcontrol->private_value; 80 81 if (dev->chip.usb_id == 82 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) { 83 /* A4DJ has only one control */ 84 /* do not expose hardware input mode 0 */ 85 ucontrol->value.integer.value[0] = dev->control_state[0] - 1; 86 return 0; 87 } 88 89 if (pos & CNT_INTVAL) 90 ucontrol->value.integer.value[0] 91 = dev->control_state[pos & ~CNT_INTVAL]; 92 else 93 ucontrol->value.integer.value[0] 94 = !!(dev->control_state[pos / 8] & (1 << pos % 8)); 95 96 return 0; 97 } 98 99 static int control_put(struct snd_kcontrol *kcontrol, 100 struct snd_ctl_elem_value *ucontrol) 101 { 102 struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol); 103 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 104 int pos = kcontrol->private_value; 105 106 if (dev->chip.usb_id == 107 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) { 108 /* A4DJ has only one control */ 109 /* do not expose hardware input mode 0 */ 110 dev->control_state[0] = ucontrol->value.integer.value[0] + 1; 111 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, 112 dev->control_state, sizeof(dev->control_state)); 113 return 1; 114 } 115 116 if (pos & CNT_INTVAL) { 117 dev->control_state[pos & ~CNT_INTVAL] 118 = ucontrol->value.integer.value[0]; 119 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, 120 dev->control_state, sizeof(dev->control_state)); 121 } else { 122 if (ucontrol->value.integer.value[0]) 123 dev->control_state[pos / 8] |= 1 << (pos % 8); 124 else 125 dev->control_state[pos / 8] &= ~(1 << (pos % 8)); 126 127 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO, 128 dev->control_state, sizeof(dev->control_state)); 129 } 130 131 return 1; 132 } 133 134 static struct snd_kcontrol_new kcontrol_template __devinitdata = { 135 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, 136 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, 137 .index = 0, 138 .info = control_info, 139 .get = control_get, 140 .put = control_put, 141 /* name and private_value filled later */ 142 }; 143 144 struct caiaq_controller { 145 char *name; 146 int index; 147 }; 148 149 static struct caiaq_controller ak1_controller[] = { 150 { "LED left", 2 }, 151 { "LED middle", 1 }, 152 { "LED right", 0 }, 153 { "LED ring", 3 } 154 }; 155 156 static struct caiaq_controller rk2_controller[] = { 157 { "LED 1", 5 }, 158 { "LED 2", 4 }, 159 { "LED 3", 3 }, 160 { "LED 4", 2 }, 161 { "LED 5", 1 }, 162 { "LED 6", 0 }, 163 { "LED pedal", 6 }, 164 { "LED 7seg_1b", 8 }, 165 { "LED 7seg_1c", 9 }, 166 { "LED 7seg_2a", 10 }, 167 { "LED 7seg_2b", 11 }, 168 { "LED 7seg_2c", 12 }, 169 { "LED 7seg_2d", 13 }, 170 { "LED 7seg_2e", 14 }, 171 { "LED 7seg_2f", 15 }, 172 { "LED 7seg_2g", 16 }, 173 { "LED 7seg_3a", 17 }, 174 { "LED 7seg_3b", 18 }, 175 { "LED 7seg_3c", 19 }, 176 { "LED 7seg_3d", 20 }, 177 { "LED 7seg_3e", 21 }, 178 { "LED 7seg_3f", 22 }, 179 { "LED 7seg_3g", 23 } 180 }; 181 182 static struct caiaq_controller rk3_controller[] = { 183 { "LED 7seg_1a", 0 + 0 }, 184 { "LED 7seg_1b", 0 + 1 }, 185 { "LED 7seg_1c", 0 + 2 }, 186 { "LED 7seg_1d", 0 + 3 }, 187 { "LED 7seg_1e", 0 + 4 }, 188 { "LED 7seg_1f", 0 + 5 }, 189 { "LED 7seg_1g", 0 + 6 }, 190 { "LED 7seg_1p", 0 + 7 }, 191 192 { "LED 7seg_2a", 8 + 0 }, 193 { "LED 7seg_2b", 8 + 1 }, 194 { "LED 7seg_2c", 8 + 2 }, 195 { "LED 7seg_2d", 8 + 3 }, 196 { "LED 7seg_2e", 8 + 4 }, 197 { "LED 7seg_2f", 8 + 5 }, 198 { "LED 7seg_2g", 8 + 6 }, 199 { "LED 7seg_2p", 8 + 7 }, 200 201 { "LED 7seg_3a", 16 + 0 }, 202 { "LED 7seg_3b", 16 + 1 }, 203 { "LED 7seg_3c", 16 + 2 }, 204 { "LED 7seg_3d", 16 + 3 }, 205 { "LED 7seg_3e", 16 + 4 }, 206 { "LED 7seg_3f", 16 + 5 }, 207 { "LED 7seg_3g", 16 + 6 }, 208 { "LED 7seg_3p", 16 + 7 }, 209 210 { "LED 7seg_4a", 24 + 0 }, 211 { "LED 7seg_4b", 24 + 1 }, 212 { "LED 7seg_4c", 24 + 2 }, 213 { "LED 7seg_4d", 24 + 3 }, 214 { "LED 7seg_4e", 24 + 4 }, 215 { "LED 7seg_4f", 24 + 5 }, 216 { "LED 7seg_4g", 24 + 6 }, 217 { "LED 7seg_4p", 24 + 7 }, 218 219 { "LED 1", 32 + 0 }, 220 { "LED 2", 32 + 1 }, 221 { "LED 3", 32 + 2 }, 222 { "LED 4", 32 + 3 }, 223 { "LED 5", 32 + 4 }, 224 { "LED 6", 32 + 5 }, 225 { "LED 7", 32 + 6 }, 226 { "LED 8", 32 + 7 }, 227 { "LED pedal", 32 + 8 } 228 }; 229 230 static struct caiaq_controller kore_controller[] = { 231 { "LED F1", 8 | CNT_INTVAL }, 232 { "LED F2", 12 | CNT_INTVAL }, 233 { "LED F3", 0 | CNT_INTVAL }, 234 { "LED F4", 4 | CNT_INTVAL }, 235 { "LED F5", 11 | CNT_INTVAL }, 236 { "LED F6", 15 | CNT_INTVAL }, 237 { "LED F7", 3 | CNT_INTVAL }, 238 { "LED F8", 7 | CNT_INTVAL }, 239 { "LED touch1", 10 | CNT_INTVAL }, 240 { "LED touch2", 14 | CNT_INTVAL }, 241 { "LED touch3", 2 | CNT_INTVAL }, 242 { "LED touch4", 6 | CNT_INTVAL }, 243 { "LED touch5", 9 | CNT_INTVAL }, 244 { "LED touch6", 13 | CNT_INTVAL }, 245 { "LED touch7", 1 | CNT_INTVAL }, 246 { "LED touch8", 5 | CNT_INTVAL }, 247 { "LED left", 18 | CNT_INTVAL }, 248 { "LED right", 22 | CNT_INTVAL }, 249 { "LED up", 16 | CNT_INTVAL }, 250 { "LED down", 20 | CNT_INTVAL }, 251 { "LED stop", 23 | CNT_INTVAL }, 252 { "LED play", 21 | CNT_INTVAL }, 253 { "LED record", 19 | CNT_INTVAL }, 254 { "LED listen", 17 | CNT_INTVAL }, 255 { "LED lcd", 30 | CNT_INTVAL }, 256 { "LED menu", 28 | CNT_INTVAL }, 257 { "LED sound", 31 | CNT_INTVAL }, 258 { "LED esc", 29 | CNT_INTVAL }, 259 { "LED view", 27 | CNT_INTVAL }, 260 { "LED enter", 24 | CNT_INTVAL }, 261 { "LED control", 26 | CNT_INTVAL } 262 }; 263 264 static struct caiaq_controller a8dj_controller[] = { 265 { "Current input mode", 0 | CNT_INTVAL }, 266 { "GND lift for TC Vinyl mode", 24 + 0 }, 267 { "GND lift for TC CD/Line mode", 24 + 1 }, 268 { "GND lift for phono mode", 24 + 2 }, 269 { "Software lock", 40 } 270 }; 271 272 static struct caiaq_controller a4dj_controller[] = { 273 { "Current input mode", 0 | CNT_INTVAL } 274 }; 275 276 static int __devinit add_controls(struct caiaq_controller *c, int num, 277 struct snd_usb_caiaqdev *dev) 278 { 279 int i, ret; 280 struct snd_kcontrol *kc; 281 282 for (i = 0; i < num; i++, c++) { 283 kcontrol_template.name = c->name; 284 kcontrol_template.private_value = c->index; 285 kc = snd_ctl_new1(&kcontrol_template, dev); 286 ret = snd_ctl_add(dev->chip.card, kc); 287 if (ret < 0) 288 return ret; 289 } 290 291 return 0; 292 } 293 294 int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev) 295 { 296 int ret = 0; 297 298 switch (dev->chip.usb_id) { 299 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 300 ret = add_controls(ak1_controller, 301 ARRAY_SIZE(ak1_controller), dev); 302 break; 303 304 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2): 305 ret = add_controls(rk2_controller, 306 ARRAY_SIZE(rk2_controller), dev); 307 break; 308 309 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 310 ret = add_controls(rk3_controller, 311 ARRAY_SIZE(rk3_controller), dev); 312 break; 313 314 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER): 315 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2): 316 ret = add_controls(kore_controller, 317 ARRAY_SIZE(kore_controller), dev); 318 break; 319 320 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 321 ret = add_controls(a8dj_controller, 322 ARRAY_SIZE(a8dj_controller), dev); 323 break; 324 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ): 325 ret = add_controls(a4dj_controller, 326 ARRAY_SIZE(a4dj_controller), dev); 327 break; 328 } 329 330 return ret; 331 } 332 333