Blame view

sound/pci/fm801.c 41.4 KB
c942fddf8   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
  /*
   *  The driver for the ForteMedia FM801 based soundcards
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
4
   *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
7
8
  #include <linux/delay.h>
  #include <linux/init.h>
  #include <linux/interrupt.h>
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
9
  #include <linux/io.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
11
  #include <linux/pci.h>
  #include <linux/slab.h>
65a772172   Paul Gortmaker   sound: fix driver...
12
  #include <linux/module.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
  #include <sound/core.h>
  #include <sound/pcm.h>
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
15
  #include <sound/tlv.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
19
  #include <sound/ac97_codec.h>
  #include <sound/mpu401.h>
  #include <sound/opl3.h>
  #include <sound/initval.h>
efce4bb9e   Adrian Bunk   [ALSA] fix the SN...
20
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
d647f0b70   Mauro Carvalho Chehab   [media] include/m...
21
  #include <media/drv-intf/tea575x.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
  #endif
c1017a4cd   Jaroslav Kysela   [ALSA] Changed Ja...
23
  MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
30
  MODULE_DESCRIPTION("ForteMedia FM801");
  MODULE_LICENSE("GPL");
  MODULE_SUPPORTED_DEVICE("{{ForteMedia,FM801},"
  		"{Genius,SoundMaker Live 5.1}}");
  
  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...
31
  static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
  /*
   *  Enable TEA575x tuner
   *    1 = MediaForte 256-PCS
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
35
   *    2 = MediaForte 256-PCP
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
36
   *    3 = MediaForte 64-PCR
fb716c0b7   Ondrej Zary   snd-fm801: autode...
37
   *   16 = setup tuner only (this is additional bit), i.e. SF64-PCR FM card
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
   *  High 16-bits are video (radio) device number + 1
   */
6581f4e74   Takashi Iwai   [ALSA] Remove zer...
40
  static int tea575x_tuner[SNDRV_CARDS];
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
41
  static int radio_nr[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
47
48
49
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for the FM801 soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
  module_param_array(tea575x_tuner, int, NULL, 0444);
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
50
  MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only).");
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
51
52
  module_param_array(radio_nr, int, NULL, 0444);
  MODULE_PARM_DESC(radio_nr, "Radio device numbers");
fb716c0b7   Ondrej Zary   snd-fm801: autode...
53

c37279b92   Ben Hutchings   ALSA: fm801: Grac...
54
  #define TUNER_DISABLED		(1<<3)
fb716c0b7   Ondrej Zary   snd-fm801: autode...
55
56
  #define TUNER_ONLY		(1<<4)
  #define TUNER_TYPE_MASK		(~TUNER_ONLY & 0xFFFF)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
60
  
  /*
   *  Direct registers
   */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
61
62
63
64
  #define fm801_writew(chip,reg,value)	outw((value), chip->port + FM801_##reg)
  #define fm801_readw(chip,reg)		inw(chip->port + FM801_##reg)
  
  #define fm801_writel(chip,reg,value)	outl((value), chip->port + FM801_##reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  
  #define FM801_PCM_VOL		0x00	/* PCM Output Volume */
  #define FM801_FM_VOL		0x02	/* FM Output Volume */
  #define FM801_I2S_VOL		0x04	/* I2S Volume */
  #define FM801_REC_SRC		0x06	/* Record Source */
  #define FM801_PLY_CTRL		0x08	/* Playback Control */
  #define FM801_PLY_COUNT		0x0a	/* Playback Count */
  #define FM801_PLY_BUF1		0x0c	/* Playback Bufer I */
  #define FM801_PLY_BUF2		0x10	/* Playback Buffer II */
  #define FM801_CAP_CTRL		0x14	/* Capture Control */
  #define FM801_CAP_COUNT		0x16	/* Capture Count */
  #define FM801_CAP_BUF1		0x18	/* Capture Buffer I */
  #define FM801_CAP_BUF2		0x1c	/* Capture Buffer II */
  #define FM801_CODEC_CTRL	0x22	/* Codec Control */
  #define FM801_I2S_MODE		0x24	/* I2S Mode Control */
  #define FM801_VOLUME		0x26	/* Volume Up/Down/Mute Status */
  #define FM801_I2C_CTRL		0x29	/* I2C Control */
  #define FM801_AC97_CMD		0x2a	/* AC'97 Command */
  #define FM801_AC97_DATA		0x2c	/* AC'97 Data */
  #define FM801_MPU401_DATA	0x30	/* MPU401 Data */
  #define FM801_MPU401_CMD	0x31	/* MPU401 Command */
  #define FM801_GPIO_CTRL		0x52	/* General Purpose I/O Control */
  #define FM801_GEN_CTRL		0x54	/* General Control */
  #define FM801_IRQ_MASK		0x56	/* Interrupt Mask */
  #define FM801_IRQ_STATUS	0x5a	/* Interrupt Status */
  #define FM801_OPL3_BANK0	0x68	/* OPL3 Status Read / Bank 0 Write */
  #define FM801_OPL3_DATA0	0x69	/* OPL3 Data 0 Write */
  #define FM801_OPL3_BANK1	0x6a	/* OPL3 Bank 1 Write */
  #define FM801_OPL3_DATA1	0x6b	/* OPL3 Bank 1 Write */
  #define FM801_POWERDOWN		0x70	/* Blocks Power Down Control */
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
95
96
97
98
99
  /* codec access */
  #define FM801_AC97_READ		(1<<7)	/* read=1, write=0 */
  #define FM801_AC97_VALID	(1<<8)	/* port valid=1 */
  #define FM801_AC97_BUSY		(1<<9)	/* busy=1 */
  #define FM801_AC97_ADDR_SHIFT	10	/* codec id (2bit) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  
  /* playback and record control register bits */
  #define FM801_BUF1_LAST		(1<<1)
  #define FM801_BUF2_LAST		(1<<2)
  #define FM801_START		(1<<5)
  #define FM801_PAUSE		(1<<6)
  #define FM801_IMMED_STOP	(1<<7)
  #define FM801_RATE_SHIFT	8
  #define FM801_RATE_MASK		(15 << FM801_RATE_SHIFT)
  #define FM801_CHANNELS_4	(1<<12)	/* playback only */
  #define FM801_CHANNELS_6	(2<<12)	/* playback only */
  #define FM801_CHANNELS_6MS	(3<<12)	/* playback only */
  #define FM801_CHANNELS_MASK	(3<<12)
  #define FM801_16BIT		(1<<14)
  #define FM801_STEREO		(1<<15)
  
  /* IRQ status bits */
  #define FM801_IRQ_PLAYBACK	(1<<8)
  #define FM801_IRQ_CAPTURE	(1<<9)
  #define FM801_IRQ_VOLUME	(1<<14)
  #define FM801_IRQ_MPU		(1<<15)
  
  /* GPIO control register */
  #define FM801_GPIO_GP0		(1<<0)	/* read/write */
  #define FM801_GPIO_GP1		(1<<1)
  #define FM801_GPIO_GP2		(1<<2)
  #define FM801_GPIO_GP3		(1<<3)
  #define FM801_GPIO_GP(x)	(1<<(0+(x)))
  #define FM801_GPIO_GD0		(1<<8)	/* directions: 1 = input, 0 = output*/
  #define FM801_GPIO_GD1		(1<<9)
  #define FM801_GPIO_GD2		(1<<10)
  #define FM801_GPIO_GD3		(1<<11)
  #define FM801_GPIO_GD(x)	(1<<(8+(x)))
  #define FM801_GPIO_GS0		(1<<12)	/* function select: */
  #define FM801_GPIO_GS1		(1<<13)	/*    1 = GPIO */
  #define FM801_GPIO_GS2		(1<<14)	/*    0 = other (S/PDIF, VOL) */
  #define FM801_GPIO_GS3		(1<<15)
  #define FM801_GPIO_GS(x)	(1<<(12+(x)))
  	
