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> 17d65a1458SDaniel Mack #include <linux/dmaengine.h> 1875b41027SLiam Girdwood 1975b41027SLiam Girdwood #include <sound/core.h> 2075b41027SLiam Girdwood #include <sound/ac97_codec.h> 2175b41027SLiam Girdwood #include <sound/soc.h> 229c636342SDmitry Baryshkov #include <sound/pxa2xx-lib.h> 23d65a1458SDaniel Mack #include <sound/dmaengine_pcm.h> 2475b41027SLiam Girdwood 25a09e64fbSRussell King #include <mach/hardware.h> 261f017a99SEric Miao #include <mach/regs-ac97.h> 274ac0478fSMarek Vasut #include <mach/audio.h> 2875b41027SLiam Girdwood 29596ce32bSLiam Girdwood #include "pxa2xx-ac97.h" 3075b41027SLiam Girdwood 3175b41027SLiam Girdwood static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 3275b41027SLiam Girdwood { 339c636342SDmitry Baryshkov pxa2xx_ac97_try_warm_reset(ac97); 3475b41027SLiam Girdwood 359c636342SDmitry Baryshkov pxa2xx_ac97_finish_reset(ac97); 3675b41027SLiam Girdwood } 3775b41027SLiam Girdwood 3875b41027SLiam Girdwood static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 3975b41027SLiam Girdwood { 409c636342SDmitry Baryshkov pxa2xx_ac97_try_cold_reset(ac97); 417a22323bSMark Brown 429c636342SDmitry Baryshkov pxa2xx_ac97_finish_reset(ac97); 4375b41027SLiam Girdwood } 4475b41027SLiam Girdwood 45b047e1ccSMark Brown static struct snd_ac97_bus_ops pxa2xx_ac97_ops = { 4675b41027SLiam Girdwood .read = pxa2xx_ac97_read, 4775b41027SLiam Girdwood .write = pxa2xx_ac97_write, 4875b41027SLiam Girdwood .warm_reset = pxa2xx_ac97_warm_reset, 4975b41027SLiam Girdwood .reset = pxa2xx_ac97_cold_reset, 5075b41027SLiam Girdwood }; 5175b41027SLiam Girdwood 52d65a1458SDaniel Mack static unsigned long pxa2xx_ac97_pcm_stereo_in_req = 12; 53d65a1458SDaniel Mack static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = { 54d65a1458SDaniel Mack .addr = __PREG(PCDR), 55d65a1458SDaniel Mack .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 56d65a1458SDaniel Mack .maxburst = 32, 57d65a1458SDaniel Mack .filter_data = &pxa2xx_ac97_pcm_stereo_in_req, 5875b41027SLiam Girdwood }; 5975b41027SLiam Girdwood 60d65a1458SDaniel Mack static unsigned long pxa2xx_ac97_pcm_stereo_out_req = 11; 61d65a1458SDaniel Mack static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = { 62d65a1458SDaniel Mack .addr = __PREG(PCDR), 63d65a1458SDaniel Mack .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES, 64d65a1458SDaniel Mack .maxburst = 32, 65d65a1458SDaniel Mack .filter_data = &pxa2xx_ac97_pcm_stereo_out_req, 6675b41027SLiam Girdwood }; 6775b41027SLiam Girdwood 68d65a1458SDaniel Mack static unsigned long pxa2xx_ac97_pcm_aux_mono_out_req = 10; 69d65a1458SDaniel Mack static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = { 70d65a1458SDaniel Mack .addr = __PREG(MODR), 71d65a1458SDaniel Mack .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 72d65a1458SDaniel Mack .maxburst = 16, 73d65a1458SDaniel Mack .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req, 7475b41027SLiam Girdwood }; 7575b41027SLiam Girdwood 76d65a1458SDaniel Mack static unsigned long pxa2xx_ac97_pcm_aux_mono_in_req = 9; 77d65a1458SDaniel Mack static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = { 78d65a1458SDaniel Mack .addr = __PREG(MODR), 79d65a1458SDaniel Mack .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 80d65a1458SDaniel Mack .maxburst = 16, 81d65a1458SDaniel Mack .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req, 8275b41027SLiam Girdwood }; 8375b41027SLiam Girdwood 84d65a1458SDaniel Mack static unsigned long pxa2xx_ac97_pcm_aux_mic_mono_req = 8; 85d65a1458SDaniel Mack static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = { 86d65a1458SDaniel Mack .addr = __PREG(MCDR), 87d65a1458SDaniel Mack .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES, 88d65a1458SDaniel Mack .maxburst = 16, 89d65a1458SDaniel Mack .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req, 9075b41027SLiam Girdwood }; 9175b41027SLiam Girdwood 9275b41027SLiam Girdwood static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream, 93dee89c4dSMark Brown struct snd_pcm_hw_params *params, 94f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 9575b41027SLiam Girdwood { 96d65a1458SDaniel Mack struct snd_dmaengine_dai_dma_data *dma_data; 9775b41027SLiam Girdwood 9875b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 995f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_stereo_out; 10075b41027SLiam Girdwood else 1015f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_stereo_in; 1025f712b2bSDaniel Mack 1035f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 10475b41027SLiam Girdwood 10575b41027SLiam Girdwood return 0; 10675b41027SLiam Girdwood } 10775b41027SLiam Girdwood 10875b41027SLiam Girdwood static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream, 109dee89c4dSMark Brown struct snd_pcm_hw_params *params, 110f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 11175b41027SLiam Girdwood { 112d65a1458SDaniel Mack struct snd_dmaengine_dai_dma_data *dma_data; 11375b41027SLiam Girdwood 11475b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1155f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_aux_mono_out; 11675b41027SLiam Girdwood else 1175f712b2bSDaniel Mack dma_data = &pxa2xx_ac97_pcm_aux_mono_in; 1185f712b2bSDaniel Mack 1195f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data); 12075b41027SLiam Girdwood 12175b41027SLiam Girdwood return 0; 12275b41027SLiam Girdwood } 12375b41027SLiam Girdwood 12475b41027SLiam Girdwood static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream, 125dee89c4dSMark Brown struct snd_pcm_hw_params *params, 126f0fba2adSLiam Girdwood struct snd_soc_dai *cpu_dai) 12775b41027SLiam Girdwood { 12875b41027SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 12975b41027SLiam Girdwood return -ENODEV; 13075b41027SLiam Girdwood else 1315f712b2bSDaniel Mack snd_soc_dai_set_dma_data(cpu_dai, substream, 1325f712b2bSDaniel Mack &pxa2xx_ac97_pcm_mic_mono_in); 13375b41027SLiam Girdwood 13475b41027SLiam Girdwood return 0; 13575b41027SLiam Girdwood } 13675b41027SLiam Girdwood 137596ce32bSLiam Girdwood #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 138596ce32bSLiam Girdwood SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 139596ce32bSLiam Girdwood SNDRV_PCM_RATE_48000) 140596ce32bSLiam Girdwood 14185e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = { 1426335d055SEric Miao .hw_params = pxa2xx_ac97_hw_params, 1436335d055SEric Miao }; 1446335d055SEric Miao 14585e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = { 146852fd9e5SMark Brown .hw_params = pxa2xx_ac97_hw_aux_params, 147852fd9e5SMark Brown }; 148852fd9e5SMark Brown 14985e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = { 150852fd9e5SMark Brown .hw_params = pxa2xx_ac97_hw_mic_params, 151852fd9e5SMark Brown }; 152852fd9e5SMark Brown 15375b41027SLiam Girdwood /* 15475b41027SLiam Girdwood * There is only 1 physical AC97 interface for pxa2xx, but it 15575b41027SLiam Girdwood * has extra fifo's that can be used for aux DACs and ADCs. 15675b41027SLiam Girdwood */ 157a3874196SAxel Lin static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = { 15875b41027SLiam Girdwood { 15975b41027SLiam Girdwood .name = "pxa2xx-ac97", 160bc263214SLars-Peter Clausen .bus_control = true, 16175b41027SLiam Girdwood .playback = { 16275b41027SLiam Girdwood .stream_name = "AC97 Playback", 16375b41027SLiam Girdwood .channels_min = 2, 164596ce32bSLiam Girdwood .channels_max = 2, 165596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 166596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 16775b41027SLiam Girdwood .capture = { 16875b41027SLiam Girdwood .stream_name = "AC97 Capture", 16975b41027SLiam Girdwood .channels_min = 2, 170596ce32bSLiam Girdwood .channels_max = 2, 171596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 172596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 173852fd9e5SMark Brown .ops = &pxa_ac97_hifi_dai_ops, 17475b41027SLiam Girdwood }, 17575b41027SLiam Girdwood { 17675b41027SLiam Girdwood .name = "pxa2xx-ac97-aux", 177bc263214SLars-Peter Clausen .bus_control = true, 17875b41027SLiam Girdwood .playback = { 17975b41027SLiam Girdwood .stream_name = "AC97 Aux Playback", 18075b41027SLiam Girdwood .channels_min = 1, 181596ce32bSLiam Girdwood .channels_max = 1, 182596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 183596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 18475b41027SLiam Girdwood .capture = { 18575b41027SLiam Girdwood .stream_name = "AC97 Aux Capture", 18675b41027SLiam Girdwood .channels_min = 1, 187596ce32bSLiam Girdwood .channels_max = 1, 188596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 189596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 190852fd9e5SMark Brown .ops = &pxa_ac97_aux_dai_ops, 19175b41027SLiam Girdwood }, 19275b41027SLiam Girdwood { 19375b41027SLiam Girdwood .name = "pxa2xx-ac97-mic", 194bc263214SLars-Peter Clausen .bus_control = true, 19575b41027SLiam Girdwood .capture = { 19675b41027SLiam Girdwood .stream_name = "AC97 Mic Capture", 19775b41027SLiam Girdwood .channels_min = 1, 198596ce32bSLiam Girdwood .channels_max = 1, 199596ce32bSLiam Girdwood .rates = PXA2XX_AC97_RATES, 200596ce32bSLiam Girdwood .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 201852fd9e5SMark Brown .ops = &pxa_ac97_mic_dai_ops, 202596ce32bSLiam Girdwood }, 20375b41027SLiam Girdwood }; 20475b41027SLiam Girdwood 205ad53232cSKuninori Morimoto static const struct snd_soc_component_driver pxa_ac97_component = { 206ad53232cSKuninori Morimoto .name = "pxa-ac97", 207ad53232cSKuninori Morimoto }; 208ad53232cSKuninori Morimoto 209570f6fe1SBill Pemberton static int pxa2xx_ac97_dev_probe(struct platform_device *pdev) 2106b849bcfSMark Brown { 2117685e016SKevin Hilman int ret; 2127685e016SKevin Hilman 213f0fba2adSLiam Girdwood if (pdev->id != -1) { 2144ac0478fSMarek Vasut dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n"); 2154ac0478fSMarek Vasut return -ENXIO; 2164ac0478fSMarek Vasut } 2174ac0478fSMarek Vasut 218f62aa9b6SDmitry Eremin-Solenikov ret = pxa2xx_ac97_hw_probe(pdev); 219f62aa9b6SDmitry Eremin-Solenikov if (ret) { 220f62aa9b6SDmitry Eremin-Solenikov dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret); 221f62aa9b6SDmitry Eremin-Solenikov return ret; 222f62aa9b6SDmitry Eremin-Solenikov } 223f62aa9b6SDmitry Eremin-Solenikov 224b047e1ccSMark Brown ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops); 225b047e1ccSMark Brown if (ret != 0) 226b047e1ccSMark Brown return ret; 227b047e1ccSMark Brown 2286b849bcfSMark Brown /* Punt most of the init to the SoC probe; we may need the machine 2296b849bcfSMark Brown * driver to do interesting things with the clocking to get us up 2306b849bcfSMark Brown * and running. 2316b849bcfSMark Brown */ 232ad53232cSKuninori Morimoto return snd_soc_register_component(&pdev->dev, &pxa_ac97_component, 233ad53232cSKuninori Morimoto pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver)); 2346b849bcfSMark Brown } 2356b849bcfSMark Brown 236570f6fe1SBill Pemberton static int pxa2xx_ac97_dev_remove(struct platform_device *pdev) 2376b849bcfSMark Brown { 238ad53232cSKuninori Morimoto snd_soc_unregister_component(&pdev->dev); 239b047e1ccSMark Brown snd_soc_set_ac97_ops(NULL); 240f62aa9b6SDmitry Eremin-Solenikov pxa2xx_ac97_hw_remove(pdev); 2416b849bcfSMark Brown return 0; 2426b849bcfSMark Brown } 2436b849bcfSMark Brown 244f62aa9b6SDmitry Eremin-Solenikov #ifdef CONFIG_PM_SLEEP 245f62aa9b6SDmitry Eremin-Solenikov static int pxa2xx_ac97_dev_suspend(struct device *dev) 246f62aa9b6SDmitry Eremin-Solenikov { 247f62aa9b6SDmitry Eremin-Solenikov return pxa2xx_ac97_hw_suspend(); 248f62aa9b6SDmitry Eremin-Solenikov } 249f62aa9b6SDmitry Eremin-Solenikov 250f62aa9b6SDmitry Eremin-Solenikov static int pxa2xx_ac97_dev_resume(struct device *dev) 251f62aa9b6SDmitry Eremin-Solenikov { 252f62aa9b6SDmitry Eremin-Solenikov return pxa2xx_ac97_hw_resume(); 253f62aa9b6SDmitry Eremin-Solenikov } 254f62aa9b6SDmitry Eremin-Solenikov 255f62aa9b6SDmitry Eremin-Solenikov static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops, 256f62aa9b6SDmitry Eremin-Solenikov pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume); 257f62aa9b6SDmitry Eremin-Solenikov #endif 258f62aa9b6SDmitry Eremin-Solenikov 2596b849bcfSMark Brown static struct platform_driver pxa2xx_ac97_driver = { 2606b849bcfSMark Brown .probe = pxa2xx_ac97_dev_probe, 261570f6fe1SBill Pemberton .remove = pxa2xx_ac97_dev_remove, 2626b849bcfSMark Brown .driver = { 2636b849bcfSMark Brown .name = "pxa2xx-ac97", 2646b849bcfSMark Brown .owner = THIS_MODULE, 265f62aa9b6SDmitry Eremin-Solenikov #ifdef CONFIG_PM_SLEEP 266f62aa9b6SDmitry Eremin-Solenikov .pm = &pxa2xx_ac97_pm_ops, 267f62aa9b6SDmitry Eremin-Solenikov #endif 2686b849bcfSMark Brown }, 2696b849bcfSMark Brown }; 2706b849bcfSMark Brown 2712f702a19SAxel Lin module_platform_driver(pxa2xx_ac97_driver); 2723f4b783cSMark Brown 27375b41027SLiam Girdwood MODULE_AUTHOR("Nicolas Pitre"); 27475b41027SLiam Girdwood MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 27575b41027SLiam Girdwood MODULE_LICENSE("GPL"); 276