Lines Matching refs:chip

3     ad1816a.c - lowlevel code for Analog Devices AD1816A chip.
20 static inline int snd_ad1816a_busy_wait(struct snd_ad1816a *chip)
28 snd_printk(KERN_WARNING "chip busy.\n");
32 static inline unsigned char snd_ad1816a_in(struct snd_ad1816a *chip, unsigned char reg)
34 snd_ad1816a_busy_wait(chip);
38 static inline void snd_ad1816a_out(struct snd_ad1816a *chip, unsigned char reg,
41 snd_ad1816a_busy_wait(chip);
45 static inline void snd_ad1816a_out_mask(struct snd_ad1816a *chip, unsigned char reg,
48 snd_ad1816a_out(chip, reg,
49 (value & mask) | (snd_ad1816a_in(chip, reg) & ~mask));
52 static unsigned short snd_ad1816a_read(struct snd_ad1816a *chip, unsigned char reg)
54 snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
55 return snd_ad1816a_in(chip, AD1816A_INDIR_DATA_LOW) |
56 (snd_ad1816a_in(chip, AD1816A_INDIR_DATA_HIGH) << 8);
59 static void snd_ad1816a_write(struct snd_ad1816a *chip, unsigned char reg,
62 snd_ad1816a_out(chip, AD1816A_INDIR_ADDR, reg & 0x3f);
63 snd_ad1816a_out(chip, AD1816A_INDIR_DATA_LOW, value & 0xff);
64 snd_ad1816a_out(chip, AD1816A_INDIR_DATA_HIGH, (value >> 8) & 0xff);
67 static void snd_ad1816a_write_mask(struct snd_ad1816a *chip, unsigned char reg,
70 snd_ad1816a_write(chip, reg,
71 (value & mask) | (snd_ad1816a_read(chip, reg) & ~mask));
75 static unsigned char snd_ad1816a_get_format(struct snd_ad1816a *chip,
97 static int snd_ad1816a_open(struct snd_ad1816a *chip, unsigned int mode)
101 spin_lock_irqsave(&chip->lock, flags);
103 if (chip->mode & mode) {
104 spin_unlock_irqrestore(&chip->lock, flags);
110 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
112 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
116 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
118 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
122 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
124 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
127 chip->mode |= mode;
129 spin_unlock_irqrestore(&chip->lock, flags);
133 static void snd_ad1816a_close(struct snd_ad1816a *chip, unsigned int mode)
137 spin_lock_irqsave(&chip->lock, flags);
141 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
143 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
147 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
149 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
153 snd_ad1816a_out_mask(chip, AD1816A_INTERRUPT_STATUS,
155 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
158 if (!((chip->mode &= ~mode) & AD1816A_MODE_OPEN))
159 chip->mode = 0;
161 spin_unlock_irqrestore(&chip->lock, flags);
165 static int snd_ad1816a_trigger(struct snd_ad1816a *chip, unsigned char what,
173 spin_lock(&chip->lock);
180 snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
183 snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
185 spin_unlock(&chip->lock);
197 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
198 return snd_ad1816a_trigger(chip, AD1816A_PLAYBACK_ENABLE,
204 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
205 return snd_ad1816a_trigger(chip, AD1816A_CAPTURE_ENABLE,
211 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
216 spin_lock_irqsave(&chip->lock, flags);
218 chip->p_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
219 snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
222 snd_dma_program(chip->dma1, runtime->dma_addr, size,
226 if (chip->clock_freq)
227 rate = (rate * 33000) / chip->clock_freq;
228 snd_ad1816a_write(chip, AD1816A_PLAYBACK_SAMPLE_RATE, rate);
229 snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
231 snd_ad1816a_get_format(chip, runtime->format,
234 snd_ad1816a_write(chip, AD1816A_PLAYBACK_BASE_COUNT,
237 spin_unlock_irqrestore(&chip->lock, flags);
243 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
248 spin_lock_irqsave(&chip->lock, flags);
250 chip->c_dma_size = size = snd_pcm_lib_buffer_bytes(substream);
251 snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
254 snd_dma_program(chip->dma2, runtime->dma_addr, size,
258 if (chip->clock_freq)
259 rate = (rate * 33000) / chip->clock_freq;
260 snd_ad1816a_write(chip, AD1816A_CAPTURE_SAMPLE_RATE, rate);
261 snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
263 snd_ad1816a_get_format(chip, runtime->format,
266 snd_ad1816a_write(chip, AD1816A_CAPTURE_BASE_COUNT,
269 spin_unlock_irqrestore(&chip->lock, flags);
276 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
278 if (!(chip->mode & AD1816A_MODE_PLAYBACK))
280 ptr = snd_dma_pointer(chip->dma1, chip->p_dma_size);
286 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
288 if (!(chip->mode & AD1816A_MODE_CAPTURE))
290 ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
297 struct snd_ad1816a *chip = dev_id;
300 spin_lock(&chip->lock);
301 status = snd_ad1816a_in(chip, AD1816A_INTERRUPT_STATUS);
302 spin_unlock(&chip->lock);
304 if ((status & AD1816A_PLAYBACK_IRQ_PENDING) && chip->playback_substream)
305 snd_pcm_period_elapsed(chip->playback_substream);
307 if ((status & AD1816A_CAPTURE_IRQ_PENDING) && chip->capture_substream)
308 snd_pcm_period_elapsed(chip->capture_substream);
310 if ((status & AD1816A_TIMER_IRQ_PENDING) && chip->timer)
311 snd_timer_interrupt(chip->timer, chip->timer->sticks);
313 spin_lock(&chip->lock);
314 snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
315 spin_unlock(&chip->lock);
360 struct snd_ad1816a *chip = snd_timer_chip(timer);
361 snd_ad1816a_close(chip, AD1816A_MODE_TIMER);
367 struct snd_ad1816a *chip = snd_timer_chip(timer);
368 snd_ad1816a_open(chip, AD1816A_MODE_TIMER);
384 struct snd_ad1816a *chip = snd_timer_chip(timer);
385 spin_lock_irqsave(&chip->lock, flags);
386 bits = snd_ad1816a_read(chip, AD1816A_INTERRUPT_ENABLE);
389 snd_ad1816a_write(chip, AD1816A_TIMER_BASE_COUNT,
392 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
395 spin_unlock_irqrestore(&chip->lock, flags);
402 struct snd_ad1816a *chip = snd_timer_chip(timer);
403 spin_lock_irqsave(&chip->lock, flags);
405 snd_ad1816a_write_mask(chip, AD1816A_INTERRUPT_ENABLE,
408 spin_unlock_irqrestore(&chip->lock, flags);
425 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
429 if ((error = snd_ad1816a_open(chip, AD1816A_MODE_PLAYBACK)) < 0)
432 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
433 snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
434 chip->playback_substream = substream;
440 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
444 if ((error = snd_ad1816a_open(chip, AD1816A_MODE_CAPTURE)) < 0)
447 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
448 snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
449 chip->capture_substream = substream;
455 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
457 chip->playback_substream = NULL;
458 snd_ad1816a_close(chip, AD1816A_MODE_PLAYBACK);
464 struct snd_ad1816a *chip = snd_pcm_substream_chip(substream);
466 chip->capture_substream = NULL;
467 snd_ad1816a_close(chip, AD1816A_MODE_CAPTURE);
472 static void snd_ad1816a_init(struct snd_ad1816a *chip)
476 spin_lock_irqsave(&chip->lock, flags);
478 snd_ad1816a_out(chip, AD1816A_INTERRUPT_STATUS, 0x00);
479 snd_ad1816a_out_mask(chip, AD1816A_PLAYBACK_CONFIG,
481 snd_ad1816a_out_mask(chip, AD1816A_CAPTURE_CONFIG,
483 snd_ad1816a_write(chip, AD1816A_INTERRUPT_ENABLE, 0x0000);
484 snd_ad1816a_write_mask(chip, AD1816A_CHIP_CONFIG,
486 snd_ad1816a_write(chip, AD1816A_DSP_CONFIG, 0x0000);
487 snd_ad1816a_write(chip, AD1816A_POWERDOWN_CTRL, 0x0000);
489 spin_unlock_irqrestore(&chip->lock, flags);
493 void snd_ad1816a_suspend(struct snd_ad1816a *chip)
498 spin_lock_irqsave(&chip->lock, flags);
500 chip->image[reg] = snd_ad1816a_read(chip, reg);
501 spin_unlock_irqrestore(&chip->lock, flags);
504 void snd_ad1816a_resume(struct snd_ad1816a *chip)
509 snd_ad1816a_init(chip);
510 spin_lock_irqsave(&chip->lock, flags);
512 snd_ad1816a_write(chip, reg, chip->image[reg]);
513 spin_unlock_irqrestore(&chip->lock, flags);
517 static int snd_ad1816a_probe(struct snd_ad1816a *chip)
521 spin_lock_irqsave(&chip->lock, flags);
523 switch (chip->version = snd_ad1816a_read(chip, AD1816A_VERSION_ID)) {
525 chip->hardware = AD1816A_HW_AD1815;
528 chip->hardware = AD1816A_HW_AD18MAX10;
531 chip->hardware = AD1816A_HW_AD1816A;
534 chip->hardware = AD1816A_HW_AUTO;
537 spin_unlock_irqrestore(&chip->lock, flags);
541 static int snd_ad1816a_free(struct snd_ad1816a *chip)
543 release_and_free_resource(chip->res_port);
544 if (chip->irq >= 0)
545 free_irq(chip->irq, (void *) chip);
546 if (chip->dma1 >= 0) {
547 snd_dma_disable(chip->dma1);
548 free_dma(chip->dma1);
550 if (chip->dma2 >= 0) {
551 snd_dma_disable(chip->dma2);
552 free_dma(chip->dma2);
559 struct snd_ad1816a *chip = device->device_data;
560 return snd_ad1816a_free(chip);
563 static const char *snd_ad1816a_chip_id(struct snd_ad1816a *chip)
565 switch (chip->hardware) {
570 snd_printk(KERN_WARNING "Unknown chip version %d:%d.\n",
571 chip->version, chip->hardware);
578 struct snd_ad1816a *chip)
585 chip->irq = -1;
586 chip->dma1 = -1;
587 chip->dma2 = -1;
589 if ((chip->res_port = request_region(port, 16, "AD1816A")) == NULL) {
591 snd_ad1816a_free(chip);
594 if (request_irq(irq, snd_ad1816a_interrupt, 0, "AD1816A", (void *) chip)) {
596 snd_ad1816a_free(chip);
599 chip->irq = irq;
600 card->sync_irq = chip->irq;
603 snd_ad1816a_free(chip);
606 chip->dma1 = dma1;
609 snd_ad1816a_free(chip);
612 chip->dma2 = dma2;
614 chip->card = card;
615 chip->port = port;
616 spin_lock_init(&chip->lock);
618 if ((error = snd_ad1816a_probe(chip))) {
619 snd_ad1816a_free(chip);
623 snd_ad1816a_init(chip);
626 if ((error = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
627 snd_ad1816a_free(chip);
650 int snd_ad1816a_pcm(struct snd_ad1816a *chip, int device)
655 if ((error = snd_pcm_new(chip->card, "AD1816A", device, 1, 1, &pcm)))
661 pcm->private_data = chip;
662 pcm->info_flags = (chip->dma1 == chip->dma2 ) ? SNDRV_PCM_INFO_JOINT_DUPLEX : 0;
664 strcpy(pcm->name, snd_ad1816a_chip_id(chip));
665 snd_ad1816a_init(chip);
667 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, chip->card->dev,
668 64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
670 chip->pcm = pcm;
674 int snd_ad1816a_timer(struct snd_ad1816a *chip, int device)
682 tid.card = chip->card->number;
685 if ((error = snd_timer_new(chip->card, "AD1816A", &tid, &timer)) < 0)
687 strcpy(timer->name, snd_ad1816a_chip_id(chip));
688 timer->private_data = chip;
689 chip->timer = timer;
710 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
714 spin_lock_irqsave(&chip->lock, flags);
715 val = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL);
716 spin_unlock_irqrestore(&chip->lock, flags);
724 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
734 spin_lock_irqsave(&chip->lock, flags);
735 change = snd_ad1816a_read(chip, AD1816A_ADC_SOURCE_SEL) != val;
736 snd_ad1816a_write(chip, AD1816A_ADC_SOURCE_SEL, val);
737 spin_unlock_irqrestore(&chip->lock, flags);
766 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
773 spin_lock_irqsave(&chip->lock, flags);
774 ucontrol->value.integer.value[0] = (snd_ad1816a_read(chip, reg) >> shift) & mask;
775 spin_unlock_irqrestore(&chip->lock, flags);
783 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
796 spin_lock_irqsave(&chip->lock, flags);
797 old_val = snd_ad1816a_read(chip, reg);
800 snd_ad1816a_write(chip, reg, val);
801 spin_unlock_irqrestore(&chip->lock, flags);
831 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
840 spin_lock_irqsave(&chip->lock, flags);
841 val = snd_ad1816a_read(chip, reg);
844 spin_unlock_irqrestore(&chip->lock, flags);
854 struct snd_ad1816a *chip = snd_kcontrol_chip(kcontrol);
872 spin_lock_irqsave(&chip->lock, flags);
873 old_val = snd_ad1816a_read(chip, reg);
876 snd_ad1816a_write(chip, reg, val1);
877 spin_unlock_irqrestore(&chip->lock, flags);
933 int snd_ad1816a_mixer(struct snd_ad1816a *chip)
939 if (snd_BUG_ON(!chip || !chip->card))
942 card = chip->card;
944 strcpy(card->mixername, snd_ad1816a_chip_id(chip));
947 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ad1816a_controls[idx], chip))) < 0)