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