Blame view

sound/pci/cs4281.c 62.5 KB
1a59d1b8e   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  /*
   *  Driver for Cirrus Logic CS4281 based PCI soundcard
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
4
   *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
   */
6cbbfe1c8   Takashi Iwai   ALSA: Include lin...
6
  #include <linux/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
  #include <linux/delay.h>
  #include <linux/interrupt.h>
  #include <linux/init.h>
  #include <linux/pci.h>
  #include <linux/slab.h>
  #include <linux/gameport.h>
65a772172   Paul Gortmaker   sound: fix driver...
13
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
15
16
17
18
  #include <sound/core.h>
  #include <sound/control.h>
  #include <sound/pcm.h>
  #include <sound/rawmidi.h>
  #include <sound/ac97_codec.h>
9f6ab2506   Takashi Iwai   [ALSA] Add dB sca...
19
  #include <sound/tlv.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
  #include <sound/opl3.h>
  #include <sound/initval.h>
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
22
  MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
25
26
27
28
  MODULE_DESCRIPTION("Cirrus Logic CS4281");
  MODULE_LICENSE("GPL");
  MODULE_SUPPORTED_DEVICE("{{Cirrus Logic,CS4281}}");
  
  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
a67ff6a54   Rusty Russell   ALSA: module_para...
29
30
  static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable switches */
  static bool dual_codec[SNDRV_CARDS];	/* dual codec */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
32
33
34
35
36
37
38
39
40
41
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for CS4281 soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for CS4281 soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable CS4281 soundcard.");
  module_param_array(dual_codec, bool, NULL, 0444);
  MODULE_PARM_DESC(dual_codec, "Secondary Codec ID (0 = disabled).");
  
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
   *  Direct registers
   */
  
  #define CS4281_BA0_SIZE		0x1000
  #define CS4281_BA1_SIZE		0x10000
  
  /*
   *  BA0 registers
   */
  #define BA0_HISR		0x0000	/* Host Interrupt Status Register */
  #define BA0_HISR_INTENA		(1<<31)	/* Internal Interrupt Enable Bit */
  #define BA0_HISR_MIDI		(1<<22)	/* MIDI port interrupt */
  #define BA0_HISR_FIFOI		(1<<20)	/* FIFO polled interrupt */
  #define BA0_HISR_DMAI		(1<<18)	/* DMA interrupt (half or end) */
  #define BA0_HISR_FIFO(c)	(1<<(12+(c))) /* FIFO channel interrupt */
  #define BA0_HISR_DMA(c)		(1<<(8+(c)))  /* DMA channel interrupt */
  #define BA0_HISR_GPPI		(1<<5)	/* General Purpose Input (Primary chip) */
  #define BA0_HISR_GPSI		(1<<4)	/* General Purpose Input (Secondary chip) */
  #define BA0_HISR_GP3I		(1<<3)	/* GPIO3 pin Interrupt */
  #define BA0_HISR_GP1I		(1<<2)	/* GPIO1 pin Interrupt */
  #define BA0_HISR_VUPI		(1<<1)	/* VOLUP pin Interrupt */
  #define BA0_HISR_VDNI		(1<<0)	/* VOLDN pin Interrupt */
  
  #define BA0_HICR		0x0008	/* Host Interrupt Control Register */
  #define BA0_HICR_CHGM		(1<<1)	/* INTENA Change Mask */
  #define BA0_HICR_IEV		(1<<0)	/* INTENA Value */
  #define BA0_HICR_EOI		(3<<0)	/* End of Interrupt command */
  
  #define BA0_HIMR		0x000c	/* Host Interrupt Mask Register */
  					/* Use same contants as for BA0_HISR */
  
  #define BA0_IIER		0x0010	/* ISA Interrupt Enable Register */
  
  #define BA0_HDSR0		0x00f0	/* Host DMA Engine 0 Status Register */
  #define BA0_HDSR1		0x00f4	/* Host DMA Engine 1 Status Register */
  #define BA0_HDSR2		0x00f8	/* Host DMA Engine 2 Status Register */
  #define BA0_HDSR3		0x00fc	/* Host DMA Engine 3 Status Register */
  
  #define BA0_HDSR_CH1P		(1<<25)	/* Channel 1 Pending */
  #define BA0_HDSR_CH2P		(1<<24)	/* Channel 2 Pending */
  #define BA0_HDSR_DHTC		(1<<17)	/* DMA Half Terminal Count */
  #define BA0_HDSR_DTC		(1<<16)	/* DMA Terminal Count */
  #define BA0_HDSR_DRUN		(1<<15)	/* DMA Running */
  #define BA0_HDSR_RQ		(1<<7)	/* Pending Request */
  
  #define BA0_DCA0		0x0110	/* Host DMA Engine 0 Current Address */
  #define BA0_DCC0		0x0114	/* Host DMA Engine 0 Current Count */
  #define BA0_DBA0		0x0118	/* Host DMA Engine 0 Base Address */
  #define BA0_DBC0		0x011c	/* Host DMA Engine 0 Base Count */
  #define BA0_DCA1		0x0120	/* Host DMA Engine 1 Current Address */
  #define BA0_DCC1		0x0124	/* Host DMA Engine 1 Current Count */
  #define BA0_DBA1		0x0128	/* Host DMA Engine 1 Base Address */
  #define BA0_DBC1		0x012c	/* Host DMA Engine 1 Base Count */
  #define BA0_DCA2		0x0130	/* Host DMA Engine 2 Current Address */
  #define BA0_DCC2		0x0134	/* Host DMA Engine 2 Current Count */
  #define BA0_DBA2		0x0138	/* Host DMA Engine 2 Base Address */
  #define BA0_DBC2		0x013c	/* Host DMA Engine 2 Base Count */
  #define BA0_DCA3		0x0140	/* Host DMA Engine 3 Current Address */
  #define BA0_DCC3		0x0144	/* Host DMA Engine 3 Current Count */
  #define BA0_DBA3		0x0148	/* Host DMA Engine 3 Base Address */
  #define BA0_DBC3		0x014c	/* Host DMA Engine 3 Base Count */
  #define BA0_DMR0		0x0150	/* Host DMA Engine 0 Mode */
  #define BA0_DCR0		0x0154	/* Host DMA Engine 0 Command */
  #define BA0_DMR1		0x0158	/* Host DMA Engine 1 Mode */
  #define BA0_DCR1		0x015c	/* Host DMA Engine 1 Command */
  #define BA0_DMR2		0x0160	/* Host DMA Engine 2 Mode */
  #define BA0_DCR2		0x0164	/* Host DMA Engine 2 Command */
  #define BA0_DMR3		0x0168	/* Host DMA Engine 3 Mode */
  #define BA0_DCR3		0x016c	/* Host DMA Engine 3 Command */
  
  #define BA0_DMR_DMA		(1<<29)	/* Enable DMA mode */
  #define BA0_DMR_POLL		(1<<28)	/* Enable poll mode */
  #define BA0_DMR_TBC		(1<<25)	/* Transfer By Channel */
  #define BA0_DMR_CBC		(1<<24)	/* Count By Channel (0 = frame resolution) */
  #define BA0_DMR_SWAPC		(1<<22)	/* Swap Left/Right Channels */
  #define BA0_DMR_SIZE20		(1<<20)	/* Sample is 20-bit */
  #define BA0_DMR_USIGN		(1<<19)	/* Unsigned */
  #define BA0_DMR_BEND		(1<<18)	/* Big Endian */
  #define BA0_DMR_MONO		(1<<17)	/* Mono */
  #define BA0_DMR_SIZE8		(1<<16)	/* Sample is 8-bit */
  #define BA0_DMR_TYPE_DEMAND	(0<<6)
  #define BA0_DMR_TYPE_SINGLE	(1<<6)
  #define BA0_DMR_TYPE_BLOCK	(2<<6)
  #define BA0_DMR_TYPE_CASCADE	(3<<6)	/* Not supported */
  #define BA0_DMR_DEC		(1<<5)	/* Access Increment (0) or Decrement (1) */
  #define BA0_DMR_AUTO		(1<<4)	/* Auto-Initialize */
  #define BA0_DMR_TR_VERIFY	(0<<2)	/* Verify Transfer */
  #define BA0_DMR_TR_WRITE	(1<<2)	/* Write Transfer */
  #define BA0_DMR_TR_READ		(2<<2)	/* Read Transfer */
  
  #define BA0_DCR_HTCIE		(1<<17)	/* Half Terminal Count Interrupt */
  #define BA0_DCR_TCIE		(1<<16)	/* Terminal Count Interrupt */
  #define BA0_DCR_MSK		(1<<0)	/* DMA Mask bit */
  
  #define BA0_FCR0		0x0180	/* FIFO Control 0 */
  #define BA0_FCR1		0x0184	/* FIFO Control 1 */
  #define BA0_FCR2		0x0188	/* FIFO Control 2 */
  #define BA0_FCR3		0x018c	/* FIFO Control 3 */
  
  #define BA0_FCR_FEN		(1<<31)	/* FIFO Enable bit */
  #define BA0_FCR_DACZ		(1<<30)	/* DAC Zero */
  #define BA0_FCR_PSH		(1<<29)	/* Previous Sample Hold */
  #define BA0_FCR_RS(x)		(((x)&0x1f)<<24) /* Right Slot Mapping */
  #define BA0_FCR_LS(x)		(((x)&0x1f)<<16) /* Left Slot Mapping */
  #define BA0_FCR_SZ(x)		(((x)&0x7f)<<8)	/* FIFO buffer size (in samples) */
  #define BA0_FCR_OF(x)		(((x)&0x7f)<<0)	/* FIFO starting offset (in samples) */
  
  #define BA0_FPDR0		0x0190	/* FIFO Polled Data 0 */
  #define BA0_FPDR1		0x0194	/* FIFO Polled Data 1 */
  #define BA0_FPDR2		0x0198	/* FIFO Polled Data 2 */
  #define BA0_FPDR3		0x019c	/* FIFO Polled Data 3 */
  
  #define BA0_FCHS		0x020c	/* FIFO Channel Status */
  #define BA0_FCHS_RCO(x)		(1<<(7+(((x)&3)<<3))) /* Right Channel Out */
  #define BA0_FCHS_LCO(x)		(1<<(6+(((x)&3)<<3))) /* Left Channel Out */
  #define BA0_FCHS_MRP(x)		(1<<(5+(((x)&3)<<3))) /* Move Read Pointer */
  #define BA0_FCHS_FE(x)		(1<<(4+(((x)&3)<<3))) /* FIFO Empty */
  #define BA0_FCHS_FF(x)		(1<<(3+(((x)&3)<<3))) /* FIFO Full */
  #define BA0_FCHS_IOR(x)		(1<<(2+(((x)&3)<<3))) /* Internal Overrun Flag */
  #define BA0_FCHS_RCI(x)		(1<<(1+(((x)&3)<<3))) /* Right Channel In */
  #define BA0_FCHS_LCI(x)		(1<<(0+(((x)&3)<<3))) /* Left Channel In */
  
  #define BA0_FSIC0		0x0210	/* FIFO Status and Interrupt Control 0 */
  #define BA0_FSIC1		0x0214	/* FIFO Status and Interrupt Control 1 */
  #define BA0_FSIC2		0x0218	/* FIFO Status and Interrupt Control 2 */
  #define BA0_FSIC3		0x021c	/* FIFO Status and Interrupt Control 3 */
  
  #define BA0_FSIC_FIC(x)		(((x)&0x7f)<<24) /* FIFO Interrupt Count */
  #define BA0_FSIC_FORIE		(1<<23) /* FIFO OverRun Interrupt Enable */
  #define BA0_FSIC_FURIE		(1<<22) /* FIFO UnderRun Interrupt Enable */
  #define BA0_FSIC_FSCIE		(1<<16)	/* FIFO Sample Count Interrupt Enable */
  #define BA0_FSIC_FSC(x)		(((x)&0x7f)<<8) /* FIFO Sample Count */
  #define BA0_FSIC_FOR		(1<<7)	/* FIFO OverRun */
  #define BA0_FSIC_FUR		(1<<6)	/* FIFO UnderRun */
  #define BA0_FSIC_FSCR		(1<<0)	/* FIFO Sample Count Reached */
  
  #define BA0_PMCS		0x0344	/* Power Management Control/Status */
  #define BA0_CWPR		0x03e0	/* Configuration Write Protect */
