yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * ALSA driver for ICEnsemble ICE1712 (Envy24) |
| 3 | * |
| 4 | * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | NOTES: |
| 24 | - spdif nonaudio consumer mode does not work (at least with my |
| 25 | Sony STR-DB830) |
| 26 | */ |
| 27 | |
| 28 | /* |
| 29 | * Changes: |
| 30 | * |
| 31 | * 2002.09.09 Takashi Iwai <tiwai@suse.de> |
| 32 | * split the code to several files. each low-level routine |
| 33 | * is stored in the local file and called from registration |
| 34 | * function from card_info struct. |
| 35 | * |
| 36 | * 2002.11.26 James Stafford <jstafford@ampltd.com> |
| 37 | * Added support for VT1724 (Envy24HT) |
| 38 | * I have left out support for 176.4 and 192 KHz for the moment. |
| 39 | * I also haven't done anything with the internal S/PDIF transmitter or the MPU-401 |
| 40 | * |
| 41 | * 2003.02.20 Taksahi Iwai <tiwai@suse.de> |
| 42 | * Split vt1724 part to an independent driver. |
| 43 | * The GPIO is accessed through the callback functions now. |
| 44 | * |
| 45 | * 2004.03.31 Doug McLain <nostar@comcast.net> |
| 46 | * Added support for Event Electronics EZ8 card to hoontech.c. |
| 47 | */ |
| 48 | |
| 49 | |
| 50 | #include <linux/io.h> |
| 51 | #include <linux/delay.h> |
| 52 | #include <linux/interrupt.h> |
| 53 | #include <linux/init.h> |
| 54 | #include <linux/pci.h> |
| 55 | #include <linux/dma-mapping.h> |
| 56 | #include <linux/slab.h> |
| 57 | #include <linux/module.h> |
| 58 | #include <linux/mutex.h> |
| 59 | |
| 60 | #include <sound/core.h> |
| 61 | #include <sound/cs8427.h> |
| 62 | #include <sound/info.h> |
| 63 | #include <sound/initval.h> |
| 64 | #include <sound/tlv.h> |
| 65 | |
| 66 | #include <sound/asoundef.h> |
| 67 | |
| 68 | #include "ice1712.h" |
| 69 | |
| 70 | /* lowlevel routines */ |
| 71 | #include "delta.h" |
| 72 | #include "ews.h" |
| 73 | #include "hoontech.h" |
| 74 | |
| 75 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
| 76 | MODULE_DESCRIPTION("ICEnsemble ICE1712 (Envy24)"); |
| 77 | MODULE_LICENSE("GPL"); |
| 78 | MODULE_SUPPORTED_DEVICE("{" |
| 79 | HOONTECH_DEVICE_DESC |
| 80 | DELTA_DEVICE_DESC |
| 81 | EWS_DEVICE_DESC |
| 82 | "{ICEnsemble,Generic ICE1712}," |
| 83 | "{ICEnsemble,Generic Envy24}}"); |
| 84 | |
| 85 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 86 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 87 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ |
| 88 | static char *model[SNDRV_CARDS]; |
| 89 | static bool omni[SNDRV_CARDS]; /* Delta44 & 66 Omni I/O support */ |
| 90 | static int cs8427_timeout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 500}; /* CS8427 S/PDIF transceiver reset timeout value in msec */ |
| 91 | static int dxr_enable[SNDRV_CARDS]; /* DXR enable for DMX6FIRE */ |
| 92 | |
| 93 | module_param_array(index, int, NULL, 0444); |
| 94 | MODULE_PARM_DESC(index, "Index value for ICE1712 soundcard."); |
| 95 | module_param_array(id, charp, NULL, 0444); |
| 96 | MODULE_PARM_DESC(id, "ID string for ICE1712 soundcard."); |
| 97 | module_param_array(enable, bool, NULL, 0444); |
| 98 | MODULE_PARM_DESC(enable, "Enable ICE1712 soundcard."); |
| 99 | module_param_array(omni, bool, NULL, 0444); |
| 100 | MODULE_PARM_DESC(omni, "Enable Midiman M-Audio Delta Omni I/O support."); |
| 101 | module_param_array(cs8427_timeout, int, NULL, 0444); |
| 102 | MODULE_PARM_DESC(cs8427_timeout, "Define reset timeout for cs8427 chip in msec resolution."); |
| 103 | module_param_array(model, charp, NULL, 0444); |
| 104 | MODULE_PARM_DESC(model, "Use the given board model."); |
| 105 | module_param_array(dxr_enable, int, NULL, 0444); |
| 106 | MODULE_PARM_DESC(dxr_enable, "Enable DXR support for Terratec DMX6FIRE."); |
| 107 | |
| 108 | |
| 109 | static DEFINE_PCI_DEVICE_TABLE(snd_ice1712_ids) = { |
| 110 | { PCI_VDEVICE(ICE, PCI_DEVICE_ID_ICE_1712), 0 }, /* ICE1712 */ |
| 111 | { 0, } |
| 112 | }; |
| 113 | |
| 114 | MODULE_DEVICE_TABLE(pci, snd_ice1712_ids); |
| 115 | |
| 116 | static int snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice); |
| 117 | static int snd_ice1712_build_controls(struct snd_ice1712 *ice); |
| 118 | |
| 119 | static int PRO_RATE_LOCKED; |
| 120 | static int PRO_RATE_RESET = 1; |
| 121 | static unsigned int PRO_RATE_DEFAULT = 44100; |
| 122 | |
| 123 | /* |
| 124 | * Basic I/O |
| 125 | */ |
| 126 | |
| 127 | /* check whether the clock mode is spdif-in */ |
| 128 | static inline int is_spdif_master(struct snd_ice1712 *ice) |
| 129 | { |
| 130 | return (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER) ? 1 : 0; |
| 131 | } |
| 132 | |
| 133 | static inline int is_pro_rate_locked(struct snd_ice1712 *ice) |
| 134 | { |
| 135 | return is_spdif_master(ice) || PRO_RATE_LOCKED; |
| 136 | } |
| 137 | |
| 138 | static inline void snd_ice1712_ds_write(struct snd_ice1712 *ice, u8 channel, u8 addr, u32 data) |
| 139 | { |
| 140 | outb((channel << 4) | addr, ICEDS(ice, INDEX)); |
| 141 | outl(data, ICEDS(ice, DATA)); |
| 142 | } |
| 143 | |
| 144 | static inline u32 snd_ice1712_ds_read(struct snd_ice1712 *ice, u8 channel, u8 addr) |
| 145 | { |
| 146 | outb((channel << 4) | addr, ICEDS(ice, INDEX)); |
| 147 | return inl(ICEDS(ice, DATA)); |
| 148 | } |
| 149 | |
| 150 | static void snd_ice1712_ac97_write(struct snd_ac97 *ac97, |
| 151 | unsigned short reg, |
| 152 | unsigned short val) |
| 153 | { |
| 154 | struct snd_ice1712 *ice = ac97->private_data; |
| 155 | int tm; |
| 156 | unsigned char old_cmd = 0; |
| 157 | |
| 158 | for (tm = 0; tm < 0x10000; tm++) { |
| 159 | old_cmd = inb(ICEREG(ice, AC97_CMD)); |
| 160 | if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ)) |
| 161 | continue; |
| 162 | if (!(old_cmd & ICE1712_AC97_READY)) |
| 163 | continue; |
| 164 | break; |
| 165 | } |
| 166 | outb(reg, ICEREG(ice, AC97_INDEX)); |
| 167 | outw(val, ICEREG(ice, AC97_DATA)); |
| 168 | old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR); |
| 169 | outb(old_cmd | ICE1712_AC97_WRITE, ICEREG(ice, AC97_CMD)); |
| 170 | for (tm = 0; tm < 0x10000; tm++) |
| 171 | if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0) |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | static unsigned short snd_ice1712_ac97_read(struct snd_ac97 *ac97, |
| 176 | unsigned short reg) |
| 177 | { |
| 178 | struct snd_ice1712 *ice = ac97->private_data; |
| 179 | int tm; |
| 180 | unsigned char old_cmd = 0; |
| 181 | |
| 182 | for (tm = 0; tm < 0x10000; tm++) { |
| 183 | old_cmd = inb(ICEREG(ice, AC97_CMD)); |
| 184 | if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ)) |
| 185 | continue; |
| 186 | if (!(old_cmd & ICE1712_AC97_READY)) |
| 187 | continue; |
| 188 | break; |
| 189 | } |
| 190 | outb(reg, ICEREG(ice, AC97_INDEX)); |
| 191 | outb(old_cmd | ICE1712_AC97_READ, ICEREG(ice, AC97_CMD)); |
| 192 | for (tm = 0; tm < 0x10000; tm++) |
| 193 | if ((inb(ICEREG(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0) |
| 194 | break; |
| 195 | if (tm >= 0x10000) /* timeout */ |
| 196 | return ~0; |
| 197 | return inw(ICEREG(ice, AC97_DATA)); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * pro ac97 section |
| 202 | */ |
| 203 | |
| 204 | static void snd_ice1712_pro_ac97_write(struct snd_ac97 *ac97, |
| 205 | unsigned short reg, |
| 206 | unsigned short val) |
| 207 | { |
| 208 | struct snd_ice1712 *ice = ac97->private_data; |
| 209 | int tm; |
| 210 | unsigned char old_cmd = 0; |
| 211 | |
| 212 | for (tm = 0; tm < 0x10000; tm++) { |
| 213 | old_cmd = inb(ICEMT(ice, AC97_CMD)); |
| 214 | if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ)) |
| 215 | continue; |
| 216 | if (!(old_cmd & ICE1712_AC97_READY)) |
| 217 | continue; |
| 218 | break; |
| 219 | } |
| 220 | outb(reg, ICEMT(ice, AC97_INDEX)); |
| 221 | outw(val, ICEMT(ice, AC97_DATA)); |
| 222 | old_cmd &= ~(ICE1712_AC97_PBK_VSR | ICE1712_AC97_CAP_VSR); |
| 223 | outb(old_cmd | ICE1712_AC97_WRITE, ICEMT(ice, AC97_CMD)); |
| 224 | for (tm = 0; tm < 0x10000; tm++) |
| 225 | if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_WRITE) == 0) |
| 226 | break; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | static unsigned short snd_ice1712_pro_ac97_read(struct snd_ac97 *ac97, |
| 231 | unsigned short reg) |
| 232 | { |
| 233 | struct snd_ice1712 *ice = ac97->private_data; |
| 234 | int tm; |
| 235 | unsigned char old_cmd = 0; |
| 236 | |
| 237 | for (tm = 0; tm < 0x10000; tm++) { |
| 238 | old_cmd = inb(ICEMT(ice, AC97_CMD)); |
| 239 | if (old_cmd & (ICE1712_AC97_WRITE | ICE1712_AC97_READ)) |
| 240 | continue; |
| 241 | if (!(old_cmd & ICE1712_AC97_READY)) |
| 242 | continue; |
| 243 | break; |
| 244 | } |
| 245 | outb(reg, ICEMT(ice, AC97_INDEX)); |
| 246 | outb(old_cmd | ICE1712_AC97_READ, ICEMT(ice, AC97_CMD)); |
| 247 | for (tm = 0; tm < 0x10000; tm++) |
| 248 | if ((inb(ICEMT(ice, AC97_CMD)) & ICE1712_AC97_READ) == 0) |
| 249 | break; |
| 250 | if (tm >= 0x10000) /* timeout */ |
| 251 | return ~0; |
| 252 | return inw(ICEMT(ice, AC97_DATA)); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * consumer ac97 digital mix |
| 257 | */ |
| 258 | #define snd_ice1712_digmix_route_ac97_info snd_ctl_boolean_mono_info |
| 259 | |
| 260 | static int snd_ice1712_digmix_route_ac97_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 261 | { |
| 262 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 263 | |
| 264 | ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_ROUTECTRL)) & ICE1712_ROUTE_AC97 ? 1 : 0; |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int snd_ice1712_digmix_route_ac97_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 269 | { |
| 270 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 271 | unsigned char val, nval; |
| 272 | |
| 273 | spin_lock_irq(&ice->reg_lock); |
| 274 | val = inb(ICEMT(ice, MONITOR_ROUTECTRL)); |
| 275 | nval = val & ~ICE1712_ROUTE_AC97; |
| 276 | if (ucontrol->value.integer.value[0]) |
| 277 | nval |= ICE1712_ROUTE_AC97; |
| 278 | outb(nval, ICEMT(ice, MONITOR_ROUTECTRL)); |
| 279 | spin_unlock_irq(&ice->reg_lock); |
| 280 | return val != nval; |
| 281 | } |
| 282 | |
| 283 | static struct snd_kcontrol_new snd_ice1712_mixer_digmix_route_ac97 __devinitdata = { |
| 284 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 285 | .name = "Digital Mixer To AC97", |
| 286 | .info = snd_ice1712_digmix_route_ac97_info, |
| 287 | .get = snd_ice1712_digmix_route_ac97_get, |
| 288 | .put = snd_ice1712_digmix_route_ac97_put, |
| 289 | }; |
| 290 | |
| 291 | |
| 292 | /* |
| 293 | * gpio operations |
| 294 | */ |
| 295 | static void snd_ice1712_set_gpio_dir(struct snd_ice1712 *ice, unsigned int data) |
| 296 | { |
| 297 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, data); |
| 298 | inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */ |
| 299 | } |
| 300 | |
| 301 | static unsigned int snd_ice1712_get_gpio_dir(struct snd_ice1712 *ice) |
| 302 | { |
| 303 | return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION); |
| 304 | } |
| 305 | |
| 306 | static unsigned int snd_ice1712_get_gpio_mask(struct snd_ice1712 *ice) |
| 307 | { |
| 308 | return snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK); |
| 309 | } |
| 310 | |
| 311 | static void snd_ice1712_set_gpio_mask(struct snd_ice1712 *ice, unsigned int data) |
| 312 | { |
| 313 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, data); |
| 314 | inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */ |
| 315 | } |
| 316 | |
| 317 | static unsigned int snd_ice1712_get_gpio_data(struct snd_ice1712 *ice) |
| 318 | { |
| 319 | return snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); |
| 320 | } |
| 321 | |
| 322 | static void snd_ice1712_set_gpio_data(struct snd_ice1712 *ice, unsigned int val) |
| 323 | { |
| 324 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, val); |
| 325 | inb(ICEREG(ice, DATA)); /* dummy read for pci-posting */ |
| 326 | } |
| 327 | |
| 328 | /* |
| 329 | * |
| 330 | * CS8427 interface |
| 331 | * |
| 332 | */ |
| 333 | |
| 334 | /* |
| 335 | * change the input clock selection |
| 336 | * spdif_clock = 1 - IEC958 input, 0 - Envy24 |
| 337 | */ |
| 338 | static int snd_ice1712_cs8427_set_input_clock(struct snd_ice1712 *ice, int spdif_clock) |
| 339 | { |
| 340 | unsigned char reg[2] = { 0x80 | 4, 0 }; /* CS8427 auto increment | register number 4 + data */ |
| 341 | unsigned char val, nval; |
| 342 | int res = 0; |
| 343 | |
| 344 | snd_i2c_lock(ice->i2c); |
| 345 | if (snd_i2c_sendbytes(ice->cs8427, reg, 1) != 1) { |
| 346 | snd_i2c_unlock(ice->i2c); |
| 347 | return -EIO; |
| 348 | } |
| 349 | if (snd_i2c_readbytes(ice->cs8427, &val, 1) != 1) { |
| 350 | snd_i2c_unlock(ice->i2c); |
| 351 | return -EIO; |
| 352 | } |
| 353 | nval = val & 0xf0; |
| 354 | if (spdif_clock) |
| 355 | nval |= 0x01; |
| 356 | else |
| 357 | nval |= 0x04; |
| 358 | if (val != nval) { |
| 359 | reg[1] = nval; |
| 360 | if (snd_i2c_sendbytes(ice->cs8427, reg, 2) != 2) { |
| 361 | res = -EIO; |
| 362 | } else { |
| 363 | res++; |
| 364 | } |
| 365 | } |
| 366 | snd_i2c_unlock(ice->i2c); |
| 367 | return res; |
| 368 | } |
| 369 | |
| 370 | /* |
| 371 | * spdif callbacks |
| 372 | */ |
| 373 | static void open_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream) |
| 374 | { |
| 375 | snd_cs8427_iec958_active(ice->cs8427, 1); |
| 376 | } |
| 377 | |
| 378 | static void close_cs8427(struct snd_ice1712 *ice, struct snd_pcm_substream *substream) |
| 379 | { |
| 380 | snd_cs8427_iec958_active(ice->cs8427, 0); |
| 381 | } |
| 382 | |
| 383 | static void setup_cs8427(struct snd_ice1712 *ice, int rate) |
| 384 | { |
| 385 | snd_cs8427_iec958_pcm(ice->cs8427, rate); |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * create and initialize callbacks for cs8427 interface |
| 390 | */ |
| 391 | int __devinit snd_ice1712_init_cs8427(struct snd_ice1712 *ice, int addr) |
| 392 | { |
| 393 | int err; |
| 394 | |
| 395 | err = snd_cs8427_create(ice->i2c, addr, |
| 396 | (ice->cs8427_timeout * HZ) / 1000, &ice->cs8427); |
| 397 | if (err < 0) { |
| 398 | snd_printk(KERN_ERR "CS8427 initialization failed\n"); |
| 399 | return err; |
| 400 | } |
| 401 | ice->spdif.ops.open = open_cs8427; |
| 402 | ice->spdif.ops.close = close_cs8427; |
| 403 | ice->spdif.ops.setup_rate = setup_cs8427; |
| 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static void snd_ice1712_set_input_clock_source(struct snd_ice1712 *ice, int spdif_is_master) |
| 408 | { |
| 409 | /* change CS8427 clock source too */ |
| 410 | if (ice->cs8427) |
| 411 | snd_ice1712_cs8427_set_input_clock(ice, spdif_is_master); |
| 412 | /* notify ak4524 chip as well */ |
| 413 | if (spdif_is_master) { |
| 414 | unsigned int i; |
| 415 | for (i = 0; i < ice->akm_codecs; i++) { |
| 416 | if (ice->akm[i].ops.set_rate_val) |
| 417 | ice->akm[i].ops.set_rate_val(&ice->akm[i], 0); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Interrupt handler |
| 424 | */ |
| 425 | |
| 426 | static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id) |
| 427 | { |
| 428 | struct snd_ice1712 *ice = dev_id; |
| 429 | unsigned char status; |
| 430 | int handled = 0; |
| 431 | |
| 432 | while (1) { |
| 433 | status = inb(ICEREG(ice, IRQSTAT)); |
| 434 | if (status == 0) |
| 435 | break; |
| 436 | handled = 1; |
| 437 | if (status & ICE1712_IRQ_MPU1) { |
| 438 | if (ice->rmidi[0]) |
| 439 | snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data); |
| 440 | outb(ICE1712_IRQ_MPU1, ICEREG(ice, IRQSTAT)); |
| 441 | status &= ~ICE1712_IRQ_MPU1; |
| 442 | } |
| 443 | if (status & ICE1712_IRQ_TIMER) |
| 444 | outb(ICE1712_IRQ_TIMER, ICEREG(ice, IRQSTAT)); |
| 445 | if (status & ICE1712_IRQ_MPU2) { |
| 446 | if (ice->rmidi[1]) |
| 447 | snd_mpu401_uart_interrupt(irq, ice->rmidi[1]->private_data); |
| 448 | outb(ICE1712_IRQ_MPU2, ICEREG(ice, IRQSTAT)); |
| 449 | status &= ~ICE1712_IRQ_MPU2; |
| 450 | } |
| 451 | if (status & ICE1712_IRQ_PROPCM) { |
| 452 | unsigned char mtstat = inb(ICEMT(ice, IRQ)); |
| 453 | if (mtstat & ICE1712_MULTI_PBKSTATUS) { |
| 454 | if (ice->playback_pro_substream) |
| 455 | snd_pcm_period_elapsed(ice->playback_pro_substream); |
| 456 | outb(ICE1712_MULTI_PBKSTATUS, ICEMT(ice, IRQ)); |
| 457 | } |
| 458 | if (mtstat & ICE1712_MULTI_CAPSTATUS) { |
| 459 | if (ice->capture_pro_substream) |
| 460 | snd_pcm_period_elapsed(ice->capture_pro_substream); |
| 461 | outb(ICE1712_MULTI_CAPSTATUS, ICEMT(ice, IRQ)); |
| 462 | } |
| 463 | } |
| 464 | if (status & ICE1712_IRQ_FM) |
| 465 | outb(ICE1712_IRQ_FM, ICEREG(ice, IRQSTAT)); |
| 466 | if (status & ICE1712_IRQ_PBKDS) { |
| 467 | u32 idx; |
| 468 | u16 pbkstatus; |
| 469 | struct snd_pcm_substream *substream; |
| 470 | pbkstatus = inw(ICEDS(ice, INTSTAT)); |
| 471 | /* printk(KERN_DEBUG "pbkstatus = 0x%x\n", pbkstatus); */ |
| 472 | for (idx = 0; idx < 6; idx++) { |
| 473 | if ((pbkstatus & (3 << (idx * 2))) == 0) |
| 474 | continue; |
| 475 | substream = ice->playback_con_substream_ds[idx]; |
| 476 | if (substream != NULL) |
| 477 | snd_pcm_period_elapsed(substream); |
| 478 | outw(3 << (idx * 2), ICEDS(ice, INTSTAT)); |
| 479 | } |
| 480 | outb(ICE1712_IRQ_PBKDS, ICEREG(ice, IRQSTAT)); |
| 481 | } |
| 482 | if (status & ICE1712_IRQ_CONCAP) { |
| 483 | if (ice->capture_con_substream) |
| 484 | snd_pcm_period_elapsed(ice->capture_con_substream); |
| 485 | outb(ICE1712_IRQ_CONCAP, ICEREG(ice, IRQSTAT)); |
| 486 | } |
| 487 | if (status & ICE1712_IRQ_CONPBK) { |
| 488 | if (ice->playback_con_substream) |
| 489 | snd_pcm_period_elapsed(ice->playback_con_substream); |
| 490 | outb(ICE1712_IRQ_CONPBK, ICEREG(ice, IRQSTAT)); |
| 491 | } |
| 492 | } |
| 493 | return IRQ_RETVAL(handled); |
| 494 | } |
| 495 | |
| 496 | |
| 497 | /* |
| 498 | * PCM part - misc |
| 499 | */ |
| 500 | |
| 501 | static int snd_ice1712_hw_params(struct snd_pcm_substream *substream, |
| 502 | struct snd_pcm_hw_params *hw_params) |
| 503 | { |
| 504 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 505 | } |
| 506 | |
| 507 | static int snd_ice1712_hw_free(struct snd_pcm_substream *substream) |
| 508 | { |
| 509 | return snd_pcm_lib_free_pages(substream); |
| 510 | } |
| 511 | |
| 512 | /* |
| 513 | * PCM part - consumer I/O |
| 514 | */ |
| 515 | |
| 516 | static int snd_ice1712_playback_trigger(struct snd_pcm_substream *substream, |
| 517 | int cmd) |
| 518 | { |
| 519 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 520 | int result = 0; |
| 521 | u32 tmp; |
| 522 | |
| 523 | spin_lock(&ice->reg_lock); |
| 524 | tmp = snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL); |
| 525 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 526 | tmp |= 1; |
| 527 | } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
| 528 | tmp &= ~1; |
| 529 | } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) { |
| 530 | tmp |= 2; |
| 531 | } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) { |
| 532 | tmp &= ~2; |
| 533 | } else { |
| 534 | result = -EINVAL; |
| 535 | } |
| 536 | snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp); |
| 537 | spin_unlock(&ice->reg_lock); |
| 538 | return result; |
| 539 | } |
| 540 | |
| 541 | static int snd_ice1712_playback_ds_trigger(struct snd_pcm_substream *substream, |
| 542 | int cmd) |
| 543 | { |
| 544 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 545 | int result = 0; |
| 546 | u32 tmp; |
| 547 | |
| 548 | spin_lock(&ice->reg_lock); |
| 549 | tmp = snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL); |
| 550 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 551 | tmp |= 1; |
| 552 | } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
| 553 | tmp &= ~1; |
| 554 | } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) { |
| 555 | tmp |= 2; |
| 556 | } else if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE) { |
| 557 | tmp &= ~2; |
| 558 | } else { |
| 559 | result = -EINVAL; |
| 560 | } |
| 561 | snd_ice1712_ds_write(ice, substream->number * 2, ICE1712_DSC_CONTROL, tmp); |
| 562 | spin_unlock(&ice->reg_lock); |
| 563 | return result; |
| 564 | } |
| 565 | |
| 566 | static int snd_ice1712_capture_trigger(struct snd_pcm_substream *substream, |
| 567 | int cmd) |
| 568 | { |
| 569 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 570 | int result = 0; |
| 571 | u8 tmp; |
| 572 | |
| 573 | spin_lock(&ice->reg_lock); |
| 574 | tmp = snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL); |
| 575 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 576 | tmp |= 1; |
| 577 | } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
| 578 | tmp &= ~1; |
| 579 | } else { |
| 580 | result = -EINVAL; |
| 581 | } |
| 582 | snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp); |
| 583 | spin_unlock(&ice->reg_lock); |
| 584 | return result; |
| 585 | } |
| 586 | |
| 587 | static int snd_ice1712_playback_prepare(struct snd_pcm_substream *substream) |
| 588 | { |
| 589 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 590 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 591 | u32 period_size, buf_size, rate, tmp; |
| 592 | |
| 593 | period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1; |
| 594 | buf_size = snd_pcm_lib_buffer_bytes(substream) - 1; |
| 595 | tmp = 0x0000; |
| 596 | if (snd_pcm_format_width(runtime->format) == 16) |
| 597 | tmp |= 0x10; |
| 598 | if (runtime->channels == 2) |
| 599 | tmp |= 0x08; |
| 600 | rate = (runtime->rate * 8192) / 375; |
| 601 | if (rate > 0x000fffff) |
| 602 | rate = 0x000fffff; |
| 603 | spin_lock_irq(&ice->reg_lock); |
| 604 | outb(0, ice->ddma_port + 15); |
| 605 | outb(ICE1712_DMA_MODE_WRITE | ICE1712_DMA_AUTOINIT, ice->ddma_port + 0x0b); |
| 606 | outl(runtime->dma_addr, ice->ddma_port + 0); |
| 607 | outw(buf_size, ice->ddma_port + 4); |
| 608 | snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_LO, rate & 0xff); |
| 609 | snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_MID, (rate >> 8) & 0xff); |
| 610 | snd_ice1712_write(ice, ICE1712_IREG_PBK_RATE_HI, (rate >> 16) & 0xff); |
| 611 | snd_ice1712_write(ice, ICE1712_IREG_PBK_CTRL, tmp); |
| 612 | snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_LO, period_size & 0xff); |
| 613 | snd_ice1712_write(ice, ICE1712_IREG_PBK_COUNT_HI, period_size >> 8); |
| 614 | snd_ice1712_write(ice, ICE1712_IREG_PBK_LEFT, 0); |
| 615 | snd_ice1712_write(ice, ICE1712_IREG_PBK_RIGHT, 0); |
| 616 | spin_unlock_irq(&ice->reg_lock); |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int snd_ice1712_playback_ds_prepare(struct snd_pcm_substream *substream) |
| 621 | { |
| 622 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 623 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 624 | u32 period_size, buf_size, rate, tmp, chn; |
| 625 | |
| 626 | period_size = snd_pcm_lib_period_bytes(substream) - 1; |
| 627 | buf_size = snd_pcm_lib_buffer_bytes(substream) - 1; |
| 628 | tmp = 0x0064; |
| 629 | if (snd_pcm_format_width(runtime->format) == 16) |
| 630 | tmp &= ~0x04; |
| 631 | if (runtime->channels == 2) |
| 632 | tmp |= 0x08; |
| 633 | rate = (runtime->rate * 8192) / 375; |
| 634 | if (rate > 0x000fffff) |
| 635 | rate = 0x000fffff; |
| 636 | ice->playback_con_active_buf[substream->number] = 0; |
| 637 | ice->playback_con_virt_addr[substream->number] = runtime->dma_addr; |
| 638 | chn = substream->number * 2; |
| 639 | spin_lock_irq(&ice->reg_lock); |
| 640 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR0, runtime->dma_addr); |
| 641 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT0, period_size); |
| 642 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_ADDR1, runtime->dma_addr + (runtime->periods > 1 ? period_size + 1 : 0)); |
| 643 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_COUNT1, period_size); |
| 644 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_RATE, rate); |
| 645 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_VOLUME, 0); |
| 646 | snd_ice1712_ds_write(ice, chn, ICE1712_DSC_CONTROL, tmp); |
| 647 | if (runtime->channels == 2) { |
| 648 | snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_RATE, rate); |
| 649 | snd_ice1712_ds_write(ice, chn + 1, ICE1712_DSC_VOLUME, 0); |
| 650 | } |
| 651 | spin_unlock_irq(&ice->reg_lock); |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int snd_ice1712_capture_prepare(struct snd_pcm_substream *substream) |
| 656 | { |
| 657 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 658 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 659 | u32 period_size, buf_size; |
| 660 | u8 tmp; |
| 661 | |
| 662 | period_size = (snd_pcm_lib_period_bytes(substream) >> 2) - 1; |
| 663 | buf_size = snd_pcm_lib_buffer_bytes(substream) - 1; |
| 664 | tmp = 0x06; |
| 665 | if (snd_pcm_format_width(runtime->format) == 16) |
| 666 | tmp &= ~0x04; |
| 667 | if (runtime->channels == 2) |
| 668 | tmp &= ~0x02; |
| 669 | spin_lock_irq(&ice->reg_lock); |
| 670 | outl(ice->capture_con_virt_addr = runtime->dma_addr, ICEREG(ice, CONCAP_ADDR)); |
| 671 | outw(buf_size, ICEREG(ice, CONCAP_COUNT)); |
| 672 | snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_HI, period_size >> 8); |
| 673 | snd_ice1712_write(ice, ICE1712_IREG_CAP_COUNT_LO, period_size & 0xff); |
| 674 | snd_ice1712_write(ice, ICE1712_IREG_CAP_CTRL, tmp); |
| 675 | spin_unlock_irq(&ice->reg_lock); |
| 676 | snd_ac97_set_rate(ice->ac97, AC97_PCM_LR_ADC_RATE, runtime->rate); |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | static snd_pcm_uframes_t snd_ice1712_playback_pointer(struct snd_pcm_substream *substream) |
| 681 | { |
| 682 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 683 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 684 | size_t ptr; |
| 685 | |
| 686 | if (!(snd_ice1712_read(ice, ICE1712_IREG_PBK_CTRL) & 1)) |
| 687 | return 0; |
| 688 | ptr = runtime->buffer_size - inw(ice->ddma_port + 4); |
| 689 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 690 | if (ptr == runtime->buffer_size) |
| 691 | ptr = 0; |
| 692 | return ptr; |
| 693 | } |
| 694 | |
| 695 | static snd_pcm_uframes_t snd_ice1712_playback_ds_pointer(struct snd_pcm_substream *substream) |
| 696 | { |
| 697 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 698 | u8 addr; |
| 699 | size_t ptr; |
| 700 | |
| 701 | if (!(snd_ice1712_ds_read(ice, substream->number * 2, ICE1712_DSC_CONTROL) & 1)) |
| 702 | return 0; |
| 703 | if (ice->playback_con_active_buf[substream->number]) |
| 704 | addr = ICE1712_DSC_ADDR1; |
| 705 | else |
| 706 | addr = ICE1712_DSC_ADDR0; |
| 707 | ptr = snd_ice1712_ds_read(ice, substream->number * 2, addr) - |
| 708 | ice->playback_con_virt_addr[substream->number]; |
| 709 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 710 | if (ptr == substream->runtime->buffer_size) |
| 711 | ptr = 0; |
| 712 | return ptr; |
| 713 | } |
| 714 | |
| 715 | static snd_pcm_uframes_t snd_ice1712_capture_pointer(struct snd_pcm_substream *substream) |
| 716 | { |
| 717 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 718 | size_t ptr; |
| 719 | |
| 720 | if (!(snd_ice1712_read(ice, ICE1712_IREG_CAP_CTRL) & 1)) |
| 721 | return 0; |
| 722 | ptr = inl(ICEREG(ice, CONCAP_ADDR)) - ice->capture_con_virt_addr; |
| 723 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 724 | if (ptr == substream->runtime->buffer_size) |
| 725 | ptr = 0; |
| 726 | return ptr; |
| 727 | } |
| 728 | |
| 729 | static const struct snd_pcm_hardware snd_ice1712_playback = { |
| 730 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 731 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 732 | SNDRV_PCM_INFO_MMAP_VALID | |
| 733 | SNDRV_PCM_INFO_PAUSE), |
| 734 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 735 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 736 | .rate_min = 4000, |
| 737 | .rate_max = 48000, |
| 738 | .channels_min = 1, |
| 739 | .channels_max = 2, |
| 740 | .buffer_bytes_max = (64*1024), |
| 741 | .period_bytes_min = 64, |
| 742 | .period_bytes_max = (64*1024), |
| 743 | .periods_min = 1, |
| 744 | .periods_max = 1024, |
| 745 | .fifo_size = 0, |
| 746 | }; |
| 747 | |
| 748 | static const struct snd_pcm_hardware snd_ice1712_playback_ds = { |
| 749 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 750 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 751 | SNDRV_PCM_INFO_MMAP_VALID | |
| 752 | SNDRV_PCM_INFO_PAUSE), |
| 753 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 754 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 755 | .rate_min = 4000, |
| 756 | .rate_max = 48000, |
| 757 | .channels_min = 1, |
| 758 | .channels_max = 2, |
| 759 | .buffer_bytes_max = (128*1024), |
| 760 | .period_bytes_min = 64, |
| 761 | .period_bytes_max = (128*1024), |
| 762 | .periods_min = 2, |
| 763 | .periods_max = 2, |
| 764 | .fifo_size = 0, |
| 765 | }; |
| 766 | |
| 767 | static const struct snd_pcm_hardware snd_ice1712_capture = { |
| 768 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 769 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 770 | SNDRV_PCM_INFO_MMAP_VALID), |
| 771 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 772 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 773 | .rate_min = 4000, |
| 774 | .rate_max = 48000, |
| 775 | .channels_min = 1, |
| 776 | .channels_max = 2, |
| 777 | .buffer_bytes_max = (64*1024), |
| 778 | .period_bytes_min = 64, |
| 779 | .period_bytes_max = (64*1024), |
| 780 | .periods_min = 1, |
| 781 | .periods_max = 1024, |
| 782 | .fifo_size = 0, |
| 783 | }; |
| 784 | |
| 785 | static int snd_ice1712_playback_open(struct snd_pcm_substream *substream) |
| 786 | { |
| 787 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 788 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 789 | |
| 790 | ice->playback_con_substream = substream; |
| 791 | runtime->hw = snd_ice1712_playback; |
| 792 | return 0; |
| 793 | } |
| 794 | |
| 795 | static int snd_ice1712_playback_ds_open(struct snd_pcm_substream *substream) |
| 796 | { |
| 797 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 798 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 799 | u32 tmp; |
| 800 | |
| 801 | ice->playback_con_substream_ds[substream->number] = substream; |
| 802 | runtime->hw = snd_ice1712_playback_ds; |
| 803 | spin_lock_irq(&ice->reg_lock); |
| 804 | tmp = inw(ICEDS(ice, INTMASK)) & ~(1 << (substream->number * 2)); |
| 805 | outw(tmp, ICEDS(ice, INTMASK)); |
| 806 | spin_unlock_irq(&ice->reg_lock); |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | static int snd_ice1712_capture_open(struct snd_pcm_substream *substream) |
| 811 | { |
| 812 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 813 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 814 | |
| 815 | ice->capture_con_substream = substream; |
| 816 | runtime->hw = snd_ice1712_capture; |
| 817 | runtime->hw.rates = ice->ac97->rates[AC97_RATES_ADC]; |
| 818 | if (!(runtime->hw.rates & SNDRV_PCM_RATE_8000)) |
| 819 | runtime->hw.rate_min = 48000; |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | static int snd_ice1712_playback_close(struct snd_pcm_substream *substream) |
| 824 | { |
| 825 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 826 | |
| 827 | ice->playback_con_substream = NULL; |
| 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | static int snd_ice1712_playback_ds_close(struct snd_pcm_substream *substream) |
| 832 | { |
| 833 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 834 | u32 tmp; |
| 835 | |
| 836 | spin_lock_irq(&ice->reg_lock); |
| 837 | tmp = inw(ICEDS(ice, INTMASK)) | (3 << (substream->number * 2)); |
| 838 | outw(tmp, ICEDS(ice, INTMASK)); |
| 839 | spin_unlock_irq(&ice->reg_lock); |
| 840 | ice->playback_con_substream_ds[substream->number] = NULL; |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | static int snd_ice1712_capture_close(struct snd_pcm_substream *substream) |
| 845 | { |
| 846 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 847 | |
| 848 | ice->capture_con_substream = NULL; |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | static struct snd_pcm_ops snd_ice1712_playback_ops = { |
| 853 | .open = snd_ice1712_playback_open, |
| 854 | .close = snd_ice1712_playback_close, |
| 855 | .ioctl = snd_pcm_lib_ioctl, |
| 856 | .hw_params = snd_ice1712_hw_params, |
| 857 | .hw_free = snd_ice1712_hw_free, |
| 858 | .prepare = snd_ice1712_playback_prepare, |
| 859 | .trigger = snd_ice1712_playback_trigger, |
| 860 | .pointer = snd_ice1712_playback_pointer, |
| 861 | }; |
| 862 | |
| 863 | static struct snd_pcm_ops snd_ice1712_playback_ds_ops = { |
| 864 | .open = snd_ice1712_playback_ds_open, |
| 865 | .close = snd_ice1712_playback_ds_close, |
| 866 | .ioctl = snd_pcm_lib_ioctl, |
| 867 | .hw_params = snd_ice1712_hw_params, |
| 868 | .hw_free = snd_ice1712_hw_free, |
| 869 | .prepare = snd_ice1712_playback_ds_prepare, |
| 870 | .trigger = snd_ice1712_playback_ds_trigger, |
| 871 | .pointer = snd_ice1712_playback_ds_pointer, |
| 872 | }; |
| 873 | |
| 874 | static struct snd_pcm_ops snd_ice1712_capture_ops = { |
| 875 | .open = snd_ice1712_capture_open, |
| 876 | .close = snd_ice1712_capture_close, |
| 877 | .ioctl = snd_pcm_lib_ioctl, |
| 878 | .hw_params = snd_ice1712_hw_params, |
| 879 | .hw_free = snd_ice1712_hw_free, |
| 880 | .prepare = snd_ice1712_capture_prepare, |
| 881 | .trigger = snd_ice1712_capture_trigger, |
| 882 | .pointer = snd_ice1712_capture_pointer, |
| 883 | }; |
| 884 | |
| 885 | static int __devinit snd_ice1712_pcm(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm) |
| 886 | { |
| 887 | struct snd_pcm *pcm; |
| 888 | int err; |
| 889 | |
| 890 | if (rpcm) |
| 891 | *rpcm = NULL; |
| 892 | err = snd_pcm_new(ice->card, "ICE1712 consumer", device, 1, 1, &pcm); |
| 893 | if (err < 0) |
| 894 | return err; |
| 895 | |
| 896 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ops); |
| 897 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_ops); |
| 898 | |
| 899 | pcm->private_data = ice; |
| 900 | pcm->info_flags = 0; |
| 901 | strcpy(pcm->name, "ICE1712 consumer"); |
| 902 | ice->pcm = pcm; |
| 903 | |
| 904 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 905 | snd_dma_pci_data(ice->pci), 64*1024, 64*1024); |
| 906 | |
| 907 | if (rpcm) |
| 908 | *rpcm = pcm; |
| 909 | |
| 910 | printk(KERN_WARNING "Consumer PCM code does not work well at the moment --jk\n"); |
| 911 | |
| 912 | return 0; |
| 913 | } |
| 914 | |
| 915 | static int __devinit snd_ice1712_pcm_ds(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm) |
| 916 | { |
| 917 | struct snd_pcm *pcm; |
| 918 | int err; |
| 919 | |
| 920 | if (rpcm) |
| 921 | *rpcm = NULL; |
| 922 | err = snd_pcm_new(ice->card, "ICE1712 consumer (DS)", device, 6, 0, &pcm); |
| 923 | if (err < 0) |
| 924 | return err; |
| 925 | |
| 926 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_ds_ops); |
| 927 | |
| 928 | pcm->private_data = ice; |
| 929 | pcm->info_flags = 0; |
| 930 | strcpy(pcm->name, "ICE1712 consumer (DS)"); |
| 931 | ice->pcm_ds = pcm; |
| 932 | |
| 933 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 934 | snd_dma_pci_data(ice->pci), 64*1024, 128*1024); |
| 935 | |
| 936 | if (rpcm) |
| 937 | *rpcm = pcm; |
| 938 | |
| 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | /* |
| 943 | * PCM code - professional part (multitrack) |
| 944 | */ |
| 945 | |
| 946 | static unsigned int rates[] = { 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
| 947 | 32000, 44100, 48000, 64000, 88200, 96000 }; |
| 948 | |
| 949 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
| 950 | .count = ARRAY_SIZE(rates), |
| 951 | .list = rates, |
| 952 | .mask = 0, |
| 953 | }; |
| 954 | |
| 955 | static int snd_ice1712_pro_trigger(struct snd_pcm_substream *substream, |
| 956 | int cmd) |
| 957 | { |
| 958 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 959 | switch (cmd) { |
| 960 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 961 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 962 | { |
| 963 | unsigned int what; |
| 964 | unsigned int old; |
| 965 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 966 | return -EINVAL; |
| 967 | what = ICE1712_PLAYBACK_PAUSE; |
| 968 | snd_pcm_trigger_done(substream, substream); |
| 969 | spin_lock(&ice->reg_lock); |
| 970 | old = inl(ICEMT(ice, PLAYBACK_CONTROL)); |
| 971 | if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) |
| 972 | old |= what; |
| 973 | else |
| 974 | old &= ~what; |
| 975 | outl(old, ICEMT(ice, PLAYBACK_CONTROL)); |
| 976 | spin_unlock(&ice->reg_lock); |
| 977 | break; |
| 978 | } |
| 979 | case SNDRV_PCM_TRIGGER_START: |
| 980 | case SNDRV_PCM_TRIGGER_STOP: |
| 981 | { |
| 982 | unsigned int what = 0; |
| 983 | unsigned int old; |
| 984 | struct snd_pcm_substream *s; |
| 985 | |
| 986 | snd_pcm_group_for_each_entry(s, substream) { |
| 987 | if (s == ice->playback_pro_substream) { |
| 988 | what |= ICE1712_PLAYBACK_START; |
| 989 | snd_pcm_trigger_done(s, substream); |
| 990 | } else if (s == ice->capture_pro_substream) { |
| 991 | what |= ICE1712_CAPTURE_START_SHADOW; |
| 992 | snd_pcm_trigger_done(s, substream); |
| 993 | } |
| 994 | } |
| 995 | spin_lock(&ice->reg_lock); |
| 996 | old = inl(ICEMT(ice, PLAYBACK_CONTROL)); |
| 997 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 998 | old |= what; |
| 999 | else |
| 1000 | old &= ~what; |
| 1001 | outl(old, ICEMT(ice, PLAYBACK_CONTROL)); |
| 1002 | spin_unlock(&ice->reg_lock); |
| 1003 | break; |
| 1004 | } |
| 1005 | default: |
| 1006 | return -EINVAL; |
| 1007 | } |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | */ |
| 1013 | static void snd_ice1712_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, int force) |
| 1014 | { |
| 1015 | unsigned long flags; |
| 1016 | unsigned char val, old; |
| 1017 | unsigned int i; |
| 1018 | |
| 1019 | switch (rate) { |
| 1020 | case 8000: val = 6; break; |
| 1021 | case 9600: val = 3; break; |
| 1022 | case 11025: val = 10; break; |
| 1023 | case 12000: val = 2; break; |
| 1024 | case 16000: val = 5; break; |
| 1025 | case 22050: val = 9; break; |
| 1026 | case 24000: val = 1; break; |
| 1027 | case 32000: val = 4; break; |
| 1028 | case 44100: val = 8; break; |
| 1029 | case 48000: val = 0; break; |
| 1030 | case 64000: val = 15; break; |
| 1031 | case 88200: val = 11; break; |
| 1032 | case 96000: val = 7; break; |
| 1033 | default: |
| 1034 | snd_BUG(); |
| 1035 | val = 0; |
| 1036 | rate = 48000; |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | spin_lock_irqsave(&ice->reg_lock, flags); |
| 1041 | if (inb(ICEMT(ice, PLAYBACK_CONTROL)) & (ICE1712_CAPTURE_START_SHADOW| |
| 1042 | ICE1712_PLAYBACK_PAUSE| |
| 1043 | ICE1712_PLAYBACK_START)) { |
| 1044 | __out: |
| 1045 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 1046 | return; |
| 1047 | } |
| 1048 | if (!force && is_pro_rate_locked(ice)) |
| 1049 | goto __out; |
| 1050 | |
| 1051 | old = inb(ICEMT(ice, RATE)); |
| 1052 | if (!force && old == val) |
| 1053 | goto __out; |
| 1054 | outb(val, ICEMT(ice, RATE)); |
| 1055 | spin_unlock_irqrestore(&ice->reg_lock, flags); |
| 1056 | |
| 1057 | if (ice->gpio.set_pro_rate) |
| 1058 | ice->gpio.set_pro_rate(ice, rate); |
| 1059 | for (i = 0; i < ice->akm_codecs; i++) { |
| 1060 | if (ice->akm[i].ops.set_rate_val) |
| 1061 | ice->akm[i].ops.set_rate_val(&ice->akm[i], rate); |
| 1062 | } |
| 1063 | if (ice->spdif.ops.setup_rate) |
| 1064 | ice->spdif.ops.setup_rate(ice, rate); |
| 1065 | } |
| 1066 | |
| 1067 | static int snd_ice1712_playback_pro_prepare(struct snd_pcm_substream *substream) |
| 1068 | { |
| 1069 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1070 | |
| 1071 | ice->playback_pro_size = snd_pcm_lib_buffer_bytes(substream); |
| 1072 | spin_lock_irq(&ice->reg_lock); |
| 1073 | outl(substream->runtime->dma_addr, ICEMT(ice, PLAYBACK_ADDR)); |
| 1074 | outw((ice->playback_pro_size >> 2) - 1, ICEMT(ice, PLAYBACK_SIZE)); |
| 1075 | outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, PLAYBACK_COUNT)); |
| 1076 | spin_unlock_irq(&ice->reg_lock); |
| 1077 | |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | static int snd_ice1712_playback_pro_hw_params(struct snd_pcm_substream *substream, |
| 1082 | struct snd_pcm_hw_params *hw_params) |
| 1083 | { |
| 1084 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1085 | |
| 1086 | snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0); |
| 1087 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 1088 | } |
| 1089 | |
| 1090 | static int snd_ice1712_capture_pro_prepare(struct snd_pcm_substream *substream) |
| 1091 | { |
| 1092 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1093 | |
| 1094 | ice->capture_pro_size = snd_pcm_lib_buffer_bytes(substream); |
| 1095 | spin_lock_irq(&ice->reg_lock); |
| 1096 | outl(substream->runtime->dma_addr, ICEMT(ice, CAPTURE_ADDR)); |
| 1097 | outw((ice->capture_pro_size >> 2) - 1, ICEMT(ice, CAPTURE_SIZE)); |
| 1098 | outw((snd_pcm_lib_period_bytes(substream) >> 2) - 1, ICEMT(ice, CAPTURE_COUNT)); |
| 1099 | spin_unlock_irq(&ice->reg_lock); |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | static int snd_ice1712_capture_pro_hw_params(struct snd_pcm_substream *substream, |
| 1104 | struct snd_pcm_hw_params *hw_params) |
| 1105 | { |
| 1106 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1107 | |
| 1108 | snd_ice1712_set_pro_rate(ice, params_rate(hw_params), 0); |
| 1109 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 1110 | } |
| 1111 | |
| 1112 | static snd_pcm_uframes_t snd_ice1712_playback_pro_pointer(struct snd_pcm_substream *substream) |
| 1113 | { |
| 1114 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1115 | size_t ptr; |
| 1116 | |
| 1117 | if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_PLAYBACK_START)) |
| 1118 | return 0; |
| 1119 | ptr = ice->playback_pro_size - (inw(ICEMT(ice, PLAYBACK_SIZE)) << 2); |
| 1120 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 1121 | if (ptr == substream->runtime->buffer_size) |
| 1122 | ptr = 0; |
| 1123 | return ptr; |
| 1124 | } |
| 1125 | |
| 1126 | static snd_pcm_uframes_t snd_ice1712_capture_pro_pointer(struct snd_pcm_substream *substream) |
| 1127 | { |
| 1128 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1129 | size_t ptr; |
| 1130 | |
| 1131 | if (!(inl(ICEMT(ice, PLAYBACK_CONTROL)) & ICE1712_CAPTURE_START_SHADOW)) |
| 1132 | return 0; |
| 1133 | ptr = ice->capture_pro_size - (inw(ICEMT(ice, CAPTURE_SIZE)) << 2); |
| 1134 | ptr = bytes_to_frames(substream->runtime, ptr); |
| 1135 | if (ptr == substream->runtime->buffer_size) |
| 1136 | ptr = 0; |
| 1137 | return ptr; |
| 1138 | } |
| 1139 | |
| 1140 | static const struct snd_pcm_hardware snd_ice1712_playback_pro = { |
| 1141 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1142 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1143 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1144 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), |
| 1145 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 1146 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000, |
| 1147 | .rate_min = 4000, |
| 1148 | .rate_max = 96000, |
| 1149 | .channels_min = 10, |
| 1150 | .channels_max = 10, |
| 1151 | .buffer_bytes_max = (256*1024), |
| 1152 | .period_bytes_min = 10 * 4 * 2, |
| 1153 | .period_bytes_max = 131040, |
| 1154 | .periods_min = 1, |
| 1155 | .periods_max = 1024, |
| 1156 | .fifo_size = 0, |
| 1157 | }; |
| 1158 | |
| 1159 | static const struct snd_pcm_hardware snd_ice1712_capture_pro = { |
| 1160 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1161 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1162 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1163 | SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_SYNC_START), |
| 1164 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 1165 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_96000, |
| 1166 | .rate_min = 4000, |
| 1167 | .rate_max = 96000, |
| 1168 | .channels_min = 12, |
| 1169 | .channels_max = 12, |
| 1170 | .buffer_bytes_max = (256*1024), |
| 1171 | .period_bytes_min = 12 * 4 * 2, |
| 1172 | .period_bytes_max = 131040, |
| 1173 | .periods_min = 1, |
| 1174 | .periods_max = 1024, |
| 1175 | .fifo_size = 0, |
| 1176 | }; |
| 1177 | |
| 1178 | static int snd_ice1712_playback_pro_open(struct snd_pcm_substream *substream) |
| 1179 | { |
| 1180 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1181 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1182 | |
| 1183 | ice->playback_pro_substream = substream; |
| 1184 | runtime->hw = snd_ice1712_playback_pro; |
| 1185 | snd_pcm_set_sync(substream); |
| 1186 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1187 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); |
| 1188 | if (is_pro_rate_locked(ice)) { |
| 1189 | runtime->hw.rate_min = PRO_RATE_DEFAULT; |
| 1190 | runtime->hw.rate_max = PRO_RATE_DEFAULT; |
| 1191 | } |
| 1192 | |
| 1193 | if (ice->spdif.ops.open) |
| 1194 | ice->spdif.ops.open(ice, substream); |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
| 1199 | static int snd_ice1712_capture_pro_open(struct snd_pcm_substream *substream) |
| 1200 | { |
| 1201 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1202 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1203 | |
| 1204 | ice->capture_pro_substream = substream; |
| 1205 | runtime->hw = snd_ice1712_capture_pro; |
| 1206 | snd_pcm_set_sync(substream); |
| 1207 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 1208 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); |
| 1209 | if (is_pro_rate_locked(ice)) { |
| 1210 | runtime->hw.rate_min = PRO_RATE_DEFAULT; |
| 1211 | runtime->hw.rate_max = PRO_RATE_DEFAULT; |
| 1212 | } |
| 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | static int snd_ice1712_playback_pro_close(struct snd_pcm_substream *substream) |
| 1218 | { |
| 1219 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1220 | |
| 1221 | if (PRO_RATE_RESET) |
| 1222 | snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); |
| 1223 | ice->playback_pro_substream = NULL; |
| 1224 | if (ice->spdif.ops.close) |
| 1225 | ice->spdif.ops.close(ice, substream); |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | static int snd_ice1712_capture_pro_close(struct snd_pcm_substream *substream) |
| 1231 | { |
| 1232 | struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); |
| 1233 | |
| 1234 | if (PRO_RATE_RESET) |
| 1235 | snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); |
| 1236 | ice->capture_pro_substream = NULL; |
| 1237 | return 0; |
| 1238 | } |
| 1239 | |
| 1240 | static struct snd_pcm_ops snd_ice1712_playback_pro_ops = { |
| 1241 | .open = snd_ice1712_playback_pro_open, |
| 1242 | .close = snd_ice1712_playback_pro_close, |
| 1243 | .ioctl = snd_pcm_lib_ioctl, |
| 1244 | .hw_params = snd_ice1712_playback_pro_hw_params, |
| 1245 | .hw_free = snd_ice1712_hw_free, |
| 1246 | .prepare = snd_ice1712_playback_pro_prepare, |
| 1247 | .trigger = snd_ice1712_pro_trigger, |
| 1248 | .pointer = snd_ice1712_playback_pro_pointer, |
| 1249 | }; |
| 1250 | |
| 1251 | static struct snd_pcm_ops snd_ice1712_capture_pro_ops = { |
| 1252 | .open = snd_ice1712_capture_pro_open, |
| 1253 | .close = snd_ice1712_capture_pro_close, |
| 1254 | .ioctl = snd_pcm_lib_ioctl, |
| 1255 | .hw_params = snd_ice1712_capture_pro_hw_params, |
| 1256 | .hw_free = snd_ice1712_hw_free, |
| 1257 | .prepare = snd_ice1712_capture_pro_prepare, |
| 1258 | .trigger = snd_ice1712_pro_trigger, |
| 1259 | .pointer = snd_ice1712_capture_pro_pointer, |
| 1260 | }; |
| 1261 | |
| 1262 | static int __devinit snd_ice1712_pcm_profi(struct snd_ice1712 *ice, int device, struct snd_pcm **rpcm) |
| 1263 | { |
| 1264 | struct snd_pcm *pcm; |
| 1265 | int err; |
| 1266 | |
| 1267 | if (rpcm) |
| 1268 | *rpcm = NULL; |
| 1269 | err = snd_pcm_new(ice->card, "ICE1712 multi", device, 1, 1, &pcm); |
| 1270 | if (err < 0) |
| 1271 | return err; |
| 1272 | |
| 1273 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ice1712_playback_pro_ops); |
| 1274 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ice1712_capture_pro_ops); |
| 1275 | |
| 1276 | pcm->private_data = ice; |
| 1277 | pcm->info_flags = 0; |
| 1278 | strcpy(pcm->name, "ICE1712 multi"); |
| 1279 | |
| 1280 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1281 | snd_dma_pci_data(ice->pci), 256*1024, 256*1024); |
| 1282 | |
| 1283 | ice->pcm_pro = pcm; |
| 1284 | if (rpcm) |
| 1285 | *rpcm = pcm; |
| 1286 | |
| 1287 | if (ice->cs8427) { |
| 1288 | /* assign channels to iec958 */ |
| 1289 | err = snd_cs8427_iec958_build(ice->cs8427, |
| 1290 | pcm->streams[0].substream, |
| 1291 | pcm->streams[1].substream); |
| 1292 | if (err < 0) |
| 1293 | return err; |
| 1294 | } |
| 1295 | |
| 1296 | err = snd_ice1712_build_pro_mixer(ice); |
| 1297 | if (err < 0) |
| 1298 | return err; |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
| 1302 | /* |
| 1303 | * Mixer section |
| 1304 | */ |
| 1305 | |
| 1306 | static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index) |
| 1307 | { |
| 1308 | unsigned int vol = ice->pro_volumes[index]; |
| 1309 | unsigned short val = 0; |
| 1310 | |
| 1311 | val |= (vol & 0x8000) == 0 ? (96 - (vol & 0x7f)) : 0x7f; |
| 1312 | val |= ((vol & 0x80000000) == 0 ? (96 - ((vol >> 16) & 0x7f)) : 0x7f) << 8; |
| 1313 | outb(index, ICEMT(ice, MONITOR_INDEX)); |
| 1314 | outw(val, ICEMT(ice, MONITOR_VOLUME)); |
| 1315 | } |
| 1316 | |
| 1317 | #define snd_ice1712_pro_mixer_switch_info snd_ctl_boolean_stereo_info |
| 1318 | |
| 1319 | static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1320 | { |
| 1321 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1322 | int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + |
| 1323 | kcontrol->private_value; |
| 1324 | |
| 1325 | spin_lock_irq(&ice->reg_lock); |
| 1326 | ucontrol->value.integer.value[0] = |
| 1327 | !((ice->pro_volumes[priv_idx] >> 15) & 1); |
| 1328 | ucontrol->value.integer.value[1] = |
| 1329 | !((ice->pro_volumes[priv_idx] >> 31) & 1); |
| 1330 | spin_unlock_irq(&ice->reg_lock); |
| 1331 | return 0; |
| 1332 | } |
| 1333 | |
| 1334 | static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1335 | { |
| 1336 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1337 | int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + |
| 1338 | kcontrol->private_value; |
| 1339 | unsigned int nval, change; |
| 1340 | |
| 1341 | nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) | |
| 1342 | (ucontrol->value.integer.value[1] ? 0 : 0x80000000); |
| 1343 | spin_lock_irq(&ice->reg_lock); |
| 1344 | nval |= ice->pro_volumes[priv_idx] & ~0x80008000; |
| 1345 | change = nval != ice->pro_volumes[priv_idx]; |
| 1346 | ice->pro_volumes[priv_idx] = nval; |
| 1347 | snd_ice1712_update_volume(ice, priv_idx); |
| 1348 | spin_unlock_irq(&ice->reg_lock); |
| 1349 | return change; |
| 1350 | } |
| 1351 | |
| 1352 | static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
| 1353 | { |
| 1354 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1355 | uinfo->count = 2; |
| 1356 | uinfo->value.integer.min = 0; |
| 1357 | uinfo->value.integer.max = 96; |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
| 1361 | static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1362 | { |
| 1363 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1364 | int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + |
| 1365 | kcontrol->private_value; |
| 1366 | |
| 1367 | spin_lock_irq(&ice->reg_lock); |
| 1368 | ucontrol->value.integer.value[0] = |
| 1369 | (ice->pro_volumes[priv_idx] >> 0) & 127; |
| 1370 | ucontrol->value.integer.value[1] = |
| 1371 | (ice->pro_volumes[priv_idx] >> 16) & 127; |
| 1372 | spin_unlock_irq(&ice->reg_lock); |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
| 1377 | { |
| 1378 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1379 | int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + |
| 1380 | kcontrol->private_value; |
| 1381 | unsigned int nval, change; |
| 1382 | |
| 1383 | nval = (ucontrol->value.integer.value[0] & 127) | |
| 1384 | ((ucontrol->value.integer.value[1] & 127) << 16); |
| 1385 | spin_lock_irq(&ice->reg_lock); |
| 1386 | nval |= ice->pro_volumes[priv_idx] & ~0x007f007f; |
| 1387 | change = nval != ice->pro_volumes[priv_idx]; |
| 1388 | ice->pro_volumes[priv_idx] = nval; |
| 1389 | snd_ice1712_update_volume(ice, priv_idx); |
| 1390 | spin_unlock_irq(&ice->reg_lock); |
| 1391 | return change; |
| 1392 | } |
| 1393 | |
| 1394 | static const DECLARE_TLV_DB_SCALE(db_scale_playback, -14400, 150, 0); |
| 1395 | |
| 1396 | static struct snd_kcontrol_new snd_ice1712_multi_playback_ctrls[] __devinitdata = { |
| 1397 | { |
| 1398 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1399 | .name = "Multi Playback Switch", |
| 1400 | .info = snd_ice1712_pro_mixer_switch_info, |
| 1401 | .get = snd_ice1712_pro_mixer_switch_get, |
| 1402 | .put = snd_ice1712_pro_mixer_switch_put, |
| 1403 | .private_value = 0, |
| 1404 | .count = 10, |
| 1405 | }, |
| 1406 | { |
| 1407 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1408 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1409 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 1410 | .name = "Multi Playback Volume", |
| 1411 | .info = snd_ice1712_pro_mixer_volume_info, |
| 1412 | .get = snd_ice1712_pro_mixer_volume_get, |
| 1413 | .put = snd_ice1712_pro_mixer_volume_put, |
| 1414 | .private_value = 0, |
| 1415 | .count = 10, |
| 1416 | .tlv = { .p = db_scale_playback } |
| 1417 | }, |
| 1418 | }; |
| 1419 | |
| 1420 | static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_switch __devinitdata = { |
| 1421 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1422 | .name = "H/W Multi Capture Switch", |
| 1423 | .info = snd_ice1712_pro_mixer_switch_info, |
| 1424 | .get = snd_ice1712_pro_mixer_switch_get, |
| 1425 | .put = snd_ice1712_pro_mixer_switch_put, |
| 1426 | .private_value = 10, |
| 1427 | }; |
| 1428 | |
| 1429 | static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_switch __devinitdata = { |
| 1430 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1431 | .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, SWITCH), |
| 1432 | .info = snd_ice1712_pro_mixer_switch_info, |
| 1433 | .get = snd_ice1712_pro_mixer_switch_get, |
| 1434 | .put = snd_ice1712_pro_mixer_switch_put, |
| 1435 | .private_value = 18, |
| 1436 | .count = 2, |
| 1437 | }; |
| 1438 | |
| 1439 | static struct snd_kcontrol_new snd_ice1712_multi_capture_analog_volume __devinitdata = { |
| 1440 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1441 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1442 | SNDRV_CTL_ELEM_ACCESS_TLV_READ), |
| 1443 | .name = "H/W Multi Capture Volume", |
| 1444 | .info = snd_ice1712_pro_mixer_volume_info, |
| 1445 | .get = snd_ice1712_pro_mixer_volume_get, |
| 1446 | .put = snd_ice1712_pro_mixer_volume_put, |
| 1447 | .private_value = 10, |
| 1448 | .tlv = { .p = db_scale_playback } |
| 1449 | }; |
| 1450 | |
| 1451 | static struct snd_kcontrol_new snd_ice1712_multi_capture_spdif_volume __devinitdata = { |
| 1452 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1453 | .name = SNDRV_CTL_NAME_IEC958("Multi ", CAPTURE, VOLUME), |
| 1454 | .info = snd_ice1712_pro_mixer_volume_info, |
| 1455 | .get = snd_ice1712_pro_mixer_volume_get, |
| 1456 | .put = snd_ice1712_pro_mixer_volume_put, |
| 1457 | .private_value = 18, |
| 1458 | .count = 2, |
| 1459 | }; |
| 1460 | |
| 1461 | static int __devinit snd_ice1712_build_pro_mixer(struct snd_ice1712 *ice) |
| 1462 | { |
| 1463 | struct snd_card *card = ice->card; |
| 1464 | unsigned int idx; |
| 1465 | int err; |
| 1466 | |
| 1467 | /* multi-channel mixer */ |
| 1468 | for (idx = 0; idx < ARRAY_SIZE(snd_ice1712_multi_playback_ctrls); idx++) { |
| 1469 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_playback_ctrls[idx], ice)); |
| 1470 | if (err < 0) |
| 1471 | return err; |
| 1472 | } |
| 1473 | |
| 1474 | if (ice->num_total_adcs > 0) { |
| 1475 | struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_switch; |
| 1476 | tmp.count = ice->num_total_adcs; |
| 1477 | err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice)); |
| 1478 | if (err < 0) |
| 1479 | return err; |
| 1480 | } |
| 1481 | |
| 1482 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_switch, ice)); |
| 1483 | if (err < 0) |
| 1484 | return err; |
| 1485 | |
| 1486 | if (ice->num_total_adcs > 0) { |
| 1487 | struct snd_kcontrol_new tmp = snd_ice1712_multi_capture_analog_volume; |
| 1488 | tmp.count = ice->num_total_adcs; |
| 1489 | err = snd_ctl_add(card, snd_ctl_new1(&tmp, ice)); |
| 1490 | if (err < 0) |
| 1491 | return err; |
| 1492 | } |
| 1493 | |
| 1494 | err = snd_ctl_add(card, snd_ctl_new1(&snd_ice1712_multi_capture_spdif_volume, ice)); |
| 1495 | if (err < 0) |
| 1496 | return err; |
| 1497 | |
| 1498 | /* initialize volumes */ |
| 1499 | for (idx = 0; idx < 10; idx++) { |
| 1500 | ice->pro_volumes[idx] = 0x80008000; /* mute */ |
| 1501 | snd_ice1712_update_volume(ice, idx); |
| 1502 | } |
| 1503 | for (idx = 10; idx < 10 + ice->num_total_adcs; idx++) { |
| 1504 | ice->pro_volumes[idx] = 0x80008000; /* mute */ |
| 1505 | snd_ice1712_update_volume(ice, idx); |
| 1506 | } |
| 1507 | for (idx = 18; idx < 20; idx++) { |
| 1508 | ice->pro_volumes[idx] = 0x80008000; /* mute */ |
| 1509 | snd_ice1712_update_volume(ice, idx); |
| 1510 | } |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | static void snd_ice1712_mixer_free_ac97(struct snd_ac97 *ac97) |
| 1515 | { |
| 1516 | struct snd_ice1712 *ice = ac97->private_data; |
| 1517 | ice->ac97 = NULL; |
| 1518 | } |
| 1519 | |
| 1520 | static int __devinit snd_ice1712_ac97_mixer(struct snd_ice1712 *ice) |
| 1521 | { |
| 1522 | int err, bus_num = 0; |
| 1523 | struct snd_ac97_template ac97; |
| 1524 | struct snd_ac97_bus *pbus; |
| 1525 | static struct snd_ac97_bus_ops con_ops = { |
| 1526 | .write = snd_ice1712_ac97_write, |
| 1527 | .read = snd_ice1712_ac97_read, |
| 1528 | }; |
| 1529 | static struct snd_ac97_bus_ops pro_ops = { |
| 1530 | .write = snd_ice1712_pro_ac97_write, |
| 1531 | .read = snd_ice1712_pro_ac97_read, |
| 1532 | }; |
| 1533 | |
| 1534 | if (ice_has_con_ac97(ice)) { |
| 1535 | err = snd_ac97_bus(ice->card, bus_num++, &con_ops, NULL, &pbus); |
| 1536 | if (err < 0) |
| 1537 | return err; |
| 1538 | memset(&ac97, 0, sizeof(ac97)); |
| 1539 | ac97.private_data = ice; |
| 1540 | ac97.private_free = snd_ice1712_mixer_free_ac97; |
| 1541 | err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); |
| 1542 | if (err < 0) |
| 1543 | printk(KERN_WARNING "ice1712: cannot initialize ac97 for consumer, skipped\n"); |
| 1544 | else { |
| 1545 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_digmix_route_ac97, ice)); |
| 1546 | if (err < 0) |
| 1547 | return err; |
| 1548 | return 0; |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | if (!(ice->eeprom.data[ICE_EEP1_ACLINK] & ICE1712_CFG_PRO_I2S)) { |
| 1553 | err = snd_ac97_bus(ice->card, bus_num, &pro_ops, NULL, &pbus); |
| 1554 | if (err < 0) |
| 1555 | return err; |
| 1556 | memset(&ac97, 0, sizeof(ac97)); |
| 1557 | ac97.private_data = ice; |
| 1558 | ac97.private_free = snd_ice1712_mixer_free_ac97; |
| 1559 | err = snd_ac97_mixer(pbus, &ac97, &ice->ac97); |
| 1560 | if (err < 0) |
| 1561 | printk(KERN_WARNING "ice1712: cannot initialize pro ac97, skipped\n"); |
| 1562 | else |
| 1563 | return 0; |
| 1564 | } |
| 1565 | /* I2S mixer only */ |
| 1566 | strcat(ice->card->mixername, "ICE1712 - multitrack"); |
| 1567 | return 0; |
| 1568 | } |
| 1569 | |
| 1570 | /* |
| 1571 | * |
| 1572 | */ |
| 1573 | |
| 1574 | static inline unsigned int eeprom_double(struct snd_ice1712 *ice, int idx) |
| 1575 | { |
| 1576 | return (unsigned int)ice->eeprom.data[idx] | ((unsigned int)ice->eeprom.data[idx + 1] << 8); |
| 1577 | } |
| 1578 | |
| 1579 | static void snd_ice1712_proc_read(struct snd_info_entry *entry, |
| 1580 | struct snd_info_buffer *buffer) |
| 1581 | { |
| 1582 | struct snd_ice1712 *ice = entry->private_data; |
| 1583 | unsigned int idx; |
| 1584 | |
| 1585 | snd_iprintf(buffer, "%s\n\n", ice->card->longname); |
| 1586 | snd_iprintf(buffer, "EEPROM:\n"); |
| 1587 | |
| 1588 | snd_iprintf(buffer, " Subvendor : 0x%x\n", ice->eeprom.subvendor); |
| 1589 | snd_iprintf(buffer, " Size : %i bytes\n", ice->eeprom.size); |
| 1590 | snd_iprintf(buffer, " Version : %i\n", ice->eeprom.version); |
| 1591 | snd_iprintf(buffer, " Codec : 0x%x\n", ice->eeprom.data[ICE_EEP1_CODEC]); |
| 1592 | snd_iprintf(buffer, " ACLink : 0x%x\n", ice->eeprom.data[ICE_EEP1_ACLINK]); |
| 1593 | snd_iprintf(buffer, " I2S ID : 0x%x\n", ice->eeprom.data[ICE_EEP1_I2SID]); |
| 1594 | snd_iprintf(buffer, " S/PDIF : 0x%x\n", ice->eeprom.data[ICE_EEP1_SPDIF]); |
| 1595 | snd_iprintf(buffer, " GPIO mask : 0x%x\n", ice->eeprom.gpiomask); |
| 1596 | snd_iprintf(buffer, " GPIO state : 0x%x\n", ice->eeprom.gpiostate); |
| 1597 | snd_iprintf(buffer, " GPIO direction : 0x%x\n", ice->eeprom.gpiodir); |
| 1598 | snd_iprintf(buffer, " AC'97 main : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_MAIN_LO)); |
| 1599 | snd_iprintf(buffer, " AC'97 pcm : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_PCM_LO)); |
| 1600 | snd_iprintf(buffer, " AC'97 record : 0x%x\n", eeprom_double(ice, ICE_EEP1_AC97_REC_LO)); |
| 1601 | snd_iprintf(buffer, " AC'97 record src : 0x%x\n", ice->eeprom.data[ICE_EEP1_AC97_RECSRC]); |
| 1602 | for (idx = 0; idx < 4; idx++) |
| 1603 | snd_iprintf(buffer, " DAC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_DAC_ID + idx]); |
| 1604 | for (idx = 0; idx < 4; idx++) |
| 1605 | snd_iprintf(buffer, " ADC ID #%i : 0x%x\n", idx, ice->eeprom.data[ICE_EEP1_ADC_ID + idx]); |
| 1606 | for (idx = 0x1c; idx < ice->eeprom.size; idx++) |
| 1607 | snd_iprintf(buffer, " Extra #%02i : 0x%x\n", idx, ice->eeprom.data[idx]); |
| 1608 | |
| 1609 | snd_iprintf(buffer, "\nRegisters:\n"); |
| 1610 | snd_iprintf(buffer, " PSDOUT03 : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_PSDOUT03))); |
| 1611 | snd_iprintf(buffer, " CAPTURE : 0x%08x\n", inl(ICEMT(ice, ROUTE_CAPTURE))); |
| 1612 | snd_iprintf(buffer, " SPDOUT : 0x%04x\n", (unsigned)inw(ICEMT(ice, ROUTE_SPDOUT))); |
| 1613 | snd_iprintf(buffer, " RATE : 0x%02x\n", (unsigned)inb(ICEMT(ice, RATE))); |
| 1614 | snd_iprintf(buffer, " GPIO_DATA : 0x%02x\n", (unsigned)snd_ice1712_get_gpio_data(ice)); |
| 1615 | snd_iprintf(buffer, " GPIO_WRITE_MASK : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_WRITE_MASK)); |
| 1616 | snd_iprintf(buffer, " GPIO_DIRECTION : 0x%02x\n", (unsigned)snd_ice1712_read(ice, ICE1712_IREG_GPIO_DIRECTION)); |
| 1617 | } |
| 1618 | |
| 1619 | static void __devinit snd_ice1712_proc_init(struct snd_ice1712 *ice) |
| 1620 | { |
| 1621 | struct snd_info_entry *entry; |
| 1622 | |
| 1623 | if (!snd_card_proc_new(ice->card, "ice1712", &entry)) |
| 1624 | snd_info_set_text_ops(entry, ice, snd_ice1712_proc_read); |
| 1625 | } |
| 1626 | |
| 1627 | /* |
| 1628 | * |
| 1629 | */ |
| 1630 | |
| 1631 | static int snd_ice1712_eeprom_info(struct snd_kcontrol *kcontrol, |
| 1632 | struct snd_ctl_elem_info *uinfo) |
| 1633 | { |
| 1634 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 1635 | uinfo->count = sizeof(struct snd_ice1712_eeprom); |
| 1636 | return 0; |
| 1637 | } |
| 1638 | |
| 1639 | static int snd_ice1712_eeprom_get(struct snd_kcontrol *kcontrol, |
| 1640 | struct snd_ctl_elem_value *ucontrol) |
| 1641 | { |
| 1642 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1643 | |
| 1644 | memcpy(ucontrol->value.bytes.data, &ice->eeprom, sizeof(ice->eeprom)); |
| 1645 | return 0; |
| 1646 | } |
| 1647 | |
| 1648 | static struct snd_kcontrol_new snd_ice1712_eeprom __devinitdata = { |
| 1649 | .iface = SNDRV_CTL_ELEM_IFACE_CARD, |
| 1650 | .name = "ICE1712 EEPROM", |
| 1651 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1652 | .info = snd_ice1712_eeprom_info, |
| 1653 | .get = snd_ice1712_eeprom_get |
| 1654 | }; |
| 1655 | |
| 1656 | /* |
| 1657 | */ |
| 1658 | static int snd_ice1712_spdif_info(struct snd_kcontrol *kcontrol, |
| 1659 | struct snd_ctl_elem_info *uinfo) |
| 1660 | { |
| 1661 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1662 | uinfo->count = 1; |
| 1663 | return 0; |
| 1664 | } |
| 1665 | |
| 1666 | static int snd_ice1712_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 1667 | struct snd_ctl_elem_value *ucontrol) |
| 1668 | { |
| 1669 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1670 | if (ice->spdif.ops.default_get) |
| 1671 | ice->spdif.ops.default_get(ice, ucontrol); |
| 1672 | return 0; |
| 1673 | } |
| 1674 | |
| 1675 | static int snd_ice1712_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 1676 | struct snd_ctl_elem_value *ucontrol) |
| 1677 | { |
| 1678 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1679 | if (ice->spdif.ops.default_put) |
| 1680 | return ice->spdif.ops.default_put(ice, ucontrol); |
| 1681 | return 0; |
| 1682 | } |
| 1683 | |
| 1684 | static struct snd_kcontrol_new snd_ice1712_spdif_default __devinitdata = |
| 1685 | { |
| 1686 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1687 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 1688 | .info = snd_ice1712_spdif_info, |
| 1689 | .get = snd_ice1712_spdif_default_get, |
| 1690 | .put = snd_ice1712_spdif_default_put |
| 1691 | }; |
| 1692 | |
| 1693 | static int snd_ice1712_spdif_maskc_get(struct snd_kcontrol *kcontrol, |
| 1694 | struct snd_ctl_elem_value *ucontrol) |
| 1695 | { |
| 1696 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1697 | if (ice->spdif.ops.default_get) { |
| 1698 | ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 1699 | IEC958_AES0_PROFESSIONAL | |
| 1700 | IEC958_AES0_CON_NOT_COPYRIGHT | |
| 1701 | IEC958_AES0_CON_EMPHASIS; |
| 1702 | ucontrol->value.iec958.status[1] = IEC958_AES1_CON_ORIGINAL | |
| 1703 | IEC958_AES1_CON_CATEGORY; |
| 1704 | ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS; |
| 1705 | } else { |
| 1706 | ucontrol->value.iec958.status[0] = 0xff; |
| 1707 | ucontrol->value.iec958.status[1] = 0xff; |
| 1708 | ucontrol->value.iec958.status[2] = 0xff; |
| 1709 | ucontrol->value.iec958.status[3] = 0xff; |
| 1710 | ucontrol->value.iec958.status[4] = 0xff; |
| 1711 | } |
| 1712 | return 0; |
| 1713 | } |
| 1714 | |
| 1715 | static int snd_ice1712_spdif_maskp_get(struct snd_kcontrol *kcontrol, |
| 1716 | struct snd_ctl_elem_value *ucontrol) |
| 1717 | { |
| 1718 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1719 | if (ice->spdif.ops.default_get) { |
| 1720 | ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO | |
| 1721 | IEC958_AES0_PROFESSIONAL | |
| 1722 | IEC958_AES0_PRO_FS | |
| 1723 | IEC958_AES0_PRO_EMPHASIS; |
| 1724 | ucontrol->value.iec958.status[1] = IEC958_AES1_PRO_MODE; |
| 1725 | } else { |
| 1726 | ucontrol->value.iec958.status[0] = 0xff; |
| 1727 | ucontrol->value.iec958.status[1] = 0xff; |
| 1728 | ucontrol->value.iec958.status[2] = 0xff; |
| 1729 | ucontrol->value.iec958.status[3] = 0xff; |
| 1730 | ucontrol->value.iec958.status[4] = 0xff; |
| 1731 | } |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
| 1735 | static struct snd_kcontrol_new snd_ice1712_spdif_maskc __devinitdata = |
| 1736 | { |
| 1737 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1738 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1739 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
| 1740 | .info = snd_ice1712_spdif_info, |
| 1741 | .get = snd_ice1712_spdif_maskc_get, |
| 1742 | }; |
| 1743 | |
| 1744 | static struct snd_kcontrol_new snd_ice1712_spdif_maskp __devinitdata = |
| 1745 | { |
| 1746 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1747 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1748 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK), |
| 1749 | .info = snd_ice1712_spdif_info, |
| 1750 | .get = snd_ice1712_spdif_maskp_get, |
| 1751 | }; |
| 1752 | |
| 1753 | static int snd_ice1712_spdif_stream_get(struct snd_kcontrol *kcontrol, |
| 1754 | struct snd_ctl_elem_value *ucontrol) |
| 1755 | { |
| 1756 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1757 | if (ice->spdif.ops.stream_get) |
| 1758 | ice->spdif.ops.stream_get(ice, ucontrol); |
| 1759 | return 0; |
| 1760 | } |
| 1761 | |
| 1762 | static int snd_ice1712_spdif_stream_put(struct snd_kcontrol *kcontrol, |
| 1763 | struct snd_ctl_elem_value *ucontrol) |
| 1764 | { |
| 1765 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1766 | if (ice->spdif.ops.stream_put) |
| 1767 | return ice->spdif.ops.stream_put(ice, ucontrol); |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | static struct snd_kcontrol_new snd_ice1712_spdif_stream __devinitdata = |
| 1772 | { |
| 1773 | .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1774 | SNDRV_CTL_ELEM_ACCESS_INACTIVE), |
| 1775 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1776 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 1777 | .info = snd_ice1712_spdif_info, |
| 1778 | .get = snd_ice1712_spdif_stream_get, |
| 1779 | .put = snd_ice1712_spdif_stream_put |
| 1780 | }; |
| 1781 | |
| 1782 | int snd_ice1712_gpio_get(struct snd_kcontrol *kcontrol, |
| 1783 | struct snd_ctl_elem_value *ucontrol) |
| 1784 | { |
| 1785 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1786 | unsigned char mask = kcontrol->private_value & 0xff; |
| 1787 | int invert = (kcontrol->private_value & (1<<24)) ? 1 : 0; |
| 1788 | |
| 1789 | snd_ice1712_save_gpio_status(ice); |
| 1790 | ucontrol->value.integer.value[0] = |
| 1791 | (snd_ice1712_gpio_read(ice) & mask ? 1 : 0) ^ invert; |
| 1792 | snd_ice1712_restore_gpio_status(ice); |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
| 1796 | int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, |
| 1797 | struct snd_ctl_elem_value *ucontrol) |
| 1798 | { |
| 1799 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1800 | unsigned char mask = kcontrol->private_value & 0xff; |
| 1801 | int invert = (kcontrol->private_value & (1<<24)) ? mask : 0; |
| 1802 | unsigned int val, nval; |
| 1803 | |
| 1804 | if (kcontrol->private_value & (1 << 31)) |
| 1805 | return -EPERM; |
| 1806 | nval = (ucontrol->value.integer.value[0] ? mask : 0) ^ invert; |
| 1807 | snd_ice1712_save_gpio_status(ice); |
| 1808 | val = snd_ice1712_gpio_read(ice); |
| 1809 | nval |= val & ~mask; |
| 1810 | if (val != nval) |
| 1811 | snd_ice1712_gpio_write(ice, nval); |
| 1812 | snd_ice1712_restore_gpio_status(ice); |
| 1813 | return val != nval; |
| 1814 | } |
| 1815 | |
| 1816 | /* |
| 1817 | * rate |
| 1818 | */ |
| 1819 | static int snd_ice1712_pro_internal_clock_info(struct snd_kcontrol *kcontrol, |
| 1820 | struct snd_ctl_elem_info *uinfo) |
| 1821 | { |
| 1822 | static const char * const texts[] = { |
| 1823 | "8000", /* 0: 6 */ |
| 1824 | "9600", /* 1: 3 */ |
| 1825 | "11025", /* 2: 10 */ |
| 1826 | "12000", /* 3: 2 */ |
| 1827 | "16000", /* 4: 5 */ |
| 1828 | "22050", /* 5: 9 */ |
| 1829 | "24000", /* 6: 1 */ |
| 1830 | "32000", /* 7: 4 */ |
| 1831 | "44100", /* 8: 8 */ |
| 1832 | "48000", /* 9: 0 */ |
| 1833 | "64000", /* 10: 15 */ |
| 1834 | "88200", /* 11: 11 */ |
| 1835 | "96000", /* 12: 7 */ |
| 1836 | "IEC958 Input", /* 13: -- */ |
| 1837 | }; |
| 1838 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1839 | uinfo->count = 1; |
| 1840 | uinfo->value.enumerated.items = 14; |
| 1841 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 1842 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 1843 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
| 1847 | static int snd_ice1712_pro_internal_clock_get(struct snd_kcontrol *kcontrol, |
| 1848 | struct snd_ctl_elem_value *ucontrol) |
| 1849 | { |
| 1850 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1851 | static const unsigned char xlate[16] = { |
| 1852 | 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 255, 255, 255, 10 |
| 1853 | }; |
| 1854 | unsigned char val; |
| 1855 | |
| 1856 | spin_lock_irq(&ice->reg_lock); |
| 1857 | if (is_spdif_master(ice)) { |
| 1858 | ucontrol->value.enumerated.item[0] = 13; |
| 1859 | } else { |
| 1860 | val = xlate[inb(ICEMT(ice, RATE)) & 15]; |
| 1861 | if (val == 255) { |
| 1862 | snd_BUG(); |
| 1863 | val = 0; |
| 1864 | } |
| 1865 | ucontrol->value.enumerated.item[0] = val; |
| 1866 | } |
| 1867 | spin_unlock_irq(&ice->reg_lock); |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
| 1871 | static int snd_ice1712_pro_internal_clock_put(struct snd_kcontrol *kcontrol, |
| 1872 | struct snd_ctl_elem_value *ucontrol) |
| 1873 | { |
| 1874 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1875 | static const unsigned int xrate[13] = { |
| 1876 | 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
| 1877 | 32000, 44100, 48000, 64000, 88200, 96000 |
| 1878 | }; |
| 1879 | unsigned char oval; |
| 1880 | int change = 0; |
| 1881 | |
| 1882 | spin_lock_irq(&ice->reg_lock); |
| 1883 | oval = inb(ICEMT(ice, RATE)); |
| 1884 | if (ucontrol->value.enumerated.item[0] == 13) { |
| 1885 | outb(oval | ICE1712_SPDIF_MASTER, ICEMT(ice, RATE)); |
| 1886 | } else { |
| 1887 | PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13]; |
| 1888 | spin_unlock_irq(&ice->reg_lock); |
| 1889 | snd_ice1712_set_pro_rate(ice, PRO_RATE_DEFAULT, 1); |
| 1890 | spin_lock_irq(&ice->reg_lock); |
| 1891 | } |
| 1892 | change = inb(ICEMT(ice, RATE)) != oval; |
| 1893 | spin_unlock_irq(&ice->reg_lock); |
| 1894 | |
| 1895 | if ((oval & ICE1712_SPDIF_MASTER) != |
| 1896 | (inb(ICEMT(ice, RATE)) & ICE1712_SPDIF_MASTER)) |
| 1897 | snd_ice1712_set_input_clock_source(ice, is_spdif_master(ice)); |
| 1898 | |
| 1899 | return change; |
| 1900 | } |
| 1901 | |
| 1902 | static struct snd_kcontrol_new snd_ice1712_pro_internal_clock __devinitdata = { |
| 1903 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1904 | .name = "Multi Track Internal Clock", |
| 1905 | .info = snd_ice1712_pro_internal_clock_info, |
| 1906 | .get = snd_ice1712_pro_internal_clock_get, |
| 1907 | .put = snd_ice1712_pro_internal_clock_put |
| 1908 | }; |
| 1909 | |
| 1910 | static int snd_ice1712_pro_internal_clock_default_info(struct snd_kcontrol *kcontrol, |
| 1911 | struct snd_ctl_elem_info *uinfo) |
| 1912 | { |
| 1913 | static const char * const texts[] = { |
| 1914 | "8000", /* 0: 6 */ |
| 1915 | "9600", /* 1: 3 */ |
| 1916 | "11025", /* 2: 10 */ |
| 1917 | "12000", /* 3: 2 */ |
| 1918 | "16000", /* 4: 5 */ |
| 1919 | "22050", /* 5: 9 */ |
| 1920 | "24000", /* 6: 1 */ |
| 1921 | "32000", /* 7: 4 */ |
| 1922 | "44100", /* 8: 8 */ |
| 1923 | "48000", /* 9: 0 */ |
| 1924 | "64000", /* 10: 15 */ |
| 1925 | "88200", /* 11: 11 */ |
| 1926 | "96000", /* 12: 7 */ |
| 1927 | /* "IEC958 Input", 13: -- */ |
| 1928 | }; |
| 1929 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1930 | uinfo->count = 1; |
| 1931 | uinfo->value.enumerated.items = 13; |
| 1932 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 1933 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 1934 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
| 1938 | static int snd_ice1712_pro_internal_clock_default_get(struct snd_kcontrol *kcontrol, |
| 1939 | struct snd_ctl_elem_value *ucontrol) |
| 1940 | { |
| 1941 | int val; |
| 1942 | static const unsigned int xrate[13] = { |
| 1943 | 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
| 1944 | 32000, 44100, 48000, 64000, 88200, 96000 |
| 1945 | }; |
| 1946 | |
| 1947 | for (val = 0; val < 13; val++) { |
| 1948 | if (xrate[val] == PRO_RATE_DEFAULT) |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | ucontrol->value.enumerated.item[0] = val; |
| 1953 | return 0; |
| 1954 | } |
| 1955 | |
| 1956 | static int snd_ice1712_pro_internal_clock_default_put(struct snd_kcontrol *kcontrol, |
| 1957 | struct snd_ctl_elem_value *ucontrol) |
| 1958 | { |
| 1959 | static const unsigned int xrate[13] = { |
| 1960 | 8000, 9600, 11025, 12000, 16000, 22050, 24000, |
| 1961 | 32000, 44100, 48000, 64000, 88200, 96000 |
| 1962 | }; |
| 1963 | unsigned char oval; |
| 1964 | int change = 0; |
| 1965 | |
| 1966 | oval = PRO_RATE_DEFAULT; |
| 1967 | PRO_RATE_DEFAULT = xrate[ucontrol->value.integer.value[0] % 13]; |
| 1968 | change = PRO_RATE_DEFAULT != oval; |
| 1969 | |
| 1970 | return change; |
| 1971 | } |
| 1972 | |
| 1973 | static struct snd_kcontrol_new snd_ice1712_pro_internal_clock_default __devinitdata = { |
| 1974 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1975 | .name = "Multi Track Internal Clock Default", |
| 1976 | .info = snd_ice1712_pro_internal_clock_default_info, |
| 1977 | .get = snd_ice1712_pro_internal_clock_default_get, |
| 1978 | .put = snd_ice1712_pro_internal_clock_default_put |
| 1979 | }; |
| 1980 | |
| 1981 | #define snd_ice1712_pro_rate_locking_info snd_ctl_boolean_mono_info |
| 1982 | |
| 1983 | static int snd_ice1712_pro_rate_locking_get(struct snd_kcontrol *kcontrol, |
| 1984 | struct snd_ctl_elem_value *ucontrol) |
| 1985 | { |
| 1986 | ucontrol->value.integer.value[0] = PRO_RATE_LOCKED; |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | static int snd_ice1712_pro_rate_locking_put(struct snd_kcontrol *kcontrol, |
| 1991 | struct snd_ctl_elem_value *ucontrol) |
| 1992 | { |
| 1993 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 1994 | int change = 0, nval; |
| 1995 | |
| 1996 | nval = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1997 | spin_lock_irq(&ice->reg_lock); |
| 1998 | change = PRO_RATE_LOCKED != nval; |
| 1999 | PRO_RATE_LOCKED = nval; |
| 2000 | spin_unlock_irq(&ice->reg_lock); |
| 2001 | return change; |
| 2002 | } |
| 2003 | |
| 2004 | static struct snd_kcontrol_new snd_ice1712_pro_rate_locking __devinitdata = { |
| 2005 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2006 | .name = "Multi Track Rate Locking", |
| 2007 | .info = snd_ice1712_pro_rate_locking_info, |
| 2008 | .get = snd_ice1712_pro_rate_locking_get, |
| 2009 | .put = snd_ice1712_pro_rate_locking_put |
| 2010 | }; |
| 2011 | |
| 2012 | #define snd_ice1712_pro_rate_reset_info snd_ctl_boolean_mono_info |
| 2013 | |
| 2014 | static int snd_ice1712_pro_rate_reset_get(struct snd_kcontrol *kcontrol, |
| 2015 | struct snd_ctl_elem_value *ucontrol) |
| 2016 | { |
| 2017 | ucontrol->value.integer.value[0] = PRO_RATE_RESET; |
| 2018 | return 0; |
| 2019 | } |
| 2020 | |
| 2021 | static int snd_ice1712_pro_rate_reset_put(struct snd_kcontrol *kcontrol, |
| 2022 | struct snd_ctl_elem_value *ucontrol) |
| 2023 | { |
| 2024 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2025 | int change = 0, nval; |
| 2026 | |
| 2027 | nval = ucontrol->value.integer.value[0] ? 1 : 0; |
| 2028 | spin_lock_irq(&ice->reg_lock); |
| 2029 | change = PRO_RATE_RESET != nval; |
| 2030 | PRO_RATE_RESET = nval; |
| 2031 | spin_unlock_irq(&ice->reg_lock); |
| 2032 | return change; |
| 2033 | } |
| 2034 | |
| 2035 | static struct snd_kcontrol_new snd_ice1712_pro_rate_reset __devinitdata = { |
| 2036 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2037 | .name = "Multi Track Rate Reset", |
| 2038 | .info = snd_ice1712_pro_rate_reset_info, |
| 2039 | .get = snd_ice1712_pro_rate_reset_get, |
| 2040 | .put = snd_ice1712_pro_rate_reset_put |
| 2041 | }; |
| 2042 | |
| 2043 | /* |
| 2044 | * routing |
| 2045 | */ |
| 2046 | static int snd_ice1712_pro_route_info(struct snd_kcontrol *kcontrol, |
| 2047 | struct snd_ctl_elem_info *uinfo) |
| 2048 | { |
| 2049 | static const char * const texts[] = { |
| 2050 | "PCM Out", /* 0 */ |
| 2051 | "H/W In 0", "H/W In 1", "H/W In 2", "H/W In 3", /* 1-4 */ |
| 2052 | "H/W In 4", "H/W In 5", "H/W In 6", "H/W In 7", /* 5-8 */ |
| 2053 | "IEC958 In L", "IEC958 In R", /* 9-10 */ |
| 2054 | "Digital Mixer", /* 11 - optional */ |
| 2055 | }; |
| 2056 | |
| 2057 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2058 | uinfo->count = 1; |
| 2059 | uinfo->value.enumerated.items = |
| 2060 | snd_ctl_get_ioffidx(kcontrol, &uinfo->id) < 2 ? 12 : 11; |
| 2061 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2062 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
| 2063 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 2064 | return 0; |
| 2065 | } |
| 2066 | |
| 2067 | static int snd_ice1712_pro_route_analog_get(struct snd_kcontrol *kcontrol, |
| 2068 | struct snd_ctl_elem_value *ucontrol) |
| 2069 | { |
| 2070 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2071 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2072 | unsigned int val, cval; |
| 2073 | |
| 2074 | spin_lock_irq(&ice->reg_lock); |
| 2075 | val = inw(ICEMT(ice, ROUTE_PSDOUT03)); |
| 2076 | cval = inl(ICEMT(ice, ROUTE_CAPTURE)); |
| 2077 | spin_unlock_irq(&ice->reg_lock); |
| 2078 | |
| 2079 | val >>= ((idx % 2) * 8) + ((idx / 2) * 2); |
| 2080 | val &= 3; |
| 2081 | cval >>= ((idx / 2) * 8) + ((idx % 2) * 4); |
| 2082 | if (val == 1 && idx < 2) |
| 2083 | ucontrol->value.enumerated.item[0] = 11; |
| 2084 | else if (val == 2) |
| 2085 | ucontrol->value.enumerated.item[0] = (cval & 7) + 1; |
| 2086 | else if (val == 3) |
| 2087 | ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9; |
| 2088 | else |
| 2089 | ucontrol->value.enumerated.item[0] = 0; |
| 2090 | return 0; |
| 2091 | } |
| 2092 | |
| 2093 | static int snd_ice1712_pro_route_analog_put(struct snd_kcontrol *kcontrol, |
| 2094 | struct snd_ctl_elem_value *ucontrol) |
| 2095 | { |
| 2096 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2097 | int change, shift; |
| 2098 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2099 | unsigned int val, old_val, nval; |
| 2100 | |
| 2101 | /* update PSDOUT */ |
| 2102 | if (ucontrol->value.enumerated.item[0] >= 11) |
| 2103 | nval = idx < 2 ? 1 : 0; /* dig mixer (or pcm) */ |
| 2104 | else if (ucontrol->value.enumerated.item[0] >= 9) |
| 2105 | nval = 3; /* spdif in */ |
| 2106 | else if (ucontrol->value.enumerated.item[0] >= 1) |
| 2107 | nval = 2; /* analog in */ |
| 2108 | else |
| 2109 | nval = 0; /* pcm */ |
| 2110 | shift = ((idx % 2) * 8) + ((idx / 2) * 2); |
| 2111 | spin_lock_irq(&ice->reg_lock); |
| 2112 | val = old_val = inw(ICEMT(ice, ROUTE_PSDOUT03)); |
| 2113 | val &= ~(0x03 << shift); |
| 2114 | val |= nval << shift; |
| 2115 | change = val != old_val; |
| 2116 | if (change) |
| 2117 | outw(val, ICEMT(ice, ROUTE_PSDOUT03)); |
| 2118 | spin_unlock_irq(&ice->reg_lock); |
| 2119 | if (nval < 2) /* dig mixer of pcm */ |
| 2120 | return change; |
| 2121 | |
| 2122 | /* update CAPTURE */ |
| 2123 | spin_lock_irq(&ice->reg_lock); |
| 2124 | val = old_val = inl(ICEMT(ice, ROUTE_CAPTURE)); |
| 2125 | shift = ((idx / 2) * 8) + ((idx % 2) * 4); |
| 2126 | if (nval == 2) { /* analog in */ |
| 2127 | nval = ucontrol->value.enumerated.item[0] - 1; |
| 2128 | val &= ~(0x07 << shift); |
| 2129 | val |= nval << shift; |
| 2130 | } else { /* spdif in */ |
| 2131 | nval = (ucontrol->value.enumerated.item[0] - 9) << 3; |
| 2132 | val &= ~(0x08 << shift); |
| 2133 | val |= nval << shift; |
| 2134 | } |
| 2135 | if (val != old_val) { |
| 2136 | change = 1; |
| 2137 | outl(val, ICEMT(ice, ROUTE_CAPTURE)); |
| 2138 | } |
| 2139 | spin_unlock_irq(&ice->reg_lock); |
| 2140 | return change; |
| 2141 | } |
| 2142 | |
| 2143 | static int snd_ice1712_pro_route_spdif_get(struct snd_kcontrol *kcontrol, |
| 2144 | struct snd_ctl_elem_value *ucontrol) |
| 2145 | { |
| 2146 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2147 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2148 | unsigned int val, cval; |
| 2149 | val = inw(ICEMT(ice, ROUTE_SPDOUT)); |
| 2150 | cval = (val >> (idx * 4 + 8)) & 0x0f; |
| 2151 | val = (val >> (idx * 2)) & 0x03; |
| 2152 | if (val == 1) |
| 2153 | ucontrol->value.enumerated.item[0] = 11; |
| 2154 | else if (val == 2) |
| 2155 | ucontrol->value.enumerated.item[0] = (cval & 7) + 1; |
| 2156 | else if (val == 3) |
| 2157 | ucontrol->value.enumerated.item[0] = ((cval >> 3) & 1) + 9; |
| 2158 | else |
| 2159 | ucontrol->value.enumerated.item[0] = 0; |
| 2160 | return 0; |
| 2161 | } |
| 2162 | |
| 2163 | static int snd_ice1712_pro_route_spdif_put(struct snd_kcontrol *kcontrol, |
| 2164 | struct snd_ctl_elem_value *ucontrol) |
| 2165 | { |
| 2166 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2167 | int change, shift; |
| 2168 | int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); |
| 2169 | unsigned int val, old_val, nval; |
| 2170 | |
| 2171 | /* update SPDOUT */ |
| 2172 | spin_lock_irq(&ice->reg_lock); |
| 2173 | val = old_val = inw(ICEMT(ice, ROUTE_SPDOUT)); |
| 2174 | if (ucontrol->value.enumerated.item[0] >= 11) |
| 2175 | nval = 1; |
| 2176 | else if (ucontrol->value.enumerated.item[0] >= 9) |
| 2177 | nval = 3; |
| 2178 | else if (ucontrol->value.enumerated.item[0] >= 1) |
| 2179 | nval = 2; |
| 2180 | else |
| 2181 | nval = 0; |
| 2182 | shift = idx * 2; |
| 2183 | val &= ~(0x03 << shift); |
| 2184 | val |= nval << shift; |
| 2185 | shift = idx * 4 + 8; |
| 2186 | if (nval == 2) { |
| 2187 | nval = ucontrol->value.enumerated.item[0] - 1; |
| 2188 | val &= ~(0x07 << shift); |
| 2189 | val |= nval << shift; |
| 2190 | } else if (nval == 3) { |
| 2191 | nval = (ucontrol->value.enumerated.item[0] - 9) << 3; |
| 2192 | val &= ~(0x08 << shift); |
| 2193 | val |= nval << shift; |
| 2194 | } |
| 2195 | change = val != old_val; |
| 2196 | if (change) |
| 2197 | outw(val, ICEMT(ice, ROUTE_SPDOUT)); |
| 2198 | spin_unlock_irq(&ice->reg_lock); |
| 2199 | return change; |
| 2200 | } |
| 2201 | |
| 2202 | static struct snd_kcontrol_new snd_ice1712_mixer_pro_analog_route __devinitdata = { |
| 2203 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2204 | .name = "H/W Playback Route", |
| 2205 | .info = snd_ice1712_pro_route_info, |
| 2206 | .get = snd_ice1712_pro_route_analog_get, |
| 2207 | .put = snd_ice1712_pro_route_analog_put, |
| 2208 | }; |
| 2209 | |
| 2210 | static struct snd_kcontrol_new snd_ice1712_mixer_pro_spdif_route __devinitdata = { |
| 2211 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2212 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Route", |
| 2213 | .info = snd_ice1712_pro_route_info, |
| 2214 | .get = snd_ice1712_pro_route_spdif_get, |
| 2215 | .put = snd_ice1712_pro_route_spdif_put, |
| 2216 | .count = 2, |
| 2217 | }; |
| 2218 | |
| 2219 | |
| 2220 | static int snd_ice1712_pro_volume_rate_info(struct snd_kcontrol *kcontrol, |
| 2221 | struct snd_ctl_elem_info *uinfo) |
| 2222 | { |
| 2223 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2224 | uinfo->count = 1; |
| 2225 | uinfo->value.integer.min = 0; |
| 2226 | uinfo->value.integer.max = 255; |
| 2227 | return 0; |
| 2228 | } |
| 2229 | |
| 2230 | static int snd_ice1712_pro_volume_rate_get(struct snd_kcontrol *kcontrol, |
| 2231 | struct snd_ctl_elem_value *ucontrol) |
| 2232 | { |
| 2233 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2234 | |
| 2235 | ucontrol->value.integer.value[0] = inb(ICEMT(ice, MONITOR_RATE)); |
| 2236 | return 0; |
| 2237 | } |
| 2238 | |
| 2239 | static int snd_ice1712_pro_volume_rate_put(struct snd_kcontrol *kcontrol, |
| 2240 | struct snd_ctl_elem_value *ucontrol) |
| 2241 | { |
| 2242 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2243 | int change; |
| 2244 | |
| 2245 | spin_lock_irq(&ice->reg_lock); |
| 2246 | change = inb(ICEMT(ice, MONITOR_RATE)) != ucontrol->value.integer.value[0]; |
| 2247 | outb(ucontrol->value.integer.value[0], ICEMT(ice, MONITOR_RATE)); |
| 2248 | spin_unlock_irq(&ice->reg_lock); |
| 2249 | return change; |
| 2250 | } |
| 2251 | |
| 2252 | static struct snd_kcontrol_new snd_ice1712_mixer_pro_volume_rate __devinitdata = { |
| 2253 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2254 | .name = "Multi Track Volume Rate", |
| 2255 | .info = snd_ice1712_pro_volume_rate_info, |
| 2256 | .get = snd_ice1712_pro_volume_rate_get, |
| 2257 | .put = snd_ice1712_pro_volume_rate_put |
| 2258 | }; |
| 2259 | |
| 2260 | static int snd_ice1712_pro_peak_info(struct snd_kcontrol *kcontrol, |
| 2261 | struct snd_ctl_elem_info *uinfo) |
| 2262 | { |
| 2263 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2264 | uinfo->count = 22; |
| 2265 | uinfo->value.integer.min = 0; |
| 2266 | uinfo->value.integer.max = 255; |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
| 2270 | static int snd_ice1712_pro_peak_get(struct snd_kcontrol *kcontrol, |
| 2271 | struct snd_ctl_elem_value *ucontrol) |
| 2272 | { |
| 2273 | struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); |
| 2274 | int idx; |
| 2275 | |
| 2276 | spin_lock_irq(&ice->reg_lock); |
| 2277 | for (idx = 0; idx < 22; idx++) { |
| 2278 | outb(idx, ICEMT(ice, MONITOR_PEAKINDEX)); |
| 2279 | ucontrol->value.integer.value[idx] = inb(ICEMT(ice, MONITOR_PEAKDATA)); |
| 2280 | } |
| 2281 | spin_unlock_irq(&ice->reg_lock); |
| 2282 | return 0; |
| 2283 | } |
| 2284 | |
| 2285 | static struct snd_kcontrol_new snd_ice1712_mixer_pro_peak __devinitdata = { |
| 2286 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 2287 | .name = "Multi Track Peak", |
| 2288 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, |
| 2289 | .info = snd_ice1712_pro_peak_info, |
| 2290 | .get = snd_ice1712_pro_peak_get |
| 2291 | }; |
| 2292 | |
| 2293 | /* |
| 2294 | * |
| 2295 | */ |
| 2296 | |
| 2297 | /* |
| 2298 | * list of available boards |
| 2299 | */ |
| 2300 | static struct snd_ice1712_card_info *card_tables[] __devinitdata = { |
| 2301 | snd_ice1712_hoontech_cards, |
| 2302 | snd_ice1712_delta_cards, |
| 2303 | snd_ice1712_ews_cards, |
| 2304 | NULL, |
| 2305 | }; |
| 2306 | |
| 2307 | static unsigned char __devinit snd_ice1712_read_i2c(struct snd_ice1712 *ice, |
| 2308 | unsigned char dev, |
| 2309 | unsigned char addr) |
| 2310 | { |
| 2311 | long t = 0x10000; |
| 2312 | |
| 2313 | outb(addr, ICEREG(ice, I2C_BYTE_ADDR)); |
| 2314 | outb(dev & ~ICE1712_I2C_WRITE, ICEREG(ice, I2C_DEV_ADDR)); |
| 2315 | while (t-- > 0 && (inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_BUSY)) ; |
| 2316 | return inb(ICEREG(ice, I2C_DATA)); |
| 2317 | } |
| 2318 | |
| 2319 | static int __devinit snd_ice1712_read_eeprom(struct snd_ice1712 *ice, |
| 2320 | const char *modelname) |
| 2321 | { |
| 2322 | int dev = 0xa0; /* EEPROM device address */ |
| 2323 | unsigned int i, size; |
| 2324 | struct snd_ice1712_card_info * const *tbl, *c; |
| 2325 | |
| 2326 | if (!modelname || !*modelname) { |
| 2327 | ice->eeprom.subvendor = 0; |
| 2328 | if ((inb(ICEREG(ice, I2C_CTRL)) & ICE1712_I2C_EEPROM) != 0) |
| 2329 | ice->eeprom.subvendor = (snd_ice1712_read_i2c(ice, dev, 0x00) << 0) | |
| 2330 | (snd_ice1712_read_i2c(ice, dev, 0x01) << 8) | |
| 2331 | (snd_ice1712_read_i2c(ice, dev, 0x02) << 16) | |
| 2332 | (snd_ice1712_read_i2c(ice, dev, 0x03) << 24); |
| 2333 | if (ice->eeprom.subvendor == 0 || |
| 2334 | ice->eeprom.subvendor == (unsigned int)-1) { |
| 2335 | /* invalid subvendor from EEPROM, try the PCI subststem ID instead */ |
| 2336 | u16 vendor, device; |
| 2337 | pci_read_config_word(ice->pci, PCI_SUBSYSTEM_VENDOR_ID, &vendor); |
| 2338 | pci_read_config_word(ice->pci, PCI_SUBSYSTEM_ID, &device); |
| 2339 | ice->eeprom.subvendor = ((unsigned int)swab16(vendor) << 16) | swab16(device); |
| 2340 | if (ice->eeprom.subvendor == 0 || ice->eeprom.subvendor == (unsigned int)-1) { |
| 2341 | printk(KERN_ERR "ice1712: No valid ID is found\n"); |
| 2342 | return -ENXIO; |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | for (tbl = card_tables; *tbl; tbl++) { |
| 2347 | for (c = *tbl; c->subvendor; c++) { |
| 2348 | if (modelname && c->model && !strcmp(modelname, c->model)) { |
| 2349 | printk(KERN_INFO "ice1712: Using board model %s\n", c->name); |
| 2350 | ice->eeprom.subvendor = c->subvendor; |
| 2351 | } else if (c->subvendor != ice->eeprom.subvendor) |
| 2352 | continue; |
| 2353 | if (!c->eeprom_size || !c->eeprom_data) |
| 2354 | goto found; |
| 2355 | /* if the EEPROM is given by the driver, use it */ |
| 2356 | snd_printdd("using the defined eeprom..\n"); |
| 2357 | ice->eeprom.version = 1; |
| 2358 | ice->eeprom.size = c->eeprom_size + 6; |
| 2359 | memcpy(ice->eeprom.data, c->eeprom_data, c->eeprom_size); |
| 2360 | goto read_skipped; |
| 2361 | } |
| 2362 | } |
| 2363 | printk(KERN_WARNING "ice1712: No matching model found for ID 0x%x\n", |
| 2364 | ice->eeprom.subvendor); |
| 2365 | |
| 2366 | found: |
| 2367 | ice->eeprom.size = snd_ice1712_read_i2c(ice, dev, 0x04); |
| 2368 | if (ice->eeprom.size < 6) |
| 2369 | ice->eeprom.size = 32; /* FIXME: any cards without the correct size? */ |
| 2370 | else if (ice->eeprom.size > 32) { |
| 2371 | snd_printk(KERN_ERR "invalid EEPROM (size = %i)\n", ice->eeprom.size); |
| 2372 | return -EIO; |
| 2373 | } |
| 2374 | ice->eeprom.version = snd_ice1712_read_i2c(ice, dev, 0x05); |
| 2375 | if (ice->eeprom.version != 1) { |
| 2376 | snd_printk(KERN_ERR "invalid EEPROM version %i\n", |
| 2377 | ice->eeprom.version); |
| 2378 | /* return -EIO; */ |
| 2379 | } |
| 2380 | size = ice->eeprom.size - 6; |
| 2381 | for (i = 0; i < size; i++) |
| 2382 | ice->eeprom.data[i] = snd_ice1712_read_i2c(ice, dev, i + 6); |
| 2383 | |
| 2384 | read_skipped: |
| 2385 | ice->eeprom.gpiomask = ice->eeprom.data[ICE_EEP1_GPIO_MASK]; |
| 2386 | ice->eeprom.gpiostate = ice->eeprom.data[ICE_EEP1_GPIO_STATE]; |
| 2387 | ice->eeprom.gpiodir = ice->eeprom.data[ICE_EEP1_GPIO_DIR]; |
| 2388 | |
| 2389 | return 0; |
| 2390 | } |
| 2391 | |
| 2392 | |
| 2393 | |
| 2394 | static int __devinit snd_ice1712_chip_init(struct snd_ice1712 *ice) |
| 2395 | { |
| 2396 | outb(ICE1712_RESET | ICE1712_NATIVE, ICEREG(ice, CONTROL)); |
| 2397 | udelay(200); |
| 2398 | outb(ICE1712_NATIVE, ICEREG(ice, CONTROL)); |
| 2399 | udelay(200); |
| 2400 | if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DMX6FIRE && |
| 2401 | !ice->dxr_enable) |
| 2402 | /* Set eeprom value to limit active ADCs and DACs to 6; |
| 2403 | * Also disable AC97 as no hardware in standard 6fire card/box |
| 2404 | * Note: DXR extensions are not currently supported |
| 2405 | */ |
| 2406 | ice->eeprom.data[ICE_EEP1_CODEC] = 0x3a; |
| 2407 | pci_write_config_byte(ice->pci, 0x60, ice->eeprom.data[ICE_EEP1_CODEC]); |
| 2408 | pci_write_config_byte(ice->pci, 0x61, ice->eeprom.data[ICE_EEP1_ACLINK]); |
| 2409 | pci_write_config_byte(ice->pci, 0x62, ice->eeprom.data[ICE_EEP1_I2SID]); |
| 2410 | pci_write_config_byte(ice->pci, 0x63, ice->eeprom.data[ICE_EEP1_SPDIF]); |
| 2411 | if (ice->eeprom.subvendor != ICE1712_SUBDEVICE_STDSP24) { |
| 2412 | ice->gpio.write_mask = ice->eeprom.gpiomask; |
| 2413 | ice->gpio.direction = ice->eeprom.gpiodir; |
| 2414 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, |
| 2415 | ice->eeprom.gpiomask); |
| 2416 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, |
| 2417 | ice->eeprom.gpiodir); |
| 2418 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, |
| 2419 | ice->eeprom.gpiostate); |
| 2420 | } else { |
| 2421 | ice->gpio.write_mask = 0xc0; |
| 2422 | ice->gpio.direction = 0xff; |
| 2423 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_WRITE_MASK, 0xc0); |
| 2424 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DIRECTION, 0xff); |
| 2425 | snd_ice1712_write(ice, ICE1712_IREG_GPIO_DATA, |
| 2426 | ICE1712_STDSP24_CLOCK_BIT); |
| 2427 | } |
| 2428 | snd_ice1712_write(ice, ICE1712_IREG_PRO_POWERDOWN, 0); |
| 2429 | if (!(ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97)) { |
| 2430 | outb(ICE1712_AC97_WARM, ICEREG(ice, AC97_CMD)); |
| 2431 | udelay(100); |
| 2432 | outb(0, ICEREG(ice, AC97_CMD)); |
| 2433 | udelay(200); |
| 2434 | snd_ice1712_write(ice, ICE1712_IREG_CONSUMER_POWERDOWN, 0); |
| 2435 | } |
| 2436 | snd_ice1712_set_pro_rate(ice, 48000, 1); |
| 2437 | |
| 2438 | return 0; |
| 2439 | } |
| 2440 | |
| 2441 | int __devinit snd_ice1712_spdif_build_controls(struct snd_ice1712 *ice) |
| 2442 | { |
| 2443 | int err; |
| 2444 | struct snd_kcontrol *kctl; |
| 2445 | |
| 2446 | if (snd_BUG_ON(!ice->pcm_pro)) |
| 2447 | return -EIO; |
| 2448 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_default, ice)); |
| 2449 | if (err < 0) |
| 2450 | return err; |
| 2451 | kctl->id.device = ice->pcm_pro->device; |
| 2452 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskc, ice)); |
| 2453 | if (err < 0) |
| 2454 | return err; |
| 2455 | kctl->id.device = ice->pcm_pro->device; |
| 2456 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_maskp, ice)); |
| 2457 | if (err < 0) |
| 2458 | return err; |
| 2459 | kctl->id.device = ice->pcm_pro->device; |
| 2460 | err = snd_ctl_add(ice->card, kctl = snd_ctl_new1(&snd_ice1712_spdif_stream, ice)); |
| 2461 | if (err < 0) |
| 2462 | return err; |
| 2463 | kctl->id.device = ice->pcm_pro->device; |
| 2464 | ice->spdif.stream_ctl = kctl; |
| 2465 | return 0; |
| 2466 | } |
| 2467 | |
| 2468 | |
| 2469 | static int __devinit snd_ice1712_build_controls(struct snd_ice1712 *ice) |
| 2470 | { |
| 2471 | int err; |
| 2472 | |
| 2473 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_eeprom, ice)); |
| 2474 | if (err < 0) |
| 2475 | return err; |
| 2476 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock, ice)); |
| 2477 | if (err < 0) |
| 2478 | return err; |
| 2479 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_internal_clock_default, ice)); |
| 2480 | if (err < 0) |
| 2481 | return err; |
| 2482 | |
| 2483 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_locking, ice)); |
| 2484 | if (err < 0) |
| 2485 | return err; |
| 2486 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_pro_rate_reset, ice)); |
| 2487 | if (err < 0) |
| 2488 | return err; |
| 2489 | |
| 2490 | if (ice->num_total_dacs > 0) { |
| 2491 | struct snd_kcontrol_new tmp = snd_ice1712_mixer_pro_analog_route; |
| 2492 | tmp.count = ice->num_total_dacs; |
| 2493 | err = snd_ctl_add(ice->card, snd_ctl_new1(&tmp, ice)); |
| 2494 | if (err < 0) |
| 2495 | return err; |
| 2496 | } |
| 2497 | |
| 2498 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_spdif_route, ice)); |
| 2499 | if (err < 0) |
| 2500 | return err; |
| 2501 | |
| 2502 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_volume_rate, ice)); |
| 2503 | if (err < 0) |
| 2504 | return err; |
| 2505 | err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_mixer_pro_peak, ice)); |
| 2506 | if (err < 0) |
| 2507 | return err; |
| 2508 | |
| 2509 | return 0; |
| 2510 | } |
| 2511 | |
| 2512 | static int snd_ice1712_free(struct snd_ice1712 *ice) |
| 2513 | { |
| 2514 | if (!ice->port) |
| 2515 | goto __hw_end; |
| 2516 | /* mask all interrupts */ |
| 2517 | outb(0xc0, ICEMT(ice, IRQ)); |
| 2518 | outb(0xff, ICEREG(ice, IRQMASK)); |
| 2519 | /* --- */ |
| 2520 | __hw_end: |
| 2521 | if (ice->irq >= 0) |
| 2522 | free_irq(ice->irq, ice); |
| 2523 | |
| 2524 | if (ice->port) |
| 2525 | pci_release_regions(ice->pci); |
| 2526 | snd_ice1712_akm4xxx_free(ice); |
| 2527 | pci_disable_device(ice->pci); |
| 2528 | kfree(ice->spec); |
| 2529 | kfree(ice); |
| 2530 | return 0; |
| 2531 | } |
| 2532 | |
| 2533 | static int snd_ice1712_dev_free(struct snd_device *device) |
| 2534 | { |
| 2535 | struct snd_ice1712 *ice = device->device_data; |
| 2536 | return snd_ice1712_free(ice); |
| 2537 | } |
| 2538 | |
| 2539 | static int __devinit snd_ice1712_create(struct snd_card *card, |
| 2540 | struct pci_dev *pci, |
| 2541 | const char *modelname, |
| 2542 | int omni, |
| 2543 | int cs8427_timeout, |
| 2544 | int dxr_enable, |
| 2545 | struct snd_ice1712 **r_ice1712) |
| 2546 | { |
| 2547 | struct snd_ice1712 *ice; |
| 2548 | int err; |
| 2549 | static struct snd_device_ops ops = { |
| 2550 | .dev_free = snd_ice1712_dev_free, |
| 2551 | }; |
| 2552 | |
| 2553 | *r_ice1712 = NULL; |
| 2554 | |
| 2555 | /* enable PCI device */ |
| 2556 | err = pci_enable_device(pci); |
| 2557 | if (err < 0) |
| 2558 | return err; |
| 2559 | /* check, if we can restrict PCI DMA transfers to 28 bits */ |
| 2560 | if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 || |
| 2561 | pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) { |
| 2562 | snd_printk(KERN_ERR "architecture does not support 28bit PCI busmaster DMA\n"); |
| 2563 | pci_disable_device(pci); |
| 2564 | return -ENXIO; |
| 2565 | } |
| 2566 | |
| 2567 | ice = kzalloc(sizeof(*ice), GFP_KERNEL); |
| 2568 | if (ice == NULL) { |
| 2569 | pci_disable_device(pci); |
| 2570 | return -ENOMEM; |
| 2571 | } |
| 2572 | ice->omni = omni ? 1 : 0; |
| 2573 | if (cs8427_timeout < 1) |
| 2574 | cs8427_timeout = 1; |
| 2575 | else if (cs8427_timeout > 1000) |
| 2576 | cs8427_timeout = 1000; |
| 2577 | ice->cs8427_timeout = cs8427_timeout; |
| 2578 | ice->dxr_enable = dxr_enable; |
| 2579 | spin_lock_init(&ice->reg_lock); |
| 2580 | mutex_init(&ice->gpio_mutex); |
| 2581 | mutex_init(&ice->i2c_mutex); |
| 2582 | mutex_init(&ice->open_mutex); |
| 2583 | ice->gpio.set_mask = snd_ice1712_set_gpio_mask; |
| 2584 | ice->gpio.get_mask = snd_ice1712_get_gpio_mask; |
| 2585 | ice->gpio.set_dir = snd_ice1712_set_gpio_dir; |
| 2586 | ice->gpio.get_dir = snd_ice1712_get_gpio_dir; |
| 2587 | ice->gpio.set_data = snd_ice1712_set_gpio_data; |
| 2588 | ice->gpio.get_data = snd_ice1712_get_gpio_data; |
| 2589 | |
| 2590 | ice->spdif.cs8403_bits = |
| 2591 | ice->spdif.cs8403_stream_bits = (0x01 | /* consumer format */ |
| 2592 | 0x10 | /* no emphasis */ |
| 2593 | 0x20); /* PCM encoder/decoder */ |
| 2594 | ice->card = card; |
| 2595 | ice->pci = pci; |
| 2596 | ice->irq = -1; |
| 2597 | pci_set_master(pci); |
| 2598 | pci_write_config_word(ice->pci, 0x40, 0x807f); |
| 2599 | pci_write_config_word(ice->pci, 0x42, 0x0006); |
| 2600 | snd_ice1712_proc_init(ice); |
| 2601 | synchronize_irq(pci->irq); |
| 2602 | |
| 2603 | card->private_data = ice; |
| 2604 | |
| 2605 | err = pci_request_regions(pci, "ICE1712"); |
| 2606 | if (err < 0) { |
| 2607 | kfree(ice); |
| 2608 | pci_disable_device(pci); |
| 2609 | return err; |
| 2610 | } |
| 2611 | ice->port = pci_resource_start(pci, 0); |
| 2612 | ice->ddma_port = pci_resource_start(pci, 1); |
| 2613 | ice->dmapath_port = pci_resource_start(pci, 2); |
| 2614 | ice->profi_port = pci_resource_start(pci, 3); |
| 2615 | |
| 2616 | if (request_irq(pci->irq, snd_ice1712_interrupt, IRQF_SHARED, |
| 2617 | KBUILD_MODNAME, ice)) { |
| 2618 | snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); |
| 2619 | snd_ice1712_free(ice); |
| 2620 | return -EIO; |
| 2621 | } |
| 2622 | |
| 2623 | ice->irq = pci->irq; |
| 2624 | |
| 2625 | if (snd_ice1712_read_eeprom(ice, modelname) < 0) { |
| 2626 | snd_ice1712_free(ice); |
| 2627 | return -EIO; |
| 2628 | } |
| 2629 | if (snd_ice1712_chip_init(ice) < 0) { |
| 2630 | snd_ice1712_free(ice); |
| 2631 | return -EIO; |
| 2632 | } |
| 2633 | |
| 2634 | /* unmask used interrupts */ |
| 2635 | outb(((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) == 0 ? |
| 2636 | ICE1712_IRQ_MPU2 : 0) | |
| 2637 | ((ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_NO_CON_AC97) ? |
| 2638 | ICE1712_IRQ_PBKDS | ICE1712_IRQ_CONCAP | ICE1712_IRQ_CONPBK : 0), |
| 2639 | ICEREG(ice, IRQMASK)); |
| 2640 | outb(0x00, ICEMT(ice, IRQ)); |
| 2641 | |
| 2642 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ice, &ops); |
| 2643 | if (err < 0) { |
| 2644 | snd_ice1712_free(ice); |
| 2645 | return err; |
| 2646 | } |
| 2647 | |
| 2648 | snd_card_set_dev(card, &pci->dev); |
| 2649 | |
| 2650 | *r_ice1712 = ice; |
| 2651 | return 0; |
| 2652 | } |
| 2653 | |
| 2654 | |
| 2655 | /* |
| 2656 | * |
| 2657 | * Registration |
| 2658 | * |
| 2659 | */ |
| 2660 | |
| 2661 | static struct snd_ice1712_card_info no_matched __devinitdata; |
| 2662 | |
| 2663 | static int __devinit snd_ice1712_probe(struct pci_dev *pci, |
| 2664 | const struct pci_device_id *pci_id) |
| 2665 | { |
| 2666 | static int dev; |
| 2667 | struct snd_card *card; |
| 2668 | struct snd_ice1712 *ice; |
| 2669 | int pcm_dev = 0, err; |
| 2670 | struct snd_ice1712_card_info * const *tbl, *c; |
| 2671 | |
| 2672 | if (dev >= SNDRV_CARDS) |
| 2673 | return -ENODEV; |
| 2674 | if (!enable[dev]) { |
| 2675 | dev++; |
| 2676 | return -ENOENT; |
| 2677 | } |
| 2678 | |
| 2679 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); |
| 2680 | if (err < 0) |
| 2681 | return err; |
| 2682 | |
| 2683 | strcpy(card->driver, "ICE1712"); |
| 2684 | strcpy(card->shortname, "ICEnsemble ICE1712"); |
| 2685 | |
| 2686 | err = snd_ice1712_create(card, pci, model[dev], omni[dev], |
| 2687 | cs8427_timeout[dev], dxr_enable[dev], &ice); |
| 2688 | if (err < 0) { |
| 2689 | snd_card_free(card); |
| 2690 | return err; |
| 2691 | } |
| 2692 | |
| 2693 | for (tbl = card_tables; *tbl; tbl++) { |
| 2694 | for (c = *tbl; c->subvendor; c++) { |
| 2695 | if (c->subvendor == ice->eeprom.subvendor) { |
| 2696 | strcpy(card->shortname, c->name); |
| 2697 | if (c->driver) /* specific driver? */ |
| 2698 | strcpy(card->driver, c->driver); |
| 2699 | if (c->chip_init) { |
| 2700 | err = c->chip_init(ice); |
| 2701 | if (err < 0) { |
| 2702 | snd_card_free(card); |
| 2703 | return err; |
| 2704 | } |
| 2705 | } |
| 2706 | goto __found; |
| 2707 | } |
| 2708 | } |
| 2709 | } |
| 2710 | c = &no_matched; |
| 2711 | __found: |
| 2712 | |
| 2713 | err = snd_ice1712_pcm_profi(ice, pcm_dev++, NULL); |
| 2714 | if (err < 0) { |
| 2715 | snd_card_free(card); |
| 2716 | return err; |
| 2717 | } |
| 2718 | |
| 2719 | if (ice_has_con_ac97(ice)) { |
| 2720 | err = snd_ice1712_pcm(ice, pcm_dev++, NULL); |
| 2721 | if (err < 0) { |
| 2722 | snd_card_free(card); |
| 2723 | return err; |
| 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | err = snd_ice1712_ac97_mixer(ice); |
| 2728 | if (err < 0) { |
| 2729 | snd_card_free(card); |
| 2730 | return err; |
| 2731 | } |
| 2732 | |
| 2733 | err = snd_ice1712_build_controls(ice); |
| 2734 | if (err < 0) { |
| 2735 | snd_card_free(card); |
| 2736 | return err; |
| 2737 | } |
| 2738 | |
| 2739 | if (c->build_controls) { |
| 2740 | err = c->build_controls(ice); |
| 2741 | if (err < 0) { |
| 2742 | snd_card_free(card); |
| 2743 | return err; |
| 2744 | } |
| 2745 | } |
| 2746 | |
| 2747 | if (ice_has_con_ac97(ice)) { |
| 2748 | err = snd_ice1712_pcm_ds(ice, pcm_dev++, NULL); |
| 2749 | if (err < 0) { |
| 2750 | snd_card_free(card); |
| 2751 | return err; |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | if (!c->no_mpu401) { |
| 2756 | err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, |
| 2757 | ICEREG(ice, MPU1_CTRL), |
| 2758 | c->mpu401_1_info_flags | |
| 2759 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
| 2760 | -1, &ice->rmidi[0]); |
| 2761 | if (err < 0) { |
| 2762 | snd_card_free(card); |
| 2763 | return err; |
| 2764 | } |
| 2765 | if (c->mpu401_1_name) |
| 2766 | /* Preferred name available in card_info */ |
| 2767 | snprintf(ice->rmidi[0]->name, |
| 2768 | sizeof(ice->rmidi[0]->name), |
| 2769 | "%s %d", c->mpu401_1_name, card->number); |
| 2770 | |
| 2771 | if (ice->eeprom.data[ICE_EEP1_CODEC] & ICE1712_CFG_2xMPU401) { |
| 2772 | /* 2nd port used */ |
| 2773 | err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712, |
| 2774 | ICEREG(ice, MPU2_CTRL), |
| 2775 | c->mpu401_2_info_flags | |
| 2776 | MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK, |
| 2777 | -1, &ice->rmidi[1]); |
| 2778 | |
| 2779 | if (err < 0) { |
| 2780 | snd_card_free(card); |
| 2781 | return err; |
| 2782 | } |
| 2783 | if (c->mpu401_2_name) |
| 2784 | /* Preferred name available in card_info */ |
| 2785 | snprintf(ice->rmidi[1]->name, |
| 2786 | sizeof(ice->rmidi[1]->name), |
| 2787 | "%s %d", c->mpu401_2_name, |
| 2788 | card->number); |
| 2789 | } |
| 2790 | } |
| 2791 | |
| 2792 | snd_ice1712_set_input_clock_source(ice, 0); |
| 2793 | |
| 2794 | sprintf(card->longname, "%s at 0x%lx, irq %i", |
| 2795 | card->shortname, ice->port, ice->irq); |
| 2796 | |
| 2797 | err = snd_card_register(card); |
| 2798 | if (err < 0) { |
| 2799 | snd_card_free(card); |
| 2800 | return err; |
| 2801 | } |
| 2802 | pci_set_drvdata(pci, card); |
| 2803 | dev++; |
| 2804 | return 0; |
| 2805 | } |
| 2806 | |
| 2807 | static void __devexit snd_ice1712_remove(struct pci_dev *pci) |
| 2808 | { |
| 2809 | snd_card_free(pci_get_drvdata(pci)); |
| 2810 | pci_set_drvdata(pci, NULL); |
| 2811 | } |
| 2812 | |
| 2813 | static struct pci_driver driver = { |
| 2814 | .name = KBUILD_MODNAME, |
| 2815 | .id_table = snd_ice1712_ids, |
| 2816 | .probe = snd_ice1712_probe, |
| 2817 | .remove = __devexit_p(snd_ice1712_remove), |
| 2818 | }; |
| 2819 | |
| 2820 | static int __init alsa_card_ice1712_init(void) |
| 2821 | { |
| 2822 | return pci_register_driver(&driver); |
| 2823 | } |
| 2824 | |
| 2825 | static void __exit alsa_card_ice1712_exit(void) |
| 2826 | { |
| 2827 | pci_unregister_driver(&driver); |
| 2828 | } |
| 2829 | |
| 2830 | module_init(alsa_card_ice1712_init) |
| 2831 | module_exit(alsa_card_ice1712_exit) |