Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC McASP Audio Layer for TI DAVINCI processor |
| 3 | * |
| 4 | * Multi-channel Audio Serial Port Driver |
| 5 | * |
| 6 | * Author: Nirmal Pandey <n-pandey@ti.com>, |
| 7 | * Suresh Rajashekara <suresh.r@ti.com> |
| 8 | * Steve Chen <schen@.mvista.com> |
| 9 | * |
| 10 | * Copyright: (C) 2009 MontaVista Software, Inc., <source@mvista.com> |
| 11 | * Copyright: (C) 2009 Texas Instruments, India |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License version 2 as |
| 15 | * published by the Free Software Foundation. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/device.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 22 | #include <linux/delay.h> |
| 23 | #include <linux/io.h> |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 24 | #include <linux/pm_runtime.h> |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_platform.h> |
| 27 | #include <linux/of_device.h> |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 28 | |
| 29 | #include <sound/core.h> |
| 30 | #include <sound/pcm.h> |
| 31 | #include <sound/pcm_params.h> |
| 32 | #include <sound/initval.h> |
| 33 | #include <sound/soc.h> |
| 34 | |
| 35 | #include "davinci-pcm.h" |
| 36 | #include "davinci-mcasp.h" |
| 37 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 38 | #define DAVINCI_MCASP_NUM_SERIALIZER 16 |
| 39 | |
Peter Ujfalusi | 21400a7 | 2013-11-14 11:35:26 +0200 | [diff] [blame^] | 40 | struct davinci_audio_dev { |
| 41 | struct davinci_pcm_dma_params dma_params[2]; |
| 42 | void __iomem *base; |
| 43 | struct device *dev; |
| 44 | |
| 45 | /* McASP specific data */ |
| 46 | int tdm_slots; |
| 47 | u8 op_mode; |
| 48 | u8 num_serializer; |
| 49 | u8 *serial_dir; |
| 50 | u8 version; |
| 51 | u16 bclk_lrclk_ratio; |
| 52 | |
| 53 | /* McASP FIFO related */ |
| 54 | u8 txnumevt; |
| 55 | u8 rxnumevt; |
| 56 | |
| 57 | #ifdef CONFIG_PM_SLEEP |
| 58 | struct { |
| 59 | u32 txfmtctl; |
| 60 | u32 rxfmtctl; |
| 61 | u32 txfmt; |
| 62 | u32 rxfmt; |
| 63 | u32 aclkxctl; |
| 64 | u32 aclkrctl; |
| 65 | u32 pdir; |
| 66 | } context; |
| 67 | #endif |
| 68 | }; |
| 69 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 70 | static inline void mcasp_set_bits(void __iomem *reg, u32 val) |
| 71 | { |
| 72 | __raw_writel(__raw_readl(reg) | val, reg); |
| 73 | } |
| 74 | |
| 75 | static inline void mcasp_clr_bits(void __iomem *reg, u32 val) |
| 76 | { |
| 77 | __raw_writel((__raw_readl(reg) & ~(val)), reg); |
| 78 | } |
| 79 | |
| 80 | static inline void mcasp_mod_bits(void __iomem *reg, u32 val, u32 mask) |
| 81 | { |
| 82 | __raw_writel((__raw_readl(reg) & ~mask) | val, reg); |
| 83 | } |
| 84 | |
| 85 | static inline void mcasp_set_reg(void __iomem *reg, u32 val) |
| 86 | { |
| 87 | __raw_writel(val, reg); |
| 88 | } |
| 89 | |
| 90 | static inline u32 mcasp_get_reg(void __iomem *reg) |
| 91 | { |
| 92 | return (unsigned int)__raw_readl(reg); |
| 93 | } |
| 94 | |
| 95 | static inline void mcasp_set_ctl_reg(void __iomem *regs, u32 val) |
| 96 | { |
| 97 | int i = 0; |
| 98 | |
| 99 | mcasp_set_bits(regs, val); |
| 100 | |
| 101 | /* programming GBLCTL needs to read back from GBLCTL and verfiy */ |
| 102 | /* loop count is to avoid the lock-up */ |
| 103 | for (i = 0; i < 1000; i++) { |
| 104 | if ((mcasp_get_reg(regs) & val) == val) |
| 105 | break; |
| 106 | } |
| 107 | |
| 108 | if (i == 1000 && ((mcasp_get_reg(regs) & val) != val)) |
| 109 | printk(KERN_ERR "GBLCTL write error\n"); |
| 110 | } |
| 111 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 112 | static void mcasp_start_rx(struct davinci_audio_dev *dev) |
| 113 | { |
| 114 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST); |
| 115 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST); |
| 116 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR); |
| 117 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); |
| 118 | |
| 119 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); |
| 120 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); |
| 121 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); |
| 122 | |
| 123 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); |
| 124 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); |
| 125 | } |
| 126 | |
| 127 | static void mcasp_start_tx(struct davinci_audio_dev *dev) |
| 128 | { |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 129 | u8 offset = 0, i; |
| 130 | u32 cnt; |
| 131 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 132 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); |
| 133 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); |
| 134 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR); |
| 135 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
| 136 | |
| 137 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSMRST); |
| 138 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXFSRST); |
| 139 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 140 | for (i = 0; i < dev->num_serializer; i++) { |
| 141 | if (dev->serial_dir[i] == TX_MODE) { |
| 142 | offset = i; |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | /* wait for TX ready */ |
| 148 | cnt = 0; |
| 149 | while (!(mcasp_get_reg(dev->base + DAVINCI_MCASP_XRSRCTL_REG(offset)) & |
| 150 | TXSTATE) && (cnt < 100000)) |
| 151 | cnt++; |
| 152 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 153 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
| 154 | } |
| 155 | |
| 156 | static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream) |
| 157 | { |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 158 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 159 | if (dev->txnumevt) { /* enable FIFO */ |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 160 | switch (dev->version) { |
| 161 | case MCASP_VERSION_3: |
| 162 | mcasp_clr_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 163 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 164 | mcasp_set_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 165 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 166 | break; |
| 167 | default: |
| 168 | mcasp_clr_bits(dev->base + |
| 169 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 170 | mcasp_set_bits(dev->base + |
| 171 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 172 | } |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 173 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 174 | mcasp_start_tx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 175 | } else { |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 176 | if (dev->rxnumevt) { /* enable FIFO */ |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 177 | switch (dev->version) { |
| 178 | case MCASP_VERSION_3: |
| 179 | mcasp_clr_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 180 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 181 | mcasp_set_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 182 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 183 | break; |
| 184 | default: |
| 185 | mcasp_clr_bits(dev->base + |
| 186 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 187 | mcasp_set_bits(dev->base + |
| 188 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 189 | } |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 190 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 191 | mcasp_start_rx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 192 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static void mcasp_stop_rx(struct davinci_audio_dev *dev) |
| 196 | { |
| 197 | mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, 0); |
| 198 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); |
| 199 | } |
| 200 | |
| 201 | static void mcasp_stop_tx(struct davinci_audio_dev *dev) |
| 202 | { |
| 203 | mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); |
| 204 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); |
| 205 | } |
| 206 | |
| 207 | static void davinci_mcasp_stop(struct davinci_audio_dev *dev, int stream) |
| 208 | { |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 209 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 210 | if (dev->txnumevt) { /* disable FIFO */ |
| 211 | switch (dev->version) { |
| 212 | case MCASP_VERSION_3: |
| 213 | mcasp_clr_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 214 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 215 | break; |
| 216 | default: |
| 217 | mcasp_clr_bits(dev->base + |
| 218 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 219 | } |
| 220 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 221 | mcasp_stop_tx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 222 | } else { |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 223 | if (dev->rxnumevt) { /* disable FIFO */ |
| 224 | switch (dev->version) { |
| 225 | case MCASP_VERSION_3: |
| 226 | mcasp_clr_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 227 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 228 | break; |
| 229 | |
| 230 | default: |
| 231 | mcasp_clr_bits(dev->base + |
| 232 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 233 | } |
| 234 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 235 | mcasp_stop_rx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 236 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
| 240 | unsigned int fmt) |
| 241 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 242 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 243 | void __iomem *base = dev->base; |
| 244 | |
Daniel Mack | 5296cf2 | 2012-10-04 15:08:42 +0200 | [diff] [blame] | 245 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 246 | case SND_SOC_DAIFMT_DSP_B: |
| 247 | case SND_SOC_DAIFMT_AC97: |
| 248 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR); |
| 249 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR); |
| 250 | break; |
| 251 | default: |
| 252 | /* configure a full-word SYNC pulse (LRCLK) */ |
| 253 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR); |
| 254 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR); |
| 255 | |
| 256 | /* make 1st data bit occur one ACLK cycle after the frame sync */ |
| 257 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, FSXDLY(1)); |
| 258 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, FSRDLY(1)); |
| 259 | break; |
| 260 | } |
| 261 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 262 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 263 | case SND_SOC_DAIFMT_CBS_CFS: |
| 264 | /* codec is clock and frame slave */ |
| 265 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
| 266 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 267 | |
| 268 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
| 269 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 270 | |
Marek Belisko | 81ee683 | 2013-04-26 14:38:11 +0200 | [diff] [blame] | 271 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 272 | ACLKX | ACLKR); |
| 273 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 274 | AFSX | AFSR); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 275 | break; |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 276 | case SND_SOC_DAIFMT_CBM_CFS: |
| 277 | /* codec is clock master and frame slave */ |
Ben Gardiner | a90f549 | 2011-04-21 14:19:03 -0400 | [diff] [blame] | 278 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 279 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 280 | |
Ben Gardiner | a90f549 | 2011-04-21 14:19:03 -0400 | [diff] [blame] | 281 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 282 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 283 | |
Ben Gardiner | db92f43 | 2011-04-21 14:19:04 -0400 | [diff] [blame] | 284 | mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 285 | ACLKX | ACLKR); |
Ben Gardiner | 9595c8f | 2011-04-21 14:19:02 -0400 | [diff] [blame] | 286 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
Ben Gardiner | db92f43 | 2011-04-21 14:19:04 -0400 | [diff] [blame] | 287 | AFSX | AFSR); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 288 | break; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 289 | case SND_SOC_DAIFMT_CBM_CFM: |
| 290 | /* codec is clock and frame master */ |
| 291 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
| 292 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 293 | |
| 294 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
| 295 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 296 | |
Ben Gardiner | 9595c8f | 2011-04-21 14:19:02 -0400 | [diff] [blame] | 297 | mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 298 | ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 299 | break; |
| 300 | |
| 301 | default: |
| 302 | return -EINVAL; |
| 303 | } |
| 304 | |
| 305 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 306 | case SND_SOC_DAIFMT_IB_NF: |
| 307 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 308 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 309 | |
| 310 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 311 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 312 | break; |
| 313 | |
| 314 | case SND_SOC_DAIFMT_NB_IF: |
| 315 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 316 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 317 | |
| 318 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 319 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 320 | break; |
| 321 | |
| 322 | case SND_SOC_DAIFMT_IB_IF: |
| 323 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 324 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 325 | |
| 326 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 327 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 328 | break; |
| 329 | |
| 330 | case SND_SOC_DAIFMT_NB_NF: |
| 331 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 332 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 333 | |
Marek Belisko | df4a4ee | 2013-05-03 07:37:36 +0200 | [diff] [blame] | 334 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 335 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 336 | break; |
| 337 | |
| 338 | default: |
| 339 | return -EINVAL; |
| 340 | } |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 345 | static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div) |
| 346 | { |
| 347 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 348 | |
| 349 | switch (div_id) { |
| 350 | case 0: /* MCLK divider */ |
| 351 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, |
| 352 | AHCLKXDIV(div - 1), AHCLKXDIV_MASK); |
| 353 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, |
| 354 | AHCLKRDIV(div - 1), AHCLKRDIV_MASK); |
| 355 | break; |
| 356 | |
| 357 | case 1: /* BCLK divider */ |
| 358 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, |
| 359 | ACLKXDIV(div - 1), ACLKXDIV_MASK); |
| 360 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKRCTL_REG, |
| 361 | ACLKRDIV(div - 1), ACLKRDIV_MASK); |
| 362 | break; |
| 363 | |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 364 | case 2: /* BCLK/LRCLK ratio */ |
| 365 | dev->bclk_lrclk_ratio = div; |
| 366 | break; |
| 367 | |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 368 | default: |
| 369 | return -EINVAL; |
| 370 | } |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 375 | static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 376 | unsigned int freq, int dir) |
| 377 | { |
| 378 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 379 | |
| 380 | if (dir == SND_SOC_CLOCK_OUT) { |
| 381 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); |
| 382 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); |
| 383 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX); |
| 384 | } else { |
| 385 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); |
| 386 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); |
| 387 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX); |
| 388 | } |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 393 | static int davinci_config_channel_size(struct davinci_audio_dev *dev, |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 394 | int word_length) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 395 | { |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 396 | u32 fmt; |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 397 | u32 tx_rotate = (word_length / 4) & 0x7; |
| 398 | u32 rx_rotate = (32 - word_length) / 4; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 399 | u32 mask = (1ULL << word_length) - 1; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 400 | |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 401 | /* |
| 402 | * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv() |
| 403 | * callback, take it into account here. That allows us to for example |
| 404 | * send 32 bits per channel to the codec, while only 16 of them carry |
| 405 | * audio payload. |
Michal Bachraty | d486fea | 2013-04-19 15:28:44 +0200 | [diff] [blame] | 406 | * The clock ratio is given for a full period of data (for I2S format |
| 407 | * both left and right channels), so it has to be divided by number of |
| 408 | * tdm-slots (for I2S - divided by 2). |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 409 | */ |
| 410 | if (dev->bclk_lrclk_ratio) |
Michal Bachraty | d486fea | 2013-04-19 15:28:44 +0200 | [diff] [blame] | 411 | word_length = dev->bclk_lrclk_ratio / dev->tdm_slots; |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 412 | |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 413 | /* mapping of the XSSZ bit-field as described in the datasheet */ |
| 414 | fmt = (word_length >> 1) - 1; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 415 | |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 416 | if (dev->op_mode != DAVINCI_MCASP_DIT_MODE) { |
| 417 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, |
| 418 | RXSSZ(fmt), RXSSZ(0x0F)); |
| 419 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
| 420 | TXSSZ(fmt), TXSSZ(0x0F)); |
| 421 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 422 | TXROT(tx_rotate), TXROT(7)); |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 423 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 424 | RXROT(rx_rotate), RXROT(7)); |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 425 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXMASK_REG, |
| 426 | mask); |
| 427 | } |
| 428 | |
Chaithrika U S | 0c31cf3 | 2009-09-15 18:13:29 -0400 | [diff] [blame] | 429 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXMASK_REG, mask); |
Chaithrika U S | 0c31cf3 | 2009-09-15 18:13:29 -0400 | [diff] [blame] | 430 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 431 | return 0; |
| 432 | } |
| 433 | |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 434 | static int davinci_hw_common_param(struct davinci_audio_dev *dev, int stream, |
| 435 | int channels) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 436 | { |
| 437 | int i; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 438 | u8 tx_ser = 0; |
| 439 | u8 rx_ser = 0; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 440 | u8 ser; |
| 441 | u8 slots = dev->tdm_slots; |
| 442 | u8 max_active_serializers = (channels + slots - 1) / slots; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 443 | /* Default configuration */ |
| 444 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT); |
| 445 | |
| 446 | /* All PINS as McASP */ |
| 447 | mcasp_set_reg(dev->base + DAVINCI_MCASP_PFUNC_REG, 0x00000000); |
| 448 | |
| 449 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 450 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); |
| 451 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, |
| 452 | TXDATADMADIS); |
| 453 | } else { |
| 454 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); |
| 455 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_REVTCTL_REG, |
| 456 | RXDATADMADIS); |
| 457 | } |
| 458 | |
| 459 | for (i = 0; i < dev->num_serializer; i++) { |
| 460 | mcasp_set_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i), |
| 461 | dev->serial_dir[i]); |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 462 | if (dev->serial_dir[i] == TX_MODE && |
| 463 | tx_ser < max_active_serializers) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 464 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, |
| 465 | AXR(i)); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 466 | tx_ser++; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 467 | } else if (dev->serial_dir[i] == RX_MODE && |
| 468 | rx_ser < max_active_serializers) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 469 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, |
| 470 | AXR(i)); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 471 | rx_ser++; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 472 | } else { |
| 473 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i), |
| 474 | SRMOD_INACTIVE, SRMOD_MASK); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
Daniel Mack | ecf327c | 2013-03-08 14:19:38 +0100 | [diff] [blame] | 478 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 479 | ser = tx_ser; |
| 480 | else |
| 481 | ser = rx_ser; |
| 482 | |
| 483 | if (ser < max_active_serializers) { |
| 484 | dev_warn(dev->dev, "stream has more channels (%d) than are " |
| 485 | "enabled in mcasp (%d)\n", channels, ser * slots); |
| 486 | return -EINVAL; |
| 487 | } |
| 488 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 489 | if (dev->txnumevt && stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 490 | if (dev->txnumevt * tx_ser > 64) |
| 491 | dev->txnumevt = 1; |
| 492 | |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 493 | switch (dev->version) { |
| 494 | case MCASP_VERSION_3: |
| 495 | mcasp_mod_bits(dev->base + MCASP_VER3_WFIFOCTL, tx_ser, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 496 | NUMDMA_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 497 | mcasp_mod_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 498 | ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 499 | break; |
| 500 | default: |
| 501 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, |
| 502 | tx_ser, NUMDMA_MASK); |
| 503 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, |
| 504 | ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); |
| 505 | } |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | if (dev->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 509 | if (dev->rxnumevt * rx_ser > 64) |
| 510 | dev->rxnumevt = 1; |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 511 | switch (dev->version) { |
| 512 | case MCASP_VERSION_3: |
| 513 | mcasp_mod_bits(dev->base + MCASP_VER3_RFIFOCTL, rx_ser, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 514 | NUMDMA_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 515 | mcasp_mod_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 516 | ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 517 | break; |
| 518 | default: |
| 519 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, |
| 520 | rx_ser, NUMDMA_MASK); |
| 521 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, |
| 522 | ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); |
| 523 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 524 | } |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 525 | |
| 526 | return 0; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) |
| 530 | { |
| 531 | int i, active_slots; |
| 532 | u32 mask = 0; |
| 533 | |
| 534 | active_slots = (dev->tdm_slots > 31) ? 32 : dev->tdm_slots; |
| 535 | for (i = 0; i < active_slots; i++) |
| 536 | mask |= (1 << i); |
| 537 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 538 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); |
| 539 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 540 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 541 | /* bit stream is MSB first with no delay */ |
| 542 | /* DSP_B mode */ |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 543 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask); |
| 544 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD); |
| 545 | |
Ben Gardiner | 049cfaa | 2011-04-21 14:19:01 -0400 | [diff] [blame] | 546 | if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 547 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, |
| 548 | FSXMOD(dev->tdm_slots), FSXMOD(0x1FF)); |
| 549 | else |
| 550 | printk(KERN_ERR "playback tdm slot %d not supported\n", |
| 551 | dev->tdm_slots); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 552 | } else { |
| 553 | /* bit stream is MSB first with no delay */ |
| 554 | /* DSP_B mode */ |
| 555 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 556 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask); |
| 557 | |
Ben Gardiner | 049cfaa | 2011-04-21 14:19:01 -0400 | [diff] [blame] | 558 | if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 559 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, |
| 560 | FSRMOD(dev->tdm_slots), FSRMOD(0x1FF)); |
| 561 | else |
| 562 | printk(KERN_ERR "capture tdm slot %d not supported\n", |
| 563 | dev->tdm_slots); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| 567 | /* S/PDIF */ |
| 568 | static void davinci_hw_dit_param(struct davinci_audio_dev *dev) |
| 569 | { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 570 | /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0 |
| 571 | and LSB first */ |
| 572 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
| 573 | TXROT(6) | TXSSZ(15)); |
| 574 | |
| 575 | /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */ |
| 576 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXFMCTL_REG, |
| 577 | AFSXE | FSXMOD(0x180)); |
| 578 | |
| 579 | /* Set the TX tdm : for all the slots */ |
| 580 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF); |
| 581 | |
| 582 | /* Set the TX clock controls : div = 1 and internal */ |
| 583 | mcasp_set_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, |
| 584 | ACLKXE | TX_ASYNC); |
| 585 | |
| 586 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS); |
| 587 | |
| 588 | /* Only 44100 and 48000 are valid, both have the same setting */ |
| 589 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3)); |
| 590 | |
| 591 | /* Enable the DIT */ |
| 592 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXDITCTL_REG, DITEN); |
| 593 | } |
| 594 | |
| 595 | static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, |
| 596 | struct snd_pcm_hw_params *params, |
| 597 | struct snd_soc_dai *cpu_dai) |
| 598 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 599 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 600 | struct davinci_pcm_dma_params *dma_params = |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 601 | &dev->dma_params[substream->stream]; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 602 | int word_length; |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 603 | u8 fifo_level; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 604 | u8 slots = dev->tdm_slots; |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 605 | u8 active_serializers; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 606 | int channels; |
| 607 | struct snd_interval *pcm_channels = hw_param_interval(params, |
| 608 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 609 | channels = pcm_channels->min; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 610 | |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 611 | active_serializers = (channels + slots - 1) / slots; |
| 612 | |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 613 | if (davinci_hw_common_param(dev, substream->stream, channels) == -EINVAL) |
| 614 | return -EINVAL; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 615 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 616 | fifo_level = dev->txnumevt * active_serializers; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 617 | else |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 618 | fifo_level = dev->rxnumevt * active_serializers; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 619 | |
| 620 | if (dev->op_mode == DAVINCI_MCASP_DIT_MODE) |
| 621 | davinci_hw_dit_param(dev); |
| 622 | else |
| 623 | davinci_hw_param(dev, substream->stream); |
| 624 | |
| 625 | switch (params_format(params)) { |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 626 | case SNDRV_PCM_FORMAT_U8: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 627 | case SNDRV_PCM_FORMAT_S8: |
| 628 | dma_params->data_type = 1; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 629 | word_length = 8; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 630 | break; |
| 631 | |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 632 | case SNDRV_PCM_FORMAT_U16_LE: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 633 | case SNDRV_PCM_FORMAT_S16_LE: |
| 634 | dma_params->data_type = 2; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 635 | word_length = 16; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 636 | break; |
| 637 | |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 638 | case SNDRV_PCM_FORMAT_U24_3LE: |
| 639 | case SNDRV_PCM_FORMAT_S24_3LE: |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 640 | dma_params->data_type = 3; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 641 | word_length = 24; |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 642 | break; |
| 643 | |
Daniel Mack | 6b7fa01 | 2012-10-09 11:56:40 +0200 | [diff] [blame] | 644 | case SNDRV_PCM_FORMAT_U24_LE: |
| 645 | case SNDRV_PCM_FORMAT_S24_LE: |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 646 | case SNDRV_PCM_FORMAT_U32_LE: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 647 | case SNDRV_PCM_FORMAT_S32_LE: |
| 648 | dma_params->data_type = 4; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 649 | word_length = 32; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 650 | break; |
| 651 | |
| 652 | default: |
| 653 | printk(KERN_WARNING "davinci-mcasp: unsupported PCM format"); |
| 654 | return -EINVAL; |
| 655 | } |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 656 | |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 657 | if (dev->version == MCASP_VERSION_2 && !fifo_level) |
| 658 | dma_params->acnt = 4; |
| 659 | else |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 660 | dma_params->acnt = dma_params->data_type; |
| 661 | |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 662 | dma_params->fifo_level = fifo_level; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 663 | davinci_config_channel_size(dev, word_length); |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | static int davinci_mcasp_trigger(struct snd_pcm_substream *substream, |
| 669 | int cmd, struct snd_soc_dai *cpu_dai) |
| 670 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 671 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(cpu_dai); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 672 | int ret = 0; |
| 673 | |
| 674 | switch (cmd) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 675 | case SNDRV_PCM_TRIGGER_RESUME: |
Chaithrika U S | e473b84 | 2010-01-20 17:06:33 +0530 | [diff] [blame] | 676 | case SNDRV_PCM_TRIGGER_START: |
| 677 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 678 | ret = pm_runtime_get_sync(dev->dev); |
| 679 | if (IS_ERR_VALUE(ret)) |
| 680 | dev_err(dev->dev, "pm_runtime_get_sync() failed\n"); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 681 | davinci_mcasp_start(dev, substream->stream); |
| 682 | break; |
| 683 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 684 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Chaithrika U S | a47979b | 2009-12-03 18:56:56 +0530 | [diff] [blame] | 685 | davinci_mcasp_stop(dev, substream->stream); |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 686 | ret = pm_runtime_put_sync(dev->dev); |
| 687 | if (IS_ERR_VALUE(ret)) |
| 688 | dev_err(dev->dev, "pm_runtime_put_sync() failed\n"); |
Chaithrika U S | a47979b | 2009-12-03 18:56:56 +0530 | [diff] [blame] | 689 | break; |
| 690 | |
| 691 | case SNDRV_PCM_TRIGGER_STOP: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 692 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 693 | davinci_mcasp_stop(dev, substream->stream); |
| 694 | break; |
| 695 | |
| 696 | default: |
| 697 | ret = -EINVAL; |
| 698 | } |
| 699 | |
| 700 | return ret; |
| 701 | } |
| 702 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 703 | static int davinci_mcasp_startup(struct snd_pcm_substream *substream, |
| 704 | struct snd_soc_dai *dai) |
| 705 | { |
| 706 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 707 | |
| 708 | snd_soc_dai_set_dma_data(dai, substream, dev->dma_params); |
| 709 | return 0; |
| 710 | } |
| 711 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 712 | static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 713 | .startup = davinci_mcasp_startup, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 714 | .trigger = davinci_mcasp_trigger, |
| 715 | .hw_params = davinci_mcasp_hw_params, |
| 716 | .set_fmt = davinci_mcasp_set_dai_fmt, |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 717 | .set_clkdiv = davinci_mcasp_set_clkdiv, |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 718 | .set_sysclk = davinci_mcasp_set_sysclk, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 719 | }; |
| 720 | |
Peter Ujfalusi | ed29cd5 | 2013-11-14 11:35:22 +0200 | [diff] [blame] | 721 | #define DAVINCI_MCASP_RATES SNDRV_PCM_RATE_8000_192000 |
| 722 | |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 723 | #define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \ |
| 724 | SNDRV_PCM_FMTBIT_U8 | \ |
| 725 | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 726 | SNDRV_PCM_FMTBIT_U16_LE | \ |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 727 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 728 | SNDRV_PCM_FMTBIT_U24_LE | \ |
| 729 | SNDRV_PCM_FMTBIT_S24_3LE | \ |
| 730 | SNDRV_PCM_FMTBIT_U24_3LE | \ |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 731 | SNDRV_PCM_FMTBIT_S32_LE | \ |
| 732 | SNDRV_PCM_FMTBIT_U32_LE) |
| 733 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 734 | static struct snd_soc_dai_driver davinci_mcasp_dai[] = { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 735 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 736 | .name = "davinci-mcasp.0", |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 737 | .playback = { |
| 738 | .channels_min = 2, |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 739 | .channels_max = 32 * 16, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 740 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 741 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 742 | }, |
| 743 | .capture = { |
| 744 | .channels_min = 2, |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 745 | .channels_max = 32 * 16, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 746 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 747 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 748 | }, |
| 749 | .ops = &davinci_mcasp_dai_ops, |
| 750 | |
| 751 | }, |
| 752 | { |
Peter Ujfalusi | 58e48d9 | 2013-11-14 11:35:24 +0200 | [diff] [blame] | 753 | .name = "davinci-mcasp.1", |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 754 | .playback = { |
| 755 | .channels_min = 1, |
| 756 | .channels_max = 384, |
| 757 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 758 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 759 | }, |
| 760 | .ops = &davinci_mcasp_dai_ops, |
| 761 | }, |
| 762 | |
| 763 | }; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 764 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 765 | static const struct snd_soc_component_driver davinci_mcasp_component = { |
| 766 | .name = "davinci-mcasp", |
| 767 | }; |
| 768 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 769 | /* Some HW specific values and defaults. The rest is filled in from DT. */ |
| 770 | static struct snd_platform_data dm646x_mcasp_pdata = { |
| 771 | .tx_dma_offset = 0x400, |
| 772 | .rx_dma_offset = 0x400, |
| 773 | .asp_chan_q = EVENTQ_0, |
| 774 | .version = MCASP_VERSION_1, |
| 775 | }; |
| 776 | |
| 777 | static struct snd_platform_data da830_mcasp_pdata = { |
| 778 | .tx_dma_offset = 0x2000, |
| 779 | .rx_dma_offset = 0x2000, |
| 780 | .asp_chan_q = EVENTQ_0, |
| 781 | .version = MCASP_VERSION_2, |
| 782 | }; |
| 783 | |
| 784 | static struct snd_platform_data omap2_mcasp_pdata = { |
| 785 | .tx_dma_offset = 0, |
| 786 | .rx_dma_offset = 0, |
| 787 | .asp_chan_q = EVENTQ_0, |
| 788 | .version = MCASP_VERSION_3, |
| 789 | }; |
| 790 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 791 | static const struct of_device_id mcasp_dt_ids[] = { |
| 792 | { |
| 793 | .compatible = "ti,dm646x-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 794 | .data = &dm646x_mcasp_pdata, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 795 | }, |
| 796 | { |
| 797 | .compatible = "ti,da830-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 798 | .data = &da830_mcasp_pdata, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 799 | }, |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 800 | { |
Jyri Sarha | 3af9e03 | 2013-10-18 18:37:44 +0300 | [diff] [blame] | 801 | .compatible = "ti,am33xx-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 802 | .data = &omap2_mcasp_pdata, |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 803 | }, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 804 | { /* sentinel */ } |
| 805 | }; |
| 806 | MODULE_DEVICE_TABLE(of, mcasp_dt_ids); |
| 807 | |
| 808 | static struct snd_platform_data *davinci_mcasp_set_pdata_from_of( |
| 809 | struct platform_device *pdev) |
| 810 | { |
| 811 | struct device_node *np = pdev->dev.of_node; |
| 812 | struct snd_platform_data *pdata = NULL; |
| 813 | const struct of_device_id *match = |
Sachin Kamat | ea421eb | 2013-05-22 16:53:37 +0530 | [diff] [blame] | 814 | of_match_device(mcasp_dt_ids, &pdev->dev); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 815 | struct of_phandle_args dma_spec; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 816 | |
| 817 | const u32 *of_serial_dir32; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 818 | u32 val; |
| 819 | int i, ret = 0; |
| 820 | |
| 821 | if (pdev->dev.platform_data) { |
| 822 | pdata = pdev->dev.platform_data; |
| 823 | return pdata; |
| 824 | } else if (match) { |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 825 | pdata = (struct snd_platform_data *) match->data; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 826 | } else { |
| 827 | /* control shouldn't reach here. something is wrong */ |
| 828 | ret = -EINVAL; |
| 829 | goto nodata; |
| 830 | } |
| 831 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 832 | ret = of_property_read_u32(np, "op-mode", &val); |
| 833 | if (ret >= 0) |
| 834 | pdata->op_mode = val; |
| 835 | |
| 836 | ret = of_property_read_u32(np, "tdm-slots", &val); |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 837 | if (ret >= 0) { |
| 838 | if (val < 2 || val > 32) { |
| 839 | dev_err(&pdev->dev, |
| 840 | "tdm-slots must be in rage [2-32]\n"); |
| 841 | ret = -EINVAL; |
| 842 | goto nodata; |
| 843 | } |
| 844 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 845 | pdata->tdm_slots = val; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 846 | } |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 847 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 848 | of_serial_dir32 = of_get_property(np, "serial-dir", &val); |
| 849 | val /= sizeof(u32); |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 850 | if (of_serial_dir32) { |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame] | 851 | u8 *of_serial_dir = devm_kzalloc(&pdev->dev, |
| 852 | (sizeof(*of_serial_dir) * val), |
| 853 | GFP_KERNEL); |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 854 | if (!of_serial_dir) { |
| 855 | ret = -ENOMEM; |
| 856 | goto nodata; |
| 857 | } |
| 858 | |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame] | 859 | for (i = 0; i < val; i++) |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 860 | of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]); |
| 861 | |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame] | 862 | pdata->num_serializer = val; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 863 | pdata->serial_dir = of_serial_dir; |
| 864 | } |
| 865 | |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 866 | ret = of_property_match_string(np, "dma-names", "tx"); |
| 867 | if (ret < 0) |
| 868 | goto nodata; |
| 869 | |
| 870 | ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret, |
| 871 | &dma_spec); |
| 872 | if (ret < 0) |
| 873 | goto nodata; |
| 874 | |
| 875 | pdata->tx_dma_channel = dma_spec.args[0]; |
| 876 | |
| 877 | ret = of_property_match_string(np, "dma-names", "rx"); |
| 878 | if (ret < 0) |
| 879 | goto nodata; |
| 880 | |
| 881 | ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret, |
| 882 | &dma_spec); |
| 883 | if (ret < 0) |
| 884 | goto nodata; |
| 885 | |
| 886 | pdata->rx_dma_channel = dma_spec.args[0]; |
| 887 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 888 | ret = of_property_read_u32(np, "tx-num-evt", &val); |
| 889 | if (ret >= 0) |
| 890 | pdata->txnumevt = val; |
| 891 | |
| 892 | ret = of_property_read_u32(np, "rx-num-evt", &val); |
| 893 | if (ret >= 0) |
| 894 | pdata->rxnumevt = val; |
| 895 | |
| 896 | ret = of_property_read_u32(np, "sram-size-playback", &val); |
| 897 | if (ret >= 0) |
| 898 | pdata->sram_size_playback = val; |
| 899 | |
| 900 | ret = of_property_read_u32(np, "sram-size-capture", &val); |
| 901 | if (ret >= 0) |
| 902 | pdata->sram_size_capture = val; |
| 903 | |
| 904 | return pdata; |
| 905 | |
| 906 | nodata: |
| 907 | if (ret < 0) { |
| 908 | dev_err(&pdev->dev, "Error populating platform data, err %d\n", |
| 909 | ret); |
| 910 | pdata = NULL; |
| 911 | } |
| 912 | return pdata; |
| 913 | } |
| 914 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 915 | static int davinci_mcasp_probe(struct platform_device *pdev) |
| 916 | { |
| 917 | struct davinci_pcm_dma_params *dma_data; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 918 | struct resource *mem, *ioarea, *res, *dat; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 919 | struct snd_platform_data *pdata; |
| 920 | struct davinci_audio_dev *dev; |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 921 | int ret; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 922 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 923 | if (!pdev->dev.platform_data && !pdev->dev.of_node) { |
| 924 | dev_err(&pdev->dev, "No platform data supplied\n"); |
| 925 | return -EINVAL; |
| 926 | } |
| 927 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 928 | dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_audio_dev), |
| 929 | GFP_KERNEL); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 930 | if (!dev) |
| 931 | return -ENOMEM; |
| 932 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 933 | pdata = davinci_mcasp_set_pdata_from_of(pdev); |
| 934 | if (!pdata) { |
| 935 | dev_err(&pdev->dev, "no platform data\n"); |
| 936 | return -EINVAL; |
| 937 | } |
| 938 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 939 | mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 940 | if (!mem) { |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 941 | dev_warn(dev->dev, |
| 942 | "\"mpu\" mem resource not found, using index 0\n"); |
| 943 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 944 | if (!mem) { |
| 945 | dev_err(&pdev->dev, "no mem resource?\n"); |
| 946 | return -ENODEV; |
| 947 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 948 | } |
| 949 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 950 | ioarea = devm_request_mem_region(&pdev->dev, mem->start, |
Vaibhav Bedia | d852f446 | 2011-02-09 18:39:52 +0530 | [diff] [blame] | 951 | resource_size(mem), pdev->name); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 952 | if (!ioarea) { |
| 953 | dev_err(&pdev->dev, "Audio region already claimed\n"); |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 954 | return -EBUSY; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 957 | pm_runtime_enable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 958 | |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 959 | ret = pm_runtime_get_sync(&pdev->dev); |
| 960 | if (IS_ERR_VALUE(ret)) { |
| 961 | dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); |
| 962 | return ret; |
| 963 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 964 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 965 | dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
Vaibhav Bedia | 4f82f02 | 2011-02-09 18:39:54 +0530 | [diff] [blame] | 966 | if (!dev->base) { |
| 967 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 968 | ret = -ENOMEM; |
| 969 | goto err_release_clk; |
| 970 | } |
| 971 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 972 | dev->op_mode = pdata->op_mode; |
| 973 | dev->tdm_slots = pdata->tdm_slots; |
| 974 | dev->num_serializer = pdata->num_serializer; |
| 975 | dev->serial_dir = pdata->serial_dir; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 976 | dev->version = pdata->version; |
| 977 | dev->txnumevt = pdata->txnumevt; |
| 978 | dev->rxnumevt = pdata->rxnumevt; |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 979 | dev->dev = &pdev->dev; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 980 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 981 | dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); |
| 982 | if (!dat) |
| 983 | dat = mem; |
| 984 | |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 985 | dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; |
Sekhar Nori | 48519f0 | 2010-07-19 12:31:16 +0530 | [diff] [blame] | 986 | dma_data->asp_chan_q = pdata->asp_chan_q; |
| 987 | dma_data->ram_chan_q = pdata->ram_chan_q; |
Matt Porter | b8ec56d | 2012-10-17 16:08:03 +0200 | [diff] [blame] | 988 | dma_data->sram_pool = pdata->sram_pool; |
Ben Gardiner | a0c8326 | 2011-05-18 09:27:45 -0400 | [diff] [blame] | 989 | dma_data->sram_size = pdata->sram_size_playback; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 990 | dma_data->dma_addr = dat->start + pdata->tx_dma_offset; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 991 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 992 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 993 | if (res) |
| 994 | dma_data->channel = res->start; |
| 995 | else |
| 996 | dma_data->channel = pdata->tx_dma_channel; |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 997 | |
| 998 | dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]; |
Sekhar Nori | 48519f0 | 2010-07-19 12:31:16 +0530 | [diff] [blame] | 999 | dma_data->asp_chan_q = pdata->asp_chan_q; |
| 1000 | dma_data->ram_chan_q = pdata->ram_chan_q; |
Matt Porter | b8ec56d | 2012-10-17 16:08:03 +0200 | [diff] [blame] | 1001 | dma_data->sram_pool = pdata->sram_pool; |
Ben Gardiner | a0c8326 | 2011-05-18 09:27:45 -0400 | [diff] [blame] | 1002 | dma_data->sram_size = pdata->sram_size_capture; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1003 | dma_data->dma_addr = dat->start + pdata->rx_dma_offset; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1004 | |
| 1005 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 1006 | if (res) |
| 1007 | dma_data->channel = res->start; |
| 1008 | else |
| 1009 | dma_data->channel = pdata->rx_dma_channel; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1010 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1011 | dev_set_drvdata(&pdev->dev, dev); |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1012 | ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component, |
| 1013 | &davinci_mcasp_dai[pdata->op_mode], 1); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1014 | |
| 1015 | if (ret != 0) |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1016 | goto err_release_clk; |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1017 | |
| 1018 | ret = davinci_soc_platform_register(&pdev->dev); |
| 1019 | if (ret) { |
| 1020 | dev_err(&pdev->dev, "register PCM failed: %d\n", ret); |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1021 | goto err_unregister_component; |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1022 | } |
| 1023 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1024 | return 0; |
| 1025 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1026 | err_unregister_component: |
| 1027 | snd_soc_unregister_component(&pdev->dev); |
Vaibhav Bedia | eef6d7b | 2011-02-09 18:39:53 +0530 | [diff] [blame] | 1028 | err_release_clk: |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1029 | pm_runtime_put_sync(&pdev->dev); |
| 1030 | pm_runtime_disable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1031 | return ret; |
| 1032 | } |
| 1033 | |
| 1034 | static int davinci_mcasp_remove(struct platform_device *pdev) |
| 1035 | { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1036 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1037 | snd_soc_unregister_component(&pdev->dev); |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1038 | davinci_soc_platform_unregister(&pdev->dev); |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1039 | |
| 1040 | pm_runtime_put_sync(&pdev->dev); |
| 1041 | pm_runtime_disable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1042 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1043 | return 0; |
| 1044 | } |
| 1045 | |
Daniel Mack | a85e419 | 2013-10-01 14:50:02 +0200 | [diff] [blame] | 1046 | #ifdef CONFIG_PM_SLEEP |
| 1047 | static int davinci_mcasp_suspend(struct device *dev) |
| 1048 | { |
| 1049 | struct davinci_audio_dev *a = dev_get_drvdata(dev); |
| 1050 | void __iomem *base = a->base; |
| 1051 | |
| 1052 | a->context.txfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_TXFMCTL_REG); |
| 1053 | a->context.rxfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_RXFMCTL_REG); |
| 1054 | a->context.txfmt = mcasp_get_reg(base + DAVINCI_MCASP_TXFMT_REG); |
| 1055 | a->context.rxfmt = mcasp_get_reg(base + DAVINCI_MCASP_RXFMT_REG); |
| 1056 | a->context.aclkxctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKXCTL_REG); |
| 1057 | a->context.aclkrctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKRCTL_REG); |
| 1058 | a->context.pdir = mcasp_get_reg(base + DAVINCI_MCASP_PDIR_REG); |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int davinci_mcasp_resume(struct device *dev) |
| 1064 | { |
| 1065 | struct davinci_audio_dev *a = dev_get_drvdata(dev); |
| 1066 | void __iomem *base = a->base; |
| 1067 | |
| 1068 | mcasp_set_reg(base + DAVINCI_MCASP_TXFMCTL_REG, a->context.txfmtctl); |
| 1069 | mcasp_set_reg(base + DAVINCI_MCASP_RXFMCTL_REG, a->context.rxfmtctl); |
| 1070 | mcasp_set_reg(base + DAVINCI_MCASP_TXFMT_REG, a->context.txfmt); |
| 1071 | mcasp_set_reg(base + DAVINCI_MCASP_RXFMT_REG, a->context.rxfmt); |
| 1072 | mcasp_set_reg(base + DAVINCI_MCASP_ACLKXCTL_REG, a->context.aclkxctl); |
| 1073 | mcasp_set_reg(base + DAVINCI_MCASP_ACLKRCTL_REG, a->context.aclkrctl); |
| 1074 | mcasp_set_reg(base + DAVINCI_MCASP_PDIR_REG, a->context.pdir); |
| 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | #endif |
| 1079 | |
| 1080 | SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops, |
| 1081 | davinci_mcasp_suspend, |
| 1082 | davinci_mcasp_resume); |
| 1083 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1084 | static struct platform_driver davinci_mcasp_driver = { |
| 1085 | .probe = davinci_mcasp_probe, |
| 1086 | .remove = davinci_mcasp_remove, |
| 1087 | .driver = { |
| 1088 | .name = "davinci-mcasp", |
| 1089 | .owner = THIS_MODULE, |
Daniel Mack | a85e419 | 2013-10-01 14:50:02 +0200 | [diff] [blame] | 1090 | .pm = &davinci_mcasp_pm_ops, |
Sachin Kamat | ea421eb | 2013-05-22 16:53:37 +0530 | [diff] [blame] | 1091 | .of_match_table = mcasp_dt_ids, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1092 | }, |
| 1093 | }; |
| 1094 | |
Axel Lin | f9b8a51 | 2011-11-25 10:09:27 +0800 | [diff] [blame] | 1095 | module_platform_driver(davinci_mcasp_driver); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1096 | |
| 1097 | MODULE_AUTHOR("Steve Chen"); |
| 1098 | MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface"); |
| 1099 | MODULE_LICENSE("GPL"); |