a488e0338   Arnaud Patard   [ALSA] cs4281 - f...
180

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
  #define BA0_EPPMC		0x03e4	/* Extended PCI Power Management Control */
a488e0338   Arnaud Patard   [ALSA] cs4281 - f...
182
  #define BA0_EPPMC_FPDN		(1<<14) /* Full Power DowN */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
  #define BA0_GPIOR		0x03e8	/* GPIO Pin Interface Register */
  
  #define BA0_SPMC		0x03ec	/* Serial Port Power Management Control (& ASDIN2 enable) */
  #define BA0_SPMC_GIPPEN		(1<<15)	/* GP INT Primary PME# Enable */
  #define BA0_SPMC_GISPEN		(1<<14)	/* GP INT Secondary PME# Enable */
  #define BA0_SPMC_EESPD		(1<<9)	/* EEPROM Serial Port Disable */
  #define BA0_SPMC_ASDI2E		(1<<8)	/* ASDIN2 Enable */
  #define BA0_SPMC_ASDO		(1<<7)	/* Asynchronous ASDOUT Assertion */
  #define BA0_SPMC_WUP2		(1<<3)	/* Wakeup for Secondary Input */
  #define BA0_SPMC_WUP1		(1<<2)	/* Wakeup for Primary Input */
  #define BA0_SPMC_ASYNC		(1<<1)	/* Asynchronous ASYNC Assertion */
  #define BA0_SPMC_RSTN		(1<<0)	/* Reset Not! */
  
  #define BA0_CFLR		0x03f0	/* Configuration Load Register (EEPROM or BIOS) */
  #define BA0_CFLR_DEFAULT	0x00000001 /* CFLR must be in AC97 link mode */
  #define BA0_IISR		0x03f4	/* ISA Interrupt Select */
  #define BA0_TMS			0x03f8	/* Test Register */
  #define BA0_SSVID		0x03fc	/* Subsystem ID register */
  
  #define BA0_CLKCR1		0x0400	/* Clock Control Register 1 */
  #define BA0_CLKCR1_CLKON	(1<<25)	/* Read Only */
  #define BA0_CLKCR1_DLLRDY	(1<<24)	/* DLL Ready */
  #define BA0_CLKCR1_DLLOS	(1<<6)	/* DLL Output Select */
  #define BA0_CLKCR1_SWCE		(1<<5)	/* Clock Enable */
  #define BA0_CLKCR1_DLLP		(1<<4)	/* DLL PowerUp */
  #define BA0_CLKCR1_DLLSS	(((x)&3)<<3) /* DLL Source Select */
  
  #define BA0_FRR			0x0410	/* Feature Reporting Register */
  #define BA0_SLT12O		0x041c	/* Slot 12 GPIO Output Register for AC-Link */
  
  #define BA0_SERMC		0x0420	/* Serial Port Master Control */
  #define BA0_SERMC_FCRN		(1<<27)	/* Force Codec Ready Not */
  #define BA0_SERMC_ODSEN2	(1<<25)	/* On-Demand Support Enable ASDIN2 */
  #define BA0_SERMC_ODSEN1	(1<<24)	/* On-Demand Support Enable ASDIN1 */
  #define BA0_SERMC_SXLB		(1<<21)	/* ASDIN2 to ASDOUT Loopback */
  #define BA0_SERMC_SLB		(1<<20)	/* ASDOUT to ASDIN2 Loopback */
  #define BA0_SERMC_LOVF		(1<<19)	/* Loopback Output Valid Frame bit */
  #define BA0_SERMC_TCID(x)	(((x)&3)<<16) /* Target Secondary Codec ID */
  #define BA0_SERMC_PXLB		(5<<1)	/* Primary Port External Loopback */
  #define BA0_SERMC_PLB		(4<<1)	/* Primary Port Internal Loopback */
  #define BA0_SERMC_PTC		(7<<1)	/* Port Timing Configuration */
  #define BA0_SERMC_PTC_AC97	(1<<1)	/* AC97 mode */
  #define BA0_SERMC_MSPE		(1<<0)	/* Master Serial Port Enable */
  
  #define BA0_SERC1		0x0428	/* Serial Port Configuration 1 */
  #define BA0_SERC1_SO1F(x)	(((x)&7)>>1) /* Primary Output Port Format */
  #define BA0_SERC1_AC97		(1<<1)
  #define BA0_SERC1_SO1EN		(1<<0)	/* Primary Output Port Enable */
  
  #define BA0_SERC2		0x042c	/* Serial Port Configuration 2 */
  #define BA0_SERC2_SI1F(x)	(((x)&7)>>1) /* Primary Input Port Format */
  #define BA0_SERC2_AC97		(1<<1)
  #define BA0_SERC2_SI1EN		(1<<0)	/* Primary Input Port Enable */
  
  #define BA0_SLT12M		0x045c	/* Slot 12 Monitor Register for Primary AC-Link */
  
  #define BA0_ACCTL		0x0460	/* AC'97 Control */
  #define BA0_ACCTL_TC		(1<<6)	/* Target Codec */
  #define BA0_ACCTL_CRW		(1<<4)	/* 0=Write, 1=Read Command */
  #define BA0_ACCTL_DCV		(1<<3)	/* Dynamic Command Valid */
  #define BA0_ACCTL_VFRM		(1<<2)	/* Valid Frame */
  #define BA0_ACCTL_ESYN		(1<<1)	/* Enable Sync */
  
  #define BA0_ACSTS		0x0464	/* AC'97 Status */
  #define BA0_ACSTS_VSTS		(1<<1)	/* Valid Status */
  #define BA0_ACSTS_CRDY		(1<<0)	/* Codec Ready */
  
  #define BA0_ACOSV		0x0468	/* AC'97 Output Slot Valid */
  #define BA0_ACOSV_SLV(x)	(1<<((x)-3))
  
  #define BA0_ACCAD		0x046c	/* AC'97 Command Address */
  #define BA0_ACCDA		0x0470	/* AC'97 Command Data */
  
  #define BA0_ACISV		0x0474	/* AC'97 Input Slot Valid */
  #define BA0_ACISV_SLV(x)	(1<<((x)-3))
  
  #define BA0_ACSAD		0x0478	/* AC'97 Status Address */
  #define BA0_ACSDA		0x047c	/* AC'97 Status Data */
  #define BA0_JSPT		0x0480	/* Joystick poll/trigger */
  #define BA0_JSCTL		0x0484	/* Joystick control */
  #define BA0_JSC1		0x0488	/* Joystick control */
  #define BA0_JSC2		0x048c	/* Joystick control */
  #define BA0_JSIO		0x04a0
  
  #define BA0_MIDCR		0x0490	/* MIDI Control */
  #define BA0_MIDCR_MRST		(1<<5)	/* Reset MIDI Interface */
  #define BA0_MIDCR_MLB		(1<<4)	/* MIDI Loop Back Enable */
  #define BA0_MIDCR_TIE		(1<<3)	/* MIDI Transmuit Interrupt Enable */
  #define BA0_MIDCR_RIE		(1<<2)	/* MIDI Receive Interrupt Enable */
  #define BA0_MIDCR_RXE		(1<<1)	/* MIDI Receive Enable */
  #define BA0_MIDCR_TXE		(1<<0)	/* MIDI Transmit Enable */
  
  #define BA0_MIDCMD		0x0494	/* MIDI Command (wo) */
  
  #define BA0_MIDSR		0x0494	/* MIDI Status (ro) */
  #define BA0_MIDSR_RDA		(1<<15)	/* Sticky bit (RBE 1->0) */
  #define BA0_MIDSR_TBE		(1<<14) /* Sticky bit (TBF 0->1) */
  #define BA0_MIDSR_RBE		(1<<7)	/* Receive Buffer Empty */
  #define BA0_MIDSR_TBF		(1<<6)	/* Transmit Buffer Full */
  
  #define BA0_MIDWP		0x0498	/* MIDI Write */
  #define BA0_MIDRP		0x049c	/* MIDI Read (ro) */
  
  #define BA0_AODSD1		0x04a8	/* AC'97 On-Demand Slot Disable for primary link (ro) */
  #define BA0_AODSD1_NDS(x)	(1<<((x)-3))
  
  #define BA0_AODSD2		0x04ac	/* AC'97 On-Demand Slot Disable for secondary link (ro) */
  #define BA0_AODSD2_NDS(x)	(1<<((x)-3))
  
  #define BA0_CFGI		0x04b0	/* Configure Interface (EEPROM interface) */
  #define BA0_SLT12M2		0x04dc	/* Slot 12 Monitor Register 2 for secondary AC-link */
  #define BA0_ACSTS2		0x04e4	/* AC'97 Status Register 2 */
  #define BA0_ACISV2		0x04f4	/* AC'97 Input Slot Valid Register 2 */
  #define BA0_ACSAD2		0x04f8	/* AC'97 Status Address Register 2 */
  #define BA0_ACSDA2		0x04fc	/* AC'97 Status Data Register 2 */
  #define BA0_FMSR		0x0730	/* FM Synthesis Status (ro) */
  #define BA0_B0AP		0x0730	/* FM Bank 0 Address Port (wo) */
  #define BA0_FMDP		0x0734	/* FM Data Port */
  #define BA0_B1AP		0x0738	/* FM Bank 1 Address Port */
  #define BA0_B1DP		0x073c	/* FM Bank 1 Data Port */
  
  #define BA0_SSPM		0x0740	/* Sound System Power Management */
  #define BA0_SSPM_MIXEN		(1<<6)	/* Playback SRC + FM/Wavetable MIX */
  #define BA0_SSPM_CSRCEN		(1<<5)	/* Capture Sample Rate Converter Enable */
  #define BA0_SSPM_PSRCEN		(1<<4)	/* Playback Sample Rate Converter Enable */
  #define BA0_SSPM_JSEN		(1<<3)	/* Joystick Enable */
  #define BA0_SSPM_ACLEN		(1<<2)	/* Serial Port Engine and AC-Link Enable */
  #define BA0_SSPM_FMEN		(1<<1)	/* FM Synthesis Block Enable */
  
  #define BA0_DACSR		0x0744	/* DAC Sample Rate - Playback SRC */
  #define BA0_ADCSR		0x0748	/* ADC Sample Rate - Capture SRC */
  
  #define BA0_SSCR		0x074c	/* Sound System Control Register */
  #define BA0_SSCR_HVS1		(1<<23)	/* Hardwave Volume Step (0=1,1=2) */
  #define BA0_SSCR_MVCS		(1<<19)	/* Master Volume Codec Select */
  #define BA0_SSCR_MVLD		(1<<18)	/* Master Volume Line Out Disable */
  #define BA0_SSCR_MVAD		(1<<17)	/* Master Volume Alternate Out Disable */
  #define BA0_SSCR_MVMD		(1<<16)	/* Master Volume Mono Out Disable */
  #define BA0_SSCR_XLPSRC		(1<<8)	/* External SRC Loopback Mode */
  #define BA0_SSCR_LPSRC		(1<<7)	/* SRC Loopback Mode */
  #define BA0_SSCR_CDTX		(1<<5)	/* CD Transfer Data */
  #define BA0_SSCR_HVC		(1<<3)	/* Harware Volume Control Enable */
  
  #define BA0_FMLVC		0x0754	/* FM Synthesis Left Volume Control */
  #define BA0_FMRVC		0x0758	/* FM Synthesis Right Volume Control */
  #define BA0_SRCSA		0x075c	/* SRC Slot Assignments */
  #define BA0_PPLVC		0x0760	/* PCM Playback Left Volume Control */
  #define BA0_PPRVC		0x0764	/* PCM Playback Right Volume Control */
  #define BA0_PASR		0x0768	/* playback sample rate */
  #define BA0_CASR		0x076C	/* capture sample rate */
  
  /* Source Slot Numbers - Playback */
  #define SRCSLOT_LEFT_PCM_PLAYBACK		0
  #define SRCSLOT_RIGHT_PCM_PLAYBACK		1
  #define SRCSLOT_PHONE_LINE_1_DAC		2
  #define SRCSLOT_CENTER_PCM_PLAYBACK		3
  #define SRCSLOT_LEFT_SURROUND_PCM_PLAYBACK	4
  #define SRCSLOT_RIGHT_SURROUND_PCM_PLAYBACK	5
  #define SRCSLOT_LFE_PCM_PLAYBACK		6
  #define SRCSLOT_PHONE_LINE_2_DAC		7
  #define SRCSLOT_HEADSET_DAC			8
  #define SRCSLOT_LEFT_WT				29  /* invalid for BA0_SRCSA */
  #define SRCSLOT_RIGHT_WT			30  /* invalid for BA0_SRCSA */
  
  /* Source Slot Numbers - Capture */
  #define SRCSLOT_LEFT_PCM_RECORD			10
  #define SRCSLOT_RIGHT_PCM_RECORD		11
  #define SRCSLOT_PHONE_LINE_1_ADC		12
  #define SRCSLOT_MIC_ADC				13
  #define SRCSLOT_PHONE_LINE_2_ADC		17
  #define SRCSLOT_HEADSET_ADC			18
  #define SRCSLOT_SECONDARY_LEFT_PCM_RECORD	20
  #define SRCSLOT_SECONDARY_RIGHT_PCM_RECORD	21
  #define SRCSLOT_SECONDARY_PHONE_LINE_1_ADC	22
  #define SRCSLOT_SECONDARY_MIC_ADC		23
  #define SRCSLOT_SECONDARY_PHONE_LINE_2_ADC	27
  #define SRCSLOT_SECONDARY_HEADSET_ADC		28
  
  /* Source Slot Numbers - Others */
  #define SRCSLOT_POWER_DOWN			31
  
  /* MIDI modes */
  #define CS4281_MODE_OUTPUT		(1<<0)
  #define CS4281_MODE_INPUT		(1<<1)
  
  /* joystick bits */
  /* Bits for JSPT */
  #define JSPT_CAX                                0x00000001
  #define JSPT_CAY                                0x00000002
  #define JSPT_CBX                                0x00000004
  #define JSPT_CBY                                0x00000008
  #define JSPT_BA1                                0x00000010
  #define JSPT_BA2                                0x00000020
  #define JSPT_BB1                                0x00000040
  #define JSPT_BB2                                0x00000080
  
  /* Bits for JSCTL */
  #define JSCTL_SP_MASK                           0x00000003
  #define JSCTL_SP_SLOW                           0x00000000
  #define JSCTL_SP_MEDIUM_SLOW                    0x00000001
  #define JSCTL_SP_MEDIUM_FAST                    0x00000002
  #define JSCTL_SP_FAST                           0x00000003
  #define JSCTL_ARE                               0x00000004
  
  /* Data register pairs masks */
  #define JSC1_Y1V_MASK                           0x0000FFFF
  #define JSC1_X1V_MASK                           0xFFFF0000
  #define JSC1_Y1V_SHIFT                          0
  #define JSC1_X1V_SHIFT                          16
  #define JSC2_Y2V_MASK                           0x0000FFFF
  #define JSC2_X2V_MASK                           0xFFFF0000
  #define JSC2_Y2V_SHIFT                          0
  #define JSC2_X2V_SHIFT                          16
  
  /* JS GPIO */
  #define JSIO_DAX                                0x00000001
  #define JSIO_DAY                                0x00000002
  #define JSIO_DBX                                0x00000004
  #define JSIO_DBY                                0x00000008
  #define JSIO_AXOE                               0x00000010
  #define JSIO_AYOE                               0x00000020
  #define JSIO_BXOE                               0x00000040
  #define JSIO_BYOE                               0x00000080
  
  /*
   *
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
410
411
  struct cs4281_dma {
  	struct snd_pcm_substream *substream;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
  	unsigned int regDBA;		/* offset to DBA register */
  	unsigned int regDCA;		/* offset to DCA register */
  	unsigned int regDBC;		/* offset to DBC register */
  	unsigned int regDCC;		/* offset to DCC register */
  	unsigned int regDMR;		/* offset to DMR register */
  	unsigned int regDCR;		/* offset to DCR register */
  	unsigned int regHDSR;		/* offset to HDSR register */
  	unsigned int regFCR;		/* offset to FCR register */
  	unsigned int regFSIC;		/* offset to FSIC register */
  	unsigned int valDMR;		/* DMA mode */
  	unsigned int valDCR;		/* DMA command */
  	unsigned int valFCR;		/* FIFO control */
  	unsigned int fifo_offset;	/* FIFO offset within BA1 */
  	unsigned char left_slot;	/* FIFO left slot */
  	unsigned char right_slot;	/* FIFO right slot */
  	int frag;			/* period number */
  };
  
  #define SUSPEND_REGISTERS	20
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
431
  struct cs4281 {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
432
433
434
435
436
437
438
439
  	int irq;
  
  	void __iomem *ba0;		/* virtual (accessible) address */
  	void __iomem *ba1;		/* virtual (accessible) address */
  	unsigned long ba0_addr;
  	unsigned long ba1_addr;
  
  	int dual_codec;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
440
441
442
  	struct snd_ac97_bus *ac97_bus;
  	struct snd_ac97 *ac97;
  	struct snd_ac97 *ac97_secondary;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
443
444
  
  	struct pci_dev *pci;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
445
446
447
448
449
  	struct snd_card *card;
  	struct snd_pcm *pcm;
  	struct snd_rawmidi *rmidi;
  	struct snd_rawmidi_substream *midi_input;
  	struct snd_rawmidi_substream *midi_output;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450

93e35f956   Takashi Iwai   [ALSA] Remove xxx...
451
  	struct cs4281_dma dma[4];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
452
453
454
455
456
457
458
459
460
461
462
463
464
465
  
  	unsigned char src_left_play_slot;
  	unsigned char src_right_play_slot;
  	unsigned char src_left_rec_slot;
  	unsigned char src_right_rec_slot;
  
  	unsigned int spurious_dhtc_irq;
  	unsigned int spurious_dtc_irq;
  
  	spinlock_t reg_lock;
  	unsigned int midcr;
  	unsigned int uartm;
  
  	struct gameport *gameport;
c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
466
  #ifdef CONFIG_PM_SLEEP
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
467
468
469
470
  	u32 suspend_regs[SUSPEND_REGISTERS];
  #endif
  
  };
