2 * Driver for the Atmel AC97C controller
4 * Copyright (C) 2005-2009 Atmel Corporation
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 #include <linux/clk.h>
11 #include <linux/delay.h>
12 #include <linux/bitmap.h>
13 #include <linux/dmaengine.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/mutex.h>
20 #include <linux/gpio.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/atmel-ac97c.h>
29 #include <sound/memalloc.h>
31 #include <linux/dw_dmac.h>
42 /* Serialize access to opened variable */
43 static DEFINE_MUTEX(opened_mutex);
45 struct atmel_ac97c_dma {
46 struct dma_chan *rx_chan;
47 struct dma_chan *tx_chan;
52 struct platform_device *pdev;
53 struct atmel_ac97c_dma dma;
55 struct snd_pcm_substream *playback_substream;
56 struct snd_pcm_substream *capture_substream;
57 struct snd_card *card;
59 struct snd_ac97 *ac97;
60 struct snd_ac97_bus *ac97_bus;
63 unsigned int cur_rate;
65 /* Serialize access to opened variable */
72 #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
74 #define ac97c_writel(chip, reg, val) \
75 __raw_writel((val), (chip)->regs + AC97C_##reg)
76 #define ac97c_readl(chip, reg) \
77 __raw_readl((chip)->regs + AC97C_##reg)
79 /* This function is called by the DMA driver. */
80 static void atmel_ac97c_dma_playback_period_done(void *arg)
82 struct atmel_ac97c *chip = arg;
83 snd_pcm_period_elapsed(chip->playback_substream);
86 static void atmel_ac97c_dma_capture_period_done(void *arg)
88 struct atmel_ac97c *chip = arg;
89 snd_pcm_period_elapsed(chip->capture_substream);
92 static int atmel_ac97c_prepare_dma(struct atmel_ac97c *chip,
93 struct snd_pcm_substream *substream,
94 enum dma_data_direction direction)
96 struct dma_chan *chan;
97 struct dw_cyclic_desc *cdesc;
98 struct snd_pcm_runtime *runtime = substream->runtime;
99 unsigned long buffer_len, period_len;
102 * We don't do DMA on "complex" transfers, i.e. with
103 * non-halfword-aligned buffers or lengths.
105 if (runtime->dma_addr & 1 || runtime->buffer_size & 1) {
106 dev_dbg(&chip->pdev->dev, "too complex transfer\n");
110 if (direction == DMA_TO_DEVICE)
111 chan = chip->dma.tx_chan;
113 chan = chip->dma.rx_chan;
115 buffer_len = frames_to_bytes(runtime, runtime->buffer_size);
116 period_len = frames_to_bytes(runtime, runtime->period_size);
118 cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len,
119 period_len, direction);
121 dev_dbg(&chip->pdev->dev, "could not prepare cyclic DMA\n");
122 return PTR_ERR(cdesc);
125 if (direction == DMA_TO_DEVICE) {
126 cdesc->period_callback = atmel_ac97c_dma_playback_period_done;
127 set_bit(DMA_TX_READY, &chip->flags);
129 cdesc->period_callback = atmel_ac97c_dma_capture_period_done;
130 set_bit(DMA_RX_READY, &chip->flags);
133 cdesc->period_callback_param = chip;
138 static struct snd_pcm_hardware atmel_ac97c_hw = {
139 .info = (SNDRV_PCM_INFO_MMAP
140 | SNDRV_PCM_INFO_MMAP_VALID
141 | SNDRV_PCM_INFO_INTERLEAVED
142 | SNDRV_PCM_INFO_BLOCK_TRANSFER
143 | SNDRV_PCM_INFO_JOINT_DUPLEX
144 | SNDRV_PCM_INFO_RESUME
145 | SNDRV_PCM_INFO_PAUSE),
146 .formats = (SNDRV_PCM_FMTBIT_S16_BE
147 | SNDRV_PCM_FMTBIT_S16_LE),
148 .rates = (SNDRV_PCM_RATE_CONTINUOUS),
153 .buffer_bytes_max = 64 * 4096,
154 .period_bytes_min = 4096,
155 .period_bytes_max = 4096,
160 static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream)
162 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
163 struct snd_pcm_runtime *runtime = substream->runtime;
165 mutex_lock(&opened_mutex);
167 runtime->hw = atmel_ac97c_hw;
168 if (chip->cur_rate) {
169 runtime->hw.rate_min = chip->cur_rate;
170 runtime->hw.rate_max = chip->cur_rate;
172 if (chip->cur_format)
173 runtime->hw.formats = (1ULL << chip->cur_format);
174 mutex_unlock(&opened_mutex);
175 chip->playback_substream = substream;
179 static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream)
181 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
182 struct snd_pcm_runtime *runtime = substream->runtime;
184 mutex_lock(&opened_mutex);
186 runtime->hw = atmel_ac97c_hw;
187 if (chip->cur_rate) {
188 runtime->hw.rate_min = chip->cur_rate;
189 runtime->hw.rate_max = chip->cur_rate;
191 if (chip->cur_format)
192 runtime->hw.formats = (1ULL << chip->cur_format);
193 mutex_unlock(&opened_mutex);
194 chip->capture_substream = substream;
198 static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream)
200 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
202 mutex_lock(&opened_mutex);
206 chip->cur_format = 0;
208 mutex_unlock(&opened_mutex);
210 chip->playback_substream = NULL;
215 static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream)
217 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
219 mutex_lock(&opened_mutex);
223 chip->cur_format = 0;
225 mutex_unlock(&opened_mutex);
227 chip->capture_substream = NULL;
232 static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
233 struct snd_pcm_hw_params *hw_params)
235 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
238 retval = snd_pcm_lib_malloc_pages(substream,
239 params_buffer_bytes(hw_params));
242 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
244 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
245 dw_dma_cyclic_free(chip->dma.tx_chan);
247 /* Set restrictions to params. */
248 mutex_lock(&opened_mutex);
249 chip->cur_rate = params_rate(hw_params);
250 chip->cur_format = params_format(hw_params);
251 mutex_unlock(&opened_mutex);
256 static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
257 struct snd_pcm_hw_params *hw_params)
259 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
262 retval = snd_pcm_lib_malloc_pages(substream,
263 params_buffer_bytes(hw_params));
266 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
268 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
269 dw_dma_cyclic_free(chip->dma.rx_chan);
271 /* Set restrictions to params. */
272 mutex_lock(&opened_mutex);
273 chip->cur_rate = params_rate(hw_params);
274 chip->cur_format = params_format(hw_params);
275 mutex_unlock(&opened_mutex);
280 static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream)
282 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
283 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
284 dw_dma_cyclic_free(chip->dma.tx_chan);
285 return snd_pcm_lib_free_pages(substream);
288 static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream)
290 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
291 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
292 dw_dma_cyclic_free(chip->dma.rx_chan);
293 return snd_pcm_lib_free_pages(substream);
296 static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
298 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
299 struct snd_pcm_runtime *runtime = substream->runtime;
300 unsigned long word = 0;
303 /* assign channels to AC97C channel A */
304 switch (runtime->channels) {
306 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
309 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
310 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
313 /* TODO: support more than two channels */
316 ac97c_writel(chip, OCA, word);
318 /* configure sample format and size */
319 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
321 switch (runtime->format) {
322 case SNDRV_PCM_FORMAT_S16_LE:
323 word |= AC97C_CMR_CEM_LITTLE;
325 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
327 word &= ~(AC97C_CMR_CEM_LITTLE);
331 ac97c_writel(chip, CAMR, word);
333 /* set variable rate if needed */
334 if (runtime->rate != 48000) {
335 word = ac97c_readl(chip, MR);
336 word |= AC97C_MR_VRA;
337 ac97c_writel(chip, MR, word);
339 word = ac97c_readl(chip, MR);
340 word &= ~(AC97C_MR_VRA);
341 ac97c_writel(chip, MR, word);
344 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
347 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
350 if (!test_bit(DMA_TX_READY, &chip->flags))
351 retval = atmel_ac97c_prepare_dma(chip, substream,
357 static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
359 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
360 struct snd_pcm_runtime *runtime = substream->runtime;
361 unsigned long word = 0;
364 /* assign channels to AC97C channel A */
365 switch (runtime->channels) {
367 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
370 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
371 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
374 /* TODO: support more than two channels */
377 ac97c_writel(chip, ICA, word);
379 /* configure sample format and size */
380 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
382 switch (runtime->format) {
383 case SNDRV_PCM_FORMAT_S16_LE:
384 word |= AC97C_CMR_CEM_LITTLE;
386 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
388 word &= ~(AC97C_CMR_CEM_LITTLE);
392 ac97c_writel(chip, CAMR, word);
394 /* set variable rate if needed */
395 if (runtime->rate != 48000) {
396 word = ac97c_readl(chip, MR);
397 word |= AC97C_MR_VRA;
398 ac97c_writel(chip, MR, word);
400 word = ac97c_readl(chip, MR);
401 word &= ~(AC97C_MR_VRA);
402 ac97c_writel(chip, MR, word);
405 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
408 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
411 if (!test_bit(DMA_RX_READY, &chip->flags))
412 retval = atmel_ac97c_prepare_dma(chip, substream,
419 atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
421 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
425 camr = ac97c_readl(chip, CAMR);
428 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
429 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
430 case SNDRV_PCM_TRIGGER_START:
431 retval = dw_dma_cyclic_start(chip->dma.tx_chan);
434 camr |= AC97C_CMR_CENA;
436 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
437 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
438 case SNDRV_PCM_TRIGGER_STOP:
439 dw_dma_cyclic_stop(chip->dma.tx_chan);
440 if (chip->opened <= 1)
441 camr &= ~AC97C_CMR_CENA;
448 ac97c_writel(chip, CAMR, camr);
454 atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
456 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
460 camr = ac97c_readl(chip, CAMR);
463 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
464 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
465 case SNDRV_PCM_TRIGGER_START:
466 retval = dw_dma_cyclic_start(chip->dma.rx_chan);
469 camr |= AC97C_CMR_CENA;
471 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
472 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
473 case SNDRV_PCM_TRIGGER_STOP:
474 dw_dma_cyclic_stop(chip->dma.rx_chan);
475 if (chip->opened <= 1)
476 camr &= ~AC97C_CMR_CENA;
483 ac97c_writel(chip, CAMR, camr);
488 static snd_pcm_uframes_t
489 atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
491 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
492 struct snd_pcm_runtime *runtime = substream->runtime;
493 snd_pcm_uframes_t frames;
496 bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
497 bytes -= runtime->dma_addr;
499 frames = bytes_to_frames(runtime, bytes);
500 if (frames >= runtime->buffer_size)
501 frames -= runtime->buffer_size;
505 static snd_pcm_uframes_t
506 atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
508 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
509 struct snd_pcm_runtime *runtime = substream->runtime;
510 snd_pcm_uframes_t frames;
513 bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
514 bytes -= runtime->dma_addr;
516 frames = bytes_to_frames(runtime, bytes);
517 if (frames >= runtime->buffer_size)
518 frames -= runtime->buffer_size;
522 static struct snd_pcm_ops atmel_ac97_playback_ops = {
523 .open = atmel_ac97c_playback_open,
524 .close = atmel_ac97c_playback_close,
525 .ioctl = snd_pcm_lib_ioctl,
526 .hw_params = atmel_ac97c_playback_hw_params,
527 .hw_free = atmel_ac97c_playback_hw_free,
528 .prepare = atmel_ac97c_playback_prepare,
529 .trigger = atmel_ac97c_playback_trigger,
530 .pointer = atmel_ac97c_playback_pointer,
533 static struct snd_pcm_ops atmel_ac97_capture_ops = {
534 .open = atmel_ac97c_capture_open,
535 .close = atmel_ac97c_capture_close,
536 .ioctl = snd_pcm_lib_ioctl,
537 .hw_params = atmel_ac97c_capture_hw_params,
538 .hw_free = atmel_ac97c_capture_hw_free,
539 .prepare = atmel_ac97c_capture_prepare,
540 .trigger = atmel_ac97c_capture_trigger,
541 .pointer = atmel_ac97c_capture_pointer,
544 static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
547 struct snd_pcm_hardware hw = atmel_ac97c_hw;
548 int capture, playback, retval;
550 capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
551 playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
553 retval = snd_pcm_new(chip->card, chip->card->shortname,
554 chip->pdev->id, playback, capture, &pcm);
559 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
560 &atmel_ac97_capture_ops);
562 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
563 &atmel_ac97_playback_ops);
565 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
566 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
567 hw.buffer_bytes_max);
571 pcm->private_data = chip;
573 strcpy(pcm->name, chip->card->shortname);
579 static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip)
581 struct snd_ac97_template template;
582 memset(&template, 0, sizeof(template));
583 template.private_data = chip;
584 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
587 static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg,
590 struct atmel_ac97c *chip = get_chip(ac97);
594 word = (reg & 0x7f) << 16 | val;
597 if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
598 ac97c_writel(chip, COTHR, word);
604 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
607 static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97,
610 struct atmel_ac97c *chip = get_chip(ac97);
615 word = (0x80 | (reg & 0x7f)) << 16;
617 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
618 ac97c_readl(chip, CORHR);
624 if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
625 ac97c_writel(chip, COTHR, word);
637 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
638 unsigned short val = ac97c_readl(chip, CORHR);
649 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
653 static bool filter(struct dma_chan *chan, void *slave)
655 struct dw_dma_slave *dws = slave;
657 if (dws->dma_dev == chan->device->dev) {
664 static void atmel_ac97c_reset(struct atmel_ac97c *chip)
666 ac97c_writel(chip, MR, AC97C_MR_WRST);
668 if (gpio_is_valid(chip->reset_pin)) {
669 gpio_set_value(chip->reset_pin, 0);
670 /* AC97 v2.2 specifications says minimum 1 us. */
672 gpio_set_value(chip->reset_pin, 1);
676 ac97c_writel(chip, MR, AC97C_MR_ENA);
679 static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
681 struct snd_card *card;
682 struct atmel_ac97c *chip;
683 struct resource *regs;
684 struct ac97c_platform_data *pdata;
686 static struct snd_ac97_bus_ops ops = {
687 .write = atmel_ac97c_write,
688 .read = atmel_ac97c_read,
692 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
694 dev_dbg(&pdev->dev, "no memory resource\n");
698 pdata = pdev->dev.platform_data;
700 dev_dbg(&pdev->dev, "no platform data\n");
704 pclk = clk_get(&pdev->dev, "pclk");
706 dev_dbg(&pdev->dev, "no peripheral clock\n");
707 return PTR_ERR(pclk);
711 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
712 THIS_MODULE, sizeof(struct atmel_ac97c), &card);
714 dev_dbg(&pdev->dev, "could not create sound card device\n");
715 goto err_snd_card_new;
718 chip = get_chip(card);
720 spin_lock_init(&chip->lock);
722 strcpy(card->driver, "Atmel AC97C");
723 strcpy(card->shortname, "Atmel AC97C");
724 sprintf(card->longname, "Atmel AC97 controller");
729 chip->regs = ioremap(regs->start, regs->end - regs->start + 1);
732 dev_dbg(&pdev->dev, "could not remap register memory\n");
736 if (gpio_is_valid(pdata->reset_pin)) {
737 if (gpio_request(pdata->reset_pin, "reset_pin")) {
738 dev_dbg(&pdev->dev, "reset pin not available\n");
739 chip->reset_pin = -ENODEV;
741 gpio_direction_output(pdata->reset_pin, 1);
742 chip->reset_pin = pdata->reset_pin;
746 snd_card_set_dev(card, &pdev->dev);
748 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
750 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
754 atmel_ac97c_reset(chip);
756 retval = atmel_ac97c_mixer_new(chip);
758 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
762 if (pdata->rx_dws.dma_dev) {
763 struct dw_dma_slave *dws = &pdata->rx_dws;
766 dws->rx_reg = regs->start + AC97C_CARHR + 2;
769 dma_cap_set(DMA_SLAVE, mask);
771 chip->dma.rx_chan = dma_request_channel(mask, filter, dws);
773 dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
774 chip->dma.rx_chan->dev->device.bus_id);
775 set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
778 if (pdata->tx_dws.dma_dev) {
779 struct dw_dma_slave *dws = &pdata->tx_dws;
782 dws->tx_reg = regs->start + AC97C_CATHR + 2;
785 dma_cap_set(DMA_SLAVE, mask);
787 chip->dma.tx_chan = dma_request_channel(mask, filter, dws);
789 dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
790 chip->dma.tx_chan->dev->device.bus_id);
791 set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
794 if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
795 !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
796 dev_dbg(&pdev->dev, "DMA not available\n");
801 retval = atmel_ac97c_pcm_new(chip);
803 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
807 retval = snd_card_register(card);
809 dev_dbg(&pdev->dev, "could not register sound card\n");
813 platform_set_drvdata(pdev, card);
815 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p\n",
821 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
822 dma_release_channel(chip->dma.rx_chan);
823 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
824 dma_release_channel(chip->dma.tx_chan);
825 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
826 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
827 chip->dma.rx_chan = NULL;
828 chip->dma.tx_chan = NULL;
830 snd_card_set_dev(card, NULL);
832 if (gpio_is_valid(chip->reset_pin))
833 gpio_free(chip->reset_pin);
845 static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg)
847 struct snd_card *card = platform_get_drvdata(pdev);
848 struct atmel_ac97c *chip = card->private_data;
850 if (test_bit(DMA_RX_READY, &chip->flags))
851 dw_dma_cyclic_stop(chip->dma.rx_chan);
852 if (test_bit(DMA_TX_READY, &chip->flags))
853 dw_dma_cyclic_stop(chip->dma.tx_chan);
854 clk_disable(chip->pclk);
859 static int atmel_ac97c_resume(struct platform_device *pdev)
861 struct snd_card *card = platform_get_drvdata(pdev);
862 struct atmel_ac97c *chip = card->private_data;
864 clk_enable(chip->pclk);
865 if (test_bit(DMA_RX_READY, &chip->flags))
866 dw_dma_cyclic_start(chip->dma.rx_chan);
867 if (test_bit(DMA_TX_READY, &chip->flags))
868 dw_dma_cyclic_start(chip->dma.tx_chan);
873 #define atmel_ac97c_suspend NULL
874 #define atmel_ac97c_resume NULL
877 static int __devexit atmel_ac97c_remove(struct platform_device *pdev)
879 struct snd_card *card = platform_get_drvdata(pdev);
880 struct atmel_ac97c *chip = get_chip(card);
882 if (gpio_is_valid(chip->reset_pin))
883 gpio_free(chip->reset_pin);
885 clk_disable(chip->pclk);
889 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
890 dma_release_channel(chip->dma.rx_chan);
891 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
892 dma_release_channel(chip->dma.tx_chan);
893 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
894 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
895 chip->dma.rx_chan = NULL;
896 chip->dma.tx_chan = NULL;
898 snd_card_set_dev(card, NULL);
901 platform_set_drvdata(pdev, NULL);
906 static struct platform_driver atmel_ac97c_driver = {
907 .remove = __devexit_p(atmel_ac97c_remove),
909 .name = "atmel_ac97c",
911 .suspend = atmel_ac97c_suspend,
912 .resume = atmel_ac97c_resume,
915 static int __init atmel_ac97c_init(void)
917 return platform_driver_probe(&atmel_ac97c_driver,
920 module_init(atmel_ac97c_init);
922 static void __exit atmel_ac97c_exit(void)
924 platform_driver_unregister(&atmel_ac97c_driver);
926 module_exit(atmel_ac97c_exit);
928 MODULE_LICENSE("GPL");
929 MODULE_DESCRIPTION("Driver for Atmel AC97 controller");
930 MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");