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