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