7d12e780e   David Howells   IRQ: Maintain reg...
471
  static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472

9baa3c34a   Benoit Taine   PCI: Remove DEFIN...
473
  static const struct pci_device_id snd_cs4281_ids[] = {
28d27aae9   Joe Perches   sound: Use PCI_VD...
474
  	{ PCI_VDEVICE(CIRRUS, 0x6005), 0, },	/* CS4281 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
475
476
477
478
479
480
481
482
483
484
485
486
487
488
  	{ 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, snd_cs4281_ids);
  
  /*
   *  constants
   */
  
  #define CS4281_FIFO_SIZE	32
  
  /*
   *  common I/O routines
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
489
490
  static inline void snd_cs4281_pokeBA0(struct cs4281 *chip, unsigned long offset,
  				      unsigned int val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
491
492
493
  {
          writel(val, chip->ba0 + offset);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
494
  static inline unsigned int snd_cs4281_peekBA0(struct cs4281 *chip, unsigned long offset)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
495
496
497
  {
          return readl(chip->ba0 + offset);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
498
  static void snd_cs4281_ac97_write(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
500
501
502
503
504
505
506
507
  				  unsigned short reg, unsigned short val)
  {
  	/*
  	 *  1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
  	 *  2. Write ACCDA = Command Data Register = 470h    for data to write to AC97
  	 *  3. Write ACCTL = Control Register = 460h for initiating the write
  	 *  4. Read ACCTL = 460h, DCV should be reset by now and 460h = 07h
  	 *  5. if DCV not cleared, break and return error
  	 */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
508
  	struct cs4281 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
  	int count;
  
  	/*
  	 *  Setup the AC97 control registers on the CS461x to send the
  	 *  appropriate command to the AC97 to perform the read.
  	 *  ACCAD = Command Address Register = 46Ch
  	 *  ACCDA = Command Data Register = 470h
  	 *  ACCTL = Control Register = 460h
  	 *  set DCV - will clear when process completed
  	 *  reset CRW - Write command
  	 *  set VFRM - valid frame enabled
  	 *  set ESYN - ASYNC generation enabled
  	 *  set RSTN - ARST# inactive, AC97 codec not reset
           */
  	snd_cs4281_pokeBA0(chip, BA0_ACCAD, reg);
  	snd_cs4281_pokeBA0(chip, BA0_ACCDA, val);
  	snd_cs4281_pokeBA0(chip, BA0_ACCTL, BA0_ACCTL_DCV | BA0_ACCTL_VFRM |
  				            BA0_ACCTL_ESYN | (ac97->num ? BA0_ACCTL_TC : 0));
  	for (count = 0; count < 2000; count++) {
  		/*
  		 *  First, we want to wait for a short time.
  		 */
  		udelay(10);
  		/*
  		 *  Now, check to see if the write has completed.
  		 *  ACCTL = 460h, DCV should be reset by now and 460h = 07h
  		 */
  		if (!(snd_cs4281_peekBA0(chip, BA0_ACCTL) & BA0_ACCTL_DCV)) {
  			return;
  		}
  	}
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
540
541
542
  	dev_err(chip->card->dev,
  		"AC'97 write problem, reg = 0x%x, val = 0x%x
  ", reg, val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
544
  static unsigned short snd_cs4281_ac97_read(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
546
  					   unsigned short reg)
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
547
  	struct cs4281 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
548
549
550
551
  	int count;
  	unsigned short result;
  	// FIXME: volatile is necessary in the following due to a bug of
  	// some gcc versions
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
552
  	volatile int ac97_num = ((volatile struct snd_ac97 *)ac97)->num;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
  
  	/*
  	 *  1. Write ACCAD = Command Address Register = 46Ch for AC97 register address
  	 *  2. Write ACCDA = Command Data Register = 470h    for data to write to AC97 
  	 *  3. Write ACCTL = Control Register = 460h for initiating the write
  	 *  4. Read ACCTL = 460h, DCV should be reset by now and 460h = 17h
  	 *  5. if DCV not cleared, break and return error
  	 *  6. Read ACSTS = Status Register = 464h, check VSTS bit
  	 */
  
  	snd_cs4281_peekBA0(chip, ac97_num ? BA0_ACSDA2 : BA0_ACSDA);
  
  	/*
  	 *  Setup the AC97 control registers on the CS461x to send the
  	 *  appropriate command to the AC97 to perform the read.
  	 *  ACCAD = Command Address Register = 46Ch
  	 *  ACCDA = Command Data Register = 470h
  	 *  ACCTL = Control Register = 460h
  	 *  set DCV - will clear when process completed
  	 *  set CRW - Read command
  	 *  set VFRM - valid frame enabled
  	 *  set ESYN - ASYNC generation enabled
  	 *  set RSTN - ARST# inactive, AC97 codec not reset
  	 */
  
  	snd_cs4281_pokeBA0(chip, BA0_ACCAD, reg);
  	snd_cs4281_pokeBA0(chip, BA0_ACCDA, 0);
  	snd_cs4281_pokeBA0(chip, BA0_ACCTL, BA0_ACCTL_DCV | BA0_ACCTL_CRW |
  					    BA0_ACCTL_VFRM | BA0_ACCTL_ESYN |
  			   (ac97_num ? BA0_ACCTL_TC : 0));
  
  
  	/*
  	 *  Wait for the read to occur.
  	 */
  	for (count = 0; count < 500; count++) {
  		/*
  		 *  First, we want to wait for a short time.
  	 	 */
  		udelay(10);
  		/*
  		 *  Now, check to see if the read has completed.
  		 *  ACCTL = 460h, DCV should be reset by now and 460h = 17h
  		 */
  		if (!(snd_cs4281_peekBA0(chip, BA0_ACCTL) & BA0_ACCTL_DCV))
  			goto __ok1;
  	}
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
600
601
602
  	dev_err(chip->card->dev,
  		"AC'97 read problem (ACCTL_DCV), reg = 0x%x
  ", reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
  	result = 0xffff;
  	goto __end;
  	
        __ok1:
  	/*
  	 *  Wait for the valid status bit to go active.
  	 */
  	for (count = 0; count < 100; count++) {
  		/*
  		 *  Read the AC97 status register.
  		 *  ACSTS = Status Register = 464h
  		 *  VSTS - Valid Status
  		 */
  		if (snd_cs4281_peekBA0(chip, ac97_num ? BA0_ACSTS2 : BA0_ACSTS) & BA0_ACSTS_VSTS)
  			goto __ok2;
  		udelay(10);
  	}
  	
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
621
622
623
  	dev_err(chip->card->dev,
  		"AC'97 read problem (ACSTS_VSTS), reg = 0x%x
  ", reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
  	result = 0xffff;
  	goto __end;
  
        __ok2:
  	/*
  	 *  Read the data returned from the AC97 register.
  	 *  ACSDA = Status Data Register = 474h
  	 */
  	result = snd_cs4281_peekBA0(chip, ac97_num ? BA0_ACSDA2 : BA0_ACSDA);
  
        __end:
  	return result;
  }
  
  /*
   *  PCM part
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
641
  static int snd_cs4281_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
642
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
643
644
  	struct cs4281_dma *dma = substream->runtime->private_data;
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
  
  	spin_lock(&chip->reg_lock);
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  		dma->valDCR |= BA0_DCR_MSK;
  		dma->valFCR |= BA0_FCR_FEN;
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  		dma->valDCR &= ~BA0_DCR_MSK;
  		dma->valFCR &= ~BA0_FCR_FEN;
  		break;
  	case SNDRV_PCM_TRIGGER_START:
  	case SNDRV_PCM_TRIGGER_RESUME:
  		snd_cs4281_pokeBA0(chip, dma->regDMR, dma->valDMR & ~BA0_DMR_DMA);
  		dma->valDMR |= BA0_DMR_DMA;
  		dma->valDCR &= ~BA0_DCR_MSK;
  		dma->valFCR |= BA0_FCR_FEN;
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  	case SNDRV_PCM_TRIGGER_SUSPEND:
  		dma->valDMR &= ~(BA0_DMR_DMA|BA0_DMR_POLL);
  		dma->valDCR |= BA0_DCR_MSK;
  		dma->valFCR &= ~BA0_FCR_FEN;
  		/* Leave wave playback FIFO enabled for FM */
  		if (dma->regFCR != BA0_FCR0)
  			dma->valFCR &= ~BA0_FCR_FEN;
  		break;
  	default:
  		spin_unlock(&chip->reg_lock);
  		return -EINVAL;
  	}
  	snd_cs4281_pokeBA0(chip, dma->regDMR, dma->valDMR);
  	snd_cs4281_pokeBA0(chip, dma->regFCR, dma->valFCR);
  	snd_cs4281_pokeBA0(chip, dma->regDCR, dma->valDCR);
  	spin_unlock(&chip->reg_lock);
  	return 0;
  }
  
  static unsigned int snd_cs4281_rate(unsigned int rate, unsigned int *real_rate)
  {
388b00f04   Colin Ian King   ALSA: cs4281: rem...
685
  	unsigned int val;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
686
687
688
689
690
691
692
693
694
695
696
697
  	
  	if (real_rate)
  		*real_rate = rate;
  	/* special "hardcoded" rates */
  	switch (rate) {
  	case 8000:	return 5;
  	case 11025:	return 4;
  	case 16000:	return 3;
  	case 22050:	return 2;
  	case 44100:	return 1;
  	case 48000:	return 0;
  	default:
388b00f04   Colin Ian King   ALSA: cs4281: rem...
698
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
699
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
700
701
702
703
704
  	val = 1536000 / rate;
  	if (real_rate)
  		*real_rate = 1536000 / val;
  	return val;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
705
706
707
  static void snd_cs4281_mode(struct cs4281 *chip, struct cs4281_dma *dma,
  			    struct snd_pcm_runtime *runtime,
  			    int capture, int src)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
  {
  	int rec_mono;
  
  	dma->valDMR = BA0_DMR_TYPE_SINGLE | BA0_DMR_AUTO |
  		      (capture ? BA0_DMR_TR_WRITE : BA0_DMR_TR_READ);
  	if (runtime->channels == 1)
  		dma->valDMR |= BA0_DMR_MONO;
  	if (snd_pcm_format_unsigned(runtime->format) > 0)
  		dma->valDMR |= BA0_DMR_USIGN;
  	if (snd_pcm_format_big_endian(runtime->format) > 0)
  		dma->valDMR |= BA0_DMR_BEND;
  	switch (snd_pcm_format_width(runtime->format)) {
  	case 8: dma->valDMR |= BA0_DMR_SIZE8;
  		if (runtime->channels == 1)
  			dma->valDMR |= BA0_DMR_SWAPC;
  		break;
  	case 32: dma->valDMR |= BA0_DMR_SIZE20; break;
  	}
  	dma->frag = 0;	/* for workaround */
  	dma->valDCR = BA0_DCR_TCIE | BA0_DCR_MSK;
  	if (runtime->buffer_size != runtime->period_size)
  		dma->valDCR |= BA0_DCR_HTCIE;
  	/* Initialize DMA */
  	snd_cs4281_pokeBA0(chip, dma->regDBA, runtime->dma_addr);
  	snd_cs4281_pokeBA0(chip, dma->regDBC, runtime->buffer_size - 1);
  	rec_mono = (chip->dma[1].valDMR & BA0_DMR_MONO) == BA0_DMR_MONO;
  	snd_cs4281_pokeBA0(chip, BA0_SRCSA, (chip->src_left_play_slot << 0) |
  					    (chip->src_right_play_slot << 8) |
  					    (chip->src_left_rec_slot << 16) |
  					    ((rec_mono ? 31 : chip->src_right_rec_slot) << 24));
  	if (!src)
  		goto __skip_src;
  	if (!capture) {
  		if (dma->left_slot == chip->src_left_play_slot) {
  			unsigned int val = snd_cs4281_rate(runtime->rate, NULL);
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
743
  			snd_BUG_ON(dma->right_slot != chip->src_right_play_slot);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
745
746
747
748
  			snd_cs4281_pokeBA0(chip, BA0_DACSR, val);
  		}
  	} else {
  		if (dma->left_slot == chip->src_left_rec_slot) {
  			unsigned int val = snd_cs4281_rate(runtime->rate, NULL);
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
749
  			snd_BUG_ON(dma->right_slot != chip->src_right_rec_slot);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
  			snd_cs4281_pokeBA0(chip, BA0_ADCSR, val);
  		}
  	}
        __skip_src:
  	/* Deactivate wave playback FIFO before changing slot assignments */
  	if (dma->regFCR == BA0_FCR0)
  		snd_cs4281_pokeBA0(chip, dma->regFCR, snd_cs4281_peekBA0(chip, dma->regFCR) & ~BA0_FCR_FEN);
  	/* Initialize FIFO */
  	dma->valFCR = BA0_FCR_LS(dma->left_slot) |
  		      BA0_FCR_RS(capture && (dma->valDMR & BA0_DMR_MONO) ? 31 : dma->right_slot) |
  		      BA0_FCR_SZ(CS4281_FIFO_SIZE) |
  		      BA0_FCR_OF(dma->fifo_offset);
  	snd_cs4281_pokeBA0(chip, dma->regFCR, dma->valFCR | (capture ? BA0_FCR_PSH : 0));
  	/* Activate FIFO again for FM playback */
  	if (dma->regFCR == BA0_FCR0)
  		snd_cs4281_pokeBA0(chip, dma->regFCR, dma->valFCR | BA0_FCR_FEN);
  	/* Clear FIFO Status and Interrupt Control Register */
  	snd_cs4281_pokeBA0(chip, dma->regFSIC, 0);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
769
  static int snd_cs4281_playback_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
770
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
771
772
773
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct cs4281_dma *dma = runtime->private_data;
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
774
775
776
777
778
779
  
  	spin_lock_irq(&chip->reg_lock);
  	snd_cs4281_mode(chip, dma, runtime, 0, 1);
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
780
  static int snd_cs4281_capture_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
781
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
782
783
784
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct cs4281_dma *dma = runtime->private_data;
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
785
786
787
788
789
790
  
  	spin_lock_irq(&chip->reg_lock);
  	snd_cs4281_mode(chip, dma, runtime, 1, 1);
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
791
  static snd_pcm_uframes_t snd_cs4281_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
792
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
793
794
795
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct cs4281_dma *dma = runtime->private_data;
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
796

ee419653a   Takashi Iwai   ALSA: Fix missing...
797
  	/*
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
798
799
800
801
  	dev_dbg(chip->card->dev,
  		"DCC = 0x%x, buffer_size = 0x%x, jiffies = %li
  ",
  		snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size,
ee419653a   Takashi Iwai   ALSA: Fix missing...
802
803
  	       jiffies);
  	*/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
804
805
806
  	return runtime->buffer_size -
  	       snd_cs4281_peekBA0(chip, dma->regDCC) - 1;
  }
dee49895b   Bhumika Goyal   ALSA: pci: make s...
807
  static const struct snd_pcm_hardware snd_cs4281_playback =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
808
  {
b83f346bc   Clemens Ladisch   [ALSA] remove inc...
809
810
811
812
813
  	.info =			SNDRV_PCM_INFO_MMAP |
  				SNDRV_PCM_INFO_INTERLEAVED |
  				SNDRV_PCM_INFO_MMAP_VALID |
  				SNDRV_PCM_INFO_PAUSE |
  				SNDRV_PCM_INFO_RESUME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
  				SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
  				SNDRV_PCM_FMTBIT_U16_BE | SNDRV_PCM_FMTBIT_S16_BE |
  				SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_S32_LE |
  				SNDRV_PCM_FMTBIT_U32_BE | SNDRV_PCM_FMTBIT_S32_BE,
  	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		4000,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(512*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(512*1024),
  	.periods_min =		1,
  	.periods_max =		2,
  	.fifo_size =		CS4281_FIFO_SIZE,
  };
dee49895b   Bhumika Goyal   ALSA: pci: make s...
831
  static const struct snd_pcm_hardware snd_cs4281_capture =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
832
  {
b83f346bc   Clemens Ladisch   [ALSA] remove inc...
833
834
835
836
837
  	.info =			SNDRV_PCM_INFO_MMAP |
  				SNDRV_PCM_INFO_INTERLEAVED |
  				SNDRV_PCM_INFO_MMAP_VALID |
  				SNDRV_PCM_INFO_PAUSE |
  				SNDRV_PCM_INFO_RESUME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
  				SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
  				SNDRV_PCM_FMTBIT_U16_BE | SNDRV_PCM_FMTBIT_S16_BE |
  				SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_S32_LE |
  				SNDRV_PCM_FMTBIT_U32_BE | SNDRV_PCM_FMTBIT_S32_BE,
  	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		4000,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(512*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(512*1024),
  	.periods_min =		1,
  	.periods_max =		2,
  	.fifo_size =		CS4281_FIFO_SIZE,
  };
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
855
  static int snd_cs4281_playback_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
856
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
857
858
859
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct cs4281_dma *dma;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
860
861
862
863
864
865
866
  
  	dma = &chip->dma[0];
  	dma->substream = substream;
  	dma->left_slot = 0;
  	dma->right_slot = 1;
  	runtime->private_data = dma;
  	runtime->hw = snd_cs4281_playback;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
867
868
869
870
871
872
  	/* should be detected from the AC'97 layer, but it seems
  	   that although CS4297A rev B reports 18-bit ADC resolution,
  	   samples are 20-bit */
  	snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
873
  static int snd_cs4281_capture_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
874
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
875
876
877
  	struct cs4281 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
  	struct cs4281_dma *dma;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
878
879
880
881
882
883
884
  
  	dma = &chip->dma[1];
  	dma->substream = substream;
  	dma->left_slot = 10;
  	dma->right_slot = 11;
  	runtime->private_data = dma;
  	runtime->hw = snd_cs4281_capture;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
886
887
888
889
890
  	/* should be detected from the AC'97 layer, but it seems
  	   that although CS4297A rev B reports 18-bit ADC resolution,
  	   samples are 20-bit */
  	snd_pcm_hw_constraint_msbits(runtime, 0, 32, 20);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
891
  static int snd_cs4281_playback_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
892
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
893
  	struct cs4281_dma *dma = substream->runtime->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
894
895
896
897
  
  	dma->substream = NULL;
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
898
  static int snd_cs4281_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
899
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
900
  	struct cs4281_dma *dma = substream->runtime->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
901
902
903
904
  
  	dma->substream = NULL;
  	return 0;
  }
6769e988b   Julia Lawall   ALSA: constify sn...
905
  static const struct snd_pcm_ops snd_cs4281_playback_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
906
907
  	.open =		snd_cs4281_playback_open,
  	.close =	snd_cs4281_playback_close,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
908
909
910
911
  	.prepare =	snd_cs4281_playback_prepare,
  	.trigger =	snd_cs4281_trigger,
  	.pointer =	snd_cs4281_pointer,
  };
6769e988b   Julia Lawall   ALSA: constify sn...
912
  static const struct snd_pcm_ops snd_cs4281_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
913
914
  	.open =		snd_cs4281_capture_open,
  	.close =	snd_cs4281_capture_close,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
915
916
917
918
  	.prepare =	snd_cs4281_capture_prepare,
  	.trigger =	snd_cs4281_trigger,
  	.pointer =	snd_cs4281_pointer,
  };
3e4f4776f   Lars-Peter Clausen   ALSA: cs4281: Rem...
919
  static int snd_cs4281_pcm(struct cs4281 *chip, int device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
920
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
921
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
922
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
923
924
925
926
927
928
929
930
  	err = snd_pcm_new(chip->card, "CS4281", device, 1, 1, &pcm);
  	if (err < 0)
  		return err;
  
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4281_playback_ops);
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4281_capture_ops);
  
  	pcm->private_data = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
931
932
933
  	pcm->info_flags = 0;
  	strcpy(pcm->name, "CS4281");
  	chip->pcm = pcm;
44e78a1a8   Takashi Iwai   ALSA: cs4281: Use...
934
935
  	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
  				       64*1024, 512*1024);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