052c233e9   Andy Shevchenko   ALSA: fm801: conv...
139
140
  /**
   * struct fm801 - describes FM801 chip
af8c5dffc   Pierre-Louis Bossart   ALSA: pci/fm801: ...
141
142
   * @dev:		device for this chio
   * @irq:		irq number
052c233e9   Andy Shevchenko   ALSA: fm801: conv...
143
144
145
146
147
148
149
   * @port:		I/O port number
   * @multichannel:	multichannel support
   * @secondary:		secondary codec
   * @secondary_addr:	address of the secondary codec
   * @tea575x_tuner:	tuner access method & flags
   * @ply_ctrl:		playback control
   * @cap_ctrl:		capture control
af8c5dffc   Pierre-Louis Bossart   ALSA: pci/fm801: ...
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
   * @ply_buffer:		playback buffer
   * @ply_buf:		playback buffer index
   * @ply_count:		playback buffer count
   * @ply_size:		playback buffer size
   * @ply_pos:		playback position
   * @cap_buffer:		capture buffer
   * @cap_buf:		capture buffer index
   * @cap_count:		capture buffer count
   * @cap_size:		capture buffer size
   * @cap_pos:		capture position
   * @ac97_bus:		ac97 bus handle
   * @ac97:		ac97 handle
   * @ac97_sec:		ac97 secondary handle
   * @card:		ALSA card
   * @pcm:		PCM devices
   * @rmidi:		rmidi device
   * @playback_substream:	substream for playback
   * @capture_substream:	substream for capture
   * @p_dma_size:		playback DMA size
   * @c_dma_size:		capture DMA size
   * @reg_lock:		lock
   * @proc_entry:		/proc entry
   * @v4l2_dev:		v4l2 device
   * @tea:		tea575a structure
   * @saved_regs:		context saved during suspend
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
   */
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
176
  struct fm801 {
d3d33aaba   Andy Shevchenko   ALSA: fm801: stor...
177
  	struct device *dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
  	int irq;
052c233e9   Andy Shevchenko   ALSA: fm801: conv...
179
180
181
182
183
  	unsigned long port;
  	unsigned int multichannel: 1,
  		     secondary: 1;
  	unsigned char secondary_addr;
  	unsigned int tea575x_tuner;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184

052c233e9   Andy Shevchenko   ALSA: fm801: conv...
185
186
  	unsigned short ply_ctrl;
  	unsigned short cap_ctrl;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
191
192
193
194
195
196
197
198
  
  	unsigned long ply_buffer;
  	unsigned int ply_buf;
  	unsigned int ply_count;
  	unsigned int ply_size;
  	unsigned int ply_pos;
  
  	unsigned long cap_buffer;
  	unsigned int cap_buf;
  	unsigned int cap_count;
  	unsigned int cap_size;
  	unsigned int cap_pos;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
199
200
201
  	struct snd_ac97_bus *ac97_bus;
  	struct snd_ac97 *ac97;
  	struct snd_ac97 *ac97_sec;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202

a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
203
204
205
206
207
  	struct snd_card *card;
  	struct snd_pcm *pcm;
  	struct snd_rawmidi *rmidi;
  	struct snd_pcm_substream *playback_substream;
  	struct snd_pcm_substream *capture_substream;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
  	unsigned int p_dma_size;
  	unsigned int c_dma_size;
  
  	spinlock_t reg_lock;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
212
  	struct snd_info_entry *proc_entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
213

fdb62b500   Ondrej Zary   ALSA: fm801: clea...
214
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
215
  	struct v4l2_device v4l2_dev;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
216
  	struct snd_tea575x tea;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
  #endif
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
218

c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
219
  #ifdef CONFIG_PM_SLEEP
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
220
221
  	u16 saved_regs[0x20];
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
  };
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
223
224
225
226
227
228
229
230
231
232
233
234
235
  /*
   * IO accessors
   */
  
  static inline void fm801_iowrite16(struct fm801 *chip, unsigned short offset, u16 value)
  {
  	outw(value, chip->port + offset);
  }
  
  static inline u16 fm801_ioread16(struct fm801 *chip, unsigned short offset)
  {
  	return inw(chip->port + offset);
  }
