Blame view

sound/pci/als4000.c 24.8 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
  /*
   *  card-als4000.c - driver for Avance Logic ALS4000 based soundcards.
   *  Copyright (C) 2000 by Bart Hartgers <bart@etpmod.phys.tue.nl>,
   *			  Jaroslav Kysela <perex@suse.cz>
   *  Copyright (C) 2002 by Andreas Mohr <hw7oshyuv3001@sneakemail.com>
   *
   *  Framework borrowed from Massimo Piccioni's card-als100.c.
   *
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
  
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
   * NOTES
   *
   *  Since Avance does not provide any meaningful documentation, and I
   *  bought an ALS4000 based soundcard, I was forced to base this driver
   *  on reverse engineering.
   *
   *  Note: this is no longer true. Pretty verbose chip docu (ALS4000a.PDF)
   *  can be found on the ALSA web site.
   *
   *  The ALS4000 seems to be the PCI-cousin of the ALS100. It contains an
   *  ALS100-like SB DSP/mixer, an OPL3 synth, a MPU401 and a gameport 
   *  interface. These subsystems can be mapped into ISA io-port space, 
   *  using the PCI-interface. In addition, the PCI-bit provides DMA and IRQ 
   *  services to the subsystems.
   * 
   * While ALS4000 is very similar to a SoundBlaster, the differences in
   * DMA and capturing require more changes to the SoundBlaster than
   * desirable, so I made this separate driver.
   * 
   * The ALS4000 can do real full duplex playback/capture.
   *
   * FMDAC:
   * - 0x4f -> port 0x14
   * - port 0x15 |= 1
   *
   * Enable/disable 3D sound:
   * - 0x50 -> port 0x14
   * - change bit 6 (0x40) of port 0x15
   *
   * Set QSound:
   * - 0xdb -> port 0x14
   * - set port 0x15:
   *   0x3e (mode 3), 0x3c (mode 2), 0x3a (mode 1), 0x38 (mode 0)
   *
   * Set KSound:
   * - value -> some port 0x0c0d
   *
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
61
62
63
   * ToDo:
   * - Proper shared IRQ handling?
   * - power management? (card can do voice wakeup according to datasheet!!)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
67
68
69
70
71
72
   */
  
  #include <sound/driver.h>
  #include <asm/io.h>
  #include <linux/init.h>
  #include <linux/pci.h>
  #include <linux/slab.h>
  #include <linux/gameport.h>
  #include <linux/moduleparam.h>
