^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Nicolas Pitre
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Created: Dec 02, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright: MontaVista Software Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/dmaengine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sound/pxa2xx-lib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sound/dmaengine_pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <mach/regs-ac97.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <mach/audio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static void pxa2xx_ac97_legacy_reset(struct snd_ac97 *ac97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (!pxa2xx_ac97_try_cold_reset())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) pxa2xx_ac97_try_warm_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) pxa2xx_ac97_finish_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static unsigned short pxa2xx_ac97_legacy_read(struct snd_ac97 *ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned short reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ret = pxa2xx_ac97_read(ac97->num, reg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return (unsigned short)(ret & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static void pxa2xx_ac97_legacy_write(struct snd_ac97 *ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) unsigned short reg, unsigned short val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int __always_unused ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ret = pxa2xx_ac97_write(ac97->num, reg, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static const struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .read = pxa2xx_ac97_legacy_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .write = pxa2xx_ac97_legacy_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) .reset = pxa2xx_ac97_legacy_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static struct snd_pcm *pxa2xx_ac97_pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct snd_ac97 *pxa2xx_ac97_ac97;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int pxa2xx_ac97_pcm_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) pxa2xx_audio_ops_t *platform_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int ret, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ret = pxa2xx_pcm_open(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) runtime->hw.channels_min = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) runtime->hw.channels_max = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) i = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) AC97_RATES_FRONT_DAC : AC97_RATES_ADC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) runtime->hw.rates = pxa2xx_ac97_ac97->rates[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) snd_pcm_limit_hw_rates(runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) platform_ops = substream->pcm->card->dev->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (platform_ops && platform_ops->startup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ret = platform_ops->startup(substream, platform_ops->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pxa2xx_pcm_close(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static int pxa2xx_ac97_pcm_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pxa2xx_audio_ops_t *platform_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) platform_ops = substream->pcm->card->dev->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (platform_ops && platform_ops->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) platform_ops->shutdown(substream, platform_ops->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int pxa2xx_ac97_pcm_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ret = pxa2xx_pcm_prepare(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return snd_ac97_set_rate(pxa2xx_ac97_ac97, reg, runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int pxa2xx_ac97_do_suspend(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) snd_power_change_state(card, SNDRV_CTL_POWER_D3cold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) snd_ac97_suspend(pxa2xx_ac97_ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (platform_ops && platform_ops->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) platform_ops->suspend(platform_ops->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return pxa2xx_ac97_hw_suspend();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int pxa2xx_ac97_do_resume(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) pxa2xx_audio_ops_t *platform_ops = card->dev->platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) rc = pxa2xx_ac97_hw_resume();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (platform_ops && platform_ops->resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) platform_ops->resume(platform_ops->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) snd_ac97_resume(pxa2xx_ac97_ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) snd_power_change_state(card, SNDRV_CTL_POWER_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static int pxa2xx_ac97_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct snd_card *card = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ret = pxa2xx_ac97_do_suspend(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int pxa2xx_ac97_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct snd_card *card = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ret = pxa2xx_ac97_do_resume(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, pxa2xx_ac97_suspend, pxa2xx_ac97_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static const struct snd_pcm_ops pxa2xx_ac97_pcm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .open = pxa2xx_ac97_pcm_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .close = pxa2xx_ac97_pcm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .hw_params = pxa2xx_pcm_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .hw_free = pxa2xx_pcm_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .prepare = pxa2xx_ac97_pcm_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) .trigger = pxa2xx_pcm_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .pointer = pxa2xx_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .mmap = pxa2xx_pcm_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) static int pxa2xx_ac97_pcm_new(struct snd_card *card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) int stream, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ret = snd_pcm_new(card, "PXA2xx-PCM", 0, 1, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) pcm->private_free = pxa2xx_pcm_free_dma_buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) stream = SNDRV_PCM_STREAM_PLAYBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) snd_pcm_set_ops(pcm, stream, &pxa2xx_ac97_pcm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) stream = SNDRV_PCM_STREAM_CAPTURE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) snd_pcm_set_ops(pcm, stream, &pxa2xx_ac97_pcm_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ret = pxa2xx_pcm_preallocate_dma_buffer(pcm, stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) pxa2xx_ac97_pcm = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static int pxa2xx_ac97_probe(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct snd_ac97_bus *ac97_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct snd_ac97_template ac97_template;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) pxa2xx_audio_ops_t *pdata = dev->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (dev->id >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dev_err(&dev->dev, "PXA2xx has only one AC97 port.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto err_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) ret = snd_card_new(&dev->dev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) THIS_MODULE, 0, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) strlcpy(card->driver, dev->dev.driver->name, sizeof(card->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ret = pxa2xx_ac97_pcm_new(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ret = pxa2xx_ac97_hw_probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = snd_ac97_bus(card, 0, &pxa2xx_ac97_ops, NULL, &ac97_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) goto err_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) memset(&ac97_template, 0, sizeof(ac97_template));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ret = snd_ac97_mixer(ac97_bus, &ac97_template, &pxa2xx_ac97_ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto err_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) snprintf(card->shortname, sizeof(card->shortname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) "%s", snd_ac97_get_short_name(pxa2xx_ac97_ac97));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) snprintf(card->longname, sizeof(card->longname),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) "%s (%s)", dev->dev.driver->name, card->mixername);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (pdata && pdata->codec_pdata[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) snd_ac97_dev_add_pdata(ac97_bus->codec[0], pdata->codec_pdata[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) platform_set_drvdata(dev, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) err_remove:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) pxa2xx_ac97_hw_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (card)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) err_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static int pxa2xx_ac97_remove(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct snd_card *card = platform_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (card) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) pxa2xx_ac97_hw_remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) static struct platform_driver pxa2xx_ac97_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .probe = pxa2xx_ac97_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .remove = pxa2xx_ac97_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) .name = "pxa2xx-ac97",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .pm = &pxa2xx_ac97_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) module_platform_driver(pxa2xx_ac97_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) MODULE_AUTHOR("Nicolas Pitre");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) MODULE_ALIAS("platform:pxa2xx-ac97");