blob: 878798c89e491ff8f2a8283e25fa0ac39afb8005 [file] [log] [blame]
Stephen Warren71f78e22011-01-07 22:36:14 -07001/*
Stephen Warrenef280d32012-04-05 15:54:53 -06002 * tegra20_i2s.c - Tegra20 I2S driver
Stephen Warren71f78e22011-01-07 22:36:14 -07003 *
4 * Author: Stephen Warren <swarren@nvidia.com>
Stephen Warren518de862012-03-20 14:55:49 -06005 * Copyright (C) 2010,2012 - NVIDIA, Inc.
Stephen Warren71f78e22011-01-07 22:36:14 -07006 *
7 * Based on code copyright/by:
8 *
9 * Copyright (c) 2009-2010, NVIDIA Corporation.
10 * Scott Peterson <speterson@nvidia.com>
11 *
12 * Copyright (C) 2010 Google, Inc.
13 * Iliyan Malchev <malchev@google.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * version 2 as published by the Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 * 02110-1301 USA
28 *
29 */
30
31#include <linux/clk.h>
32#include <linux/module.h>
33#include <linux/debugfs.h>
34#include <linux/device.h>
35#include <linux/platform_device.h>
36#include <linux/seq_file.h>
37#include <linux/slab.h>
38#include <linux/io.h>
Stephen Warrenbf554992011-11-29 18:36:48 -070039#include <linux/of.h>
Stephen Warren71f78e22011-01-07 22:36:14 -070040#include <mach/iomap.h>
41#include <sound/core.h>
42#include <sound/pcm.h>
43#include <sound/pcm_params.h>
44#include <sound/soc.h>
45
Stephen Warrenef280d32012-04-05 15:54:53 -060046#include "tegra20_i2s.h"
Stephen Warren71f78e22011-01-07 22:36:14 -070047
Stephen Warren896637a2012-04-06 10:30:52 -060048#define DRV_NAME "tegra20-i2s"
Stephen Warren71f78e22011-01-07 22:36:14 -070049
Stephen Warren896637a2012-04-06 10:30:52 -060050static inline void tegra20_i2s_write(struct tegra20_i2s *i2s, u32 reg, u32 val)
Stephen Warren71f78e22011-01-07 22:36:14 -070051{
52 __raw_writel(val, i2s->regs + reg);
53}
54
Stephen Warren896637a2012-04-06 10:30:52 -060055static inline u32 tegra20_i2s_read(struct tegra20_i2s *i2s, u32 reg)
Stephen Warren71f78e22011-01-07 22:36:14 -070056{
57 return __raw_readl(i2s->regs + reg);
58}
59
60#ifdef CONFIG_DEBUG_FS
Stephen Warren896637a2012-04-06 10:30:52 -060061static int tegra20_i2s_show(struct seq_file *s, void *unused)
Stephen Warren71f78e22011-01-07 22:36:14 -070062{
63#define REG(r) { r, #r }
64 static const struct {
65 int offset;
66 const char *name;
67 } regs[] = {
Stephen Warren896637a2012-04-06 10:30:52 -060068 REG(TEGRA20_I2S_CTRL),
69 REG(TEGRA20_I2S_STATUS),
70 REG(TEGRA20_I2S_TIMING),
71 REG(TEGRA20_I2S_FIFO_SCR),
72 REG(TEGRA20_I2S_PCM_CTRL),
73 REG(TEGRA20_I2S_NW_CTRL),
74 REG(TEGRA20_I2S_TDM_CTRL),
75 REG(TEGRA20_I2S_TDM_TX_RX_CTRL),
Stephen Warren71f78e22011-01-07 22:36:14 -070076 };
77#undef REG
78
Stephen Warren896637a2012-04-06 10:30:52 -060079 struct tegra20_i2s *i2s = s->private;
Stephen Warren71f78e22011-01-07 22:36:14 -070080 int i;
81
82 for (i = 0; i < ARRAY_SIZE(regs); i++) {
Stephen Warren896637a2012-04-06 10:30:52 -060083 u32 val = tegra20_i2s_read(i2s, regs[i].offset);
Stephen Warren71f78e22011-01-07 22:36:14 -070084 seq_printf(s, "%s = %08x\n", regs[i].name, val);
85 }
86
87 return 0;
88}
89
Stephen Warren896637a2012-04-06 10:30:52 -060090static int tegra20_i2s_debug_open(struct inode *inode, struct file *file)
Stephen Warren71f78e22011-01-07 22:36:14 -070091{
Stephen Warren896637a2012-04-06 10:30:52 -060092 return single_open(file, tegra20_i2s_show, inode->i_private);
Stephen Warren71f78e22011-01-07 22:36:14 -070093}
94
Stephen Warren896637a2012-04-06 10:30:52 -060095static const struct file_operations tegra20_i2s_debug_fops = {
96 .open = tegra20_i2s_debug_open,
Stephen Warren71f78e22011-01-07 22:36:14 -070097 .read = seq_read,
98 .llseek = seq_lseek,
99 .release = single_release,
100};
101
Stephen Warren896637a2012-04-06 10:30:52 -0600102static void tegra20_i2s_debug_add(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700103{
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700104 i2s->debug = debugfs_create_file(i2s->dai.name, S_IRUGO,
105 snd_soc_debugfs_root, i2s,
Stephen Warren896637a2012-04-06 10:30:52 -0600106 &tegra20_i2s_debug_fops);
Stephen Warren71f78e22011-01-07 22:36:14 -0700107}
108
Stephen Warren896637a2012-04-06 10:30:52 -0600109static void tegra20_i2s_debug_remove(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700110{
111 if (i2s->debug)
112 debugfs_remove(i2s->debug);
113}
114#else
Stephen Warren896637a2012-04-06 10:30:52 -0600115static inline void tegra20_i2s_debug_add(struct tegra20_i2s *i2s, int id)
Stephen Warren71f78e22011-01-07 22:36:14 -0700116{
117}
118
Stephen Warren896637a2012-04-06 10:30:52 -0600119static inline void tegra20_i2s_debug_remove(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700120{
121}
122#endif
123
Stephen Warren896637a2012-04-06 10:30:52 -0600124static int tegra20_i2s_set_fmt(struct snd_soc_dai *dai,
Stephen Warren71f78e22011-01-07 22:36:14 -0700125 unsigned int fmt)
126{
Stephen Warren896637a2012-04-06 10:30:52 -0600127 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700128
129 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
130 case SND_SOC_DAIFMT_NB_NF:
131 break;
132 default:
133 return -EINVAL;
134 }
135
Stephen Warren896637a2012-04-06 10:30:52 -0600136 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_MASTER_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -0700137 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
138 case SND_SOC_DAIFMT_CBS_CFS:
Stephen Warren896637a2012-04-06 10:30:52 -0600139 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_MASTER_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -0700140 break;
141 case SND_SOC_DAIFMT_CBM_CFM:
142 break;
143 default:
144 return -EINVAL;
145 }
146
Stephen Warren896637a2012-04-06 10:30:52 -0600147 i2s->reg_ctrl &= ~(TEGRA20_I2S_CTRL_BIT_FORMAT_MASK |
148 TEGRA20_I2S_CTRL_LRCK_MASK);
Stephen Warren71f78e22011-01-07 22:36:14 -0700149 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
150 case SND_SOC_DAIFMT_DSP_A:
Stephen Warren896637a2012-04-06 10:30:52 -0600151 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
152 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700153 break;
154 case SND_SOC_DAIFMT_DSP_B:
Stephen Warren896637a2012-04-06 10:30:52 -0600155 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
156 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_R_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700157 break;
158 case SND_SOC_DAIFMT_I2S:
Stephen Warren896637a2012-04-06 10:30:52 -0600159 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_I2S;
160 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700161 break;
162 case SND_SOC_DAIFMT_RIGHT_J:
Stephen Warren896637a2012-04-06 10:30:52 -0600163 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_RJM;
164 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700165 break;
166 case SND_SOC_DAIFMT_LEFT_J:
Stephen Warren896637a2012-04-06 10:30:52 -0600167 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_FORMAT_LJM;
168 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700169 break;
170 default:
171 return -EINVAL;
172 }
173
174 return 0;
175}
176
Stephen Warren896637a2012-04-06 10:30:52 -0600177static int tegra20_i2s_hw_params(struct snd_pcm_substream *substream,
178 struct snd_pcm_hw_params *params,
179 struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700180{
Stephen Warren7deb2b42012-03-30 17:07:21 -0600181 struct device *dev = substream->pcm->card->dev;
Stephen Warren896637a2012-04-06 10:30:52 -0600182 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700183 u32 reg;
184 int ret, sample_size, srate, i2sclock, bitcnt;
185
Stephen Warren896637a2012-04-06 10:30:52 -0600186 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_BIT_SIZE_MASK;
Stephen Warren71f78e22011-01-07 22:36:14 -0700187 switch (params_format(params)) {
188 case SNDRV_PCM_FORMAT_S16_LE:
Stephen Warren896637a2012-04-06 10:30:52 -0600189 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_16;
Stephen Warren71f78e22011-01-07 22:36:14 -0700190 sample_size = 16;
191 break;
192 case SNDRV_PCM_FORMAT_S24_LE:
Stephen Warren896637a2012-04-06 10:30:52 -0600193 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_24;
Stephen Warren71f78e22011-01-07 22:36:14 -0700194 sample_size = 24;
195 break;
196 case SNDRV_PCM_FORMAT_S32_LE:
Stephen Warren896637a2012-04-06 10:30:52 -0600197 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_BIT_SIZE_32;
Stephen Warren71f78e22011-01-07 22:36:14 -0700198 sample_size = 32;
199 break;
200 default:
201 return -EINVAL;
202 }
203
204 srate = params_rate(params);
205
206 /* Final "* 2" required by Tegra hardware */
207 i2sclock = srate * params_channels(params) * sample_size * 2;
208
209 ret = clk_set_rate(i2s->clk_i2s, i2sclock);
210 if (ret) {
211 dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
212 return ret;
213 }
214
215 bitcnt = (i2sclock / (2 * srate)) - 1;
Stephen Warren896637a2012-04-06 10:30:52 -0600216 if (bitcnt < 0 || bitcnt > TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
Stephen Warren71f78e22011-01-07 22:36:14 -0700217 return -EINVAL;
Stephen Warren896637a2012-04-06 10:30:52 -0600218 reg = bitcnt << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
Stephen Warren71f78e22011-01-07 22:36:14 -0700219
220 if (i2sclock % (2 * srate))
Stephen Warren896637a2012-04-06 10:30:52 -0600221 reg |= TEGRA20_I2S_TIMING_NON_SYM_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -0700222
Stephen Warren30d436a2012-03-30 17:07:16 -0600223 clk_enable(i2s->clk_i2s);
Stephen Warren713d1362011-07-01 13:56:13 -0600224
Stephen Warren896637a2012-04-06 10:30:52 -0600225 tegra20_i2s_write(i2s, TEGRA20_I2S_TIMING, reg);
Stephen Warren71f78e22011-01-07 22:36:14 -0700226
Stephen Warren896637a2012-04-06 10:30:52 -0600227 tegra20_i2s_write(i2s, TEGRA20_I2S_FIFO_SCR,
228 TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS |
229 TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS);
Stephen Warren71f78e22011-01-07 22:36:14 -0700230
Stephen Warren30d436a2012-03-30 17:07:16 -0600231 clk_disable(i2s->clk_i2s);
Stephen Warren713d1362011-07-01 13:56:13 -0600232
Stephen Warren71f78e22011-01-07 22:36:14 -0700233 return 0;
234}
235
Stephen Warren896637a2012-04-06 10:30:52 -0600236static void tegra20_i2s_start_playback(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700237{
Stephen Warren896637a2012-04-06 10:30:52 -0600238 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO1_ENABLE;
239 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
Stephen Warren71f78e22011-01-07 22:36:14 -0700240}
241
Stephen Warren896637a2012-04-06 10:30:52 -0600242static void tegra20_i2s_stop_playback(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700243{
Stephen Warren896637a2012-04-06 10:30:52 -0600244 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO1_ENABLE;
245 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
Stephen Warren71f78e22011-01-07 22:36:14 -0700246}
247
Stephen Warren896637a2012-04-06 10:30:52 -0600248static void tegra20_i2s_start_capture(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700249{
Stephen Warren896637a2012-04-06 10:30:52 -0600250 i2s->reg_ctrl |= TEGRA20_I2S_CTRL_FIFO2_ENABLE;
251 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
Stephen Warren71f78e22011-01-07 22:36:14 -0700252}
253
Stephen Warren896637a2012-04-06 10:30:52 -0600254static void tegra20_i2s_stop_capture(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700255{
Stephen Warren896637a2012-04-06 10:30:52 -0600256 i2s->reg_ctrl &= ~TEGRA20_I2S_CTRL_FIFO2_ENABLE;
257 tegra20_i2s_write(i2s, TEGRA20_I2S_CTRL, i2s->reg_ctrl);
Stephen Warren71f78e22011-01-07 22:36:14 -0700258}
259
Stephen Warren896637a2012-04-06 10:30:52 -0600260static int tegra20_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
261 struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700262{
Stephen Warren896637a2012-04-06 10:30:52 -0600263 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700264
265 switch (cmd) {
266 case SNDRV_PCM_TRIGGER_START:
267 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
268 case SNDRV_PCM_TRIGGER_RESUME:
Stephen Warren30d436a2012-03-30 17:07:16 -0600269 clk_enable(i2s->clk_i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700270 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Stephen Warren896637a2012-04-06 10:30:52 -0600271 tegra20_i2s_start_playback(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700272 else
Stephen Warren896637a2012-04-06 10:30:52 -0600273 tegra20_i2s_start_capture(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700274 break;
275 case SNDRV_PCM_TRIGGER_STOP:
276 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
277 case SNDRV_PCM_TRIGGER_SUSPEND:
278 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Stephen Warren896637a2012-04-06 10:30:52 -0600279 tegra20_i2s_stop_playback(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700280 else
Stephen Warren896637a2012-04-06 10:30:52 -0600281 tegra20_i2s_stop_capture(i2s);
Stephen Warren30d436a2012-03-30 17:07:16 -0600282 clk_disable(i2s->clk_i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700283 break;
284 default:
285 return -EINVAL;
286 }
287
288 return 0;
289}
290
Stephen Warren896637a2012-04-06 10:30:52 -0600291static int tegra20_i2s_probe(struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700292{
Stephen Warren896637a2012-04-06 10:30:52 -0600293 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700294
295 dai->capture_dma_data = &i2s->capture_dma_data;
296 dai->playback_dma_data = &i2s->playback_dma_data;
297
298 return 0;
299}
300
Stephen Warren896637a2012-04-06 10:30:52 -0600301static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = {
302 .set_fmt = tegra20_i2s_set_fmt,
303 .hw_params = tegra20_i2s_hw_params,
304 .trigger = tegra20_i2s_trigger,
Stephen Warren71f78e22011-01-07 22:36:14 -0700305};
306
Stephen Warren896637a2012-04-06 10:30:52 -0600307static const struct snd_soc_dai_driver tegra20_i2s_dai_template = {
308 .probe = tegra20_i2s_probe,
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700309 .playback = {
310 .channels_min = 2,
311 .channels_max = 2,
312 .rates = SNDRV_PCM_RATE_8000_96000,
313 .formats = SNDRV_PCM_FMTBIT_S16_LE,
Stephen Warren71f78e22011-01-07 22:36:14 -0700314 },
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700315 .capture = {
316 .channels_min = 2,
317 .channels_max = 2,
318 .rates = SNDRV_PCM_RATE_8000_96000,
319 .formats = SNDRV_PCM_FMTBIT_S16_LE,
Stephen Warren71f78e22011-01-07 22:36:14 -0700320 },
Stephen Warren896637a2012-04-06 10:30:52 -0600321 .ops = &tegra20_i2s_dai_ops,
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700322 .symmetric_rates = 1,
Stephen Warren71f78e22011-01-07 22:36:14 -0700323};
324
Stephen Warren896637a2012-04-06 10:30:52 -0600325static __devinit int tegra20_i2s_platform_probe(struct platform_device *pdev)
Stephen Warren71f78e22011-01-07 22:36:14 -0700326{
Stephen Warren896637a2012-04-06 10:30:52 -0600327 struct tegra20_i2s *i2s;
Stephen Warren71f78e22011-01-07 22:36:14 -0700328 struct resource *mem, *memregion, *dmareq;
Stephen Warrenbf554992011-11-29 18:36:48 -0700329 u32 of_dma[2];
330 u32 dma_ch;
Stephen Warren71f78e22011-01-07 22:36:14 -0700331 int ret;
332
Stephen Warren896637a2012-04-06 10:30:52 -0600333 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_i2s), GFP_KERNEL);
Stephen Warren71f78e22011-01-07 22:36:14 -0700334 if (!i2s) {
Stephen Warren896637a2012-04-06 10:30:52 -0600335 dev_err(&pdev->dev, "Can't allocate tegra20_i2s\n");
Stephen Warren71f78e22011-01-07 22:36:14 -0700336 ret = -ENOMEM;
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700337 goto err;
Stephen Warren71f78e22011-01-07 22:36:14 -0700338 }
339 dev_set_drvdata(&pdev->dev, i2s);
340
Stephen Warren896637a2012-04-06 10:30:52 -0600341 i2s->dai = tegra20_i2s_dai_template;
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700342 i2s->dai.name = dev_name(&pdev->dev);
343
Stephen Warrenb5f9cfe2011-07-01 13:56:14 -0600344 i2s->clk_i2s = clk_get(&pdev->dev, NULL);
Stephen Warren422650e2011-01-11 12:48:53 -0700345 if (IS_ERR(i2s->clk_i2s)) {
Stephen Warren713dce42011-01-28 14:26:41 -0700346 dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
Stephen Warren71f78e22011-01-07 22:36:14 -0700347 ret = PTR_ERR(i2s->clk_i2s);
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700348 goto err;
Stephen Warren71f78e22011-01-07 22:36:14 -0700349 }
350
351 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
352 if (!mem) {
353 dev_err(&pdev->dev, "No memory resource\n");
354 ret = -ENODEV;
355 goto err_clk_put;
356 }
357
358 dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
359 if (!dmareq) {
Stephen Warrenbf554992011-11-29 18:36:48 -0700360 if (of_property_read_u32_array(pdev->dev.of_node,
361 "nvidia,dma-request-selector",
362 of_dma, 2) < 0) {
363 dev_err(&pdev->dev, "No DMA resource\n");
364 ret = -ENODEV;
365 goto err_clk_put;
366 }
367 dma_ch = of_dma[1];
368 } else {
369 dma_ch = dmareq->start;
Stephen Warren71f78e22011-01-07 22:36:14 -0700370 }
371
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700372 memregion = devm_request_mem_region(&pdev->dev, mem->start,
373 resource_size(mem), DRV_NAME);
Stephen Warren71f78e22011-01-07 22:36:14 -0700374 if (!memregion) {
375 dev_err(&pdev->dev, "Memory region already claimed\n");
376 ret = -EBUSY;
377 goto err_clk_put;
378 }
379
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700380 i2s->regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
Stephen Warren71f78e22011-01-07 22:36:14 -0700381 if (!i2s->regs) {
382 dev_err(&pdev->dev, "ioremap failed\n");
383 ret = -ENOMEM;
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700384 goto err_clk_put;
Stephen Warren71f78e22011-01-07 22:36:14 -0700385 }
386
Stephen Warren896637a2012-04-06 10:30:52 -0600387 i2s->capture_dma_data.addr = mem->start + TEGRA20_I2S_FIFO2;
Stephen Warren71f78e22011-01-07 22:36:14 -0700388 i2s->capture_dma_data.wrap = 4;
389 i2s->capture_dma_data.width = 32;
Stephen Warrenbf554992011-11-29 18:36:48 -0700390 i2s->capture_dma_data.req_sel = dma_ch;
Stephen Warren71f78e22011-01-07 22:36:14 -0700391
Stephen Warren896637a2012-04-06 10:30:52 -0600392 i2s->playback_dma_data.addr = mem->start + TEGRA20_I2S_FIFO1;
Stephen Warren71f78e22011-01-07 22:36:14 -0700393 i2s->playback_dma_data.wrap = 4;
394 i2s->playback_dma_data.width = 32;
Stephen Warrenbf554992011-11-29 18:36:48 -0700395 i2s->playback_dma_data.req_sel = dma_ch;
Stephen Warren71f78e22011-01-07 22:36:14 -0700396
Stephen Warren896637a2012-04-06 10:30:52 -0600397 i2s->reg_ctrl = TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED;
Stephen Warren71f78e22011-01-07 22:36:14 -0700398
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700399 ret = snd_soc_register_dai(&pdev->dev, &i2s->dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700400 if (ret) {
401 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
402 ret = -ENOMEM;
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700403 goto err_clk_put;
Stephen Warren71f78e22011-01-07 22:36:14 -0700404 }
405
Stephen Warren518de862012-03-20 14:55:49 -0600406 ret = tegra_pcm_platform_register(&pdev->dev);
407 if (ret) {
408 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
409 goto err_unregister_dai;
410 }
411
Stephen Warren896637a2012-04-06 10:30:52 -0600412 tegra20_i2s_debug_add(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700413
414 return 0;
415
Stephen Warren518de862012-03-20 14:55:49 -0600416err_unregister_dai:
417 snd_soc_unregister_dai(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700418err_clk_put:
419 clk_put(i2s->clk_i2s);
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700420err:
Stephen Warren71f78e22011-01-07 22:36:14 -0700421 return ret;
422}
423
Stephen Warren896637a2012-04-06 10:30:52 -0600424static int __devexit tegra20_i2s_platform_remove(struct platform_device *pdev)
Stephen Warren71f78e22011-01-07 22:36:14 -0700425{
Stephen Warren896637a2012-04-06 10:30:52 -0600426 struct tegra20_i2s *i2s = dev_get_drvdata(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700427
Stephen Warren518de862012-03-20 14:55:49 -0600428 tegra_pcm_platform_unregister(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700429 snd_soc_unregister_dai(&pdev->dev);
430
Stephen Warren896637a2012-04-06 10:30:52 -0600431 tegra20_i2s_debug_remove(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700432
Stephen Warren71f78e22011-01-07 22:36:14 -0700433 clk_put(i2s->clk_i2s);
434
Stephen Warren71f78e22011-01-07 22:36:14 -0700435 return 0;
436}
437
Stephen Warren896637a2012-04-06 10:30:52 -0600438static const struct of_device_id tegra20_i2s_of_match[] __devinitconst = {
Stephen Warrenbf554992011-11-29 18:36:48 -0700439 { .compatible = "nvidia,tegra20-i2s", },
440 {},
441};
442
Stephen Warren896637a2012-04-06 10:30:52 -0600443static struct platform_driver tegra20_i2s_driver = {
Stephen Warren71f78e22011-01-07 22:36:14 -0700444 .driver = {
445 .name = DRV_NAME,
446 .owner = THIS_MODULE,
Stephen Warren896637a2012-04-06 10:30:52 -0600447 .of_match_table = tegra20_i2s_of_match,
Stephen Warren71f78e22011-01-07 22:36:14 -0700448 },
Stephen Warren896637a2012-04-06 10:30:52 -0600449 .probe = tegra20_i2s_platform_probe,
450 .remove = __devexit_p(tegra20_i2s_platform_remove),
Stephen Warren71f78e22011-01-07 22:36:14 -0700451};
Stephen Warren896637a2012-04-06 10:30:52 -0600452module_platform_driver(tegra20_i2s_driver);
Stephen Warren71f78e22011-01-07 22:36:14 -0700453
454MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
Stephen Warren896637a2012-04-06 10:30:52 -0600455MODULE_DESCRIPTION("Tegra20 I2S ASoC driver");
Stephen Warren71f78e22011-01-07 22:36:14 -0700456MODULE_LICENSE("GPL");
Stephen Warren8eb34202011-02-10 15:37:19 -0700457MODULE_ALIAS("platform:" DRV_NAME);
Stephen Warren896637a2012-04-06 10:30:52 -0600458MODULE_DEVICE_TABLE(of, tegra20_i2s_of_match);