0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <linux/delay.h>
0021 #include <linux/init.h>
0022 #include <linux/module.h>
0023 #include <linux/pci.h>
0024 #include <linux/dma-mapping.h>
0025 #include <linux/interrupt.h>
0026 #include <linux/slab.h>
0027 #include <linux/io.h>
0028
0029 #include <sound/core.h>
0030 #include <sound/control.h>
0031 #include <sound/initval.h>
0032 #include <sound/pcm.h>
0033 #include <sound/pcm_params.h>
0034 #include <sound/ac97_codec.h>
0035 #include <sound/opl3.h>
0036
0037
0038 #define IRQ_DISABLE 0
0039 #define IRQ_ENABLE 1
0040
0041
0042 #define AC97_ACCESS 0x00
0043 #define AC97_READ 0x04
0044 #define AC97_STATUS 0x06
0045 #define AC97_DATA_AVAIL (1<<6)
0046 #define AC97_BUSY (1<<7)
0047 #define ALS300_IRQ_STATUS 0x07
0048 #define IRQ_PLAYBACK (1<<3)
0049 #define IRQ_CAPTURE (1<<2)
0050 #define GCR_DATA 0x08
0051 #define GCR_INDEX 0x0C
0052 #define ALS300P_DRAM_IRQ_STATUS 0x0D
0053 #define MPU_IRQ_STATUS 0x0E
0054 #define ALS300P_IRQ_STATUS 0x0F
0055
0056
0057 #define PLAYBACK_START 0x80
0058 #define PLAYBACK_END 0x81
0059 #define PLAYBACK_CONTROL 0x82
0060 #define TRANSFER_START (1<<16)
0061 #define FIFO_PAUSE (1<<17)
0062 #define RECORD_START 0x83
0063 #define RECORD_END 0x84
0064 #define RECORD_CONTROL 0x85
0065 #define DRAM_WRITE_CONTROL 0x8B
0066 #define WRITE_TRANS_START (1<<16)
0067 #define DRAM_MODE_2 (1<<17)
0068 #define MISC_CONTROL 0x8C
0069 #define IRQ_SET_BIT (1<<15)
0070 #define VMUTE_NORMAL (1<<20)
0071 #define MMUTE_NORMAL (1<<21)
0072 #define MUS_VOC_VOL 0x8E
0073 #define PLAYBACK_BLOCK_COUNTER 0x9A
0074 #define RECORD_BLOCK_COUNTER 0x9B
0075
0076 #define DEBUG_PLAY_REC 0
0077
0078 #if DEBUG_PLAY_REC
0079 #define snd_als300_dbgplay(format, args...) printk(KERN_ERR format, ##args)
0080 #else
0081 #define snd_als300_dbgplay(format, args...)
0082 #endif
0083
0084 enum {DEVICE_ALS300, DEVICE_ALS300_PLUS};
0085
0086 MODULE_AUTHOR("Ash Willis <ashwillis@programmer.net>");
0087 MODULE_DESCRIPTION("Avance Logic ALS300");
0088 MODULE_LICENSE("GPL");
0089
0090 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
0091 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
0092 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
0093
0094 module_param_array(index, int, NULL, 0444);
0095 MODULE_PARM_DESC(index, "Index value for ALS300 sound card.");
0096 module_param_array(id, charp, NULL, 0444);
0097 MODULE_PARM_DESC(id, "ID string for ALS300 sound card.");
0098 module_param_array(enable, bool, NULL, 0444);
0099 MODULE_PARM_DESC(enable, "Enable ALS300 sound card.");
0100
0101 struct snd_als300 {
0102 unsigned long port;
0103 spinlock_t reg_lock;
0104 struct snd_card *card;
0105 struct pci_dev *pci;
0106
0107 struct snd_pcm *pcm;
0108 struct snd_pcm_substream *playback_substream;
0109 struct snd_pcm_substream *capture_substream;
0110
0111 struct snd_ac97 *ac97;
0112 struct snd_opl3 *opl3;
0113
0114 struct resource *res_port;
0115
0116 int irq;
0117
0118 int chip_type;
0119
0120 char revision;
0121 };
0122
0123 struct snd_als300_substream_data {
0124 int period_flipflop;
0125 int control_register;
0126 int block_counter_register;
0127 };
0128
0129 static const struct pci_device_id snd_als300_ids[] = {
0130 { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 },
0131 { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS },
0132 { 0, }
0133 };
0134
0135 MODULE_DEVICE_TABLE(pci, snd_als300_ids);
0136
0137 static inline u32 snd_als300_gcr_read(unsigned long port, unsigned short reg)
0138 {
0139 outb(reg, port+GCR_INDEX);
0140 return inl(port+GCR_DATA);
0141 }
0142
0143 static inline void snd_als300_gcr_write(unsigned long port,
0144 unsigned short reg, u32 val)
0145 {
0146 outb(reg, port+GCR_INDEX);
0147 outl(val, port+GCR_DATA);
0148 }
0149
0150
0151 static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
0152 {
0153 u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
0154
0155
0156
0157
0158 if (((chip->revision > 5 || chip->chip_type == DEVICE_ALS300_PLUS) ^
0159 (cmd == IRQ_ENABLE)) == 0)
0160 tmp |= IRQ_SET_BIT;
0161 else
0162 tmp &= ~IRQ_SET_BIT;
0163 snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
0164 }
0165
0166 static void snd_als300_free(struct snd_card *card)
0167 {
0168 struct snd_als300 *chip = card->private_data;
0169
0170 snd_als300_set_irq_flag(chip, IRQ_DISABLE);
0171 }
0172
0173 static irqreturn_t snd_als300_interrupt(int irq, void *dev_id)
0174 {
0175 u8 status;
0176 struct snd_als300 *chip = dev_id;
0177 struct snd_als300_substream_data *data;
0178
0179 status = inb(chip->port+ALS300_IRQ_STATUS);
0180 if (!status)
0181 return IRQ_NONE;
0182
0183
0184 outb(status, chip->port+ALS300_IRQ_STATUS);
0185 if (status & IRQ_PLAYBACK) {
0186 if (chip->pcm && chip->playback_substream) {
0187 data = chip->playback_substream->runtime->private_data;
0188 data->period_flipflop ^= 1;
0189 snd_pcm_period_elapsed(chip->playback_substream);
0190 snd_als300_dbgplay("IRQ_PLAYBACK\n");
0191 }
0192 }
0193 if (status & IRQ_CAPTURE) {
0194 if (chip->pcm && chip->capture_substream) {
0195 data = chip->capture_substream->runtime->private_data;
0196 data->period_flipflop ^= 1;
0197 snd_pcm_period_elapsed(chip->capture_substream);
0198 snd_als300_dbgplay("IRQ_CAPTURE\n");
0199 }
0200 }
0201 return IRQ_HANDLED;
0202 }
0203
0204 static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
0205 {
0206 u8 general, mpu, dram;
0207 struct snd_als300 *chip = dev_id;
0208 struct snd_als300_substream_data *data;
0209
0210 general = inb(chip->port+ALS300P_IRQ_STATUS);
0211 mpu = inb(chip->port+MPU_IRQ_STATUS);
0212 dram = inb(chip->port+ALS300P_DRAM_IRQ_STATUS);
0213
0214
0215 if ((general == 0) && ((mpu & 0x80) == 0) && ((dram & 0x01) == 0))
0216 return IRQ_NONE;
0217
0218 if (general & IRQ_PLAYBACK) {
0219 if (chip->pcm && chip->playback_substream) {
0220 outb(IRQ_PLAYBACK, chip->port+ALS300P_IRQ_STATUS);
0221 data = chip->playback_substream->runtime->private_data;
0222 data->period_flipflop ^= 1;
0223 snd_pcm_period_elapsed(chip->playback_substream);
0224 snd_als300_dbgplay("IRQ_PLAYBACK\n");
0225 }
0226 }
0227 if (general & IRQ_CAPTURE) {
0228 if (chip->pcm && chip->capture_substream) {
0229 outb(IRQ_CAPTURE, chip->port+ALS300P_IRQ_STATUS);
0230 data = chip->capture_substream->runtime->private_data;
0231 data->period_flipflop ^= 1;
0232 snd_pcm_period_elapsed(chip->capture_substream);
0233 snd_als300_dbgplay("IRQ_CAPTURE\n");
0234 }
0235 }
0236
0237
0238 return IRQ_HANDLED;
0239 }
0240
0241 static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97,
0242 unsigned short reg)
0243 {
0244 int i;
0245 struct snd_als300 *chip = ac97->private_data;
0246
0247 for (i = 0; i < 1000; i++) {
0248 if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
0249 break;
0250 udelay(10);
0251 }
0252 outl((reg << 24) | (1 << 31), chip->port+AC97_ACCESS);
0253
0254 for (i = 0; i < 1000; i++) {
0255 if ((inb(chip->port+AC97_STATUS) & (AC97_DATA_AVAIL)) != 0)
0256 break;
0257 udelay(10);
0258 }
0259 return inw(chip->port+AC97_READ);
0260 }
0261
0262 static void snd_als300_ac97_write(struct snd_ac97 *ac97,
0263 unsigned short reg, unsigned short val)
0264 {
0265 int i;
0266 struct snd_als300 *chip = ac97->private_data;
0267
0268 for (i = 0; i < 1000; i++) {
0269 if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
0270 break;
0271 udelay(10);
0272 }
0273 outl((reg << 24) | val, chip->port+AC97_ACCESS);
0274 }
0275
0276 static int snd_als300_ac97(struct snd_als300 *chip)
0277 {
0278 struct snd_ac97_bus *bus;
0279 struct snd_ac97_template ac97;
0280 int err;
0281 static const struct snd_ac97_bus_ops ops = {
0282 .write = snd_als300_ac97_write,
0283 .read = snd_als300_ac97_read,
0284 };
0285
0286 err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus);
0287 if (err < 0)
0288 return err;
0289
0290 memset(&ac97, 0, sizeof(ac97));
0291 ac97.private_data = chip;
0292
0293 return snd_ac97_mixer(bus, &ac97, &chip->ac97);
0294 }
0295
0296
0297
0298
0299
0300
0301
0302
0303 static const struct snd_pcm_hardware snd_als300_playback_hw =
0304 {
0305 .info = (SNDRV_PCM_INFO_MMAP |
0306 SNDRV_PCM_INFO_INTERLEAVED |
0307 SNDRV_PCM_INFO_PAUSE |
0308 SNDRV_PCM_INFO_MMAP_VALID),
0309 .formats = SNDRV_PCM_FMTBIT_S16,
0310 .rates = SNDRV_PCM_RATE_48000,
0311 .rate_min = 48000,
0312 .rate_max = 48000,
0313 .channels_min = 2,
0314 .channels_max = 2,
0315 .buffer_bytes_max = 64 * 1024,
0316 .period_bytes_min = 64,
0317 .period_bytes_max = 32 * 1024,
0318 .periods_min = 2,
0319 .periods_max = 2,
0320 };
0321
0322 static const struct snd_pcm_hardware snd_als300_capture_hw =
0323 {
0324 .info = (SNDRV_PCM_INFO_MMAP |
0325 SNDRV_PCM_INFO_INTERLEAVED |
0326 SNDRV_PCM_INFO_PAUSE |
0327 SNDRV_PCM_INFO_MMAP_VALID),
0328 .formats = SNDRV_PCM_FMTBIT_S16,
0329 .rates = SNDRV_PCM_RATE_48000,
0330 .rate_min = 48000,
0331 .rate_max = 48000,
0332 .channels_min = 2,
0333 .channels_max = 2,
0334 .buffer_bytes_max = 64 * 1024,
0335 .period_bytes_min = 64,
0336 .period_bytes_max = 32 * 1024,
0337 .periods_min = 2,
0338 .periods_max = 2,
0339 };
0340
0341 static int snd_als300_playback_open(struct snd_pcm_substream *substream)
0342 {
0343 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0344 struct snd_pcm_runtime *runtime = substream->runtime;
0345 struct snd_als300_substream_data *data = kzalloc(sizeof(*data),
0346 GFP_KERNEL);
0347
0348 if (!data)
0349 return -ENOMEM;
0350 chip->playback_substream = substream;
0351 runtime->hw = snd_als300_playback_hw;
0352 runtime->private_data = data;
0353 data->control_register = PLAYBACK_CONTROL;
0354 data->block_counter_register = PLAYBACK_BLOCK_COUNTER;
0355 return 0;
0356 }
0357
0358 static int snd_als300_playback_close(struct snd_pcm_substream *substream)
0359 {
0360 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0361 struct snd_als300_substream_data *data;
0362
0363 data = substream->runtime->private_data;
0364 kfree(data);
0365 chip->playback_substream = NULL;
0366 return 0;
0367 }
0368
0369 static int snd_als300_capture_open(struct snd_pcm_substream *substream)
0370 {
0371 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0372 struct snd_pcm_runtime *runtime = substream->runtime;
0373 struct snd_als300_substream_data *data = kzalloc(sizeof(*data),
0374 GFP_KERNEL);
0375
0376 if (!data)
0377 return -ENOMEM;
0378 chip->capture_substream = substream;
0379 runtime->hw = snd_als300_capture_hw;
0380 runtime->private_data = data;
0381 data->control_register = RECORD_CONTROL;
0382 data->block_counter_register = RECORD_BLOCK_COUNTER;
0383 return 0;
0384 }
0385
0386 static int snd_als300_capture_close(struct snd_pcm_substream *substream)
0387 {
0388 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0389 struct snd_als300_substream_data *data;
0390
0391 data = substream->runtime->private_data;
0392 kfree(data);
0393 chip->capture_substream = NULL;
0394 return 0;
0395 }
0396
0397 static int snd_als300_playback_prepare(struct snd_pcm_substream *substream)
0398 {
0399 u32 tmp;
0400 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0401 struct snd_pcm_runtime *runtime = substream->runtime;
0402 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
0403 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
0404
0405 spin_lock_irq(&chip->reg_lock);
0406 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
0407 tmp &= ~TRANSFER_START;
0408
0409 snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n",
0410 period_bytes, buffer_bytes);
0411
0412
0413 tmp &= 0xffff0000;
0414 tmp |= period_bytes - 1;
0415 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, tmp);
0416
0417
0418 snd_als300_gcr_write(chip->port, PLAYBACK_START,
0419 runtime->dma_addr);
0420 snd_als300_gcr_write(chip->port, PLAYBACK_END,
0421 runtime->dma_addr + buffer_bytes - 1);
0422 spin_unlock_irq(&chip->reg_lock);
0423 return 0;
0424 }
0425
0426 static int snd_als300_capture_prepare(struct snd_pcm_substream *substream)
0427 {
0428 u32 tmp;
0429 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0430 struct snd_pcm_runtime *runtime = substream->runtime;
0431 unsigned short period_bytes = snd_pcm_lib_period_bytes(substream);
0432 unsigned short buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
0433
0434 spin_lock_irq(&chip->reg_lock);
0435 tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL);
0436 tmp &= ~TRANSFER_START;
0437
0438 snd_als300_dbgplay("Period bytes: %d Buffer bytes %d\n", period_bytes,
0439 buffer_bytes);
0440
0441
0442 tmp &= 0xffff0000;
0443 tmp |= period_bytes - 1;
0444
0445
0446 snd_als300_gcr_write(chip->port, RECORD_CONTROL, tmp);
0447 snd_als300_gcr_write(chip->port, RECORD_START,
0448 runtime->dma_addr);
0449 snd_als300_gcr_write(chip->port, RECORD_END,
0450 runtime->dma_addr + buffer_bytes - 1);
0451 spin_unlock_irq(&chip->reg_lock);
0452 return 0;
0453 }
0454
0455 static int snd_als300_trigger(struct snd_pcm_substream *substream, int cmd)
0456 {
0457 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0458 u32 tmp;
0459 struct snd_als300_substream_data *data;
0460 unsigned short reg;
0461 int ret = 0;
0462
0463 data = substream->runtime->private_data;
0464 reg = data->control_register;
0465
0466 spin_lock(&chip->reg_lock);
0467 switch (cmd) {
0468 case SNDRV_PCM_TRIGGER_START:
0469 case SNDRV_PCM_TRIGGER_RESUME:
0470 tmp = snd_als300_gcr_read(chip->port, reg);
0471 data->period_flipflop = 1;
0472 snd_als300_gcr_write(chip->port, reg, tmp | TRANSFER_START);
0473 snd_als300_dbgplay("TRIGGER START\n");
0474 break;
0475 case SNDRV_PCM_TRIGGER_STOP:
0476 case SNDRV_PCM_TRIGGER_SUSPEND:
0477 tmp = snd_als300_gcr_read(chip->port, reg);
0478 snd_als300_gcr_write(chip->port, reg, tmp & ~TRANSFER_START);
0479 snd_als300_dbgplay("TRIGGER STOP\n");
0480 break;
0481 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
0482 tmp = snd_als300_gcr_read(chip->port, reg);
0483 snd_als300_gcr_write(chip->port, reg, tmp | FIFO_PAUSE);
0484 snd_als300_dbgplay("TRIGGER PAUSE\n");
0485 break;
0486 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
0487 tmp = snd_als300_gcr_read(chip->port, reg);
0488 snd_als300_gcr_write(chip->port, reg, tmp & ~FIFO_PAUSE);
0489 snd_als300_dbgplay("TRIGGER RELEASE\n");
0490 break;
0491 default:
0492 snd_als300_dbgplay("TRIGGER INVALID\n");
0493 ret = -EINVAL;
0494 }
0495 spin_unlock(&chip->reg_lock);
0496 return ret;
0497 }
0498
0499 static snd_pcm_uframes_t snd_als300_pointer(struct snd_pcm_substream *substream)
0500 {
0501 u16 current_ptr;
0502 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
0503 struct snd_als300_substream_data *data;
0504 unsigned short period_bytes;
0505
0506 data = substream->runtime->private_data;
0507 period_bytes = snd_pcm_lib_period_bytes(substream);
0508
0509 spin_lock(&chip->reg_lock);
0510 current_ptr = (u16) snd_als300_gcr_read(chip->port,
0511 data->block_counter_register) + 4;
0512 spin_unlock(&chip->reg_lock);
0513 if (current_ptr > period_bytes)
0514 current_ptr = 0;
0515 else
0516 current_ptr = period_bytes - current_ptr;
0517
0518 if (data->period_flipflop == 0)
0519 current_ptr += period_bytes;
0520 snd_als300_dbgplay("Pointer (bytes): %d\n", current_ptr);
0521 return bytes_to_frames(substream->runtime, current_ptr);
0522 }
0523
0524 static const struct snd_pcm_ops snd_als300_playback_ops = {
0525 .open = snd_als300_playback_open,
0526 .close = snd_als300_playback_close,
0527 .prepare = snd_als300_playback_prepare,
0528 .trigger = snd_als300_trigger,
0529 .pointer = snd_als300_pointer,
0530 };
0531
0532 static const struct snd_pcm_ops snd_als300_capture_ops = {
0533 .open = snd_als300_capture_open,
0534 .close = snd_als300_capture_close,
0535 .prepare = snd_als300_capture_prepare,
0536 .trigger = snd_als300_trigger,
0537 .pointer = snd_als300_pointer,
0538 };
0539
0540 static int snd_als300_new_pcm(struct snd_als300 *chip)
0541 {
0542 struct snd_pcm *pcm;
0543 int err;
0544
0545 err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm);
0546 if (err < 0)
0547 return err;
0548 pcm->private_data = chip;
0549 strcpy(pcm->name, "ALS300");
0550 chip->pcm = pcm;
0551
0552
0553 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
0554 &snd_als300_playback_ops);
0555 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
0556 &snd_als300_capture_ops);
0557
0558
0559 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
0560 64*1024, 64*1024);
0561 return 0;
0562 }
0563
0564 static void snd_als300_init(struct snd_als300 *chip)
0565 {
0566 unsigned long flags;
0567 u32 tmp;
0568
0569 spin_lock_irqsave(&chip->reg_lock, flags);
0570 chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16)
0571 & 0x0000000F;
0572
0573 tmp = snd_als300_gcr_read(chip->port, DRAM_WRITE_CONTROL);
0574 snd_als300_gcr_write(chip->port, DRAM_WRITE_CONTROL,
0575 (tmp | DRAM_MODE_2)
0576 & ~WRITE_TRANS_START);
0577
0578
0579 snd_als300_set_irq_flag(chip, IRQ_ENABLE);
0580
0581
0582
0583 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
0584 snd_als300_gcr_write(chip->port, MISC_CONTROL,
0585 tmp | VMUTE_NORMAL | MMUTE_NORMAL);
0586
0587
0588 snd_als300_gcr_write(chip->port, MUS_VOC_VOL, 0);
0589
0590
0591 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
0592 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL,
0593 tmp & ~TRANSFER_START);
0594 spin_unlock_irqrestore(&chip->reg_lock, flags);
0595 }
0596
0597 static int snd_als300_create(struct snd_card *card,
0598 struct pci_dev *pci, int chip_type)
0599 {
0600 struct snd_als300 *chip = card->private_data;
0601 void *irq_handler;
0602 int err;
0603
0604 err = pcim_enable_device(pci);
0605 if (err < 0)
0606 return err;
0607
0608 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
0609 dev_err(card->dev, "error setting 28bit DMA mask\n");
0610 return -ENXIO;
0611 }
0612 pci_set_master(pci);
0613
0614 chip->card = card;
0615 chip->pci = pci;
0616 chip->irq = -1;
0617 chip->chip_type = chip_type;
0618 spin_lock_init(&chip->reg_lock);
0619
0620 err = pci_request_regions(pci, "ALS300");
0621 if (err < 0)
0622 return err;
0623
0624 chip->port = pci_resource_start(pci, 0);
0625
0626 if (chip->chip_type == DEVICE_ALS300_PLUS)
0627 irq_handler = snd_als300plus_interrupt;
0628 else
0629 irq_handler = snd_als300_interrupt;
0630
0631 if (devm_request_irq(&pci->dev, pci->irq, irq_handler, IRQF_SHARED,
0632 KBUILD_MODNAME, chip)) {
0633 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
0634 return -EBUSY;
0635 }
0636 chip->irq = pci->irq;
0637 card->sync_irq = chip->irq;
0638 card->private_free = snd_als300_free;
0639
0640 snd_als300_init(chip);
0641
0642 err = snd_als300_ac97(chip);
0643 if (err < 0) {
0644 dev_err(card->dev, "Could not create ac97\n");
0645 return err;
0646 }
0647
0648 err = snd_als300_new_pcm(chip);
0649 if (err < 0) {
0650 dev_err(card->dev, "Could not create PCM\n");
0651 return err;
0652 }
0653
0654 return 0;
0655 }
0656
0657 #ifdef CONFIG_PM_SLEEP
0658 static int snd_als300_suspend(struct device *dev)
0659 {
0660 struct snd_card *card = dev_get_drvdata(dev);
0661 struct snd_als300 *chip = card->private_data;
0662
0663 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
0664 snd_ac97_suspend(chip->ac97);
0665 return 0;
0666 }
0667
0668 static int snd_als300_resume(struct device *dev)
0669 {
0670 struct snd_card *card = dev_get_drvdata(dev);
0671 struct snd_als300 *chip = card->private_data;
0672
0673 snd_als300_init(chip);
0674 snd_ac97_resume(chip->ac97);
0675
0676 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
0677 return 0;
0678 }
0679
0680 static SIMPLE_DEV_PM_OPS(snd_als300_pm, snd_als300_suspend, snd_als300_resume);
0681 #define SND_ALS300_PM_OPS &snd_als300_pm
0682 #else
0683 #define SND_ALS300_PM_OPS NULL
0684 #endif
0685
0686 static int snd_als300_probe(struct pci_dev *pci,
0687 const struct pci_device_id *pci_id)
0688 {
0689 static int dev;
0690 struct snd_card *card;
0691 struct snd_als300 *chip;
0692 int err, chip_type;
0693
0694 if (dev >= SNDRV_CARDS)
0695 return -ENODEV;
0696 if (!enable[dev]) {
0697 dev++;
0698 return -ENOENT;
0699 }
0700
0701 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0702 sizeof(*chip), &card);
0703 if (err < 0)
0704 return err;
0705 chip = card->private_data;
0706
0707 chip_type = pci_id->driver_data;
0708
0709 err = snd_als300_create(card, pci, chip_type);
0710 if (err < 0)
0711 goto error;
0712
0713 strcpy(card->driver, "ALS300");
0714 if (chip->chip_type == DEVICE_ALS300_PLUS)
0715
0716
0717 sprintf(card->shortname, "ALS300+ (Rev. %d)", chip->revision);
0718 else
0719 sprintf(card->shortname, "ALS300 (Rev. %c)", 'A' +
0720 chip->revision - 1);
0721 sprintf(card->longname, "%s at 0x%lx irq %i",
0722 card->shortname, chip->port, chip->irq);
0723
0724 err = snd_card_register(card);
0725 if (err < 0)
0726 goto error;
0727
0728 pci_set_drvdata(pci, card);
0729 dev++;
0730 return 0;
0731
0732 error:
0733 snd_card_free(card);
0734 return err;
0735 }
0736
0737 static struct pci_driver als300_driver = {
0738 .name = KBUILD_MODNAME,
0739 .id_table = snd_als300_ids,
0740 .probe = snd_als300_probe,
0741 .driver = {
0742 .pm = SND_ALS300_PM_OPS,
0743 },
0744 };
0745
0746 module_pci_driver(als300_driver);