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