9baa3c34a   Benoit Taine   PCI: Remove DEFIN...
236
  static const struct pci_device_id snd_fm801_ids[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
  	{ 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* FM801 */
26be86592   Sergey Vlasov   [ALSA] Add PCI ID...
238
  	{ 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* Gallant Odyssey Sound 4 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
241
242
243
244
245
246
  	{ 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, snd_fm801_ids);
  
  /*
   *  common I/O routines
   */
02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
  static bool fm801_ac97_is_ready(struct fm801 *chip, unsigned int iterations)
  {
  	unsigned int idx;
  
  	for (idx = 0; idx < iterations; idx++) {
  		if (!(fm801_readw(chip, AC97_CMD) & FM801_AC97_BUSY))
  			return true;
  		udelay(10);
  	}
  	return false;
  }
  
  static bool fm801_ac97_is_valid(struct fm801 *chip, unsigned int iterations)
  {
  	unsigned int idx;
  
  	for (idx = 0; idx < iterations; idx++) {
  		if (fm801_readw(chip, AC97_CMD) & FM801_AC97_VALID)
  			return true;
  		udelay(10);
  	}
  	return false;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
270
  static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
271
272
273
274
275
276
277
  				 unsigned short mask, unsigned short value)
  {
  	int change;
  	unsigned long flags;
  	unsigned short old, new;
  
  	spin_lock_irqsave(&chip->reg_lock, flags);
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
278
  	old = fm801_ioread16(chip, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
279
280
281
  	new = (old & ~mask) | value;
  	change = old != new;
  	if (change)
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
282
  		fm801_iowrite16(chip, reg, new);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
283
284
285
  	spin_unlock_irqrestore(&chip->reg_lock, flags);
  	return change;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
286
  static void snd_fm801_codec_write(struct snd_ac97 *ac97,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
287
288
289
  				  unsigned short reg,
  				  unsigned short val)
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
290
  	struct fm801 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
292
293
294
  
  	/*
  	 *  Wait until the codec interface is not ready..
  	 */
02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
295
296
297
298
  	if (!fm801_ac97_is_ready(chip, 100)) {
  		dev_err(chip->card->dev, "AC'97 interface is busy (1)
  ");
  		return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
301
  	/* write data and address */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
302
303
  	fm801_writew(chip, AC97_DATA, val);
  	fm801_writew(chip, AC97_CMD, reg | (ac97->addr << FM801_AC97_ADDR_SHIFT));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
  	/*
  	 *  Wait until the write command is not completed..
02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
306
307
308
309
310
  	 */
  	if (!fm801_ac97_is_ready(chip, 1000))
  		dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)
  ",
  		ac97->num);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
312
  static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
314
  	struct fm801 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
316
317
318
  
  	/*
  	 *  Wait until the codec interface is not ready..
  	 */
02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
319
320
321
322
  	if (!fm801_ac97_is_ready(chip, 100)) {
  		dev_err(chip->card->dev, "AC'97 interface is busy (1)
  ");
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
323
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325
  	/* read command */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
326
327
  	fm801_writew(chip, AC97_CMD,
  		     reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ);
02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
328
329
330
331
332
  	if (!fm801_ac97_is_ready(chip, 100)) {
  		dev_err(chip->card->dev, "AC'97 interface #%d is busy (2)
  ",
  			ac97->num);
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
334

02fd1a76b   Andy Shevchenko   ALSA: fm801: intr...
335
336
337
338
339
  	if (!fm801_ac97_is_valid(chip, 1000)) {
  		dev_err(chip->card->dev,
  			"AC'97 interface #%d is not valid (2)
  ", ac97->num);
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341

215dacc28   Andy Shevchenko   ALSA: fm801: intr...
342
  	return fm801_readw(chip, AC97_DATA);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
343
  }
d71a13f4c   Takashi Iwai   ALSA: fm801: Cons...
344
  static const unsigned int rates[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
346
347
348
    5500,  8000,  9600, 11025,
    16000, 19200, 22050, 32000,
    38400, 44100, 48000
  };
d71a13f4c   Takashi Iwai   ALSA: fm801: Cons...
349
  static const struct snd_pcm_hw_constraint_list hw_constraints_rates = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
351
352
353
  	.count = ARRAY_SIZE(rates),
  	.list = rates,
  	.mask = 0,
  };
d71a13f4c   Takashi Iwai   ALSA: fm801: Cons...
354
  static const unsigned int channels[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
355
356
    2, 4, 6
  };
d71a13f4c   Takashi Iwai   ALSA: fm801: Cons...
357
  static const struct snd_pcm_hw_constraint_list hw_constraints_channels = {
5e4968e24   Tobias Klauser   [ALSA] sound/pci/...
358
  	.count = ARRAY_SIZE(channels),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
  	.list = channels,
  	.mask = 0,
  };
  
  /*
   *  Sample rate routines
   */
  
  static unsigned short snd_fm801_rate_bits(unsigned int rate)
  {
  	unsigned int idx;
  
  	for (idx = 0; idx < ARRAY_SIZE(rates); idx++)
  		if (rates[idx] == rate)
  			return idx;
  	snd_BUG();
  	return ARRAY_SIZE(rates) - 1;
  }
  
  /*
   *  PCM part
   */
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
381
  static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
382
383
  				      int cmd)
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
384
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
385
386
387
388
389
390
391
392
393
394
395
396
397
398
  
  	spin_lock(&chip->reg_lock);
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_START:
  		chip->ply_ctrl &= ~(FM801_BUF1_LAST |
  				     FM801_BUF2_LAST |
  				     FM801_PAUSE);
  		chip->ply_ctrl |= FM801_START |
  				   FM801_IMMED_STOP;
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  		chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE);
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
399
  	case SNDRV_PCM_TRIGGER_SUSPEND:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
400
401
402
  		chip->ply_ctrl |= FM801_PAUSE;
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
403
  	case SNDRV_PCM_TRIGGER_RESUME:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
404
405
406
407
408
409
410
  		chip->ply_ctrl &= ~FM801_PAUSE;
  		break;
  	default:
  		spin_unlock(&chip->reg_lock);
  		snd_BUG();
  		return -EINVAL;
  	}
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
411
  	fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
412
413
414
  	spin_unlock(&chip->reg_lock);
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
415
  static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
416
417
  				     int cmd)
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
418
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
421
422
423
424
425
426
427
428
429
430
431
432
  
  	spin_lock(&chip->reg_lock);
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_START:
  		chip->cap_ctrl &= ~(FM801_BUF1_LAST |
  				     FM801_BUF2_LAST |
  				     FM801_PAUSE);
  		chip->cap_ctrl |= FM801_START |
  				   FM801_IMMED_STOP;
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  		chip->cap_ctrl &= ~(FM801_START | FM801_PAUSE);
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
433
  	case SNDRV_PCM_TRIGGER_SUSPEND:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
434
435
436
  		chip->cap_ctrl |= FM801_PAUSE;
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
437
  	case SNDRV_PCM_TRIGGER_RESUME:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
438
439
440
441
442
443
444
  		chip->cap_ctrl &= ~FM801_PAUSE;
  		break;
  	default:
  		spin_unlock(&chip->reg_lock);
  		snd_BUG();
  		return -EINVAL;
  	}
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
445
  	fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
446
447
448
  	spin_unlock(&chip->reg_lock);
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
449
  static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
450
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
451
452
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
  
  	chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
  	chip->ply_count = snd_pcm_lib_period_bytes(substream);
  	spin_lock_irq(&chip->reg_lock);
  	chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
  			     FM801_STEREO | FM801_RATE_MASK |
  			     FM801_CHANNELS_MASK);
  	if (snd_pcm_format_width(runtime->format) == 16)
  		chip->ply_ctrl |= FM801_16BIT;
  	if (runtime->channels > 1) {
  		chip->ply_ctrl |= FM801_STEREO;
  		if (runtime->channels == 4)
  			chip->ply_ctrl |= FM801_CHANNELS_4;
  		else if (runtime->channels == 6)
  			chip->ply_ctrl |= FM801_CHANNELS_6;
  	}
  	chip->ply_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
  	chip->ply_buf = 0;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
471
472
  	fm801_writew(chip, PLY_CTRL, chip->ply_ctrl);
  	fm801_writew(chip, PLY_COUNT, chip->ply_count - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
474
  	chip->ply_buffer = runtime->dma_addr;
  	chip->ply_pos = 0;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
475
476
477
  	fm801_writel(chip, PLY_BUF1, chip->ply_buffer);
  	fm801_writel(chip, PLY_BUF2,
  		     chip->ply_buffer + (chip->ply_count % chip->ply_size));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
478
479
480
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
481
  static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
482
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
483
484
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
485
486
487
488
489
490
491
492
493
494
495
496
  
  	chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
  	chip->cap_count = snd_pcm_lib_period_bytes(substream);
  	spin_lock_irq(&chip->reg_lock);
  	chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
  			     FM801_STEREO | FM801_RATE_MASK);
  	if (snd_pcm_format_width(runtime->format) == 16)
  		chip->cap_ctrl |= FM801_16BIT;
  	if (runtime->channels > 1)
  		chip->cap_ctrl |= FM801_STEREO;
  	chip->cap_ctrl |= snd_fm801_rate_bits(runtime->rate) << FM801_RATE_SHIFT;
  	chip->cap_buf = 0;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
497
498
  	fm801_writew(chip, CAP_CTRL, chip->cap_ctrl);
  	fm801_writew(chip, CAP_COUNT, chip->cap_count - 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
499
500
  	chip->cap_buffer = runtime->dma_addr;
  	chip->cap_pos = 0;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
501
502
503
  	fm801_writel(chip, CAP_BUF1, chip->cap_buffer);
  	fm801_writel(chip, CAP_BUF2,
  		     chip->cap_buffer + (chip->cap_count % chip->cap_size));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
504
505
506
  	spin_unlock_irq(&chip->reg_lock);
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
507
  static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
508
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
509
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
510
511
512
513
514
  	size_t ptr;
  
  	if (!(chip->ply_ctrl & FM801_START))
  		return 0;
  	spin_lock(&chip->reg_lock);
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
515
516
  	ptr = chip->ply_pos + (chip->ply_count - 1) - fm801_readw(chip, PLY_COUNT);
  	if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_PLAYBACK) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
517
518
519
520
521
522
  		ptr += chip->ply_count;
  		ptr %= chip->ply_size;
  	}
  	spin_unlock(&chip->reg_lock);
  	return bytes_to_frames(substream->runtime, ptr);
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
523
  static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
525
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
526
527
528
529
530
  	size_t ptr;
  
  	if (!(chip->cap_ctrl & FM801_START))
  		return 0;
  	spin_lock(&chip->reg_lock);
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
531
532
  	ptr = chip->cap_pos + (chip->cap_count - 1) - fm801_readw(chip, CAP_COUNT);
  	if (fm801_readw(chip, IRQ_STATUS) & FM801_IRQ_CAPTURE) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
533
534
535
536
537
538
  		ptr += chip->cap_count;
  		ptr %= chip->cap_size;
  	}
  	spin_unlock(&chip->reg_lock);
  	return bytes_to_frames(substream->runtime, ptr);
  }
7d12e780e   David Howells   IRQ: Maintain reg...
539
  static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
