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