936

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
937
938
939
940
941
942
943
944
  	return 0;
  }
  
  /*
   *  Mixer section
   */
  
  #define CS_VOL_MASK	0x1f
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
945
946
  static int snd_cs4281_info_volume(struct snd_kcontrol *kcontrol,
  				  struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
947
948
949
950
951
952
953
954
  {
  	uinfo->type              = SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count             = 2;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = CS_VOL_MASK;
  	return 0;
  }
   
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
955
956
  static int snd_cs4281_get_volume(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
957
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
958
  	struct cs4281 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
959
960
961
962
963
964
965
966
967
968
969
  	int regL = (kcontrol->private_value >> 16) & 0xffff;
  	int regR = kcontrol->private_value & 0xffff;
  	int volL, volR;
  
  	volL = CS_VOL_MASK - (snd_cs4281_peekBA0(chip, regL) & CS_VOL_MASK);
  	volR = CS_VOL_MASK - (snd_cs4281_peekBA0(chip, regR) & CS_VOL_MASK);
  
  	ucontrol->value.integer.value[0] = volL;
  	ucontrol->value.integer.value[1] = volR;
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
970
971
  static int snd_cs4281_put_volume(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
972
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
973
  	struct cs4281 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
974
975
976
977
978
979
980
981
982
983
984
985
986
  	int change = 0;
  	int regL = (kcontrol->private_value >> 16) & 0xffff;
  	int regR = kcontrol->private_value & 0xffff;
  	int volL, volR;
  
  	volL = CS_VOL_MASK - (snd_cs4281_peekBA0(chip, regL) & CS_VOL_MASK);
  	volR = CS_VOL_MASK - (snd_cs4281_peekBA0(chip, regR) & CS_VOL_MASK);
  
  	if (ucontrol->value.integer.value[0] != volL) {
  		volL = CS_VOL_MASK - (ucontrol->value.integer.value[0] & CS_VOL_MASK);
  		snd_cs4281_pokeBA0(chip, regL, volL);
  		change = 1;
  	}
e860f0004   Takashi Iwai   [ALSA] cs4281 - F...
987
  	if (ucontrol->value.integer.value[1] != volR) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
988
989
990
991
992
993
  		volR = CS_VOL_MASK - (ucontrol->value.integer.value[1] & CS_VOL_MASK);
  		snd_cs4281_pokeBA0(chip, regR, volR);
  		change = 1;
  	}
  	return change;
  }
0cb29ea0d   Takashi Iwai   [ALSA] Add even m...
994
  static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -4650, 150, 0);
