Sylwester Nawrocki | 521cc68 | 2019-04-19 12:21:49 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // s3c24xx-i2s.c -- ALSA Soc Audio Layer |
| 4 | // |
| 5 | // (c) 2006 Wolfson Microelectronics PLC. |
| 6 | // Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com |
| 7 | // |
| 8 | // Copyright 2004-2005 Simtec Electronics |
| 9 | // http://armlinux.simtec.co.uk/ |
| 10 | // Ben Dooks <ben@simtec.co.uk> |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 11 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 12 | #include <linux/delay.h> |
| 13 | #include <linux/clk.h> |
Mark Brown | 40efc15 | 2008-04-23 15:09:31 +0200 | [diff] [blame] | 14 | #include <linux/io.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 15 | #include <linux/gpio.h> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Ben Dooks | ec976d6 | 2009-05-13 22:52:24 +0100 | [diff] [blame] | 17 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 18 | #include <sound/soc.h> |
Seungwhan Youn | 0378b6a | 2011-01-11 07:26:06 +0900 | [diff] [blame] | 19 | #include <sound/pcm_params.h> |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 20 | |
Sachin Kamat | abffae6 | 2014-01-22 17:30:38 +0530 | [diff] [blame] | 21 | #include <mach/gpio-samsung.h> |
| 22 | #include <plat/gpio-cfg.h> |
Arnd Bergmann | 5d229ce5 | 2013-04-11 19:08:42 +0200 | [diff] [blame] | 23 | #include "regs-iis.h" |
Harald Welte | aa9673c | 2007-12-19 15:37:49 +0100 | [diff] [blame] | 24 | |
Jassi Brar | 4b640cf | 2010-11-22 15:35:57 +0900 | [diff] [blame] | 25 | #include "dma.h" |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 26 | #include "s3c24xx-i2s.h" |
| 27 | |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 28 | static struct snd_dmaengine_dai_dma_data s3c24xx_i2s_pcm_stereo_out = { |
Sylwester Nawrocki | b8ab0cc | 2017-01-17 14:16:42 +0100 | [diff] [blame] | 29 | .chan_name = "tx", |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 30 | .addr_width = 2, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 33 | static struct snd_dmaengine_dai_dma_data s3c24xx_i2s_pcm_stereo_in = { |
Sylwester Nawrocki | b8ab0cc | 2017-01-17 14:16:42 +0100 | [diff] [blame] | 34 | .chan_name = "rx", |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 35 | .addr_width = 2, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | struct s3c24xx_i2s_info { |
| 39 | void __iomem *regs; |
| 40 | struct clk *iis_clk; |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 41 | u32 iiscon; |
| 42 | u32 iismod; |
| 43 | u32 iisfcon; |
| 44 | u32 iispsr; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 45 | }; |
| 46 | static struct s3c24xx_i2s_info s3c24xx_i2s; |
| 47 | |
| 48 | static void s3c24xx_snd_txctrl(int on) |
| 49 | { |
| 50 | u32 iisfcon; |
| 51 | u32 iiscon; |
| 52 | u32 iismod; |
| 53 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 54 | iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 55 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 56 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 57 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 58 | pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 59 | |
| 60 | if (on) { |
| 61 | iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE; |
| 62 | iiscon |= S3C2410_IISCON_TXDMAEN | S3C2410_IISCON_IISEN; |
| 63 | iiscon &= ~S3C2410_IISCON_TXIDLE; |
| 64 | iismod |= S3C2410_IISMOD_TXMODE; |
| 65 | |
| 66 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 67 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 68 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 69 | } else { |
| 70 | /* note, we have to disable the FIFOs otherwise bad things |
| 71 | * seem to happen when the DMA stops. According to the |
| 72 | * Samsung supplied kernel, this should allow the DMA |
| 73 | * engine and FIFOs to reset. If this isn't allowed, the |
| 74 | * DMA engine will simply freeze randomly. |
| 75 | */ |
| 76 | |
| 77 | iisfcon &= ~S3C2410_IISFCON_TXENABLE; |
| 78 | iisfcon &= ~S3C2410_IISFCON_TXDMA; |
| 79 | iiscon |= S3C2410_IISCON_TXIDLE; |
| 80 | iiscon &= ~S3C2410_IISCON_TXDMAEN; |
| 81 | iismod &= ~S3C2410_IISMOD_TXMODE; |
| 82 | |
| 83 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 84 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 85 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 86 | } |
| 87 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 88 | pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void s3c24xx_snd_rxctrl(int on) |
| 92 | { |
| 93 | u32 iisfcon; |
| 94 | u32 iiscon; |
| 95 | u32 iismod; |
| 96 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 97 | iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 98 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 99 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 100 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 101 | pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 102 | |
| 103 | if (on) { |
| 104 | iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE; |
| 105 | iiscon |= S3C2410_IISCON_RXDMAEN | S3C2410_IISCON_IISEN; |
| 106 | iiscon &= ~S3C2410_IISCON_RXIDLE; |
| 107 | iismod |= S3C2410_IISMOD_RXMODE; |
| 108 | |
| 109 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 110 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 111 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 112 | } else { |
| 113 | /* note, we have to disable the FIFOs otherwise bad things |
| 114 | * seem to happen when the DMA stops. According to the |
| 115 | * Samsung supplied kernel, this should allow the DMA |
| 116 | * engine and FIFOs to reset. If this isn't allowed, the |
| 117 | * DMA engine will simply freeze randomly. |
| 118 | */ |
| 119 | |
Mark Brown | 0015e7d | 2008-04-23 15:09:57 +0200 | [diff] [blame] | 120 | iisfcon &= ~S3C2410_IISFCON_RXENABLE; |
| 121 | iisfcon &= ~S3C2410_IISFCON_RXDMA; |
| 122 | iiscon |= S3C2410_IISCON_RXIDLE; |
| 123 | iiscon &= ~S3C2410_IISCON_RXDMAEN; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 124 | iismod &= ~S3C2410_IISMOD_RXMODE; |
| 125 | |
| 126 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 127 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 128 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 129 | } |
| 130 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 131 | pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | /* |
| 135 | * Wait for the LR signal to allow synchronisation to the L/R clock |
| 136 | * from the codec. May only be needed for slave mode. |
| 137 | */ |
| 138 | static int s3c24xx_snd_lrsync(void) |
| 139 | { |
| 140 | u32 iiscon; |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 141 | int timeout = 50; /* 5ms */ |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 142 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 143 | while (1) { |
| 144 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 145 | if (iiscon & S3C2410_IISCON_LRINDEX) |
| 146 | break; |
| 147 | |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 148 | if (!timeout--) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 149 | return -ETIMEDOUT; |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 150 | udelay(100); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Check whether CPU is the master or slave |
| 158 | */ |
| 159 | static inline int s3c24xx_snd_is_clkmaster(void) |
| 160 | { |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 161 | return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Set S3C24xx I2S DAI format |
| 166 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 167 | static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 168 | unsigned int fmt) |
| 169 | { |
| 170 | u32 iismod; |
| 171 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 172 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 173 | pr_debug("hw_params r: IISMOD: %x \n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 174 | |
| 175 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 176 | case SND_SOC_DAIFMT_CBM_CFM: |
| 177 | iismod |= S3C2410_IISMOD_SLAVE; |
| 178 | break; |
| 179 | case SND_SOC_DAIFMT_CBS_CFS: |
Davide Rizzo | 2c36eec | 2008-05-05 14:59:39 +0200 | [diff] [blame] | 180 | iismod &= ~S3C2410_IISMOD_SLAVE; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 181 | break; |
| 182 | default: |
| 183 | return -EINVAL; |
| 184 | } |
| 185 | |
| 186 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 187 | case SND_SOC_DAIFMT_LEFT_J: |
| 188 | iismod |= S3C2410_IISMOD_MSB; |
| 189 | break; |
| 190 | case SND_SOC_DAIFMT_I2S: |
Davide Rizzo | 2c36eec | 2008-05-05 14:59:39 +0200 | [diff] [blame] | 191 | iismod &= ~S3C2410_IISMOD_MSB; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 192 | break; |
| 193 | default: |
| 194 | return -EINVAL; |
| 195 | } |
| 196 | |
| 197 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 198 | pr_debug("hw_params w: IISMOD: %x \n", iismod); |
Sylwester Nawrocki | 2ef9555 | 2016-10-25 17:08:41 +0200 | [diff] [blame] | 199 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 204 | struct snd_pcm_hw_params *params, |
| 205 | struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 206 | { |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 207 | struct snd_dmaengine_dai_dma_data *dma_data; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 208 | u32 iismod; |
| 209 | |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 210 | dma_data = snd_soc_dai_get_dma_data(dai, substream); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 211 | |
| 212 | /* Working copies of register */ |
| 213 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 214 | pr_debug("hw_params r: IISMOD: %x\n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 215 | |
Tushar Behera | 88ce146 | 2014-05-23 17:35:39 +0530 | [diff] [blame] | 216 | switch (params_width(params)) { |
| 217 | case 8: |
Christian Pellegrin | 53599bb | 2008-11-08 08:44:16 +0100 | [diff] [blame] | 218 | iismod &= ~S3C2410_IISMOD_16BIT; |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 219 | dma_data->addr_width = 1; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 220 | break; |
Tushar Behera | 88ce146 | 2014-05-23 17:35:39 +0530 | [diff] [blame] | 221 | case 16: |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 222 | iismod |= S3C2410_IISMOD_16BIT; |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 223 | dma_data->addr_width = 2; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 224 | break; |
Christian Pellegrin | 53599bb | 2008-11-08 08:44:16 +0100 | [diff] [blame] | 225 | default: |
| 226 | return -EINVAL; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 230 | pr_debug("hw_params w: IISMOD: %x\n", iismod); |
Sylwester Nawrocki | 2ef9555 | 2016-10-25 17:08:41 +0200 | [diff] [blame] | 231 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 232 | return 0; |
| 233 | } |
| 234 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 235 | static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 236 | struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 237 | { |
| 238 | int ret = 0; |
| 239 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 240 | switch (cmd) { |
| 241 | case SNDRV_PCM_TRIGGER_START: |
| 242 | case SNDRV_PCM_TRIGGER_RESUME: |
| 243 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 244 | if (!s3c24xx_snd_is_clkmaster()) { |
| 245 | ret = s3c24xx_snd_lrsync(); |
| 246 | if (ret) |
| 247 | goto exit_err; |
| 248 | } |
| 249 | |
| 250 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 251 | s3c24xx_snd_rxctrl(1); |
| 252 | else |
| 253 | s3c24xx_snd_txctrl(1); |
Shine Liu | faf907c | 2009-08-25 20:05:50 +0800 | [diff] [blame] | 254 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 255 | break; |
| 256 | case SNDRV_PCM_TRIGGER_STOP: |
| 257 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 258 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 259 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 260 | s3c24xx_snd_rxctrl(0); |
| 261 | else |
| 262 | s3c24xx_snd_txctrl(0); |
| 263 | break; |
| 264 | default: |
| 265 | ret = -EINVAL; |
| 266 | break; |
| 267 | } |
| 268 | |
| 269 | exit_err: |
| 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Set S3C24xx Clock source |
| 275 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 276 | static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 277 | int clk_id, unsigned int freq, int dir) |
| 278 | { |
| 279 | u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 280 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 281 | iismod &= ~S3C2440_IISMOD_MPLL; |
| 282 | |
| 283 | switch (clk_id) { |
| 284 | case S3C24XX_CLKSRC_PCLK: |
| 285 | break; |
| 286 | case S3C24XX_CLKSRC_MPLL: |
| 287 | iismod |= S3C2440_IISMOD_MPLL; |
| 288 | break; |
| 289 | default: |
| 290 | return -EINVAL; |
| 291 | } |
| 292 | |
| 293 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Set S3C24xx Clock dividers |
| 299 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 300 | static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 301 | int div_id, int div) |
| 302 | { |
| 303 | u32 reg; |
| 304 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 305 | switch (div_id) { |
Matt Reimer | 82fb159 | 2007-07-12 12:27:24 +0200 | [diff] [blame] | 306 | case S3C24XX_DIV_BCLK: |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 307 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~S3C2410_IISMOD_FS_MASK; |
| 308 | writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 309 | break; |
Matt Reimer | 82fb159 | 2007-07-12 12:27:24 +0200 | [diff] [blame] | 310 | case S3C24XX_DIV_MCLK: |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 311 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~(S3C2410_IISMOD_384FS); |
| 312 | writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 313 | break; |
| 314 | case S3C24XX_DIV_PRESCALER: |
| 315 | writel(div, s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 316 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 317 | writel(reg | S3C2410_IISCON_PSCEN, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 318 | break; |
| 319 | default: |
| 320 | return -EINVAL; |
| 321 | } |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | /* |
| 327 | * To avoid duplicating clock code, allow machine driver to |
| 328 | * get the clockrate from here. |
| 329 | */ |
| 330 | u32 s3c24xx_i2s_get_clockrate(void) |
| 331 | { |
| 332 | return clk_get_rate(s3c24xx_i2s.iis_clk); |
| 333 | } |
| 334 | EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate); |
| 335 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 336 | static int s3c24xx_i2s_probe(struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 337 | { |
Arvind Yadav | 8698475 | 2017-07-25 15:44:29 +0530 | [diff] [blame] | 338 | int ret; |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 339 | snd_soc_dai_init_dma_data(dai, &s3c24xx_i2s_pcm_stereo_out, |
| 340 | &s3c24xx_i2s_pcm_stereo_in); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 341 | |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 342 | s3c24xx_i2s.iis_clk = devm_clk_get(dai->dev, "iis"); |
Axel Lin | 7803e32 | 2011-09-15 10:36:54 +0800 | [diff] [blame] | 343 | if (IS_ERR(s3c24xx_i2s.iis_clk)) { |
Mark Brown | b52a519 | 2009-03-06 18:13:43 +0000 | [diff] [blame] | 344 | pr_err("failed to get iis_clock\n"); |
Axel Lin | 7803e32 | 2011-09-15 10:36:54 +0800 | [diff] [blame] | 345 | return PTR_ERR(s3c24xx_i2s.iis_clk); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 346 | } |
Arvind Yadav | 8698475 | 2017-07-25 15:44:29 +0530 | [diff] [blame] | 347 | ret = clk_prepare_enable(s3c24xx_i2s.iis_clk); |
| 348 | if (ret) |
| 349 | return ret; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 350 | |
Sylwester Nawrocki | 0eed8a1 | 2012-07-13 19:22:44 +0200 | [diff] [blame] | 351 | /* Configure the I2S pins (GPE0...GPE4) in correct mode */ |
| 352 | s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2), |
| 353 | S3C_GPIO_PULL_NONE); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 354 | |
| 355 | writel(S3C2410_IISCON_IISEN, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 356 | |
| 357 | s3c24xx_snd_txctrl(0); |
| 358 | s3c24xx_snd_rxctrl(0); |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 363 | #ifdef CONFIG_PM |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 364 | static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai) |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 365 | { |
| 366 | s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 367 | s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 368 | s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 369 | s3c24xx_i2s.iispsr = readl(s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 370 | |
Vasily Khoruzhick | c1ae59c | 2014-06-23 23:24:07 +0300 | [diff] [blame] | 371 | clk_disable_unprepare(s3c24xx_i2s.iis_clk); |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 376 | static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai) |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 377 | { |
Arvind Yadav | 8698475 | 2017-07-25 15:44:29 +0530 | [diff] [blame] | 378 | int ret; |
| 379 | |
| 380 | ret = clk_prepare_enable(s3c24xx_i2s.iis_clk); |
| 381 | if (ret) |
| 382 | return ret; |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 383 | |
| 384 | writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 385 | writel(s3c24xx_i2s.iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 386 | writel(s3c24xx_i2s.iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 387 | writel(s3c24xx_i2s.iispsr, s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 388 | |
| 389 | return 0; |
| 390 | } |
| 391 | #else |
| 392 | #define s3c24xx_i2s_suspend NULL |
| 393 | #define s3c24xx_i2s_resume NULL |
| 394 | #endif |
| 395 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 396 | #define S3C24XX_I2S_RATES \ |
| 397 | (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \ |
| 398 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 399 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
| 400 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 401 | static const struct snd_soc_dai_ops s3c24xx_i2s_dai_ops = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 402 | .trigger = s3c24xx_i2s_trigger, |
| 403 | .hw_params = s3c24xx_i2s_hw_params, |
| 404 | .set_fmt = s3c24xx_i2s_set_fmt, |
| 405 | .set_clkdiv = s3c24xx_i2s_set_clkdiv, |
| 406 | .set_sysclk = s3c24xx_i2s_set_sysclk, |
| 407 | }; |
| 408 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 409 | static struct snd_soc_dai_driver s3c24xx_i2s_dai = { |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 410 | .probe = s3c24xx_i2s_probe, |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 411 | .suspend = s3c24xx_i2s_suspend, |
| 412 | .resume = s3c24xx_i2s_resume, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 413 | .playback = { |
| 414 | .channels_min = 2, |
| 415 | .channels_max = 2, |
| 416 | .rates = S3C24XX_I2S_RATES, |
| 417 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,}, |
| 418 | .capture = { |
| 419 | .channels_min = 2, |
| 420 | .channels_max = 2, |
| 421 | .rates = S3C24XX_I2S_RATES, |
| 422 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 423 | .ops = &s3c24xx_i2s_dai_ops, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 424 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 425 | |
Kuninori Morimoto | 5642ddf | 2013-03-21 03:35:11 -0700 | [diff] [blame] | 426 | static const struct snd_soc_component_driver s3c24xx_i2s_component = { |
| 427 | .name = "s3c24xx-i2s", |
| 428 | }; |
| 429 | |
Bill Pemberton | fdca21a | 2012-12-07 09:26:15 -0500 | [diff] [blame] | 430 | static int s3c24xx_iis_dev_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 431 | { |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 432 | struct resource *res; |
Sylwester Nawrocki | 5d3c1f6 | 2016-11-02 12:11:47 +0100 | [diff] [blame] | 433 | int ret; |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 434 | |
| 435 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 436 | s3c24xx_i2s.regs = devm_ioremap_resource(&pdev->dev, res); |
Wei Yongjun | c479163 | 2015-04-16 20:18:02 +0800 | [diff] [blame] | 437 | if (IS_ERR(s3c24xx_i2s.regs)) |
| 438 | return PTR_ERR(s3c24xx_i2s.regs); |
Vasily Khoruzhick | 87b132bc0 | 2014-06-23 23:24:04 +0300 | [diff] [blame] | 439 | |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 440 | s3c24xx_i2s_pcm_stereo_out.addr = res->start + S3C2410_IISFIFO; |
Sylwester Nawrocki | 8999390 | 2016-08-04 11:30:27 +0200 | [diff] [blame] | 441 | s3c24xx_i2s_pcm_stereo_in.addr = res->start + S3C2410_IISFIFO; |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 442 | |
Sylwester Nawrocki | 6c9473c | 2016-11-02 12:04:36 +0100 | [diff] [blame] | 443 | ret = samsung_asoc_dma_platform_register(&pdev->dev, NULL, |
Sylwester Nawrocki | 0f928c1 | 2019-02-14 10:37:41 +0100 | [diff] [blame] | 444 | "tx", "rx", NULL); |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 445 | if (ret) { |
Sylwester Nawrocki | 6c9473c | 2016-11-02 12:04:36 +0100 | [diff] [blame] | 446 | dev_err(&pdev->dev, "Failed to register the DMA: %d\n", ret); |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 447 | return ret; |
| 448 | } |
| 449 | |
Marek Szyprowski | 73f5dfc | 2016-10-27 12:34:02 +0200 | [diff] [blame] | 450 | ret = devm_snd_soc_register_component(&pdev->dev, |
| 451 | &s3c24xx_i2s_component, &s3c24xx_i2s_dai, 1); |
Tushar Behera | 7253e35 | 2014-05-21 08:52:19 +0530 | [diff] [blame] | 452 | if (ret) |
Sylwester Nawrocki | 6c9473c | 2016-11-02 12:04:36 +0100 | [diff] [blame] | 453 | dev_err(&pdev->dev, "Failed to register the DAI\n"); |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 454 | |
Padmavathi Venna | a08485d8 | 2012-12-07 13:59:21 +0530 | [diff] [blame] | 455 | return ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 458 | static struct platform_driver s3c24xx_iis_driver = { |
| 459 | .probe = s3c24xx_iis_dev_probe, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 460 | .driver = { |
| 461 | .name = "s3c24xx-iis", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 462 | }, |
| 463 | }; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 464 | |
Mark Brown | e00c3f5 | 2011-11-23 15:20:13 +0000 | [diff] [blame] | 465 | module_platform_driver(s3c24xx_iis_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 466 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 467 | /* Module information */ |
| 468 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
| 469 | MODULE_DESCRIPTION("s3c24xx I2S SoC Interface"); |
| 470 | MODULE_LICENSE("GPL"); |
Mark Brown | 960d069 | 2010-08-12 11:02:19 +0100 | [diff] [blame] | 471 | MODULE_ALIAS("platform:s3c24xx-iis"); |