delta.c 23.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 *   ALSA driver for ICEnsemble ICE1712 (Envy24)
 *
4 5
 *   Lowlevel functions for M-Audio Delta 1010, 1010E, 44, 66, 66E, Dio2496,
 *			    Audiophile, Digigram VX442
L
Linus Torvalds 已提交
6
 *
7
 *	Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
L
Linus Torvalds 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */      

#include <asm/io.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/init.h>
#include <linux/slab.h>
30 31
#include <linux/mutex.h>

L
Linus Torvalds 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#include <sound/core.h>
#include <sound/cs8427.h>
#include <sound/asoundef.h>

#include "ice1712.h"
#include "delta.h"

#define SND_CS8403
#include <sound/cs8403.h>


/*
 * CS8427 via SPI mode (for Audiophile), emulated I2C
 */

/* send 8 bits */
48
static void ap_cs8427_write_byte(struct snd_ice1712 *ice, unsigned char data, unsigned char tmp)
L
Linus Torvalds 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
{
	int idx;

	for (idx = 7; idx >= 0; idx--) {
		tmp &= ~(ICE1712_DELTA_AP_DOUT|ICE1712_DELTA_AP_CCLK);
		if (data & (1 << idx))
			tmp |= ICE1712_DELTA_AP_DOUT;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(5);
		tmp |= ICE1712_DELTA_AP_CCLK;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(5);
	}
}

/* read 8 bits */
65
static unsigned char ap_cs8427_read_byte(struct snd_ice1712 *ice, unsigned char tmp)
L
Linus Torvalds 已提交
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
{
	unsigned char data = 0;
	int idx;
	
	for (idx = 7; idx >= 0; idx--) {
		tmp &= ~ICE1712_DELTA_AP_CCLK;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(5);
		if (snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ICE1712_DELTA_AP_DIN)
			data |= 1 << idx;
		tmp |= ICE1712_DELTA_AP_CCLK;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(5);
	}
	return data;
}

/* assert chip select */
84
static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
L
Linus Torvalds 已提交
85 86 87 88
{
	unsigned char tmp;
	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
	switch (ice->eeprom.subvendor) {
89
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
	case ICE1712_SUBDEVICE_DELTA1010LT:
		tmp &= ~ICE1712_DELTA_1010LT_CS;
		tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
		break;
	case ICE1712_SUBDEVICE_AUDIOPHILE:
	case ICE1712_SUBDEVICE_DELTA410:
		tmp |= ICE1712_DELTA_AP_CCLK | ICE1712_DELTA_AP_CS_CODEC;
		tmp &= ~ICE1712_DELTA_AP_CS_DIGITAL;
		break;
	case ICE1712_SUBDEVICE_VX442:
		tmp |= ICE1712_VX442_CCLK | ICE1712_VX442_CODEC_CHIP_A | ICE1712_VX442_CODEC_CHIP_B;
		tmp &= ~ICE1712_VX442_CS_DIGITAL;
		break;
	}
	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
	udelay(5);
	return tmp;
}

/* deassert chip select */
110
static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
L
Linus Torvalds 已提交
111 112
{
	switch (ice->eeprom.subvendor) {
113
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
	case ICE1712_SUBDEVICE_DELTA1010LT:
		tmp &= ~ICE1712_DELTA_1010LT_CS;
		tmp |= ICE1712_DELTA_1010LT_CS_NONE;
		break;
	case ICE1712_SUBDEVICE_AUDIOPHILE:
	case ICE1712_SUBDEVICE_DELTA410:
		tmp |= ICE1712_DELTA_AP_CS_DIGITAL;
		break;
	case ICE1712_SUBDEVICE_VX442:
		tmp |= ICE1712_VX442_CS_DIGITAL;
		break;
	}
	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
}

/* sequential write */
130
static int ap_cs8427_sendbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
L
Linus Torvalds 已提交
131
{
132
	struct snd_ice1712 *ice = device->bus->private_data;
L
Linus Torvalds 已提交
133 134 135
	int res = count;
	unsigned char tmp;

136
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
137 138 139 140 141
	tmp = ap_cs8427_codec_select(ice);
	ap_cs8427_write_byte(ice, (device->addr << 1) | 0, tmp); /* address + write mode */
	while (count-- > 0)
		ap_cs8427_write_byte(ice, *bytes++, tmp);
	ap_cs8427_codec_deassert(ice, tmp);
142
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
143 144 145 146
	return res;
}

