apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * kirkwood-i2s.c |
| 3 | * |
| 4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 5 | * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/mbus.h> |
| 19 | #include <linux/delay.h> |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 20 | #include <linux/clk.h> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 21 | #include <sound/pcm.h> |
| 22 | #include <sound/pcm_params.h> |
| 23 | #include <sound/soc.h> |
Arnd Bergmann | c02cecb | 2012-08-24 15:21:54 +0200 | [diff] [blame] | 24 | #include <linux/platform_data/asoc-kirkwood.h> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 25 | #include "kirkwood.h" |
| 26 | |
| 27 | #define DRV_NAME "kirkwood-i2s" |
| 28 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 29 | #define KIRKWOOD_I2S_FORMATS \ |
| 30 | (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 31 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 32 | SNDRV_PCM_FMTBIT_S32_LE) |
| 33 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 34 | static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
| 35 | unsigned int fmt) |
| 36 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 37 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 38 | unsigned long mask; |
| 39 | unsigned long value; |
| 40 | |
| 41 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 42 | case SND_SOC_DAIFMT_RIGHT_J: |
| 43 | mask = KIRKWOOD_I2S_CTL_RJ; |
| 44 | break; |
| 45 | case SND_SOC_DAIFMT_LEFT_J: |
| 46 | mask = KIRKWOOD_I2S_CTL_LJ; |
| 47 | break; |
| 48 | case SND_SOC_DAIFMT_I2S: |
| 49 | mask = KIRKWOOD_I2S_CTL_I2S; |
| 50 | break; |
| 51 | default: |
| 52 | return -EINVAL; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Set same format for playback and record |
| 57 | * This avoids some troubles. |
| 58 | */ |
| 59 | value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL); |
| 60 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; |
| 61 | value |= mask; |
| 62 | writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL); |
| 63 | |
| 64 | value = readl(priv->io+KIRKWOOD_I2S_RECCTL); |
| 65 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; |
| 66 | value |= mask; |
| 67 | writel(value, priv->io+KIRKWOOD_I2S_RECCTL); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate) |
| 73 | { |
| 74 | unsigned long value; |
| 75 | |
| 76 | value = KIRKWOOD_DCO_CTL_OFFSET_0; |
| 77 | switch (rate) { |
| 78 | default: |
| 79 | case 44100: |
| 80 | value |= KIRKWOOD_DCO_CTL_FREQ_11; |
| 81 | break; |
| 82 | case 48000: |
| 83 | value |= KIRKWOOD_DCO_CTL_FREQ_12; |
| 84 | break; |
| 85 | case 96000: |
| 86 | value |= KIRKWOOD_DCO_CTL_FREQ_24; |
| 87 | break; |
| 88 | } |
| 89 | writel(value, io + KIRKWOOD_DCO_CTL); |
| 90 | |
| 91 | /* wait for dco locked */ |
| 92 | do { |
| 93 | cpu_relax(); |
| 94 | value = readl(io + KIRKWOOD_DCO_SPCR_STATUS); |
Russell King | 2424d45 | 2012-11-20 12:18:32 +0000 | [diff] [blame] | 95 | value &= KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 96 | } while (value == 0); |
| 97 | } |
| 98 | |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 99 | static void kirkwood_set_rate(struct snd_soc_dai *dai, |
| 100 | struct kirkwood_dma_data *priv, unsigned long rate) |
| 101 | { |
| 102 | uint32_t clks_ctrl; |
| 103 | |
| 104 | if (rate == 44100 || rate == 48000 || rate == 96000) { |
Jean-Francois Moine | 8a537f8 | 2013-07-16 08:47:47 +0200 | [diff] [blame^] | 105 | /* use internal dco for the supported rates |
| 106 | * defined in kirkwood_i2s_dai */ |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 107 | dev_dbg(dai->dev, "%s: dco set rate = %lu\n", |
| 108 | __func__, rate); |
| 109 | kirkwood_set_dco(priv->io, rate); |
| 110 | |
| 111 | clks_ctrl = KIRKWOOD_MCLK_SOURCE_DCO; |
Jean-Francois Moine | 8a537f8 | 2013-07-16 08:47:47 +0200 | [diff] [blame^] | 112 | } else { |
| 113 | /* use the external clock for the other rates |
| 114 | * defined in kirkwood_i2s_dai_extclk */ |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 115 | dev_dbg(dai->dev, "%s: extclk set rate = %lu -> %lu\n", |
| 116 | __func__, rate, 256 * rate); |
| 117 | clk_set_rate(priv->extclk, 256 * rate); |
| 118 | |
| 119 | clks_ctrl = KIRKWOOD_MCLK_SOURCE_EXTCLK; |
| 120 | } |
| 121 | writel(clks_ctrl, priv->io + KIRKWOOD_CLOCKS_CTRL); |
| 122 | } |
| 123 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 124 | static int kirkwood_i2s_startup(struct snd_pcm_substream *substream, |
| 125 | struct snd_soc_dai *dai) |
| 126 | { |
| 127 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
| 128 | |
| 129 | snd_soc_dai_set_dma_data(dai, substream, priv); |
| 130 | return 0; |
| 131 | } |
| 132 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 133 | static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream, |
| 134 | struct snd_pcm_hw_params *params, |
| 135 | struct snd_soc_dai *dai) |
| 136 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 137 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 138 | uint32_t ctl_play, ctl_rec; |
| 139 | unsigned int i2s_reg; |
| 140 | unsigned long i2s_value; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 141 | |
| 142 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 143 | i2s_reg = KIRKWOOD_I2S_PLAYCTL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 144 | } else { |
| 145 | i2s_reg = KIRKWOOD_I2S_RECCTL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 148 | kirkwood_set_rate(dai, priv, params_rate(params)); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 149 | |
| 150 | i2s_value = readl(priv->io+i2s_reg); |
| 151 | i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK; |
| 152 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 153 | /* |
| 154 | * Size settings in play/rec i2s control regs and play/rec control |
| 155 | * regs must be the same. |
| 156 | */ |
| 157 | switch (params_format(params)) { |
| 158 | case SNDRV_PCM_FORMAT_S16_LE: |
| 159 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 160 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C | |
| 161 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 162 | ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C | |
| 163 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 164 | break; |
| 165 | /* |
| 166 | * doesn't work... S20_3LE != kirkwood 20bit format ? |
| 167 | * |
| 168 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 169 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 170 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 | |
| 171 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 172 | ctl_rec = KIRKWOOD_RECCTL_SIZE_20 | |
| 173 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 174 | break; |
| 175 | */ |
| 176 | case SNDRV_PCM_FORMAT_S24_LE: |
| 177 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 178 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 | |
| 179 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 180 | ctl_rec = KIRKWOOD_RECCTL_SIZE_24 | |
| 181 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 182 | break; |
| 183 | case SNDRV_PCM_FORMAT_S32_LE: |
| 184 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 185 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 | |
| 186 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 187 | ctl_rec = KIRKWOOD_RECCTL_SIZE_32 | |
| 188 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 189 | break; |
| 190 | default: |
| 191 | return -EINVAL; |
| 192 | } |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 193 | |
| 194 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 195 | if (params_channels(params) == 1) |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 196 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH; |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 197 | else |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 198 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF; |
| 199 | |
| 200 | priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK | |
| 201 | KIRKWOOD_PLAYCTL_I2S_EN | |
| 202 | KIRKWOOD_PLAYCTL_SPDIF_EN | |
| 203 | KIRKWOOD_PLAYCTL_SIZE_MASK); |
| 204 | priv->ctl_play |= ctl_play; |
| 205 | } else { |
| 206 | priv->ctl_rec &= ~KIRKWOOD_RECCTL_SIZE_MASK; |
| 207 | priv->ctl_rec |= ctl_rec; |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 208 | } |
| 209 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 210 | writel(i2s_value, priv->io+i2s_reg); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, |
| 216 | int cmd, struct snd_soc_dai *dai) |
| 217 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 218 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 219 | uint32_t ctl, value; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 220 | |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 221 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); |
| 222 | if (ctl & KIRKWOOD_PLAYCTL_PAUSE) { |
| 223 | unsigned timeout = 5000; |
| 224 | /* |
| 225 | * The Armada510 spec says that if we enter pause mode, the |
| 226 | * busy bit must be read back as clear _twice_. Make sure |
| 227 | * we respect that otherwise we get DMA underruns. |
| 228 | */ |
| 229 | do { |
| 230 | value = ctl; |
| 231 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); |
| 232 | if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)) |
| 233 | break; |
| 234 | udelay(1); |
| 235 | } while (timeout--); |
| 236 | |
| 237 | if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY) |
| 238 | dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n", |
| 239 | ctl); |
| 240 | } |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 241 | |
| 242 | switch (cmd) { |
| 243 | case SNDRV_PCM_TRIGGER_START: |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 244 | /* configure */ |
| 245 | ctl = priv->ctl_play; |
| 246 | value = ctl & ~(KIRKWOOD_PLAYCTL_I2S_EN | |
| 247 | KIRKWOOD_PLAYCTL_SPDIF_EN); |
| 248 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
| 249 | |
| 250 | /* enable interrupts */ |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 251 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 252 | value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; |
| 253 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 254 | |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 255 | /* enable playback */ |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 256 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 257 | break; |
| 258 | |
| 259 | case SNDRV_PCM_TRIGGER_STOP: |
| 260 | /* stop audio, disable interrupts */ |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 261 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; |
| 262 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 263 | |
| 264 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 265 | value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; |
| 266 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 267 | |
| 268 | /* disable all playbacks */ |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 269 | ctl &= ~(KIRKWOOD_PLAYCTL_I2S_EN | KIRKWOOD_PLAYCTL_SPDIF_EN); |
| 270 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 271 | break; |
| 272 | |
| 273 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 274 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 275 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE; |
| 276 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | case SNDRV_PCM_TRIGGER_RESUME: |
| 280 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 281 | ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE); |
| 282 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 283 | break; |
| 284 | |
| 285 | default: |
| 286 | return -EINVAL; |
| 287 | } |
| 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, |
| 293 | int cmd, struct snd_soc_dai *dai) |
| 294 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 295 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 296 | uint32_t ctl, value; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 297 | |
| 298 | value = readl(priv->io + KIRKWOOD_RECCTL); |
| 299 | |
| 300 | switch (cmd) { |
| 301 | case SNDRV_PCM_TRIGGER_START: |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 302 | /* configure */ |
| 303 | ctl = priv->ctl_rec; |
| 304 | value = ctl & ~KIRKWOOD_RECCTL_I2S_EN; |
| 305 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 306 | |
| 307 | /* enable interrupts */ |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 308 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 309 | value |= KIRKWOOD_INT_CAUSE_REC_BYTES; |
| 310 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 311 | |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 312 | /* enable record */ |
| 313 | writel(ctl, priv->io + KIRKWOOD_RECCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 314 | break; |
| 315 | |
| 316 | case SNDRV_PCM_TRIGGER_STOP: |
| 317 | /* stop audio, disable interrupts */ |
| 318 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 319 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 320 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 321 | |
| 322 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 323 | value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; |
| 324 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 325 | |
| 326 | /* disable all records */ |
| 327 | value = readl(priv->io + KIRKWOOD_RECCTL); |
| 328 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); |
| 329 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 330 | break; |
| 331 | |
| 332 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 333 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 334 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 335 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 336 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 337 | break; |
| 338 | |
| 339 | case SNDRV_PCM_TRIGGER_RESUME: |
| 340 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 341 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 342 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 343 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 344 | break; |
| 345 | |
| 346 | default: |
| 347 | return -EINVAL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 354 | struct snd_soc_dai *dai) |
| 355 | { |
| 356 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 357 | return kirkwood_i2s_play_trigger(substream, cmd, dai); |
| 358 | else |
| 359 | return kirkwood_i2s_rec_trigger(substream, cmd, dai); |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 364 | static int kirkwood_i2s_probe(struct snd_soc_dai *dai) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 365 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 366 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 367 | unsigned long value; |
| 368 | unsigned int reg_data; |
| 369 | |
| 370 | /* put system in a "safe" state : */ |
| 371 | /* disable audio interrupts */ |
| 372 | writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); |
| 373 | writel(0, priv->io + KIRKWOOD_INT_MASK); |
| 374 | |
| 375 | reg_data = readl(priv->io + 0x1200); |
| 376 | reg_data &= (~(0x333FF8)); |
| 377 | reg_data |= 0x111D18; |
| 378 | writel(reg_data, priv->io + 0x1200); |
| 379 | |
| 380 | msleep(500); |
| 381 | |
| 382 | reg_data = readl(priv->io + 0x1200); |
| 383 | reg_data &= (~(0x333FF8)); |
| 384 | reg_data |= 0x111D18; |
| 385 | writel(reg_data, priv->io + 0x1200); |
| 386 | |
| 387 | /* disable playback/record */ |
| 388 | value = readl(priv->io + KIRKWOOD_PLAYCTL); |
| 389 | value &= ~(KIRKWOOD_PLAYCTL_I2S_EN|KIRKWOOD_PLAYCTL_SPDIF_EN); |
| 390 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
| 391 | |
| 392 | value = readl(priv->io + KIRKWOOD_RECCTL); |
| 393 | value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN); |
| 394 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 395 | |
| 396 | return 0; |
| 397 | |
| 398 | } |
| 399 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 400 | static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 401 | .startup = kirkwood_i2s_startup, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 402 | .trigger = kirkwood_i2s_trigger, |
| 403 | .hw_params = kirkwood_i2s_hw_params, |
| 404 | .set_fmt = kirkwood_i2s_set_fmt, |
| 405 | }; |
| 406 | |
| 407 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 408 | static struct snd_soc_dai_driver kirkwood_i2s_dai = { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 409 | .probe = kirkwood_i2s_probe, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 410 | .playback = { |
| 411 | .channels_min = 1, |
| 412 | .channels_max = 2, |
Mark Brown | 9e12cbd | 2013-07-16 10:47:10 +0100 | [diff] [blame] | 413 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 414 | SNDRV_PCM_RATE_96000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 415 | .formats = KIRKWOOD_I2S_FORMATS, |
| 416 | }, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 417 | .capture = { |
| 418 | .channels_min = 1, |
| 419 | .channels_max = 2, |
Mark Brown | 9e12cbd | 2013-07-16 10:47:10 +0100 | [diff] [blame] | 420 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 421 | SNDRV_PCM_RATE_96000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 422 | .formats = KIRKWOOD_I2S_FORMATS, |
| 423 | }, |
| 424 | .ops = &kirkwood_i2s_dai_ops, |
| 425 | }; |
| 426 | |
| 427 | static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk = { |
| 428 | .probe = kirkwood_i2s_probe, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 429 | .playback = { |
| 430 | .channels_min = 1, |
| 431 | .channels_max = 2, |
| 432 | .rates = SNDRV_PCM_RATE_8000_192000 | |
| 433 | SNDRV_PCM_RATE_CONTINUOUS | |
| 434 | SNDRV_PCM_RATE_KNOT, |
| 435 | .formats = KIRKWOOD_I2S_FORMATS, |
| 436 | }, |
| 437 | .capture = { |
| 438 | .channels_min = 1, |
| 439 | .channels_max = 2, |
| 440 | .rates = SNDRV_PCM_RATE_8000_192000 | |
| 441 | SNDRV_PCM_RATE_CONTINUOUS | |
| 442 | SNDRV_PCM_RATE_KNOT, |
| 443 | .formats = KIRKWOOD_I2S_FORMATS, |
| 444 | }, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 445 | .ops = &kirkwood_i2s_dai_ops, |
| 446 | }; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 447 | |
Kuninori Morimoto | 83d85f5 | 2013-03-21 03:32:39 -0700 | [diff] [blame] | 448 | static const struct snd_soc_component_driver kirkwood_i2s_component = { |
| 449 | .name = DRV_NAME, |
| 450 | }; |
| 451 | |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 452 | static int kirkwood_i2s_dev_probe(struct platform_device *pdev) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 453 | { |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 454 | struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data; |
| 455 | struct snd_soc_dai_driver *soc_dai = &kirkwood_i2s_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 456 | struct kirkwood_dma_data *priv; |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 457 | struct resource *mem; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 458 | int err; |
| 459 | |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 460 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 461 | if (!priv) { |
| 462 | dev_err(&pdev->dev, "allocation failed\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 463 | return -ENOMEM; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 464 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 465 | dev_set_drvdata(&pdev->dev, priv); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 466 | |
| 467 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | b25b5aa | 2013-01-21 11:09:26 +0100 | [diff] [blame] | 468 | priv->io = devm_ioremap_resource(&pdev->dev, mem); |
| 469 | if (IS_ERR(priv->io)) |
| 470 | return PTR_ERR(priv->io); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 471 | |
| 472 | priv->irq = platform_get_irq(pdev, 0); |
| 473 | if (priv->irq <= 0) { |
| 474 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 475 | return -ENXIO; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Axel Lin | d4d9820 | 2011-12-28 16:05:22 +0800 | [diff] [blame] | 478 | if (!data) { |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 479 | dev_err(&pdev->dev, "no platform data ?!\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 480 | return -EINVAL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 481 | } |
| 482 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 483 | priv->burst = data->burst; |
| 484 | |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 485 | priv->clk = devm_clk_get(&pdev->dev, NULL); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 486 | if (IS_ERR(priv->clk)) { |
| 487 | dev_err(&pdev->dev, "no clock\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 488 | return PTR_ERR(priv->clk); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 489 | } |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 490 | |
| 491 | err = clk_prepare_enable(priv->clk); |
| 492 | if (err < 0) |
| 493 | return err; |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 494 | |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 495 | priv->extclk = devm_clk_get(&pdev->dev, "extclk"); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 496 | if (!IS_ERR(priv->extclk)) { |
| 497 | if (priv->extclk == priv->clk) { |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 498 | priv->extclk = ERR_PTR(-EINVAL); |
| 499 | } else { |
| 500 | dev_info(&pdev->dev, "found external clock\n"); |
| 501 | clk_prepare_enable(priv->extclk); |
| 502 | soc_dai = &kirkwood_i2s_dai_extclk; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | /* Some sensible defaults - this reflects the powerup values */ |
| 507 | priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24; |
| 508 | priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24; |
| 509 | |
| 510 | /* Select the burst size */ |
| 511 | if (data->burst == 32) { |
| 512 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32; |
| 513 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32; |
| 514 | } else { |
| 515 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128; |
| 516 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128; |
| 517 | } |
| 518 | |
Kuninori Morimoto | 83d85f5 | 2013-03-21 03:32:39 -0700 | [diff] [blame] | 519 | err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component, |
| 520 | soc_dai, 1); |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 521 | if (!err) |
| 522 | return 0; |
Kuninori Morimoto | 83d85f5 | 2013-03-21 03:32:39 -0700 | [diff] [blame] | 523 | dev_err(&pdev->dev, "snd_soc_register_component failed\n"); |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 524 | |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 525 | if (!IS_ERR(priv->extclk)) |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 526 | clk_disable_unprepare(priv->extclk); |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 527 | clk_disable_unprepare(priv->clk); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 528 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 529 | return err; |
| 530 | } |
| 531 | |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 532 | static int kirkwood_i2s_dev_remove(struct platform_device *pdev) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 533 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 534 | struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev); |
| 535 | |
Kuninori Morimoto | 83d85f5 | 2013-03-21 03:32:39 -0700 | [diff] [blame] | 536 | snd_soc_unregister_component(&pdev->dev); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 537 | |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 538 | if (!IS_ERR(priv->extclk)) |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 539 | clk_disable_unprepare(priv->extclk); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 540 | clk_disable_unprepare(priv->clk); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 541 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static struct platform_driver kirkwood_i2s_driver = { |
| 546 | .probe = kirkwood_i2s_dev_probe, |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 547 | .remove = kirkwood_i2s_dev_remove, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 548 | .driver = { |
| 549 | .name = DRV_NAME, |
| 550 | .owner = THIS_MODULE, |
| 551 | }, |
| 552 | }; |
| 553 | |
Axel Lin | 41b1022 | 2011-11-24 11:43:09 +0800 | [diff] [blame] | 554 | module_platform_driver(kirkwood_i2s_driver); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 555 | |
| 556 | /* Module information */ |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 557 | MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>"); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 558 | MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); |
| 559 | MODULE_LICENSE("GPL"); |
| 560 | MODULE_ALIAS("platform:kirkwood-i2s"); |