541
  	struct fm801 *chip = dev_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542
543
  	unsigned short status;
  	unsigned int tmp;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
544
  	status = fm801_readw(chip, IRQ_STATUS);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
546
547
548
  	status &= FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU|FM801_IRQ_VOLUME;
  	if (! status)
  		return IRQ_NONE;
  	/* ack first */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
549
  	fm801_writew(chip, IRQ_STATUS, status);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
550
551
552
553
554
555
556
  	if (chip->pcm && (status & FM801_IRQ_PLAYBACK) && chip->playback_substream) {
  		spin_lock(&chip->reg_lock);
  		chip->ply_buf++;
  		chip->ply_pos += chip->ply_count;
  		chip->ply_pos %= chip->ply_size;
  		tmp = chip->ply_pos + chip->ply_count;
  		tmp %= chip->ply_size;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
557
558
559
560
  		if (chip->ply_buf & 1)
  			fm801_writel(chip, PLY_BUF1, chip->ply_buffer + tmp);
  		else
  			fm801_writel(chip, PLY_BUF2, chip->ply_buffer + tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
561
562
563
564
565
566
567
568
569
570
  		spin_unlock(&chip->reg_lock);
  		snd_pcm_period_elapsed(chip->playback_substream);
  	}
  	if (chip->pcm && (status & FM801_IRQ_CAPTURE) && chip->capture_substream) {
  		spin_lock(&chip->reg_lock);
  		chip->cap_buf++;
  		chip->cap_pos += chip->cap_count;
  		chip->cap_pos %= chip->cap_size;
  		tmp = chip->cap_pos + chip->cap_count;
  		tmp %= chip->cap_size;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
571
572
573
574
  		if (chip->cap_buf & 1)
  			fm801_writel(chip, CAP_BUF1, chip->cap_buffer + tmp);
  		else
  			fm801_writel(chip, CAP_BUF2, chip->cap_buffer + tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
575
576
577
578
  		spin_unlock(&chip->reg_lock);
  		snd_pcm_period_elapsed(chip->capture_substream);
  	}
  	if (chip->rmidi && (status & FM801_IRQ_MPU))
7d12e780e   David Howells   IRQ: Maintain reg...
579
  		snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
997c87dad   Andy Shevchenko   ALSA: fm801: put ...
580
581
582
  	if (status & FM801_IRQ_VOLUME) {
  		/* TODO */
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
583
584
585
  
  	return IRQ_HANDLED;
  }
dee49895b   Bhumika Goyal   ALSA: pci: make s...
586
  static const struct snd_pcm_hardware snd_fm801_playback =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
587
588
589
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
590
  				 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  				 SNDRV_PCM_INFO_MMAP_VALID),
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		5500,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(128*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(128*1024),
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
dee49895b   Bhumika Goyal   ALSA: pci: make s...
605
  static const struct snd_pcm_hardware snd_fm801_capture =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
606
607
608
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
609
  				 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
610
611
612
613
614
615
616
617
618
619
620
621
622
623
  				 SNDRV_PCM_INFO_MMAP_VALID),
  	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =		SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
  	.rate_min =		5500,
  	.rate_max =		48000,
  	.channels_min =		1,
  	.channels_max =		2,
  	.buffer_bytes_max =	(128*1024),
  	.period_bytes_min =	64,
  	.period_bytes_max =	(128*1024),
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0,
  };
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
624
  static int snd_fm801_playback_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
625
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
626
627
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
629
630
631
  	int err;
  
  	chip->playback_substream = substream;
  	runtime->hw = snd_fm801_playback;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
632
633
  	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				   &hw_constraints_rates);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
634
635
  	if (chip->multichannel) {
  		runtime->hw.channels_max = 6;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
636
637
638
  		snd_pcm_hw_constraint_list(runtime, 0,
  					   SNDRV_PCM_HW_PARAM_CHANNELS,
  					   &hw_constraints_channels);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
639
640
641
642
643
  	}
  	if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  		return err;
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
644
  static int snd_fm801_capture_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
646
647
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
648
649
650
651
  	int err;
  
  	chip->capture_substream = substream;
  	runtime->hw = snd_fm801_capture;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
652
653
  	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
  				   &hw_constraints_rates);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
654
655
656
657
  	if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
  		return err;
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
658
  static int snd_fm801_playback_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
659
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
660
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
661
662
663
664
  
  	chip->playback_substream = NULL;
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
665
  static int snd_fm801_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
666
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
667
  	struct fm801 *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
668
669
670
671
  
  	chip->capture_substream = NULL;
  	return 0;
  }
6769e988b   Julia Lawall   ALSA: constify sn...
672
  static const struct snd_pcm_ops snd_fm801_playback_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
673
674
  	.open =		snd_fm801_playback_open,
  	.close =	snd_fm801_playback_close,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
675
676
677
678
  	.prepare =	snd_fm801_playback_prepare,
  	.trigger =	snd_fm801_playback_trigger,
  	.pointer =	snd_fm801_playback_pointer,
  };
6769e988b   Julia Lawall   ALSA: constify sn...
679
  static const struct snd_pcm_ops snd_fm801_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
680
681
  	.open =		snd_fm801_capture_open,
  	.close =	snd_fm801_capture_close,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
682
683
684
685
  	.prepare =	snd_fm801_capture_prepare,
  	.trigger =	snd_fm801_capture_trigger,
  	.pointer =	snd_fm801_capture_pointer,
  };
483337f90   Lars-Peter Clausen   ALSA: fm801: Remo...
686
  static int snd_fm801_pcm(struct fm801 *chip, int device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
687
  {
d3d33aaba   Andy Shevchenko   ALSA: fm801: stor...
688
  	struct pci_dev *pdev = to_pci_dev(chip->dev);
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
689
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
690
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
692
693
694
695
696
697
  	if ((err = snd_pcm_new(chip->card, "FM801", device, 1, 1, &pcm)) < 0)
  		return err;
  
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_fm801_playback_ops);
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_fm801_capture_ops);
  
  	pcm->private_data = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
698
699
700
  	pcm->info_flags = 0;
  	strcpy(pcm->name, "FM801");
  	chip->pcm = pcm;
247ed1020   Takashi Iwai   ALSA: fm801: Use ...
701
702
  	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &pdev->dev,
  				       chip->multichannel ? 128*1024 : 64*1024, 128*1024);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
703

483337f90   Lars-Peter Clausen   ALSA: fm801: Remo...
704
  	return snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
e36e3b86c   Takashi Iwai   ALSA: Implement c...
705
706
707
  				     snd_pcm_alt_chmaps,
  				     chip->multichannel ? 6 : 2, 0,
  				     NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
708
709
710
711
712
  }
  
  /*
   *  TEA5757 radio
   */
fdb62b500   Ondrej Zary   ALSA: fm801: clea...
713
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714