/* sequential read */
147
static int ap_cs8427_readbytes(struct snd_i2c_device *device, unsigned char *bytes, int count)
L
Linus Torvalds 已提交
148
{
149
	struct snd_ice1712 *ice = device->bus->private_data;
L
Linus Torvalds 已提交
150 151 152
	int res = count;
	unsigned char tmp;
	
153
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
154 155 156 157 158
	tmp = ap_cs8427_codec_select(ice);
	ap_cs8427_write_byte(ice, (device->addr << 1) | 1, tmp); /* address + read mode */
	while (count-- > 0)
		*bytes++ = ap_cs8427_read_byte(ice, tmp);
	ap_cs8427_codec_deassert(ice, tmp);
159
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
160 161 162
	return res;
}

163
static int ap_cs8427_probeaddr(struct snd_i2c_bus *bus, unsigned short addr)
L
Linus Torvalds 已提交
164 165 166 167 168 169
{
	if (addr == 0x10)
		return 1;
	return -ENOENT;
}

170
static struct snd_i2c_ops ap_cs8427_i2c_ops = {
L
Linus Torvalds 已提交
171 172 173 174 175 176 177 178
	.sendbytes = ap_cs8427_sendbytes,
	.readbytes = ap_cs8427_readbytes,
	.probeaddr = ap_cs8427_probeaddr,
};

/*
 */

179
static void snd_ice1712_delta_cs8403_spdif_write(struct snd_ice1712 *ice, unsigned char bits)
L
Linus Torvalds 已提交
180 181 182 183 184 185
{
	unsigned char tmp, mask1, mask2;
	int idx;
	/* send byte to transmitter */
	mask1 = ICE1712_DELTA_SPDIF_OUT_STAT_CLOCK;
	mask2 = ICE1712_DELTA_SPDIF_OUT_STAT_DATA;
186
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
187 188 189 190 191 192 193 194 195 196 197 198 199
	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
	for (idx = 7; idx >= 0; idx--) {
		tmp &= ~(mask1 | mask2);
		if (bits & (1 << idx))
			tmp |= mask2;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(100);
		tmp |= mask1;
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
		udelay(100);
	}
	tmp &= ~mask1;
	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
200
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
201 202 203
}


204
static void delta_spdif_default_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
205 206 207 208
{
	snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_bits);
}

209
static int delta_spdif_default_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
{
	unsigned int val;
	int change;

	val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
	spin_lock_irq(&ice->reg_lock);
	change = ice->spdif.cs8403_bits != val;
	ice->spdif.cs8403_bits = val;
	if (change && ice->playback_pro_substream == NULL) {
		spin_unlock_irq(&ice->reg_lock);
		snd_ice1712_delta_cs8403_spdif_write(ice, val);
	} else {
		spin_unlock_irq(&ice->reg_lock);
	}
	return change;
}

