| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | *   ALSA driver for ICEnsemble VT1724 (Envy24HT) | 
|  | 3 | * | 
|  | 4 | *   Lowlevel functions for ESI Juli@ cards | 
|  | 5 | * | 
| Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 6 | *	Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * | 
|  | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <asm/io.h> | 
|  | 25 | #include <linux/delay.h> | 
|  | 26 | #include <linux/interrupt.h> | 
|  | 27 | #include <linux/init.h> | 
|  | 28 | #include <linux/slab.h> | 
|  | 29 | #include <sound/core.h> | 
|  | 30 |  | 
|  | 31 | #include "ice1712.h" | 
|  | 32 | #include "envy24ht.h" | 
|  | 33 | #include "juli.h" | 
|  | 34 |  | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 35 | struct juli_spec { | 
|  | 36 | struct ak4114 *ak4114; | 
|  | 37 | unsigned int analog: 1; | 
|  | 38 | }; | 
|  | 39 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | /* | 
|  | 41 | * chip addresses on I2C bus | 
|  | 42 | */ | 
|  | 43 | #define AK4114_ADDR		0x20		/* S/PDIF receiver */ | 
|  | 44 | #define AK4358_ADDR		0x22		/* DAC */ | 
|  | 45 |  | 
|  | 46 | /* | 
|  | 47 | * GPIO pins | 
|  | 48 | */ | 
|  | 49 | #define GPIO_FREQ_MASK		(3<<0) | 
|  | 50 | #define GPIO_FREQ_32KHZ		(0<<0) | 
|  | 51 | #define GPIO_FREQ_44KHZ		(1<<0) | 
|  | 52 | #define GPIO_FREQ_48KHZ		(2<<0) | 
|  | 53 | #define GPIO_MULTI_MASK		(3<<2) | 
|  | 54 | #define GPIO_MULTI_4X		(0<<2) | 
|  | 55 | #define GPIO_MULTI_2X		(1<<2) | 
|  | 56 | #define GPIO_MULTI_1X		(2<<2)		/* also external */ | 
|  | 57 | #define GPIO_MULTI_HALF		(3<<2) | 
|  | 58 | #define GPIO_INTERNAL_CLOCK	(1<<4) | 
|  | 59 | #define GPIO_ANALOG_PRESENT	(1<<5)		/* RO only: 0 = present */ | 
|  | 60 | #define GPIO_RXMCLK_SEL		(1<<7)		/* must be 0 */ | 
|  | 61 | #define GPIO_AK5385A_CKS0	(1<<8) | 
|  | 62 | #define GPIO_AK5385A_DFS0	(1<<9)		/* swapped with DFS1 according doc? */ | 
|  | 63 | #define GPIO_AK5385A_DFS1	(1<<10) | 
|  | 64 | #define GPIO_DIGOUT_MONITOR	(1<<11)		/* 1 = active */ | 
|  | 65 | #define GPIO_DIGIN_MONITOR	(1<<12)		/* 1 = active */ | 
|  | 66 | #define GPIO_ANAIN_MONITOR	(1<<13)		/* 1 = active */ | 
|  | 67 | #define GPIO_AK5385A_MCLK	(1<<14)		/* must be 0 */ | 
|  | 68 | #define GPIO_MUTE_CONTROL	(1<<15)		/* 0 = off, 1 = on */ | 
|  | 69 |  | 
|  | 70 | static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) | 
|  | 71 | { | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 72 | snd_vt1724_write_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg, val); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } | 
|  | 74 |  | 
|  | 75 | static unsigned char juli_ak4114_read(void *private_data, unsigned char reg) | 
|  | 76 | { | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 77 | return snd_vt1724_read_i2c((struct snd_ice1712 *)private_data, AK4114_ADDR, reg); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
|  | 80 | /* | 
|  | 81 | * AK4358 section | 
|  | 82 | */ | 
|  | 83 |  | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 84 | static void juli_akm_lock(struct snd_akm4xxx *ak, int chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { | 
|  | 86 | } | 
|  | 87 |  | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 88 | static void juli_akm_unlock(struct snd_akm4xxx *ak, int chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { | 
|  | 90 | } | 
|  | 91 |  | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 92 | static void juli_akm_write(struct snd_akm4xxx *ak, int chip, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | unsigned char addr, unsigned char data) | 
|  | 94 | { | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 95 | struct snd_ice1712 *ice = ak->private_data[0]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 |  | 
|  | 97 | snd_assert(chip == 0, return); | 
|  | 98 | snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data); | 
|  | 99 | } | 
|  | 100 |  | 
|  | 101 | /* | 
|  | 102 | * change the rate of envy24HT, AK4358 | 
|  | 103 | */ | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 104 | static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { | 
|  | 106 | unsigned char old, tmp, dfs; | 
|  | 107 |  | 
|  | 108 | if (rate == 0)  /* no hint - S/PDIF input is master, simply return */ | 
|  | 109 | return; | 
|  | 110 |  | 
|  | 111 | /* adjust DFS on codecs */ | 
|  | 112 | if (rate > 96000) | 
|  | 113 | dfs = 2; | 
|  | 114 | else if (rate > 48000) | 
|  | 115 | dfs = 1; | 
|  | 116 | else | 
|  | 117 | dfs = 0; | 
|  | 118 |  | 
|  | 119 | tmp = snd_akm4xxx_get(ak, 0, 2); | 
|  | 120 | old = (tmp >> 4) & 0x03; | 
|  | 121 | if (old == dfs) | 
|  | 122 | return; | 
|  | 123 | /* reset DFS */ | 
|  | 124 | snd_akm4xxx_reset(ak, 1); | 
|  | 125 | tmp = snd_akm4xxx_get(ak, 0, 2); | 
|  | 126 | tmp &= ~(0x03 << 4); | 
|  | 127 | tmp |= dfs << 4; | 
|  | 128 | snd_akm4xxx_set(ak, 0, 2, tmp); | 
|  | 129 | snd_akm4xxx_reset(ak, 0); | 
|  | 130 | } | 
|  | 131 |  | 
| Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 132 | static struct snd_akm4xxx akm_juli_dac __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .type = SND_AK4358, | 
|  | 134 | .num_dacs = 2, | 
|  | 135 | .ops = { | 
|  | 136 | .lock = juli_akm_lock, | 
|  | 137 | .unlock = juli_akm_unlock, | 
|  | 138 | .write = juli_akm_write, | 
|  | 139 | .set_rate_val = juli_akm_set_rate_val | 
|  | 140 | } | 
|  | 141 | }; | 
|  | 142 |  | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 143 | static int __devinit juli_add_controls(struct snd_ice1712 *ice) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 145 | struct juli_spec *spec = ice->spec; | 
| Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 146 | int err; | 
|  | 147 | err = snd_ice1712_akm4xxx_build_controls(ice); | 
|  | 148 | if (err < 0) | 
|  | 149 | return err; | 
|  | 150 | /* only capture SPDIF over AK4114 */ | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 151 | err = snd_ak4114_build(spec->ak4114, NULL, | 
| Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 152 | ice->pcm_pro->streams[SNDRV_PCM_STREAM_CAPTURE].substream); | 
|  | 153 | if (err < 0) | 
|  | 154 | return err; | 
|  | 155 | return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } | 
|  | 157 |  | 
|  | 158 | /* | 
|  | 159 | * initialize the chip | 
|  | 160 | */ | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 161 | static int __devinit juli_init(struct snd_ice1712 *ice) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { | 
| Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 163 | static const unsigned char ak4114_init_vals[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* AK4117_REG_PWRDN */	AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1, | 
|  | 165 | /* AK4114_REQ_FORMAT */	AK4114_DIF_I24I2S, | 
|  | 166 | /* AK4114_REG_IO0 */	AK4114_TX1E, | 
|  | 167 | /* AK4114_REG_IO1 */	AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1), | 
|  | 168 | /* AK4114_REG_INT0_MASK */ 0, | 
|  | 169 | /* AK4114_REG_INT1_MASK */ 0 | 
|  | 170 | }; | 
| Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 171 | static const unsigned char ak4114_init_txcsb[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | 0x41, 0x02, 0x2c, 0x00, 0x00 | 
|  | 173 | }; | 
|  | 174 | int err; | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 175 | struct juli_spec *spec; | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 176 | struct snd_akm4xxx *ak; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 |  | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 178 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); | 
|  | 179 | if (!spec) | 
|  | 180 | return -ENOMEM; | 
|  | 181 | ice->spec = spec; | 
|  | 182 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | err = snd_ak4114_create(ice->card, | 
|  | 184 | juli_ak4114_read, | 
|  | 185 | juli_ak4114_write, | 
|  | 186 | ak4114_init_vals, ak4114_init_txcsb, | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 187 | ice, &spec->ak4114); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | if (err < 0) | 
|  | 189 | return err; | 
|  | 190 |  | 
| Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 191 | #if 0 | 
|  | 192 | /* it seems that the analog doughter board detection does not work | 
|  | 193 | reliably, so force the analog flag; it should be very rare | 
|  | 194 | to use Juli@ without the analog doughter board */ | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 195 | spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1; | 
| Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 196 | #else | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 197 | spec->analog = 1; | 
| Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 198 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
| Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 200 | if (spec->analog) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | printk(KERN_INFO "juli@: analog I/O detected\n"); | 
|  | 202 | ice->num_total_dacs = 2; | 
|  | 203 | ice->num_total_adcs = 2; | 
|  | 204 |  | 
| Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 205 | ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | if (! ak) | 
|  | 207 | return -ENOMEM; | 
|  | 208 | ice->akm_codecs = 1; | 
|  | 209 | if ((err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice)) < 0) | 
|  | 210 | return err; | 
|  | 211 | } | 
|  | 212 |  | 
|  | 213 | return 0; | 
|  | 214 | } | 
|  | 215 |  | 
|  | 216 |  | 
|  | 217 | /* | 
|  | 218 | * Juli@ boards don't provide the EEPROM data except for the vendor IDs. | 
|  | 219 | * hence the driver needs to sets up it properly. | 
|  | 220 | */ | 
|  | 221 |  | 
| Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 222 | static unsigned char juli_eeprom[] __devinitdata = { | 
| Takashi Iwai | 189bc17 | 2007-01-29 15:25:40 +0100 | [diff] [blame] | 223 | [ICE_EEP2_SYSCONF]     = 0x20,	/* clock 512, mpu401, 1xADC, 1xDACs */ | 
|  | 224 | [ICE_EEP2_ACLINK]      = 0x80,	/* I2S */ | 
|  | 225 | [ICE_EEP2_I2S]         = 0xf8,	/* vol, 96k, 24bit, 192k */ | 
|  | 226 | [ICE_EEP2_SPDIF]       = 0xc3,	/* out-en, out-int, spdif-in */ | 
|  | 227 | [ICE_EEP2_GPIO_DIR]    = 0x9f, | 
|  | 228 | [ICE_EEP2_GPIO_DIR1]   = 0xff, | 
|  | 229 | [ICE_EEP2_GPIO_DIR2]   = 0x7f, | 
|  | 230 | [ICE_EEP2_GPIO_MASK]   = 0x9f, | 
|  | 231 | [ICE_EEP2_GPIO_MASK1]  = 0xff, | 
|  | 232 | [ICE_EEP2_GPIO_MASK2]  = 0x7f, | 
|  | 233 | [ICE_EEP2_GPIO_STATE]  = 0x16,	/* internal clock, multiple 1x, 48kHz */ | 
|  | 234 | [ICE_EEP2_GPIO_STATE1] = 0x80,	/* mute */ | 
|  | 235 | [ICE_EEP2_GPIO_STATE2] = 0x00, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | }; | 
|  | 237 |  | 
|  | 238 | /* entry point */ | 
| Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 239 | struct snd_ice1712_card_info snd_vt1724_juli_cards[] __devinitdata = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { | 
|  | 241 | .subvendor = VT1724_SUBDEVICE_JULI, | 
|  | 242 | .name = "ESI Juli@", | 
|  | 243 | .model = "juli", | 
|  | 244 | .chip_init = juli_init, | 
|  | 245 | .build_controls = juli_add_controls, | 
|  | 246 | .eeprom_size = sizeof(juli_eeprom), | 
|  | 247 | .eeprom_data = juli_eeprom, | 
|  | 248 | }, | 
|  | 249 | { } /* terminator */ | 
|  | 250 | }; |