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