227
static void delta_spdif_stream_get(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
228 229 230 231
{
	snd_cs8403_decode_spdif_bits(&ucontrol->value.iec958, ice->spdif.cs8403_stream_bits);
}

232
static int delta_spdif_stream_put(struct snd_ice1712 *ice, struct snd_ctl_elem_value *ucontrol)
L
Linus Torvalds 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
{
	unsigned int val;
	int change;

	val = snd_cs8403_encode_spdif_bits(&ucontrol->value.iec958);
	spin_lock_irq(&ice->reg_lock);
	change = ice->spdif.cs8403_stream_bits != val;
	ice->spdif.cs8403_stream_bits = val;
	if (change && ice->playback_pro_substream != NULL) {
		spin_unlock_irq(&ice->reg_lock);
		snd_ice1712_delta_cs8403_spdif_write(ice, val);
	} else {
		spin_unlock_irq(&ice->reg_lock);
	}
	return change;
}


/*
 * AK4524 on Delta 44 and 66 to choose the chip mask
 */
254
static void delta_ak4524_lock(struct snd_akm4xxx *ak, int chip)
L
Linus Torvalds 已提交
255 256
{
        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
257
        struct snd_ice1712 *ice = ak->private_data[0];
L
Linus Torvalds 已提交
258 259 260 261 262 263 264 265 266 267

	snd_ice1712_save_gpio_status(ice);
	priv->cs_mask =
	priv->cs_addr = chip == 0 ? ICE1712_DELTA_CODEC_CHIP_A :
				    ICE1712_DELTA_CODEC_CHIP_B;
}

/*
 * AK4524 on Delta1010LT to choose the chip address
 */
268
static void delta1010lt_ak4524_lock(struct snd_akm4xxx *ak, int chip)
L
Linus Torvalds 已提交
269 270
{
        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
271
        struct snd_ice1712 *ice = ak->private_data[0];
L
Linus Torvalds 已提交
272 273 274 275 276 277 278 279 280

	snd_ice1712_save_gpio_status(ice);
	priv->cs_mask = ICE1712_DELTA_1010LT_CS;
	priv->cs_addr = chip << 4;
}

/*
 * AK4528 on VX442 to choose the chip mask
 */
281
static void vx442_ak4524_lock(struct snd_akm4xxx *ak, int chip)
L
Linus Torvalds 已提交
282 283
{
        struct snd_ak4xxx_private *priv = (void *)ak->private_value[0];
284
        struct snd_ice1712 *ice = ak->private_data[0];
L
Linus Torvalds 已提交
285 286 287 288 289 290 291 292 293 294

	snd_ice1712_save_gpio_status(ice);
	priv->cs_mask =
	priv->cs_addr = chip == 0 ? ICE1712_VX442_CODEC_CHIP_A :
				    ICE1712_VX442_CODEC_CHIP_B;
}

/*
 * change the DFS bit according rate for Delta1010
 */
295
static void delta_1010_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
L
Linus Torvalds 已提交
296 297 298 299 300 301
{
	unsigned char tmp, tmp2;

	if (rate == 0)	/* no hint - S/PDIF input is master, simply return */
		return;

302
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
303 304 305 306 307 308
	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
	tmp2 = tmp & ~ICE1712_DELTA_DFS;
	if (rate > 48000)
		tmp2 |= ICE1712_DELTA_DFS;
	if (tmp != tmp2)
		snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp2);
309
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
310 311 312 313 314
}

/*
 * change the rate of AK4524 on Delta 44/66, AP, 1010LT
 */
315
static void delta_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
L
Linus Torvalds 已提交
316 317
{
	unsigned char tmp, tmp2;
318
	struct snd_ice1712 *ice = ak->private_data[0];
L
Linus Torvalds 已提交
319 320 321 322 323

	if (rate == 0)	/* no hint - S/PDIF input is master, simply return */
		return;

	/* check before reset ak4524 to avoid unnecessary clicks */
324
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
325
	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
326
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
327 328 329 330 331 332 333 334
	tmp2 = tmp & ~ICE1712_DELTA_DFS; 
	if (rate > 48000)
		tmp2 |= ICE1712_DELTA_DFS;
	if (tmp == tmp2)
		return;

	/* do it again */
	snd_akm4xxx_reset(ak, 1);
335
	mutex_lock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
336 337 338 339
	tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA) & ~ICE1712_DELTA_DFS;
	if (rate > 48000)
		tmp |= ICE1712_DELTA_DFS;
	snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, tmp);
340
	mutex_unlock(&ice->gpio_mutex);
L
Linus Torvalds 已提交
341 342 343 344 345 346
	snd_akm4xxx_reset(ak, 0);
}

/*
 * change the rate of AK4524 on VX442
 */
347
static void vx442_ak4524_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
L
Linus Torvalds 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
{
	unsigned char val;

	val = (rate > 48000) ? 0x65 : 0x60;
	if (snd_akm4xxx_get(ak, 0, 0x02) != val ||
	    snd_akm4xxx_get(ak, 1, 0x02) != val) {
		snd_akm4xxx_reset(ak, 1);
		snd_akm4xxx_write(ak, 0, 0x02, val);
		snd_akm4xxx_write(ak, 1, 0x02, val);
		snd_akm4xxx_reset(ak, 0);
	}
}


/*
 * SPDIF ops for Delta 1010, Dio, 66
 */

/* open callback */
367
static void delta_open_spdif(struct snd_ice1712 *ice, struct snd_pcm_substream *substream)
L
Linus Torvalds 已提交
368 369 370 371 372
{
	ice->spdif.cs8403_stream_bits = ice->spdif.cs8403_bits;
}

