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