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