9f6ab2506   Takashi Iwai   [ALSA] Add dB sca...
995

f3b827e0b   Bhumika Goyal   ALSA: pci: consti...
996
  static const struct snd_kcontrol_new snd_cs4281_fm_vol =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
997
998
999
1000
1001
1002
1003
  {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Synth Playback Volume",
  	.info = snd_cs4281_info_volume, 
  	.get = snd_cs4281_get_volume,
  	.put = snd_cs4281_put_volume, 
  	.private_value = ((BA0_FMLVC << 16) | BA0_FMRVC),
9f6ab2506   Takashi Iwai   [ALSA] Add dB sca...
1004
  	.tlv = { .p = db_scale_dsp },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1005
  };
f3b827e0b   Bhumika Goyal   ALSA: pci: consti...
1006
  static const struct snd_kcontrol_new snd_cs4281_pcm_vol =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1007
1008
1009
1010
1011
1012
1013
  {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "PCM Stream Playback Volume",
  	.info = snd_cs4281_info_volume, 
  	.get = snd_cs4281_get_volume,
  	.put = snd_cs4281_put_volume, 
  	.private_value = ((BA0_PPLVC << 16) | BA0_PPRVC),
9f6ab2506   Takashi Iwai   [ALSA] Add dB sca...
1014
  	.tlv = { .p = db_scale_dsp },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1015
  };
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1016
  static void snd_cs4281_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1017
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1018
  	struct cs4281 *chip = bus->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1019
1020
  	chip->ac97_bus = NULL;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1021
  static void snd_cs4281_mixer_free_ac97(struct snd_ac97 *ac97)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1023
  	struct cs4281 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1024
1025
1026
1027
1028
  	if (ac97->num)
  		chip->ac97_secondary = NULL;
  	else
  		chip->ac97 = NULL;
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1029
  static int snd_cs4281_mixer(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1030
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1031
1032
  	struct snd_card *card = chip->card;
  	struct snd_ac97_template ac97;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1033
  	int err;
51055da51   Takashi Iwai   ALSA: pci: Consti...
1034
  	static const struct snd_ac97_bus_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
  		.write = snd_cs4281_ac97_write,
  		.read = snd_cs4281_ac97_read,
  	};
  
  	if ((err = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus)) < 0)
  		return err;
  	chip->ac97_bus->private_free = snd_cs4281_mixer_free_ac97_bus;
  
  	memset(&ac97, 0, sizeof(ac97));
  	ac97.private_data = chip;
  	ac97.private_free = snd_cs4281_mixer_free_ac97;
  	if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
  		return err;
  	if (chip->dual_codec) {
  		ac97.num = 1;
  		if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_secondary)) < 0)
  			return err;
  	}
  	if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_fm_vol, chip))) < 0)
  		return err;
  	if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4281_pcm_vol, chip))) < 0)
  		return err;
  	return 0;
  }
  
  
  /*
   * proc interface
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1064
1065
  static void snd_cs4281_proc_read(struct snd_info_entry *entry, 
  				  struct snd_info_buffer *buffer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1066
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1067
  	struct cs4281 *chip = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1068
1069
1070
1071
1072
1073
1074
1075
1076
  
  	snd_iprintf(buffer, "Cirrus Logic CS4281
  
  ");
  	snd_iprintf(buffer, "Spurious half IRQs   : %u
  ", chip->spurious_dhtc_irq);
  	snd_iprintf(buffer, "Spurious end IRQs    : %u
  ", chip->spurious_dtc_irq);
  }
24e4a1211   Takashi Iwai   ALSA: info - Use ...
1077
1078
1079
1080
  static ssize_t snd_cs4281_BA0_read(struct snd_info_entry *entry,
  				   void *file_private_data,
  				   struct file *file, char __user *buf,
  				   size_t count, loff_t pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1081
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1082
  	struct cs4281 *chip = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1083
  	
d97e1b782   Takashi Iwai   ALSA: info - Chec...
1084
1085
1086
  	if (copy_to_user_fromio(buf, chip->ba0 + pos, count))
  		return -EFAULT;
  	return count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1087
  }
24e4a1211   Takashi Iwai   ALSA: info - Use ...
1088
1089
1090
1091
  static ssize_t snd_cs4281_BA1_read(struct snd_info_entry *entry,
  				   void *file_private_data,
  				   struct file *file, char __user *buf,
  				   size_t count, loff_t pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1092
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1093
  	struct cs4281 *chip = entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1094
  	
d97e1b782   Takashi Iwai   ALSA: info - Chec...
1095
1096
1097
  	if (copy_to_user_fromio(buf, chip->ba1 + pos, count))
  		return -EFAULT;
  	return count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1098
  }
d25ff2684   Takashi Iwai   ALSA: info: Make ...
1099
  static const struct snd_info_entry_ops snd_cs4281_proc_ops_BA0 = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1100
1101
  	.read = snd_cs4281_BA0_read,
  };
d25ff2684   Takashi Iwai   ALSA: info: Make ...
1102
  static const struct snd_info_entry_ops snd_cs4281_proc_ops_BA1 = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1103
1104
  	.read = snd_cs4281_BA1_read,
  };
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1105
  static void snd_cs4281_proc_init(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1106
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1107
  	struct snd_info_entry *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1108

47f2769b4   Takashi Iwai   ALSA: pci: Clean ...
1109
  	snd_card_ro_proc_new(chip->card, "cs4281", chip, snd_cs4281_proc_read);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
  	if (! snd_card_proc_new(chip->card, "cs4281_BA0", &entry)) {
  		entry->content = SNDRV_INFO_CONTENT_DATA;
  		entry->private_data = chip;
  		entry->c.ops = &snd_cs4281_proc_ops_BA0;
  		entry->size = CS4281_BA0_SIZE;
  	}
  	if (! snd_card_proc_new(chip->card, "cs4281_BA1", &entry)) {
  		entry->content = SNDRV_INFO_CONTENT_DATA;
  		entry->private_data = chip;
  		entry->c.ops = &snd_cs4281_proc_ops_BA1;
  		entry->size = CS4281_BA1_SIZE;
  	}
  }
  
  /*
   * joystick support
   */
b2fac0730   Fabian Frederick   ALSA: pci: don't ...
1127
  #if IS_REACHABLE(CONFIG_GAMEPORT)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1128
1129
1130
  
  static void snd_cs4281_gameport_trigger(struct gameport *gameport)
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1131
  	struct cs4281 *chip = gameport_get_port_data(gameport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1132

da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
1133
1134
  	if (snd_BUG_ON(!chip))
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1135
1136
1137
1138
1139
  	snd_cs4281_pokeBA0(chip, BA0_JSPT, 0xff);
  }
  
  static unsigned char snd_cs4281_gameport_read(struct gameport *gameport)
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1140
  	struct cs4281 *chip = gameport_get_port_data(gameport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1141

da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
1142
1143
  	if (snd_BUG_ON(!chip))
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1144
1145
1146
1147
  	return snd_cs4281_peekBA0(chip, BA0_JSPT);
  }
  
  #ifdef COOKED_MODE
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1148
1149
  static int snd_cs4281_gameport_cooked_read(struct gameport *gameport,
  					   int *axes, int *buttons)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1150
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1151
  	struct cs4281 *chip = gameport_get_port_data(gameport);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1152
