blob: 6d0b8897fa6cdf64e77aec7c951234a2e285d89d [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 Nawrockiea37bd42016-08-04 11:30:28 +020038 .addr_width = 4,
Ben Dooks49646df2008-01-10 14:47:21 +010039};
40
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020041static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_in = {
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020042 .addr_width = 4,
Ben Dooks49646df2008-01-10 14:47:21 +010043};
44
Ben Dooksdc854472009-03-04 00:49:30 +000045static struct s3c_i2sv2_info s3c2412_i2s;
Ben Dooks49646df2008-01-10 14:47:21 +010046
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000047static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
Ben Dooks49646df2008-01-10 14:47:21 +010048{
Ben Dooksdc854472009-03-04 00:49:30 +000049 int ret;
50
Mark Brownee7d4762009-03-06 18:04:34 +000051 pr_debug("Entered %s\n", __func__);
Ben Dooks49646df2008-01-10 14:47:21 +010052
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +020053 snd_soc_dai_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
54 &s3c2412_i2s_pcm_stereo_in);
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +030055
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000056 ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
Ben Dooksdc854472009-03-04 00:49:30 +000057 if (ret)
58 return ret;
Ben Dooks49646df2008-01-10 14:47:21 +010059
Ben Dooksdc854472009-03-04 00:49:30 +000060 s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
61 s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
Ben Dooks49646df2008-01-10 14:47:21 +010062
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +030063 s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
Axel Lin7803e322011-09-15 10:36:54 +080064 if (IS_ERR(s3c2412_i2s.iis_cclk)) {
Mark Brown008bec32009-04-24 16:27:09 +010065 pr_err("failed to get i2sclk clock\n");
Axel Lin7803e322011-09-15 10:36:54 +080066 return PTR_ERR(s3c2412_i2s.iis_cclk);
Ben Dooks49646df2008-01-10 14:47:21 +010067 }
68
Ben Dooksdc854472009-03-04 00:49:30 +000069 /* Set MPLL as the source for IIS CLK */
Ben Dooks49646df2008-01-10 14:47:21 +010070
Ben Dooksdc854472009-03-04 00:49:30 +000071 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
Vasily Khoruzhick77ea6bf2014-06-23 23:24:06 +030072 clk_prepare_enable(s3c2412_i2s.iis_cclk);
Ben Dooks49646df2008-01-10 14:47:21 +010073
Ben Dooksdc854472009-03-04 00:49:30 +000074 s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
Ben Dooks49646df2008-01-10 14:47:21 +010075
Sylwester Nawrocki601787c2012-07-13 19:22:45 +020076 /* Configure the I2S pins (GPE0...GPE4) in correct mode */
77 s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
78 S3C_GPIO_PULL_NONE);
Ben Dooks49646df2008-01-10 14:47:21 +010079
Ben Dooks49646df2008-01-10 14:47:21 +010080 return 0;
81}
82
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
84{
Vasily Khoruzhick77ea6bf2014-06-23 23:24:06 +030085 clk_disable_unprepare(s3c2412_i2s.iis_cclk);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000086
87 return 0;
88}
89
Jassi Brar9c9b1252010-03-10 16:48:58 +090090static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
91 struct snd_pcm_hw_params *params,
92 struct snd_soc_dai *cpu_dai)
93{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000094 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
Jassi Brar9c9b1252010-03-10 16:48:58 +090095 u32 iismod;
96
97 pr_debug("Entered %s\n", __func__);
98
Jassi Brar9c9b1252010-03-10 16:48:58 +090099 iismod = readl(i2s->regs + S3C2412_IISMOD);
100 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
101
Tushar Behera88ce1462014-05-23 17:35:39 +0530102 switch (params_width(params)) {
103 case 8:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900104 iismod |= S3C2412_IISMOD_8BIT;
105 break;
Tushar Behera88ce1462014-05-23 17:35:39 +0530106 case 16:
Jassi Brar9c9b1252010-03-10 16:48:58 +0900107 iismod &= ~S3C2412_IISMOD_8BIT;
108 break;
109 }
110
111 writel(iismod, i2s->regs + S3C2412_IISMOD);
112 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
113
114 return 0;
115}
116
Ben Dooks49646df2008-01-10 14:47:21 +0100117#define S3C2412_I2S_RATES \
118 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
119 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
120 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
121
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100122static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
Jassi Brar9c9b1252010-03-10 16:48:58 +0900123 .hw_params = s3c2412_i2s_hw_params,
Eric Miao6335d052009-03-03 09:41:00 +0800124};
125
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000126static struct snd_soc_dai_driver s3c2412_i2s_dai = {
Ben Dooksdc854472009-03-04 00:49:30 +0000127 .probe = s3c2412_i2s_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000128 .remove = s3c2412_i2s_remove,
Ben Dooks49646df2008-01-10 14:47:21 +0100129 .playback = {
130 .channels_min = 2,
131 .channels_max = 2,
132 .rates = S3C2412_I2S_RATES,
133 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
134 },
135 .capture = {
136 .channels_min = 2,
137 .channels_max = 2,
138 .rates = S3C2412_I2S_RATES,
139 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
140 },
Eric Miao6335d052009-03-03 09:41:00 +0800141 .ops = &s3c2412_i2s_dai_ops,
Ben Dooks49646df2008-01-10 14:47:21 +0100142};
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000143
Kuninori Morimotoeca3b012013-03-21 03:35:22 -0700144static const struct snd_soc_component_driver s3c2412_i2s_component = {
145 .name = "s3c2412-i2s",
146};
147
Bill Pembertonfdca21a2012-12-07 09:26:15 -0500148static int s3c2412_iis_dev_probe(struct platform_device *pdev)
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000149{
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530150 int ret = 0;
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300151 struct resource *res;
Arnd Bergmann359fdfa2015-11-18 15:26:00 +0100152 struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
153
154 if (!pdata) {
155 dev_err(&pdev->dev, "missing platform data");
156 return -ENXIO;
157 }
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300158
159 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300160 s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
Wei Yongjun71864b22014-07-20 11:43:07 +0800161 if (IS_ERR(s3c2412_i2s.regs))
162 return PTR_ERR(s3c2412_i2s.regs);
Vasily Khoruzhick87b132b2014-06-23 23:24:04 +0300163
Sylwester Nawrockiea37bd42016-08-04 11:30:28 +0200164 s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
165 s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
166 s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
167 s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530168
Arnd Bergmann9bdca822015-11-18 22:31:11 +0100169 ret = samsung_asoc_dma_platform_register(&pdev->dev,
Sylwester Nawrocki42a74e72016-07-21 20:03:50 +0200170 pdata->dma_filter,
171 NULL, NULL);
Marek Szyprowski73f5dfc2016-10-27 12:34:02 +0200172 if (ret) {
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530173 pr_err("failed to register the DMA: %d\n", ret);
Marek Szyprowski73f5dfc2016-10-27 12:34:02 +0200174 return ret;
175 }
176
177 ret = s3c_i2sv2_register_component(&pdev->dev, -1,
178 &s3c2412_i2s_component,
179 &s3c2412_i2s_dai);
180 if (ret)
181 pr_err("failed to register the dai\n");
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530182
Padmavathi Vennaa08485d82012-12-07 13:59:21 +0530183 return ret;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000184}
185
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000186static struct platform_driver s3c2412_iis_driver = {
187 .probe = s3c2412_iis_dev_probe,
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000188 .driver = {
189 .name = "s3c2412-iis",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000190 },
191};
Ben Dooks49646df2008-01-10 14:47:21 +0100192
Mark Browne00c3f52011-11-23 15:20:13 +0000193module_platform_driver(s3c2412_iis_driver);
Mark Brown3f4b7832008-12-03 19:26:35 +0000194
Ben Dooks49646df2008-01-10 14:47:21 +0100195/* Module information */
196MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
197MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
198MODULE_LICENSE("GPL");
Mark Brown960d0692010-08-12 11:02:19 +0100199MODULE_ALIAS("platform:s3c2412-iis");