910638ae7   Matthias Gehre   [PATCH] Replace 0...
73
  #include <linux/dma-mapping.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  #include <sound/core.h>
  #include <sound/pcm.h>
  #include <sound/rawmidi.h>
  #include <sound/mpu401.h>
  #include <sound/opl3.h>
  #include <sound/sb.h>
  #include <sound/initval.h>
  
  MODULE_AUTHOR("Bart Hartgers <bart@etpmod.phys.tue.nl>");
  MODULE_DESCRIPTION("Avance Logic ALS4000");
  MODULE_LICENSE("GPL");
  MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS4000}}");
  
  #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
  #define SUPPORT_JOYSTICK 1
  #endif
  
  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
  static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
  #ifdef SUPPORT_JOYSTICK
  static int joystick_port[SNDRV_CARDS];
  #endif
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for ALS4000 soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for ALS4000 soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable ALS4000 soundcard.");
  #ifdef SUPPORT_JOYSTICK
  module_param_array(joystick_port, int, NULL, 0444);
  MODULE_PARM_DESC(joystick_port, "Joystick port address for ALS4000 soundcard. (0 = disabled)");
  #endif
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
108
  struct snd_card_als4000 {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
109
  	/* most frequent access first */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  	unsigned long gcr;
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
111
  	struct pci_dev *pci;
703529140   Takashi Iwai   [ALSA] als4000 - ...
112
  	struct snd_sb *chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
115
  #ifdef SUPPORT_JOYSTICK
  	struct gameport *gameport;
  #endif
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
116
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

f40b68903   Takashi Iwai   [ALSA] Fix sectio...
118
  static struct pci_device_id snd_als4000_ids[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
123
124
125
126
127
128
129
  	{ 0x4005, 0x4000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* ALS4000 */
  	{ 0, }
  };
  
  MODULE_DEVICE_TABLE(pci, snd_als4000_ids);
  
  static inline void snd_als4000_gcr_write_addr(unsigned long port, u32 reg, u32 val)
  {
  	outb(reg, port+0x0c);
  	outl(val, port+0x08);
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
130
  static inline void snd_als4000_gcr_write(struct snd_sb *sb, u32 reg, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131
132
133
134
135
136
137
138
139
  {
  	snd_als4000_gcr_write_addr(sb->alt_port, reg, val);
  }	
  
  static inline u32 snd_als4000_gcr_read_addr(unsigned long port, u32 reg)
  {
  	outb(reg, port+0x0c);
  	return inl(port+0x08);
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
140
  static inline u32 snd_als4000_gcr_read(struct snd_sb *sb, u32 reg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
143
  {
  	return snd_als4000_gcr_read_addr(sb->alt_port, reg);
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
144
  static void snd_als4000_set_rate(struct snd_sb *chip, unsigned int rate)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
147
148
149
150
151
  {
  	if (!(chip->mode & SB_RATE_LOCK)) {
  		snd_sbdsp_command(chip, SB_DSP_SAMPLE_RATE_OUT);
  		snd_sbdsp_command(chip, rate>>8);
  		snd_sbdsp_command(chip, rate);
  	}
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
152
153
  static inline void snd_als4000_set_capture_dma(struct snd_sb *chip,
  					       dma_addr_t addr, unsigned size)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
154
155
156
157
  {
  	snd_als4000_gcr_write(chip, 0xa2, addr);
  	snd_als4000_gcr_write(chip, 0xa3, (size-1));
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
158
159
  static inline void snd_als4000_set_playback_dma(struct snd_sb *chip,
  						dma_addr_t addr, unsigned size)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
163
164
165
166
167
  {
  	snd_als4000_gcr_write(chip, 0x91, addr);
  	snd_als4000_gcr_write(chip, 0x92, (size-1)|0x180000);
  }
  
  #define ALS4000_FORMAT_SIGNED	(1<<0)
  #define ALS4000_FORMAT_16BIT	(1<<1)
  #define ALS4000_FORMAT_STEREO	(1<<2)
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
168
  static int snd_als4000_get_format(struct snd_pcm_runtime *runtime)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
171
172
173
174
175
176
177
178
179
180
181
182
  {
  	int result;
  
  	result = 0;
  	if (snd_pcm_format_signed(runtime->format))
  		result |= ALS4000_FORMAT_SIGNED;
  	if (snd_pcm_format_physical_width(runtime->format) == 16)
  		result |= ALS4000_FORMAT_16BIT;
  	if (runtime->channels > 1)
  		result |= ALS4000_FORMAT_STEREO;
  	return result;
  }
  
  /* structure for setting up playback */
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
183
  static const struct {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  	unsigned char dsp_cmd, dma_on, dma_off, format;
  } playback_cmd_vals[]={
  /* ALS4000_FORMAT_U8_MONO */
  { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_MONO },
  /* ALS4000_FORMAT_S8_MONO */	
  { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_MONO },
  /* ALS4000_FORMAT_U16L_MONO */
  { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_MONO },
  /* ALS4000_FORMAT_S16L_MONO */
  { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_MONO },
  /* ALS4000_FORMAT_U8_STEREO */
  { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_UNS_STEREO },
  /* ALS4000_FORMAT_S8_STEREO */	
  { SB_DSP4_OUT8_AI, SB_DSP_DMA8_ON, SB_DSP_DMA8_OFF, SB_DSP4_MODE_SIGN_STEREO },
  /* ALS4000_FORMAT_U16L_STEREO */
  { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_UNS_STEREO },
  /* ALS4000_FORMAT_S16L_STEREO */
  { SB_DSP4_OUT16_AI, SB_DSP_DMA16_ON, SB_DSP_DMA16_OFF, SB_DSP4_MODE_SIGN_STEREO },
  };
  #define playback_cmd(chip) (playback_cmd_vals[(chip)->playback_format])
  
  /* structure for setting up capture */
  enum { CMD_WIDTH8=0x04, CMD_SIGNED=0x10, CMD_MONO=0x80, CMD_STEREO=0xA0 };
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
207
  static const unsigned char capture_cmd_vals[]=
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
212
213
214
215
216
217
218
  {
  CMD_WIDTH8|CMD_MONO,			/* ALS4000_FORMAT_U8_MONO */
  CMD_WIDTH8|CMD_SIGNED|CMD_MONO,		/* ALS4000_FORMAT_S8_MONO */	
  CMD_MONO,				/* ALS4000_FORMAT_U16L_MONO */
  CMD_SIGNED|CMD_MONO,			/* ALS4000_FORMAT_S16L_MONO */
  CMD_WIDTH8|CMD_STEREO,			/* ALS4000_FORMAT_U8_STEREO */
  CMD_WIDTH8|CMD_SIGNED|CMD_STEREO,	/* ALS4000_FORMAT_S8_STEREO */	
  CMD_STEREO,				/* ALS4000_FORMAT_U16L_STEREO */
  CMD_SIGNED|CMD_STEREO,			/* ALS4000_FORMAT_S16L_STEREO */
  };	
  #define capture_cmd(chip) (capture_cmd_vals[(chip)->capture_format])
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
219
220
  static int snd_als4000_hw_params(struct snd_pcm_substream *substream,
  				 struct snd_pcm_hw_params *hw_params)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
221
222
223
  {
  	return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
224
  static int snd_als4000_hw_free(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
226
227
228
  {
  	snd_pcm_lib_free_pages(substream);
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
229
  static int snd_als4000_capture_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
231
232
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
237
238
239
240
241
242
243
  	unsigned long size;
  	unsigned count;
  
  	chip->capture_format = snd_als4000_get_format(runtime);
  		
  	size = snd_pcm_lib_buffer_bytes(substream);
  	count = snd_pcm_lib_period_bytes(substream);
  	
  	if (chip->capture_format & ALS4000_FORMAT_16BIT)
  		count >>=1;
  	count--;
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
244
  	spin_lock_irq(&chip->reg_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
245
246
  	snd_als4000_set_rate(chip, runtime->rate);
  	snd_als4000_set_capture_dma(chip, runtime->dma_addr, size);
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
247
248
  	spin_unlock_irq(&chip->reg_lock);
  	spin_lock_irq(&chip->mixer_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
  	snd_sbmixer_write(chip, 0xdc, count);
  	snd_sbmixer_write(chip, 0xdd, count>>8);
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
251
  	spin_unlock_irq(&chip->mixer_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
253
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
254
  static int snd_als4000_playback_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
256
257
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
  	unsigned long size;
  	unsigned count;
  
  	chip->playback_format = snd_als4000_get_format(runtime);
  	
  	size = snd_pcm_lib_buffer_bytes(substream);
  	count = snd_pcm_lib_period_bytes(substream);
  	
  	if (chip->playback_format & ALS4000_FORMAT_16BIT)
  		count >>=1;
  	count--;
  	
  	/* FIXME: from second playback on, there's a lot more clicks and pops
  	 * involved here than on first playback. Fiddling with
  	 * tons of different settings didn't help (DMA, speaker on/off,
  	 * reordering, ...). Something seems to get enabled on playback
  	 * that I haven't found out how to disable again, which then causes
  	 * the switching pops to reach the speakers the next time here. */
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
276
  	spin_lock_irq(&chip->reg_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
278
279
280
281
282
283
284
285
286
  	snd_als4000_set_rate(chip, runtime->rate);
  	snd_als4000_set_playback_dma(chip, runtime->dma_addr, size);
  	
  	/* SPEAKER_ON not needed, since dma_on seems to also enable speaker */
  	/* snd_sbdsp_command(chip, SB_DSP_SPEAKER_ON); */
  	snd_sbdsp_command(chip, playback_cmd(chip).dsp_cmd);
  	snd_sbdsp_command(chip, playback_cmd(chip).format);
  	snd_sbdsp_command(chip, count);
  	snd_sbdsp_command(chip, count>>8);
  	snd_sbdsp_command(chip, playback_cmd(chip).dma_off);	
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
287
  	spin_unlock_irq(&chip->reg_lock);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
  	
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
291
  static int snd_als4000_capture_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
293
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
294
295
296
  	int result = 0;
  	
  	spin_lock(&chip->mixer_lock);
703529140   Takashi Iwai   [ALSA] als4000 - ...
297
298
299
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_START:
  	case SNDRV_PCM_TRIGGER_RESUME:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
301
  		chip->mode |= SB_RATE_LOCK_CAPTURE;
  		snd_sbmixer_write(chip, 0xde, capture_cmd(chip));
703529140   Takashi Iwai   [ALSA] als4000 - ...
302
303
304
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  	case SNDRV_PCM_TRIGGER_SUSPEND:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
305
306
  		chip->mode &= ~SB_RATE_LOCK_CAPTURE;
  		snd_sbmixer_write(chip, 0xde, 0);
703529140   Takashi Iwai   [ALSA] als4000 - ...
307
308
  		break;
  	default:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
309
  		result = -EINVAL;
703529140   Takashi Iwai   [ALSA] als4000 - ...
310
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
311
312
313
314
  	}
  	spin_unlock(&chip->mixer_lock);
  	return result;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
315
  static int snd_als4000_playback_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
317
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
319
320
  	int result = 0;
  
  	spin_lock(&chip->reg_lock);
703529140   Takashi Iwai   [ALSA] als4000 - ...
321
322
323
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_START:
  	case SNDRV_PCM_TRIGGER_RESUME:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
324
325
  		chip->mode |= SB_RATE_LOCK_PLAYBACK;
  		snd_sbdsp_command(chip, playback_cmd(chip).dma_on);
703529140   Takashi Iwai   [ALSA] als4000 - ...
326
327
328
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  	case SNDRV_PCM_TRIGGER_SUSPEND:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
329
330
  		snd_sbdsp_command(chip, playback_cmd(chip).dma_off);
  		chip->mode &= ~SB_RATE_LOCK_PLAYBACK;
703529140   Takashi Iwai   [ALSA] als4000 - ...
331
332
  		break;
  	default:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
333
  		result = -EINVAL;
703529140   Takashi Iwai   [ALSA] als4000 - ...
334
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
336
337
338
  	}
  	spin_unlock(&chip->reg_lock);
  	return result;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
339
  static snd_pcm_uframes_t snd_als4000_capture_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
340
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
341
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
342
343
344
345
346
347
348
  	unsigned int result;
  
  	spin_lock(&chip->reg_lock);	
  	result = snd_als4000_gcr_read(chip, 0xa4) & 0xffff;
  	spin_unlock(&chip->reg_lock);
  	return bytes_to_frames( substream->runtime, result );
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
349
  static snd_pcm_uframes_t snd_als4000_playback_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
351
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
352
353
354
355
356
357
358
  	unsigned result;
  
  	spin_lock(&chip->reg_lock);	
  	result = snd_als4000_gcr_read(chip, 0xa0) & 0xffff;
  	spin_unlock(&chip->reg_lock);
  	return bytes_to_frames( substream->runtime, result );
  }
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
359
360
361
362
363
364
365
366
367
368
369
370
  /* FIXME: this IRQ routine doesn't really support IRQ sharing (we always
   * return IRQ_HANDLED no matter whether we actually had an IRQ flag or not).
   * ALS4000a.PDF writes that while ACKing IRQ in PCI block will *not* ACK
   * the IRQ in the SB core, ACKing IRQ in SB block *will* ACK the PCI IRQ
   * register (alt_port + 0x0e). Probably something could be optimized here to
   * query/write one register only...
   * And even if both registers need to be queried, then there's still the
   * question of whether it's actually correct to ACK PCI IRQ before reading
   * SB IRQ like we do now, since ALS4000a.PDF mentions that PCI IRQ will *clear*
   * SB IRQ status.
   * And do we *really* need the lock here for *reading* SB_DSP4_IRQSTATUS??
   * */
7d12e780e   David Howells   IRQ: Maintain reg...
371
  static irqreturn_t snd_als4000_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
372
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
373
  	struct snd_sb *chip = dev_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
374
375
376
377
378
379
380
381
382
383
384
  	unsigned gcr_status;
  	unsigned sb_status;
  
  	/* find out which bit of the ALS4000 produced the interrupt */
  	gcr_status = inb(chip->alt_port + 0xe);
  
  	if ((gcr_status & 0x80) && (chip->playback_substream)) /* playback */
  		snd_pcm_period_elapsed(chip->playback_substream);
  	if ((gcr_status & 0x40) && (chip->capture_substream)) /* capturing */
  		snd_pcm_period_elapsed(chip->capture_substream);
  	if ((gcr_status & 0x10) && (chip->rmidi)) /* MPU401 interrupt */
7d12e780e   David Howells   IRQ: Maintain reg...
385
  		snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
  	/* release the gcr */
  	outb(gcr_status, chip->alt_port + 0xe);
  	
  	spin_lock(&chip->mixer_lock);
  	sb_status = snd_sbmixer_read(chip, SB_DSP4_IRQSTATUS);
  	spin_unlock(&chip->mixer_lock);
  	
  	if (sb_status & SB_IRQTYPE_8BIT) 
  		snd_sb_ack_8bit(chip);
  	if (sb_status & SB_IRQTYPE_16BIT) 
  		snd_sb_ack_16bit(chip);
  	if (sb_status & SB_IRQTYPE_MPUIN)
  		inb(chip->mpu_port);
  	if (sb_status & 0x20)
  		inb(SBP(chip, RESET));
  	return IRQ_HANDLED;
  }
  
  /*****************************************************************/
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
405
  static struct snd_pcm_hardware snd_als4000_playback =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_MMAP_VALID),
  	.formats =		SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
  				SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE,	/* formats */
  	.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 =	65536,
  	.period_bytes_min =	64,
  	.period_bytes_max =	65536,
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0
  };
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
423
  static struct snd_pcm_hardware snd_als4000_capture =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
  {
  	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
  				 SNDRV_PCM_INFO_MMAP_VALID),
  	.formats =		SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U8 |
  				SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_U16_LE,	/* formats */
  	.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 =	65536,
  	.period_bytes_min =	64,
  	.period_bytes_max =	65536,
  	.periods_min =		1,
  	.periods_max =		1024,
  	.fifo_size =		0
  };
  
  /*****************************************************************/
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
443
  static int snd_als4000_playback_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
444
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
445
446
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
447
448
449
450
451
  
  	chip->playback_substream = substream;
  	runtime->hw = snd_als4000_playback;
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
452
  static int snd_als4000_playback_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
453
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
454
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
455
456
457
458
459
  
  	chip->playback_substream = NULL;
  	snd_pcm_lib_free_pages(substream);
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
460
  static int snd_als4000_capture_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
462
463
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
464
465
466
467
468
  
  	chip->capture_substream = substream;
  	runtime->hw = snd_als4000_capture;
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
469
  static int snd_als4000_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
470
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
471
  	struct snd_sb *chip = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
472
473
474
475
476
477
478
  
  	chip->capture_substream = NULL;
  	snd_pcm_lib_free_pages(substream);
  	return 0;
  }
  
  /******************************************************************/
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
479
  static struct snd_pcm_ops snd_als4000_playback_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
480
481
482
483
484
485
486
487
488
  	.open =		snd_als4000_playback_open,
  	.close =	snd_als4000_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_als4000_hw_params,
  	.hw_free =	snd_als4000_hw_free,
  	.prepare =	snd_als4000_playback_prepare,
  	.trigger =	snd_als4000_playback_trigger,
  	.pointer =	snd_als4000_playback_pointer
  };
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
489
  static struct snd_pcm_ops snd_als4000_capture_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
490
491
492
493
494
495
496
497
498
  	.open =		snd_als4000_capture_open,
  	.close =	snd_als4000_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_als4000_hw_params,
  	.hw_free =	snd_als4000_hw_free,
  	.prepare =	snd_als4000_capture_prepare,
  	.trigger =	snd_als4000_capture_trigger,
  	.pointer =	snd_als4000_capture_pointer
  };
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
499
  static int __devinit snd_als4000_pcm(struct snd_sb *chip, int device)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
500
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
501
  	struct snd_pcm *pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
502
503
504
505
  	int err;
  
  	if ((err = snd_pcm_new(chip->card, "ALS4000 DSP", device, 1, 1, &pcm)) < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
508
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
540
  	pcm->private_data = chip;
  	pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_als4000_playback_ops);
  	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_als4000_capture_ops);
  
  	snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci),
  					      64*1024, 64*1024);
  
  	chip->pcm = pcm;
  
  	return 0;
  }
  
  /******************************************************************/
  
  static void snd_als4000_set_addr(unsigned long gcr,
  					unsigned int sb,
  					unsigned int mpu,
  					unsigned int opl,
  					unsigned int game)
  {
  	u32 confA = 0;
  	u32 confB = 0;
  
  	if (mpu > 0)
  		confB |= (mpu | 1) << 16;
  	if (sb > 0)
  		confB |= (sb | 1);
  	if (game > 0)
  		confA |= (game | 1) << 16;
  	if (opl > 0)	
  		confA |= (opl | 1);
  	snd_als4000_gcr_write_addr(gcr, 0xa8, confA);
  	snd_als4000_gcr_write_addr(gcr, 0xa9, confB);
  }
703529140   Takashi Iwai   [ALSA] als4000 - ...
541
  static void snd_als4000_configure(struct snd_sb *chip)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
  {
  	unsigned tmp;
  	int i;
  
  	/* do some more configuration */
  	spin_lock_irq(&chip->mixer_lock);
  	tmp = snd_sbmixer_read(chip, 0xc0);
  	snd_sbmixer_write(chip, 0xc0, tmp|0x80);
  	/* always select DMA channel 0, since we do not actually use DMA */
  	snd_sbmixer_write(chip, SB_DSP4_DMASETUP, SB_DMASETUP_DMA0);
  	snd_sbmixer_write(chip, 0xc0, tmp&0x7f);
  	spin_unlock_irq(&chip->mixer_lock);
  	
  	spin_lock_irq(&chip->reg_lock);
  	/* magic number. Enables interrupts(?) */
  	snd_als4000_gcr_write(chip, 0x8c, 0x28000);
  	for(i = 0x91; i <= 0x96; ++i)
  		snd_als4000_gcr_write(chip, i, 0);
  	
  	snd_als4000_gcr_write(chip, 0x99, snd_als4000_gcr_read(chip, 0x99));
  	spin_unlock_irq(&chip->reg_lock);
  }
  
  #ifdef SUPPORT_JOYSTICK
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
566
  static int __devinit snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
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
  {
  	struct gameport *gp;
  	struct resource *r;
  	int io_port;
  
  	if (joystick_port[dev] == 0)
  		return -ENODEV;
  
  	if (joystick_port[dev] == 1) { /* auto-detect */
  		for (io_port = 0x200; io_port <= 0x218; io_port += 8) {
  			r = request_region(io_port, 8, "ALS4000 gameport");
  			if (r)
  				break;
  		}
  	} else {
  		io_port = joystick_port[dev];
  		r = request_region(io_port, 8, "ALS4000 gameport");
  	}
  
  	if (!r) {
  		printk(KERN_WARNING "als4000: cannot reserve joystick ports
  ");
  		return -EBUSY;
  	}
  
  	acard->gameport = gp = gameport_allocate_port();
  	if (!gp) {
  		printk(KERN_ERR "als4000: cannot allocate memory for gameport
  ");
b1d5776d8   Takashi Iwai   [ALSA] Remove vma...
596
  		release_and_free_resource(r);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
  		return -ENOMEM;
  	}
  
  	gameport_set_name(gp, "ALS4000 Gameport");
  	gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci));
  	gameport_set_dev_parent(gp, &acard->pci->dev);
  	gp->io = io_port;
  	gameport_set_port_data(gp, r);
  
  	/* Enable legacy joystick port */
  	snd_als4000_set_addr(acard->gcr, 0, 0, 0, 1);
  
  	gameport_register_port(acard->gameport);
  
  	return 0;
  }
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
613
  static void snd_als4000_free_gameport(struct snd_card_als4000 *acard)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
615
616
617
618
619
620
621
  {
  	if (acard->gameport) {
  		struct resource *r = gameport_get_port_data(acard->gameport);
  
  		gameport_unregister_port(acard->gameport);
  		acard->gameport = NULL;
  
  		snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0); /* disable joystick */
b1d5776d8   Takashi Iwai   [ALSA] Remove vma...
622
  		release_and_free_resource(r);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
623
624
625
  	}
  }
  #else
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
626
627
  static inline int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev) { return -ENOSYS; }
  static inline void snd_als4000_free_gameport(struct snd_card_als4000 *acard) { }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
  #endif
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
629
  static void snd_card_als4000_free( struct snd_card *card )
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
630
  {
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
631
  	struct snd_card_als4000 * acard = (struct snd_card_als4000 *)card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
632
633
634
635
636
637
638
639
640
641
642
643
644
  
  	/* make sure that interrupts are disabled */
  	snd_als4000_gcr_write_addr( acard->gcr, 0x8c, 0);
  	/* free resources */
  	snd_als4000_free_gameport(acard);
  	pci_release_regions(acard->pci);
  	pci_disable_device(acard->pci);
  }
  
  static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
  					  const struct pci_device_id *pci_id)
  {
  	static int dev;
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
645
646
  	struct snd_card *card;
  	struct snd_card_als4000 *acard;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
647
  	unsigned long gcr;
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
648
649
  	struct snd_sb *chip;
  	struct snd_opl3 *opl3;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
  	unsigned short word;
  	int err;
  
  	if (dev >= SNDRV_CARDS)
  		return -ENODEV;
  	if (!enable[dev]) {
  		dev++;
  		return -ENOENT;
  	}
  
  	/* enable PCI device */
  	if ((err = pci_enable_device(pci)) < 0) {
  		return err;
  	}
  	/* check, if we can restrict PCI DMA transfers to 24 bits */
910638ae7   Matthias Gehre   [PATCH] Replace 0...
665
666
  	if (pci_set_dma_mask(pci, DMA_24BIT_MASK) < 0 ||
  	    pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) {
99b359ba1   Takashi Iwai   [ALSA] Add missin...
667
668
  		snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
  		pci_disable_device(pci);
  		return -ENXIO;
  	}
  
  	if ((err = pci_request_regions(pci, "ALS4000")) < 0) {
  		pci_disable_device(pci);
  		return err;
  	}
  	gcr = pci_resource_start(pci, 0);
  
  	pci_read_config_word(pci, PCI_COMMAND, &word);
  	pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
  	pci_set_master(pci);
  	
  	card = snd_card_new(index[dev], id[dev], THIS_MODULE, 
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
684
  			    sizeof( struct snd_card_als4000 ) );
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
685
686
687
688
689
  	if (card == NULL) {
  		pci_release_regions(pci);
  		pci_disable_device(pci);
  		return -ENOMEM;
  	}
17c39d9a5   Takashi Iwai   [ALSA] Remove xxx...
690
  	acard = (struct snd_card_als4000 *)card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
  	acard->pci = pci;
  	acard->gcr = gcr;
  	card->private_free = snd_card_als4000_free;
  
  	/* disable all legacy ISA stuff */
  	snd_als4000_set_addr(acard->gcr, 0, 0, 0, 0);
  
  	if ((err = snd_sbdsp_create(card,
  				    gcr + 0x10,
  				    pci->irq,
  				    snd_als4000_interrupt,
  				    -1,
  				    -1,
  				    SB_HW_ALS4000,
  				    &chip)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
706
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
707
  	}
703529140   Takashi Iwai   [ALSA] als4000 - ...
708
  	acard->chip = chip;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
709
710
711
712
713
714
715
716
717
718
719
720
721
  
  	chip->pci = pci;
  	chip->alt_port = gcr;
  	snd_card_set_dev(card, &pci->dev);
  
  	snd_als4000_configure(chip);
  
  	strcpy(card->driver, "ALS4000");
  	strcpy(card->shortname, "Avance Logic ALS4000");
  	sprintf(card->longname, "%s at 0x%lx, irq %i",
  		card->shortname, chip->alt_port, chip->irq);
  
  	if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
302e4c2f9   Takashi Iwai   [ALSA] Change an ...
722
723
  				        gcr+0x30, MPU401_INFO_INTEGRATED,
  					pci->irq, 0, &chip->rmidi)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
724
725
726
  		printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?
  ", gcr+0x30);
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
727
728
729
  	}
  
  	if ((err = snd_als4000_pcm(chip, 0)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
730
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
731
732
  	}
  	if ((err = snd_sbmixer_new(chip)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
733
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
734
735
736
737
  	}	    
  
  	if (snd_opl3_create(card, gcr+0x10, gcr+0x12,
  			    OPL3_HW_AUTO, 1, &opl3) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
738
739
  		printk(KERN_ERR "als4000: no OPL device at 0x%lx-0x%lx?
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
740
741
742
  			   gcr+0x10, gcr+0x12 );
  	} else {
  		if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
743
  			goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
744
745
746
747
748
749
  		}
  	}
  
  	snd_als4000_create_gameport(acard, dev);
  
  	if ((err = snd_card_register(card)) < 0) {
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
750
  		goto out_err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
751
752
753
  	}
  	pci_set_drvdata(pci, card);
  	dev++;
ba7301c7d   Andreas Mohr   [ALSA] ALS4000 up...
754
755
756
757
758
759
760
761
  	err = 0;
  	goto out;
  
  out_err:
  	snd_card_free(card);
  	
  out:
  	return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
762
763
764
765
766
767
768
  }
  
  static void __devexit snd_card_als4000_remove(struct pci_dev *pci)
  {
  	snd_card_free(pci_get_drvdata(pci));
  	pci_set_drvdata(pci, NULL);
  }