1153
  	unsigned js1, js2, jst;
  	
da3cec35d   Takashi Iwai   ALSA: Kill snd_as...
1154
1155
  	if (snd_BUG_ON(!chip))
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
  
  	js1 = snd_cs4281_peekBA0(chip, BA0_JSC1);
  	js2 = snd_cs4281_peekBA0(chip, BA0_JSC2);
  	jst = snd_cs4281_peekBA0(chip, BA0_JSPT);
  	
  	*buttons = (~jst >> 4) & 0x0F; 
  	
  	axes[0] = ((js1 & JSC1_Y1V_MASK) >> JSC1_Y1V_SHIFT) & 0xFFFF;
  	axes[1] = ((js1 & JSC1_X1V_MASK) >> JSC1_X1V_SHIFT) & 0xFFFF;
  	axes[2] = ((js2 & JSC2_Y2V_MASK) >> JSC2_Y2V_SHIFT) & 0xFFFF;
  	axes[3] = ((js2 & JSC2_X2V_MASK) >> JSC2_X2V_SHIFT) & 0xFFFF;
  
  	for (jst = 0; jst < 4; ++jst)
  		if (axes[jst] == 0xFFFF) axes[jst] = -1;
  	return 0;
  }
  #else
  #define snd_cs4281_gameport_cooked_read	NULL
  #endif
  
  static int snd_cs4281_gameport_open(struct gameport *gameport, int mode)
  {
  	switch (mode) {
  #ifdef COOKED_MODE
  	case GAMEPORT_MODE_COOKED:
  		return 0;
  #endif
  	case GAMEPORT_MODE_RAW:
  		return 0;
  	default:
  		return -1;
  	}
  	return 0;
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1190
  static int snd_cs4281_create_gameport(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1191
1192
1193
1194
1195
  {
  	struct gameport *gp;
  
  	chip->gameport = gp = gameport_allocate_port();
  	if (!gp) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1196
1197
1198
  		dev_err(chip->card->dev,
  			"cannot allocate memory for gameport
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
  		return -ENOMEM;
  	}
  
  	gameport_set_name(gp, "CS4281 Gameport");
  	gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
  	gameport_set_dev_parent(gp, &chip->pci->dev);
  	gp->open = snd_cs4281_gameport_open;
  	gp->read = snd_cs4281_gameport_read;
  	gp->trigger = snd_cs4281_gameport_trigger;
  	gp->cooked_read = snd_cs4281_gameport_cooked_read;
  	gameport_set_port_data(gp, chip);
  
  	snd_cs4281_pokeBA0(chip, BA0_JSIO, 0xFF); // ?
  	snd_cs4281_pokeBA0(chip, BA0_JSCTL, JSCTL_SP_MEDIUM_SLOW);
  
  	gameport_register_port(gp);
  
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1218
  static void snd_cs4281_free_gameport(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1219
1220
1221
1222
1223
1224
1225
  {
  	if (chip->gameport) {
  		gameport_unregister_port(chip->gameport);
  		chip->gameport = NULL;
  	}
  }
  #else
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1226
1227
  static inline int snd_cs4281_create_gameport(struct cs4281 *chip) { return -ENOSYS; }
  static inline void snd_cs4281_free_gameport(struct cs4281 *chip) { }
667011706   Takashi Iwai   ALSA: cs4281: Fix...
1228
  #endif /* IS_REACHABLE(CONFIG_GAMEPORT) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1229

93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1230
  static int snd_cs4281_free(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1231
1232
  {
  	snd_cs4281_free_gameport(chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1233
1234
1235
1236
1237
1238
1239
  	/* Mask interrupts */
  	snd_cs4281_pokeBA0(chip, BA0_HIMR, 0x7fffffff);
  	/* Stop the DLL Clock logic. */
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, 0);
  	/* Sound System Power Management - Turn Everything OFF */
  	snd_cs4281_pokeBA0(chip, BA0_SSPM, 0);
  	/* PCI interface - D3 state */
db10e7fbb   Yijing Wang   ALSA: pci: trivia...
1240
  	pci_set_power_state(chip->pci, PCI_D3hot);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1241
1242
  
  	if (chip->irq >= 0)
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1243
  		free_irq(chip->irq, chip);
ff6defa6a   Markus Elfring   ALSA: Deletion of...
1244
1245
  	iounmap(chip->ba0);
  	iounmap(chip->ba1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1246
1247
1248
1249
1250
1251
  	pci_release_regions(chip->pci);
  	pci_disable_device(chip->pci);
  
  	kfree(chip);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1252
  static int snd_cs4281_dev_free(struct snd_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1253
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1254
  	struct cs4281 *chip = device->device_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1255
1256
  	return snd_cs4281_free(chip);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1257
  static int snd_cs4281_chip_init(struct cs4281 *chip); /* defined below */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1258

e23e7a143   Bill Pemberton   ALSA: pci: remove...
1259
1260
1261
1262
  static int snd_cs4281_create(struct snd_card *card,
  			     struct pci_dev *pci,
  			     struct cs4281 **rchip,
  			     int dual_codec)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1263
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1264
  	struct cs4281 *chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1265
1266
  	unsigned int tmp;
  	int err;
efb0ad25d   Takashi Iwai   ALSA: pci: Consti...
1267
  	static const struct snd_device_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1268
1269
1270
1271
1272
1273
  		.dev_free =	snd_cs4281_dev_free,
  	};
  
  	*rchip = NULL;
  	if ((err = pci_enable_device(pci)) < 0)
  		return err;
e560d8d83   Takashi Iwai   [ALSA] Replace wi...
1274
  	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
  	if (chip == NULL) {
  		pci_disable_device(pci);
  		return -ENOMEM;
  	}
  	spin_lock_init(&chip->reg_lock);
  	chip->card = card;
  	chip->pci = pci;
  	chip->irq = -1;
  	pci_set_master(pci);
  	if (dual_codec < 0 || dual_codec > 3) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1285
1286
  		dev_err(card->dev, "invalid dual_codec option %d
  ", dual_codec);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
  		dual_codec = 0;
  	}
  	chip->dual_codec = dual_codec;
  
  	if ((err = pci_request_regions(pci, "CS4281")) < 0) {
  		kfree(chip);
  		pci_disable_device(pci);
  		return err;
  	}
  	chip->ba0_addr = pci_resource_start(pci, 0);
  	chip->ba1_addr = pci_resource_start(pci, 1);
2f5ad54ea   Arjan van de Ven   pci: use pci_iore...
1298
1299
  	chip->ba0 = pci_ioremap_bar(pci, 0);
  	chip->ba1 = pci_ioremap_bar(pci, 1);
688956f23   Takashi Iwai   [ALSA] Fix races ...
1300
1301
1302
1303
1304
  	if (!chip->ba0 || !chip->ba1) {
  		snd_cs4281_free(chip);
  		return -ENOMEM;
  	}
  	
437a5a460   Takashi Iwai   [ALSA] Remove IRQ...
1305
  	if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED,
934c2b6d0   Takashi Iwai   ALSA: use KBUILD_...
1306
  			KBUILD_MODNAME, chip)) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1307
1308
  		dev_err(card->dev, "unable to grab IRQ %d
  ", pci->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1309
1310
1311
1312
  		snd_cs4281_free(chip);
  		return -ENOMEM;
  	}
  	chip->irq = pci->irq;
5afff8c1b   Takashi Iwai   ALSA: cs4281: Sup...
1313
  	card->sync_irq = chip->irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1314

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
  	tmp = snd_cs4281_chip_init(chip);
  	if (tmp) {
  		snd_cs4281_free(chip);
  		return tmp;
  	}
  
  	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  		snd_cs4281_free(chip);
  		return err;
  	}
  
  	snd_cs4281_proc_init(chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1327
1328
1329
  	*rchip = chip;
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1330
  static int snd_cs4281_chip_init(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1331
1332
  {
  	unsigned int tmp;
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1333
  	unsigned long end_time;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1334
  	int retry_count = 2;
a488e0338   Arnaud Patard   [ALSA] cs4281 - f...
1335
1336
1337
1338
  	/* Having EPPMC.FPDN=1 prevent proper chip initialisation */
  	tmp = snd_cs4281_peekBA0(chip, BA0_EPPMC);
  	if (tmp & BA0_EPPMC_FPDN)
  		snd_cs4281_pokeBA0(chip, BA0_EPPMC, tmp & ~BA0_EPPMC_FPDN);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1339
1340
1341
1342
1343
1344
        __retry:
  	tmp = snd_cs4281_peekBA0(chip, BA0_CFLR);
  	if (tmp != BA0_CFLR_DEFAULT) {
  		snd_cs4281_pokeBA0(chip, BA0_CFLR, BA0_CFLR_DEFAULT);
  		tmp = snd_cs4281_peekBA0(chip, BA0_CFLR);
  		if (tmp != BA0_CFLR_DEFAULT) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1345
1346
1347
  			dev_err(chip->card->dev,
  				"CFLR setup failed (0x%x)
  ", tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
  			return -EIO;
  		}
  	}
  
  	/* Set the 'Configuration Write Protect' register
  	 * to 4281h.  Allows vendor-defined configuration
           * space between 0e4h and 0ffh to be written. */	
  	snd_cs4281_pokeBA0(chip, BA0_CWPR, 0x4281);
  	
  	if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC1)) != (BA0_SERC1_SO1EN | BA0_SERC1_AC97)) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1358
1359
1360
  		dev_err(chip->card->dev,
  			"SERC1 AC'97 check failed (0x%x)
  ", tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1361
1362
1363
  		return -EIO;
  	}
  	if ((tmp = snd_cs4281_peekBA0(chip, BA0_SERC2)) != (BA0_SERC2_SI1EN | BA0_SERC2_AC97)) {
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1364
1365
1366
  		dev_err(chip->card->dev,
  			"SERC2 AC'97 check failed (0x%x)
  ", tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
  		return -EIO;
  	}
  
  	/* Sound System Power Management */
  	snd_cs4281_pokeBA0(chip, BA0_SSPM, BA0_SSPM_MIXEN | BA0_SSPM_CSRCEN |
  				           BA0_SSPM_PSRCEN | BA0_SSPM_JSEN |
  				           BA0_SSPM_ACLEN | BA0_SSPM_FMEN);
  
  	/* Serial Port Power Management */
   	/* Blast the clock control register to zero so that the
           * PLL starts out in a known state, and blast the master serial
           * port control register to zero so that the serial ports also
           * start out in a known state. */
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, 0);
  	snd_cs4281_pokeBA0(chip, BA0_SERMC, 0);
  
          /* Make ESYN go to zero to turn off
           * the Sync pulse on the AC97 link. */
  	snd_cs4281_pokeBA0(chip, BA0_ACCTL, 0);
  	udelay(50);
                  
  	/*  Drive the ARST# pin low for a minimum of 1uS (as defined in the AC97
  	 *  spec) and then drive it high.  This is done for non AC97 modes since
  	 *  there might be logic external to the CS4281 that uses the ARST# line
  	 *  for a reset. */
  	snd_cs4281_pokeBA0(chip, BA0_SPMC, 0);
  	udelay(50);
  	snd_cs4281_pokeBA0(chip, BA0_SPMC, BA0_SPMC_RSTN);
c9a49bb19   Takashi Iwai   [ALSA] cs4281 - C...
1395
  	msleep(50);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
  
  	if (chip->dual_codec)
  		snd_cs4281_pokeBA0(chip, BA0_SPMC, BA0_SPMC_RSTN | BA0_SPMC_ASDI2E);
  
  	/*
  	 *  Set the serial port timing configuration.
  	 */
  	snd_cs4281_pokeBA0(chip, BA0_SERMC,
  			   (chip->dual_codec ? BA0_SERMC_TCID(chip->dual_codec) : BA0_SERMC_TCID(1)) |
  			   BA0_SERMC_PTC_AC97 | BA0_SERMC_MSPE);
  
  	/*
  	 *  Start the DLL Clock logic.
  	 */
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, BA0_CLKCR1_DLLP);
c9a49bb19   Takashi Iwai   [ALSA] cs4281 - C...
1411
  	msleep(50);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1412
1413
1414
1415
1416
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, BA0_CLKCR1_SWCE | BA0_CLKCR1_DLLP);
  
  	/*
  	 * Wait for the DLL ready signal from the clock logic.
  	 */
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1417
  	end_time = jiffies + HZ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1418
1419
1420
1421
1422
1423
1424
  	do {
  		/*
  		 *  Read the AC97 status register to see if we've seen a CODEC
  		 *  signal from the AC97 codec.
  		 */
  		if (snd_cs4281_peekBA0(chip, BA0_CLKCR1) & BA0_CLKCR1_DLLRDY)
  			goto __ok0;
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1425
1426
  		schedule_timeout_uninterruptible(1);
  	} while (time_after_eq(end_time, jiffies));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1427

b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1428
1429
  	dev_err(chip->card->dev, "DLLRDY not seen
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
  	return -EIO;
  
        __ok0:
  
  	/*
  	 *  The first thing we do here is to enable sync generation.  As soon
  	 *  as we start receiving bit clock, we'll start producing the SYNC
  	 *  signal.
  	 */
  	snd_cs4281_pokeBA0(chip, BA0_ACCTL, BA0_ACCTL_ESYN);
  
  	/*
  	 * Wait for the codec ready signal from the AC97 codec.
  	 */
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1444
  	end_time = jiffies + HZ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1445
1446
1447
1448
1449
1450
1451
  	do {
  		/*
  		 *  Read the AC97 status register to see if we've seen a CODEC
  		 *  signal from the AC97 codec.
  		 */
  		if (snd_cs4281_peekBA0(chip, BA0_ACSTS) & BA0_ACSTS_CRDY)
  			goto __ok1;
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1452
1453
  		schedule_timeout_uninterruptible(1);
  	} while (time_after_eq(end_time, jiffies));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1454

b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1455
1456
1457
1458
  	dev_err(chip->card->dev,
  		"never read codec ready from AC'97 (0x%x)
  ",
  		snd_cs4281_peekBA0(chip, BA0_ACSTS));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1459
1460
1461
1462
  	return -EIO;
  
        __ok1:
  	if (chip->dual_codec) {
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1463
  		end_time = jiffies + HZ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1464
1465
1466
  		do {
  			if (snd_cs4281_peekBA0(chip, BA0_ACSTS2) & BA0_ACSTS_CRDY)
  				goto __codec2_ok;
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1467
1468
  			schedule_timeout_uninterruptible(1);
  		} while (time_after_eq(end_time, jiffies));
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1469
1470
1471
  		dev_info(chip->card->dev,
  			 "secondary codec doesn't respond. disable it...
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
  		chip->dual_codec = 0;
  	__codec2_ok: ;
  	}
  
  	/*
  	 *  Assert the valid frame signal so that we can start sending commands
  	 *  to the AC97 codec.
  	 */
  
  	snd_cs4281_pokeBA0(chip, BA0_ACCTL, BA0_ACCTL_VFRM | BA0_ACCTL_ESYN);
  
  	/*
  	 *  Wait until we've sampled input slots 3 and 4 as valid, meaning that
  	 *  the codec is pumping ADC data across the AC-link.
  	 */
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1487
  	end_time = jiffies + HZ;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1488
1489
1490
1491
1492
1493
1494
  	do {
  		/*
  		 *  Read the input slot valid register and see if input slots 3
  		 *  4 are valid yet.
  		 */
                  if ((snd_cs4281_peekBA0(chip, BA0_ACISV) & (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4))) == (BA0_ACISV_SLV(3) | BA0_ACISV_SLV(4)))
                          goto __ok2;
38223daa1   Takashi Iwai   [ALSA] cs4281 - F...
1495
1496
  		schedule_timeout_uninterruptible(1);
  	} while (time_after_eq(end_time, jiffies));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1497
1498
1499
  
  	if (--retry_count > 0)
  		goto __retry;
b055e7b48   Takashi Iwai   ALSA: cs4281: Use...
1500
1501
  	dev_err(chip->card->dev, "never read ISV3 and ISV4 from AC'97
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
  	return -EIO;
  
        __ok2:
  
  	/*
  	 *  Now, assert valid frame and the slot 3 and 4 valid bits.  This will
  	 *  commense the transfer of digital audio data to the AC97 codec.
  	 */
  	snd_cs4281_pokeBA0(chip, BA0_ACOSV, BA0_ACOSV_SLV(3) | BA0_ACOSV_SLV(4));
  
  	/*
  	 *  Initialize DMA structures
  	 */
  	for (tmp = 0; tmp < 4; tmp++) {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1516
  		struct cs4281_dma *dma = &chip->dma[tmp];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
  		dma->regDBA = BA0_DBA0 + (tmp * 0x10);
  		dma->regDCA = BA0_DCA0 + (tmp * 0x10);
  		dma->regDBC = BA0_DBC0 + (tmp * 0x10);
  		dma->regDCC = BA0_DCC0 + (tmp * 0x10);
  		dma->regDMR = BA0_DMR0 + (tmp * 8);
  		dma->regDCR = BA0_DCR0 + (tmp * 8);
  		dma->regHDSR = BA0_HDSR0 + (tmp * 4);
  		dma->regFCR = BA0_FCR0 + (tmp * 4);
  		dma->regFSIC = BA0_FSIC0 + (tmp * 4);
  		dma->fifo_offset = tmp * CS4281_FIFO_SIZE;
  		snd_cs4281_pokeBA0(chip, dma->regFCR,
  				   BA0_FCR_LS(31) |
  				   BA0_FCR_RS(31) |
  				   BA0_FCR_SZ(CS4281_FIFO_SIZE) |
  				   BA0_FCR_OF(dma->fifo_offset));
  	}
  
  	chip->src_left_play_slot = 0;	/* AC'97 left PCM playback (3) */
  	chip->src_right_play_slot = 1;	/* AC'97 right PCM playback (4) */
  	chip->src_left_rec_slot = 10;	/* AC'97 left PCM record (3) */
  	chip->src_right_rec_slot = 11;	/* AC'97 right PCM record (4) */
  
  	/* Activate wave playback FIFO for FM playback */
  	chip->dma[0].valFCR = BA0_FCR_FEN | BA0_FCR_LS(0) |
  		              BA0_FCR_RS(1) |
   	  	              BA0_FCR_SZ(CS4281_FIFO_SIZE) |
  		              BA0_FCR_OF(chip->dma[0].fifo_offset);
  	snd_cs4281_pokeBA0(chip, chip->dma[0].regFCR, chip->dma[0].valFCR);
  	snd_cs4281_pokeBA0(chip, BA0_SRCSA, (chip->src_left_play_slot << 0) |
  					    (chip->src_right_play_slot << 8) |
  					    (chip->src_left_rec_slot << 16) |
  					    (chip->src_right_rec_slot << 24));
  
  	/* Initialize digital volume */
  	snd_cs4281_pokeBA0(chip, BA0_PPLVC, 0);
  	snd_cs4281_pokeBA0(chip, BA0_PPRVC, 0);
  
  	/* Enable IRQs */
  	snd_cs4281_pokeBA0(chip, BA0_HICR, BA0_HICR_EOI);
  	/* Unmask interrupts */
  	snd_cs4281_pokeBA0(chip, BA0_HIMR, 0x7fffffff & ~(
  					BA0_HISR_MIDI |
  					BA0_HISR_DMAI |
  					BA0_HISR_DMA(0) |
  					BA0_HISR_DMA(1) |
  					BA0_HISR_DMA(2) |
  					BA0_HISR_DMA(3)));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1564
1565
1566
1567
1568
1569
1570
  
  	return 0;
  }
  
  /*
   *  MIDI section
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1571
  static void snd_cs4281_midi_reset(struct cs4281 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1572
1573
1574
1575
1576
  {
  	snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr | BA0_MIDCR_MRST);
  	udelay(100);
  	snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1577
  static int snd_cs4281_midi_input_open(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1578
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1579
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
  
  	spin_lock_irq(&chip->reg_lock);
   	chip->midcr |= BA0_MIDCR_RXE;
  	chip->midi_input = substream;
  	if (!(chip->uartm & CS4281_MODE_OUTPUT)) {
  		snd_cs4281_midi_reset(chip);
  	} else {
  		snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  	}
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1592
  static int snd_cs4281_midi_input_close(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1593
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1594
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
  
  	spin_lock_irq(&chip->reg_lock);
  	chip->midcr &= ~(BA0_MIDCR_RXE | BA0_MIDCR_RIE);
  	chip->midi_input = NULL;
  	if (!(chip->uartm & CS4281_MODE_OUTPUT)) {
  		snd_cs4281_midi_reset(chip);
  	} else {
  		snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  	}
  	chip->uartm &= ~CS4281_MODE_INPUT;
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1608
  static int snd_cs4281_midi_output_open(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1609
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1610
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
  
  	spin_lock_irq(&chip->reg_lock);
  	chip->uartm |= CS4281_MODE_OUTPUT;
  	chip->midcr |= BA0_MIDCR_TXE;
  	chip->midi_output = substream;
  	if (!(chip->uartm & CS4281_MODE_INPUT)) {
  		snd_cs4281_midi_reset(chip);
  	} else {
  		snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  	}
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1624
  static int snd_cs4281_midi_output_close(struct snd_rawmidi_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1625
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1626
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
  
  	spin_lock_irq(&chip->reg_lock);
  	chip->midcr &= ~(BA0_MIDCR_TXE | BA0_MIDCR_TIE);
  	chip->midi_output = NULL;
  	if (!(chip->uartm & CS4281_MODE_INPUT)) {
  		snd_cs4281_midi_reset(chip);
  	} else {
  		snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  	}
  	chip->uartm &= ~CS4281_MODE_OUTPUT;
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1640
  static void snd_cs4281_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1641
1642
  {
  	unsigned long flags;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1643
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
  
  	spin_lock_irqsave(&chip->reg_lock, flags);
  	if (up) {
  		if ((chip->midcr & BA0_MIDCR_RIE) == 0) {
  			chip->midcr |= BA0_MIDCR_RIE;
  			snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  		}
  	} else {
  		if (chip->midcr & BA0_MIDCR_RIE) {
  			chip->midcr &= ~BA0_MIDCR_RIE;
  			snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  		}
  	}
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
  }
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1659
  static void snd_cs4281_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1660
1661
  {
  	unsigned long flags;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1662
  	struct cs4281 *chip = substream->rmidi->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
  	unsigned char byte;
  
  	spin_lock_irqsave(&chip->reg_lock, flags);
  	if (up) {
  		if ((chip->midcr & BA0_MIDCR_TIE) == 0) {
  			chip->midcr |= BA0_MIDCR_TIE;
  			/* fill UART FIFO buffer at first, and turn Tx interrupts only if necessary */
  			while ((chip->midcr & BA0_MIDCR_TIE) &&
  			       (snd_cs4281_peekBA0(chip, BA0_MIDSR) & BA0_MIDSR_TBF) == 0) {
  				if (snd_rawmidi_transmit(substream, &byte, 1) != 1) {
  					chip->midcr &= ~BA0_MIDCR_TIE;
  				} else {
  					snd_cs4281_pokeBA0(chip, BA0_MIDWP, byte);
  				}
  			}
  			snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  		}
  	} else {
  		if (chip->midcr & BA0_MIDCR_TIE) {
  			chip->midcr &= ~BA0_MIDCR_TIE;
  			snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  		}
  	}
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
  }
