blob: 3e89fbc0c51d046049f6b6413d554c7e62186055 [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 = {
38 .chan_name = "tx",
39 .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 = {
43 .chan_name = "rx",
44 .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 Khoruzhick87b132b2014-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 Khoruzhick87b132b2014-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");
Axel Lin7803e322011-09-15 10:36:54 +080068 return PTR_ERR(s3c2412_i2s.iis_cclk);
Ben Dooks49646df2008-01-10 14:47:21 +010069 }
70
Ben Dooksdc854472009-03-04 00:49:30 +000071 /* Set MPLL as the source for IIS CLK */
Ben Dooks49646df2008-01-10 14:47:21 +010072
Ben Dooksdc854472009-03-04 00:49:30 +000073 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
Vasily Khoruzhick77ea6bf2014-06-23 23:24:06 +030074 clk_prepare_enable(s3c2412_i2s.iis_cclk);
Ben Dooks49646df2008-01-10 14:47:21 +010075
Ben Dooksdc854472009-03-04 00:49:30 +000076 s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
Ben Dooks49646df2008-01-10 14:47:21 +010077
Sylwester Nawrocki601787c2012-07-13 19:22:45 +020078 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
79 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
80 S3C_GPIO_PULL_NONE);
Ben Dooks49646df2008-01-10 14:47:21 +010081
Ben Dooks49646df2008-01-10 14:47:21 +010082 return 0;
83}
84
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000085static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
86{
Vasily Khoruzhick77ea6bf2014-06-23 23:24:06 +030087 clk_disable_unprepare(s3c2412_i2s.iis_cclk);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000088
89 return 0;
90}
91
Jassi Brar9c9b1252010-03-10 16:48:58 +090092static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
93 struct snd_pcm_hw_params *params,
94 struct snd_soc_dai *cpu_dai)
95{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000096 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
Jassi Brar9c9b1252010-03-10 16:48:58 +090097 u32 iismod;
98
99 pr_debug("Entered %s\n", __func__);
100
Jassi Brar9c9b1252010-03-10 16:48:58 +0900101 iismod = readl(i2s->regs + S3C2412_IISMOD);
102 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
103
Tushar Behera88ce1462014-05-23 17:35:39 +0530104 switch (params_width(params)) {
105 case 8:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900106 iismod |= S3C2412_IISMOD_8BIT;
107 break;
Tushar Behera88ce1462014-05-23 17:35:39 +0530108 case 16:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900109 iismod &= ~S3C2412_IISMOD_8BIT;
110 break;
111 }
112
113 writel(iismod, i2s->regs + S3C2412_IISMOD);
114 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
115
116 return 0;
117}
118
Ben Dooks49646df2008-01-10 14:47:21 +0100119#define S3C2412_I2S_RATES \
120 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
121 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
122 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
123
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100124static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
Jassi Brar9c9b1252010-03-10 16:48:58 +0900125 .hw_params = s3c2412_i2s_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +0800126};
127
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000128static struct snd_soc_dai_driver s3c2412_i2s_dai = {
Ben Dooksdc854472009-03-04 00:49:30 +0000129 .probe = s3c2412_i2s_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000130 .remove = s3c2412_i2s_remove,
Ben Dooks49646df2008-01-10 14:47:21 +0100131 .playback = {
132 .channels_min = 2,
133 .channels_max = 2,
134 .rates = S3C2412_I2S_RATES,
135 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
136 },
137 .capture = {
138 .channels_min = 2,
139 .channels_max = 2,
140 .rates = S3C2412_I2S_RATES,
141 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
142 },
Eric Miao6335d052009-03-03 09:41:00 +0800143 .ops = &s3c2412_i2s_dai_ops,
Ben Dooks49646df2008-01-10 14:47:21 +0100144};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000145
Kuninori Morimotoeca3b012013-03-21 03:35:22 -0700146static const struct snd_soc_component_driver s3c2412_i2s_component = {
147 .name = "s3c2412-i2s",
148};
149
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500150static int s3c2412_iis_dev_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000151{
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530152 int ret = 0;
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300153 struct resource *res;
Arnd Bergmann359fdfa2015-11-18 15:26:00 +0100154 struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
155
156 if (!pdata) {
157 dev_err(&pdev->dev, "missing platform data");
158 return -ENXIO;
159 }
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300160
161 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300162 s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
Wei Yongjun71864b22014-07-20 11:43:07 +0800163 if (IS_ERR(s3c2412_i2s.regs))
164 return PTR_ERR(s3c2412_i2s.regs);
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300165
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +0200166 s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
167 s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
168 s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
169 s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530170
Kuninori Morimotoeca3b012013-03-21 03:35:22 -0700171 ret = s3c_i2sv2_register_component(&pdev->dev, -1,
172 &s3c2412_i2s_component,
173 &s3c2412_i2s_dai);
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530174 if (ret) {
175 pr_err("failed to register the dai\n");
176 return ret;
177 }
178
Arnd Bergmann9bdca822015-11-18 22:31:11 +0100179 ret = samsung_asoc_dma_platform_register(&pdev->dev,
Sylwester Nawrocki42a74e72016-07-21 20:03:50 +0200180 pdata->dma_filter,
181 NULL, NULL);
Tushar Behera7253e352014-05-21 08:52:19 +0530182 if (ret)
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530183 pr_err("failed to register the DMA: %d\n", ret);
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530184
Padmavathi Vennaa08485d2012-12-07 13:59:21 +0530185 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000186}
187
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000188static struct platform_driver s3c2412_iis_driver = {
189 .probe = s3c2412_iis_dev_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000190 .driver = {
191 .name = "s3c2412-iis",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000192 },
193};
Ben Dooks49646df2008-01-10 14:47:21 +0100194
Mark Browne00c3f52011-11-23 15:20:13 +0000195module_platform_driver(s3c2412_iis_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000196
Ben Dooks49646df2008-01-10 14:47:21 +0100197/* Module information */
198MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
199MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
200MODULE_LICENSE("GPL");
Mark Brown960d0692010-08-12 11:02:19 +0100201MODULE_ALIAS("platform:s3c2412-iis");