703529140   Takashi Iwai   [ALSA] als4000 - ...
769
770
771
772
773
774
775
776
777
778
779
  #ifdef CONFIG_PM
  static int snd_als4000_suspend(struct pci_dev *pci, pm_message_t state)
  {
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct snd_card_als4000 *acard = card->private_data;
  	struct snd_sb *chip = acard->chip;
  
  	snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  	
  	snd_pcm_suspend_all(chip->pcm);
  	snd_sbmixer_suspend(chip);
703529140   Takashi Iwai   [ALSA] als4000 - ...
780
781
  	pci_disable_device(pci);
  	pci_save_state(pci);
30b35399c   Takashi Iwai   [ALSA] Various fi...
782
  	pci_set_power_state(pci, pci_choose_state(pci, state));
703529140   Takashi Iwai   [ALSA] als4000 - ...
783
784
785
786
787
788
789
790
  	return 0;
  }
  
  static int snd_als4000_resume(struct pci_dev *pci)
  {
  	struct snd_card *card = pci_get_drvdata(pci);
  	struct snd_card_als4000 *acard = card->private_data;
  	struct snd_sb *chip = acard->chip;
703529140   Takashi Iwai   [ALSA] als4000 - ...
791
  	pci_set_power_state(pci, PCI_D0);
30b35399c   Takashi Iwai   [ALSA] Various fi...
792
793
794
795
796
797
798
799
  	pci_restore_state(pci);
  	if (pci_enable_device(pci) < 0) {
  		printk(KERN_ERR "als4000: pci_enable_device failed, "
  		       "disabling device
  ");
  		snd_card_disconnect(card);
  		return -EIO;
  	}
703529140   Takashi Iwai   [ALSA] als4000 - ...
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
  	pci_set_master(pci);
  
  	snd_als4000_configure(chip);
  	snd_sbdsp_reset(chip);
  	snd_sbmixer_resume(chip);
  
  #ifdef SUPPORT_JOYSTICK
  	if (acard->gameport)
  		snd_als4000_set_addr(acard->gcr, 0, 0, 0, 1);
  #endif
  
  	snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  	return 0;
  }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
815
816
817
818
819
  static struct pci_driver driver = {
  	.name = "ALS4000",
  	.id_table = snd_als4000_ids,
  	.probe = snd_card_als4000_probe,
  	.remove = __devexit_p(snd_card_als4000_remove),
703529140   Takashi Iwai   [ALSA] als4000 - ...
820
821
822
823
  #ifdef CONFIG_PM
  	.suspend = snd_als4000_suspend,
  	.resume = snd_als4000_resume,
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
824
825
826
827
  };
  
  static int __init alsa_card_als4000_init(void)
  {
01d25d460   Takashi Iwai   [ALSA] Replace pc...
828
  	return pci_register_driver(&driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
829
830
831
832
833
834
835
836
837
  }
  
  static void __exit alsa_card_als4000_exit(void)
  {
  	pci_unregister_driver(&driver);
  }
  
  module_init(alsa_card_als4000_init)
  module_exit(alsa_card_als4000_exit)