938a1566b   Ondrej Zary   ALSA: fm801: conv...
715
716
717
  /* GPIO to TEA575x maps */
  struct snd_fm801_tea575x_gpio {
  	u8 data, clk, wren, most;
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
718
  	char *name;
938a1566b   Ondrej Zary   ALSA: fm801: conv...
719
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
720

fb537cd00   Takashi Iwai   ALSA: fm801: Cons...
721
  static const struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
722
723
724
  	{ .data = 1, .clk = 3, .wren = 2, .most = 0, .name = "SF256-PCS" },
  	{ .data = 1, .clk = 0, .wren = 2, .most = 3, .name = "SF256-PCP" },
  	{ .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
938a1566b   Ondrej Zary   ALSA: fm801: conv...
725
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
726

8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
727
728
  #define get_tea575x_gpio(chip) \
  	(&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
938a1566b   Ondrej Zary   ALSA: fm801: conv...
729
  static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
730
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
731
  	struct fm801 *chip = tea->private_data;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
732
  	unsigned short reg = fm801_readw(chip, GPIO_CTRL);
8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
733
  	struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
734

938a1566b   Ondrej Zary   ALSA: fm801: conv...
735
736
737
  	reg &= ~(FM801_GPIO_GP(gpio.data) |
  		 FM801_GPIO_GP(gpio.clk) |
  		 FM801_GPIO_GP(gpio.wren));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
738

938a1566b   Ondrej Zary   ALSA: fm801: conv...
739
740
741
742
  	reg |= (pins & TEA575X_DATA) ? FM801_GPIO_GP(gpio.data) : 0;
  	reg |= (pins & TEA575X_CLK)  ? FM801_GPIO_GP(gpio.clk) : 0;
  	/* WRITE_ENABLE is inverted */
  	reg |= (pins & TEA575X_WREN) ? 0 : FM801_GPIO_GP(gpio.wren);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
743

215dacc28   Andy Shevchenko   ALSA: fm801: intr...
744
  	fm801_writew(chip, GPIO_CTRL, reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
745
  }
938a1566b   Ondrej Zary   ALSA: fm801: conv...
746
  static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
747
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
748
  	struct fm801 *chip = tea->private_data;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
749
  	unsigned short reg = fm801_readw(chip, GPIO_CTRL);
8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
750
  	struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
effded75e   Dan Carpenter   ALSA: fm801: prec...
751
752
753
754
755
756
757
758
  	u8 ret;
  
  	ret = 0;
  	if (reg & FM801_GPIO_GP(gpio.data))
  		ret |= TEA575X_DATA;
  	if (reg & FM801_GPIO_GP(gpio.most))
  		ret |= TEA575X_MOST;
  	return ret;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
759
  }
938a1566b   Ondrej Zary   ALSA: fm801: conv...
760
  static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
761
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
762
  	struct fm801 *chip = tea->private_data;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
763
  	unsigned short reg = fm801_readw(chip, GPIO_CTRL);
8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
764
  	struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
765

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
766
  	/* use GPIO lines and set write enable bit */
938a1566b   Ondrej Zary   ALSA: fm801: conv...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
  	reg |= FM801_GPIO_GS(gpio.data) |
  	       FM801_GPIO_GS(gpio.wren) |
  	       FM801_GPIO_GS(gpio.clk) |
  	       FM801_GPIO_GS(gpio.most);
  	if (output) {
  		/* all of lines are in the write direction */
  		/* clear data and clock lines */
  		reg &= ~(FM801_GPIO_GD(gpio.data) |
  			 FM801_GPIO_GD(gpio.wren) |
  			 FM801_GPIO_GD(gpio.clk) |
  			 FM801_GPIO_GP(gpio.data) |
  			 FM801_GPIO_GP(gpio.clk) |
  			 FM801_GPIO_GP(gpio.wren));
  	} else {
  		/* use GPIO lines, set data direction to input */
  		reg |= FM801_GPIO_GD(gpio.data) |
  		       FM801_GPIO_GD(gpio.most) |
  		       FM801_GPIO_GP(gpio.data) |
  		       FM801_GPIO_GP(gpio.most) |
  		       FM801_GPIO_GP(gpio.wren);
  		/* all of lines are in the write direction, except data */
  		/* clear data, write enable and clock lines */
  		reg &= ~(FM801_GPIO_GD(gpio.wren) |
  			 FM801_GPIO_GD(gpio.clk) |
  			 FM801_GPIO_GP(gpio.clk));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
792
  	}
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
793
  	fm801_writew(chip, GPIO_CTRL, reg);
69252128e   Andy Shevchenko   [ALSA] fm801 - Ad...
794
  }
22dbec265   Julia Lawall   [media] media, so...
795
  static const struct snd_tea575x_ops snd_fm801_tea_ops = {
938a1566b   Ondrej Zary   ALSA: fm801: conv...
796
797
798
  	.set_pins = snd_fm801_tea575x_set_pins,
  	.get_pins = snd_fm801_tea575x_get_pins,
  	.set_direction = snd_fm801_tea575x_set_direction,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
800
801
802
803
804
805
806
807
808
809
  };
  #endif
  
  /*
   *  Mixer routines
   */
  
  #define FM801_SINGLE(xname, reg, shift, mask, invert) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_single, \
    .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
    .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
810
811
  static int snd_fm801_info_single(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
812
813
814
815
816
817
818
819
820
  {
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  
  	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 1;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = mask;
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
821
822
  static int snd_fm801_get_single(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
823
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
824
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
825
826
827
828
  	int reg = kcontrol->private_value & 0xff;
  	int shift = (kcontrol->private_value >> 8) & 0xff;
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  	int invert = (kcontrol->private_value >> 24) & 0xff;
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
829
  	long *value = ucontrol->value.integer.value;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
830

4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
831
  	value[0] = (fm801_ioread16(chip, reg) >> shift) & mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
832
  	if (invert)
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
833
  		value[0] = mask - value[0];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
834
835
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
836
837
  static int snd_fm801_put_single(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
838
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
839
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
  	int reg = kcontrol->private_value & 0xff;
  	int shift = (kcontrol->private_value >> 8) & 0xff;
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  	int invert = (kcontrol->private_value >> 24) & 0xff;
  	unsigned short val;
  
  	val = (ucontrol->value.integer.value[0] & mask);
  	if (invert)
  		val = mask - val;
  	return snd_fm801_update_bits(chip, reg, mask << shift, val << shift);
  }
  
  #define FM801_DOUBLE(xname, reg, shift_left, shift_right, mask, invert) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
    .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
    .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
856
857
858
859
860
861
862
  #define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
  { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
    .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
    .name = xname, .info = snd_fm801_info_double, \
    .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
    .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
    .tlv = { .p = (xtlv) } }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
863

a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
864
865
  static int snd_fm801_info_double(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
866
867
868
869
870
871
872
873
874
  {
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  
  	uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
  	uinfo->count = 2;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = mask;
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
875
876
  static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
877
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
878
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
879
880
881
882
883
          int reg = kcontrol->private_value & 0xff;
  	int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  	int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  	int invert = (kcontrol->private_value >> 24) & 0xff;
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
884
  	long *value = ucontrol->value.integer.value;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
885
886
  
  	spin_lock_irq(&chip->reg_lock);
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
887
888
  	value[0] = (fm801_ioread16(chip, reg) >> shift_left) & mask;
  	value[1] = (fm801_ioread16(chip, reg) >> shift_right) & mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
889
890
  	spin_unlock_irq(&chip->reg_lock);
  	if (invert) {
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
891
892
  		value[0] = mask - value[0];
  		value[1] = mask - value[1];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
893
894
895
  	}
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
896
897
  static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
898
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
899
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
  	int reg = kcontrol->private_value & 0xff;
  	int shift_left = (kcontrol->private_value >> 8) & 0x0f;
  	int shift_right = (kcontrol->private_value >> 12) & 0x0f;
  	int mask = (kcontrol->private_value >> 16) & 0xff;
  	int invert = (kcontrol->private_value >> 24) & 0xff;
  	unsigned short val1, val2;
   
  	val1 = ucontrol->value.integer.value[0] & mask;
  	val2 = ucontrol->value.integer.value[1] & mask;
  	if (invert) {
  		val1 = mask - val1;
  		val2 = mask - val2;
  	}
  	return snd_fm801_update_bits(chip, reg,
  				     (mask << shift_left) | (mask << shift_right),
  				     (val1 << shift_left ) | (val2 << shift_right));
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
917
918
  static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
  			      struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
919
  {
ca776a28a   Takashi Iwai   ALSA: fm801: Use ...
920
  	static const char * const texts[5] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
921
922
923
  		"AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
  	};
   
ca776a28a   Takashi Iwai   ALSA: fm801: Use ...
924
  	return snd_ctl_enum_info(uinfo, 1, 5, texts);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
925
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
926
927
  static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
  			     struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
928
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
929
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
930
931
          unsigned short val;
   
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
932
  	val = fm801_readw(chip, REC_SRC) & 7;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
933
934
935
936
937
  	if (val > 4)
  		val = 4;
          ucontrol->value.enumerated.item[0] = val;
          return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
938
939
  static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol,
  			     struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
940
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
941
  	struct fm801 *chip = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
942
943
944
945
946
947
          unsigned short val;
   
          if ((val = ucontrol->value.enumerated.item[0]) > 4)
                  return -EINVAL;
  	return snd_fm801_update_bits(chip, FM801_REC_SRC, 7, val);
  }
0cb29ea0d   Takashi Iwai   [ALSA] Add even m...
948
  static const DECLARE_TLV_DB_SCALE(db_scale_dsp, -3450, 150, 0);
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
949

a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
950
  #define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
951

b4e5e7077   Takashi Iwai   ALSA: pci: Consti...
952
  static const struct snd_kcontrol_new snd_fm801_controls[] = {
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
953
954
  FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1,
  		 db_scale_dsp),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
955
  FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1),
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
956
957
  FM801_DOUBLE_TLV("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1,
  		 db_scale_dsp),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
958
  FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL, 15, 1, 1),
666c70ffd   Takashi Iwai   [ALSA] Add dB sca...
959
960
  FM801_DOUBLE_TLV("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1,
  		 db_scale_dsp),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
961
962
963
964
965
966
967
968
969
  FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
  {
  	.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  	.name = "Digital Capture Source",
  	.info = snd_fm801_info_mux,
  	.get = snd_fm801_get_mux,
  	.put = snd_fm801_put_mux,
  }
  };
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
970
  #define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
971

b4e5e7077   Takashi Iwai   ALSA: pci: Consti...
972
  static const struct snd_kcontrol_new snd_fm801_controls_multi[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
973
974
  FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
  FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
10e8d78a9   Clemens Ladisch   [ALSA] use SNDRV_...
975
976
977
978
  FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0),
  FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",PLAYBACK,SWITCH), FM801_I2S_MODE, 9, 1, 0),
  FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, 10, 1, 0),
  FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0),
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
979
  };
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
980
  static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
