Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 2 | /* |
| 3 | * kirkwood-i2s.c |
| 4 | * |
| 5 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 6 | * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/platform_device.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/mbus.h> |
| 15 | #include <linux/delay.h> |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 16 | #include <linux/clk.h> |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 17 | #include <sound/pcm.h> |
| 18 | #include <sound/pcm_params.h> |
| 19 | #include <sound/soc.h> |
Arnd Bergmann | c02cecb | 2012-08-24 15:21:54 +0200 | [diff] [blame] | 20 | #include <linux/platform_data/asoc-kirkwood.h> |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 23 | #include "kirkwood.h" |
| 24 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 25 | #define KIRKWOOD_I2S_FORMATS \ |
| 26 | (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 27 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 28 | SNDRV_PCM_FMTBIT_S32_LE) |
| 29 | |
Jean-Francois Moine | 1c195dd | 2013-11-26 10:41:40 +0100 | [diff] [blame] | 30 | #define KIRKWOOD_SPDIF_FORMATS \ |
| 31 | (SNDRV_PCM_FMTBIT_S16_LE | \ |
| 32 | SNDRV_PCM_FMTBIT_S24_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 | |
Jean-Francois Moine | 1f1b657 | 2013-10-18 20:34:52 +0200 | [diff] [blame] | 104 | if (IS_ERR(priv->extclk)) { |
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 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 161 | KIRKWOOD_PLAYCTL_I2S_EN | |
| 162 | KIRKWOOD_PLAYCTL_SPDIF_EN; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 163 | ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 164 | KIRKWOOD_RECCTL_I2S_EN | |
| 165 | KIRKWOOD_RECCTL_SPDIF_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 166 | break; |
| 167 | /* |
| 168 | * doesn't work... S20_3LE != kirkwood 20bit format ? |
| 169 | * |
| 170 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 171 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 172 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 | |
| 173 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 174 | ctl_rec = KIRKWOOD_RECCTL_SIZE_20 | |
| 175 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 176 | break; |
| 177 | */ |
| 178 | case SNDRV_PCM_FORMAT_S24_LE: |
| 179 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 180 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 181 | KIRKWOOD_PLAYCTL_I2S_EN | |
| 182 | KIRKWOOD_PLAYCTL_SPDIF_EN; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 183 | ctl_rec = KIRKWOOD_RECCTL_SIZE_24 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 184 | KIRKWOOD_RECCTL_I2S_EN | |
| 185 | KIRKWOOD_RECCTL_SPDIF_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 186 | break; |
| 187 | case SNDRV_PCM_FORMAT_S32_LE: |
| 188 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 189 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 | |
| 190 | KIRKWOOD_PLAYCTL_I2S_EN; |
| 191 | ctl_rec = KIRKWOOD_RECCTL_SIZE_32 | |
| 192 | KIRKWOOD_RECCTL_I2S_EN; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 193 | break; |
| 194 | default: |
| 195 | return -EINVAL; |
| 196 | } |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 197 | |
| 198 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 199 | if (params_channels(params) == 1) |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 200 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH; |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 201 | else |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 202 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF; |
| 203 | |
| 204 | priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK | |
Russell King | db43b16 | 2013-08-04 20:26:03 +0100 | [diff] [blame] | 205 | KIRKWOOD_PLAYCTL_ENABLE_MASK | |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 206 | KIRKWOOD_PLAYCTL_SIZE_MASK); |
| 207 | priv->ctl_play |= ctl_play; |
| 208 | } else { |
Russell King | 6772190 | 2014-06-26 15:23:00 +0100 | [diff] [blame] | 209 | priv->ctl_rec &= ~(KIRKWOOD_RECCTL_ENABLE_MASK | |
| 210 | KIRKWOOD_RECCTL_SIZE_MASK); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 211 | priv->ctl_rec |= ctl_rec; |
arnaud.patard@rtp-net.org | dfe4c93 | 2010-07-11 23:28:31 +0200 | [diff] [blame] | 212 | } |
| 213 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 214 | writel(i2s_value, priv->io+i2s_reg); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Russell King | 2fbc382 | 2014-06-26 15:23:05 +0100 | [diff] [blame] | 219 | static unsigned kirkwood_i2s_play_mute(unsigned ctl) |
| 220 | { |
| 221 | if (!(ctl & KIRKWOOD_PLAYCTL_I2S_EN)) |
| 222 | ctl |= KIRKWOOD_PLAYCTL_I2S_MUTE; |
| 223 | if (!(ctl & KIRKWOOD_PLAYCTL_SPDIF_EN)) |
| 224 | ctl |= KIRKWOOD_PLAYCTL_SPDIF_MUTE; |
| 225 | return ctl; |
| 226 | } |
| 227 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 228 | static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, |
| 229 | int cmd, struct snd_soc_dai *dai) |
| 230 | { |
Russell King | 920ec4e | 2014-06-26 15:23:20 +0100 | [diff] [blame] | 231 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 232 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 233 | uint32_t ctl, value; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 234 | |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 235 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); |
Russell King | 4d2097e | 2014-06-26 15:23:10 +0100 | [diff] [blame] | 236 | if ((ctl & KIRKWOOD_PLAYCTL_ENABLE_MASK) == 0) { |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 237 | unsigned timeout = 5000; |
| 238 | /* |
| 239 | * The Armada510 spec says that if we enter pause mode, the |
| 240 | * busy bit must be read back as clear _twice_. Make sure |
| 241 | * we respect that otherwise we get DMA underruns. |
| 242 | */ |
| 243 | do { |
| 244 | value = ctl; |
| 245 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); |
| 246 | if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)) |
| 247 | break; |
| 248 | udelay(1); |
| 249 | } while (timeout--); |
| 250 | |
| 251 | if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY) |
| 252 | dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n", |
| 253 | ctl); |
| 254 | } |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 255 | |
| 256 | switch (cmd) { |
| 257 | case SNDRV_PCM_TRIGGER_START: |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 258 | /* configure */ |
| 259 | ctl = priv->ctl_play; |
Jean-Francois Moine | 4f6f147 | 2013-11-25 20:19:05 +0100 | [diff] [blame] | 260 | if (dai->id == 0) |
| 261 | ctl &= ~KIRKWOOD_PLAYCTL_SPDIF_EN; /* i2s */ |
| 262 | else |
| 263 | ctl &= ~KIRKWOOD_PLAYCTL_I2S_EN; /* spdif */ |
Russell King | 2fbc382 | 2014-06-26 15:23:05 +0100 | [diff] [blame] | 264 | ctl = kirkwood_i2s_play_mute(ctl); |
Russell King | db43b16 | 2013-08-04 20:26:03 +0100 | [diff] [blame] | 265 | value = ctl & ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 266 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
| 267 | |
| 268 | /* enable interrupts */ |
Russell King | 920ec4e | 2014-06-26 15:23:20 +0100 | [diff] [blame] | 269 | if (!runtime->no_period_wakeup) { |
| 270 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 271 | value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; |
| 272 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 273 | } |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 274 | |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 275 | /* enable playback */ |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 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_STOP: |
| 280 | /* stop audio, disable interrupts */ |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 281 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
| 282 | KIRKWOOD_PLAYCTL_SPDIF_MUTE; |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 283 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 284 | |
| 285 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 286 | value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; |
| 287 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 288 | |
| 289 | /* disable all playbacks */ |
Russell King | db43b16 | 2013-08-04 20:26:03 +0100 | [diff] [blame] | 290 | ctl &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 291 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 292 | break; |
| 293 | |
| 294 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 295 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 296 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
| 297 | KIRKWOOD_PLAYCTL_SPDIF_MUTE; |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 298 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 299 | break; |
| 300 | |
| 301 | case SNDRV_PCM_TRIGGER_RESUME: |
| 302 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 303 | ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
| 304 | KIRKWOOD_PLAYCTL_SPDIF_MUTE); |
Russell King | 2fbc382 | 2014-06-26 15:23:05 +0100 | [diff] [blame] | 305 | ctl = kirkwood_i2s_play_mute(ctl); |
Russell King | 982b604 | 2012-11-20 12:18:52 +0000 | [diff] [blame] | 306 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 307 | break; |
| 308 | |
| 309 | default: |
| 310 | return -EINVAL; |
| 311 | } |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, |
| 317 | int cmd, struct snd_soc_dai *dai) |
| 318 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 319 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 320 | uint32_t ctl, value; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 321 | |
| 322 | value = readl(priv->io + KIRKWOOD_RECCTL); |
| 323 | |
| 324 | switch (cmd) { |
| 325 | case SNDRV_PCM_TRIGGER_START: |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 326 | /* configure */ |
| 327 | ctl = priv->ctl_rec; |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 328 | if (dai->id == 0) |
| 329 | ctl &= ~KIRKWOOD_RECCTL_SPDIF_EN; /* i2s */ |
| 330 | else |
| 331 | ctl &= ~KIRKWOOD_RECCTL_I2S_EN; /* spdif */ |
| 332 | |
Russell King | 52b896c | 2014-06-26 15:22:55 +0100 | [diff] [blame] | 333 | value = ctl & ~KIRKWOOD_RECCTL_ENABLE_MASK; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 334 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 335 | |
| 336 | /* enable interrupts */ |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 337 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 338 | value |= KIRKWOOD_INT_CAUSE_REC_BYTES; |
| 339 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 340 | |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 341 | /* enable record */ |
| 342 | writel(ctl, priv->io + KIRKWOOD_RECCTL); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 343 | break; |
| 344 | |
| 345 | case SNDRV_PCM_TRIGGER_STOP: |
| 346 | /* stop audio, disable interrupts */ |
| 347 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 348 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 349 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 350 | |
| 351 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
| 352 | value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; |
| 353 | writel(value, priv->io + KIRKWOOD_INT_MASK); |
| 354 | |
| 355 | /* disable all records */ |
| 356 | value = readl(priv->io + KIRKWOOD_RECCTL); |
Russell King | 52b896c | 2014-06-26 15:22:55 +0100 | [diff] [blame] | 357 | value &= ~KIRKWOOD_RECCTL_ENABLE_MASK; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 358 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 359 | break; |
| 360 | |
| 361 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 362 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 363 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 364 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 365 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 366 | break; |
| 367 | |
| 368 | case SNDRV_PCM_TRIGGER_RESUME: |
| 369 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 370 | value = readl(priv->io + KIRKWOOD_RECCTL); |
arnaud.patard@rtp-net.org | b424ec9 | 2010-07-11 23:28:32 +0200 | [diff] [blame] | 371 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 372 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 373 | break; |
| 374 | |
| 375 | default: |
| 376 | return -EINVAL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
| 382 | static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 383 | struct snd_soc_dai *dai) |
| 384 | { |
| 385 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 386 | return kirkwood_i2s_play_trigger(substream, cmd, dai); |
| 387 | else |
| 388 | return kirkwood_i2s_rec_trigger(substream, cmd, dai); |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 393 | static int kirkwood_i2s_init(struct kirkwood_dma_data *priv) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 394 | { |
| 395 | unsigned long value; |
| 396 | unsigned int reg_data; |
| 397 | |
| 398 | /* put system in a "safe" state : */ |
| 399 | /* disable audio interrupts */ |
| 400 | writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); |
| 401 | writel(0, priv->io + KIRKWOOD_INT_MASK); |
| 402 | |
| 403 | reg_data = readl(priv->io + 0x1200); |
| 404 | reg_data &= (~(0x333FF8)); |
| 405 | reg_data |= 0x111D18; |
| 406 | writel(reg_data, priv->io + 0x1200); |
| 407 | |
| 408 | msleep(500); |
| 409 | |
| 410 | reg_data = readl(priv->io + 0x1200); |
| 411 | reg_data &= (~(0x333FF8)); |
| 412 | reg_data |= 0x111D18; |
| 413 | writel(reg_data, priv->io + 0x1200); |
| 414 | |
| 415 | /* disable playback/record */ |
| 416 | value = readl(priv->io + KIRKWOOD_PLAYCTL); |
Russell King | db43b16 | 2013-08-04 20:26:03 +0100 | [diff] [blame] | 417 | value &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 418 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
| 419 | |
| 420 | value = readl(priv->io + KIRKWOOD_RECCTL); |
Russell King | 52b896c | 2014-06-26 15:22:55 +0100 | [diff] [blame] | 421 | value &= ~KIRKWOOD_RECCTL_ENABLE_MASK; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 422 | writel(value, priv->io + KIRKWOOD_RECCTL); |
| 423 | |
| 424 | return 0; |
| 425 | |
| 426 | } |
| 427 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 428 | static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 429 | .startup = kirkwood_i2s_startup, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 430 | .trigger = kirkwood_i2s_trigger, |
| 431 | .hw_params = kirkwood_i2s_hw_params, |
| 432 | .set_fmt = kirkwood_i2s_set_fmt, |
| 433 | }; |
| 434 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 435 | static struct snd_soc_dai_driver kirkwood_i2s_dai[2] = { |
| 436 | { |
| 437 | .name = "i2s", |
| 438 | .id = 0, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 439 | .playback = { |
| 440 | .channels_min = 1, |
| 441 | .channels_max = 2, |
Mark Brown | 9e12cbd | 2013-07-16 10:47:10 +0100 | [diff] [blame] | 442 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 443 | SNDRV_PCM_RATE_96000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 444 | .formats = KIRKWOOD_I2S_FORMATS, |
| 445 | }, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 446 | .capture = { |
| 447 | .channels_min = 1, |
| 448 | .channels_max = 2, |
Mark Brown | 9e12cbd | 2013-07-16 10:47:10 +0100 | [diff] [blame] | 449 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 450 | SNDRV_PCM_RATE_96000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 451 | .formats = KIRKWOOD_I2S_FORMATS, |
| 452 | }, |
| 453 | .ops = &kirkwood_i2s_dai_ops, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 454 | }, |
| 455 | { |
| 456 | .name = "spdif", |
| 457 | .id = 1, |
| 458 | .playback = { |
| 459 | .channels_min = 1, |
| 460 | .channels_max = 2, |
| 461 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 462 | SNDRV_PCM_RATE_96000, |
Jean-Francois Moine | 1c195dd | 2013-11-26 10:41:40 +0100 | [diff] [blame] | 463 | .formats = KIRKWOOD_SPDIF_FORMATS, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 464 | }, |
| 465 | .capture = { |
| 466 | .channels_min = 1, |
| 467 | .channels_max = 2, |
| 468 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 469 | SNDRV_PCM_RATE_96000, |
Jean-Francois Moine | 1c195dd | 2013-11-26 10:41:40 +0100 | [diff] [blame] | 470 | .formats = KIRKWOOD_SPDIF_FORMATS, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 471 | }, |
| 472 | .ops = &kirkwood_i2s_dai_ops, |
| 473 | }, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 476 | static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk[2] = { |
| 477 | { |
| 478 | .name = "i2s", |
| 479 | .id = 0, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 480 | .playback = { |
| 481 | .channels_min = 1, |
| 482 | .channels_max = 2, |
Jean-Francois Moine | 02fc17c | 2013-11-27 21:10:24 +0100 | [diff] [blame] | 483 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 484 | .rate_min = 5512, |
| 485 | .rate_max = 192000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 486 | .formats = KIRKWOOD_I2S_FORMATS, |
| 487 | }, |
| 488 | .capture = { |
| 489 | .channels_min = 1, |
| 490 | .channels_max = 2, |
Jean-Francois Moine | 02fc17c | 2013-11-27 21:10:24 +0100 | [diff] [blame] | 491 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 492 | .rate_min = 5512, |
| 493 | .rate_max = 192000, |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 494 | .formats = KIRKWOOD_I2S_FORMATS, |
| 495 | }, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 496 | .ops = &kirkwood_i2s_dai_ops, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 497 | }, |
| 498 | { |
| 499 | .name = "spdif", |
| 500 | .id = 1, |
| 501 | .playback = { |
| 502 | .channels_min = 1, |
| 503 | .channels_max = 2, |
Jean-Francois Moine | 02fc17c | 2013-11-27 21:10:24 +0100 | [diff] [blame] | 504 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 505 | .rate_min = 5512, |
| 506 | .rate_max = 192000, |
Jean-Francois Moine | 1c195dd | 2013-11-26 10:41:40 +0100 | [diff] [blame] | 507 | .formats = KIRKWOOD_SPDIF_FORMATS, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 508 | }, |
| 509 | .capture = { |
| 510 | .channels_min = 1, |
| 511 | .channels_max = 2, |
Jean-Francois Moine | 02fc17c | 2013-11-27 21:10:24 +0100 | [diff] [blame] | 512 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
| 513 | .rate_min = 5512, |
| 514 | .rate_max = 192000, |
Jean-Francois Moine | 1c195dd | 2013-11-26 10:41:40 +0100 | [diff] [blame] | 515 | .formats = KIRKWOOD_SPDIF_FORMATS, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 516 | }, |
| 517 | .ops = &kirkwood_i2s_dai_ops, |
| 518 | }, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 519 | }; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 520 | |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 521 | static int kirkwood_i2s_dev_probe(struct platform_device *pdev) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 522 | { |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 523 | struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data; |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 524 | struct snd_soc_dai_driver *soc_dai = kirkwood_i2s_dai; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 525 | struct kirkwood_dma_data *priv; |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 526 | struct resource *mem; |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 527 | struct device_node *np = pdev->dev.of_node; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 528 | int err; |
| 529 | |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 530 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
Markus Elfring | c7591ed | 2017-08-11 09:35:33 +0200 | [diff] [blame] | 531 | if (!priv) |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 532 | return -ENOMEM; |
Markus Elfring | c7591ed | 2017-08-11 09:35:33 +0200 | [diff] [blame] | 533 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 534 | dev_set_drvdata(&pdev->dev, priv); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 535 | |
| 536 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | b25b5aa | 2013-01-21 11:09:26 +0100 | [diff] [blame] | 537 | priv->io = devm_ioremap_resource(&pdev->dev, mem); |
| 538 | if (IS_ERR(priv->io)) |
| 539 | return PTR_ERR(priv->io); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 540 | |
| 541 | priv->irq = platform_get_irq(pdev, 0); |
Gustavo A. R. Silva | e7b2e30 | 2017-06-30 16:46:33 -0500 | [diff] [blame] | 542 | if (priv->irq < 0) { |
| 543 | dev_err(&pdev->dev, "platform_get_irq failed: %d\n", priv->irq); |
| 544 | return priv->irq; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 545 | } |
| 546 | |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 547 | if (np) { |
| 548 | priv->burst = 128; /* might be 32 or 128 */ |
| 549 | } else if (data) { |
| 550 | priv->burst = data->burst; |
| 551 | } else { |
| 552 | dev_err(&pdev->dev, "no DT nor platform data ?!\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 553 | return -EINVAL; |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 554 | } |
| 555 | |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 556 | priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 557 | if (IS_ERR(priv->clk)) { |
| 558 | dev_err(&pdev->dev, "no clock\n"); |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 559 | return PTR_ERR(priv->clk); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 560 | } |
Russell King | dbc517b | 2012-11-20 12:19:33 +0000 | [diff] [blame] | 561 | |
| 562 | err = clk_prepare_enable(priv->clk); |
| 563 | if (err < 0) |
| 564 | return err; |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 565 | |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 566 | priv->extclk = devm_clk_get(&pdev->dev, "extclk"); |
Jean-Francois Moine | 84aac6c | 2013-09-21 12:00:36 +0200 | [diff] [blame] | 567 | if (IS_ERR(priv->extclk)) { |
| 568 | if (PTR_ERR(priv->extclk) == -EPROBE_DEFER) |
| 569 | return -EPROBE_DEFER; |
| 570 | } else { |
Shawn Guo | aaa6d06 | 2015-02-25 22:53:38 +0800 | [diff] [blame] | 571 | if (clk_is_match(priv->extclk, priv->clk)) { |
Russell King | af64d73 | 2013-08-04 20:23:03 +0100 | [diff] [blame] | 572 | devm_clk_put(&pdev->dev, priv->extclk); |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 573 | priv->extclk = ERR_PTR(-EINVAL); |
| 574 | } else { |
| 575 | dev_info(&pdev->dev, "found external clock\n"); |
| 576 | clk_prepare_enable(priv->extclk); |
Jean-Francois Moine | 99d8d3b | 2013-10-24 17:55:18 +0200 | [diff] [blame] | 577 | soc_dai = kirkwood_i2s_dai_extclk; |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
| 581 | /* Some sensible defaults - this reflects the powerup values */ |
| 582 | priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24; |
| 583 | priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24; |
| 584 | |
| 585 | /* Select the burst size */ |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 586 | if (priv->burst == 32) { |
Russell King | d8d11ba | 2012-11-20 12:19:53 +0000 | [diff] [blame] | 587 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32; |
| 588 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32; |
| 589 | } else { |
| 590 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128; |
| 591 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128; |
| 592 | } |
| 593 | |
Kuninori Morimoto | f98fc0f | 2018-01-29 02:48:03 +0000 | [diff] [blame] | 594 | err = devm_snd_soc_register_component(&pdev->dev, &kirkwood_soc_component, |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 595 | soc_dai, 2); |
Russell King | 64ddf1f | 2013-08-04 20:27:03 +0100 | [diff] [blame] | 596 | if (err) { |
| 597 | dev_err(&pdev->dev, "snd_soc_register_component failed\n"); |
| 598 | goto err_component; |
| 599 | } |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 600 | |
Jean-Francois Moine | 75b9b65 | 2013-10-21 10:50:49 +0200 | [diff] [blame] | 601 | kirkwood_i2s_init(priv); |
| 602 | |
Russell King | 64ddf1f | 2013-08-04 20:27:03 +0100 | [diff] [blame] | 603 | return 0; |
Kuninori Morimoto | f98fc0f | 2018-01-29 02:48:03 +0000 | [diff] [blame] | 604 | |
Russell King | 64ddf1f | 2013-08-04 20:27:03 +0100 | [diff] [blame] | 605 | err_component: |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 606 | if (!IS_ERR(priv->extclk)) |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 607 | clk_disable_unprepare(priv->extclk); |
Simon Baatz | baffab2 | 2012-07-19 00:04:09 +0200 | [diff] [blame] | 608 | clk_disable_unprepare(priv->clk); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 609 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 610 | return err; |
| 611 | } |
| 612 | |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 613 | static int kirkwood_i2s_dev_remove(struct platform_device *pdev) |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 614 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 615 | struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev); |
| 616 | |
Mark Brown | 4734dc9 | 2013-07-15 16:41:14 +0100 | [diff] [blame] | 617 | if (!IS_ERR(priv->extclk)) |
Russell King | 363589b | 2012-11-20 12:20:34 +0000 | [diff] [blame] | 618 | clk_disable_unprepare(priv->extclk); |
Andrew Lunn | e919c71 | 2012-03-09 09:56:41 +0100 | [diff] [blame] | 619 | clk_disable_unprepare(priv->clk); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 620 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 621 | return 0; |
| 622 | } |
| 623 | |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 624 | #ifdef CONFIG_OF |
Fabian Frederick | 7f2c52a | 2015-03-18 17:48:58 +0100 | [diff] [blame] | 625 | static const struct of_device_id mvebu_audio_of_match[] = { |
Thomas Petazzoni | d098b2f | 2013-09-05 14:56:31 +0200 | [diff] [blame] | 626 | { .compatible = "marvell,kirkwood-audio" }, |
| 627 | { .compatible = "marvell,dove-audio" }, |
Thomas Petazzoni | 9a0d511 | 2014-01-30 18:14:06 +0100 | [diff] [blame] | 628 | { .compatible = "marvell,armada370-audio" }, |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 629 | { } |
| 630 | }; |
| 631 | MODULE_DEVICE_TABLE(of, mvebu_audio_of_match); |
| 632 | #endif |
| 633 | |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 634 | static struct platform_driver kirkwood_i2s_driver = { |
| 635 | .probe = kirkwood_i2s_dev_probe, |
Bill Pemberton | 34e15fb | 2012-12-07 09:26:26 -0500 | [diff] [blame] | 636 | .remove = kirkwood_i2s_dev_remove, |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 637 | .driver = { |
| 638 | .name = DRV_NAME, |
Jean-Francois Moine | eb63231 | 2013-08-14 12:27:33 +0200 | [diff] [blame] | 639 | .of_match_table = of_match_ptr(mvebu_audio_of_match), |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 640 | }, |
| 641 | }; |
| 642 | |
Axel Lin | 41b1022 | 2011-11-24 11:43:09 +0800 | [diff] [blame] | 643 | module_platform_driver(kirkwood_i2s_driver); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 644 | |
| 645 | /* Module information */ |
Arnaud Patard (Rtp) | 6973789 | 2010-09-09 14:10:33 +0200 | [diff] [blame] | 646 | MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>"); |
apatard@mandriva.com | f9b9598 | 2010-05-31 13:49:14 +0200 | [diff] [blame] | 647 | MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); |
| 648 | MODULE_LICENSE("GPL"); |
Russell King | 64ddf1f | 2013-08-04 20:27:03 +0100 | [diff] [blame] | 649 | MODULE_ALIAS("platform:mvebu-audio"); |