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 | |
| 38 | /* |
| 39 | * McASP register definitions |
| 40 | */ |
| 41 | #define DAVINCI_MCASP_PID_REG 0x00 |
| 42 | #define DAVINCI_MCASP_PWREMUMGT_REG 0x04 |
| 43 | |
| 44 | #define DAVINCI_MCASP_PFUNC_REG 0x10 |
| 45 | #define DAVINCI_MCASP_PDIR_REG 0x14 |
| 46 | #define DAVINCI_MCASP_PDOUT_REG 0x18 |
| 47 | #define DAVINCI_MCASP_PDSET_REG 0x1c |
| 48 | |
| 49 | #define DAVINCI_MCASP_PDCLR_REG 0x20 |
| 50 | |
| 51 | #define DAVINCI_MCASP_TLGC_REG 0x30 |
| 52 | #define DAVINCI_MCASP_TLMR_REG 0x34 |
| 53 | |
| 54 | #define DAVINCI_MCASP_GBLCTL_REG 0x44 |
| 55 | #define DAVINCI_MCASP_AMUTE_REG 0x48 |
| 56 | #define DAVINCI_MCASP_LBCTL_REG 0x4c |
| 57 | |
| 58 | #define DAVINCI_MCASP_TXDITCTL_REG 0x50 |
| 59 | |
| 60 | #define DAVINCI_MCASP_GBLCTLR_REG 0x60 |
| 61 | #define DAVINCI_MCASP_RXMASK_REG 0x64 |
| 62 | #define DAVINCI_MCASP_RXFMT_REG 0x68 |
| 63 | #define DAVINCI_MCASP_RXFMCTL_REG 0x6c |
| 64 | |
| 65 | #define DAVINCI_MCASP_ACLKRCTL_REG 0x70 |
| 66 | #define DAVINCI_MCASP_AHCLKRCTL_REG 0x74 |
| 67 | #define DAVINCI_MCASP_RXTDM_REG 0x78 |
| 68 | #define DAVINCI_MCASP_EVTCTLR_REG 0x7c |
| 69 | |
| 70 | #define DAVINCI_MCASP_RXSTAT_REG 0x80 |
| 71 | #define DAVINCI_MCASP_RXTDMSLOT_REG 0x84 |
| 72 | #define DAVINCI_MCASP_RXCLKCHK_REG 0x88 |
| 73 | #define DAVINCI_MCASP_REVTCTL_REG 0x8c |
| 74 | |
| 75 | #define DAVINCI_MCASP_GBLCTLX_REG 0xa0 |
| 76 | #define DAVINCI_MCASP_TXMASK_REG 0xa4 |
| 77 | #define DAVINCI_MCASP_TXFMT_REG 0xa8 |
| 78 | #define DAVINCI_MCASP_TXFMCTL_REG 0xac |
| 79 | |
| 80 | #define DAVINCI_MCASP_ACLKXCTL_REG 0xb0 |
| 81 | #define DAVINCI_MCASP_AHCLKXCTL_REG 0xb4 |
| 82 | #define DAVINCI_MCASP_TXTDM_REG 0xb8 |
| 83 | #define DAVINCI_MCASP_EVTCTLX_REG 0xbc |
| 84 | |
| 85 | #define DAVINCI_MCASP_TXSTAT_REG 0xc0 |
| 86 | #define DAVINCI_MCASP_TXTDMSLOT_REG 0xc4 |
| 87 | #define DAVINCI_MCASP_TXCLKCHK_REG 0xc8 |
| 88 | #define DAVINCI_MCASP_XEVTCTL_REG 0xcc |
| 89 | |
| 90 | /* Left(even TDM Slot) Channel Status Register File */ |
| 91 | #define DAVINCI_MCASP_DITCSRA_REG 0x100 |
| 92 | /* Right(odd TDM slot) Channel Status Register File */ |
| 93 | #define DAVINCI_MCASP_DITCSRB_REG 0x118 |
| 94 | /* Left(even TDM slot) User Data Register File */ |
| 95 | #define DAVINCI_MCASP_DITUDRA_REG 0x130 |
| 96 | /* Right(odd TDM Slot) User Data Register File */ |
| 97 | #define DAVINCI_MCASP_DITUDRB_REG 0x148 |
| 98 | |
| 99 | /* Serializer n Control Register */ |
| 100 | #define DAVINCI_MCASP_XRSRCTL_BASE_REG 0x180 |
| 101 | #define DAVINCI_MCASP_XRSRCTL_REG(n) (DAVINCI_MCASP_XRSRCTL_BASE_REG + \ |
| 102 | (n << 2)) |
| 103 | |
| 104 | /* Transmit Buffer for Serializer n */ |
| 105 | #define DAVINCI_MCASP_TXBUF_REG 0x200 |
| 106 | /* Receive Buffer for Serializer n */ |
| 107 | #define DAVINCI_MCASP_RXBUF_REG 0x280 |
| 108 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 109 | /* McASP FIFO Registers */ |
| 110 | #define DAVINCI_MCASP_WFIFOCTL (0x1010) |
| 111 | #define DAVINCI_MCASP_WFIFOSTS (0x1014) |
| 112 | #define DAVINCI_MCASP_RFIFOCTL (0x1018) |
| 113 | #define DAVINCI_MCASP_RFIFOSTS (0x101C) |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 114 | #define MCASP_VER3_WFIFOCTL (0x1000) |
| 115 | #define MCASP_VER3_WFIFOSTS (0x1004) |
| 116 | #define MCASP_VER3_RFIFOCTL (0x1008) |
| 117 | #define MCASP_VER3_RFIFOSTS (0x100C) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * DAVINCI_MCASP_PWREMUMGT_REG - Power Down and Emulation Management |
| 121 | * Register Bits |
| 122 | */ |
| 123 | #define MCASP_FREE BIT(0) |
| 124 | #define MCASP_SOFT BIT(1) |
| 125 | |
| 126 | /* |
| 127 | * DAVINCI_MCASP_PFUNC_REG - Pin Function / GPIO Enable Register Bits |
| 128 | */ |
| 129 | #define AXR(n) (1<<n) |
| 130 | #define PFUNC_AMUTE BIT(25) |
| 131 | #define ACLKX BIT(26) |
| 132 | #define AHCLKX BIT(27) |
| 133 | #define AFSX BIT(28) |
| 134 | #define ACLKR BIT(29) |
| 135 | #define AHCLKR BIT(30) |
| 136 | #define AFSR BIT(31) |
| 137 | |
| 138 | /* |
| 139 | * DAVINCI_MCASP_PDIR_REG - Pin Direction Register Bits |
| 140 | */ |
| 141 | #define AXR(n) (1<<n) |
| 142 | #define PDIR_AMUTE BIT(25) |
| 143 | #define ACLKX BIT(26) |
| 144 | #define AHCLKX BIT(27) |
| 145 | #define AFSX BIT(28) |
| 146 | #define ACLKR BIT(29) |
| 147 | #define AHCLKR BIT(30) |
| 148 | #define AFSR BIT(31) |
| 149 | |
| 150 | /* |
| 151 | * DAVINCI_MCASP_TXDITCTL_REG - Transmit DIT Control Register Bits |
| 152 | */ |
| 153 | #define DITEN BIT(0) /* Transmit DIT mode enable/disable */ |
| 154 | #define VA BIT(2) |
| 155 | #define VB BIT(3) |
| 156 | |
| 157 | /* |
| 158 | * DAVINCI_MCASP_TXFMT_REG - Transmit Bitstream Format Register Bits |
| 159 | */ |
| 160 | #define TXROT(val) (val) |
| 161 | #define TXSEL BIT(3) |
| 162 | #define TXSSZ(val) (val<<4) |
| 163 | #define TXPBIT(val) (val<<8) |
| 164 | #define TXPAD(val) (val<<13) |
| 165 | #define TXORD BIT(15) |
| 166 | #define FSXDLY(val) (val<<16) |
| 167 | |
| 168 | /* |
| 169 | * DAVINCI_MCASP_RXFMT_REG - Receive Bitstream Format Register Bits |
| 170 | */ |
| 171 | #define RXROT(val) (val) |
| 172 | #define RXSEL BIT(3) |
| 173 | #define RXSSZ(val) (val<<4) |
| 174 | #define RXPBIT(val) (val<<8) |
| 175 | #define RXPAD(val) (val<<13) |
| 176 | #define RXORD BIT(15) |
| 177 | #define FSRDLY(val) (val<<16) |
| 178 | |
| 179 | /* |
| 180 | * DAVINCI_MCASP_TXFMCTL_REG - Transmit Frame Control Register Bits |
| 181 | */ |
| 182 | #define FSXPOL BIT(0) |
| 183 | #define AFSXE BIT(1) |
| 184 | #define FSXDUR BIT(4) |
| 185 | #define FSXMOD(val) (val<<7) |
| 186 | |
| 187 | /* |
| 188 | * DAVINCI_MCASP_RXFMCTL_REG - Receive Frame Control Register Bits |
| 189 | */ |
| 190 | #define FSRPOL BIT(0) |
| 191 | #define AFSRE BIT(1) |
| 192 | #define FSRDUR BIT(4) |
| 193 | #define FSRMOD(val) (val<<7) |
| 194 | |
| 195 | /* |
| 196 | * DAVINCI_MCASP_ACLKXCTL_REG - Transmit Clock Control Register Bits |
| 197 | */ |
| 198 | #define ACLKXDIV(val) (val) |
| 199 | #define ACLKXE BIT(5) |
| 200 | #define TX_ASYNC BIT(6) |
| 201 | #define ACLKXPOL BIT(7) |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 202 | #define ACLKXDIV_MASK 0x1f |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * DAVINCI_MCASP_ACLKRCTL_REG Receive Clock Control Register Bits |
| 206 | */ |
| 207 | #define ACLKRDIV(val) (val) |
| 208 | #define ACLKRE BIT(5) |
| 209 | #define RX_ASYNC BIT(6) |
| 210 | #define ACLKRPOL BIT(7) |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 211 | #define ACLKRDIV_MASK 0x1f |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 212 | |
| 213 | /* |
| 214 | * DAVINCI_MCASP_AHCLKXCTL_REG - High Frequency Transmit Clock Control |
| 215 | * Register Bits |
| 216 | */ |
| 217 | #define AHCLKXDIV(val) (val) |
| 218 | #define AHCLKXPOL BIT(14) |
| 219 | #define AHCLKXE BIT(15) |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 220 | #define AHCLKXDIV_MASK 0xfff |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * DAVINCI_MCASP_AHCLKRCTL_REG - High Frequency Receive Clock Control |
| 224 | * Register Bits |
| 225 | */ |
| 226 | #define AHCLKRDIV(val) (val) |
| 227 | #define AHCLKRPOL BIT(14) |
| 228 | #define AHCLKRE BIT(15) |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 229 | #define AHCLKRDIV_MASK 0xfff |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * DAVINCI_MCASP_XRSRCTL_BASE_REG - Serializer Control Register Bits |
| 233 | */ |
| 234 | #define MODE(val) (val) |
| 235 | #define DISMOD (val)(val<<2) |
| 236 | #define TXSTATE BIT(4) |
| 237 | #define RXSTATE BIT(5) |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 238 | #define SRMOD_MASK 3 |
| 239 | #define SRMOD_INACTIVE 0 |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * DAVINCI_MCASP_LBCTL_REG - Loop Back Control Register Bits |
| 243 | */ |
| 244 | #define LBEN BIT(0) |
| 245 | #define LBORD BIT(1) |
| 246 | #define LBGENMODE(val) (val<<2) |
| 247 | |
| 248 | /* |
| 249 | * DAVINCI_MCASP_TXTDMSLOT_REG - Transmit TDM Slot Register configuration |
| 250 | */ |
| 251 | #define TXTDMS(n) (1<<n) |
| 252 | |
| 253 | /* |
| 254 | * DAVINCI_MCASP_RXTDMSLOT_REG - Receive TDM Slot Register configuration |
| 255 | */ |
| 256 | #define RXTDMS(n) (1<<n) |
| 257 | |
| 258 | /* |
| 259 | * DAVINCI_MCASP_GBLCTL_REG - Global Control Register Bits |
| 260 | */ |
| 261 | #define RXCLKRST BIT(0) /* Receiver Clock Divider Reset */ |
| 262 | #define RXHCLKRST BIT(1) /* Receiver High Frequency Clock Divider */ |
| 263 | #define RXSERCLR BIT(2) /* Receiver Serializer Clear */ |
| 264 | #define RXSMRST BIT(3) /* Receiver State Machine Reset */ |
| 265 | #define RXFSRST BIT(4) /* Frame Sync Generator Reset */ |
| 266 | #define TXCLKRST BIT(8) /* Transmitter Clock Divider Reset */ |
| 267 | #define TXHCLKRST BIT(9) /* Transmitter High Frequency Clock Divider*/ |
| 268 | #define TXSERCLR BIT(10) /* Transmit Serializer Clear */ |
| 269 | #define TXSMRST BIT(11) /* Transmitter State Machine Reset */ |
| 270 | #define TXFSRST BIT(12) /* Frame Sync Generator Reset */ |
| 271 | |
| 272 | /* |
| 273 | * DAVINCI_MCASP_AMUTE_REG - Mute Control Register Bits |
| 274 | */ |
| 275 | #define MUTENA(val) (val) |
| 276 | #define MUTEINPOL BIT(2) |
| 277 | #define MUTEINENA BIT(3) |
| 278 | #define MUTEIN BIT(4) |
| 279 | #define MUTER BIT(5) |
| 280 | #define MUTEX BIT(6) |
| 281 | #define MUTEFSR BIT(7) |
| 282 | #define MUTEFSX BIT(8) |
| 283 | #define MUTEBADCLKR BIT(9) |
| 284 | #define MUTEBADCLKX BIT(10) |
| 285 | #define MUTERXDMAERR BIT(11) |
| 286 | #define MUTETXDMAERR BIT(12) |
| 287 | |
| 288 | /* |
| 289 | * DAVINCI_MCASP_REVTCTL_REG - Receiver DMA Event Control Register bits |
| 290 | */ |
| 291 | #define RXDATADMADIS BIT(0) |
| 292 | |
| 293 | /* |
| 294 | * DAVINCI_MCASP_XEVTCTL_REG - Transmitter DMA Event Control Register bits |
| 295 | */ |
| 296 | #define TXDATADMADIS BIT(0) |
| 297 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 298 | /* |
| 299 | * DAVINCI_MCASP_W[R]FIFOCTL - Write/Read FIFO Control Register bits |
| 300 | */ |
| 301 | #define FIFO_ENABLE BIT(16) |
| 302 | #define NUMEVT_MASK (0xFF << 8) |
| 303 | #define NUMDMA_MASK (0xFF) |
| 304 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 305 | #define DAVINCI_MCASP_NUM_SERIALIZER 16 |
| 306 | |
| 307 | static inline void mcasp_set_bits(void __iomem *reg, u32 val) |
| 308 | { |
| 309 | __raw_writel(__raw_readl(reg) | val, reg); |
| 310 | } |
| 311 | |
| 312 | static inline void mcasp_clr_bits(void __iomem *reg, u32 val) |
| 313 | { |
| 314 | __raw_writel((__raw_readl(reg) & ~(val)), reg); |
| 315 | } |
| 316 | |
| 317 | static inline void mcasp_mod_bits(void __iomem *reg, u32 val, u32 mask) |
| 318 | { |
| 319 | __raw_writel((__raw_readl(reg) & ~mask) | val, reg); |
| 320 | } |
| 321 | |
| 322 | static inline void mcasp_set_reg(void __iomem *reg, u32 val) |
| 323 | { |
| 324 | __raw_writel(val, reg); |
| 325 | } |
| 326 | |
| 327 | static inline u32 mcasp_get_reg(void __iomem *reg) |
| 328 | { |
| 329 | return (unsigned int)__raw_readl(reg); |
| 330 | } |
| 331 | |
| 332 | static inline void mcasp_set_ctl_reg(void __iomem *regs, u32 val) |
| 333 | { |
| 334 | int i = 0; |
| 335 | |
| 336 | mcasp_set_bits(regs, val); |
| 337 | |
| 338 | /* programming GBLCTL needs to read back from GBLCTL and verfiy */ |
| 339 | /* loop count is to avoid the lock-up */ |
| 340 | for (i = 0; i < 1000; i++) { |
| 341 | if ((mcasp_get_reg(regs) & val) == val) |
| 342 | break; |
| 343 | } |
| 344 | |
| 345 | if (i == 1000 && ((mcasp_get_reg(regs) & val) != val)) |
| 346 | printk(KERN_ERR "GBLCTL write error\n"); |
| 347 | } |
| 348 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 349 | static void mcasp_start_rx(struct davinci_audio_dev *dev) |
| 350 | { |
| 351 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXHCLKRST); |
| 352 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXCLKRST); |
| 353 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSERCLR); |
| 354 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); |
| 355 | |
| 356 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); |
| 357 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); |
| 358 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXBUF_REG, 0); |
| 359 | |
| 360 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXSMRST); |
| 361 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, RXFSRST); |
| 362 | } |
| 363 | |
| 364 | static void mcasp_start_tx(struct davinci_audio_dev *dev) |
| 365 | { |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 366 | u8 offset = 0, i; |
| 367 | u32 cnt; |
| 368 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 369 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXHCLKRST); |
| 370 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXCLKRST); |
| 371 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSERCLR); |
| 372 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
| 373 | |
| 374 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXSMRST); |
| 375 | mcasp_set_ctl_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, TXFSRST); |
| 376 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 377 | for (i = 0; i < dev->num_serializer; i++) { |
| 378 | if (dev->serial_dir[i] == TX_MODE) { |
| 379 | offset = i; |
| 380 | break; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | /* wait for TX ready */ |
| 385 | cnt = 0; |
| 386 | while (!(mcasp_get_reg(dev->base + DAVINCI_MCASP_XRSRCTL_REG(offset)) & |
| 387 | TXSTATE) && (cnt < 100000)) |
| 388 | cnt++; |
| 389 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 390 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXBUF_REG, 0); |
| 391 | } |
| 392 | |
| 393 | static void davinci_mcasp_start(struct davinci_audio_dev *dev, int stream) |
| 394 | { |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 395 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 396 | if (dev->txnumevt) { /* enable FIFO */ |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 397 | switch (dev->version) { |
| 398 | case MCASP_VERSION_3: |
| 399 | mcasp_clr_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 400 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 401 | mcasp_set_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 402 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 403 | break; |
| 404 | default: |
| 405 | mcasp_clr_bits(dev->base + |
| 406 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 407 | mcasp_set_bits(dev->base + |
| 408 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 409 | } |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 410 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 411 | mcasp_start_tx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 412 | } else { |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 413 | if (dev->rxnumevt) { /* enable FIFO */ |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 414 | switch (dev->version) { |
| 415 | case MCASP_VERSION_3: |
| 416 | mcasp_clr_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 417 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 418 | mcasp_set_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 419 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 420 | break; |
| 421 | default: |
| 422 | mcasp_clr_bits(dev->base + |
| 423 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 424 | mcasp_set_bits(dev->base + |
| 425 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 426 | } |
Vaibhav Bedia | 0d62427 | 2012-08-08 20:40:31 +0530 | [diff] [blame] | 427 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 428 | mcasp_start_rx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 429 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static void mcasp_stop_rx(struct davinci_audio_dev *dev) |
| 433 | { |
| 434 | mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLR_REG, 0); |
| 435 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); |
| 436 | } |
| 437 | |
| 438 | static void mcasp_stop_tx(struct davinci_audio_dev *dev) |
| 439 | { |
| 440 | mcasp_set_reg(dev->base + DAVINCI_MCASP_GBLCTLX_REG, 0); |
| 441 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); |
| 442 | } |
| 443 | |
| 444 | static void davinci_mcasp_stop(struct davinci_audio_dev *dev, int stream) |
| 445 | { |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 446 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 447 | if (dev->txnumevt) { /* disable FIFO */ |
| 448 | switch (dev->version) { |
| 449 | case MCASP_VERSION_3: |
| 450 | mcasp_clr_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 451 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 452 | break; |
| 453 | default: |
| 454 | mcasp_clr_bits(dev->base + |
| 455 | DAVINCI_MCASP_WFIFOCTL, FIFO_ENABLE); |
| 456 | } |
| 457 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 458 | mcasp_stop_tx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 459 | } else { |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 460 | if (dev->rxnumevt) { /* disable FIFO */ |
| 461 | switch (dev->version) { |
| 462 | case MCASP_VERSION_3: |
| 463 | mcasp_clr_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 464 | FIFO_ENABLE); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 465 | break; |
| 466 | |
| 467 | default: |
| 468 | mcasp_clr_bits(dev->base + |
| 469 | DAVINCI_MCASP_RFIFOCTL, FIFO_ENABLE); |
| 470 | } |
| 471 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 472 | mcasp_stop_rx(dev); |
Chaithrika U S | 539d3d8 | 2009-09-23 10:12:08 -0400 | [diff] [blame] | 473 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | static int davinci_mcasp_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
| 477 | unsigned int fmt) |
| 478 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 479 | 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] | 480 | void __iomem *base = dev->base; |
| 481 | |
Daniel Mack | 5296cf2 | 2012-10-04 15:08:42 +0200 | [diff] [blame] | 482 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 483 | case SND_SOC_DAIFMT_DSP_B: |
| 484 | case SND_SOC_DAIFMT_AC97: |
| 485 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR); |
| 486 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR); |
| 487 | break; |
| 488 | default: |
| 489 | /* configure a full-word SYNC pulse (LRCLK) */ |
| 490 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, FSXDUR); |
| 491 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, FSRDUR); |
| 492 | |
| 493 | /* make 1st data bit occur one ACLK cycle after the frame sync */ |
| 494 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, FSXDLY(1)); |
| 495 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, FSRDLY(1)); |
| 496 | break; |
| 497 | } |
| 498 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 499 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 500 | case SND_SOC_DAIFMT_CBS_CFS: |
| 501 | /* codec is clock and frame slave */ |
| 502 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
| 503 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 504 | |
| 505 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
| 506 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 507 | |
Marek Belisko | 81ee683 | 2013-04-26 14:38:11 +0200 | [diff] [blame] | 508 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 509 | ACLKX | ACLKR); |
| 510 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 511 | AFSX | AFSR); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 512 | break; |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 513 | case SND_SOC_DAIFMT_CBM_CFS: |
| 514 | /* codec is clock master and frame slave */ |
Ben Gardiner | a90f549 | 2011-04-21 14:19:03 -0400 | [diff] [blame] | 515 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 516 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 517 | |
Ben Gardiner | a90f549 | 2011-04-21 14:19:03 -0400 | [diff] [blame] | 518 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 519 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 520 | |
Ben Gardiner | db92f43 | 2011-04-21 14:19:04 -0400 | [diff] [blame] | 521 | mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 522 | ACLKX | ACLKR); |
Ben Gardiner | 9595c8f | 2011-04-21 14:19:02 -0400 | [diff] [blame] | 523 | mcasp_set_bits(base + DAVINCI_MCASP_PDIR_REG, |
Ben Gardiner | db92f43 | 2011-04-21 14:19:04 -0400 | [diff] [blame] | 524 | AFSX | AFSR); |
Chaithrika U S | 517ee6c | 2009-08-11 16:59:12 -0400 | [diff] [blame] | 525 | break; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 526 | case SND_SOC_DAIFMT_CBM_CFM: |
| 527 | /* codec is clock and frame master */ |
| 528 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXE); |
| 529 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, AFSXE); |
| 530 | |
| 531 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRE); |
| 532 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, AFSRE); |
| 533 | |
Ben Gardiner | 9595c8f | 2011-04-21 14:19:02 -0400 | [diff] [blame] | 534 | mcasp_clr_bits(base + DAVINCI_MCASP_PDIR_REG, |
| 535 | ACLKX | AHCLKX | AFSX | ACLKR | AHCLKR | AFSR); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 536 | break; |
| 537 | |
| 538 | default: |
| 539 | return -EINVAL; |
| 540 | } |
| 541 | |
| 542 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 543 | case SND_SOC_DAIFMT_IB_NF: |
| 544 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 545 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 546 | |
| 547 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 548 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 549 | break; |
| 550 | |
| 551 | case SND_SOC_DAIFMT_NB_IF: |
| 552 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 553 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 554 | |
| 555 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 556 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 557 | break; |
| 558 | |
| 559 | case SND_SOC_DAIFMT_IB_IF: |
| 560 | mcasp_clr_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 561 | mcasp_set_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 562 | |
| 563 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
| 564 | mcasp_set_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 565 | break; |
| 566 | |
| 567 | case SND_SOC_DAIFMT_NB_NF: |
| 568 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKXCTL_REG, ACLKXPOL); |
| 569 | mcasp_clr_bits(base + DAVINCI_MCASP_TXFMCTL_REG, FSXPOL); |
| 570 | |
Marek Belisko | df4a4ee | 2013-05-03 07:37:36 +0200 | [diff] [blame] | 571 | mcasp_set_bits(base + DAVINCI_MCASP_ACLKRCTL_REG, ACLKRPOL); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 572 | mcasp_clr_bits(base + DAVINCI_MCASP_RXFMCTL_REG, FSRPOL); |
| 573 | break; |
| 574 | |
| 575 | default: |
| 576 | return -EINVAL; |
| 577 | } |
| 578 | |
| 579 | return 0; |
| 580 | } |
| 581 | |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 582 | static int davinci_mcasp_set_clkdiv(struct snd_soc_dai *dai, int div_id, int div) |
| 583 | { |
| 584 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 585 | |
| 586 | switch (div_id) { |
| 587 | case 0: /* MCLK divider */ |
| 588 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, |
| 589 | AHCLKXDIV(div - 1), AHCLKXDIV_MASK); |
| 590 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, |
| 591 | AHCLKRDIV(div - 1), AHCLKRDIV_MASK); |
| 592 | break; |
| 593 | |
| 594 | case 1: /* BCLK divider */ |
| 595 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, |
| 596 | ACLKXDIV(div - 1), ACLKXDIV_MASK); |
| 597 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_ACLKRCTL_REG, |
| 598 | ACLKRDIV(div - 1), ACLKRDIV_MASK); |
| 599 | break; |
| 600 | |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 601 | case 2: /* BCLK/LRCLK ratio */ |
| 602 | dev->bclk_lrclk_ratio = div; |
| 603 | break; |
| 604 | |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 605 | default: |
| 606 | return -EINVAL; |
| 607 | } |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 612 | static int davinci_mcasp_set_sysclk(struct snd_soc_dai *dai, int clk_id, |
| 613 | unsigned int freq, int dir) |
| 614 | { |
| 615 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 616 | |
| 617 | if (dir == SND_SOC_CLOCK_OUT) { |
| 618 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); |
| 619 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); |
| 620 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX); |
| 621 | } else { |
| 622 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXE); |
| 623 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_AHCLKRCTL_REG, AHCLKRE); |
| 624 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, AHCLKX); |
| 625 | } |
| 626 | |
| 627 | return 0; |
| 628 | } |
| 629 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 630 | static int davinci_config_channel_size(struct davinci_audio_dev *dev, |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 631 | int word_length) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 632 | { |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 633 | u32 fmt; |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 634 | u32 tx_rotate = (word_length / 4) & 0x7; |
| 635 | u32 rx_rotate = (32 - word_length) / 4; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 636 | u32 mask = (1ULL << word_length) - 1; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 637 | |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 638 | /* |
| 639 | * if s BCLK-to-LRCLK ratio has been configured via the set_clkdiv() |
| 640 | * callback, take it into account here. That allows us to for example |
| 641 | * send 32 bits per channel to the codec, while only 16 of them carry |
| 642 | * audio payload. |
Michal Bachraty | d486fea | 2013-04-19 15:28:44 +0200 | [diff] [blame] | 643 | * The clock ratio is given for a full period of data (for I2S format |
| 644 | * both left and right channels), so it has to be divided by number of |
| 645 | * tdm-slots (for I2S - divided by 2). |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 646 | */ |
| 647 | if (dev->bclk_lrclk_ratio) |
Michal Bachraty | d486fea | 2013-04-19 15:28:44 +0200 | [diff] [blame] | 648 | word_length = dev->bclk_lrclk_ratio / dev->tdm_slots; |
Daniel Mack | 1b3bc06 | 2012-12-05 18:20:38 +0100 | [diff] [blame] | 649 | |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 650 | /* mapping of the XSSZ bit-field as described in the datasheet */ |
| 651 | fmt = (word_length >> 1) - 1; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 652 | |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 653 | if (dev->op_mode != DAVINCI_MCASP_DIT_MODE) { |
| 654 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, |
| 655 | RXSSZ(fmt), RXSSZ(0x0F)); |
| 656 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
| 657 | TXSSZ(fmt), TXSSZ(0x0F)); |
| 658 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 659 | TXROT(tx_rotate), TXROT(7)); |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 660 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, |
Daniel Mack | 7967189 | 2013-05-16 15:25:01 +0200 | [diff] [blame] | 661 | RXROT(rx_rotate), RXROT(7)); |
Yegor Yefremov | f5023af | 2013-04-04 16:13:20 +0200 | [diff] [blame] | 662 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXMASK_REG, |
| 663 | mask); |
| 664 | } |
| 665 | |
Chaithrika U S | 0c31cf3 | 2009-09-15 18:13:29 -0400 | [diff] [blame] | 666 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXMASK_REG, mask); |
Chaithrika U S | 0c31cf3 | 2009-09-15 18:13:29 -0400 | [diff] [blame] | 667 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 668 | return 0; |
| 669 | } |
| 670 | |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 671 | static int davinci_hw_common_param(struct davinci_audio_dev *dev, int stream, |
| 672 | int channels) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 673 | { |
| 674 | int i; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 675 | u8 tx_ser = 0; |
| 676 | u8 rx_ser = 0; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 677 | u8 ser; |
| 678 | u8 slots = dev->tdm_slots; |
| 679 | u8 max_active_serializers = (channels + slots - 1) / slots; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 680 | /* Default configuration */ |
| 681 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PWREMUMGT_REG, MCASP_SOFT); |
| 682 | |
| 683 | /* All PINS as McASP */ |
| 684 | mcasp_set_reg(dev->base + DAVINCI_MCASP_PFUNC_REG, 0x00000000); |
| 685 | |
| 686 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 687 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXSTAT_REG, 0xFFFFFFFF); |
| 688 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, |
| 689 | TXDATADMADIS); |
| 690 | } else { |
| 691 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXSTAT_REG, 0xFFFFFFFF); |
| 692 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_REVTCTL_REG, |
| 693 | RXDATADMADIS); |
| 694 | } |
| 695 | |
| 696 | for (i = 0; i < dev->num_serializer; i++) { |
| 697 | mcasp_set_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i), |
| 698 | dev->serial_dir[i]); |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 699 | if (dev->serial_dir[i] == TX_MODE && |
| 700 | tx_ser < max_active_serializers) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 701 | mcasp_set_bits(dev->base + DAVINCI_MCASP_PDIR_REG, |
| 702 | AXR(i)); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 703 | tx_ser++; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 704 | } else if (dev->serial_dir[i] == RX_MODE && |
| 705 | rx_ser < max_active_serializers) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 706 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_PDIR_REG, |
| 707 | AXR(i)); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 708 | rx_ser++; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 709 | } else { |
| 710 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_XRSRCTL_REG(i), |
| 711 | SRMOD_INACTIVE, SRMOD_MASK); |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Daniel Mack | ecf327c | 2013-03-08 14:19:38 +0100 | [diff] [blame] | 715 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 716 | ser = tx_ser; |
| 717 | else |
| 718 | ser = rx_ser; |
| 719 | |
| 720 | if (ser < max_active_serializers) { |
| 721 | dev_warn(dev->dev, "stream has more channels (%d) than are " |
| 722 | "enabled in mcasp (%d)\n", channels, ser * slots); |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 726 | if (dev->txnumevt && stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 727 | if (dev->txnumevt * tx_ser > 64) |
| 728 | dev->txnumevt = 1; |
| 729 | |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 730 | switch (dev->version) { |
| 731 | case MCASP_VERSION_3: |
| 732 | mcasp_mod_bits(dev->base + MCASP_VER3_WFIFOCTL, tx_ser, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 733 | NUMDMA_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 734 | mcasp_mod_bits(dev->base + MCASP_VER3_WFIFOCTL, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 735 | ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 736 | break; |
| 737 | default: |
| 738 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, |
| 739 | tx_ser, NUMDMA_MASK); |
| 740 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_WFIFOCTL, |
| 741 | ((dev->txnumevt * tx_ser) << 8), NUMEVT_MASK); |
| 742 | } |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (dev->rxnumevt && stream == SNDRV_PCM_STREAM_CAPTURE) { |
| 746 | if (dev->rxnumevt * rx_ser > 64) |
| 747 | dev->rxnumevt = 1; |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 748 | switch (dev->version) { |
| 749 | case MCASP_VERSION_3: |
| 750 | mcasp_mod_bits(dev->base + MCASP_VER3_RFIFOCTL, rx_ser, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 751 | NUMDMA_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 752 | mcasp_mod_bits(dev->base + MCASP_VER3_RFIFOCTL, |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 753 | ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 754 | break; |
| 755 | default: |
| 756 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, |
| 757 | rx_ser, NUMDMA_MASK); |
| 758 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RFIFOCTL, |
| 759 | ((dev->rxnumevt * rx_ser) << 8), NUMEVT_MASK); |
| 760 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 761 | } |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 762 | |
| 763 | return 0; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void davinci_hw_param(struct davinci_audio_dev *dev, int stream) |
| 767 | { |
| 768 | int i, active_slots; |
| 769 | u32 mask = 0; |
| 770 | |
| 771 | active_slots = (dev->tdm_slots > 31) ? 32 : dev->tdm_slots; |
| 772 | for (i = 0; i < active_slots; i++) |
| 773 | mask |= (1 << i); |
| 774 | |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 775 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, TX_ASYNC); |
| 776 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 777 | if (stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 778 | /* bit stream is MSB first with no delay */ |
| 779 | /* DSP_B mode */ |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 780 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, mask); |
| 781 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, TXORD); |
| 782 | |
Ben Gardiner | 049cfaa | 2011-04-21 14:19:01 -0400 | [diff] [blame] | 783 | if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 784 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_TXFMCTL_REG, |
| 785 | FSXMOD(dev->tdm_slots), FSXMOD(0x1FF)); |
| 786 | else |
| 787 | printk(KERN_ERR "playback tdm slot %d not supported\n", |
| 788 | dev->tdm_slots); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 789 | } else { |
| 790 | /* bit stream is MSB first with no delay */ |
| 791 | /* DSP_B mode */ |
| 792 | mcasp_set_bits(dev->base + DAVINCI_MCASP_RXFMT_REG, RXORD); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 793 | mcasp_set_reg(dev->base + DAVINCI_MCASP_RXTDM_REG, mask); |
| 794 | |
Ben Gardiner | 049cfaa | 2011-04-21 14:19:01 -0400 | [diff] [blame] | 795 | if ((dev->tdm_slots >= 2) && (dev->tdm_slots <= 32)) |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 796 | mcasp_mod_bits(dev->base + DAVINCI_MCASP_RXFMCTL_REG, |
| 797 | FSRMOD(dev->tdm_slots), FSRMOD(0x1FF)); |
| 798 | else |
| 799 | printk(KERN_ERR "capture tdm slot %d not supported\n", |
| 800 | dev->tdm_slots); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 801 | } |
| 802 | } |
| 803 | |
| 804 | /* S/PDIF */ |
| 805 | static void davinci_hw_dit_param(struct davinci_audio_dev *dev) |
| 806 | { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 807 | /* Set the TX format : 24 bit right rotation, 32 bit slot, Pad 0 |
| 808 | and LSB first */ |
| 809 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXFMT_REG, |
| 810 | TXROT(6) | TXSSZ(15)); |
| 811 | |
| 812 | /* Set TX frame synch : DIT Mode, 1 bit width, internal, rising edge */ |
| 813 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXFMCTL_REG, |
| 814 | AFSXE | FSXMOD(0x180)); |
| 815 | |
| 816 | /* Set the TX tdm : for all the slots */ |
| 817 | mcasp_set_reg(dev->base + DAVINCI_MCASP_TXTDM_REG, 0xFFFFFFFF); |
| 818 | |
| 819 | /* Set the TX clock controls : div = 1 and internal */ |
| 820 | mcasp_set_bits(dev->base + DAVINCI_MCASP_ACLKXCTL_REG, |
| 821 | ACLKXE | TX_ASYNC); |
| 822 | |
| 823 | mcasp_clr_bits(dev->base + DAVINCI_MCASP_XEVTCTL_REG, TXDATADMADIS); |
| 824 | |
| 825 | /* Only 44100 and 48000 are valid, both have the same setting */ |
| 826 | mcasp_set_bits(dev->base + DAVINCI_MCASP_AHCLKXCTL_REG, AHCLKXDIV(3)); |
| 827 | |
| 828 | /* Enable the DIT */ |
| 829 | mcasp_set_bits(dev->base + DAVINCI_MCASP_TXDITCTL_REG, DITEN); |
| 830 | } |
| 831 | |
| 832 | static int davinci_mcasp_hw_params(struct snd_pcm_substream *substream, |
| 833 | struct snd_pcm_hw_params *params, |
| 834 | struct snd_soc_dai *cpu_dai) |
| 835 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 836 | 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] | 837 | struct davinci_pcm_dma_params *dma_params = |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 838 | &dev->dma_params[substream->stream]; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 839 | int word_length; |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 840 | u8 fifo_level; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 841 | u8 slots = dev->tdm_slots; |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 842 | u8 active_serializers; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 843 | int channels; |
| 844 | struct snd_interval *pcm_channels = hw_param_interval(params, |
| 845 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 846 | channels = pcm_channels->min; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 847 | |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 848 | active_serializers = (channels + slots - 1) / slots; |
| 849 | |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 850 | if (davinci_hw_common_param(dev, substream->stream, channels) == -EINVAL) |
| 851 | return -EINVAL; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 852 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 853 | fifo_level = dev->txnumevt * active_serializers; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 854 | else |
Michal Bachraty | 7c21a78 | 2013-04-19 15:28:03 +0200 | [diff] [blame] | 855 | fifo_level = dev->rxnumevt * active_serializers; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 856 | |
| 857 | if (dev->op_mode == DAVINCI_MCASP_DIT_MODE) |
| 858 | davinci_hw_dit_param(dev); |
| 859 | else |
| 860 | davinci_hw_param(dev, substream->stream); |
| 861 | |
| 862 | switch (params_format(params)) { |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 863 | case SNDRV_PCM_FORMAT_U8: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 864 | case SNDRV_PCM_FORMAT_S8: |
| 865 | dma_params->data_type = 1; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 866 | word_length = 8; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 867 | break; |
| 868 | |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 869 | case SNDRV_PCM_FORMAT_U16_LE: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 870 | case SNDRV_PCM_FORMAT_S16_LE: |
| 871 | dma_params->data_type = 2; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 872 | word_length = 16; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 873 | break; |
| 874 | |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 875 | case SNDRV_PCM_FORMAT_U24_3LE: |
| 876 | case SNDRV_PCM_FORMAT_S24_3LE: |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 877 | dma_params->data_type = 3; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 878 | word_length = 24; |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 879 | break; |
| 880 | |
Daniel Mack | 6b7fa01 | 2012-10-09 11:56:40 +0200 | [diff] [blame] | 881 | case SNDRV_PCM_FORMAT_U24_LE: |
| 882 | case SNDRV_PCM_FORMAT_S24_LE: |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 883 | case SNDRV_PCM_FORMAT_U32_LE: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 884 | case SNDRV_PCM_FORMAT_S32_LE: |
| 885 | dma_params->data_type = 4; |
Daniel Mack | ba764b3 | 2012-12-05 18:20:37 +0100 | [diff] [blame] | 886 | word_length = 32; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | default: |
| 890 | printk(KERN_WARNING "davinci-mcasp: unsupported PCM format"); |
| 891 | return -EINVAL; |
| 892 | } |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 893 | |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 894 | if (dev->version == MCASP_VERSION_2 && !fifo_level) |
| 895 | dma_params->acnt = 4; |
| 896 | else |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 897 | dma_params->acnt = dma_params->data_type; |
| 898 | |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 899 | dma_params->fifo_level = fifo_level; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 900 | davinci_config_channel_size(dev, word_length); |
| 901 | |
| 902 | return 0; |
| 903 | } |
| 904 | |
| 905 | static int davinci_mcasp_trigger(struct snd_pcm_substream *substream, |
| 906 | int cmd, struct snd_soc_dai *cpu_dai) |
| 907 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 908 | 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] | 909 | int ret = 0; |
| 910 | |
| 911 | switch (cmd) { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 912 | case SNDRV_PCM_TRIGGER_RESUME: |
Chaithrika U S | e473b84 | 2010-01-20 17:06:33 +0530 | [diff] [blame] | 913 | case SNDRV_PCM_TRIGGER_START: |
| 914 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 915 | ret = pm_runtime_get_sync(dev->dev); |
| 916 | if (IS_ERR_VALUE(ret)) |
| 917 | dev_err(dev->dev, "pm_runtime_get_sync() failed\n"); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 918 | davinci_mcasp_start(dev, substream->stream); |
| 919 | break; |
| 920 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 921 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Chaithrika U S | a47979b | 2009-12-03 18:56:56 +0530 | [diff] [blame] | 922 | davinci_mcasp_stop(dev, substream->stream); |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 923 | ret = pm_runtime_put_sync(dev->dev); |
| 924 | if (IS_ERR_VALUE(ret)) |
| 925 | dev_err(dev->dev, "pm_runtime_put_sync() failed\n"); |
Chaithrika U S | a47979b | 2009-12-03 18:56:56 +0530 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case SNDRV_PCM_TRIGGER_STOP: |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 929 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 930 | davinci_mcasp_stop(dev, substream->stream); |
| 931 | break; |
| 932 | |
| 933 | default: |
| 934 | ret = -EINVAL; |
| 935 | } |
| 936 | |
| 937 | return ret; |
| 938 | } |
| 939 | |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 940 | static int davinci_mcasp_startup(struct snd_pcm_substream *substream, |
| 941 | struct snd_soc_dai *dai) |
| 942 | { |
| 943 | struct davinci_audio_dev *dev = snd_soc_dai_get_drvdata(dai); |
| 944 | |
| 945 | snd_soc_dai_set_dma_data(dai, substream, dev->dma_params); |
| 946 | return 0; |
| 947 | } |
| 948 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 949 | static const struct snd_soc_dai_ops davinci_mcasp_dai_ops = { |
Chris Paulson-Ellis | bedad0c | 2010-11-16 12:27:09 +0000 | [diff] [blame] | 950 | .startup = davinci_mcasp_startup, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 951 | .trigger = davinci_mcasp_trigger, |
| 952 | .hw_params = davinci_mcasp_hw_params, |
| 953 | .set_fmt = davinci_mcasp_set_dai_fmt, |
Daniel Mack | 4ed8c9b | 2012-10-04 15:08:39 +0200 | [diff] [blame] | 954 | .set_clkdiv = davinci_mcasp_set_clkdiv, |
Daniel Mack | 5b66aa2 | 2012-10-04 15:08:41 +0200 | [diff] [blame] | 955 | .set_sysclk = davinci_mcasp_set_sysclk, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 956 | }; |
| 957 | |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 958 | #define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \ |
| 959 | SNDRV_PCM_FMTBIT_U8 | \ |
| 960 | SNDRV_PCM_FMTBIT_S16_LE | \ |
| 961 | SNDRV_PCM_FMTBIT_U16_LE | \ |
Daniel Mack | 21eb24d | 2012-10-09 09:35:16 +0200 | [diff] [blame] | 962 | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 963 | SNDRV_PCM_FMTBIT_U24_LE | \ |
| 964 | SNDRV_PCM_FMTBIT_S24_3LE | \ |
| 965 | SNDRV_PCM_FMTBIT_U24_3LE | \ |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 966 | SNDRV_PCM_FMTBIT_S32_LE | \ |
| 967 | SNDRV_PCM_FMTBIT_U32_LE) |
| 968 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 969 | static struct snd_soc_dai_driver davinci_mcasp_dai[] = { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 970 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 971 | .name = "davinci-mcasp.0", |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 972 | .playback = { |
| 973 | .channels_min = 2, |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 974 | .channels_max = 32 * 16, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 975 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 976 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 977 | }, |
| 978 | .capture = { |
| 979 | .channels_min = 2, |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 980 | .channels_max = 32 * 16, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 981 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 982 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 983 | }, |
| 984 | .ops = &davinci_mcasp_dai_ops, |
| 985 | |
| 986 | }, |
| 987 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 988 | "davinci-mcasp.1", |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 989 | .playback = { |
| 990 | .channels_min = 1, |
| 991 | .channels_max = 384, |
| 992 | .rates = DAVINCI_MCASP_RATES, |
Ben Gardiner | 0a9d138 | 2011-08-26 12:02:44 -0400 | [diff] [blame] | 993 | .formats = DAVINCI_MCASP_PCM_FMTS, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 994 | }, |
| 995 | .ops = &davinci_mcasp_dai_ops, |
| 996 | }, |
| 997 | |
| 998 | }; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 999 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1000 | static const struct snd_soc_component_driver davinci_mcasp_component = { |
| 1001 | .name = "davinci-mcasp", |
| 1002 | }; |
| 1003 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1004 | /* Some HW specific values and defaults. The rest is filled in from DT. */ |
| 1005 | static struct snd_platform_data dm646x_mcasp_pdata = { |
| 1006 | .tx_dma_offset = 0x400, |
| 1007 | .rx_dma_offset = 0x400, |
| 1008 | .asp_chan_q = EVENTQ_0, |
| 1009 | .version = MCASP_VERSION_1, |
| 1010 | }; |
| 1011 | |
| 1012 | static struct snd_platform_data da830_mcasp_pdata = { |
| 1013 | .tx_dma_offset = 0x2000, |
| 1014 | .rx_dma_offset = 0x2000, |
| 1015 | .asp_chan_q = EVENTQ_0, |
| 1016 | .version = MCASP_VERSION_2, |
| 1017 | }; |
| 1018 | |
| 1019 | static struct snd_platform_data omap2_mcasp_pdata = { |
| 1020 | .tx_dma_offset = 0, |
| 1021 | .rx_dma_offset = 0, |
| 1022 | .asp_chan_q = EVENTQ_0, |
| 1023 | .version = MCASP_VERSION_3, |
| 1024 | }; |
| 1025 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1026 | static const struct of_device_id mcasp_dt_ids[] = { |
| 1027 | { |
| 1028 | .compatible = "ti,dm646x-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1029 | .data = &dm646x_mcasp_pdata, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1030 | }, |
| 1031 | { |
| 1032 | .compatible = "ti,da830-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1033 | .data = &da830_mcasp_pdata, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1034 | }, |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 1035 | { |
Jyri Sarha | 3af9e03 | 2013-10-18 18:37:44 +0300 | [diff] [blame] | 1036 | .compatible = "ti,am33xx-mcasp-audio", |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1037 | .data = &omap2_mcasp_pdata, |
Hebbar, Gururaja | e5ec69d | 2012-09-03 13:40:40 +0530 | [diff] [blame] | 1038 | }, |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1039 | { /* sentinel */ } |
| 1040 | }; |
| 1041 | MODULE_DEVICE_TABLE(of, mcasp_dt_ids); |
| 1042 | |
| 1043 | static struct snd_platform_data *davinci_mcasp_set_pdata_from_of( |
| 1044 | struct platform_device *pdev) |
| 1045 | { |
| 1046 | struct device_node *np = pdev->dev.of_node; |
| 1047 | struct snd_platform_data *pdata = NULL; |
| 1048 | const struct of_device_id *match = |
Sachin Kamat | ea421eb | 2013-05-22 16:53:37 +0530 | [diff] [blame] | 1049 | of_match_device(mcasp_dt_ids, &pdev->dev); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 1050 | struct of_phandle_args dma_spec; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1051 | |
| 1052 | const u32 *of_serial_dir32; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1053 | u32 val; |
| 1054 | int i, ret = 0; |
| 1055 | |
| 1056 | if (pdev->dev.platform_data) { |
| 1057 | pdata = pdev->dev.platform_data; |
| 1058 | return pdata; |
| 1059 | } else if (match) { |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1060 | pdata = (struct snd_platform_data *) match->data; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1061 | } else { |
| 1062 | /* control shouldn't reach here. something is wrong */ |
| 1063 | ret = -EINVAL; |
| 1064 | goto nodata; |
| 1065 | } |
| 1066 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1067 | ret = of_property_read_u32(np, "op-mode", &val); |
| 1068 | if (ret >= 0) |
| 1069 | pdata->op_mode = val; |
| 1070 | |
| 1071 | ret = of_property_read_u32(np, "tdm-slots", &val); |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 1072 | if (ret >= 0) { |
| 1073 | if (val < 2 || val > 32) { |
| 1074 | dev_err(&pdev->dev, |
| 1075 | "tdm-slots must be in rage [2-32]\n"); |
| 1076 | ret = -EINVAL; |
| 1077 | goto nodata; |
| 1078 | } |
| 1079 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1080 | pdata->tdm_slots = val; |
Michal Bachraty | 2952b27 | 2013-02-28 16:07:08 +0100 | [diff] [blame] | 1081 | } |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1082 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1083 | of_serial_dir32 = of_get_property(np, "serial-dir", &val); |
| 1084 | val /= sizeof(u32); |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1085 | if (of_serial_dir32) { |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame^] | 1086 | u8 *of_serial_dir = devm_kzalloc(&pdev->dev, |
| 1087 | (sizeof(*of_serial_dir) * val), |
| 1088 | GFP_KERNEL); |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1089 | if (!of_serial_dir) { |
| 1090 | ret = -ENOMEM; |
| 1091 | goto nodata; |
| 1092 | } |
| 1093 | |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame^] | 1094 | for (i = 0; i < val; i++) |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1095 | of_serial_dir[i] = be32_to_cpup(&of_serial_dir32[i]); |
| 1096 | |
Peter Ujfalusi | 1427e66 | 2013-10-18 18:37:46 +0300 | [diff] [blame^] | 1097 | pdata->num_serializer = val; |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1098 | pdata->serial_dir = of_serial_dir; |
| 1099 | } |
| 1100 | |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 1101 | ret = of_property_match_string(np, "dma-names", "tx"); |
| 1102 | if (ret < 0) |
| 1103 | goto nodata; |
| 1104 | |
| 1105 | ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret, |
| 1106 | &dma_spec); |
| 1107 | if (ret < 0) |
| 1108 | goto nodata; |
| 1109 | |
| 1110 | pdata->tx_dma_channel = dma_spec.args[0]; |
| 1111 | |
| 1112 | ret = of_property_match_string(np, "dma-names", "rx"); |
| 1113 | if (ret < 0) |
| 1114 | goto nodata; |
| 1115 | |
| 1116 | ret = of_parse_phandle_with_args(np, "dmas", "#dma-cells", ret, |
| 1117 | &dma_spec); |
| 1118 | if (ret < 0) |
| 1119 | goto nodata; |
| 1120 | |
| 1121 | pdata->rx_dma_channel = dma_spec.args[0]; |
| 1122 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1123 | ret = of_property_read_u32(np, "tx-num-evt", &val); |
| 1124 | if (ret >= 0) |
| 1125 | pdata->txnumevt = val; |
| 1126 | |
| 1127 | ret = of_property_read_u32(np, "rx-num-evt", &val); |
| 1128 | if (ret >= 0) |
| 1129 | pdata->rxnumevt = val; |
| 1130 | |
| 1131 | ret = of_property_read_u32(np, "sram-size-playback", &val); |
| 1132 | if (ret >= 0) |
| 1133 | pdata->sram_size_playback = val; |
| 1134 | |
| 1135 | ret = of_property_read_u32(np, "sram-size-capture", &val); |
| 1136 | if (ret >= 0) |
| 1137 | pdata->sram_size_capture = val; |
| 1138 | |
| 1139 | return pdata; |
| 1140 | |
| 1141 | nodata: |
| 1142 | if (ret < 0) { |
| 1143 | dev_err(&pdev->dev, "Error populating platform data, err %d\n", |
| 1144 | ret); |
| 1145 | pdata = NULL; |
| 1146 | } |
| 1147 | return pdata; |
| 1148 | } |
| 1149 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1150 | static int davinci_mcasp_probe(struct platform_device *pdev) |
| 1151 | { |
| 1152 | struct davinci_pcm_dma_params *dma_data; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1153 | struct resource *mem, *ioarea, *res, *dat; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1154 | struct snd_platform_data *pdata; |
| 1155 | struct davinci_audio_dev *dev; |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1156 | int ret; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1157 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1158 | if (!pdev->dev.platform_data && !pdev->dev.of_node) { |
| 1159 | dev_err(&pdev->dev, "No platform data supplied\n"); |
| 1160 | return -EINVAL; |
| 1161 | } |
| 1162 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1163 | dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_audio_dev), |
| 1164 | GFP_KERNEL); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1165 | if (!dev) |
| 1166 | return -ENOMEM; |
| 1167 | |
Hebbar, Gururaja | 3e3b8c3 | 2012-08-27 18:56:42 +0530 | [diff] [blame] | 1168 | pdata = davinci_mcasp_set_pdata_from_of(pdev); |
| 1169 | if (!pdata) { |
| 1170 | dev_err(&pdev->dev, "no platform data\n"); |
| 1171 | return -EINVAL; |
| 1172 | } |
| 1173 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1174 | mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu"); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1175 | if (!mem) { |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1176 | dev_warn(dev->dev, |
| 1177 | "\"mpu\" mem resource not found, using index 0\n"); |
| 1178 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1179 | if (!mem) { |
| 1180 | dev_err(&pdev->dev, "no mem resource?\n"); |
| 1181 | return -ENODEV; |
| 1182 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1183 | } |
| 1184 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1185 | ioarea = devm_request_mem_region(&pdev->dev, mem->start, |
Vaibhav Bedia | d852f446 | 2011-02-09 18:39:52 +0530 | [diff] [blame] | 1186 | resource_size(mem), pdev->name); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1187 | if (!ioarea) { |
| 1188 | dev_err(&pdev->dev, "Audio region already claimed\n"); |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1189 | return -EBUSY; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1192 | pm_runtime_enable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1193 | |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1194 | ret = pm_runtime_get_sync(&pdev->dev); |
| 1195 | if (IS_ERR_VALUE(ret)) { |
| 1196 | dev_err(&pdev->dev, "pm_runtime_get_sync() failed\n"); |
| 1197 | return ret; |
| 1198 | } |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1199 | |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1200 | dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem)); |
Vaibhav Bedia | 4f82f02 | 2011-02-09 18:39:54 +0530 | [diff] [blame] | 1201 | if (!dev->base) { |
| 1202 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1203 | ret = -ENOMEM; |
| 1204 | goto err_release_clk; |
| 1205 | } |
| 1206 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1207 | dev->op_mode = pdata->op_mode; |
| 1208 | dev->tdm_slots = pdata->tdm_slots; |
| 1209 | dev->num_serializer = pdata->num_serializer; |
| 1210 | dev->serial_dir = pdata->serial_dir; |
Chaithrika U S | 6a99fb5 | 2009-08-11 16:58:52 -0400 | [diff] [blame] | 1211 | dev->version = pdata->version; |
| 1212 | dev->txnumevt = pdata->txnumevt; |
| 1213 | dev->rxnumevt = pdata->rxnumevt; |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1214 | dev->dev = &pdev->dev; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1215 | |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1216 | dat = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); |
| 1217 | if (!dat) |
| 1218 | dat = mem; |
| 1219 | |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 1220 | dma_data = &dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]; |
Sekhar Nori | 48519f0 | 2010-07-19 12:31:16 +0530 | [diff] [blame] | 1221 | dma_data->asp_chan_q = pdata->asp_chan_q; |
| 1222 | dma_data->ram_chan_q = pdata->ram_chan_q; |
Matt Porter | b8ec56d | 2012-10-17 16:08:03 +0200 | [diff] [blame] | 1223 | dma_data->sram_pool = pdata->sram_pool; |
Ben Gardiner | a0c8326 | 2011-05-18 09:27:45 -0400 | [diff] [blame] | 1224 | dma_data->sram_size = pdata->sram_size_playback; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1225 | dma_data->dma_addr = dat->start + pdata->tx_dma_offset; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1226 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1227 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 1228 | if (res) |
| 1229 | dma_data->channel = res->start; |
| 1230 | else |
| 1231 | dma_data->channel = pdata->tx_dma_channel; |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 1232 | |
| 1233 | dma_data = &dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]; |
Sekhar Nori | 48519f0 | 2010-07-19 12:31:16 +0530 | [diff] [blame] | 1234 | dma_data->asp_chan_q = pdata->asp_chan_q; |
| 1235 | dma_data->ram_chan_q = pdata->ram_chan_q; |
Matt Porter | b8ec56d | 2012-10-17 16:08:03 +0200 | [diff] [blame] | 1236 | dma_data->sram_pool = pdata->sram_pool; |
Ben Gardiner | a0c8326 | 2011-05-18 09:27:45 -0400 | [diff] [blame] | 1237 | dma_data->sram_size = pdata->sram_size_capture; |
Jyri Sarha | 256ba18 | 2013-10-18 18:37:42 +0300 | [diff] [blame] | 1238 | dma_data->dma_addr = dat->start + pdata->rx_dma_offset; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1239 | |
| 1240 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
Jyri Sarha | 4023fe6 | 2013-10-18 18:37:43 +0300 | [diff] [blame] | 1241 | if (res) |
| 1242 | dma_data->channel = res->start; |
| 1243 | else |
| 1244 | dma_data->channel = pdata->rx_dma_channel; |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1245 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1246 | dev_set_drvdata(&pdev->dev, dev); |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1247 | ret = snd_soc_register_component(&pdev->dev, &davinci_mcasp_component, |
| 1248 | &davinci_mcasp_dai[pdata->op_mode], 1); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1249 | |
| 1250 | if (ret != 0) |
Julia Lawall | 96d31e2 | 2011-12-29 17:51:21 +0100 | [diff] [blame] | 1251 | goto err_release_clk; |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1252 | |
| 1253 | ret = davinci_soc_platform_register(&pdev->dev); |
| 1254 | if (ret) { |
| 1255 | dev_err(&pdev->dev, "register PCM failed: %d\n", ret); |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1256 | goto err_unregister_component; |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1257 | } |
| 1258 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1259 | return 0; |
| 1260 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1261 | err_unregister_component: |
| 1262 | snd_soc_unregister_component(&pdev->dev); |
Vaibhav Bedia | eef6d7b | 2011-02-09 18:39:53 +0530 | [diff] [blame] | 1263 | err_release_clk: |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1264 | pm_runtime_put_sync(&pdev->dev); |
| 1265 | pm_runtime_disable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1266 | return ret; |
| 1267 | } |
| 1268 | |
| 1269 | static int davinci_mcasp_remove(struct platform_device *pdev) |
| 1270 | { |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1271 | |
Kuninori Morimoto | eeef0ed | 2013-03-21 03:31:19 -0700 | [diff] [blame] | 1272 | snd_soc_unregister_component(&pdev->dev); |
Hebbar, Gururaja | f08095a | 2012-08-27 18:56:39 +0530 | [diff] [blame] | 1273 | davinci_soc_platform_unregister(&pdev->dev); |
Hebbar, Gururaja | 1088434 | 2012-08-08 20:40:32 +0530 | [diff] [blame] | 1274 | |
| 1275 | pm_runtime_put_sync(&pdev->dev); |
| 1276 | pm_runtime_disable(&pdev->dev); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1277 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1278 | return 0; |
| 1279 | } |
| 1280 | |
Daniel Mack | a85e419 | 2013-10-01 14:50:02 +0200 | [diff] [blame] | 1281 | #ifdef CONFIG_PM_SLEEP |
| 1282 | static int davinci_mcasp_suspend(struct device *dev) |
| 1283 | { |
| 1284 | struct davinci_audio_dev *a = dev_get_drvdata(dev); |
| 1285 | void __iomem *base = a->base; |
| 1286 | |
| 1287 | a->context.txfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_TXFMCTL_REG); |
| 1288 | a->context.rxfmtctl = mcasp_get_reg(base + DAVINCI_MCASP_RXFMCTL_REG); |
| 1289 | a->context.txfmt = mcasp_get_reg(base + DAVINCI_MCASP_TXFMT_REG); |
| 1290 | a->context.rxfmt = mcasp_get_reg(base + DAVINCI_MCASP_RXFMT_REG); |
| 1291 | a->context.aclkxctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKXCTL_REG); |
| 1292 | a->context.aclkrctl = mcasp_get_reg(base + DAVINCI_MCASP_ACLKRCTL_REG); |
| 1293 | a->context.pdir = mcasp_get_reg(base + DAVINCI_MCASP_PDIR_REG); |
| 1294 | |
| 1295 | return 0; |
| 1296 | } |
| 1297 | |
| 1298 | static int davinci_mcasp_resume(struct device *dev) |
| 1299 | { |
| 1300 | struct davinci_audio_dev *a = dev_get_drvdata(dev); |
| 1301 | void __iomem *base = a->base; |
| 1302 | |
| 1303 | mcasp_set_reg(base + DAVINCI_MCASP_TXFMCTL_REG, a->context.txfmtctl); |
| 1304 | mcasp_set_reg(base + DAVINCI_MCASP_RXFMCTL_REG, a->context.rxfmtctl); |
| 1305 | mcasp_set_reg(base + DAVINCI_MCASP_TXFMT_REG, a->context.txfmt); |
| 1306 | mcasp_set_reg(base + DAVINCI_MCASP_RXFMT_REG, a->context.rxfmt); |
| 1307 | mcasp_set_reg(base + DAVINCI_MCASP_ACLKXCTL_REG, a->context.aclkxctl); |
| 1308 | mcasp_set_reg(base + DAVINCI_MCASP_ACLKRCTL_REG, a->context.aclkrctl); |
| 1309 | mcasp_set_reg(base + DAVINCI_MCASP_PDIR_REG, a->context.pdir); |
| 1310 | |
| 1311 | return 0; |
| 1312 | } |
| 1313 | #endif |
| 1314 | |
| 1315 | SIMPLE_DEV_PM_OPS(davinci_mcasp_pm_ops, |
| 1316 | davinci_mcasp_suspend, |
| 1317 | davinci_mcasp_resume); |
| 1318 | |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1319 | static struct platform_driver davinci_mcasp_driver = { |
| 1320 | .probe = davinci_mcasp_probe, |
| 1321 | .remove = davinci_mcasp_remove, |
| 1322 | .driver = { |
| 1323 | .name = "davinci-mcasp", |
| 1324 | .owner = THIS_MODULE, |
Daniel Mack | a85e419 | 2013-10-01 14:50:02 +0200 | [diff] [blame] | 1325 | .pm = &davinci_mcasp_pm_ops, |
Sachin Kamat | ea421eb | 2013-05-22 16:53:37 +0530 | [diff] [blame] | 1326 | .of_match_table = mcasp_dt_ids, |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1327 | }, |
| 1328 | }; |
| 1329 | |
Axel Lin | f9b8a51 | 2011-11-25 10:09:27 +0800 | [diff] [blame] | 1330 | module_platform_driver(davinci_mcasp_driver); |
Chaithrika U S | b67f448 | 2009-06-05 06:28:40 -0400 | [diff] [blame] | 1331 | |
| 1332 | MODULE_AUTHOR("Steve Chen"); |
| 1333 | MODULE_DESCRIPTION("TI DAVINCI McASP SoC Interface"); |
| 1334 | MODULE_LICENSE("GPL"); |