Commit | Line | Data |
---|---|---|
5033f43c | 1 | /* sound/soc/samsung/s3c2412-i2s.c |
49646dfa BD |
2 | * |
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 | ||
49646dfa | 19 | #include <linux/delay.h> |
ec976d6e | 20 | #include <linux/gpio.h> |
49646dfa | 21 | #include <linux/clk.h> |
8150bc88 | 22 | #include <linux/io.h> |
da155d5b | 23 | #include <linux/module.h> |
49646dfa | 24 | |
49646dfa | 25 | #include <sound/soc.h> |
0378b6ac | 26 | #include <sound/pcm_params.h> |
49646dfa | 27 | |
a09e64fb | 28 | #include <mach/dma.h> |
abffae64 SK |
29 | #include <mach/gpio-samsung.h> |
30 | #include <plat/gpio-cfg.h> | |
49646dfa | 31 | |
4b640cf3 | 32 | #include "dma.h" |
d07e7ce9 | 33 | #include "regs-i2s-v2.h" |
49646dfa BD |
34 | #include "s3c2412-i2s.h" |
35 | ||
faa31776 | 36 | static struct s3c_dma_params s3c2412_i2s_pcm_stereo_out = { |
49646dfa | 37 | .channel = DMACH_I2S_OUT, |
87b132bc | 38 | .ch_name = "tx", |
49646dfa BD |
39 | .dma_size = 4, |
40 | }; | |
41 | ||
faa31776 | 42 | static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = { |
49646dfa | 43 | .channel = DMACH_I2S_IN, |
87b132bc | 44 | .ch_name = "rx", |
49646dfa BD |
45 | .dma_size = 4, |
46 | }; | |
47 | ||
dc85447b | 48 | static struct s3c_i2sv2_info s3c2412_i2s; |
49646dfa | 49 | |
f0fba2ad | 50 | static int s3c2412_i2s_probe(struct snd_soc_dai *dai) |
49646dfa | 51 | { |
dc85447b | 52 | int ret; |
49646dfa | 53 | |
ee7d4767 | 54 | pr_debug("Entered %s\n", __func__); |
49646dfa | 55 | |
87b132bc VK |
56 | samsung_asoc_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out, |
57 | &s3c2412_i2s_pcm_stereo_in); | |
58 | ||
f0fba2ad | 59 | ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS); |
dc85447b BD |
60 | if (ret) |
61 | return ret; | |
49646dfa | 62 | |
dc85447b BD |
63 | s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in; |
64 | s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out; | |
49646dfa | 65 | |
87b132bc | 66 | s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk"); |
7803e329 | 67 | if (IS_ERR(s3c2412_i2s.iis_cclk)) { |
008bec39 | 68 | pr_err("failed to get i2sclk clock\n"); |
7803e329 | 69 | return PTR_ERR(s3c2412_i2s.iis_cclk); |
49646dfa BD |
70 | } |
71 | ||
dc85447b | 72 | /* Set MPLL as the source for IIS CLK */ |
49646dfa | 73 | |
dc85447b | 74 | clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll")); |
77ea6bf7 | 75 | clk_prepare_enable(s3c2412_i2s.iis_cclk); |
49646dfa | 76 | |
dc85447b | 77 | s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk; |
49646dfa | 78 | |
601787c2 SN |
79 | /* 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); | |
49646dfa | 82 | |
6cab2d3d BD |
83 | return 0; |
84 | } | |
85 | ||
f0fba2ad LG |
86 | static int s3c2412_i2s_remove(struct snd_soc_dai *dai) |
87 | { | |
77ea6bf7 | 88 | clk_disable_unprepare(s3c2412_i2s.iis_cclk); |
f0fba2ad LG |
89 | |
90 | return 0; | |
91 | } | |
92 | ||
9c9b1257 JB |
93 | static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream, |
94 | struct snd_pcm_hw_params *params, | |
95 | struct snd_soc_dai *cpu_dai) | |
96 | { | |
f0fba2ad | 97 | struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai); |
9c9b1257 JB |
98 | u32 iismod; |
99 | ||
100 | pr_debug("Entered %s\n", __func__); | |
101 | ||
9c9b1257 JB |
102 | iismod = readl(i2s->regs + S3C2412_IISMOD); |
103 | pr_debug("%s: r: IISMOD: %x\n", __func__, iismod); | |
104 | ||
88ce1465 TB |
105 | switch (params_width(params)) { |
106 | case 8: | |
9c9b1257 JB |
107 | iismod |= S3C2412_IISMOD_8BIT; |
108 | break; | |
88ce1465 | 109 | case 16: |
9c9b1257 JB |
110 | iismod &= ~S3C2412_IISMOD_8BIT; |
111 | break; | |
112 | } | |
113 | ||
114 | writel(iismod, i2s->regs + S3C2412_IISMOD); | |
115 | pr_debug("%s: w: IISMOD: %x\n", __func__, iismod); | |
116 | ||
117 | return 0; | |
118 | } | |
119 | ||
49646dfa BD |
120 | #define S3C2412_I2S_RATES \ |
121 | (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \ | |
122 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ | |
123 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) | |
124 | ||
85e7652d | 125 | static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = { |
9c9b1257 | 126 | .hw_params = s3c2412_i2s_hw_params, |
6335d055 EM |
127 | }; |
128 | ||
f0fba2ad | 129 | static struct snd_soc_dai_driver s3c2412_i2s_dai = { |
dc85447b | 130 | .probe = s3c2412_i2s_probe, |
f0fba2ad | 131 | .remove = s3c2412_i2s_remove, |
49646dfa BD |
132 | .playback = { |
133 | .channels_min = 2, | |
134 | .channels_max = 2, | |
135 | .rates = S3C2412_I2S_RATES, | |
136 | .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE, | |
137 | }, | |
138 | .capture = { | |
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 | }, | |
6335d055 | 144 | .ops = &s3c2412_i2s_dai_ops, |
49646dfa | 145 | }; |
f0fba2ad | 146 | |
eca3b01d KM |
147 | static const struct snd_soc_component_driver s3c2412_i2s_component = { |
148 | .name = "s3c2412-i2s", | |
149 | }; | |
150 | ||
fdca21ad | 151 | static int s3c2412_iis_dev_probe(struct platform_device *pdev) |
f0fba2ad | 152 | { |
a08485d8 | 153 | int ret = 0; |
87b132bc VK |
154 | struct resource *res; |
155 | ||
156 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
87b132bc | 157 | s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res); |
71864b22 WY |
158 | if (IS_ERR(s3c2412_i2s.regs)) |
159 | return PTR_ERR(s3c2412_i2s.regs); | |
87b132bc VK |
160 | |
161 | s3c2412_i2s_pcm_stereo_out.dma_addr = res->start + S3C2412_IISTXD; | |
162 | s3c2412_i2s_pcm_stereo_in.dma_addr = res->start + S3C2412_IISRXD; | |
a08485d8 | 163 | |
eca3b01d KM |
164 | ret = s3c_i2sv2_register_component(&pdev->dev, -1, |
165 | &s3c2412_i2s_component, | |
166 | &s3c2412_i2s_dai); | |
a08485d8 PV |
167 | if (ret) { |
168 | pr_err("failed to register the dai\n"); | |
169 | return ret; | |
170 | } | |
171 | ||
06b10ff9 | 172 | ret = samsung_asoc_dma_platform_register(&pdev->dev); |
7253e354 | 173 | if (ret) |
a08485d8 | 174 | pr_err("failed to register the DMA: %d\n", ret); |
a08485d8 | 175 | |
a08485d8 | 176 | return ret; |
f0fba2ad LG |
177 | } |
178 | ||
f0fba2ad LG |
179 | static struct platform_driver s3c2412_iis_driver = { |
180 | .probe = s3c2412_iis_dev_probe, | |
f0fba2ad LG |
181 | .driver = { |
182 | .name = "s3c2412-iis", | |
f0fba2ad LG |
183 | }, |
184 | }; | |
49646dfa | 185 | |
e00c3f55 | 186 | module_platform_driver(s3c2412_iis_driver); |
3f4b783c | 187 | |
49646dfa BD |
188 | /* Module information */ |
189 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); | |
190 | MODULE_DESCRIPTION("S3C2412 I2S SoC Interface"); | |
191 | MODULE_LICENSE("GPL"); | |
960d0697 | 192 | MODULE_ALIAS("platform:s3c2412-iis"); |