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> |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 7 | * 2008 Pavel Hofman <dustin@seznam.cz> |
| 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | * |
| 24 | */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/io.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/interrupt.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <sound/core.h> |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 32 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include "ice1712.h" |
| 35 | #include "envy24ht.h" |
| 36 | #include "juli.h" |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 37 | struct juli_spec { |
| 38 | struct ak4114 *ak4114; |
| 39 | unsigned int analog: 1; |
| 40 | }; |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* |
| 43 | * chip addresses on I2C bus |
| 44 | */ |
| 45 | #define AK4114_ADDR 0x20 /* S/PDIF receiver */ |
| 46 | #define AK4358_ADDR 0x22 /* DAC */ |
| 47 | |
| 48 | /* |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 49 | * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is |
| 50 | * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency |
| 51 | * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx. |
| 52 | * |
| 53 | * The clock circuitry is supplied by the two ice1724 crystals. This |
| 54 | * arrangement allows to generate independent clock signal for AK4114's input |
| 55 | * rate detection circuit. As a result, Juli, unlike most other |
| 56 | * ice1724+ak4114-based cards, detects spdif input rate correctly. |
| 57 | * This fact is applied in the driver, allowing to modify PCM stream rate |
| 58 | * parameter according to the actual input rate. |
| 59 | * |
| 60 | * Juli uses the remaining three stereo-channels of its DAC to optionally |
| 61 | * monitor analog input, digital input, and digital output. The corresponding |
| 62 | * I2S signals are routed by Xilinx, controlled by GPIOs. |
| 63 | * |
| 64 | * The master mute is implemented using output muting transistors (GPIO) in |
| 65 | * combination with smuting the DAC. |
| 66 | * |
| 67 | * The card itself has no HW master volume control, implemented using the |
| 68 | * vmaster control. |
| 69 | * |
| 70 | * TODO: |
| 71 | * researching and fixing the input monitors |
| 72 | */ |
| 73 | |
| 74 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * GPIO pins |
| 76 | */ |
| 77 | #define GPIO_FREQ_MASK (3<<0) |
| 78 | #define GPIO_FREQ_32KHZ (0<<0) |
| 79 | #define GPIO_FREQ_44KHZ (1<<0) |
| 80 | #define GPIO_FREQ_48KHZ (2<<0) |
| 81 | #define GPIO_MULTI_MASK (3<<2) |
| 82 | #define GPIO_MULTI_4X (0<<2) |
| 83 | #define GPIO_MULTI_2X (1<<2) |
| 84 | #define GPIO_MULTI_1X (2<<2) /* also external */ |
| 85 | #define GPIO_MULTI_HALF (3<<2) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 86 | #define GPIO_INTERNAL_CLOCK (1<<4) /* 0 = external, 1 = internal */ |
| 87 | #define GPIO_CLOCK_MASK (1<<4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */ |
| 89 | #define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */ |
| 90 | #define GPIO_AK5385A_CKS0 (1<<8) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 91 | #define GPIO_AK5385A_DFS1 (1<<9) |
| 92 | #define GPIO_AK5385A_DFS0 (1<<10) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | #define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */ |
| 94 | #define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */ |
| 95 | #define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 96 | #define GPIO_AK5385A_CKS1 (1<<14) /* must be 0 */ |
| 97 | #define GPIO_MUTE_CONTROL (1<<15) /* output mute, 1 = muted */ |
| 98 | |
| 99 | #define GPIO_RATE_MASK (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \ |
| 100 | GPIO_CLOCK_MASK) |
| 101 | #define GPIO_AK5385A_MASK (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \ |
| 102 | GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1) |
| 103 | |
| 104 | #define JULI_PCM_RATE (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ |
| 105 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 106 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \ |
| 107 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \ |
| 108 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000) |
| 109 | |
| 110 | #define GPIO_RATE_16000 (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \ |
| 111 | GPIO_INTERNAL_CLOCK) |
| 112 | #define GPIO_RATE_22050 (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \ |
| 113 | GPIO_INTERNAL_CLOCK) |
| 114 | #define GPIO_RATE_24000 (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \ |
| 115 | GPIO_INTERNAL_CLOCK) |
| 116 | #define GPIO_RATE_32000 (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \ |
| 117 | GPIO_INTERNAL_CLOCK) |
| 118 | #define GPIO_RATE_44100 (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \ |
| 119 | GPIO_INTERNAL_CLOCK) |
| 120 | #define GPIO_RATE_48000 (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \ |
| 121 | GPIO_INTERNAL_CLOCK) |
| 122 | #define GPIO_RATE_64000 (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \ |
| 123 | GPIO_INTERNAL_CLOCK) |
| 124 | #define GPIO_RATE_88200 (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \ |
| 125 | GPIO_INTERNAL_CLOCK) |
| 126 | #define GPIO_RATE_96000 (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \ |
| 127 | GPIO_INTERNAL_CLOCK) |
| 128 | #define GPIO_RATE_176400 (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \ |
| 129 | GPIO_INTERNAL_CLOCK) |
| 130 | #define GPIO_RATE_192000 (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \ |
| 131 | GPIO_INTERNAL_CLOCK) |
| 132 | |
| 133 | /* |
| 134 | * Initial setup of the conversion array GPIO <-> rate |
| 135 | */ |
| 136 | static unsigned int juli_rates[] = { |
| 137 | 16000, 22050, 24000, 32000, |
| 138 | 44100, 48000, 64000, 88200, |
| 139 | 96000, 176400, 192000, |
| 140 | }; |
| 141 | |
| 142 | static unsigned int gpio_vals[] = { |
| 143 | GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000, |
| 144 | GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200, |
| 145 | GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000, |
| 146 | }; |
| 147 | |
| 148 | static struct snd_pcm_hw_constraint_list juli_rates_info = { |
| 149 | .count = ARRAY_SIZE(juli_rates), |
| 150 | .list = juli_rates, |
| 151 | .mask = 0, |
| 152 | }; |
| 153 | |
| 154 | static int get_gpio_val(int rate) |
| 155 | { |
| 156 | int i; |
| 157 | for (i = 0; i < ARRAY_SIZE(juli_rates); i++) |
| 158 | if (juli_rates[i] == rate) |
| 159 | return gpio_vals[i]; |
| 160 | return 0; |
| 161 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) |
| 164 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 165 | 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] | 166 | } |
| 167 | |
| 168 | static unsigned char juli_ak4114_read(void *private_data, unsigned char reg) |
| 169 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 170 | 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] | 171 | } |
| 172 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 173 | /* |
| 174 | * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate |
| 175 | * to the external rate |
| 176 | */ |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 177 | static void juli_spdif_in_open(struct snd_ice1712 *ice, |
| 178 | struct snd_pcm_substream *substream) |
| 179 | { |
| 180 | struct juli_spec *spec = ice->spec; |
| 181 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 182 | int rate; |
| 183 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 184 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK || |
| 185 | !ice->is_spdif_master(ice)) |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 186 | return; |
| 187 | rate = snd_ak4114_external_rate(spec->ak4114); |
| 188 | if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) { |
| 189 | runtime->hw.rate_min = rate; |
| 190 | runtime->hw.rate_max = rate; |
| 191 | } |
| 192 | } |
| 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* |
| 195 | * AK4358 section |
| 196 | */ |
| 197 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 198 | static void juli_akm_lock(struct snd_akm4xxx *ak, int chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | { |
| 200 | } |
| 201 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 202 | static void juli_akm_unlock(struct snd_akm4xxx *ak, int chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | } |
| 205 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 206 | static void juli_akm_write(struct snd_akm4xxx *ak, int chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | unsigned char addr, unsigned char data) |
| 208 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 209 | struct snd_ice1712 *ice = ak->private_data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame^] | 211 | if (snd_BUG_ON(chip)) |
| 212 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | snd_vt1724_write_i2c(ice, AK4358_ADDR, addr, data); |
| 214 | } |
| 215 | |
| 216 | /* |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 217 | * change the rate of envy24HT, AK4358, AK5385 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 219 | 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] | 220 | { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 221 | unsigned char old, tmp, ak4358_dfs; |
| 222 | unsigned int ak5385_pins, old_gpio, new_gpio; |
| 223 | struct snd_ice1712 *ice = ak->private_data[0]; |
| 224 | struct juli_spec *spec = ice->spec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 226 | if (rate == 0) /* no hint - S/PDIF input is master or the new spdif |
| 227 | input rate undetected, simply return */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | return; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* adjust DFS on codecs */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 231 | if (rate > 96000) { |
| 232 | ak4358_dfs = 2; |
| 233 | ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0; |
| 234 | } else if (rate > 48000) { |
| 235 | ak4358_dfs = 1; |
| 236 | ak5385_pins = GPIO_AK5385A_DFS0; |
| 237 | } else { |
| 238 | ak4358_dfs = 0; |
| 239 | ak5385_pins = 0; |
| 240 | } |
| 241 | /* AK5385 first, since it requires cold reset affecting both codecs */ |
| 242 | old_gpio = ice->gpio.get_data(ice); |
| 243 | new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins; |
| 244 | /* printk(KERN_DEBUG "JULI - ak5385 set_rate_val: new gpio 0x%x\n", |
| 245 | new_gpio); */ |
| 246 | ice->gpio.set_data(ice, new_gpio); |
| 247 | |
| 248 | /* cold reset */ |
| 249 | old = inb(ICEMT1724(ice, AC97_CMD)); |
| 250 | outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD)); |
| 251 | udelay(1); |
| 252 | outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD)); |
| 253 | |
| 254 | /* AK4358 */ |
| 255 | /* set new value, reset DFS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | tmp = snd_akm4xxx_get(ak, 0, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | snd_akm4xxx_reset(ak, 1); |
| 258 | tmp = snd_akm4xxx_get(ak, 0, 2); |
| 259 | tmp &= ~(0x03 << 4); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 260 | tmp |= ak4358_dfs << 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | snd_akm4xxx_set(ak, 0, 2, tmp); |
| 262 | snd_akm4xxx_reset(ak, 0); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 263 | |
| 264 | /* reinit ak4114 */ |
| 265 | snd_ak4114_reinit(spec->ak4114); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 268 | #define AK_DAC(xname, xch) { .name = xname, .num_channels = xch } |
| 269 | #define PCM_VOLUME "PCM Playback Volume" |
| 270 | #define MONITOR_AN_IN_VOLUME "Monitor Analog In Volume" |
| 271 | #define MONITOR_DIG_IN_VOLUME "Monitor Digital In Volume" |
| 272 | #define MONITOR_DIG_OUT_VOLUME "Monitor Digital Out Volume" |
| 273 | |
| 274 | static const struct snd_akm4xxx_dac_channel juli_dac[] = { |
| 275 | AK_DAC(PCM_VOLUME, 2), |
| 276 | AK_DAC(MONITOR_AN_IN_VOLUME, 2), |
| 277 | AK_DAC(MONITOR_DIG_OUT_VOLUME, 2), |
| 278 | AK_DAC(MONITOR_DIG_IN_VOLUME, 2), |
| 279 | }; |
| 280 | |
| 281 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 282 | static struct snd_akm4xxx akm_juli_dac __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | .type = SND_AK4358, |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 284 | .num_dacs = 8, /* DAC1 - analog out |
| 285 | DAC2 - analog in monitor |
| 286 | DAC3 - digital out monitor |
| 287 | DAC4 - digital in monitor |
| 288 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | .ops = { |
| 290 | .lock = juli_akm_lock, |
| 291 | .unlock = juli_akm_unlock, |
| 292 | .write = juli_akm_write, |
| 293 | .set_rate_val = juli_akm_set_rate_val |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 294 | }, |
| 295 | .dac_info = juli_dac, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 298 | #define juli_mute_info snd_ctl_boolean_mono_info |
| 299 | |
| 300 | static int juli_mute_get(struct snd_kcontrol *kcontrol, |
| 301 | struct snd_ctl_elem_value *ucontrol) |
| 302 | { |
| 303 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 304 | unsigned int val; |
| 305 | val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value; |
| 306 | if (kcontrol->private_value == GPIO_MUTE_CONTROL) |
| 307 | /* val 0 = signal on */ |
| 308 | ucontrol->value.integer.value[0] = (val) ? 0 : 1; |
| 309 | else |
| 310 | /* val 1 = signal on */ |
| 311 | ucontrol->value.integer.value[0] = (val) ? 1 : 0; |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static int juli_mute_put(struct snd_kcontrol *kcontrol, |
| 316 | struct snd_ctl_elem_value *ucontrol) |
| 317 | { |
| 318 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 319 | unsigned int old_gpio, new_gpio; |
| 320 | old_gpio = ice->gpio.get_data(ice); |
| 321 | if (ucontrol->value.integer.value[0]) { |
| 322 | /* unmute */ |
| 323 | if (kcontrol->private_value == GPIO_MUTE_CONTROL) { |
| 324 | /* 0 = signal on */ |
| 325 | new_gpio = old_gpio & ~GPIO_MUTE_CONTROL; |
| 326 | /* un-smuting DAC */ |
| 327 | snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01); |
| 328 | } else |
| 329 | /* 1 = signal on */ |
| 330 | new_gpio = old_gpio | |
| 331 | (unsigned int) kcontrol->private_value; |
| 332 | } else { |
| 333 | /* mute */ |
| 334 | if (kcontrol->private_value == GPIO_MUTE_CONTROL) { |
| 335 | /* 1 = signal off */ |
| 336 | new_gpio = old_gpio | GPIO_MUTE_CONTROL; |
| 337 | /* smuting DAC */ |
| 338 | snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03); |
| 339 | } else |
| 340 | /* 0 = signal off */ |
| 341 | new_gpio = old_gpio & |
| 342 | ~((unsigned int) kcontrol->private_value); |
| 343 | } |
| 344 | /* printk("JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, \ |
| 345 | new_gpio 0x%x\n", |
| 346 | (unsigned int)ucontrol->value.integer.value[0], old_gpio, |
| 347 | new_gpio); */ |
| 348 | if (old_gpio != new_gpio) { |
| 349 | ice->gpio.set_data(ice, new_gpio); |
| 350 | return 1; |
| 351 | } |
| 352 | /* no change */ |
| 353 | return 0; |
| 354 | } |
| 355 | |
| 356 | static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = { |
| 357 | { |
| 358 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 359 | .name = "Master Playback Switch", |
| 360 | .info = juli_mute_info, |
| 361 | .get = juli_mute_get, |
| 362 | .put = juli_mute_put, |
| 363 | .private_value = GPIO_MUTE_CONTROL, |
| 364 | }, |
| 365 | /* Although the following functionality respects the succint NDA'd |
| 366 | * documentation from the card manufacturer, and the same way of |
| 367 | * operation is coded in OSS Juli driver, only Digital Out monitor |
| 368 | * seems to work. Surprisingly, Analog input monitor outputs Digital |
| 369 | * output data. The two are independent, as enabling both doubles |
| 370 | * volume of the monitor sound. |
| 371 | * |
| 372 | * Checking traces on the board suggests the functionality described |
| 373 | * by the manufacturer is correct - I2S from ADC and AK4114 |
| 374 | * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor |
| 375 | * inputs) are fed from Xilinx. |
| 376 | * |
| 377 | * I even checked traces on board and coded a support in driver for |
| 378 | * an alternative possiblity - the unused I2S ICE output channels |
| 379 | * switched to HW-IN/SPDIF-IN and providing the monitoring signal to |
| 380 | * the DAC - to no avail. The I2S outputs seem to be unconnected. |
| 381 | * |
| 382 | * The windows driver supports the monitoring correctly. |
| 383 | */ |
| 384 | { |
| 385 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 386 | .name = "Monitor Analog In Switch", |
| 387 | .info = juli_mute_info, |
| 388 | .get = juli_mute_get, |
| 389 | .put = juli_mute_put, |
| 390 | .private_value = GPIO_ANAIN_MONITOR, |
| 391 | }, |
| 392 | { |
| 393 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 394 | .name = "Monitor Digital Out Switch", |
| 395 | .info = juli_mute_info, |
| 396 | .get = juli_mute_get, |
| 397 | .put = juli_mute_put, |
| 398 | .private_value = GPIO_DIGOUT_MONITOR, |
| 399 | }, |
| 400 | { |
| 401 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 402 | .name = "Monitor Digital In Switch", |
| 403 | .info = juli_mute_info, |
| 404 | .get = juli_mute_get, |
| 405 | .put = juli_mute_put, |
| 406 | .private_value = GPIO_DIGIN_MONITOR, |
| 407 | }, |
| 408 | }; |
| 409 | |
| 410 | |
| 411 | static void ak4358_proc_regs_read(struct snd_info_entry *entry, |
| 412 | struct snd_info_buffer *buffer) |
| 413 | { |
| 414 | struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data; |
| 415 | int reg, val; |
| 416 | for (reg = 0; reg <= 0xf; reg++) { |
| 417 | val = snd_akm4xxx_get(ice->akm, 0, reg); |
| 418 | snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | static void ak4358_proc_init(struct snd_ice1712 *ice) |
| 423 | { |
| 424 | struct snd_info_entry *entry; |
| 425 | if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry)) |
| 426 | snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read); |
| 427 | } |
| 428 | |
| 429 | static char *slave_vols[] __devinitdata = { |
| 430 | PCM_VOLUME, |
| 431 | MONITOR_AN_IN_VOLUME, |
| 432 | MONITOR_DIG_IN_VOLUME, |
| 433 | MONITOR_DIG_OUT_VOLUME, |
| 434 | NULL |
| 435 | }; |
| 436 | |
| 437 | static __devinitdata |
| 438 | DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1); |
| 439 | |
| 440 | static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card, |
| 441 | const char *name) |
| 442 | { |
| 443 | struct snd_ctl_elem_id sid; |
| 444 | memset(&sid, 0, sizeof(sid)); |
| 445 | /* FIXME: strcpy is bad. */ |
| 446 | strcpy(sid.name, name); |
| 447 | sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 448 | return snd_ctl_find_id(card, &sid); |
| 449 | } |
| 450 | |
| 451 | static void __devinit add_slaves(struct snd_card *card, |
| 452 | struct snd_kcontrol *master, char **list) |
| 453 | { |
| 454 | for (; *list; list++) { |
| 455 | struct snd_kcontrol *slave = ctl_find(card, *list); |
| 456 | /* printk(KERN_DEBUG "add_slaves - %s\n", *list); */ |
| 457 | if (slave) { |
| 458 | /* printk(KERN_DEBUG "slave %s found\n", *list); */ |
| 459 | snd_ctl_add_slave(master, slave); |
| 460 | } |
| 461 | } |
| 462 | } |
| 463 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 464 | static int __devinit juli_add_controls(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | { |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 466 | struct juli_spec *spec = ice->spec; |
Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 467 | int err; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 468 | unsigned int i; |
| 469 | struct snd_kcontrol *vmaster; |
| 470 | |
Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 471 | err = snd_ice1712_akm4xxx_build_controls(ice); |
| 472 | if (err < 0) |
| 473 | return err; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 474 | |
| 475 | for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) { |
| 476 | err = snd_ctl_add(ice->card, |
| 477 | snd_ctl_new1(&juli_mute_controls[i], ice)); |
| 478 | if (err < 0) |
| 479 | return err; |
| 480 | } |
| 481 | /* Create virtual master control */ |
| 482 | vmaster = snd_ctl_make_virtual_master("Master Playback Volume", |
| 483 | juli_master_db_scale); |
| 484 | if (!vmaster) |
| 485 | return -ENOMEM; |
| 486 | add_slaves(ice->card, vmaster, slave_vols); |
| 487 | err = snd_ctl_add(ice->card, vmaster); |
| 488 | if (err < 0) |
| 489 | return err; |
| 490 | |
Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 491 | /* only capture SPDIF over AK4114 */ |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 492 | err = snd_ak4114_build(spec->ak4114, NULL, |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 493 | ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); |
| 494 | |
| 495 | ak4358_proc_init(ice); |
Takashi Iwai | fdd4bb4 | 2007-04-05 17:08:57 +0200 | [diff] [blame] | 496 | if (err < 0) |
| 497 | return err; |
| 498 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | /* |
| 502 | * initialize the chip |
| 503 | */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 504 | |
| 505 | static inline int juli_is_spdif_master(struct snd_ice1712 *ice) |
| 506 | { |
| 507 | return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1; |
| 508 | } |
| 509 | |
| 510 | static unsigned int juli_get_rate(struct snd_ice1712 *ice) |
| 511 | { |
| 512 | int i; |
| 513 | unsigned char result; |
| 514 | |
| 515 | result = ice->gpio.get_data(ice) & GPIO_RATE_MASK; |
| 516 | for (i = 0; i < ARRAY_SIZE(gpio_vals); i++) |
| 517 | if (gpio_vals[i] == result) |
| 518 | return juli_rates[i]; |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | /* setting new rate */ |
| 523 | static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate) |
| 524 | { |
| 525 | unsigned int old, new; |
| 526 | unsigned char val; |
| 527 | |
| 528 | old = ice->gpio.get_data(ice); |
| 529 | new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate); |
| 530 | /* printk(KERN_DEBUG "JULI - set_rate: old %x, new %x\n", |
| 531 | old & GPIO_RATE_MASK, |
| 532 | new & GPIO_RATE_MASK); */ |
| 533 | |
| 534 | ice->gpio.set_data(ice, new); |
| 535 | /* switching to external clock - supplied by external circuits */ |
| 536 | val = inb(ICEMT1724(ice, RATE)); |
| 537 | outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE)); |
| 538 | } |
| 539 | |
| 540 | static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice, |
| 541 | unsigned int rate) |
| 542 | { |
| 543 | /* no change in master clock */ |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | /* setting clock to external - SPDIF */ |
| 548 | static void juli_set_spdif_clock(struct snd_ice1712 *ice) |
| 549 | { |
| 550 | unsigned int old; |
| 551 | old = ice->gpio.get_data(ice); |
| 552 | /* external clock (= 0), multiply 1x, 48kHz */ |
| 553 | ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X | |
| 554 | GPIO_FREQ_48KHZ); |
| 555 | } |
| 556 | |
| 557 | /* Called when ak4114 detects change in the input SPDIF stream */ |
| 558 | static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0, |
| 559 | unsigned char c1) |
| 560 | { |
| 561 | struct snd_ice1712 *ice = ak4114->change_callback_private; |
| 562 | int rate; |
| 563 | if (ice->is_spdif_master(ice) && c1) { |
| 564 | /* only for SPDIF master mode, rate was changed */ |
| 565 | rate = snd_ak4114_external_rate(ak4114); |
| 566 | /* printk(KERN_DEBUG "ak4114 - input rate changed to %d\n", |
| 567 | rate); */ |
| 568 | juli_akm_set_rate_val(ice->akm, rate); |
| 569 | } |
| 570 | } |
| 571 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 572 | static int __devinit juli_init(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | { |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 574 | static const unsigned char ak4114_init_vals[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | /* AK4117_REG_PWRDN */ AK4114_RST | AK4114_PWN | AK4114_OCKS0 | AK4114_OCKS1, |
| 576 | /* AK4114_REQ_FORMAT */ AK4114_DIF_I24I2S, |
| 577 | /* AK4114_REG_IO0 */ AK4114_TX1E, |
| 578 | /* AK4114_REG_IO1 */ AK4114_EFH_1024 | AK4114_DIT | AK4114_IPS(1), |
| 579 | /* AK4114_REG_INT0_MASK */ 0, |
| 580 | /* AK4114_REG_INT1_MASK */ 0 |
| 581 | }; |
Takashi Iwai | 517400c | 2007-01-29 15:27:56 +0100 | [diff] [blame] | 582 | static const unsigned char ak4114_init_txcsb[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | 0x41, 0x02, 0x2c, 0x00, 0x00 |
| 584 | }; |
| 585 | int err; |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 586 | struct juli_spec *spec; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 587 | struct snd_akm4xxx *ak; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 589 | spec = kzalloc(sizeof(*spec), GFP_KERNEL); |
| 590 | if (!spec) |
| 591 | return -ENOMEM; |
| 592 | ice->spec = spec; |
| 593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | err = snd_ak4114_create(ice->card, |
| 595 | juli_ak4114_read, |
| 596 | juli_ak4114_write, |
| 597 | ak4114_init_vals, ak4114_init_txcsb, |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 598 | ice, &spec->ak4114); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | if (err < 0) |
| 600 | return err; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 601 | /* callback for codecs rate setting */ |
| 602 | spec->ak4114->change_callback = juli_ak4114_change; |
| 603 | spec->ak4114->change_callback_private = ice; |
| 604 | /* AK4114 in Juli can detect external rate correctly */ |
| 605 | spec->ak4114->check_flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | |
Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 607 | #if 0 |
| 608 | /* it seems that the analog doughter board detection does not work |
| 609 | reliably, so force the analog flag; it should be very rare |
| 610 | to use Juli@ without the analog doughter board */ |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 611 | spec->analog = (ice->gpio.get_data(ice) & GPIO_ANALOG_PRESENT) ? 0 : 1; |
Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 612 | #else |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 613 | spec->analog = 1; |
Jaroslav Kysela | fd6715e | 2005-11-10 07:51:31 +0100 | [diff] [blame] | 614 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 616 | if (spec->analog) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | printk(KERN_INFO "juli@: analog I/O detected\n"); |
| 618 | ice->num_total_dacs = 2; |
| 619 | ice->num_total_adcs = 2; |
| 620 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 621 | ak = ice->akm = kzalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | if (! ak) |
| 623 | return -ENOMEM; |
| 624 | ice->akm_codecs = 1; |
| 625 | if ((err = snd_ice1712_akm4xxx_init(ak, &akm_juli_dac, NULL, ice)) < 0) |
| 626 | return err; |
| 627 | } |
| 628 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 629 | /* juli is clocked by Xilinx array */ |
| 630 | ice->hw_rates = &juli_rates_info; |
| 631 | ice->is_spdif_master = juli_is_spdif_master; |
| 632 | ice->get_rate = juli_get_rate; |
| 633 | ice->set_rate = juli_set_rate; |
| 634 | ice->set_mclk = juli_set_mclk; |
| 635 | ice->set_spdif_clock = juli_set_spdif_clock; |
| 636 | |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 637 | ice->spdif.ops.open = juli_spdif_in_open; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | |
| 642 | /* |
| 643 | * Juli@ boards don't provide the EEPROM data except for the vendor IDs. |
| 644 | * hence the driver needs to sets up it properly. |
| 645 | */ |
| 646 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 647 | static unsigned char juli_eeprom[] __devinitdata = { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 648 | [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, 1xADC, 1xDACs, |
| 649 | SPDIF in */ |
Takashi Iwai | 189bc17 | 2007-01-29 15:25:40 +0100 | [diff] [blame] | 650 | [ICE_EEP2_ACLINK] = 0x80, /* I2S */ |
| 651 | [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ |
| 652 | [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 653 | [ICE_EEP2_GPIO_DIR] = 0x9f, /* 5, 6:inputs; 7, 4-0 outputs*/ |
Takashi Iwai | 189bc17 | 2007-01-29 15:25:40 +0100 | [diff] [blame] | 654 | [ICE_EEP2_GPIO_DIR1] = 0xff, |
| 655 | [ICE_EEP2_GPIO_DIR2] = 0x7f, |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 656 | [ICE_EEP2_GPIO_MASK] = 0x60, /* 5, 6: locked; 7, 4-0 writable */ |
| 657 | [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0-7 writable */ |
Takashi Iwai | 189bc17 | 2007-01-29 15:25:40 +0100 | [diff] [blame] | 658 | [ICE_EEP2_GPIO_MASK2] = 0x7f, |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 659 | [ICE_EEP2_GPIO_STATE] = GPIO_FREQ_48KHZ | GPIO_MULTI_1X | |
| 660 | GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/ |
| 661 | [ICE_EEP2_GPIO_STATE1] = 0x00, /* unmuted */ |
Takashi Iwai | 189bc17 | 2007-01-29 15:25:40 +0100 | [diff] [blame] | 662 | [ICE_EEP2_GPIO_STATE2] = 0x00, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | }; |
| 664 | |
| 665 | /* entry point */ |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 666 | struct snd_ice1712_card_info snd_vt1724_juli_cards[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | .subvendor = VT1724_SUBDEVICE_JULI, |
| 669 | .name = "ESI Juli@", |
| 670 | .model = "juli", |
| 671 | .chip_init = juli_init, |
| 672 | .build_controls = juli_add_controls, |
| 673 | .eeprom_size = sizeof(juli_eeprom), |
| 674 | .eeprom_data = juli_eeprom, |
| 675 | }, |
| 676 | { } /* terminator */ |
| 677 | }; |