/* set up */
373
static void delta_setup_spdif(struct snd_ice1712 *ice, int rate)
L
Linus Torvalds 已提交
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
{
	unsigned long flags;
	unsigned int tmp;
	int change;

	spin_lock_irqsave(&ice->reg_lock, flags);
	tmp = ice->spdif.cs8403_stream_bits;
	if (tmp & 0x01)		/* consumer */
		tmp &= (tmp & 0x01) ? ~0x06 : ~0x18;
	switch (rate) {
	case 32000: tmp |= (tmp & 0x01) ? 0x04 : 0x00; break;
	case 44100: tmp |= (tmp & 0x01) ? 0x00 : 0x10; break;
	case 48000: tmp |= (tmp & 0x01) ? 0x02 : 0x08; break;
	default: tmp |= (tmp & 0x01) ? 0x00 : 0x18; break;
	}
	change = ice->spdif.cs8403_stream_bits != tmp;
	ice->spdif.cs8403_stream_bits = tmp;
	spin_unlock_irqrestore(&ice->reg_lock, flags);
	if (change)
		snd_ctl_notify(ice->card, SNDRV_CTL_EVENT_MASK_VALUE, &ice->spdif.stream_ctl->id);
	snd_ice1712_delta_cs8403_spdif_write(ice, tmp);
}

397 398
#define snd_ice1712_delta1010lt_wordclock_status_info \
	snd_ctl_boolean_mono_info
399

400
static int snd_ice1712_delta1010lt_wordclock_status_get(struct snd_kcontrol *kcontrol,
401 402
			 struct snd_ctl_elem_value *ucontrol)
{
403
	char reg = 0x10; /* CS8427 receiver error register */
404 405 406 407 408
	struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);

	if (snd_i2c_sendbytes(ice->cs8427, &reg, 1) != 1)
		snd_printk(KERN_ERR "unable to send register 0x%x byte to CS8427\n", reg);
	snd_i2c_readbytes(ice->cs8427, &reg, 1);
409
	ucontrol->value.integer.value[0] = (reg & CS8427_UNLOCK) ? 1 : 0;
410 411 412
	return 0;
}

R
Ralf Baechle 已提交
413
static struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_status __devinitdata =
414 415 416 417 418 419 420
{
	.access =	(SNDRV_CTL_ELEM_ACCESS_READ),
	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
	.name =         "Word Clock Status",
	.info =		snd_ice1712_delta1010lt_wordclock_status_info,
	.get =		snd_ice1712_delta1010lt_wordclock_status_get,
};
L
Linus Torvalds 已提交
421 422 423 424 425

/*
 * initialize the chips on M-Audio cards
 */

R
Ralf Baechle 已提交
426
static struct snd_akm4xxx akm_audiophile __devinitdata = {
L
Linus Torvalds 已提交
427 428 429 430 431 432 433 434
	.type = SND_AK4528,
	.num_adcs = 2,
	.num_dacs = 2,
	.ops = {
		.set_rate_val = delta_ak4524_set_rate_val
	}
};

R
Ralf Baechle 已提交
435
static struct snd_ak4xxx_private akm_audiophile_priv __devinitdata = {
L
Linus Torvalds 已提交
436 437 438 439 440 441 442 443 444 445 446
	.caddr = 2,
	.cif = 0,
	.data_mask = ICE1712_DELTA_AP_DOUT,
	.clk_mask = ICE1712_DELTA_AP_CCLK,
	.cs_mask = ICE1712_DELTA_AP_CS_CODEC,
	.cs_addr = ICE1712_DELTA_AP_CS_CODEC,
	.cs_none = 0,
	.add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
	.mask_flags = 0,
};

R
Ralf Baechle 已提交
447
static struct snd_akm4xxx akm_delta410 __devinitdata = {
L
Linus Torvalds 已提交
448 449 450 451 452 453 454 455
	.type = SND_AK4529,
	.num_adcs = 2,
	.num_dacs = 8,
	.ops = {
		.set_rate_val = delta_ak4524_set_rate_val
	}
};

R
Ralf Baechle 已提交
456
static struct snd_ak4xxx_private akm_delta410_priv __devinitdata = {
L
Linus Torvalds 已提交
457 458 459 460 461 462 463 464 465 466 467
	.caddr = 0,
	.cif = 0,
	.data_mask = ICE1712_DELTA_AP_DOUT,
	.clk_mask = ICE1712_DELTA_AP_CCLK,
	.cs_mask = ICE1712_DELTA_AP_CS_CODEC,
	.cs_addr = ICE1712_DELTA_AP_CS_CODEC,
	.cs_none = 0,
	.add_flags = ICE1712_DELTA_AP_CS_DIGITAL,
	.mask_flags = 0,
};

