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