485885b9d   Takashi Iwai   ALSA: pci: Consti...
1688
  static const struct snd_rawmidi_ops snd_cs4281_midi_output =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1689
1690
1691
1692
1693
  {
  	.open =		snd_cs4281_midi_output_open,
  	.close =	snd_cs4281_midi_output_close,
  	.trigger =	snd_cs4281_midi_output_trigger,
  };
485885b9d   Takashi Iwai   ALSA: pci: Consti...
1694
  static const struct snd_rawmidi_ops snd_cs4281_midi_input =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1695
1696
1697
1698
1699
  {
  	.open = 	snd_cs4281_midi_input_open,
  	.close =	snd_cs4281_midi_input_close,
  	.trigger =	snd_cs4281_midi_input_trigger,
  };
3e4f4776f   Lars-Peter Clausen   ALSA: cs4281: Rem...
1700
  static int snd_cs4281_midi(struct cs4281 *chip, int device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1701
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1702
  	struct snd_rawmidi *rmidi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1703
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1704
1705
1706
1707
1708
1709
1710
1711
  	if ((err = snd_rawmidi_new(chip->card, "CS4281", device, 1, 1, &rmidi)) < 0)
  		return err;
  	strcpy(rmidi->name, "CS4281");
  	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_cs4281_midi_output);
  	snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_cs4281_midi_input);
  	rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT | SNDRV_RAWMIDI_INFO_INPUT | SNDRV_RAWMIDI_INFO_DUPLEX;
  	rmidi->private_data = chip;
  	chip->rmidi = rmidi;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1712
