blob: 14106fa82bca3ed821c2a2ad9977c2856e37bbf8 [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>
Stephen Warren71f78e22011-01-07 22:36:14 -070032#include <linux/device.h>
Stephen Warren7613c502012-04-06 11:12:25 -060033#include <linux/io.h>
34#include <linux/module.h>
35#include <linux/of.h>
Stephen Warren71f78e22011-01-07 22:36:14 -070036#include <linux/platform_device.h>
Stephen Warren82ef0ae2012-04-09 09:52:22 -060037#include <linux/pm_runtime.h>
Stephen Warrenc1607412012-04-13 12:14:06 -060038#include <linux/regmap.h>
Stephen Warren71f78e22011-01-07 22:36:14 -070039#include <linux/slab.h>
Stephen Warren71f78e22011-01-07 22:36:14 -070040#include <sound/core.h>
41#include <sound/pcm.h>
42#include <sound/pcm_params.h>
43#include <sound/soc.h>
Lars-Peter Clausen3489d502013-04-03 11:06:03 +020044#include <sound/dmaengine_pcm.h>
Stephen Warren71f78e22011-01-07 22:36:14 -070045
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 Warren82ef0ae2012-04-09 09:52:22 -060050static int tegra20_i2s_runtime_suspend(struct device *dev)
51{
52 struct tegra20_i2s *i2s = dev_get_drvdata(dev);
53
Prashant Gaikwad65d2bdd2012-06-05 09:59:42 +053054 clk_disable_unprepare(i2s->clk_i2s);
Stephen Warren82ef0ae2012-04-09 09:52:22 -060055
56 return 0;
57}
58
59static int tegra20_i2s_runtime_resume(struct device *dev)
60{
61 struct tegra20_i2s *i2s = dev_get_drvdata(dev);
62 int ret;
63
Prashant Gaikwad65d2bdd2012-06-05 09:59:42 +053064 ret = clk_prepare_enable(i2s->clk_i2s);
Stephen Warren82ef0ae2012-04-09 09:52:22 -060065 if (ret) {
66 dev_err(dev, "clk_enable failed: %d\n", ret);
67 return ret;
68 }
69
70 return 0;
71}
72
Stephen Warren896637a2012-04-06 10:30:52 -060073static int tegra20_i2s_set_fmt(struct snd_soc_dai *dai,
Stephen Warren71f78e22011-01-07 22:36:14 -070074 unsigned int fmt)
75{
Stephen Warren896637a2012-04-06 10:30:52 -060076 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren241bf432013-12-06 13:34:50 -070077 unsigned int mask = 0, val = 0;
Stephen Warren71f78e22011-01-07 22:36:14 -070078
79 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
80 case SND_SOC_DAIFMT_NB_NF:
81 break;
82 default:
83 return -EINVAL;
84 }
85
Stephen Warren241bf432013-12-06 13:34:50 -070086 mask |= TEGRA20_I2S_CTRL_MASTER_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -070087 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
88 case SND_SOC_DAIFMT_CBS_CFS:
Stephen Warren241bf432013-12-06 13:34:50 -070089 val |= TEGRA20_I2S_CTRL_MASTER_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -070090 break;
91 case SND_SOC_DAIFMT_CBM_CFM:
92 break;
93 default:
94 return -EINVAL;
95 }
96
Stephen Warren0f163542012-06-06 17:15:06 -060097 mask |= TEGRA20_I2S_CTRL_BIT_FORMAT_MASK |
98 TEGRA20_I2S_CTRL_LRCK_MASK;
Stephen Warren71f78e22011-01-07 22:36:14 -070099 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
100 case SND_SOC_DAIFMT_DSP_A:
Stephen Warren0f163542012-06-06 17:15:06 -0600101 val |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
102 val |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700103 break;
104 case SND_SOC_DAIFMT_DSP_B:
Stephen Warren0f163542012-06-06 17:15:06 -0600105 val |= TEGRA20_I2S_CTRL_BIT_FORMAT_DSP;
106 val |= TEGRA20_I2S_CTRL_LRCK_R_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700107 break;
108 case SND_SOC_DAIFMT_I2S:
Stephen Warren0f163542012-06-06 17:15:06 -0600109 val |= TEGRA20_I2S_CTRL_BIT_FORMAT_I2S;
110 val |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700111 break;
112 case SND_SOC_DAIFMT_RIGHT_J:
Stephen Warren0f163542012-06-06 17:15:06 -0600113 val |= TEGRA20_I2S_CTRL_BIT_FORMAT_RJM;
114 val |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700115 break;
116 case SND_SOC_DAIFMT_LEFT_J:
Stephen Warren0f163542012-06-06 17:15:06 -0600117 val |= TEGRA20_I2S_CTRL_BIT_FORMAT_LJM;
118 val |= TEGRA20_I2S_CTRL_LRCK_L_LOW;
Stephen Warren71f78e22011-01-07 22:36:14 -0700119 break;
120 default:
121 return -EINVAL;
122 }
123
Stephen Warren0f163542012-06-06 17:15:06 -0600124 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL, mask, val);
125
Stephen Warren71f78e22011-01-07 22:36:14 -0700126 return 0;
127}
128
Stephen Warren896637a2012-04-06 10:30:52 -0600129static int tegra20_i2s_hw_params(struct snd_pcm_substream *substream,
130 struct snd_pcm_hw_params *params,
131 struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700132{
Stephen Warrenc92a40e2012-06-06 17:15:05 -0600133 struct device *dev = dai->dev;
Stephen Warren896637a2012-04-06 10:30:52 -0600134 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren0f163542012-06-06 17:15:06 -0600135 unsigned int mask, val;
Stephen Warren71f78e22011-01-07 22:36:14 -0700136 int ret, sample_size, srate, i2sclock, bitcnt;
137
Stephen Warren0f163542012-06-06 17:15:06 -0600138 mask = TEGRA20_I2S_CTRL_BIT_SIZE_MASK;
Stephen Warren71f78e22011-01-07 22:36:14 -0700139 switch (params_format(params)) {
140 case SNDRV_PCM_FORMAT_S16_LE:
Stephen Warren0f163542012-06-06 17:15:06 -0600141 val = TEGRA20_I2S_CTRL_BIT_SIZE_16;
Stephen Warren71f78e22011-01-07 22:36:14 -0700142 sample_size = 16;
143 break;
144 case SNDRV_PCM_FORMAT_S24_LE:
Stephen Warren0f163542012-06-06 17:15:06 -0600145 val = TEGRA20_I2S_CTRL_BIT_SIZE_24;
Stephen Warren71f78e22011-01-07 22:36:14 -0700146 sample_size = 24;
147 break;
148 case SNDRV_PCM_FORMAT_S32_LE:
Stephen Warren0f163542012-06-06 17:15:06 -0600149 val = TEGRA20_I2S_CTRL_BIT_SIZE_32;
Stephen Warren71f78e22011-01-07 22:36:14 -0700150 sample_size = 32;
151 break;
152 default:
153 return -EINVAL;
154 }
155
Stephen Warren0f163542012-06-06 17:15:06 -0600156 mask |= TEGRA20_I2S_CTRL_FIFO_FORMAT_MASK;
157 val |= TEGRA20_I2S_CTRL_FIFO_FORMAT_PACKED;
158
159 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL, mask, val);
160
Stephen Warren71f78e22011-01-07 22:36:14 -0700161 srate = params_rate(params);
162
163 /* Final "* 2" required by Tegra hardware */
164 i2sclock = srate * params_channels(params) * sample_size * 2;
165
166 ret = clk_set_rate(i2s->clk_i2s, i2sclock);
167 if (ret) {
168 dev_err(dev, "Can't set I2S clock rate: %d\n", ret);
169 return ret;
170 }
171
172 bitcnt = (i2sclock / (2 * srate)) - 1;
Stephen Warren896637a2012-04-06 10:30:52 -0600173 if (bitcnt < 0 || bitcnt > TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_MASK_US)
Stephen Warren71f78e22011-01-07 22:36:14 -0700174 return -EINVAL;
Stephen Warren0f163542012-06-06 17:15:06 -0600175 val = bitcnt << TEGRA20_I2S_TIMING_CHANNEL_BIT_COUNT_SHIFT;
Stephen Warren71f78e22011-01-07 22:36:14 -0700176
177 if (i2sclock % (2 * srate))
Stephen Warren0f163542012-06-06 17:15:06 -0600178 val |= TEGRA20_I2S_TIMING_NON_SYM_ENABLE;
Stephen Warren71f78e22011-01-07 22:36:14 -0700179
Stephen Warren0f163542012-06-06 17:15:06 -0600180 regmap_write(i2s->regmap, TEGRA20_I2S_TIMING, val);
Stephen Warren71f78e22011-01-07 22:36:14 -0700181
Stephen Warren0f163542012-06-06 17:15:06 -0600182 regmap_write(i2s->regmap, TEGRA20_I2S_FIFO_SCR,
183 TEGRA20_I2S_FIFO_SCR_FIFO2_ATN_LVL_FOUR_SLOTS |
184 TEGRA20_I2S_FIFO_SCR_FIFO1_ATN_LVL_FOUR_SLOTS);
Stephen Warren71f78e22011-01-07 22:36:14 -0700185
186 return 0;
187}
188
Stephen Warren896637a2012-04-06 10:30:52 -0600189static void tegra20_i2s_start_playback(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700190{
Stephen Warren0f163542012-06-06 17:15:06 -0600191 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL,
192 TEGRA20_I2S_CTRL_FIFO1_ENABLE,
193 TEGRA20_I2S_CTRL_FIFO1_ENABLE);
Stephen Warren71f78e22011-01-07 22:36:14 -0700194}
195
Stephen Warren896637a2012-04-06 10:30:52 -0600196static void tegra20_i2s_stop_playback(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700197{
Stephen Warren0f163542012-06-06 17:15:06 -0600198 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL,
199 TEGRA20_I2S_CTRL_FIFO1_ENABLE, 0);
Stephen Warren71f78e22011-01-07 22:36:14 -0700200}
201
Stephen Warren896637a2012-04-06 10:30:52 -0600202static void tegra20_i2s_start_capture(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700203{
Stephen Warren0f163542012-06-06 17:15:06 -0600204 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL,
205 TEGRA20_I2S_CTRL_FIFO2_ENABLE,
206 TEGRA20_I2S_CTRL_FIFO2_ENABLE);
Stephen Warren71f78e22011-01-07 22:36:14 -0700207}
208
Stephen Warren896637a2012-04-06 10:30:52 -0600209static void tegra20_i2s_stop_capture(struct tegra20_i2s *i2s)
Stephen Warren71f78e22011-01-07 22:36:14 -0700210{
Stephen Warren0f163542012-06-06 17:15:06 -0600211 regmap_update_bits(i2s->regmap, TEGRA20_I2S_CTRL,
212 TEGRA20_I2S_CTRL_FIFO2_ENABLE, 0);
Stephen Warren71f78e22011-01-07 22:36:14 -0700213}
214
Stephen Warren896637a2012-04-06 10:30:52 -0600215static int tegra20_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
216 struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700217{
Stephen Warren896637a2012-04-06 10:30:52 -0600218 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700219
220 switch (cmd) {
221 case SNDRV_PCM_TRIGGER_START:
222 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
223 case SNDRV_PCM_TRIGGER_RESUME:
Stephen Warren71f78e22011-01-07 22:36:14 -0700224 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Stephen Warren896637a2012-04-06 10:30:52 -0600225 tegra20_i2s_start_playback(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700226 else
Stephen Warren896637a2012-04-06 10:30:52 -0600227 tegra20_i2s_start_capture(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700228 break;
229 case SNDRV_PCM_TRIGGER_STOP:
230 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
231 case SNDRV_PCM_TRIGGER_SUSPEND:
232 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Stephen Warren896637a2012-04-06 10:30:52 -0600233 tegra20_i2s_stop_playback(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700234 else
Stephen Warren896637a2012-04-06 10:30:52 -0600235 tegra20_i2s_stop_capture(i2s);
Stephen Warren71f78e22011-01-07 22:36:14 -0700236 break;
237 default:
238 return -EINVAL;
239 }
240
241 return 0;
242}
243
Stephen Warren896637a2012-04-06 10:30:52 -0600244static int tegra20_i2s_probe(struct snd_soc_dai *dai)
Stephen Warren71f78e22011-01-07 22:36:14 -0700245{
Stephen Warren896637a2012-04-06 10:30:52 -0600246 struct tegra20_i2s *i2s = snd_soc_dai_get_drvdata(dai);
Stephen Warren71f78e22011-01-07 22:36:14 -0700247
248 dai->capture_dma_data = &i2s->capture_dma_data;
249 dai->playback_dma_data = &i2s->playback_dma_data;
250
251 return 0;
252}
253
Stephen Warren896637a2012-04-06 10:30:52 -0600254static const struct snd_soc_dai_ops tegra20_i2s_dai_ops = {
255 .set_fmt = tegra20_i2s_set_fmt,
256 .hw_params = tegra20_i2s_hw_params,
257 .trigger = tegra20_i2s_trigger,
Stephen Warren71f78e22011-01-07 22:36:14 -0700258};
259
Stephen Warren896637a2012-04-06 10:30:52 -0600260static const struct snd_soc_dai_driver tegra20_i2s_dai_template = {
261 .probe = tegra20_i2s_probe,
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700262 .playback = {
Stephen Warren9515c102012-06-06 17:15:07 -0600263 .stream_name = "Playback",
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700264 .channels_min = 2,
265 .channels_max = 2,
266 .rates = SNDRV_PCM_RATE_8000_96000,
267 .formats = SNDRV_PCM_FMTBIT_S16_LE,
Stephen Warren71f78e22011-01-07 22:36:14 -0700268 },
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700269 .capture = {
Stephen Warren9515c102012-06-06 17:15:07 -0600270 .stream_name = "Capture",
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700271 .channels_min = 2,
272 .channels_max = 2,
273 .rates = SNDRV_PCM_RATE_8000_96000,
274 .formats = SNDRV_PCM_FMTBIT_S16_LE,
Stephen Warren71f78e22011-01-07 22:36:14 -0700275 },
Stephen Warren896637a2012-04-06 10:30:52 -0600276 .ops = &tegra20_i2s_dai_ops,
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700277 .symmetric_rates = 1,
Stephen Warren71f78e22011-01-07 22:36:14 -0700278};
279
Kuninori Morimotoa413a3c2013-03-21 03:37:55 -0700280static const struct snd_soc_component_driver tegra20_i2s_component = {
281 .name = DRV_NAME,
282};
283
Stephen Warrenc1607412012-04-13 12:14:06 -0600284static bool tegra20_i2s_wr_rd_reg(struct device *dev, unsigned int reg)
285{
286 switch (reg) {
287 case TEGRA20_I2S_CTRL:
288 case TEGRA20_I2S_STATUS:
289 case TEGRA20_I2S_TIMING:
290 case TEGRA20_I2S_FIFO_SCR:
291 case TEGRA20_I2S_PCM_CTRL:
292 case TEGRA20_I2S_NW_CTRL:
293 case TEGRA20_I2S_TDM_CTRL:
294 case TEGRA20_I2S_TDM_TX_RX_CTRL:
295 case TEGRA20_I2S_FIFO1:
296 case TEGRA20_I2S_FIFO2:
297 return true;
298 default:
299 return false;
Joe Perches1d198f22013-10-08 15:55:45 -0700300 }
Stephen Warrenc1607412012-04-13 12:14:06 -0600301}
302
303static bool tegra20_i2s_volatile_reg(struct device *dev, unsigned int reg)
304{
305 switch (reg) {
306 case TEGRA20_I2S_STATUS:
307 case TEGRA20_I2S_FIFO_SCR:
308 case TEGRA20_I2S_FIFO1:
309 case TEGRA20_I2S_FIFO2:
310 return true;
311 default:
312 return false;
Joe Perches1d198f22013-10-08 15:55:45 -0700313 }
Stephen Warrenc1607412012-04-13 12:14:06 -0600314}
315
316static bool tegra20_i2s_precious_reg(struct device *dev, unsigned int reg)
317{
318 switch (reg) {
319 case TEGRA20_I2S_FIFO1:
320 case TEGRA20_I2S_FIFO2:
321 return true;
322 default:
323 return false;
Joe Perches1d198f22013-10-08 15:55:45 -0700324 }
Stephen Warrenc1607412012-04-13 12:14:06 -0600325}
326
327static const struct regmap_config tegra20_i2s_regmap_config = {
328 .reg_bits = 32,
329 .reg_stride = 4,
330 .val_bits = 32,
331 .max_register = TEGRA20_I2S_FIFO2,
332 .writeable_reg = tegra20_i2s_wr_rd_reg,
333 .readable_reg = tegra20_i2s_wr_rd_reg,
334 .volatile_reg = tegra20_i2s_volatile_reg,
335 .precious_reg = tegra20_i2s_precious_reg,
Dylan Reid591d14f2014-03-17 22:08:49 -0700336 .cache_type = REGCACHE_FLAT,
Stephen Warrenc1607412012-04-13 12:14:06 -0600337};
338
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500339static int tegra20_i2s_platform_probe(struct platform_device *pdev)
Stephen Warren71f78e22011-01-07 22:36:14 -0700340{
Stephen Warren896637a2012-04-06 10:30:52 -0600341 struct tegra20_i2s *i2s;
Axel Linf57ddcd2015-08-23 23:32:14 +0800342 struct resource *mem;
Stephen Warrenc1607412012-04-13 12:14:06 -0600343 void __iomem *regs;
Stephen Warren71f78e22011-01-07 22:36:14 -0700344 int ret;
345
Stephen Warren896637a2012-04-06 10:30:52 -0600346 i2s = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_i2s), GFP_KERNEL);
Stephen Warren71f78e22011-01-07 22:36:14 -0700347 if (!i2s) {
Stephen Warren896637a2012-04-06 10:30:52 -0600348 dev_err(&pdev->dev, "Can't allocate tegra20_i2s\n");
Stephen Warren71f78e22011-01-07 22:36:14 -0700349 ret = -ENOMEM;
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700350 goto err;
Stephen Warren71f78e22011-01-07 22:36:14 -0700351 }
352 dev_set_drvdata(&pdev->dev, i2s);
353
Stephen Warren896637a2012-04-06 10:30:52 -0600354 i2s->dai = tegra20_i2s_dai_template;
Stephen Warrend4a2eca2011-11-23 13:33:25 -0700355 i2s->dai.name = dev_name(&pdev->dev);
356
Stephen Warrenb5f9cfe2011-07-01 13:56:14 -0600357 i2s->clk_i2s = clk_get(&pdev->dev, NULL);
Stephen Warren422650e2011-01-11 12:48:53 -0700358 if (IS_ERR(i2s->clk_i2s)) {
Stephen Warren713dce42011-01-28 14:26:41 -0700359 dev_err(&pdev->dev, "Can't retrieve i2s clock\n");
Stephen Warren71f78e22011-01-07 22:36:14 -0700360 ret = PTR_ERR(i2s->clk_i2s);
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700361 goto err;
Stephen Warren71f78e22011-01-07 22:36:14 -0700362 }
363
364 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Axel Linf57ddcd2015-08-23 23:32:14 +0800365 regs = devm_ioremap_resource(&pdev->dev, mem);
366 if (IS_ERR(regs)) {
367 ret = PTR_ERR(regs);
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700368 goto err_clk_put;
Stephen Warren71f78e22011-01-07 22:36:14 -0700369 }
370
Stephen Warrenc1607412012-04-13 12:14:06 -0600371 i2s->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
372 &tegra20_i2s_regmap_config);
373 if (IS_ERR(i2s->regmap)) {
374 dev_err(&pdev->dev, "regmap init failed\n");
375 ret = PTR_ERR(i2s->regmap);
376 goto err_clk_put;
377 }
378
Stephen Warren896637a2012-04-06 10:30:52 -0600379 i2s->capture_dma_data.addr = mem->start + TEGRA20_I2S_FIFO2;
Lars-Peter Clausen3489d502013-04-03 11:06:03 +0200380 i2s->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
381 i2s->capture_dma_data.maxburst = 4;
Stephen Warren71f78e22011-01-07 22:36:14 -0700382
Stephen Warren896637a2012-04-06 10:30:52 -0600383 i2s->playback_dma_data.addr = mem->start + TEGRA20_I2S_FIFO1;
Lars-Peter Clausen3489d502013-04-03 11:06:03 +0200384 i2s->playback_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
385 i2s->playback_dma_data.maxburst = 4;
Stephen Warren71f78e22011-01-07 22:36:14 -0700386
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600387 pm_runtime_enable(&pdev->dev);
388 if (!pm_runtime_enabled(&pdev->dev)) {
389 ret = tegra20_i2s_runtime_resume(&pdev->dev);
390 if (ret)
391 goto err_pm_disable;
392 }
393
Kuninori Morimotoa413a3c2013-03-21 03:37:55 -0700394 ret = snd_soc_register_component(&pdev->dev, &tegra20_i2s_component,
395 &i2s->dai, 1);
Stephen Warren71f78e22011-01-07 22:36:14 -0700396 if (ret) {
397 dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
398 ret = -ENOMEM;
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600399 goto err_suspend;
Stephen Warren71f78e22011-01-07 22:36:14 -0700400 }
401
Stephen Warren518de862012-03-20 14:55:49 -0600402 ret = tegra_pcm_platform_register(&pdev->dev);
403 if (ret) {
404 dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
Kuninori Morimotoa413a3c2013-03-21 03:37:55 -0700405 goto err_unregister_component;
Stephen Warren518de862012-03-20 14:55:49 -0600406 }
407
Stephen Warren71f78e22011-01-07 22:36:14 -0700408 return 0;
409
Kuninori Morimotoa413a3c2013-03-21 03:37:55 -0700410err_unregister_component:
411 snd_soc_unregister_component(&pdev->dev);
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600412err_suspend:
413 if (!pm_runtime_status_suspended(&pdev->dev))
414 tegra20_i2s_runtime_suspend(&pdev->dev);
415err_pm_disable:
416 pm_runtime_disable(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700417err_clk_put:
418 clk_put(i2s->clk_i2s);
Stephen Warrenbea0ed02011-11-22 18:21:16 -0700419err:
Stephen Warren71f78e22011-01-07 22:36:14 -0700420 return ret;
421}
422
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500423static int tegra20_i2s_platform_remove(struct platform_device *pdev)
Stephen Warren71f78e22011-01-07 22:36:14 -0700424{
Stephen Warren896637a2012-04-06 10:30:52 -0600425 struct tegra20_i2s *i2s = dev_get_drvdata(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700426
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600427 pm_runtime_disable(&pdev->dev);
428 if (!pm_runtime_status_suspended(&pdev->dev))
429 tegra20_i2s_runtime_suspend(&pdev->dev);
430
Stephen Warren518de862012-03-20 14:55:49 -0600431 tegra_pcm_platform_unregister(&pdev->dev);
Kuninori Morimotoa413a3c2013-03-21 03:37:55 -0700432 snd_soc_unregister_component(&pdev->dev);
Stephen Warren71f78e22011-01-07 22:36:14 -0700433
Stephen Warren71f78e22011-01-07 22:36:14 -0700434 clk_put(i2s->clk_i2s);
435
Stephen Warren71f78e22011-01-07 22:36:14 -0700436 return 0;
437}
438
Bill Pembertonf6e65742012-11-19 13:25:33 -0500439static const struct of_device_id tegra20_i2s_of_match[] = {
Stephen Warrenbf554992011-11-29 18:36:48 -0700440 { .compatible = "nvidia,tegra20-i2s", },
441 {},
442};
443
Bill Pembertonf6e65742012-11-19 13:25:33 -0500444static const struct dev_pm_ops tegra20_i2s_pm_ops = {
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600445 SET_RUNTIME_PM_OPS(tegra20_i2s_runtime_suspend,
446 tegra20_i2s_runtime_resume, NULL)
447};
448
Stephen Warren896637a2012-04-06 10:30:52 -0600449static struct platform_driver tegra20_i2s_driver = {
Stephen Warren71f78e22011-01-07 22:36:14 -0700450 .driver = {
451 .name = DRV_NAME,
Stephen Warren896637a2012-04-06 10:30:52 -0600452 .of_match_table = tegra20_i2s_of_match,
Stephen Warren82ef0ae2012-04-09 09:52:22 -0600453 .pm = &tegra20_i2s_pm_ops,
Stephen Warren71f78e22011-01-07 22:36:14 -0700454 },
Stephen Warren896637a2012-04-06 10:30:52 -0600455 .probe = tegra20_i2s_platform_probe,
Bill Pemberton4652a0d2012-12-07 09:26:33 -0500456 .remove = tegra20_i2s_platform_remove,
Stephen Warren71f78e22011-01-07 22:36:14 -0700457};
Stephen Warren896637a2012-04-06 10:30:52 -0600458module_platform_driver(tegra20_i2s_driver);
Stephen Warren71f78e22011-01-07 22:36:14 -0700459
460MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
Stephen Warren896637a2012-04-06 10:30:52 -0600461MODULE_DESCRIPTION("Tegra20 I2S ASoC driver");
Stephen Warren71f78e22011-01-07 22:36:14 -0700462MODULE_LICENSE("GPL");
Stephen Warren8eb34202011-02-10 15:37:19 -0700463MODULE_ALIAS("platform:" DRV_NAME);
Stephen Warren896637a2012-04-06 10:30:52 -0600464MODULE_DEVICE_TABLE(of, tegra20_i2s_of_match);