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