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