981
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
982
  	struct fm801 *chip = bus->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
983
984
  	chip->ac97_bus = NULL;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
985
  static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
986
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
987
  	struct fm801 *chip = ac97->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
988
989
990
991
992
993
  	if (ac97->num == 0) {
  		chip->ac97 = NULL;
  	} else {
  		chip->ac97_sec = NULL;
  	}
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
994
  static int snd_fm801_mixer(struct fm801 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
995
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
996
  	struct snd_ac97_template ac97;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
997
998
  	unsigned int i;
  	int err;
51055da51   Takashi Iwai   ALSA: pci: Consti...
999
  	static const struct snd_ac97_bus_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
  		.write = snd_fm801_codec_write,
  		.read = snd_fm801_codec_read,
  	};
  
  	if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0)
  		return err;
  	chip->ac97_bus->private_free = snd_fm801_mixer_free_ac97_bus;
  
  	memset(&ac97, 0, sizeof(ac97));
  	ac97.private_data = chip;
  	ac97.private_free = snd_fm801_mixer_free_ac97;
  	if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
  		return err;
  	if (chip->secondary) {
  		ac97.num = 1;
  		ac97.addr = chip->secondary_addr;
  		if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97_sec)) < 0)
  			return err;
  	}
ef1ffbe78   Zhouyang Jia   ALSA: fm801: add ...
1019
1020
1021
1022
1023
1024
  	for (i = 0; i < FM801_CONTROLS; i++) {
  		err = snd_ctl_add(chip->card,
  			snd_ctl_new1(&snd_fm801_controls[i], chip));
  		if (err < 0)
  			return err;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1025
  	if (chip->multichannel) {
ef1ffbe78   Zhouyang Jia   ALSA: fm801: add ...
1026
1027
1028
1029
1030
1031
  		for (i = 0; i < FM801_CONTROLS_MULTI; i++) {
  			err = snd_ctl_add(chip->card,
  				snd_ctl_new1(&snd_fm801_controls_multi[i], chip));
  			if (err < 0)
  				return err;
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1032
1033
1034
1035
1036
1037
1038
  	}
  	return 0;
  }
  
  /*
   *  initialization routines
   */
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1039
1040
1041
1042
  static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
  			  unsigned short reg, unsigned long waits)
  {
  	unsigned long timeout = jiffies + waits;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1043
1044
  	fm801_writew(chip, AC97_CMD,
  		     reg | (codec_id << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1045
1046
  	udelay(5);
  	do {
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1047
1048
  		if ((fm801_readw(chip, AC97_CMD) &
  		     (FM801_AC97_VALID | FM801_AC97_BUSY)) == FM801_AC97_VALID)
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1049
1050
1051
1052
1053
  			return 0;
  		schedule_timeout_uninterruptible(1);
  	} while (time_after(timeout, jiffies));
  	return -EIO;
  }
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1054
  static int reset_codec(struct fm801 *chip)
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1055
  {
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1056
  	/* codec cold reset + AC'97 warm reset */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1057
1058
  	fm801_writew(chip, CODEC_CTRL, (1 << 5) | (1 << 6));
  	fm801_readw(chip, CODEC_CTRL); /* flush posting data */
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1059
  	udelay(100);
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1060
  	fm801_writew(chip, CODEC_CTRL, 0);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1061

b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1062
1063
1064
1065
1066
1067
  	return wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750));
  }
  
  static void snd_fm801_chip_multichannel_init(struct fm801 *chip)
  {
  	unsigned short cmdw;
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1068
1069
1070
1071
1072
1073
1074
1075
  
  	if (chip->multichannel) {
  		if (chip->secondary_addr) {
  			wait_for_codec(chip, chip->secondary_addr,
  				       AC97_VENDOR_ID1, msecs_to_jiffies(50));
  		} else {
  			/* my card has the secondary codec */
  			/* at address #3, so the loop is inverted */
58e4334e8   Harvey Harrison   [ALSA] sound: fm8...
1076
1077
1078
  			int i;
  			for (i = 3; i > 0; i--) {
  				if (!wait_for_codec(chip, i, AC97_VENDOR_ID1,
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1079
  						     msecs_to_jiffies(50))) {
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1080
  					cmdw = fm801_readw(chip, AC97_DATA);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1081
1082
  					if (cmdw != 0xffff && cmdw != 0) {
  						chip->secondary = 1;
58e4334e8   Harvey Harrison   [ALSA] sound: fm8...
1083
  						chip->secondary_addr = i;
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
  						break;
  					}
  				}
  			}
  		}
  
  		/* the recovery phase, it seems that probing for non-existing codec might */
  		/* cause timeout problems */
  		wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
  	}
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1094
  }
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1095

