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; member
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; in atmel_ac97c_playback_open()
92 chip->opened++; in atmel_ac97c_playback_open()
93 runtime->hw = atmel_ac97c_hw; in atmel_ac97c_playback_open()
94 if (chip->cur_rate) { in atmel_ac97c_playback_open()
95 runtime->hw.rate_min = chip->cur_rate; in atmel_ac97c_playback_open()
96 runtime->hw.rate_max = chip->cur_rate; in atmel_ac97c_playback_open()
98 if (chip->cur_format) in atmel_ac97c_playback_open()
99 runtime->hw.formats = pcm_format_to_bits(chip->cur_format); in atmel_ac97c_playback_open()
101 chip->playback_substream = substream; in atmel_ac97c_playback_open()
108 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_ac97c_capture_open()
111 chip->opened++; in atmel_ac97c_capture_open()
112 runtime->hw = atmel_ac97c_hw; in atmel_ac97c_capture_open()
113 if (chip->cur_rate) { in atmel_ac97c_capture_open()
114 runtime->hw.rate_min = chip->cur_rate; in atmel_ac97c_capture_open()
115 runtime->hw.rate_max = chip->cur_rate; in atmel_ac97c_capture_open()
117 if (chip->cur_format) in atmel_ac97c_capture_open()
118 runtime->hw.formats = pcm_format_to_bits(chip->cur_format); in atmel_ac97c_capture_open()
120 chip->capture_substream = substream; in atmel_ac97c_capture_open()
129 chip->opened--; in atmel_ac97c_playback_close()
130 if (!chip->opened) { in atmel_ac97c_playback_close()
131 chip->cur_rate = 0; in atmel_ac97c_playback_close()
132 chip->cur_format = 0; in atmel_ac97c_playback_close()
136 chip->playback_substream = NULL; in atmel_ac97c_playback_close()
146 chip->opened--; in atmel_ac97c_capture_close()
147 if (!chip->opened) { in atmel_ac97c_capture_close()
148 chip->cur_rate = 0; in atmel_ac97c_capture_close()
149 chip->cur_format = 0; in atmel_ac97c_capture_close()
153 chip->capture_substream = NULL; in atmel_ac97c_capture_close()
165 chip->cur_rate = params_rate(hw_params); in atmel_ac97c_playback_hw_params()
166 chip->cur_format = params_format(hw_params); in atmel_ac97c_playback_hw_params()
179 chip->cur_rate = params_rate(hw_params); in atmel_ac97c_capture_hw_params()
180 chip->cur_format = params_format(hw_params); in atmel_ac97c_capture_hw_params()
189 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_ac97c_playback_prepare()
190 int block_size = frames_to_bytes(runtime, runtime->period_size); in atmel_ac97c_playback_prepare()
194 chip->playback_period = 0; in atmel_ac97c_playback_prepare()
198 switch (runtime->channels) { in atmel_ac97c_playback_prepare()
208 return -EINVAL; in atmel_ac97c_playback_prepare()
212 /* configure sample format and size */ in atmel_ac97c_playback_prepare()
214 if (chip->opened <= 1) in atmel_ac97c_playback_prepare()
219 switch (runtime->format) { in atmel_ac97c_playback_prepare()
229 return -EINVAL; in atmel_ac97c_playback_prepare()
243 if (runtime->rate != 48000) { in atmel_ac97c_playback_prepare()
253 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE, in atmel_ac97c_playback_prepare()
254 runtime->rate); in atmel_ac97c_playback_prepare()
256 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", in atmel_ac97c_playback_prepare()
257 runtime->rate); in atmel_ac97c_playback_prepare()
260 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR); in atmel_ac97c_playback_prepare()
261 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR); in atmel_ac97c_playback_prepare()
262 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR); in atmel_ac97c_playback_prepare()
263 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR); in atmel_ac97c_playback_prepare()
271 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_ac97c_capture_prepare()
272 int block_size = frames_to_bytes(runtime, runtime->period_size); in atmel_ac97c_capture_prepare()
276 chip->capture_period = 0; in atmel_ac97c_capture_prepare()
280 switch (runtime->channels) { in atmel_ac97c_capture_prepare()
290 return -EINVAL; in atmel_ac97c_capture_prepare()
294 /* configure sample format and size */ in atmel_ac97c_capture_prepare()
296 if (chip->opened <= 1) in atmel_ac97c_capture_prepare()
301 switch (runtime->format) { in atmel_ac97c_capture_prepare()
311 return -EINVAL; in atmel_ac97c_capture_prepare()
325 if (runtime->rate != 48000) { in atmel_ac97c_capture_prepare()
335 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE, in atmel_ac97c_capture_prepare()
336 runtime->rate); in atmel_ac97c_capture_prepare()
338 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", in atmel_ac97c_capture_prepare()
339 runtime->rate); in atmel_ac97c_capture_prepare()
342 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR); in atmel_ac97c_capture_prepare()
343 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR); in atmel_ac97c_capture_prepare()
344 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR); in atmel_ac97c_capture_prepare()
345 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR); in atmel_ac97c_capture_prepare()
369 if (chip->opened <= 1) in atmel_ac97c_playback_trigger()
373 return -EINVAL; in atmel_ac97c_playback_trigger()
377 writel(ptcr, chip->regs + ATMEL_PDC_PTCR); in atmel_ac97c_playback_trigger()
388 ptcr = readl(chip->regs + ATMEL_PDC_PTSR); in atmel_ac97c_capture_trigger()
401 if (chip->opened <= 1) in atmel_ac97c_capture_trigger()
405 return -EINVAL; in atmel_ac97c_capture_trigger()
409 writel(ptcr, chip->regs + ATMEL_PDC_PTCR); in atmel_ac97c_capture_trigger()
417 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_ac97c_playback_pointer()
421 bytes = readl(chip->regs + ATMEL_PDC_TPR); in atmel_ac97c_playback_pointer()
422 bytes -= runtime->dma_addr; in atmel_ac97c_playback_pointer()
425 if (frames >= runtime->buffer_size) in atmel_ac97c_playback_pointer()
426 frames -= runtime->buffer_size; in atmel_ac97c_playback_pointer()
434 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_ac97c_capture_pointer()
438 bytes = readl(chip->regs + ATMEL_PDC_RPR); in atmel_ac97c_capture_pointer()
439 bytes -= runtime->dma_addr; in atmel_ac97c_capture_pointer()
442 if (frames >= runtime->buffer_size) in atmel_ac97c_capture_pointer()
443 frames -= runtime->buffer_size; in atmel_ac97c_capture_pointer()
477 dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n", in atmel_ac97c_interrupt()
485 runtime = chip->playback_substream->runtime; in atmel_ac97c_interrupt()
486 block_size = frames_to_bytes(runtime, runtime->period_size); in atmel_ac97c_interrupt()
487 chip->playback_period++; in atmel_ac97c_interrupt()
489 if (chip->playback_period == runtime->periods) in atmel_ac97c_interrupt()
490 chip->playback_period = 0; in atmel_ac97c_interrupt()
491 next_period = chip->playback_period + 1; in atmel_ac97c_interrupt()
492 if (next_period == runtime->periods) in atmel_ac97c_interrupt()
497 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR); in atmel_ac97c_interrupt()
498 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR); in atmel_ac97c_interrupt()
500 snd_pcm_period_elapsed(chip->playback_substream); in atmel_ac97c_interrupt()
503 runtime = chip->capture_substream->runtime; in atmel_ac97c_interrupt()
504 block_size = frames_to_bytes(runtime, runtime->period_size); in atmel_ac97c_interrupt()
505 chip->capture_period++; in atmel_ac97c_interrupt()
507 if (chip->capture_period == runtime->periods) in atmel_ac97c_interrupt()
508 chip->capture_period = 0; in atmel_ac97c_interrupt()
509 next_period = chip->capture_period + 1; in atmel_ac97c_interrupt()
510 if (next_period == runtime->periods) in atmel_ac97c_interrupt()
515 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR); in atmel_ac97c_interrupt()
516 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR); in atmel_ac97c_interrupt()
517 snd_pcm_period_elapsed(chip->capture_substream); in atmel_ac97c_interrupt()
523 dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n", in atmel_ac97c_interrupt()
533 dev_err(&chip->pdev->dev, "spurious interrupt sr 0x%08x " in atmel_ac97c_interrupt()
574 retval = snd_ac97_pcm_assign(chip->ac97_bus, in atmel_ac97c_pcm_new()
580 retval = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm); in atmel_ac97c_pcm_new()
588 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min, in atmel_ac97c_pcm_new()
591 pcm->private_data = chip; in atmel_ac97c_pcm_new()
592 pcm->info_flags = 0; in atmel_ac97c_pcm_new()
593 strcpy(pcm->name, chip->card->shortname); in atmel_ac97c_pcm_new()
594 chip->pcm = pcm; in atmel_ac97c_pcm_new()
604 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97); in atmel_ac97c_mixer_new()
622 } while (--timeout); in atmel_ac97c_write()
624 dev_dbg(&chip->pdev->dev, "codec write timeout\n"); in atmel_ac97c_write()
649 } while (--timeout); in atmel_ac97c_read()
651 if (!--write) in atmel_ac97c_read()
662 } while (--timeout); in atmel_ac97c_read()
664 if (!--write) in atmel_ac97c_read()
669 dev_dbg(&chip->pdev->dev, "codec read timeout\n"); in atmel_ac97c_read()
680 if (!IS_ERR(chip->reset_pin)) { in atmel_ac97c_reset()
681 gpiod_set_value(chip->reset_pin, 0); in atmel_ac97c_reset()
684 gpiod_set_value(chip->reset_pin, 1); in atmel_ac97c_reset()
693 { .compatible = "atmel,at91sam9263-ac97c", },
700 struct device *dev = &pdev->dev; in atmel_ac97c_probe()
704 struct clk *pclk; in atmel_ac97c_probe() local
714 dev_dbg(&pdev->dev, "no memory resource\n"); in atmel_ac97c_probe()
715 return -ENXIO; in atmel_ac97c_probe()
720 dev_dbg(&pdev->dev, "could not get irq: %d\n", irq); in atmel_ac97c_probe()
724 pclk = clk_get(&pdev->dev, "ac97_clk"); in atmel_ac97c_probe()
725 if (IS_ERR(pclk)) { in atmel_ac97c_probe()
726 dev_dbg(&pdev->dev, "no peripheral clock\n"); in atmel_ac97c_probe()
727 return PTR_ERR(pclk); in atmel_ac97c_probe()
729 retval = clk_prepare_enable(pclk); in atmel_ac97c_probe()
733 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1, in atmel_ac97c_probe()
737 dev_dbg(&pdev->dev, "could not create sound card device\n"); in atmel_ac97c_probe()
745 dev_dbg(&pdev->dev, "unable to request irq %d\n", irq); in atmel_ac97c_probe()
748 chip->irq = irq; in atmel_ac97c_probe()
750 spin_lock_init(&chip->lock); in atmel_ac97c_probe()
752 strcpy(card->driver, "Atmel AC97C"); in atmel_ac97c_probe()
753 strcpy(card->shortname, "Atmel AC97C"); in atmel_ac97c_probe()
754 sprintf(card->longname, "Atmel AC97 controller"); in atmel_ac97c_probe()
756 chip->card = card; in atmel_ac97c_probe()
757 chip->pclk = pclk; in atmel_ac97c_probe()
758 chip->pdev = pdev; in atmel_ac97c_probe()
759 chip->regs = ioremap(regs->start, resource_size(regs)); in atmel_ac97c_probe()
761 if (!chip->regs) { in atmel_ac97c_probe()
762 dev_dbg(&pdev->dev, "could not remap register memory\n"); in atmel_ac97c_probe()
763 retval = -ENOMEM; in atmel_ac97c_probe()
767 chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH); in atmel_ac97c_probe()
768 if (IS_ERR(chip->reset_pin)) in atmel_ac97c_probe()
777 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus); in atmel_ac97c_probe()
779 dev_dbg(&pdev->dev, "could not register on ac97 bus\n"); in atmel_ac97c_probe()
785 dev_dbg(&pdev->dev, "could not register ac97 mixer\n"); in atmel_ac97c_probe()
791 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n"); in atmel_ac97c_probe()
797 dev_dbg(&pdev->dev, "could not register sound card\n"); in atmel_ac97c_probe()
803 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n", in atmel_ac97c_probe()
804 chip->regs, irq); in atmel_ac97c_probe()
809 iounmap(chip->regs); in atmel_ac97c_probe()
815 clk_disable_unprepare(pclk); in atmel_ac97c_probe()
817 clk_put(pclk); in atmel_ac97c_probe()
825 struct atmel_ac97c *chip = card->private_data; in atmel_ac97c_suspend()
827 clk_disable_unprepare(chip->pclk); in atmel_ac97c_suspend()
834 struct atmel_ac97c *chip = card->private_data; in atmel_ac97c_resume()
835 int ret = clk_prepare_enable(chip->pclk); in atmel_ac97c_resume()
855 clk_disable_unprepare(chip->pclk); in atmel_ac97c_remove()
856 clk_put(chip->pclk); in atmel_ac97c_remove()
857 iounmap(chip->regs); in atmel_ac97c_remove()
858 free_irq(chip->irq, chip); in atmel_ac97c_remove()
878 MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");