Lines Matching +full:pclk +full:- +full:sample
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2005-2009 Atmel Corporation
36 struct clk *pclk;
57 #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
60 __raw_writel((val), (chip)->regs + AC97C_##reg)
62 __raw_readl((chip)->regs + AC97C_##reg)
89 struct snd_pcm_runtime *runtime = substream->runtime;
92 chip->opened++;
93 runtime->hw = atmel_ac97c_hw;
94 if (chip->cur_rate) {
95 runtime->hw.rate_min = chip->cur_rate;
96 runtime->hw.rate_max = chip->cur_rate;
98 if (chip->cur_format)
99 runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
100 chip->playback_substream = substream;
107 struct snd_pcm_runtime *runtime = substream->runtime;
110 chip->opened++;
111 runtime->hw = atmel_ac97c_hw;
112 if (chip->cur_rate) {
113 runtime->hw.rate_min = chip->cur_rate;
114 runtime->hw.rate_max = chip->cur_rate;
116 if (chip->cur_format)
117 runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
118 chip->capture_substream = substream;
127 chip->opened--;
128 if (!chip->opened) {
129 chip->cur_rate = 0;
130 chip->cur_format = 0;
133 chip->playback_substream = NULL;
143 chip->opened--;
144 if (!chip->opened) {
145 chip->cur_rate = 0;
146 chip->cur_format = 0;
149 chip->capture_substream = NULL;
161 chip->cur_rate = params_rate(hw_params);
162 chip->cur_format = params_format(hw_params);
174 chip->cur_rate = params_rate(hw_params);
175 chip->cur_format = params_format(hw_params);
183 struct snd_pcm_runtime *runtime = substream->runtime;
184 int block_size = frames_to_bytes(runtime, runtime->period_size);
188 chip->playback_period = 0;
192 switch (runtime->channels) {
202 return -EINVAL;
206 /* configure sample format and size */
208 if (chip->opened <= 1)
213 switch (runtime->format) {
223 return -EINVAL;
237 if (runtime->rate != 48000) {
247 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
248 runtime->rate);
250 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
251 runtime->rate);
254 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
255 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
256 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR);
257 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
265 struct snd_pcm_runtime *runtime = substream->runtime;
266 int block_size = frames_to_bytes(runtime, runtime->period_size);
270 chip->capture_period = 0;
274 switch (runtime->channels) {
284 return -EINVAL;
288 /* configure sample format and size */
290 if (chip->opened <= 1)
295 switch (runtime->format) {
305 return -EINVAL;
319 if (runtime->rate != 48000) {
329 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
330 runtime->rate);
332 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
333 runtime->rate);
336 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
337 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
338 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR);
339 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
363 if (chip->opened <= 1)
367 return -EINVAL;
371 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
382 ptcr = readl(chip->regs + ATMEL_PDC_PTSR);
395 if (chip->opened <= 1)
399 return -EINVAL;
403 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
411 struct snd_pcm_runtime *runtime = substream->runtime;
415 bytes = readl(chip->regs + ATMEL_PDC_TPR);
416 bytes -= runtime->dma_addr;
419 if (frames >= runtime->buffer_size)
420 frames -= runtime->buffer_size;
428 struct snd_pcm_runtime *runtime = substream->runtime;
432 bytes = readl(chip->regs + ATMEL_PDC_RPR);
433 bytes -= runtime->dma_addr;
436 if (frames >= runtime->buffer_size)
437 frames -= runtime->buffer_size;
471 dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
479 runtime = chip->playback_substream->runtime;
480 block_size = frames_to_bytes(runtime, runtime->period_size);
481 chip->playback_period++;
483 if (chip->playback_period == runtime->periods)
484 chip->playback_period = 0;
485 next_period = chip->playback_period + 1;
486 if (next_period == runtime->periods)
491 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR);
492 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
494 snd_pcm_period_elapsed(chip->playback_substream);
497 runtime = chip->capture_substream->runtime;
498 block_size = frames_to_bytes(runtime, runtime->period_size);
499 chip->capture_period++;
501 if (chip->capture_period == runtime->periods)
502 chip->capture_period = 0;
503 next_period = chip->capture_period + 1;
504 if (next_period == runtime->periods)
509 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR);
510 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
511 snd_pcm_period_elapsed(chip->capture_substream);
517 dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n",
527 dev_err(&chip->pdev->dev, "spurious interrupt sr 0x%08x "
568 retval = snd_ac97_pcm_assign(chip->ac97_bus,
574 retval = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
582 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
585 pcm->private_data = chip;
586 pcm->info_flags = 0;
587 strscpy(pcm->name, chip->card->shortname);
588 chip->pcm = pcm;
598 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
616 } while (--timeout);
618 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
643 } while (--timeout);
645 if (!--write)
656 } while (--timeout);
658 if (!--write)
663 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
674 if (!IS_ERR(chip->reset_pin)) {
675 gpiod_set_value(chip->reset_pin, 0);
678 gpiod_set_value(chip->reset_pin, 1);
687 { .compatible = "atmel,at91sam9263-ac97c", },
694 struct device *dev = &pdev->dev;
698 struct clk *pclk;
708 dev_dbg(&pdev->dev, "no memory resource\n");
709 return -ENXIO;
714 dev_dbg(&pdev->dev, "could not get irq: %d\n", irq);
718 pclk = clk_get(&pdev->dev, "ac97_clk");
719 if (IS_ERR(pclk)) {
720 dev_dbg(&pdev->dev, "no peripheral clock\n");
721 return PTR_ERR(pclk);
723 retval = clk_prepare_enable(pclk);
727 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
731 dev_dbg(&pdev->dev, "could not create sound card device\n");
739 dev_dbg(&pdev->dev, "unable to request irq %d\n", irq);
742 chip->irq = irq;
744 spin_lock_init(&chip->lock);
746 strscpy(card->driver, "Atmel AC97C");
747 strscpy(card->shortname, "Atmel AC97C");
748 strscpy(card->longname, "Atmel AC97 controller");
750 chip->card = card;
751 chip->pclk = pclk;
752 chip->pdev = pdev;
753 chip->regs = ioremap(regs->start, resource_size(regs));
755 if (!chip->regs) {
756 dev_dbg(&pdev->dev, "could not remap register memory\n");
757 retval = -ENOMEM;
761 chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
762 if (IS_ERR(chip->reset_pin))
771 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
773 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
779 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
785 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
791 dev_dbg(&pdev->dev, "could not register sound card\n");
797 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n",
798 chip->regs, irq);
803 iounmap(chip->regs);
809 clk_disable_unprepare(pclk);
811 clk_put(pclk);
818 struct atmel_ac97c *chip = card->private_data;
820 clk_disable_unprepare(chip->pclk);
827 struct atmel_ac97c *chip = card->private_data;
828 int ret = clk_prepare_enable(chip->pclk);
844 clk_disable_unprepare(chip->pclk);
845 clk_put(chip->pclk);
846 iounmap(chip->regs);
847 free_irq(chip->irq, chip);
865 MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");