Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver for CS4231 sound chips found on Sparcs. |
| 3 | * Copyright (C) 2002 David S. Miller <davem@redhat.com> |
| 4 | * |
| 5 | * Based entirely upon drivers/sbus/audio/cs4231.c which is: |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 6 | * Copyright (C) 1996, 1997, 1998 Derrick J Brashear (shadow@andrew.cmu.edu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * and also sound/isa/cs423x/cs4231_lib.c which is: |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 8 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/interrupt.h> |
| 17 | #include <linux/moduleparam.h> |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 18 | #include <linux/irq.h> |
| 19 | #include <linux/io.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | #include <sound/driver.h> |
| 23 | #include <sound/core.h> |
| 24 | #include <sound/pcm.h> |
| 25 | #include <sound/info.h> |
| 26 | #include <sound/control.h> |
| 27 | #include <sound/timer.h> |
| 28 | #include <sound/initval.h> |
| 29 | #include <sound/pcm_params.h> |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #ifdef CONFIG_SBUS |
| 32 | #define SBUS_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/sbus.h> |
| 34 | #endif |
| 35 | |
| 36 | #if defined(CONFIG_PCI) && defined(CONFIG_SPARC64) |
| 37 | #define EBUS_SUPPORT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/pci.h> |
| 39 | #include <asm/ebus.h> |
| 40 | #endif |
| 41 | |
| 42 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 43 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 44 | /* Enable this card */ |
| 45 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | module_param_array(index, int, NULL, 0444); |
| 48 | MODULE_PARM_DESC(index, "Index value for Sun CS4231 soundcard."); |
| 49 | module_param_array(id, charp, NULL, 0444); |
| 50 | MODULE_PARM_DESC(id, "ID string for Sun CS4231 soundcard."); |
| 51 | module_param_array(enable, bool, NULL, 0444); |
| 52 | MODULE_PARM_DESC(enable, "Enable Sun CS4231 soundcard."); |
| 53 | MODULE_AUTHOR("Jaroslav Kysela, Derrick J. Brashear and David S. Miller"); |
| 54 | MODULE_DESCRIPTION("Sun CS4231"); |
| 55 | MODULE_LICENSE("GPL"); |
| 56 | MODULE_SUPPORTED_DEVICE("{{Sun,CS4231}}"); |
| 57 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 58 | #ifdef SBUS_SUPPORT |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 59 | struct sbus_dma_info { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 60 | spinlock_t lock; /* DMA access lock */ |
| 61 | int dir; |
| 62 | void __iomem *regs; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 63 | }; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 64 | #endif |
| 65 | |
David S. Miller | 4f3f2f6 | 2006-01-17 15:55:58 -0800 | [diff] [blame] | 66 | struct snd_cs4231; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 67 | struct cs4231_dma_control { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 68 | void (*prepare)(struct cs4231_dma_control *dma_cont, |
| 69 | int dir); |
| 70 | void (*enable)(struct cs4231_dma_control *dma_cont, int on); |
| 71 | int (*request)(struct cs4231_dma_control *dma_cont, |
| 72 | dma_addr_t bus_addr, size_t len); |
| 73 | unsigned int (*address)(struct cs4231_dma_control *dma_cont); |
| 74 | void (*preallocate)(struct snd_cs4231 *chip, |
| 75 | struct snd_pcm *pcm); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 76 | #ifdef EBUS_SUPPORT |
| 77 | struct ebus_dma_info ebus_info; |
| 78 | #endif |
| 79 | #ifdef SBUS_SUPPORT |
| 80 | struct sbus_dma_info sbus_info; |
| 81 | #endif |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 82 | }; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 83 | |
| 84 | struct snd_cs4231 { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 85 | spinlock_t lock; /* registers access lock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | void __iomem *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 88 | struct cs4231_dma_control p_dma; |
| 89 | struct cs4231_dma_control c_dma; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | u32 flags; |
| 92 | #define CS4231_FLAG_EBUS 0x00000001 |
| 93 | #define CS4231_FLAG_PLAYBACK 0x00000002 |
| 94 | #define CS4231_FLAG_CAPTURE 0x00000004 |
| 95 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 96 | struct snd_card *card; |
| 97 | struct snd_pcm *pcm; |
| 98 | struct snd_pcm_substream *playback_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | unsigned int p_periods_sent; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 100 | struct snd_pcm_substream *capture_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | unsigned int c_periods_sent; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 102 | struct snd_timer *timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | unsigned short mode; |
| 105 | #define CS4231_MODE_NONE 0x0000 |
| 106 | #define CS4231_MODE_PLAY 0x0001 |
| 107 | #define CS4231_MODE_RECORD 0x0002 |
| 108 | #define CS4231_MODE_TIMER 0x0004 |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 109 | #define CS4231_MODE_OPEN (CS4231_MODE_PLAY | CS4231_MODE_RECORD | \ |
| 110 | CS4231_MODE_TIMER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | unsigned char image[32]; /* registers image */ |
| 113 | int mce_bit; |
| 114 | int calibrate_mute; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 115 | struct mutex mce_mutex; /* mutex for mce register */ |
| 116 | struct mutex open_mutex; /* mutex for ALSA open/close */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | union { |
| 119 | #ifdef SBUS_SUPPORT |
| 120 | struct sbus_dev *sdev; |
| 121 | #endif |
| 122 | #ifdef EBUS_SUPPORT |
| 123 | struct pci_dev *pdev; |
| 124 | #endif |
| 125 | } dev_u; |
| 126 | unsigned int irq[2]; |
| 127 | unsigned int regs_size; |
| 128 | struct snd_cs4231 *next; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 129 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 131 | static struct snd_cs4231 *cs4231_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | /* Eventually we can use sound/isa/cs423x/cs4231_lib.c directly, but for |
| 134 | * now.... -DaveM |
| 135 | */ |
| 136 | |
| 137 | /* IO ports */ |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 138 | #include <sound/cs4231-regs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | /* XXX offsets are different than PC ISA chips... */ |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 141 | #define CS4231U(chip, x) ((chip)->port + ((c_d_c_CS4231##x) << 2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* SBUS DMA register defines. */ |
| 144 | |
| 145 | #define APCCSR 0x10UL /* APC DMA CSR */ |
| 146 | #define APCCVA 0x20UL /* APC Capture DMA Address */ |
| 147 | #define APCCC 0x24UL /* APC Capture Count */ |
| 148 | #define APCCNVA 0x28UL /* APC Capture DMA Next Address */ |
| 149 | #define APCCNC 0x2cUL /* APC Capture Next Count */ |
| 150 | #define APCPVA 0x30UL /* APC Play DMA Address */ |
| 151 | #define APCPC 0x34UL /* APC Play Count */ |
| 152 | #define APCPNVA 0x38UL /* APC Play DMA Next Address */ |
| 153 | #define APCPNC 0x3cUL /* APC Play Next Count */ |
| 154 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 155 | /* Defines for SBUS DMA-routines */ |
| 156 | |
| 157 | #define APCVA 0x0UL /* APC DMA Address */ |
| 158 | #define APCC 0x4UL /* APC Count */ |
| 159 | #define APCNVA 0x8UL /* APC DMA Next Address */ |
| 160 | #define APCNC 0xcUL /* APC Next Count */ |
| 161 | #define APC_PLAY 0x30UL /* Play registers start at 0x30 */ |
| 162 | #define APC_RECORD 0x20UL /* Record registers start at 0x20 */ |
| 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | /* APCCSR bits */ |
| 165 | |
| 166 | #define APC_INT_PENDING 0x800000 /* Interrupt Pending */ |
| 167 | #define APC_PLAY_INT 0x400000 /* Playback interrupt */ |
| 168 | #define APC_CAPT_INT 0x200000 /* Capture interrupt */ |
| 169 | #define APC_GENL_INT 0x100000 /* General interrupt */ |
| 170 | #define APC_XINT_ENA 0x80000 /* General ext int. enable */ |
| 171 | #define APC_XINT_PLAY 0x40000 /* Playback ext intr */ |
| 172 | #define APC_XINT_CAPT 0x20000 /* Capture ext intr */ |
| 173 | #define APC_XINT_GENL 0x10000 /* Error ext intr */ |
| 174 | #define APC_XINT_EMPT 0x8000 /* Pipe empty interrupt (0 write to pva) */ |
| 175 | #define APC_XINT_PEMP 0x4000 /* Play pipe empty (pva and pnva not set) */ |
| 176 | #define APC_XINT_PNVA 0x2000 /* Playback NVA dirty */ |
| 177 | #define APC_XINT_PENA 0x1000 /* play pipe empty Int enable */ |
| 178 | #define APC_XINT_COVF 0x800 /* Cap data dropped on floor */ |
| 179 | #define APC_XINT_CNVA 0x400 /* Capture NVA dirty */ |
| 180 | #define APC_XINT_CEMP 0x200 /* Capture pipe empty (cva and cnva not set) */ |
| 181 | #define APC_XINT_CENA 0x100 /* Cap. pipe empty int enable */ |
| 182 | #define APC_PPAUSE 0x80 /* Pause the play DMA */ |
| 183 | #define APC_CPAUSE 0x40 /* Pause the capture DMA */ |
| 184 | #define APC_CDC_RESET 0x20 /* CODEC RESET */ |
| 185 | #define APC_PDMA_READY 0x08 /* Play DMA Go */ |
| 186 | #define APC_CDMA_READY 0x04 /* Capture DMA Go */ |
| 187 | #define APC_CHIP_RESET 0x01 /* Reset the chip */ |
| 188 | |
| 189 | /* EBUS DMA register offsets */ |
| 190 | |
| 191 | #define EBDMA_CSR 0x00UL /* Control/Status */ |
| 192 | #define EBDMA_ADDR 0x04UL /* DMA Address */ |
| 193 | #define EBDMA_COUNT 0x08UL /* DMA Count */ |
| 194 | |
| 195 | /* |
| 196 | * Some variables |
| 197 | */ |
| 198 | |
| 199 | static unsigned char freq_bits[14] = { |
| 200 | /* 5510 */ 0x00 | CS4231_XTAL2, |
| 201 | /* 6620 */ 0x0E | CS4231_XTAL2, |
| 202 | /* 8000 */ 0x00 | CS4231_XTAL1, |
| 203 | /* 9600 */ 0x0E | CS4231_XTAL1, |
| 204 | /* 11025 */ 0x02 | CS4231_XTAL2, |
| 205 | /* 16000 */ 0x02 | CS4231_XTAL1, |
| 206 | /* 18900 */ 0x04 | CS4231_XTAL2, |
| 207 | /* 22050 */ 0x06 | CS4231_XTAL2, |
| 208 | /* 27042 */ 0x04 | CS4231_XTAL1, |
| 209 | /* 32000 */ 0x06 | CS4231_XTAL1, |
| 210 | /* 33075 */ 0x0C | CS4231_XTAL2, |
| 211 | /* 37800 */ 0x08 | CS4231_XTAL2, |
| 212 | /* 44100 */ 0x0A | CS4231_XTAL2, |
| 213 | /* 48000 */ 0x0C | CS4231_XTAL1 |
| 214 | }; |
| 215 | |
| 216 | static unsigned int rates[14] = { |
| 217 | 5510, 6620, 8000, 9600, 11025, 16000, 18900, 22050, |
| 218 | 27042, 32000, 33075, 37800, 44100, 48000 |
| 219 | }; |
| 220 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 221 | static struct snd_pcm_hw_constraint_list hw_constraints_rates = { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 222 | .count = ARRAY_SIZE(rates), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | .list = rates, |
| 224 | }; |
| 225 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 226 | static int snd_cs4231_xrate(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | return snd_pcm_hw_constraint_list(runtime, 0, |
| 229 | SNDRV_PCM_HW_PARAM_RATE, |
| 230 | &hw_constraints_rates); |
| 231 | } |
| 232 | |
| 233 | static unsigned char snd_cs4231_original_image[32] = |
| 234 | { |
| 235 | 0x00, /* 00/00 - lic */ |
| 236 | 0x00, /* 01/01 - ric */ |
| 237 | 0x9f, /* 02/02 - la1ic */ |
| 238 | 0x9f, /* 03/03 - ra1ic */ |
| 239 | 0x9f, /* 04/04 - la2ic */ |
| 240 | 0x9f, /* 05/05 - ra2ic */ |
| 241 | 0xbf, /* 06/06 - loc */ |
| 242 | 0xbf, /* 07/07 - roc */ |
| 243 | 0x20, /* 08/08 - pdfr */ |
| 244 | CS4231_AUTOCALIB, /* 09/09 - ic */ |
| 245 | 0x00, /* 0a/10 - pc */ |
| 246 | 0x00, /* 0b/11 - ti */ |
| 247 | CS4231_MODE2, /* 0c/12 - mi */ |
| 248 | 0x00, /* 0d/13 - lbc */ |
| 249 | 0x00, /* 0e/14 - pbru */ |
| 250 | 0x00, /* 0f/15 - pbrl */ |
| 251 | 0x80, /* 10/16 - afei */ |
| 252 | 0x01, /* 11/17 - afeii */ |
| 253 | 0x9f, /* 12/18 - llic */ |
| 254 | 0x9f, /* 13/19 - rlic */ |
| 255 | 0x00, /* 14/20 - tlb */ |
| 256 | 0x00, /* 15/21 - thb */ |
| 257 | 0x00, /* 16/22 - la3mic/reserved */ |
| 258 | 0x00, /* 17/23 - ra3mic/reserved */ |
| 259 | 0x00, /* 18/24 - afs */ |
| 260 | 0x00, /* 19/25 - lamoc/version */ |
| 261 | 0x00, /* 1a/26 - mioc */ |
| 262 | 0x00, /* 1b/27 - ramoc/reserved */ |
| 263 | 0x20, /* 1c/28 - cdfr */ |
| 264 | 0x00, /* 1d/29 - res4 */ |
| 265 | 0x00, /* 1e/30 - cbru */ |
| 266 | 0x00, /* 1f/31 - cbrl */ |
| 267 | }; |
| 268 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 269 | static u8 __cs4231_readb(struct snd_cs4231 *cp, void __iomem *reg_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | { |
| 271 | #ifdef EBUS_SUPPORT |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 272 | if (cp->flags & CS4231_FLAG_EBUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | return readb(reg_addr); |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 274 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | #endif |
| 276 | #ifdef SBUS_SUPPORT |
| 277 | return sbus_readb(reg_addr); |
| 278 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 281 | static void __cs4231_writeb(struct snd_cs4231 *cp, u8 val, |
| 282 | void __iomem *reg_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | #ifdef EBUS_SUPPORT |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 285 | if (cp->flags & CS4231_FLAG_EBUS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | return writeb(val, reg_addr); |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 287 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | #endif |
| 289 | #ifdef SBUS_SUPPORT |
| 290 | return sbus_writeb(val, reg_addr); |
| 291 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* |
| 295 | * Basic I/O functions |
| 296 | */ |
| 297 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 298 | static void snd_cs4231_ready(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
| 300 | int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 302 | for (timeout = 250; timeout > 0; timeout--) { |
| 303 | int val = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
| 304 | if ((val & CS4231_INIT) == 0) |
| 305 | break; |
| 306 | udelay(100); |
| 307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 310 | static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, |
| 311 | unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 313 | snd_cs4231_ready(chip); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 314 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 315 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 316 | snd_printdd("out: auto calibration time out - reg = 0x%x, " |
| 317 | "value = 0x%x\n", |
| 318 | reg, value); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 319 | #endif |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 320 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 321 | wmb(); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 322 | __cs4231_writeb(chip, value, CS4231U(chip, REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | mb(); |
| 324 | } |
| 325 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 326 | static inline void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg, |
| 327 | unsigned char mask, unsigned char value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 329 | unsigned char tmp = (chip->image[reg] & mask) | value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 331 | chip->image[reg] = tmp; |
| 332 | if (!chip->calibrate_mute) |
| 333 | snd_cs4231_dout(chip, reg, tmp); |
| 334 | } |
| 335 | |
| 336 | static void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, |
| 337 | unsigned char value) |
| 338 | { |
| 339 | snd_cs4231_dout(chip, reg, value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | chip->image[reg] = value; |
| 341 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 344 | static unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 346 | snd_cs4231_ready(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 348 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 349 | snd_printdd("in: auto calibration time out - reg = 0x%x\n", |
| 350 | reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #endif |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 352 | __cs4231_writeb(chip, chip->mce_bit | reg, CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | mb(); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 354 | return __cs4231_readb(chip, CS4231U(chip, REG)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* |
| 358 | * CS4231 detection / MCE routines |
| 359 | */ |
| 360 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 361 | static void snd_cs4231_busy_wait(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
| 363 | int timeout; |
| 364 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 365 | /* looks like this sequence is proper for CS4231A chip (GUS MAX) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | for (timeout = 5; timeout > 0; timeout--) |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 367 | __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | /* end of cleanup sequence */ |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 370 | for (timeout = 500; timeout > 0; timeout--) { |
| 371 | int val = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
| 372 | if ((val & CS4231_INIT) == 0) |
| 373 | break; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 374 | msleep(1); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 378 | static void snd_cs4231_mce_up(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
| 380 | unsigned long flags; |
| 381 | int timeout; |
| 382 | |
| 383 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 384 | snd_cs4231_ready(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 386 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 387 | snd_printdd("mce_up - auto calibration time out (0)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | #endif |
| 389 | chip->mce_bit |= CS4231_MCE; |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 390 | timeout = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | if (timeout == 0x80) |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 392 | snd_printdd("mce_up [%p]: serious init problem - " |
| 393 | "codec still busy\n", |
| 394 | chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | if (!(timeout & CS4231_MCE)) |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 396 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), |
| 397 | CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | spin_unlock_irqrestore(&chip->lock, flags); |
| 399 | } |
| 400 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 401 | static void snd_cs4231_mce_down(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | { |
| 403 | unsigned long flags; |
| 404 | int timeout; |
| 405 | |
| 406 | spin_lock_irqsave(&chip->lock, flags); |
| 407 | snd_cs4231_busy_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 409 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
| 410 | snd_printdd("mce_down [%p] - auto calibration time out (0)\n", |
| 411 | CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | #endif |
| 413 | chip->mce_bit &= ~CS4231_MCE; |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 414 | timeout = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
| 415 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), |
| 416 | CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | if (timeout == 0x80) |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 418 | snd_printdd("mce_down [%p]: serious init problem - " |
| 419 | "codec still busy\n", |
| 420 | chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | if ((timeout & CS4231_MCE) == 0) { |
| 422 | spin_unlock_irqrestore(&chip->lock, flags); |
| 423 | return; |
| 424 | } |
| 425 | snd_cs4231_busy_wait(chip); |
| 426 | |
| 427 | /* calibration process */ |
| 428 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 429 | snd_cs4231_ready(chip); |
| 430 | snd_cs4231_ready(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 431 | timeout = snd_cs4231_in(chip, CS4231_TEST_INIT); |
| 432 | if ((timeout & CS4231_CALIB_IN_PROGRESS) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | snd_printd("cs4231_mce_down - auto calibration time out (1)\n"); |
| 434 | spin_unlock_irqrestore(&chip->lock, flags); |
| 435 | return; |
| 436 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | /* in 10ms increments, check condition, up to 250ms */ |
| 439 | timeout = 25; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 440 | while (snd_cs4231_in(chip, CS4231_TEST_INIT) & |
| 441 | CS4231_CALIB_IN_PROGRESS) { |
| 442 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | spin_unlock_irqrestore(&chip->lock, flags); |
| 444 | if (--timeout < 0) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 445 | snd_printk("mce_down - " |
| 446 | "auto calibration time out (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | return; |
| 448 | } |
| 449 | msleep(10); |
| 450 | spin_lock_irqsave(&chip->lock, flags); |
| 451 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | /* in 10ms increments, check condition, up to 100ms */ |
| 454 | timeout = 10; |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 455 | while (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | spin_unlock_irqrestore(&chip->lock, flags); |
| 457 | if (--timeout < 0) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 458 | snd_printk("mce_down - " |
| 459 | "auto calibration time out (3)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | return; |
| 461 | } |
| 462 | msleep(10); |
| 463 | spin_lock_irqsave(&chip->lock, flags); |
| 464 | } |
| 465 | spin_unlock_irqrestore(&chip->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 468 | static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont, |
| 469 | struct snd_pcm_substream *substream, |
| 470 | unsigned int *periods_sent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 472 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | while (1) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 475 | unsigned int period_size = snd_pcm_lib_period_bytes(substream); |
| 476 | unsigned int offset = period_size * (*periods_sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
Eric Sesterhenn | 817dd6e | 2006-03-24 18:49:12 +0100 | [diff] [blame] | 478 | BUG_ON(period_size >= (1 << 24)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 480 | if (dma_cont->request(dma_cont, |
| 481 | runtime->dma_addr + offset, period_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; |
| 484 | } |
| 485 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 486 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 487 | static void cs4231_dma_trigger(struct snd_pcm_substream *substream, |
| 488 | unsigned int what, int on) |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 489 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 490 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 491 | struct cs4231_dma_control *dma_cont; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 492 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 493 | if (what & CS4231_PLAYBACK_ENABLE) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 494 | dma_cont = &chip->p_dma; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 495 | if (on) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 496 | dma_cont->prepare(dma_cont, 0); |
| 497 | dma_cont->enable(dma_cont, 1); |
| 498 | snd_cs4231_advance_dma(dma_cont, |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 499 | chip->playback_substream, |
| 500 | &chip->p_periods_sent); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 501 | } else { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 502 | dma_cont->enable(dma_cont, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 503 | } |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 504 | } |
| 505 | if (what & CS4231_RECORD_ENABLE) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 506 | dma_cont = &chip->c_dma; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 507 | if (on) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 508 | dma_cont->prepare(dma_cont, 1); |
| 509 | dma_cont->enable(dma_cont, 1); |
| 510 | snd_cs4231_advance_dma(dma_cont, |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 511 | chip->capture_substream, |
| 512 | &chip->c_periods_sent); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 513 | } else { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 514 | dma_cont->enable(dma_cont, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 515 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 519 | static int snd_cs4231_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 521 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | int result = 0; |
| 523 | |
| 524 | switch (cmd) { |
| 525 | case SNDRV_PCM_TRIGGER_START: |
| 526 | case SNDRV_PCM_TRIGGER_STOP: |
| 527 | { |
| 528 | unsigned int what = 0; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 529 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | unsigned long flags; |
| 531 | |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 532 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | if (s == chip->playback_substream) { |
| 534 | what |= CS4231_PLAYBACK_ENABLE; |
| 535 | snd_pcm_trigger_done(s, substream); |
| 536 | } else if (s == chip->capture_substream) { |
| 537 | what |= CS4231_RECORD_ENABLE; |
| 538 | snd_pcm_trigger_done(s, substream); |
| 539 | } |
| 540 | } |
| 541 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | spin_lock_irqsave(&chip->lock, flags); |
| 543 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 544 | cs4231_dma_trigger(substream, what, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | chip->image[CS4231_IFACE_CTRL] |= what; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | } else { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 547 | cs4231_dma_trigger(substream, what, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | chip->image[CS4231_IFACE_CTRL] &= ~what; |
| 549 | } |
| 550 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, |
| 551 | chip->image[CS4231_IFACE_CTRL]); |
| 552 | spin_unlock_irqrestore(&chip->lock, flags); |
| 553 | break; |
| 554 | } |
| 555 | default: |
| 556 | result = -EINVAL; |
| 557 | break; |
| 558 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | return result; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * CODEC I/O |
| 565 | */ |
| 566 | |
| 567 | static unsigned char snd_cs4231_get_rate(unsigned int rate) |
| 568 | { |
| 569 | int i; |
| 570 | |
| 571 | for (i = 0; i < 14; i++) |
| 572 | if (rate == rates[i]) |
| 573 | return freq_bits[i]; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 574 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | return freq_bits[13]; |
| 576 | } |
| 577 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 578 | static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, int format, |
| 579 | int channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | { |
| 581 | unsigned char rformat; |
| 582 | |
| 583 | rformat = CS4231_LINEAR_8; |
| 584 | switch (format) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 585 | case SNDRV_PCM_FORMAT_MU_LAW: |
| 586 | rformat = CS4231_ULAW_8; |
| 587 | break; |
| 588 | case SNDRV_PCM_FORMAT_A_LAW: |
| 589 | rformat = CS4231_ALAW_8; |
| 590 | break; |
| 591 | case SNDRV_PCM_FORMAT_S16_LE: |
| 592 | rformat = CS4231_LINEAR_16; |
| 593 | break; |
| 594 | case SNDRV_PCM_FORMAT_S16_BE: |
| 595 | rformat = CS4231_LINEAR_16_BIG; |
| 596 | break; |
| 597 | case SNDRV_PCM_FORMAT_IMA_ADPCM: |
| 598 | rformat = CS4231_ADPCM_16; |
| 599 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | if (channels > 1) |
| 602 | rformat |= CS4231_STEREO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | return rformat; |
| 604 | } |
| 605 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 606 | static void snd_cs4231_calibrate_mute(struct snd_cs4231 *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
| 608 | unsigned long flags; |
| 609 | |
| 610 | mute = mute ? 1 : 0; |
| 611 | spin_lock_irqsave(&chip->lock, flags); |
| 612 | if (chip->calibrate_mute == mute) { |
| 613 | spin_unlock_irqrestore(&chip->lock, flags); |
| 614 | return; |
| 615 | } |
| 616 | if (!mute) { |
| 617 | snd_cs4231_dout(chip, CS4231_LEFT_INPUT, |
| 618 | chip->image[CS4231_LEFT_INPUT]); |
| 619 | snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, |
| 620 | chip->image[CS4231_RIGHT_INPUT]); |
| 621 | snd_cs4231_dout(chip, CS4231_LOOPBACK, |
| 622 | chip->image[CS4231_LOOPBACK]); |
| 623 | } |
| 624 | snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, |
| 625 | mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]); |
| 626 | snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, |
| 627 | mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]); |
| 628 | snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, |
| 629 | mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]); |
| 630 | snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, |
| 631 | mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]); |
| 632 | snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, |
| 633 | mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]); |
| 634 | snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, |
| 635 | mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]); |
| 636 | snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, |
| 637 | mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]); |
| 638 | snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, |
| 639 | mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]); |
| 640 | snd_cs4231_dout(chip, CS4231_MONO_CTRL, |
| 641 | mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]); |
| 642 | chip->calibrate_mute = mute; |
| 643 | spin_unlock_irqrestore(&chip->lock, flags); |
| 644 | } |
| 645 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 646 | static void snd_cs4231_playback_format(struct snd_cs4231 *chip, |
| 647 | struct snd_pcm_hw_params *params, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | unsigned char pdfr) |
| 649 | { |
| 650 | unsigned long flags; |
| 651 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 652 | mutex_lock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | snd_cs4231_calibrate_mute(chip, 1); |
| 654 | |
| 655 | snd_cs4231_mce_up(chip); |
| 656 | |
| 657 | spin_lock_irqsave(&chip->lock, flags); |
| 658 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 659 | (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ? |
| 660 | (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) : |
| 661 | pdfr); |
| 662 | spin_unlock_irqrestore(&chip->lock, flags); |
| 663 | |
| 664 | snd_cs4231_mce_down(chip); |
| 665 | |
| 666 | snd_cs4231_calibrate_mute(chip, 0); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 667 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 670 | static void snd_cs4231_capture_format(struct snd_cs4231 *chip, |
| 671 | struct snd_pcm_hw_params *params, |
| 672 | unsigned char cdfr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | { |
| 674 | unsigned long flags; |
| 675 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 676 | mutex_lock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | snd_cs4231_calibrate_mute(chip, 1); |
| 678 | |
| 679 | snd_cs4231_mce_up(chip); |
| 680 | |
| 681 | spin_lock_irqsave(&chip->lock, flags); |
| 682 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) { |
| 683 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 684 | ((chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) | |
| 685 | (cdfr & 0x0f)); |
| 686 | spin_unlock_irqrestore(&chip->lock, flags); |
| 687 | snd_cs4231_mce_down(chip); |
| 688 | snd_cs4231_mce_up(chip); |
| 689 | spin_lock_irqsave(&chip->lock, flags); |
| 690 | } |
| 691 | snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr); |
| 692 | spin_unlock_irqrestore(&chip->lock, flags); |
| 693 | |
| 694 | snd_cs4231_mce_down(chip); |
| 695 | |
| 696 | snd_cs4231_calibrate_mute(chip, 0); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 697 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* |
| 701 | * Timer interface |
| 702 | */ |
| 703 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 704 | static unsigned long snd_cs4231_timer_resolution(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 706 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920; |
| 709 | } |
| 710 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 711 | static int snd_cs4231_timer_start(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | { |
| 713 | unsigned long flags; |
| 714 | unsigned int ticks; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 715 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
| 717 | spin_lock_irqsave(&chip->lock, flags); |
| 718 | ticks = timer->sticks; |
| 719 | if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 || |
| 720 | (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] || |
| 721 | (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) { |
| 722 | snd_cs4231_out(chip, CS4231_TIMER_HIGH, |
| 723 | chip->image[CS4231_TIMER_HIGH] = |
| 724 | (unsigned char) (ticks >> 8)); |
| 725 | snd_cs4231_out(chip, CS4231_TIMER_LOW, |
| 726 | chip->image[CS4231_TIMER_LOW] = |
| 727 | (unsigned char) ticks); |
| 728 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 729 | chip->image[CS4231_ALT_FEATURE_1] | |
| 730 | CS4231_TIMER_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | } |
| 732 | spin_unlock_irqrestore(&chip->lock, flags); |
| 733 | |
| 734 | return 0; |
| 735 | } |
| 736 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 737 | static int snd_cs4231_timer_stop(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | { |
| 739 | unsigned long flags; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 740 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 743 | chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 745 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | spin_unlock_irqrestore(&chip->lock, flags); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 751 | static void __init snd_cs4231_init(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | { |
| 753 | unsigned long flags; |
| 754 | |
| 755 | snd_cs4231_mce_down(chip); |
| 756 | |
| 757 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 758 | snd_printdd("init: (1)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | #endif |
| 760 | snd_cs4231_mce_up(chip); |
| 761 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 762 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
| 763 | CS4231_PLAYBACK_PIO | |
| 764 | CS4231_RECORD_ENABLE | |
| 765 | CS4231_RECORD_PIO | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | CS4231_CALIB_MODE); |
| 767 | chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; |
| 768 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); |
| 769 | spin_unlock_irqrestore(&chip->lock, flags); |
| 770 | snd_cs4231_mce_down(chip); |
| 771 | |
| 772 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 773 | snd_printdd("init: (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | #endif |
| 775 | |
| 776 | snd_cs4231_mce_up(chip); |
| 777 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 778 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
| 779 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | spin_unlock_irqrestore(&chip->lock, flags); |
| 781 | snd_cs4231_mce_down(chip); |
| 782 | |
| 783 | #ifdef SNDRV_DEBUG_MCE |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 784 | snd_printdd("init: (3) - afei = 0x%x\n", |
| 785 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | #endif |
| 787 | |
| 788 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 789 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, |
| 790 | chip->image[CS4231_ALT_FEATURE_2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | spin_unlock_irqrestore(&chip->lock, flags); |
| 792 | |
| 793 | snd_cs4231_mce_up(chip); |
| 794 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 795 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 796 | chip->image[CS4231_PLAYBK_FORMAT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | spin_unlock_irqrestore(&chip->lock, flags); |
| 798 | snd_cs4231_mce_down(chip); |
| 799 | |
| 800 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 801 | snd_printdd("init: (4)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | #endif |
| 803 | |
| 804 | snd_cs4231_mce_up(chip); |
| 805 | spin_lock_irqsave(&chip->lock, flags); |
| 806 | snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]); |
| 807 | spin_unlock_irqrestore(&chip->lock, flags); |
| 808 | snd_cs4231_mce_down(chip); |
| 809 | |
| 810 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 811 | snd_printdd("init: (5)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | #endif |
| 813 | } |
| 814 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 815 | static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | { |
| 817 | unsigned long flags; |
| 818 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 819 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | if ((chip->mode & mode)) { |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 821 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | return -EAGAIN; |
| 823 | } |
| 824 | if (chip->mode & CS4231_MODE_OPEN) { |
| 825 | chip->mode |= mode; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 826 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | return 0; |
| 828 | } |
| 829 | /* ok. now enable and ack CODEC IRQ */ |
| 830 | spin_lock_irqsave(&chip->lock, flags); |
| 831 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | |
| 832 | CS4231_RECORD_IRQ | |
| 833 | CS4231_TIMER_IRQ); |
| 834 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 835 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 836 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
| 838 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | |
| 839 | CS4231_RECORD_IRQ | |
| 840 | CS4231_TIMER_IRQ); |
| 841 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | spin_unlock_irqrestore(&chip->lock, flags); |
| 844 | |
| 845 | chip->mode = mode; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 846 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 850 | static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
| 852 | unsigned long flags; |
| 853 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 854 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | chip->mode &= ~mode; |
| 856 | if (chip->mode & CS4231_MODE_OPEN) { |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 857 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | return; |
| 859 | } |
| 860 | snd_cs4231_calibrate_mute(chip, 1); |
| 861 | |
| 862 | /* disable IRQ */ |
| 863 | spin_lock_irqsave(&chip->lock, flags); |
| 864 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 865 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 866 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | /* now disable record & playback */ |
| 869 | |
| 870 | if (chip->image[CS4231_IFACE_CTRL] & |
| 871 | (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 872 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) { |
| 873 | spin_unlock_irqrestore(&chip->lock, flags); |
| 874 | snd_cs4231_mce_up(chip); |
| 875 | spin_lock_irqsave(&chip->lock, flags); |
| 876 | chip->image[CS4231_IFACE_CTRL] &= |
| 877 | ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 878 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 879 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, |
| 880 | chip->image[CS4231_IFACE_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | spin_unlock_irqrestore(&chip->lock, flags); |
| 882 | snd_cs4231_mce_down(chip); |
| 883 | spin_lock_irqsave(&chip->lock, flags); |
| 884 | } |
| 885 | |
| 886 | /* clear IRQ again */ |
| 887 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 888 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 889 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | spin_unlock_irqrestore(&chip->lock, flags); |
| 891 | |
| 892 | snd_cs4231_calibrate_mute(chip, 0); |
| 893 | |
| 894 | chip->mode = 0; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 895 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | /* |
| 899 | * timer open/close |
| 900 | */ |
| 901 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 902 | static int snd_cs4231_timer_open(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 904 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | snd_cs4231_open(chip, CS4231_MODE_TIMER); |
| 906 | return 0; |
| 907 | } |
| 908 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 909 | static int snd_cs4231_timer_close(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 911 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | snd_cs4231_close(chip, CS4231_MODE_TIMER); |
| 913 | return 0; |
| 914 | } |
| 915 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 916 | static struct snd_timer_hardware snd_cs4231_timer_table = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | .flags = SNDRV_TIMER_HW_AUTO, |
| 918 | .resolution = 9945, |
| 919 | .ticks = 65535, |
| 920 | .open = snd_cs4231_timer_open, |
| 921 | .close = snd_cs4231_timer_close, |
| 922 | .c_resolution = snd_cs4231_timer_resolution, |
| 923 | .start = snd_cs4231_timer_start, |
| 924 | .stop = snd_cs4231_timer_stop, |
| 925 | }; |
| 926 | |
| 927 | /* |
| 928 | * ok.. exported functions.. |
| 929 | */ |
| 930 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 931 | static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream, |
| 932 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 934 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | unsigned char new_pdfr; |
| 936 | int err; |
| 937 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 938 | err = snd_pcm_lib_malloc_pages(substream, |
| 939 | params_buffer_bytes(hw_params)); |
| 940 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | return err; |
| 942 | new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
| 943 | params_channels(hw_params)) | |
| 944 | snd_cs4231_get_rate(params_rate(hw_params)); |
| 945 | snd_cs4231_playback_format(chip, hw_params, new_pdfr); |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 950 | static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 952 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 953 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | unsigned long flags; |
| 955 | |
| 956 | spin_lock_irqsave(&chip->lock, flags); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
| 959 | CS4231_PLAYBACK_PIO); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 960 | |
Eric Sesterhenn | 817dd6e | 2006-03-24 18:49:12 +0100 | [diff] [blame] | 961 | BUG_ON(runtime->period_size > 0xffff + 1); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 962 | |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 963 | chip->p_periods_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | spin_unlock_irqrestore(&chip->lock, flags); |
| 965 | |
| 966 | return 0; |
| 967 | } |
| 968 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 969 | static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream, |
| 970 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 972 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | unsigned char new_cdfr; |
| 974 | int err; |
| 975 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 976 | err = snd_pcm_lib_malloc_pages(substream, |
| 977 | params_buffer_bytes(hw_params)); |
| 978 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return err; |
| 980 | new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
| 981 | params_channels(hw_params)) | |
| 982 | snd_cs4231_get_rate(params_rate(hw_params)); |
| 983 | snd_cs4231_capture_format(chip, hw_params, new_cdfr); |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 988 | static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 990 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | unsigned long flags; |
| 992 | |
| 993 | spin_lock_irqsave(&chip->lock, flags); |
| 994 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | |
| 995 | CS4231_RECORD_PIO); |
| 996 | |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 997 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 998 | chip->c_periods_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1004 | static void snd_cs4231_overrange(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | { |
| 1006 | unsigned long flags; |
| 1007 | unsigned char res; |
| 1008 | |
| 1009 | spin_lock_irqsave(&chip->lock, flags); |
| 1010 | res = snd_cs4231_in(chip, CS4231_TEST_INIT); |
| 1011 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1012 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1013 | /* detect overrange only above 0dB; may be user selectable? */ |
| 1014 | if (res & (0x08 | 0x02)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | chip->capture_substream->runtime->overrange++; |
| 1016 | } |
| 1017 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1018 | static void snd_cs4231_play_callback(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) { |
| 1021 | snd_pcm_period_elapsed(chip->playback_substream); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1022 | snd_cs4231_advance_dma(&chip->p_dma, chip->playback_substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | &chip->p_periods_sent); |
| 1024 | } |
| 1025 | } |
| 1026 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1027 | static void snd_cs4231_capture_callback(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) { |
| 1030 | snd_pcm_period_elapsed(chip->capture_substream); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1031 | snd_cs4231_advance_dma(&chip->c_dma, chip->capture_substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | &chip->c_periods_sent); |
| 1033 | } |
| 1034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1036 | static snd_pcm_uframes_t snd_cs4231_playback_pointer( |
| 1037 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1039 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1040 | struct cs4231_dma_control *dma_cont = &chip->p_dma; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1041 | size_t ptr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1042 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) |
| 1044 | return 0; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1045 | ptr = dma_cont->address(dma_cont); |
| 1046 | if (ptr != 0) |
| 1047 | ptr -= substream->runtime->dma_addr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1048 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1049 | return bytes_to_frames(substream->runtime, ptr); |
| 1050 | } |
| 1051 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1052 | static snd_pcm_uframes_t snd_cs4231_capture_pointer( |
| 1053 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1055 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1056 | struct cs4231_dma_control *dma_cont = &chip->c_dma; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1057 | size_t ptr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) |
| 1060 | return 0; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1061 | ptr = dma_cont->address(dma_cont); |
| 1062 | if (ptr != 0) |
| 1063 | ptr -= substream->runtime->dma_addr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | return bytes_to_frames(substream->runtime, ptr); |
| 1066 | } |
| 1067 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1068 | static int __init snd_cs4231_probe(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | { |
| 1070 | unsigned long flags; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1071 | int i; |
| 1072 | int id = 0; |
| 1073 | int vers = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | unsigned char *ptr; |
| 1075 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | for (i = 0; i < 50; i++) { |
| 1077 | mb(); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 1078 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1079 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | else { |
| 1081 | spin_lock_irqsave(&chip->lock, flags); |
| 1082 | snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2); |
| 1083 | id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f; |
| 1084 | vers = snd_cs4231_in(chip, CS4231_VERSION); |
| 1085 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1086 | if (id == 0x0a) |
| 1087 | break; /* this is valid value */ |
| 1088 | } |
| 1089 | } |
| 1090 | snd_printdd("cs4231: port = %p, id = 0x%x\n", chip->port, id); |
| 1091 | if (id != 0x0a) |
| 1092 | return -ENODEV; /* no valid device found */ |
| 1093 | |
| 1094 | spin_lock_irqsave(&chip->lock, flags); |
| 1095 | |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 1096 | /* clear any pendings IRQ */ |
| 1097 | __cs4231_readb(chip, CS4231U(chip, STATUS)); |
| 1098 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | mb(); |
| 1100 | |
| 1101 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1102 | |
| 1103 | chip->image[CS4231_MISC_INFO] = CS4231_MODE2; |
| 1104 | chip->image[CS4231_IFACE_CTRL] = |
| 1105 | chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA; |
| 1106 | chip->image[CS4231_ALT_FEATURE_1] = 0x80; |
| 1107 | chip->image[CS4231_ALT_FEATURE_2] = 0x01; |
| 1108 | if (vers & 0x20) |
| 1109 | chip->image[CS4231_ALT_FEATURE_2] |= 0x02; |
| 1110 | |
| 1111 | ptr = (unsigned char *) &chip->image; |
| 1112 | |
| 1113 | snd_cs4231_mce_down(chip); |
| 1114 | |
| 1115 | spin_lock_irqsave(&chip->lock, flags); |
| 1116 | |
| 1117 | for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */ |
| 1118 | snd_cs4231_out(chip, i, *ptr++); |
| 1119 | |
| 1120 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1121 | |
| 1122 | snd_cs4231_mce_up(chip); |
| 1123 | |
| 1124 | snd_cs4231_mce_down(chip); |
| 1125 | |
| 1126 | mdelay(2); |
| 1127 | |
| 1128 | return 0; /* all things are ok.. */ |
| 1129 | } |
| 1130 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1131 | static struct snd_pcm_hardware snd_cs4231_playback = { |
| 1132 | .info = SNDRV_PCM_INFO_MMAP | |
| 1133 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1134 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1135 | SNDRV_PCM_INFO_SYNC_START, |
| 1136 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
| 1137 | SNDRV_PCM_FMTBIT_A_LAW | |
| 1138 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1139 | SNDRV_PCM_FMTBIT_U8 | |
| 1140 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1141 | SNDRV_PCM_FMTBIT_S16_BE, |
| 1142 | .rates = SNDRV_PCM_RATE_KNOT | |
| 1143 | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | .rate_min = 5510, |
| 1145 | .rate_max = 48000, |
| 1146 | .channels_min = 1, |
| 1147 | .channels_max = 2, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1148 | .buffer_bytes_max = 32 * 1024, |
David S. Miller | f9af1d9 | 2007-01-03 18:51:54 -0800 | [diff] [blame] | 1149 | .period_bytes_min = 64, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1150 | .period_bytes_max = 32 * 1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | .periods_min = 1, |
| 1152 | .periods_max = 1024, |
| 1153 | }; |
| 1154 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1155 | static struct snd_pcm_hardware snd_cs4231_capture = { |
| 1156 | .info = SNDRV_PCM_INFO_MMAP | |
| 1157 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1158 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1159 | SNDRV_PCM_INFO_SYNC_START, |
| 1160 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
| 1161 | SNDRV_PCM_FMTBIT_A_LAW | |
| 1162 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1163 | SNDRV_PCM_FMTBIT_U8 | |
| 1164 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1165 | SNDRV_PCM_FMTBIT_S16_BE, |
| 1166 | .rates = SNDRV_PCM_RATE_KNOT | |
| 1167 | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | .rate_min = 5510, |
| 1169 | .rate_max = 48000, |
| 1170 | .channels_min = 1, |
| 1171 | .channels_max = 2, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1172 | .buffer_bytes_max = 32 * 1024, |
David S. Miller | f9af1d9 | 2007-01-03 18:51:54 -0800 | [diff] [blame] | 1173 | .period_bytes_min = 64, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1174 | .period_bytes_max = 32 * 1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | .periods_min = 1, |
| 1176 | .periods_max = 1024, |
| 1177 | }; |
| 1178 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1179 | static int snd_cs4231_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1181 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1182 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | int err; |
| 1184 | |
| 1185 | runtime->hw = snd_cs4231_playback; |
| 1186 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1187 | err = snd_cs4231_open(chip, CS4231_MODE_PLAY); |
| 1188 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1190 | return err; |
| 1191 | } |
| 1192 | chip->playback_substream = substream; |
| 1193 | chip->p_periods_sent = 0; |
| 1194 | snd_pcm_set_sync(substream); |
| 1195 | snd_cs4231_xrate(runtime); |
| 1196 | |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1200 | static int snd_cs4231_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1202 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1203 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | int err; |
| 1205 | |
| 1206 | runtime->hw = snd_cs4231_capture; |
| 1207 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1208 | err = snd_cs4231_open(chip, CS4231_MODE_RECORD); |
| 1209 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1211 | return err; |
| 1212 | } |
| 1213 | chip->capture_substream = substream; |
| 1214 | chip->c_periods_sent = 0; |
| 1215 | snd_pcm_set_sync(substream); |
| 1216 | snd_cs4231_xrate(runtime); |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1221 | static int snd_cs4231_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1223 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | snd_cs4231_close(chip, CS4231_MODE_PLAY); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1226 | chip->playback_substream = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | |
| 1228 | return 0; |
| 1229 | } |
| 1230 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1231 | static int snd_cs4231_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1233 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | snd_cs4231_close(chip, CS4231_MODE_RECORD); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1236 | chip->capture_substream = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | /* XXX We can do some power-management, in particular on EBUS using |
| 1242 | * XXX the audio AUXIO register... |
| 1243 | */ |
| 1244 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1245 | static struct snd_pcm_ops snd_cs4231_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | .open = snd_cs4231_playback_open, |
| 1247 | .close = snd_cs4231_playback_close, |
| 1248 | .ioctl = snd_pcm_lib_ioctl, |
| 1249 | .hw_params = snd_cs4231_playback_hw_params, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1250 | .hw_free = snd_pcm_lib_free_pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | .prepare = snd_cs4231_playback_prepare, |
| 1252 | .trigger = snd_cs4231_trigger, |
| 1253 | .pointer = snd_cs4231_playback_pointer, |
| 1254 | }; |
| 1255 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1256 | static struct snd_pcm_ops snd_cs4231_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | .open = snd_cs4231_capture_open, |
| 1258 | .close = snd_cs4231_capture_close, |
| 1259 | .ioctl = snd_pcm_lib_ioctl, |
| 1260 | .hw_params = snd_cs4231_capture_hw_params, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1261 | .hw_free = snd_pcm_lib_free_pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | .prepare = snd_cs4231_capture_prepare, |
| 1263 | .trigger = snd_cs4231_trigger, |
| 1264 | .pointer = snd_cs4231_capture_pointer, |
| 1265 | }; |
| 1266 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1267 | static int __init snd_cs4231_pcm(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1269 | struct snd_cs4231 *chip = card->private_data; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1270 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | int err; |
| 1272 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1273 | err = snd_pcm_new(card, "CS4231", 0, 1, 1, &pcm); |
| 1274 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | return err; |
| 1276 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1277 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1278 | &snd_cs4231_playback_ops); |
| 1279 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1280 | &snd_cs4231_capture_ops); |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | /* global setup */ |
| 1283 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1285 | strcpy(pcm->name, "CS4231"); |
| 1286 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1287 | chip->p_dma.preallocate(chip, pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | chip->pcm = pcm; |
| 1290 | |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1294 | static int __init snd_cs4231_timer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1296 | struct snd_cs4231 *chip = card->private_data; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1297 | struct snd_timer *timer; |
| 1298 | struct snd_timer_id tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | int err; |
| 1300 | |
| 1301 | /* Timer initialization */ |
| 1302 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; |
| 1303 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1304 | tid.card = card->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | tid.device = 0; |
| 1306 | tid.subdevice = 0; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1307 | err = snd_timer_new(card, "CS4231", &tid, &timer); |
| 1308 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | return err; |
| 1310 | strcpy(timer->name, "CS4231"); |
| 1311 | timer->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | timer->hw = snd_cs4231_timer_table; |
| 1313 | chip->timer = timer; |
| 1314 | |
| 1315 | return 0; |
| 1316 | } |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | /* |
| 1319 | * MIXER part |
| 1320 | */ |
| 1321 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1322 | static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, |
| 1323 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
| 1325 | static char *texts[4] = { |
| 1326 | "Line", "CD", "Mic", "Mix" |
| 1327 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1330 | uinfo->count = 2; |
| 1331 | uinfo->value.enumerated.items = 4; |
| 1332 | if (uinfo->value.enumerated.item > 3) |
| 1333 | uinfo->value.enumerated.item = 3; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1334 | strcpy(uinfo->value.enumerated.name, |
| 1335 | texts[uinfo->value.enumerated.item]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1340 | static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, |
| 1341 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1343 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | unsigned long flags; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1345 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | spin_lock_irqsave(&chip->lock, flags); |
| 1347 | ucontrol->value.enumerated.item[0] = |
| 1348 | (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1349 | ucontrol->value.enumerated.item[1] = |
| 1350 | (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1351 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1356 | static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, |
| 1357 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1359 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | unsigned long flags; |
| 1361 | unsigned short left, right; |
| 1362 | int change; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | if (ucontrol->value.enumerated.item[0] > 3 || |
| 1365 | ucontrol->value.enumerated.item[1] > 3) |
| 1366 | return -EINVAL; |
| 1367 | left = ucontrol->value.enumerated.item[0] << 6; |
| 1368 | right = ucontrol->value.enumerated.item[1] << 6; |
| 1369 | |
| 1370 | spin_lock_irqsave(&chip->lock, flags); |
| 1371 | |
| 1372 | left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; |
| 1373 | right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; |
| 1374 | change = left != chip->image[CS4231_LEFT_INPUT] || |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1375 | right != chip->image[CS4231_RIGHT_INPUT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | snd_cs4231_out(chip, CS4231_LEFT_INPUT, left); |
| 1377 | snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right); |
| 1378 | |
| 1379 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1380 | |
| 1381 | return change; |
| 1382 | } |
| 1383 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1384 | static int snd_cs4231_info_single(struct snd_kcontrol *kcontrol, |
| 1385 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | { |
| 1387 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1388 | |
| 1389 | uinfo->type = (mask == 1) ? |
| 1390 | SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1391 | uinfo->count = 1; |
| 1392 | uinfo->value.integer.min = 0; |
| 1393 | uinfo->value.integer.max = mask; |
| 1394 | |
| 1395 | return 0; |
| 1396 | } |
| 1397 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1398 | static int snd_cs4231_get_single(struct snd_kcontrol *kcontrol, |
| 1399 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1401 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | unsigned long flags; |
| 1403 | int reg = kcontrol->private_value & 0xff; |
| 1404 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1405 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1406 | int invert = (kcontrol->private_value >> 24) & 0xff; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | spin_lock_irqsave(&chip->lock, flags); |
| 1409 | |
| 1410 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; |
| 1411 | |
| 1412 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1413 | |
| 1414 | if (invert) |
| 1415 | ucontrol->value.integer.value[0] = |
| 1416 | (mask - ucontrol->value.integer.value[0]); |
| 1417 | |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1421 | static int snd_cs4231_put_single(struct snd_kcontrol *kcontrol, |
| 1422 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1424 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | unsigned long flags; |
| 1426 | int reg = kcontrol->private_value & 0xff; |
| 1427 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1428 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1429 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1430 | int change; |
| 1431 | unsigned short val; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | val = (ucontrol->value.integer.value[0] & mask); |
| 1434 | if (invert) |
| 1435 | val = mask - val; |
| 1436 | val <<= shift; |
| 1437 | |
| 1438 | spin_lock_irqsave(&chip->lock, flags); |
| 1439 | |
| 1440 | val = (chip->image[reg] & ~(mask << shift)) | val; |
| 1441 | change = val != chip->image[reg]; |
| 1442 | snd_cs4231_out(chip, reg, val); |
| 1443 | |
| 1444 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1445 | |
| 1446 | return change; |
| 1447 | } |
| 1448 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1449 | static int snd_cs4231_info_double(struct snd_kcontrol *kcontrol, |
| 1450 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
| 1452 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1453 | |
| 1454 | uinfo->type = mask == 1 ? |
| 1455 | SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1456 | uinfo->count = 2; |
| 1457 | uinfo->value.integer.min = 0; |
| 1458 | uinfo->value.integer.max = mask; |
| 1459 | |
| 1460 | return 0; |
| 1461 | } |
| 1462 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1463 | static int snd_cs4231_get_double(struct snd_kcontrol *kcontrol, |
| 1464 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1466 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | unsigned long flags; |
| 1468 | int left_reg = kcontrol->private_value & 0xff; |
| 1469 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1470 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1471 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1472 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1473 | int invert = (kcontrol->private_value >> 22) & 1; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | spin_lock_irqsave(&chip->lock, flags); |
| 1476 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1477 | ucontrol->value.integer.value[0] = |
| 1478 | (chip->image[left_reg] >> shift_left) & mask; |
| 1479 | ucontrol->value.integer.value[1] = |
| 1480 | (chip->image[right_reg] >> shift_right) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | |
| 1482 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1483 | |
| 1484 | if (invert) { |
| 1485 | ucontrol->value.integer.value[0] = |
| 1486 | (mask - ucontrol->value.integer.value[0]); |
| 1487 | ucontrol->value.integer.value[1] = |
| 1488 | (mask - ucontrol->value.integer.value[1]); |
| 1489 | } |
| 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1494 | static int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, |
| 1495 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1497 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | unsigned long flags; |
| 1499 | int left_reg = kcontrol->private_value & 0xff; |
| 1500 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1501 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1502 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1503 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1504 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1505 | int change; |
| 1506 | unsigned short val1, val2; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1509 | val2 = ucontrol->value.integer.value[1] & mask; |
| 1510 | if (invert) { |
| 1511 | val1 = mask - val1; |
| 1512 | val2 = mask - val2; |
| 1513 | } |
| 1514 | val1 <<= shift_left; |
| 1515 | val2 <<= shift_right; |
| 1516 | |
| 1517 | spin_lock_irqsave(&chip->lock, flags); |
| 1518 | |
| 1519 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
| 1520 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1521 | change = val1 != chip->image[left_reg]; |
| 1522 | change |= val2 != chip->image[right_reg]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | snd_cs4231_out(chip, left_reg, val1); |
| 1524 | snd_cs4231_out(chip, right_reg, val2); |
| 1525 | |
| 1526 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1527 | |
| 1528 | return change; |
| 1529 | } |
| 1530 | |
| 1531 | #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1532 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
| 1533 | .info = snd_cs4231_info_single, \ |
| 1534 | .get = snd_cs4231_get_single, .put = snd_cs4231_put_single, \ |
| 1535 | .private_value = (reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1537 | #define CS4231_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, \ |
| 1538 | shift_right, mask, invert) \ |
| 1539 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
| 1540 | .info = snd_cs4231_info_double, \ |
| 1541 | .get = snd_cs4231_get_double, .put = snd_cs4231_put_double, \ |
| 1542 | .private_value = (left_reg) | ((right_reg) << 8) | ((shift_left) << 16) | \ |
| 1543 | ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1545 | static struct snd_kcontrol_new snd_cs4231_controls[] __initdata = { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1546 | CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, |
| 1547 | CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 1548 | CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, |
| 1549 | CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
| 1550 | CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, |
| 1551 | CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 1552 | CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, |
| 1553 | CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
| 1554 | CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, |
| 1555 | CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 1556 | CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, |
| 1557 | CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), |
| 1558 | CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, |
| 1559 | CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 1560 | CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, |
| 1561 | CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1), |
| 1563 | CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), |
| 1564 | CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1), |
| 1565 | CS4231_SINGLE("Mono Output Playback Bypass", 0, CS4231_MONO_CTRL, 5, 1, 0), |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1566 | CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, |
| 1567 | 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | { |
| 1569 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1570 | .name = "Capture Source", |
| 1571 | .info = snd_cs4231_info_mux, |
| 1572 | .get = snd_cs4231_get_mux, |
| 1573 | .put = snd_cs4231_put_mux, |
| 1574 | }, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1575 | CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, |
| 1576 | 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), |
| 1578 | CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1), |
| 1579 | /* SPARC specific uses of XCTL{0,1} general purpose outputs. */ |
| 1580 | CS4231_SINGLE("Line Out Switch", 0, CS4231_PIN_CTRL, 6, 1, 1), |
| 1581 | CS4231_SINGLE("Headphone Out Switch", 0, CS4231_PIN_CTRL, 7, 1, 1) |
| 1582 | }; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1583 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1584 | static int __init snd_cs4231_mixer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1586 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | int err, idx; |
| 1588 | |
| 1589 | snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL); |
| 1590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | strcpy(card->mixername, chip->pcm->name); |
| 1592 | |
| 1593 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1594 | err = snd_ctl_add(card, |
| 1595 | snd_ctl_new1(&snd_cs4231_controls[idx], chip)); |
| 1596 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | return err; |
| 1598 | } |
| 1599 | return 0; |
| 1600 | } |
| 1601 | |
| 1602 | static int dev; |
| 1603 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1604 | static int __init cs4231_attach_begin(struct snd_card **rcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1606 | struct snd_card *card; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1607 | struct snd_cs4231 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | |
| 1609 | *rcard = NULL; |
| 1610 | |
| 1611 | if (dev >= SNDRV_CARDS) |
| 1612 | return -ENODEV; |
| 1613 | |
| 1614 | if (!enable[dev]) { |
| 1615 | dev++; |
| 1616 | return -ENOENT; |
| 1617 | } |
| 1618 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1619 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 1620 | sizeof(struct snd_cs4231)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | if (card == NULL) |
| 1622 | return -ENOMEM; |
| 1623 | |
| 1624 | strcpy(card->driver, "CS4231"); |
| 1625 | strcpy(card->shortname, "Sun CS4231"); |
| 1626 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1627 | chip = card->private_data; |
| 1628 | chip->card = card; |
| 1629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | *rcard = card; |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1634 | static int __init cs4231_attach_finish(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1636 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | int err; |
| 1638 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1639 | err = snd_cs4231_pcm(card); |
| 1640 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | goto out_err; |
| 1642 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1643 | err = snd_cs4231_mixer(card); |
| 1644 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | goto out_err; |
| 1646 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1647 | err = snd_cs4231_timer(card); |
| 1648 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | goto out_err; |
| 1650 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1651 | err = snd_card_register(card); |
| 1652 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | goto out_err; |
| 1654 | |
| 1655 | chip->next = cs4231_list; |
| 1656 | cs4231_list = chip; |
| 1657 | |
| 1658 | dev++; |
| 1659 | return 0; |
| 1660 | |
| 1661 | out_err: |
| 1662 | snd_card_free(card); |
| 1663 | return err; |
| 1664 | } |
| 1665 | |
| 1666 | #ifdef SBUS_SUPPORT |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1667 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1668 | static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1669 | { |
| 1670 | unsigned long flags; |
| 1671 | unsigned char status; |
| 1672 | u32 csr; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1673 | struct snd_cs4231 *chip = dev_id; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1674 | |
| 1675 | /*This is IRQ is not raised by the cs4231*/ |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame^] | 1676 | if (!(__cs4231_readb(chip, CS4231U(chip, STATUS)) & CS4231_GLOBALIRQ)) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1677 | return IRQ_NONE; |
| 1678 | |
| 1679 | /* ACK the APC interrupt. */ |
| 1680 | csr = sbus_readl(chip->port + APCCSR); |
| 1681 | |
| 1682 | sbus_writel(csr, chip->port + APCCSR); |
| 1683 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1684 | if ((csr & APC_PDMA_READY) && |
| 1685 | (csr & APC_PLAY_INT) && |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1686 | (csr & APC_XINT_PNVA) && |
| 1687 | !(csr & APC_XINT_EMPT)) |
| 1688 | snd_cs4231_play_callback(chip); |
| 1689 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1690 | if ((csr & APC_CDMA_READY) && |
| 1691 | (csr & APC_CAPT_INT) && |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1692 | (csr & APC_XINT_CNVA) && |
| 1693 | !(csr & APC_XINT_EMPT)) |
| 1694 | snd_cs4231_capture_callback(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1695 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1696 | status = snd_cs4231_in(chip, CS4231_IRQ_STATUS); |
| 1697 | |
| 1698 | if (status & CS4231_TIMER_IRQ) { |
| 1699 | if (chip->timer) |
| 1700 | snd_timer_interrupt(chip->timer, chip->timer->sticks); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1701 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1702 | |
| 1703 | if ((status & CS4231_RECORD_IRQ) && (csr & APC_CDMA_READY)) |
| 1704 | snd_cs4231_overrange(chip); |
| 1705 | |
| 1706 | /* ACK the CS4231 interrupt. */ |
| 1707 | spin_lock_irqsave(&chip->lock, flags); |
| 1708 | snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0); |
| 1709 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1710 | |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1711 | return IRQ_HANDLED; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /* |
| 1715 | * SBUS DMA routines |
| 1716 | */ |
| 1717 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1718 | static int sbus_dma_request(struct cs4231_dma_control *dma_cont, |
| 1719 | dma_addr_t bus_addr, size_t len) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1720 | { |
| 1721 | unsigned long flags; |
| 1722 | u32 test, csr; |
| 1723 | int err; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1724 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1725 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1726 | if (len >= (1 << 24)) |
| 1727 | return -EINVAL; |
| 1728 | spin_lock_irqsave(&base->lock, flags); |
| 1729 | csr = sbus_readl(base->regs + APCCSR); |
| 1730 | err = -EINVAL; |
| 1731 | test = APC_CDMA_READY; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1732 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1733 | test = APC_PDMA_READY; |
| 1734 | if (!(csr & test)) |
| 1735 | goto out; |
| 1736 | err = -EBUSY; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1737 | test = APC_XINT_CNVA; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1738 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1739 | test = APC_XINT_PNVA; |
| 1740 | if (!(csr & test)) |
| 1741 | goto out; |
| 1742 | err = 0; |
| 1743 | sbus_writel(bus_addr, base->regs + base->dir + APCNVA); |
| 1744 | sbus_writel(len, base->regs + base->dir + APCNC); |
| 1745 | out: |
| 1746 | spin_unlock_irqrestore(&base->lock, flags); |
| 1747 | return err; |
| 1748 | } |
| 1749 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1750 | static void sbus_dma_prepare(struct cs4231_dma_control *dma_cont, int d) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1751 | { |
| 1752 | unsigned long flags; |
| 1753 | u32 csr, test; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1754 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1755 | |
| 1756 | spin_lock_irqsave(&base->lock, flags); |
| 1757 | csr = sbus_readl(base->regs + APCCSR); |
| 1758 | test = APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA | |
| 1759 | APC_XINT_PLAY | APC_XINT_PEMP | APC_XINT_GENL | |
| 1760 | APC_XINT_PENA; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1761 | if (base->dir == APC_RECORD) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1762 | test = APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA | |
| 1763 | APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL; |
| 1764 | csr |= test; |
| 1765 | sbus_writel(csr, base->regs + APCCSR); |
| 1766 | spin_unlock_irqrestore(&base->lock, flags); |
| 1767 | } |
| 1768 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1769 | static void sbus_dma_enable(struct cs4231_dma_control *dma_cont, int on) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1770 | { |
| 1771 | unsigned long flags; |
| 1772 | u32 csr, shift; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1773 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1774 | |
| 1775 | spin_lock_irqsave(&base->lock, flags); |
| 1776 | if (!on) { |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1777 | sbus_writel(0, base->regs + base->dir + APCNC); |
| 1778 | sbus_writel(0, base->regs + base->dir + APCNVA); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1779 | if (base->dir == APC_PLAY) { |
Georg Chini | 3daadf3 | 2007-08-01 21:55:58 -0700 | [diff] [blame] | 1780 | sbus_writel(0, base->regs + base->dir + APCC); |
| 1781 | sbus_writel(0, base->regs + base->dir + APCVA); |
| 1782 | } |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1783 | |
Georg Chini | 3daadf3 | 2007-08-01 21:55:58 -0700 | [diff] [blame] | 1784 | udelay(1200); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1785 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1786 | csr = sbus_readl(base->regs + APCCSR); |
| 1787 | shift = 0; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1788 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1789 | shift = 1; |
| 1790 | if (on) |
| 1791 | csr &= ~(APC_CPAUSE << shift); |
| 1792 | else |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1793 | csr |= (APC_CPAUSE << shift); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1794 | sbus_writel(csr, base->regs + APCCSR); |
| 1795 | if (on) |
| 1796 | csr |= (APC_CDMA_READY << shift); |
| 1797 | else |
| 1798 | csr &= ~(APC_CDMA_READY << shift); |
| 1799 | sbus_writel(csr, base->regs + APCCSR); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1800 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1801 | spin_unlock_irqrestore(&base->lock, flags); |
| 1802 | } |
| 1803 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1804 | static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1805 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1806 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1807 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1808 | return sbus_readl(base->regs + base->dir + APCVA); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1809 | } |
| 1810 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1811 | static void sbus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1812 | { |
| 1813 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1814 | snd_dma_sbus_data(chip->dev_u.sdev), |
| 1815 | 64 * 1024, 128 * 1024); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | /* |
| 1819 | * Init and exit routines |
| 1820 | */ |
| 1821 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1822 | static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
| 1824 | if (chip->irq[0]) |
| 1825 | free_irq(chip->irq[0], chip); |
| 1826 | |
| 1827 | if (chip->port) |
| 1828 | sbus_iounmap(chip->port, chip->regs_size); |
| 1829 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | return 0; |
| 1831 | } |
| 1832 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1833 | static int snd_cs4231_sbus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1835 | struct snd_cs4231 *cp = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
| 1837 | return snd_cs4231_sbus_free(cp); |
| 1838 | } |
| 1839 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1840 | static struct snd_device_ops snd_cs4231_sbus_dev_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | .dev_free = snd_cs4231_sbus_dev_free, |
| 1842 | }; |
| 1843 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1844 | static int __init snd_cs4231_sbus_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | struct sbus_dev *sdev, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1846 | int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1848 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | int err; |
| 1850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | spin_lock_init(&chip->lock); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1852 | spin_lock_init(&chip->c_dma.sbus_info.lock); |
| 1853 | spin_lock_init(&chip->p_dma.sbus_info.lock); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 1854 | mutex_init(&chip->mce_mutex); |
| 1855 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | chip->dev_u.sdev = sdev; |
| 1857 | chip->regs_size = sdev->reg_addrs[0].reg_size; |
| 1858 | memcpy(&chip->image, &snd_cs4231_original_image, |
| 1859 | sizeof(snd_cs4231_original_image)); |
| 1860 | |
| 1861 | chip->port = sbus_ioremap(&sdev->resource[0], 0, |
| 1862 | chip->regs_size, "cs4231"); |
| 1863 | if (!chip->port) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 1864 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | return -EIO; |
| 1866 | } |
| 1867 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1868 | chip->c_dma.sbus_info.regs = chip->port; |
| 1869 | chip->p_dma.sbus_info.regs = chip->port; |
| 1870 | chip->c_dma.sbus_info.dir = APC_RECORD; |
| 1871 | chip->p_dma.sbus_info.dir = APC_PLAY; |
| 1872 | |
| 1873 | chip->p_dma.prepare = sbus_dma_prepare; |
| 1874 | chip->p_dma.enable = sbus_dma_enable; |
| 1875 | chip->p_dma.request = sbus_dma_request; |
| 1876 | chip->p_dma.address = sbus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1877 | chip->p_dma.preallocate = sbus_dma_preallocate; |
| 1878 | |
| 1879 | chip->c_dma.prepare = sbus_dma_prepare; |
| 1880 | chip->c_dma.enable = sbus_dma_enable; |
| 1881 | chip->c_dma.request = sbus_dma_request; |
| 1882 | chip->c_dma.address = sbus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1883 | chip->c_dma.preallocate = sbus_dma_preallocate; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | if (request_irq(sdev->irqs[0], snd_cs4231_sbus_interrupt, |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 1886 | IRQF_SHARED, "cs4231", chip)) { |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 1887 | snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %d\n", |
| 1888 | dev, sdev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | snd_cs4231_sbus_free(chip); |
| 1890 | return -EBUSY; |
| 1891 | } |
| 1892 | chip->irq[0] = sdev->irqs[0]; |
| 1893 | |
| 1894 | if (snd_cs4231_probe(chip) < 0) { |
| 1895 | snd_cs4231_sbus_free(chip); |
| 1896 | return -ENODEV; |
| 1897 | } |
| 1898 | snd_cs4231_init(chip); |
| 1899 | |
| 1900 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
| 1901 | chip, &snd_cs4231_sbus_dev_ops)) < 0) { |
| 1902 | snd_cs4231_sbus_free(chip); |
| 1903 | return err; |
| 1904 | } |
| 1905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | return 0; |
| 1907 | } |
| 1908 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1909 | static int __init cs4231_sbus_attach(struct sbus_dev *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | { |
| 1911 | struct resource *rp = &sdev->resource[0]; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1912 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | int err; |
| 1914 | |
| 1915 | err = cs4231_attach_begin(&card); |
| 1916 | if (err) |
| 1917 | return err; |
| 1918 | |
Andrew Morton | 5863aa6 | 2006-07-03 00:24:22 -0700 | [diff] [blame] | 1919 | sprintf(card->longname, "%s at 0x%02lx:0x%016Lx, irq %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | card->shortname, |
| 1921 | rp->flags & 0xffL, |
Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 1922 | (unsigned long long)rp->start, |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 1923 | sdev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1925 | err = snd_cs4231_sbus_create(card, sdev, dev); |
| 1926 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | snd_card_free(card); |
| 1928 | return err; |
| 1929 | } |
| 1930 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1931 | return cs4231_attach_finish(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | } |
| 1933 | #endif |
| 1934 | |
| 1935 | #ifdef EBUS_SUPPORT |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1936 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1937 | static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, |
| 1938 | void *cookie) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1939 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1940 | struct snd_cs4231 *chip = cookie; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1941 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1942 | snd_cs4231_play_callback(chip); |
| 1943 | } |
| 1944 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1945 | static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, |
| 1946 | int event, void *cookie) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1947 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1948 | struct snd_cs4231 *chip = cookie; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1949 | |
| 1950 | snd_cs4231_capture_callback(chip); |
| 1951 | } |
| 1952 | |
| 1953 | /* |
| 1954 | * EBUS DMA wrappers |
| 1955 | */ |
| 1956 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1957 | static int _ebus_dma_request(struct cs4231_dma_control *dma_cont, |
| 1958 | dma_addr_t bus_addr, size_t len) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1959 | { |
| 1960 | return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len); |
| 1961 | } |
| 1962 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1963 | static void _ebus_dma_enable(struct cs4231_dma_control *dma_cont, int on) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1964 | { |
| 1965 | ebus_dma_enable(&dma_cont->ebus_info, on); |
| 1966 | } |
| 1967 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1968 | static void _ebus_dma_prepare(struct cs4231_dma_control *dma_cont, int dir) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1969 | { |
| 1970 | ebus_dma_prepare(&dma_cont->ebus_info, dir); |
| 1971 | } |
| 1972 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1973 | static unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1974 | { |
| 1975 | return ebus_dma_addr(&dma_cont->ebus_info); |
| 1976 | } |
| 1977 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1978 | static void _ebus_dma_preallocate(struct snd_cs4231 *chip, struct snd_pcm *pcm) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1979 | { |
| 1980 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1981 | snd_dma_pci_data(chip->dev_u.pdev), |
| 1982 | 64*1024, 128*1024); |
| 1983 | } |
| 1984 | |
| 1985 | /* |
| 1986 | * Init and exit routines |
| 1987 | */ |
| 1988 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1989 | static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1991 | if (chip->c_dma.ebus_info.regs) { |
| 1992 | ebus_dma_unregister(&chip->c_dma.ebus_info); |
| 1993 | iounmap(chip->c_dma.ebus_info.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1995 | if (chip->p_dma.ebus_info.regs) { |
| 1996 | ebus_dma_unregister(&chip->p_dma.ebus_info); |
| 1997 | iounmap(chip->p_dma.ebus_info.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | if (chip->port) |
| 2001 | iounmap(chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | return 0; |
| 2004 | } |
| 2005 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2006 | static int snd_cs4231_ebus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2008 | struct snd_cs4231 *cp = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | |
| 2010 | return snd_cs4231_ebus_free(cp); |
| 2011 | } |
| 2012 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2013 | static struct snd_device_ops snd_cs4231_ebus_dev_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | .dev_free = snd_cs4231_ebus_dev_free, |
| 2015 | }; |
| 2016 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2017 | static int __init snd_cs4231_ebus_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | struct linux_ebus_device *edev, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2019 | int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2021 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | int err; |
| 2023 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | spin_lock_init(&chip->lock); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2025 | spin_lock_init(&chip->c_dma.ebus_info.lock); |
| 2026 | spin_lock_init(&chip->p_dma.ebus_info.lock); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 2027 | mutex_init(&chip->mce_mutex); |
| 2028 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | chip->flags |= CS4231_FLAG_EBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | chip->dev_u.pdev = edev->bus->self; |
| 2031 | memcpy(&chip->image, &snd_cs4231_original_image, |
| 2032 | sizeof(snd_cs4231_original_image)); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2033 | strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); |
| 2034 | chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
| 2035 | chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; |
| 2036 | chip->c_dma.ebus_info.client_cookie = chip; |
| 2037 | chip->c_dma.ebus_info.irq = edev->irqs[0]; |
| 2038 | strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); |
| 2039 | chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
| 2040 | chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; |
| 2041 | chip->p_dma.ebus_info.client_cookie = chip; |
| 2042 | chip->p_dma.ebus_info.irq = edev->irqs[1]; |
| 2043 | |
| 2044 | chip->p_dma.prepare = _ebus_dma_prepare; |
| 2045 | chip->p_dma.enable = _ebus_dma_enable; |
| 2046 | chip->p_dma.request = _ebus_dma_request; |
| 2047 | chip->p_dma.address = _ebus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2048 | chip->p_dma.preallocate = _ebus_dma_preallocate; |
| 2049 | |
| 2050 | chip->c_dma.prepare = _ebus_dma_prepare; |
| 2051 | chip->c_dma.enable = _ebus_dma_enable; |
| 2052 | chip->c_dma.request = _ebus_dma_request; |
| 2053 | chip->c_dma.address = _ebus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2054 | chip->c_dma.preallocate = _ebus_dma_preallocate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
| 2056 | chip->port = ioremap(edev->resource[0].start, 0x10); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2057 | chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); |
| 2058 | chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2059 | if (!chip->port || !chip->p_dma.ebus_info.regs || |
| 2060 | !chip->c_dma.ebus_info.regs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | snd_cs4231_ebus_free(chip); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 2062 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | return -EIO; |
| 2064 | } |
| 2065 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2066 | if (ebus_dma_register(&chip->c_dma.ebus_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2068 | snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", |
| 2069 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | return -EBUSY; |
| 2071 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2072 | if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2074 | snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", |
| 2075 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | return -EBUSY; |
| 2077 | } |
| 2078 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2079 | if (ebus_dma_register(&chip->p_dma.ebus_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2081 | snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", |
| 2082 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2083 | return -EBUSY; |
| 2084 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2085 | if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | snd_cs4231_ebus_free(chip); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 2087 | snd_printdd("cs4231-%d: Unable to enable EBUS play IRQ\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | return -EBUSY; |
| 2089 | } |
| 2090 | |
| 2091 | if (snd_cs4231_probe(chip) < 0) { |
| 2092 | snd_cs4231_ebus_free(chip); |
| 2093 | return -ENODEV; |
| 2094 | } |
| 2095 | snd_cs4231_init(chip); |
| 2096 | |
| 2097 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
| 2098 | chip, &snd_cs4231_ebus_dev_ops)) < 0) { |
| 2099 | snd_cs4231_ebus_free(chip); |
| 2100 | return err; |
| 2101 | } |
| 2102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | return 0; |
| 2104 | } |
| 2105 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2106 | static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2108 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | int err; |
| 2110 | |
| 2111 | err = cs4231_attach_begin(&card); |
| 2112 | if (err) |
| 2113 | return err; |
| 2114 | |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 2115 | sprintf(card->longname, "%s at 0x%lx, irq %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | card->shortname, |
| 2117 | edev->resource[0].start, |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 2118 | edev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2120 | err = snd_cs4231_ebus_create(card, edev, dev); |
| 2121 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | snd_card_free(card); |
| 2123 | return err; |
| 2124 | } |
| 2125 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2126 | return cs4231_attach_finish(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | } |
| 2128 | #endif |
| 2129 | |
| 2130 | static int __init cs4231_init(void) |
| 2131 | { |
| 2132 | #ifdef SBUS_SUPPORT |
| 2133 | struct sbus_bus *sbus; |
| 2134 | struct sbus_dev *sdev; |
| 2135 | #endif |
| 2136 | #ifdef EBUS_SUPPORT |
| 2137 | struct linux_ebus *ebus; |
| 2138 | struct linux_ebus_device *edev; |
| 2139 | #endif |
| 2140 | int found; |
| 2141 | |
| 2142 | found = 0; |
| 2143 | |
| 2144 | #ifdef SBUS_SUPPORT |
| 2145 | for_all_sbusdev(sdev, sbus) { |
| 2146 | if (!strcmp(sdev->prom_name, "SUNW,CS4231")) { |
| 2147 | if (cs4231_sbus_attach(sdev) == 0) |
| 2148 | found++; |
| 2149 | } |
| 2150 | } |
| 2151 | #endif |
| 2152 | #ifdef EBUS_SUPPORT |
| 2153 | for_each_ebus(ebus) { |
| 2154 | for_each_ebusdev(edev, ebus) { |
| 2155 | int match = 0; |
| 2156 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2157 | if (!strcmp(edev->prom_node->name, "SUNW,CS4231")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | match = 1; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2159 | } else if (!strcmp(edev->prom_node->name, "audio")) { |
Stephen Rothwell | 3198514 | 2007-03-29 00:50:57 -0700 | [diff] [blame] | 2160 | const char *compat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2162 | compat = of_get_property(edev->prom_node, |
| 2163 | "compatible", NULL); |
| 2164 | if (compat && !strcmp(compat, "SUNW,CS4231")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | match = 1; |
| 2166 | } |
| 2167 | |
| 2168 | if (match && |
| 2169 | cs4231_ebus_attach(edev) == 0) |
| 2170 | found++; |
| 2171 | } |
| 2172 | } |
| 2173 | #endif |
| 2174 | |
| 2175 | |
| 2176 | return (found > 0) ? 0 : -EIO; |
| 2177 | } |
| 2178 | |
| 2179 | static void __exit cs4231_exit(void) |
| 2180 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2181 | struct snd_cs4231 *p = cs4231_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | |
| 2183 | while (p != NULL) { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2184 | struct snd_cs4231 *next = p->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | |
| 2186 | snd_card_free(p->card); |
| 2187 | |
| 2188 | p = next; |
| 2189 | } |
| 2190 | |
| 2191 | cs4231_list = NULL; |
| 2192 | } |
| 2193 | |
| 2194 | module_init(cs4231_init); |
| 2195 | module_exit(cs4231_exit); |