Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Au12x0/Au1550 PSC ALSA ASoC audio support. |
| 4 | * |
| 5 | * (c) 2007-2008 MSC Vertriebsges.m.b.H., |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 6 | * Manuel Lauss <manuel.lauss@gmail.com> |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 7 | * |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 8 | * Au1xxx-PSC I2S glue. |
| 9 | * |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 10 | * NOTE: so far only PSC slave mode (bit- and frameclock) is supported. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 16 | #include <linux/suspend.h> |
| 17 | #include <sound/core.h> |
| 18 | #include <sound/pcm.h> |
| 19 | #include <sound/initval.h> |
| 20 | #include <sound/soc.h> |
| 21 | #include <asm/mach-au1x00/au1000.h> |
| 22 | #include <asm/mach-au1x00/au1xxx_psc.h> |
| 23 | |
| 24 | #include "psc.h" |
| 25 | |
| 26 | /* supported I2S DAI hardware formats */ |
| 27 | #define AU1XPSC_I2S_DAIFMT \ |
| 28 | (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J | \ |
| 29 | SND_SOC_DAIFMT_NB_NF) |
| 30 | |
| 31 | /* supported I2S direction */ |
| 32 | #define AU1XPSC_I2S_DIR \ |
| 33 | (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE) |
| 34 | |
| 35 | #define AU1XPSC_I2S_RATES \ |
| 36 | SNDRV_PCM_RATE_8000_192000 |
| 37 | |
| 38 | #define AU1XPSC_I2S_FMTS \ |
| 39 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE) |
| 40 | |
| 41 | #define I2SSTAT_BUSY(stype) \ |
Manuel Lauss | 25942fd | 2011-07-25 13:45:04 +0200 | [diff] [blame] | 42 | ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SSTAT_TB : PSC_I2SSTAT_RB) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 43 | #define I2SPCR_START(stype) \ |
Manuel Lauss | 25942fd | 2011-07-25 13:45:04 +0200 | [diff] [blame] | 44 | ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TS : PSC_I2SPCR_RS) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 45 | #define I2SPCR_STOP(stype) \ |
Manuel Lauss | 25942fd | 2011-07-25 13:45:04 +0200 | [diff] [blame] | 46 | ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TP : PSC_I2SPCR_RP) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 47 | #define I2SPCR_CLRFIFO(stype) \ |
Manuel Lauss | 25942fd | 2011-07-25 13:45:04 +0200 | [diff] [blame] | 48 | ((stype) == SNDRV_PCM_STREAM_PLAYBACK ? PSC_I2SPCR_TC : PSC_I2SPCR_RC) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 49 | |
| 50 | |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 51 | static int au1xpsc_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
| 52 | unsigned int fmt) |
| 53 | { |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 54 | struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(cpu_dai); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 55 | unsigned long ct; |
| 56 | int ret; |
| 57 | |
| 58 | ret = -EINVAL; |
| 59 | |
| 60 | ct = pscdata->cfg; |
| 61 | |
| 62 | ct &= ~(PSC_I2SCFG_XM | PSC_I2SCFG_MLJ); /* left-justified */ |
| 63 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 64 | case SND_SOC_DAIFMT_I2S: |
| 65 | ct |= PSC_I2SCFG_XM; /* enable I2S mode */ |
| 66 | break; |
| 67 | case SND_SOC_DAIFMT_MSB: |
| 68 | break; |
| 69 | case SND_SOC_DAIFMT_LSB: |
| 70 | ct |= PSC_I2SCFG_MLJ; /* LSB (right-) justified */ |
| 71 | break; |
| 72 | default: |
| 73 | goto out; |
| 74 | } |
| 75 | |
| 76 | ct &= ~(PSC_I2SCFG_BI | PSC_I2SCFG_WI); /* IB-IF */ |
| 77 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 78 | case SND_SOC_DAIFMT_NB_NF: |
| 79 | ct |= PSC_I2SCFG_BI | PSC_I2SCFG_WI; |
| 80 | break; |
| 81 | case SND_SOC_DAIFMT_NB_IF: |
| 82 | ct |= PSC_I2SCFG_BI; |
| 83 | break; |
| 84 | case SND_SOC_DAIFMT_IB_NF: |
| 85 | ct |= PSC_I2SCFG_WI; |
| 86 | break; |
| 87 | case SND_SOC_DAIFMT_IB_IF: |
| 88 | break; |
| 89 | default: |
| 90 | goto out; |
| 91 | } |
| 92 | |
| 93 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 94 | case SND_SOC_DAIFMT_CBM_CFM: /* CODEC master */ |
| 95 | ct |= PSC_I2SCFG_MS; /* PSC I2S slave mode */ |
| 96 | break; |
| 97 | case SND_SOC_DAIFMT_CBS_CFS: /* CODEC slave */ |
| 98 | ct &= ~PSC_I2SCFG_MS; /* PSC I2S Master mode */ |
| 99 | break; |
| 100 | default: |
| 101 | goto out; |
| 102 | } |
| 103 | |
| 104 | pscdata->cfg = ct; |
| 105 | ret = 0; |
| 106 | out: |
| 107 | return ret; |
| 108 | } |
| 109 | |
| 110 | static int au1xpsc_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 111 | struct snd_pcm_hw_params *params, |
| 112 | struct snd_soc_dai *dai) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 113 | { |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 114 | struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 115 | |
| 116 | int cfgbits; |
| 117 | unsigned long stat; |
| 118 | |
| 119 | /* check if the PSC is already streaming data */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 120 | stat = __raw_readl(I2S_STAT(pscdata)); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 121 | if (stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB)) { |
| 122 | /* reject parameters not currently set up in hardware */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 123 | cfgbits = __raw_readl(I2S_CFG(pscdata)); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 124 | if ((PSC_I2SCFG_GET_LEN(cfgbits) != params->msbits) || |
| 125 | (params_rate(params) != pscdata->rate)) |
| 126 | return -EINVAL; |
| 127 | } else { |
| 128 | /* set sample bitdepth */ |
| 129 | pscdata->cfg &= ~(0x1f << 4); |
| 130 | pscdata->cfg |= PSC_I2SCFG_SET_LEN(params->msbits); |
| 131 | /* remember current rate for other stream */ |
| 132 | pscdata->rate = params_rate(params); |
| 133 | } |
| 134 | return 0; |
| 135 | } |
| 136 | |
| 137 | /* Configure PSC late: on my devel systems the codec is I2S master and |
| 138 | * supplies the i2sbitclock __AND__ i2sMclk (!) to the PSC unit. ASoC |
| 139 | * uses aggressive PM and switches the codec off when it is not in use |
| 140 | * which also means the PSC unit doesn't get any clocks and is therefore |
| 141 | * dead. That's why this chunk here gets called from the trigger callback |
| 142 | * because I can be reasonably certain the codec is driving the clocks. |
| 143 | */ |
| 144 | static int au1xpsc_i2s_configure(struct au1xpsc_audio_data *pscdata) |
| 145 | { |
| 146 | unsigned long tmo; |
| 147 | |
| 148 | /* bring PSC out of sleep, and configure I2S unit */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 149 | __raw_writel(PSC_CTRL_ENABLE, PSC_CTRL(pscdata)); |
| 150 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 151 | |
| 152 | tmo = 1000000; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 153 | while (!(__raw_readl(I2S_STAT(pscdata)) & PSC_I2SSTAT_SR) && tmo) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 154 | tmo--; |
| 155 | |
| 156 | if (!tmo) |
| 157 | goto psc_err; |
| 158 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 159 | __raw_writel(0, I2S_CFG(pscdata)); |
| 160 | wmb(); /* drain writebuffer */ |
| 161 | __raw_writel(pscdata->cfg | PSC_I2SCFG_DE_ENABLE, I2S_CFG(pscdata)); |
| 162 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 163 | |
| 164 | /* wait for I2S controller to become ready */ |
| 165 | tmo = 1000000; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 166 | while (!(__raw_readl(I2S_STAT(pscdata)) & PSC_I2SSTAT_DR) && tmo) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 167 | tmo--; |
| 168 | |
| 169 | if (tmo) |
| 170 | return 0; |
| 171 | |
| 172 | psc_err: |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 173 | __raw_writel(0, I2S_CFG(pscdata)); |
| 174 | __raw_writel(PSC_CTRL_SUSPEND, PSC_CTRL(pscdata)); |
| 175 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 176 | return -ETIMEDOUT; |
| 177 | } |
| 178 | |
| 179 | static int au1xpsc_i2s_start(struct au1xpsc_audio_data *pscdata, int stype) |
| 180 | { |
| 181 | unsigned long tmo, stat; |
| 182 | int ret; |
| 183 | |
| 184 | ret = 0; |
| 185 | |
| 186 | /* if both TX and RX are idle, configure the PSC */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 187 | stat = __raw_readl(I2S_STAT(pscdata)); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 188 | if (!(stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB))) { |
| 189 | ret = au1xpsc_i2s_configure(pscdata); |
| 190 | if (ret) |
| 191 | goto out; |
| 192 | } |
| 193 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 194 | __raw_writel(I2SPCR_CLRFIFO(stype), I2S_PCR(pscdata)); |
| 195 | wmb(); /* drain writebuffer */ |
| 196 | __raw_writel(I2SPCR_START(stype), I2S_PCR(pscdata)); |
| 197 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 198 | |
| 199 | /* wait for start confirmation */ |
| 200 | tmo = 1000000; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 201 | while (!(__raw_readl(I2S_STAT(pscdata)) & I2SSTAT_BUSY(stype)) && tmo) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 202 | tmo--; |
| 203 | |
| 204 | if (!tmo) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 205 | __raw_writel(I2SPCR_STOP(stype), I2S_PCR(pscdata)); |
| 206 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 207 | ret = -ETIMEDOUT; |
| 208 | } |
| 209 | out: |
| 210 | return ret; |
| 211 | } |
| 212 | |
| 213 | static int au1xpsc_i2s_stop(struct au1xpsc_audio_data *pscdata, int stype) |
| 214 | { |
| 215 | unsigned long tmo, stat; |
| 216 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 217 | __raw_writel(I2SPCR_STOP(stype), I2S_PCR(pscdata)); |
| 218 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 219 | |
| 220 | /* wait for stop confirmation */ |
| 221 | tmo = 1000000; |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 222 | while ((__raw_readl(I2S_STAT(pscdata)) & I2SSTAT_BUSY(stype)) && tmo) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 223 | tmo--; |
| 224 | |
| 225 | /* if both TX and RX are idle, disable PSC */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 226 | stat = __raw_readl(I2S_STAT(pscdata)); |
Roel Kluin | 2b30a55 | 2008-07-15 15:07:19 +0200 | [diff] [blame] | 227 | if (!(stat & (PSC_I2SSTAT_TB | PSC_I2SSTAT_RB))) { |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 228 | __raw_writel(0, I2S_CFG(pscdata)); |
| 229 | wmb(); /* drain writebuffer */ |
| 230 | __raw_writel(PSC_CTRL_SUSPEND, PSC_CTRL(pscdata)); |
| 231 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 232 | } |
| 233 | return 0; |
| 234 | } |
| 235 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 236 | static int au1xpsc_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 237 | struct snd_soc_dai *dai) |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 238 | { |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 239 | struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai); |
Manuel Lauss | 25942fd | 2011-07-25 13:45:04 +0200 | [diff] [blame] | 240 | int ret, stype = substream->stream; |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 241 | |
| 242 | switch (cmd) { |
| 243 | case SNDRV_PCM_TRIGGER_START: |
| 244 | case SNDRV_PCM_TRIGGER_RESUME: |
| 245 | ret = au1xpsc_i2s_start(pscdata, stype); |
| 246 | break; |
| 247 | case SNDRV_PCM_TRIGGER_STOP: |
| 248 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 249 | ret = au1xpsc_i2s_stop(pscdata, stype); |
| 250 | break; |
| 251 | default: |
| 252 | ret = -EINVAL; |
| 253 | } |
| 254 | return ret; |
| 255 | } |
| 256 | |
Manuel Lauss | 5b0912b | 2011-07-25 13:45:02 +0200 | [diff] [blame] | 257 | static int au1xpsc_i2s_startup(struct snd_pcm_substream *substream, |
| 258 | struct snd_soc_dai *dai) |
| 259 | { |
| 260 | struct au1xpsc_audio_data *pscdata = snd_soc_dai_get_drvdata(dai); |
| 261 | snd_soc_dai_set_dma_data(dai, substream, &pscdata->dmaids[0]); |
| 262 | return 0; |
| 263 | } |
| 264 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 265 | static const struct snd_soc_dai_ops au1xpsc_i2s_dai_ops = { |
Manuel Lauss | 5b0912b | 2011-07-25 13:45:02 +0200 | [diff] [blame] | 266 | .startup = au1xpsc_i2s_startup, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 267 | .trigger = au1xpsc_i2s_trigger, |
| 268 | .hw_params = au1xpsc_i2s_hw_params, |
| 269 | .set_fmt = au1xpsc_i2s_set_fmt, |
| 270 | }; |
| 271 | |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 272 | static const struct snd_soc_dai_driver au1xpsc_i2s_dai_template = { |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 273 | .playback = { |
| 274 | .rates = AU1XPSC_I2S_RATES, |
| 275 | .formats = AU1XPSC_I2S_FMTS, |
| 276 | .channels_min = 2, |
| 277 | .channels_max = 8, /* 2 without external help */ |
| 278 | }, |
| 279 | .capture = { |
| 280 | .rates = AU1XPSC_I2S_RATES, |
| 281 | .formats = AU1XPSC_I2S_FMTS, |
| 282 | .channels_min = 2, |
| 283 | .channels_max = 8, /* 2 without external help */ |
| 284 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 285 | .ops = &au1xpsc_i2s_dai_ops, |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 286 | }; |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 287 | |
Kuninori Morimoto | 4edf87f | 2013-03-21 03:29:24 -0700 | [diff] [blame] | 288 | static const struct snd_soc_component_driver au1xpsc_i2s_component = { |
| 289 | .name = "au1xpsc-i2s", |
| 290 | }; |
| 291 | |
Bill Pemberton | 5c658be | 2012-12-07 09:26:22 -0500 | [diff] [blame] | 292 | static int au1xpsc_i2s_drvprobe(struct platform_device *pdev) |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 293 | { |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 294 | struct resource *iores, *dmares; |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 295 | unsigned long sel; |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 296 | struct au1xpsc_audio_data *wd; |
| 297 | |
Julia Lawall | aa4079c | 2011-12-29 17:51:24 +0100 | [diff] [blame] | 298 | wd = devm_kzalloc(&pdev->dev, sizeof(struct au1xpsc_audio_data), |
| 299 | GFP_KERNEL); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 300 | if (!wd) |
| 301 | return -ENOMEM; |
| 302 | |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 303 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Axel Lin | fd63542 | 2015-08-30 11:09:49 +0800 | [diff] [blame] | 304 | wd->mmio = devm_ioremap_resource(&pdev->dev, iores); |
| 305 | if (IS_ERR(wd->mmio)) |
| 306 | return PTR_ERR(wd->mmio); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 307 | |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 308 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 309 | if (!dmares) |
Julia Lawall | aa4079c | 2011-12-29 17:51:24 +0100 | [diff] [blame] | 310 | return -EBUSY; |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 311 | wd->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = dmares->start; |
Manuel Lauss | 5b0912b | 2011-07-25 13:45:02 +0200 | [diff] [blame] | 312 | |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 313 | dmares = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 314 | if (!dmares) |
Julia Lawall | aa4079c | 2011-12-29 17:51:24 +0100 | [diff] [blame] | 315 | return -EBUSY; |
Julia Lawall | 226d0f2 | 2011-10-18 17:06:39 +0200 | [diff] [blame] | 316 | wd->dmaids[SNDRV_PCM_STREAM_CAPTURE] = dmares->start; |
Manuel Lauss | 5b0912b | 2011-07-25 13:45:02 +0200 | [diff] [blame] | 317 | |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 318 | /* preserve PSC clock source set up by platform (dev.platform_data |
| 319 | * is already occupied by soc layer) |
| 320 | */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 321 | sel = __raw_readl(PSC_SEL(wd)) & PSC_SEL_CLK_MASK; |
| 322 | __raw_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd)); |
| 323 | wmb(); /* drain writebuffer */ |
| 324 | __raw_writel(PSC_SEL_PS_I2SMODE | sel, PSC_SEL(wd)); |
| 325 | __raw_writel(0, I2S_CFG(wd)); |
| 326 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 327 | |
| 328 | /* preconfigure: set max rx/tx fifo depths */ |
| 329 | wd->cfg |= PSC_I2SCFG_RT_FIFO8 | PSC_I2SCFG_TT_FIFO8; |
| 330 | |
| 331 | /* don't wait for I2S core to become ready now; clocks may not |
| 332 | * be running yet; depending on clock input for PSC a wait might |
| 333 | * time out. |
| 334 | */ |
| 335 | |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 336 | /* name the DAI like this device instance ("au1xpsc-i2s.PSCINDEX") */ |
| 337 | memcpy(&wd->dai_drv, &au1xpsc_i2s_dai_template, |
| 338 | sizeof(struct snd_soc_dai_driver)); |
| 339 | wd->dai_drv.name = dev_name(&pdev->dev); |
| 340 | |
| 341 | platform_set_drvdata(pdev, wd); |
| 342 | |
Kuninori Morimoto | 4edf87f | 2013-03-21 03:29:24 -0700 | [diff] [blame] | 343 | return snd_soc_register_component(&pdev->dev, &au1xpsc_i2s_component, |
| 344 | &wd->dai_drv, 1); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 345 | } |
| 346 | |
Bill Pemberton | 5c658be | 2012-12-07 09:26:22 -0500 | [diff] [blame] | 347 | static int au1xpsc_i2s_drvremove(struct platform_device *pdev) |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 348 | { |
| 349 | struct au1xpsc_audio_data *wd = platform_get_drvdata(pdev); |
| 350 | |
Kuninori Morimoto | 4edf87f | 2013-03-21 03:29:24 -0700 | [diff] [blame] | 351 | snd_soc_unregister_component(&pdev->dev); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 352 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 353 | __raw_writel(0, I2S_CFG(wd)); |
| 354 | wmb(); /* drain writebuffer */ |
| 355 | __raw_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd)); |
| 356 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 357 | |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | #ifdef CONFIG_PM |
| 362 | static int au1xpsc_i2s_drvsuspend(struct device *dev) |
| 363 | { |
| 364 | struct au1xpsc_audio_data *wd = dev_get_drvdata(dev); |
| 365 | |
| 366 | /* save interesting register and disable PSC */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 367 | wd->pm[0] = __raw_readl(PSC_SEL(wd)); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 368 | |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 369 | __raw_writel(0, I2S_CFG(wd)); |
| 370 | wmb(); /* drain writebuffer */ |
| 371 | __raw_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd)); |
| 372 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 373 | |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | static int au1xpsc_i2s_drvresume(struct device *dev) |
| 378 | { |
| 379 | struct au1xpsc_audio_data *wd = dev_get_drvdata(dev); |
| 380 | |
| 381 | /* select I2S mode and PSC clock */ |
Manuel Lauss | 2f73bfb | 2014-07-23 16:36:26 +0200 | [diff] [blame] | 382 | __raw_writel(PSC_CTRL_DISABLE, PSC_CTRL(wd)); |
| 383 | wmb(); /* drain writebuffer */ |
| 384 | __raw_writel(0, PSC_SEL(wd)); |
| 385 | wmb(); /* drain writebuffer */ |
| 386 | __raw_writel(wd->pm[0], PSC_SEL(wd)); |
| 387 | wmb(); /* drain writebuffer */ |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | |
Gustavo A. R. Silva | 90982dc | 2017-07-16 21:12:49 -0500 | [diff] [blame] | 392 | static const struct dev_pm_ops au1xpsci2s_pmops = { |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 393 | .suspend = au1xpsc_i2s_drvsuspend, |
| 394 | .resume = au1xpsc_i2s_drvresume, |
| 395 | }; |
| 396 | |
| 397 | #define AU1XPSCI2S_PMOPS &au1xpsci2s_pmops |
| 398 | |
| 399 | #else |
| 400 | |
| 401 | #define AU1XPSCI2S_PMOPS NULL |
| 402 | |
| 403 | #endif |
| 404 | |
| 405 | static struct platform_driver au1xpsc_i2s_driver = { |
| 406 | .driver = { |
Manuel Lauss | ffc4fdb | 2010-08-26 14:53:51 +0200 | [diff] [blame] | 407 | .name = "au1xpsc_i2s", |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 408 | .pm = AU1XPSCI2S_PMOPS, |
| 409 | }, |
| 410 | .probe = au1xpsc_i2s_drvprobe, |
Bill Pemberton | 5c658be | 2012-12-07 09:26:22 -0500 | [diff] [blame] | 411 | .remove = au1xpsc_i2s_drvremove, |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 412 | }; |
| 413 | |
Axel Lin | 8a124f9 | 2011-11-25 10:06:59 +0800 | [diff] [blame] | 414 | module_platform_driver(au1xpsc_i2s_driver); |
Manuel Lauss | 4a161d2 | 2008-07-09 16:27:56 +0200 | [diff] [blame] | 415 | |
| 416 | MODULE_LICENSE("GPL"); |
| 417 | MODULE_DESCRIPTION("Au12x0/Au1550 PSC I2S ALSA ASoC audio driver"); |
Manuel Lauss | 0f83d63 | 2009-10-31 20:15:08 +0100 | [diff] [blame] | 418 | MODULE_AUTHOR("Manuel Lauss"); |