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/mod_devicetable.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/mutex.h>
19 #include <linux/types.h>
22 #include <sound/core.h>
23 #include <sound/initval.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/ac97_codec.h>
27 #include <sound/memalloc.h>
31 /* Serialize access to opened variable */
32 static DEFINE_MUTEX(opened_mutex);
36 struct platform_device *pdev;
38 struct snd_pcm_substream *playback_substream;
39 struct snd_pcm_substream *capture_substream;
40 struct snd_card *card;
42 struct snd_ac97 *ac97;
43 struct snd_ac97_bus *ac97_bus;
46 unsigned int cur_rate;
47 int playback_period, capture_period;
48 /* Serialize access to opened variable */
53 struct gpio_desc *reset_pin;
56 #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
58 #define ac97c_writel(chip, reg, val) \
59 __raw_writel((val), (chip)->regs + AC97C_##reg)
60 #define ac97c_readl(chip, reg) \
61 __raw_readl((chip)->regs + AC97C_##reg)
63 static const struct snd_pcm_hardware atmel_ac97c_hw = {
64 .info = (SNDRV_PCM_INFO_MMAP
65 | SNDRV_PCM_INFO_MMAP_VALID
66 | SNDRV_PCM_INFO_INTERLEAVED
67 | SNDRV_PCM_INFO_BLOCK_TRANSFER
68 | SNDRV_PCM_INFO_JOINT_DUPLEX
69 | SNDRV_PCM_INFO_RESUME
70 | SNDRV_PCM_INFO_PAUSE),
71 .formats = (SNDRV_PCM_FMTBIT_S16_BE
72 | SNDRV_PCM_FMTBIT_S16_LE),
73 .rates = (SNDRV_PCM_RATE_CONTINUOUS),
78 .buffer_bytes_max = 2 * 2 * 64 * 2048,
79 .period_bytes_min = 4096,
80 .period_bytes_max = 4096,
85 static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream)
87 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
88 struct snd_pcm_runtime *runtime = substream->runtime;
90 mutex_lock(&opened_mutex);
92 runtime->hw = atmel_ac97c_hw;
94 runtime->hw.rate_min = chip->cur_rate;
95 runtime->hw.rate_max = chip->cur_rate;
98 runtime->hw.formats = pcm_format_to_bits(chip->cur_format);
99 mutex_unlock(&opened_mutex);
100 chip->playback_substream = substream;
104 static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream)
106 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
107 struct snd_pcm_runtime *runtime = substream->runtime;
109 mutex_lock(&opened_mutex);
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 mutex_unlock(&opened_mutex);
119 chip->capture_substream = substream;
123 static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream)
125 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
127 mutex_lock(&opened_mutex);
131 chip->cur_format = 0;
133 mutex_unlock(&opened_mutex);
135 chip->playback_substream = NULL;
140 static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream)
142 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
144 mutex_lock(&opened_mutex);
148 chip->cur_format = 0;
150 mutex_unlock(&opened_mutex);
152 chip->capture_substream = NULL;
157 static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
158 struct snd_pcm_hw_params *hw_params)
160 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
162 /* Set restrictions to params. */
163 mutex_lock(&opened_mutex);
164 chip->cur_rate = params_rate(hw_params);
165 chip->cur_format = params_format(hw_params);
166 mutex_unlock(&opened_mutex);
171 static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
172 struct snd_pcm_hw_params *hw_params)
174 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
176 /* Set restrictions to params. */
177 mutex_lock(&opened_mutex);
178 chip->cur_rate = params_rate(hw_params);
179 chip->cur_format = params_format(hw_params);
180 mutex_unlock(&opened_mutex);
185 static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
187 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
188 struct snd_pcm_runtime *runtime = substream->runtime;
189 int block_size = frames_to_bytes(runtime, runtime->period_size);
190 unsigned long word = ac97c_readl(chip, OCA);
193 chip->playback_period = 0;
194 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
196 /* assign channels to AC97C channel A */
197 switch (runtime->channels) {
199 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
202 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
203 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
206 /* TODO: support more than two channels */
209 ac97c_writel(chip, OCA, word);
211 /* configure sample format and size */
212 word = ac97c_readl(chip, CAMR);
213 if (chip->opened <= 1)
214 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
216 word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
218 switch (runtime->format) {
219 case SNDRV_PCM_FORMAT_S16_LE:
221 case SNDRV_PCM_FORMAT_S16_BE:
222 word &= ~(AC97C_CMR_CEM_LITTLE);
225 word = ac97c_readl(chip, OCA);
226 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
227 ac97c_writel(chip, OCA, word);
231 /* Enable underrun interrupt on channel A */
232 word |= AC97C_CSR_UNRUN;
234 ac97c_writel(chip, CAMR, word);
236 /* Enable channel A event interrupt */
237 word = ac97c_readl(chip, IMR);
238 word |= AC97C_SR_CAEVT;
239 ac97c_writel(chip, IER, word);
241 /* set variable rate if needed */
242 if (runtime->rate != 48000) {
243 word = ac97c_readl(chip, MR);
244 word |= AC97C_MR_VRA;
245 ac97c_writel(chip, MR, word);
247 word = ac97c_readl(chip, MR);
248 word &= ~(AC97C_MR_VRA);
249 ac97c_writel(chip, MR, word);
252 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
255 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
258 /* Initialize and start the PDC */
259 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
260 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
261 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR);
262 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
267 static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
269 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
270 struct snd_pcm_runtime *runtime = substream->runtime;
271 int block_size = frames_to_bytes(runtime, runtime->period_size);
272 unsigned long word = ac97c_readl(chip, ICA);
275 chip->capture_period = 0;
276 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
278 /* assign channels to AC97C channel A */
279 switch (runtime->channels) {
281 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
284 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
285 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
288 /* TODO: support more than two channels */
291 ac97c_writel(chip, ICA, word);
293 /* configure sample format and size */
294 word = ac97c_readl(chip, CAMR);
295 if (chip->opened <= 1)
296 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
298 word |= AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
300 switch (runtime->format) {
301 case SNDRV_PCM_FORMAT_S16_LE:
303 case SNDRV_PCM_FORMAT_S16_BE:
304 word &= ~(AC97C_CMR_CEM_LITTLE);
307 word = ac97c_readl(chip, ICA);
308 word &= ~(AC97C_CH_MASK(PCM_LEFT) | AC97C_CH_MASK(PCM_RIGHT));
309 ac97c_writel(chip, ICA, word);
313 /* Enable overrun interrupt on channel A */
314 word |= AC97C_CSR_OVRUN;
316 ac97c_writel(chip, CAMR, word);
318 /* Enable channel A event interrupt */
319 word = ac97c_readl(chip, IMR);
320 word |= AC97C_SR_CAEVT;
321 ac97c_writel(chip, IER, word);
323 /* set variable rate if needed */
324 if (runtime->rate != 48000) {
325 word = ac97c_readl(chip, MR);
326 word |= AC97C_MR_VRA;
327 ac97c_writel(chip, MR, word);
329 word = ac97c_readl(chip, MR);
330 word &= ~(AC97C_MR_VRA);
331 ac97c_writel(chip, MR, word);
334 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
337 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
340 /* Initialize and start the PDC */
341 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
342 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
343 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR);
344 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
350 atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
352 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
353 unsigned long camr, ptcr = 0;
355 camr = ac97c_readl(chip, CAMR);
358 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
359 case SNDRV_PCM_TRIGGER_RESUME:
360 case SNDRV_PCM_TRIGGER_START:
361 ptcr = ATMEL_PDC_TXTEN;
362 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX;
364 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
365 case SNDRV_PCM_TRIGGER_SUSPEND:
366 case SNDRV_PCM_TRIGGER_STOP:
367 ptcr |= ATMEL_PDC_TXTDIS;
368 if (chip->opened <= 1)
369 camr &= ~AC97C_CMR_CENA;
375 ac97c_writel(chip, CAMR, camr);
376 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
381 atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
383 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
384 unsigned long camr, ptcr = 0;
386 camr = ac97c_readl(chip, CAMR);
387 ptcr = readl(chip->regs + ATMEL_PDC_PTSR);
390 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
391 case SNDRV_PCM_TRIGGER_RESUME:
392 case SNDRV_PCM_TRIGGER_START:
393 ptcr = ATMEL_PDC_RXTEN;
394 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX;
396 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
397 case SNDRV_PCM_TRIGGER_SUSPEND:
398 case SNDRV_PCM_TRIGGER_STOP:
399 ptcr |= ATMEL_PDC_RXTDIS;
400 if (chip->opened <= 1)
401 camr &= ~AC97C_CMR_CENA;
407 ac97c_writel(chip, CAMR, camr);
408 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
412 static snd_pcm_uframes_t
413 atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
415 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
416 struct snd_pcm_runtime *runtime = substream->runtime;
417 snd_pcm_uframes_t frames;
420 bytes = readl(chip->regs + ATMEL_PDC_TPR);
421 bytes -= runtime->dma_addr;
423 frames = bytes_to_frames(runtime, bytes);
424 if (frames >= runtime->buffer_size)
425 frames -= runtime->buffer_size;
429 static snd_pcm_uframes_t
430 atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
432 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
433 struct snd_pcm_runtime *runtime = substream->runtime;
434 snd_pcm_uframes_t frames;
437 bytes = readl(chip->regs + ATMEL_PDC_RPR);
438 bytes -= runtime->dma_addr;
440 frames = bytes_to_frames(runtime, bytes);
441 if (frames >= runtime->buffer_size)
442 frames -= runtime->buffer_size;
446 static const struct snd_pcm_ops atmel_ac97_playback_ops = {
447 .open = atmel_ac97c_playback_open,
448 .close = atmel_ac97c_playback_close,
449 .hw_params = atmel_ac97c_playback_hw_params,
450 .prepare = atmel_ac97c_playback_prepare,
451 .trigger = atmel_ac97c_playback_trigger,
452 .pointer = atmel_ac97c_playback_pointer,
455 static const struct snd_pcm_ops atmel_ac97_capture_ops = {
456 .open = atmel_ac97c_capture_open,
457 .close = atmel_ac97c_capture_close,
458 .hw_params = atmel_ac97c_capture_hw_params,
459 .prepare = atmel_ac97c_capture_prepare,
460 .trigger = atmel_ac97c_capture_trigger,
461 .pointer = atmel_ac97c_capture_pointer,
464 static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
466 struct atmel_ac97c *chip = (struct atmel_ac97c *)dev;
467 irqreturn_t retval = IRQ_NONE;
468 u32 sr = ac97c_readl(chip, SR);
469 u32 casr = ac97c_readl(chip, CASR);
470 u32 cosr = ac97c_readl(chip, COSR);
471 u32 camr = ac97c_readl(chip, CAMR);
473 if (sr & AC97C_SR_CAEVT) {
474 struct snd_pcm_runtime *runtime;
475 int offset, next_period, block_size;
476 dev_dbg(&chip->pdev->dev, "channel A event%s%s%s%s%s%s\n",
477 (casr & AC97C_CSR_OVRUN) ? " OVRUN" : "",
478 (casr & AC97C_CSR_RXRDY) ? " RXRDY" : "",
479 (casr & AC97C_CSR_UNRUN) ? " UNRUN" : "",
480 (casr & AC97C_CSR_TXEMPTY) ? " TXEMPTY" : "",
481 (casr & AC97C_CSR_TXRDY) ? " TXRDY" : "",
482 !casr ? " NONE" : "");
483 if ((casr & camr) & AC97C_CSR_ENDTX) {
484 runtime = chip->playback_substream->runtime;
485 block_size = frames_to_bytes(runtime, runtime->period_size);
486 chip->playback_period++;
488 if (chip->playback_period == runtime->periods)
489 chip->playback_period = 0;
490 next_period = chip->playback_period + 1;
491 if (next_period == runtime->periods)
494 offset = block_size * next_period;
496 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR);
497 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
499 snd_pcm_period_elapsed(chip->playback_substream);
501 if ((casr & camr) & AC97C_CSR_ENDRX) {
502 runtime = chip->capture_substream->runtime;
503 block_size = frames_to_bytes(runtime, runtime->period_size);
504 chip->capture_period++;
506 if (chip->capture_period == runtime->periods)
507 chip->capture_period = 0;
508 next_period = chip->capture_period + 1;
509 if (next_period == runtime->periods)
512 offset = block_size * next_period;
514 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR);
515 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
516 snd_pcm_period_elapsed(chip->capture_substream);
518 retval = IRQ_HANDLED;
521 if (sr & AC97C_SR_COEVT) {
522 dev_info(&chip->pdev->dev, "codec channel event%s%s%s%s%s\n",
523 (cosr & AC97C_CSR_OVRUN) ? " OVRUN" : "",
524 (cosr & AC97C_CSR_RXRDY) ? " RXRDY" : "",
525 (cosr & AC97C_CSR_TXEMPTY) ? " TXEMPTY" : "",
526 (cosr & AC97C_CSR_TXRDY) ? " TXRDY" : "",
527 !cosr ? " NONE" : "");
528 retval = IRQ_HANDLED;
531 if (retval == IRQ_NONE) {
532 dev_err(&chip->pdev->dev, "spurious interrupt sr 0x%08x "
533 "casr 0x%08x cosr 0x%08x\n", sr, casr, cosr);
539 static const struct ac97_pcm at91_ac97_pcm_defs[] = {
544 .slots = ((1 << AC97_SLOT_PCM_LEFT)
545 | (1 << AC97_SLOT_PCM_RIGHT)),
553 .slots = ((1 << AC97_SLOT_PCM_LEFT)
554 | (1 << AC97_SLOT_PCM_RIGHT)),
562 .slots = (1<<AC97_SLOT_MIC),
567 static int atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
570 struct snd_pcm_hardware hw = atmel_ac97c_hw;
573 retval = snd_ac97_pcm_assign(chip->ac97_bus,
574 ARRAY_SIZE(at91_ac97_pcm_defs),
579 retval = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
583 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &atmel_ac97_capture_ops);
584 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_ac97_playback_ops);
586 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
587 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
588 hw.buffer_bytes_max);
590 pcm->private_data = chip;
592 strcpy(pcm->name, chip->card->shortname);
598 static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip)
600 struct snd_ac97_template template;
601 memset(&template, 0, sizeof(template));
602 template.private_data = chip;
603 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
606 static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg,
609 struct atmel_ac97c *chip = get_chip(ac97);
613 word = (reg & 0x7f) << 16 | val;
616 if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
617 ac97c_writel(chip, COTHR, word);
623 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
626 static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97,
629 struct atmel_ac97c *chip = get_chip(ac97);
634 word = (0x80 | (reg & 0x7f)) << 16;
636 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
637 ac97c_readl(chip, CORHR);
643 if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
644 ac97c_writel(chip, COTHR, word);
656 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
657 unsigned short val = ac97c_readl(chip, CORHR);
668 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
672 static void atmel_ac97c_reset(struct atmel_ac97c *chip)
674 ac97c_writel(chip, MR, 0);
675 ac97c_writel(chip, MR, AC97C_MR_ENA);
676 ac97c_writel(chip, CAMR, 0);
677 ac97c_writel(chip, COMR, 0);
679 if (!IS_ERR(chip->reset_pin)) {
680 gpiod_set_value(chip->reset_pin, 0);
681 /* AC97 v2.2 specifications says minimum 1 us. */
683 gpiod_set_value(chip->reset_pin, 1);
685 ac97c_writel(chip, MR, AC97C_MR_WRST | AC97C_MR_ENA);
687 ac97c_writel(chip, MR, AC97C_MR_ENA);
691 static const struct of_device_id atmel_ac97c_dt_ids[] = {
692 { .compatible = "atmel,at91sam9263-ac97c", },
695 MODULE_DEVICE_TABLE(of, atmel_ac97c_dt_ids);
697 static int atmel_ac97c_probe(struct platform_device *pdev)
699 struct device *dev = &pdev->dev;
700 struct snd_card *card;
701 struct atmel_ac97c *chip;
702 struct resource *regs;
704 static const struct snd_ac97_bus_ops ops = {
705 .write = atmel_ac97c_write,
706 .read = atmel_ac97c_read,
711 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
713 dev_dbg(&pdev->dev, "no memory resource\n");
717 irq = platform_get_irq(pdev, 0);
719 dev_dbg(&pdev->dev, "could not get irq: %d\n", irq);
723 pclk = clk_get(&pdev->dev, "ac97_clk");
725 dev_dbg(&pdev->dev, "no peripheral clock\n");
726 return PTR_ERR(pclk);
728 retval = clk_prepare_enable(pclk);
730 goto err_prepare_enable;
732 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
733 SNDRV_DEFAULT_STR1, THIS_MODULE,
734 sizeof(struct atmel_ac97c), &card);
736 dev_dbg(&pdev->dev, "could not create sound card device\n");
737 goto err_snd_card_new;
740 chip = get_chip(card);
742 retval = request_irq(irq, atmel_ac97c_interrupt, 0, "AC97C", chip);
744 dev_dbg(&pdev->dev, "unable to request irq %d\n", irq);
745 goto err_request_irq;
749 spin_lock_init(&chip->lock);
751 strcpy(card->driver, "Atmel AC97C");
752 strcpy(card->shortname, "Atmel AC97C");
753 sprintf(card->longname, "Atmel AC97 controller");
758 chip->regs = ioremap(regs->start, resource_size(regs));
761 dev_dbg(&pdev->dev, "could not remap register memory\n");
766 chip->reset_pin = devm_gpiod_get_index(dev, "ac97", 2, GPIOD_OUT_HIGH);
767 if (IS_ERR(chip->reset_pin))
768 dev_dbg(dev, "reset pin not available\n");
770 atmel_ac97c_reset(chip);
772 /* Enable overrun interrupt from codec channel */
773 ac97c_writel(chip, COMR, AC97C_CSR_OVRUN);
774 ac97c_writel(chip, IER, ac97c_readl(chip, IMR) | AC97C_SR_COEVT);
776 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
778 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
782 retval = atmel_ac97c_mixer_new(chip);
784 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
788 retval = atmel_ac97c_pcm_new(chip);
790 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
794 retval = snd_card_register(card);
796 dev_dbg(&pdev->dev, "could not register sound card\n");
800 platform_set_drvdata(pdev, card);
802 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p, irq = %d\n",
814 clk_disable_unprepare(pclk);
820 #ifdef CONFIG_PM_SLEEP
821 static int atmel_ac97c_suspend(struct device *pdev)
823 struct snd_card *card = dev_get_drvdata(pdev);
824 struct atmel_ac97c *chip = card->private_data;
826 clk_disable_unprepare(chip->pclk);
830 static int atmel_ac97c_resume(struct device *pdev)
832 struct snd_card *card = dev_get_drvdata(pdev);
833 struct atmel_ac97c *chip = card->private_data;
834 int ret = clk_prepare_enable(chip->pclk);
839 static SIMPLE_DEV_PM_OPS(atmel_ac97c_pm, atmel_ac97c_suspend, atmel_ac97c_resume);
840 #define ATMEL_AC97C_PM_OPS &atmel_ac97c_pm
842 #define ATMEL_AC97C_PM_OPS NULL
845 static void atmel_ac97c_remove(struct platform_device *pdev)
847 struct snd_card *card = platform_get_drvdata(pdev);
848 struct atmel_ac97c *chip = get_chip(card);
850 ac97c_writel(chip, CAMR, 0);
851 ac97c_writel(chip, COMR, 0);
852 ac97c_writel(chip, MR, 0);
854 clk_disable_unprepare(chip->pclk);
857 free_irq(chip->irq, chip);
862 static struct platform_driver atmel_ac97c_driver = {
863 .probe = atmel_ac97c_probe,
864 .remove_new = atmel_ac97c_remove,
866 .name = "atmel_ac97c",
867 .pm = ATMEL_AC97C_PM_OPS,
868 .of_match_table = atmel_ac97c_dt_ids,
871 module_platform_driver(atmel_ac97c_driver);
873 MODULE_LICENSE("GPL");
874 MODULE_DESCRIPTION("Driver for Atmel AC97 controller");
875 MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");