blob: cf5c7c0898fd4e6c488321a55259f2855a23a3f4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 *
4 * Lowlevel functions for Hoontech STDSP24
5 *
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02006 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/io.h>
25#include <linux/delay.h>
26#include <linux/interrupt.h>
27#include <linux/init.h>
28#include <linux/slab.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010029#include <linux/mutex.h>
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
32
33#include "ice1712.h"
34#include "hoontech.h"
35
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010036/* Hoontech-specific setting */
37struct hoontech_spec {
38 unsigned char boxbits[4];
39 unsigned int config;
40 unsigned short boxconfig[4];
41};
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Takashi Iwai6ca308d2005-11-17 14:59:52 +010043static void __devinit snd_ice1712_stdsp24_gpio_write(struct snd_ice1712 *ice, unsigned char byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
45 byte |= ICE1712_STDSP24_CLOCK_BIT;
46 udelay(100);
47 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
48 byte &= ~ICE1712_STDSP24_CLOCK_BIT;
49 udelay(100);
50 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
51 byte |= ICE1712_STDSP24_CLOCK_BIT;
52 udelay(100);
53 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, byte);
54}
55
Takashi Iwai6ca308d2005-11-17 14:59:52 +010056static void __devinit snd_ice1712_stdsp24_darear(struct snd_ice1712 *ice, int activate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010058 struct hoontech_spec *spec = ice->spec;
Ingo Molnar62932df2006-01-16 16:34:20 +010059 mutex_lock(&ice->gpio_mutex);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010060 ICE1712_STDSP24_0_DAREAR(spec->boxbits, activate);
61 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
Ingo Molnar62932df2006-01-16 16:34:20 +010062 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063}
64
Takashi Iwai6ca308d2005-11-17 14:59:52 +010065static void __devinit snd_ice1712_stdsp24_mute(struct snd_ice1712 *ice, int activate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010067 struct hoontech_spec *spec = ice->spec;
Ingo Molnar62932df2006-01-16 16:34:20 +010068 mutex_lock(&ice->gpio_mutex);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010069 ICE1712_STDSP24_3_MUTE(spec->boxbits, activate);
70 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
Ingo Molnar62932df2006-01-16 16:34:20 +010071 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072}
73
Takashi Iwai6ca308d2005-11-17 14:59:52 +010074static void __devinit snd_ice1712_stdsp24_insel(struct snd_ice1712 *ice, int activate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010076 struct hoontech_spec *spec = ice->spec;
Ingo Molnar62932df2006-01-16 16:34:20 +010077 mutex_lock(&ice->gpio_mutex);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010078 ICE1712_STDSP24_3_INSEL(spec->boxbits, activate);
79 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
Ingo Molnar62932df2006-01-16 16:34:20 +010080 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Takashi Iwai6ca308d2005-11-17 14:59:52 +010083static void __devinit snd_ice1712_stdsp24_box_channel(struct snd_ice1712 *ice, int box, int chn, int activate)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010085 struct hoontech_spec *spec = ice->spec;
86
Ingo Molnar62932df2006-01-16 16:34:20 +010087 mutex_lock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 /* select box */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010090 ICE1712_STDSP24_0_BOX(spec->boxbits, box);
91 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 /* prepare for write */
94 if (chn == 3)
Takashi Iwai7cda8ba2008-01-18 13:36:07 +010095 ICE1712_STDSP24_2_CHN4(spec->boxbits, 0);
96 ICE1712_STDSP24_2_MIDI1(spec->boxbits, activate);
97 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
98 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100100 ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
101 ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
102 ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
103 ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
104 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
105 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 udelay(100);
107 if (chn == 3) {
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100108 ICE1712_STDSP24_2_CHN4(spec->boxbits, 0);
109 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 } else {
111 switch (chn) {
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100112 case 0: ICE1712_STDSP24_1_CHN1(spec->boxbits, 0); break;
113 case 1: ICE1712_STDSP24_1_CHN2(spec->boxbits, 0); break;
114 case 2: ICE1712_STDSP24_1_CHN3(spec->boxbits, 0); break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100116 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
118 udelay(100);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100119 ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
120 ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
121 ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
122 ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
123 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[1]);
124 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 udelay(100);
126
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100127 ICE1712_STDSP24_2_MIDI1(spec->boxbits, 0);
128 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Ingo Molnar62932df2006-01-16 16:34:20 +0100130 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100133static void __devinit snd_ice1712_stdsp24_box_midi(struct snd_ice1712 *ice, int box, int master)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100135 struct hoontech_spec *spec = ice->spec;
136
Ingo Molnar62932df2006-01-16 16:34:20 +0100137 mutex_lock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* select box */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100140 ICE1712_STDSP24_0_BOX(spec->boxbits, box);
141 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100143 ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
144 ICE1712_STDSP24_2_MIDI1(spec->boxbits, master);
145 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
146 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 udelay(100);
149
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100150 ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 0);
151 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 mdelay(10);
154
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100155 ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
156 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Ingo Molnar62932df2006-01-16 16:34:20 +0100158 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100161static void __devinit snd_ice1712_stdsp24_midi2(struct snd_ice1712 *ice, int activate)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100163 struct hoontech_spec *spec = ice->spec;
Ingo Molnar62932df2006-01-16 16:34:20 +0100164 mutex_lock(&ice->gpio_mutex);
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100165 ICE1712_STDSP24_3_MIDI2(spec->boxbits, activate);
166 snd_ice1712_stdsp24_gpio_write(ice, spec->boxbits[3]);
Ingo Molnar62932df2006-01-16 16:34:20 +0100167 mutex_unlock(&ice->gpio_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168}
169
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100170static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100172 struct hoontech_spec *spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 int box, chn;
174
175 ice->num_total_dacs = 8;
176 ice->num_total_adcs = 8;
177
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100178 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
179 if (!spec)
180 return -ENOMEM;
181 ice->spec = spec;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100183 ICE1712_STDSP24_SET_ADDR(spec->boxbits, 0);
184 ICE1712_STDSP24_CLOCK(spec->boxbits, 0, 1);
185 ICE1712_STDSP24_0_BOX(spec->boxbits, 0);
186 ICE1712_STDSP24_0_DAREAR(spec->boxbits, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100188 ICE1712_STDSP24_SET_ADDR(spec->boxbits, 1);
189 ICE1712_STDSP24_CLOCK(spec->boxbits, 1, 1);
190 ICE1712_STDSP24_1_CHN1(spec->boxbits, 1);
191 ICE1712_STDSP24_1_CHN2(spec->boxbits, 1);
192 ICE1712_STDSP24_1_CHN3(spec->boxbits, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100194 ICE1712_STDSP24_SET_ADDR(spec->boxbits, 2);
195 ICE1712_STDSP24_CLOCK(spec->boxbits, 2, 1);
196 ICE1712_STDSP24_2_CHN4(spec->boxbits, 1);
197 ICE1712_STDSP24_2_MIDIIN(spec->boxbits, 1);
198 ICE1712_STDSP24_2_MIDI1(spec->boxbits, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100200 ICE1712_STDSP24_SET_ADDR(spec->boxbits, 3);
201 ICE1712_STDSP24_CLOCK(spec->boxbits, 3, 1);
202 ICE1712_STDSP24_3_MIDI2(spec->boxbits, 0);
203 ICE1712_STDSP24_3_MUTE(spec->boxbits, 1);
204 ICE1712_STDSP24_3_INSEL(spec->boxbits, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 /* let's go - activate only functions in first box */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100207 spec->config = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /* ICE1712_STDSP24_MUTE |
209 ICE1712_STDSP24_INSEL |
210 ICE1712_STDSP24_DAREAR; */
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100211 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 ICE1712_STDSP24_BOX_CHN2 |
213 ICE1712_STDSP24_BOX_CHN3 |
214 ICE1712_STDSP24_BOX_CHN4 |
215 ICE1712_STDSP24_BOX_MIDI1 |
216 ICE1712_STDSP24_BOX_MIDI2;
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100217 spec->boxconfig[1] =
218 spec->boxconfig[2] =
219 spec->boxconfig[3] = 0;
220 snd_ice1712_stdsp24_darear(ice,
221 (spec->config & ICE1712_STDSP24_DAREAR) ? 1 : 0);
222 snd_ice1712_stdsp24_mute(ice,
223 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
224 snd_ice1712_stdsp24_insel(ice,
225 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
Jaroslav Kyselab8c5b532008-01-16 20:12:34 +0100226 for (box = 0; box < 1; box++) {
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100227 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
Jaroslav Kyselab8c5b532008-01-16 20:12:34 +0100228 snd_ice1712_stdsp24_midi2(ice, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 for (chn = 0; chn < 4; chn++)
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100230 snd_ice1712_stdsp24_box_channel(ice, box, chn,
231 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 snd_ice1712_stdsp24_box_midi(ice, box,
Takashi Iwai7cda8ba2008-01-18 13:36:07 +0100233 (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 }
235
236 return 0;
237}
238
239/*
240 * AK4524 access
241 */
242
243/* start callback for STDSP24 with modified hardware */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100244static void stdsp24_ak4524_lock(struct snd_akm4xxx *ak, int chip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245{
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100246 struct snd_ice1712 *ice = ak->private_data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 unsigned char tmp;
248 snd_ice1712_save_gpio_status(ice);
249 tmp = ICE1712_STDSP24_SERIAL_DATA |
250 ICE1712_STDSP24_SERIAL_CLOCK |
251 ICE1712_STDSP24_AK4524_CS;
252 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION,
253 ice->gpio.direction | tmp);
254 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ~tmp);
255}
256
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100257static int __devinit snd_ice1712_value_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 /* Hoontech STDSP24 with modified hardware */
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100260 static struct snd_akm4xxx akm_stdsp24_mv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 .num_adcs = 2,
262 .num_dacs = 2,
263 .type = SND_AK4524,
264 .ops = {
265 .lock = stdsp24_ak4524_lock
266 }
267 };
268
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100269 static struct snd_ak4xxx_private akm_stdsp24_mv_priv __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 .caddr = 2,
271 .cif = 1, /* CIF high */
272 .data_mask = ICE1712_STDSP24_SERIAL_DATA,
273 .clk_mask = ICE1712_STDSP24_SERIAL_CLOCK,
274 .cs_mask = ICE1712_STDSP24_AK4524_CS,
275 .cs_addr = ICE1712_STDSP24_AK4524_CS,
276 .cs_none = 0,
277 .add_flags = 0,
278 };
279
280 int err;
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100281 struct snd_akm4xxx *ak;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 /* set the analog DACs */
284 ice->num_total_dacs = 2;
285
286 /* set the analog ADCs */
287 ice->num_total_adcs = 2;
288
289 /* analog section */
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100290 ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 if (! ak)
292 return -ENOMEM;
293 ice->akm_codecs = 1;
294
295 err = snd_ice1712_akm4xxx_init(ak, &akm_stdsp24_mv, &akm_stdsp24_mv_priv, ice);
296 if (err < 0)
297 return err;
298
299 /* ak4524 controls */
300 err = snd_ice1712_akm4xxx_build_controls(ice);
301 if (err < 0)
302 return err;
303
304 return 0;
305}
306
Takashi Iwai6ca308d2005-11-17 14:59:52 +0100307static int __devinit snd_ice1712_ez8_init(struct snd_ice1712 *ice)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 ice->gpio.write_mask = ice->eeprom.gpiomask;
310 ice->gpio.direction = ice->eeprom.gpiodir;
311 snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, ice->eeprom.gpiomask);
312 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, ice->eeprom.gpiodir);
313 snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, ice->eeprom.gpiostate);
314 return 0;
315}
316
317
318/* entry point */
Ralf Baechlebf748ed2007-03-13 15:31:08 +0100319struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 {
321 .subvendor = ICE1712_SUBDEVICE_STDSP24,
322 .name = "Hoontech SoundTrack Audio DSP24",
323 .model = "dsp24",
324 .chip_init = snd_ice1712_hoontech_init,
325 },
326 {
327 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
328 .name = "Hoontech SoundTrack Audio DSP24 Value",
329 .model = "dsp24_value",
330 .chip_init = snd_ice1712_value_init,
331 },
332 {
333 .subvendor = ICE1712_SUBDEVICE_STDSP24_MEDIA7_1,
334 .name = "Hoontech STA DSP24 Media 7.1",
335 .model = "dsp24_71",
336 .chip_init = snd_ice1712_hoontech_init,
337 },
338 {
339 .subvendor = ICE1712_SUBDEVICE_EVENT_EZ8, /* a dummy id */
340 .name = "Event Electronics EZ8",
341 .model = "ez8",
342 .chip_init = snd_ice1712_ez8_init,
343 },
344 { } /* terminator */
345};