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; |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 404 | unsigned long end_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | int timeout; |
| 406 | |
| 407 | spin_lock_irqsave(&chip->lock, flags); |
| 408 | snd_cs4231_busy_wait(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | #ifdef CONFIG_SND_DEBUG |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 410 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
| 411 | snd_printdd("mce_down [%p] - auto calibration time out (0)\n", |
| 412 | CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | #endif |
| 414 | chip->mce_bit &= ~CS4231_MCE; |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 415 | timeout = __cs4231_readb(chip, CS4231U(chip, REGSEL)); |
| 416 | __cs4231_writeb(chip, chip->mce_bit | (timeout & 0x1f), |
| 417 | CS4231U(chip, REGSEL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | if (timeout == 0x80) |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 419 | snd_printdd("mce_down [%p]: serious init problem - " |
| 420 | "codec still busy\n", |
| 421 | chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | if ((timeout & CS4231_MCE) == 0) { |
| 423 | spin_unlock_irqrestore(&chip->lock, flags); |
| 424 | return; |
| 425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Krzysztof Helt | 56f9158 | 2007-09-11 00:55:46 +0200 | [diff] [blame] | 427 | /* |
| 428 | * Wait for (possible -- during init auto-calibration may not be set) |
| 429 | * calibration process to start. Needs upto 5 sample periods on AD1848 |
| 430 | * which at the slowest possible rate of 5.5125 kHz means 907 us. |
| 431 | */ |
| 432 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Krzysztof Helt | 56f9158 | 2007-09-11 00:55:46 +0200 | [diff] [blame] | 434 | /* check condition up to 250ms */ |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 435 | end_time = jiffies + msecs_to_jiffies(250); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 436 | while (snd_cs4231_in(chip, CS4231_TEST_INIT) & |
| 437 | CS4231_CALIB_IN_PROGRESS) { |
| 438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | spin_unlock_irqrestore(&chip->lock, flags); |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 440 | if (time_after(jiffies, end_time)) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 441 | snd_printk("mce_down - " |
| 442 | "auto calibration time out (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | return; |
| 444 | } |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 445 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | spin_lock_irqsave(&chip->lock, flags); |
| 447 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 448 | |
Krzysztof Helt | 56f9158 | 2007-09-11 00:55:46 +0200 | [diff] [blame] | 449 | /* check condition up to 100ms */ |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 450 | end_time = jiffies + msecs_to_jiffies(100); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 451 | while (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | spin_unlock_irqrestore(&chip->lock, flags); |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 453 | if (time_after(jiffies, end_time)) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 454 | snd_printk("mce_down - " |
| 455 | "auto calibration time out (3)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | return; |
| 457 | } |
Takashi Iwai | b875d65 | 2007-09-11 10:12:14 +0200 | [diff] [blame] | 458 | msleep(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | spin_lock_irqsave(&chip->lock, flags); |
| 460 | } |
| 461 | spin_unlock_irqrestore(&chip->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 464 | static void snd_cs4231_advance_dma(struct cs4231_dma_control *dma_cont, |
| 465 | struct snd_pcm_substream *substream, |
| 466 | unsigned int *periods_sent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 468 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | while (1) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 471 | unsigned int period_size = snd_pcm_lib_period_bytes(substream); |
| 472 | unsigned int offset = period_size * (*periods_sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Eric Sesterhenn | 817dd6e | 2006-03-24 18:49:12 +0100 | [diff] [blame] | 474 | BUG_ON(period_size >= (1 << 24)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 476 | if (dma_cont->request(dma_cont, |
| 477 | runtime->dma_addr + offset, period_size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | (*periods_sent) = ((*periods_sent) + 1) % runtime->periods; |
| 480 | } |
| 481 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 482 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 483 | static void cs4231_dma_trigger(struct snd_pcm_substream *substream, |
| 484 | unsigned int what, int on) |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 485 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 486 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 487 | struct cs4231_dma_control *dma_cont; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 488 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 489 | if (what & CS4231_PLAYBACK_ENABLE) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 490 | dma_cont = &chip->p_dma; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 491 | if (on) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 492 | dma_cont->prepare(dma_cont, 0); |
| 493 | dma_cont->enable(dma_cont, 1); |
| 494 | snd_cs4231_advance_dma(dma_cont, |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 495 | chip->playback_substream, |
| 496 | &chip->p_periods_sent); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 497 | } else { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 498 | dma_cont->enable(dma_cont, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 499 | } |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 500 | } |
| 501 | if (what & CS4231_RECORD_ENABLE) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 502 | dma_cont = &chip->c_dma; |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 503 | if (on) { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 504 | dma_cont->prepare(dma_cont, 1); |
| 505 | dma_cont->enable(dma_cont, 1); |
| 506 | snd_cs4231_advance_dma(dma_cont, |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 507 | chip->capture_substream, |
| 508 | &chip->c_periods_sent); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 509 | } else { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 510 | dma_cont->enable(dma_cont, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 511 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 515 | static int snd_cs4231_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 517 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | int result = 0; |
| 519 | |
| 520 | switch (cmd) { |
| 521 | case SNDRV_PCM_TRIGGER_START: |
| 522 | case SNDRV_PCM_TRIGGER_STOP: |
| 523 | { |
| 524 | unsigned int what = 0; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 525 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | unsigned long flags; |
| 527 | |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 528 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | if (s == chip->playback_substream) { |
| 530 | what |= CS4231_PLAYBACK_ENABLE; |
| 531 | snd_pcm_trigger_done(s, substream); |
| 532 | } else if (s == chip->capture_substream) { |
| 533 | what |= CS4231_RECORD_ENABLE; |
| 534 | snd_pcm_trigger_done(s, substream); |
| 535 | } |
| 536 | } |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | spin_lock_irqsave(&chip->lock, flags); |
| 539 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 540 | cs4231_dma_trigger(substream, what, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | chip->image[CS4231_IFACE_CTRL] |= what; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } else { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 543 | cs4231_dma_trigger(substream, what, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | chip->image[CS4231_IFACE_CTRL] &= ~what; |
| 545 | } |
| 546 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, |
| 547 | chip->image[CS4231_IFACE_CTRL]); |
| 548 | spin_unlock_irqrestore(&chip->lock, flags); |
| 549 | break; |
| 550 | } |
| 551 | default: |
| 552 | result = -EINVAL; |
| 553 | break; |
| 554 | } |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return result; |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * CODEC I/O |
| 561 | */ |
| 562 | |
| 563 | static unsigned char snd_cs4231_get_rate(unsigned int rate) |
| 564 | { |
| 565 | int i; |
| 566 | |
| 567 | for (i = 0; i < 14; i++) |
| 568 | if (rate == rates[i]) |
| 569 | return freq_bits[i]; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | return freq_bits[13]; |
| 572 | } |
| 573 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 574 | static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip, int format, |
| 575 | int channels) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
| 577 | unsigned char rformat; |
| 578 | |
| 579 | rformat = CS4231_LINEAR_8; |
| 580 | switch (format) { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 581 | case SNDRV_PCM_FORMAT_MU_LAW: |
| 582 | rformat = CS4231_ULAW_8; |
| 583 | break; |
| 584 | case SNDRV_PCM_FORMAT_A_LAW: |
| 585 | rformat = CS4231_ALAW_8; |
| 586 | break; |
| 587 | case SNDRV_PCM_FORMAT_S16_LE: |
| 588 | rformat = CS4231_LINEAR_16; |
| 589 | break; |
| 590 | case SNDRV_PCM_FORMAT_S16_BE: |
| 591 | rformat = CS4231_LINEAR_16_BIG; |
| 592 | break; |
| 593 | case SNDRV_PCM_FORMAT_IMA_ADPCM: |
| 594 | rformat = CS4231_ADPCM_16; |
| 595 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | } |
| 597 | if (channels > 1) |
| 598 | rformat |= CS4231_STEREO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | return rformat; |
| 600 | } |
| 601 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 602 | static void snd_cs4231_calibrate_mute(struct snd_cs4231 *chip, int mute) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
| 604 | unsigned long flags; |
| 605 | |
| 606 | mute = mute ? 1 : 0; |
| 607 | spin_lock_irqsave(&chip->lock, flags); |
| 608 | if (chip->calibrate_mute == mute) { |
| 609 | spin_unlock_irqrestore(&chip->lock, flags); |
| 610 | return; |
| 611 | } |
| 612 | if (!mute) { |
| 613 | snd_cs4231_dout(chip, CS4231_LEFT_INPUT, |
| 614 | chip->image[CS4231_LEFT_INPUT]); |
| 615 | snd_cs4231_dout(chip, CS4231_RIGHT_INPUT, |
| 616 | chip->image[CS4231_RIGHT_INPUT]); |
| 617 | snd_cs4231_dout(chip, CS4231_LOOPBACK, |
| 618 | chip->image[CS4231_LOOPBACK]); |
| 619 | } |
| 620 | snd_cs4231_dout(chip, CS4231_AUX1_LEFT_INPUT, |
| 621 | mute ? 0x80 : chip->image[CS4231_AUX1_LEFT_INPUT]); |
| 622 | snd_cs4231_dout(chip, CS4231_AUX1_RIGHT_INPUT, |
| 623 | mute ? 0x80 : chip->image[CS4231_AUX1_RIGHT_INPUT]); |
| 624 | snd_cs4231_dout(chip, CS4231_AUX2_LEFT_INPUT, |
| 625 | mute ? 0x80 : chip->image[CS4231_AUX2_LEFT_INPUT]); |
| 626 | snd_cs4231_dout(chip, CS4231_AUX2_RIGHT_INPUT, |
| 627 | mute ? 0x80 : chip->image[CS4231_AUX2_RIGHT_INPUT]); |
| 628 | snd_cs4231_dout(chip, CS4231_LEFT_OUTPUT, |
| 629 | mute ? 0x80 : chip->image[CS4231_LEFT_OUTPUT]); |
| 630 | snd_cs4231_dout(chip, CS4231_RIGHT_OUTPUT, |
| 631 | mute ? 0x80 : chip->image[CS4231_RIGHT_OUTPUT]); |
| 632 | snd_cs4231_dout(chip, CS4231_LEFT_LINE_IN, |
| 633 | mute ? 0x80 : chip->image[CS4231_LEFT_LINE_IN]); |
| 634 | snd_cs4231_dout(chip, CS4231_RIGHT_LINE_IN, |
| 635 | mute ? 0x80 : chip->image[CS4231_RIGHT_LINE_IN]); |
| 636 | snd_cs4231_dout(chip, CS4231_MONO_CTRL, |
| 637 | mute ? 0xc0 : chip->image[CS4231_MONO_CTRL]); |
| 638 | chip->calibrate_mute = mute; |
| 639 | spin_unlock_irqrestore(&chip->lock, flags); |
| 640 | } |
| 641 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 642 | static void snd_cs4231_playback_format(struct snd_cs4231 *chip, |
| 643 | struct snd_pcm_hw_params *params, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | unsigned char pdfr) |
| 645 | { |
| 646 | unsigned long flags; |
| 647 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 648 | mutex_lock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | snd_cs4231_calibrate_mute(chip, 1); |
| 650 | |
| 651 | snd_cs4231_mce_up(chip); |
| 652 | |
| 653 | spin_lock_irqsave(&chip->lock, flags); |
| 654 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 655 | (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) ? |
| 656 | (pdfr & 0xf0) | (chip->image[CS4231_REC_FORMAT] & 0x0f) : |
| 657 | pdfr); |
| 658 | spin_unlock_irqrestore(&chip->lock, flags); |
| 659 | |
| 660 | snd_cs4231_mce_down(chip); |
| 661 | |
| 662 | snd_cs4231_calibrate_mute(chip, 0); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 663 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 666 | static void snd_cs4231_capture_format(struct snd_cs4231 *chip, |
| 667 | struct snd_pcm_hw_params *params, |
| 668 | unsigned char cdfr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
| 670 | unsigned long flags; |
| 671 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 672 | mutex_lock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | snd_cs4231_calibrate_mute(chip, 1); |
| 674 | |
| 675 | snd_cs4231_mce_up(chip); |
| 676 | |
| 677 | spin_lock_irqsave(&chip->lock, flags); |
| 678 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) { |
| 679 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 680 | ((chip->image[CS4231_PLAYBK_FORMAT]) & 0xf0) | |
| 681 | (cdfr & 0x0f)); |
| 682 | spin_unlock_irqrestore(&chip->lock, flags); |
| 683 | snd_cs4231_mce_down(chip); |
| 684 | snd_cs4231_mce_up(chip); |
| 685 | spin_lock_irqsave(&chip->lock, flags); |
| 686 | } |
| 687 | snd_cs4231_out(chip, CS4231_REC_FORMAT, cdfr); |
| 688 | spin_unlock_irqrestore(&chip->lock, flags); |
| 689 | |
| 690 | snd_cs4231_mce_down(chip); |
| 691 | |
| 692 | snd_cs4231_calibrate_mute(chip, 0); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 693 | mutex_unlock(&chip->mce_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | /* |
| 697 | * Timer interface |
| 698 | */ |
| 699 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 700 | static unsigned long snd_cs4231_timer_resolution(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 702 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920; |
| 705 | } |
| 706 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 707 | static int snd_cs4231_timer_start(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | { |
| 709 | unsigned long flags; |
| 710 | unsigned int ticks; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 711 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
| 713 | spin_lock_irqsave(&chip->lock, flags); |
| 714 | ticks = timer->sticks; |
| 715 | if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 || |
| 716 | (unsigned char)(ticks >> 8) != chip->image[CS4231_TIMER_HIGH] || |
| 717 | (unsigned char)ticks != chip->image[CS4231_TIMER_LOW]) { |
| 718 | snd_cs4231_out(chip, CS4231_TIMER_HIGH, |
| 719 | chip->image[CS4231_TIMER_HIGH] = |
| 720 | (unsigned char) (ticks >> 8)); |
| 721 | snd_cs4231_out(chip, CS4231_TIMER_LOW, |
| 722 | chip->image[CS4231_TIMER_LOW] = |
| 723 | (unsigned char) ticks); |
| 724 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 725 | chip->image[CS4231_ALT_FEATURE_1] | |
| 726 | CS4231_TIMER_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | } |
| 728 | spin_unlock_irqrestore(&chip->lock, flags); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 733 | static int snd_cs4231_timer_stop(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | { |
| 735 | unsigned long flags; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 736 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 739 | chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 741 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | spin_unlock_irqrestore(&chip->lock, flags); |
| 743 | |
| 744 | return 0; |
| 745 | } |
| 746 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 747 | static void __init snd_cs4231_init(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
| 749 | unsigned long flags; |
| 750 | |
| 751 | snd_cs4231_mce_down(chip); |
| 752 | |
| 753 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 754 | snd_printdd("init: (1)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | #endif |
| 756 | snd_cs4231_mce_up(chip); |
| 757 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 758 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
| 759 | CS4231_PLAYBACK_PIO | |
| 760 | CS4231_RECORD_ENABLE | |
| 761 | CS4231_RECORD_PIO | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | CS4231_CALIB_MODE); |
| 763 | chip->image[CS4231_IFACE_CTRL] |= CS4231_AUTOCALIB; |
| 764 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]); |
| 765 | spin_unlock_irqrestore(&chip->lock, flags); |
| 766 | snd_cs4231_mce_down(chip); |
| 767 | |
| 768 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 769 | snd_printdd("init: (2)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | #endif |
| 771 | |
| 772 | snd_cs4231_mce_up(chip); |
| 773 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 774 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, |
| 775 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | spin_unlock_irqrestore(&chip->lock, flags); |
| 777 | snd_cs4231_mce_down(chip); |
| 778 | |
| 779 | #ifdef SNDRV_DEBUG_MCE |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 780 | snd_printdd("init: (3) - afei = 0x%x\n", |
| 781 | chip->image[CS4231_ALT_FEATURE_1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | #endif |
| 783 | |
| 784 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 785 | snd_cs4231_out(chip, CS4231_ALT_FEATURE_2, |
| 786 | chip->image[CS4231_ALT_FEATURE_2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | spin_unlock_irqrestore(&chip->lock, flags); |
| 788 | |
| 789 | snd_cs4231_mce_up(chip); |
| 790 | spin_lock_irqsave(&chip->lock, flags); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 791 | snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, |
| 792 | chip->image[CS4231_PLAYBK_FORMAT]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | spin_unlock_irqrestore(&chip->lock, flags); |
| 794 | snd_cs4231_mce_down(chip); |
| 795 | |
| 796 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 797 | snd_printdd("init: (4)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | #endif |
| 799 | |
| 800 | snd_cs4231_mce_up(chip); |
| 801 | spin_lock_irqsave(&chip->lock, flags); |
| 802 | snd_cs4231_out(chip, CS4231_REC_FORMAT, chip->image[CS4231_REC_FORMAT]); |
| 803 | spin_unlock_irqrestore(&chip->lock, flags); |
| 804 | snd_cs4231_mce_down(chip); |
| 805 | |
| 806 | #ifdef SNDRV_DEBUG_MCE |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 807 | snd_printdd("init: (5)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | #endif |
| 809 | } |
| 810 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 811 | static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | { |
| 813 | unsigned long flags; |
| 814 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 815 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | if ((chip->mode & mode)) { |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 817 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return -EAGAIN; |
| 819 | } |
| 820 | if (chip->mode & CS4231_MODE_OPEN) { |
| 821 | chip->mode |= mode; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 822 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return 0; |
| 824 | } |
| 825 | /* ok. now enable and ack CODEC IRQ */ |
| 826 | spin_lock_irqsave(&chip->lock, flags); |
| 827 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | |
| 828 | CS4231_RECORD_IRQ | |
| 829 | CS4231_TIMER_IRQ); |
| 830 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 831 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 832 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, CS4231_PLAYBACK_IRQ | |
| 835 | CS4231_RECORD_IRQ | |
| 836 | CS4231_TIMER_IRQ); |
| 837 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 838 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | spin_unlock_irqrestore(&chip->lock, flags); |
| 840 | |
| 841 | chip->mode = mode; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 842 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | return 0; |
| 844 | } |
| 845 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 846 | static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
| 848 | unsigned long flags; |
| 849 | |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 850 | mutex_lock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | chip->mode &= ~mode; |
| 852 | if (chip->mode & CS4231_MODE_OPEN) { |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 853 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return; |
| 855 | } |
| 856 | snd_cs4231_calibrate_mute(chip, 1); |
| 857 | |
| 858 | /* disable IRQ */ |
| 859 | spin_lock_irqsave(&chip->lock, flags); |
| 860 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 861 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 862 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | /* now disable record & playback */ |
| 865 | |
| 866 | if (chip->image[CS4231_IFACE_CTRL] & |
| 867 | (CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 868 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO)) { |
| 869 | spin_unlock_irqrestore(&chip->lock, flags); |
| 870 | snd_cs4231_mce_up(chip); |
| 871 | spin_lock_irqsave(&chip->lock, flags); |
| 872 | chip->image[CS4231_IFACE_CTRL] &= |
| 873 | ~(CS4231_PLAYBACK_ENABLE | CS4231_PLAYBACK_PIO | |
| 874 | CS4231_RECORD_ENABLE | CS4231_RECORD_PIO); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 875 | snd_cs4231_out(chip, CS4231_IFACE_CTRL, |
| 876 | chip->image[CS4231_IFACE_CTRL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | spin_unlock_irqrestore(&chip->lock, flags); |
| 878 | snd_cs4231_mce_down(chip); |
| 879 | spin_lock_irqsave(&chip->lock, flags); |
| 880 | } |
| 881 | |
| 882 | /* clear IRQ again */ |
| 883 | snd_cs4231_out(chip, CS4231_IRQ_STATUS, 0); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 884 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
| 885 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); /* clear IRQ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | spin_unlock_irqrestore(&chip->lock, flags); |
| 887 | |
| 888 | snd_cs4231_calibrate_mute(chip, 0); |
| 889 | |
| 890 | chip->mode = 0; |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 891 | mutex_unlock(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /* |
| 895 | * timer open/close |
| 896 | */ |
| 897 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 898 | static int snd_cs4231_timer_open(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 900 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | snd_cs4231_open(chip, CS4231_MODE_TIMER); |
| 902 | return 0; |
| 903 | } |
| 904 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 905 | static int snd_cs4231_timer_close(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 907 | struct snd_cs4231 *chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | snd_cs4231_close(chip, CS4231_MODE_TIMER); |
| 909 | return 0; |
| 910 | } |
| 911 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 912 | static struct snd_timer_hardware snd_cs4231_timer_table = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | .flags = SNDRV_TIMER_HW_AUTO, |
| 914 | .resolution = 9945, |
| 915 | .ticks = 65535, |
| 916 | .open = snd_cs4231_timer_open, |
| 917 | .close = snd_cs4231_timer_close, |
| 918 | .c_resolution = snd_cs4231_timer_resolution, |
| 919 | .start = snd_cs4231_timer_start, |
| 920 | .stop = snd_cs4231_timer_stop, |
| 921 | }; |
| 922 | |
| 923 | /* |
| 924 | * ok.. exported functions.. |
| 925 | */ |
| 926 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 927 | static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream, |
| 928 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 930 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | unsigned char new_pdfr; |
| 932 | int err; |
| 933 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 934 | err = snd_pcm_lib_malloc_pages(substream, |
| 935 | params_buffer_bytes(hw_params)); |
| 936 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | return err; |
| 938 | new_pdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
| 939 | params_channels(hw_params)) | |
| 940 | snd_cs4231_get_rate(params_rate(hw_params)); |
| 941 | snd_cs4231_playback_format(chip, hw_params, new_pdfr); |
| 942 | |
| 943 | return 0; |
| 944 | } |
| 945 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 946 | static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 948 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 949 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | unsigned long flags; |
| 951 | |
| 952 | spin_lock_irqsave(&chip->lock, flags); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_PLAYBACK_ENABLE | |
| 955 | CS4231_PLAYBACK_PIO); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 956 | |
Eric Sesterhenn | 817dd6e | 2006-03-24 18:49:12 +0100 | [diff] [blame] | 957 | BUG_ON(runtime->period_size > 0xffff + 1); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 958 | |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 959 | chip->p_periods_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | spin_unlock_irqrestore(&chip->lock, flags); |
| 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 965 | static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream, |
| 966 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 968 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | unsigned char new_cdfr; |
| 970 | int err; |
| 971 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 972 | err = snd_pcm_lib_malloc_pages(substream, |
| 973 | params_buffer_bytes(hw_params)); |
| 974 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | return err; |
| 976 | new_cdfr = snd_cs4231_get_format(chip, params_format(hw_params), |
| 977 | params_channels(hw_params)) | |
| 978 | snd_cs4231_get_rate(params_rate(hw_params)); |
| 979 | snd_cs4231_capture_format(chip, hw_params, new_cdfr); |
| 980 | |
| 981 | return 0; |
| 982 | } |
| 983 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 984 | static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 986 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | unsigned long flags; |
| 988 | |
| 989 | spin_lock_irqsave(&chip->lock, flags); |
| 990 | chip->image[CS4231_IFACE_CTRL] &= ~(CS4231_RECORD_ENABLE | |
| 991 | CS4231_RECORD_PIO); |
| 992 | |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 993 | |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 994 | chip->c_periods_sent = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | spin_unlock_irqrestore(&chip->lock, flags); |
| 996 | |
| 997 | return 0; |
| 998 | } |
| 999 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1000 | static void snd_cs4231_overrange(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | { |
| 1002 | unsigned long flags; |
| 1003 | unsigned char res; |
| 1004 | |
| 1005 | spin_lock_irqsave(&chip->lock, flags); |
| 1006 | res = snd_cs4231_in(chip, CS4231_TEST_INIT); |
| 1007 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1008 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1009 | /* detect overrange only above 0dB; may be user selectable? */ |
| 1010 | if (res & (0x08 | 0x02)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | chip->capture_substream->runtime->overrange++; |
| 1012 | } |
| 1013 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1014 | static void snd_cs4231_play_callback(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | if (chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE) { |
| 1017 | snd_pcm_period_elapsed(chip->playback_substream); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1018 | snd_cs4231_advance_dma(&chip->p_dma, chip->playback_substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | &chip->p_periods_sent); |
| 1020 | } |
| 1021 | } |
| 1022 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1023 | static void snd_cs4231_capture_callback(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1024 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | if (chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE) { |
| 1026 | snd_pcm_period_elapsed(chip->capture_substream); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1027 | snd_cs4231_advance_dma(&chip->c_dma, chip->capture_substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | &chip->c_periods_sent); |
| 1029 | } |
| 1030 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1032 | static snd_pcm_uframes_t snd_cs4231_playback_pointer( |
| 1033 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1035 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1036 | struct cs4231_dma_control *dma_cont = &chip->p_dma; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1037 | size_t ptr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE)) |
| 1040 | return 0; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1041 | ptr = dma_cont->address(dma_cont); |
| 1042 | if (ptr != 0) |
| 1043 | ptr -= substream->runtime->dma_addr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | return bytes_to_frames(substream->runtime, ptr); |
| 1046 | } |
| 1047 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1048 | static snd_pcm_uframes_t snd_cs4231_capture_pointer( |
| 1049 | struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1051 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1052 | struct cs4231_dma_control *dma_cont = &chip->c_dma; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1053 | size_t ptr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1054 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE)) |
| 1056 | return 0; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1057 | ptr = dma_cont->address(dma_cont); |
| 1058 | if (ptr != 0) |
| 1059 | ptr -= substream->runtime->dma_addr; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | return bytes_to_frames(substream->runtime, ptr); |
| 1062 | } |
| 1063 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1064 | static int __init snd_cs4231_probe(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | { |
| 1066 | unsigned long flags; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1067 | int i; |
| 1068 | int id = 0; |
| 1069 | int vers = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | unsigned char *ptr; |
| 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | for (i = 0; i < 50; i++) { |
| 1073 | mb(); |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 1074 | if (__cs4231_readb(chip, CS4231U(chip, REGSEL)) & CS4231_INIT) |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1075 | msleep(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | else { |
| 1077 | spin_lock_irqsave(&chip->lock, flags); |
| 1078 | snd_cs4231_out(chip, CS4231_MISC_INFO, CS4231_MODE2); |
| 1079 | id = snd_cs4231_in(chip, CS4231_MISC_INFO) & 0x0f; |
| 1080 | vers = snd_cs4231_in(chip, CS4231_VERSION); |
| 1081 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1082 | if (id == 0x0a) |
| 1083 | break; /* this is valid value */ |
| 1084 | } |
| 1085 | } |
| 1086 | snd_printdd("cs4231: port = %p, id = 0x%x\n", chip->port, id); |
| 1087 | if (id != 0x0a) |
| 1088 | return -ENODEV; /* no valid device found */ |
| 1089 | |
| 1090 | spin_lock_irqsave(&chip->lock, flags); |
| 1091 | |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 1092 | /* clear any pendings IRQ */ |
| 1093 | __cs4231_readb(chip, CS4231U(chip, STATUS)); |
| 1094 | __cs4231_writeb(chip, 0, CS4231U(chip, STATUS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | mb(); |
| 1096 | |
| 1097 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1098 | |
| 1099 | chip->image[CS4231_MISC_INFO] = CS4231_MODE2; |
| 1100 | chip->image[CS4231_IFACE_CTRL] = |
| 1101 | chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA; |
| 1102 | chip->image[CS4231_ALT_FEATURE_1] = 0x80; |
| 1103 | chip->image[CS4231_ALT_FEATURE_2] = 0x01; |
| 1104 | if (vers & 0x20) |
| 1105 | chip->image[CS4231_ALT_FEATURE_2] |= 0x02; |
| 1106 | |
| 1107 | ptr = (unsigned char *) &chip->image; |
| 1108 | |
| 1109 | snd_cs4231_mce_down(chip); |
| 1110 | |
| 1111 | spin_lock_irqsave(&chip->lock, flags); |
| 1112 | |
| 1113 | for (i = 0; i < 32; i++) /* ok.. fill all CS4231 registers */ |
| 1114 | snd_cs4231_out(chip, i, *ptr++); |
| 1115 | |
| 1116 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1117 | |
| 1118 | snd_cs4231_mce_up(chip); |
| 1119 | |
| 1120 | snd_cs4231_mce_down(chip); |
| 1121 | |
| 1122 | mdelay(2); |
| 1123 | |
| 1124 | return 0; /* all things are ok.. */ |
| 1125 | } |
| 1126 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1127 | static struct snd_pcm_hardware snd_cs4231_playback = { |
| 1128 | .info = SNDRV_PCM_INFO_MMAP | |
| 1129 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1130 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1131 | SNDRV_PCM_INFO_SYNC_START, |
| 1132 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
| 1133 | SNDRV_PCM_FMTBIT_A_LAW | |
| 1134 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1135 | SNDRV_PCM_FMTBIT_U8 | |
| 1136 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1137 | SNDRV_PCM_FMTBIT_S16_BE, |
| 1138 | .rates = SNDRV_PCM_RATE_KNOT | |
| 1139 | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | .rate_min = 5510, |
| 1141 | .rate_max = 48000, |
| 1142 | .channels_min = 1, |
| 1143 | .channels_max = 2, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1144 | .buffer_bytes_max = 32 * 1024, |
David S. Miller | f9af1d9 | 2007-01-03 18:51:54 -0800 | [diff] [blame] | 1145 | .period_bytes_min = 64, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1146 | .period_bytes_max = 32 * 1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | .periods_min = 1, |
| 1148 | .periods_max = 1024, |
| 1149 | }; |
| 1150 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1151 | static struct snd_pcm_hardware snd_cs4231_capture = { |
| 1152 | .info = SNDRV_PCM_INFO_MMAP | |
| 1153 | SNDRV_PCM_INFO_INTERLEAVED | |
| 1154 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1155 | SNDRV_PCM_INFO_SYNC_START, |
| 1156 | .formats = SNDRV_PCM_FMTBIT_MU_LAW | |
| 1157 | SNDRV_PCM_FMTBIT_A_LAW | |
| 1158 | SNDRV_PCM_FMTBIT_IMA_ADPCM | |
| 1159 | SNDRV_PCM_FMTBIT_U8 | |
| 1160 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1161 | SNDRV_PCM_FMTBIT_S16_BE, |
| 1162 | .rates = SNDRV_PCM_RATE_KNOT | |
| 1163 | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | .rate_min = 5510, |
| 1165 | .rate_max = 48000, |
| 1166 | .channels_min = 1, |
| 1167 | .channels_max = 2, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1168 | .buffer_bytes_max = 32 * 1024, |
David S. Miller | f9af1d9 | 2007-01-03 18:51:54 -0800 | [diff] [blame] | 1169 | .period_bytes_min = 64, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1170 | .period_bytes_max = 32 * 1024, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | .periods_min = 1, |
| 1172 | .periods_max = 1024, |
| 1173 | }; |
| 1174 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1175 | static int snd_cs4231_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1177 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1178 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | int err; |
| 1180 | |
| 1181 | runtime->hw = snd_cs4231_playback; |
| 1182 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1183 | err = snd_cs4231_open(chip, CS4231_MODE_PLAY); |
| 1184 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1186 | return err; |
| 1187 | } |
| 1188 | chip->playback_substream = substream; |
| 1189 | chip->p_periods_sent = 0; |
| 1190 | snd_pcm_set_sync(substream); |
| 1191 | snd_cs4231_xrate(runtime); |
| 1192 | |
| 1193 | return 0; |
| 1194 | } |
| 1195 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1196 | static int snd_cs4231_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1198 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
| 1199 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | int err; |
| 1201 | |
| 1202 | runtime->hw = snd_cs4231_capture; |
| 1203 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1204 | err = snd_cs4231_open(chip, CS4231_MODE_RECORD); |
| 1205 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | snd_free_pages(runtime->dma_area, runtime->dma_bytes); |
| 1207 | return err; |
| 1208 | } |
| 1209 | chip->capture_substream = substream; |
| 1210 | chip->c_periods_sent = 0; |
| 1211 | snd_pcm_set_sync(substream); |
| 1212 | snd_cs4231_xrate(runtime); |
| 1213 | |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1217 | static int snd_cs4231_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1219 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | snd_cs4231_close(chip, CS4231_MODE_PLAY); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1222 | chip->playback_substream = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1227 | static int snd_cs4231_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1229 | struct snd_cs4231 *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | snd_cs4231_close(chip, CS4231_MODE_RECORD); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1232 | chip->capture_substream = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | /* XXX We can do some power-management, in particular on EBUS using |
| 1238 | * XXX the audio AUXIO register... |
| 1239 | */ |
| 1240 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1241 | static struct snd_pcm_ops snd_cs4231_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | .open = snd_cs4231_playback_open, |
| 1243 | .close = snd_cs4231_playback_close, |
| 1244 | .ioctl = snd_pcm_lib_ioctl, |
| 1245 | .hw_params = snd_cs4231_playback_hw_params, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1246 | .hw_free = snd_pcm_lib_free_pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | .prepare = snd_cs4231_playback_prepare, |
| 1248 | .trigger = snd_cs4231_trigger, |
| 1249 | .pointer = snd_cs4231_playback_pointer, |
| 1250 | }; |
| 1251 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1252 | static struct snd_pcm_ops snd_cs4231_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | .open = snd_cs4231_capture_open, |
| 1254 | .close = snd_cs4231_capture_close, |
| 1255 | .ioctl = snd_pcm_lib_ioctl, |
| 1256 | .hw_params = snd_cs4231_capture_hw_params, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1257 | .hw_free = snd_pcm_lib_free_pages, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | .prepare = snd_cs4231_capture_prepare, |
| 1259 | .trigger = snd_cs4231_trigger, |
| 1260 | .pointer = snd_cs4231_capture_pointer, |
| 1261 | }; |
| 1262 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1263 | static int __init snd_cs4231_pcm(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1265 | struct snd_cs4231 *chip = card->private_data; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1266 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | int err; |
| 1268 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1269 | err = snd_pcm_new(card, "CS4231", 0, 1, 1, &pcm); |
| 1270 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | return err; |
| 1272 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1273 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1274 | &snd_cs4231_playback_ops); |
| 1275 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1276 | &snd_cs4231_capture_ops); |
| 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | /* global setup */ |
| 1279 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1281 | strcpy(pcm->name, "CS4231"); |
| 1282 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1283 | chip->p_dma.preallocate(chip, pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
| 1285 | chip->pcm = pcm; |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1290 | static int __init snd_cs4231_timer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1292 | struct snd_cs4231 *chip = card->private_data; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1293 | struct snd_timer *timer; |
| 1294 | struct snd_timer_id tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | int err; |
| 1296 | |
| 1297 | /* Timer initialization */ |
| 1298 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; |
| 1299 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1300 | tid.card = card->number; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | tid.device = 0; |
| 1302 | tid.subdevice = 0; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1303 | err = snd_timer_new(card, "CS4231", &tid, &timer); |
| 1304 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | return err; |
| 1306 | strcpy(timer->name, "CS4231"); |
| 1307 | timer->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | timer->hw = snd_cs4231_timer_table; |
| 1309 | chip->timer = timer; |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | /* |
| 1315 | * MIXER part |
| 1316 | */ |
| 1317 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1318 | static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, |
| 1319 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | { |
| 1321 | static char *texts[4] = { |
| 1322 | "Line", "CD", "Mic", "Mix" |
| 1323 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 1326 | uinfo->count = 2; |
| 1327 | uinfo->value.enumerated.items = 4; |
| 1328 | if (uinfo->value.enumerated.item > 3) |
| 1329 | uinfo->value.enumerated.item = 3; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1330 | strcpy(uinfo->value.enumerated.name, |
| 1331 | texts[uinfo->value.enumerated.item]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | |
| 1333 | return 0; |
| 1334 | } |
| 1335 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1336 | static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, |
| 1337 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1339 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | unsigned long flags; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | spin_lock_irqsave(&chip->lock, flags); |
| 1343 | ucontrol->value.enumerated.item[0] = |
| 1344 | (chip->image[CS4231_LEFT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1345 | ucontrol->value.enumerated.item[1] = |
| 1346 | (chip->image[CS4231_RIGHT_INPUT] & CS4231_MIXS_ALL) >> 6; |
| 1347 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1348 | |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1352 | static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, |
| 1353 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1355 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | unsigned long flags; |
| 1357 | unsigned short left, right; |
| 1358 | int change; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | if (ucontrol->value.enumerated.item[0] > 3 || |
| 1361 | ucontrol->value.enumerated.item[1] > 3) |
| 1362 | return -EINVAL; |
| 1363 | left = ucontrol->value.enumerated.item[0] << 6; |
| 1364 | right = ucontrol->value.enumerated.item[1] << 6; |
| 1365 | |
| 1366 | spin_lock_irqsave(&chip->lock, flags); |
| 1367 | |
| 1368 | left = (chip->image[CS4231_LEFT_INPUT] & ~CS4231_MIXS_ALL) | left; |
| 1369 | right = (chip->image[CS4231_RIGHT_INPUT] & ~CS4231_MIXS_ALL) | right; |
| 1370 | change = left != chip->image[CS4231_LEFT_INPUT] || |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1371 | right != chip->image[CS4231_RIGHT_INPUT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | snd_cs4231_out(chip, CS4231_LEFT_INPUT, left); |
| 1373 | snd_cs4231_out(chip, CS4231_RIGHT_INPUT, right); |
| 1374 | |
| 1375 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1376 | |
| 1377 | return change; |
| 1378 | } |
| 1379 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1380 | static int snd_cs4231_info_single(struct snd_kcontrol *kcontrol, |
| 1381 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | { |
| 1383 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1384 | |
| 1385 | uinfo->type = (mask == 1) ? |
| 1386 | SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1387 | uinfo->count = 1; |
| 1388 | uinfo->value.integer.min = 0; |
| 1389 | uinfo->value.integer.max = mask; |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1394 | static int snd_cs4231_get_single(struct snd_kcontrol *kcontrol, |
| 1395 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1397 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | unsigned long flags; |
| 1399 | int reg = kcontrol->private_value & 0xff; |
| 1400 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1401 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1402 | int invert = (kcontrol->private_value >> 24) & 0xff; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | spin_lock_irqsave(&chip->lock, flags); |
| 1405 | |
| 1406 | ucontrol->value.integer.value[0] = (chip->image[reg] >> shift) & mask; |
| 1407 | |
| 1408 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1409 | |
| 1410 | if (invert) |
| 1411 | ucontrol->value.integer.value[0] = |
| 1412 | (mask - ucontrol->value.integer.value[0]); |
| 1413 | |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1417 | static int snd_cs4231_put_single(struct snd_kcontrol *kcontrol, |
| 1418 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1420 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | unsigned long flags; |
| 1422 | int reg = kcontrol->private_value & 0xff; |
| 1423 | int shift = (kcontrol->private_value >> 8) & 0xff; |
| 1424 | int mask = (kcontrol->private_value >> 16) & 0xff; |
| 1425 | int invert = (kcontrol->private_value >> 24) & 0xff; |
| 1426 | int change; |
| 1427 | unsigned short val; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | val = (ucontrol->value.integer.value[0] & mask); |
| 1430 | if (invert) |
| 1431 | val = mask - val; |
| 1432 | val <<= shift; |
| 1433 | |
| 1434 | spin_lock_irqsave(&chip->lock, flags); |
| 1435 | |
| 1436 | val = (chip->image[reg] & ~(mask << shift)) | val; |
| 1437 | change = val != chip->image[reg]; |
| 1438 | snd_cs4231_out(chip, reg, val); |
| 1439 | |
| 1440 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1441 | |
| 1442 | return change; |
| 1443 | } |
| 1444 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1445 | static int snd_cs4231_info_double(struct snd_kcontrol *kcontrol, |
| 1446 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
| 1448 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1449 | |
| 1450 | uinfo->type = mask == 1 ? |
| 1451 | SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1452 | uinfo->count = 2; |
| 1453 | uinfo->value.integer.min = 0; |
| 1454 | uinfo->value.integer.max = mask; |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1459 | static int snd_cs4231_get_double(struct snd_kcontrol *kcontrol, |
| 1460 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1462 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | unsigned long flags; |
| 1464 | int left_reg = kcontrol->private_value & 0xff; |
| 1465 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1466 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1467 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1468 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1469 | int invert = (kcontrol->private_value >> 22) & 1; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | spin_lock_irqsave(&chip->lock, flags); |
| 1472 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1473 | ucontrol->value.integer.value[0] = |
| 1474 | (chip->image[left_reg] >> shift_left) & mask; |
| 1475 | ucontrol->value.integer.value[1] = |
| 1476 | (chip->image[right_reg] >> shift_right) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
| 1478 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1479 | |
| 1480 | if (invert) { |
| 1481 | ucontrol->value.integer.value[0] = |
| 1482 | (mask - ucontrol->value.integer.value[0]); |
| 1483 | ucontrol->value.integer.value[1] = |
| 1484 | (mask - ucontrol->value.integer.value[1]); |
| 1485 | } |
| 1486 | |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1490 | static int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, |
| 1491 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1493 | struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | unsigned long flags; |
| 1495 | int left_reg = kcontrol->private_value & 0xff; |
| 1496 | int right_reg = (kcontrol->private_value >> 8) & 0xff; |
| 1497 | int shift_left = (kcontrol->private_value >> 16) & 0x07; |
| 1498 | int shift_right = (kcontrol->private_value >> 19) & 0x07; |
| 1499 | int mask = (kcontrol->private_value >> 24) & 0xff; |
| 1500 | int invert = (kcontrol->private_value >> 22) & 1; |
| 1501 | int change; |
| 1502 | unsigned short val1, val2; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1505 | val2 = ucontrol->value.integer.value[1] & mask; |
| 1506 | if (invert) { |
| 1507 | val1 = mask - val1; |
| 1508 | val2 = mask - val2; |
| 1509 | } |
| 1510 | val1 <<= shift_left; |
| 1511 | val2 <<= shift_right; |
| 1512 | |
| 1513 | spin_lock_irqsave(&chip->lock, flags); |
| 1514 | |
| 1515 | val1 = (chip->image[left_reg] & ~(mask << shift_left)) | val1; |
| 1516 | val2 = (chip->image[right_reg] & ~(mask << shift_right)) | val2; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1517 | change = val1 != chip->image[left_reg]; |
| 1518 | change |= val2 != chip->image[right_reg]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | snd_cs4231_out(chip, left_reg, val1); |
| 1520 | snd_cs4231_out(chip, right_reg, val2); |
| 1521 | |
| 1522 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1523 | |
| 1524 | return change; |
| 1525 | } |
| 1526 | |
| 1527 | #define CS4231_SINGLE(xname, xindex, reg, shift, mask, invert) \ |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1528 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
| 1529 | .info = snd_cs4231_info_single, \ |
| 1530 | .get = snd_cs4231_get_single, .put = snd_cs4231_put_single, \ |
| 1531 | .private_value = (reg) | ((shift) << 8) | ((mask) << 16) | ((invert) << 24) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1533 | #define CS4231_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, \ |
| 1534 | shift_right, mask, invert) \ |
| 1535 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .index = (xindex), \ |
| 1536 | .info = snd_cs4231_info_double, \ |
| 1537 | .get = snd_cs4231_get_double, .put = snd_cs4231_put_double, \ |
| 1538 | .private_value = (left_reg) | ((right_reg) << 8) | ((shift_left) << 16) | \ |
| 1539 | ((shift_right) << 19) | ((mask) << 24) | ((invert) << 22) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1541 | static struct snd_kcontrol_new snd_cs4231_controls[] __initdata = { |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1542 | CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, |
| 1543 | CS4231_RIGHT_OUTPUT, 7, 7, 1, 1), |
| 1544 | CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, |
| 1545 | CS4231_RIGHT_OUTPUT, 0, 0, 63, 1), |
| 1546 | CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, |
| 1547 | CS4231_RIGHT_LINE_IN, 7, 7, 1, 1), |
| 1548 | CS4231_DOUBLE("Line Playback Volume", 0, CS4231_LEFT_LINE_IN, |
| 1549 | CS4231_RIGHT_LINE_IN, 0, 0, 31, 1), |
| 1550 | CS4231_DOUBLE("Aux Playback Switch", 0, CS4231_AUX1_LEFT_INPUT, |
| 1551 | CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1), |
| 1552 | CS4231_DOUBLE("Aux Playback Volume", 0, CS4231_AUX1_LEFT_INPUT, |
| 1553 | CS4231_AUX1_RIGHT_INPUT, 0, 0, 31, 1), |
| 1554 | CS4231_DOUBLE("Aux Playback Switch", 1, CS4231_AUX2_LEFT_INPUT, |
| 1555 | CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1), |
| 1556 | CS4231_DOUBLE("Aux Playback Volume", 1, CS4231_AUX2_LEFT_INPUT, |
| 1557 | CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | CS4231_SINGLE("Mono Playback Switch", 0, CS4231_MONO_CTRL, 7, 1, 1), |
| 1559 | CS4231_SINGLE("Mono Playback Volume", 0, CS4231_MONO_CTRL, 0, 15, 1), |
| 1560 | CS4231_SINGLE("Mono Output Playback Switch", 0, CS4231_MONO_CTRL, 6, 1, 1), |
| 1561 | 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] | 1562 | CS4231_DOUBLE("Capture Volume", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, |
| 1563 | 15, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | { |
| 1565 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1566 | .name = "Capture Source", |
| 1567 | .info = snd_cs4231_info_mux, |
| 1568 | .get = snd_cs4231_get_mux, |
| 1569 | .put = snd_cs4231_put_mux, |
| 1570 | }, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1571 | CS4231_DOUBLE("Mic Boost", 0, CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, |
| 1572 | 1, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0), |
| 1574 | CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1), |
| 1575 | /* SPARC specific uses of XCTL{0,1} general purpose outputs. */ |
| 1576 | CS4231_SINGLE("Line Out Switch", 0, CS4231_PIN_CTRL, 6, 1, 1), |
| 1577 | CS4231_SINGLE("Headphone Out Switch", 0, CS4231_PIN_CTRL, 7, 1, 1) |
| 1578 | }; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1579 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1580 | static int __init snd_cs4231_mixer(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1582 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | int err, idx; |
| 1584 | |
| 1585 | snd_assert(chip != NULL && chip->pcm != NULL, return -EINVAL); |
| 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | strcpy(card->mixername, chip->pcm->name); |
| 1588 | |
| 1589 | for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1590 | err = snd_ctl_add(card, |
| 1591 | snd_ctl_new1(&snd_cs4231_controls[idx], chip)); |
| 1592 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | return err; |
| 1594 | } |
| 1595 | return 0; |
| 1596 | } |
| 1597 | |
| 1598 | static int dev; |
| 1599 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1600 | static int __init cs4231_attach_begin(struct snd_card **rcard) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1602 | struct snd_card *card; |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1603 | struct snd_cs4231 *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | |
| 1605 | *rcard = NULL; |
| 1606 | |
| 1607 | if (dev >= SNDRV_CARDS) |
| 1608 | return -ENODEV; |
| 1609 | |
| 1610 | if (!enable[dev]) { |
| 1611 | dev++; |
| 1612 | return -ENOENT; |
| 1613 | } |
| 1614 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1615 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, |
| 1616 | sizeof(struct snd_cs4231)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | if (card == NULL) |
| 1618 | return -ENOMEM; |
| 1619 | |
| 1620 | strcpy(card->driver, "CS4231"); |
| 1621 | strcpy(card->shortname, "Sun CS4231"); |
| 1622 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1623 | chip = card->private_data; |
| 1624 | chip->card = card; |
| 1625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | *rcard = card; |
| 1627 | return 0; |
| 1628 | } |
| 1629 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1630 | static int __init cs4231_attach_finish(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1632 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | int err; |
| 1634 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1635 | err = snd_cs4231_pcm(card); |
| 1636 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1637 | goto out_err; |
| 1638 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1639 | err = snd_cs4231_mixer(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_timer(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_card_register(card); |
| 1648 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | goto out_err; |
| 1650 | |
| 1651 | chip->next = cs4231_list; |
| 1652 | cs4231_list = chip; |
| 1653 | |
| 1654 | dev++; |
| 1655 | return 0; |
| 1656 | |
| 1657 | out_err: |
| 1658 | snd_card_free(card); |
| 1659 | return err; |
| 1660 | } |
| 1661 | |
| 1662 | #ifdef SBUS_SUPPORT |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1663 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1664 | static irqreturn_t snd_cs4231_sbus_interrupt(int irq, void *dev_id) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1665 | { |
| 1666 | unsigned long flags; |
| 1667 | unsigned char status; |
| 1668 | u32 csr; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1669 | struct snd_cs4231 *chip = dev_id; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1670 | |
| 1671 | /*This is IRQ is not raised by the cs4231*/ |
Krzysztof Helt | 7e52f3d | 2007-09-05 15:08:23 +0200 | [diff] [blame] | 1672 | if (!(__cs4231_readb(chip, CS4231U(chip, STATUS)) & CS4231_GLOBALIRQ)) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1673 | return IRQ_NONE; |
| 1674 | |
| 1675 | /* ACK the APC interrupt. */ |
| 1676 | csr = sbus_readl(chip->port + APCCSR); |
| 1677 | |
| 1678 | sbus_writel(csr, chip->port + APCCSR); |
| 1679 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1680 | if ((csr & APC_PDMA_READY) && |
| 1681 | (csr & APC_PLAY_INT) && |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1682 | (csr & APC_XINT_PNVA) && |
| 1683 | !(csr & APC_XINT_EMPT)) |
| 1684 | snd_cs4231_play_callback(chip); |
| 1685 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1686 | if ((csr & APC_CDMA_READY) && |
| 1687 | (csr & APC_CAPT_INT) && |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1688 | (csr & APC_XINT_CNVA) && |
| 1689 | !(csr & APC_XINT_EMPT)) |
| 1690 | snd_cs4231_capture_callback(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1691 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1692 | status = snd_cs4231_in(chip, CS4231_IRQ_STATUS); |
| 1693 | |
| 1694 | if (status & CS4231_TIMER_IRQ) { |
| 1695 | if (chip->timer) |
| 1696 | snd_timer_interrupt(chip->timer, chip->timer->sticks); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1697 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1698 | |
| 1699 | if ((status & CS4231_RECORD_IRQ) && (csr & APC_CDMA_READY)) |
| 1700 | snd_cs4231_overrange(chip); |
| 1701 | |
| 1702 | /* ACK the CS4231 interrupt. */ |
| 1703 | spin_lock_irqsave(&chip->lock, flags); |
| 1704 | snd_cs4231_outm(chip, CS4231_IRQ_STATUS, ~CS4231_ALL_IRQS | ~status, 0); |
| 1705 | spin_unlock_irqrestore(&chip->lock, flags); |
| 1706 | |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1707 | return IRQ_HANDLED; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | /* |
| 1711 | * SBUS DMA routines |
| 1712 | */ |
| 1713 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1714 | static int sbus_dma_request(struct cs4231_dma_control *dma_cont, |
| 1715 | dma_addr_t bus_addr, size_t len) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1716 | { |
| 1717 | unsigned long flags; |
| 1718 | u32 test, csr; |
| 1719 | int err; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1720 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1721 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1722 | if (len >= (1 << 24)) |
| 1723 | return -EINVAL; |
| 1724 | spin_lock_irqsave(&base->lock, flags); |
| 1725 | csr = sbus_readl(base->regs + APCCSR); |
| 1726 | err = -EINVAL; |
| 1727 | test = APC_CDMA_READY; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1728 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1729 | test = APC_PDMA_READY; |
| 1730 | if (!(csr & test)) |
| 1731 | goto out; |
| 1732 | err = -EBUSY; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1733 | test = APC_XINT_CNVA; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1734 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1735 | test = APC_XINT_PNVA; |
| 1736 | if (!(csr & test)) |
| 1737 | goto out; |
| 1738 | err = 0; |
| 1739 | sbus_writel(bus_addr, base->regs + base->dir + APCNVA); |
| 1740 | sbus_writel(len, base->regs + base->dir + APCNC); |
| 1741 | out: |
| 1742 | spin_unlock_irqrestore(&base->lock, flags); |
| 1743 | return err; |
| 1744 | } |
| 1745 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1746 | 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] | 1747 | { |
| 1748 | unsigned long flags; |
| 1749 | u32 csr, test; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1750 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1751 | |
| 1752 | spin_lock_irqsave(&base->lock, flags); |
| 1753 | csr = sbus_readl(base->regs + APCCSR); |
| 1754 | test = APC_GENL_INT | APC_PLAY_INT | APC_XINT_ENA | |
| 1755 | APC_XINT_PLAY | APC_XINT_PEMP | APC_XINT_GENL | |
| 1756 | APC_XINT_PENA; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1757 | if (base->dir == APC_RECORD) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1758 | test = APC_GENL_INT | APC_CAPT_INT | APC_XINT_ENA | |
| 1759 | APC_XINT_CAPT | APC_XINT_CEMP | APC_XINT_GENL; |
| 1760 | csr |= test; |
| 1761 | sbus_writel(csr, base->regs + APCCSR); |
| 1762 | spin_unlock_irqrestore(&base->lock, flags); |
| 1763 | } |
| 1764 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1765 | 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] | 1766 | { |
| 1767 | unsigned long flags; |
| 1768 | u32 csr, shift; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1769 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1770 | |
| 1771 | spin_lock_irqsave(&base->lock, flags); |
| 1772 | if (!on) { |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1773 | sbus_writel(0, base->regs + base->dir + APCNC); |
| 1774 | sbus_writel(0, base->regs + base->dir + APCNVA); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1775 | if (base->dir == APC_PLAY) { |
Georg Chini | 3daadf3 | 2007-08-01 21:55:58 -0700 | [diff] [blame] | 1776 | sbus_writel(0, base->regs + base->dir + APCC); |
| 1777 | sbus_writel(0, base->regs + base->dir + APCVA); |
| 1778 | } |
Georg Chini | d35a1b9 | 2007-01-02 21:28:17 -0800 | [diff] [blame] | 1779 | |
Georg Chini | 3daadf3 | 2007-08-01 21:55:58 -0700 | [diff] [blame] | 1780 | udelay(1200); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1781 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1782 | csr = sbus_readl(base->regs + APCCSR); |
| 1783 | shift = 0; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1784 | if (base->dir == APC_PLAY) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1785 | shift = 1; |
| 1786 | if (on) |
| 1787 | csr &= ~(APC_CPAUSE << shift); |
| 1788 | else |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1789 | csr |= (APC_CPAUSE << shift); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1790 | sbus_writel(csr, base->regs + APCCSR); |
| 1791 | if (on) |
| 1792 | csr |= (APC_CDMA_READY << shift); |
| 1793 | else |
| 1794 | csr &= ~(APC_CDMA_READY << shift); |
| 1795 | sbus_writel(csr, base->regs + APCCSR); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1796 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1797 | spin_unlock_irqrestore(&base->lock, flags); |
| 1798 | } |
| 1799 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1800 | static unsigned int sbus_dma_addr(struct cs4231_dma_control *dma_cont) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1801 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1802 | struct sbus_dma_info *base = &dma_cont->sbus_info; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1803 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1804 | return sbus_readl(base->regs + base->dir + APCVA); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1805 | } |
| 1806 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1807 | 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] | 1808 | { |
| 1809 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS, |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1810 | snd_dma_sbus_data(chip->dev_u.sdev), |
| 1811 | 64 * 1024, 128 * 1024); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /* |
| 1815 | * Init and exit routines |
| 1816 | */ |
| 1817 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1818 | static int snd_cs4231_sbus_free(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | { |
| 1820 | if (chip->irq[0]) |
| 1821 | free_irq(chip->irq[0], chip); |
| 1822 | |
| 1823 | if (chip->port) |
| 1824 | sbus_iounmap(chip->port, chip->regs_size); |
| 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | return 0; |
| 1827 | } |
| 1828 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1829 | static int snd_cs4231_sbus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1831 | struct snd_cs4231 *cp = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | |
| 1833 | return snd_cs4231_sbus_free(cp); |
| 1834 | } |
| 1835 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1836 | static struct snd_device_ops snd_cs4231_sbus_dev_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | .dev_free = snd_cs4231_sbus_dev_free, |
| 1838 | }; |
| 1839 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1840 | static int __init snd_cs4231_sbus_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | struct sbus_dev *sdev, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1842 | int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1844 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | int err; |
| 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | spin_lock_init(&chip->lock); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1848 | spin_lock_init(&chip->c_dma.sbus_info.lock); |
| 1849 | spin_lock_init(&chip->p_dma.sbus_info.lock); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 1850 | mutex_init(&chip->mce_mutex); |
| 1851 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | chip->dev_u.sdev = sdev; |
| 1853 | chip->regs_size = sdev->reg_addrs[0].reg_size; |
| 1854 | memcpy(&chip->image, &snd_cs4231_original_image, |
| 1855 | sizeof(snd_cs4231_original_image)); |
| 1856 | |
| 1857 | chip->port = sbus_ioremap(&sdev->resource[0], 0, |
| 1858 | chip->regs_size, "cs4231"); |
| 1859 | if (!chip->port) { |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 1860 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | return -EIO; |
| 1862 | } |
| 1863 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1864 | chip->c_dma.sbus_info.regs = chip->port; |
| 1865 | chip->p_dma.sbus_info.regs = chip->port; |
| 1866 | chip->c_dma.sbus_info.dir = APC_RECORD; |
| 1867 | chip->p_dma.sbus_info.dir = APC_PLAY; |
| 1868 | |
| 1869 | chip->p_dma.prepare = sbus_dma_prepare; |
| 1870 | chip->p_dma.enable = sbus_dma_enable; |
| 1871 | chip->p_dma.request = sbus_dma_request; |
| 1872 | chip->p_dma.address = sbus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1873 | chip->p_dma.preallocate = sbus_dma_preallocate; |
| 1874 | |
| 1875 | chip->c_dma.prepare = sbus_dma_prepare; |
| 1876 | chip->c_dma.enable = sbus_dma_enable; |
| 1877 | chip->c_dma.request = sbus_dma_request; |
| 1878 | chip->c_dma.address = sbus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1879 | chip->c_dma.preallocate = sbus_dma_preallocate; |
Georg Chini | 5a820fa | 2005-11-07 14:08:25 -0800 | [diff] [blame] | 1880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | if (request_irq(sdev->irqs[0], snd_cs4231_sbus_interrupt, |
Thomas Gleixner | 65ca68b | 2006-07-01 19:29:46 -0700 | [diff] [blame] | 1882 | IRQF_SHARED, "cs4231", chip)) { |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 1883 | snd_printdd("cs4231-%d: Unable to grab SBUS IRQ %d\n", |
| 1884 | dev, sdev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | snd_cs4231_sbus_free(chip); |
| 1886 | return -EBUSY; |
| 1887 | } |
| 1888 | chip->irq[0] = sdev->irqs[0]; |
| 1889 | |
| 1890 | if (snd_cs4231_probe(chip) < 0) { |
| 1891 | snd_cs4231_sbus_free(chip); |
| 1892 | return -ENODEV; |
| 1893 | } |
| 1894 | snd_cs4231_init(chip); |
| 1895 | |
| 1896 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
| 1897 | chip, &snd_cs4231_sbus_dev_ops)) < 0) { |
| 1898 | snd_cs4231_sbus_free(chip); |
| 1899 | return err; |
| 1900 | } |
| 1901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | return 0; |
| 1903 | } |
| 1904 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1905 | static int __init cs4231_sbus_attach(struct sbus_dev *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | { |
| 1907 | struct resource *rp = &sdev->resource[0]; |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1908 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | int err; |
| 1910 | |
| 1911 | err = cs4231_attach_begin(&card); |
| 1912 | if (err) |
| 1913 | return err; |
| 1914 | |
Andrew Morton | 5863aa6 | 2006-07-03 00:24:22 -0700 | [diff] [blame] | 1915 | sprintf(card->longname, "%s at 0x%02lx:0x%016Lx, irq %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | card->shortname, |
| 1917 | rp->flags & 0xffL, |
Greg Kroah-Hartman | aa0a2dd | 2006-06-12 14:50:27 -0700 | [diff] [blame] | 1918 | (unsigned long long)rp->start, |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 1919 | sdev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1921 | err = snd_cs4231_sbus_create(card, sdev, dev); |
| 1922 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | snd_card_free(card); |
| 1924 | return err; |
| 1925 | } |
| 1926 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 1927 | return cs4231_attach_finish(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | } |
| 1929 | #endif |
| 1930 | |
| 1931 | #ifdef EBUS_SUPPORT |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1932 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1933 | static void snd_cs4231_ebus_play_callback(struct ebus_dma_info *p, int event, |
| 1934 | void *cookie) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1935 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1936 | struct snd_cs4231 *chip = cookie; |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1937 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1938 | snd_cs4231_play_callback(chip); |
| 1939 | } |
| 1940 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1941 | static void snd_cs4231_ebus_capture_callback(struct ebus_dma_info *p, |
| 1942 | int event, void *cookie) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1943 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1944 | struct snd_cs4231 *chip = cookie; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1945 | |
| 1946 | snd_cs4231_capture_callback(chip); |
| 1947 | } |
| 1948 | |
| 1949 | /* |
| 1950 | * EBUS DMA wrappers |
| 1951 | */ |
| 1952 | |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 1953 | static int _ebus_dma_request(struct cs4231_dma_control *dma_cont, |
| 1954 | dma_addr_t bus_addr, size_t len) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1955 | { |
| 1956 | return ebus_dma_request(&dma_cont->ebus_info, bus_addr, len); |
| 1957 | } |
| 1958 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1959 | 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] | 1960 | { |
| 1961 | ebus_dma_enable(&dma_cont->ebus_info, on); |
| 1962 | } |
| 1963 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1964 | 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] | 1965 | { |
| 1966 | ebus_dma_prepare(&dma_cont->ebus_info, dir); |
| 1967 | } |
| 1968 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1969 | static unsigned int _ebus_dma_addr(struct cs4231_dma_control *dma_cont) |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1970 | { |
| 1971 | return ebus_dma_addr(&dma_cont->ebus_info); |
| 1972 | } |
| 1973 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1974 | 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] | 1975 | { |
| 1976 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1977 | snd_dma_pci_data(chip->dev_u.pdev), |
| 1978 | 64*1024, 128*1024); |
| 1979 | } |
| 1980 | |
| 1981 | /* |
| 1982 | * Init and exit routines |
| 1983 | */ |
| 1984 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 1985 | static int snd_cs4231_ebus_free(struct snd_cs4231 *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | { |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 1987 | if (chip->c_dma.ebus_info.regs) { |
| 1988 | ebus_dma_unregister(&chip->c_dma.ebus_info); |
| 1989 | iounmap(chip->c_dma.ebus_info.regs); |
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->p_dma.ebus_info.regs) { |
| 1992 | ebus_dma_unregister(&chip->p_dma.ebus_info); |
| 1993 | iounmap(chip->p_dma.ebus_info.regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | if (chip->port) |
| 1997 | iounmap(chip->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | return 0; |
| 2000 | } |
| 2001 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2002 | static int snd_cs4231_ebus_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2004 | struct snd_cs4231 *cp = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
| 2006 | return snd_cs4231_ebus_free(cp); |
| 2007 | } |
| 2008 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2009 | static struct snd_device_ops snd_cs4231_ebus_dev_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | .dev_free = snd_cs4231_ebus_dev_free, |
| 2011 | }; |
| 2012 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2013 | static int __init snd_cs4231_ebus_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | struct linux_ebus_device *edev, |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2015 | int dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | { |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2017 | struct snd_cs4231 *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | int err; |
| 2019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | spin_lock_init(&chip->lock); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2021 | spin_lock_init(&chip->c_dma.ebus_info.lock); |
| 2022 | spin_lock_init(&chip->p_dma.ebus_info.lock); |
Ingo Molnar | 12aa757 | 2006-01-16 16:36:05 +0100 | [diff] [blame] | 2023 | mutex_init(&chip->mce_mutex); |
| 2024 | mutex_init(&chip->open_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | chip->flags |= CS4231_FLAG_EBUS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | chip->dev_u.pdev = edev->bus->self; |
| 2027 | memcpy(&chip->image, &snd_cs4231_original_image, |
| 2028 | sizeof(snd_cs4231_original_image)); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2029 | strcpy(chip->c_dma.ebus_info.name, "cs4231(capture)"); |
| 2030 | chip->c_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
| 2031 | chip->c_dma.ebus_info.callback = snd_cs4231_ebus_capture_callback; |
| 2032 | chip->c_dma.ebus_info.client_cookie = chip; |
| 2033 | chip->c_dma.ebus_info.irq = edev->irqs[0]; |
| 2034 | strcpy(chip->p_dma.ebus_info.name, "cs4231(play)"); |
| 2035 | chip->p_dma.ebus_info.flags = EBUS_DMA_FLAG_USE_EBDMA_HANDLER; |
| 2036 | chip->p_dma.ebus_info.callback = snd_cs4231_ebus_play_callback; |
| 2037 | chip->p_dma.ebus_info.client_cookie = chip; |
| 2038 | chip->p_dma.ebus_info.irq = edev->irqs[1]; |
| 2039 | |
| 2040 | chip->p_dma.prepare = _ebus_dma_prepare; |
| 2041 | chip->p_dma.enable = _ebus_dma_enable; |
| 2042 | chip->p_dma.request = _ebus_dma_request; |
| 2043 | chip->p_dma.address = _ebus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2044 | chip->p_dma.preallocate = _ebus_dma_preallocate; |
| 2045 | |
| 2046 | chip->c_dma.prepare = _ebus_dma_prepare; |
| 2047 | chip->c_dma.enable = _ebus_dma_enable; |
| 2048 | chip->c_dma.request = _ebus_dma_request; |
| 2049 | chip->c_dma.address = _ebus_dma_addr; |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2050 | chip->c_dma.preallocate = _ebus_dma_preallocate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
| 2052 | chip->port = ioremap(edev->resource[0].start, 0x10); |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2053 | chip->p_dma.ebus_info.regs = ioremap(edev->resource[1].start, 0x10); |
| 2054 | chip->c_dma.ebus_info.regs = ioremap(edev->resource[2].start, 0x10); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2055 | if (!chip->port || !chip->p_dma.ebus_info.regs || |
| 2056 | !chip->c_dma.ebus_info.regs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | snd_cs4231_ebus_free(chip); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 2058 | snd_printdd("cs4231-%d: Unable to map chip registers.\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | return -EIO; |
| 2060 | } |
| 2061 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2062 | if (ebus_dma_register(&chip->c_dma.ebus_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2064 | snd_printdd("cs4231-%d: Unable to register EBUS capture DMA\n", |
| 2065 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | return -EBUSY; |
| 2067 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2068 | if (ebus_dma_irq_enable(&chip->c_dma.ebus_info, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2070 | snd_printdd("cs4231-%d: Unable to enable EBUS capture IRQ\n", |
| 2071 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | return -EBUSY; |
| 2073 | } |
| 2074 | |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2075 | if (ebus_dma_register(&chip->p_dma.ebus_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | snd_cs4231_ebus_free(chip); |
Krzysztof Helt | 9e9abb4 | 2007-09-10 23:06:55 +0200 | [diff] [blame] | 2077 | snd_printdd("cs4231-%d: Unable to register EBUS play DMA\n", |
| 2078 | dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | return -EBUSY; |
| 2080 | } |
Georg Chini | b128254 | 2005-11-07 14:09:19 -0800 | [diff] [blame] | 2081 | if (ebus_dma_irq_enable(&chip->p_dma.ebus_info, 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | snd_cs4231_ebus_free(chip); |
Christopher Zimmermann | a131430 | 2005-09-21 00:41:22 -0700 | [diff] [blame] | 2083 | snd_printdd("cs4231-%d: Unable to enable EBUS play IRQ\n", dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | return -EBUSY; |
| 2085 | } |
| 2086 | |
| 2087 | if (snd_cs4231_probe(chip) < 0) { |
| 2088 | snd_cs4231_ebus_free(chip); |
| 2089 | return -ENODEV; |
| 2090 | } |
| 2091 | snd_cs4231_init(chip); |
| 2092 | |
| 2093 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, |
| 2094 | chip, &snd_cs4231_ebus_dev_ops)) < 0) { |
| 2095 | snd_cs4231_ebus_free(chip); |
| 2096 | return err; |
| 2097 | } |
| 2098 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | return 0; |
| 2100 | } |
| 2101 | |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2102 | static int __init cs4231_ebus_attach(struct linux_ebus_device *edev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2104 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | int err; |
| 2106 | |
| 2107 | err = cs4231_attach_begin(&card); |
| 2108 | if (err) |
| 2109 | return err; |
| 2110 | |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 2111 | sprintf(card->longname, "%s at 0x%lx, irq %d", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | card->shortname, |
| 2113 | edev->resource[0].start, |
David S. Miller | c6387a4 | 2006-06-20 01:21:29 -0700 | [diff] [blame] | 2114 | edev->irqs[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2116 | err = snd_cs4231_ebus_create(card, edev, dev); |
| 2117 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | snd_card_free(card); |
| 2119 | return err; |
| 2120 | } |
| 2121 | |
Krzysztof Helt | c6c2d57 | 2007-09-04 13:08:24 +0200 | [diff] [blame] | 2122 | return cs4231_attach_finish(card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | } |
| 2124 | #endif |
| 2125 | |
| 2126 | static int __init cs4231_init(void) |
| 2127 | { |
| 2128 | #ifdef SBUS_SUPPORT |
| 2129 | struct sbus_bus *sbus; |
| 2130 | struct sbus_dev *sdev; |
| 2131 | #endif |
| 2132 | #ifdef EBUS_SUPPORT |
| 2133 | struct linux_ebus *ebus; |
| 2134 | struct linux_ebus_device *edev; |
| 2135 | #endif |
| 2136 | int found; |
| 2137 | |
| 2138 | found = 0; |
| 2139 | |
| 2140 | #ifdef SBUS_SUPPORT |
| 2141 | for_all_sbusdev(sdev, sbus) { |
| 2142 | if (!strcmp(sdev->prom_name, "SUNW,CS4231")) { |
| 2143 | if (cs4231_sbus_attach(sdev) == 0) |
| 2144 | found++; |
| 2145 | } |
| 2146 | } |
| 2147 | #endif |
| 2148 | #ifdef EBUS_SUPPORT |
| 2149 | for_each_ebus(ebus) { |
| 2150 | for_each_ebusdev(edev, ebus) { |
| 2151 | int match = 0; |
| 2152 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2153 | if (!strcmp(edev->prom_node->name, "SUNW,CS4231")) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | match = 1; |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2155 | } else if (!strcmp(edev->prom_node->name, "audio")) { |
Stephen Rothwell | 3198514 | 2007-03-29 00:50:57 -0700 | [diff] [blame] | 2156 | const char *compat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | |
David S. Miller | 690c8fd | 2006-06-22 19:12:03 -0700 | [diff] [blame] | 2158 | compat = of_get_property(edev->prom_node, |
| 2159 | "compatible", NULL); |
| 2160 | if (compat && !strcmp(compat, "SUNW,CS4231")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | match = 1; |
| 2162 | } |
| 2163 | |
| 2164 | if (match && |
| 2165 | cs4231_ebus_attach(edev) == 0) |
| 2166 | found++; |
| 2167 | } |
| 2168 | } |
| 2169 | #endif |
| 2170 | |
| 2171 | |
| 2172 | return (found > 0) ? 0 : -EIO; |
| 2173 | } |
| 2174 | |
| 2175 | static void __exit cs4231_exit(void) |
| 2176 | { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2177 | struct snd_cs4231 *p = cs4231_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | |
| 2179 | while (p != NULL) { |
Takashi Iwai | be9b7e8 | 2006-01-03 13:42:38 +0100 | [diff] [blame] | 2180 | struct snd_cs4231 *next = p->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | |
| 2182 | snd_card_free(p->card); |
| 2183 | |
| 2184 | p = next; |
| 2185 | } |
| 2186 | |
| 2187 | cs4231_list = NULL; |
| 2188 | } |
| 2189 | |
| 2190 | module_init(cs4231_init); |
| 2191 | module_exit(cs4231_exit); |