Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Routines for control of CS4231(A)/CS4232/InterWave & compatible chips |
| 4 | * |
| 5 | * Bugs: |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 6 | * - sometimes record brokes playback with WSS portion of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Yamaha OPL3-SA3 chip |
| 8 | * - CS4231 (GUS MAX) - still trouble with occasional noises |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 9 | * - broken initialization? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/delay.h> |
| 28 | #include <linux/pm.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/interrupt.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/ioport.h> |
| 33 | #include <sound/core.h> |
Krzysztof Helt | 61ef19d | 2008-07-31 21:02:42 +0200 | [diff] [blame] | 34 | #include <sound/wss.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <sound/pcm_params.h> |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 36 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | #include <asm/io.h> |
| 39 | #include <asm/dma.h> |
| 40 | #include <asm/irq.h> |
| 41 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 42 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
| 46 | #if 0 |
| 47 | #define SNDRV_DEBUG_MCE |
| 48 | #endif |
| 49 | |
| 50 | /* |
| 51 | * Some variables |
| 52 | */ |
| 53 | |
| 54 | static unsigned char freq_bits[14] = { |
| 55 | /* 5510 */ 0x00 | CS4231_XTAL2, |
| 56 | /* 6620 */ 0x0E | CS4231_XTAL2, |
| 57 | /* 8000 */ 0x00 | CS4231_XTAL1, |
| 58 | /* 9600 */ 0x0E | CS4231_XTAL1, |
| 59 | /* 11025 */ 0x02 | CS4231_XTAL2, |
| 60 | /* 16000 */ 0x02 | CS4231_XTAL1, |
| 61 | /* 18900 */ 0x04 | CS4231_XTAL2, |
| 62 | /* 22050 */ 0x06 | CS4231_XTAL2, |
| 63 | /* 27042 */ 0x04 | CS4231_XTAL1, |
| 64 | /* 32000 */ 0x06 | CS4231_XTAL1, |
| 65 | /* 33075 */ 0x0C | CS4231_XTAL2, |
| 66 | /* 37800 */ 0x08 | CS4231_XTAL2, |
| 67 | /* 44100 */ 0x0A | CS4231_XTAL2, |
| 68 | /* 48000 */ 0x0C | CS4231_XTAL1 |
| 69 | }; |
| 70 | |
| 71 | static unsigned int rates[14] = { |
| 72 | 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050, |
| 73 | 27042, 32000, 33075, 37800, 44100, 48000 |
| 74 | }; |
| 75 | |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 76 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 77 | .count = ARRAY_SIZE(rates), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | .list = rates, |
| 79 | .mask = 0, |
| 80 | }; |
| 81 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 82 | static int snd_wss_xrate(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 84 | return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 85 | &hw_constraints_rates); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 88 | static unsigned char snd_wss_original_image[32] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | 0x00, /* 00/00 - lic */ |
| 91 | 0x00, /* 01/01 - ric */ |
| 92 | 0x9f, /* 02/02 - la1ic */ |
| 93 | 0x9f, /* 03/03 - ra1ic */ |
| 94 | 0x9f, /* 04/04 - la2ic */ |
| 95 | 0x9f, /* 05/05 - ra2ic */ |
| 96 | 0xbf, /* 06/06 - loc */ |
| 97 | 0xbf, /* 07/07 - roc */ |
| 98 | 0x20, /* 08/08 - pdfr */ |
| 99 | CS4231_AUTOCALIB, /* 09/09 - ic */ |
| 100 | 0x00, /* 0a/10 - pc */ |
| 101 | 0x00, /* 0b/11 - ti */ |
| 102 | CS4231_MODE2, /* 0c/12 - mi */ |
| 103 | 0xfc, /* 0d/13 - lbc */ |
| 104 | 0x00, /* 0e/14 - pbru */ |
| 105 | 0x00, /* 0f/15 - pbrl */ |
| 106 | 0x80, /* 10/16 - afei */ |
| 107 | 0x01, /* 11/17 - afeii */ |
| 108 | 0x9f, /* 12/18 - llic */ |
| 109 | 0x9f, /* 13/19 - rlic */ |
| 110 | 0x00, /* 14/20 - tlb */ |
| 111 | 0x00, /* 15/21 - thb */ |
| 112 | 0x00, /* 16/22 - la3mic/reserved */ |
| 113 | 0x00, /* 17/23 - ra3mic/reserved */ |
| 114 | 0x00, /* 18/24 - afs */ |
| 115 | 0x00, /* 19/25 - lamoc/version */ |
| 116 | 0xcf, /* 1a/26 - mioc */ |
| 117 | 0x00, /* 1b/27 - ramoc/reserved */ |
| 118 | 0x20, /* 1c/28 - cdfr */ |
| 119 | 0x00, /* 1d/29 - res4 */ |
| 120 | 0x00, /* 1e/30 - cbru */ |
| 121 | 0x00, /* 1f/31 - cbrl */ |
| 122 | }; |
| 123 | |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 124 | static unsigned char snd_opti93x_original_image[32] = |
| 125 | { |
| 126 | 0x00, /* 00/00 - l_mixout_outctrl */ |
| 127 | 0x00, /* 01/01 - r_mixout_outctrl */ |
| 128 | 0x88, /* 02/02 - l_cd_inctrl */ |
| 129 | 0x88, /* 03/03 - r_cd_inctrl */ |
| 130 | 0x88, /* 04/04 - l_a1/fm_inctrl */ |
| 131 | 0x88, /* 05/05 - r_a1/fm_inctrl */ |
| 132 | 0x80, /* 06/06 - l_dac_inctrl */ |
| 133 | 0x80, /* 07/07 - r_dac_inctrl */ |
| 134 | 0x00, /* 08/08 - ply_dataform_reg */ |
| 135 | 0x00, /* 09/09 - if_conf */ |
| 136 | 0x00, /* 0a/10 - pin_ctrl */ |
| 137 | 0x00, /* 0b/11 - err_init_reg */ |
| 138 | 0x0a, /* 0c/12 - id_reg */ |
| 139 | 0x00, /* 0d/13 - reserved */ |
| 140 | 0x00, /* 0e/14 - ply_upcount_reg */ |
| 141 | 0x00, /* 0f/15 - ply_lowcount_reg */ |
| 142 | 0x88, /* 10/16 - reserved/l_a1_inctrl */ |
| 143 | 0x88, /* 11/17 - reserved/r_a1_inctrl */ |
| 144 | 0x88, /* 12/18 - l_line_inctrl */ |
| 145 | 0x88, /* 13/19 - r_line_inctrl */ |
| 146 | 0x88, /* 14/20 - l_mic_inctrl */ |
| 147 | 0x88, /* 15/21 - r_mic_inctrl */ |
| 148 | 0x80, /* 16/22 - l_out_outctrl */ |
| 149 | 0x80, /* 17/23 - r_out_outctrl */ |
| 150 | 0x00, /* 18/24 - reserved */ |
| 151 | 0x00, /* 19/25 - reserved */ |
| 152 | 0x00, /* 1a/26 - reserved */ |
| 153 | 0x00, /* 1b/27 - reserved */ |
| 154 | 0x00, /* 1c/28 - cap_dataform_reg */ |
| 155 | 0x00, /* 1d/29 - reserved */ |
| 156 | 0x00, /* 1e/30 - cap_upcount_reg */ |
| 157 | 0x00 /* 1f/31 - cap_lowcount_reg */ |
| 158 | }; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* |
| 161 | * Basic I/O functions |
| 162 | */ |
| 163 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 164 | static inline void wss_outb(struct snd_wss *chip, u8 offset, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | outb(val, chip->port + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | } |
| 168 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 169 | static inline u8 wss_inb(struct snd_wss *chip, u8 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return inb(chip->port + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 174 | static void snd_wss_wait(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | for (timeout = 250; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 179 | timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | timeout--) |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 181 | udelay(100); |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 184 | static void snd_wss_outm(struct snd_wss *chip, unsigned char reg, |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 185 | unsigned char mask, unsigned char value) |
| 186 | { |
| 187 | unsigned char tmp = (chip->image[reg] & mask) | value; |
| 188 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 189 | snd_wss_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 191 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); |
| 193 | #endif |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 194 | chip->image[reg] = tmp; |
| 195 | if (!chip->calibrate_mute) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 196 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 197 | wmb(); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 198 | wss_outb(chip, CS4231P(REG), tmp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | mb(); |
| 200 | } |
| 201 | } |
| 202 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 203 | static void snd_wss_dout(struct snd_wss *chip, unsigned char reg, |
| 204 | unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | { |
| 206 | int timeout; |
| 207 | |
| 208 | for (timeout = 250; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 209 | timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | timeout--) |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 211 | udelay(10); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 212 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); |
| 213 | wss_outb(chip, CS4231P(REG), value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | mb(); |
| 215 | } |
| 216 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 217 | void snd_wss_out(struct snd_wss *chip, unsigned char reg, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 219 | snd_wss_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 221 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); |
| 223 | #endif |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 224 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); |
| 225 | wss_outb(chip, CS4231P(REG), value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | chip->image[reg] = value; |
| 227 | mb(); |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 228 | snd_printdd("codec out - reg 0x%x = 0x%x\n", |
| 229 | chip->mce_bit | reg, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 231 | EXPORT_SYMBOL(snd_wss_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 233 | unsigned char snd_wss_in(struct snd_wss *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 235 | snd_wss_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 237 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | snd_printk("in: auto calibration time out - reg = 0x%x\n", reg); |
| 239 | #endif |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 240 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | mb(); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 242 | return wss_inb(chip, CS4231P(REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 244 | EXPORT_SYMBOL(snd_wss_in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 246 | void snd_cs4236_ext_out(struct snd_wss *chip, unsigned char reg, |
| 247 | unsigned char val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 249 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17); |
| 250 | wss_outb(chip, CS4231P(REG), |
| 251 | reg | (chip->image[CS4236_EXT_REG] & 0x01)); |
| 252 | wss_outb(chip, CS4231P(REG), val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | chip->eimage[CS4236_REG(reg)] = val; |
| 254 | #if 0 |
| 255 | printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val); |
| 256 | #endif |
| 257 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 258 | EXPORT_SYMBOL(snd_cs4236_ext_out); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 260 | unsigned char snd_cs4236_ext_in(struct snd_wss *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 262 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17); |
| 263 | wss_outb(chip, CS4231P(REG), |
| 264 | reg | (chip->image[CS4236_EXT_REG] & 0x01)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | #if 1 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 266 | return wss_inb(chip, CS4231P(REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | #else |
| 268 | { |
| 269 | unsigned char res; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 270 | res = wss_inb(chip, CS4231P(REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res); |
| 272 | return res; |
| 273 | } |
| 274 | #endif |
| 275 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 276 | EXPORT_SYMBOL(snd_cs4236_ext_in); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | #if 0 |
| 279 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 280 | static void snd_wss_debug(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 282 | printk(KERN_DEBUG |
| 283 | "CS4231 REGS: INDEX = 0x%02x " |
| 284 | " STATUS = 0x%02x\n", |
Rene Herman | 3caf8c0 | 2008-08-08 16:39:21 +0200 | [diff] [blame] | 285 | wss_inb(chip, CS4231P(REGSEL)), |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 286 | wss_inb(chip, CS4231P(STATUS))); |
| 287 | printk(KERN_DEBUG |
| 288 | " 0x00: left input = 0x%02x " |
| 289 | " 0x10: alt 1 (CFIG 2) = 0x%02x\n", |
| 290 | snd_wss_in(chip, 0x00), |
| 291 | snd_wss_in(chip, 0x10)); |
| 292 | printk(KERN_DEBUG |
| 293 | " 0x01: right input = 0x%02x " |
| 294 | " 0x11: alt 2 (CFIG 3) = 0x%02x\n", |
| 295 | snd_wss_in(chip, 0x01), |
| 296 | snd_wss_in(chip, 0x11)); |
| 297 | printk(KERN_DEBUG |
| 298 | " 0x02: GF1 left input = 0x%02x " |
| 299 | " 0x12: left line in = 0x%02x\n", |
| 300 | snd_wss_in(chip, 0x02), |
| 301 | snd_wss_in(chip, 0x12)); |
| 302 | printk(KERN_DEBUG |
| 303 | " 0x03: GF1 right input = 0x%02x " |
| 304 | " 0x13: right line in = 0x%02x\n", |
| 305 | snd_wss_in(chip, 0x03), |
| 306 | snd_wss_in(chip, 0x13)); |
| 307 | printk(KERN_DEBUG |
| 308 | " 0x04: CD left input = 0x%02x " |
| 309 | " 0x14: timer low = 0x%02x\n", |
| 310 | snd_wss_in(chip, 0x04), |
| 311 | snd_wss_in(chip, 0x14)); |
| 312 | printk(KERN_DEBUG |
| 313 | " 0x05: CD right input = 0x%02x " |
| 314 | " 0x15: timer high = 0x%02x\n", |
| 315 | snd_wss_in(chip, 0x05), |
| 316 | snd_wss_in(chip, 0x15)); |
| 317 | printk(KERN_DEBUG |
| 318 | " 0x06: left output = 0x%02x " |
| 319 | " 0x16: left MIC (PnP) = 0x%02x\n", |
| 320 | snd_wss_in(chip, 0x06), |
| 321 | snd_wss_in(chip, 0x16)); |
| 322 | printk(KERN_DEBUG |
| 323 | " 0x07: right output = 0x%02x " |
| 324 | " 0x17: right MIC (PnP) = 0x%02x\n", |
| 325 | snd_wss_in(chip, 0x07), |
| 326 | snd_wss_in(chip, 0x17)); |
| 327 | printk(KERN_DEBUG |
| 328 | " 0x08: playback format = 0x%02x " |
| 329 | " 0x18: IRQ status = 0x%02x\n", |
| 330 | snd_wss_in(chip, 0x08), |
| 331 | snd_wss_in(chip, 0x18)); |
| 332 | printk(KERN_DEBUG |
| 333 | " 0x09: iface (CFIG 1) = 0x%02x " |
| 334 | " 0x19: left line out = 0x%02x\n", |
| 335 | snd_wss_in(chip, 0x09), |
| 336 | snd_wss_in(chip, 0x19)); |
| 337 | printk(KERN_DEBUG |
| 338 | " 0x0a: pin control = 0x%02x " |
| 339 | " 0x1a: mono control = 0x%02x\n", |
| 340 | snd_wss_in(chip, 0x0a), |
| 341 | snd_wss_in(chip, 0x1a)); |
| 342 | printk(KERN_DEBUG |
| 343 | " 0x0b: init & status = 0x%02x " |
| 344 | " 0x1b: right line out = 0x%02x\n", |
| 345 | snd_wss_in(chip, 0x0b), |
| 346 | snd_wss_in(chip, 0x1b)); |
| 347 | printk(KERN_DEBUG |
| 348 | " 0x0c: revision & mode = 0x%02x " |
| 349 | " 0x1c: record format = 0x%02x\n", |
| 350 | snd_wss_in(chip, 0x0c), |
| 351 | snd_wss_in(chip, 0x1c)); |
| 352 | printk(KERN_DEBUG |
| 353 | " 0x0d: loopback = 0x%02x " |
| 354 | " 0x1d: var freq (PnP) = 0x%02x\n", |
| 355 | snd_wss_in(chip, 0x0d), |
| 356 | snd_wss_in(chip, 0x1d)); |
| 357 | printk(KERN_DEBUG |
| 358 | " 0x0e: ply upr count = 0x%02x " |
| 359 | " 0x1e: ply lwr count = 0x%02x\n", |
| 360 | snd_wss_in(chip, 0x0e), |
| 361 | snd_wss_in(chip, 0x1e)); |
| 362 | printk(KERN_DEBUG |
| 363 | " 0x0f: rec upr count = 0x%02x " |
| 364 | " 0x1f: rec lwr count = 0x%02x\n", |
| 365 | snd_wss_in(chip, 0x0f), |
| 366 | snd_wss_in(chip, 0x1f)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | #endif |
| 370 | |
| 371 | /* |
| 372 | * CS4231 detection / MCE routines |
| 373 | */ |
| 374 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 375 | static void snd_wss_busy_wait(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | { |
| 377 | int timeout; |
| 378 | |
| 379 | /* huh.. looks like this sequence is proper for CS4231A chip (GUS MAX) */ |
| 380 | for (timeout = 5; timeout > 0; timeout--) |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 381 | wss_inb(chip, CS4231P(REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | /* end of cleanup sequence */ |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 383 | for (timeout = 25000; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 384 | timeout > 0 && (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | timeout--) |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 386 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 389 | void snd_wss_mce_up(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
| 391 | unsigned long flags; |
| 392 | int timeout; |
| 393 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 394 | snd_wss_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 396 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | snd_printk("mce_up - auto calibration time out (0)\n"); |
| 398 | #endif |
| 399 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 400 | chip->mce_bit |= CS4231_MCE; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 401 | timeout = wss_inb(chip, CS4231P(REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | if (timeout == 0x80) |
| 403 | snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port); |
| 404 | if (!(timeout & CS4231_MCE)) |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 405 | wss_outb(chip, CS4231P(REGSEL), |
| 406 | chip->mce_bit | (timeout & 0x1f)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 408 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 409 | EXPORT_SYMBOL(snd_wss_mce_up); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 411 | void snd_wss_mce_down(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
| 413 | unsigned long flags; |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 414 | unsigned long end_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | int timeout; |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 416 | int hw_mask = WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK | WSS_HW_AD1848; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 418 | snd_wss_busy_wait(chip); |
Rene Herman | d44df2d | 2007-09-10 23:22:55 +0200 | [diff] [blame] | 419 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 421 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL)); |
| 423 | #endif |
| 424 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 425 | chip->mce_bit &= ~CS4231_MCE; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 426 | timeout = wss_inb(chip, CS4231P(REGSEL)); |
| 427 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 429 | if (timeout == 0x80) |
| 430 | snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 431 | if ((timeout & CS4231_MCE) == 0 || !(chip->hardware & hw_mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Rene Herman | 90cf9b8 | 2007-09-10 23:19:55 +0200 | [diff] [blame] | 434 | /* |
| 435 | * Wait for (possible -- during init auto-calibration may not be set) |
| 436 | * calibration process to start. Needs upto 5 sample periods on AD1848 |
| 437 | * which at the slowest possible rate of 5.5125 kHz means 907 us. |
| 438 | */ |
| 439 | msleep(1); |
Rene Herman | d44df2d | 2007-09-10 23:22:55 +0200 | [diff] [blame] | 440 | |
| 441 | snd_printdd("(1) jiffies = %lu\n", jiffies); |
| 442 | |
Krzysztof Helt | 23d4635ed | 2007-09-11 00:40:42 +0200 | [diff] [blame] | 443 | /* check condition up to 250 ms */ |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 444 | end_time = jiffies + msecs_to_jiffies(250); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 445 | while (snd_wss_in(chip, CS4231_TEST_INIT) & |
Krzysztof Helt | 23d4635ed | 2007-09-11 00:40:42 +0200 | [diff] [blame] | 446 | CS4231_CALIB_IN_PROGRESS) { |
| 447 | |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 448 | if (time_after(jiffies, end_time)) { |
Krzysztof Helt | 23d4635ed | 2007-09-11 00:40:42 +0200 | [diff] [blame] | 449 | snd_printk(KERN_ERR "mce_down - " |
| 450 | "auto calibration time out (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return; |
| 452 | } |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 453 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
Rene Herman | d44df2d | 2007-09-10 23:22:55 +0200 | [diff] [blame] | 455 | |
| 456 | snd_printdd("(2) jiffies = %lu\n", jiffies); |
| 457 | |
Krzysztof Helt | 23d4635ed | 2007-09-11 00:40:42 +0200 | [diff] [blame] | 458 | /* check condition up to 100 ms */ |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 459 | end_time = jiffies + msecs_to_jiffies(100); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 460 | while (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) { |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 461 | if (time_after(jiffies, end_time)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n"); |
| 463 | return; |
| 464 | } |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 465 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
Rene Herman | d44df2d | 2007-09-10 23:22:55 +0200 | [diff] [blame] | 467 | |
| 468 | snd_printdd("(3) jiffies = %lu\n", jiffies); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 469 | snd_printd("mce_down - exit = 0x%x\n", wss_inb(chip, CS4231P(REGSEL))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 471 | EXPORT_SYMBOL(snd_wss_mce_down); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 473 | static unsigned int snd_wss_get_count(unsigned char format, unsigned int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
| 475 | switch (format & 0xe0) { |
| 476 | case CS4231_LINEAR_16: |
| 477 | case CS4231_LINEAR_16_BIG: |
| 478 | size >>= 1; |
| 479 | break; |
| 480 | case CS4231_ADPCM_16: |
| 481 | return size >> 2; |
| 482 | } |
| 483 | if (format & CS4231_STEREO) |
| 484 | size >>= 1; |
| 485 | return size; |
| 486 | } |
| 487 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 488 | static int snd_wss_trigger(struct snd_pcm_substream *substream, |
| 489 | int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 491 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | int result = 0; |
| 493 | unsigned int what; |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 494 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | int do_start; |
| 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | switch (cmd) { |
| 498 | case SNDRV_PCM_TRIGGER_START: |
| 499 | case SNDRV_PCM_TRIGGER_RESUME: |
| 500 | do_start = 1; break; |
| 501 | case SNDRV_PCM_TRIGGER_STOP: |
| 502 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 503 | do_start = 0; break; |
| 504 | default: |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | |
| 508 | what = 0; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 509 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | if (s == chip->playback_substream) { |
| 511 | what |= CS4231_PLAYBACK_ENABLE; |
| 512 | snd_pcm_trigger_done(s, substream); |
| 513 | } else if (s == chip->capture_substream) { |
| 514 | what |= CS4231_RECORD_ENABLE; |
| 515 | snd_pcm_trigger_done(s, substream); |
| 516 | } |
| 517 | } |
| 518 | spin_lock(&chip->reg_lock); |
| 519 | if (do_start) { |
| 520 | chip->image[CS4231_IFACE_CTRL] |= what; |
| 521 | if (chip->trigger) |
| 522 | chip->trigger(chip, what, 1); |
| 523 | } else { |
| 524 | chip->image[CS4231_IFACE_CTRL] &= ~what; |
| 525 | if (chip->trigger) |
| 526 | chip->trigger(chip, what, 0); |
| 527 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 528 | snd_wss_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | spin_unlock(&chip->reg_lock); |
| 530 | #if 0 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 531 | snd_wss_debug(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | #endif |
| 533 | return result; |
| 534 | } |
| 535 | |
| 536 | /* |
| 537 | * CODEC I/O |
| 538 | */ |
| 539 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 540 | static unsigned char snd_wss_get_rate(unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | { |
| 542 | int i; |
| 543 | |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 544 | for (i = 0; i < ARRAY_SIZE(rates); i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | if (rate == rates[i]) |
| 546 | return freq_bits[i]; |
| 547 | // snd_BUG(); |
Krzysztof Helt | 6c041b5 | 2007-09-06 15:03:59 +0200 | [diff] [blame] | 548 | return freq_bits[ARRAY_SIZE(rates) - 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 551 | static unsigned char snd_wss_get_format(struct snd_wss *chip, |
| 552 | int format, |
| 553 | int channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | { |
| 555 | unsigned char rformat; |
| 556 | |
| 557 | rformat = CS4231_LINEAR_8; |
| 558 | switch (format) { |
| 559 | case SNDRV_PCM_FORMAT_MU_LAW: rformat = CS4231_ULAW_8; break; |
| 560 | case SNDRV_PCM_FORMAT_A_LAW: rformat = CS4231_ALAW_8; break; |
| 561 | case SNDRV_PCM_FORMAT_S16_LE: rformat = CS4231_LINEAR_16; break; |
| 562 | case SNDRV_PCM_FORMAT_S16_BE: rformat = CS4231_LINEAR_16_BIG; break; |
| 563 | case SNDRV_PCM_FORMAT_IMA_ADPCM: rformat = CS4231_ADPCM_16; break; |
| 564 | } |
| 565 | if (channels > 1) |
| 566 | rformat |= CS4231_STEREO; |
| 567 | #if 0 |
| 568 | snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode); |
| 569 | #endif |
| 570 | return rformat; |
| 571 | } |
| 572 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 573 | static void snd_wss_calibrate_mute(struct snd_wss *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | { |
| 575 | unsigned long flags; |
| 576 | |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 577 | mute = mute ? 0x80 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 579 | if (chip->calibrate_mute == mute) { |
| 580 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 581 | return; |
| 582 | } |
| 583 | if (!mute) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 584 | snd_wss_dout(chip, CS4231_LEFT_INPUT, |
| 585 | chip->image[CS4231_LEFT_INPUT]); |
| 586 | snd_wss_dout(chip, CS4231_RIGHT_INPUT, |
| 587 | chip->image[CS4231_RIGHT_INPUT]); |
| 588 | snd_wss_dout(chip, CS4231_LOOPBACK, |
| 589 | chip->image[CS4231_LOOPBACK]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 591 | snd_wss_dout(chip, CS4231_AUX1_LEFT_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 592 | mute | chip->image[CS4231_AUX1_LEFT_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 593 | snd_wss_dout(chip, CS4231_AUX1_RIGHT_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 594 | mute | chip->image[CS4231_AUX1_RIGHT_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 595 | snd_wss_dout(chip, CS4231_AUX2_LEFT_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 596 | mute | chip->image[CS4231_AUX2_LEFT_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 597 | snd_wss_dout(chip, CS4231_AUX2_RIGHT_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 598 | mute | chip->image[CS4231_AUX2_RIGHT_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 599 | snd_wss_dout(chip, CS4231_LEFT_OUTPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 600 | mute | chip->image[CS4231_LEFT_OUTPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 601 | snd_wss_dout(chip, CS4231_RIGHT_OUTPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 602 | mute | chip->image[CS4231_RIGHT_OUTPUT]); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 603 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) { |
| 604 | snd_wss_dout(chip, CS4231_LEFT_LINE_IN, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 605 | mute | chip->image[CS4231_LEFT_LINE_IN]); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 606 | snd_wss_dout(chip, CS4231_RIGHT_LINE_IN, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 607 | mute | chip->image[CS4231_RIGHT_LINE_IN]); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 608 | snd_wss_dout(chip, CS4231_MONO_CTRL, |
| 609 | mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]); |
| 610 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 611 | if (chip->hardware == WSS_HW_INTERWAVE) { |
| 612 | snd_wss_dout(chip, CS4231_LEFT_MIC_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 613 | mute | chip->image[CS4231_LEFT_MIC_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 614 | snd_wss_dout(chip, CS4231_RIGHT_MIC_INPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 615 | mute | chip->image[CS4231_RIGHT_MIC_INPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 616 | snd_wss_dout(chip, CS4231_LINE_LEFT_OUTPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 617 | mute | chip->image[CS4231_LINE_LEFT_OUTPUT]); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 618 | snd_wss_dout(chip, CS4231_LINE_RIGHT_OUTPUT, |
Krzysztof Helt | ace457c | 2008-08-17 22:38:27 +0200 | [diff] [blame^] | 619 | mute | chip->image[CS4231_LINE_RIGHT_OUTPUT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | } |
| 621 | chip->calibrate_mute = mute; |
| 622 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 623 | } |
| 624 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 625 | static void snd_wss_playback_format(struct snd_wss *chip, |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 626 | struct snd_pcm_hw_params *params, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | unsigned char pdfr) |
| 628 | { |
| 629 | unsigned long flags; |
| 630 | int full_calib = 1; |
| 631 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 632 | mutex_lock(&chip->mce_mutex); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 633 | snd_wss_calibrate_mute(chip, 1); |
| 634 | if (chip->hardware == WSS_HW_CS4231A || |
| 635 | (chip->hardware & WSS_HW_CS4232_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 637 | if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (pdfr & 0x0f)) { /* rate is same? */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 638 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 639 | chip->image[CS4231_ALT_FEATURE_1] | 0x10); |
| 640 | chip->image[CS4231_PLAYBK_FORMAT] = pdfr; |
| 641 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, |
| 642 | chip->image[CS4231_PLAYBK_FORMAT]); |
| 643 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 644 | chip->image[CS4231_ALT_FEATURE_1] &= ~0x10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | udelay(100); /* Fixes audible clicks at least on GUS MAX */ |
| 646 | full_calib = 0; |
| 647 | } |
| 648 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 649 | } |
| 650 | if (full_calib) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 651 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 653 | if (chip->hardware != WSS_HW_INTERWAVE && !chip->single_dma) { |
| 654 | if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) |
| 655 | pdfr = (pdfr & 0xf0) | |
| 656 | (chip->image[CS4231_REC_FORMAT] & 0x0f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } else { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 658 | chip->image[CS4231_PLAYBK_FORMAT] = pdfr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 660 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, pdfr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 662 | if (chip->hardware == WSS_HW_OPL3SA2) |
Paul Vojta | e234046 | 2007-07-27 12:20:38 +0200 | [diff] [blame] | 663 | udelay(100); /* this seems to help */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 664 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 666 | snd_wss_calibrate_mute(chip, 0); |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 667 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 670 | static void snd_wss_capture_format(struct snd_wss *chip, |
| 671 | struct snd_pcm_hw_params *params, |
| 672 | unsigned char cdfr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | unsigned long flags; |
| 675 | int full_calib = 1; |
| 676 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 677 | mutex_lock(&chip->mce_mutex); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 678 | snd_wss_calibrate_mute(chip, 1); |
| 679 | if (chip->hardware == WSS_HW_CS4231A || |
| 680 | (chip->hardware & WSS_HW_CS4232_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 682 | if ((chip->image[CS4231_PLAYBK_FORMAT] & 0x0f) == (cdfr & 0x0f) || /* rate is same? */ |
| 683 | (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 684 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 685 | chip->image[CS4231_ALT_FEATURE_1] | 0x20); |
| 686 | snd_wss_out(chip, CS4231_REC_FORMAT, |
| 687 | chip->image[CS4231_REC_FORMAT] = cdfr); |
| 688 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 689 | chip->image[CS4231_ALT_FEATURE_1] &= ~0x20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | full_calib = 0; |
| 691 | } |
| 692 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 693 | } |
| 694 | if (full_calib) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 695 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 697 | if (chip->hardware != WSS_HW_INTERWAVE && |
| 698 | !(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) { |
| 699 | if (chip->single_dma) |
| 700 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, cdfr); |
| 701 | else |
| 702 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, |
| 703 | (chip->image[CS4231_PLAYBK_FORMAT] & 0xf0) | |
| 704 | (cdfr & 0x0f)); |
| 705 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 706 | snd_wss_mce_down(chip); |
| 707 | snd_wss_mce_up(chip); |
| 708 | spin_lock_irqsave(&chip->reg_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 710 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 711 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, cdfr); |
| 712 | else |
| 713 | snd_wss_out(chip, CS4231_REC_FORMAT, cdfr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 715 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 717 | snd_wss_calibrate_mute(chip, 0); |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 718 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | /* |
| 722 | * Timer interface |
| 723 | */ |
| 724 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 725 | static unsigned long snd_wss_timer_resolution(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 727 | struct snd_wss *chip = snd_timer_chip(timer); |
| 728 | if (chip->hardware & WSS_HW_CS4236B_MASK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | return 14467; |
| 730 | else |
| 731 | return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920; |
| 732 | } |
| 733 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 734 | static int snd_wss_timer_start(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
| 736 | unsigned long flags; |
| 737 | unsigned int ticks; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 738 | struct snd_wss *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 740 | ticks = timer->sticks; |
| 741 | if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 || |
| 742 | (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] || |
| 743 | (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 744 | chip->image[CS4231_TIMER_HIGH] = (unsigned char) (ticks >> 8); |
| 745 | snd_wss_out(chip, CS4231_TIMER_HIGH, |
| 746 | chip->image[CS4231_TIMER_HIGH]); |
| 747 | chip->image[CS4231_TIMER_LOW] = (unsigned char) ticks; |
| 748 | snd_wss_out(chip, CS4231_TIMER_LOW, |
| 749 | chip->image[CS4231_TIMER_LOW]); |
| 750 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 751 | chip->image[CS4231_ALT_FEATURE_1] | |
| 752 | CS4231_TIMER_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 755 | return 0; |
| 756 | } |
| 757 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 758 | static int snd_wss_timer_stop(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
| 760 | unsigned long flags; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 761 | struct snd_wss *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 763 | chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE; |
| 764 | snd_wss_out(chip, CS4231_ALT_FEATURE_1, |
| 765 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 767 | return 0; |
| 768 | } |
| 769 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 770 | static void snd_wss_init(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
| 772 | unsigned long flags; |
| 773 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 774 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | #ifdef SNDRV_DEBUG_MCE |
| 777 | snd_printk("init: (1)\n"); |
| 778 | #endif |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 779 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 781 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
| 782 | CS4231_PLAYBACK_PIO | |
| 783 | CS4231_RECORD_ENABLE | |
| 784 | CS4231_RECORD_PIO | |
| 785 | CS4231_CALIB_MODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 787 | snd_wss_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 789 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | #ifdef SNDRV_DEBUG_MCE |
| 792 | snd_printk("init: (2)\n"); |
| 793 | #endif |
| 794 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 795 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 797 | snd_wss_out(chip, |
| 798 | CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 800 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | #ifdef SNDRV_DEBUG_MCE |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 803 | snd_printk("init: (3) - afei = 0x%x\n", |
| 804 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | #endif |
| 806 | |
| 807 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 808 | snd_wss_out(chip, CS4231_ALT_FEATURE_2, |
| 809 | chip->image[CS4231_ALT_FEATURE_2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 811 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 812 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 814 | snd_wss_out(chip, CS4231_PLAYBK_FORMAT, |
| 815 | chip->image[CS4231_PLAYBK_FORMAT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 817 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | |
| 819 | #ifdef SNDRV_DEBUG_MCE |
| 820 | snd_printk("init: (4)\n"); |
| 821 | #endif |
| 822 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 823 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 825 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) |
| 826 | snd_wss_out(chip, CS4231_REC_FORMAT, |
| 827 | chip->image[CS4231_REC_FORMAT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 829 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | |
| 831 | #ifdef SNDRV_DEBUG_MCE |
| 832 | snd_printk("init: (5)\n"); |
| 833 | #endif |
| 834 | } |
| 835 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 836 | static int snd_wss_open(struct snd_wss *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
| 838 | unsigned long flags; |
| 839 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 840 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | if ((chip->mode & mode) || |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 842 | ((chip->mode & WSS_MODE_OPEN) && chip->single_dma)) { |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 843 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return -EAGAIN; |
| 845 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 846 | if (chip->mode & WSS_MODE_OPEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | chip->mode |= mode; |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 848 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | return 0; |
| 850 | } |
| 851 | /* ok. now enable and ack CODEC IRQ */ |
| 852 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 853 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) { |
| 854 | snd_wss_out(chip, CS4231_IRQ_STATUS, |
| 855 | CS4231_PLAYBACK_IRQ | |
| 856 | CS4231_RECORD_IRQ | |
| 857 | CS4231_TIMER_IRQ); |
| 858 | snd_wss_out(chip, CS4231_IRQ_STATUS, 0); |
| 859 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 860 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
| 861 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | chip->image[CS4231_PIN_CTRL] |= CS4231_IRQ_ENABLE; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 863 | snd_wss_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 864 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) { |
| 865 | snd_wss_out(chip, CS4231_IRQ_STATUS, |
| 866 | CS4231_PLAYBACK_IRQ | |
| 867 | CS4231_RECORD_IRQ | |
| 868 | CS4231_TIMER_IRQ); |
| 869 | snd_wss_out(chip, CS4231_IRQ_STATUS, 0); |
| 870 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 872 | |
| 873 | chip->mode = mode; |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 874 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | return 0; |
| 876 | } |
| 877 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 878 | static void snd_wss_close(struct snd_wss *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | { |
| 880 | unsigned long flags; |
| 881 | |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 882 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | chip->mode &= ~mode; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 884 | if (chip->mode & WSS_MODE_OPEN) { |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 885 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | return; |
| 887 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 888 | snd_wss_calibrate_mute(chip, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
| 890 | /* disable IRQ */ |
| 891 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 892 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) |
| 893 | snd_wss_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 894 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
| 895 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | chip->image[CS4231_PIN_CTRL] &= ~CS4231_IRQ_ENABLE; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 897 | snd_wss_out(chip, CS4231_PIN_CTRL, chip->image[CS4231_PIN_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
| 899 | /* now disable record & playback */ |
| 900 | |
| 901 | if (chip->image[CS4231_IFACE_CTRL] & (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 902 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) { |
| 903 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 904 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 906 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 907 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 908 | snd_wss_out(chip, CS4231_IFACE_CTRL, |
| 909 | chip->image[CS4231_IFACE_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 911 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 913 | } |
| 914 | |
| 915 | /* clear IRQ again */ |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 916 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) |
| 917 | snd_wss_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 918 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
| 919 | wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 921 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 922 | snd_wss_calibrate_mute(chip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
| 924 | chip->mode = 0; |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 925 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /* |
| 929 | * timer open/close |
| 930 | */ |
| 931 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 932 | static int snd_wss_timer_open(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 934 | struct snd_wss *chip = snd_timer_chip(timer); |
| 935 | snd_wss_open(chip, WSS_MODE_TIMER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 939 | static int snd_wss_timer_close(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 941 | struct snd_wss *chip = snd_timer_chip(timer); |
| 942 | snd_wss_close(chip, WSS_MODE_TIMER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | return 0; |
| 944 | } |
| 945 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 946 | static struct snd_timer_hardware snd_wss_timer_table = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
| 948 | .flags = SNDRV_TIMER_HW_AUTO, |
| 949 | .resolution = 9945, |
| 950 | .ticks = 65535, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 951 | .open = snd_wss_timer_open, |
| 952 | .close = snd_wss_timer_close, |
| 953 | .c_resolution = snd_wss_timer_resolution, |
| 954 | .start = snd_wss_timer_start, |
| 955 | .stop = snd_wss_timer_stop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | }; |
| 957 | |
| 958 | /* |
| 959 | * ok.. exported functions.. |
| 960 | */ |
| 961 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 962 | static int snd_wss_playback_hw_params(struct snd_pcm_substream *substream, |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 963 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 965 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | unsigned char new_pdfr; |
| 967 | int err; |
| 968 | |
| 969 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 970 | return err; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 971 | new_pdfr = snd_wss_get_format(chip, params_format(hw_params), |
| 972 | params_channels(hw_params)) | |
| 973 | snd_wss_get_rate(params_rate(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | chip->set_playback_format(chip, hw_params, new_pdfr); |
| 975 | return 0; |
| 976 | } |
| 977 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 978 | static int snd_wss_playback_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
| 980 | return snd_pcm_lib_free_pages(substream); |
| 981 | } |
| 982 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 983 | static int snd_wss_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 985 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 986 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | unsigned long flags; |
| 988 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 989 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 990 | |
| 991 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 992 | chip->p_dma_size = size; |
| 993 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO); |
| 994 | snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 995 | count = snd_wss_get_count(chip->image[CS4231_PLAYBK_FORMAT], count) - 1; |
| 996 | snd_wss_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count); |
| 997 | snd_wss_out(chip, CS4231_PLY_UPR_CNT, (unsigned char) (count >> 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 999 | #if 0 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1000 | snd_wss_debug(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | #endif |
| 1002 | return 0; |
| 1003 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1005 | static int snd_wss_capture_hw_params(struct snd_pcm_substream *substream, |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1006 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1008 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | unsigned char new_cdfr; |
| 1010 | int err; |
| 1011 | |
| 1012 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 1013 | return err; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1014 | new_cdfr = snd_wss_get_format(chip, params_format(hw_params), |
| 1015 | params_channels(hw_params)) | |
| 1016 | snd_wss_get_rate(params_rate(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | chip->set_capture_format(chip, hw_params, new_cdfr); |
| 1018 | return 0; |
| 1019 | } |
| 1020 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1021 | static int snd_wss_capture_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | { |
| 1023 | return snd_pcm_lib_free_pages(substream); |
| 1024 | } |
| 1025 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1026 | static int snd_wss_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1028 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1029 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | unsigned long flags; |
| 1031 | unsigned int size = snd_pcm_lib_buffer_bytes(substream); |
| 1032 | unsigned int count = snd_pcm_lib_period_bytes(substream); |
| 1033 | |
| 1034 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1035 | chip->c_dma_size = size; |
| 1036 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); |
| 1037 | snd_dma_program(chip->dma2, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1038 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 1039 | count = snd_wss_get_count(chip->image[CS4231_PLAYBK_FORMAT], |
| 1040 | count); |
| 1041 | else |
| 1042 | count = snd_wss_get_count(chip->image[CS4231_REC_FORMAT], |
| 1043 | count); |
| 1044 | count--; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1045 | if (chip->single_dma && chip->hardware != WSS_HW_INTERWAVE) { |
| 1046 | snd_wss_out(chip, CS4231_PLY_LWR_CNT, (unsigned char) count); |
| 1047 | snd_wss_out(chip, CS4231_PLY_UPR_CNT, |
| 1048 | (unsigned char) (count >> 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | } else { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1050 | snd_wss_out(chip, CS4231_REC_LWR_CNT, (unsigned char) count); |
| 1051 | snd_wss_out(chip, CS4231_REC_UPR_CNT, |
| 1052 | (unsigned char) (count >> 8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | } |
| 1054 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1055 | return 0; |
| 1056 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1058 | void snd_wss_overrange(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | { |
| 1060 | unsigned long flags; |
| 1061 | unsigned char res; |
| 1062 | |
| 1063 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1064 | res = snd_wss_in(chip, CS4231_TEST_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1066 | if (res & (0x08 | 0x02)) /* detect overrange only above 0dB; may be user selectable? */ |
| 1067 | chip->capture_substream->runtime->overrange++; |
| 1068 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1069 | EXPORT_SYMBOL(snd_wss_overrange); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1071 | irqreturn_t snd_wss_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1073 | struct snd_wss *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | unsigned char status; |
| 1075 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1076 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 1077 | /* pretend it was the only possible irq for AD1848 */ |
| 1078 | status = CS4231_PLAYBACK_IRQ; |
| 1079 | else |
| 1080 | status = snd_wss_in(chip, CS4231_IRQ_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | if (status & CS4231_TIMER_IRQ) { |
| 1082 | if (chip->timer) |
| 1083 | snd_timer_interrupt(chip->timer, chip->timer->sticks); |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1084 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1085 | if (chip->single_dma && chip->hardware != WSS_HW_INTERWAVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | if (status & CS4231_PLAYBACK_IRQ) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1087 | if (chip->mode & WSS_MODE_PLAY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | if (chip->playback_substream) |
| 1089 | snd_pcm_period_elapsed(chip->playback_substream); |
| 1090 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1091 | if (chip->mode & WSS_MODE_RECORD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | if (chip->capture_substream) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1093 | snd_wss_overrange(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | snd_pcm_period_elapsed(chip->capture_substream); |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | } else { |
| 1099 | if (status & CS4231_PLAYBACK_IRQ) { |
| 1100 | if (chip->playback_substream) |
| 1101 | snd_pcm_period_elapsed(chip->playback_substream); |
| 1102 | } |
| 1103 | if (status & CS4231_RECORD_IRQ) { |
| 1104 | if (chip->capture_substream) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1105 | snd_wss_overrange(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | snd_pcm_period_elapsed(chip->capture_substream); |
| 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | spin_lock(&chip->reg_lock); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1112 | status = ~CS4231_ALL_IRQS | ~status; |
| 1113 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 1114 | wss_outb(chip, CS4231P(STATUS), 0); |
| 1115 | else |
| 1116 | snd_wss_outm(chip, CS4231_IRQ_STATUS, status, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | spin_unlock(&chip->reg_lock); |
| 1118 | return IRQ_HANDLED; |
| 1119 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1120 | EXPORT_SYMBOL(snd_wss_interrupt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1122 | static snd_pcm_uframes_t snd_wss_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1124 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | size_t ptr; |
| 1126 | |
| 1127 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) |
| 1128 | return 0; |
| 1129 | ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size); |
| 1130 | return bytes_to_frames(substream->runtime, ptr); |
| 1131 | } |
| 1132 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1133 | static snd_pcm_uframes_t snd_wss_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1135 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | size_t ptr; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) |
| 1139 | return 0; |
| 1140 | ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size); |
| 1141 | return bytes_to_frames(substream->runtime, ptr); |
| 1142 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | |
| 1144 | /* |
| 1145 | |
| 1146 | */ |
| 1147 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1148 | static int snd_ad1848_probe(struct snd_wss *chip) |
| 1149 | { |
Rene Herman | c9a7dc2 | 2008-08-06 08:09:34 +0200 | [diff] [blame] | 1150 | unsigned long timeout = jiffies + msecs_to_jiffies(1000); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1151 | unsigned long flags; |
Rene Herman | c9a7dc2 | 2008-08-06 08:09:34 +0200 | [diff] [blame] | 1152 | unsigned char r; |
| 1153 | unsigned short hardware = 0; |
| 1154 | int err = 0; |
| 1155 | int i; |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1156 | |
Rene Herman | c9a7dc2 | 2008-08-06 08:09:34 +0200 | [diff] [blame] | 1157 | while (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) { |
| 1158 | if (time_after(jiffies, timeout)) |
| 1159 | return -ENODEV; |
| 1160 | cond_resched(); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1161 | } |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1162 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1163 | |
Rene Herman | c9a7dc2 | 2008-08-06 08:09:34 +0200 | [diff] [blame] | 1164 | /* set CS423x MODE 1 */ |
| 1165 | snd_wss_out(chip, CS4231_MISC_INFO, 0); |
| 1166 | |
| 1167 | snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x45); /* 0x55 & ~0x10 */ |
| 1168 | r = snd_wss_in(chip, CS4231_RIGHT_INPUT); |
| 1169 | if (r != 0x45) { |
| 1170 | /* RMGE always high on AD1847 */ |
| 1171 | if ((r & ~CS4231_ENABLE_MIC_GAIN) != 0x45) { |
| 1172 | err = -ENODEV; |
| 1173 | goto out; |
| 1174 | } |
| 1175 | hardware = WSS_HW_AD1847; |
| 1176 | } else { |
| 1177 | snd_wss_out(chip, CS4231_LEFT_INPUT, 0xaa); |
| 1178 | r = snd_wss_in(chip, CS4231_LEFT_INPUT); |
| 1179 | /* L/RMGE always low on AT2320 */ |
| 1180 | if ((r | CS4231_ENABLE_MIC_GAIN) != 0xaa) { |
| 1181 | err = -ENODEV; |
| 1182 | goto out; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | /* clear pending IRQ */ |
| 1187 | wss_inb(chip, CS4231P(STATUS)); |
| 1188 | wss_outb(chip, CS4231P(STATUS), 0); |
| 1189 | mb(); |
| 1190 | |
| 1191 | if ((chip->hardware & WSS_HW_TYPE_MASK) != WSS_HW_DETECT) |
| 1192 | goto out; |
| 1193 | |
| 1194 | if (hardware) { |
| 1195 | chip->hardware = hardware; |
| 1196 | goto out; |
| 1197 | } |
| 1198 | |
| 1199 | r = snd_wss_in(chip, CS4231_MISC_INFO); |
| 1200 | |
| 1201 | /* set CS423x MODE 2 */ |
| 1202 | snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2); |
| 1203 | for (i = 0; i < 16; i++) { |
| 1204 | if (snd_wss_in(chip, i) != snd_wss_in(chip, 16 + i)) { |
| 1205 | /* we have more than 16 registers: check ID */ |
| 1206 | if ((r & 0xf) != 0xa) |
| 1207 | goto out_mode; |
| 1208 | /* |
| 1209 | * on CMI8330, CS4231_VERSION is volume control and |
| 1210 | * can be set to 0 |
| 1211 | */ |
| 1212 | snd_wss_dout(chip, CS4231_VERSION, 0); |
| 1213 | r = snd_wss_in(chip, CS4231_VERSION) & 0xe7; |
| 1214 | if (!r) |
| 1215 | chip->hardware = WSS_HW_CMI8330; |
| 1216 | goto out_mode; |
| 1217 | } |
| 1218 | } |
| 1219 | if (r & 0x80) |
| 1220 | chip->hardware = WSS_HW_CS4248; |
| 1221 | else |
| 1222 | chip->hardware = WSS_HW_AD1848; |
| 1223 | out_mode: |
| 1224 | snd_wss_out(chip, CS4231_MISC_INFO, 0); |
| 1225 | out: |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1226 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Rene Herman | c9a7dc2 | 2008-08-06 08:09:34 +0200 | [diff] [blame] | 1227 | return err; |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1228 | } |
| 1229 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1230 | static int snd_wss_probe(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | { |
| 1232 | unsigned long flags; |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1233 | int i, id, rev, regnum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | unsigned char *ptr; |
| 1235 | unsigned int hw; |
| 1236 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1237 | id = snd_ad1848_probe(chip); |
| 1238 | if (id < 0) |
| 1239 | return id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1241 | hw = chip->hardware; |
| 1242 | if ((hw & WSS_HW_TYPE_MASK) == WSS_HW_DETECT) { |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1243 | for (i = 0; i < 50; i++) { |
| 1244 | mb(); |
| 1245 | if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) |
| 1246 | msleep(2); |
| 1247 | else { |
| 1248 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1249 | snd_wss_out(chip, CS4231_MISC_INFO, |
| 1250 | CS4231_MODE2); |
| 1251 | id = snd_wss_in(chip, CS4231_MISC_INFO) & 0x0f; |
| 1252 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1253 | if (id == 0x0a) |
| 1254 | break; /* this is valid value */ |
| 1255 | } |
| 1256 | } |
| 1257 | snd_printdd("wss: port = 0x%lx, id = 0x%x\n", chip->port, id); |
| 1258 | if (id != 0x0a) |
| 1259 | return -ENODEV; /* no valid device found */ |
| 1260 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1261 | rev = snd_wss_in(chip, CS4231_VERSION) & 0xe7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | snd_printdd("CS4231: VERSION (I25) = 0x%x\n", rev); |
| 1263 | if (rev == 0x80) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1264 | unsigned char tmp = snd_wss_in(chip, 23); |
| 1265 | snd_wss_out(chip, 23, ~tmp); |
| 1266 | if (snd_wss_in(chip, 23) != tmp) |
| 1267 | chip->hardware = WSS_HW_AD1845; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | else |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1269 | chip->hardware = WSS_HW_CS4231; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | } else if (rev == 0xa0) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1271 | chip->hardware = WSS_HW_CS4231A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | } else if (rev == 0xa2) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1273 | chip->hardware = WSS_HW_CS4232; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | } else if (rev == 0xb2) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1275 | chip->hardware = WSS_HW_CS4232A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | } else if (rev == 0x83) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1277 | chip->hardware = WSS_HW_CS4236; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | } else if (rev == 0x03) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1279 | chip->hardware = WSS_HW_CS4236B; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | } else { |
| 1281 | snd_printk("unknown CS chip with version 0x%x\n", rev); |
| 1282 | return -ENODEV; /* unknown CS4231 chip? */ |
| 1283 | } |
| 1284 | } |
| 1285 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1286 | wss_inb(chip, CS4231P(STATUS)); /* clear any pendings IRQ */ |
| 1287 | wss_outb(chip, CS4231P(STATUS), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | mb(); |
| 1289 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1290 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1291 | if (!(chip->hardware & WSS_HW_AD1848_MASK)) |
| 1292 | chip->image[CS4231_MISC_INFO] = CS4231_MODE2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | switch (chip->hardware) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1294 | case WSS_HW_INTERWAVE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | chip->image[CS4231_MISC_INFO] = CS4231_IW_MODE3; |
| 1296 | break; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1297 | case WSS_HW_CS4235: |
| 1298 | case WSS_HW_CS4236B: |
| 1299 | case WSS_HW_CS4237B: |
| 1300 | case WSS_HW_CS4238B: |
| 1301 | case WSS_HW_CS4239: |
| 1302 | if (hw == WSS_HW_DETECT3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | chip->image[CS4231_MISC_INFO] = CS4231_4236_MODE3; |
| 1304 | else |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1305 | chip->hardware = WSS_HW_CS4236; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | break; |
| 1307 | } |
| 1308 | |
| 1309 | chip->image[CS4231_IFACE_CTRL] = |
| 1310 | (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) | |
| 1311 | (chip->single_dma ? CS4231_SINGLE_DMA : 0); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1312 | if (chip->hardware != WSS_HW_OPTI93X) { |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 1313 | chip->image[CS4231_ALT_FEATURE_1] = 0x80; |
| 1314 | chip->image[CS4231_ALT_FEATURE_2] = |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1315 | chip->hardware == WSS_HW_INTERWAVE ? 0xc2 : 0x01; |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 1316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | ptr = (unsigned char *) &chip->image; |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1318 | regnum = (chip->hardware & WSS_HW_AD1848_MASK) ? 16 : 32; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1319 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1321 | for (i = 0; i < regnum; i++) /* ok.. fill all registers */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1322 | snd_wss_out(chip, i, *ptr++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1324 | snd_wss_mce_up(chip); |
| 1325 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | |
| 1327 | mdelay(2); |
| 1328 | |
| 1329 | /* ok.. try check hardware version for CS4236+ chips */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1330 | if ((hw & WSS_HW_TYPE_MASK) == WSS_HW_DETECT) { |
| 1331 | if (chip->hardware == WSS_HW_CS4236B) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | rev = snd_cs4236_ext_in(chip, CS4236_VERSION); |
| 1333 | snd_cs4236_ext_out(chip, CS4236_VERSION, 0xff); |
| 1334 | id = snd_cs4236_ext_in(chip, CS4236_VERSION); |
| 1335 | snd_cs4236_ext_out(chip, CS4236_VERSION, rev); |
| 1336 | snd_printdd("CS4231: ext version; rev = 0x%x, id = 0x%x\n", rev, id); |
| 1337 | if ((id & 0x1f) == 0x1d) { /* CS4235 */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1338 | chip->hardware = WSS_HW_CS4235; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | switch (id >> 5) { |
| 1340 | case 4: |
| 1341 | case 5: |
| 1342 | case 6: |
| 1343 | break; |
| 1344 | default: |
| 1345 | snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id); |
| 1346 | } |
| 1347 | } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */ |
| 1348 | switch (id >> 5) { |
| 1349 | case 4: |
| 1350 | case 5: |
| 1351 | case 6: |
| 1352 | case 7: |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1353 | chip->hardware = WSS_HW_CS4236B; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | break; |
| 1355 | default: |
| 1356 | snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id); |
| 1357 | } |
| 1358 | } else if ((id & 0x1f) == 0x08) { /* CS4237B */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1359 | chip->hardware = WSS_HW_CS4237B; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | switch (id >> 5) { |
| 1361 | case 4: |
| 1362 | case 5: |
| 1363 | case 6: |
| 1364 | case 7: |
| 1365 | break; |
| 1366 | default: |
| 1367 | snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id); |
| 1368 | } |
| 1369 | } else if ((id & 0x1f) == 0x09) { /* CS4238B */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1370 | chip->hardware = WSS_HW_CS4238B; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | switch (id >> 5) { |
| 1372 | case 5: |
| 1373 | case 6: |
| 1374 | case 7: |
| 1375 | break; |
| 1376 | default: |
| 1377 | snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id); |
| 1378 | } |
| 1379 | } else if ((id & 0x1f) == 0x1e) { /* CS4239 */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1380 | chip->hardware = WSS_HW_CS4239; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | switch (id >> 5) { |
| 1382 | case 4: |
| 1383 | case 5: |
| 1384 | case 6: |
| 1385 | break; |
| 1386 | default: |
| 1387 | snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id); |
| 1388 | } |
| 1389 | } else { |
| 1390 | snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id); |
| 1391 | } |
| 1392 | } |
| 1393 | } |
| 1394 | return 0; /* all things are ok.. */ |
| 1395 | } |
| 1396 | |
| 1397 | /* |
| 1398 | |
| 1399 | */ |
| 1400 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1401 | static struct snd_pcm_hardware snd_wss_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | { |
| 1403 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1404 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1405 | SNDRV_PCM_INFO_RESUME | |
| 1406 | SNDRV_PCM_INFO_SYNC_START), |
| 1407 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1408 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE), |
| 1409 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, |
| 1410 | .rate_min = 5510, |
| 1411 | .rate_max = 48000, |
| 1412 | .channels_min = 1, |
| 1413 | .channels_max = 2, |
| 1414 | .buffer_bytes_max = (128*1024), |
| 1415 | .period_bytes_min = 64, |
| 1416 | .period_bytes_max = (128*1024), |
| 1417 | .periods_min = 1, |
| 1418 | .periods_max = 1024, |
| 1419 | .fifo_size = 0, |
| 1420 | }; |
| 1421 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1422 | static struct snd_pcm_hardware snd_wss_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | { |
| 1424 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1425 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1426 | SNDRV_PCM_INFO_RESUME | |
| 1427 | SNDRV_PCM_INFO_SYNC_START), |
| 1428 | .formats = (SNDRV_PCM_FMTBIT_MU_LAW | SNDRV_PCM_FMTBIT_A_LAW | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1429 | SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE), |
| 1430 | .rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000, |
| 1431 | .rate_min = 5510, |
| 1432 | .rate_max = 48000, |
| 1433 | .channels_min = 1, |
| 1434 | .channels_max = 2, |
| 1435 | .buffer_bytes_max = (128*1024), |
| 1436 | .period_bytes_min = 64, |
| 1437 | .period_bytes_max = (128*1024), |
| 1438 | .periods_min = 1, |
| 1439 | .periods_max = 1024, |
| 1440 | .fifo_size = 0, |
| 1441 | }; |
| 1442 | |
| 1443 | /* |
| 1444 | |
| 1445 | */ |
| 1446 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1447 | static int snd_wss_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1449 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1450 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | int err; |
| 1452 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1453 | runtime->hw = snd_wss_playback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1455 | /* hardware limitation of older chipsets */ |
| 1456 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 1457 | runtime->hw.formats &= ~(SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1458 | SNDRV_PCM_FMTBIT_S16_BE); |
| 1459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | /* hardware bug in InterWave chipset */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1461 | if (chip->hardware == WSS_HW_INTERWAVE && chip->dma1 > 3) |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1462 | runtime->hw.formats &= ~SNDRV_PCM_FMTBIT_MU_LAW; |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | /* hardware limitation of cheap chips */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1465 | if (chip->hardware == WSS_HW_CS4235 || |
| 1466 | chip->hardware == WSS_HW_CS4239) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE; |
| 1468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max); |
| 1470 | snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max); |
| 1471 | |
| 1472 | if (chip->claim_dma) { |
| 1473 | if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0) |
| 1474 | return err; |
| 1475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1477 | err = snd_wss_open(chip, WSS_MODE_PLAY); |
| 1478 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | if (chip->release_dma) |
| 1480 | chip->release_dma(chip, chip->dma_private_data, chip->dma1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1482 | return err; |
| 1483 | } |
| 1484 | chip->playback_substream = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | snd_pcm_set_sync(substream); |
| 1486 | chip->rate_constraint(runtime); |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1490 | static int snd_wss_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1492 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1493 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | int err; |
| 1495 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1496 | runtime->hw = snd_wss_capture; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1498 | /* hardware limitation of older chipsets */ |
| 1499 | if (chip->hardware & WSS_HW_AD1848_MASK) |
| 1500 | runtime->hw.formats &= ~(SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1501 | SNDRV_PCM_FMTBIT_S16_BE); |
| 1502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | /* hardware limitation of cheap chips */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1504 | if (chip->hardware == WSS_HW_CS4235 || |
Krzysztof Helt | 31eca30 | 2008-07-31 21:11:46 +0200 | [diff] [blame] | 1505 | chip->hardware == WSS_HW_CS4239 || |
| 1506 | chip->hardware == WSS_HW_OPTI93X) |
| 1507 | runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | |
| 1508 | SNDRV_PCM_FMTBIT_S16_LE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max); |
| 1511 | snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max); |
| 1512 | |
| 1513 | if (chip->claim_dma) { |
| 1514 | if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0) |
| 1515 | return err; |
| 1516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1518 | err = snd_wss_open(chip, WSS_MODE_RECORD); |
| 1519 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | if (chip->release_dma) |
| 1521 | chip->release_dma(chip, chip->dma_private_data, chip->dma2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1523 | return err; |
| 1524 | } |
| 1525 | chip->capture_substream = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | snd_pcm_set_sync(substream); |
| 1527 | chip->rate_constraint(runtime); |
| 1528 | return 0; |
| 1529 | } |
| 1530 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1531 | static int snd_wss_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1533 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | |
| 1535 | chip->playback_substream = NULL; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1536 | snd_wss_close(chip, WSS_MODE_PLAY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | return 0; |
| 1538 | } |
| 1539 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1540 | static int snd_wss_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1542 | struct snd_wss *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | |
| 1544 | chip->capture_substream = NULL; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1545 | snd_wss_close(chip, WSS_MODE_RECORD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | return 0; |
| 1547 | } |
| 1548 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1549 | static void snd_wss_thinkpad_twiddle(struct snd_wss *chip, int on) |
| 1550 | { |
| 1551 | int tmp; |
| 1552 | |
| 1553 | if (!chip->thinkpad_flag) |
| 1554 | return; |
| 1555 | |
| 1556 | outb(0x1c, AD1848_THINKPAD_CTL_PORT1); |
| 1557 | tmp = inb(AD1848_THINKPAD_CTL_PORT2); |
| 1558 | |
| 1559 | if (on) |
| 1560 | /* turn it on */ |
| 1561 | tmp |= AD1848_THINKPAD_CS4248_ENABLE_BIT; |
| 1562 | else |
| 1563 | /* turn it off */ |
| 1564 | tmp &= ~AD1848_THINKPAD_CS4248_ENABLE_BIT; |
| 1565 | |
| 1566 | outb(tmp, AD1848_THINKPAD_CTL_PORT2); |
| 1567 | } |
| 1568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | #ifdef CONFIG_PM |
| 1570 | |
| 1571 | /* lowlevel suspend callback for CS4231 */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1572 | static void snd_wss_suspend(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | { |
| 1574 | int reg; |
| 1575 | unsigned long flags; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1576 | |
Takashi Iwai | 7bb35e20 | 2005-11-17 17:00:17 +0100 | [diff] [blame] | 1577 | snd_pcm_suspend_all(chip->pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1579 | for (reg = 0; reg < 32; reg++) |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1580 | chip->image[reg] = snd_wss_in(chip, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1582 | if (chip->thinkpad_flag) |
| 1583 | snd_wss_thinkpad_twiddle(chip, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | /* lowlevel resume callback for CS4231 */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1587 | static void snd_wss_resume(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | { |
| 1589 | int reg; |
| 1590 | unsigned long flags; |
Takashi Iwai | a2c855b | 2005-11-18 18:52:39 +0100 | [diff] [blame] | 1591 | /* int timeout; */ |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1592 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1593 | if (chip->thinkpad_flag) |
| 1594 | snd_wss_thinkpad_twiddle(chip, 1); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1595 | snd_wss_mce_up(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1597 | for (reg = 0; reg < 32; reg++) { |
| 1598 | switch (reg) { |
| 1599 | case CS4231_VERSION: |
| 1600 | break; |
| 1601 | default: |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1602 | snd_wss_out(chip, reg, chip->image[reg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | break; |
| 1604 | } |
| 1605 | } |
| 1606 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
Takashi Iwai | fa55f83 | 2005-11-17 17:48:30 +0100 | [diff] [blame] | 1607 | #if 1 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1608 | snd_wss_mce_down(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | #else |
| 1610 | /* The following is a workaround to avoid freeze after resume on TP600E. |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1611 | This is the first half of copy of snd_wss_mce_down(), but doesn't |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | include rescheduling. -- iwai |
| 1613 | */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1614 | snd_wss_busy_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1616 | chip->mce_bit &= ~CS4231_MCE; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1617 | timeout = wss_inb(chip, CS4231P(REGSEL)); |
| 1618 | wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1620 | if (timeout == 0x80) |
| 1621 | snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port); |
| 1622 | if ((timeout & CS4231_MCE) == 0 || |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1623 | !(chip->hardware & (WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | return; |
| 1625 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1626 | snd_wss_busy_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | #endif |
| 1628 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | #endif /* CONFIG_PM */ |
| 1630 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1631 | static int snd_wss_free(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | { |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 1633 | release_and_free_resource(chip->res_port); |
| 1634 | release_and_free_resource(chip->res_cport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | if (chip->irq >= 0) { |
| 1636 | disable_irq(chip->irq); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1637 | if (!(chip->hwshare & WSS_HWSHARE_IRQ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | free_irq(chip->irq, (void *) chip); |
| 1639 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1640 | if (!(chip->hwshare & WSS_HWSHARE_DMA1) && chip->dma1 >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | snd_dma_disable(chip->dma1); |
| 1642 | free_dma(chip->dma1); |
| 1643 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1644 | if (!(chip->hwshare & WSS_HWSHARE_DMA2) && |
| 1645 | chip->dma2 >= 0 && chip->dma2 != chip->dma1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | snd_dma_disable(chip->dma2); |
| 1647 | free_dma(chip->dma2); |
| 1648 | } |
| 1649 | if (chip->timer) |
| 1650 | snd_device_free(chip->card, chip->timer); |
| 1651 | kfree(chip); |
| 1652 | return 0; |
| 1653 | } |
| 1654 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1655 | static int snd_wss_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1657 | struct snd_wss *chip = device->device_data; |
| 1658 | return snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1661 | const char *snd_wss_chip_id(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | { |
| 1663 | switch (chip->hardware) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1664 | case WSS_HW_CS4231: |
| 1665 | return "CS4231"; |
| 1666 | case WSS_HW_CS4231A: |
| 1667 | return "CS4231A"; |
| 1668 | case WSS_HW_CS4232: |
| 1669 | return "CS4232"; |
| 1670 | case WSS_HW_CS4232A: |
| 1671 | return "CS4232A"; |
| 1672 | case WSS_HW_CS4235: |
| 1673 | return "CS4235"; |
| 1674 | case WSS_HW_CS4236: |
| 1675 | return "CS4236"; |
| 1676 | case WSS_HW_CS4236B: |
| 1677 | return "CS4236B"; |
| 1678 | case WSS_HW_CS4237B: |
| 1679 | return "CS4237B"; |
| 1680 | case WSS_HW_CS4238B: |
| 1681 | return "CS4238B"; |
| 1682 | case WSS_HW_CS4239: |
| 1683 | return "CS4239"; |
| 1684 | case WSS_HW_INTERWAVE: |
| 1685 | return "AMD InterWave"; |
| 1686 | case WSS_HW_OPL3SA2: |
| 1687 | return chip->card->shortname; |
| 1688 | case WSS_HW_AD1845: |
| 1689 | return "AD1845"; |
| 1690 | case WSS_HW_OPTI93X: |
| 1691 | return "OPTi 93x"; |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1692 | case WSS_HW_AD1847: |
| 1693 | return "AD1847"; |
| 1694 | case WSS_HW_AD1848: |
| 1695 | return "AD1848"; |
| 1696 | case WSS_HW_CS4248: |
| 1697 | return "CS4248"; |
| 1698 | case WSS_HW_CMI8330: |
| 1699 | return "CMI8330/C3D"; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1700 | default: |
| 1701 | return "???"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | } |
| 1703 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1704 | EXPORT_SYMBOL(snd_wss_chip_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1706 | static int snd_wss_new(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | unsigned short hardware, |
| 1708 | unsigned short hwshare, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1709 | struct snd_wss **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1711 | struct snd_wss *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | |
| 1713 | *rchip = NULL; |
Takashi Iwai | 9e76a76 | 2005-09-09 14:21:17 +0200 | [diff] [blame] | 1714 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | if (chip == NULL) |
| 1716 | return -ENOMEM; |
| 1717 | chip->hardware = hardware; |
| 1718 | chip->hwshare = hwshare; |
| 1719 | |
| 1720 | spin_lock_init(&chip->reg_lock); |
Ingo Molnar | 8b7547f | 2006-01-16 16:33:08 +0100 | [diff] [blame] | 1721 | mutex_init(&chip->mce_mutex); |
| 1722 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | chip->card = card; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1724 | chip->rate_constraint = snd_wss_xrate; |
| 1725 | chip->set_playback_format = snd_wss_playback_format; |
| 1726 | chip->set_capture_format = snd_wss_capture_format; |
| 1727 | if (chip->hardware == WSS_HW_OPTI93X) |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 1728 | memcpy(&chip->image, &snd_opti93x_original_image, |
| 1729 | sizeof(snd_opti93x_original_image)); |
| 1730 | else |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1731 | memcpy(&chip->image, &snd_wss_original_image, |
| 1732 | sizeof(snd_wss_original_image)); |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1733 | if (chip->hardware & WSS_HW_AD1848_MASK) { |
| 1734 | chip->image[CS4231_PIN_CTRL] = 0; |
| 1735 | chip->image[CS4231_TEST_INIT] = 0; |
| 1736 | } |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 1737 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1738 | *rchip = chip; |
| 1739 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | } |
| 1741 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1742 | int snd_wss_create(struct snd_card *card, |
| 1743 | unsigned long port, |
| 1744 | unsigned long cport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | int irq, int dma1, int dma2, |
| 1746 | unsigned short hardware, |
| 1747 | unsigned short hwshare, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1748 | struct snd_wss **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1750 | static struct snd_device_ops ops = { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1751 | .dev_free = snd_wss_dev_free, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | }; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1753 | struct snd_wss *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | int err; |
| 1755 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1756 | err = snd_wss_new(card, hardware, hwshare, &chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | if (err < 0) |
| 1758 | return err; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | chip->irq = -1; |
| 1761 | chip->dma1 = -1; |
| 1762 | chip->dma2 = -1; |
| 1763 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1764 | chip->res_port = request_region(port, 4, "WSS"); |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1765 | if (!chip->res_port) { |
| 1766 | snd_printk(KERN_ERR "wss: can't grab port 0x%lx\n", port); |
| 1767 | snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | return -EBUSY; |
| 1769 | } |
| 1770 | chip->port = port; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1771 | if ((long)cport >= 0) { |
| 1772 | chip->res_cport = request_region(cport, 8, "CS4232 Control"); |
| 1773 | if (!chip->res_cport) { |
| 1774 | snd_printk(KERN_ERR |
| 1775 | "wss: can't grab control port 0x%lx\n", cport); |
| 1776 | snd_wss_free(chip); |
| 1777 | return -ENODEV; |
| 1778 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | chip->cport = cport; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1781 | if (!(hwshare & WSS_HWSHARE_IRQ)) |
| 1782 | if (request_irq(irq, snd_wss_interrupt, IRQF_DISABLED, |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1783 | "WSS", (void *) chip)) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1784 | snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq); |
| 1785 | snd_wss_free(chip); |
| 1786 | return -EBUSY; |
| 1787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | chip->irq = irq; |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1789 | if (!(hwshare & WSS_HWSHARE_DMA1) && request_dma(dma1, "WSS - 1")) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1790 | snd_printk(KERN_ERR "wss: can't grab DMA1 %d\n", dma1); |
| 1791 | snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | return -EBUSY; |
| 1793 | } |
| 1794 | chip->dma1 = dma1; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1795 | if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 && |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1796 | dma2 >= 0 && request_dma(dma2, "WSS - 2")) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1797 | snd_printk(KERN_ERR "wss: can't grab DMA2 %d\n", dma2); |
| 1798 | snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | return -EBUSY; |
| 1800 | } |
| 1801 | if (dma1 == dma2 || dma2 < 0) { |
| 1802 | chip->single_dma = 1; |
| 1803 | chip->dma2 = chip->dma1; |
| 1804 | } else |
| 1805 | chip->dma2 = dma2; |
| 1806 | |
Krzysztof Helt | 760fc6b8 | 2008-07-31 21:10:47 +0200 | [diff] [blame] | 1807 | if (hardware == WSS_HW_THINKPAD) { |
| 1808 | chip->thinkpad_flag = 1; |
| 1809 | chip->hardware = WSS_HW_DETECT; /* reset */ |
| 1810 | snd_wss_thinkpad_twiddle(chip, 1); |
| 1811 | } |
| 1812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | /* global setup */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1814 | if (snd_wss_probe(chip) < 0) { |
| 1815 | snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | return -ENODEV; |
| 1817 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1818 | snd_wss_init(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 1820 | #if 0 |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1821 | if (chip->hardware & WSS_HW_CS4232_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | if (chip->res_cport == NULL) |
| 1823 | snd_printk("CS4232 control port features are not accessible\n"); |
| 1824 | } |
Takashi Iwai | a9824c8 | 2005-11-17 17:51:00 +0100 | [diff] [blame] | 1825 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | |
| 1827 | /* Register device */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1828 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); |
| 1829 | if (err < 0) { |
| 1830 | snd_wss_free(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | return err; |
| 1832 | } |
| 1833 | |
| 1834 | #ifdef CONFIG_PM |
| 1835 | /* Power Management */ |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1836 | chip->suspend = snd_wss_suspend; |
| 1837 | chip->resume = snd_wss_resume; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | #endif |
| 1839 | |
| 1840 | *rchip = chip; |
| 1841 | return 0; |
| 1842 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1843 | EXPORT_SYMBOL(snd_wss_create); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1845 | static struct snd_pcm_ops snd_wss_playback_ops = { |
| 1846 | .open = snd_wss_playback_open, |
| 1847 | .close = snd_wss_playback_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | .ioctl = snd_pcm_lib_ioctl, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1849 | .hw_params = snd_wss_playback_hw_params, |
| 1850 | .hw_free = snd_wss_playback_hw_free, |
| 1851 | .prepare = snd_wss_playback_prepare, |
| 1852 | .trigger = snd_wss_trigger, |
| 1853 | .pointer = snd_wss_playback_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1854 | }; |
| 1855 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1856 | static struct snd_pcm_ops snd_wss_capture_ops = { |
| 1857 | .open = snd_wss_capture_open, |
| 1858 | .close = snd_wss_capture_close, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | .ioctl = snd_pcm_lib_ioctl, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1860 | .hw_params = snd_wss_capture_hw_params, |
| 1861 | .hw_free = snd_wss_capture_hw_free, |
| 1862 | .prepare = snd_wss_capture_prepare, |
| 1863 | .trigger = snd_wss_trigger, |
| 1864 | .pointer = snd_wss_capture_pointer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | }; |
| 1866 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1867 | int snd_wss_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1869 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | int err; |
| 1871 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 1872 | err = snd_pcm_new(chip->card, "WSS", device, 1, 1, &pcm); |
| 1873 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | return err; |
| 1875 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1876 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_wss_playback_ops); |
| 1877 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_wss_capture_ops); |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | /* global setup */ |
| 1880 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | pcm->info_flags = 0; |
| 1882 | if (chip->single_dma) |
| 1883 | pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1884 | if (chip->hardware != WSS_HW_INTERWAVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1886 | strcpy(pcm->name, snd_wss_chip_id(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1889 | snd_dma_isa_data(), |
| 1890 | 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
| 1892 | chip->pcm = pcm; |
| 1893 | if (rpcm) |
| 1894 | *rpcm = pcm; |
| 1895 | return 0; |
| 1896 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1897 | EXPORT_SYMBOL(snd_wss_pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1899 | static void snd_wss_timer_free(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1901 | struct snd_wss *chip = timer->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | chip->timer = NULL; |
| 1903 | } |
| 1904 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1905 | int snd_wss_timer(struct snd_wss *chip, int device, struct snd_timer **rtimer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 1907 | struct snd_timer *timer; |
| 1908 | struct snd_timer_id tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | int err; |
| 1910 | |
| 1911 | /* Timer initialization */ |
| 1912 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; |
| 1913 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; |
| 1914 | tid.card = chip->card->number; |
| 1915 | tid.device = device; |
| 1916 | tid.subdevice = 0; |
| 1917 | if ((err = snd_timer_new(chip->card, "CS4231", &tid, &timer)) < 0) |
| 1918 | return err; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1919 | strcpy(timer->name, snd_wss_chip_id(chip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | timer->private_data = chip; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1921 | timer->private_free = snd_wss_timer_free; |
| 1922 | timer->hw = snd_wss_timer_table; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | chip->timer = timer; |
| 1924 | if (rtimer) |
| 1925 | *rtimer = timer; |
| 1926 | return 0; |
| 1927 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1928 | EXPORT_SYMBOL(snd_wss_timer); |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | /* |
| 1931 | * MIXER part |
| 1932 | */ |
| 1933 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1934 | static int snd_wss_info_mux(struct snd_kcontrol *kcontrol, |
| 1935 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | { |
| 1937 | static char *texts[4] = { |
| 1938 | "Line", "Aux", "Mic", "Mix" |
| 1939 | }; |
| 1940 | static char *opl3sa_texts[4] = { |
| 1941 | "Line", "CD", "Mic", "Mix" |
| 1942 | }; |
| 1943 | static char *gusmax_texts[4] = { |
| 1944 | "Line", "Synth", "Mic", "Mix" |
| 1945 | }; |
| 1946 | char **ptexts = texts; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1947 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | |
Takashi Iwai | 622207d | 2008-08-08 17:11:45 +0200 | [diff] [blame] | 1949 | if (snd_BUG_ON(!chip->card)) |
| 1950 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1952 | uinfo->count = 2; |
| 1953 | uinfo->value.enumerated.items = 4; |
| 1954 | if (uinfo->value.enumerated.item > 3) |
| 1955 | uinfo->value.enumerated.item = 3; |
| 1956 | if (!strcmp(chip->card->driver, "GUS MAX")) |
| 1957 | ptexts = gusmax_texts; |
| 1958 | switch (chip->hardware) { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1959 | case WSS_HW_INTERWAVE: |
| 1960 | ptexts = gusmax_texts; |
| 1961 | break; |
| 1962 | case WSS_HW_OPL3SA2: |
| 1963 | ptexts = opl3sa_texts; |
| 1964 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | } |
| 1966 | strcpy(uinfo->value.enumerated.name, ptexts[uinfo->value.enumerated.item]); |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1970 | static int snd_wss_get_mux(struct snd_kcontrol *kcontrol, |
| 1971 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1973 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | unsigned long flags; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1975 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1977 | ucontrol->value.enumerated.item[0] = (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1978 | ucontrol->value.enumerated.item[1] = (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1979 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1983 | static int snd_wss_put_mux(struct snd_kcontrol *kcontrol, |
| 1984 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 1986 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | unsigned long flags; |
| 1988 | unsigned short left, right; |
| 1989 | int change; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 1990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if (ucontrol->value.enumerated.item[0] > 3 || |
| 1992 | ucontrol->value.enumerated.item[1] > 3) |
| 1993 | return -EINVAL; |
| 1994 | left = ucontrol->value.enumerated.item[0] << 6; |
| 1995 | right = ucontrol->value.enumerated.item[1] << 6; |
| 1996 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1997 | left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; |
| 1998 | right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; |
| 1999 | change = left != chip->image[CS4231_LEFT_INPUT] || |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2000 | right != chip->image[CS4231_RIGHT_INPUT]; |
| 2001 | snd_wss_out(chip, CS4231_LEFT_INPUT, left); |
| 2002 | snd_wss_out(chip, CS4231_RIGHT_INPUT, right); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 2004 | return change; |
| 2005 | } |
| 2006 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2007 | int snd_wss_info_single(struct snd_kcontrol *kcontrol, |
| 2008 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | { |
| 2010 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 2011 | |
| 2012 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2013 | uinfo->count = 1; |
| 2014 | uinfo->value.integer.min = 0; |
| 2015 | uinfo->value.integer.max = mask; |
| 2016 | return 0; |
| 2017 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2018 | EXPORT_SYMBOL(snd_wss_info_single); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2020 | int snd_wss_get_single(struct snd_kcontrol *kcontrol, |
| 2021 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2023 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | unsigned long flags; |
| 2025 | int reg = kcontrol->private_value & 0xff; |
| 2026 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 2027 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 2028 | int invert = (kcontrol->private_value >> 24) & 0xff; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 2029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 2031 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; |
| 2032 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 2033 | if (invert) |
| 2034 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 2035 | return 0; |
| 2036 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2037 | EXPORT_SYMBOL(snd_wss_get_single); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2039 | int snd_wss_put_single(struct snd_kcontrol *kcontrol, |
| 2040 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2042 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | unsigned long flags; |
| 2044 | int reg = kcontrol->private_value & 0xff; |
| 2045 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 2046 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 2047 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 2048 | int change; |
| 2049 | unsigned short val; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 2050 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | val = (ucontrol->value.integer.value[0] & mask); |
| 2052 | if (invert) |
| 2053 | val = mask - val; |
| 2054 | val <<= shift; |
| 2055 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 2056 | val = (chip->image[reg] & ~(mask << shift)) | val; |
| 2057 | change = val != chip->image[reg]; |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2058 | snd_wss_out(chip, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 2060 | return change; |
| 2061 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2062 | EXPORT_SYMBOL(snd_wss_put_single); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2064 | int snd_wss_info_double(struct snd_kcontrol *kcontrol, |
| 2065 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | { |
| 2067 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 2068 | |
| 2069 | uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2070 | uinfo->count = 2; |
| 2071 | uinfo->value.integer.min = 0; |
| 2072 | uinfo->value.integer.max = mask; |
| 2073 | return 0; |
| 2074 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2075 | EXPORT_SYMBOL(snd_wss_info_double); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2077 | int snd_wss_get_double(struct snd_kcontrol *kcontrol, |
| 2078 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2080 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | unsigned long flags; |
| 2082 | int left_reg = kcontrol->private_value & 0xff; |
| 2083 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 2084 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 2085 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 2086 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 2087 | int invert = (kcontrol->private_value >> 22) & 1; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 2088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 2090 | ucontrol->value.integer.value[0] = (chip->image[left_reg] >> shift_left) & mask; |
| 2091 | ucontrol->value.integer.value[1] = (chip->image[right_reg] >> shift_right) & mask; |
| 2092 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 2093 | if (invert) { |
| 2094 | ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; |
| 2095 | ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; |
| 2096 | } |
| 2097 | return 0; |
| 2098 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2099 | EXPORT_SYMBOL(snd_wss_get_double); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2101 | int snd_wss_put_double(struct snd_kcontrol *kcontrol, |
| 2102 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2104 | struct snd_wss *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | unsigned long flags; |
| 2106 | int left_reg = kcontrol->private_value & 0xff; |
| 2107 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 2108 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 2109 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 2110 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 2111 | int invert = (kcontrol->private_value >> 22) & 1; |
| 2112 | int change; |
| 2113 | unsigned short val1, val2; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 2114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | val1 = ucontrol->value.integer.value[0] & mask; |
| 2116 | val2 = ucontrol->value.integer.value[1] & mask; |
| 2117 | if (invert) { |
| 2118 | val1 = mask - val1; |
| 2119 | val2 = mask - val2; |
| 2120 | } |
| 2121 | val1 <<= shift_left; |
| 2122 | val2 <<= shift_right; |
| 2123 | spin_lock_irqsave(&chip->reg_lock, flags); |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 2124 | if (left_reg != right_reg) { |
| 2125 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
| 2126 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; |
| 2127 | change = val1 != chip->image[left_reg] || |
| 2128 | val2 != chip->image[right_reg]; |
| 2129 | snd_wss_out(chip, left_reg, val1); |
| 2130 | snd_wss_out(chip, right_reg, val2); |
| 2131 | } else { |
| 2132 | mask = (mask << shift_left) | (mask << shift_right); |
| 2133 | val1 = (chip->image[left_reg] & ~mask) | val1 | val2; |
| 2134 | change = val1 != chip->image[left_reg]; |
| 2135 | snd_wss_out(chip, left_reg, val1); |
| 2136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 2138 | return change; |
| 2139 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2140 | EXPORT_SYMBOL(snd_wss_put_double); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 2142 | static const DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0); |
| 2143 | static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); |
| 2144 | static const DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0); |
| 2145 | |
| 2146 | static struct snd_kcontrol_new snd_ad1848_controls[] = { |
| 2147 | WSS_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, |
| 2148 | 7, 7, 1, 1), |
| 2149 | WSS_DOUBLE_TLV("PCM Playback Volume", 0, |
| 2150 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1, |
| 2151 | db_scale_6bit), |
| 2152 | WSS_DOUBLE("Aux Playback Switch", 0, |
| 2153 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 2154 | WSS_DOUBLE_TLV("Aux Playback Volume", 0, |
| 2155 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1, |
| 2156 | db_scale_5bit_12db_max), |
| 2157 | WSS_DOUBLE("Aux Playback Switch", 1, |
| 2158 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 2159 | WSS_DOUBLE_TLV("Aux Playback Volume", 1, |
| 2160 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1, |
| 2161 | db_scale_5bit_12db_max), |
| 2162 | WSS_DOUBLE_TLV("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, |
| 2163 | 0, 0, 15, 0, db_scale_rec_gain), |
| 2164 | { |
| 2165 | .name = "Capture Source", |
| 2166 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2167 | .info = snd_wss_info_mux, |
| 2168 | .get = snd_wss_get_mux, |
| 2169 | .put = snd_wss_put_mux, |
| 2170 | }, |
| 2171 | WSS_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), |
| 2172 | WSS_SINGLE_TLV("Loopback Capture Volume", 0, CS4231_LOOPBACK, 1, 63, 0, |
| 2173 | db_scale_6bit), |
| 2174 | }; |
| 2175 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2176 | static struct snd_kcontrol_new snd_wss_controls[] = { |
| 2177 | WSS_DOUBLE("PCM Playback Switch", 0, |
| 2178 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 2179 | WSS_DOUBLE("PCM Playback Volume", 0, |
| 2180 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
| 2181 | WSS_DOUBLE("Line Playback Switch", 0, |
| 2182 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 2183 | WSS_DOUBLE("Line Playback Volume", 0, |
| 2184 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
| 2185 | WSS_DOUBLE("Aux Playback Switch", 0, |
| 2186 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 2187 | WSS_DOUBLE("Aux Playback Volume", 0, |
| 2188 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), |
| 2189 | WSS_DOUBLE("Aux Playback Switch", 1, |
| 2190 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 2191 | WSS_DOUBLE("Aux Playback Volume", 1, |
| 2192 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), |
| 2193 | WSS_SINGLE("Mono Playback Switch", 0, |
| 2194 | CS4231_MONO_CTRL, 7, 1, 1), |
| 2195 | WSS_SINGLE("Mono Playback Volume", 0, |
| 2196 | CS4231_MONO_CTRL, 0, 15, 1), |
| 2197 | WSS_SINGLE("Mono Output Playback Switch", 0, |
| 2198 | CS4231_MONO_CTRL, 6, 1, 1), |
| 2199 | WSS_SINGLE("Mono Output Playback Bypass", 0, |
| 2200 | CS4231_MONO_CTRL, 5, 1, 0), |
| 2201 | WSS_DOUBLE("Capture Volume", 0, |
| 2202 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | { |
| 2204 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2205 | .name = "Capture Source", |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2206 | .info = snd_wss_info_mux, |
| 2207 | .get = snd_wss_get_mux, |
| 2208 | .put = snd_wss_put_mux, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | }, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2210 | WSS_DOUBLE("Mic Boost", 0, |
| 2211 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0), |
| 2212 | WSS_SINGLE("Loopback Capture Switch", 0, |
| 2213 | CS4231_LOOPBACK, 0, 1, 0), |
| 2214 | WSS_SINGLE("Loopback Capture Volume", 0, |
| 2215 | CS4231_LOOPBACK, 2, 63, 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2216 | }; |
Krzysztof Helt | 9295aea | 2008-07-31 21:00:17 +0200 | [diff] [blame] | 2217 | |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2218 | static struct snd_kcontrol_new snd_opti93x_controls[] = { |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2219 | WSS_DOUBLE("Master Playback Switch", 0, |
| 2220 | OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1), |
| 2221 | WSS_DOUBLE("Master Playback Volume", 0, |
| 2222 | OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1), |
| 2223 | WSS_DOUBLE("PCM Playback Switch", 0, |
| 2224 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 2225 | WSS_DOUBLE("PCM Playback Volume", 0, |
| 2226 | CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1), |
| 2227 | WSS_DOUBLE("FM Playback Switch", 0, |
| 2228 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 2229 | WSS_DOUBLE("FM Playback Volume", 0, |
| 2230 | CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1), |
| 2231 | WSS_DOUBLE("Line Playback Switch", 0, |
| 2232 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 2233 | WSS_DOUBLE("Line Playback Volume", 0, |
| 2234 | CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1), |
| 2235 | WSS_DOUBLE("Mic Playback Switch", 0, |
| 2236 | OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1), |
| 2237 | WSS_DOUBLE("Mic Playback Volume", 0, |
| 2238 | OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1), |
| 2239 | WSS_DOUBLE("Mic Boost", 0, |
| 2240 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0), |
| 2241 | WSS_DOUBLE("CD Playback Switch", 0, |
| 2242 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 2243 | WSS_DOUBLE("CD Playback Volume", 0, |
| 2244 | CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1), |
| 2245 | WSS_DOUBLE("Aux Playback Switch", 0, |
| 2246 | OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1), |
| 2247 | WSS_DOUBLE("Aux Playback Volume", 0, |
| 2248 | OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1), |
| 2249 | WSS_DOUBLE("Capture Volume", 0, |
| 2250 | CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0), |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2251 | { |
| 2252 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 2253 | .name = "Capture Source", |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2254 | .info = snd_wss_info_mux, |
| 2255 | .get = snd_wss_get_mux, |
| 2256 | .put = snd_wss_put_mux, |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2257 | } |
| 2258 | }; |
| 2259 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2260 | int snd_wss_mixer(struct snd_wss *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | { |
Takashi Iwai | ba2375a | 2005-11-17 14:30:42 +0100 | [diff] [blame] | 2262 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | unsigned int idx; |
| 2264 | int err; |
| 2265 | |
Takashi Iwai | 622207d | 2008-08-08 17:11:45 +0200 | [diff] [blame] | 2266 | if (snd_BUG_ON(!chip || !chip->pcm)) |
| 2267 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | |
| 2269 | card = chip->card; |
| 2270 | |
| 2271 | strcpy(card->mixername, chip->pcm->name); |
| 2272 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2273 | if (chip->hardware == WSS_HW_OPTI93X) |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2274 | for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) { |
| 2275 | err = snd_ctl_add(card, |
| 2276 | snd_ctl_new1(&snd_opti93x_controls[idx], |
| 2277 | chip)); |
| 2278 | if (err < 0) |
| 2279 | return err; |
| 2280 | } |
Krzysztof Helt | 5664daa | 2008-07-31 21:08:32 +0200 | [diff] [blame] | 2281 | else if (chip->hardware & WSS_HW_AD1848_MASK) |
| 2282 | for (idx = 0; idx < ARRAY_SIZE(snd_ad1848_controls); idx++) { |
| 2283 | err = snd_ctl_add(card, |
| 2284 | snd_ctl_new1(&snd_ad1848_controls[idx], |
| 2285 | chip)); |
| 2286 | if (err < 0) |
| 2287 | return err; |
| 2288 | } |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2289 | else |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2290 | for (idx = 0; idx < ARRAY_SIZE(snd_wss_controls); idx++) { |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2291 | err = snd_ctl_add(card, |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2292 | snd_ctl_new1(&snd_wss_controls[idx], |
Krzysztof Helt | abf1f5a | 2008-06-09 23:07:28 +0200 | [diff] [blame] | 2293 | chip)); |
| 2294 | if (err < 0) |
| 2295 | return err; |
| 2296 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | return 0; |
| 2298 | } |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2299 | EXPORT_SYMBOL(snd_wss_mixer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | |
Krzysztof Helt | ead893c | 2008-07-31 21:09:32 +0200 | [diff] [blame] | 2301 | const struct snd_pcm_ops *snd_wss_get_pcm_ops(int direction) |
| 2302 | { |
| 2303 | return direction == SNDRV_PCM_STREAM_PLAYBACK ? |
| 2304 | &snd_wss_playback_ops : &snd_wss_capture_ops; |
| 2305 | } |
| 2306 | EXPORT_SYMBOL(snd_wss_get_pcm_ops); |
| 2307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | /* |
| 2309 | * INIT part |
| 2310 | */ |
| 2311 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2312 | static int __init alsa_wss_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | { |
| 2314 | return 0; |
| 2315 | } |
| 2316 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2317 | static void __exit alsa_wss_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | { |
| 2319 | } |
| 2320 | |
Krzysztof Helt | 7779f75 | 2008-07-31 21:03:41 +0200 | [diff] [blame] | 2321 | module_init(alsa_wss_init); |
| 2322 | module_exit(alsa_wss_exit); |