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