caiaq-control.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. #include <linux/init.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/usb.h>
  22. #include <sound/core.h>
  23. #include <sound/initval.h>
  24. #include <sound/pcm.h>
  25. #include <sound/rawmidi.h>
  26. #include <sound/control.h>
  27. #include <linux/input.h>
  28. #include "caiaq-device.h"
  29. #include "caiaq-control.h"
  30. #define CNT_INTVAL 0x10000
  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. uinfo->count = 1;
  39. pos &= ~CNT_INTVAL;
  40. if (dev->chip.usb_id ==
  41. USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
  42. && (pos == 0)) {
  43. /* current input mode of A8DJ */
  44. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  45. uinfo->value.integer.min = 0;
  46. uinfo->value.integer.max = 2;
  47. return 0;
  48. }
  49. if (is_intval) {
  50. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  51. uinfo->value.integer.min = 0;
  52. uinfo->value.integer.max = 64;
  53. } else {
  54. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  55. uinfo->value.integer.min = 0;
  56. uinfo->value.integer.max = 1;
  57. }
  58. return 0;
  59. }
  60. static int control_get(struct snd_kcontrol *kcontrol,
  61. struct snd_ctl_elem_value *ucontrol)
  62. {
  63. struct snd_usb_audio *chip = snd_kcontrol_chip(kcontrol);
  64. struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
  65. int pos = kcontrol->private_value;
  66. if (pos & CNT_INTVAL)
  67. ucontrol->value.integer.value[0]
  68. = dev->control_state[pos & ~CNT_INTVAL];
  69. else
  70. ucontrol->value.integer.value[0]
  71. = !!(dev->control_state[pos / 8] & (1 << pos % 8));
  72. return 0;
  73. }
  74. static int control_put(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. if (pos & CNT_INTVAL) {
  81. dev->control_state[pos & ~CNT_INTVAL]
  82. = ucontrol->value.integer.value[0];
  83. snd_usb_caiaq_send_command(dev, EP1_CMD_DIMM_LEDS,
  84. dev->control_state, sizeof(dev->control_state));
  85. } else {
  86. if (ucontrol->value.integer.value[0])
  87. dev->control_state[pos / 8] |= 1 << (pos % 8);
  88. else
  89. dev->control_state[pos / 8] &= ~(1 << (pos % 8));
  90. snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
  91. dev->control_state, sizeof(dev->control_state));
  92. }
  93. return 1;
  94. }
  95. static struct snd_kcontrol_new kcontrol_template __devinitdata = {
  96. .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
  97. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  98. .index = 0,
  99. .info = control_info,
  100. .get = control_get,
  101. .put = control_put,
  102. /* name and private_value filled later */
  103. };
  104. struct caiaq_controller {
  105. char *name;
  106. int index;
  107. };
  108. static struct caiaq_controller ak1_controller[] = {
  109. { "LED left", 2 },
  110. { "LED middle", 1 },
  111. { "LED right", 0 },
  112. { "LED ring", 3 }
  113. };
  114. static struct caiaq_controller rk2_controller[] = {
  115. { "LED 1", 5 },
  116. { "LED 2", 4 },
  117. { "LED 3", 3 },
  118. { "LED 4", 2 },
  119. { "LED 5", 1 },
  120. { "LED 6", 0 },
  121. { "LED pedal", 6 },
  122. { "LED 7seg_1b", 8 },
  123. { "LED 7seg_1c", 9 },
  124. { "LED 7seg_2a", 10 },
  125. { "LED 7seg_2b", 11 },
  126. { "LED 7seg_2c", 12 },
  127. { "LED 7seg_2d", 13 },
  128. { "LED 7seg_2e", 14 },
  129. { "LED 7seg_2f", 15 },
  130. { "LED 7seg_2g", 16 },
  131. { "LED 7seg_3a", 17 },
  132. { "LED 7seg_3b", 18 },
  133. { "LED 7seg_3c", 19 },
  134. { "LED 7seg_3d", 20 },
  135. { "LED 7seg_3e", 21 },
  136. { "LED 7seg_3f", 22 },
  137. { "LED 7seg_3g", 23 }
  138. };
  139. static struct caiaq_controller rk3_controller[] = {
  140. { "LED 7seg_1a", 0 + 0 },
  141. { "LED 7seg_1b", 0 + 1 },
  142. { "LED 7seg_1c", 0 + 2 },
  143. { "LED 7seg_1d", 0 + 3 },
  144. { "LED 7seg_1e", 0 + 4 },
  145. { "LED 7seg_1f", 0 + 5 },
  146. { "LED 7seg_1g", 0 + 6 },
  147. { "LED 7seg_1p", 0 + 7 },
  148. { "LED 7seg_2a", 8 + 0 },
  149. { "LED 7seg_2b", 8 + 1 },
  150. { "LED 7seg_2c", 8 + 2 },
  151. { "LED 7seg_2d", 8 + 3 },
  152. { "LED 7seg_2e", 8 + 4 },
  153. { "LED 7seg_2f", 8 + 5 },
  154. { "LED 7seg_2g", 8 + 6 },
  155. { "LED 7seg_2p", 8 + 7 },
  156. { "LED 7seg_3a", 16 + 0 },
  157. { "LED 7seg_3b", 16 + 1 },
  158. { "LED 7seg_3c", 16 + 2 },
  159. { "LED 7seg_3d", 16 + 3 },
  160. { "LED 7seg_3e", 16 + 4 },
  161. { "LED 7seg_3f", 16 + 5 },
  162. { "LED 7seg_3g", 16 + 6 },
  163. { "LED 7seg_3p", 16 + 7 },
  164. { "LED 7seg_4a", 24 + 0 },
  165. { "LED 7seg_4b", 24 + 1 },
  166. { "LED 7seg_4c", 24 + 2 },
  167. { "LED 7seg_4d", 24 + 3 },
  168. { "LED 7seg_4e", 24 + 4 },
  169. { "LED 7seg_4f", 24 + 5 },
  170. { "LED 7seg_4g", 24 + 6 },
  171. { "LED 7seg_4p", 24 + 7 },
  172. { "LED 1", 32 + 0 },
  173. { "LED 2", 32 + 1 },
  174. { "LED 3", 32 + 2 },
  175. { "LED 4", 32 + 3 },
  176. { "LED 5", 32 + 4 },
  177. { "LED 6", 32 + 5 },
  178. { "LED 7", 32 + 6 },
  179. { "LED 8", 32 + 7 },
  180. { "LED pedal", 32 + 8 }
  181. };
  182. static struct caiaq_controller kore_controller[] = {
  183. { "LED F1", 8 | CNT_INTVAL },
  184. { "LED F2", 12 | CNT_INTVAL },
  185. { "LED F3", 0 | CNT_INTVAL },
  186. { "LED F4", 4 | CNT_INTVAL },
  187. { "LED F5", 11 | CNT_INTVAL },
  188. { "LED F6", 15 | CNT_INTVAL },
  189. { "LED F7", 3 | CNT_INTVAL },
  190. { "LED F8", 7 | CNT_INTVAL },
  191. { "LED touch1", 10 | CNT_INTVAL },
  192. { "LED touch2", 14 | CNT_INTVAL },
  193. { "LED touch3", 2 | CNT_INTVAL },
  194. { "LED touch4", 6 | CNT_INTVAL },
  195. { "LED touch5", 9 | CNT_INTVAL },
  196. { "LED touch6", 13 | CNT_INTVAL },
  197. { "LED touch7", 1 | CNT_INTVAL },
  198. { "LED touch8", 5 | CNT_INTVAL },
  199. { "LED left", 18 | CNT_INTVAL },
  200. { "LED right", 22 | CNT_INTVAL },
  201. { "LED up", 16 | CNT_INTVAL },
  202. { "LED down", 20 | CNT_INTVAL },
  203. { "LED stop", 23 | CNT_INTVAL },
  204. { "LED play", 21 | CNT_INTVAL },
  205. { "LED record", 19 | CNT_INTVAL },
  206. { "LED listen", 17 | CNT_INTVAL },
  207. { "LED lcd", 30 | CNT_INTVAL },
  208. { "LED menu", 28 | CNT_INTVAL },
  209. { "LED sound", 31 | CNT_INTVAL },
  210. { "LED esc", 29 | CNT_INTVAL },
  211. { "LED view", 27 | CNT_INTVAL },
  212. { "LED enter", 24 | CNT_INTVAL },
  213. { "LED control", 26 | CNT_INTVAL }
  214. };
  215. static struct caiaq_controller a8dj_controller[] = {
  216. { "Current input mode", 0 | CNT_INTVAL },
  217. { "GND lift for TC Vinyl mode", 24 + 0 },
  218. { "GND lift for TC CD/Line mode", 24 + 1 },
  219. { "GND lift for phono mode", 24 + 2 },
  220. { "GND lift for TC Vinyl mode", 24 + 3 },
  221. { "Software lock", 40 }
  222. };
  223. int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
  224. {
  225. int i;
  226. struct snd_kcontrol *kc;
  227. switch (dev->chip.usb_id) {
  228. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
  229. for (i = 0; i < ARRAY_SIZE(ak1_controller); i++) {
  230. struct caiaq_controller *c = ak1_controller + i;
  231. kcontrol_template.name = c->name;
  232. kcontrol_template.private_value = c->index;
  233. kc = snd_ctl_new1(&kcontrol_template, dev);
  234. snd_ctl_add(dev->chip.card, kc);
  235. }
  236. break;
  237. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL2):
  238. for (i = 0; i < ARRAY_SIZE(rk2_controller); i++) {
  239. struct caiaq_controller *c = rk2_controller + i;
  240. kcontrol_template.name = c->name;
  241. kcontrol_template.private_value = c->index;
  242. kc = snd_ctl_new1(&kcontrol_template, dev);
  243. snd_ctl_add(dev->chip.card, kc);
  244. }
  245. break;
  246. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
  247. for (i = 0; i < ARRAY_SIZE(rk3_controller); i++) {
  248. struct caiaq_controller *c = rk3_controller + i;
  249. kcontrol_template.name = c->name;
  250. kcontrol_template.private_value = c->index;
  251. kc = snd_ctl_new1(&kcontrol_template, dev);
  252. snd_ctl_add(dev->chip.card, kc);
  253. }
  254. break;
  255. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER):
  256. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_KORECONTROLLER2):
  257. for (i = 0; i < ARRAY_SIZE(kore_controller); i++) {
  258. struct caiaq_controller *c = kore_controller + i;
  259. kcontrol_template.name = c->name;
  260. kcontrol_template.private_value = c->index;
  261. kc = snd_ctl_new1(&kcontrol_template, dev);
  262. snd_ctl_add(dev->chip.card, kc);
  263. }
  264. break;
  265. case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
  266. for (i = 0; i < ARRAY_SIZE(a8dj_controller); i++) {
  267. struct caiaq_controller *c = a8dj_controller + i;
  268. kcontrol_template.name = c->name;
  269. kcontrol_template.private_value = c->index;
  270. kc = snd_ctl_new1(&kcontrol_template, dev);
  271. snd_ctl_add(dev->chip.card, kc);
  272. }
  273. break;
  274. }
  275. return 0;
  276. }