R
Ralf Baechle 已提交
468
static struct snd_akm4xxx akm_delta1010lt __devinitdata = {
L
Linus Torvalds 已提交
469 470 471 472 473 474 475 476 477
	.type = SND_AK4524,
	.num_adcs = 8,
	.num_dacs = 8,
	.ops = {
		.lock = delta1010lt_ak4524_lock,
		.set_rate_val = delta_ak4524_set_rate_val
	}
};

R
Ralf Baechle 已提交
478
static struct snd_ak4xxx_private akm_delta1010lt_priv __devinitdata = {
L
Linus Torvalds 已提交
479 480 481 482 483 484 485 486 487 488 489
	.caddr = 2,
	.cif = 0, /* the default level of the CIF pin from AK4524 */
	.data_mask = ICE1712_DELTA_1010LT_DOUT,
	.clk_mask = ICE1712_DELTA_1010LT_CCLK,
	.cs_mask = 0,
	.cs_addr = 0, /* set later */
	.cs_none = ICE1712_DELTA_1010LT_CS_NONE,
	.add_flags = 0,
	.mask_flags = 0,
};

R
Ralf Baechle 已提交
490
static struct snd_akm4xxx akm_delta44 __devinitdata = {
L
Linus Torvalds 已提交
491 492 493 494 495 496 497 498 499
	.type = SND_AK4524,
	.num_adcs = 4,
	.num_dacs = 4,
	.ops = {
		.lock = delta_ak4524_lock,
		.set_rate_val = delta_ak4524_set_rate_val
	}
};

R
Ralf Baechle 已提交
500
static struct snd_ak4xxx_private akm_delta44_priv __devinitdata = {
L
Linus Torvalds 已提交
501 502 503 504 505 506 507 508 509 510 511
	.caddr = 2,
	.cif = 0, /* the default level of the CIF pin from AK4524 */
	.data_mask = ICE1712_DELTA_CODEC_SERIAL_DATA,
	.clk_mask = ICE1712_DELTA_CODEC_SERIAL_CLOCK,
	.cs_mask = 0,
	.cs_addr = 0, /* set later */
	.cs_none = 0,
	.add_flags = 0,
	.mask_flags = 0,
};

R
Ralf Baechle 已提交
512
static struct snd_akm4xxx akm_vx442 __devinitdata = {
L
Linus Torvalds 已提交
513 514 515 516 517 518 519 520 521
	.type = SND_AK4524,
	.num_adcs = 4,
	.num_dacs = 4,
	.ops = {
		.lock = vx442_ak4524_lock,
		.set_rate_val = vx442_ak4524_set_rate_val
	}
};

R
Ralf Baechle 已提交
522
static struct snd_ak4xxx_private akm_vx442_priv __devinitdata = {
L
Linus Torvalds 已提交
523 524 525 526 527 528 529 530 531 532 533
	.caddr = 2,
	.cif = 0,
	.data_mask = ICE1712_VX442_DOUT,
	.clk_mask = ICE1712_VX442_CCLK,
	.cs_mask = 0,
	.cs_addr = 0, /* set later */
	.cs_none = 0,
	.add_flags = 0,
	.mask_flags = 0,
};

534
static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
L
Linus Torvalds 已提交
535 536
{
	int err;
537
	struct snd_akm4xxx *ak;
L
Linus Torvalds 已提交
538

539 540
	if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA1010 &&
	    ice->eeprom.gpiodir == 0x7b)
541 542
		ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA1010E;

543 544 545 546
	if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA66 &&
	    ice->eeprom.gpiodir == 0xfb)
	    	ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA66E;

L
Linus Torvalds 已提交
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
	/* determine I2C, DACs and ADCs */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_AUDIOPHILE:
		ice->num_total_dacs = 2;
		ice->num_total_adcs = 2;
		break;
	case ICE1712_SUBDEVICE_DELTA410:
		ice->num_total_dacs = 8;
		ice->num_total_adcs = 2;
		break;
	case ICE1712_SUBDEVICE_DELTA44:
	case ICE1712_SUBDEVICE_DELTA66:
		ice->num_total_dacs = ice->omni ? 8 : 4;
		ice->num_total_adcs = ice->omni ? 8 : 4;
		break;
	case ICE1712_SUBDEVICE_DELTA1010:
