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