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