563
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
564 565 566 567 568 569 570 571 572
	case ICE1712_SUBDEVICE_DELTA1010LT:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		ice->num_total_dacs = 8;
		ice->num_total_adcs = 8;
		break;
	case ICE1712_SUBDEVICE_DELTADIO2496:
		ice->num_total_dacs = 4;	/* two AK4324 codecs */
		break;
	case ICE1712_SUBDEVICE_VX442:
573
	case ICE1712_SUBDEVICE_DELTA66E:	/* omni not suported yet */
L
Linus Torvalds 已提交
574 575 576 577 578 579 580 581 582
		ice->num_total_dacs = 4;
		ice->num_total_adcs = 4;
		break;
	}

	/* initialize spdif */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_AUDIOPHILE:
	case ICE1712_SUBDEVICE_DELTA410:
583
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
584 585
	case ICE1712_SUBDEVICE_DELTA1010LT:
	case ICE1712_SUBDEVICE_VX442:
586
	case ICE1712_SUBDEVICE_DELTA66E:
L
Linus Torvalds 已提交
587
		if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
588
			snd_printk(KERN_ERR "unable to create I2C bus\n");
L
Linus Torvalds 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
			return err;
		}
		ice->i2c->private_data = ice;
		ice->i2c->ops = &ap_cs8427_i2c_ops;
		if ((err = snd_ice1712_init_cs8427(ice, CS8427_BASE_ADDR)) < 0)
			return err;
		break;
	case ICE1712_SUBDEVICE_DELTA1010:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		ice->gpio.set_pro_rate = delta_1010_set_rate_val;
		break;
	case ICE1712_SUBDEVICE_DELTADIO2496:
		ice->gpio.set_pro_rate = delta_1010_set_rate_val;
		/* fall thru */
	case ICE1712_SUBDEVICE_DELTA66:
		ice->spdif.ops.open = delta_open_spdif;
		ice->spdif.ops.setup_rate = delta_setup_spdif;
		ice->spdif.ops.default_get = delta_spdif_default_get;
		ice->spdif.ops.default_put = delta_spdif_default_put;
		ice->spdif.ops.stream_get = delta_spdif_stream_get;
		ice->spdif.ops.stream_put = delta_spdif_stream_put;
		/* Set spdif defaults */
		snd_ice1712_delta_cs8403_spdif_write(ice, ice->spdif.cs8403_bits);
		break;
	}

	/* no analog? */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_DELTA1010:
618
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
619 620 621 622 623 624
	case ICE1712_SUBDEVICE_DELTADIO2496:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		return 0;
	}

	/* second stage of initialization, analog parts and others */
625
	ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
L
Linus Torvalds 已提交
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
	if (! ak)
		return -ENOMEM;
	ice->akm_codecs = 1;

	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_AUDIOPHILE:
		err = snd_ice1712_akm4xxx_init(ak, &akm_audiophile, &akm_audiophile_priv, ice);
		break;
	case ICE1712_SUBDEVICE_DELTA410:
		err = snd_ice1712_akm4xxx_init(ak, &akm_delta410, &akm_delta410_priv, ice);
		break;
	case ICE1712_SUBDEVICE_DELTA1010LT:
		err = snd_ice1712_akm4xxx_init(ak, &akm_delta1010lt, &akm_delta1010lt_priv, ice);
		break;
	case ICE1712_SUBDEVICE_DELTA66:
	case ICE1712_SUBDEVICE_DELTA44:
		err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
		break;
	case ICE1712_SUBDEVICE_VX442:
645
	case ICE1712_SUBDEVICE_DELTA66E:
L
Linus Torvalds 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660
		err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
		break;
	default:
		snd_BUG();
		return -EINVAL;
	}

	return err;
}


/*
 * additional controls for M-Audio cards
 */

