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