1/* 2 * ALSA driver for ICEnsemble VT1724 (Envy24HT) 3 * 4 * Lowlevel functions for AudioTrak Prodigy 192 cards 5 * Supported IEC958 input from optional MI/ODI/O add-on card. 6 * 7 * Specifics (SW, HW): 8 * ------------------- 9 * * 49.5MHz crystal 10 * * SPDIF-OUT on the card: 11 * - coax (through isolation transformer)/toslink supplied by 12 * 74HC04 gates - 3 in parallel 13 * - output switched between on-board CD drive dig-out connector 14 * and ice1724 SPDTX pin, using 74HC02 NOR gates, controlled 15 * by GPIO20 (0 = CD dig-out, 1 = SPDTX) 16 * * SPDTX goes straight to MI/ODI/O card's SPDIF-OUT coax 17 * 18 * * MI/ODI/O card: AK4114 based, used for iec958 input only 19 * - toslink input -> RX0 20 * - coax input -> RX1 21 * - 4wire protocol: 22 * AK4114 ICE1724 23 * ------------------------------ 24 * CDTO (pin 32) -- GPIO11 pin 86 25 * CDTI (pin 33) -- GPIO10 pin 77 26 * CCLK (pin 34) -- GPIO9 pin 76 27 * CSN (pin 35) -- GPIO8 pin 75 28 * - output data Mode 7 (24bit, I2S, slave) 29 * - both MCKO1 and MCKO2 of ak4114 are fed to FPGA, which 30 * outputs master clock to SPMCLKIN of ice1724. 31 * Experimentally I found out that only a combination of 32 * OCKS0=1, OCKS1=1 (128fs, 64fs output) and ice1724 - 33 * VT1724_MT_I2S_MCLK_128X=0 (256fs input) yields correct 34 * sampling rate. That means the the FPGA doubles the 35 * MCK01 rate. 36 * 37 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de> 38 * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca> 39 * Copyright (c) 2004 Kouichi ONO <co2b@ceres.dti.ne.jp> 40 * 41 * This program is free software; you can redistribute it and/or modify 42 * it under the terms of the GNU General Public License as published by 43 * the Free Software Foundation; either version 2 of the License, or 44 * (at your option) any later version. 45 * 46 * This program is distributed in the hope that it will be useful, 47 * but WITHOUT ANY WARRANTY; without even the implied warranty of 48 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 49 * GNU General Public License for more details. 50 * 51 * You should have received a copy of the GNU General Public License 52 * along with this program; if not, write to the Free Software 53 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 54 * 55 */ 56 57#include <sound/driver.h> 58#include <asm/io.h> 59#include <linux/delay.h> 60#include <linux/interrupt.h> 61#include <linux/init.h> 62#include <linux/slab.h> 63#include <sound/core.h> 64 65#include "ice1712.h" 66#include "envy24ht.h" 67#include "prodigy192.h" 68#include "stac946x.h" 69#include <sound/tlv.h> 70 71static inline void stac9460_put(struct snd_ice1712 *ice, int reg, unsigned char val) 72{ 73 snd_vt1724_write_i2c(ice, PRODIGY192_STAC9460_ADDR, reg, val); 74} 75 76static inline unsigned char stac9460_get(struct snd_ice1712 *ice, int reg) 77{ 78 return snd_vt1724_read_i2c(ice, PRODIGY192_STAC9460_ADDR, reg); 79} 80 81/* 82 * DAC mute control 83 */ 84static int stac9460_dac_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 85{ 86 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 87 uinfo->count = 1; 88 uinfo->value.integer.min = 0; 89 uinfo->value.integer.max = 1; 90 return 0; 91} 92 93static int stac9460_dac_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 94{ 95 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 96 unsigned char val; 97 int idx; 98 99 if (kcontrol->private_value) 100 idx = STAC946X_MASTER_VOLUME; 101 else 102 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME; 103 val = stac9460_get(ice, idx); 104 ucontrol->value.integer.value[0] = (~val >> 7) & 0x1; 105 return 0; 106} 107 108static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 109{ 110 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 111 unsigned char new, old; 112 int idx; 113 int change; 114 115 if (kcontrol->private_value) 116 idx = STAC946X_MASTER_VOLUME; 117 else 118 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME; 119 old = stac9460_get(ice, idx); 120 new = (~ucontrol->value.integer.value[0]<< 7 & 0x80) | (old & ~0x80); 121 change = (new != old); 122 if (change) 123 stac9460_put(ice, idx, new); 124 125 return change; 126} 127 128/* 129 * DAC volume attenuation mixer control 130 */ 131static int stac9460_dac_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 132{ 133 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 134 uinfo->count = 1; 135 uinfo->value.integer.min = 0; /* mute */ 136 uinfo->value.integer.max = 0x7f; /* 0dB */ 137 return 0; 138} 139 140static int stac9460_dac_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 141{ 142 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 143 int idx; 144 unsigned char vol; 145 146 if (kcontrol->private_value) 147 idx = STAC946X_MASTER_VOLUME; 148 else 149 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME; 150 vol = stac9460_get(ice, idx) & 0x7f; 151 ucontrol->value.integer.value[0] = 0x7f - vol; 152 153 return 0; 154} 155 156static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 157{ 158 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 159 int idx; 160 unsigned char tmp, ovol, nvol; 161 int change; 162 163 if (kcontrol->private_value) 164 idx = STAC946X_MASTER_VOLUME; 165 else 166 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME; 167 nvol = ucontrol->value.integer.value[0]; 168 tmp = stac9460_get(ice, idx); 169 ovol = 0x7f - (tmp & 0x7f); 170 change = (ovol != nvol); 171 if (change) { 172 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); 173 } 174 return change; 175} 176 177/* 178 * ADC mute control 179 */ 180static int stac9460_adc_mute_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 181{ 182 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 183 uinfo->count = 2; 184 uinfo->value.integer.min = 0; 185 uinfo->value.integer.max = 1; 186 return 0; 187} 188 189static int stac9460_adc_mute_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 190{ 191 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 192 unsigned char val; 193 int i; 194 195 for (i = 0; i < 2; ++i) { 196 val = stac9460_get(ice, STAC946X_MIC_L_VOLUME + i); 197 ucontrol->value.integer.value[i] = ~val>>7 & 0x1; 198 } 199 200 return 0; 201} 202 203static int stac9460_adc_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 204{ 205 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 206 unsigned char new, old; 207 int i, reg; 208 int change; 209 210 for (i = 0; i < 2; ++i) { 211 reg = STAC946X_MIC_L_VOLUME + i; 212 old = stac9460_get(ice, reg); 213 new = (~ucontrol->value.integer.value[i]<<7&0x80) | (old&~0x80); 214 change = (new != old); 215 if (change) 216 stac9460_put(ice, reg, new); 217 } 218 219 return change; 220} 221 222/* 223 * ADC gain mixer control 224 */ 225static int stac9460_adc_vol_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 226{ 227 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 228 uinfo->count = 2; 229 uinfo->value.integer.min = 0; /* 0dB */ 230 uinfo->value.integer.max = 0x0f; /* 22.5dB */ 231 return 0; 232} 233 234static int stac9460_adc_vol_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 235{ 236 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 237 int i, reg; 238 unsigned char vol; 239 240 for (i = 0; i < 2; ++i) { 241 reg = STAC946X_MIC_L_VOLUME + i; 242 vol = stac9460_get(ice, reg) & 0x0f; 243 ucontrol->value.integer.value[i] = 0x0f - vol; 244 } 245 246 return 0; 247} 248 249static int stac9460_adc_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 250{ 251 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 252 int i, reg; 253 unsigned char ovol, nvol; 254 int change; 255 256 for (i = 0; i < 2; ++i) { 257 reg = STAC946X_MIC_L_VOLUME + i; 258 nvol = ucontrol->value.integer.value[i]; 259 ovol = 0x0f - stac9460_get(ice, reg); 260 change = ((ovol & 0x0f) != nvol); 261 if (change) 262 stac9460_put(ice, reg, (0x0f - nvol) | (ovol & ~0x0f)); 263 } 264 265 return change; 266} 267 268static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol, 269 struct snd_ctl_elem_info *uinfo) 270{ 271 static char *texts[2] = { "Line In", "Mic" }; 272 273 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 274 uinfo->count = 1; 275 uinfo->value.enumerated.items = 2; 276 277 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 278 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 279 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 280 281 return 0; 282} 283 284 285static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol, 286 struct snd_ctl_elem_value *ucontrol) 287{ 288 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 289 unsigned char val; 290 291 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 292 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1; 293 return 0; 294} 295 296static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol, 297 struct snd_ctl_elem_value *ucontrol) 298{ 299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 300 unsigned char new, old; 301 int change; 302 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE); 303 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80); 304 change = (new != old); 305 if (change) 306 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new); 307 return change; 308} 309 310static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); 311static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); 312 313/* 314 * mixers 315 */ 316 317static struct snd_kcontrol_new stac_controls[] __devinitdata = { 318 { 319 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 320 .name = "Master Playback Switch", 321 .info = stac9460_dac_mute_info, 322 .get = stac9460_dac_mute_get, 323 .put = stac9460_dac_mute_put, 324 .private_value = 1, 325 .tlv = { .p = db_scale_dac } 326 }, 327 { 328 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 329 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 330 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 331 .name = "Master Playback Volume", 332 .info = stac9460_dac_vol_info, 333 .get = stac9460_dac_vol_get, 334 .put = stac9460_dac_vol_put, 335 .private_value = 1, 336 .tlv = { .p = db_scale_dac } 337 }, 338 { 339 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 340 .name = "DAC Switch", 341 .count = 6, 342 .info = stac9460_dac_mute_info, 343 .get = stac9460_dac_mute_get, 344 .put = stac9460_dac_mute_put, 345 }, 346 { 347 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 348 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 349 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 350 .name = "DAC Volume", 351 .count = 6, 352 .info = stac9460_dac_vol_info, 353 .get = stac9460_dac_vol_get, 354 .put = stac9460_dac_vol_put, 355 .tlv = { .p = db_scale_dac } 356 }, 357 { 358 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 359 .name = "ADC Capture Switch", 360 .count = 1, 361 .info = stac9460_adc_mute_info, 362 .get = stac9460_adc_mute_get, 363 .put = stac9460_adc_mute_put, 364 365 }, 366 { 367 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 368 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 369 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 370 .name = "ADC Capture Volume", 371 .count = 1, 372 .info = stac9460_adc_vol_info, 373 .get = stac9460_adc_vol_get, 374 .put = stac9460_adc_vol_put, 375 .tlv = { .p = db_scale_adc } 376 }, 377 { 378 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 379 .name = "Analog Capture Input", 380 .info = stac9460_mic_sw_info, 381 .get = stac9460_mic_sw_get, 382 .put = stac9460_mic_sw_put, 383 384 }, 385}; 386 387 388/* AK4114 - ICE1724 connections on Prodigy192 + MI/ODI/O */ 389/* CDTO (pin 32) -- GPIO11 pin 86 390 * CDTI (pin 33) -- GPIO10 pin 77 391 * CCLK (pin 34) -- GPIO9 pin 76 392 * CSN (pin 35) -- GPIO8 pin 75 393 */ 394#define AK4114_ADDR 0x00 /* C1-C0: Chip Address 395 * (According to datasheet fixed to ���00���) 396 */ 397 398/* 399 * 4wire ak4114 protocol - writing data 400 */ 401static void write_data(struct snd_ice1712 *ice, unsigned int gpio, 402 unsigned int data, int idx) 403{ 404 for (; idx >= 0; idx--) { 405 /* drop clock */ 406 gpio &= ~VT1724_PRODIGY192_CCLK; 407 snd_ice1712_gpio_write(ice, gpio); 408 udelay(1); 409 /* set data */ 410 if (data & (1 << idx)) 411 gpio |= VT1724_PRODIGY192_CDOUT; 412 else 413 gpio &= ~VT1724_PRODIGY192_CDOUT; 414 snd_ice1712_gpio_write(ice, gpio); 415 udelay(1); 416 /* raise clock */ 417 gpio |= VT1724_PRODIGY192_CCLK; 418 snd_ice1712_gpio_write(ice, gpio); 419 udelay(1); 420 } 421} 422 423/* 424 * 4wire ak4114 protocol - reading data 425 */ 426static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio, 427 int idx) 428{ 429 unsigned char data = 0; 430 431 for (; idx >= 0; idx--) { 432 /* drop clock */ 433 gpio &= ~VT1724_PRODIGY192_CCLK; 434 snd_ice1712_gpio_write(ice, gpio); 435 udelay(1); 436 /* read data */ 437 if (snd_ice1712_gpio_read(ice) & VT1724_PRODIGY192_CDIN) 438 data |= (1 << idx); 439 udelay(1); 440 /* raise clock */ 441 gpio |= VT1724_PRODIGY192_CCLK; 442 snd_ice1712_gpio_write(ice, gpio); 443 udelay(1); 444 } 445 return data; 446} 447/* 448 * 4wire ak4114 protocol - starting sequence 449 */ 450static unsigned int prodigy192_4wire_start(struct snd_ice1712 *ice) 451{ 452 unsigned int tmp; 453 454 snd_ice1712_save_gpio_status(ice); 455 tmp = snd_ice1712_gpio_read(ice); 456 457 tmp |= VT1724_PRODIGY192_CCLK; /* high at init */ 458 tmp &= ~VT1724_PRODIGY192_CS; /* drop chip select */ 459 snd_ice1712_gpio_write(ice, tmp); 460 udelay(1); 461 return tmp; 462} 463 464/* 465 * 4wire ak4114 protocol - final sequence 466 */ 467static void prodigy192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp) 468{ 469 tmp |= VT1724_PRODIGY192_CS; /* raise chip select */ 470 snd_ice1712_gpio_write(ice, tmp); 471 udelay(1); 472 snd_ice1712_restore_gpio_status(ice); 473} 474 475/* 476 * Write data to addr register of ak4114 477 */ 478static void prodigy192_ak4114_write(void *private_data, unsigned char addr, 479 unsigned char data) 480{ 481 struct snd_ice1712 *ice = private_data; 482 unsigned int tmp, addrdata; 483 tmp = prodigy192_4wire_start(ice); 484 addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f); 485 addrdata = (addrdata << 8) | data; 486 write_data(ice, tmp, addrdata, 15); 487 prodigy192_4wire_finish(ice, tmp); 488} 489 490/* 491 * Read data from addr register of ak4114 492 */ 493static unsigned char prodigy192_ak4114_read(void *private_data, 494 unsigned char addr) 495{ 496 struct snd_ice1712 *ice = private_data; 497 unsigned int tmp; 498 unsigned char data; 499 500 tmp = prodigy192_4wire_start(ice); 501 write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7); 502 data = read_data(ice, tmp, 7); 503 prodigy192_4wire_finish(ice, tmp); 504 return data; 505} 506 507 508static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol, 509 struct snd_ctl_elem_info *uinfo) 510{ 511 static char *texts[2] = { "Toslink", "Coax" }; 512 513 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 514 uinfo->count = 1; 515 uinfo->value.enumerated.items = 2; 516 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 517 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 518 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 519 return 0; 520} 521 522 523static int ak4114_input_sw_get(struct snd_kcontrol *kcontrol, 524 struct snd_ctl_elem_value *ucontrol) 525{ 526 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 527 unsigned char val; 528 529 val = prodigy192_ak4114_read(ice, AK4114_REG_IO1); 530 /* AK4114_IPS0 bit = 0 -> RX0 = Toslink 531 * AK4114_IPS0 bit = 1 -> RX1 = Coax 532 */ 533 ucontrol->value.enumerated.item[0] = (val & AK4114_IPS0) ? 1 : 0; 534 return 0; 535} 536 537static int ak4114_input_sw_put(struct snd_kcontrol *kcontrol, 538 struct snd_ctl_elem_value *ucontrol) 539{ 540 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 541 unsigned char new, old, itemvalue; 542 int change; 543 544 old = prodigy192_ak4114_read(ice, AK4114_REG_IO1); 545 /* AK4114_IPS0 could be any bit */ 546 itemvalue = (ucontrol->value.enumerated.item[0]) ? 0xff : 0x00; 547 548 new = (itemvalue & AK4114_IPS0) | (old & ~AK4114_IPS0); 549 change = (new != old); 550 if (change) 551 prodigy192_ak4114_write(ice, AK4114_REG_IO1, new); 552 return change; 553} 554 555 556static struct snd_kcontrol_new ak4114_controls[] __devinitdata = { 557 { 558 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 559 .name = "MIODIO IEC958 Capture Input", 560 .info = ak4114_input_sw_info, 561 .get = ak4114_input_sw_get, 562 .put = ak4114_input_sw_put, 563 564 } 565}; 566 567 568static int prodigy192_ak4114_init(struct snd_ice1712 *ice) 569{ 570 static const unsigned char ak4114_init_vals[] = { 571 AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1, 572 /* ice1724 expects I2S and provides clock, 573 * DEM0 disables the deemphasis filter 574 */ 575 AK4114_DIF_I24I2S | AK4114_DEM0 , 576 AK4114_TX1E, 577 AK4114_EFH_1024 | AK4114_DIT, /* default input RX0 */ 578 0, 579 0 580 }; 581 static const unsigned char ak4114_init_txcsb[] = { 582 0x41, 0x02, 0x2c, 0x00, 0x00 583 }; 584 585 return snd_ak4114_create(ice->card, 586 prodigy192_ak4114_read, 587 prodigy192_ak4114_write, 588 ak4114_init_vals, ak4114_init_txcsb, 589 ice, &ice->spec.prodigy192.ak4114); 590} 591 592static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice) 593{ 594 unsigned int i; 595 int err; 596 597 for (i = 0; i < ARRAY_SIZE(stac_controls); i++) { 598 err = snd_ctl_add(ice->card, 599 snd_ctl_new1(&stac_controls[i], ice)); 600 if (err < 0) 601 return err; 602 } 603 if (ice->spec.prodigy192.ak4114) { 604 /* ak4114 is connected */ 605 for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) { 606 err = snd_ctl_add(ice->card, 607 snd_ctl_new1(&ak4114_controls[i], 608 ice)); 609 if (err < 0) 610 return err; 611 } 612 err = snd_ak4114_build(ice->spec.prodigy192.ak4114, 613 NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */ 614 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 615 if (err < 0) 616 return err; 617 } 618 return 0; 619} 620 621/* 622 * check for presence of MI/ODI/O add-on card with digital inputs 623 */ 624static int prodigy192_miodio_exists(struct snd_ice1712 *ice) 625{ 626 627 unsigned char orig_value; 628 const unsigned char test_data = 0xd1; /* random value */ 629 unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */ 630 int exists = 0; 631 632 orig_value = prodigy192_ak4114_read(ice, addr); 633 prodigy192_ak4114_write(ice, addr, test_data); 634 if (prodigy192_ak4114_read(ice, addr) == test_data) { 635 /* ak4114 seems to communicate, apparently exists */ 636 /* writing back original value */ 637 prodigy192_ak4114_write(ice, addr, orig_value); 638 exists = 1; 639 } 640 return exists; 641} 642 643/* 644 * initialize the chip 645 */ 646static int __devinit prodigy192_init(struct snd_ice1712 *ice) 647{ 648 static const unsigned short stac_inits_prodigy[] = { 649 STAC946X_RESET, 0, 650/* STAC946X_MASTER_VOLUME, 0, 651 STAC946X_LF_VOLUME, 0, 652 STAC946X_RF_VOLUME, 0, 653 STAC946X_LR_VOLUME, 0, 654 STAC946X_RR_VOLUME, 0, 655 STAC946X_CENTER_VOLUME, 0, 656 STAC946X_LFE_VOLUME, 0,*/ 657 (unsigned short)-1 658 }; 659 const unsigned short *p; 660 int err = 0; 661 662 /* prodigy 192 */ 663 ice->num_total_dacs = 6; 664 ice->num_total_adcs = 2; 665 ice->vt1720 = 0; /* ice1724, e.g. 23 GPIOs */ 666 667 /* initialize codec */ 668 p = stac_inits_prodigy; 669 for (; *p != (unsigned short)-1; p += 2) 670 stac9460_put(ice, p[0], p[1]); 671 672 /* MI/ODI/O add on card with AK4114 */ 673 if (prodigy192_miodio_exists(ice)) { 674 err = prodigy192_ak4114_init(ice); 675 /* from this moment if err = 0 then 676 * ice->spec.prodigy192.ak4114 should not be null 677 */ 678 snd_printdd("AK4114 initialized with status %d\n", err); 679 } else 680 snd_printdd("AK4114 not found\n"); 681 if (err < 0) 682 return err; 683 684 return 0; 685} 686 687 688/* 689 * Aureon boards don't provide the EEPROM data except for the vendor IDs. 690 * hence the driver needs to sets up it properly. 691 */ 692 693static unsigned char prodigy71_eeprom[] __devinitdata = { 694 [ICE_EEP2_SYSCONF] = 0x6a, /* 49MHz crystal, mpu401, 695 * spdif-in+ 1 stereo ADC, 696 * 3 stereo DACs 697 */ 698 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 699 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 700 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 701 [ICE_EEP2_GPIO_DIR] = 0xff, 702 [ICE_EEP2_GPIO_DIR1] = ~(VT1724_PRODIGY192_CDIN >> 8) , 703 [ICE_EEP2_GPIO_DIR2] = 0xbf, 704 [ICE_EEP2_GPIO_MASK] = 0x00, 705 [ICE_EEP2_GPIO_MASK1] = 0x00, 706 [ICE_EEP2_GPIO_MASK2] = 0x00, 707 [ICE_EEP2_GPIO_STATE] = 0x00, 708 [ICE_EEP2_GPIO_STATE1] = 0x00, 709 [ICE_EEP2_GPIO_STATE2] = 0x10, /* GPIO20: 0 = CD drive dig. input 710 * passthrough, 711 * 1 = SPDIF-OUT from ice1724 712 */ 713}; 714 715 716/* entry point */ 717struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = { 718 { 719 .subvendor = VT1724_SUBDEVICE_PRODIGY192VE, 720 .name = "Audiotrak Prodigy 192", 721 .model = "prodigy192", 722 .chip_init = prodigy192_init, 723 .build_controls = prodigy192_add_controls, 724 .eeprom_size = sizeof(prodigy71_eeprom), 725 .eeprom_data = prodigy71_eeprom, 726 }, 727 { } /* terminator */ 728}; 729