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 */
317 ac97c_writel(chip, OCA, word);
319 /* configure sample format and size */
320 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
322 switch (runtime->format) {
323 case SNDRV_PCM_FORMAT_S16_LE:
324 word |= AC97C_CMR_CEM_LITTLE;
326 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
328 word &= ~(AC97C_CMR_CEM_LITTLE);
332 ac97c_writel(chip, CAMR, word);
334 /* set variable rate if needed */
335 if (runtime->rate != 48000) {
336 word = ac97c_readl(chip, MR);
337 word |= AC97C_MR_VRA;
338 ac97c_writel(chip, MR, word);
340 word = ac97c_readl(chip, MR);
341 word &= ~(AC97C_MR_VRA);
342 ac97c_writel(chip, MR, word);
345 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
348 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
351 if (!test_bit(DMA_TX_READY, &chip->flags))
352 retval = atmel_ac97c_prepare_dma(chip, substream,
358 static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
360 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
361 struct snd_pcm_runtime *runtime = substream->runtime;
362 unsigned long word = 0;
365 /* assign channels to AC97C channel A */
366 switch (runtime->channels) {
368 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
371 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
372 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
375 /* TODO: support more than two channels */
379 ac97c_writel(chip, ICA, word);
381 /* configure sample format and size */
382 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
384 switch (runtime->format) {
385 case SNDRV_PCM_FORMAT_S16_LE:
386 word |= AC97C_CMR_CEM_LITTLE;
388 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
390 word &= ~(AC97C_CMR_CEM_LITTLE);
394 ac97c_writel(chip, CAMR, word);
396 /* set variable rate if needed */
397 if (runtime->rate != 48000) {
398 word = ac97c_readl(chip, MR);
399 word |= AC97C_MR_VRA;
400 ac97c_writel(chip, MR, word);
402 word = ac97c_readl(chip, MR);
403 word &= ~(AC97C_MR_VRA);
404 ac97c_writel(chip, MR, word);
407 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
410 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
413 if (!test_bit(DMA_RX_READY, &chip->flags))
414 retval = atmel_ac97c_prepare_dma(chip, substream,
421 atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
423 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
427 camr = ac97c_readl(chip, CAMR);
430 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
431 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
432 case SNDRV_PCM_TRIGGER_START:
433 retval = dw_dma_cyclic_start(chip->dma.tx_chan);
436 camr |= AC97C_CMR_CENA;
438 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
439 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
440 case SNDRV_PCM_TRIGGER_STOP:
441 dw_dma_cyclic_stop(chip->dma.tx_chan);
442 if (chip->opened <= 1)
443 camr &= ~AC97C_CMR_CENA;
450 ac97c_writel(chip, CAMR, camr);
456 atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
458 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
462 camr = ac97c_readl(chip, CAMR);
465 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
466 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
467 case SNDRV_PCM_TRIGGER_START:
468 retval = dw_dma_cyclic_start(chip->dma.rx_chan);
471 camr |= AC97C_CMR_CENA;
473 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
474 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
475 case SNDRV_PCM_TRIGGER_STOP:
476 dw_dma_cyclic_stop(chip->dma.rx_chan);
477 if (chip->opened <= 1)
478 camr &= ~AC97C_CMR_CENA;
485 ac97c_writel(chip, CAMR, camr);
490 static snd_pcm_uframes_t
491 atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
493 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
494 struct snd_pcm_runtime *runtime = substream->runtime;
495 snd_pcm_uframes_t frames;
498 bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
499 bytes -= runtime->dma_addr;
501 frames = bytes_to_frames(runtime, bytes);
502 if (frames >= runtime->buffer_size)
503 frames -= runtime->buffer_size;
507 static snd_pcm_uframes_t
508 atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
510 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
511 struct snd_pcm_runtime *runtime = substream->runtime;
512 snd_pcm_uframes_t frames;
515 bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
516 bytes -= runtime->dma_addr;
518 frames = bytes_to_frames(runtime, bytes);
519 if (frames >= runtime->buffer_size)
520 frames -= runtime->buffer_size;
524 static struct snd_pcm_ops atmel_ac97_playback_ops = {
525 .open = atmel_ac97c_playback_open,
526 .close = atmel_ac97c_playback_close,
527 .ioctl = snd_pcm_lib_ioctl,
528 .hw_params = atmel_ac97c_playback_hw_params,
529 .hw_free = atmel_ac97c_playback_hw_free,
530 .prepare = atmel_ac97c_playback_prepare,
531 .trigger = atmel_ac97c_playback_trigger,
532 .pointer = atmel_ac97c_playback_pointer,
535 static struct snd_pcm_ops atmel_ac97_capture_ops = {
536 .open = atmel_ac97c_capture_open,
537 .close = atmel_ac97c_capture_close,
538 .ioctl = snd_pcm_lib_ioctl,
539 .hw_params = atmel_ac97c_capture_hw_params,
540 .hw_free = atmel_ac97c_capture_hw_free,
541 .prepare = atmel_ac97c_capture_prepare,
542 .trigger = atmel_ac97c_capture_trigger,
543 .pointer = atmel_ac97c_capture_pointer,
546 static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
549 struct snd_pcm_hardware hw = atmel_ac97c_hw;
550 int capture, playback, retval;
552 capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
553 playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
555 retval = snd_pcm_new(chip->card, chip->card->shortname,
556 chip->pdev->id, playback, capture, &pcm);
561 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
562 &atmel_ac97_capture_ops);
564 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
565 &atmel_ac97_playback_ops);
567 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
568 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
569 hw.buffer_bytes_max);
573 pcm->private_data = chip;
575 strcpy(pcm->name, chip->card->shortname);
581 static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip)
583 struct snd_ac97_template template;
584 memset(&template, 0, sizeof(template));
585 template.private_data = chip;
586 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
589 static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg,
592 struct atmel_ac97c *chip = get_chip(ac97);
596 word = (reg & 0x7f) << 16 | val;
599 if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
600 ac97c_writel(chip, COTHR, word);
606 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
609 static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97,
612 struct atmel_ac97c *chip = get_chip(ac97);
617 word = (0x80 | (reg & 0x7f)) << 16;
619 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
620 ac97c_readl(chip, CORHR);
626 if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
627 ac97c_writel(chip, COTHR, word);
639 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
640 unsigned short val = ac97c_readl(chip, CORHR);
651 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
655 static bool filter(struct dma_chan *chan, void *slave)
657 struct dw_dma_slave *dws = slave;
659 if (dws->dma_dev == chan->device->dev) {
666 static void atmel_ac97c_reset(struct atmel_ac97c *chip)
668 ac97c_writel(chip, MR, AC97C_MR_WRST);
670 if (gpio_is_valid(chip->reset_pin)) {
671 gpio_set_value(chip->reset_pin, 0);
672 /* AC97 v2.2 specifications says minimum 1 us. */
674 gpio_set_value(chip->reset_pin, 1);
678 ac97c_writel(chip, MR, AC97C_MR_ENA);
681 static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
683 struct snd_card *card;
684 struct atmel_ac97c *chip;
685 struct resource *regs;
686 struct ac97c_platform_data *pdata;
688 static struct snd_ac97_bus_ops ops = {
689 .write = atmel_ac97c_write,
690 .read = atmel_ac97c_read,
694 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
696 dev_dbg(&pdev->dev, "no memory resource\n");
700 pdata = pdev->dev.platform_data;
702 dev_dbg(&pdev->dev, "no platform data\n");
706 pclk = clk_get(&pdev->dev, "pclk");
708 dev_dbg(&pdev->dev, "no peripheral clock\n");
709 return PTR_ERR(pclk);
713 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
714 THIS_MODULE, sizeof(struct atmel_ac97c), &card);
716 dev_dbg(&pdev->dev, "could not create sound card device\n");
717 goto err_snd_card_new;
720 chip = get_chip(card);
722 spin_lock_init(&chip->lock);
724 strcpy(card->driver, "Atmel AC97C");
725 strcpy(card->shortname, "Atmel AC97C");
726 sprintf(card->longname, "Atmel AC97 controller");
731 chip->regs = ioremap(regs->start, regs->end - regs->start + 1);
734 dev_dbg(&pdev->dev, "could not remap register memory\n");
738 if (gpio_is_valid(pdata->reset_pin)) {
739 if (gpio_request(pdata->reset_pin, "reset_pin")) {
740 dev_dbg(&pdev->dev, "reset pin not available\n");
741 chip->reset_pin = -ENODEV;
743 gpio_direction_output(pdata->reset_pin, 1);
744 chip->reset_pin = pdata->reset_pin;
748 snd_card_set_dev(card, &pdev->dev);
750 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
752 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
756 atmel_ac97c_reset(chip);
758 retval = atmel_ac97c_mixer_new(chip);
760 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
764 if (pdata->rx_dws.dma_dev) {
765 struct dw_dma_slave *dws = &pdata->rx_dws;
768 dws->rx_reg = regs->start + AC97C_CARHR + 2;
771 dma_cap_set(DMA_SLAVE, mask);
773 chip->dma.rx_chan = dma_request_channel(mask, filter, dws);
775 dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
776 chip->dma.rx_chan->dev->device.bus_id);
777 set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
780 if (pdata->tx_dws.dma_dev) {
781 struct dw_dma_slave *dws = &pdata->tx_dws;
784 dws->tx_reg = regs->start + AC97C_CATHR + 2;
787 dma_cap_set(DMA_SLAVE, mask);
789 chip->dma.tx_chan = dma_request_channel(mask, filter, dws);
791 dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
792 chip->dma.tx_chan->dev->device.bus_id);
793 set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
796 if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
797 !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
798 dev_dbg(&pdev->dev, "DMA not available\n");
803 retval = atmel_ac97c_pcm_new(chip);
805 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
809 retval = snd_card_register(card);
811 dev_dbg(&pdev->dev, "could not register sound card\n");
815 platform_set_drvdata(pdev, card);
817 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p\n",
823 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
824 dma_release_channel(chip->dma.rx_chan);
825 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
826 dma_release_channel(chip->dma.tx_chan);
827 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
828 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
829 chip->dma.rx_chan = NULL;
830 chip->dma.tx_chan = NULL;
832 snd_card_set_dev(card, NULL);
834 if (gpio_is_valid(chip->reset_pin))
835 gpio_free(chip->reset_pin);
847 static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg)
849 struct snd_card *card = platform_get_drvdata(pdev);
850 struct atmel_ac97c *chip = card->private_data;
852 if (test_bit(DMA_RX_READY, &chip->flags))
853 dw_dma_cyclic_stop(chip->dma.rx_chan);
854 if (test_bit(DMA_TX_READY, &chip->flags))
855 dw_dma_cyclic_stop(chip->dma.tx_chan);
856 clk_disable(chip->pclk);
861 static int atmel_ac97c_resume(struct platform_device *pdev)
863 struct snd_card *card = platform_get_drvdata(pdev);
864 struct atmel_ac97c *chip = card->private_data;
866 clk_enable(chip->pclk);
867 if (test_bit(DMA_RX_READY, &chip->flags))
868 dw_dma_cyclic_start(chip->dma.rx_chan);
869 if (test_bit(DMA_TX_READY, &chip->flags))
870 dw_dma_cyclic_start(chip->dma.tx_chan);
875 #define atmel_ac97c_suspend NULL
876 #define atmel_ac97c_resume NULL
879 static int __devexit atmel_ac97c_remove(struct platform_device *pdev)
881 struct snd_card *card = platform_get_drvdata(pdev);
882 struct atmel_ac97c *chip = get_chip(card);
884 if (gpio_is_valid(chip->reset_pin))
885 gpio_free(chip->reset_pin);
887 clk_disable(chip->pclk);
891 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
892 dma_release_channel(chip->dma.rx_chan);
893 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
894 dma_release_channel(chip->dma.tx_chan);
895 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
896 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
897 chip->dma.rx_chan = NULL;
898 chip->dma.tx_chan = NULL;
900 snd_card_set_dev(card, NULL);
903 platform_set_drvdata(pdev, NULL);
908 static struct platform_driver atmel_ac97c_driver = {
909 .remove = __devexit_p(atmel_ac97c_remove),
911 .name = "atmel_ac97c",
913 .suspend = atmel_ac97c_suspend,
914 .resume = atmel_ac97c_resume,
917 static int __init atmel_ac97c_init(void)
919 return platform_driver_probe(&atmel_ac97c_driver,
922 module_init(atmel_ac97c_init);
924 static void __exit atmel_ac97c_exit(void)
926 platform_driver_unregister(&atmel_ac97c_driver);
928 module_exit(atmel_ac97c_exit);
930 MODULE_LICENSE("GPL");
931 MODULE_DESCRIPTION("Driver for Atmel AC97 controller");
932 MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");