Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> |
| 3 | * Routines for control of AD1848/AD1847/CS4248 |
| 4 | * |
| 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 | #define SNDRV_MAIN_OBJECT_FILE |
| 23 | #include <sound/driver.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <sound/core.h> |
| 30 | #include <sound/ad1848.h> |
| 31 | #include <sound/control.h> |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 32 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <sound/pcm_params.h> |
| 34 | |
| 35 | #include <asm/io.h> |
| 36 | #include <asm/dma.h> |
| 37 | |
| 38 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); |
| 39 | MODULE_DESCRIPTION("Routines for control of AD1848/AD1847/CS4248"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
| 42 | #if 0 |
| 43 | #define SNDRV_DEBUG_MCE |
| 44 | #endif |
| 45 | |
| 46 | /* |
| 47 | * Some variables |
| 48 | */ |
| 49 | |
| 50 | static unsigned char freq_bits[14] = { |
| 51 | /* 5510 */ 0x00 | AD1848_XTAL2, |
| 52 | /* 6620 */ 0x0E | AD1848_XTAL2, |
| 53 | /* 8000 */ 0x00 | AD1848_XTAL1, |
| 54 | /* 9600 */ 0x0E | AD1848_XTAL1, |
| 55 | /* 11025 */ 0x02 | AD1848_XTAL2, |
| 56 | /* 16000 */ 0x02 | AD1848_XTAL1, |
| 57 | /* 18900 */ 0x04 | AD1848_XTAL2, |
| 58 | /* 22050 */ 0x06 | AD1848_XTAL2, |
| 59 | /* 27042 */ 0x04 | AD1848_XTAL1, |
| 60 | /* 32000 */ 0x06 | AD1848_XTAL1, |
| 61 | /* 33075 */ 0x0C | AD1848_XTAL2, |
| 62 | /* 37800 */ 0x08 | AD1848_XTAL2, |
| 63 | /* 44100 */ 0x0A | AD1848_XTAL2, |
| 64 | /* 48000 */ 0x0C | AD1848_XTAL1 |
| 65 | }; |
| 66 | |
| 67 | static unsigned int rates[14] = { |
| 68 | 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050, |
| 69 | 27042, 32000, 33075, 37800, 44100, 48000 |
| 70 | }; |
| 71 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 72 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 73 | .count = ARRAY_SIZE(rates), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | .list = rates, |
| 75 | .mask = 0, |
| 76 | }; |
| 77 | |
| 78 | static unsigned char snd_ad1848_original_image[16] = |
| 79 | { |
| 80 | 0x00, /* 00 - lic */ |
| 81 | 0x00, /* 01 - ric */ |
| 82 | 0x9f, /* 02 - la1ic */ |
| 83 | 0x9f, /* 03 - ra1ic */ |
| 84 | 0x9f, /* 04 - la2ic */ |
| 85 | 0x9f, /* 05 - ra2ic */ |
| 86 | 0xbf, /* 06 - loc */ |
| 87 | 0xbf, /* 07 - roc */ |
| 88 | 0x20, /* 08 - dfr */ |
| 89 | AD1848_AUTOCALIB, /* 09 - ic */ |
| 90 | 0x00, /* 0a - pc */ |
| 91 | 0x00, /* 0b - ti */ |
| 92 | 0x00, /* 0c - mi */ |
| 93 | 0x00, /* 0d - lbc */ |
| 94 | 0x00, /* 0e - dru */ |
| 95 | 0x00, /* 0f - drl */ |
| 96 | }; |
| 97 | |
| 98 | /* |
| 99 | * Basic I/O functions |
| 100 | */ |
| 101 | |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 102 | static void snd_ad1848_wait(struct snd_ad1848 *chip) |
| 103 | { |
| 104 | int timeout; |
| 105 | |
| 106 | for (timeout = 250; timeout > 0; timeout--) { |
| 107 | if ((inb(AD1848P(chip, REGSEL)) & AD1848_INIT) == 0) |
| 108 | break; |
| 109 | udelay(100); |
| 110 | } |
| 111 | } |
| 112 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 113 | void snd_ad1848_out(struct snd_ad1848 *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | unsigned char reg, |
| 115 | unsigned char value) |
| 116 | { |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 117 | snd_ad1848_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #ifdef CONFIG_SND_DEBUG |
| 119 | if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 120 | snd_printk(KERN_WARNING "auto calibration time out - " |
| 121 | "reg = 0x%x, value = 0x%x\n", reg, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #endif |
| 123 | outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); |
| 124 | outb(chip->image[reg] = value, AD1848P(chip, REG)); |
| 125 | mb(); |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 126 | snd_printdd("codec out - reg 0x%x = 0x%x\n", |
| 127 | chip->mce_bit | reg, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 130 | EXPORT_SYMBOL(snd_ad1848_out); |
| 131 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 132 | static void snd_ad1848_dout(struct snd_ad1848 *chip, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | unsigned char reg, unsigned char value) |
| 134 | { |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 135 | snd_ad1848_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); |
| 137 | outb(value, AD1848P(chip, REG)); |
| 138 | mb(); |
| 139 | } |
| 140 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 141 | static unsigned char snd_ad1848_in(struct snd_ad1848 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 143 | snd_ad1848_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #ifdef CONFIG_SND_DEBUG |
| 145 | if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 146 | snd_printk(KERN_WARNING "auto calibration time out - " |
| 147 | "reg = 0x%x\n", reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #endif |
| 149 | outb(chip->mce_bit | reg, AD1848P(chip, REGSEL)); |
| 150 | mb(); |
| 151 | return inb(AD1848P(chip, REG)); |
| 152 | } |
| 153 | |
| 154 | #if 0 |
| 155 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 156 | static void snd_ad1848_debug(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | printk("AD1848 REGS: INDEX = 0x%02x ", inb(AD1848P(chip, REGSEL))); |
| 159 | printk(" STATUS = 0x%02x\n", inb(AD1848P(chip, STATUS))); |
| 160 | printk(" 0x00: left input = 0x%02x ", snd_ad1848_in(chip, 0x00)); |
| 161 | printk(" 0x08: playback format = 0x%02x\n", snd_ad1848_in(chip, 0x08)); |
| 162 | printk(" 0x01: right input = 0x%02x ", snd_ad1848_in(chip, 0x01)); |
| 163 | printk(" 0x09: iface (CFIG 1) = 0x%02x\n", snd_ad1848_in(chip, 0x09)); |
| 164 | printk(" 0x02: AUXA left = 0x%02x ", snd_ad1848_in(chip, 0x02)); |
| 165 | printk(" 0x0a: pin control = 0x%02x\n", snd_ad1848_in(chip, 0x0a)); |
| 166 | printk(" 0x03: AUXA right = 0x%02x ", snd_ad1848_in(chip, 0x03)); |
| 167 | printk(" 0x0b: init & status = 0x%02x\n", snd_ad1848_in(chip, 0x0b)); |
| 168 | printk(" 0x04: AUXB left = 0x%02x ", snd_ad1848_in(chip, 0x04)); |
| 169 | printk(" 0x0c: revision & mode = 0x%02x\n", snd_ad1848_in(chip, 0x0c)); |
| 170 | printk(" 0x05: AUXB right = 0x%02x ", snd_ad1848_in(chip, 0x05)); |
| 171 | printk(" 0x0d: loopback = 0x%02x\n", snd_ad1848_in(chip, 0x0d)); |
| 172 | printk(" 0x06: left output = 0x%02x ", snd_ad1848_in(chip, 0x06)); |
| 173 | printk(" 0x0e: data upr count = 0x%02x\n", snd_ad1848_in(chip, 0x0e)); |
| 174 | printk(" 0x07: right output = 0x%02x ", snd_ad1848_in(chip, 0x07)); |
| 175 | printk(" 0x0f: data lwr count = 0x%02x\n", snd_ad1848_in(chip, 0x0f)); |
| 176 | } |
| 177 | |
| 178 | #endif |
| 179 | |
| 180 | /* |
| 181 | * AD1848 detection / MCE routines |
| 182 | */ |
| 183 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 184 | static void snd_ad1848_mce_up(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | unsigned long flags; |
| 187 | int timeout; |
| 188 | |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 189 | snd_ad1848_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #ifdef CONFIG_SND_DEBUG |
| 191 | if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 192 | snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | #endif |
| 194 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 195 | chip->mce_bit |= AD1848_MCE; |
| 196 | timeout = inb(AD1848P(chip, REGSEL)); |
| 197 | if (timeout == 0x80) |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 198 | snd_printk(KERN_WARNING "mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | if (!(timeout & AD1848_MCE)) |
| 200 | outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL)); |
| 201 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 202 | } |
| 203 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 204 | static void snd_ad1848_mce_down(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
| 206 | unsigned long flags; |
| 207 | int timeout; |
| 208 | signed long time; |
| 209 | |
| 210 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 211 | for (timeout = 5; timeout > 0; timeout--) |
| 212 | inb(AD1848P(chip, REGSEL)); |
| 213 | /* end of cleanup sequence */ |
| 214 | for (timeout = 12000; timeout > 0 && (inb(AD1848P(chip, REGSEL)) & AD1848_INIT); timeout--) |
| 215 | udelay(100); |
| 216 | #if 0 |
| 217 | printk("(1) timeout = %i\n", timeout); |
| 218 | #endif |
| 219 | #ifdef CONFIG_SND_DEBUG |
| 220 | if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 221 | snd_printk(KERN_WARNING "mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | #endif |
| 223 | chip->mce_bit &= ~AD1848_MCE; |
| 224 | timeout = inb(AD1848P(chip, REGSEL)); |
| 225 | outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL)); |
| 226 | if (timeout == 0x80) |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 227 | snd_printk(KERN_WARNING "mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if ((timeout & AD1848_MCE) == 0) { |
| 229 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 230 | return; |
| 231 | } |
| 232 | /* calibration process */ |
| 233 | |
| 234 | for (timeout = 500; timeout > 0 && (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0; timeout--); |
| 235 | if ((snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) == 0) { |
| 236 | snd_printd("mce_down - auto calibration time out (1)\n"); |
| 237 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 238 | return; |
| 239 | } |
| 240 | #if 0 |
| 241 | printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies); |
| 242 | #endif |
| 243 | time = HZ / 4; |
| 244 | while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) { |
| 245 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 246 | if (time <= 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 247 | snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | return; |
| 249 | } |
Takashi Iwai | e65365d | 2007-06-25 12:09:32 +0200 | [diff] [blame] | 250 | time = schedule_timeout(time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 252 | } |
| 253 | #if 0 |
| 254 | printk("(3) jiffies = %li\n", jiffies); |
| 255 | #endif |
| 256 | time = HZ / 10; |
| 257 | while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) { |
| 258 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 259 | if (time <= 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 260 | snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | return; |
| 262 | } |
Takashi Iwai | e65365d | 2007-06-25 12:09:32 +0200 | [diff] [blame] | 263 | time = schedule_timeout(time); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 265 | } |
| 266 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 267 | #if 0 |
| 268 | printk("(4) jiffies = %li\n", jiffies); |
| 269 | snd_printk("mce_down - exit = 0x%x\n", inb(AD1848P(chip, REGSEL))); |
| 270 | #endif |
| 271 | } |
| 272 | |
| 273 | static unsigned int snd_ad1848_get_count(unsigned char format, |
| 274 | unsigned int size) |
| 275 | { |
| 276 | switch (format & 0xe0) { |
| 277 | case AD1848_LINEAR_16: |
| 278 | size >>= 1; |
| 279 | break; |
| 280 | } |
| 281 | if (format & AD1848_STEREO) |
| 282 | size >>= 1; |
| 283 | return size; |
| 284 | } |
| 285 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 286 | static int snd_ad1848_trigger(struct snd_ad1848 *chip, unsigned char what, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | int channel, int cmd) |
| 288 | { |
| 289 | int result = 0; |
| 290 | |
| 291 | #if 0 |
| 292 | printk("codec trigger!!! - what = %i, enable = %i, status = 0x%x\n", what, enable, inb(AD1848P(card, STATUS))); |
| 293 | #endif |
| 294 | spin_lock(&chip->reg_lock); |
| 295 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 296 | if (chip->image[AD1848_IFACE_CTRL] & what) { |
| 297 | spin_unlock(&chip->reg_lock); |
| 298 | return 0; |
| 299 | } |
| 300 | snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] |= what); |
| 301 | chip->mode |= AD1848_MODE_RUNNING; |
| 302 | } else if (cmd == SNDRV_PCM_TRIGGER_STOP) { |
| 303 | if (!(chip->image[AD1848_IFACE_CTRL] & what)) { |
| 304 | spin_unlock(&chip->reg_lock); |
| 305 | return 0; |
| 306 | } |
| 307 | snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL] &= ~what); |
| 308 | chip->mode &= ~AD1848_MODE_RUNNING; |
| 309 | } else { |
| 310 | result = -EINVAL; |
| 311 | } |
| 312 | spin_unlock(&chip->reg_lock); |
| 313 | return result; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * CODEC I/O |
| 318 | */ |
| 319 | |
| 320 | static unsigned char snd_ad1848_get_rate(unsigned int rate) |
| 321 | { |
| 322 | int i; |
| 323 | |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 324 | for (i = 0; i < ARRAY_SIZE(rates); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | if (rate == rates[i]) |
| 326 | return freq_bits[i]; |
| 327 | snd_BUG(); |
Krzysztof Helt | 8e6a2c2 | 2007-09-06 15:03:22 +0200 | [diff] [blame] | 328 | return freq_bits[ARRAY_SIZE(rates) - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 331 | static int snd_ad1848_ioctl(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | unsigned int cmd, void *arg) |
| 333 | { |
| 334 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 335 | } |
| 336 | |
| 337 | static unsigned char snd_ad1848_get_format(int format, int channels) |
| 338 | { |
| 339 | unsigned char rformat; |
| 340 | |
| 341 | rformat = AD1848_LINEAR_8; |
| 342 | switch (format) { |
| 343 | case SNDRV_PCM_FORMAT_A_LAW: rformat = AD1848_ALAW_8; break; |
| 344 | case SNDRV_PCM_FORMAT_MU_LAW: rformat = AD1848_ULAW_8; break; |
| 345 | case SNDRV_PCM_FORMAT_S16_LE: rformat = AD1848_LINEAR_16; break; |
| 346 | } |
| 347 | if (channels > 1) |
| 348 | rformat |= AD1848_STEREO; |
| 349 | #if 0 |
| 350 | snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode); |
| 351 | #endif |
| 352 | return rformat; |
| 353 | } |
| 354 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 355 | static void snd_ad1848_calibrate_mute(struct snd_ad1848 *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | unsigned long flags; |
| 358 | |
| 359 | mute = mute ? 1 : 0; |
| 360 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 361 | if (chip->calibrate_mute == mute) { |
| 362 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 363 | return; |
| 364 | } |
| 365 | if (!mute) { |
| 366 | snd_ad1848_dout(chip, AD1848_LEFT_INPUT, chip->image[AD1848_LEFT_INPUT]); |
| 367 | snd_ad1848_dout(chip, AD1848_RIGHT_INPUT, chip->image[AD1848_RIGHT_INPUT]); |
| 368 | } |
| 369 | snd_ad1848_dout(chip, AD1848_AUX1_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_LEFT_INPUT]); |
| 370 | snd_ad1848_dout(chip, AD1848_AUX1_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX1_RIGHT_INPUT]); |
| 371 | snd_ad1848_dout(chip, AD1848_AUX2_LEFT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_LEFT_INPUT]); |
| 372 | snd_ad1848_dout(chip, AD1848_AUX2_RIGHT_INPUT, mute ? 0x80 : chip->image[AD1848_AUX2_RIGHT_INPUT]); |
| 373 | snd_ad1848_dout(chip, AD1848_LEFT_OUTPUT, mute ? 0x80 : chip->image[AD1848_LEFT_OUTPUT]); |
| 374 | snd_ad1848_dout(chip, AD1848_RIGHT_OUTPUT, mute ? 0x80 : chip->image[AD1848_RIGHT_OUTPUT]); |
| 375 | chip->calibrate_mute = mute; |
| 376 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 377 | } |
| 378 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 379 | static void snd_ad1848_set_data_format(struct snd_ad1848 *chip, struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
| 381 | if (hw_params == NULL) { |
| 382 | chip->image[AD1848_DATA_FORMAT] = 0x20; |
| 383 | } else { |
| 384 | chip->image[AD1848_DATA_FORMAT] = |
| 385 | snd_ad1848_get_format(params_format(hw_params), params_channels(hw_params)) | |
| 386 | snd_ad1848_get_rate(params_rate(hw_params)); |
| 387 | } |
| 388 | // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]); |
| 389 | } |
| 390 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 391 | static int snd_ad1848_open(struct snd_ad1848 *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | { |
| 393 | unsigned long flags; |
| 394 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 395 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (chip->mode & AD1848_MODE_OPEN) { |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 397 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | return -EAGAIN; |
| 399 | } |
| 400 | snd_ad1848_mce_down(chip); |
| 401 | |
| 402 | #ifdef SNDRV_DEBUG_MCE |
| 403 | snd_printk("open: (1)\n"); |
| 404 | #endif |
| 405 | snd_ad1848_mce_up(chip); |
| 406 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 407 | chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO | |
| 408 | AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO | |
| 409 | AD1848_CALIB_MODE); |
| 410 | chip->image[AD1848_IFACE_CTRL] |= AD1848_AUTOCALIB; |
| 411 | snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]); |
| 412 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 413 | snd_ad1848_mce_down(chip); |
| 414 | |
| 415 | #ifdef SNDRV_DEBUG_MCE |
| 416 | snd_printk("open: (2)\n"); |
| 417 | #endif |
| 418 | |
| 419 | snd_ad1848_set_data_format(chip, NULL); |
| 420 | |
| 421 | snd_ad1848_mce_up(chip); |
| 422 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 423 | snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]); |
| 424 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 425 | snd_ad1848_mce_down(chip); |
| 426 | |
| 427 | #ifdef SNDRV_DEBUG_MCE |
| 428 | snd_printk("open: (3)\n"); |
| 429 | #endif |
| 430 | |
| 431 | /* ok. now enable and ack CODEC IRQ */ |
| 432 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 433 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 434 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 435 | chip->image[AD1848_PIN_CTRL] |= AD1848_IRQ_ENABLE; |
| 436 | snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]); |
| 437 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 438 | |
| 439 | chip->mode = mode; |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 440 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | return 0; |
| 443 | } |
| 444 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 445 | static void snd_ad1848_close(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | unsigned long flags; |
| 448 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 449 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | if (!chip->mode) { |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 451 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return; |
| 453 | } |
| 454 | /* disable IRQ */ |
| 455 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 456 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 457 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 458 | chip->image[AD1848_PIN_CTRL] &= ~AD1848_IRQ_ENABLE; |
| 459 | snd_ad1848_out(chip, AD1848_PIN_CTRL, chip->image[AD1848_PIN_CTRL]); |
| 460 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 461 | |
| 462 | /* now disable capture & playback */ |
| 463 | |
| 464 | snd_ad1848_mce_up(chip); |
| 465 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 466 | chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO | |
| 467 | AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO); |
| 468 | snd_ad1848_out(chip, AD1848_IFACE_CTRL, chip->image[AD1848_IFACE_CTRL]); |
| 469 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 470 | snd_ad1848_mce_down(chip); |
| 471 | |
| 472 | /* clear IRQ again */ |
| 473 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 474 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 475 | outb(0, AD1848P(chip, STATUS)); /* clear IRQ */ |
| 476 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 477 | |
| 478 | chip->mode = 0; |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 479 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | /* |
| 483 | * ok.. exported functions.. |
| 484 | */ |
| 485 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 486 | static int snd_ad1848_playback_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | int cmd) |
| 488 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 489 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd); |
| 491 | } |
| 492 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 493 | static int snd_ad1848_capture_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | int cmd) |
| 495 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 496 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd); |
| 498 | } |
| 499 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 500 | static int snd_ad1848_playback_hw_params(struct snd_pcm_substream *substream, |
| 501 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 503 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | unsigned long flags; |
| 505 | int err; |
| 506 | |
| 507 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 508 | return err; |
| 509 | snd_ad1848_calibrate_mute(chip, 1); |
| 510 | snd_ad1848_set_data_format(chip, hw_params); |
| 511 | snd_ad1848_mce_up(chip); |
| 512 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 513 | snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]); |
| 514 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 515 | snd_ad1848_mce_down(chip); |
| 516 | snd_ad1848_calibrate_mute(chip, 0); |
| 517 | return 0; |
| 518 | } |
| 519 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 520 | static int snd_ad1848_playback_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
| 522 | return snd_pcm_lib_free_pages(substream); |
| 523 | } |
| 524 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 525 | static int snd_ad1848_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 527 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
| 528 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | unsigned long flags; |
| 530 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 531 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 532 | |
| 533 | chip->dma_size = size; |
| 534 | chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_PLAYBACK_ENABLE | AD1848_PLAYBACK_PIO); |
| 535 | snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
| 536 | count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1; |
| 537 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 538 | snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count); |
| 539 | snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8)); |
| 540 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 541 | return 0; |
| 542 | } |
| 543 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 544 | static int snd_ad1848_capture_hw_params(struct snd_pcm_substream *substream, |
| 545 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 547 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | unsigned long flags; |
| 549 | int err; |
| 550 | |
| 551 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 552 | return err; |
| 553 | snd_ad1848_calibrate_mute(chip, 1); |
| 554 | snd_ad1848_set_data_format(chip, hw_params); |
| 555 | snd_ad1848_mce_up(chip); |
| 556 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 557 | snd_ad1848_out(chip, AD1848_DATA_FORMAT, chip->image[AD1848_DATA_FORMAT]); |
| 558 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 559 | snd_ad1848_mce_down(chip); |
| 560 | snd_ad1848_calibrate_mute(chip, 0); |
| 561 | return 0; |
| 562 | } |
| 563 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 564 | static int snd_ad1848_capture_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
| 566 | return snd_pcm_lib_free_pages(substream); |
| 567 | } |
| 568 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 569 | static int snd_ad1848_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 571 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
| 572 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | unsigned long flags; |
| 574 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 575 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 576 | |
| 577 | chip->dma_size = size; |
| 578 | chip->image[AD1848_IFACE_CTRL] &= ~(AD1848_CAPTURE_ENABLE | AD1848_CAPTURE_PIO); |
| 579 | snd_dma_program(chip->dma, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); |
| 580 | count = snd_ad1848_get_count(chip->image[AD1848_DATA_FORMAT], count) - 1; |
| 581 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 582 | snd_ad1848_out(chip, AD1848_DATA_LWR_CNT, (unsigned char) count); |
| 583 | snd_ad1848_out(chip, AD1848_DATA_UPR_CNT, (unsigned char) (count >> 8)); |
| 584 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 585 | return 0; |
| 586 | } |
| 587 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 588 | static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 590 | struct snd_ad1848 *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | |
| 592 | if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream && |
| 593 | (chip->mode & AD1848_MODE_RUNNING)) |
| 594 | snd_pcm_period_elapsed(chip->playback_substream); |
| 595 | if ((chip->mode & AD1848_MODE_CAPTURE) && chip->capture_substream && |
| 596 | (chip->mode & AD1848_MODE_RUNNING)) |
| 597 | snd_pcm_period_elapsed(chip->capture_substream); |
| 598 | outb(0, AD1848P(chip, STATUS)); /* clear global interrupt bit */ |
| 599 | return IRQ_HANDLED; |
| 600 | } |
| 601 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 602 | static snd_pcm_uframes_t snd_ad1848_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 604 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | size_t ptr; |
| 606 | |
| 607 | if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE)) |
| 608 | return 0; |
| 609 | ptr = snd_dma_pointer(chip->dma, chip->dma_size); |
| 610 | return bytes_to_frames(substream->runtime, ptr); |
| 611 | } |
| 612 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 613 | static snd_pcm_uframes_t snd_ad1848_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 615 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | size_t ptr; |
| 617 | |
| 618 | if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE)) |
| 619 | return 0; |
| 620 | ptr = snd_dma_pointer(chip->dma, chip->dma_size); |
| 621 | return bytes_to_frames(substream->runtime, ptr); |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | |
| 626 | */ |
| 627 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 628 | static void snd_ad1848_thinkpad_twiddle(struct snd_ad1848 *chip, int on) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
| 630 | int tmp; |
| 631 | |
| 632 | if (!chip->thinkpad_flag) return; |
| 633 | |
| 634 | outb(0x1c, AD1848_THINKPAD_CTL_PORT1); |
| 635 | tmp = inb(AD1848_THINKPAD_CTL_PORT2); |
| 636 | |
| 637 | if (on) |
| 638 | /* turn it on */ |
| 639 | tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT; |
| 640 | else |
| 641 | /* turn it off */ |
| 642 | tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT; |
| 643 | |
| 644 | outb(tmp, AD1848_THINKPAD_CTL_PORT2); |
| 645 | |
| 646 | } |
| 647 | |
| 648 | #ifdef CONFIG_PM |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 649 | static void snd_ad1848_suspend(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | snd_pcm_suspend_all(chip->pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (chip->thinkpad_flag) |
| 653 | snd_ad1848_thinkpad_twiddle(chip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 656 | static void snd_ad1848_resume(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 658 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | if (chip->thinkpad_flag) |
| 661 | snd_ad1848_thinkpad_twiddle(chip, 1); |
| 662 | |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 663 | /* clear any pendings IRQ */ |
| 664 | inb(AD1848P(chip, STATUS)); |
| 665 | outb(0, AD1848P(chip, STATUS)); |
| 666 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 668 | snd_ad1848_mce_down(chip); |
| 669 | for (i = 0; i < 16; i++) |
| 670 | snd_ad1848_out(chip, i, chip->image[i]); |
| 671 | snd_ad1848_mce_up(chip); |
| 672 | snd_ad1848_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | #endif /* CONFIG_PM */ |
| 675 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 676 | static int snd_ad1848_probe(struct snd_ad1848 * chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | { |
| 678 | unsigned long flags; |
| 679 | int i, id, rev, ad1847; |
| 680 | unsigned char *ptr; |
| 681 | |
| 682 | #if 0 |
| 683 | snd_ad1848_debug(chip); |
| 684 | #endif |
| 685 | id = ad1847 = 0; |
| 686 | for (i = 0; i < 1000; i++) { |
| 687 | mb(); |
| 688 | if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) |
| 689 | udelay(500); |
| 690 | else { |
| 691 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 692 | snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00); |
| 693 | snd_ad1848_out(chip, AD1848_LEFT_INPUT, 0xaa); |
| 694 | snd_ad1848_out(chip, AD1848_RIGHT_INPUT, 0x45); |
| 695 | rev = snd_ad1848_in(chip, AD1848_RIGHT_INPUT); |
| 696 | if (rev == 0x65) { |
| 697 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 698 | id = 1; |
| 699 | ad1847 = 1; |
| 700 | break; |
| 701 | } |
| 702 | if (snd_ad1848_in(chip, AD1848_LEFT_INPUT) == 0xaa && rev == 0x45) { |
| 703 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 704 | id = 1; |
| 705 | break; |
| 706 | } |
| 707 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 708 | } |
| 709 | } |
| 710 | if (id != 1) |
| 711 | return -ENODEV; /* no valid device found */ |
| 712 | if (chip->hardware == AD1848_HW_DETECT) { |
| 713 | if (ad1847) { |
| 714 | chip->hardware = AD1848_HW_AD1847; |
| 715 | } else { |
| 716 | chip->hardware = AD1848_HW_AD1848; |
| 717 | rev = snd_ad1848_in(chip, AD1848_MISC_INFO); |
| 718 | if (rev & 0x80) { |
| 719 | chip->hardware = AD1848_HW_CS4248; |
| 720 | } else if ((rev & 0x0f) == 0x0a) { |
| 721 | snd_ad1848_out(chip, AD1848_MISC_INFO, 0x40); |
| 722 | for (i = 0; i < 16; ++i) { |
| 723 | if (snd_ad1848_in(chip, i) != snd_ad1848_in(chip, i + 16)) { |
| 724 | chip->hardware = AD1848_HW_CMI8330; |
| 725 | break; |
| 726 | } |
| 727 | } |
| 728 | snd_ad1848_out(chip, AD1848_MISC_INFO, 0x00); |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 733 | inb(AD1848P(chip, STATUS)); /* clear any pendings IRQ */ |
| 734 | outb(0, AD1848P(chip, STATUS)); |
| 735 | mb(); |
| 736 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 737 | |
| 738 | chip->image[AD1848_MISC_INFO] = 0x00; |
| 739 | chip->image[AD1848_IFACE_CTRL] = |
| 740 | (chip->image[AD1848_IFACE_CTRL] & ~AD1848_SINGLE_DMA) | AD1848_SINGLE_DMA; |
| 741 | ptr = (unsigned char *) &chip->image; |
| 742 | snd_ad1848_mce_down(chip); |
| 743 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 744 | for (i = 0; i < 16; i++) /* ok.. fill all AD1848 registers */ |
| 745 | snd_ad1848_out(chip, i, *ptr++); |
| 746 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 747 | snd_ad1848_mce_up(chip); |
| 748 | snd_ad1848_mce_down(chip); |
| 749 | return 0; /* all things are ok.. */ |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | |
| 754 | */ |
| 755 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 756 | static struct snd_pcm_hardware snd_ad1848_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
| 758 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 759 | SNDRV_PCM_INFO_MMAP_VALID), |
| 760 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | |
| 761 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE), |
| 762 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, |
| 763 | .rate_min = 5510, |
| 764 | .rate_max = 48000, |
| 765 | .channels_min = 1, |
| 766 | .channels_max = 2, |
| 767 | .buffer_bytes_max = (128*1024), |
| 768 | .period_bytes_min = 64, |
| 769 | .period_bytes_max = (128*1024), |
| 770 | .periods_min = 1, |
| 771 | .periods_max = 1024, |
| 772 | .fifo_size = 0, |
| 773 | }; |
| 774 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 775 | static struct snd_pcm_hardware snd_ad1848_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
| 777 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 778 | SNDRV_PCM_INFO_MMAP_VALID), |
| 779 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | |
| 780 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE), |
| 781 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, |
| 782 | .rate_min = 5510, |
| 783 | .rate_max = 48000, |
| 784 | .channels_min = 1, |
| 785 | .channels_max = 2, |
| 786 | .buffer_bytes_max = (128*1024), |
| 787 | .period_bytes_min = 64, |
| 788 | .period_bytes_max = (128*1024), |
| 789 | .periods_min = 1, |
| 790 | .periods_max = 1024, |
| 791 | .fifo_size = 0, |
| 792 | }; |
| 793 | |
| 794 | /* |
| 795 | |
| 796 | */ |
| 797 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 798 | static int snd_ad1848_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 800 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
| 801 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | int err; |
| 803 | |
| 804 | if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0) |
| 805 | return err; |
| 806 | chip->playback_substream = substream; |
| 807 | runtime->hw = snd_ad1848_playback; |
| 808 | snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max); |
| 809 | snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max); |
| 810 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); |
| 811 | return 0; |
| 812 | } |
| 813 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 814 | static int snd_ad1848_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 816 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
| 817 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | int err; |
| 819 | |
| 820 | if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0) |
| 821 | return err; |
| 822 | chip->capture_substream = substream; |
| 823 | runtime->hw = snd_ad1848_capture; |
| 824 | snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.buffer_bytes_max); |
| 825 | snd_pcm_limit_isa_dma_size(chip->dma, &runtime->hw.period_bytes_max); |
| 826 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates); |
| 827 | return 0; |
| 828 | } |
| 829 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 830 | static int snd_ad1848_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 832 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | chip->mode &= ~AD1848_MODE_PLAY; |
| 835 | chip->playback_substream = NULL; |
| 836 | snd_ad1848_close(chip); |
| 837 | return 0; |
| 838 | } |
| 839 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 840 | static int snd_ad1848_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 842 | struct snd_ad1848 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | chip->mode &= ~AD1848_MODE_CAPTURE; |
| 845 | chip->capture_substream = NULL; |
| 846 | snd_ad1848_close(chip); |
| 847 | return 0; |
| 848 | } |
| 849 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 850 | static int snd_ad1848_free(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 852 | release_and_free_resource(chip->res_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | if (chip->irq >= 0) |
| 854 | free_irq(chip->irq, (void *) chip); |
| 855 | if (chip->dma >= 0) { |
| 856 | snd_dma_disable(chip->dma); |
| 857 | free_dma(chip->dma); |
| 858 | } |
| 859 | kfree(chip); |
| 860 | return 0; |
| 861 | } |
| 862 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 863 | static int snd_ad1848_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 865 | struct snd_ad1848 *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | return snd_ad1848_free(chip); |
| 867 | } |
| 868 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 869 | static const char *snd_ad1848_chip_id(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | { |
| 871 | switch (chip->hardware) { |
| 872 | case AD1848_HW_AD1847: return "AD1847"; |
| 873 | case AD1848_HW_AD1848: return "AD1848"; |
| 874 | case AD1848_HW_CS4248: return "CS4248"; |
| 875 | case AD1848_HW_CMI8330: return "CMI8330/C3D"; |
| 876 | default: return "???"; |
| 877 | } |
| 878 | } |
| 879 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 880 | int snd_ad1848_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | unsigned long port, |
| 882 | int irq, int dma, |
| 883 | unsigned short hardware, |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 884 | struct snd_ad1848 ** rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 886 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | .dev_free = snd_ad1848_dev_free, |
| 888 | }; |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 889 | struct snd_ad1848 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | int err; |
| 891 | |
| 892 | *rchip = NULL; |
Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 893 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | if (chip == NULL) |
| 895 | return -ENOMEM; |
| 896 | spin_lock_init(&chip->reg_lock); |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 897 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | chip->card = card; |
| 899 | chip->port = port; |
| 900 | chip->irq = -1; |
| 901 | chip->dma = -1; |
| 902 | chip->hardware = hardware; |
| 903 | memcpy(&chip->image, &snd_ad1848_original_image, sizeof(snd_ad1848_original_image)); |
| 904 | |
| 905 | if ((chip->res_port = request_region(port, 4, "AD1848")) == NULL) { |
| 906 | snd_printk(KERN_ERR "ad1848: can't grab port 0x%lx\n", port); |
| 907 | snd_ad1848_free(chip); |
| 908 | return -EBUSY; |
| 909 | } |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 910 | if (request_irq(irq, snd_ad1848_interrupt, IRQF_DISABLED, "AD1848", (void *) chip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq); |
| 912 | snd_ad1848_free(chip); |
| 913 | return -EBUSY; |
| 914 | } |
| 915 | chip->irq = irq; |
| 916 | if (request_dma(dma, "AD1848")) { |
| 917 | snd_printk(KERN_ERR "ad1848: can't grab DMA %d\n", dma); |
| 918 | snd_ad1848_free(chip); |
| 919 | return -EBUSY; |
| 920 | } |
| 921 | chip->dma = dma; |
| 922 | |
| 923 | if (hardware == AD1848_HW_THINKPAD) { |
| 924 | chip->thinkpad_flag = 1; |
| 925 | chip->hardware = AD1848_HW_DETECT; /* reset */ |
| 926 | snd_ad1848_thinkpad_twiddle(chip, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | if (snd_ad1848_probe(chip) < 0) { |
| 930 | snd_ad1848_free(chip); |
| 931 | return -ENODEV; |
| 932 | } |
| 933 | |
| 934 | /* Register device */ |
| 935 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 936 | snd_ad1848_free(chip); |
| 937 | return err; |
| 938 | } |
| 939 | |
Takashi Iwai | 9d70d91 | 2005-11-30 10:12:26 +0100 | [diff] [blame] | 940 | #ifdef CONFIG_PM |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 941 | chip->suspend = snd_ad1848_suspend; |
| 942 | chip->resume = snd_ad1848_resume; |
Takashi Iwai | 9d70d91 | 2005-11-30 10:12:26 +0100 | [diff] [blame] | 943 | #endif |
Takashi Iwai | c66d7f7 | 2005-11-17 16:57:48 +0100 | [diff] [blame] | 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | *rchip = chip; |
| 946 | return 0; |
| 947 | } |
| 948 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 949 | EXPORT_SYMBOL(snd_ad1848_create); |
| 950 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 951 | static struct snd_pcm_ops snd_ad1848_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | .open = snd_ad1848_playback_open, |
| 953 | .close = snd_ad1848_playback_close, |
| 954 | .ioctl = snd_ad1848_ioctl, |
| 955 | .hw_params = snd_ad1848_playback_hw_params, |
| 956 | .hw_free = snd_ad1848_playback_hw_free, |
| 957 | .prepare = snd_ad1848_playback_prepare, |
| 958 | .trigger = snd_ad1848_playback_trigger, |
| 959 | .pointer = snd_ad1848_playback_pointer, |
| 960 | }; |
| 961 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 962 | static struct snd_pcm_ops snd_ad1848_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 963 | .open = snd_ad1848_capture_open, |
| 964 | .close = snd_ad1848_capture_close, |
| 965 | .ioctl = snd_ad1848_ioctl, |
| 966 | .hw_params = snd_ad1848_capture_hw_params, |
| 967 | .hw_free = snd_ad1848_capture_hw_free, |
| 968 | .prepare = snd_ad1848_capture_prepare, |
| 969 | .trigger = snd_ad1848_capture_trigger, |
| 970 | .pointer = snd_ad1848_capture_pointer, |
| 971 | }; |
| 972 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 973 | int snd_ad1848_pcm(struct snd_ad1848 *chip, int device, struct snd_pcm **rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 975 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 976 | int err; |
| 977 | |
| 978 | if ((err = snd_pcm_new(chip->card, "AD1848", device, 1, 1, &pcm)) < 0) |
| 979 | return err; |
| 980 | |
| 981 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops); |
| 982 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops); |
| 983 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | pcm->private_data = chip; |
| 985 | pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; |
| 986 | strcpy(pcm->name, snd_ad1848_chip_id(chip)); |
| 987 | |
| 988 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 989 | snd_dma_isa_data(), |
| 990 | 64*1024, chip->dma > 3 ? 128*1024 : 64*1024); |
| 991 | |
| 992 | chip->pcm = pcm; |
| 993 | if (rpcm) |
| 994 | *rpcm = pcm; |
| 995 | return 0; |
| 996 | } |
| 997 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 998 | EXPORT_SYMBOL(snd_ad1848_pcm); |
| 999 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1000 | const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | { |
| 1002 | return direction == SNDRV_PCM_STREAM_PLAYBACK ? |
| 1003 | &snd_ad1848_playback_ops : &snd_ad1848_capture_ops; |
| 1004 | } |
| 1005 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1006 | EXPORT_SYMBOL(snd_ad1848_get_pcm_ops); |
| 1007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | /* |
| 1009 | * MIXER part |
| 1010 | */ |
| 1011 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1012 | static int snd_ad1848_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | { |
| 1014 | static char *texts[4] = { |
| 1015 | "Line", "Aux", "Mic", "Mix" |
| 1016 | }; |
| 1017 | |
| 1018 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1019 | uinfo->count = 2; |
| 1020 | uinfo->value.enumerated.items = 4; |
| 1021 | if (uinfo->value.enumerated.item > 3) |
| 1022 | uinfo->value.enumerated.item = 3; |
| 1023 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1027 | static int snd_ad1848_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1029 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | unsigned long flags; |
| 1031 | |
| 1032 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1033 | ucontrol->value.enumerated.item[0] = (chip->image[AD1848_LEFT_INPUT] & AD1848_MIXS_ALL) >> 6; |
| 1034 | ucontrol->value.enumerated.item[1] = (chip->image[AD1848_RIGHT_INPUT] & AD1848_MIXS_ALL) >> 6; |
| 1035 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1039 | static int snd_ad1848_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1041 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | unsigned long flags; |
| 1043 | unsigned short left, right; |
| 1044 | int change; |
| 1045 | |
| 1046 | if (ucontrol->value.enumerated.item[0] > 3 || |
| 1047 | ucontrol->value.enumerated.item[1] > 3) |
| 1048 | return -EINVAL; |
| 1049 | left = ucontrol->value.enumerated.item[0] << 6; |
| 1050 | right = ucontrol->value.enumerated.item[1] << 6; |
| 1051 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1052 | left = (chip->image[AD1848_LEFT_INPUT] & ~AD1848_MIXS_ALL) | left; |
| 1053 | right = (chip->image[AD1848_RIGHT_INPUT] & ~AD1848_MIXS_ALL) | right; |
| 1054 | change = left != chip->image[AD1848_LEFT_INPUT] || |
| 1055 | right != chip->image[AD1848_RIGHT_INPUT]; |
| 1056 | snd_ad1848_out(chip, AD1848_LEFT_INPUT, left); |
| 1057 | snd_ad1848_out(chip, AD1848_RIGHT_INPUT, right); |
| 1058 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1059 | return change; |
| 1060 | } |
| 1061 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1062 | static int snd_ad1848_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | { |
| 1064 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1065 | |
| 1066 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1067 | uinfo->count = 1; |
| 1068 | uinfo->value.integer.min = 0; |
| 1069 | uinfo->value.integer.max = mask; |
| 1070 | return 0; |
| 1071 | } |
| 1072 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1073 | static int snd_ad1848_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1075 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | unsigned long flags; |
| 1077 | int reg = kcontrol->private_value & 0xff; |
| 1078 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1079 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1080 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1081 | |
| 1082 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1083 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; |
| 1084 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1085 | if (invert) |
| 1086 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1087 | return 0; |
| 1088 | } |
| 1089 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1090 | static int snd_ad1848_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1092 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | unsigned long flags; |
| 1094 | int reg = kcontrol->private_value & 0xff; |
| 1095 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1096 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1097 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1098 | int change; |
| 1099 | unsigned short val; |
| 1100 | |
| 1101 | val = (ucontrol->value.integer.value[0] & mask); |
| 1102 | if (invert) |
| 1103 | val = mask - val; |
| 1104 | val <<= shift; |
| 1105 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1106 | val = (chip->image[reg] & ~(mask << shift)) | val; |
| 1107 | change = val != chip->image[reg]; |
| 1108 | snd_ad1848_out(chip, reg, val); |
| 1109 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1110 | return change; |
| 1111 | } |
| 1112 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1113 | static int snd_ad1848_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | { |
| 1115 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1116 | |
| 1117 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1118 | uinfo->count = 2; |
| 1119 | uinfo->value.integer.min = 0; |
| 1120 | uinfo->value.integer.max = mask; |
| 1121 | return 0; |
| 1122 | } |
| 1123 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1124 | static int snd_ad1848_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1126 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | unsigned long flags; |
| 1128 | int left_reg = kcontrol->private_value & 0xff; |
| 1129 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1130 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1131 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1132 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1133 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1134 | |
| 1135 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1136 | ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; |
| 1137 | ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask; |
| 1138 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1139 | if (invert) { |
| 1140 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 1141 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 1142 | } |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1146 | static int snd_ad1848_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1148 | struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | unsigned long flags; |
| 1150 | int left_reg = kcontrol->private_value & 0xff; |
| 1151 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1152 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1153 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1154 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1155 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1156 | int change; |
| 1157 | unsigned short val1, val2; |
| 1158 | |
| 1159 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1160 | val2 = ucontrol->value.integer.value[1] & mask; |
| 1161 | if (invert) { |
| 1162 | val1 = mask - val1; |
| 1163 | val2 = mask - val2; |
| 1164 | } |
| 1165 | val1 <<= shift_left; |
| 1166 | val2 <<= shift_right; |
| 1167 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1168 | if (left_reg != right_reg) { |
| 1169 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
| 1170 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; |
| 1171 | change = val1 != chip->image[left_reg] || val2 != chip->image[right_reg]; |
| 1172 | snd_ad1848_out(chip, left_reg, val1); |
| 1173 | snd_ad1848_out(chip, right_reg, val2); |
| 1174 | } else { |
| 1175 | val1 = (chip->image[left_reg] & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; |
| 1176 | change = val1 != chip->image[left_reg]; |
| 1177 | snd_ad1848_out(chip, left_reg, val1); |
| 1178 | } |
| 1179 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1180 | return change; |
| 1181 | } |
| 1182 | |
| 1183 | /* |
| 1184 | */ |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1185 | int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip, |
| 1186 | const struct ad1848_mix_elem *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1188 | static struct snd_kcontrol_new newctls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | [AD1848_MIX_SINGLE] = { |
| 1190 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1191 | .info = snd_ad1848_info_single, |
| 1192 | .get = snd_ad1848_get_single, |
| 1193 | .put = snd_ad1848_put_single, |
| 1194 | }, |
| 1195 | [AD1848_MIX_DOUBLE] = { |
| 1196 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1197 | .info = snd_ad1848_info_double, |
| 1198 | .get = snd_ad1848_get_double, |
| 1199 | .put = snd_ad1848_put_double, |
| 1200 | }, |
| 1201 | [AD1848_MIX_CAPTURE] = { |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 1202 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | .info = snd_ad1848_info_mux, |
| 1204 | .get = snd_ad1848_get_mux, |
| 1205 | .put = snd_ad1848_put_mux, |
| 1206 | }, |
| 1207 | }; |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1208 | struct snd_kcontrol *ctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | int err; |
| 1210 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1211 | ctl = snd_ctl_new1(&newctls[c->type], chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | if (! ctl) |
| 1213 | return -ENOMEM; |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1214 | strlcpy(ctl->id.name, c->name, sizeof(ctl->id.name)); |
| 1215 | ctl->id.index = c->index; |
| 1216 | ctl->private_value = c->private_value; |
| 1217 | if (c->tlv) { |
| 1218 | ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; |
| 1219 | ctl->tlv.p = c->tlv; |
| 1220 | } |
Dave Jones | 3de4414 | 2006-03-06 13:31:18 +0100 | [diff] [blame] | 1221 | if ((err = snd_ctl_add(chip->card, ctl)) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | return 0; |
| 1224 | } |
| 1225 | |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1226 | EXPORT_SYMBOL(snd_ad1848_add_ctl_elem); |
| 1227 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 1228 | static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); |
| 1229 | static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); |
| 1230 | static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | |
| 1232 | static struct ad1848_mix_elem snd_ad1848_controls[] = { |
| 1233 | AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1), |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1234 | AD1848_DOUBLE_TLV("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1, |
| 1235 | db_scale_6bit), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1237 | AD1848_DOUBLE_TLV("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1, |
| 1238 | db_scale_5bit_12db_max), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1240 | AD1848_DOUBLE_TLV("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1, |
| 1241 | db_scale_5bit_12db_max), |
| 1242 | AD1848_DOUBLE_TLV("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0, |
| 1243 | db_scale_rec_gain), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | { |
| 1245 | .name = "Capture Source", |
| 1246 | .type = AD1848_MIX_CAPTURE, |
| 1247 | }, |
| 1248 | AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0), |
Takashi Iwai | eac06a1 | 2006-08-22 13:16:25 +0200 | [diff] [blame] | 1249 | AD1848_SINGLE_TLV("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0, |
| 1250 | db_scale_6bit), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | }; |
| 1252 | |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1253 | int snd_ad1848_mixer(struct snd_ad1848 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | { |
Takashi Iwai | c8ff664 | 2005-11-17 14:29:37 +0100 | [diff] [blame] | 1255 | struct snd_card *card; |
| 1256 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | unsigned int idx; |
| 1258 | int err; |
| 1259 | |
| 1260 | snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL); |
| 1261 | |
| 1262 | pcm = chip->pcm; |
| 1263 | card = chip->card; |
| 1264 | |
| 1265 | strcpy(card->mixername, pcm->name); |
| 1266 | |
| 1267 | for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++) |
| 1268 | if ((err = snd_ad1848_add_ctl_elem(chip, &snd_ad1848_controls[idx])) < 0) |
| 1269 | return err; |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | EXPORT_SYMBOL(snd_ad1848_mixer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
| 1276 | /* |
| 1277 | * INIT part |
| 1278 | */ |
| 1279 | |
| 1280 | static int __init alsa_ad1848_init(void) |
| 1281 | { |
| 1282 | return 0; |
| 1283 | } |
| 1284 | |
| 1285 | static void __exit alsa_ad1848_exit(void) |
| 1286 | { |
| 1287 | } |
| 1288 | |
| 1289 | module_init(alsa_ad1848_init) |
| 1290 | module_exit(alsa_ad1848_exit) |