aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ice1712/prodigy192.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/ice1712/prodigy192.c')
-rw-r--r--sound/pci/ice1712/prodigy192.c360
1 files changed, 351 insertions, 9 deletions
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index 31cc66eb9f8f..f03c02c07743 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -2,6 +2,37 @@
2 * ALSA driver for ICEnsemble VT1724 (Envy24HT) 2 * ALSA driver for ICEnsemble VT1724 (Envy24HT)
3 * 3 *
4 * Lowlevel functions for AudioTrak Prodigy 192 cards 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.
5 * 36 *
6 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de> 37 * Copyright (c) 2003 Takashi Iwai <tiwai@suse.de>
7 * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca> 38 * Copyright (c) 2003 Dimitromanolakis Apostolos <apostol@cs.utoronto.ca>
@@ -356,6 +387,47 @@ static int aureon_oversampling_put(struct snd_kcontrol *kcontrol, struct snd_ctl
356 return 0; 387 return 0;
357} 388}
358#endif 389#endif
390static int stac9460_mic_sw_info(struct snd_kcontrol *kcontrol,
391 struct snd_ctl_elem_info *uinfo)
392{
393 static char *texts[2] = { "Line In", "Mic" };
394
395 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
396 uinfo->count = 1;
397 uinfo->value.enumerated.items = 2;
398
399 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
400 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
401 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
402
403 return 0;
404}
405
406
407static int stac9460_mic_sw_get(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol)
409{
410 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
411 unsigned char val;
412
413 val = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
414 ucontrol->value.enumerated.item[0] = (val >> 7) & 0x1;
415 return 0;
416}
417
418static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
419 struct snd_ctl_elem_value *ucontrol)
420{
421 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
422 unsigned char new, old;
423 int change;
424 old = stac9460_get(ice, STAC946X_GENERAL_PURPOSE);
425 new = (ucontrol->value.enumerated.item[0] << 7 & 0x80) | (old & ~0x80);
426 change = (new != old);
427 if (change)
428 stac9460_put(ice, STAC946X_GENERAL_PURPOSE, new);
429 return change;
430}
359 431
360static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); 432static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
361static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); 433static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
@@ -364,7 +436,7 @@ static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
364 * mixers 436 * mixers
365 */ 437 */
366 438
367static const struct snd_kcontrol_new stac_controls[] __devinitdata = { 439static struct snd_kcontrol_new stac_controls[] __devinitdata = {
368 { 440 {
369 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 441 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
370 .name = "Master Playback Switch", 442 .name = "Master Playback Switch",
@@ -406,7 +478,7 @@ static const struct snd_kcontrol_new stac_controls[] __devinitdata = {
406 }, 478 },
407 { 479 {
408 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 480 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
409 .name = "ADC Switch", 481 .name = "ADC Capture Switch",
410 .count = 1, 482 .count = 1,
411 .info = stac9460_adc_mute_info, 483 .info = stac9460_adc_mute_info,
412 .get = stac9460_adc_mute_get, 484 .get = stac9460_adc_mute_get,
@@ -417,13 +489,21 @@ static const struct snd_kcontrol_new stac_controls[] __devinitdata = {
417 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 489 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
418 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | 490 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
419 SNDRV_CTL_ELEM_ACCESS_TLV_READ), 491 SNDRV_CTL_ELEM_ACCESS_TLV_READ),
420 .name = "ADC Volume", 492 .name = "ADC Capture Volume",
421 .count = 1, 493 .count = 1,
422 .info = stac9460_adc_vol_info, 494 .info = stac9460_adc_vol_info,
423 .get = stac9460_adc_vol_get, 495 .get = stac9460_adc_vol_get,
424 .put = stac9460_adc_vol_put, 496 .put = stac9460_adc_vol_put,
425 .tlv = { .p = db_scale_adc } 497 .tlv = { .p = db_scale_adc }
426 }, 498 },
499 {
500 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
501 .name = "Analog Capture Input",
502 .info = stac9460_mic_sw_info,
503 .get = stac9460_mic_sw_get,
504 .put = stac9460_mic_sw_put,
505
506 },
427#if 0 507#if 0
428 { 508 {
429 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 509 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -456,19 +536,261 @@ static const struct snd_kcontrol_new stac_controls[] __devinitdata = {
456#endif 536#endif
457}; 537};
458 538
539
540/* AK4114 - ICE1724 connections on Prodigy192 + MI/ODI/O */
541/* CDTO (pin 32) -- GPIO11 pin 86
542 * CDTI (pin 33) -- GPIO10 pin 77
543 * CCLK (pin 34) -- GPIO9 pin 76
544 * CSN (pin 35) -- GPIO8 pin 75
545 */
546#define AK4114_ADDR 0x00 /* C1-C0: Chip Address
547 * (According to datasheet fixed to “00”)
548 */
549
550/*
551 * 4wire ak4114 protocol - writing data
552 */
553static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
554 unsigned int data, int idx)
555{
556 for (; idx >= 0; idx--) {
557 /* drop clock */
558 gpio &= ~VT1724_PRODIGY192_CCLK;
559 snd_ice1712_gpio_write(ice, gpio);
560 udelay(1);
561 /* set data */
562 if (data & (1 << idx))
563 gpio |= VT1724_PRODIGY192_CDOUT;
564 else
565 gpio &= ~VT1724_PRODIGY192_CDOUT;
566 snd_ice1712_gpio_write(ice, gpio);
567 udelay(1);
568 /* raise clock */
569 gpio |= VT1724_PRODIGY192_CCLK;
570 snd_ice1712_gpio_write(ice, gpio);
571 udelay(1);
572 }
573}
574
575/*
576 * 4wire ak4114 protocol - reading data
577 */
578static unsigned char read_data(struct snd_ice1712 *ice, unsigned int gpio,
579 int idx)
580{
581 unsigned char data = 0;
582
583 for (; idx >= 0; idx--) {
584 /* drop clock */
585 gpio &= ~VT1724_PRODIGY192_CCLK;
586 snd_ice1712_gpio_write(ice, gpio);
587 udelay(1);
588 /* read data */
589 if (snd_ice1712_gpio_read(ice) & VT1724_PRODIGY192_CDIN)
590 data |= (1 << idx);
591 udelay(1);
592 /* raise clock */
593 gpio |= VT1724_PRODIGY192_CCLK;
594 snd_ice1712_gpio_write(ice, gpio);
595 udelay(1);
596 }
597 return data;
598}
599/*
600 * 4wire ak4114 protocol - starting sequence
601 */
602static unsigned int prodigy192_4wire_start(struct snd_ice1712 *ice)
603{
604 unsigned int tmp;
605
606 snd_ice1712_save_gpio_status(ice);
607 tmp = snd_ice1712_gpio_read(ice);
608
609 tmp |= VT1724_PRODIGY192_CCLK; /* high at init */
610 tmp &= ~VT1724_PRODIGY192_CS; /* drop chip select */
611 snd_ice1712_gpio_write(ice, tmp);
612 udelay(1);
613 return tmp;
614}
615
616/*
617 * 4wire ak4114 protocol - final sequence
618 */
619static void prodigy192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
620{
621 tmp |= VT1724_PRODIGY192_CS; /* raise chip select */
622 snd_ice1712_gpio_write(ice, tmp);
623 udelay(1);
624 snd_ice1712_restore_gpio_status(ice);
625}
626
627/*
628 * Write data to addr register of ak4114
629 */
630static void prodigy192_ak4114_write(void *private_data, unsigned char addr,
631 unsigned char data)
632{
633 struct snd_ice1712 *ice = private_data;
634 unsigned int tmp, addrdata;
635 tmp = prodigy192_4wire_start(ice);
636 addrdata = (AK4114_ADDR << 6) | 0x20 | (addr & 0x1f);
637 addrdata = (addrdata << 8) | data;
638 write_data(ice, tmp, addrdata, 15);
639 prodigy192_4wire_finish(ice, tmp);
640}
641
642/*
643 * Read data from addr register of ak4114
644 */
645static unsigned char prodigy192_ak4114_read(void *private_data,
646 unsigned char addr)
647{
648 struct snd_ice1712 *ice = private_data;
649 unsigned int tmp;
650 unsigned char data;
651
652 tmp = prodigy192_4wire_start(ice);
653 write_data(ice, tmp, (AK4114_ADDR << 6) | (addr & 0x1f), 7);
654 data = read_data(ice, tmp, 7);
655 prodigy192_4wire_finish(ice, tmp);
656 return data;
657}
658
659
660static int ak4114_input_sw_info(struct snd_kcontrol *kcontrol,
661 struct snd_ctl_elem_info *uinfo)
662{
663 static char *texts[2] = { "Toslink", "Coax" };
664
665 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
666 uinfo->count = 1;
667 uinfo->value.enumerated.items = 2;
668 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
669 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
670 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
671 return 0;
672}
673
674
675static int ak4114_input_sw_get(struct snd_kcontrol *kcontrol,
676 struct snd_ctl_elem_value *ucontrol)
677{
678 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
679 unsigned char val;
680
681 val = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
682 /* AK4114_IPS0 bit = 0 -> RX0 = Toslink
683 * AK4114_IPS0 bit = 1 -> RX1 = Coax
684 */
685 ucontrol->value.enumerated.item[0] = (val & AK4114_IPS0) ? 1 : 0;
686 return 0;
687}
688
689static int ak4114_input_sw_put(struct snd_kcontrol *kcontrol,
690 struct snd_ctl_elem_value *ucontrol)
691{
692 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
693 unsigned char new, old, itemvalue;
694 int change;
695
696 old = prodigy192_ak4114_read(ice, AK4114_REG_IO1);
697 /* AK4114_IPS0 could be any bit */
698 itemvalue = (ucontrol->value.enumerated.item[0]) ? 0xff : 0x00;
699
700 new = (itemvalue & AK4114_IPS0) | (old & ~AK4114_IPS0);
701 change = (new != old);
702 if (change)
703 prodigy192_ak4114_write(ice, AK4114_REG_IO1, new);
704 return change;
705}
706
707
708static const struct snd_kcontrol_new ak4114_controls[] __devinitdata = {
709 {
710 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
711 .name = "MIODIO IEC958 Capture Input",
712 .info = ak4114_input_sw_info,
713 .get = ak4114_input_sw_get,
714 .put = ak4114_input_sw_put,
715
716 }
717};
718
719
720static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
721{
722 static const unsigned char ak4114_init_vals[] = {
723 AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1,
724 /* ice1724 expects I2S and provides clock,
725 * DEM0 disables the deemphasis filter
726 */
727 AK4114_DIF_I24I2S | AK4114_DEM0 ,
728 AK4114_TX1E,
729 AK4114_EFH_1024 | AK4114_DIT, /* default input RX0 */
730 0,
731 0
732 };
733 static const unsigned char ak4114_init_txcsb[] = {
734 0x41, 0x02, 0x2c, 0x00, 0x00
735 };
736
737 return snd_ak4114_create(ice->card,
738 prodigy192_ak4114_read,
739 prodigy192_ak4114_write,
740 ak4114_init_vals, ak4114_init_txcsb,
741 ice, &ice->spec.prodigy192.ak4114);
742}
743
459static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice) 744static int __devinit prodigy192_add_controls(struct snd_ice1712 *ice)
460{ 745{
461 unsigned int i; 746 unsigned int i;
462 int err; 747 int err;
463 748
464 for (i = 0; i < ARRAY_SIZE(stac_controls); i++) { 749 for (i = 0; i < ARRAY_SIZE(stac_controls); i++) {
465 err = snd_ctl_add(ice->card, snd_ctl_new1(&stac_controls[i], ice)); 750 err = snd_ctl_add(ice->card,
751 snd_ctl_new1(&stac_controls[i], ice));
752 if (err < 0)
753 return err;
754 }
755 if (ice->spec.prodigy192.ak4114) {
756 /* ak4114 is connected */
757 for (i = 0; i < ARRAY_SIZE(ak4114_controls); i++) {
758 err = snd_ctl_add(ice->card,
759 snd_ctl_new1(&ak4114_controls[i],
760 ice));
761 if (err < 0)
762 return err;
763 }
764 err = snd_ak4114_build(ice->spec.prodigy192.ak4114,
765 NULL, /* ak4114 in MIO/DI/O handles no IEC958 output */
766 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
466 if (err < 0) 767 if (err < 0)
467 return err; 768 return err;
468 } 769 }
469 return 0; 770 return 0;
470} 771}
471 772
773/*
774 * check for presence of MI/ODI/O add-on card with digital inputs
775 */
776static int prodigy192_miodio_exists(struct snd_ice1712 *ice)
777{
778
779 unsigned char orig_value;
780 const unsigned char test_data = 0xd1; /* random value */
781 unsigned char addr = AK4114_REG_INT0_MASK; /* random SAFE address */
782 int exists = 0;
783
784 orig_value = prodigy192_ak4114_read(ice, addr);
785 prodigy192_ak4114_write(ice, addr, test_data);
786 if (prodigy192_ak4114_read(ice, addr) == test_data) {
787 /* ak4114 seems to communicate, apparently exists */
788 /* writing back original value */
789 prodigy192_ak4114_write(ice, addr, orig_value);
790 exists = 1;
791 }
792 return exists;
793}
472 794
473/* 795/*
474 * initialize the chip 796 * initialize the chip
@@ -487,16 +809,30 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
487 (unsigned short)-1 809 (unsigned short)-1
488 }; 810 };
489 const unsigned short *p; 811 const unsigned short *p;
812 int err = 0;
490 813
491 /* prodigy 192 */ 814 /* prodigy 192 */
492 ice->num_total_dacs = 6; 815 ice->num_total_dacs = 6;
493 ice->num_total_adcs = 2; 816 ice->num_total_adcs = 2;
817 ice->vt1720 = 0; /* ice1724, e.g. 23 GPIOs */
494 818
495 /* initialize codec */ 819 /* initialize codec */
496 p = stac_inits_prodigy; 820 p = stac_inits_prodigy;
497 for (; *p != (unsigned short)-1; p += 2) 821 for (; *p != (unsigned short)-1; p += 2)
498 stac9460_put(ice, p[0], p[1]); 822 stac9460_put(ice, p[0], p[1]);
499 823
824 /* MI/ODI/O add on card with AK4114 */
825 if (prodigy192_miodio_exists(ice)) {
826 err = prodigy192_ak4114_init(ice);
827 /* from this moment if err = 0 then
828 * ice->spec.prodigy192.ak4114 should not be null
829 */
830 snd_printdd("AK4114 initialized with status %d\n", err);
831 } else
832 snd_printdd("AK4114 not found\n");
833 if (err < 0)
834 return err;
835
500 return 0; 836 return 0;
501} 837}
502 838
@@ -506,25 +842,31 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
506 * hence the driver needs to sets up it properly. 842 * hence the driver needs to sets up it properly.
507 */ 843 */
508 844
509static const unsigned char prodigy71_eeprom[] __devinitdata = { 845static unsigned char prodigy71_eeprom[] __devinitdata = {
510 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, spdif-in/ADC, 4DACs */ 846 [ICE_EEP2_SYSCONF] = 0x6a, /* 49MHz crystal, mpu401,
847 * spdif-in+ 1 stereo ADC,
848 * 3 stereo DACs
849 */
511 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 850 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
512 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 851 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
513 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 852 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
514 [ICE_EEP2_GPIO_DIR] = 0xff, 853 [ICE_EEP2_GPIO_DIR] = 0xff,
515 [ICE_EEP2_GPIO_DIR1] = 0xff, 854 [ICE_EEP2_GPIO_DIR1] = ~(VT1724_PRODIGY192_CDIN >> 8) ,
516 [ICE_EEP2_GPIO_DIR2] = 0xbf, 855 [ICE_EEP2_GPIO_DIR2] = 0xbf,
517 [ICE_EEP2_GPIO_MASK] = 0x00, 856 [ICE_EEP2_GPIO_MASK] = 0x00,
518 [ICE_EEP2_GPIO_MASK1] = 0x00, 857 [ICE_EEP2_GPIO_MASK1] = 0x00,
519 [ICE_EEP2_GPIO_MASK2] = 0x00, 858 [ICE_EEP2_GPIO_MASK2] = 0x00,
520 [ICE_EEP2_GPIO_STATE] = 0x00, 859 [ICE_EEP2_GPIO_STATE] = 0x00,
521 [ICE_EEP2_GPIO_STATE1] = 0x00, 860 [ICE_EEP2_GPIO_STATE1] = 0x00,
522 [ICE_EEP2_GPIO_STATE2] = 0x00, 861 [ICE_EEP2_GPIO_STATE2] = 0x10, /* GPIO20: 0 = CD drive dig. input
862 * passthrough,
863 * 1 = SPDIF-OUT from ice1724
864 */
523}; 865};
524 866
525 867
526/* entry point */ 868/* entry point */
527const struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = { 869struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
528 { 870 {
529 .subvendor = VT1724_SUBDEVICE_PRODIGY192VE, 871 .subvendor = VT1724_SUBDEVICE_PRODIGY192VE,
530 .name = "Audiotrak Prodigy 192", 872 .name = "Audiotrak Prodigy 192",