175b41027SLiam Girdwood /* 275b41027SLiam Girdwood * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip. 375b41027SLiam Girdwood * 475b41027SLiam Girdwood * Author: Nicolas Pitre 575b41027SLiam Girdwood * Created: Dec 02, 2004 675b41027SLiam Girdwood * Copyright: MontaVista Software Inc. 775b41027SLiam Girdwood * 875b41027SLiam Girdwood * This program is free software; you can redistribute it and/or modify 975b41027SLiam Girdwood * it under the terms of the GNU General Public License version 2 as 1075b41027SLiam Girdwood * published by the Free Software Foundation. 1175b41027SLiam Girdwood */ 1275b41027SLiam Girdwood 1375b41027SLiam Girdwood #include <linux/init.h> 1423019a73SRob Herring #include <linux/io.h> 1575b41027SLiam Girdwood #include <linux/module.h> 1675b41027SLiam Girdwood #include <linux/platform_device.h> 1775b41027SLiam Girdwood 1875b41027SLiam Girdwood #include <sound/core.h> 1975b41027SLiam Girdwood #include <sound/ac97_codec.h> 2075b41027SLiam Girdwood #include <sound/soc.h> 219c636342SDmitry Baryshkov #include <sound/pxa2xx-lib.h> 2275b41027SLiam Girdwood 23a09e64fbSRussell King #include <mach/hardware.h> 241f017a99SEric Miao #include <mach/regs-ac97.h> 257ebc8d56SEric Miao #include <mach/dma.h> 264ac0478fSMarek Vasut #include <mach/audio.h> 2775b41027SLiam Girdwood 28596ce32bSLiam Girdwood #include "pxa2xx-ac97.h" 2975b41027SLiam Girdwood 3075b41027SLiam Girdwood static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 3175b41027SLiam Girdwood { 329c636342SDmitry Baryshkov pxa2xx_ac97_try_warm_reset(ac97); 3375b41027SLiam Girdwood 349c636342SDmitry Baryshkov pxa2xx_ac97_finish_reset(ac97); 3575b41027SLiam Girdwood } 3675b41027SLiam Girdwood 3775b41027SLiam Girdwood static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 3875b41027SLiam Girdwood { 399c636342SDmitry Baryshkov pxa2xx_ac97_try_cold_reset(ac97); 407a22323bSMark Brown 419c636342SDmitry Baryshkov pxa2xx_ac97_finish_reset(ac97); 4275b41027SLiam Girdwood } 4375b41027SLiam Girdwood 4475b41027SLiam Girdwood struct snd_ac97_bus_ops soc_ac97_ops = { 4575b41027SLiam Girdwood .read = pxa2xx_ac97_read, 4675b41027SLiam Girdwood .write = pxa2xx_ac97_write, 4775b41027SLiam Girdwood .warm_reset = pxa2xx_ac97_warm_reset, 4875b41027SLiam Girdwood .reset = pxa2xx_ac97_cold_reset, 4975b41027SLiam Girdwood }; 508abfc260SKuninori Morimoto EXPORT_SYMBOL_GPL(soc_ac97_ops); 5175b41027SLiam Girdwood 5275b41027SLiam Girdwood static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_out = { 5375b41027SLiam Girdwood .name = "AC97 PCM Stereo out", 5475b41027SLiam Girdwood .dev_addr = __PREG(PCDR), 5587f3dd77SEric Miao .drcmr = &DRCMR(12), 5675b41027SLiam Girdwood .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | 5775b41027SLiam Girdwood DCMD_BURST32 | DCMD_WIDTH4, 5875b41027SLiam Girdwood }; 5975b41027SLiam Girdwood 6075b41027SLiam Girdwood static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_in = { 6175b41027SLiam Girdwood .name = "AC97 PCM Stereo in", 6275b41027SLiam Girdwood .dev_addr = __PREG(PCDR), 6387f3dd77SEric Miao .drcmr = &DRCMR(11), 6475b41027SLiam Girdwood .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | 6575b41027SLiam Girdwood DCMD_BURST32 | DCMD_WIDTH4, 6675b41027SLiam Girdwood }; 6775b41027SLiam Girdwood 6875b41027SLiam Girdwood static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_out = { 6975b41027SLiam Girdwood .name = "AC97 Aux PCM (Slot 5) Mono out", 7075b41027SLiam Girdwood .dev_addr = __PREG(MODR), 7187f3dd77SEric Miao .drcmr = &DRCMR(10), 7275b41027SLiam Girdwood .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG | 7375b41027SLiam Girdwood DCMD_BURST16 | DCMD_WIDTH2, 7475b41027SLiam Girdwood }; 7575b41027SLiam Girdwood 7675b41027SLiam Girdwood static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_in = { 7775b41027SLiam Girdwood .name = "AC97 Aux PCM (Slot 5) Mono in", 7875b41027SLiam Girdwood .dev_addr = __PREG(MODR), 7987f3dd77SEric Miao .drcmr = &DRCMR(9), 8075b41027SLiam Girdwood .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | 8175b41027SLiam Girdwood DCMD_BURST16 | DCMD_WIDTH2, 8275b41027SLiam Girdwood }; 8375b41027SLiam Girdwood 8475b41027SLiam Girdwood static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_mic_mono_in = { 8575b41027SLiam Girdwood .name = "AC97 Mic PCM (Slot 6) Mono in", 8675b41027SLiam Girdwood .dev_addr = __PREG(MCDR), 8787f3dd77SEric Miao .drcmr = &DRCMR(8), 8875b41027SLiam Girdwood .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC | 8975b41027SLiam Girdwood DCMD_BURST16 | DCMD_WIDTH2, 9075b41027SLiam Girdwood }; 9175b41027SLiam Girdwood 9275b41027SLiam Girdwood #ifdef CONFIG_PM 93dc7d7b83SMark Brown static int pxa2xx_ac97_suspend(struct snd_soc_dai *dai) 9475b41027SLiam Girdwood { 959c636342SDmitry Baryshkov return pxa2xx_ac97_hw_suspend(); 9675b41027SLiam Girdwood } 9775b41027SLiam Girdwood 98dc7d7b83SMark Brown static int pxa2xx_ac97_resume(struct snd_soc_dai *dai) 9975b41027SLiam Girdwood { 1009c636342SDmitry Baryshkov return pxa2xx_ac97_hw_resume(); 10175b41027SLiam Girdwood } 10275b41027SLiam Girdwood 10375b41027SLiam Girdwood #else 10475b41027SLiam Girdwood #define pxa2xx_ac97_suspend NULL 10575b41027SLiam Girdwood #define pxa2xx_ac97_resume NULL 10675b41027SLiam Girdwood #endif 10775b41027SLiam Girdwood 108570f6fe1SBill Pemberton static int pxa2xx_ac97_probe(struct snd_soc_dai *dai) 10975b41027SLiam Girdwood { 1106b849bcfSMark Brown return pxa2xx_ac97_hw_probe(to_platform_device(dai->dev)); 11175b41027SLiam Girdwood } 11275b41027SLiam Girdwood 113f0fba2adSLiam Girdwood static int pxa2xx_ac97_remove(struct snd_soc_dai *dai) 11475b41027SLiam Girdwood { 1156b849bcfSMark Brown pxa2xx_ac97_hw_remove(to_platform_device(dai->dev)); 116f0fba2adSLiam Girdwood return 0; 11775b41027SLiam Girdwood } 11875b41027SLiam Girdwood 11975b41027SLiam Girdwood static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream, 120dee89c4dSMark Brown struct snd_pcm_hw_params *params, 121f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 12275b41027SLiam Girdwood { 1235f712b2bSDaniel Mack struct pxa2xx_pcm_dma_params *dma_data; 12475b41027SLiam Girdwood 12575b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1265f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_stereo_out; 12775b41027SLiam Girdwood else 1285f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_stereo_in; 1295f712b2bSDaniel Mack 1305f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 13175b41027SLiam Girdwood 13275b41027SLiam Girdwood return 0; 13375b41027SLiam Girdwood } 13475b41027SLiam Girdwood 13575b41027SLiam Girdwood static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream, 136dee89c4dSMark Brown struct snd_pcm_hw_params *params, 137f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 13875b41027SLiam Girdwood { 1395f712b2bSDaniel Mack struct pxa2xx_pcm_dma_params *dma_data; 14075b41027SLiam Girdwood 14175b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1425f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_aux_mono_out; 14375b41027SLiam Girdwood else 1445f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_aux_mono_in; 1455f712b2bSDaniel Mack 1465f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 14775b41027SLiam Girdwood 14875b41027SLiam Girdwood return 0; 14975b41027SLiam Girdwood } 15075b41027SLiam Girdwood 15175b41027SLiam Girdwood static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream, 152dee89c4dSMark Brown struct snd_pcm_hw_params *params, 153f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 15475b41027SLiam Girdwood { 15575b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 15675b41027SLiam Girdwood return -ENODEV; 15775b41027SLiam Girdwood else 1585f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, 1595f712b2bSDaniel Mack &pxa2xx_ac97_pcm_mic_mono_in); 16075b41027SLiam Girdwood 16175b41027SLiam Girdwood return 0; 16275b41027SLiam Girdwood } 16375b41027SLiam Girdwood 164596ce32bSLiam Girdwood #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 165596ce32bSLiam Girdwood SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 166596ce32bSLiam Girdwood SNDRV_PCM_RATE_48000) 167596ce32bSLiam Girdwood 16885e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = { 1696335d055SEric Miao .hw_params = pxa2xx_ac97_hw_params, 1706335d055SEric Miao }; 1716335d055SEric Miao 17285e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = { 173852fd9e5SMark Brown .hw_params = pxa2xx_ac97_hw_aux_params, 174852fd9e5SMark Brown }; 175852fd9e5SMark Brown 17685e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = { 177852fd9e5SMark Brown .hw_params = pxa2xx_ac97_hw_mic_params, 178852fd9e5SMark Brown }; 179852fd9e5SMark Brown 18075b41027SLiam Girdwood /* 18175b41027SLiam Girdwood * There is only 1 physical AC97 interface for pxa2xx, but it 18275b41027SLiam Girdwood * has extra fifo's that can be used for aux DACs and ADCs. 18375b41027SLiam Girdwood */ 184a3874196SAxel Lin static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { 18575b41027SLiam Girdwood { 18675b41027SLiam Girdwood .name = "pxa2xx-ac97", 1873ba9e10aSMark Brown .ac97_control = 1, 18875b41027SLiam Girdwood .probe = pxa2xx_ac97_probe, 18975b41027SLiam Girdwood .remove = pxa2xx_ac97_remove, 19075b41027SLiam Girdwood .suspend = pxa2xx_ac97_suspend, 19175b41027SLiam Girdwood .resume = pxa2xx_ac97_resume, 19275b41027SLiam Girdwood .playback = { 19375b41027SLiam Girdwood .stream_name = "AC97 Playback", 19475b41027SLiam Girdwood .channels_min = 2, 195596ce32bSLiam Girdwood .channels_max = 2, 196596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 197596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 19875b41027SLiam Girdwood .capture = { 19975b41027SLiam Girdwood .stream_name = "AC97 Capture", 20075b41027SLiam Girdwood .channels_min = 2, 201596ce32bSLiam Girdwood .channels_max = 2, 202596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 203596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 204852fd9e5SMark Brown .ops = &pxa_ac97_hifi_dai_ops, 20575b41027SLiam Girdwood }, 20675b41027SLiam Girdwood { 20775b41027SLiam Girdwood .name = "pxa2xx-ac97-aux", 2083ba9e10aSMark Brown .ac97_control = 1, 20975b41027SLiam Girdwood .playback = { 21075b41027SLiam Girdwood .stream_name = "AC97 Aux Playback", 21175b41027SLiam Girdwood .channels_min = 1, 212596ce32bSLiam Girdwood .channels_max = 1, 213596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 214596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 21575b41027SLiam Girdwood .capture = { 21675b41027SLiam Girdwood .stream_name = "AC97 Aux Capture", 21775b41027SLiam Girdwood .channels_min = 1, 218596ce32bSLiam Girdwood .channels_max = 1, 219596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 220596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 221852fd9e5SMark Brown .ops = &pxa_ac97_aux_dai_ops, 22275b41027SLiam Girdwood }, 22375b41027SLiam Girdwood { 22475b41027SLiam Girdwood .name = "pxa2xx-ac97-mic", 2253ba9e10aSMark Brown .ac97_control = 1, 22675b41027SLiam Girdwood .capture = { 22775b41027SLiam Girdwood .stream_name = "AC97 Mic Capture", 22875b41027SLiam Girdwood .channels_min = 1, 229596ce32bSLiam Girdwood .channels_max = 1, 230596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 231596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 232852fd9e5SMark Brown .ops = &pxa_ac97_mic_dai_ops, 233596ce32bSLiam Girdwood }, 23475b41027SLiam Girdwood }; 23575b41027SLiam Girdwood 236570f6fe1SBill Pemberton static int pxa2xx_ac97_dev_probe(struct platform_device *pdev) 2376b849bcfSMark Brown { 238f0fba2adSLiam Girdwood if (pdev->id != -1) { 2394ac0478fSMarek Vasut dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n"); 2404ac0478fSMarek Vasut return -ENXIO; 2414ac0478fSMarek Vasut } 2424ac0478fSMarek Vasut 2436b849bcfSMark Brown /* Punt most of the init to the SoC probe; we may need the machine 2446b849bcfSMark Brown * driver to do interesting things with the clocking to get us up 2456b849bcfSMark Brown * and running. 2466b849bcfSMark Brown */ 247a3874196SAxel Lin return snd_soc_register_dais(&pdev->dev, pxa_ac97_dai_driver, 248a3874196SAxel Lin ARRAY_SIZE(pxa_ac97_dai_driver)); 2496b849bcfSMark Brown } 2506b849bcfSMark Brown 251570f6fe1SBill Pemberton static int pxa2xx_ac97_dev_remove(struct platform_device *pdev) 2526b849bcfSMark Brown { 253a3874196SAxel Lin snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(pxa_ac97_dai_driver)); 2546b849bcfSMark Brown return 0; 2556b849bcfSMark Brown } 2566b849bcfSMark Brown 2576b849bcfSMark Brown static struct platform_driver pxa2xx_ac97_driver = { 2586b849bcfSMark Brown .probe = pxa2xx_ac97_dev_probe, 259570f6fe1SBill Pemberton .remove = pxa2xx_ac97_dev_remove, 2606b849bcfSMark Brown .driver = { 2616b849bcfSMark Brown .name = "pxa2xx-ac97", 2626b849bcfSMark Brown .owner = THIS_MODULE, 2636b849bcfSMark Brown }, 2646b849bcfSMark Brown }; 2656b849bcfSMark Brown 2662f702a19SAxel Lin module_platform_driver(pxa2xx_ac97_driver); 2673f4b783cSMark Brown 26875b41027SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre"); 26975b41027SLiam Girdwood MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 27075b41027SLiam Girdwood MODULE_LICENSE("GPL"); 271