1f9b95980Sapatard@mandriva.com /* 2f9b95980Sapatard@mandriva.com * kirkwood-i2s.c 3f9b95980Sapatard@mandriva.com * 4f9b95980Sapatard@mandriva.com * (c) 2010 Arnaud Patard <apatard@mandriva.com> 569737897SArnaud Patard (Rtp) * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> 6f9b95980Sapatard@mandriva.com * 7f9b95980Sapatard@mandriva.com * This program is free software; you can redistribute it and/or modify it 8f9b95980Sapatard@mandriva.com * under the terms of the GNU General Public License as published by the 9f9b95980Sapatard@mandriva.com * Free Software Foundation; either version 2 of the License, or (at your 10f9b95980Sapatard@mandriva.com * option) any later version. 11f9b95980Sapatard@mandriva.com */ 12f9b95980Sapatard@mandriva.com 13f9b95980Sapatard@mandriva.com #include <linux/init.h> 14f9b95980Sapatard@mandriva.com #include <linux/module.h> 15f9b95980Sapatard@mandriva.com #include <linux/platform_device.h> 16f9b95980Sapatard@mandriva.com #include <linux/io.h> 17f9b95980Sapatard@mandriva.com #include <linux/slab.h> 18f9b95980Sapatard@mandriva.com #include <linux/mbus.h> 19f9b95980Sapatard@mandriva.com #include <linux/delay.h> 20f9b95980Sapatard@mandriva.com #include <sound/pcm.h> 21f9b95980Sapatard@mandriva.com #include <sound/pcm_params.h> 22f9b95980Sapatard@mandriva.com #include <sound/soc.h> 23f9b95980Sapatard@mandriva.com #include <plat/audio.h> 24f9b95980Sapatard@mandriva.com #include "kirkwood.h" 25f9b95980Sapatard@mandriva.com 26f9b95980Sapatard@mandriva.com #define DRV_NAME "kirkwood-i2s" 27f9b95980Sapatard@mandriva.com 28f9b95980Sapatard@mandriva.com #define KIRKWOOD_I2S_RATES \ 29f9b95980Sapatard@mandriva.com (SNDRV_PCM_RATE_44100 | \ 30f9b95980Sapatard@mandriva.com SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000) 31f9b95980Sapatard@mandriva.com #define KIRKWOOD_I2S_FORMATS \ 32f9b95980Sapatard@mandriva.com (SNDRV_PCM_FMTBIT_S16_LE | \ 33f9b95980Sapatard@mandriva.com SNDRV_PCM_FMTBIT_S24_LE | \ 34f9b95980Sapatard@mandriva.com SNDRV_PCM_FMTBIT_S32_LE) 35f9b95980Sapatard@mandriva.com 36f9b95980Sapatard@mandriva.com static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai, 37f9b95980Sapatard@mandriva.com unsigned int fmt) 38f9b95980Sapatard@mandriva.com { 39f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai); 40f9b95980Sapatard@mandriva.com unsigned long mask; 41f9b95980Sapatard@mandriva.com unsigned long value; 42f9b95980Sapatard@mandriva.com 43f9b95980Sapatard@mandriva.com switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 44f9b95980Sapatard@mandriva.com case SND_SOC_DAIFMT_RIGHT_J: 45f9b95980Sapatard@mandriva.com mask = KIRKWOOD_I2S_CTL_RJ; 46f9b95980Sapatard@mandriva.com break; 47f9b95980Sapatard@mandriva.com case SND_SOC_DAIFMT_LEFT_J: 48f9b95980Sapatard@mandriva.com mask = KIRKWOOD_I2S_CTL_LJ; 49f9b95980Sapatard@mandriva.com break; 50f9b95980Sapatard@mandriva.com case SND_SOC_DAIFMT_I2S: 51f9b95980Sapatard@mandriva.com mask = KIRKWOOD_I2S_CTL_I2S; 52f9b95980Sapatard@mandriva.com break; 53f9b95980Sapatard@mandriva.com default: 54f9b95980Sapatard@mandriva.com return -EINVAL; 55f9b95980Sapatard@mandriva.com } 56f9b95980Sapatard@mandriva.com 57f9b95980Sapatard@mandriva.com /* 58f9b95980Sapatard@mandriva.com * Set same format for playback and record 59f9b95980Sapatard@mandriva.com * This avoids some troubles. 60f9b95980Sapatard@mandriva.com */ 61f9b95980Sapatard@mandriva.com value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL); 62f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; 63f9b95980Sapatard@mandriva.com value |= mask; 64f9b95980Sapatard@mandriva.com writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL); 65f9b95980Sapatard@mandriva.com 66f9b95980Sapatard@mandriva.com value = readl(priv->io+KIRKWOOD_I2S_RECCTL); 67f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; 68f9b95980Sapatard@mandriva.com value |= mask; 69f9b95980Sapatard@mandriva.com writel(value, priv->io+KIRKWOOD_I2S_RECCTL); 70f9b95980Sapatard@mandriva.com 71f9b95980Sapatard@mandriva.com return 0; 72f9b95980Sapatard@mandriva.com } 73f9b95980Sapatard@mandriva.com 74f9b95980Sapatard@mandriva.com static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate) 75f9b95980Sapatard@mandriva.com { 76f9b95980Sapatard@mandriva.com unsigned long value; 77f9b95980Sapatard@mandriva.com 78f9b95980Sapatard@mandriva.com value = KIRKWOOD_DCO_CTL_OFFSET_0; 79f9b95980Sapatard@mandriva.com switch (rate) { 80f9b95980Sapatard@mandriva.com default: 81f9b95980Sapatard@mandriva.com case 44100: 82f9b95980Sapatard@mandriva.com value |= KIRKWOOD_DCO_CTL_FREQ_11; 83f9b95980Sapatard@mandriva.com break; 84f9b95980Sapatard@mandriva.com case 48000: 85f9b95980Sapatard@mandriva.com value |= KIRKWOOD_DCO_CTL_FREQ_12; 86f9b95980Sapatard@mandriva.com break; 87f9b95980Sapatard@mandriva.com case 96000: 88f9b95980Sapatard@mandriva.com value |= KIRKWOOD_DCO_CTL_FREQ_24; 89f9b95980Sapatard@mandriva.com break; 90f9b95980Sapatard@mandriva.com } 91f9b95980Sapatard@mandriva.com writel(value, io + KIRKWOOD_DCO_CTL); 92f9b95980Sapatard@mandriva.com 93f9b95980Sapatard@mandriva.com /* wait for dco locked */ 94f9b95980Sapatard@mandriva.com do { 95f9b95980Sapatard@mandriva.com cpu_relax(); 96f9b95980Sapatard@mandriva.com value = readl(io + KIRKWOOD_DCO_SPCR_STATUS); 97f9b95980Sapatard@mandriva.com value &= KIRKWOOD_DCO_SPCR_STATUS; 98f9b95980Sapatard@mandriva.com } while (value == 0); 99f9b95980Sapatard@mandriva.com } 100f9b95980Sapatard@mandriva.com 101f0fba2adSLiam Girdwood static int kirkwood_i2s_startup(struct snd_pcm_substream *substream, 102f0fba2adSLiam Girdwood struct snd_soc_dai *dai) 103f0fba2adSLiam Girdwood { 104f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); 105f0fba2adSLiam Girdwood 106f0fba2adSLiam Girdwood snd_soc_dai_set_dma_data(dai, substream, priv); 107f0fba2adSLiam Girdwood return 0; 108f0fba2adSLiam Girdwood } 109f0fba2adSLiam Girdwood 110f9b95980Sapatard@mandriva.com static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream, 111f9b95980Sapatard@mandriva.com struct snd_pcm_hw_params *params, 112f9b95980Sapatard@mandriva.com struct snd_soc_dai *dai) 113f9b95980Sapatard@mandriva.com { 114f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); 115f9b95980Sapatard@mandriva.com unsigned int i2s_reg, reg; 116f9b95980Sapatard@mandriva.com unsigned long i2s_value, value; 117f9b95980Sapatard@mandriva.com 118f9b95980Sapatard@mandriva.com if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 119f9b95980Sapatard@mandriva.com i2s_reg = KIRKWOOD_I2S_PLAYCTL; 120f9b95980Sapatard@mandriva.com reg = KIRKWOOD_PLAYCTL; 121f9b95980Sapatard@mandriva.com } else { 122f9b95980Sapatard@mandriva.com i2s_reg = KIRKWOOD_I2S_RECCTL; 123f9b95980Sapatard@mandriva.com reg = KIRKWOOD_RECCTL; 124f9b95980Sapatard@mandriva.com } 125f9b95980Sapatard@mandriva.com 126f9b95980Sapatard@mandriva.com /* set dco conf */ 127f9b95980Sapatard@mandriva.com kirkwood_set_dco(priv->io, params_rate(params)); 128f9b95980Sapatard@mandriva.com 129f9b95980Sapatard@mandriva.com i2s_value = readl(priv->io+i2s_reg); 130f9b95980Sapatard@mandriva.com i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK; 131f9b95980Sapatard@mandriva.com 132f9b95980Sapatard@mandriva.com value = readl(priv->io+reg); 133f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_PLAYCTL_SIZE_MASK; 134f9b95980Sapatard@mandriva.com 135f9b95980Sapatard@mandriva.com /* 136f9b95980Sapatard@mandriva.com * Size settings in play/rec i2s control regs and play/rec control 137f9b95980Sapatard@mandriva.com * regs must be the same. 138f9b95980Sapatard@mandriva.com */ 139f9b95980Sapatard@mandriva.com switch (params_format(params)) { 140f9b95980Sapatard@mandriva.com case SNDRV_PCM_FORMAT_S16_LE: 141f9b95980Sapatard@mandriva.com i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16; 142f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_SIZE_16_C; 143f9b95980Sapatard@mandriva.com break; 144f9b95980Sapatard@mandriva.com /* 145f9b95980Sapatard@mandriva.com * doesn't work... S20_3LE != kirkwood 20bit format ? 146f9b95980Sapatard@mandriva.com * 147f9b95980Sapatard@mandriva.com case SNDRV_PCM_FORMAT_S20_3LE: 148f9b95980Sapatard@mandriva.com i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20; 149f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_SIZE_20; 150f9b95980Sapatard@mandriva.com break; 151f9b95980Sapatard@mandriva.com */ 152f9b95980Sapatard@mandriva.com case SNDRV_PCM_FORMAT_S24_LE: 153f9b95980Sapatard@mandriva.com i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; 154f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_SIZE_24; 155f9b95980Sapatard@mandriva.com break; 156f9b95980Sapatard@mandriva.com case SNDRV_PCM_FORMAT_S32_LE: 157f9b95980Sapatard@mandriva.com i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; 158f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_SIZE_32; 159f9b95980Sapatard@mandriva.com break; 160f9b95980Sapatard@mandriva.com default: 161f9b95980Sapatard@mandriva.com return -EINVAL; 162f9b95980Sapatard@mandriva.com } 163dfe4c936Sarnaud.patard@rtp-net.org 164dfe4c936Sarnaud.patard@rtp-net.org if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 165dfe4c936Sarnaud.patard@rtp-net.org value &= ~KIRKWOOD_PLAYCTL_MONO_MASK; 166dfe4c936Sarnaud.patard@rtp-net.org if (params_channels(params) == 1) 167dfe4c936Sarnaud.patard@rtp-net.org value |= KIRKWOOD_PLAYCTL_MONO_BOTH; 168dfe4c936Sarnaud.patard@rtp-net.org else 169dfe4c936Sarnaud.patard@rtp-net.org value |= KIRKWOOD_PLAYCTL_MONO_OFF; 170dfe4c936Sarnaud.patard@rtp-net.org } 171dfe4c936Sarnaud.patard@rtp-net.org 172f9b95980Sapatard@mandriva.com writel(i2s_value, priv->io+i2s_reg); 173f9b95980Sapatard@mandriva.com writel(value, priv->io+reg); 174f9b95980Sapatard@mandriva.com 175f9b95980Sapatard@mandriva.com return 0; 176f9b95980Sapatard@mandriva.com } 177f9b95980Sapatard@mandriva.com 178f9b95980Sapatard@mandriva.com static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, 179f9b95980Sapatard@mandriva.com int cmd, struct snd_soc_dai *dai) 180f9b95980Sapatard@mandriva.com { 181f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); 182f9b95980Sapatard@mandriva.com unsigned long value; 183f9b95980Sapatard@mandriva.com 184f9b95980Sapatard@mandriva.com /* 185f9b95980Sapatard@mandriva.com * specs says KIRKWOOD_PLAYCTL must be read 2 times before 186f9b95980Sapatard@mandriva.com * changing it. So read 1 time here and 1 later. 187f9b95980Sapatard@mandriva.com */ 188f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 189f9b95980Sapatard@mandriva.com 190f9b95980Sapatard@mandriva.com switch (cmd) { 191f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_START: 192f9b95980Sapatard@mandriva.com /* stop audio, enable interrupts */ 193f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 194f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_PAUSE; 195f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 196f9b95980Sapatard@mandriva.com 197f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_INT_MASK); 198f9b95980Sapatard@mandriva.com value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; 199f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_INT_MASK); 200f9b95980Sapatard@mandriva.com 201f9b95980Sapatard@mandriva.com /* configure audio & enable i2s playback */ 202f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 203f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_PLAYCTL_BURST_MASK; 204b424ec95Sarnaud.patard@rtp-net.org value &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE 205b424ec95Sarnaud.patard@rtp-net.org | KIRKWOOD_PLAYCTL_SPDIF_EN); 206f9b95980Sapatard@mandriva.com 207f9b95980Sapatard@mandriva.com if (priv->burst == 32) 208f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_BURST_32; 209f9b95980Sapatard@mandriva.com else 210f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_BURST_128; 211f9b95980Sapatard@mandriva.com value |= KIRKWOOD_PLAYCTL_I2S_EN; 212f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 213f9b95980Sapatard@mandriva.com break; 214f9b95980Sapatard@mandriva.com 215f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_STOP: 216f9b95980Sapatard@mandriva.com /* stop audio, disable interrupts */ 217f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 218b424ec95Sarnaud.patard@rtp-net.org value |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; 219f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 220f9b95980Sapatard@mandriva.com 221f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_INT_MASK); 222f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; 223f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_INT_MASK); 224f9b95980Sapatard@mandriva.com 225f9b95980Sapatard@mandriva.com /* disable all playbacks */ 226f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 227f9b95980Sapatard@mandriva.com value &= ~(KIRKWOOD_PLAYCTL_I2S_EN | KIRKWOOD_PLAYCTL_SPDIF_EN); 228f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 229f9b95980Sapatard@mandriva.com break; 230f9b95980Sapatard@mandriva.com 231f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 232f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_SUSPEND: 233f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 234b424ec95Sarnaud.patard@rtp-net.org value |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; 235f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 236f9b95980Sapatard@mandriva.com break; 237f9b95980Sapatard@mandriva.com 238f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_RESUME: 239f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 240f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 241b424ec95Sarnaud.patard@rtp-net.org value &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE); 242f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 243f9b95980Sapatard@mandriva.com break; 244f9b95980Sapatard@mandriva.com 245f9b95980Sapatard@mandriva.com default: 246f9b95980Sapatard@mandriva.com return -EINVAL; 247f9b95980Sapatard@mandriva.com } 248f9b95980Sapatard@mandriva.com 249f9b95980Sapatard@mandriva.com return 0; 250f9b95980Sapatard@mandriva.com } 251f9b95980Sapatard@mandriva.com 252f9b95980Sapatard@mandriva.com static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, 253f9b95980Sapatard@mandriva.com int cmd, struct snd_soc_dai *dai) 254f9b95980Sapatard@mandriva.com { 255f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); 256f9b95980Sapatard@mandriva.com unsigned long value; 257f9b95980Sapatard@mandriva.com 258f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 259f9b95980Sapatard@mandriva.com 260f9b95980Sapatard@mandriva.com switch (cmd) { 261f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_START: 262f9b95980Sapatard@mandriva.com /* stop audio, enable interrupts */ 263f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 264f9b95980Sapatard@mandriva.com value |= KIRKWOOD_RECCTL_PAUSE; 265f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 266f9b95980Sapatard@mandriva.com 267f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_INT_MASK); 268f9b95980Sapatard@mandriva.com value |= KIRKWOOD_INT_CAUSE_REC_BYTES; 269f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_INT_MASK); 270f9b95980Sapatard@mandriva.com 271f9b95980Sapatard@mandriva.com /* configure audio & enable i2s record */ 272f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 273f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_RECCTL_BURST_MASK; 274f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_RECCTL_MONO; 275b424ec95Sarnaud.patard@rtp-net.org value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE 276b424ec95Sarnaud.patard@rtp-net.org | KIRKWOOD_RECCTL_SPDIF_EN); 277f9b95980Sapatard@mandriva.com 278f9b95980Sapatard@mandriva.com if (priv->burst == 32) 279f9b95980Sapatard@mandriva.com value |= KIRKWOOD_RECCTL_BURST_32; 280f9b95980Sapatard@mandriva.com else 281f9b95980Sapatard@mandriva.com value |= KIRKWOOD_RECCTL_BURST_128; 282f9b95980Sapatard@mandriva.com value |= KIRKWOOD_RECCTL_I2S_EN; 283f9b95980Sapatard@mandriva.com 284f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 285f9b95980Sapatard@mandriva.com break; 286f9b95980Sapatard@mandriva.com 287f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_STOP: 288f9b95980Sapatard@mandriva.com /* stop audio, disable interrupts */ 289f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 290b424ec95Sarnaud.patard@rtp-net.org value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; 291f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 292f9b95980Sapatard@mandriva.com 293f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_INT_MASK); 294f9b95980Sapatard@mandriva.com value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; 295f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_INT_MASK); 296f9b95980Sapatard@mandriva.com 297f9b95980Sapatard@mandriva.com /* disable all records */ 298f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 299f9b95980Sapatard@mandriva.com value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); 300f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 301f9b95980Sapatard@mandriva.com break; 302f9b95980Sapatard@mandriva.com 303f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 304f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_SUSPEND: 305f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 306b424ec95Sarnaud.patard@rtp-net.org value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; 307f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 308f9b95980Sapatard@mandriva.com break; 309f9b95980Sapatard@mandriva.com 310f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_RESUME: 311f9b95980Sapatard@mandriva.com case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 312f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 313b424ec95Sarnaud.patard@rtp-net.org value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE); 314f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 315f9b95980Sapatard@mandriva.com break; 316f9b95980Sapatard@mandriva.com 317f9b95980Sapatard@mandriva.com default: 318f9b95980Sapatard@mandriva.com return -EINVAL; 319f9b95980Sapatard@mandriva.com } 320f9b95980Sapatard@mandriva.com 321f9b95980Sapatard@mandriva.com return 0; 322f9b95980Sapatard@mandriva.com } 323f9b95980Sapatard@mandriva.com 324f9b95980Sapatard@mandriva.com static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, 325f9b95980Sapatard@mandriva.com struct snd_soc_dai *dai) 326f9b95980Sapatard@mandriva.com { 327f9b95980Sapatard@mandriva.com if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 328f9b95980Sapatard@mandriva.com return kirkwood_i2s_play_trigger(substream, cmd, dai); 329f9b95980Sapatard@mandriva.com else 330f9b95980Sapatard@mandriva.com return kirkwood_i2s_rec_trigger(substream, cmd, dai); 331f9b95980Sapatard@mandriva.com 332f9b95980Sapatard@mandriva.com return 0; 333f9b95980Sapatard@mandriva.com } 334f9b95980Sapatard@mandriva.com 335f0fba2adSLiam Girdwood static int kirkwood_i2s_probe(struct snd_soc_dai *dai) 336f9b95980Sapatard@mandriva.com { 337f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); 338f9b95980Sapatard@mandriva.com unsigned long value; 339f9b95980Sapatard@mandriva.com unsigned int reg_data; 340f9b95980Sapatard@mandriva.com 341f9b95980Sapatard@mandriva.com /* put system in a "safe" state : */ 342f9b95980Sapatard@mandriva.com /* disable audio interrupts */ 343f9b95980Sapatard@mandriva.com writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); 344f9b95980Sapatard@mandriva.com writel(0, priv->io + KIRKWOOD_INT_MASK); 345f9b95980Sapatard@mandriva.com 346f9b95980Sapatard@mandriva.com reg_data = readl(priv->io + 0x1200); 347f9b95980Sapatard@mandriva.com reg_data &= (~(0x333FF8)); 348f9b95980Sapatard@mandriva.com reg_data |= 0x111D18; 349f9b95980Sapatard@mandriva.com writel(reg_data, priv->io + 0x1200); 350f9b95980Sapatard@mandriva.com 351f9b95980Sapatard@mandriva.com msleep(500); 352f9b95980Sapatard@mandriva.com 353f9b95980Sapatard@mandriva.com reg_data = readl(priv->io + 0x1200); 354f9b95980Sapatard@mandriva.com reg_data &= (~(0x333FF8)); 355f9b95980Sapatard@mandriva.com reg_data |= 0x111D18; 356f9b95980Sapatard@mandriva.com writel(reg_data, priv->io + 0x1200); 357f9b95980Sapatard@mandriva.com 358f9b95980Sapatard@mandriva.com /* disable playback/record */ 359f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_PLAYCTL); 360f9b95980Sapatard@mandriva.com value &= ~(KIRKWOOD_PLAYCTL_I2S_EN|KIRKWOOD_PLAYCTL_SPDIF_EN); 361f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_PLAYCTL); 362f9b95980Sapatard@mandriva.com 363f9b95980Sapatard@mandriva.com value = readl(priv->io + KIRKWOOD_RECCTL); 364f9b95980Sapatard@mandriva.com value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); 365f9b95980Sapatard@mandriva.com writel(value, priv->io + KIRKWOOD_RECCTL); 366f9b95980Sapatard@mandriva.com 367f9b95980Sapatard@mandriva.com return 0; 368f9b95980Sapatard@mandriva.com 369f9b95980Sapatard@mandriva.com } 370f9b95980Sapatard@mandriva.com 371f0fba2adSLiam Girdwood static int kirkwood_i2s_remove(struct snd_soc_dai *dai) 372f9b95980Sapatard@mandriva.com { 373f0fba2adSLiam Girdwood return 0; 374f9b95980Sapatard@mandriva.com } 375f9b95980Sapatard@mandriva.com 376f9b95980Sapatard@mandriva.com static struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { 377f0fba2adSLiam Girdwood .startup = kirkwood_i2s_startup, 378f9b95980Sapatard@mandriva.com .trigger = kirkwood_i2s_trigger, 379f9b95980Sapatard@mandriva.com .hw_params = kirkwood_i2s_hw_params, 380f9b95980Sapatard@mandriva.com .set_fmt = kirkwood_i2s_set_fmt, 381f9b95980Sapatard@mandriva.com }; 382f9b95980Sapatard@mandriva.com 383f9b95980Sapatard@mandriva.com 384f0fba2adSLiam Girdwood static struct snd_soc_dai_driver kirkwood_i2s_dai = { 385f9b95980Sapatard@mandriva.com .probe = kirkwood_i2s_probe, 386f9b95980Sapatard@mandriva.com .remove = kirkwood_i2s_remove, 387f9b95980Sapatard@mandriva.com .playback = { 388f9b95980Sapatard@mandriva.com .channels_min = 1, 389f9b95980Sapatard@mandriva.com .channels_max = 2, 390f9b95980Sapatard@mandriva.com .rates = KIRKWOOD_I2S_RATES, 391f9b95980Sapatard@mandriva.com .formats = KIRKWOOD_I2S_FORMATS,}, 392f9b95980Sapatard@mandriva.com .capture = { 393f9b95980Sapatard@mandriva.com .channels_min = 1, 394f9b95980Sapatard@mandriva.com .channels_max = 2, 395f9b95980Sapatard@mandriva.com .rates = KIRKWOOD_I2S_RATES, 396f9b95980Sapatard@mandriva.com .formats = KIRKWOOD_I2S_FORMATS,}, 397f9b95980Sapatard@mandriva.com .ops = &kirkwood_i2s_dai_ops, 398f9b95980Sapatard@mandriva.com }; 399f9b95980Sapatard@mandriva.com 400f9b95980Sapatard@mandriva.com static __devinit int kirkwood_i2s_dev_probe(struct platform_device *pdev) 401f9b95980Sapatard@mandriva.com { 402f9b95980Sapatard@mandriva.com struct resource *mem; 403f9b95980Sapatard@mandriva.com struct kirkwood_asoc_platform_data *data = 404f9b95980Sapatard@mandriva.com pdev->dev.platform_data; 405f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv; 406f9b95980Sapatard@mandriva.com int err; 407f9b95980Sapatard@mandriva.com 408f9b95980Sapatard@mandriva.com priv = kzalloc(sizeof(struct kirkwood_dma_data), GFP_KERNEL); 409f9b95980Sapatard@mandriva.com if (!priv) { 410f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "allocation failed\n"); 411f9b95980Sapatard@mandriva.com err = -ENOMEM; 412f9b95980Sapatard@mandriva.com goto error; 413f9b95980Sapatard@mandriva.com } 414f0fba2adSLiam Girdwood dev_set_drvdata(&pdev->dev, priv); 415f9b95980Sapatard@mandriva.com 416f9b95980Sapatard@mandriva.com mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 417f9b95980Sapatard@mandriva.com if (!mem) { 418f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "platform_get_resource failed\n"); 419f9b95980Sapatard@mandriva.com err = -ENXIO; 420f9b95980Sapatard@mandriva.com goto err_alloc; 421f9b95980Sapatard@mandriva.com } 422f9b95980Sapatard@mandriva.com 423f9b95980Sapatard@mandriva.com priv->mem = request_mem_region(mem->start, SZ_16K, DRV_NAME); 424f9b95980Sapatard@mandriva.com if (!priv->mem) { 425f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "request_mem_region failed\n"); 426f9b95980Sapatard@mandriva.com err = -EBUSY; 427*5013951bSArnd Bergmann goto err_alloc; 428f9b95980Sapatard@mandriva.com } 429f9b95980Sapatard@mandriva.com 430f9b95980Sapatard@mandriva.com priv->io = ioremap(priv->mem->start, SZ_16K); 431f9b95980Sapatard@mandriva.com if (!priv->io) { 432f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "ioremap failed\n"); 433f9b95980Sapatard@mandriva.com err = -ENOMEM; 434f9b95980Sapatard@mandriva.com goto err_iomem; 435f9b95980Sapatard@mandriva.com } 436f9b95980Sapatard@mandriva.com 437f9b95980Sapatard@mandriva.com priv->irq = platform_get_irq(pdev, 0); 438f9b95980Sapatard@mandriva.com if (priv->irq <= 0) { 439f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "platform_get_irq failed\n"); 440f9b95980Sapatard@mandriva.com err = -ENXIO; 441f9b95980Sapatard@mandriva.com goto err_ioremap; 442f9b95980Sapatard@mandriva.com } 443f9b95980Sapatard@mandriva.com 444f9b95980Sapatard@mandriva.com if (!data || !data->dram) { 445f9b95980Sapatard@mandriva.com dev_err(&pdev->dev, "no platform data ?!\n"); 446f9b95980Sapatard@mandriva.com err = -EINVAL; 447f9b95980Sapatard@mandriva.com goto err_ioremap; 448f9b95980Sapatard@mandriva.com } 449f9b95980Sapatard@mandriva.com 450f9b95980Sapatard@mandriva.com priv->dram = data->dram; 451f9b95980Sapatard@mandriva.com priv->burst = data->burst; 452f9b95980Sapatard@mandriva.com 453f0fba2adSLiam Girdwood return snd_soc_register_dai(&pdev->dev, &kirkwood_i2s_dai); 454f9b95980Sapatard@mandriva.com 455f9b95980Sapatard@mandriva.com err_ioremap: 456f9b95980Sapatard@mandriva.com iounmap(priv->io); 457f9b95980Sapatard@mandriva.com err_iomem: 458f9b95980Sapatard@mandriva.com release_mem_region(priv->mem->start, SZ_16K); 459f9b95980Sapatard@mandriva.com err_alloc: 460f9b95980Sapatard@mandriva.com kfree(priv); 461f9b95980Sapatard@mandriva.com error: 462f9b95980Sapatard@mandriva.com return err; 463f9b95980Sapatard@mandriva.com } 464f9b95980Sapatard@mandriva.com 465f9b95980Sapatard@mandriva.com static __devexit int kirkwood_i2s_dev_remove(struct platform_device *pdev) 466f9b95980Sapatard@mandriva.com { 467f0fba2adSLiam Girdwood struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev); 468f0fba2adSLiam Girdwood 469f0fba2adSLiam Girdwood snd_soc_unregister_dai(&pdev->dev); 470f9b95980Sapatard@mandriva.com iounmap(priv->io); 471f9b95980Sapatard@mandriva.com release_mem_region(priv->mem->start, SZ_16K); 472f9b95980Sapatard@mandriva.com kfree(priv); 473f0fba2adSLiam Girdwood 474f9b95980Sapatard@mandriva.com return 0; 475f9b95980Sapatard@mandriva.com } 476f9b95980Sapatard@mandriva.com 477f9b95980Sapatard@mandriva.com static struct platform_driver kirkwood_i2s_driver = { 478f9b95980Sapatard@mandriva.com .probe = kirkwood_i2s_dev_probe, 479f9b95980Sapatard@mandriva.com .remove = kirkwood_i2s_dev_remove, 480f9b95980Sapatard@mandriva.com .driver = { 481f9b95980Sapatard@mandriva.com .name = DRV_NAME, 482f9b95980Sapatard@mandriva.com .owner = THIS_MODULE, 483f9b95980Sapatard@mandriva.com }, 484f9b95980Sapatard@mandriva.com }; 485f9b95980Sapatard@mandriva.com 486f9b95980Sapatard@mandriva.com static int __init kirkwood_i2s_init(void) 487f9b95980Sapatard@mandriva.com { 488f9b95980Sapatard@mandriva.com return platform_driver_register(&kirkwood_i2s_driver); 489f9b95980Sapatard@mandriva.com } 490f9b95980Sapatard@mandriva.com module_init(kirkwood_i2s_init); 491f9b95980Sapatard@mandriva.com 492f9b95980Sapatard@mandriva.com static void __exit kirkwood_i2s_exit(void) 493f9b95980Sapatard@mandriva.com { 494f9b95980Sapatard@mandriva.com platform_driver_unregister(&kirkwood_i2s_driver); 495f9b95980Sapatard@mandriva.com } 496f9b95980Sapatard@mandriva.com module_exit(kirkwood_i2s_exit); 497f9b95980Sapatard@mandriva.com 498f9b95980Sapatard@mandriva.com /* Module information */ 49969737897SArnaud Patard (Rtp) MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>"); 500f9b95980Sapatard@mandriva.com MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); 501f9b95980Sapatard@mandriva.com MODULE_LICENSE("GPL"); 502f9b95980Sapatard@mandriva.com MODULE_ALIAS("platform:kirkwood-i2s"); 503