1713
1714
1715
1716
1717
  	return 0;
  }
  
  /*
   *  Interrupt handler
   */
7d12e780e   David Howells   IRQ: Maintain reg...
1718
  static irqreturn_t snd_cs4281_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1719
  {
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1720
  	struct cs4281 *chip = dev_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1721
  	unsigned int status, dma, val;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1722
  	struct cs4281_dma *cdma;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
  
  	if (chip == NULL)
  		return IRQ_NONE;
  	status = snd_cs4281_peekBA0(chip, BA0_HISR);
  	if ((status & 0x7fffffff) == 0) {
  		snd_cs4281_pokeBA0(chip, BA0_HICR, BA0_HICR_EOI);
  		return IRQ_NONE;
  	}
  
  	if (status & (BA0_HISR_DMA(0)|BA0_HISR_DMA(1)|BA0_HISR_DMA(2)|BA0_HISR_DMA(3))) {
  		for (dma = 0; dma < 4; dma++)
  			if (status & BA0_HISR_DMA(dma)) {
  				cdma = &chip->dma[dma];
  				spin_lock(&chip->reg_lock);
  				/* ack DMA IRQ */
  				val = snd_cs4281_peekBA0(chip, cdma->regHDSR);
  				/* workaround, sometimes CS4281 acknowledges */
  				/* end or middle transfer position twice */
  				cdma->frag++;
  				if ((val & BA0_HDSR_DHTC) && !(cdma->frag & 1)) {
  					cdma->frag--;
  					chip->spurious_dhtc_irq++;
  					spin_unlock(&chip->reg_lock);
  					continue;
  				}
  				if ((val & BA0_HDSR_DTC) && (cdma->frag & 1)) {
  					cdma->frag--;
  					chip->spurious_dtc_irq++;
  					spin_unlock(&chip->reg_lock);
  					continue;
  				}
  				spin_unlock(&chip->reg_lock);
  				snd_pcm_period_elapsed(cdma->substream);
  			}
  	}
  
  	if ((status & BA0_HISR_MIDI) && chip->rmidi) {
  		unsigned char c;
  		
  		spin_lock(&chip->reg_lock);
  		while ((snd_cs4281_peekBA0(chip, BA0_MIDSR) & BA0_MIDSR_RBE) == 0) {
  			c = snd_cs4281_peekBA0(chip, BA0_MIDRP);
  			if ((chip->midcr & BA0_MIDCR_RIE) == 0)
  				continue;
  			snd_rawmidi_receive(chip->midi_input, &c, 1);
  		}
  		while ((snd_cs4281_peekBA0(chip, BA0_MIDSR) & BA0_MIDSR_TBF) == 0) {
  			if ((chip->midcr & BA0_MIDCR_TIE) == 0)
  				break;
  			if (snd_rawmidi_transmit(chip->midi_output, &c, 1) != 1) {
  				chip->midcr &= ~BA0_MIDCR_TIE;
  				snd_cs4281_pokeBA0(chip, BA0_MIDCR, chip->midcr);
  				break;
  			}
  			snd_cs4281_pokeBA0(chip, BA0_MIDWP, c);
  		}
  		spin_unlock(&chip->reg_lock);
  	}
  
  	/* EOI to the PCI part... reenables interrupts */
  	snd_cs4281_pokeBA0(chip, BA0_HICR, BA0_HICR_EOI);
  
  	return IRQ_HANDLED;
  }
  
  
  /*
   * OPL3 command
   */
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1792
1793
  static void snd_cs4281_opl3_command(struct snd_opl3 *opl3, unsigned short cmd,
  				    unsigned char val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1794
1795
  {
  	unsigned long flags;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1796
  	struct cs4281 *chip = opl3->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
  	void __iomem *port;
  
  	if (cmd & OPL3_RIGHT)
  		port = chip->ba0 + BA0_B1AP; /* right port */
  	else
  		port = chip->ba0 + BA0_B0AP; /* left port */
  
  	spin_lock_irqsave(&opl3->reg_lock, flags);
  
  	writel((unsigned int)cmd, port);
  	udelay(10);
  
  	writel((unsigned int)val, port + 4);
  	udelay(30);
  
  	spin_unlock_irqrestore(&opl3->reg_lock, flags);
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1814
1815
  static int snd_cs4281_probe(struct pci_dev *pci,
  			    const struct pci_device_id *pci_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1816
1817
  {
  	static int dev;
93e35f956   Takashi Iwai   [ALSA] Remove xxx...
1818
1819
1820
  	struct snd_card *card;
  	struct cs4281 *chip;
  	struct snd_opl3 *opl3;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1821
1822
1823
1824
1825
1826
1827
1828
  	int err;
  
          if (dev >= SNDRV_CARDS)
                  return -ENODEV;
  	if (!enable[dev]) {
  		dev++;
  		return -ENOENT;
  	}
60c5772b5   Takashi Iwai   ALSA: pci: Conver...
1829
1830
  	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  			   0, &card);
e58de7baf   Takashi Iwai   ALSA: Convert to ...
1831
1832
  	if (err < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1833
1834
1835
1836
1837
  
  	if ((err = snd_cs4281_create(card, pci, &chip, dual_codec[dev])) < 0) {
  		snd_card_free(card);
  		return err;
  	}
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1838
  	card->private_data = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1839
1840
1841
1842
1843
  
  	if ((err = snd_cs4281_mixer(chip)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
3e4f4776f   Lars-Peter Clausen   ALSA: cs4281: Rem...
1844
  	if ((err = snd_cs4281_pcm(chip, 0)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1845
1846
1847
  		snd_card_free(card);
  		return err;
  	}
3e4f4776f   Lars-Peter Clausen   ALSA: cs4281: Rem...
1848
  	if ((err = snd_cs4281_midi(chip, 0)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_opl3_new(card, OPL3_HW_OPL3_CS4281, &opl3)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	opl3->private_data = chip;
  	opl3->command = snd_cs4281_opl3_command;
  	snd_opl3_init(opl3);
  	if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	snd_cs4281_create_gameport(chip);
  	strcpy(card->driver, "CS4281");
  	strcpy(card->shortname, "Cirrus Logic CS4281");
  	sprintf(card->longname, "%s at 0x%lx, irq %d",
  		card->shortname,
  		chip->ba0_addr,
  		chip->irq);
  
  	if ((err = snd_card_register(card)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  
  	pci_set_drvdata(pci, card);
  	dev++;
  	return 0;
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1880
  static void snd_cs4281_remove(struct pci_dev *pci)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1881
1882
  {
  	snd_card_free(pci_get_drvdata(pci));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1883
1884
1885
1886
1887
  }
  
  /*
   * Power Management
   */
c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
1888
  #ifdef CONFIG_PM_SLEEP
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1889

e157f0cd0   Takashi Iwai   ALSA: cs4281: Mor...
1890
  static const int saved_regs[SUSPEND_REGISTERS] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
  	BA0_JSCTL,
  	BA0_GPIOR,
  	BA0_SSCR,
  	BA0_MIDCR,
  	BA0_SRCSA,
  	BA0_PASR,
  	BA0_CASR,
  	BA0_DACSR,
  	BA0_ADCSR,
  	BA0_FMLVC,
  	BA0_FMRVC,
  	BA0_PPLVC,
  	BA0_PPRVC,
  };
  
  #define CLKCR1_CKRA                             0x00010000L
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1907
  static int cs4281_suspend(struct device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1908
  {
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1909
  	struct snd_card *card = dev_get_drvdata(dev);
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1910
  	struct cs4281 *chip = card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1911
1912
  	u32 ulCLK;
  	unsigned int i;
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1913
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1914
1915
  	snd_ac97_suspend(chip->ac97);
  	snd_ac97_suspend(chip->ac97_secondary);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
  
  	ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1);
  	ulCLK |= CLKCR1_CKRA;
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
  
  	/* Disable interrupts. */
  	snd_cs4281_pokeBA0(chip, BA0_HICR, BA0_HICR_CHGM);
  
  	/* remember the status registers */
  	for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
  		if (saved_regs[i])
  			chip->suspend_regs[i] = snd_cs4281_peekBA0(chip, saved_regs[i]);
  
  	/* Turn off the serial ports. */
  	snd_cs4281_pokeBA0(chip, BA0_SERMC, 0);
  
  	/* Power off FM, Joystick, AC link, */
  	snd_cs4281_pokeBA0(chip, BA0_SSPM, 0);
  
  	/* DLL off. */
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, 0);
  
  	/* AC link off. */
  	snd_cs4281_pokeBA0(chip, BA0_SPMC, 0);
  
  	ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1);
  	ulCLK &= ~CLKCR1_CKRA;
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1944
1945
  	return 0;
  }
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1946
  static int cs4281_resume(struct device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1947
  {
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1948
  	struct snd_card *card = dev_get_drvdata(dev);
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1949
  	struct cs4281 *chip = card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1950
1951
  	unsigned int i;
  	u32 ulCLK;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
  	ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1);
  	ulCLK |= CLKCR1_CKRA;
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
  
  	snd_cs4281_chip_init(chip);
  
  	/* restore the status registers */
  	for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
  		if (saved_regs[i])
  			snd_cs4281_pokeBA0(chip, saved_regs[i], chip->suspend_regs[i]);
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1962
1963
  	snd_ac97_resume(chip->ac97);
  	snd_ac97_resume(chip->ac97_secondary);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1964
1965
1966
1967
  
  	ulCLK = snd_cs4281_peekBA0(chip, BA0_CLKCR1);
  	ulCLK &= ~CLKCR1_CKRA;
  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, ulCLK);
38c0a158e   Takashi Iwai   [ALSA] cs4281 - F...
1968
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1969
1970
  	return 0;
  }
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1971
1972
1973
1974
1975
  
  static SIMPLE_DEV_PM_OPS(cs4281_pm, cs4281_suspend, cs4281_resume);
  #define CS4281_PM_OPS	&cs4281_pm
  #else
  #define CS4281_PM_OPS	NULL
c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
1976
  #endif /* CONFIG_PM_SLEEP */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1977

e9f66d9b9   Takashi Iwai   ALSA: pci: clean ...
1978
  static struct pci_driver cs4281_driver = {
3733e424c   Takashi Iwai   ALSA: Use KBUILD_...
1979
  	.name = KBUILD_MODNAME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1980
1981
  	.id_table = snd_cs4281_ids,
  	.probe = snd_cs4281_probe,
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1982
  	.remove = snd_cs4281_remove,
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1983
1984
1985
  	.driver = {
  		.pm = CS4281_PM_OPS,
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1986
1987
  };
  	
e9f66d9b9   Takashi Iwai   ALSA: pci: clean ...
1988
  module_pci_driver(cs4281_driver);