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