0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/init.h>
0011 #include <linux/io.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/dmaengine.h>
0015 #include <linux/dma/pxa-dma.h>
0016
0017 #include <sound/ac97/controller.h>
0018 #include <sound/core.h>
0019 #include <sound/ac97_codec.h>
0020 #include <sound/soc.h>
0021 #include <sound/pxa2xx-lib.h>
0022 #include <sound/dmaengine_pcm.h>
0023
0024 #include <linux/platform_data/asoc-pxa.h>
0025
0026 #define PCDR 0x0040
0027 #define MODR 0x0140
0028 #define MCDR 0x0060
0029
0030 static void pxa2xx_ac97_warm_reset(struct ac97_controller *adrv)
0031 {
0032 pxa2xx_ac97_try_warm_reset();
0033
0034 pxa2xx_ac97_finish_reset();
0035 }
0036
0037 static void pxa2xx_ac97_cold_reset(struct ac97_controller *adrv)
0038 {
0039 pxa2xx_ac97_try_cold_reset();
0040
0041 pxa2xx_ac97_finish_reset();
0042 }
0043
0044 static int pxa2xx_ac97_read_actrl(struct ac97_controller *adrv, int slot,
0045 unsigned short reg)
0046 {
0047 return pxa2xx_ac97_read(slot, reg);
0048 }
0049
0050 static int pxa2xx_ac97_write_actrl(struct ac97_controller *adrv, int slot,
0051 unsigned short reg, unsigned short val)
0052 {
0053 return pxa2xx_ac97_write(slot, reg, val);
0054 }
0055
0056 static struct ac97_controller_ops pxa2xx_ac97_ops = {
0057 .read = pxa2xx_ac97_read_actrl,
0058 .write = pxa2xx_ac97_write_actrl,
0059 .warm_reset = pxa2xx_ac97_warm_reset,
0060 .reset = pxa2xx_ac97_cold_reset,
0061 };
0062
0063 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
0064 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
0065 .chan_name = "pcm_pcm_stereo_in",
0066 .maxburst = 32,
0067 };
0068
0069 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
0070 .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
0071 .chan_name = "pcm_pcm_stereo_out",
0072 .maxburst = 32,
0073 };
0074
0075 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
0076 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
0077 .chan_name = "pcm_aux_mono_out",
0078 .maxburst = 16,
0079 };
0080
0081 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
0082 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
0083 .chan_name = "pcm_aux_mono_in",
0084 .maxburst = 16,
0085 };
0086
0087 static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
0088 .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
0089 .chan_name = "pcm_aux_mic_mono",
0090 .maxburst = 16,
0091 };
0092
0093 static int pxa2xx_ac97_hifi_startup(struct snd_pcm_substream *substream,
0094 struct snd_soc_dai *cpu_dai)
0095 {
0096 struct snd_dmaengine_dai_dma_data *dma_data;
0097
0098 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
0099 dma_data = &pxa2xx_ac97_pcm_stereo_out;
0100 else
0101 dma_data = &pxa2xx_ac97_pcm_stereo_in;
0102
0103 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
0104
0105 return 0;
0106 }
0107
0108 static int pxa2xx_ac97_aux_startup(struct snd_pcm_substream *substream,
0109 struct snd_soc_dai *cpu_dai)
0110 {
0111 struct snd_dmaengine_dai_dma_data *dma_data;
0112
0113 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
0114 dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
0115 else
0116 dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
0117
0118 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
0119
0120 return 0;
0121 }
0122
0123 static int pxa2xx_ac97_mic_startup(struct snd_pcm_substream *substream,
0124 struct snd_soc_dai *cpu_dai)
0125 {
0126 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
0127 return -ENODEV;
0128 snd_soc_dai_set_dma_data(cpu_dai, substream,
0129 &pxa2xx_ac97_pcm_mic_mono_in);
0130
0131 return 0;
0132 }
0133
0134 #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
0135 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
0136 SNDRV_PCM_RATE_48000)
0137
0138 static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
0139 .startup = pxa2xx_ac97_hifi_startup,
0140 };
0141
0142 static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
0143 .startup = pxa2xx_ac97_aux_startup,
0144 };
0145
0146 static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
0147 .startup = pxa2xx_ac97_mic_startup,
0148 };
0149
0150
0151
0152
0153
0154 static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
0155 {
0156 .name = "pxa2xx-ac97",
0157 .playback = {
0158 .stream_name = "AC97 Playback",
0159 .channels_min = 2,
0160 .channels_max = 2,
0161 .rates = PXA2XX_AC97_RATES,
0162 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
0163 .capture = {
0164 .stream_name = "AC97 Capture",
0165 .channels_min = 2,
0166 .channels_max = 2,
0167 .rates = PXA2XX_AC97_RATES,
0168 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
0169 .ops = &pxa_ac97_hifi_dai_ops,
0170 },
0171 {
0172 .name = "pxa2xx-ac97-aux",
0173 .playback = {
0174 .stream_name = "AC97 Aux Playback",
0175 .channels_min = 1,
0176 .channels_max = 1,
0177 .rates = PXA2XX_AC97_RATES,
0178 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
0179 .capture = {
0180 .stream_name = "AC97 Aux Capture",
0181 .channels_min = 1,
0182 .channels_max = 1,
0183 .rates = PXA2XX_AC97_RATES,
0184 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
0185 .ops = &pxa_ac97_aux_dai_ops,
0186 },
0187 {
0188 .name = "pxa2xx-ac97-mic",
0189 .capture = {
0190 .stream_name = "AC97 Mic Capture",
0191 .channels_min = 1,
0192 .channels_max = 1,
0193 .rates = PXA2XX_AC97_RATES,
0194 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
0195 .ops = &pxa_ac97_mic_dai_ops,
0196 },
0197 };
0198
0199 static const struct snd_soc_component_driver pxa_ac97_component = {
0200 .name = "pxa-ac97",
0201 .pcm_construct = pxa2xx_soc_pcm_new,
0202 .open = pxa2xx_soc_pcm_open,
0203 .close = pxa2xx_soc_pcm_close,
0204 .hw_params = pxa2xx_soc_pcm_hw_params,
0205 .prepare = pxa2xx_soc_pcm_prepare,
0206 .trigger = pxa2xx_soc_pcm_trigger,
0207 .pointer = pxa2xx_soc_pcm_pointer,
0208 };
0209
0210 #ifdef CONFIG_OF
0211 static const struct of_device_id pxa2xx_ac97_dt_ids[] = {
0212 { .compatible = "marvell,pxa250-ac97", },
0213 { .compatible = "marvell,pxa270-ac97", },
0214 { .compatible = "marvell,pxa300-ac97", },
0215 { }
0216 };
0217 MODULE_DEVICE_TABLE(of, pxa2xx_ac97_dt_ids);
0218
0219 #endif
0220
0221 static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
0222 {
0223 int ret;
0224 struct ac97_controller *ctrl;
0225 pxa2xx_audio_ops_t *pdata = pdev->dev.platform_data;
0226 struct resource *regs;
0227 void **codecs_pdata;
0228
0229 if (pdev->id != -1) {
0230 dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
0231 return -ENXIO;
0232 }
0233
0234 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0235 if (!regs)
0236 return -ENXIO;
0237
0238 pxa2xx_ac97_pcm_stereo_in.addr = regs->start + PCDR;
0239 pxa2xx_ac97_pcm_stereo_out.addr = regs->start + PCDR;
0240 pxa2xx_ac97_pcm_aux_mono_out.addr = regs->start + MODR;
0241 pxa2xx_ac97_pcm_aux_mono_in.addr = regs->start + MODR;
0242 pxa2xx_ac97_pcm_mic_mono_in.addr = regs->start + MCDR;
0243
0244 ret = pxa2xx_ac97_hw_probe(pdev);
0245 if (ret) {
0246 dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
0247 return ret;
0248 }
0249
0250 codecs_pdata = pdata ? pdata->codec_pdata : NULL;
0251 ctrl = snd_ac97_controller_register(&pxa2xx_ac97_ops, &pdev->dev,
0252 AC97_SLOTS_AVAILABLE_ALL,
0253 codecs_pdata);
0254 if (IS_ERR(ctrl))
0255 return PTR_ERR(ctrl);
0256
0257 platform_set_drvdata(pdev, ctrl);
0258
0259
0260
0261
0262 return devm_snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
0263 pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
0264 }
0265
0266 static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
0267 {
0268 struct ac97_controller *ctrl = platform_get_drvdata(pdev);
0269
0270 snd_ac97_controller_unregister(ctrl);
0271 pxa2xx_ac97_hw_remove(pdev);
0272 return 0;
0273 }
0274
0275 #ifdef CONFIG_PM_SLEEP
0276 static int pxa2xx_ac97_dev_suspend(struct device *dev)
0277 {
0278 return pxa2xx_ac97_hw_suspend();
0279 }
0280
0281 static int pxa2xx_ac97_dev_resume(struct device *dev)
0282 {
0283 return pxa2xx_ac97_hw_resume();
0284 }
0285
0286 static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
0287 pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
0288 #endif
0289
0290 static struct platform_driver pxa2xx_ac97_driver = {
0291 .probe = pxa2xx_ac97_dev_probe,
0292 .remove = pxa2xx_ac97_dev_remove,
0293 .driver = {
0294 .name = "pxa2xx-ac97",
0295 #ifdef CONFIG_PM_SLEEP
0296 .pm = &pxa2xx_ac97_pm_ops,
0297 #endif
0298 .of_match_table = of_match_ptr(pxa2xx_ac97_dt_ids),
0299 },
0300 };
0301
0302 module_platform_driver(pxa2xx_ac97_driver);
0303
0304 MODULE_AUTHOR("Nicolas Pitre");
0305 MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
0306 MODULE_LICENSE("GPL");
0307 MODULE_ALIAS("platform:pxa2xx-ac97");