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