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