Jassi Brar | 5033f43 | 2010-11-22 15:37:25 +0900 | [diff] [blame] | 1 | /* sound/soc/samsung/s3c-i2c-v2.c |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 2 | * |
| 3 | * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs. |
| 4 | * |
| 5 | * Copyright (c) 2006 Wolfson Microelectronics PLC. |
| 6 | * Graeme Gregory graeme.gregory@wolfsonmicro.com |
| 7 | * linux@wolfsonmicro.com |
| 8 | * |
| 9 | * Copyright (c) 2008, 2007, 2004-2005 Simtec Electronics |
| 10 | * http://armlinux.simtec.co.uk/ |
| 11 | * Ben Dooks <ben@simtec.co.uk> |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms of the GNU General Public License as published by the |
| 15 | * Free Software Foundation; either version 2 of the License, or (at your |
| 16 | * option) any later version. |
| 17 | */ |
| 18 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <linux/clk.h> |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 21 | #include <linux/io.h> |
| 22 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 23 | #include <sound/pcm.h> |
| 24 | #include <sound/pcm_params.h> |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 25 | #include <sound/soc.h> |
| 26 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 27 | #include <mach/dma.h> |
| 28 | |
Jassi Brar | d07e7ce | 2010-04-27 15:55:21 +0900 | [diff] [blame] | 29 | #include "regs-i2s-v2.h" |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 30 | #include "s3c-i2s-v2.h" |
Jassi Brar | 4b640cf | 2010-11-22 15:35:57 +0900 | [diff] [blame] | 31 | #include "dma.h" |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 32 | |
Mark Brown | 8a0f62b | 2009-04-29 20:28:47 +0100 | [diff] [blame] | 33 | #undef S3C_IIS_V2_SUPPORTED |
| 34 | |
Chanwoo Choi | 5c51976 | 2010-07-20 14:28:30 +0900 | [diff] [blame] | 35 | #if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413) \ |
| 36 | || defined(CONFIG_CPU_S5PV210) |
Mark Brown | 8a0f62b | 2009-04-29 20:28:47 +0100 | [diff] [blame] | 37 | #define S3C_IIS_V2_SUPPORTED |
| 38 | #endif |
| 39 | |
| 40 | #ifdef CONFIG_PLAT_S3C64XX |
| 41 | #define S3C_IIS_V2_SUPPORTED |
| 42 | #endif |
| 43 | |
| 44 | #ifndef S3C_IIS_V2_SUPPORTED |
| 45 | #error Unsupported CPU model |
| 46 | #endif |
| 47 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 48 | #define S3C2412_I2S_DEBUG_CON 0 |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 49 | |
| 50 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) |
| 51 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 52 | return snd_soc_dai_get_drvdata(cpu_dai); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #define bit_set(v, b) (((v) & (b)) ? 1 : 0) |
| 56 | |
| 57 | #if S3C2412_I2S_DEBUG_CON |
| 58 | static void dbg_showcon(const char *fn, u32 con) |
| 59 | { |
| 60 | printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn, |
| 61 | bit_set(con, S3C2412_IISCON_LRINDEX), |
| 62 | bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY), |
| 63 | bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY), |
| 64 | bit_set(con, S3C2412_IISCON_TXFIFO_FULL), |
| 65 | bit_set(con, S3C2412_IISCON_RXFIFO_FULL)); |
| 66 | |
| 67 | printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n", |
| 68 | fn, |
| 69 | bit_set(con, S3C2412_IISCON_TXDMA_PAUSE), |
| 70 | bit_set(con, S3C2412_IISCON_RXDMA_PAUSE), |
| 71 | bit_set(con, S3C2412_IISCON_TXCH_PAUSE), |
| 72 | bit_set(con, S3C2412_IISCON_RXCH_PAUSE)); |
| 73 | printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn, |
| 74 | bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE), |
| 75 | bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE), |
| 76 | bit_set(con, S3C2412_IISCON_IIS_ACTIVE)); |
| 77 | } |
| 78 | #else |
| 79 | static inline void dbg_showcon(const char *fn, u32 con) |
| 80 | { |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | |
| 85 | /* Turn on or off the transmission path. */ |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 86 | static void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on) |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 87 | { |
| 88 | void __iomem *regs = i2s->regs; |
| 89 | u32 fic, con, mod; |
| 90 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 91 | pr_debug("%s(%d)\n", __func__, on); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 92 | |
| 93 | fic = readl(regs + S3C2412_IISFIC); |
| 94 | con = readl(regs + S3C2412_IISCON); |
| 95 | mod = readl(regs + S3C2412_IISMOD); |
| 96 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 97 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 98 | |
| 99 | if (on) { |
| 100 | con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE; |
| 101 | con &= ~S3C2412_IISCON_TXDMA_PAUSE; |
| 102 | con &= ~S3C2412_IISCON_TXCH_PAUSE; |
| 103 | |
| 104 | switch (mod & S3C2412_IISMOD_MODE_MASK) { |
| 105 | case S3C2412_IISMOD_MODE_TXONLY: |
| 106 | case S3C2412_IISMOD_MODE_TXRX: |
| 107 | /* do nothing, we are in the right mode */ |
| 108 | break; |
| 109 | |
| 110 | case S3C2412_IISMOD_MODE_RXONLY: |
| 111 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 112 | mod |= S3C2412_IISMOD_MODE_TXRX; |
| 113 | break; |
| 114 | |
| 115 | default: |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 116 | dev_err(i2s->dev, "TXEN: Invalid MODE %x in IISMOD\n", |
| 117 | mod & S3C2412_IISMOD_MODE_MASK); |
| 118 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | writel(con, regs + S3C2412_IISCON); |
| 122 | writel(mod, regs + S3C2412_IISMOD); |
| 123 | } else { |
| 124 | /* Note, we do not have any indication that the FIFO problems |
| 125 | * tha the S3C2410/2440 had apply here, so we should be able |
| 126 | * to disable the DMA and TX without resetting the FIFOS. |
| 127 | */ |
| 128 | |
| 129 | con |= S3C2412_IISCON_TXDMA_PAUSE; |
| 130 | con |= S3C2412_IISCON_TXCH_PAUSE; |
| 131 | con &= ~S3C2412_IISCON_TXDMA_ACTIVE; |
| 132 | |
| 133 | switch (mod & S3C2412_IISMOD_MODE_MASK) { |
| 134 | case S3C2412_IISMOD_MODE_TXRX: |
| 135 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 136 | mod |= S3C2412_IISMOD_MODE_RXONLY; |
| 137 | break; |
| 138 | |
| 139 | case S3C2412_IISMOD_MODE_TXONLY: |
| 140 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 141 | con &= ~S3C2412_IISCON_IIS_ACTIVE; |
| 142 | break; |
| 143 | |
| 144 | default: |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 145 | dev_err(i2s->dev, "TXDIS: Invalid MODE %x in IISMOD\n", |
| 146 | mod & S3C2412_IISMOD_MODE_MASK); |
| 147 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | writel(mod, regs + S3C2412_IISMOD); |
| 151 | writel(con, regs + S3C2412_IISCON); |
| 152 | } |
| 153 | |
| 154 | fic = readl(regs + S3C2412_IISFIC); |
| 155 | dbg_showcon(__func__, con); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 156 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 157 | } |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 158 | |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 159 | static void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on) |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 160 | { |
| 161 | void __iomem *regs = i2s->regs; |
| 162 | u32 fic, con, mod; |
| 163 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 164 | pr_debug("%s(%d)\n", __func__, on); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 165 | |
| 166 | fic = readl(regs + S3C2412_IISFIC); |
| 167 | con = readl(regs + S3C2412_IISCON); |
| 168 | mod = readl(regs + S3C2412_IISMOD); |
| 169 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 170 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 171 | |
| 172 | if (on) { |
| 173 | con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE; |
| 174 | con &= ~S3C2412_IISCON_RXDMA_PAUSE; |
| 175 | con &= ~S3C2412_IISCON_RXCH_PAUSE; |
| 176 | |
| 177 | switch (mod & S3C2412_IISMOD_MODE_MASK) { |
| 178 | case S3C2412_IISMOD_MODE_TXRX: |
| 179 | case S3C2412_IISMOD_MODE_RXONLY: |
| 180 | /* do nothing, we are in the right mode */ |
| 181 | break; |
| 182 | |
| 183 | case S3C2412_IISMOD_MODE_TXONLY: |
| 184 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 185 | mod |= S3C2412_IISMOD_MODE_TXRX; |
| 186 | break; |
| 187 | |
| 188 | default: |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 189 | dev_err(i2s->dev, "RXEN: Invalid MODE %x in IISMOD\n", |
| 190 | mod & S3C2412_IISMOD_MODE_MASK); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | writel(mod, regs + S3C2412_IISMOD); |
| 194 | writel(con, regs + S3C2412_IISCON); |
| 195 | } else { |
| 196 | /* See txctrl notes on FIFOs. */ |
| 197 | |
| 198 | con &= ~S3C2412_IISCON_RXDMA_ACTIVE; |
| 199 | con |= S3C2412_IISCON_RXDMA_PAUSE; |
| 200 | con |= S3C2412_IISCON_RXCH_PAUSE; |
| 201 | |
| 202 | switch (mod & S3C2412_IISMOD_MODE_MASK) { |
| 203 | case S3C2412_IISMOD_MODE_RXONLY: |
| 204 | con &= ~S3C2412_IISCON_IIS_ACTIVE; |
| 205 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 206 | break; |
| 207 | |
| 208 | case S3C2412_IISMOD_MODE_TXRX: |
| 209 | mod &= ~S3C2412_IISMOD_MODE_MASK; |
| 210 | mod |= S3C2412_IISMOD_MODE_TXONLY; |
| 211 | break; |
| 212 | |
| 213 | default: |
Mark Brown | abbc8246 | 2009-04-30 13:21:52 +0100 | [diff] [blame] | 214 | dev_err(i2s->dev, "RXDIS: Invalid MODE %x in IISMOD\n", |
| 215 | mod & S3C2412_IISMOD_MODE_MASK); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | writel(con, regs + S3C2412_IISCON); |
| 219 | writel(mod, regs + S3C2412_IISMOD); |
| 220 | } |
| 221 | |
| 222 | fic = readl(regs + S3C2412_IISFIC); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 223 | pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 224 | } |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 225 | |
Jassi | fa68e00 | 2009-09-15 19:02:37 +0900 | [diff] [blame] | 226 | #define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t) |
| 227 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 228 | /* |
| 229 | * Wait for the LR signal to allow synchronisation to the L/R clock |
| 230 | * from the codec. May only be needed for slave mode. |
| 231 | */ |
| 232 | static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s) |
| 233 | { |
| 234 | u32 iiscon; |
Jassi | fa68e00 | 2009-09-15 19:02:37 +0900 | [diff] [blame] | 235 | unsigned long loops = msecs_to_loops(5); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 236 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 237 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 238 | |
Jassi | fa68e00 | 2009-09-15 19:02:37 +0900 | [diff] [blame] | 239 | while (--loops) { |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 240 | iiscon = readl(i2s->regs + S3C2412_IISCON); |
| 241 | if (iiscon & S3C2412_IISCON_LRINDEX) |
| 242 | break; |
| 243 | |
Jassi | fa68e00 | 2009-09-15 19:02:37 +0900 | [diff] [blame] | 244 | cpu_relax(); |
| 245 | } |
| 246 | |
| 247 | if (!loops) { |
| 248 | printk(KERN_ERR "%s: timeout\n", __func__); |
| 249 | return -ETIMEDOUT; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * Set S3C2412 I2S DAI format |
| 257 | */ |
| 258 | static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
| 259 | unsigned int fmt) |
| 260 | { |
| 261 | struct s3c_i2sv2_info *i2s = to_info(cpu_dai); |
| 262 | u32 iismod; |
| 263 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 264 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 265 | |
| 266 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 267 | pr_debug("hw_params r: IISMOD: %x \n", iismod); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 268 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 269 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 270 | case SND_SOC_DAIFMT_CBM_CFM: |
| 271 | i2s->master = 0; |
Jassi Brar | ce76f9f | 2010-04-27 15:56:27 +0900 | [diff] [blame] | 272 | iismod |= S3C2412_IISMOD_SLAVE; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 273 | break; |
| 274 | case SND_SOC_DAIFMT_CBS_CFS: |
| 275 | i2s->master = 1; |
Jassi Brar | ce76f9f | 2010-04-27 15:56:27 +0900 | [diff] [blame] | 276 | iismod &= ~S3C2412_IISMOD_SLAVE; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 277 | break; |
| 278 | default: |
Mark Brown | 38e43c8 | 2009-04-30 13:14:38 +0100 | [diff] [blame] | 279 | pr_err("unknwon master/slave format\n"); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 280 | return -EINVAL; |
| 281 | } |
| 282 | |
| 283 | iismod &= ~S3C2412_IISMOD_SDF_MASK; |
| 284 | |
| 285 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 286 | case SND_SOC_DAIFMT_RIGHT_J: |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 287 | iismod |= S3C2412_IISMOD_LR_RLOW; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 288 | iismod |= S3C2412_IISMOD_SDF_MSB; |
| 289 | break; |
| 290 | case SND_SOC_DAIFMT_LEFT_J: |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 291 | iismod |= S3C2412_IISMOD_LR_RLOW; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 292 | iismod |= S3C2412_IISMOD_SDF_LSB; |
| 293 | break; |
| 294 | case SND_SOC_DAIFMT_I2S: |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 295 | iismod &= ~S3C2412_IISMOD_LR_RLOW; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 296 | iismod |= S3C2412_IISMOD_SDF_IIS; |
| 297 | break; |
| 298 | default: |
Mark Brown | 38e43c8 | 2009-04-30 13:14:38 +0100 | [diff] [blame] | 299 | pr_err("Unknown data format\n"); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 300 | return -EINVAL; |
| 301 | } |
| 302 | |
| 303 | writel(iismod, i2s->regs + S3C2412_IISMOD); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 304 | pr_debug("hw_params w: IISMOD: %x \n", iismod); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 305 | return 0; |
| 306 | } |
| 307 | |
Jassi Brar | 9c9b125 | 2010-03-10 16:48:58 +0900 | [diff] [blame] | 308 | static int s3c_i2sv2_hw_params(struct snd_pcm_substream *substream, |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 309 | struct snd_pcm_hw_params *params, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 310 | struct snd_soc_dai *dai) |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 311 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 312 | struct s3c_i2sv2_info *i2s = to_info(dai); |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 313 | struct s3c_dma_params *dma_data; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 314 | u32 iismod; |
| 315 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 316 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 317 | |
| 318 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 319 | dma_data = i2s->dma_playback; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 320 | else |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 321 | dma_data = i2s->dma_capture; |
| 322 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 323 | snd_soc_dai_set_dma_data(dai, substream, dma_data); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 324 | |
| 325 | /* Working copies of register */ |
| 326 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 327 | pr_debug("%s: r: IISMOD: %x\n", __func__, iismod); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 328 | |
Jassi Brar | bf32882 | 2010-03-10 16:48:52 +0900 | [diff] [blame] | 329 | iismod &= ~S3C64XX_IISMOD_BLC_MASK; |
Mark Brown | 553b1dd | 2009-04-29 20:29:25 +0100 | [diff] [blame] | 330 | /* Sample size */ |
| 331 | switch (params_format(params)) { |
| 332 | case SNDRV_PCM_FORMAT_S8: |
Jassi Brar | bf32882 | 2010-03-10 16:48:52 +0900 | [diff] [blame] | 333 | iismod |= S3C64XX_IISMOD_BLC_8BIT; |
Mark Brown | 553b1dd | 2009-04-29 20:29:25 +0100 | [diff] [blame] | 334 | break; |
| 335 | case SNDRV_PCM_FORMAT_S16_LE: |
Mark Brown | 553b1dd | 2009-04-29 20:29:25 +0100 | [diff] [blame] | 336 | break; |
| 337 | case SNDRV_PCM_FORMAT_S24_LE: |
Jassi Brar | bf32882 | 2010-03-10 16:48:52 +0900 | [diff] [blame] | 338 | iismod |= S3C64XX_IISMOD_BLC_24BIT; |
Mark Brown | 553b1dd | 2009-04-29 20:29:25 +0100 | [diff] [blame] | 339 | break; |
| 340 | } |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 341 | |
| 342 | writel(iismod, i2s->regs + S3C2412_IISMOD); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 343 | pr_debug("%s: w: IISMOD: %x\n", __func__, iismod); |
Jassi Brar | 8a7c251 | 2010-04-27 15:57:05 +0900 | [diff] [blame] | 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | static int s3c_i2sv2_set_sysclk(struct snd_soc_dai *cpu_dai, |
| 349 | int clk_id, unsigned int freq, int dir) |
| 350 | { |
| 351 | struct s3c_i2sv2_info *i2s = to_info(cpu_dai); |
| 352 | u32 iismod = readl(i2s->regs + S3C2412_IISMOD); |
| 353 | |
| 354 | pr_debug("Entered %s\n", __func__); |
| 355 | pr_debug("%s r: IISMOD: %x\n", __func__, iismod); |
| 356 | |
| 357 | switch (clk_id) { |
| 358 | case S3C_I2SV2_CLKSRC_PCLK: |
| 359 | iismod &= ~S3C2412_IISMOD_IMS_SYSMUX; |
| 360 | break; |
| 361 | |
| 362 | case S3C_I2SV2_CLKSRC_AUDIOBUS: |
| 363 | iismod |= S3C2412_IISMOD_IMS_SYSMUX; |
| 364 | break; |
| 365 | |
| 366 | case S3C_I2SV2_CLKSRC_CDCLK: |
| 367 | /* Error if controller doesn't have the CDCLKCON bit */ |
| 368 | if (!(i2s->feature & S3C_FEATURE_CDCLKCON)) |
| 369 | return -EINVAL; |
| 370 | |
| 371 | switch (dir) { |
| 372 | case SND_SOC_CLOCK_IN: |
| 373 | iismod |= S3C64XX_IISMOD_CDCLKCON; |
| 374 | break; |
| 375 | case SND_SOC_CLOCK_OUT: |
| 376 | iismod &= ~S3C64XX_IISMOD_CDCLKCON; |
| 377 | break; |
| 378 | default: |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | break; |
| 382 | |
| 383 | default: |
| 384 | return -EINVAL; |
| 385 | } |
| 386 | |
| 387 | writel(iismod, i2s->regs + S3C2412_IISMOD); |
| 388 | pr_debug("%s w: IISMOD: %x\n", __func__, iismod); |
| 389 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 394 | struct snd_soc_dai *dai) |
| 395 | { |
| 396 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 397 | struct s3c_i2sv2_info *i2s = to_info(rtd->cpu_dai); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 398 | int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE); |
| 399 | unsigned long irqs; |
| 400 | int ret = 0; |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 401 | struct s3c_dma_params *dma_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 402 | snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 403 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 404 | pr_debug("Entered %s\n", __func__); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 405 | |
| 406 | switch (cmd) { |
| 407 | case SNDRV_PCM_TRIGGER_START: |
| 408 | /* On start, ensure that the FIFOs are cleared and reset. */ |
| 409 | |
| 410 | writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH, |
| 411 | i2s->regs + S3C2412_IISFIC); |
| 412 | |
| 413 | /* clear again, just in case */ |
| 414 | writel(0x0, i2s->regs + S3C2412_IISFIC); |
| 415 | |
| 416 | case SNDRV_PCM_TRIGGER_RESUME: |
| 417 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 418 | if (!i2s->master) { |
| 419 | ret = s3c2412_snd_lrsync(i2s); |
| 420 | if (ret) |
| 421 | goto exit_err; |
| 422 | } |
| 423 | |
| 424 | local_irq_save(irqs); |
| 425 | |
| 426 | if (capture) |
| 427 | s3c2412_snd_rxctrl(i2s, 1); |
| 428 | else |
| 429 | s3c2412_snd_txctrl(i2s, 1); |
| 430 | |
| 431 | local_irq_restore(irqs); |
Shine Liu | faf907c | 2009-08-25 20:05:50 +0800 | [diff] [blame] | 432 | |
| 433 | /* |
| 434 | * Load the next buffer to DMA to meet the reqirement |
| 435 | * of the auto reload mechanism of S3C24XX. |
| 436 | * This call won't bother S3C64XX. |
| 437 | */ |
Daniel Mack | fd23b7d | 2010-03-19 14:52:55 +0000 | [diff] [blame] | 438 | s3c2410_dma_ctrl(dma_data->channel, S3C2410_DMAOP_STARTED); |
Shine Liu | faf907c | 2009-08-25 20:05:50 +0800 | [diff] [blame] | 439 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 440 | break; |
| 441 | |
| 442 | case SNDRV_PCM_TRIGGER_STOP: |
| 443 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 444 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 445 | local_irq_save(irqs); |
| 446 | |
| 447 | if (capture) |
| 448 | s3c2412_snd_rxctrl(i2s, 0); |
| 449 | else |
| 450 | s3c2412_snd_txctrl(i2s, 0); |
| 451 | |
| 452 | local_irq_restore(irqs); |
| 453 | break; |
| 454 | default: |
| 455 | ret = -EINVAL; |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | exit_err: |
| 460 | return ret; |
| 461 | } |
| 462 | |
| 463 | /* |
| 464 | * Set S3C2412 Clock dividers |
| 465 | */ |
| 466 | static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai, |
| 467 | int div_id, int div) |
| 468 | { |
| 469 | struct s3c_i2sv2_info *i2s = to_info(cpu_dai); |
| 470 | u32 reg; |
| 471 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 472 | pr_debug("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 473 | |
| 474 | switch (div_id) { |
| 475 | case S3C_I2SV2_DIV_BCLK: |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 476 | switch (div) { |
| 477 | case 16: |
| 478 | div = S3C2412_IISMOD_BCLK_16FS; |
| 479 | break; |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 480 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 481 | case 32: |
| 482 | div = S3C2412_IISMOD_BCLK_32FS; |
| 483 | break; |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 484 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 485 | case 24: |
| 486 | div = S3C2412_IISMOD_BCLK_24FS; |
| 487 | break; |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 488 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 489 | case 48: |
| 490 | div = S3C2412_IISMOD_BCLK_48FS; |
| 491 | break; |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 492 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 493 | default: |
| 494 | return -EINVAL; |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 495 | } |
| 496 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 497 | reg = readl(i2s->regs + S3C2412_IISMOD); |
| 498 | reg &= ~S3C2412_IISMOD_BCLK_MASK; |
| 499 | writel(reg | div, i2s->regs + S3C2412_IISMOD); |
| 500 | |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 501 | pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD)); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 502 | break; |
| 503 | |
| 504 | case S3C_I2SV2_DIV_RCLK: |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 505 | switch (div) { |
| 506 | case 256: |
| 507 | div = S3C2412_IISMOD_RCLK_256FS; |
| 508 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 509 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 510 | case 384: |
| 511 | div = S3C2412_IISMOD_RCLK_384FS; |
| 512 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 513 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 514 | case 512: |
| 515 | div = S3C2412_IISMOD_RCLK_512FS; |
| 516 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 517 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 518 | case 768: |
| 519 | div = S3C2412_IISMOD_RCLK_768FS; |
| 520 | break; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 521 | |
Jassi Brar | 51c6ab1 | 2010-03-10 16:48:51 +0900 | [diff] [blame] | 522 | default: |
| 523 | return -EINVAL; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | reg = readl(i2s->regs + S3C2412_IISMOD); |
| 527 | reg &= ~S3C2412_IISMOD_RCLK_MASK; |
| 528 | writel(reg | div, i2s->regs + S3C2412_IISMOD); |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 529 | pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD)); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 530 | break; |
| 531 | |
| 532 | case S3C_I2SV2_DIV_PRESCALER: |
| 533 | if (div >= 0) { |
| 534 | writel((div << 8) | S3C2412_IISPSR_PSREN, |
| 535 | i2s->regs + S3C2412_IISPSR); |
| 536 | } else { |
| 537 | writel(0x0, i2s->regs + S3C2412_IISPSR); |
| 538 | } |
Mark Brown | ee7d476 | 2009-03-06 18:04:34 +0000 | [diff] [blame] | 539 | pr_debug("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR)); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 540 | break; |
| 541 | |
| 542 | default: |
| 543 | return -EINVAL; |
| 544 | } |
| 545 | |
| 546 | return 0; |
| 547 | } |
| 548 | |
Mark Brown | 1ca7578 | 2010-03-04 14:54:40 +0000 | [diff] [blame] | 549 | static snd_pcm_sframes_t s3c2412_i2s_delay(struct snd_pcm_substream *substream, |
| 550 | struct snd_soc_dai *dai) |
| 551 | { |
| 552 | struct s3c_i2sv2_info *i2s = to_info(dai); |
| 553 | u32 reg = readl(i2s->regs + S3C2412_IISFIC); |
| 554 | snd_pcm_sframes_t delay; |
| 555 | |
| 556 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 557 | delay = S3C2412_IISFIC_TXCOUNT(reg); |
| 558 | else |
| 559 | delay = S3C2412_IISFIC_RXCOUNT(reg); |
| 560 | |
| 561 | return delay; |
| 562 | } |
| 563 | |
Jassi Brar | 5728242 | 2010-04-27 15:56:45 +0900 | [diff] [blame] | 564 | struct clk *s3c_i2sv2_get_clock(struct snd_soc_dai *cpu_dai) |
| 565 | { |
| 566 | struct s3c_i2sv2_info *i2s = to_info(cpu_dai); |
| 567 | u32 iismod = readl(i2s->regs + S3C2412_IISMOD); |
| 568 | |
| 569 | if (iismod & S3C2412_IISMOD_IMS_SYSMUX) |
| 570 | return i2s->iis_cclk; |
| 571 | else |
| 572 | return i2s->iis_pclk; |
| 573 | } |
| 574 | EXPORT_SYMBOL_GPL(s3c_i2sv2_get_clock); |
| 575 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 576 | /* default table of all avaialable root fs divisors */ |
| 577 | static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 }; |
| 578 | |
Ben Dooks | 1d2b7ae | 2009-04-16 10:32:23 +0100 | [diff] [blame] | 579 | int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info, |
| 580 | unsigned int *fstab, |
| 581 | unsigned int rate, struct clk *clk) |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 582 | { |
| 583 | unsigned long clkrate = clk_get_rate(clk); |
| 584 | unsigned int div; |
| 585 | unsigned int fsclk; |
| 586 | unsigned int actual; |
| 587 | unsigned int fs; |
| 588 | unsigned int fsdiv; |
| 589 | signed int deviation = 0; |
| 590 | unsigned int best_fs = 0; |
| 591 | unsigned int best_div = 0; |
| 592 | unsigned int best_rate = 0; |
| 593 | unsigned int best_deviation = INT_MAX; |
| 594 | |
Mark Brown | af3ea7b | 2009-04-30 13:13:55 +0100 | [diff] [blame] | 595 | pr_debug("Input clock rate %ldHz\n", clkrate); |
| 596 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 597 | if (fstab == NULL) |
| 598 | fstab = iis_fs_tab; |
| 599 | |
| 600 | for (fs = 0; fs < ARRAY_SIZE(iis_fs_tab); fs++) { |
| 601 | fsdiv = iis_fs_tab[fs]; |
| 602 | |
| 603 | fsclk = clkrate / fsdiv; |
| 604 | div = fsclk / rate; |
| 605 | |
| 606 | if ((fsclk % rate) > (rate / 2)) |
| 607 | div++; |
| 608 | |
| 609 | if (div <= 1) |
| 610 | continue; |
| 611 | |
| 612 | actual = clkrate / (fsdiv * div); |
| 613 | deviation = actual - rate; |
| 614 | |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 615 | printk(KERN_DEBUG "%ufs: div %u => result %u, deviation %d\n", |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 616 | fsdiv, div, actual, deviation); |
| 617 | |
| 618 | deviation = abs(deviation); |
| 619 | |
| 620 | if (deviation < best_deviation) { |
| 621 | best_fs = fsdiv; |
| 622 | best_div = div; |
| 623 | best_rate = actual; |
| 624 | best_deviation = deviation; |
| 625 | } |
| 626 | |
| 627 | if (deviation == 0) |
| 628 | break; |
| 629 | } |
| 630 | |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 631 | printk(KERN_DEBUG "best: fs=%u, div=%u, rate=%u\n", |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 632 | best_fs, best_div, best_rate); |
| 633 | |
| 634 | info->fs_div = best_fs; |
| 635 | info->clk_div = best_div; |
| 636 | |
| 637 | return 0; |
| 638 | } |
Ben Dooks | 1d2b7ae | 2009-04-16 10:32:23 +0100 | [diff] [blame] | 639 | EXPORT_SYMBOL_GPL(s3c_i2sv2_iis_calc_rate); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 640 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 641 | int s3c_i2sv2_probe(struct snd_soc_dai *dai, |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 642 | struct s3c_i2sv2_info *i2s, |
| 643 | unsigned long base) |
| 644 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 645 | struct device *dev = dai->dev; |
Mark Brown | 07736d4 | 2009-04-30 13:13:14 +0100 | [diff] [blame] | 646 | unsigned int iismod; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 647 | |
| 648 | i2s->dev = dev; |
| 649 | |
| 650 | /* record our i2s structure for later use in the callbacks */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 651 | snd_soc_dai_set_drvdata(dai, i2s); |
Mark Brown | c86bde5 | 2009-04-30 13:09:33 +0100 | [diff] [blame] | 652 | |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 653 | i2s->regs = ioremap(base, 0x100); |
| 654 | if (i2s->regs == NULL) { |
| 655 | dev_err(dev, "cannot ioremap registers\n"); |
| 656 | return -ENXIO; |
| 657 | } |
| 658 | |
| 659 | i2s->iis_pclk = clk_get(dev, "iis"); |
Jassi | fd5ad65 | 2009-09-15 19:02:38 +0900 | [diff] [blame] | 660 | if (IS_ERR(i2s->iis_pclk)) { |
Mark Brown | b52a519 | 2009-03-06 18:13:43 +0000 | [diff] [blame] | 661 | dev_err(dev, "failed to get iis_clock\n"); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 662 | iounmap(i2s->regs); |
| 663 | return -ENOENT; |
| 664 | } |
| 665 | |
| 666 | clk_enable(i2s->iis_pclk); |
| 667 | |
Mark Brown | 07736d4 | 2009-04-30 13:13:14 +0100 | [diff] [blame] | 668 | /* Mark ourselves as in TXRX mode so we can run through our cleanup |
| 669 | * process without warnings. */ |
| 670 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
| 671 | iismod |= S3C2412_IISMOD_MODE_TXRX; |
| 672 | writel(iismod, i2s->regs + S3C2412_IISMOD); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 673 | s3c2412_snd_txctrl(i2s, 0); |
| 674 | s3c2412_snd_rxctrl(i2s, 0); |
| 675 | |
| 676 | return 0; |
| 677 | } |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 678 | EXPORT_SYMBOL_GPL(s3c_i2sv2_probe); |
| 679 | |
| 680 | #ifdef CONFIG_PM |
| 681 | static int s3c2412_i2s_suspend(struct snd_soc_dai *dai) |
| 682 | { |
| 683 | struct s3c_i2sv2_info *i2s = to_info(dai); |
| 684 | u32 iismod; |
| 685 | |
| 686 | if (dai->active) { |
| 687 | i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD); |
| 688 | i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON); |
| 689 | i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR); |
| 690 | |
| 691 | /* some basic suspend checks */ |
| 692 | |
| 693 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
| 694 | |
| 695 | if (iismod & S3C2412_IISCON_RXDMA_ACTIVE) |
| 696 | pr_warning("%s: RXDMA active?\n", __func__); |
| 697 | |
| 698 | if (iismod & S3C2412_IISCON_TXDMA_ACTIVE) |
| 699 | pr_warning("%s: TXDMA active?\n", __func__); |
| 700 | |
| 701 | if (iismod & S3C2412_IISCON_IIS_ACTIVE) |
| 702 | pr_warning("%s: IIS active\n", __func__); |
| 703 | } |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | static int s3c2412_i2s_resume(struct snd_soc_dai *dai) |
| 709 | { |
| 710 | struct s3c_i2sv2_info *i2s = to_info(dai); |
| 711 | |
| 712 | pr_info("dai_active %d, IISMOD %08x, IISCON %08x\n", |
| 713 | dai->active, i2s->suspend_iismod, i2s->suspend_iiscon); |
| 714 | |
| 715 | if (dai->active) { |
| 716 | writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON); |
| 717 | writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD); |
| 718 | writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR); |
| 719 | |
| 720 | writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH, |
| 721 | i2s->regs + S3C2412_IISFIC); |
| 722 | |
| 723 | ndelay(250); |
| 724 | writel(0x0, i2s->regs + S3C2412_IISFIC); |
| 725 | } |
| 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | #else |
| 730 | #define s3c2412_i2s_suspend NULL |
| 731 | #define s3c2412_i2s_resume NULL |
| 732 | #endif |
| 733 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 734 | int s3c_i2sv2_register_dai(struct device *dev, int id, |
| 735 | struct snd_soc_dai_driver *drv) |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 736 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 737 | struct snd_soc_dai_ops *ops = drv->ops; |
Ben Dooks | 3715c6a | 2009-04-16 10:32:22 +0100 | [diff] [blame] | 738 | |
| 739 | ops->trigger = s3c2412_i2s_trigger; |
Jassi Brar | 9c9b125 | 2010-03-10 16:48:58 +0900 | [diff] [blame] | 740 | if (!ops->hw_params) |
| 741 | ops->hw_params = s3c_i2sv2_hw_params; |
Ben Dooks | 3715c6a | 2009-04-16 10:32:22 +0100 | [diff] [blame] | 742 | ops->set_fmt = s3c2412_i2s_set_fmt; |
| 743 | ops->set_clkdiv = s3c2412_i2s_set_clkdiv; |
Jassi Brar | 8a7c251 | 2010-04-27 15:57:05 +0900 | [diff] [blame] | 744 | ops->set_sysclk = s3c_i2sv2_set_sysclk; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 745 | |
Mark Brown | 1ca7578 | 2010-03-04 14:54:40 +0000 | [diff] [blame] | 746 | /* Allow overriding by (for example) IISv4 */ |
| 747 | if (!ops->delay) |
Jassi Brar | 0822661 | 2010-03-10 16:48:50 +0900 | [diff] [blame] | 748 | ops->delay = s3c2412_i2s_delay; |
Mark Brown | 1ca7578 | 2010-03-04 14:54:40 +0000 | [diff] [blame] | 749 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 750 | drv->suspend = s3c2412_i2s_suspend; |
| 751 | drv->resume = s3c2412_i2s_resume; |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 752 | |
Chanwoo Choi | 3782a52 | 2010-07-21 08:06:56 +0900 | [diff] [blame] | 753 | return snd_soc_register_dai(dev, drv); |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 754 | } |
Ben Dooks | dc85447 | 2009-03-04 00:49:30 +0000 | [diff] [blame] | 755 | EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai); |
Mark Brown | a396e32 | 2009-04-23 15:43:45 +0100 | [diff] [blame] | 756 | |
| 757 | MODULE_LICENSE("GPL"); |