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