R
Ralf Baechle 已提交
661
static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_select __devinitdata =
662
ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_WORD_CLOCK_SELECT, 1, 0);
R
Ralf Baechle 已提交
663
static struct snd_kcontrol_new snd_ice1712_delta1010lt_wordclock_select __devinitdata =
664
ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Sync", 0, ICE1712_DELTA_1010LT_WORDCLOCK, 0, 0);
R
Ralf Baechle 已提交
665
static struct snd_kcontrol_new snd_ice1712_delta1010_wordclock_status __devinitdata =
666
ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Word Clock Status", 0, ICE1712_DELTA_WORD_CLOCK_STATUS, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
R
Ralf Baechle 已提交
667
static struct snd_kcontrol_new snd_ice1712_deltadio2496_spdif_in_select __devinitdata =
668
ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "IEC958 Input Optical", 0, ICE1712_DELTA_SPDIF_INPUT_SELECT, 0, 0);
R
Ralf Baechle 已提交
669
static struct snd_kcontrol_new snd_ice1712_delta_spdif_in_status __devinitdata =
670
ICE1712_GPIO(SNDRV_CTL_ELEM_IFACE_MIXER, "Delta IEC958 Input Status", 0, ICE1712_DELTA_SPDIF_IN_STAT, 1, SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE);
L
Linus Torvalds 已提交
671 672


673
static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
L
Linus Torvalds 已提交
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692
{
	int err;

	/* 1010 and dio specific controls */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_DELTA1010:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_select, ice));
		if (err < 0)
			return err;
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010_wordclock_status, ice));
		if (err < 0)
			return err;
		break;
	case ICE1712_SUBDEVICE_DELTADIO2496:
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_deltadio2496_spdif_in_select, ice));
		if (err < 0)
			return err;
		break;
693
	case ICE1712_SUBDEVICE_DELTA1010E:
L
Linus Torvalds 已提交
694 695
	case ICE1712_SUBDEVICE_DELTA1010LT:
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
696 697 698
		if (err < 0)
			return err;
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_status, ice));
L
Linus Torvalds 已提交
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
		if (err < 0)
			return err;
		break;
	}

	/* normal spdif controls */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_DELTA1010:
	case ICE1712_SUBDEVICE_DELTADIO2496:
	case ICE1712_SUBDEVICE_DELTA66:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		err = snd_ice1712_spdif_build_controls(ice);
		if (err < 0)
			return err;
		break;
	}

	/* spdif status in */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_DELTA1010:
	case ICE1712_SUBDEVICE_DELTADIO2496:
	case ICE1712_SUBDEVICE_DELTA66:
	case ICE1712_SUBDEVICE_MEDIASTATION:
		err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta_spdif_in_status, ice));
		if (err < 0)
			return err;
		break;
	}

	/* ak4524 controls */
	switch (ice->eeprom.subvendor) {
	case ICE1712_SUBDEVICE_DELTA1010LT:
	case ICE1712_SUBDEVICE_AUDIOPHILE:
	case ICE1712_SUBDEVICE_DELTA410:
	case ICE1712_SUBDEVICE_DELTA44:
	case ICE1712_SUBDEVICE_DELTA66:
	case ICE1712_SUBDEVICE_VX442:
736
	case ICE1712_SUBDEVICE_DELTA66E:
L
Linus Torvalds 已提交
737 738 739 740 741 742 743 744 745 746 747
		err = snd_ice1712_akm4xxx_build_controls(ice);
		if (err < 0)
			return err;
		break;
	}

	return 0;
}


/* entry point */
R
Ralf Baechle 已提交
748
struct snd_ice1712_card_info snd_ice1712_delta_cards[] __devinitdata = {
L
Linus Torvalds 已提交
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
	{
		.subvendor = ICE1712_SUBDEVICE_DELTA1010,
		.name = "M Audio Delta 1010",
		.model = "delta1010",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_DELTADIO2496,
		.name = "M Audio Delta DiO 2496",
		.model = "dio2496",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
		.no_mpu401 = 1,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_DELTA66,
		.name = "M Audio Delta 66",
		.model = "delta66",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
		.no_mpu401 = 1,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_DELTA44,
		.name = "M Audio Delta 44",
		.model = "delta44",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
		.no_mpu401 = 1,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_AUDIOPHILE,
		.name = "M Audio Audiophile 24/96",
		.model = "audiophile",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_DELTA410,
		.name = "M Audio Delta 410",
		.model = "delta410",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_DELTA1010LT,
		.name = "M Audio Delta 1010LT",
		.model = "delta1010lt",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_VX442,
		.name = "Digigram VX442",
		.model = "vx442",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
		.no_mpu401 = 1,
	},
	{
		.subvendor = ICE1712_SUBDEVICE_MEDIASTATION,
		.name = "Lionstracs Mediastation",
		.model = "mediastation",
		.chip_init = snd_ice1712_delta_init,
		.build_controls = snd_ice1712_delta_add_controls,
	},
	{ } /* terminator */
};