b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1096
1097
1098
  static void snd_fm801_chip_init(struct fm801 *chip)
  {
  	unsigned short cmdw;
6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1099

b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1100
  	/* init volume */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1101
1102
1103
  	fm801_writew(chip, PCM_VOL, 0x0808);
  	fm801_writew(chip, FM_VOL, 0x9f1f);
  	fm801_writew(chip, I2S_VOL, 0x8808);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1104
1105
  
  	/* I2S control - I2S mode */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1106
  	fm801_writew(chip, I2S_MODE, 0x0003);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1107

6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1108
  	/* interrupt setup */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1109
  	cmdw = fm801_readw(chip, IRQ_MASK);
6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1110
1111
1112
1113
  	if (chip->irq < 0)
  		cmdw |= 0x00c3;		/* mask everything, no PCM nor MPU */
  	else
  		cmdw &= ~0x0083;	/* unmask MPU, PLAYBACK & CAPTURE */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1114
  	fm801_writew(chip, IRQ_MASK, cmdw);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1115
1116
  
  	/* interrupt clear */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1117
1118
  	fm801_writew(chip, IRQ_STATUS,
  		     FM801_IRQ_PLAYBACK | FM801_IRQ_CAPTURE | FM801_IRQ_MPU);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1119
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
1120
  static int snd_fm801_free(struct fm801 *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1121
1122
1123
1124
1125
1126
1127
  {
  	unsigned short cmdw;
  
  	if (chip->irq < 0)
  		goto __end_hw;
  
  	/* interrupt setup - mask everything */
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1128
  	cmdw = fm801_readw(chip, IRQ_MASK);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1129
  	cmdw |= 0x00c3;
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1130
  	fm801_writew(chip, IRQ_MASK, cmdw);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1131

d3d33aaba   Andy Shevchenko   ALSA: fm801: stor...
1132
  	devm_free_irq(chip->dev, chip->irq, chip);
e97e98c63   Andy Shevchenko   ALSA: fm801: expl...
1133

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1134
        __end_hw:
fdb62b500   Ondrej Zary   ALSA: fm801: clea...
1135
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
1136
  	if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
c37279b92   Ben Hutchings   ALSA: fm801: Grac...
1137
  		snd_tea575x_exit(&chip->tea);
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
1138
1139
  		v4l2_device_unregister(&chip->v4l2_dev);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1140
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1141
1142
  	return 0;
  }
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
1143
  static int snd_fm801_dev_free(struct snd_device *device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1144
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
1145
  	struct fm801 *chip = device->device_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1146
1147
  	return snd_fm801_free(chip);
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1148
1149
1150
1151
1152
  static int snd_fm801_create(struct snd_card *card,
  			    struct pci_dev *pci,
  			    int tea575x_tuner,
  			    int radio_nr,
  			    struct fm801 **rchip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1153
  {
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
1154
  	struct fm801 *chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1155
  	int err;
efb0ad25d   Takashi Iwai   ALSA: pci: Consti...
1156
  	static const struct snd_device_ops ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1157
1158
1159
1160
  		.dev_free =	snd_fm801_dev_free,
  	};
  
  	*rchip = NULL;
5618955c4   Andy Shevchenko   ALSA: fm801: move...
1161
  	if ((err = pcim_enable_device(pci)) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1162
  		return err;
5618955c4   Andy Shevchenko   ALSA: fm801: move...
1163
1164
  	chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL);
  	if (chip == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1165
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1166
1167
  	spin_lock_init(&chip->reg_lock);
  	chip->card = card;
d3d33aaba   Andy Shevchenko   ALSA: fm801: stor...
1168
  	chip->dev = &pci->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1169
  	chip->irq = -1;
6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1170
  	chip->tea575x_tuner = tea575x_tuner;
5618955c4   Andy Shevchenko   ALSA: fm801: move...
1171
  	if ((err = pci_request_regions(pci, "FM801")) < 0)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1172
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1173
  	chip->port = pci_resource_start(pci, 0);
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
  
  	if (pci->revision >= 0xb1)	/* FM801-AU */
  		chip->multichannel = 1;
  
  	if (!(chip->tea575x_tuner & TUNER_ONLY)) {
  		if (reset_codec(chip) < 0) {
  			dev_info(chip->card->dev,
  				 "Primary AC'97 codec not found, assume SF64-PCR (tuner-only)
  ");
  			chip->tea575x_tuner = 3 | TUNER_ONLY;
  		} else {
  			snd_fm801_chip_multichannel_init(chip);
  		}
  	}
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1188
  	if ((chip->tea575x_tuner & TUNER_ONLY) == 0) {
5618955c4   Andy Shevchenko   ALSA: fm801: move...
1189
1190
1191
1192
  		if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt,
  				IRQF_SHARED, KBUILD_MODNAME, chip)) {
  			dev_err(card->dev, "unable to grab IRQ %d
  ", pci->irq);
6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1193
1194
1195
1196
  			snd_fm801_free(chip);
  			return -EBUSY;
  		}
  		chip->irq = pci->irq;
e41dbd203   Takashi Iwai   ALSA: fm801: Supp...
1197
  		card->sync_irq = chip->irq;
6bbe13ecb   Jaroslav Kysela   [ALSA] fm801: fix...
1198
  		pci_set_master(pci);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1199
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1200

610e1ae9b   Andy Shevchenko   ALSA: fm801: Init...
1201
  	snd_fm801_chip_init(chip);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1202
1203
1204
1205
  	if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
  		snd_fm801_free(chip);
  		return err;
  	}
fdb62b500   Ondrej Zary   ALSA: fm801: clea...
1206
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
1207
1208
1209
1210
1211
1212
1213
  	err = v4l2_device_register(&pci->dev, &chip->v4l2_dev);
  	if (err < 0) {
  		snd_fm801_free(chip);
  		return err;
  	}
  	chip->tea.v4l2_dev = &chip->v4l2_dev;
  	chip->tea.radio_nr = radio_nr;
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
1214
1215
  	chip->tea.private_data = chip;
  	chip->tea.ops = &snd_fm801_tea_ops;
10ca72014   Ondrej Zary   ALSA: tea575x: us...
1216
  	sprintf(chip->tea.bus_info, "PCI:%s", pci_name(pci));
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1217
1218
  	if ((chip->tea575x_tuner & TUNER_TYPE_MASK) > 0 &&
  	    (chip->tea575x_tuner & TUNER_TYPE_MASK) < 4) {
5daf53a6e   Hans de Goede   [media] snd_tea57...
1219
  		if (snd_tea575x_init(&chip->tea, THIS_MODULE)) {
9c7f9abf6   Takashi Iwai   ALSA: fm801: Use ...
1220
1221
  			dev_err(card->dev, "TEA575x radio not found
  ");
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
1222
  			snd_fm801_free(chip);
967600155   Dan Carpenter   ALSA: fm801: add ...
1223
1224
  			return -ENODEV;
  		}
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1225
1226
  	} else if ((chip->tea575x_tuner & TUNER_TYPE_MASK) == 0) {
  		unsigned int tuner_only = chip->tea575x_tuner & TUNER_ONLY;
dbec6719a   Andy Shevchenko   ALSA: fm801: prop...
1227

d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
1228
1229
1230
  		/* autodetect tuner connection */
  		for (tea575x_tuner = 1; tea575x_tuner <= 3; tea575x_tuner++) {
  			chip->tea575x_tuner = tea575x_tuner;
5daf53a6e   Hans de Goede   [media] snd_tea57...
1231
  			if (!snd_tea575x_init(&chip->tea, THIS_MODULE)) {
9c7f9abf6   Takashi Iwai   ALSA: fm801: Use ...
1232
1233
1234
  				dev_info(card->dev,
  					 "detected TEA575x radio type %s
  ",
8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
1235
  					   get_tea575x_gpio(chip)->name);
d7ba858a7   Ondrej Zary   ALSA: fm801: impl...
1236
1237
1238
  				break;
  			}
  		}
967600155   Dan Carpenter   ALSA: fm801: add ...
1239
  		if (tea575x_tuner == 4) {
9c7f9abf6   Takashi Iwai   ALSA: fm801: Use ...
1240
1241
  			dev_err(card->dev, "TEA575x radio not found
  ");
c37279b92   Ben Hutchings   ALSA: fm801: Grac...
1242
  			chip->tea575x_tuner = TUNER_DISABLED;
967600155   Dan Carpenter   ALSA: fm801: add ...
1243
  		}
dbec6719a   Andy Shevchenko   ALSA: fm801: prop...
1244
1245
  
  		chip->tea575x_tuner |= tuner_only;
967600155   Dan Carpenter   ALSA: fm801: add ...
1246
  	}
c37279b92   Ben Hutchings   ALSA: fm801: Grac...
1247
  	if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
8e699d2cc   Takashi Iwai   ALSA: fm801 - Cle...
1248
  		strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name,
c37279b92   Ben Hutchings   ALSA: fm801: Grac...
1249
1250
  			sizeof(chip->tea.card));
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1251
1252
1253
1254
1255
  #endif
  
  	*rchip = chip;
  	return 0;
  }
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1256
1257
  static int snd_card_fm801_probe(struct pci_dev *pci,
  				const struct pci_device_id *pci_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1258
1259
  {
  	static int dev;
a5f22156e   Takashi Iwai   [ALSA] Remove xxx...
1260
1261
1262
  	struct snd_card *card;
  	struct fm801 *chip;
  	struct snd_opl3 *opl3;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1263
1264
1265
1266
1267
1268
1269
1270
  	int err;
  
          if (dev >= SNDRV_CARDS)
                  return -ENODEV;
  	if (!enable[dev]) {
  		dev++;
  		return -ENOENT;
  	}
60c5772b5   Takashi Iwai   ALSA: pci: Conver...
1271
1272
  	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  			   0, &card);
e58de7baf   Takashi Iwai   ALSA: Convert to ...
1273
1274
  	if (err < 0)
  		return err;
d4ecc83b7   Hans Verkuil   [media] tea575x-t...
1275
  	if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], radio_nr[dev], &chip)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1276
1277
1278
  		snd_card_free(card);
  		return err;
  	}
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1279
  	card->private_data = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1280
1281
1282
1283
1284
1285
  
  	strcpy(card->driver, "FM801");
  	strcpy(card->shortname, "ForteMedia FM801-");
  	strcat(card->shortname, chip->multichannel ? "AU" : "AS");
  	sprintf(card->longname, "%s at 0x%lx, irq %i",
  		card->shortname, chip->port, chip->irq);
fb716c0b7   Ondrej Zary   snd-fm801: autode...
1286
  	if (chip->tea575x_tuner & TUNER_ONLY)
e0a5d82a9   Andy Shevchenko   [ALSA] fm801: Sup...
1287
  		goto __fm801_tuner_only;
483337f90   Lars-Peter Clausen   ALSA: fm801: Remo...
1288
  	if ((err = snd_fm801_pcm(chip, 0)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1289
1290
1291
1292
1293
1294
1295
1296
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_fm801_mixer(chip)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1297
  				       chip->port + FM801_MPU401_DATA,
dba8b4699   Clemens Ladisch   ALSA: mpu401: cle...
1298
1299
1300
  				       MPU401_INFO_INTEGRATED |
  				       MPU401_INFO_IRQ_HOOK,
  				       -1, &chip->rmidi)) < 0) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1301
1302
1303
  		snd_card_free(card);
  		return err;
  	}
215dacc28   Andy Shevchenko   ALSA: fm801: intr...
1304
1305
  	if ((err = snd_opl3_create(card, chip->port + FM801_OPL3_BANK0,
  				   chip->port + FM801_OPL3_BANK1,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1306
1307
1308
1309
1310
1311
1312
1313
  				   OPL3_HW_OPL3_FM801, 1, &opl3)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
e0a5d82a9   Andy Shevchenko   [ALSA] fm801: Sup...
1314
        __fm801_tuner_only:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1315
1316
1317
1318
1319
1320
1321
1322
  	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...
1323
  static void snd_card_fm801_remove(struct pci_dev *pci)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1324
1325
  {
  	snd_card_free(pci_get_drvdata(pci));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1326
  }
c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
1327
  #ifdef CONFIG_PM_SLEEP
8045d0fc9   Takashi Iwai   ALSA: fm801: More...
1328
  static const unsigned char saved_regs[] = {
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1329
1330
1331
1332
1333
  	FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
  	FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
  	FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2,
  	FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL,
  };
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1334
  static int snd_fm801_suspend(struct device *dev)
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1335
  {
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1336
  	struct snd_card *card = dev_get_drvdata(dev);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1337
1338
1339
1340
  	struct fm801 *chip = card->private_data;
  	int i;
  
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
14da04b5f   Andy Shevchenko   ALSA: fm801: no n...
1341

b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1342
  	for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
37ba8fca7   Andy Shevchenko   ALSA: fm801: save...
1343
  		chip->saved_regs[i] = fm801_ioread16(chip, saved_regs[i]);
14da04b5f   Andy Shevchenko   ALSA: fm801: no n...
1344
1345
1346
  	if (chip->tea575x_tuner & TUNER_ONLY) {
  		/* FIXME: tea575x suspend */
  	} else {
14da04b5f   Andy Shevchenko   ALSA: fm801: no n...
1347
1348
1349
  		snd_ac97_suspend(chip->ac97);
  		snd_ac97_suspend(chip->ac97_sec);
  	}
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1350
1351
  	return 0;
  }
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1352
  static int snd_fm801_resume(struct device *dev)
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1353
  {
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1354
  	struct snd_card *card = dev_get_drvdata(dev);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1355
1356
  	struct fm801 *chip = card->private_data;
  	int i;
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1357
1358
1359
1360
1361
1362
  	if (chip->tea575x_tuner & TUNER_ONLY) {
  		snd_fm801_chip_init(chip);
  	} else {
  		reset_codec(chip);
  		snd_fm801_chip_multichannel_init(chip);
  		snd_fm801_chip_init(chip);
14da04b5f   Andy Shevchenko   ALSA: fm801: no n...
1363
1364
  		snd_ac97_resume(chip->ac97);
  		snd_ac97_resume(chip->ac97_sec);
b56fa687e   Andy Shevchenko   ALSA: fm801: dete...
1365
  	}
14da04b5f   Andy Shevchenko   ALSA: fm801: no n...
1366

b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1367
  	for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
4b5c15f74   Andy Shevchenko   ALSA: fm801: conv...
1368
  		fm801_iowrite16(chip, saved_regs[i], chip->saved_regs[i]);
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1369

cb41f271d   Andy Shevchenko   ALSA: fm801: rest...
1370
1371
1372
1373
  #ifdef CONFIG_SND_FM801_TEA575X_BOOL
  	if (!(chip->tea575x_tuner & TUNER_DISABLED))
  		snd_tea575x_set_freq(&chip->tea);
  #endif
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1374
1375
1376
1377
  
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  	return 0;
  }
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1378
1379
1380
1381
1382
  
  static SIMPLE_DEV_PM_OPS(snd_fm801_pm, snd_fm801_suspend, snd_fm801_resume);
  #define SND_FM801_PM_OPS	&snd_fm801_pm
  #else
  #define SND_FM801_PM_OPS	NULL
c7561cd80   Takashi Iwai   ALSA: PCI: Replac...
1383
  #endif /* CONFIG_PM_SLEEP */
b1e9ed26a   Takashi Iwai   [ALSA] fm801 - Ad...
1384

e9f66d9b9   Takashi Iwai   ALSA: pci: clean ...
1385
  static struct pci_driver fm801_driver = {
3733e424c   Takashi Iwai   ALSA: Use KBUILD_...
1386
  	.name = KBUILD_MODNAME,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1387
1388
  	.id_table = snd_fm801_ids,
  	.probe = snd_card_fm801_probe,
e23e7a143   Bill Pemberton   ALSA: pci: remove...
1389
  	.remove = snd_card_fm801_remove,
68cb2b559   Takashi Iwai   ALSA: Convert to ...
1390
1391
1392
  	.driver = {
  		.pm = SND_FM801_PM_OPS,
  	},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1393
  };
e9f66d9b9   Takashi Iwai   ALSA: pci: clean ...
1394
  module_pci_driver(fm801_driver);