blob: c08638b0e458350e847955e67fdd312f510e3dde [file] [log] [blame]
Jassi Brar5033f432010-11-22 15:37:25 +09001/* sound/soc/samsung/s3c2412-i2s.c
Ben Dooks49646df2008-01-10 14:47:21 +01002 *
3 * ALSA Soc Audio Layer - S3C2412 I2S driver
4 *
5 * Copyright (c) 2006 Wolfson Microelectronics PLC.
6 * Graeme Gregory graeme.gregory@wolfsonmicro.com
7 * linux@wolfsonmicro.com
8 *
9 * Copyright (c) 2007, 2004-2005 Simtec Electronics
10 * http://armlinux.simtec.co.uk/
11 * Ben Dooks <ben@simtec.co.uk>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
Ben Dooks49646df2008-01-10 14:47:21 +010019#include <linux/delay.h>
Ben Dooksec976d62009-05-13 22:52:24 +010020#include <linux/gpio.h>
Ben Dooks49646df2008-01-10 14:47:21 +010021#include <linux/clk.h>
Ben Dooks8150bc82009-03-04 00:49:26 +000022#include <linux/io.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040023#include <linux/module.h>
Ben Dooks49646df2008-01-10 14:47:21 +010024
Ben Dooks49646df2008-01-10 14:47:21 +010025#include <sound/soc.h>
Seungwhan Youn0378b6a2011-01-11 07:26:06 +090026#include <sound/pcm_params.h>
Ben Dooks49646df2008-01-10 14:47:21 +010027
Sachin Kamatabffae62014-01-22 17:30:38 +053028#include <mach/gpio-samsung.h>
29#include <plat/gpio-cfg.h>
Ben Dooks49646df2008-01-10 14:47:21 +010030
Jassi Brar4b640cf2010-11-22 15:35:57 +090031#include "dma.h"
Jassi Brard07e7ce2010-04-27 15:55:21 +090032#include "regs-i2s-v2.h"
Ben Dooks49646df2008-01-10 14:47:21 +010033#include "s3c2412-i2s.h"
34
Arnd Bergmann359fdfa2015-11-18 15:26:00 +010035#include <linux/platform_data/asoc-s3c.h>
36
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020037static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_out = {
Sylwester Nawrockib8ab0cc2017-01-17 14:16:42 +010038 .chan_name = "tx",
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020039 .addr_width = 4,
Ben Dooks49646df2008-01-10 14:47:21 +010040};
41
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020042static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_in = {
Sylwester Nawrockib8ab0cc2017-01-17 14:16:42 +010043 .chan_name = "rx",
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020044 .addr_width = 4,
Ben Dooks49646df2008-01-10 14:47:21 +010045};
46
Ben Dooksdc854472009-03-04 00:49:30 +000047static struct s3c_i2sv2_info s3c2412_i2s;
Ben Dooks49646df2008-01-10 14:47:21 +010048
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000049static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
Ben Dooks49646df2008-01-10 14:47:21 +010050{
Ben Dooksdc854472009-03-04 00:49:30 +000051 int ret;
52
Mark Brownee7d4762009-03-06 18:04:34 +000053 pr_debug("Entered %s\n", __func__);
Ben Dooks49646df2008-01-10 14:47:21 +010054
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020055 snd_soc_dai_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
56 &s3c2412_i2s_pcm_stereo_in);
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +030057
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000058 ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
Ben Dooksdc854472009-03-04 00:49:30 +000059 if (ret)
60 return ret;
Ben Dooks49646df2008-01-10 14:47:21 +010061
Ben Dooksdc854472009-03-04 00:49:30 +000062 s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
63 s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
Ben Dooks49646df2008-01-10 14:47:21 +010064
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +030065 s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
Axel Lin7803e322011-09-15 10:36:54 +080066 if (IS_ERR(s3c2412_i2s.iis_cclk)) {
Mark Brown008bec32009-04-24 16:27:09 +010067 pr_err("failed to get i2sclk clock\n");
Krzysztof Kozlowski6f187f72017-07-27 19:13:38 +020068 ret = PTR_ERR(s3c2412_i2s.iis_cclk);
69 goto err;
Ben Dooks49646df2008-01-10 14:47:21 +010070 }
71
Ben Dooksdc854472009-03-04 00:49:30 +000072 /* Set MPLL as the source for IIS CLK */
Ben Dooks49646df2008-01-10 14:47:21 +010073
Ben Dooksdc854472009-03-04 00:49:30 +000074 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
Arvind Yadavd2d2c0a2017-07-25 15:44:28 +053075 ret = clk_prepare_enable(s3c2412_i2s.iis_cclk);
76 if (ret)
Krzysztof Kozlowski6f187f72017-07-27 19:13:38 +020077 goto err;
Ben Dooks49646df2008-01-10 14:47:21 +010078
Sylwester Nawrocki601787c2012-07-13 19:22:45 +020079 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
80 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
81 S3C_GPIO_PULL_NONE);
Ben Dooks49646df2008-01-10 14:47:21 +010082
Ben Dooks49646df2008-01-10 14:47:21 +010083 return 0;
Krzysztof Kozlowski6f187f72017-07-27 19:13:38 +020084
85err:
86 s3c_i2sv2_cleanup(dai, &s3c2412_i2s);
87
88 return ret;
Ben Dooks49646df2008-01-10 14:47:21 +010089}
90
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000091static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
92{
Vasily Khoruzhick77ea6bf2014-06-23 23:24:06 +030093 clk_disable_unprepare(s3c2412_i2s.iis_cclk);
Krzysztof Kozlowski6f187f72017-07-27 19:13:38 +020094 s3c_i2sv2_cleanup(dai, &s3c2412_i2s);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000095
96 return 0;
97}
98
Jassi Brar9c9b1252010-03-10 16:48:58 +090099static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
100 struct snd_pcm_hw_params *params,
101 struct snd_soc_dai *cpu_dai)
102{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000103 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
Jassi Brar9c9b1252010-03-10 16:48:58 +0900104 u32 iismod;
105
106 pr_debug("Entered %s\n", __func__);
107
Jassi Brar9c9b1252010-03-10 16:48:58 +0900108 iismod = readl(i2s->regs + S3C2412_IISMOD);
109 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
110
Tushar Behera88ce1462014-05-23 17:35:39 +0530111 switch (params_width(params)) {
112 case 8:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900113 iismod |= S3C2412_IISMOD_8BIT;
114 break;
Tushar Behera88ce1462014-05-23 17:35:39 +0530115 case 16:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900116 iismod &= ~S3C2412_IISMOD_8BIT;
117 break;
118 }
119
120 writel(iismod, i2s->regs + S3C2412_IISMOD);
121 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
122
123 return 0;
124}
125
Ben Dooks49646df2008-01-10 14:47:21 +0100126#define S3C2412_I2S_RATES \
127 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
128 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
129 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
130
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100131static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
Jassi Brar9c9b1252010-03-10 16:48:58 +0900132 .hw_params = s3c2412_i2s_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +0800133};
134
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000135static struct snd_soc_dai_driver s3c2412_i2s_dai = {
Ben Dooksdc854472009-03-04 00:49:30 +0000136 .probe = s3c2412_i2s_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000137 .remove = s3c2412_i2s_remove,
Ben Dooks49646df2008-01-10 14:47:21 +0100138 .playback = {
139 .channels_min = 2,
140 .channels_max = 2,
141 .rates = S3C2412_I2S_RATES,
142 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
143 },
144 .capture = {
145 .channels_min = 2,
146 .channels_max = 2,
147 .rates = S3C2412_I2S_RATES,
148 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
149 },
Eric Miao6335d052009-03-03 09:41:00 +0800150 .ops = &s3c2412_i2s_dai_ops,
Ben Dooks49646df2008-01-10 14:47:21 +0100151};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000152
Kuninori Morimotoeca3b012013-03-21 03:35:22 -0700153static const struct snd_soc_component_driver s3c2412_i2s_component = {
154 .name = "s3c2412-i2s",
155};
156
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500157static int s3c2412_iis_dev_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000158{
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530159 int ret = 0;
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +0300160 struct resource *res;
Arnd Bergmann359fdfa2015-11-18 15:26:00 +0100161 struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
162
163 if (!pdata) {
164 dev_err(&pdev->dev, "missing platform data");
165 return -ENXIO;
166 }
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +0300167
168 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +0300169 s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
Wei Yongjun71864b22014-07-20 11:43:07 +0800170 if (IS_ERR(s3c2412_i2s.regs))
171 return PTR_ERR(s3c2412_i2s.regs);
Vasily Khoruzhick87b132bc02014-06-23 23:24:04 +0300172
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +0200173 s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
174 s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
175 s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
176 s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530177
Arnd Bergmann9bdca822015-11-18 22:31:11 +0100178 ret = samsung_asoc_dma_platform_register(&pdev->dev,
Sylwester Nawrocki42a74e72016-07-21 20:03:50 +0200179 pdata->dma_filter,
Sylwester Nawrocki0f928c12019-02-14 10:37:41 +0100180 "tx", "rx", NULL);
Marek Szyprowski73f5dfc2016-10-27 12:34:02 +0200181 if (ret) {
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530182 pr_err("failed to register the DMA: %d\n", ret);
Marek Szyprowski73f5dfc2016-10-27 12:34:02 +0200183 return ret;
184 }
185
186 ret = s3c_i2sv2_register_component(&pdev->dev, -1,
187 &s3c2412_i2s_component,
188 &s3c2412_i2s_dai);
189 if (ret)
190 pr_err("failed to register the dai\n");
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530191
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530192 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000193}
194
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000195static struct platform_driver s3c2412_iis_driver = {
196 .probe = s3c2412_iis_dev_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000197 .driver = {
198 .name = "s3c2412-iis",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000199 },
200};
Ben Dooks49646df2008-01-10 14:47:21 +0100201
Mark Browne00c3f52011-11-23 15:20:13 +0000202module_platform_driver(s3c2412_iis_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000203
Ben Dooks49646df2008-01-10 14:47:21 +0100204/* Module information */
205MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
206MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
207MODULE_LICENSE("GPL");
Mark Brown960d0692010-08-12 11:02:19 +0100208MODULE_ALIAS("platform:s3c2412-iis");