Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor |
| 3 | * |
Vladimir Barinov | d6b5203 | 2008-09-29 23:14:11 +0400 | [diff] [blame] | 4 | * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/io.h> |
| 17 | #include <linux/clk.h> |
| 18 | |
| 19 | #include <sound/core.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/pcm_params.h> |
| 22 | #include <sound/initval.h> |
| 23 | #include <sound/soc.h> |
| 24 | |
Mark Brown | ff7d04b | 2009-07-08 16:54:51 +0100 | [diff] [blame] | 25 | #include <mach/asp.h> |
| 26 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 27 | #include "davinci-pcm.h" |
| 28 | |
David Brownell | a62114c | 2009-05-14 12:47:42 -0700 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * NOTE: terminology here is confusing. |
| 32 | * |
| 33 | * - This driver supports the "Audio Serial Port" (ASP), |
| 34 | * found on dm6446, dm355, and other DaVinci chips. |
| 35 | * |
| 36 | * - But it labels it a "Multi-channel Buffered Serial Port" |
| 37 | * (McBSP) as on older chips like the dm642 ... which was |
| 38 | * backward-compatible, possibly explaining that confusion. |
| 39 | * |
| 40 | * - OMAP chips have a controller called McBSP, which is |
| 41 | * incompatible with the DaVinci flavor of McBSP. |
| 42 | * |
| 43 | * - Newer DaVinci chips have a controller called McASP, |
| 44 | * incompatible with ASP and with either McBSP. |
| 45 | * |
| 46 | * In short: this uses ASP to implement I2S, not McBSP. |
| 47 | * And it won't be the only DaVinci implemention of I2S. |
| 48 | */ |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 49 | #define DAVINCI_MCBSP_DRR_REG 0x00 |
| 50 | #define DAVINCI_MCBSP_DXR_REG 0x04 |
| 51 | #define DAVINCI_MCBSP_SPCR_REG 0x08 |
| 52 | #define DAVINCI_MCBSP_RCR_REG 0x0c |
| 53 | #define DAVINCI_MCBSP_XCR_REG 0x10 |
| 54 | #define DAVINCI_MCBSP_SRGR_REG 0x14 |
| 55 | #define DAVINCI_MCBSP_PCR_REG 0x24 |
| 56 | |
| 57 | #define DAVINCI_MCBSP_SPCR_RRST (1 << 0) |
| 58 | #define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4) |
| 59 | #define DAVINCI_MCBSP_SPCR_XRST (1 << 16) |
| 60 | #define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20) |
| 61 | #define DAVINCI_MCBSP_SPCR_GRST (1 << 22) |
| 62 | #define DAVINCI_MCBSP_SPCR_FRST (1 << 23) |
| 63 | #define DAVINCI_MCBSP_SPCR_FREE (1 << 25) |
| 64 | |
| 65 | #define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5) |
| 66 | #define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8) |
| 67 | #define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16) |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 68 | #define DAVINCI_MCBSP_RCR_RFIG (1 << 18) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 69 | #define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21) |
| 70 | |
| 71 | #define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5) |
| 72 | #define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8) |
| 73 | #define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16) |
| 74 | #define DAVINCI_MCBSP_XCR_XFIG (1 << 18) |
| 75 | #define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21) |
| 76 | |
| 77 | #define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8) |
| 78 | #define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16) |
| 79 | #define DAVINCI_MCBSP_SRGR_FSGM (1 << 28) |
| 80 | |
| 81 | #define DAVINCI_MCBSP_PCR_CLKRP (1 << 0) |
| 82 | #define DAVINCI_MCBSP_PCR_CLKXP (1 << 1) |
| 83 | #define DAVINCI_MCBSP_PCR_FSRP (1 << 2) |
| 84 | #define DAVINCI_MCBSP_PCR_FSXP (1 << 3) |
Hugo Villeneuve | b402dff | 2008-11-08 13:26:09 -0500 | [diff] [blame] | 85 | #define DAVINCI_MCBSP_PCR_SCLKME (1 << 7) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 86 | #define DAVINCI_MCBSP_PCR_CLKRM (1 << 8) |
| 87 | #define DAVINCI_MCBSP_PCR_CLKXM (1 << 9) |
| 88 | #define DAVINCI_MCBSP_PCR_FSRM (1 << 10) |
| 89 | #define DAVINCI_MCBSP_PCR_FSXM (1 << 11) |
| 90 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 91 | enum { |
| 92 | DAVINCI_MCBSP_WORD_8 = 0, |
| 93 | DAVINCI_MCBSP_WORD_12, |
| 94 | DAVINCI_MCBSP_WORD_16, |
| 95 | DAVINCI_MCBSP_WORD_20, |
| 96 | DAVINCI_MCBSP_WORD_24, |
| 97 | DAVINCI_MCBSP_WORD_32, |
| 98 | }; |
| 99 | |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 100 | static const unsigned char data_type[SNDRV_PCM_FORMAT_S32_LE + 1] = { |
| 101 | [SNDRV_PCM_FORMAT_S8] = 1, |
| 102 | [SNDRV_PCM_FORMAT_S16_LE] = 2, |
| 103 | [SNDRV_PCM_FORMAT_S32_LE] = 4, |
| 104 | }; |
| 105 | |
| 106 | static const unsigned char asp_word_length[SNDRV_PCM_FORMAT_S32_LE + 1] = { |
| 107 | [SNDRV_PCM_FORMAT_S8] = DAVINCI_MCBSP_WORD_8, |
| 108 | [SNDRV_PCM_FORMAT_S16_LE] = DAVINCI_MCBSP_WORD_16, |
| 109 | [SNDRV_PCM_FORMAT_S32_LE] = DAVINCI_MCBSP_WORD_32, |
| 110 | }; |
| 111 | |
| 112 | static const unsigned char double_fmt[SNDRV_PCM_FORMAT_S32_LE + 1] = { |
| 113 | [SNDRV_PCM_FORMAT_S8] = SNDRV_PCM_FORMAT_S16_LE, |
| 114 | [SNDRV_PCM_FORMAT_S16_LE] = SNDRV_PCM_FORMAT_S32_LE, |
| 115 | }; |
| 116 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 117 | struct davinci_mcbsp_dev { |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 118 | struct davinci_pcm_dma_params dma_params[2]; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 119 | void __iomem *base; |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 120 | #define MOD_DSP_A 0 |
| 121 | #define MOD_DSP_B 1 |
| 122 | int mode; |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 123 | u32 pcr; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 124 | struct clk *clk; |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 125 | /* |
| 126 | * Combining both channels into 1 element will at least double the |
| 127 | * amount of time between servicing the dma channel, increase |
| 128 | * effiency, and reduce the chance of overrun/underrun. But, |
| 129 | * it will result in the left & right channels being swapped. |
| 130 | * |
| 131 | * If relabeling the left and right channels is not possible, |
| 132 | * you may want to let the codec know to swap them back. |
| 133 | * |
| 134 | * It may allow x10 the amount of time to service dma requests, |
| 135 | * if the codec is master and is using an unnecessarily fast bit clock |
| 136 | * (ie. tlvaic23b), independent of the sample rate. So, having an |
| 137 | * entire frame at once means it can be serviced at the sample rate |
| 138 | * instead of the bit clock rate. |
| 139 | * |
| 140 | * In the now unlikely case that an underrun still |
| 141 | * occurs, both the left and right samples will be repeated |
| 142 | * so that no pops are heard, and the left and right channels |
| 143 | * won't end up being swapped because of the underrun. |
| 144 | */ |
| 145 | unsigned enable_channel_combine:1; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, |
| 149 | int reg, u32 val) |
| 150 | { |
| 151 | __raw_writel(val, dev->base + reg); |
| 152 | } |
| 153 | |
| 154 | static inline u32 davinci_mcbsp_read_reg(struct davinci_mcbsp_dev *dev, int reg) |
| 155 | { |
| 156 | return __raw_readl(dev->base + reg); |
| 157 | } |
| 158 | |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 159 | static void toggle_clock(struct davinci_mcbsp_dev *dev, int playback) |
| 160 | { |
| 161 | u32 m = playback ? DAVINCI_MCBSP_PCR_CLKXP : DAVINCI_MCBSP_PCR_CLKRP; |
| 162 | /* The clock needs to toggle to complete reset. |
| 163 | * So, fake it by toggling the clk polarity. |
| 164 | */ |
| 165 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, dev->pcr ^ m); |
| 166 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, dev->pcr); |
| 167 | } |
| 168 | |
Troy Kisky | f9af37c | 2009-07-04 19:29:53 -0700 | [diff] [blame] | 169 | static void davinci_mcbsp_start(struct davinci_mcbsp_dev *dev, |
| 170 | struct snd_pcm_substream *substream) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 171 | { |
| 172 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 173 | struct snd_soc_device *socdev = rtd->socdev; |
Mark Brown | 87689d5 | 2008-12-02 16:01:14 +0000 | [diff] [blame] | 174 | struct snd_soc_platform *platform = socdev->card->platform; |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 175 | int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 176 | u32 spcr; |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 177 | u32 mask = playback ? DAVINCI_MCBSP_SPCR_XRST : DAVINCI_MCBSP_SPCR_RRST; |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 178 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 179 | if (spcr & mask) { |
| 180 | /* start off disabled */ |
| 181 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, |
| 182 | spcr & ~mask); |
| 183 | toggle_clock(dev, playback); |
| 184 | } |
Troy Kisky | 1bef449 | 2009-07-04 19:29:55 -0700 | [diff] [blame] | 185 | if (dev->pcr & (DAVINCI_MCBSP_PCR_FSXM | DAVINCI_MCBSP_PCR_FSRM | |
| 186 | DAVINCI_MCBSP_PCR_CLKXM | DAVINCI_MCBSP_PCR_CLKRM)) { |
| 187 | /* Start the sample generator */ |
| 188 | spcr |= DAVINCI_MCBSP_SPCR_GRST; |
| 189 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
| 190 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 191 | |
Troy Kisky | 1bef449 | 2009-07-04 19:29:55 -0700 | [diff] [blame] | 192 | if (playback) { |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 193 | /* Stop the DMA to avoid data loss */ |
| 194 | /* while the transmitter is out of reset to handle XSYNCERR */ |
| 195 | if (platform->pcm_ops->trigger) { |
Troy Kisky | eba575c | 2009-07-04 19:29:54 -0700 | [diff] [blame] | 196 | int ret = platform->pcm_ops->trigger(substream, |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 197 | SNDRV_PCM_TRIGGER_STOP); |
| 198 | if (ret < 0) |
| 199 | printk(KERN_DEBUG "Playback DMA stop failed\n"); |
| 200 | } |
| 201 | |
| 202 | /* Enable the transmitter */ |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 203 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
| 204 | spcr |= DAVINCI_MCBSP_SPCR_XRST; |
| 205 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 206 | |
| 207 | /* wait for any unexpected frame sync error to occur */ |
| 208 | udelay(100); |
| 209 | |
| 210 | /* Disable the transmitter to clear any outstanding XSYNCERR */ |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 211 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
| 212 | spcr &= ~DAVINCI_MCBSP_SPCR_XRST; |
| 213 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 214 | toggle_clock(dev, playback); |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 215 | |
| 216 | /* Restart the DMA */ |
| 217 | if (platform->pcm_ops->trigger) { |
Troy Kisky | eba575c | 2009-07-04 19:29:54 -0700 | [diff] [blame] | 218 | int ret = platform->pcm_ops->trigger(substream, |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 219 | SNDRV_PCM_TRIGGER_START); |
| 220 | if (ret < 0) |
| 221 | printk(KERN_DEBUG "Playback DMA start failed\n"); |
| 222 | } |
Naresh Medisetty | fb0ef64 | 2008-11-12 10:26:31 +0530 | [diff] [blame] | 223 | } |
| 224 | |
Troy Kisky | 1bef449 | 2009-07-04 19:29:55 -0700 | [diff] [blame] | 225 | /* Enable transmitter or receiver */ |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 226 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
Troy Kisky | 1bef449 | 2009-07-04 19:29:55 -0700 | [diff] [blame] | 227 | spcr |= mask; |
| 228 | |
| 229 | if (dev->pcr & (DAVINCI_MCBSP_PCR_FSXM | DAVINCI_MCBSP_PCR_FSRM)) { |
| 230 | /* Start frame sync */ |
| 231 | spcr |= DAVINCI_MCBSP_SPCR_FRST; |
| 232 | } |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 233 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Troy Kisky | f9af37c | 2009-07-04 19:29:53 -0700 | [diff] [blame] | 236 | static void davinci_mcbsp_stop(struct davinci_mcbsp_dev *dev, int playback) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 237 | { |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 238 | u32 spcr; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 239 | |
| 240 | /* Reset transmitter/receiver and sample rate/frame sync generators */ |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 241 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
| 242 | spcr &= ~(DAVINCI_MCBSP_SPCR_GRST | DAVINCI_MCBSP_SPCR_FRST); |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 243 | spcr &= playback ? ~DAVINCI_MCBSP_SPCR_XRST : ~DAVINCI_MCBSP_SPCR_RRST; |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 244 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 245 | toggle_clock(dev, playback); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 248 | #define DEFAULT_BITPERSAMPLE 16 |
| 249 | |
Liam Girdwood | 9cb132d | 2008-07-07 16:07:42 +0100 | [diff] [blame] | 250 | static int davinci_i2s_set_dai_fmt(struct snd_soc_dai *cpu_dai, |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 251 | unsigned int fmt) |
| 252 | { |
| 253 | struct davinci_mcbsp_dev *dev = cpu_dai->private_data; |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 254 | unsigned int pcr; |
| 255 | unsigned int srgr; |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 256 | srgr = DAVINCI_MCBSP_SRGR_FSGM | |
| 257 | DAVINCI_MCBSP_SRGR_FPER(DEFAULT_BITPERSAMPLE * 2 - 1) | |
| 258 | DAVINCI_MCBSP_SRGR_FWID(DEFAULT_BITPERSAMPLE - 1); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 259 | |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 260 | /* set master/slave audio interface */ |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 261 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 262 | case SND_SOC_DAIFMT_CBS_CFS: |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 263 | /* cpu is master */ |
| 264 | pcr = DAVINCI_MCBSP_PCR_FSXM | |
| 265 | DAVINCI_MCBSP_PCR_FSRM | |
| 266 | DAVINCI_MCBSP_PCR_CLKXM | |
| 267 | DAVINCI_MCBSP_PCR_CLKRM; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 268 | break; |
Hugo Villeneuve | b402dff | 2008-11-08 13:26:09 -0500 | [diff] [blame] | 269 | case SND_SOC_DAIFMT_CBM_CFS: |
| 270 | /* McBSP CLKR pin is the input for the Sample Rate Generator. |
| 271 | * McBSP FSR and FSX are driven by the Sample Rate Generator. */ |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 272 | pcr = DAVINCI_MCBSP_PCR_SCLKME | |
| 273 | DAVINCI_MCBSP_PCR_FSXM | |
| 274 | DAVINCI_MCBSP_PCR_FSRM; |
Hugo Villeneuve | b402dff | 2008-11-08 13:26:09 -0500 | [diff] [blame] | 275 | break; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 276 | case SND_SOC_DAIFMT_CBM_CFM: |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 277 | /* codec is master */ |
| 278 | pcr = 0; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 279 | break; |
| 280 | default: |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 281 | printk(KERN_ERR "%s:bad master\n", __func__); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 282 | return -EINVAL; |
| 283 | } |
| 284 | |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 285 | /* interface format */ |
Troy Kisky | 69ab820 | 2008-12-18 12:36:44 -0700 | [diff] [blame] | 286 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
Troy Kisky | 69ab820 | 2008-12-18 12:36:44 -0700 | [diff] [blame] | 287 | case SND_SOC_DAIFMT_I2S: |
Troy Kisky | 07d8d9d | 2008-12-19 13:05:24 -0700 | [diff] [blame] | 288 | /* Davinci doesn't support TRUE I2S, but some codecs will have |
| 289 | * the left and right channels contiguous. This allows |
| 290 | * dsp_a mode to be used with an inverted normal frame clk. |
| 291 | * If your codec is master and does not have contiguous |
| 292 | * channels, then you will have sound on only one channel. |
| 293 | * Try using a different mode, or codec as slave. |
| 294 | * |
| 295 | * The TLV320AIC33 is an example of a codec where this works. |
| 296 | * It has a variable bit clock frequency allowing it to have |
| 297 | * valid data on every bit clock. |
| 298 | * |
| 299 | * The TLV320AIC23 is an example of a codec where this does not |
| 300 | * work. It has a fixed bit clock frequency with progressively |
| 301 | * more empty bit clock slots between channels as the sample |
| 302 | * rate is lowered. |
| 303 | */ |
| 304 | fmt ^= SND_SOC_DAIFMT_NB_IF; |
| 305 | case SND_SOC_DAIFMT_DSP_A: |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 306 | dev->mode = MOD_DSP_A; |
| 307 | break; |
| 308 | case SND_SOC_DAIFMT_DSP_B: |
| 309 | dev->mode = MOD_DSP_B; |
Troy Kisky | 69ab820 | 2008-12-18 12:36:44 -0700 | [diff] [blame] | 310 | break; |
| 311 | default: |
| 312 | printk(KERN_ERR "%s:bad format\n", __func__); |
| 313 | return -EINVAL; |
| 314 | } |
| 315 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 316 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 317 | case SND_SOC_DAIFMT_NB_NF: |
Troy Kisky | 664b4af | 2008-12-18 12:36:41 -0700 | [diff] [blame] | 318 | /* CLKRP Receive clock polarity, |
| 319 | * 1 - sampled on rising edge of CLKR |
| 320 | * valid on rising edge |
| 321 | * CLKXP Transmit clock polarity, |
| 322 | * 1 - clocked on falling edge of CLKX |
| 323 | * valid on rising edge |
| 324 | * FSRP Receive frame sync pol, 0 - active high |
| 325 | * FSXP Transmit frame sync pol, 0 - active high |
| 326 | */ |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 327 | pcr |= (DAVINCI_MCBSP_PCR_CLKXP | DAVINCI_MCBSP_PCR_CLKRP); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 328 | break; |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 329 | case SND_SOC_DAIFMT_IB_IF: |
Troy Kisky | 664b4af | 2008-12-18 12:36:41 -0700 | [diff] [blame] | 330 | /* CLKRP Receive clock polarity, |
| 331 | * 0 - sampled on falling edge of CLKR |
| 332 | * valid on falling edge |
| 333 | * CLKXP Transmit clock polarity, |
| 334 | * 0 - clocked on rising edge of CLKX |
| 335 | * valid on falling edge |
| 336 | * FSRP Receive frame sync pol, 1 - active low |
| 337 | * FSXP Transmit frame sync pol, 1 - active low |
| 338 | */ |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 339 | pcr |= (DAVINCI_MCBSP_PCR_FSXP | DAVINCI_MCBSP_PCR_FSRP); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 340 | break; |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 341 | case SND_SOC_DAIFMT_NB_IF: |
Troy Kisky | 664b4af | 2008-12-18 12:36:41 -0700 | [diff] [blame] | 342 | /* CLKRP Receive clock polarity, |
| 343 | * 1 - sampled on rising edge of CLKR |
| 344 | * valid on rising edge |
| 345 | * CLKXP Transmit clock polarity, |
| 346 | * 1 - clocked on falling edge of CLKX |
| 347 | * valid on rising edge |
| 348 | * FSRP Receive frame sync pol, 1 - active low |
| 349 | * FSXP Transmit frame sync pol, 1 - active low |
| 350 | */ |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 351 | pcr |= (DAVINCI_MCBSP_PCR_CLKXP | DAVINCI_MCBSP_PCR_CLKRP | |
| 352 | DAVINCI_MCBSP_PCR_FSXP | DAVINCI_MCBSP_PCR_FSRP); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 353 | break; |
Troy Kisky | 9e03162 | 2008-12-19 13:05:23 -0700 | [diff] [blame] | 354 | case SND_SOC_DAIFMT_IB_NF: |
Troy Kisky | 664b4af | 2008-12-18 12:36:41 -0700 | [diff] [blame] | 355 | /* CLKRP Receive clock polarity, |
| 356 | * 0 - sampled on falling edge of CLKR |
| 357 | * valid on falling edge |
| 358 | * CLKXP Transmit clock polarity, |
| 359 | * 0 - clocked on rising edge of CLKX |
| 360 | * valid on falling edge |
| 361 | * FSRP Receive frame sync pol, 0 - active high |
| 362 | * FSXP Transmit frame sync pol, 0 - active high |
| 363 | */ |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 364 | break; |
| 365 | default: |
| 366 | return -EINVAL; |
| 367 | } |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 368 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, srgr); |
Troy Kisky | c392bec | 2009-07-04 19:29:52 -0700 | [diff] [blame] | 369 | dev->pcr = pcr; |
Troy Kisky | 21903c1 | 2008-12-18 12:36:43 -0700 | [diff] [blame] | 370 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, pcr); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 375 | struct snd_pcm_hw_params *params, |
| 376 | struct snd_soc_dai *dai) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 377 | { |
Troy Kisky | 9bb7415 | 2009-08-06 16:55:31 -0700 | [diff] [blame] | 378 | struct davinci_mcbsp_dev *dev = dai->private_data; |
Troy Kisky | 81ac55a | 2009-09-11 14:29:02 -0700 | [diff] [blame] | 379 | struct davinci_pcm_dma_params *dma_params = |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 380 | &dev->dma_params[substream->stream]; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 381 | struct snd_interval *i = NULL; |
| 382 | int mcbsp_word_length; |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 383 | unsigned int rcr, xcr, srgr; |
| 384 | u32 spcr; |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 385 | snd_pcm_format_t fmt; |
| 386 | unsigned element_cnt = 1; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 387 | |
| 388 | /* general line settings */ |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 389 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
Naresh Medisetty | cb6e206 | 2008-11-18 11:01:03 +0530 | [diff] [blame] | 390 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 391 | spcr |= DAVINCI_MCBSP_SPCR_RINTM(3) | DAVINCI_MCBSP_SPCR_FREE; |
| 392 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Naresh Medisetty | cb6e206 | 2008-11-18 11:01:03 +0530 | [diff] [blame] | 393 | } else { |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 394 | spcr |= DAVINCI_MCBSP_SPCR_XINTM(3) | DAVINCI_MCBSP_SPCR_FREE; |
| 395 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, spcr); |
Naresh Medisetty | cb6e206 | 2008-11-18 11:01:03 +0530 | [diff] [blame] | 396 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 397 | |
| 398 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS); |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 399 | srgr = DAVINCI_MCBSP_SRGR_FSGM; |
| 400 | srgr |= DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 401 | |
| 402 | i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS); |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 403 | srgr |= DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1); |
| 404 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, srgr); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 405 | |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 406 | rcr = DAVINCI_MCBSP_RCR_RFIG; |
| 407 | xcr = DAVINCI_MCBSP_XCR_XFIG; |
| 408 | if (dev->mode == MOD_DSP_B) { |
| 409 | rcr |= DAVINCI_MCBSP_RCR_RDATDLY(0); |
| 410 | xcr |= DAVINCI_MCBSP_XCR_XDATDLY(0); |
| 411 | } else { |
| 412 | rcr |= DAVINCI_MCBSP_RCR_RDATDLY(1); |
| 413 | xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1); |
| 414 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 415 | /* Determine xfer data type */ |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 416 | fmt = params_format(params); |
| 417 | if ((fmt > SNDRV_PCM_FORMAT_S32_LE) || !data_type[fmt]) { |
Jean Delvare | 9b6e12e | 2008-08-26 15:47:55 +0200 | [diff] [blame] | 418 | printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n"); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 419 | return -EINVAL; |
| 420 | } |
| 421 | |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 422 | if (params_channels(params) == 2) { |
| 423 | element_cnt = 2; |
| 424 | if (double_fmt[fmt] && dev->enable_channel_combine) { |
| 425 | element_cnt = 1; |
| 426 | fmt = double_fmt[fmt]; |
| 427 | } |
| 428 | } |
| 429 | dma_params->acnt = dma_params->data_type = data_type[fmt]; |
Chaithrika U S | 4fa9c1a | 2009-09-30 17:32:27 -0400 | [diff] [blame] | 430 | dma_params->fifo_level = 0; |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 431 | mcbsp_word_length = asp_word_length[fmt]; |
| 432 | rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(element_cnt - 1); |
| 433 | xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(element_cnt - 1); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 434 | |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 435 | rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | |
| 436 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length); |
| 437 | xcr |= DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) | |
| 438 | DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length); |
| 439 | |
| 440 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Troy Kisky | 35cf635 | 2009-07-04 19:29:51 -0700 | [diff] [blame] | 441 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, xcr); |
Troy Kisky | f5cfa95 | 2009-07-04 19:29:57 -0700 | [diff] [blame] | 442 | else |
| 443 | davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, rcr); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 444 | return 0; |
| 445 | } |
| 446 | |
Troy Kisky | af0adf3 | 2009-07-04 19:29:59 -0700 | [diff] [blame] | 447 | static int davinci_i2s_prepare(struct snd_pcm_substream *substream, |
| 448 | struct snd_soc_dai *dai) |
| 449 | { |
Troy Kisky | 9bb7415 | 2009-08-06 16:55:31 -0700 | [diff] [blame] | 450 | struct davinci_mcbsp_dev *dev = dai->private_data; |
Troy Kisky | af0adf3 | 2009-07-04 19:29:59 -0700 | [diff] [blame] | 451 | int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
| 452 | davinci_mcbsp_stop(dev, playback); |
| 453 | if ((dev->pcr & DAVINCI_MCBSP_PCR_FSXM) == 0) { |
| 454 | /* codec is master */ |
| 455 | davinci_mcbsp_start(dev, substream); |
| 456 | } |
| 457 | return 0; |
| 458 | } |
| 459 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 460 | static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd, |
| 461 | struct snd_soc_dai *dai) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 462 | { |
Troy Kisky | 9bb7415 | 2009-08-06 16:55:31 -0700 | [diff] [blame] | 463 | struct davinci_mcbsp_dev *dev = dai->private_data; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 464 | int ret = 0; |
Troy Kisky | f9af37c | 2009-07-04 19:29:53 -0700 | [diff] [blame] | 465 | int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
Troy Kisky | af0adf3 | 2009-07-04 19:29:59 -0700 | [diff] [blame] | 466 | if ((dev->pcr & DAVINCI_MCBSP_PCR_FSXM) == 0) |
| 467 | return 0; /* return if codec is master */ |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 468 | |
| 469 | switch (cmd) { |
| 470 | case SNDRV_PCM_TRIGGER_START: |
| 471 | case SNDRV_PCM_TRIGGER_RESUME: |
| 472 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
Troy Kisky | f9af37c | 2009-07-04 19:29:53 -0700 | [diff] [blame] | 473 | davinci_mcbsp_start(dev, substream); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 474 | break; |
| 475 | case SNDRV_PCM_TRIGGER_STOP: |
| 476 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 477 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
Troy Kisky | f9af37c | 2009-07-04 19:29:53 -0700 | [diff] [blame] | 478 | davinci_mcbsp_stop(dev, playback); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 479 | break; |
| 480 | default: |
| 481 | ret = -EINVAL; |
| 482 | } |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 483 | return ret; |
| 484 | } |
| 485 | |
Troy Kisky | af0adf3 | 2009-07-04 19:29:59 -0700 | [diff] [blame] | 486 | static void davinci_i2s_shutdown(struct snd_pcm_substream *substream, |
| 487 | struct snd_soc_dai *dai) |
| 488 | { |
Troy Kisky | 9bb7415 | 2009-08-06 16:55:31 -0700 | [diff] [blame] | 489 | struct davinci_mcbsp_dev *dev = dai->private_data; |
Troy Kisky | af0adf3 | 2009-07-04 19:29:59 -0700 | [diff] [blame] | 490 | int playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); |
| 491 | davinci_mcbsp_stop(dev, playback); |
| 492 | } |
| 493 | |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 494 | #define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 |
| 495 | |
| 496 | static struct snd_soc_dai_ops davinci_i2s_dai_ops = { |
Mark Brown | 3f405b4 | 2009-07-07 19:18:46 +0100 | [diff] [blame] | 497 | .shutdown = davinci_i2s_shutdown, |
| 498 | .prepare = davinci_i2s_prepare, |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 499 | .trigger = davinci_i2s_trigger, |
| 500 | .hw_params = davinci_i2s_hw_params, |
| 501 | .set_fmt = davinci_i2s_set_dai_fmt, |
| 502 | |
| 503 | }; |
| 504 | |
| 505 | struct snd_soc_dai davinci_i2s_dai = { |
| 506 | .name = "davinci-i2s", |
| 507 | .id = 0, |
| 508 | .playback = { |
| 509 | .channels_min = 2, |
| 510 | .channels_max = 2, |
| 511 | .rates = DAVINCI_I2S_RATES, |
| 512 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 513 | .capture = { |
| 514 | .channels_min = 2, |
| 515 | .channels_max = 2, |
| 516 | .rates = DAVINCI_I2S_RATES, |
| 517 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 518 | .ops = &davinci_i2s_dai_ops, |
| 519 | |
| 520 | }; |
| 521 | EXPORT_SYMBOL_GPL(davinci_i2s_dai); |
| 522 | |
| 523 | static int davinci_i2s_probe(struct platform_device *pdev) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 524 | { |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 525 | struct snd_platform_data *pdata = pdev->dev.platform_data; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 526 | struct davinci_mcbsp_dev *dev; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 527 | struct resource *mem, *ioarea, *res; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 528 | int ret; |
| 529 | |
| 530 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 531 | if (!mem) { |
| 532 | dev_err(&pdev->dev, "no mem resource?\n"); |
| 533 | return -ENODEV; |
| 534 | } |
| 535 | |
| 536 | ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1, |
| 537 | pdev->name); |
| 538 | if (!ioarea) { |
| 539 | dev_err(&pdev->dev, "McBSP region already claimed\n"); |
| 540 | return -EBUSY; |
| 541 | } |
| 542 | |
| 543 | dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL); |
| 544 | if (!dev) { |
| 545 | ret = -ENOMEM; |
| 546 | goto err_release_region; |
| 547 | } |
Troy Kisky | 0d6c977 | 2009-11-18 17:49:51 -0700 | [diff] [blame^] | 548 | if (pdata) |
| 549 | dev->enable_channel_combine = pdata->enable_channel_combine; |
Kevin Hilman | 3e46a44 | 2009-07-15 10:42:09 -0700 | [diff] [blame] | 550 | dev->clk = clk_get(&pdev->dev, NULL); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 551 | if (IS_ERR(dev->clk)) { |
| 552 | ret = -ENODEV; |
| 553 | goto err_free_mem; |
| 554 | } |
| 555 | clk_enable(dev->clk); |
| 556 | |
| 557 | dev->base = (void __iomem *)IO_ADDRESS(mem->start); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 558 | |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 559 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].dma_addr = |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 560 | (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG); |
| 561 | |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 562 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].dma_addr = |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 563 | (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG); |
| 564 | |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 565 | /* first TX, then RX */ |
| 566 | res = platform_get_resource(pdev, IORESOURCE_DMA, 0); |
| 567 | if (!res) { |
| 568 | dev_err(&pdev->dev, "no DMA resource\n"); |
Chaithrika U S | efd13be | 2009-06-08 06:49:41 -0400 | [diff] [blame] | 569 | ret = -ENXIO; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 570 | goto err_free_mem; |
| 571 | } |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 572 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].channel = res->start; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 573 | |
| 574 | res = platform_get_resource(pdev, IORESOURCE_DMA, 1); |
| 575 | if (!res) { |
| 576 | dev_err(&pdev->dev, "no DMA resource\n"); |
Chaithrika U S | efd13be | 2009-06-08 06:49:41 -0400 | [diff] [blame] | 577 | ret = -ENXIO; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 578 | goto err_free_mem; |
| 579 | } |
Troy Kisky | 92e2a6f | 2009-09-11 14:29:03 -0700 | [diff] [blame] | 580 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 581 | |
| 582 | davinci_i2s_dai.private_data = dev; |
Troy Kisky | 57512c6 | 2009-11-16 16:52:31 -0700 | [diff] [blame] | 583 | davinci_i2s_dai.dma_data = dev->dma_params; |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 584 | ret = snd_soc_register_dai(&davinci_i2s_dai); |
| 585 | if (ret != 0) |
| 586 | goto err_free_mem; |
| 587 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 588 | return 0; |
| 589 | |
| 590 | err_free_mem: |
| 591 | kfree(dev); |
| 592 | err_release_region: |
| 593 | release_mem_region(mem->start, (mem->end - mem->start) + 1); |
| 594 | |
| 595 | return ret; |
| 596 | } |
| 597 | |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 598 | static int davinci_i2s_remove(struct platform_device *pdev) |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 599 | { |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 600 | struct davinci_mcbsp_dev *dev = davinci_i2s_dai.private_data; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 601 | struct resource *mem; |
| 602 | |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 603 | snd_soc_unregister_dai(&davinci_i2s_dai); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 604 | clk_disable(dev->clk); |
| 605 | clk_put(dev->clk); |
| 606 | dev->clk = NULL; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 607 | kfree(dev); |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 608 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 609 | release_mem_region(mem->start, (mem->end - mem->start) + 1); |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 610 | |
| 611 | return 0; |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 612 | } |
| 613 | |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 614 | static struct platform_driver davinci_mcbsp_driver = { |
| 615 | .probe = davinci_i2s_probe, |
| 616 | .remove = davinci_i2s_remove, |
| 617 | .driver = { |
| 618 | .name = "davinci-asp", |
| 619 | .owner = THIS_MODULE, |
| 620 | }, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 621 | }; |
| 622 | |
Takashi Iwai | c9b3a40 | 2008-12-10 07:47:22 +0100 | [diff] [blame] | 623 | static int __init davinci_i2s_init(void) |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 624 | { |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 625 | return platform_driver_register(&davinci_mcbsp_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 626 | } |
| 627 | module_init(davinci_i2s_init); |
| 628 | |
| 629 | static void __exit davinci_i2s_exit(void) |
| 630 | { |
Chaithrika U S | 5204d49 | 2009-06-05 06:28:23 -0400 | [diff] [blame] | 631 | platform_driver_unregister(&davinci_mcbsp_driver); |
Mark Brown | 3f4b783 | 2008-12-03 19:26:35 +0000 | [diff] [blame] | 632 | } |
| 633 | module_exit(davinci_i2s_exit); |
| 634 | |
Vladimir Barinov | 310355c | 2008-02-18 11:40:22 +0100 | [diff] [blame] | 635 | MODULE_AUTHOR("Vladimir Barinov"); |
| 636 | MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface"); |
| 637 | MODULE_LICENSE("GPL"); |