11a59d1b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2b3a70d5eSAsh Willis /*
3b3a70d5eSAsh Willis * als300.c - driver for Avance Logic ALS300/ALS300+ soundcards.
4b3a70d5eSAsh Willis * Copyright (C) 2005 by Ash Willis <ashwillis@programmer.net>
5b3a70d5eSAsh Willis *
6b3a70d5eSAsh Willis * TODO
7b3a70d5eSAsh Willis * 4 channel playback for ALS300+
8b3a70d5eSAsh Willis * gameport
9b3a70d5eSAsh Willis * mpu401
10b3a70d5eSAsh Willis * opl3
11b3a70d5eSAsh Willis *
12b3a70d5eSAsh Willis * NOTES
13b3a70d5eSAsh Willis * The BLOCK_COUNTER registers for the ALS300(+) return a figure related to
14b3a70d5eSAsh Willis * the position in the current period, NOT the whole buffer. It is important
15b3a70d5eSAsh Willis * to know which period we are in so we can calculate the correct pointer.
16b3a70d5eSAsh Willis * This is why we always use 2 periods. We can then use a flip-flop variable
17b3a70d5eSAsh Willis * to keep track of what period we are in.
18b3a70d5eSAsh Willis */
19b3a70d5eSAsh Willis
20b3a70d5eSAsh Willis #include <linux/delay.h>
21b3a70d5eSAsh Willis #include <linux/init.h>
2265a77217SPaul Gortmaker #include <linux/module.h>
23b3a70d5eSAsh Willis #include <linux/pci.h>
2456b146d3STobias Klauser #include <linux/dma-mapping.h>
25b3a70d5eSAsh Willis #include <linux/interrupt.h>
26b3a70d5eSAsh Willis #include <linux/slab.h>
276cbbfe1cSTakashi Iwai #include <linux/io.h>
28b3a70d5eSAsh Willis
29b3a70d5eSAsh Willis #include <sound/core.h>
30b3a70d5eSAsh Willis #include <sound/control.h>
31b3a70d5eSAsh Willis #include <sound/initval.h>
32b3a70d5eSAsh Willis #include <sound/pcm.h>
33b3a70d5eSAsh Willis #include <sound/pcm_params.h>
34b3a70d5eSAsh Willis #include <sound/ac97_codec.h>
35b3a70d5eSAsh Willis #include <sound/opl3.h>
36b3a70d5eSAsh Willis
37b3a70d5eSAsh Willis /* snd_als300_set_irq_flag */
38b3a70d5eSAsh Willis #define IRQ_DISABLE 0
39b3a70d5eSAsh Willis #define IRQ_ENABLE 1
40b3a70d5eSAsh Willis
41b3a70d5eSAsh Willis /* I/O port layout */
42b3a70d5eSAsh Willis #define AC97_ACCESS 0x00
43b3a70d5eSAsh Willis #define AC97_READ 0x04
44b3a70d5eSAsh Willis #define AC97_STATUS 0x06
45b3a70d5eSAsh Willis #define AC97_DATA_AVAIL (1<<6)
46b3a70d5eSAsh Willis #define AC97_BUSY (1<<7)
47b3a70d5eSAsh Willis #define ALS300_IRQ_STATUS 0x07 /* ALS300 Only */
48b3a70d5eSAsh Willis #define IRQ_PLAYBACK (1<<3)
49b3a70d5eSAsh Willis #define IRQ_CAPTURE (1<<2)
50b3a70d5eSAsh Willis #define GCR_DATA 0x08
51b3a70d5eSAsh Willis #define GCR_INDEX 0x0C
52b3a70d5eSAsh Willis #define ALS300P_DRAM_IRQ_STATUS 0x0D /* ALS300+ Only */
53b3a70d5eSAsh Willis #define MPU_IRQ_STATUS 0x0E /* ALS300 Rev. E+, ALS300+ */
54b3a70d5eSAsh Willis #define ALS300P_IRQ_STATUS 0x0F /* ALS300+ Only */
55b3a70d5eSAsh Willis
56b3a70d5eSAsh Willis /* General Control Registers */
57b3a70d5eSAsh Willis #define PLAYBACK_START 0x80
58b3a70d5eSAsh Willis #define PLAYBACK_END 0x81
59b3a70d5eSAsh Willis #define PLAYBACK_CONTROL 0x82
60b3a70d5eSAsh Willis #define TRANSFER_START (1<<16)
61b3a70d5eSAsh Willis #define FIFO_PAUSE (1<<17)
62b3a70d5eSAsh Willis #define RECORD_START 0x83
63b3a70d5eSAsh Willis #define RECORD_END 0x84
64b3a70d5eSAsh Willis #define RECORD_CONTROL 0x85
65b3a70d5eSAsh Willis #define DRAM_WRITE_CONTROL 0x8B
66b3a70d5eSAsh Willis #define WRITE_TRANS_START (1<<16)
67b3a70d5eSAsh Willis #define DRAM_MODE_2 (1<<17)
68b3a70d5eSAsh Willis #define MISC_CONTROL 0x8C
69b3a70d5eSAsh Willis #define IRQ_SET_BIT (1<<15)
70b3a70d5eSAsh Willis #define VMUTE_NORMAL (1<<20)
71b3a70d5eSAsh Willis #define MMUTE_NORMAL (1<<21)
72b3a70d5eSAsh Willis #define MUS_VOC_VOL 0x8E
73b3a70d5eSAsh Willis #define PLAYBACK_BLOCK_COUNTER 0x9A
74b3a70d5eSAsh Willis #define RECORD_BLOCK_COUNTER 0x9B
75b3a70d5eSAsh Willis
7665ff2357SAsh Willis #define DEBUG_PLAY_REC 0
77b3a70d5eSAsh Willis
78b3a70d5eSAsh Willis #if DEBUG_PLAY_REC
79b3a70d5eSAsh Willis #define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args)
80b3a70d5eSAsh Willis #else
81b3a70d5eSAsh Willis #define snd_als300_dbgplay(format, args...)
82b3a70d5eSAsh Willis #endif
83b3a70d5eSAsh Willis
84b3a70d5eSAsh Willis enum {DEVICE_ALS300, DEVICE_ALS300_PLUS};
85b3a70d5eSAsh Willis
86b3a70d5eSAsh Willis MODULE_AUTHOR("Ash Willis <ashwillis@programmer.net>");
87b3a70d5eSAsh Willis MODULE_DESCRIPTION("Avance Logic ALS300");
88b3a70d5eSAsh Willis MODULE_LICENSE("GPL");
89b3a70d5eSAsh Willis
90b3a70d5eSAsh Willis static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
91b3a70d5eSAsh Willis static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
92cde94480STakashi Iwai static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
93cde94480STakashi Iwai
94cde94480STakashi Iwai module_param_array(index, int, NULL, 0444);
95cde94480STakashi Iwai MODULE_PARM_DESC(index, "Index value for ALS300 sound card.");
96cde94480STakashi Iwai module_param_array(id, charp, NULL, 0444);
97cde94480STakashi Iwai MODULE_PARM_DESC(id, "ID string for ALS300 sound card.");
98cde94480STakashi Iwai module_param_array(enable, bool, NULL, 0444);
99cde94480STakashi Iwai MODULE_PARM_DESC(enable, "Enable ALS300 sound card.");
100b3a70d5eSAsh Willis
101b3a70d5eSAsh Willis struct snd_als300 {
102b3a70d5eSAsh Willis unsigned long port;
103b3a70d5eSAsh Willis spinlock_t reg_lock;
104b3a70d5eSAsh Willis struct snd_card *card;
105b3a70d5eSAsh Willis struct pci_dev *pci;
106b3a70d5eSAsh Willis
107b3a70d5eSAsh Willis struct snd_pcm *pcm;
108b3a70d5eSAsh Willis struct snd_pcm_substream *playback_substream;
109b3a70d5eSAsh Willis struct snd_pcm_substream *capture_substream;
110b3a70d5eSAsh Willis
111b3a70d5eSAsh Willis struct snd_ac97 *ac97;
112b3a70d5eSAsh Willis struct snd_opl3 *opl3;
113b3a70d5eSAsh Willis
114b3a70d5eSAsh Willis struct resource *res_port;
115b3a70d5eSAsh Willis
116b3a70d5eSAsh Willis int irq;
117b3a70d5eSAsh Willis
118b3a70d5eSAsh Willis int chip_type; /* ALS300 or ALS300+ */
119b3a70d5eSAsh Willis
120b3a70d5eSAsh Willis char revision;
121b3a70d5eSAsh Willis };
122b3a70d5eSAsh Willis
123b3a70d5eSAsh Willis struct snd_als300_substream_data {
124b3a70d5eSAsh Willis int period_flipflop;
125b3a70d5eSAsh Willis int control_register;
126b3a70d5eSAsh Willis int block_counter_register;
127b3a70d5eSAsh Willis };
128b3a70d5eSAsh Willis
1299baa3c34SBenoit Taine static const struct pci_device_id snd_als300_ids[] = {
130b3a70d5eSAsh Willis { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 },
131b3a70d5eSAsh Willis { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS },
132b3a70d5eSAsh Willis { 0, }
133b3a70d5eSAsh Willis };
134b3a70d5eSAsh Willis
135b3a70d5eSAsh Willis MODULE_DEVICE_TABLE(pci, snd_als300_ids);
136b3a70d5eSAsh Willis
snd_als300_gcr_read(unsigned long port,unsigned short reg)137b3a70d5eSAsh Willis static inline u32 snd_als300_gcr_read(unsigned long port, unsigned short reg)
138b3a70d5eSAsh Willis {
139b3a70d5eSAsh Willis outb(reg, port+GCR_INDEX);
140b3a70d5eSAsh Willis return inl(port+GCR_DATA);
141b3a70d5eSAsh Willis }
142b3a70d5eSAsh Willis
snd_als300_gcr_write(unsigned long port,unsigned short reg,u32 val)143b3a70d5eSAsh Willis static inline void snd_als300_gcr_write(unsigned long port,
144b3a70d5eSAsh Willis unsigned short reg, u32 val)
145b3a70d5eSAsh Willis {
146b3a70d5eSAsh Willis outb(reg, port+GCR_INDEX);
147b3a70d5eSAsh Willis outl(val, port+GCR_DATA);
148b3a70d5eSAsh Willis }
149b3a70d5eSAsh Willis
150b3a70d5eSAsh Willis /* Enable/Disable Interrupts */
snd_als300_set_irq_flag(struct snd_als300 * chip,int cmd)151b3a70d5eSAsh Willis static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
152b3a70d5eSAsh Willis {
153b3a70d5eSAsh Willis u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
154b3a70d5eSAsh Willis
155b3a70d5eSAsh Willis /* boolean XOR check, since old vs. new hardware have
156b3a70d5eSAsh Willis directly reversed bit setting for ENABLE and DISABLE.
157b3a70d5eSAsh Willis ALS300+ acts like newer versions of ALS300 */
158b3a70d5eSAsh Willis if (((chip->revision > 5 || chip->chip_type == DEVICE_ALS300_PLUS) ^
159b3a70d5eSAsh Willis (cmd == IRQ_ENABLE)) == 0)
160b3a70d5eSAsh Willis tmp |= IRQ_SET_BIT;
161b3a70d5eSAsh Willis else
162b3a70d5eSAsh Willis tmp &= ~IRQ_SET_BIT;
163b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
164b3a70d5eSAsh Willis }
165b3a70d5eSAsh Willis
snd_als300_free(struct snd_card * card)16621a9314cSTakashi Iwai static void snd_als300_free(struct snd_card *card)
167b3a70d5eSAsh Willis {
16821a9314cSTakashi Iwai struct snd_als300 *chip = card->private_data;
169b3a70d5eSAsh Willis
17021a9314cSTakashi Iwai snd_als300_set_irq_flag(chip, IRQ_DISABLE);
171b3a70d5eSAsh Willis }
172b3a70d5eSAsh Willis
snd_als300_interrupt(int irq,void * dev_id)1737d12e780SDavid Howells static irqreturn_t snd_als300_interrupt(int irq, void *dev_id)
174b3a70d5eSAsh Willis {
175b3a70d5eSAsh Willis u8 status;
176b3a70d5eSAsh Willis struct snd_als300 *chip = dev_id;
177b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
178b3a70d5eSAsh Willis
179b3a70d5eSAsh Willis status = inb(chip->port+ALS300_IRQ_STATUS);
180b3a70d5eSAsh Willis if (!status) /* shared IRQ, for different device?? Exit ASAP! */
181b3a70d5eSAsh Willis return IRQ_NONE;
182b3a70d5eSAsh Willis
183b3a70d5eSAsh Willis /* ACK everything ASAP */
184b3a70d5eSAsh Willis outb(status, chip->port+ALS300_IRQ_STATUS);
185b3a70d5eSAsh Willis if (status & IRQ_PLAYBACK) {
186b3a70d5eSAsh Willis if (chip->pcm && chip->playback_substream) {
187b3a70d5eSAsh Willis data = chip->playback_substream->runtime->private_data;
188b3a70d5eSAsh Willis data->period_flipflop ^= 1;
189b3a70d5eSAsh Willis snd_pcm_period_elapsed(chip->playback_substream);
190b3a70d5eSAsh Willis snd_als300_dbgplay("IRQ_PLAYBACK\n");
191b3a70d5eSAsh Willis }
192b3a70d5eSAsh Willis }
193b3a70d5eSAsh Willis if (status & IRQ_CAPTURE) {
194b3a70d5eSAsh Willis if (chip->pcm && chip->capture_substream) {
195b3a70d5eSAsh Willis data = chip->capture_substream->runtime->private_data;
196b3a70d5eSAsh Willis data->period_flipflop ^= 1;
197b3a70d5eSAsh Willis snd_pcm_period_elapsed(chip->capture_substream);
198b3a70d5eSAsh Willis snd_als300_dbgplay("IRQ_CAPTURE\n");
199b3a70d5eSAsh Willis }
200b3a70d5eSAsh Willis }
201b3a70d5eSAsh Willis return IRQ_HANDLED;
202b3a70d5eSAsh Willis }
203b3a70d5eSAsh Willis
snd_als300plus_interrupt(int irq,void * dev_id)2047d12e780SDavid Howells static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
205b3a70d5eSAsh Willis {
206b3a70d5eSAsh Willis u8 general, mpu, dram;
207b3a70d5eSAsh Willis struct snd_als300 *chip = dev_id;
208b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
209b3a70d5eSAsh Willis
210b3a70d5eSAsh Willis general = inb(chip->port+ALS300P_IRQ_STATUS);
211b3a70d5eSAsh Willis mpu = inb(chip->port+MPU_IRQ_STATUS);
212b3a70d5eSAsh Willis dram = inb(chip->port+ALS300P_DRAM_IRQ_STATUS);
213b3a70d5eSAsh Willis
214b3a70d5eSAsh Willis /* shared IRQ, for different device?? Exit ASAP! */
215b3a70d5eSAsh Willis if ((general == 0) && ((mpu & 0x80) == 0) && ((dram & 0x01) == 0))
216b3a70d5eSAsh Willis return IRQ_NONE;
217b3a70d5eSAsh Willis
218b3a70d5eSAsh Willis if (general & IRQ_PLAYBACK) {
219b3a70d5eSAsh Willis if (chip->pcm && chip->playback_substream) {
220b3a70d5eSAsh Willis outb(IRQ_PLAYBACK, chip->port+ALS300P_IRQ_STATUS);
221b3a70d5eSAsh Willis data = chip->playback_substream->runtime->private_data;
222b3a70d5eSAsh Willis data->period_flipflop ^= 1;
223b3a70d5eSAsh Willis snd_pcm_period_elapsed(chip->playback_substream);
224b3a70d5eSAsh Willis snd_als300_dbgplay("IRQ_PLAYBACK\n");
225b3a70d5eSAsh Willis }
226b3a70d5eSAsh Willis }
227b3a70d5eSAsh Willis if (general & IRQ_CAPTURE) {
228b3a70d5eSAsh Willis if (chip->pcm && chip->capture_substream) {
229b3a70d5eSAsh Willis outb(IRQ_CAPTURE, chip->port+ALS300P_IRQ_STATUS);
230b3a70d5eSAsh Willis data = chip->capture_substream->runtime->private_data;
231b3a70d5eSAsh Willis data->period_flipflop ^= 1;
232b3a70d5eSAsh Willis snd_pcm_period_elapsed(chip->capture_substream);
233b3a70d5eSAsh Willis snd_als300_dbgplay("IRQ_CAPTURE\n");
234b3a70d5eSAsh Willis }
235b3a70d5eSAsh Willis }
236b3a70d5eSAsh Willis /* FIXME: Ack other interrupt types. Not important right now as
237b3a70d5eSAsh Willis * those other devices aren't enabled. */
238b3a70d5eSAsh Willis return IRQ_HANDLED;
239b3a70d5eSAsh Willis }
240b3a70d5eSAsh Willis
snd_als300_ac97_read(struct snd_ac97 * ac97,unsigned short reg)241b3a70d5eSAsh Willis static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97,
242b3a70d5eSAsh Willis unsigned short reg)
243b3a70d5eSAsh Willis {
244b3a70d5eSAsh Willis int i;
245b3a70d5eSAsh Willis struct snd_als300 *chip = ac97->private_data;
246b3a70d5eSAsh Willis
247b3a70d5eSAsh Willis for (i = 0; i < 1000; i++) {
248b3a70d5eSAsh Willis if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
249b3a70d5eSAsh Willis break;
250b3a70d5eSAsh Willis udelay(10);
251b3a70d5eSAsh Willis }
252b3a70d5eSAsh Willis outl((reg << 24) | (1 << 31), chip->port+AC97_ACCESS);
253b3a70d5eSAsh Willis
254b3a70d5eSAsh Willis for (i = 0; i < 1000; i++) {
255b3a70d5eSAsh Willis if ((inb(chip->port+AC97_STATUS) & (AC97_DATA_AVAIL)) != 0)
256b3a70d5eSAsh Willis break;
257b3a70d5eSAsh Willis udelay(10);
258b3a70d5eSAsh Willis }
259b3a70d5eSAsh Willis return inw(chip->port+AC97_READ);
260b3a70d5eSAsh Willis }
261b3a70d5eSAsh Willis
snd_als300_ac97_write(struct snd_ac97 * ac97,unsigned short reg,unsigned short val)262b3a70d5eSAsh Willis static void snd_als300_ac97_write(struct snd_ac97 *ac97,
263b3a70d5eSAsh Willis unsigned short reg, unsigned short val)
264b3a70d5eSAsh Willis {
265b3a70d5eSAsh Willis int i;
266b3a70d5eSAsh Willis struct snd_als300 *chip = ac97->private_data;
267b3a70d5eSAsh Willis
268b3a70d5eSAsh Willis for (i = 0; i < 1000; i++) {
269b3a70d5eSAsh Willis if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
270b3a70d5eSAsh Willis break;
271b3a70d5eSAsh Willis udelay(10);
272b3a70d5eSAsh Willis }
273b3a70d5eSAsh Willis outl((reg << 24) | val, chip->port+AC97_ACCESS);
274b3a70d5eSAsh Willis }
275b3a70d5eSAsh Willis
snd_als300_ac97(struct snd_als300 * chip)276b3a70d5eSAsh Willis static int snd_als300_ac97(struct snd_als300 *chip)
277b3a70d5eSAsh Willis {
278b3a70d5eSAsh Willis struct snd_ac97_bus *bus;
279b3a70d5eSAsh Willis struct snd_ac97_template ac97;
280b3a70d5eSAsh Willis int err;
28151055da5STakashi Iwai static const struct snd_ac97_bus_ops ops = {
282b3a70d5eSAsh Willis .write = snd_als300_ac97_write,
283b3a70d5eSAsh Willis .read = snd_als300_ac97_read,
284b3a70d5eSAsh Willis };
285b3a70d5eSAsh Willis
2865bd11527STakashi Iwai err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus);
2875bd11527STakashi Iwai if (err < 0)
288b3a70d5eSAsh Willis return err;
289b3a70d5eSAsh Willis
290b3a70d5eSAsh Willis memset(&ac97, 0, sizeof(ac97));
291b3a70d5eSAsh Willis ac97.private_data = chip;
292b3a70d5eSAsh Willis
293b3a70d5eSAsh Willis return snd_ac97_mixer(bus, &ac97, &chip->ac97);
294b3a70d5eSAsh Willis }
295b3a70d5eSAsh Willis
296b3a70d5eSAsh Willis /* hardware definition
297b3a70d5eSAsh Willis *
298b3a70d5eSAsh Willis * In AC97 mode, we always use 48k/16bit/stereo.
299b3a70d5eSAsh Willis * Any request to change data type is ignored by
300b3a70d5eSAsh Willis * the card when it is running outside of legacy
301b3a70d5eSAsh Willis * mode.
302b3a70d5eSAsh Willis */
303dee49895SBhumika Goyal static const struct snd_pcm_hardware snd_als300_playback_hw =
304b3a70d5eSAsh Willis {
305b3a70d5eSAsh Willis .info = (SNDRV_PCM_INFO_MMAP |
306b3a70d5eSAsh Willis SNDRV_PCM_INFO_INTERLEAVED |
307b3a70d5eSAsh Willis SNDRV_PCM_INFO_PAUSE |
308b3a70d5eSAsh Willis SNDRV_PCM_INFO_MMAP_VALID),
309b3a70d5eSAsh Willis .formats = SNDRV_PCM_FMTBIT_S16,
310b3a70d5eSAsh Willis .rates = SNDRV_PCM_RATE_48000,
311b3a70d5eSAsh Willis .rate_min = 48000,
312b3a70d5eSAsh Willis .rate_max = 48000,
313b3a70d5eSAsh Willis .channels_min = 2,
314b3a70d5eSAsh Willis .channels_max = 2,
315b3a70d5eSAsh Willis .buffer_bytes_max = 64 * 1024,
316b3a70d5eSAsh Willis .period_bytes_min = 64,
317b3a70d5eSAsh Willis .period_bytes_max = 32 * 1024,
318b3a70d5eSAsh Willis .periods_min = 2,
319b3a70d5eSAsh Willis .periods_max = 2,
320b3a70d5eSAsh Willis };
321b3a70d5eSAsh Willis
322dee49895SBhumika Goyal static const struct snd_pcm_hardware snd_als300_capture_hw =
323b3a70d5eSAsh Willis {
324b3a70d5eSAsh Willis .info = (SNDRV_PCM_INFO_MMAP |
325b3a70d5eSAsh Willis SNDRV_PCM_INFO_INTERLEAVED |
326b3a70d5eSAsh Willis SNDRV_PCM_INFO_PAUSE |
327b3a70d5eSAsh Willis SNDRV_PCM_INFO_MMAP_VALID),
328b3a70d5eSAsh Willis .formats = SNDRV_PCM_FMTBIT_S16,
329b3a70d5eSAsh Willis .rates = SNDRV_PCM_RATE_48000,
330b3a70d5eSAsh Willis .rate_min = 48000,
331b3a70d5eSAsh Willis .rate_max = 48000,
332b3a70d5eSAsh Willis .channels_min = 2,
333b3a70d5eSAsh Willis .channels_max = 2,
334b3a70d5eSAsh Willis .buffer_bytes_max = 64 * 1024,
335b3a70d5eSAsh Willis .period_bytes_min = 64,
336b3a70d5eSAsh Willis .period_bytes_max = 32 * 1024,
337b3a70d5eSAsh Willis .periods_min = 2,
338b3a70d5eSAsh Willis .periods_max = 2,
339b3a70d5eSAsh Willis };
340b3a70d5eSAsh Willis
snd_als300_playback_open(struct snd_pcm_substream * substream)341b3a70d5eSAsh Willis static int snd_als300_playback_open(struct snd_pcm_substream *substream)
342b3a70d5eSAsh Willis {
343b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
344b3a70d5eSAsh Willis struct snd_pcm_runtime *runtime = substream->runtime;
345b3a70d5eSAsh Willis struct snd_als300_substream_data *data = kzalloc(sizeof(*data),
346b3a70d5eSAsh Willis GFP_KERNEL);
347b3a70d5eSAsh Willis
34821b3de88SDenis Kirjanov if (!data)
34921b3de88SDenis Kirjanov return -ENOMEM;
350b3a70d5eSAsh Willis chip->playback_substream = substream;
351b3a70d5eSAsh Willis runtime->hw = snd_als300_playback_hw;
352b3a70d5eSAsh Willis runtime->private_data = data;
353b3a70d5eSAsh Willis data->control_register = PLAYBACK_CONTROL;
354b3a70d5eSAsh Willis data->block_counter_register = PLAYBACK_BLOCK_COUNTER;
355b3a70d5eSAsh Willis return 0;
356b3a70d5eSAsh Willis }
357b3a70d5eSAsh Willis
snd_als300_playback_close(struct snd_pcm_substream * substream)358b3a70d5eSAsh Willis static int snd_als300_playback_close(struct snd_pcm_substream *substream)
359b3a70d5eSAsh Willis {
360b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
361b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
362b3a70d5eSAsh Willis
363b3a70d5eSAsh Willis data = substream->runtime->private_data;
364b3a70d5eSAsh Willis kfree(data);
365b3a70d5eSAsh Willis chip->playback_substream = NULL;
366b3a70d5eSAsh Willis return 0;
367b3a70d5eSAsh Willis }
368b3a70d5eSAsh Willis
snd_als300_capture_open(struct snd_pcm_substream * substream)369b3a70d5eSAsh Willis static int snd_als300_capture_open(struct snd_pcm_substream *substream)
370b3a70d5eSAsh Willis {
371b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
372b3a70d5eSAsh Willis struct snd_pcm_runtime *runtime = substream->runtime;
373b3a70d5eSAsh Willis struct snd_als300_substream_data *data = kzalloc(sizeof(*data),
374b3a70d5eSAsh Willis GFP_KERNEL);
375b3a70d5eSAsh Willis
37621b3de88SDenis Kirjanov if (!data)
37721b3de88SDenis Kirjanov return -ENOMEM;
378b3a70d5eSAsh Willis chip->capture_substream = substream;
379b3a70d5eSAsh Willis runtime->hw = snd_als300_capture_hw;
380b3a70d5eSAsh Willis runtime->private_data = data;
381b3a70d5eSAsh Willis data->control_register = RECORD_CONTROL;
382b3a70d5eSAsh Willis data->block_counter_register = RECORD_BLOCK_COUNTER;
383b3a70d5eSAsh Willis return 0;
384b3a70d5eSAsh Willis }
385b3a70d5eSAsh Willis
snd_als300_capture_close(struct snd_pcm_substream * substream)386b3a70d5eSAsh Willis static int snd_als300_capture_close(struct snd_pcm_substream *substream)
387b3a70d5eSAsh Willis {
388b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
389b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
390b3a70d5eSAsh Willis
391b3a70d5eSAsh Willis data = substream->runtime->private_data;
392b3a70d5eSAsh Willis kfree(data);
393b3a70d5eSAsh Willis chip->capture_substream = NULL;
394b3a70d5eSAsh Willis return 0;
395b3a70d5eSAsh Willis }
396b3a70d5eSAsh Willis
snd_als300_playback_prepare(struct snd_pcm_substream * substream)397b3a70d5eSAsh Willis static int snd_als300_playback_prepare(struct snd_pcm_substream *substream)
398b3a70d5eSAsh Willis {
399b3a70d5eSAsh Willis u32 tmp;
400b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
401b3a70d5eSAsh Willis struct snd_pcm_runtime *runtime = substream->runtime;
402b3a70d5eSAsh Willis unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
403b3a70d5eSAsh Willis unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
404b3a70d5eSAsh Willis
405b3a70d5eSAsh Willis spin_lock_irq(&chip->reg_lock);
406b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
407b3a70d5eSAsh Willis tmp &= ~TRANSFER_START;
408b3a70d5eSAsh Willis
409b3a70d5eSAsh Willis snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n",
410b3a70d5eSAsh Willis period_bytes, buffer_bytes);
411b3a70d5eSAsh Willis
412b3a70d5eSAsh Willis /* set block size */
413b3a70d5eSAsh Willis tmp &= 0xffff0000;
414b3a70d5eSAsh Willis tmp |= period_bytes - 1;
415b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, tmp);
416b3a70d5eSAsh Willis
417b3a70d5eSAsh Willis /* set dma area */
418b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, PLAYBACK_START,
419b3a70d5eSAsh Willis runtime->dma_addr);
420b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, PLAYBACK_END,
421b3a70d5eSAsh Willis runtime->dma_addr + buffer_bytes - 1);
422b3a70d5eSAsh Willis spin_unlock_irq(&chip->reg_lock);
423b3a70d5eSAsh Willis return 0;
424b3a70d5eSAsh Willis }
425b3a70d5eSAsh Willis
snd_als300_capture_prepare(struct snd_pcm_substream * substream)426b3a70d5eSAsh Willis static int snd_als300_capture_prepare(struct snd_pcm_substream *substream)
427b3a70d5eSAsh Willis {
428b3a70d5eSAsh Willis u32 tmp;
429b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
430b3a70d5eSAsh Willis struct snd_pcm_runtime *runtime = substream->runtime;
431b3a70d5eSAsh Willis unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
432b3a70d5eSAsh Willis unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
433b3a70d5eSAsh Willis
434b3a70d5eSAsh Willis spin_lock_irq(&chip->reg_lock);
435b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL);
436b3a70d5eSAsh Willis tmp &= ~TRANSFER_START;
437b3a70d5eSAsh Willis
438b3a70d5eSAsh Willis snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n", period_bytes,
439b3a70d5eSAsh Willis buffer_bytes);
440b3a70d5eSAsh Willis
441b3a70d5eSAsh Willis /* set block size */
442b3a70d5eSAsh Willis tmp &= 0xffff0000;
443b3a70d5eSAsh Willis tmp |= period_bytes - 1;
444b3a70d5eSAsh Willis
445b3a70d5eSAsh Willis /* set dma area */
446b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, RECORD_CONTROL, tmp);
447b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, RECORD_START,
448b3a70d5eSAsh Willis runtime->dma_addr);
449b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, RECORD_END,
450b3a70d5eSAsh Willis runtime->dma_addr + buffer_bytes - 1);
451b3a70d5eSAsh Willis spin_unlock_irq(&chip->reg_lock);
452b3a70d5eSAsh Willis return 0;
453b3a70d5eSAsh Willis }
454b3a70d5eSAsh Willis
snd_als300_trigger(struct snd_pcm_substream * substream,int cmd)455b3a70d5eSAsh Willis static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd)
456b3a70d5eSAsh Willis {
457b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
458b3a70d5eSAsh Willis u32 tmp;
459b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
460b3a70d5eSAsh Willis unsigned short reg;
461b3a70d5eSAsh Willis int ret = 0;
462b3a70d5eSAsh Willis
463b3a70d5eSAsh Willis data = substream->runtime->private_data;
464b3a70d5eSAsh Willis reg = data->control_register;
465b3a70d5eSAsh Willis
466b3a70d5eSAsh Willis spin_lock(&chip->reg_lock);
467b3a70d5eSAsh Willis switch (cmd) {
468b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_START:
469b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_RESUME:
470b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, reg);
471b3a70d5eSAsh Willis data->period_flipflop = 1;
472b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, reg, tmp | TRANSFER_START);
473b3a70d5eSAsh Willis snd_als300_dbgplay("TRIGGER START\n");
474b3a70d5eSAsh Willis break;
475b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_STOP:
476b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_SUSPEND:
477b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, reg);
478b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, reg, tmp & ~TRANSFER_START);
479b3a70d5eSAsh Willis snd_als300_dbgplay("TRIGGER STOP\n");
480b3a70d5eSAsh Willis break;
481b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
482b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, reg);
483b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, reg, tmp | FIFO_PAUSE);
484b3a70d5eSAsh Willis snd_als300_dbgplay("TRIGGER PAUSE\n");
485b3a70d5eSAsh Willis break;
486b3a70d5eSAsh Willis case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
487b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, reg);
488b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, reg, tmp & ~FIFO_PAUSE);
489b3a70d5eSAsh Willis snd_als300_dbgplay("TRIGGER RELEASE\n");
490b3a70d5eSAsh Willis break;
491b3a70d5eSAsh Willis default:
492b3a70d5eSAsh Willis snd_als300_dbgplay("TRIGGER INVALID\n");
493b3a70d5eSAsh Willis ret = -EINVAL;
494b3a70d5eSAsh Willis }
495b3a70d5eSAsh Willis spin_unlock(&chip->reg_lock);
496b3a70d5eSAsh Willis return ret;
497b3a70d5eSAsh Willis }
498b3a70d5eSAsh Willis
snd_als300_pointer(struct snd_pcm_substream * substream)499b3a70d5eSAsh Willis static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream)
500b3a70d5eSAsh Willis {
501b3a70d5eSAsh Willis u16 current_ptr;
502b3a70d5eSAsh Willis struct snd_als300 *chip = snd_pcm_substream_chip(substream);
503b3a70d5eSAsh Willis struct snd_als300_substream_data *data;
504b3a70d5eSAsh Willis unsigned short period_bytes;
505b3a70d5eSAsh Willis
506b3a70d5eSAsh Willis data = substream->runtime->private_data;
507b3a70d5eSAsh Willis period_bytes = snd_pcm_lib_period_bytes(substream);
508b3a70d5eSAsh Willis
509b3a70d5eSAsh Willis spin_lock(&chip->reg_lock);
510b3a70d5eSAsh Willis current_ptr = (u16) snd_als300_gcr_read(chip->port,
511b3a70d5eSAsh Willis data->block_counter_register) + 4;
512b3a70d5eSAsh Willis spin_unlock(&chip->reg_lock);
513b3a70d5eSAsh Willis if (current_ptr > period_bytes)
514b3a70d5eSAsh Willis current_ptr = 0;
515b3a70d5eSAsh Willis else
516b3a70d5eSAsh Willis current_ptr = period_bytes - current_ptr;
517b3a70d5eSAsh Willis
518b3a70d5eSAsh Willis if (data->period_flipflop == 0)
519b3a70d5eSAsh Willis current_ptr += period_bytes;
520b3a70d5eSAsh Willis snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr);
521b3a70d5eSAsh Willis return bytes_to_frames(substream->runtime, current_ptr);
522b3a70d5eSAsh Willis }
523b3a70d5eSAsh Willis
5246769e988SJulia Lawall static const struct snd_pcm_ops snd_als300_playback_ops = {
525b3a70d5eSAsh Willis .open = snd_als300_playback_open,
526b3a70d5eSAsh Willis .close = snd_als300_playback_close,
527b3a70d5eSAsh Willis .prepare = snd_als300_playback_prepare,
528b3a70d5eSAsh Willis .trigger = snd_als300_trigger,
529b3a70d5eSAsh Willis .pointer = snd_als300_pointer,
530b3a70d5eSAsh Willis };
531b3a70d5eSAsh Willis
5326769e988SJulia Lawall static const struct snd_pcm_ops snd_als300_capture_ops = {
533b3a70d5eSAsh Willis .open = snd_als300_capture_open,
534b3a70d5eSAsh Willis .close = snd_als300_capture_close,
535b3a70d5eSAsh Willis .prepare = snd_als300_capture_prepare,
536b3a70d5eSAsh Willis .trigger = snd_als300_trigger,
537b3a70d5eSAsh Willis .pointer = snd_als300_pointer,
538b3a70d5eSAsh Willis };
539b3a70d5eSAsh Willis
snd_als300_new_pcm(struct snd_als300 * chip)540e23e7a14SBill Pemberton static int snd_als300_new_pcm(struct snd_als300 *chip)
541b3a70d5eSAsh Willis {
542b3a70d5eSAsh Willis struct snd_pcm *pcm;
543b3a70d5eSAsh Willis int err;
544b3a70d5eSAsh Willis
545b3a70d5eSAsh Willis err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm);
546b3a70d5eSAsh Willis if (err < 0)
547b3a70d5eSAsh Willis return err;
548b3a70d5eSAsh Willis pcm->private_data = chip;
549b3a70d5eSAsh Willis strcpy(pcm->name, "ALS300");
550b3a70d5eSAsh Willis chip->pcm = pcm;
551b3a70d5eSAsh Willis
552b3a70d5eSAsh Willis /* set operators */
553b3a70d5eSAsh Willis snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
554b3a70d5eSAsh Willis &snd_als300_playback_ops);
555b3a70d5eSAsh Willis snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
556b3a70d5eSAsh Willis &snd_als300_capture_ops);
557b3a70d5eSAsh Willis
558b3a70d5eSAsh Willis /* pre-allocation of buffers */
559909c7d2cSTakashi Iwai snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
5606974f8adSTakashi Iwai 64*1024, 64*1024);
561b3a70d5eSAsh Willis return 0;
562b3a70d5eSAsh Willis }
563b3a70d5eSAsh Willis
snd_als300_init(struct snd_als300 * chip)564b3a70d5eSAsh Willis static void snd_als300_init(struct snd_als300 *chip)
565b3a70d5eSAsh Willis {
566b3a70d5eSAsh Willis unsigned long flags;
567b3a70d5eSAsh Willis u32 tmp;
568b3a70d5eSAsh Willis
569b3a70d5eSAsh Willis spin_lock_irqsave(&chip->reg_lock, flags);
570b3a70d5eSAsh Willis chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16)
571b3a70d5eSAsh Willis & 0x0000000F;
572b3a70d5eSAsh Willis /* Setup DRAM */
573b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, DRAM_WRITE_CONTROL);
574b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, DRAM_WRITE_CONTROL,
575b3a70d5eSAsh Willis (tmp | DRAM_MODE_2)
576b3a70d5eSAsh Willis & ~WRITE_TRANS_START);
577b3a70d5eSAsh Willis
578b3a70d5eSAsh Willis /* Enable IRQ output */
579b3a70d5eSAsh Willis snd_als300_set_irq_flag(chip, IRQ_ENABLE);
580b3a70d5eSAsh Willis
581b3a70d5eSAsh Willis /* Unmute hardware devices so their outputs get routed to
582b3a70d5eSAsh Willis * the onboard mixer */
583b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
584b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, MISC_CONTROL,
585b3a70d5eSAsh Willis tmp | VMUTE_NORMAL | MMUTE_NORMAL);
586b3a70d5eSAsh Willis
587b3a70d5eSAsh Willis /* Reset volumes */
588b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, MUS_VOC_VOL, 0);
589b3a70d5eSAsh Willis
590b3a70d5eSAsh Willis /* Make sure playback transfer is stopped */
591b3a70d5eSAsh Willis tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
592b3a70d5eSAsh Willis snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL,
593b3a70d5eSAsh Willis tmp & ~TRANSFER_START);
594b3a70d5eSAsh Willis spin_unlock_irqrestore(&chip->reg_lock, flags);
595b3a70d5eSAsh Willis }
596b3a70d5eSAsh Willis
snd_als300_create(struct snd_card * card,struct pci_dev * pci,int chip_type)597e23e7a14SBill Pemberton static int snd_als300_create(struct snd_card *card,
59821a9314cSTakashi Iwai struct pci_dev *pci, int chip_type)
599b3a70d5eSAsh Willis {
60021a9314cSTakashi Iwai struct snd_als300 *chip = card->private_data;
601b3a70d5eSAsh Willis void *irq_handler;
602b3a70d5eSAsh Willis int err;
603b3a70d5eSAsh Willis
60421a9314cSTakashi Iwai err = pcim_enable_device(pci);
6055bd11527STakashi Iwai if (err < 0)
606b3a70d5eSAsh Willis return err;
607b3a70d5eSAsh Willis
608669f65eaSTakashi Iwai if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
609c778f7ecSTakashi Iwai dev_err(card->dev, "error setting 28bit DMA mask\n");
610b3a70d5eSAsh Willis return -ENXIO;
611b3a70d5eSAsh Willis }
612b3a70d5eSAsh Willis pci_set_master(pci);
613b3a70d5eSAsh Willis
614b3a70d5eSAsh Willis chip->card = card;
615b3a70d5eSAsh Willis chip->pci = pci;
616b3a70d5eSAsh Willis chip->irq = -1;
617b3a70d5eSAsh Willis chip->chip_type = chip_type;
618b3a70d5eSAsh Willis spin_lock_init(&chip->reg_lock);
619b3a70d5eSAsh Willis
6205bd11527STakashi Iwai err = pci_request_regions(pci, "ALS300");
62121a9314cSTakashi Iwai if (err < 0)
622b3a70d5eSAsh Willis return err;
62321a9314cSTakashi Iwai
624b3a70d5eSAsh Willis chip->port = pci_resource_start(pci, 0);
625b3a70d5eSAsh Willis
626b3a70d5eSAsh Willis if (chip->chip_type == DEVICE_ALS300_PLUS)
627b3a70d5eSAsh Willis irq_handler = snd_als300plus_interrupt;
628b3a70d5eSAsh Willis else
629b3a70d5eSAsh Willis irq_handler = snd_als300_interrupt;
630b3a70d5eSAsh Willis
63121a9314cSTakashi Iwai if (devm_request_irq(&pci->dev, pci->irq, irq_handler, IRQF_SHARED,
632934c2b6dSTakashi Iwai KBUILD_MODNAME, chip)) {
633c778f7ecSTakashi Iwai dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
634b3a70d5eSAsh Willis return -EBUSY;
635b3a70d5eSAsh Willis }
636b3a70d5eSAsh Willis chip->irq = pci->irq;
637ea2eab50STakashi Iwai card->sync_irq = chip->irq;
63821a9314cSTakashi Iwai card->private_free = snd_als300_free;
639b3a70d5eSAsh Willis
640b3a70d5eSAsh Willis snd_als300_init(chip);
641b3a70d5eSAsh Willis
64265ff2357SAsh Willis err = snd_als300_ac97(chip);
64365ff2357SAsh Willis if (err < 0) {
644c778f7ecSTakashi Iwai dev_err(card->dev, "Could not create ac97\n");
645b3a70d5eSAsh Willis return err;
646b3a70d5eSAsh Willis }
647b3a70d5eSAsh Willis
6485bd11527STakashi Iwai err = snd_als300_new_pcm(chip);
6495bd11527STakashi Iwai if (err < 0) {
650c778f7ecSTakashi Iwai dev_err(card->dev, "Could not create PCM\n");
651b3a70d5eSAsh Willis return err;
652b3a70d5eSAsh Willis }
653b3a70d5eSAsh Willis
654b3a70d5eSAsh Willis return 0;
655b3a70d5eSAsh Willis }
656b3a70d5eSAsh Willis
657c7561cd8STakashi Iwai #ifdef CONFIG_PM_SLEEP
snd_als300_suspend(struct device * dev)65868cb2b55STakashi Iwai static int snd_als300_suspend(struct device *dev)
659b3a70d5eSAsh Willis {
66068cb2b55STakashi Iwai struct snd_card *card = dev_get_drvdata(dev);
661b3a70d5eSAsh Willis struct snd_als300 *chip = card->private_data;
662b3a70d5eSAsh Willis
663b3a70d5eSAsh Willis snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
664b3a70d5eSAsh Willis snd_ac97_suspend(chip->ac97);
665b3a70d5eSAsh Willis return 0;
666b3a70d5eSAsh Willis }
667b3a70d5eSAsh Willis
snd_als300_resume(struct device * dev)66868cb2b55STakashi Iwai static int snd_als300_resume(struct device *dev)
669b3a70d5eSAsh Willis {
67068cb2b55STakashi Iwai struct snd_card *card = dev_get_drvdata(dev);
671b3a70d5eSAsh Willis struct snd_als300 *chip = card->private_data;
672b3a70d5eSAsh Willis
673b3a70d5eSAsh Willis snd_als300_init(chip);
674b3a70d5eSAsh Willis snd_ac97_resume(chip->ac97);
675b3a70d5eSAsh Willis
676b3a70d5eSAsh Willis snd_power_change_state(card, SNDRV_CTL_POWER_D0);
677b3a70d5eSAsh Willis return 0;
678b3a70d5eSAsh Willis }
67968cb2b55STakashi Iwai
68068cb2b55STakashi Iwai static SIMPLE_DEV_PM_OPS(snd_als300_pm, snd_als300_suspend, snd_als300_resume);
68168cb2b55STakashi Iwai #define SND_ALS300_PM_OPS &snd_als300_pm
68268cb2b55STakashi Iwai #else
68368cb2b55STakashi Iwai #define SND_ALS300_PM_OPS NULL
684b3a70d5eSAsh Willis #endif
685b3a70d5eSAsh Willis
snd_als300_probe(struct pci_dev * pci,const struct pci_device_id * pci_id)686e23e7a14SBill Pemberton static int snd_als300_probe(struct pci_dev *pci,
687b3a70d5eSAsh Willis const struct pci_device_id *pci_id)
688b3a70d5eSAsh Willis {
689b3a70d5eSAsh Willis static int dev;
690b3a70d5eSAsh Willis struct snd_card *card;
691b3a70d5eSAsh Willis struct snd_als300 *chip;
692b3a70d5eSAsh Willis int err, chip_type;
693b3a70d5eSAsh Willis
694b3a70d5eSAsh Willis if (dev >= SNDRV_CARDS)
695b3a70d5eSAsh Willis return -ENODEV;
696b3a70d5eSAsh Willis if (!enable[dev]) {
697b3a70d5eSAsh Willis dev++;
698b3a70d5eSAsh Willis return -ENOENT;
699b3a70d5eSAsh Willis }
700b3a70d5eSAsh Willis
70121a9314cSTakashi Iwai err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
70221a9314cSTakashi Iwai sizeof(*chip), &card);
703e58de7baSTakashi Iwai if (err < 0)
704e58de7baSTakashi Iwai return err;
705f263a2c2STakashi Iwai chip = card->private_data;
706b3a70d5eSAsh Willis
707b3a70d5eSAsh Willis chip_type = pci_id->driver_data;
708b3a70d5eSAsh Willis
70921a9314cSTakashi Iwai err = snd_als300_create(card, pci, chip_type);
71021a9314cSTakashi Iwai if (err < 0)
711*ab8bce9dSTakashi Iwai goto error;
712b3a70d5eSAsh Willis
713b3a70d5eSAsh Willis strcpy(card->driver, "ALS300");
714b3a70d5eSAsh Willis if (chip->chip_type == DEVICE_ALS300_PLUS)
715b3a70d5eSAsh Willis /* don't know much about ALS300+ yet
716b3a70d5eSAsh Willis * print revision number for now */
717b3a70d5eSAsh Willis sprintf(card->shortname, "ALS300+ (Rev. %d)", chip->revision);
718b3a70d5eSAsh Willis else
719b3a70d5eSAsh Willis sprintf(card->shortname, "ALS300 (Rev. %c)", 'A' +
720b3a70d5eSAsh Willis chip->revision - 1);
721b3a70d5eSAsh Willis sprintf(card->longname, "%s at 0x%lx irq %i",
722b3a70d5eSAsh Willis card->shortname, chip->port, chip->irq);
723b3a70d5eSAsh Willis
7245bd11527STakashi Iwai err = snd_card_register(card);
72521a9314cSTakashi Iwai if (err < 0)
726*ab8bce9dSTakashi Iwai goto error;
72721a9314cSTakashi Iwai
728b3a70d5eSAsh Willis pci_set_drvdata(pci, card);
729b3a70d5eSAsh Willis dev++;
730b3a70d5eSAsh Willis return 0;
731*ab8bce9dSTakashi Iwai
732*ab8bce9dSTakashi Iwai error:
733*ab8bce9dSTakashi Iwai snd_card_free(card);
734*ab8bce9dSTakashi Iwai return err;
735b3a70d5eSAsh Willis }
736b3a70d5eSAsh Willis
737e9f66d9bSTakashi Iwai static struct pci_driver als300_driver = {
7383733e424STakashi Iwai .name = KBUILD_MODNAME,
739b3a70d5eSAsh Willis .id_table = snd_als300_ids,
740b3a70d5eSAsh Willis .probe = snd_als300_probe,
74168cb2b55STakashi Iwai .driver = {
74268cb2b55STakashi Iwai .pm = SND_ALS300_PM_OPS,
74368cb2b55STakashi Iwai },
744b3a70d5eSAsh Willis };
745b3a70d5eSAsh Willis
746e9f66d9bSTakashi Iwai module_pci_driver(als300_driver);
747