Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALSA driver for VT1724 ICEnsemble ICE1724 / VIA VT1724 (Envy24HT) |
| 3 | * VIA VT1720 (Envy24PT) |
| 4 | * |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 5 | * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * 2002 James Stafford <jstafford@ampltd.com> |
| 7 | * 2003 Takashi Iwai <tiwai@suse.de> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | * |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 23 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 25 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/delay.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/pci.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/moduleparam.h> |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 32 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <sound/core.h> |
| 34 | #include <sound/info.h> |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 35 | #include <sound/rawmidi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <sound/initval.h> |
| 37 | |
| 38 | #include <sound/asoundef.h> |
| 39 | |
| 40 | #include "ice1712.h" |
| 41 | #include "envy24ht.h" |
| 42 | |
| 43 | /* lowlevel routines */ |
| 44 | #include "amp.h" |
| 45 | #include "revo.h" |
| 46 | #include "aureon.h" |
| 47 | #include "vt1720_mobo.h" |
| 48 | #include "pontis.h" |
| 49 | #include "prodigy192.h" |
Julian Scheel | 6b8d6e5 | 2008-01-16 19:50:00 +0100 | [diff] [blame] | 50 | #include "prodigy_hifi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include "juli.h" |
Takashi Iwai | 72cbfd4 | 2009-05-06 17:33:19 +0200 | [diff] [blame^] | 52 | #include "maya44.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include "phase.h" |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 54 | #include "wtm.h" |
Shin-ya Okada | f31639b | 2007-10-23 15:08:18 +0200 | [diff] [blame] | 55 | #include "se.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 57 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | MODULE_DESCRIPTION("VIA ICEnsemble ICE1724/1720 (Envy24HT/PT)"); |
| 59 | MODULE_LICENSE("GPL"); |
| 60 | MODULE_SUPPORTED_DEVICE("{" |
| 61 | REVO_DEVICE_DESC |
| 62 | AMP_AUDIO2000_DEVICE_DESC |
| 63 | AUREON_DEVICE_DESC |
| 64 | VT1720_MOBO_DEVICE_DESC |
| 65 | PONTIS_DEVICE_DESC |
| 66 | PRODIGY192_DEVICE_DESC |
Julian Scheel | 6b8d6e5 | 2008-01-16 19:50:00 +0100 | [diff] [blame] | 67 | PRODIGY_HIFI_DEVICE_DESC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | JULI_DEVICE_DESC |
Takashi Iwai | 72cbfd4 | 2009-05-06 17:33:19 +0200 | [diff] [blame^] | 69 | MAYA44_DEVICE_DESC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | PHASE_DEVICE_DESC |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 71 | WTM_DEVICE_DESC |
Shin-ya Okada | f31639b | 2007-10-23 15:08:18 +0200 | [diff] [blame] | 72 | SE_DEVICE_DESC |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | "{VIA,VT1720}," |
| 74 | "{VIA,VT1724}," |
| 75 | "{ICEnsemble,Generic ICE1724}," |
| 76 | "{ICEnsemble,Generic Envy24HT}" |
| 77 | "{ICEnsemble,Generic Envy24PT}}"); |
| 78 | |
| 79 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 80 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 81 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 82 | static char *model[SNDRV_CARDS]; |
| 83 | |
| 84 | module_param_array(index, int, NULL, 0444); |
| 85 | MODULE_PARM_DESC(index, "Index value for ICE1724 soundcard."); |
| 86 | module_param_array(id, charp, NULL, 0444); |
| 87 | MODULE_PARM_DESC(id, "ID string for ICE1724 soundcard."); |
| 88 | module_param_array(enable, bool, NULL, 0444); |
| 89 | MODULE_PARM_DESC(enable, "Enable ICE1724 soundcard."); |
| 90 | module_param_array(model, charp, NULL, 0444); |
| 91 | MODULE_PARM_DESC(model, "Use the given board model."); |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | /* Both VT1720 and VT1724 have the same PCI IDs */ |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 95 | static const struct pci_device_id snd_vt1724_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { PCI_VENDOR_ID_ICE, PCI_DEVICE_ID_VT1724, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, |
| 97 | { 0, } |
| 98 | }; |
| 99 | |
| 100 | MODULE_DEVICE_TABLE(pci, snd_vt1724_ids); |
| 101 | |
| 102 | |
| 103 | static int PRO_RATE_LOCKED; |
| 104 | static int PRO_RATE_RESET = 1; |
| 105 | static unsigned int PRO_RATE_DEFAULT = 44100; |
| 106 | |
| 107 | /* |
| 108 | * Basic I/O |
| 109 | */ |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 110 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 111 | /* |
| 112 | * default rates, default clock routines |
| 113 | */ |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* check whether the clock mode is spdif-in */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 116 | static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
| 118 | return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; |
| 119 | } |
| 120 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 121 | static inline int is_pro_rate_locked(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 123 | return ice->is_spdif_master(ice) || PRO_RATE_LOCKED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | /* |
| 127 | * ac97 section |
| 128 | */ |
| 129 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 130 | static unsigned char snd_vt1724_ac97_ready(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | unsigned char old_cmd; |
| 133 | int tm; |
| 134 | for (tm = 0; tm < 0x10000; tm++) { |
| 135 | old_cmd = inb(ICEMT1724(ice, AC97_CMD)); |
| 136 | if (old_cmd & (VT1724_AC97_WRITE | VT1724_AC97_READ)) |
| 137 | continue; |
| 138 | if (!(old_cmd & VT1724_AC97_READY)) |
| 139 | continue; |
| 140 | return old_cmd; |
| 141 | } |
| 142 | snd_printd(KERN_ERR "snd_vt1724_ac97_ready: timeout\n"); |
| 143 | return old_cmd; |
| 144 | } |
| 145 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 146 | static int snd_vt1724_ac97_wait_bit(struct snd_ice1712 *ice, unsigned char bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | int tm; |
| 149 | for (tm = 0; tm < 0x10000; tm++) |
| 150 | if ((inb(ICEMT1724(ice, AC97_CMD)) & bit) == 0) |
| 151 | return 0; |
| 152 | snd_printd(KERN_ERR "snd_vt1724_ac97_wait_bit: timeout\n"); |
| 153 | return -EIO; |
| 154 | } |
| 155 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 156 | static void snd_vt1724_ac97_write(struct snd_ac97 *ac97, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | unsigned short reg, |
| 158 | unsigned short val) |
| 159 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 160 | struct snd_ice1712 *ice = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | unsigned char old_cmd; |
| 162 | |
| 163 | old_cmd = snd_vt1724_ac97_ready(ice); |
| 164 | old_cmd &= ~VT1724_AC97_ID_MASK; |
| 165 | old_cmd |= ac97->num; |
| 166 | outb(reg, ICEMT1724(ice, AC97_INDEX)); |
| 167 | outw(val, ICEMT1724(ice, AC97_DATA)); |
| 168 | outb(old_cmd | VT1724_AC97_WRITE, ICEMT1724(ice, AC97_CMD)); |
| 169 | snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_WRITE); |
| 170 | } |
| 171 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 172 | static unsigned short snd_vt1724_ac97_read(struct snd_ac97 *ac97, unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 174 | struct snd_ice1712 *ice = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | unsigned char old_cmd; |
| 176 | |
| 177 | old_cmd = snd_vt1724_ac97_ready(ice); |
| 178 | old_cmd &= ~VT1724_AC97_ID_MASK; |
| 179 | old_cmd |= ac97->num; |
| 180 | outb(reg, ICEMT1724(ice, AC97_INDEX)); |
| 181 | outb(old_cmd | VT1724_AC97_READ, ICEMT1724(ice, AC97_CMD)); |
| 182 | if (snd_vt1724_ac97_wait_bit(ice, VT1724_AC97_READ) < 0) |
| 183 | return ~0; |
| 184 | return inw(ICEMT1724(ice, AC97_DATA)); |
| 185 | } |
| 186 | |
| 187 | |
| 188 | /* |
| 189 | * GPIO operations |
| 190 | */ |
| 191 | |
| 192 | /* set gpio direction 0 = read, 1 = write */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 193 | static void snd_vt1724_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | { |
| 195 | outl(data, ICEREG1724(ice, GPIO_DIRECTION)); |
| 196 | inw(ICEREG1724(ice, GPIO_DIRECTION)); /* dummy read for pci-posting */ |
| 197 | } |
| 198 | |
| 199 | /* set the gpio mask (0 = writable) */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 200 | static void snd_vt1724_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | outw(data, ICEREG1724(ice, GPIO_WRITE_MASK)); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 203 | if (!ice->vt1720) /* VT1720 supports only 16 GPIO bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | outb((data >> 16) & 0xff, ICEREG1724(ice, GPIO_WRITE_MASK_22)); |
| 205 | inw(ICEREG1724(ice, GPIO_WRITE_MASK)); /* dummy read for pci-posting */ |
| 206 | } |
| 207 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 208 | static void snd_vt1724_set_gpio_data(struct snd_ice1712 *ice, unsigned int data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
| 210 | outw(data, ICEREG1724(ice, GPIO_DATA)); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 211 | if (!ice->vt1720) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | outb(data >> 16, ICEREG1724(ice, GPIO_DATA_22)); |
| 213 | inw(ICEREG1724(ice, GPIO_DATA)); /* dummy read for pci-posting */ |
| 214 | } |
| 215 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 216 | static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | { |
| 218 | unsigned int data; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 219 | if (!ice->vt1720) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | data = (unsigned int)inb(ICEREG1724(ice, GPIO_DATA_22)); |
| 221 | else |
| 222 | data = 0; |
| 223 | data = (data << 16) | inw(ICEREG1724(ice, GPIO_DATA)); |
| 224 | return data; |
| 225 | } |
| 226 | |
| 227 | /* |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 228 | * MIDI |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 229 | */ |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 230 | |
| 231 | static void vt1724_midi_clear_rx(struct snd_ice1712 *ice) |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 232 | { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 233 | unsigned int count; |
| 234 | |
| 235 | for (count = inb(ICEREG1724(ice, MPU_RXFIFO)); count > 0; --count) |
| 236 | inb(ICEREG1724(ice, MPU_DATA)); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 239 | static inline struct snd_rawmidi_substream * |
| 240 | get_rawmidi_substream(struct snd_ice1712 *ice, unsigned int stream) |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 241 | { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 242 | return list_first_entry(&ice->rmidi[0]->streams[stream].substreams, |
| 243 | struct snd_rawmidi_substream, list); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 246 | static void enable_midi_irq(struct snd_ice1712 *ice, u8 flag, int enable); |
| 247 | |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 248 | static void vt1724_midi_write(struct snd_ice1712 *ice) |
| 249 | { |
| 250 | struct snd_rawmidi_substream *s; |
| 251 | int count, i; |
| 252 | u8 buffer[32]; |
| 253 | |
| 254 | s = get_rawmidi_substream(ice, SNDRV_RAWMIDI_STREAM_OUTPUT); |
| 255 | count = 31 - inb(ICEREG1724(ice, MPU_TXFIFO)); |
| 256 | if (count > 0) { |
| 257 | count = snd_rawmidi_transmit(s, buffer, count); |
| 258 | for (i = 0; i < count; ++i) |
| 259 | outb(buffer[i], ICEREG1724(ice, MPU_DATA)); |
| 260 | } |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 261 | /* mask irq when all bytes have been transmitted. |
| 262 | * enabled again in output_trigger when the new data comes in. |
| 263 | */ |
| 264 | enable_midi_irq(ice, VT1724_IRQ_MPU_TX, |
| 265 | !snd_rawmidi_transmit_empty(s)); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | static void vt1724_midi_read(struct snd_ice1712 *ice) |
| 269 | { |
| 270 | struct snd_rawmidi_substream *s; |
| 271 | int count, i; |
| 272 | u8 buffer[32]; |
| 273 | |
| 274 | s = get_rawmidi_substream(ice, SNDRV_RAWMIDI_STREAM_INPUT); |
| 275 | count = inb(ICEREG1724(ice, MPU_RXFIFO)); |
| 276 | if (count > 0) { |
| 277 | count = min(count, 32); |
| 278 | for (i = 0; i < count; ++i) |
| 279 | buffer[i] = inb(ICEREG1724(ice, MPU_DATA)); |
| 280 | snd_rawmidi_receive(s, buffer, count); |
| 281 | } |
| 282 | } |
| 283 | |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 284 | /* call with ice->reg_lock */ |
| 285 | static void enable_midi_irq(struct snd_ice1712 *ice, u8 flag, int enable) |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 286 | { |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 287 | u8 mask = inb(ICEREG1724(ice, IRQMASK)); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 288 | if (enable) |
| 289 | mask &= ~flag; |
| 290 | else |
| 291 | mask |= flag; |
| 292 | outb(mask, ICEREG1724(ice, IRQMASK)); |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void vt1724_enable_midi_irq(struct snd_rawmidi_substream *substream, |
| 296 | u8 flag, int enable) |
| 297 | { |
| 298 | struct snd_ice1712 *ice = substream->rmidi->private_data; |
| 299 | |
| 300 | spin_lock_irq(&ice->reg_lock); |
| 301 | enable_midi_irq(ice, flag, enable); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 302 | spin_unlock_irq(&ice->reg_lock); |
| 303 | } |
| 304 | |
| 305 | static int vt1724_midi_output_open(struct snd_rawmidi_substream *s) |
| 306 | { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static int vt1724_midi_output_close(struct snd_rawmidi_substream *s) |
| 311 | { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | static void vt1724_midi_output_trigger(struct snd_rawmidi_substream *s, int up) |
| 316 | { |
| 317 | struct snd_ice1712 *ice = s->rmidi->private_data; |
| 318 | unsigned long flags; |
| 319 | |
| 320 | spin_lock_irqsave(&ice->reg_lock, flags); |
| 321 | if (up) { |
| 322 | ice->midi_output = 1; |
| 323 | vt1724_midi_write(ice); |
| 324 | } else { |
| 325 | ice->midi_output = 0; |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 326 | enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 327 | } |
| 328 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 329 | } |
| 330 | |
| 331 | static void vt1724_midi_output_drain(struct snd_rawmidi_substream *s) |
| 332 | { |
| 333 | struct snd_ice1712 *ice = s->rmidi->private_data; |
| 334 | unsigned long timeout; |
| 335 | |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 336 | vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 0); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 337 | /* 32 bytes should be transmitted in less than about 12 ms */ |
| 338 | timeout = jiffies + msecs_to_jiffies(15); |
| 339 | do { |
| 340 | if (inb(ICEREG1724(ice, MPU_CTRL)) & VT1724_MPU_TX_EMPTY) |
| 341 | break; |
| 342 | schedule_timeout_uninterruptible(1); |
| 343 | } while (time_after(timeout, jiffies)); |
| 344 | } |
| 345 | |
| 346 | static struct snd_rawmidi_ops vt1724_midi_output_ops = { |
| 347 | .open = vt1724_midi_output_open, |
| 348 | .close = vt1724_midi_output_close, |
| 349 | .trigger = vt1724_midi_output_trigger, |
| 350 | .drain = vt1724_midi_output_drain, |
| 351 | }; |
| 352 | |
| 353 | static int vt1724_midi_input_open(struct snd_rawmidi_substream *s) |
| 354 | { |
| 355 | vt1724_midi_clear_rx(s->rmidi->private_data); |
| 356 | vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_RX, 1); |
| 357 | return 0; |
| 358 | } |
| 359 | |
| 360 | static int vt1724_midi_input_close(struct snd_rawmidi_substream *s) |
| 361 | { |
| 362 | vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_RX, 0); |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | static void vt1724_midi_input_trigger(struct snd_rawmidi_substream *s, int up) |
| 367 | { |
| 368 | struct snd_ice1712 *ice = s->rmidi->private_data; |
| 369 | unsigned long flags; |
| 370 | |
| 371 | spin_lock_irqsave(&ice->reg_lock, flags); |
| 372 | if (up) { |
| 373 | ice->midi_input = 1; |
| 374 | vt1724_midi_read(ice); |
| 375 | } else { |
| 376 | ice->midi_input = 0; |
| 377 | } |
| 378 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 379 | } |
| 380 | |
| 381 | static struct snd_rawmidi_ops vt1724_midi_input_ops = { |
| 382 | .open = vt1724_midi_input_open, |
| 383 | .close = vt1724_midi_input_close, |
| 384 | .trigger = vt1724_midi_input_trigger, |
| 385 | }; |
| 386 | |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 387 | |
| 388 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | * Interrupt handler |
| 390 | */ |
| 391 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 392 | static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 394 | struct snd_ice1712 *ice = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | unsigned char status; |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 396 | unsigned char status_mask = |
| 397 | VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | int handled = 0; |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 399 | int timeout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | while (1) { |
| 402 | status = inb(ICEREG1724(ice, IRQSTAT)); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 403 | status &= status_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | if (status == 0) |
| 405 | break; |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 406 | spin_lock(&ice->reg_lock); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 407 | if (++timeout > 10) { |
Takashi Iwai | 1083206 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 408 | status = inb(ICEREG1724(ice, IRQSTAT)); |
| 409 | printk(KERN_ERR "ice1724: Too long irq loop, " |
| 410 | "status = 0x%x\n", status); |
| 411 | if (status & VT1724_IRQ_MPU_TX) { |
| 412 | printk(KERN_ERR "ice1724: Disabling MPU_TX\n"); |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 413 | enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0); |
Takashi Iwai | 1083206 | 2008-08-11 10:18:39 +0200 | [diff] [blame] | 414 | } |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 415 | spin_unlock(&ice->reg_lock); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 416 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 418 | handled = 1; |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 419 | if (status & VT1724_IRQ_MPU_TX) { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 420 | if (ice->midi_output) |
| 421 | vt1724_midi_write(ice); |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 422 | else |
| 423 | enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 424 | /* Due to mysterical reasons, MPU_TX is always |
| 425 | * generated (and can't be cleared) when a PCM |
| 426 | * playback is going. So let's ignore at the |
| 427 | * next loop. |
| 428 | */ |
| 429 | status_mask &= ~VT1724_IRQ_MPU_TX; |
| 430 | } |
| 431 | if (status & VT1724_IRQ_MPU_RX) { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 432 | if (ice->midi_input) |
| 433 | vt1724_midi_read(ice); |
| 434 | else |
| 435 | vt1724_midi_clear_rx(ice); |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 436 | } |
| 437 | /* ack MPU irq */ |
| 438 | outb(status, ICEREG1724(ice, IRQSTAT)); |
Takashi Iwai | e683ec4 | 2008-11-12 16:42:44 +0100 | [diff] [blame] | 439 | spin_unlock(&ice->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | if (status & VT1724_IRQ_MTPCM) { |
| 441 | /* |
| 442 | * Multi-track PCM |
| 443 | * PCM assignment are: |
| 444 | * Playback DMA0 (M/C) = playback_pro_substream |
| 445 | * Playback DMA1 = playback_con_substream_ds[0] |
| 446 | * Playback DMA2 = playback_con_substream_ds[1] |
| 447 | * Playback DMA3 = playback_con_substream_ds[2] |
| 448 | * Playback DMA4 (SPDIF) = playback_con_substream |
| 449 | * Record DMA0 = capture_pro_substream |
| 450 | * Record DMA1 = capture_con_substream |
| 451 | */ |
| 452 | unsigned char mtstat = inb(ICEMT1724(ice, IRQ)); |
| 453 | if (mtstat & VT1724_MULTI_PDMA0) { |
| 454 | if (ice->playback_pro_substream) |
| 455 | snd_pcm_period_elapsed(ice->playback_pro_substream); |
| 456 | } |
| 457 | if (mtstat & VT1724_MULTI_RDMA0) { |
| 458 | if (ice->capture_pro_substream) |
| 459 | snd_pcm_period_elapsed(ice->capture_pro_substream); |
| 460 | } |
| 461 | if (mtstat & VT1724_MULTI_PDMA1) { |
| 462 | if (ice->playback_con_substream_ds[0]) |
| 463 | snd_pcm_period_elapsed(ice->playback_con_substream_ds[0]); |
| 464 | } |
| 465 | if (mtstat & VT1724_MULTI_PDMA2) { |
| 466 | if (ice->playback_con_substream_ds[1]) |
| 467 | snd_pcm_period_elapsed(ice->playback_con_substream_ds[1]); |
| 468 | } |
| 469 | if (mtstat & VT1724_MULTI_PDMA3) { |
| 470 | if (ice->playback_con_substream_ds[2]) |
| 471 | snd_pcm_period_elapsed(ice->playback_con_substream_ds[2]); |
| 472 | } |
| 473 | if (mtstat & VT1724_MULTI_PDMA4) { |
| 474 | if (ice->playback_con_substream) |
| 475 | snd_pcm_period_elapsed(ice->playback_con_substream); |
| 476 | } |
| 477 | if (mtstat & VT1724_MULTI_RDMA1) { |
| 478 | if (ice->capture_con_substream) |
| 479 | snd_pcm_period_elapsed(ice->capture_con_substream); |
| 480 | } |
| 481 | /* ack anyway to avoid freeze */ |
| 482 | outb(mtstat, ICEMT1724(ice, IRQ)); |
| 483 | /* ought to really handle this properly */ |
| 484 | if (mtstat & VT1724_MULTI_FIFO_ERR) { |
| 485 | unsigned char fstat = inb(ICEMT1724(ice, DMA_FIFO_ERR)); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 486 | outb(fstat, ICEMT1724(ice, DMA_FIFO_ERR)); |
| 487 | outb(VT1724_MULTI_FIFO_ERR | inb(ICEMT1724(ice, DMA_INT_MASK)), ICEMT1724(ice, DMA_INT_MASK)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | /* If I don't do this, I get machine lockup due to continual interrupts */ |
| 489 | } |
| 490 | |
| 491 | } |
| 492 | } |
| 493 | return IRQ_RETVAL(handled); |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * PCM code - professional part (multitrack) |
| 498 | */ |
| 499 | |
| 500 | static unsigned int rates[] = { |
| 501 | 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
| 502 | 32000, 44100, 48000, 64000, 88200, 96000, |
| 503 | 176400, 192000, |
| 504 | }; |
| 505 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 506 | static struct snd_pcm_hw_constraint_list hw_constraints_rates_96 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | .count = ARRAY_SIZE(rates) - 2, /* up to 96000 */ |
| 508 | .list = rates, |
| 509 | .mask = 0, |
| 510 | }; |
| 511 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 512 | static struct snd_pcm_hw_constraint_list hw_constraints_rates_48 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | .count = ARRAY_SIZE(rates) - 5, /* up to 48000 */ |
| 514 | .list = rates, |
| 515 | .mask = 0, |
| 516 | }; |
| 517 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 518 | static struct snd_pcm_hw_constraint_list hw_constraints_rates_192 = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | .count = ARRAY_SIZE(rates), |
| 520 | .list = rates, |
| 521 | .mask = 0, |
| 522 | }; |
| 523 | |
| 524 | struct vt1724_pcm_reg { |
| 525 | unsigned int addr; /* ADDR register offset */ |
| 526 | unsigned int size; /* SIZE register offset */ |
| 527 | unsigned int count; /* COUNT register offset */ |
| 528 | unsigned int start; /* start & pause bit */ |
| 529 | }; |
| 530 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 531 | static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 533 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | unsigned char what; |
| 535 | unsigned char old; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 536 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | what = 0; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 539 | snd_pcm_group_for_each_entry(s, substream) { |
Clemens Ladisch | 29998d2 | 2007-07-30 08:14:31 +0200 | [diff] [blame] | 540 | if (snd_pcm_substream_chip(s) == ice) { |
| 541 | const struct vt1724_pcm_reg *reg; |
| 542 | reg = s->runtime->private_data; |
| 543 | what |= reg->start; |
| 544 | snd_pcm_trigger_done(s, substream); |
| 545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | switch (cmd) { |
| 549 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 550 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 551 | spin_lock(&ice->reg_lock); |
| 552 | old = inb(ICEMT1724(ice, DMA_PAUSE)); |
| 553 | if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) |
| 554 | old |= what; |
| 555 | else |
| 556 | old &= ~what; |
| 557 | outb(old, ICEMT1724(ice, DMA_PAUSE)); |
| 558 | spin_unlock(&ice->reg_lock); |
| 559 | break; |
| 560 | |
| 561 | case SNDRV_PCM_TRIGGER_START: |
| 562 | case SNDRV_PCM_TRIGGER_STOP: |
| 563 | spin_lock(&ice->reg_lock); |
| 564 | old = inb(ICEMT1724(ice, DMA_CONTROL)); |
| 565 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 566 | old |= what; |
| 567 | else |
| 568 | old &= ~what; |
| 569 | outb(old, ICEMT1724(ice, DMA_CONTROL)); |
| 570 | spin_unlock(&ice->reg_lock); |
| 571 | break; |
| 572 | |
| 573 | default: |
| 574 | return -EINVAL; |
| 575 | } |
| 576 | return 0; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | */ |
| 581 | |
| 582 | #define DMA_STARTS (VT1724_RDMA0_START|VT1724_PDMA0_START|VT1724_RDMA1_START|\ |
| 583 | VT1724_PDMA1_START|VT1724_PDMA2_START|VT1724_PDMA3_START|VT1724_PDMA4_START) |
| 584 | #define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\ |
| 585 | VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE) |
| 586 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 587 | static const unsigned int stdclock_rate_list[16] = { |
| 588 | 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100, |
| 589 | 22050, 11025, 88200, 176400, 0, 192000, 64000 |
| 590 | }; |
| 591 | |
| 592 | static unsigned int stdclock_get_rate(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 594 | unsigned int rate; |
| 595 | rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15]; |
| 596 | return rate; |
| 597 | } |
| 598 | |
| 599 | static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate) |
| 600 | { |
| 601 | int i; |
| 602 | for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) { |
| 603 | if (stdclock_rate_list[i] == rate) { |
| 604 | outb(i, ICEMT1724(ice, RATE)); |
| 605 | return; |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice, |
| 611 | unsigned int rate) |
| 612 | { |
| 613 | unsigned char val, old; |
| 614 | /* check MT02 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 616 | val = old = inb(ICEMT1724(ice, I2S_FORMAT)); |
| 617 | if (rate > 96000) |
| 618 | val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | else |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 620 | val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */ |
| 621 | if (val != old) { |
| 622 | outb(val, ICEMT1724(ice, I2S_FORMAT)); |
| 623 | /* master clock changed */ |
| 624 | return 1; |
| 625 | } |
| 626 | } |
| 627 | /* no change in master clock */ |
| 628 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
| 630 | |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 631 | static int snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 632 | int force) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
| 634 | unsigned long flags; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 635 | unsigned char mclk_change; |
| 636 | unsigned int i, old_rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 638 | if (rate > ice->hw_rates->list[ice->hw_rates->count - 1]) |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 639 | return -EINVAL; |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | spin_lock_irqsave(&ice->reg_lock, flags); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 642 | if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) { |
| 644 | /* running? we cannot change the rate now... */ |
| 645 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 646 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | if (!force && is_pro_rate_locked(ice)) { |
| 649 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 650 | return (rate == ice->cur_rate) ? 0 : -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 653 | old_rate = ice->get_rate(ice); |
| 654 | if (force || (old_rate != rate)) |
| 655 | ice->set_rate(ice, rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | else if (rate == ice->cur_rate) { |
| 657 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 658 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | ice->cur_rate = rate; |
| 662 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 663 | /* setting master clock */ |
| 664 | mclk_change = ice->set_mclk(ice, rate); |
| 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 667 | |
| 668 | if (mclk_change && ice->gpio.i2s_mclk_changed) |
| 669 | ice->gpio.i2s_mclk_changed(ice); |
| 670 | if (ice->gpio.set_pro_rate) |
| 671 | ice->gpio.set_pro_rate(ice, rate); |
| 672 | |
| 673 | /* set up codecs */ |
| 674 | for (i = 0; i < ice->akm_codecs; i++) { |
| 675 | if (ice->akm[i].ops.set_rate_val) |
| 676 | ice->akm[i].ops.set_rate_val(&ice->akm[i], rate); |
| 677 | } |
| 678 | if (ice->spdif.ops.setup_rate) |
| 679 | ice->spdif.ops.setup_rate(ice, rate); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 680 | |
| 681 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 684 | static int snd_vt1724_pcm_hw_params(struct snd_pcm_substream *substream, |
| 685 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 687 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 688 | int i, chs, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | chs = params_channels(hw_params); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 691 | mutex_lock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | /* mark surround channels */ |
| 693 | if (substream == ice->playback_pro_substream) { |
| 694 | /* PDMA0 can be multi-channel up to 8 */ |
| 695 | chs = chs / 2 - 1; |
| 696 | for (i = 0; i < chs; i++) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 697 | if (ice->pcm_reserved[i] && |
| 698 | ice->pcm_reserved[i] != substream) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 699 | mutex_unlock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | return -EBUSY; |
| 701 | } |
| 702 | ice->pcm_reserved[i] = substream; |
| 703 | } |
| 704 | for (; i < 3; i++) { |
| 705 | if (ice->pcm_reserved[i] == substream) |
| 706 | ice->pcm_reserved[i] = NULL; |
| 707 | } |
| 708 | } else { |
| 709 | for (i = 0; i < 3; i++) { |
| 710 | /* check individual playback stream */ |
| 711 | if (ice->playback_con_substream_ds[i] == substream) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 712 | if (ice->pcm_reserved[i] && |
| 713 | ice->pcm_reserved[i] != substream) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 714 | mutex_unlock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | return -EBUSY; |
| 716 | } |
| 717 | ice->pcm_reserved[i] = substream; |
| 718 | break; |
| 719 | } |
| 720 | } |
| 721 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 722 | mutex_unlock(&ice->open_mutex); |
Takashi Iwai | 92d7100 | 2009-05-06 17:18:34 +0200 | [diff] [blame] | 723 | |
| 724 | err = snd_vt1724_set_pro_rate(ice, params_rate(hw_params), 0); |
| 725 | if (err < 0) |
| 726 | return err; |
| 727 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 729 | } |
| 730 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 731 | static int snd_vt1724_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 733 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | int i; |
| 735 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 736 | mutex_lock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | /* unmark surround channels */ |
| 738 | for (i = 0; i < 3; i++) |
| 739 | if (ice->pcm_reserved[i] == substream) |
| 740 | ice->pcm_reserved[i] = NULL; |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 741 | mutex_unlock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | return snd_pcm_lib_free_pages(substream); |
| 743 | } |
| 744 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 745 | static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 747 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | unsigned char val; |
| 749 | unsigned int size; |
| 750 | |
| 751 | spin_lock_irq(&ice->reg_lock); |
| 752 | val = (8 - substream->runtime->channels) >> 1; |
| 753 | outb(val, ICEMT1724(ice, BURST)); |
| 754 | |
| 755 | outl(substream->runtime->dma_addr, ICEMT1724(ice, PLAYBACK_ADDR)); |
| 756 | |
| 757 | size = (snd_pcm_lib_buffer_bytes(substream) >> 2) - 1; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 758 | /* outl(size, ICEMT1724(ice, PLAYBACK_SIZE)); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | outw(size, ICEMT1724(ice, PLAYBACK_SIZE)); |
| 760 | outb(size >> 16, ICEMT1724(ice, PLAYBACK_SIZE) + 2); |
| 761 | size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 762 | /* outl(size, ICEMT1724(ice, PLAYBACK_COUNT)); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | outw(size, ICEMT1724(ice, PLAYBACK_COUNT)); |
| 764 | outb(size >> 16, ICEMT1724(ice, PLAYBACK_COUNT) + 2); |
| 765 | |
| 766 | spin_unlock_irq(&ice->reg_lock); |
| 767 | |
Takashi Iwai | e2ea7cfc | 2009-02-05 16:07:02 +0100 | [diff] [blame] | 768 | /* |
| 769 | printk(KERN_DEBUG "pro prepare: ch = %d, addr = 0x%x, " |
| 770 | "buffer = 0x%x, period = 0x%x\n", |
| 771 | substream->runtime->channels, |
| 772 | (unsigned int)substream->runtime->dma_addr, |
| 773 | snd_pcm_lib_buffer_bytes(substream), |
| 774 | snd_pcm_lib_period_bytes(substream)); |
| 775 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return 0; |
| 777 | } |
| 778 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 779 | static snd_pcm_uframes_t snd_vt1724_playback_pro_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 781 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | size_t ptr; |
| 783 | |
| 784 | if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & VT1724_PDMA0_START)) |
| 785 | return 0; |
| 786 | #if 0 /* read PLAYBACK_ADDR */ |
| 787 | ptr = inl(ICEMT1724(ice, PLAYBACK_ADDR)); |
| 788 | if (ptr < substream->runtime->dma_addr) { |
| 789 | snd_printd("ice1724: invalid negative ptr\n"); |
| 790 | return 0; |
| 791 | } |
| 792 | ptr -= substream->runtime->dma_addr; |
| 793 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 794 | if (ptr >= substream->runtime->buffer_size) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 795 | snd_printd("ice1724: invalid ptr %d (size=%d)\n", |
| 796 | (int)ptr, (int)substream->runtime->period_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | return 0; |
| 798 | } |
| 799 | #else /* read PLAYBACK_SIZE */ |
| 800 | ptr = inl(ICEMT1724(ice, PLAYBACK_SIZE)) & 0xffffff; |
| 801 | ptr = (ptr + 1) << 2; |
| 802 | ptr = bytes_to_frames(substream->runtime, ptr); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 803 | if (!ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | ; |
| 805 | else if (ptr <= substream->runtime->buffer_size) |
| 806 | ptr = substream->runtime->buffer_size - ptr; |
| 807 | else { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 808 | snd_printd("ice1724: invalid ptr %d (size=%d)\n", |
| 809 | (int)ptr, (int)substream->runtime->buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | ptr = 0; |
| 811 | } |
| 812 | #endif |
| 813 | return ptr; |
| 814 | } |
| 815 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 816 | static int snd_vt1724_pcm_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 818 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 819 | const struct vt1724_pcm_reg *reg = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
| 821 | spin_lock_irq(&ice->reg_lock); |
| 822 | outl(substream->runtime->dma_addr, ice->profi_port + reg->addr); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 823 | outw((snd_pcm_lib_buffer_bytes(substream) >> 2) - 1, |
| 824 | ice->profi_port + reg->size); |
| 825 | outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, |
| 826 | ice->profi_port + reg->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | spin_unlock_irq(&ice->reg_lock); |
| 828 | return 0; |
| 829 | } |
| 830 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 831 | static snd_pcm_uframes_t snd_vt1724_pcm_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 833 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 834 | const struct vt1724_pcm_reg *reg = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | size_t ptr; |
| 836 | |
| 837 | if (!(inl(ICEMT1724(ice, DMA_CONTROL)) & reg->start)) |
| 838 | return 0; |
| 839 | #if 0 /* use ADDR register */ |
| 840 | ptr = inl(ice->profi_port + reg->addr); |
| 841 | ptr -= substream->runtime->dma_addr; |
| 842 | return bytes_to_frames(substream->runtime, ptr); |
| 843 | #else /* use SIZE register */ |
| 844 | ptr = inw(ice->profi_port + reg->size); |
| 845 | ptr = (ptr + 1) << 2; |
| 846 | ptr = bytes_to_frames(substream->runtime, ptr); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 847 | if (!ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | ; |
| 849 | else if (ptr <= substream->runtime->buffer_size) |
| 850 | ptr = substream->runtime->buffer_size - ptr; |
| 851 | else { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 852 | snd_printd("ice1724: invalid ptr %d (size=%d)\n", |
| 853 | (int)ptr, (int)substream->runtime->buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | ptr = 0; |
| 855 | } |
| 856 | return ptr; |
| 857 | #endif |
| 858 | } |
| 859 | |
Takashi Iwai | a5b7b5c | 2009-05-06 17:22:07 +0200 | [diff] [blame] | 860 | static const struct vt1724_pcm_reg vt1724_pdma0_reg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | .addr = VT1724_MT_PLAYBACK_ADDR, |
| 862 | .size = VT1724_MT_PLAYBACK_SIZE, |
| 863 | .count = VT1724_MT_PLAYBACK_COUNT, |
| 864 | .start = VT1724_PDMA0_START, |
| 865 | }; |
| 866 | |
Takashi Iwai | a5b7b5c | 2009-05-06 17:22:07 +0200 | [diff] [blame] | 867 | static const struct vt1724_pcm_reg vt1724_pdma4_reg = { |
| 868 | .addr = VT1724_MT_PDMA4_ADDR, |
| 869 | .size = VT1724_MT_PDMA4_SIZE, |
| 870 | .count = VT1724_MT_PDMA4_COUNT, |
| 871 | .start = VT1724_PDMA4_START, |
| 872 | }; |
| 873 | |
| 874 | static const struct vt1724_pcm_reg vt1724_rdma0_reg = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | .addr = VT1724_MT_CAPTURE_ADDR, |
| 876 | .size = VT1724_MT_CAPTURE_SIZE, |
| 877 | .count = VT1724_MT_CAPTURE_COUNT, |
| 878 | .start = VT1724_RDMA0_START, |
| 879 | }; |
| 880 | |
Takashi Iwai | a5b7b5c | 2009-05-06 17:22:07 +0200 | [diff] [blame] | 881 | static const struct vt1724_pcm_reg vt1724_rdma1_reg = { |
| 882 | .addr = VT1724_MT_RDMA1_ADDR, |
| 883 | .size = VT1724_MT_RDMA1_SIZE, |
| 884 | .count = VT1724_MT_RDMA1_COUNT, |
| 885 | .start = VT1724_RDMA1_START, |
| 886 | }; |
| 887 | |
| 888 | #define vt1724_playback_pro_reg vt1724_pdma0_reg |
| 889 | #define vt1724_playback_spdif_reg vt1724_pdma4_reg |
| 890 | #define vt1724_capture_pro_reg vt1724_rdma0_reg |
| 891 | #define vt1724_capture_spdif_reg vt1724_rdma1_reg |
| 892 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 893 | static const struct snd_pcm_hardware snd_vt1724_playback_pro = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 895 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 896 | SNDRV_PCM_INFO_MMAP_VALID | |
| 897 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), |
| 898 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 899 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000, |
| 900 | .rate_min = 8000, |
| 901 | .rate_max = 192000, |
| 902 | .channels_min = 2, |
| 903 | .channels_max = 8, |
| 904 | .buffer_bytes_max = (1UL << 21), /* 19bits dword */ |
| 905 | .period_bytes_min = 8 * 4 * 2, /* FIXME: constraints needed */ |
| 906 | .period_bytes_max = (1UL << 21), |
| 907 | .periods_min = 2, |
| 908 | .periods_max = 1024, |
| 909 | }; |
| 910 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 911 | static const struct snd_pcm_hardware snd_vt1724_spdif = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 913 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 914 | SNDRV_PCM_INFO_MMAP_VALID | |
| 915 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), |
| 916 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
Takashi Iwai | 2dfbeca | 2005-10-12 10:04:42 +0200 | [diff] [blame] | 917 | .rates = (SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100| |
| 918 | SNDRV_PCM_RATE_48000|SNDRV_PCM_RATE_88200| |
| 919 | SNDRV_PCM_RATE_96000|SNDRV_PCM_RATE_176400| |
| 920 | SNDRV_PCM_RATE_192000), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | .rate_min = 32000, |
Takashi Iwai | 2dfbeca | 2005-10-12 10:04:42 +0200 | [diff] [blame] | 922 | .rate_max = 192000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | .channels_min = 2, |
| 924 | .channels_max = 2, |
| 925 | .buffer_bytes_max = (1UL << 18), /* 16bits dword */ |
| 926 | .period_bytes_min = 2 * 4 * 2, |
| 927 | .period_bytes_max = (1UL << 18), |
| 928 | .periods_min = 2, |
| 929 | .periods_max = 1024, |
| 930 | }; |
| 931 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 932 | static const struct snd_pcm_hardware snd_vt1724_2ch_stereo = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 934 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 935 | SNDRV_PCM_INFO_MMAP_VALID | |
| 936 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), |
| 937 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 938 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_192000, |
| 939 | .rate_min = 8000, |
| 940 | .rate_max = 192000, |
| 941 | .channels_min = 2, |
| 942 | .channels_max = 2, |
| 943 | .buffer_bytes_max = (1UL << 18), /* 16bits dword */ |
| 944 | .period_bytes_min = 2 * 4 * 2, |
| 945 | .period_bytes_max = (1UL << 18), |
| 946 | .periods_min = 2, |
| 947 | .periods_max = 1024, |
| 948 | }; |
| 949 | |
| 950 | /* |
| 951 | * set rate constraints |
| 952 | */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 953 | static void set_std_hw_rates(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { |
| 956 | /* I2S */ |
| 957 | /* VT1720 doesn't support more than 96kHz */ |
| 958 | if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 959 | ice->hw_rates = &hw_constraints_rates_192; |
| 960 | else |
| 961 | ice->hw_rates = &hw_constraints_rates_96; |
| 962 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | /* ACLINK */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 964 | ice->hw_rates = &hw_constraints_rates_48; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | } |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static int set_rate_constraints(struct snd_ice1712 *ice, |
| 969 | struct snd_pcm_substream *substream) |
| 970 | { |
| 971 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 972 | |
| 973 | runtime->hw.rate_min = ice->hw_rates->list[0]; |
| 974 | runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1]; |
| 975 | runtime->hw.rates = SNDRV_PCM_RATE_KNOT; |
| 976 | return snd_pcm_hw_constraint_list(runtime, 0, |
| 977 | SNDRV_PCM_HW_PARAM_RATE, |
| 978 | ice->hw_rates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | /* multi-channel playback needs alignment 8x32bit regardless of the channels |
| 982 | * actually used |
| 983 | */ |
| 984 | #define VT1724_BUFFER_ALIGN 0x20 |
| 985 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 986 | static int snd_vt1724_playback_pro_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 988 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 989 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Takashi Iwai | a6b936b | 2008-08-29 16:17:25 +0200 | [diff] [blame] | 990 | int chs, num_indeps; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 992 | runtime->private_data = (void *)&vt1724_playback_pro_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | ice->playback_pro_substream = substream; |
| 994 | runtime->hw = snd_vt1724_playback_pro; |
| 995 | snd_pcm_set_sync(substream); |
| 996 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 997 | set_rate_constraints(ice, substream); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 998 | mutex_lock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | /* calculate the currently available channels */ |
Takashi Iwai | a6b936b | 2008-08-29 16:17:25 +0200 | [diff] [blame] | 1000 | num_indeps = ice->num_total_dacs / 2 - 1; |
| 1001 | for (chs = 0; chs < num_indeps; chs++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | if (ice->pcm_reserved[chs]) |
| 1003 | break; |
| 1004 | } |
| 1005 | chs = (chs + 1) * 2; |
| 1006 | runtime->hw.channels_max = chs; |
| 1007 | if (chs > 2) /* channels must be even */ |
| 1008 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1009 | mutex_unlock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1011 | VT1724_BUFFER_ALIGN); |
| 1012 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1013 | VT1724_BUFFER_ALIGN); |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1017 | static int snd_vt1724_capture_pro_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1019 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1020 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1022 | runtime->private_data = (void *)&vt1724_capture_pro_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | ice->capture_pro_substream = substream; |
| 1024 | runtime->hw = snd_vt1724_2ch_stereo; |
| 1025 | snd_pcm_set_sync(substream); |
| 1026 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1027 | set_rate_constraints(ice, substream); |
| 1028 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1029 | VT1724_BUFFER_ALIGN); |
| 1030 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1031 | VT1724_BUFFER_ALIGN); |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1035 | static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1037 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
| 1039 | if (PRO_RATE_RESET) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1040 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | ice->playback_pro_substream = NULL; |
| 1042 | |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1046 | static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1048 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | |
| 1050 | if (PRO_RATE_RESET) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1051 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | ice->capture_pro_substream = NULL; |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1056 | static struct snd_pcm_ops snd_vt1724_playback_pro_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | .open = snd_vt1724_playback_pro_open, |
| 1058 | .close = snd_vt1724_playback_pro_close, |
| 1059 | .ioctl = snd_pcm_lib_ioctl, |
| 1060 | .hw_params = snd_vt1724_pcm_hw_params, |
| 1061 | .hw_free = snd_vt1724_pcm_hw_free, |
| 1062 | .prepare = snd_vt1724_playback_pro_prepare, |
| 1063 | .trigger = snd_vt1724_pcm_trigger, |
| 1064 | .pointer = snd_vt1724_playback_pro_pointer, |
| 1065 | }; |
| 1066 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1067 | static struct snd_pcm_ops snd_vt1724_capture_pro_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | .open = snd_vt1724_capture_pro_open, |
| 1069 | .close = snd_vt1724_capture_pro_close, |
| 1070 | .ioctl = snd_pcm_lib_ioctl, |
| 1071 | .hw_params = snd_vt1724_pcm_hw_params, |
| 1072 | .hw_free = snd_vt1724_pcm_hw_free, |
| 1073 | .prepare = snd_vt1724_pcm_prepare, |
| 1074 | .trigger = snd_vt1724_pcm_trigger, |
| 1075 | .pointer = snd_vt1724_pcm_pointer, |
| 1076 | }; |
| 1077 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1078 | static int __devinit snd_vt1724_pcm_profi(struct snd_ice1712 *ice, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1080 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | int err; |
| 1082 | |
| 1083 | err = snd_pcm_new(ice->card, "ICE1724", device, 1, 1, &pcm); |
| 1084 | if (err < 0) |
| 1085 | return err; |
| 1086 | |
| 1087 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_vt1724_playback_pro_ops); |
| 1088 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_vt1724_capture_pro_ops); |
| 1089 | |
| 1090 | pcm->private_data = ice; |
| 1091 | pcm->info_flags = 0; |
| 1092 | strcpy(pcm->name, "ICE1724"); |
| 1093 | |
| 1094 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1095 | snd_dma_pci_data(ice->pci), |
| 1096 | 256*1024, 256*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
| 1098 | ice->pcm_pro = pcm; |
| 1099 | |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | /* |
| 1105 | * SPDIF PCM |
| 1106 | */ |
| 1107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | /* update spdif control bits; call with reg_lock */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1109 | static void update_spdif_bits(struct snd_ice1712 *ice, unsigned int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
| 1111 | unsigned char cbit, disabled; |
| 1112 | |
| 1113 | cbit = inb(ICEREG1724(ice, SPDIF_CFG)); |
| 1114 | disabled = cbit & ~VT1724_CFG_SPDIF_OUT_EN; |
| 1115 | if (cbit != disabled) |
| 1116 | outb(disabled, ICEREG1724(ice, SPDIF_CFG)); |
| 1117 | outw(val, ICEMT1724(ice, SPDIF_CTRL)); |
| 1118 | if (cbit != disabled) |
| 1119 | outb(cbit, ICEREG1724(ice, SPDIF_CFG)); |
| 1120 | outw(val, ICEMT1724(ice, SPDIF_CTRL)); |
| 1121 | } |
| 1122 | |
| 1123 | /* update SPDIF control bits according to the given rate */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1124 | static void update_spdif_rate(struct snd_ice1712 *ice, unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | { |
| 1126 | unsigned int val, nval; |
| 1127 | unsigned long flags; |
| 1128 | |
| 1129 | spin_lock_irqsave(&ice->reg_lock, flags); |
| 1130 | nval = val = inw(ICEMT1724(ice, SPDIF_CTRL)); |
| 1131 | nval &= ~(7 << 12); |
| 1132 | switch (rate) { |
| 1133 | case 44100: break; |
| 1134 | case 48000: nval |= 2 << 12; break; |
| 1135 | case 32000: nval |= 3 << 12; break; |
Takashi Iwai | 2dfbeca | 2005-10-12 10:04:42 +0200 | [diff] [blame] | 1136 | case 88200: nval |= 4 << 12; break; |
| 1137 | case 96000: nval |= 5 << 12; break; |
| 1138 | case 192000: nval |= 6 << 12; break; |
| 1139 | case 176400: nval |= 7 << 12; break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | if (val != nval) |
| 1142 | update_spdif_bits(ice, nval); |
| 1143 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 1144 | } |
| 1145 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1146 | static int snd_vt1724_playback_spdif_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1148 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1149 | if (!ice->force_pdma4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | update_spdif_rate(ice, substream->runtime->rate); |
| 1151 | return snd_vt1724_pcm_prepare(substream); |
| 1152 | } |
| 1153 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1154 | static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1156 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1157 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1159 | runtime->private_data = (void *)&vt1724_playback_spdif_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | ice->playback_con_substream = substream; |
| 1161 | if (ice->force_pdma4) { |
| 1162 | runtime->hw = snd_vt1724_2ch_stereo; |
| 1163 | set_rate_constraints(ice, substream); |
| 1164 | } else |
| 1165 | runtime->hw = snd_vt1724_spdif; |
| 1166 | snd_pcm_set_sync(substream); |
| 1167 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1168 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1169 | VT1724_BUFFER_ALIGN); |
| 1170 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1171 | VT1724_BUFFER_ALIGN); |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 1172 | if (ice->spdif.ops.open) |
| 1173 | ice->spdif.ops.open(ice, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | return 0; |
| 1175 | } |
| 1176 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1177 | static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1179 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | |
| 1181 | if (PRO_RATE_RESET) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1182 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | ice->playback_con_substream = NULL; |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 1184 | if (ice->spdif.ops.close) |
| 1185 | ice->spdif.ops.close(ice, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1190 | static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1192 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1193 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1195 | runtime->private_data = (void *)&vt1724_capture_spdif_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | ice->capture_con_substream = substream; |
| 1197 | if (ice->force_rdma1) { |
| 1198 | runtime->hw = snd_vt1724_2ch_stereo; |
| 1199 | set_rate_constraints(ice, substream); |
| 1200 | } else |
| 1201 | runtime->hw = snd_vt1724_spdif; |
| 1202 | snd_pcm_set_sync(substream); |
| 1203 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1204 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 1205 | VT1724_BUFFER_ALIGN); |
| 1206 | snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
| 1207 | VT1724_BUFFER_ALIGN); |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 1208 | if (ice->spdif.ops.open) |
| 1209 | ice->spdif.ops.open(ice, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1213 | static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1215 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
| 1217 | if (PRO_RATE_RESET) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1218 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | ice->capture_con_substream = NULL; |
Takashi Iwai | c93f5a1 | 2008-03-14 17:17:09 +0100 | [diff] [blame] | 1220 | if (ice->spdif.ops.close) |
| 1221 | ice->spdif.ops.close(ice, substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1226 | static struct snd_pcm_ops snd_vt1724_playback_spdif_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | .open = snd_vt1724_playback_spdif_open, |
| 1228 | .close = snd_vt1724_playback_spdif_close, |
| 1229 | .ioctl = snd_pcm_lib_ioctl, |
| 1230 | .hw_params = snd_vt1724_pcm_hw_params, |
| 1231 | .hw_free = snd_vt1724_pcm_hw_free, |
| 1232 | .prepare = snd_vt1724_playback_spdif_prepare, |
| 1233 | .trigger = snd_vt1724_pcm_trigger, |
| 1234 | .pointer = snd_vt1724_pcm_pointer, |
| 1235 | }; |
| 1236 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1237 | static struct snd_pcm_ops snd_vt1724_capture_spdif_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | .open = snd_vt1724_capture_spdif_open, |
| 1239 | .close = snd_vt1724_capture_spdif_close, |
| 1240 | .ioctl = snd_pcm_lib_ioctl, |
| 1241 | .hw_params = snd_vt1724_pcm_hw_params, |
| 1242 | .hw_free = snd_vt1724_pcm_hw_free, |
| 1243 | .prepare = snd_vt1724_pcm_prepare, |
| 1244 | .trigger = snd_vt1724_pcm_trigger, |
| 1245 | .pointer = snd_vt1724_pcm_pointer, |
| 1246 | }; |
| 1247 | |
| 1248 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1249 | static int __devinit snd_vt1724_pcm_spdif(struct snd_ice1712 *ice, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | { |
| 1251 | char *name; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1252 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | int play, capt; |
| 1254 | int err; |
| 1255 | |
| 1256 | if (ice->force_pdma4 || |
| 1257 | (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_OUT_INT)) { |
| 1258 | play = 1; |
| 1259 | ice->has_spdif = 1; |
| 1260 | } else |
| 1261 | play = 0; |
| 1262 | if (ice->force_rdma1 || |
| 1263 | (ice->eeprom.data[ICE_EEP2_SPDIF] & VT1724_CFG_SPDIF_IN)) { |
| 1264 | capt = 1; |
| 1265 | ice->has_spdif = 1; |
| 1266 | } else |
| 1267 | capt = 0; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1268 | if (!play && !capt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | return 0; /* no spdif device */ |
| 1270 | |
| 1271 | if (ice->force_pdma4 || ice->force_rdma1) |
| 1272 | name = "ICE1724 Secondary"; |
| 1273 | else |
Alan Horstmann | 8eca753 | 2009-01-05 18:30:04 +0100 | [diff] [blame] | 1274 | name = "ICE1724 IEC958"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | err = snd_pcm_new(ice->card, name, device, play, capt, &pcm); |
| 1276 | if (err < 0) |
| 1277 | return err; |
| 1278 | |
| 1279 | if (play) |
| 1280 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1281 | &snd_vt1724_playback_spdif_ops); |
| 1282 | if (capt) |
| 1283 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1284 | &snd_vt1724_capture_spdif_ops); |
| 1285 | |
| 1286 | pcm->private_data = ice; |
| 1287 | pcm->info_flags = 0; |
| 1288 | strcpy(pcm->name, name); |
| 1289 | |
| 1290 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1291 | snd_dma_pci_data(ice->pci), |
| 1292 | 64*1024, 64*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | ice->pcm = pcm; |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | |
| 1300 | /* |
| 1301 | * independent surround PCMs |
| 1302 | */ |
| 1303 | |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1304 | static const struct vt1724_pcm_reg vt1724_playback_dma_regs[3] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | { |
| 1306 | .addr = VT1724_MT_PDMA1_ADDR, |
| 1307 | .size = VT1724_MT_PDMA1_SIZE, |
| 1308 | .count = VT1724_MT_PDMA1_COUNT, |
| 1309 | .start = VT1724_PDMA1_START, |
| 1310 | }, |
| 1311 | { |
| 1312 | .addr = VT1724_MT_PDMA2_ADDR, |
| 1313 | .size = VT1724_MT_PDMA2_SIZE, |
| 1314 | .count = VT1724_MT_PDMA2_COUNT, |
| 1315 | .start = VT1724_PDMA2_START, |
| 1316 | }, |
| 1317 | { |
| 1318 | .addr = VT1724_MT_PDMA3_ADDR, |
| 1319 | .size = VT1724_MT_PDMA3_SIZE, |
| 1320 | .count = VT1724_MT_PDMA3_COUNT, |
| 1321 | .start = VT1724_PDMA3_START, |
| 1322 | }, |
| 1323 | }; |
| 1324 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1325 | static int snd_vt1724_playback_indep_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1327 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | unsigned char val; |
| 1329 | |
| 1330 | spin_lock_irq(&ice->reg_lock); |
| 1331 | val = 3 - substream->number; |
| 1332 | if (inb(ICEMT1724(ice, BURST)) < val) |
| 1333 | outb(val, ICEMT1724(ice, BURST)); |
| 1334 | spin_unlock_irq(&ice->reg_lock); |
| 1335 | return snd_vt1724_pcm_prepare(substream); |
| 1336 | } |
| 1337 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1338 | static int snd_vt1724_playback_indep_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1340 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1341 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1343 | mutex_lock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | /* already used by PDMA0? */ |
| 1345 | if (ice->pcm_reserved[substream->number]) { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1346 | mutex_unlock(&ice->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | return -EBUSY; /* FIXME: should handle blocking mode properly */ |
| 1348 | } |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 1349 | mutex_unlock(&ice->open_mutex); |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1350 | runtime->private_data = (void *)&vt1724_playback_dma_regs[substream->number]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | ice->playback_con_substream_ds[substream->number] = substream; |
| 1352 | runtime->hw = snd_vt1724_2ch_stereo; |
| 1353 | snd_pcm_set_sync(substream); |
| 1354 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1355 | set_rate_constraints(ice, substream); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1359 | static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1361 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
| 1363 | if (PRO_RATE_RESET) |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1364 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | ice->playback_con_substream_ds[substream->number] = NULL; |
| 1366 | ice->pcm_reserved[substream->number] = NULL; |
| 1367 | |
| 1368 | return 0; |
| 1369 | } |
| 1370 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1371 | static struct snd_pcm_ops snd_vt1724_playback_indep_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | .open = snd_vt1724_playback_indep_open, |
| 1373 | .close = snd_vt1724_playback_indep_close, |
| 1374 | .ioctl = snd_pcm_lib_ioctl, |
| 1375 | .hw_params = snd_vt1724_pcm_hw_params, |
| 1376 | .hw_free = snd_vt1724_pcm_hw_free, |
| 1377 | .prepare = snd_vt1724_playback_indep_prepare, |
| 1378 | .trigger = snd_vt1724_pcm_trigger, |
| 1379 | .pointer = snd_vt1724_pcm_pointer, |
| 1380 | }; |
| 1381 | |
| 1382 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1383 | static int __devinit snd_vt1724_pcm_indep(struct snd_ice1712 *ice, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1385 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | int play; |
| 1387 | int err; |
| 1388 | |
| 1389 | play = ice->num_total_dacs / 2 - 1; |
| 1390 | if (play <= 0) |
| 1391 | return 0; |
| 1392 | |
| 1393 | err = snd_pcm_new(ice->card, "ICE1724 Surrounds", device, play, 0, &pcm); |
| 1394 | if (err < 0) |
| 1395 | return err; |
| 1396 | |
| 1397 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1398 | &snd_vt1724_playback_indep_ops); |
| 1399 | |
| 1400 | pcm->private_data = ice; |
| 1401 | pcm->info_flags = 0; |
| 1402 | strcpy(pcm->name, "ICE1724 Surround PCM"); |
| 1403 | |
| 1404 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1405 | snd_dma_pci_data(ice->pci), |
| 1406 | 64*1024, 64*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | ice->pcm_ds = pcm; |
| 1409 | |
| 1410 | return 0; |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | /* |
| 1415 | * Mixer section |
| 1416 | */ |
| 1417 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1418 | static int __devinit snd_vt1724_ac97_mixer(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
| 1420 | int err; |
| 1421 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1422 | if (!(ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S)) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1423 | struct snd_ac97_bus *pbus; |
| 1424 | struct snd_ac97_template ac97; |
| 1425 | static struct snd_ac97_bus_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | .write = snd_vt1724_ac97_write, |
| 1427 | .read = snd_vt1724_ac97_read, |
| 1428 | }; |
| 1429 | |
| 1430 | /* cold reset */ |
| 1431 | outb(inb(ICEMT1724(ice, AC97_CMD)) | 0x80, ICEMT1724(ice, AC97_CMD)); |
| 1432 | mdelay(5); /* FIXME */ |
| 1433 | outb(inb(ICEMT1724(ice, AC97_CMD)) & ~0x80, ICEMT1724(ice, AC97_CMD)); |
| 1434 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1435 | err = snd_ac97_bus(ice->card, 0, &ops, NULL, &pbus); |
| 1436 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | return err; |
| 1438 | memset(&ac97, 0, sizeof(ac97)); |
| 1439 | ac97.private_data = ice; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1440 | err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); |
| 1441 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); |
| 1443 | else |
| 1444 | return 0; |
| 1445 | } |
| 1446 | /* I2S mixer only */ |
| 1447 | strcat(ice->card->mixername, "ICE1724 - multitrack"); |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | /* |
| 1452 | * |
| 1453 | */ |
| 1454 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1455 | static inline unsigned int eeprom_triple(struct snd_ice1712 *ice, int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | return (unsigned int)ice->eeprom.data[idx] | \ |
| 1458 | ((unsigned int)ice->eeprom.data[idx + 1] << 8) | \ |
| 1459 | ((unsigned int)ice->eeprom.data[idx + 2] << 16); |
| 1460 | } |
| 1461 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1462 | static void snd_vt1724_proc_read(struct snd_info_entry *entry, |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1463 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1465 | struct snd_ice1712 *ice = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | unsigned int idx; |
| 1467 | |
| 1468 | snd_iprintf(buffer, "%s\n\n", ice->card->longname); |
| 1469 | snd_iprintf(buffer, "EEPROM:\n"); |
| 1470 | |
| 1471 | snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor); |
| 1472 | snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size); |
| 1473 | snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1474 | snd_iprintf(buffer, " System Config : 0x%x\n", |
| 1475 | ice->eeprom.data[ICE_EEP2_SYSCONF]); |
| 1476 | snd_iprintf(buffer, " ACLink : 0x%x\n", |
| 1477 | ice->eeprom.data[ICE_EEP2_ACLINK]); |
| 1478 | snd_iprintf(buffer, " I2S : 0x%x\n", |
| 1479 | ice->eeprom.data[ICE_EEP2_I2S]); |
| 1480 | snd_iprintf(buffer, " S/PDIF : 0x%x\n", |
| 1481 | ice->eeprom.data[ICE_EEP2_SPDIF]); |
| 1482 | snd_iprintf(buffer, " GPIO direction : 0x%x\n", |
| 1483 | ice->eeprom.gpiodir); |
| 1484 | snd_iprintf(buffer, " GPIO mask : 0x%x\n", |
| 1485 | ice->eeprom.gpiomask); |
| 1486 | snd_iprintf(buffer, " GPIO state : 0x%x\n", |
| 1487 | ice->eeprom.gpiostate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | for (idx = 0x12; idx < ice->eeprom.size; idx++) |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1489 | snd_iprintf(buffer, " Extra #%02i : 0x%x\n", |
| 1490 | idx, ice->eeprom.data[idx]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
| 1492 | snd_iprintf(buffer, "\nRegisters:\n"); |
| 1493 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1494 | snd_iprintf(buffer, " PSDOUT03 : 0x%08x\n", |
| 1495 | (unsigned)inl(ICEMT1724(ice, ROUTE_PLAYBACK))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | for (idx = 0x0; idx < 0x20 ; idx++) |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1497 | snd_iprintf(buffer, " CCS%02x : 0x%02x\n", |
| 1498 | idx, inb(ice->port+idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | for (idx = 0x0; idx < 0x30 ; idx++) |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1500 | snd_iprintf(buffer, " MT%02x : 0x%02x\n", |
| 1501 | idx, inb(ice->profi_port+idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | } |
| 1503 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1504 | static void __devinit snd_vt1724_proc_init(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1506 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1508 | if (!snd_card_proc_new(ice->card, "ice1724", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1509 | snd_info_set_text_ops(entry, ice, snd_vt1724_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | /* |
| 1513 | * |
| 1514 | */ |
| 1515 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1516 | static int snd_vt1724_eeprom_info(struct snd_kcontrol *kcontrol, |
| 1517 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | { |
| 1519 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1520 | uinfo->count = sizeof(struct snd_ice1712_eeprom); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | return 0; |
| 1522 | } |
| 1523 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1524 | static int snd_vt1724_eeprom_get(struct snd_kcontrol *kcontrol, |
| 1525 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1527 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom)); |
| 1530 | return 0; |
| 1531 | } |
| 1532 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1533 | static struct snd_kcontrol_new snd_vt1724_eeprom __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 1535 | .name = "ICE1724 EEPROM", |
| 1536 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1537 | .info = snd_vt1724_eeprom_info, |
| 1538 | .get = snd_vt1724_eeprom_get |
| 1539 | }; |
| 1540 | |
| 1541 | /* |
| 1542 | */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1543 | static int snd_vt1724_spdif_info(struct snd_kcontrol *kcontrol, |
| 1544 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | { |
| 1546 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1547 | uinfo->count = 1; |
| 1548 | return 0; |
| 1549 | } |
| 1550 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1551 | static unsigned int encode_spdif_bits(struct snd_aes_iec958 *diga) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | { |
Takashi Iwai | 2dfbeca | 2005-10-12 10:04:42 +0200 | [diff] [blame] | 1553 | unsigned int val, rbits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
| 1555 | val = diga->status[0] & 0x03; /* professional, non-audio */ |
| 1556 | if (val & 0x01) { |
| 1557 | /* professional */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1558 | if ((diga->status[0] & IEC958_AES0_PRO_EMPHASIS) == |
| 1559 | IEC958_AES0_PRO_EMPHASIS_5015) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | val |= 1U << 3; |
Takashi Iwai | 2dfbeca | 2005-10-12 10:04:42 +0200 | [diff] [blame] | 1561 | rbits = (diga->status[4] >> 3) & 0x0f; |
| 1562 | if (rbits) { |
| 1563 | switch (rbits) { |
| 1564 | case 2: val |= 5 << 12; break; /* 96k */ |
| 1565 | case 3: val |= 6 << 12; break; /* 192k */ |
| 1566 | case 10: val |= 4 << 12; break; /* 88.2k */ |
| 1567 | case 11: val |= 7 << 12; break; /* 176.4k */ |
| 1568 | } |
| 1569 | } else { |
| 1570 | switch (diga->status[0] & IEC958_AES0_PRO_FS) { |
| 1571 | case IEC958_AES0_PRO_FS_44100: |
| 1572 | break; |
| 1573 | case IEC958_AES0_PRO_FS_32000: |
| 1574 | val |= 3U << 12; |
| 1575 | break; |
| 1576 | default: |
| 1577 | val |= 2U << 12; |
| 1578 | break; |
| 1579 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | } |
| 1581 | } else { |
| 1582 | /* consumer */ |
| 1583 | val |= diga->status[1] & 0x04; /* copyright */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1584 | if ((diga->status[0] & IEC958_AES0_CON_EMPHASIS) == |
| 1585 | IEC958_AES0_CON_EMPHASIS_5015) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | val |= 1U << 3; |
| 1587 | val |= (unsigned int)(diga->status[1] & 0x3f) << 4; /* category */ |
| 1588 | val |= (unsigned int)(diga->status[3] & IEC958_AES3_CON_FS) << 12; /* fs */ |
| 1589 | } |
| 1590 | return val; |
| 1591 | } |
| 1592 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1593 | static void decode_spdif_bits(struct snd_aes_iec958 *diga, unsigned int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | { |
| 1595 | memset(diga->status, 0, sizeof(diga->status)); |
| 1596 | diga->status[0] = val & 0x03; /* professional, non-audio */ |
| 1597 | if (val & 0x01) { |
| 1598 | /* professional */ |
| 1599 | if (val & (1U << 3)) |
| 1600 | diga->status[0] |= IEC958_AES0_PRO_EMPHASIS_5015; |
| 1601 | switch ((val >> 12) & 0x7) { |
| 1602 | case 0: |
| 1603 | break; |
| 1604 | case 2: |
| 1605 | diga->status[0] |= IEC958_AES0_PRO_FS_32000; |
| 1606 | break; |
| 1607 | default: |
| 1608 | diga->status[0] |= IEC958_AES0_PRO_FS_48000; |
| 1609 | break; |
| 1610 | } |
| 1611 | } else { |
| 1612 | /* consumer */ |
| 1613 | diga->status[0] |= val & (1U << 2); /* copyright */ |
| 1614 | if (val & (1U << 3)) |
| 1615 | diga->status[0] |= IEC958_AES0_CON_EMPHASIS_5015; |
| 1616 | diga->status[1] |= (val >> 4) & 0x3f; /* category */ |
| 1617 | diga->status[3] |= (val >> 12) & 0x07; /* fs */ |
| 1618 | } |
| 1619 | } |
| 1620 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1621 | static int snd_vt1724_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 1622 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1624 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | unsigned int val; |
| 1626 | val = inw(ICEMT1724(ice, SPDIF_CTRL)); |
| 1627 | decode_spdif_bits(&ucontrol->value.iec958, val); |
| 1628 | return 0; |
| 1629 | } |
| 1630 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1631 | static int snd_vt1724_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 1632 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1634 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | unsigned int val, old; |
| 1636 | |
| 1637 | val = encode_spdif_bits(&ucontrol->value.iec958); |
| 1638 | spin_lock_irq(&ice->reg_lock); |
| 1639 | old = inw(ICEMT1724(ice, SPDIF_CTRL)); |
| 1640 | if (val != old) |
| 1641 | update_spdif_bits(ice, val); |
| 1642 | spin_unlock_irq(&ice->reg_lock); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1643 | return val != old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | } |
| 1645 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1646 | static struct snd_kcontrol_new snd_vt1724_spdif_default __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | { |
| 1648 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1649 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | .info = snd_vt1724_spdif_info, |
| 1651 | .get = snd_vt1724_spdif_default_get, |
| 1652 | .put = snd_vt1724_spdif_default_put |
| 1653 | }; |
| 1654 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1655 | static int snd_vt1724_spdif_maskc_get(struct snd_kcontrol *kcontrol, |
| 1656 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | { |
| 1658 | ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 1659 | IEC958_AES0_PROFESSIONAL | |
| 1660 | IEC958_AES0_CON_NOT_COPYRIGHT | |
| 1661 | IEC958_AES0_CON_EMPHASIS; |
| 1662 | ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL | |
| 1663 | IEC958_AES1_CON_CATEGORY; |
| 1664 | ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS; |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1668 | static int snd_vt1724_spdif_maskp_get(struct snd_kcontrol *kcontrol, |
| 1669 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | { |
| 1671 | ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 1672 | IEC958_AES0_PROFESSIONAL | |
| 1673 | IEC958_AES0_PRO_FS | |
| 1674 | IEC958_AES0_PRO_EMPHASIS; |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1678 | static struct snd_kcontrol_new snd_vt1724_spdif_maskc __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | { |
| 1680 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 1681 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1682 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | .info = snd_vt1724_spdif_info, |
| 1684 | .get = snd_vt1724_spdif_maskc_get, |
| 1685 | }; |
| 1686 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1687 | static struct snd_kcontrol_new snd_vt1724_spdif_maskp __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | { |
| 1689 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 1690 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1691 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | .info = snd_vt1724_spdif_info, |
| 1693 | .get = snd_vt1724_spdif_maskp_get, |
| 1694 | }; |
| 1695 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1696 | #define snd_vt1724_spdif_sw_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1698 | static int snd_vt1724_spdif_sw_get(struct snd_kcontrol *kcontrol, |
| 1699 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1701 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1702 | ucontrol->value.integer.value[0] = inb(ICEREG1724(ice, SPDIF_CFG)) & |
| 1703 | VT1724_CFG_SPDIF_OUT_EN ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | return 0; |
| 1705 | } |
| 1706 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1707 | static int snd_vt1724_spdif_sw_put(struct snd_kcontrol *kcontrol, |
| 1708 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1710 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | unsigned char old, val; |
| 1712 | |
| 1713 | spin_lock_irq(&ice->reg_lock); |
| 1714 | old = val = inb(ICEREG1724(ice, SPDIF_CFG)); |
| 1715 | val &= ~VT1724_CFG_SPDIF_OUT_EN; |
| 1716 | if (ucontrol->value.integer.value[0]) |
| 1717 | val |= VT1724_CFG_SPDIF_OUT_EN; |
| 1718 | if (old != val) |
| 1719 | outb(val, ICEREG1724(ice, SPDIF_CFG)); |
| 1720 | spin_unlock_irq(&ice->reg_lock); |
| 1721 | return old != val; |
| 1722 | } |
| 1723 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1724 | static struct snd_kcontrol_new snd_vt1724_spdif_switch __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
| 1726 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1727 | /* FIXME: the following conflict with IEC958 Playback Route */ |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1728 | /* .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), */ |
| 1729 | .name = SNDRV_CTL_NAME_IEC958("Output ", NONE, SWITCH), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | .info = snd_vt1724_spdif_sw_info, |
| 1731 | .get = snd_vt1724_spdif_sw_get, |
| 1732 | .put = snd_vt1724_spdif_sw_put |
| 1733 | }; |
| 1734 | |
| 1735 | |
| 1736 | #if 0 /* NOT USED YET */ |
| 1737 | /* |
| 1738 | * GPIO access from extern |
| 1739 | */ |
| 1740 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1741 | #define snd_vt1724_gpio_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1743 | int snd_vt1724_gpio_get(struct snd_kcontrol *kcontrol, |
| 1744 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1746 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1747 | int shift = kcontrol->private_value & 0xff; |
| 1748 | int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | snd_ice1712_save_gpio_status(ice); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1751 | ucontrol->value.integer.value[0] = |
| 1752 | (snd_ice1712_gpio_read(ice) & (1 << shift) ? 1 : 0) ^ invert; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | snd_ice1712_restore_gpio_status(ice); |
| 1754 | return 0; |
| 1755 | } |
| 1756 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1757 | int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, |
| 1758 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1760 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | int shift = kcontrol->private_value & 0xff; |
| 1762 | int invert = (kcontrol->private_value & (1<<24)) ? mask : 0; |
| 1763 | unsigned int val, nval; |
| 1764 | |
| 1765 | if (kcontrol->private_value & (1 << 31)) |
| 1766 | return -EPERM; |
| 1767 | nval = (ucontrol->value.integer.value[0] ? (1 << shift) : 0) ^ invert; |
| 1768 | snd_ice1712_save_gpio_status(ice); |
| 1769 | val = snd_ice1712_gpio_read(ice); |
| 1770 | nval |= val & ~(1 << shift); |
| 1771 | if (val != nval) |
| 1772 | snd_ice1712_gpio_write(ice, nval); |
| 1773 | snd_ice1712_restore_gpio_status(ice); |
| 1774 | return val != nval; |
| 1775 | } |
| 1776 | #endif /* NOT USED YET */ |
| 1777 | |
| 1778 | /* |
| 1779 | * rate |
| 1780 | */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1781 | static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol, |
| 1782 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1784 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
| 1786 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1787 | uinfo->count = 1; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1788 | uinfo->value.enumerated.items = ice->hw_rates->count + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 1790 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1791 | if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1) |
| 1792 | strcpy(uinfo->value.enumerated.name, "IEC958 Input"); |
| 1793 | else |
| 1794 | sprintf(uinfo->value.enumerated.name, "%d", |
| 1795 | ice->hw_rates->list[uinfo->value.enumerated.item]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | return 0; |
| 1797 | } |
| 1798 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1799 | static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol, |
| 1800 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1802 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1803 | unsigned int i, rate; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | spin_lock_irq(&ice->reg_lock); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1806 | if (ice->is_spdif_master(ice)) { |
| 1807 | ucontrol->value.enumerated.item[0] = ice->hw_rates->count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | } else { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1809 | rate = ice->get_rate(ice); |
| 1810 | ucontrol->value.enumerated.item[0] = 0; |
| 1811 | for (i = 0; i < ice->hw_rates->count; i++) { |
| 1812 | if (ice->hw_rates->list[i] == rate) { |
| 1813 | ucontrol->value.enumerated.item[0] = i; |
| 1814 | break; |
| 1815 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | } |
| 1818 | spin_unlock_irq(&ice->reg_lock); |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1822 | /* setting clock to external - SPDIF */ |
| 1823 | static void stdclock_set_spdif_clock(struct snd_ice1712 *ice) |
| 1824 | { |
| 1825 | unsigned char oval; |
| 1826 | unsigned char i2s_oval; |
| 1827 | oval = inb(ICEMT1724(ice, RATE)); |
| 1828 | outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE)); |
| 1829 | /* setting 256fs */ |
| 1830 | i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); |
| 1831 | outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT)); |
| 1832 | } |
| 1833 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1834 | static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, |
| 1835 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1837 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1838 | unsigned int old_rate, new_rate; |
| 1839 | unsigned int item = ucontrol->value.enumerated.item[0]; |
| 1840 | unsigned int spdif = ice->hw_rates->count; |
| 1841 | |
| 1842 | if (item > spdif) |
| 1843 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
| 1845 | spin_lock_irq(&ice->reg_lock); |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1846 | if (ice->is_spdif_master(ice)) |
| 1847 | old_rate = 0; |
| 1848 | else |
| 1849 | old_rate = ice->get_rate(ice); |
| 1850 | if (item == spdif) { |
| 1851 | /* switching to external clock via SPDIF */ |
| 1852 | ice->set_spdif_clock(ice); |
| 1853 | new_rate = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | } else { |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1855 | /* internal on-card clock */ |
| 1856 | new_rate = ice->hw_rates->list[item]; |
| 1857 | ice->pro_rate_default = new_rate; |
| 1858 | spin_unlock_irq(&ice->reg_lock); |
| 1859 | snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1); |
| 1860 | spin_lock_irq(&ice->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | spin_unlock_irq(&ice->reg_lock); |
| 1863 | |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1864 | /* the first reset to the SPDIF master mode? */ |
| 1865 | if (old_rate != new_rate && !new_rate) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | /* notify akm chips as well */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1867 | unsigned int i; |
| 1868 | if (ice->gpio.set_pro_rate) |
| 1869 | ice->gpio.set_pro_rate(ice, 0); |
| 1870 | for (i = 0; i < ice->akm_codecs; i++) { |
| 1871 | if (ice->akm[i].ops.set_rate_val) |
| 1872 | ice->akm[i].ops.set_rate_val(&ice->akm[i], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1873 | } |
| 1874 | } |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 1875 | return old_rate != new_rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1878 | static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1880 | .name = "Multi Track Internal Clock", |
| 1881 | .info = snd_vt1724_pro_internal_clock_info, |
| 1882 | .get = snd_vt1724_pro_internal_clock_get, |
| 1883 | .put = snd_vt1724_pro_internal_clock_put |
| 1884 | }; |
| 1885 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1886 | #define snd_vt1724_pro_rate_locking_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1888 | static int snd_vt1724_pro_rate_locking_get(struct snd_kcontrol *kcontrol, |
| 1889 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | { |
| 1891 | ucontrol->value.integer.value[0] = PRO_RATE_LOCKED; |
| 1892 | return 0; |
| 1893 | } |
| 1894 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1895 | static int snd_vt1724_pro_rate_locking_put(struct snd_kcontrol *kcontrol, |
| 1896 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1898 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | int change = 0, nval; |
| 1900 | |
| 1901 | nval = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1902 | spin_lock_irq(&ice->reg_lock); |
| 1903 | change = PRO_RATE_LOCKED != nval; |
| 1904 | PRO_RATE_LOCKED = nval; |
| 1905 | spin_unlock_irq(&ice->reg_lock); |
| 1906 | return change; |
| 1907 | } |
| 1908 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1909 | static struct snd_kcontrol_new snd_vt1724_pro_rate_locking __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1911 | .name = "Multi Track Rate Locking", |
| 1912 | .info = snd_vt1724_pro_rate_locking_info, |
| 1913 | .get = snd_vt1724_pro_rate_locking_get, |
| 1914 | .put = snd_vt1724_pro_rate_locking_put |
| 1915 | }; |
| 1916 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1917 | #define snd_vt1724_pro_rate_reset_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1919 | static int snd_vt1724_pro_rate_reset_get(struct snd_kcontrol *kcontrol, |
| 1920 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | { |
| 1922 | ucontrol->value.integer.value[0] = PRO_RATE_RESET ? 1 : 0; |
| 1923 | return 0; |
| 1924 | } |
| 1925 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1926 | static int snd_vt1724_pro_rate_reset_put(struct snd_kcontrol *kcontrol, |
| 1927 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1929 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | int change = 0, nval; |
| 1931 | |
| 1932 | nval = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1933 | spin_lock_irq(&ice->reg_lock); |
| 1934 | change = PRO_RATE_RESET != nval; |
| 1935 | PRO_RATE_RESET = nval; |
| 1936 | spin_unlock_irq(&ice->reg_lock); |
| 1937 | return change; |
| 1938 | } |
| 1939 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 1940 | static struct snd_kcontrol_new snd_vt1724_pro_rate_reset __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1942 | .name = "Multi Track Rate Reset", |
| 1943 | .info = snd_vt1724_pro_rate_reset_info, |
| 1944 | .get = snd_vt1724_pro_rate_reset_get, |
| 1945 | .put = snd_vt1724_pro_rate_reset_put |
| 1946 | }; |
| 1947 | |
| 1948 | |
| 1949 | /* |
| 1950 | * routing |
| 1951 | */ |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 1952 | static int snd_vt1724_pro_route_info(struct snd_kcontrol *kcontrol, |
| 1953 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | { |
| 1955 | static char *texts[] = { |
| 1956 | "PCM Out", /* 0 */ |
| 1957 | "H/W In 0", "H/W In 1", /* 1-2 */ |
| 1958 | "IEC958 In L", "IEC958 In R", /* 3-4 */ |
| 1959 | }; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1960 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1962 | uinfo->count = 1; |
| 1963 | uinfo->value.enumerated.items = 5; |
| 1964 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 1965 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 1966 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | static inline int analog_route_shift(int idx) |
| 1971 | { |
| 1972 | return (idx % 2) * 12 + ((idx / 2) * 3) + 8; |
| 1973 | } |
| 1974 | |
| 1975 | static inline int digital_route_shift(int idx) |
| 1976 | { |
| 1977 | return idx * 3; |
| 1978 | } |
| 1979 | |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 1980 | int snd_ice1724_get_route_val(struct snd_ice1712 *ice, int shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | { |
| 1982 | unsigned long val; |
| 1983 | unsigned char eitem; |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 1984 | static const unsigned char xlate[8] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | 0, 255, 1, 2, 255, 255, 3, 4, |
| 1986 | }; |
| 1987 | |
| 1988 | val = inl(ICEMT1724(ice, ROUTE_PLAYBACK)); |
| 1989 | val >>= shift; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 1990 | val &= 7; /* we now have 3 bits per output */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | eitem = xlate[val]; |
| 1992 | if (eitem == 255) { |
| 1993 | snd_BUG(); |
| 1994 | return 0; |
| 1995 | } |
| 1996 | return eitem; |
| 1997 | } |
| 1998 | |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 1999 | int snd_ice1724_put_route_val(struct snd_ice1712 *ice, unsigned int val, |
| 2000 | int shift) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2001 | { |
| 2002 | unsigned int old_val, nval; |
| 2003 | int change; |
Takashi Iwai | 32b47da | 2007-01-29 15:26:36 +0100 | [diff] [blame] | 2004 | static const unsigned char xroute[8] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | 0, /* PCM */ |
| 2006 | 2, /* PSDIN0 Left */ |
| 2007 | 3, /* PSDIN0 Right */ |
| 2008 | 6, /* SPDIN Left */ |
| 2009 | 7, /* SPDIN Right */ |
| 2010 | }; |
| 2011 | |
| 2012 | nval = xroute[val % 5]; |
| 2013 | val = old_val = inl(ICEMT1724(ice, ROUTE_PLAYBACK)); |
| 2014 | val &= ~(0x07 << shift); |
| 2015 | val |= nval << shift; |
| 2016 | change = val != old_val; |
| 2017 | if (change) |
| 2018 | outl(val, ICEMT1724(ice, ROUTE_PLAYBACK)); |
| 2019 | return change; |
| 2020 | } |
| 2021 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2022 | static int snd_vt1724_pro_route_analog_get(struct snd_kcontrol *kcontrol, |
| 2023 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2025 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2027 | ucontrol->value.enumerated.item[0] = |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2028 | snd_ice1724_get_route_val(ice, analog_route_shift(idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | return 0; |
| 2030 | } |
| 2031 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2032 | static int snd_vt1724_pro_route_analog_put(struct snd_kcontrol *kcontrol, |
| 2033 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2035 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2037 | return snd_ice1724_put_route_val(ice, |
| 2038 | ucontrol->value.enumerated.item[0], |
| 2039 | analog_route_shift(idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2042 | static int snd_vt1724_pro_route_spdif_get(struct snd_kcontrol *kcontrol, |
| 2043 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2045 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2047 | ucontrol->value.enumerated.item[0] = |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2048 | snd_ice1724_get_route_val(ice, digital_route_shift(idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | return 0; |
| 2050 | } |
| 2051 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2052 | static int snd_vt1724_pro_route_spdif_put(struct snd_kcontrol *kcontrol, |
| 2053 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2055 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2057 | return snd_ice1724_put_route_val(ice, |
| 2058 | ucontrol->value.enumerated.item[0], |
| 2059 | digital_route_shift(idx)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2062 | static struct snd_kcontrol_new snd_vt1724_mixer_pro_analog_route __devinitdata = |
| 2063 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2065 | .name = "H/W Playback Route", |
| 2066 | .info = snd_vt1724_pro_route_info, |
| 2067 | .get = snd_vt1724_pro_route_analog_get, |
| 2068 | .put = snd_vt1724_pro_route_analog_put, |
| 2069 | }; |
| 2070 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2071 | static struct snd_kcontrol_new snd_vt1724_mixer_pro_spdif_route __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2073 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | .info = snd_vt1724_pro_route_info, |
| 2075 | .get = snd_vt1724_pro_route_spdif_get, |
| 2076 | .put = snd_vt1724_pro_route_spdif_put, |
| 2077 | .count = 2, |
| 2078 | }; |
| 2079 | |
| 2080 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2081 | static int snd_vt1724_pro_peak_info(struct snd_kcontrol *kcontrol, |
| 2082 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | { |
| 2084 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2085 | uinfo->count = 22; /* FIXME: for compatibility with ice1712... */ |
| 2086 | uinfo->value.integer.min = 0; |
| 2087 | uinfo->value.integer.max = 255; |
| 2088 | return 0; |
| 2089 | } |
| 2090 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2091 | static int snd_vt1724_pro_peak_get(struct snd_kcontrol *kcontrol, |
| 2092 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2094 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | int idx; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | spin_lock_irq(&ice->reg_lock); |
| 2098 | for (idx = 0; idx < 22; idx++) { |
| 2099 | outb(idx, ICEMT1724(ice, MONITOR_PEAKINDEX)); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2100 | ucontrol->value.integer.value[idx] = |
| 2101 | inb(ICEMT1724(ice, MONITOR_PEAKDATA)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | } |
| 2103 | spin_unlock_irq(&ice->reg_lock); |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2107 | static struct snd_kcontrol_new snd_vt1724_mixer_pro_peak __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2109 | .name = "Multi Track Peak", |
| 2110 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2111 | .info = snd_vt1724_pro_peak_info, |
| 2112 | .get = snd_vt1724_pro_peak_get |
| 2113 | }; |
| 2114 | |
| 2115 | /* |
| 2116 | * |
| 2117 | */ |
| 2118 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2119 | static struct snd_ice1712_card_info no_matched __devinitdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2121 | static struct snd_ice1712_card_info *card_tables[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | snd_vt1724_revo_cards, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2123 | snd_vt1724_amp_cards, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | snd_vt1724_aureon_cards, |
| 2125 | snd_vt1720_mobo_cards, |
| 2126 | snd_vt1720_pontis_cards, |
Julian Scheel | 6b8d6e5 | 2008-01-16 19:50:00 +0100 | [diff] [blame] | 2127 | snd_vt1724_prodigy_hifi_cards, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | snd_vt1724_prodigy192_cards, |
| 2129 | snd_vt1724_juli_cards, |
Takashi Iwai | 72cbfd4 | 2009-05-06 17:33:19 +0200 | [diff] [blame^] | 2130 | snd_vt1724_maya44_cards, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | snd_vt1724_phase_cards, |
Clement Guedez | f6cdab5 | 2007-01-08 10:48:41 +0100 | [diff] [blame] | 2132 | snd_vt1724_wtm_cards, |
Shin-ya Okada | f31639b | 2007-10-23 15:08:18 +0200 | [diff] [blame] | 2133 | snd_vt1724_se_cards, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | NULL, |
| 2135 | }; |
| 2136 | |
| 2137 | |
| 2138 | /* |
| 2139 | */ |
| 2140 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2141 | static void wait_i2c_busy(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | { |
| 2143 | int t = 0x10000; |
| 2144 | while ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_BUSY) && t--) |
| 2145 | ; |
| 2146 | if (t == -1) |
| 2147 | printk(KERN_ERR "ice1724: i2c busy timeout\n"); |
| 2148 | } |
| 2149 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2150 | unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice, |
| 2151 | unsigned char dev, unsigned char addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | { |
| 2153 | unsigned char val; |
| 2154 | |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2155 | mutex_lock(&ice->i2c_mutex); |
Pavel Hofman | acec30f | 2007-12-03 12:37:17 +0100 | [diff] [blame] | 2156 | wait_i2c_busy(ice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR)); |
| 2158 | outb(dev & ~VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR)); |
| 2159 | wait_i2c_busy(ice); |
| 2160 | val = inb(ICEREG1724(ice, I2C_DATA)); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2161 | mutex_unlock(&ice->i2c_mutex); |
Takashi Iwai | e2ea7cfc | 2009-02-05 16:07:02 +0100 | [diff] [blame] | 2162 | /* |
| 2163 | printk(KERN_DEBUG "i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val); |
| 2164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | return val; |
| 2166 | } |
| 2167 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2168 | void snd_vt1724_write_i2c(struct snd_ice1712 *ice, |
| 2169 | unsigned char dev, unsigned char addr, unsigned char data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | { |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2171 | mutex_lock(&ice->i2c_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2172 | wait_i2c_busy(ice); |
Takashi Iwai | e2ea7cfc | 2009-02-05 16:07:02 +0100 | [diff] [blame] | 2173 | /* |
| 2174 | printk(KERN_DEBUG "i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data); |
| 2175 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2176 | outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR)); |
| 2177 | outb(data, ICEREG1724(ice, I2C_DATA)); |
| 2178 | outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR)); |
| 2179 | wait_i2c_busy(ice); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2180 | mutex_unlock(&ice->i2c_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | } |
| 2182 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2183 | static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice, |
| 2184 | const char *modelname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | { |
| 2186 | const int dev = 0xa0; /* EEPROM device address */ |
| 2187 | unsigned int i, size; |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2188 | struct snd_ice1712_card_info * const *tbl, *c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2190 | if (!modelname || !*modelname) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | ice->eeprom.subvendor = 0; |
| 2192 | if ((inb(ICEREG1724(ice, I2C_CTRL)) & VT1724_I2C_EEPROM) != 0) |
| 2193 | ice->eeprom.subvendor = |
| 2194 | (snd_vt1724_read_i2c(ice, dev, 0x00) << 0) | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2195 | (snd_vt1724_read_i2c(ice, dev, 0x01) << 8) | |
| 2196 | (snd_vt1724_read_i2c(ice, dev, 0x02) << 16) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | (snd_vt1724_read_i2c(ice, dev, 0x03) << 24); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2198 | if (ice->eeprom.subvendor == 0 || |
| 2199 | ice->eeprom.subvendor == (unsigned int)-1) { |
| 2200 | /* invalid subvendor from EEPROM, try the PCI |
| 2201 | * subststem ID instead |
| 2202 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | u16 vendor, device; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2204 | pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, |
| 2205 | &vendor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2206 | pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device); |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2207 | ice->eeprom.subvendor = |
| 2208 | ((unsigned int)swab16(vendor) << 16) | swab16(device); |
| 2209 | if (ice->eeprom.subvendor == 0 || |
| 2210 | ice->eeprom.subvendor == (unsigned int)-1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | printk(KERN_ERR "ice1724: No valid ID is found\n"); |
| 2212 | return -ENXIO; |
| 2213 | } |
| 2214 | } |
| 2215 | } |
| 2216 | for (tbl = card_tables; *tbl; tbl++) { |
| 2217 | for (c = *tbl; c->subvendor; c++) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2218 | if (modelname && c->model && |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2219 | !strcmp(modelname, c->model)) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2220 | printk(KERN_INFO "ice1724: Using board model %s\n", |
| 2221 | c->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | ice->eeprom.subvendor = c->subvendor; |
| 2223 | } else if (c->subvendor != ice->eeprom.subvendor) |
| 2224 | continue; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2225 | if (!c->eeprom_size || !c->eeprom_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2226 | goto found; |
| 2227 | /* if the EEPROM is given by the driver, use it */ |
| 2228 | snd_printdd("using the defined eeprom..\n"); |
| 2229 | ice->eeprom.version = 2; |
| 2230 | ice->eeprom.size = c->eeprom_size + 6; |
| 2231 | memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size); |
| 2232 | goto read_skipped; |
| 2233 | } |
| 2234 | } |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2235 | printk(KERN_WARNING "ice1724: No matching model found for ID 0x%x\n", |
| 2236 | ice->eeprom.subvendor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | |
| 2238 | found: |
| 2239 | ice->eeprom.size = snd_vt1724_read_i2c(ice, dev, 0x04); |
| 2240 | if (ice->eeprom.size < 6) |
| 2241 | ice->eeprom.size = 32; |
| 2242 | else if (ice->eeprom.size > 32) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2243 | printk(KERN_ERR "ice1724: Invalid EEPROM (size = %i)\n", |
| 2244 | ice->eeprom.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | return -EIO; |
| 2246 | } |
| 2247 | ice->eeprom.version = snd_vt1724_read_i2c(ice, dev, 0x05); |
| 2248 | if (ice->eeprom.version != 2) |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2249 | printk(KERN_WARNING "ice1724: Invalid EEPROM version %i\n", |
| 2250 | ice->eeprom.version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | size = ice->eeprom.size - 6; |
| 2252 | for (i = 0; i < size; i++) |
| 2253 | ice->eeprom.data[i] = snd_vt1724_read_i2c(ice, dev, i + 6); |
| 2254 | |
| 2255 | read_skipped: |
| 2256 | ice->eeprom.gpiomask = eeprom_triple(ice, ICE_EEP2_GPIO_MASK); |
| 2257 | ice->eeprom.gpiostate = eeprom_triple(ice, ICE_EEP2_GPIO_STATE); |
| 2258 | ice->eeprom.gpiodir = eeprom_triple(ice, ICE_EEP2_GPIO_DIR); |
| 2259 | |
| 2260 | return 0; |
| 2261 | } |
| 2262 | |
| 2263 | |
| 2264 | |
Karsten Wiese | 988f066 | 2008-04-22 12:52:15 +0200 | [diff] [blame] | 2265 | static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | { |
| 2267 | outb(VT1724_RESET , ICEREG1724(ice, CONTROL)); |
Takashi Iwai | d82b64f | 2009-05-06 17:25:42 +0200 | [diff] [blame] | 2268 | inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */ |
Karsten Wiese | 988f066 | 2008-04-22 12:52:15 +0200 | [diff] [blame] | 2269 | msleep(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2270 | outb(0, ICEREG1724(ice, CONTROL)); |
Takashi Iwai | d82b64f | 2009-05-06 17:25:42 +0200 | [diff] [blame] | 2271 | inb(ICEREG1724(ice, CONTROL)); /* pci posting flush */ |
Karsten Wiese | 988f066 | 2008-04-22 12:52:15 +0200 | [diff] [blame] | 2272 | msleep(10); |
| 2273 | } |
| 2274 | |
| 2275 | static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice) |
| 2276 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG)); |
| 2278 | outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG)); |
| 2279 | outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES)); |
| 2280 | outb(ice->eeprom.data[ICE_EEP2_SPDIF], ICEREG1724(ice, SPDIF_CFG)); |
| 2281 | |
| 2282 | ice->gpio.write_mask = ice->eeprom.gpiomask; |
| 2283 | ice->gpio.direction = ice->eeprom.gpiodir; |
| 2284 | snd_vt1724_set_gpio_mask(ice, ice->eeprom.gpiomask); |
| 2285 | snd_vt1724_set_gpio_dir(ice, ice->eeprom.gpiodir); |
| 2286 | snd_vt1724_set_gpio_data(ice, ice->eeprom.gpiostate); |
| 2287 | |
| 2288 | outb(0, ICEREG1724(ice, POWERDOWN)); |
| 2289 | |
| 2290 | return 0; |
| 2291 | } |
| 2292 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2293 | static int __devinit snd_vt1724_spdif_build_controls(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2294 | { |
| 2295 | int err; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2296 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 2298 | if (snd_BUG_ON(!ice->pcm)) |
| 2299 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2301 | if (!ice->own_routing) { |
| 2302 | err = snd_ctl_add(ice->card, |
| 2303 | snd_ctl_new1(&snd_vt1724_mixer_pro_spdif_route, ice)); |
| 2304 | if (err < 0) |
| 2305 | return err; |
| 2306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | |
| 2308 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_spdif_switch, ice)); |
| 2309 | if (err < 0) |
| 2310 | return err; |
| 2311 | |
| 2312 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_default, ice)); |
| 2313 | if (err < 0) |
| 2314 | return err; |
| 2315 | kctl->id.device = ice->pcm->device; |
| 2316 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskc, ice)); |
| 2317 | if (err < 0) |
| 2318 | return err; |
| 2319 | kctl->id.device = ice->pcm->device; |
| 2320 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_maskp, ice)); |
| 2321 | if (err < 0) |
| 2322 | return err; |
| 2323 | kctl->id.device = ice->pcm->device; |
| 2324 | #if 0 /* use default only */ |
| 2325 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_vt1724_spdif_stream, ice)); |
| 2326 | if (err < 0) |
| 2327 | return err; |
| 2328 | kctl->id.device = ice->pcm->device; |
| 2329 | ice->spdif.stream_ctl = kctl; |
| 2330 | #endif |
| 2331 | return 0; |
| 2332 | } |
| 2333 | |
| 2334 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2335 | static int __devinit snd_vt1724_build_controls(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | { |
| 2337 | int err; |
| 2338 | |
| 2339 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_eeprom, ice)); |
| 2340 | if (err < 0) |
| 2341 | return err; |
| 2342 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_internal_clock, ice)); |
| 2343 | if (err < 0) |
| 2344 | return err; |
| 2345 | |
| 2346 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_locking, ice)); |
| 2347 | if (err < 0) |
| 2348 | return err; |
| 2349 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_pro_rate_reset, ice)); |
| 2350 | if (err < 0) |
| 2351 | return err; |
| 2352 | |
Takashi Iwai | 2bf864a | 2009-05-06 17:30:17 +0200 | [diff] [blame] | 2353 | if (!ice->own_routing && ice->num_total_dacs > 0) { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2354 | struct snd_kcontrol_new tmp = snd_vt1724_mixer_pro_analog_route; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | tmp.count = ice->num_total_dacs; |
| 2356 | if (ice->vt1720 && tmp.count > 2) |
| 2357 | tmp.count = 2; |
| 2358 | err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice)); |
| 2359 | if (err < 0) |
| 2360 | return err; |
| 2361 | } |
| 2362 | |
| 2363 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_vt1724_mixer_pro_peak, ice)); |
| 2364 | if (err < 0) |
| 2365 | return err; |
| 2366 | |
| 2367 | return 0; |
| 2368 | } |
| 2369 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2370 | static int snd_vt1724_free(struct snd_ice1712 *ice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | { |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2372 | if (!ice->port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2373 | goto __hw_end; |
| 2374 | /* mask all interrupts */ |
| 2375 | outb(0xff, ICEMT1724(ice, DMA_INT_MASK)); |
| 2376 | outb(0xff, ICEREG1724(ice, IRQMASK)); |
| 2377 | /* --- */ |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2378 | __hw_end: |
Jeff Garzik | f000fd8 | 2008-04-22 13:50:34 +0200 | [diff] [blame] | 2379 | if (ice->irq >= 0) |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2380 | free_irq(ice->irq, ice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | pci_release_regions(ice->pci); |
| 2382 | snd_ice1712_akm4xxx_free(ice); |
| 2383 | pci_disable_device(ice->pci); |
Takashi Iwai | 7cda8ba | 2008-01-18 13:36:07 +0100 | [diff] [blame] | 2384 | kfree(ice->spec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | kfree(ice); |
| 2386 | return 0; |
| 2387 | } |
| 2388 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2389 | static int snd_vt1724_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2391 | struct snd_ice1712 *ice = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2392 | return snd_vt1724_free(ice); |
| 2393 | } |
| 2394 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2395 | static int __devinit snd_vt1724_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | struct pci_dev *pci, |
| 2397 | const char *modelname, |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2398 | struct snd_ice1712 **r_ice1712) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | { |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2400 | struct snd_ice1712 *ice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | int err; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2402 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | .dev_free = snd_vt1724_dev_free, |
| 2404 | }; |
| 2405 | |
| 2406 | *r_ice1712 = NULL; |
| 2407 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2408 | /* enable PCI device */ |
| 2409 | err = pci_enable_device(pci); |
| 2410 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | return err; |
| 2412 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 2413 | ice = kzalloc(sizeof(*ice), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | if (ice == NULL) { |
| 2415 | pci_disable_device(pci); |
| 2416 | return -ENOMEM; |
| 2417 | } |
| 2418 | ice->vt1724 = 1; |
| 2419 | spin_lock_init(&ice->reg_lock); |
Ingo Molnar | 62932df | 2006-01-16 16:34:20 +0100 | [diff] [blame] | 2420 | mutex_init(&ice->gpio_mutex); |
| 2421 | mutex_init(&ice->open_mutex); |
| 2422 | mutex_init(&ice->i2c_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | ice->gpio.set_mask = snd_vt1724_set_gpio_mask; |
| 2424 | ice->gpio.set_dir = snd_vt1724_set_gpio_dir; |
| 2425 | ice->gpio.set_data = snd_vt1724_set_gpio_data; |
| 2426 | ice->gpio.get_data = snd_vt1724_get_gpio_data; |
| 2427 | ice->card = card; |
| 2428 | ice->pci = pci; |
| 2429 | ice->irq = -1; |
| 2430 | pci_set_master(pci); |
| 2431 | snd_vt1724_proc_init(ice); |
| 2432 | synchronize_irq(pci->irq); |
| 2433 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2434 | err = pci_request_regions(pci, "ICE1724"); |
| 2435 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | kfree(ice); |
| 2437 | pci_disable_device(pci); |
| 2438 | return err; |
| 2439 | } |
| 2440 | ice->port = pci_resource_start(pci, 0); |
| 2441 | ice->profi_port = pci_resource_start(pci, 1); |
| 2442 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2443 | if (request_irq(pci->irq, snd_vt1724_interrupt, |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2444 | IRQF_SHARED, "ICE1724", ice)) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2445 | snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | snd_vt1724_free(ice); |
| 2447 | return -EIO; |
| 2448 | } |
| 2449 | |
| 2450 | ice->irq = pci->irq; |
| 2451 | |
Karsten Wiese | 988f066 | 2008-04-22 12:52:15 +0200 | [diff] [blame] | 2452 | snd_vt1724_chip_reset(ice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | if (snd_vt1724_read_eeprom(ice, modelname) < 0) { |
| 2454 | snd_vt1724_free(ice); |
| 2455 | return -EIO; |
| 2456 | } |
| 2457 | if (snd_vt1724_chip_init(ice) < 0) { |
| 2458 | snd_vt1724_free(ice); |
| 2459 | return -EIO; |
| 2460 | } |
| 2461 | |
Takashi Iwai | 6834d7c | 2008-11-05 17:41:23 +0100 | [diff] [blame] | 2462 | /* MPU_RX and TX irq masks are cleared later dynamically */ |
| 2463 | outb(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX , ICEREG1724(ice, IRQMASK)); |
Takashi Iwai | 4074ea2 | 2008-11-01 11:01:50 +0100 | [diff] [blame] | 2464 | |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2465 | /* don't handle FIFO overrun/underruns (just yet), |
| 2466 | * since they cause machine lockups |
| 2467 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2468 | outb(VT1724_MULTI_FIFO_ERR, ICEMT1724(ice, DMA_INT_MASK)); |
| 2469 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2470 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops); |
| 2471 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2472 | snd_vt1724_free(ice); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2473 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | snd_card_set_dev(card, &pci->dev); |
| 2477 | |
| 2478 | *r_ice1712 = ice; |
| 2479 | return 0; |
| 2480 | } |
| 2481 | |
| 2482 | |
| 2483 | /* |
| 2484 | * |
| 2485 | * Registration |
| 2486 | * |
| 2487 | */ |
| 2488 | |
| 2489 | static int __devinit snd_vt1724_probe(struct pci_dev *pci, |
| 2490 | const struct pci_device_id *pci_id) |
| 2491 | { |
| 2492 | static int dev; |
Takashi Iwai | ab0c7d7 | 2005-11-17 15:00:18 +0100 | [diff] [blame] | 2493 | struct snd_card *card; |
| 2494 | struct snd_ice1712 *ice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2495 | int pcm_dev = 0, err; |
Takashi Iwai | 1b60f6b | 2007-03-13 22:13:47 +0100 | [diff] [blame] | 2496 | struct snd_ice1712_card_info * const *tbl, *c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
| 2498 | if (dev >= SNDRV_CARDS) |
| 2499 | return -ENODEV; |
| 2500 | if (!enable[dev]) { |
| 2501 | dev++; |
| 2502 | return -ENOENT; |
| 2503 | } |
| 2504 | |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 2505 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); |
| 2506 | if (err < 0) |
| 2507 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
| 2509 | strcpy(card->driver, "ICE1724"); |
| 2510 | strcpy(card->shortname, "ICEnsemble ICE1724"); |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2511 | |
| 2512 | err = snd_vt1724_create(card, pci, model[dev], &ice); |
| 2513 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2514 | snd_card_free(card); |
| 2515 | return err; |
| 2516 | } |
| 2517 | |
| 2518 | for (tbl = card_tables; *tbl; tbl++) { |
| 2519 | for (c = *tbl; c->subvendor; c++) { |
| 2520 | if (c->subvendor == ice->eeprom.subvendor) { |
| 2521 | strcpy(card->shortname, c->name); |
| 2522 | if (c->driver) /* specific driver? */ |
| 2523 | strcpy(card->driver, c->driver); |
| 2524 | if (c->chip_init) { |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2525 | err = c->chip_init(ice); |
| 2526 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | snd_card_free(card); |
| 2528 | return err; |
| 2529 | } |
| 2530 | } |
| 2531 | goto __found; |
| 2532 | } |
| 2533 | } |
| 2534 | } |
| 2535 | c = &no_matched; |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2536 | __found: |
| 2537 | /* |
| 2538 | * VT1724 has separate DMAs for the analog and the SPDIF streams while |
| 2539 | * ICE1712 has only one for both (mixed up). |
| 2540 | * |
| 2541 | * Confusingly the analog PCM is named "professional" here because it |
| 2542 | * was called so in ice1712 driver, and vt1724 driver is derived from |
| 2543 | * ice1712 driver. |
| 2544 | */ |
Pavel Hofman | d16be8e | 2008-03-20 12:10:27 +0100 | [diff] [blame] | 2545 | ice->pro_rate_default = PRO_RATE_DEFAULT; |
| 2546 | if (!ice->is_spdif_master) |
| 2547 | ice->is_spdif_master = stdclock_is_spdif_master; |
| 2548 | if (!ice->get_rate) |
| 2549 | ice->get_rate = stdclock_get_rate; |
| 2550 | if (!ice->set_rate) |
| 2551 | ice->set_rate = stdclock_set_rate; |
| 2552 | if (!ice->set_mclk) |
| 2553 | ice->set_mclk = stdclock_set_mclk; |
| 2554 | if (!ice->set_spdif_clock) |
| 2555 | ice->set_spdif_clock = stdclock_set_spdif_clock; |
| 2556 | if (!ice->hw_rates) |
| 2557 | set_std_hw_rates(ice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2559 | err = snd_vt1724_pcm_profi(ice, pcm_dev++); |
| 2560 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | snd_card_free(card); |
| 2562 | return err; |
| 2563 | } |
| 2564 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2565 | err = snd_vt1724_pcm_spdif(ice, pcm_dev++); |
| 2566 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | snd_card_free(card); |
| 2568 | return err; |
| 2569 | } |
| 2570 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2571 | err = snd_vt1724_pcm_indep(ice, pcm_dev++); |
| 2572 | if (err < 0) { |
| 2573 | snd_card_free(card); |
| 2574 | return err; |
| 2575 | } |
| 2576 | |
| 2577 | err = snd_vt1724_ac97_mixer(ice); |
| 2578 | if (err < 0) { |
| 2579 | snd_card_free(card); |
| 2580 | return err; |
| 2581 | } |
| 2582 | |
| 2583 | err = snd_vt1724_build_controls(ice); |
| 2584 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | snd_card_free(card); |
| 2586 | return err; |
| 2587 | } |
| 2588 | |
| 2589 | if (ice->pcm && ice->has_spdif) { /* has SPDIF I/O */ |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2590 | err = snd_vt1724_spdif_build_controls(ice); |
| 2591 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | snd_card_free(card); |
| 2593 | return err; |
| 2594 | } |
| 2595 | } |
| 2596 | |
| 2597 | if (c->build_controls) { |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2598 | err = c->build_controls(ice); |
| 2599 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | snd_card_free(card); |
| 2601 | return err; |
| 2602 | } |
| 2603 | } |
| 2604 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2605 | if (!c->no_mpu401) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) { |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 2607 | struct snd_rawmidi *rmidi; |
| 2608 | |
| 2609 | err = snd_rawmidi_new(card, "MIDI", 0, 1, 1, &rmidi); |
| 2610 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | snd_card_free(card); |
| 2612 | return err; |
| 2613 | } |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 2614 | ice->rmidi[0] = rmidi; |
| 2615 | rmidi->private_data = ice; |
| 2616 | strcpy(rmidi->name, "ICE1724 MIDI"); |
| 2617 | rmidi->info_flags = SNDRV_RAWMIDI_INFO_OUTPUT | |
| 2618 | SNDRV_RAWMIDI_INFO_INPUT | |
| 2619 | SNDRV_RAWMIDI_INFO_DUPLEX; |
| 2620 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, |
| 2621 | &vt1724_midi_output_ops); |
| 2622 | snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, |
| 2623 | &vt1724_midi_input_ops); |
| 2624 | |
Takashi Iwai | 3a841d5 | 2008-04-23 17:47:28 +0200 | [diff] [blame] | 2625 | /* set watermarks */ |
| 2626 | outb(VT1724_MPU_RX_FIFO | 0x1, |
| 2627 | ICEREG1724(ice, MPU_FIFO_WM)); |
| 2628 | outb(0x1, ICEREG1724(ice, MPU_FIFO_WM)); |
Clemens Ladisch | aea3bfb | 2008-05-20 14:22:44 +0200 | [diff] [blame] | 2629 | /* set UART mode */ |
| 2630 | outb(VT1724_MPU_UART, ICEREG1724(ice, MPU_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | sprintf(card->longname, "%s at 0x%lx, irq %i", |
| 2635 | card->shortname, ice->port, ice->irq); |
| 2636 | |
Alexander Beregalov | 1de9fdc | 2008-09-07 14:11:04 +0400 | [diff] [blame] | 2637 | err = snd_card_register(card); |
| 2638 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | snd_card_free(card); |
| 2640 | return err; |
| 2641 | } |
| 2642 | pci_set_drvdata(pci, card); |
| 2643 | dev++; |
| 2644 | return 0; |
| 2645 | } |
| 2646 | |
| 2647 | static void __devexit snd_vt1724_remove(struct pci_dev *pci) |
| 2648 | { |
| 2649 | snd_card_free(pci_get_drvdata(pci)); |
| 2650 | pci_set_drvdata(pci, NULL); |
| 2651 | } |
| 2652 | |
| 2653 | static struct pci_driver driver = { |
| 2654 | .name = "ICE1724", |
| 2655 | .id_table = snd_vt1724_ids, |
| 2656 | .probe = snd_vt1724_probe, |
| 2657 | .remove = __devexit_p(snd_vt1724_remove), |
| 2658 | }; |
| 2659 | |
| 2660 | static int __init alsa_card_ice1724_init(void) |
| 2661 | { |
Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 2662 | return pci_register_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | static void __exit alsa_card_ice1724_exit(void) |
| 2666 | { |
| 2667 | pci_unregister_driver(&driver); |
| 2668 | } |
| 2669 | |
| 2670 | module_init(alsa_card_ice1724_init) |
| 2671 | module_exit(alsa_card_ice1724_exit) |