1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for Atmel AC97C
5 * Copyright (C) 2005-2009 Atmel Corporation
8 #include <linux/delay.h>
9 #include <linux/bitmap.h>
10 #include <linux/device.h>
11 #include <linux/atmel_pdc.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/init.h>
14 #include <linux/interrupt.h>
15 #include <linux/module.h>
16 #include <linux/platform_device.h>
17 #include <linux/mutex.h>
18 #include <linux/types.h>
21 #include <linux/of_device.h>
23 #include <sound/core.h>
24 #include <sound/initval.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/ac97_codec.h>
28 #include <sound/memalloc.h>
32 /* Serialize access to opened variable */
33 static DEFINE_MUTEX(opened_mutex);
37 struct platform_device *pdev;
39 struct snd_pcm_substream *playback_substream;
40 struct snd_pcm_substream *capture_substream;
41 struct snd_card *card;
43 struct snd_ac97 *ac97;
44 struct snd_ac97_bus *ac97_bus;
47 unsigned int cur_rate;
48 int playback_period, capture_period;
49 /* Serialize access to opened variable */
54 struct gpio_desc *reset_pin;
57 #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
59 #define ac97c_writel(chip, reg, val) \
60 __raw_writel((val), (chip)->regs + AC97C_##reg)
61 #define ac97c_readl(chip, reg) \
62 __raw_readl((chip)->regs + AC97C_##reg)
64 static const struct snd_pcm_hardware atmel_ac97c_hw = {
65 .info = (SNDRV_PCM_INFO_MMAP
66 | SNDRV_PCM_INFO_MMAP_VALID
67 | SNDRV_PCM_INFO_INTERLEAVED
68 | SNDRV_PCM_INFO_BLOCK_TRANSFER
69 | SNDRV_PCM_INFO_JOINT_DUPLEX
70 | SNDRV_PCM_INFO_RESUME
71 | SNDRV_PCM_INFO_PAUSE),
72 .formats = (SNDRV_PCM_FMTBIT_S16_BE
73 | SNDRV_PCM_FMTBIT_S16_LE),
74 .rates = (SNDRV_PCM_RATE_CONTINUOUS),
79 .buffer_bytes_max = 2 * 2 * 64 * 2048,
80 .period_bytes_min = 4096,
81 .period_bytes_max = 4096,
86 static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream)
88 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
89 struct snd_pcm_runtime *runtime = substream->runtime;
91 mutex_lock(&opened_mutex);
93 runtime->hw = atmel_ac97c_hw;
95 runtime->hw.rate_min = chip->cur_rate;
96 runtime->hw.rate_max = chip->cur_rate;
99 runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
100 mutex_unlock(&opened_mutex);
101 chip->playback_substream = substream;
105 static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream)
107 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
108 struct snd_pcm_runtime *runtime = substream->runtime;
110 mutex_lock(&opened_mutex);
112 runtime->hw = atmel_ac97c_hw;
113 if (chip->cur_rate) {
114 runtime->hw.rate_min = chip->cur_rate;
115 runtime->hw.rate_max = chip->cur_rate;
117 if (chip->cur_format)
118 runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
119 mutex_unlock(&opened_mutex);
120 chip->capture_substream = substream;
124 static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream)
126 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
128 mutex_lock(&opened_mutex);
132 chip->cur_format = 0;
134 mutex_unlock(&opened_mutex);
136 chip->playback_substream = NULL;
141 static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream)
143 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
145 mutex_lock(&opened_mutex);
149 chip->cur_format = 0;
151 mutex_unlock(&opened_mutex);
153 chip->capture_substream = NULL;
158 static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
159 struct snd_pcm_hw_params *hw_params)
161 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
163 /* Set restrictions to params. */
164 mutex_lock(&opened_mutex);
165 chip->cur_rate = params_rate(hw_params);
166 chip->cur_format = params_format(hw_params);
167 mutex_unlock(&opened_mutex);
172 static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
173 struct snd_pcm_hw_params *hw_params)
175 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
177 /* Set restrictions to params. */
178 mutex_lock(&opened_mutex);
179 chip->cur_rate = params_rate(hw_params);
180 chip->cur_format = params_format(hw_params);
181 mutex_unlock(&opened_mutex);
186 static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
188 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
189 struct snd_pcm_runtime *runtime = substream->runtime;
190 int block_size = frames_to_bytes(runtime, runtime->period_size);
191 unsigned long word = ac97c_readl(chip, OCA);
194 chip->playback_period = 0;
195 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
197 /* assign channels to AC97C channel A */
198 switch (runtime->channels) {
200 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
203 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
204 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
207 /* TODO: support more than two channels */
210 ac97c_writel(chip, OCA, word);
212 /* configure sample format and size */
213 word = ac97c_readl(chip, CAMR);
214 if (chip->opened <= 1)
215 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
217 word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
219 switch (runtime->format) {
220 case SNDRV_PCM_FORMAT_S16_LE:
222 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
223 word &= ~(AC97C_CMR_CEM_LITTLE);
226 word = ac97c_readl(chip, OCA);
227 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
228 ac97c_writel(chip, OCA, word);
232 /* Enable underrun interrupt on channel A */
233 word |= AC97C_CSR_UNRUN;
235 ac97c_writel(chip, CAMR, word);
237 /* Enable channel A event interrupt */
238 word = ac97c_readl(chip, IMR);
239 word |= AC97C_SR_CAEVT;
240 ac97c_writel(chip, IER, word);
242 /* set variable rate if needed */
243 if (runtime->rate != 48000) {
244 word = ac97c_readl(chip, MR);
245 word |= AC97C_MR_VRA;
246 ac97c_writel(chip, MR, word);
248 word = ac97c_readl(chip, MR);
249 word &= ~(AC97C_MR_VRA);
250 ac97c_writel(chip, MR, word);
253 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
256 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
259 /* Initialize and start the PDC */
260 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
261 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
262 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR);
263 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
268 static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
270 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
271 struct snd_pcm_runtime *runtime = substream->runtime;
272 int block_size = frames_to_bytes(runtime, runtime->period_size);
273 unsigned long word = ac97c_readl(chip, ICA);
276 chip->capture_period = 0;
277 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
279 /* assign channels to AC97C channel A */
280 switch (runtime->channels) {
282 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
285 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
286 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
289 /* TODO: support more than two channels */
292 ac97c_writel(chip, ICA, word);
294 /* configure sample format and size */
295 word = ac97c_readl(chip, CAMR);
296 if (chip->opened <= 1)
297 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
299 word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
301 switch (runtime->format) {
302 case SNDRV_PCM_FORMAT_S16_LE:
304 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
305 word &= ~(AC97C_CMR_CEM_LITTLE);
308 word = ac97c_readl(chip, ICA);
309 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
310 ac97c_writel(chip, ICA, word);
314 /* Enable overrun interrupt on channel A */
315 word |= AC97C_CSR_OVRUN;
317 ac97c_writel(chip, CAMR, word);
319 /* Enable channel A event interrupt */
320 word = ac97c_readl(chip, IMR);
321 word |= AC97C_SR_CAEVT;
322 ac97c_writel(chip, IER, word);
324 /* set variable rate if needed */
325 if (runtime->rate != 48000) {
326 word = ac97c_readl(chip, MR);
327 word |= AC97C_MR_VRA;
328 ac97c_writel(chip, MR, word);
330 word = ac97c_readl(chip, MR);
331 word &= ~(AC97C_MR_VRA);
332 ac97c_writel(chip, MR, word);
335 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
338 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
341 /* Initialize and start the PDC */
342 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
343 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
344 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR);
345 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
351 atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
353 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
354 unsigned long camr, ptcr = 0;
356 camr = ac97c_readl(chip, CAMR);
359 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
360 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
361 case SNDRV_PCM_TRIGGER_START:
362 ptcr = ATMEL_PDC_TXTEN;
363 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX;
365 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
366 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
367 case SNDRV_PCM_TRIGGER_STOP:
368 ptcr |= ATMEL_PDC_TXTDIS;
369 if (chip->opened <= 1)
370 camr &= ~AC97C_CMR_CENA;
376 ac97c_writel(chip, CAMR, camr);
377 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
382 atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
384 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
385 unsigned long camr, ptcr = 0;
387 camr = ac97c_readl(chip, CAMR);
388 ptcr = readl(chip->regs + ATMEL_PDC_PTSR);
391 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
392 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
393 case SNDRV_PCM_TRIGGER_START:
394 ptcr = ATMEL_PDC_RXTEN;
395 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX;
397 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
398 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
399 case SNDRV_PCM_TRIGGER_STOP:
400 ptcr |= ATMEL_PDC_RXTDIS;
401 if (chip->opened <= 1)
402 camr &= ~AC97C_CMR_CENA;
408 ac97c_writel(chip, CAMR, camr);
409 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
413 static snd_pcm_uframes_t
414 atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
416 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
417 struct snd_pcm_runtime *runtime = substream->runtime;
418 snd_pcm_uframes_t frames;
421 bytes = readl(chip->regs + ATMEL_PDC_TPR);
422 bytes -= runtime->dma_addr;
424 frames = bytes_to_frames(runtime, bytes);
425 if (frames >= runtime->buffer_size)
426 frames -= runtime->buffer_size;
430 static snd_pcm_uframes_t
431 atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
433 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
434 struct snd_pcm_runtime *runtime = substream->runtime;
435 snd_pcm_uframes_t frames;
438 bytes = readl(chip->regs + ATMEL_PDC_RPR);
439 bytes -= runtime->dma_addr;
441 frames = bytes_to_frames(runtime, bytes);
442 if (frames >= runtime->buffer_size)
443 frames -= runtime->buffer_size;
447 static const struct snd_pcm_ops atmel_ac97_playback_ops = {
448 .open = atmel_ac97c_playback_open,
449 .close = atmel_ac97c_playback_close,
450 .ioctl = snd_pcm_lib_ioctl,
451 .hw_params = atmel_ac97c_playback_hw_params,
452 .prepare = atmel_ac97c_playback_prepare,
453 .trigger = atmel_ac97c_playback_trigger,
454 .pointer = atmel_ac97c_playback_pointer,
457 static const struct snd_pcm_ops atmel_ac97_capture_ops = {
458 .open = atmel_ac97c_capture_open,
459 .close = atmel_ac97c_capture_close,
460 .ioctl = snd_pcm_lib_ioctl,
461 .hw_params = atmel_ac97c_capture_hw_params,
462 .prepare = atmel_ac97c_capture_prepare,
463 .trigger = atmel_ac97c_capture_trigger,
464 .pointer = atmel_ac97c_capture_pointer,
467 static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
469 struct atmel_ac97c *chip = (struct atmel_ac97c *)dev;
470 irqreturn_t retval = IRQ_NONE;
471 u32 sr = ac97c_readl(chip, SR);
472 u32 casr = ac97c_readl(chip, CASR);
473 u32 cosr = ac97c_readl(chip, COSR);
474 u32 camr = ac97c_readl(chip, CAMR);
476 if (sr & AC97C_SR_CAEVT) {
477 struct snd_pcm_runtime *runtime;
478 int offset, next_period, block_size;
479 dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
480 casr & AC97C_CSR_OVRUN ? " OVRUN" : "",
481 casr & AC97C_CSR_RXRDY ? " RXRDY" : "",
482 casr & AC97C_CSR_UNRUN ? " UNRUN" : "",
483 casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
484 casr & AC97C_CSR_TXRDY ? " TXRDY" : "",
485 !casr ? " NONE" : "");
486 if ((casr & camr) & AC97C_CSR_ENDTX) {
487 runtime = chip->playback_substream->runtime;
488 block_size = frames_to_bytes(runtime, runtime->period_size);
489 chip->playback_period++;
491 if (chip->playback_period == runtime->periods)
492 chip->playback_period = 0;
493 next_period = chip->playback_period + 1;
494 if (next_period == runtime->periods)
497 offset = block_size * next_period;
499 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR);
500 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
502 snd_pcm_period_elapsed(chip->playback_substream);
504 if ((casr & camr) & AC97C_CSR_ENDRX) {
505 runtime = chip->capture_substream->runtime;
506 block_size = frames_to_bytes(runtime, runtime->period_size);
507 chip->capture_period++;
509 if (chip->capture_period == runtime->periods)
510 chip->capture_period = 0;
511 next_period = chip->capture_period + 1;
512 if (next_period == runtime->periods)
515 offset = block_size * next_period;
517 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR);
518 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
519 snd_pcm_period_elapsed(chip->capture_substream);
521 retval = IRQ_HANDLED;
524 if (sr & AC97C_SR_COEVT) {
525 dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n",
526 cosr & AC97C_CSR_OVRUN ? " OVRUN" : "",
527 cosr & AC97C_CSR_RXRDY ? " RXRDY" : "",
528 cosr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
529 cosr & AC97C_CSR_TXRDY ? " TXRDY" : "",
530 !cosr ? " NONE" : "");
531 retval = IRQ_HANDLED;
534 if (retval == IRQ_NONE) {
535 dev_err(&chip->pdev->dev, "spurious interrupt sr 0x%08x "
536 "casr 0x%08x cosr 0x%08x\n", sr, casr, cosr);
542 static const struct ac97_pcm at91_ac97_pcm_defs[] = {
547 .slots = ((1 << AC97_SLOT_PCM_LEFT)
548 | (1 << AC97_SLOT_PCM_RIGHT)),
556 .slots = ((1 << AC97_SLOT_PCM_LEFT)
557 | (1 << AC97_SLOT_PCM_RIGHT)),
565 .slots = (1<<AC97_SLOT_MIC),
570 static int atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
573 struct snd_pcm_hardware hw = atmel_ac97c_hw;
576 retval = snd_ac97_pcm_assign(chip->ac97_bus,
577 ARRAY_SIZE(at91_ac97_pcm_defs),
582 retval = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
586 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &atmel_ac97_capture_ops);
587 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_ac97_playback_ops);
589 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
590 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
591 hw.buffer_bytes_max);
593 pcm->private_data = chip;
595 strcpy(pcm->name, chip->card->shortname);
601 static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip)
603 struct snd_ac97_template template;
604 memset(&template, 0, sizeof(template));
605 template.private_data = chip;
606 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
609 static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg,
612 struct atmel_ac97c *chip = get_chip(ac97);
616 word = (reg & 0x7f) << 16 | val;
619 if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
620 ac97c_writel(chip, COTHR, word);
626 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
629 static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97,
632 struct atmel_ac97c *chip = get_chip(ac97);
637 word = (0x80 | (reg & 0x7f)) << 16;
639 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
640 ac97c_readl(chip, CORHR);
646 if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
647 ac97c_writel(chip, COTHR, word);
659 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
660 unsigned short val = ac97c_readl(chip, CORHR);
671 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
675 static void atmel_ac97c_reset(struct atmel_ac97c *chip)
677 ac97c_writel(chip, MR, 0);
678 ac97c_writel(chip, MR, AC97C_MR_ENA);
679 ac97c_writel(chip, CAMR, 0);
680 ac97c_writel(chip, COMR, 0);
682 if (!IS_ERR(chip->reset_pin)) {
683 gpiod_set_value(chip->reset_pin, 0);
684 /* AC97 v2.2 specifications says minimum 1 us. */
686 gpiod_set_value(chip->reset_pin, 1);
688 ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA);
690 ac97c_writel(chip, MR, AC97C_MR_ENA);
694 static const struct of_device_id atmel_ac97c_dt_ids[] = {
695 { .compatible = "atmel,at91sam9263-ac97c", },
698 MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids);
700 static int atmel_ac97c_probe(struct platform_device *pdev)
702 struct device *dev = &pdev->dev;
703 struct snd_card *card;
704 struct atmel_ac97c *chip;
705 struct resource *regs;
707 static struct snd_ac97_bus_ops ops = {
708 .write = atmel_ac97c_write,
709 .read = atmel_ac97c_read,
714 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
716 dev_dbg(&pdev->dev, "no memory resource\n");
720 irq = platform_get_irq(pdev, 0);
722 dev_dbg(&pdev->dev, "could not get irq: %d\n", irq);
726 pclk = clk_get(&pdev->dev, "ac97_clk");
728 dev_dbg(&pdev->dev, "no peripheral clock\n");
729 return PTR_ERR(pclk);
731 retval = clk_prepare_enable(pclk);
733 goto err_prepare_enable;
735 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
736 SNDRV_DEFAULT_STR1, THIS_MODULE,
737 sizeof(struct atmel_ac97c), &card);
739 dev_dbg(&pdev->dev, "could not create sound card device\n");
740 goto err_snd_card_new;
743 chip = get_chip(card);
745 retval = request_irq(irq, atmel_ac97c_interrupt, 0, "AC97C", chip);
747 dev_dbg(&pdev->dev, "unable to request irq %d\n", irq);
748 goto err_request_irq;
752 spin_lock_init(&chip->lock);
754 strcpy(card->driver, "Atmel AC97C");
755 strcpy(card->shortname, "Atmel AC97C");
756 sprintf(card->longname, "Atmel AC97 controller");
761 chip->regs = ioremap(regs->start, resource_size(regs));
764 dev_dbg(&pdev->dev, "could not remap register memory\n");
769 chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
770 if (IS_ERR(chip->reset_pin))
771 dev_dbg(dev, "reset pin not available\n");
773 atmel_ac97c_reset(chip);
775 /* Enable overrun interrupt from codec channel */
776 ac97c_writel(chip, COMR, AC97C_CSR_OVRUN);
777 ac97c_writel(chip, IER, ac97c_readl(chip, IMR) | AC97C_SR_COEVT);
779 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
781 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
785 retval = atmel_ac97c_mixer_new(chip);
787 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
791 retval = atmel_ac97c_pcm_new(chip);
793 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
797 retval = snd_card_register(card);
799 dev_dbg(&pdev->dev, "could not register sound card\n");
803 platform_set_drvdata(pdev, card);
805 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n",
817 clk_disable_unprepare(pclk);
823 #ifdef CONFIG_PM_SLEEP
824 static int atmel_ac97c_suspend(struct device *pdev)
826 struct snd_card *card = dev_get_drvdata(pdev);
827 struct atmel_ac97c *chip = card->private_data;
829 clk_disable_unprepare(chip->pclk);
833 static int atmel_ac97c_resume(struct device *pdev)
835 struct snd_card *card = dev_get_drvdata(pdev);
836 struct atmel_ac97c *chip = card->private_data;
837 int ret = clk_prepare_enable(chip->pclk);
842 static SIMPLE_DEV_PM_OPS(atmel_ac97c_pm, atmel_ac97c_suspend, atmel_ac97c_resume);
843 #define ATMEL_AC97C_PM_OPS &atmel_ac97c_pm
845 #define ATMEL_AC97C_PM_OPS NULL
848 static int atmel_ac97c_remove(struct platform_device *pdev)
850 struct snd_card *card = platform_get_drvdata(pdev);
851 struct atmel_ac97c *chip = get_chip(card);
853 ac97c_writel(chip, CAMR, 0);
854 ac97c_writel(chip, COMR, 0);
855 ac97c_writel(chip, MR, 0);
857 clk_disable_unprepare(chip->pclk);
860 free_irq(chip->irq, chip);
867 static struct platform_driver atmel_ac97c_driver = {
868 .probe = atmel_ac97c_probe,
869 .remove = atmel_ac97c_remove,
871 .name = "atmel_ac97c",
872 .pm = ATMEL_AC97C_PM_OPS,
873 .of_match_table = atmel_ac97c_dt_ids,
876 module_platform_driver(atmel_ac97c_driver);
878 MODULE_LICENSE("GPL");
879 MODULE_DESCRIPTION("Driver for Atmel AC97 controller");
880 MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");