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> |
| 21 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 22 | #include <sound/soc.h> |
Seungwhan Youn | 0378b6a | 2011-01-11 07:26:06 +0900 | [diff] [blame] | 23 | #include <sound/pcm_params.h> |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 24 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 25 | #include <mach/regs-gpio.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 26 | #include <mach/dma.h> |
Ben Dooks | 8150bc8 | 2009-03-04 00:49:26 +0000 | [diff] [blame] | 27 | #include <plat/regs-iis.h> |
Harald Welte | aa9673c | 2007-12-19 15:37:49 +0100 | [diff] [blame] | 28 | |
Jassi Brar | 4b640cf | 2010-11-22 15:35:57 +0900 | [diff] [blame] | 29 | #include "dma.h" |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 30 | #include "s3c24xx-i2s.h" |
| 31 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 32 | static struct s3c2410_dma_client s3c24xx_dma_client_out = { |
| 33 | .name = "I2S PCM Stereo out" |
| 34 | }; |
| 35 | |
| 36 | static struct s3c2410_dma_client s3c24xx_dma_client_in = { |
| 37 | .name = "I2S PCM Stereo in" |
| 38 | }; |
| 39 | |
Jassi Brar | faa3177 | 2009-11-17 16:53:23 +0900 | [diff] [blame] | 40 | static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_out = { |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 41 | .client = &s3c24xx_dma_client_out, |
| 42 | .channel = DMACH_I2S_OUT, |
Graeme Gregory | e81208f | 2007-04-17 12:35:48 +0200 | [diff] [blame] | 43 | .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO, |
| 44 | .dma_size = 2, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 45 | }; |
| 46 | |
Jassi Brar | faa3177 | 2009-11-17 16:53:23 +0900 | [diff] [blame] | 47 | static struct s3c_dma_params s3c24xx_i2s_pcm_stereo_in = { |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 48 | .client = &s3c24xx_dma_client_in, |
| 49 | .channel = DMACH_I2S_IN, |
Graeme Gregory | e81208f | 2007-04-17 12:35:48 +0200 | [diff] [blame] | 50 | .dma_addr = S3C2410_PA_IIS + S3C2410_IISFIFO, |
| 51 | .dma_size = 2, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | struct s3c24xx_i2s_info { |
| 55 | void __iomem *regs; |
| 56 | struct clk *iis_clk; |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 57 | u32 iiscon; |
| 58 | u32 iismod; |
| 59 | u32 iisfcon; |
| 60 | u32 iispsr; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 61 | }; |
| 62 | static struct s3c24xx_i2s_info s3c24xx_i2s; |
| 63 | |
| 64 | static void s3c24xx_snd_txctrl(int on) |
| 65 | { |
| 66 | u32 iisfcon; |
| 67 | u32 iiscon; |
| 68 | u32 iismod; |
| 69 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 70 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 71 | |
| 72 | iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 73 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 74 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 75 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 76 | 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] | 77 | |
| 78 | if (on) { |
| 79 | iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE; |
| 80 | iiscon |= S3C2410_IISCON_TXDMAEN | S3C2410_IISCON_IISEN; |
| 81 | iiscon &= ~S3C2410_IISCON_TXIDLE; |
| 82 | iismod |= S3C2410_IISMOD_TXMODE; |
| 83 | |
| 84 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 85 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 86 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 87 | } else { |
| 88 | /* note, we have to disable the FIFOs otherwise bad things |
| 89 | * seem to happen when the DMA stops. According to the |
| 90 | * Samsung supplied kernel, this should allow the DMA |
| 91 | * engine and FIFOs to reset. If this isn't allowed, the |
| 92 | * DMA engine will simply freeze randomly. |
| 93 | */ |
| 94 | |
| 95 | iisfcon &= ~S3C2410_IISFCON_TXENABLE; |
| 96 | iisfcon &= ~S3C2410_IISFCON_TXDMA; |
| 97 | iiscon |= S3C2410_IISCON_TXIDLE; |
| 98 | iiscon &= ~S3C2410_IISCON_TXDMAEN; |
| 99 | iismod &= ~S3C2410_IISMOD_TXMODE; |
| 100 | |
| 101 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 102 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 103 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 104 | } |
| 105 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 106 | 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] | 107 | } |
| 108 | |
| 109 | static void s3c24xx_snd_rxctrl(int on) |
| 110 | { |
| 111 | u32 iisfcon; |
| 112 | u32 iiscon; |
| 113 | u32 iismod; |
| 114 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 115 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 116 | |
| 117 | iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 118 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 119 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 120 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 121 | 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] | 122 | |
| 123 | if (on) { |
| 124 | iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE; |
| 125 | iiscon |= S3C2410_IISCON_RXDMAEN | S3C2410_IISCON_IISEN; |
| 126 | iiscon &= ~S3C2410_IISCON_RXIDLE; |
| 127 | iismod |= S3C2410_IISMOD_RXMODE; |
| 128 | |
| 129 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 130 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 131 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 132 | } else { |
| 133 | /* note, we have to disable the FIFOs otherwise bad things |
| 134 | * seem to happen when the DMA stops. According to the |
| 135 | * Samsung supplied kernel, this should allow the DMA |
| 136 | * engine and FIFOs to reset. If this isn't allowed, the |
| 137 | * DMA engine will simply freeze randomly. |
| 138 | */ |
| 139 | |
Mark Brown | 0015e7d | 2008-04-23 15:09:57 +0200 | [diff] [blame] | 140 | iisfcon &= ~S3C2410_IISFCON_RXENABLE; |
| 141 | iisfcon &= ~S3C2410_IISFCON_RXDMA; |
| 142 | iiscon |= S3C2410_IISCON_RXIDLE; |
| 143 | iiscon &= ~S3C2410_IISCON_RXDMAEN; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 144 | iismod &= ~S3C2410_IISMOD_RXMODE; |
| 145 | |
| 146 | writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 147 | writel(iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 148 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 149 | } |
| 150 | |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 151 | 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] | 152 | } |
| 153 | |
| 154 | /* |
| 155 | * Wait for the LR signal to allow synchronisation to the L/R clock |
| 156 | * from the codec. May only be needed for slave mode. |
| 157 | */ |
| 158 | static int s3c24xx_snd_lrsync(void) |
| 159 | { |
| 160 | u32 iiscon; |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 161 | int timeout = 50; /* 5ms */ |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 162 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 163 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 164 | |
| 165 | while (1) { |
| 166 | iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 167 | if (iiscon & S3C2410_IISCON_LRINDEX) |
| 168 | break; |
| 169 | |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 170 | if (!timeout--) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 171 | return -ETIMEDOUT; |
Werner Almesberger | 33e5b22 | 2008-04-14 14:26:44 +0200 | [diff] [blame] | 172 | udelay(100); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /* |
| 179 | * Check whether CPU is the master or slave |
| 180 | */ |
| 181 | static inline int s3c24xx_snd_is_clkmaster(void) |
| 182 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 183 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 184 | |
| 185 | return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; |
| 186 | } |
| 187 | |
| 188 | /* |
| 189 | * Set S3C24xx I2S DAI format |
| 190 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 191 | static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 192 | unsigned int fmt) |
| 193 | { |
| 194 | u32 iismod; |
| 195 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 196 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 197 | |
| 198 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 199 | pr_debug("hw_params r: IISMOD: %x \n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 200 | |
| 201 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 202 | case SND_SOC_DAIFMT_CBM_CFM: |
| 203 | iismod |= S3C2410_IISMOD_SLAVE; |
| 204 | break; |
| 205 | case SND_SOC_DAIFMT_CBS_CFS: |
Davide Rizzo | 2c36eec | 2008-05-05 14:59:39 +0200 | [diff] [blame] | 206 | iismod &= ~S3C2410_IISMOD_SLAVE; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 207 | break; |
| 208 | default: |
| 209 | return -EINVAL; |
| 210 | } |
| 211 | |
| 212 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 213 | case SND_SOC_DAIFMT_LEFT_J: |
| 214 | iismod |= S3C2410_IISMOD_MSB; |
| 215 | break; |
| 216 | case SND_SOC_DAIFMT_I2S: |
Davide Rizzo | 2c36eec | 2008-05-05 14:59:39 +0200 | [diff] [blame] | 217 | iismod &= ~S3C2410_IISMOD_MSB; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 218 | break; |
| 219 | default: |
| 220 | return -EINVAL; |
| 221 | } |
| 222 | |
| 223 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 224 | pr_debug("hw_params w: IISMOD: %x \n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 229 | struct snd_pcm_hw_params *params, |
| 230 | struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 231 | { |
| 232 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 233 | struct s3c_dma_params *dma_data; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 234 | u32 iismod; |
| 235 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 236 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 237 | |
| 238 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 239 | dma_data = &s3c24xx_i2s_pcm_stereo_out; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 240 | else |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 241 | dma_data = &s3c24xx_i2s_pcm_stereo_in; |
| 242 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 243 | snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_data); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 244 | |
| 245 | /* Working copies of register */ |
| 246 | iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 247 | pr_debug("hw_params r: IISMOD: %x\n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 248 | |
| 249 | switch (params_format(params)) { |
| 250 | case SNDRV_PCM_FORMAT_S8: |
Christian Pellegrin | 53599bb | 2008-11-08 08:44:16 +0100 | [diff] [blame] | 251 | iismod &= ~S3C2410_IISMOD_16BIT; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 252 | dma_data->dma_size = 1; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 253 | break; |
| 254 | case SNDRV_PCM_FORMAT_S16_LE: |
| 255 | iismod |= S3C2410_IISMOD_16BIT; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 256 | dma_data->dma_size = 2; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 257 | break; |
Christian Pellegrin | 53599bb | 2008-11-08 08:44:16 +0100 | [diff] [blame] | 258 | default: |
| 259 | return -EINVAL; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
Mark Brown | 5314adc | 2009-03-11 16:28:29 +0000 | [diff] [blame] | 263 | pr_debug("hw_params w: IISMOD: %x\n", iismod); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 267 | static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 268 | struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 269 | { |
| 270 | int ret = 0; |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 271 | struct s3c_dma_params *dma_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 272 | snd_soc_dai_get_dma_data(dai, substream); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 273 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 274 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 275 | |
| 276 | switch (cmd) { |
| 277 | case SNDRV_PCM_TRIGGER_START: |
| 278 | case SNDRV_PCM_TRIGGER_RESUME: |
| 279 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 280 | if (!s3c24xx_snd_is_clkmaster()) { |
| 281 | ret = s3c24xx_snd_lrsync(); |
| 282 | if (ret) |
| 283 | goto exit_err; |
| 284 | } |
| 285 | |
| 286 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 287 | s3c24xx_snd_rxctrl(1); |
| 288 | else |
| 289 | s3c24xx_snd_txctrl(1); |
Shine Liu | faf907c | 2009-08-25 20:05:50 +0800 | [diff] [blame] | 290 | |
Daniel Mack | 5f712b2 | 2010-03-22 10:11:15 +0100 | [diff] [blame] | 291 | s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 292 | break; |
| 293 | case SNDRV_PCM_TRIGGER_STOP: |
| 294 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 295 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 296 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 297 | s3c24xx_snd_rxctrl(0); |
| 298 | else |
| 299 | s3c24xx_snd_txctrl(0); |
| 300 | break; |
| 301 | default: |
| 302 | ret = -EINVAL; |
| 303 | break; |
| 304 | } |
| 305 | |
| 306 | exit_err: |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Set S3C24xx Clock source |
| 312 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 313 | static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 314 | int clk_id, unsigned int freq, int dir) |
| 315 | { |
| 316 | u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 317 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 318 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 319 | |
| 320 | iismod &= ~S3C2440_IISMOD_MPLL; |
| 321 | |
| 322 | switch (clk_id) { |
| 323 | case S3C24XX_CLKSRC_PCLK: |
| 324 | break; |
| 325 | case S3C24XX_CLKSRC_MPLL: |
| 326 | iismod |= S3C2440_IISMOD_MPLL; |
| 327 | break; |
| 328 | default: |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | |
| 332 | writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * Set S3C24xx Clock dividers |
| 338 | */ |
Liam Girdwood | 1992a6f | 2008-07-07 16:08:24 +0100 | [diff] [blame] | 339 | static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 340 | int div_id, int div) |
| 341 | { |
| 342 | u32 reg; |
| 343 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 344 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 345 | |
| 346 | switch (div_id) { |
Matt Reimer | 82fb159 | 2007-07-12 12:27:24 +0200 | [diff] [blame] | 347 | case S3C24XX_DIV_BCLK: |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 348 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~S3C2410_IISMOD_FS_MASK; |
| 349 | writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 350 | break; |
Matt Reimer | 82fb159 | 2007-07-12 12:27:24 +0200 | [diff] [blame] | 351 | case S3C24XX_DIV_MCLK: |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 352 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & ~(S3C2410_IISMOD_384FS); |
| 353 | writel(reg | div, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 354 | break; |
| 355 | case S3C24XX_DIV_PRESCALER: |
| 356 | writel(div, s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 357 | reg = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 358 | writel(reg | S3C2410_IISCON_PSCEN, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 359 | break; |
| 360 | default: |
| 361 | return -EINVAL; |
| 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * To avoid duplicating clock code, allow machine driver to |
| 369 | * get the clockrate from here. |
| 370 | */ |
| 371 | u32 s3c24xx_i2s_get_clockrate(void) |
| 372 | { |
| 373 | return clk_get_rate(s3c24xx_i2s.iis_clk); |
| 374 | } |
| 375 | EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate); |
| 376 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 377 | static int s3c24xx_i2s_probe(struct snd_soc_dai *dai) |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 378 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 379 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 380 | |
| 381 | s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); |
| 382 | if (s3c24xx_i2s.regs == NULL) |
| 383 | return -ENXIO; |
| 384 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 385 | s3c24xx_i2s.iis_clk = clk_get(dai->dev, "iis"); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 386 | if (s3c24xx_i2s.iis_clk == NULL) { |
Mark Brown | b52a519 | 2009-03-06 18:13:43 +0000 | [diff] [blame] | 387 | pr_err("failed to get iis_clock\n"); |
Scott Thompson | 8642a4b | 2007-08-01 13:38:59 +0200 | [diff] [blame] | 388 | iounmap(s3c24xx_i2s.regs); |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 389 | return -ENODEV; |
| 390 | } |
| 391 | clk_enable(s3c24xx_i2s.iis_clk); |
| 392 | |
| 393 | /* Configure the I2S pins in correct mode */ |
| 394 | s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK); |
| 395 | s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK); |
| 396 | s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK); |
| 397 | s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI); |
| 398 | s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO); |
| 399 | |
| 400 | writel(S3C2410_IISCON_IISEN, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 401 | |
| 402 | s3c24xx_snd_txctrl(0); |
| 403 | s3c24xx_snd_rxctrl(0); |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 408 | #ifdef CONFIG_PM |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 409 | static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai) |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 410 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 411 | pr_debug("Entered %s\n", __func__); |
Tim Niemeyer | 4092030 | 2008-04-22 18:26:59 +0200 | [diff] [blame] | 412 | |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 413 | s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); |
| 414 | s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 415 | s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 416 | s3c24xx_i2s.iispsr = readl(s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 417 | |
| 418 | clk_disable(s3c24xx_i2s.iis_clk); |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
Mark Brown | dc7d7b8 | 2008-12-03 18:21:52 +0000 | [diff] [blame] | 423 | static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai) |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 424 | { |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 425 | pr_debug("Entered %s\n", __func__); |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 426 | clk_enable(s3c24xx_i2s.iis_clk); |
| 427 | |
| 428 | writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); |
| 429 | writel(s3c24xx_i2s.iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); |
| 430 | writel(s3c24xx_i2s.iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); |
| 431 | writel(s3c24xx_i2s.iispsr, s3c24xx_i2s.regs + S3C2410_IISPSR); |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | #else |
| 436 | #define s3c24xx_i2s_suspend NULL |
| 437 | #define s3c24xx_i2s_resume NULL |
| 438 | #endif |
| 439 | |
| 440 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 441 | #define S3C24XX_I2S_RATES \ |
| 442 | (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \ |
| 443 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ |
| 444 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) |
| 445 | |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 446 | static struct snd_soc_dai_ops s3c24xx_i2s_dai_ops = { |
| 447 | .trigger = s3c24xx_i2s_trigger, |
| 448 | .hw_params = s3c24xx_i2s_hw_params, |
| 449 | .set_fmt = s3c24xx_i2s_set_fmt, |
| 450 | .set_clkdiv = s3c24xx_i2s_set_clkdiv, |
| 451 | .set_sysclk = s3c24xx_i2s_set_sysclk, |
| 452 | }; |
| 453 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 454 | static struct snd_soc_dai_driver s3c24xx_i2s_dai = { |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 455 | .probe = s3c24xx_i2s_probe, |
Graeme Gregory | 5cd919a | 2008-01-10 14:44:58 +0100 | [diff] [blame] | 456 | .suspend = s3c24xx_i2s_suspend, |
| 457 | .resume = s3c24xx_i2s_resume, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 458 | .playback = { |
| 459 | .channels_min = 2, |
| 460 | .channels_max = 2, |
| 461 | .rates = S3C24XX_I2S_RATES, |
| 462 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,}, |
| 463 | .capture = { |
| 464 | .channels_min = 2, |
| 465 | .channels_max = 2, |
| 466 | .rates = S3C24XX_I2S_RATES, |
| 467 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 468 | .ops = &s3c24xx_i2s_dai_ops, |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 469 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 470 | |
| 471 | static __devinit int s3c24xx_iis_dev_probe(struct platform_device *pdev) |
| 472 | { |
| 473 | return snd_soc_register_dai(&pdev->dev, &s3c24xx_i2s_dai); |
| 474 | } |
| 475 | |
| 476 | static __devexit int s3c24xx_iis_dev_remove(struct platform_device *pdev) |
| 477 | { |
| 478 | snd_soc_unregister_dai(&pdev->dev); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static struct platform_driver s3c24xx_iis_driver = { |
| 483 | .probe = s3c24xx_iis_dev_probe, |
| 484 | .remove = s3c24xx_iis_dev_remove, |
| 485 | .driver = { |
| 486 | .name = "s3c24xx-iis", |
| 487 | .owner = THIS_MODULE, |
| 488 | }, |
| 489 | }; |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 490 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 491 | static int __init s3c24xx_i2s_init(void) |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 492 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 493 | return platform_driver_register(&s3c24xx_iis_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 494 | } |
| 495 | module_init(s3c24xx_i2s_init); |
| 496 | |
| 497 | static void __exit s3c24xx_i2s_exit(void) |
| 498 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 499 | platform_driver_unregister(&s3c24xx_iis_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 500 | } |
| 501 | module_exit(s3c24xx_i2s_exit); |
| 502 | |
Ben Dooks | c1422a6 | 2007-02-14 13:17:49 +0100 | [diff] [blame] | 503 | /* Module information */ |
| 504 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
| 505 | MODULE_DESCRIPTION("s3c24xx I2S SoC Interface"); |
| 506 | MODULE_LICENSE("GPL"); |
Mark Brown | 960d069 | 2010-08-12 11:02:19 +0100 | [diff] [blame] | 507 | MODULE_ALIAS("platform:s3c24xx-iis"); |