Lines Matching +full:flip +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * als300.c - driver for Avance Logic ALS300/ALS300+ soundcards.
16 * This is why we always use 2 periods. We can then use a flip-flop variable
24 #include <linux/dma-mapping.h>
151 static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
153 u32 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
158 if (((chip->revision > 5 || chip->chip_type == DEVICE_ALS300_PLUS) ^
163 snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
168 struct snd_als300 *chip = card->private_data;
170 snd_als300_set_irq_flag(chip, IRQ_DISABLE);
176 struct snd_als300 *chip = dev_id;
179 status = inb(chip->port+ALS300_IRQ_STATUS);
184 outb(status, chip->port+ALS300_IRQ_STATUS);
186 if (chip->pcm && chip->playback_substream) {
187 data = chip->playback_substream->runtime->private_data;
188 data->period_flipflop ^= 1;
189 snd_pcm_period_elapsed(chip->playback_substream);
194 if (chip->pcm && chip->capture_substream) {
195 data = chip->capture_substream->runtime->private_data;
196 data->period_flipflop ^= 1;
197 snd_pcm_period_elapsed(chip->capture_substream);
207 struct snd_als300 *chip = dev_id;
210 general = inb(chip->port+ALS300P_IRQ_STATUS);
211 mpu = inb(chip->port+MPU_IRQ_STATUS);
212 dram = inb(chip->port+ALS300P_DRAM_IRQ_STATUS);
219 if (chip->pcm && chip->playback_substream) {
220 outb(IRQ_PLAYBACK, chip->port+ALS300P_IRQ_STATUS);
221 data = chip->playback_substream->runtime->private_data;
222 data->period_flipflop ^= 1;
223 snd_pcm_period_elapsed(chip->playback_substream);
228 if (chip->pcm && chip->capture_substream) {
229 outb(IRQ_CAPTURE, chip->port+ALS300P_IRQ_STATUS);
230 data = chip->capture_substream->runtime->private_data;
231 data->period_flipflop ^= 1;
232 snd_pcm_period_elapsed(chip->capture_substream);
245 struct snd_als300 *chip = ac97->private_data;
248 if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
252 outl((reg << 24) | (1 << 31), chip->port+AC97_ACCESS);
255 if ((inb(chip->port+AC97_STATUS) & (AC97_DATA_AVAIL)) != 0)
259 return inw(chip->port+AC97_READ);
266 struct snd_als300 *chip = ac97->private_data;
269 if ((inb(chip->port+AC97_STATUS) & (AC97_BUSY)) == 0)
273 outl((reg << 24) | val, chip->port+AC97_ACCESS);
276 static int snd_als300_ac97(struct snd_als300 *chip)
286 err = snd_ac97_bus(chip->card, 0, &ops, NULL, &bus);
291 ac97.private_data = chip;
293 return snd_ac97_mixer(bus, &ac97, &chip->ac97);
343 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
344 struct snd_pcm_runtime *runtime = substream->runtime;
349 return -ENOMEM;
350 chip->playback_substream = substream;
351 runtime->hw = snd_als300_playback_hw;
352 runtime->private_data = data;
353 data->control_register = PLAYBACK_CONTROL;
354 data->block_counter_register = PLAYBACK_BLOCK_COUNTER;
360 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
363 data = substream->runtime->private_data;
365 chip->playback_substream = NULL;
371 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
372 struct snd_pcm_runtime *runtime = substream->runtime;
377 return -ENOMEM;
378 chip->capture_substream = substream;
379 runtime->hw = snd_als300_capture_hw;
380 runtime->private_data = data;
381 data->control_register = RECORD_CONTROL;
382 data->block_counter_register = RECORD_BLOCK_COUNTER;
388 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
391 data = substream->runtime->private_data;
393 chip->capture_substream = NULL;
400 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
401 struct snd_pcm_runtime *runtime = substream->runtime;
405 guard(spinlock_irq)(&chip->reg_lock);
406 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
414 tmp |= period_bytes - 1;
415 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL, tmp);
418 snd_als300_gcr_write(chip->port, PLAYBACK_START,
419 runtime->dma_addr);
420 snd_als300_gcr_write(chip->port, PLAYBACK_END,
421 runtime->dma_addr + buffer_bytes - 1);
428 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
429 struct snd_pcm_runtime *runtime = substream->runtime;
433 guard(spinlock_irq)(&chip->reg_lock);
434 tmp = snd_als300_gcr_read(chip->port, RECORD_CONTROL);
442 tmp |= period_bytes - 1;
445 snd_als300_gcr_write(chip->port, RECORD_CONTROL, tmp);
446 snd_als300_gcr_write(chip->port, RECORD_START,
447 runtime->dma_addr);
448 snd_als300_gcr_write(chip->port, RECORD_END,
449 runtime->dma_addr + buffer_bytes - 1);
455 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
461 data = substream->runtime->private_data;
462 reg = data->control_register;
464 guard(spinlock)(&chip->reg_lock);
468 tmp = snd_als300_gcr_read(chip->port, reg);
469 data->period_flipflop = 1;
470 snd_als300_gcr_write(chip->port, reg, tmp | TRANSFER_START);
475 tmp = snd_als300_gcr_read(chip->port, reg);
476 snd_als300_gcr_write(chip->port, reg, tmp & ~TRANSFER_START);
480 tmp = snd_als300_gcr_read(chip->port, reg);
481 snd_als300_gcr_write(chip->port, reg, tmp | FIFO_PAUSE);
485 tmp = snd_als300_gcr_read(chip->port, reg);
486 snd_als300_gcr_write(chip->port, reg, tmp & ~FIFO_PAUSE);
491 ret = -EINVAL;
499 struct snd_als300 *chip = snd_pcm_substream_chip(substream);
503 data = substream->runtime->private_data;
506 scoped_guard(spinlock, &chip->reg_lock) {
507 current_ptr = (u16) snd_als300_gcr_read(chip->port,
508 data->block_counter_register) + 4;
513 current_ptr = period_bytes - current_ptr;
515 if (data->period_flipflop == 0)
518 return bytes_to_frames(substream->runtime, current_ptr);
537 static int snd_als300_new_pcm(struct snd_als300 *chip)
542 err = snd_pcm_new(chip->card, "ALS300", 0, 1, 1, &pcm);
545 pcm->private_data = chip;
546 strscpy(pcm->name, "ALS300");
547 chip->pcm = pcm;
555 /* pre-allocation of buffers */
556 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &chip->pci->dev,
561 static void snd_als300_init(struct snd_als300 *chip)
565 guard(spinlock_irqsave)(&chip->reg_lock);
566 chip->revision = (snd_als300_gcr_read(chip->port, MISC_CONTROL) >> 16)
569 tmp = snd_als300_gcr_read(chip->port, DRAM_WRITE_CONTROL);
570 snd_als300_gcr_write(chip->port, DRAM_WRITE_CONTROL,
575 snd_als300_set_irq_flag(chip, IRQ_ENABLE);
579 tmp = snd_als300_gcr_read(chip->port, MISC_CONTROL);
580 snd_als300_gcr_write(chip->port, MISC_CONTROL,
584 snd_als300_gcr_write(chip->port, MUS_VOC_VOL, 0);
587 tmp = snd_als300_gcr_read(chip->port, PLAYBACK_CONTROL);
588 snd_als300_gcr_write(chip->port, PLAYBACK_CONTROL,
595 struct snd_als300 *chip = card->private_data;
603 if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
604 dev_err(card->dev, "error setting 28bit DMA mask\n");
605 return -ENXIO;
609 chip->card = card;
610 chip->pci = pci;
611 chip->irq = -1;
612 chip->chip_type = chip_type;
613 spin_lock_init(&chip->reg_lock);
619 chip->port = pci_resource_start(pci, 0);
621 if (chip->chip_type == DEVICE_ALS300_PLUS)
626 if (devm_request_irq(&pci->dev, pci->irq, irq_handler, IRQF_SHARED,
627 KBUILD_MODNAME, chip)) {
628 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
629 return -EBUSY;
631 chip->irq = pci->irq;
632 card->sync_irq = chip->irq;
633 card->private_free = snd_als300_free;
635 snd_als300_init(chip);
637 err = snd_als300_ac97(chip);
639 dev_err(card->dev, "Could not create ac97\n");
643 err = snd_als300_new_pcm(chip);
645 dev_err(card->dev, "Could not create PCM\n");
655 struct snd_als300 *chip = card->private_data;
658 snd_ac97_suspend(chip->ac97);
665 struct snd_als300 *chip = card->private_data;
667 snd_als300_init(chip);
668 snd_ac97_resume(chip->ac97);
681 struct snd_als300 *chip;
685 return -ENODEV;
688 return -ENOENT;
691 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
692 sizeof(*chip), &card);
695 chip = card->private_data;
697 chip_type = pci_id->driver_data;
703 strscpy(card->driver, "ALS300");
704 if (chip->chip_type == DEVICE_ALS300_PLUS)
707 sprintf(card->shortname, "ALS300+ (Rev. %d)", chip->revision);
709 sprintf(card->shortname, "ALS300 (Rev. %c)", 'A' +
710 chip->revision - 1);
711 sprintf(card->longname, "%s at 0x%lx irq %i",
712 card->shortname, chip->port, chip->irq);