aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/sh
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/sh')
-rw-r--r--sound/soc/sh/Kconfig15
-rw-r--r--sound/soc/sh/Makefile2
-rw-r--r--sound/soc/sh/dma-sh7760.c53
-rw-r--r--sound/soc/sh/fsi-ak4642.c171
-rw-r--r--sound/soc/sh/fsi-da7210.c35
-rw-r--r--sound/soc/sh/fsi-hdmi.c127
-rw-r--r--sound/soc/sh/fsi.c1187
-rw-r--r--sound/soc/sh/hac.c46
-rw-r--r--sound/soc/sh/migor.c37
-rw-r--r--sound/soc/sh/sh7760-ac97.c30
-rw-r--r--sound/soc/sh/siu.h8
-rw-r--r--sound/soc/sh/siu_dai.c99
-rw-r--r--sound/soc/sh/siu_pcm.c36
-rw-r--r--sound/soc/sh/ssi.c55
14 files changed, 1214 insertions, 687 deletions
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index 52d7e8ed9c1f..d8e06a607a22 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -47,21 +47,28 @@ config SND_SH7760_AC97
47 AC97 unit of the SH7760. 47 AC97 unit of the SH7760.
48 48
49config SND_FSI_AK4642 49config SND_FSI_AK4642
50 bool "FSI-AK4642 sound support" 50 tristate "FSI-AK4642 sound support"
51 depends on SND_SOC_SH4_FSI && I2C_SH_MOBILE 51 depends on SND_SOC_SH4_FSI && I2C
52 select SND_SOC_AK4642 52 select SND_SOC_AK4642
53 help 53 help
54 This option enables generic sound support for the 54 This option enables generic sound support for the
55 FSI - AK4642 unit 55 FSI - AK4642 unit
56 56
57config SND_FSI_DA7210 57config SND_FSI_DA7210
58 bool "FSI-DA7210 sound support" 58 tristate "FSI-DA7210 sound support"
59 depends on SND_SOC_SH4_FSI && I2C_SH_MOBILE 59 depends on SND_SOC_SH4_FSI && I2C
60 select SND_SOC_DA7210 60 select SND_SOC_DA7210
61 help 61 help
62 This option enables generic sound support for the 62 This option enables generic sound support for the
63 FSI - DA7210 unit 63 FSI - DA7210 unit
64 64
65config SND_FSI_HDMI
66 tristate "FSI-HDMI sound support"
67 depends on SND_SOC_SH4_FSI && FB_SH_MOBILE_HDMI
68 help
69 This option enables generic sound support for the
70 FSI - HDMI unit
71
65config SND_SIU_MIGOR 72config SND_SIU_MIGOR
66 tristate "SIU sound support on Migo-R" 73 tristate "SIU sound support on Migo-R"
67 depends on SH_MIGOR 74 depends on SH_MIGOR
diff --git a/sound/soc/sh/Makefile b/sound/soc/sh/Makefile
index 8a5a19293bda..94476d4c0fd5 100644
--- a/sound/soc/sh/Makefile
+++ b/sound/soc/sh/Makefile
@@ -16,9 +16,11 @@ obj-$(CONFIG_SND_SOC_SH4_SIU) += snd-soc-siu.o
16snd-soc-sh7760-ac97-objs := sh7760-ac97.o 16snd-soc-sh7760-ac97-objs := sh7760-ac97.o
17snd-soc-fsi-ak4642-objs := fsi-ak4642.o 17snd-soc-fsi-ak4642-objs := fsi-ak4642.o
18snd-soc-fsi-da7210-objs := fsi-da7210.o 18snd-soc-fsi-da7210-objs := fsi-da7210.o
19snd-soc-fsi-hdmi-objs := fsi-hdmi.o
19snd-soc-migor-objs := migor.o 20snd-soc-migor-objs := migor.o
20 21
21obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o 22obj-$(CONFIG_SND_SH7760_AC97) += snd-soc-sh7760-ac97.o
22obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o 23obj-$(CONFIG_SND_FSI_AK4642) += snd-soc-fsi-ak4642.o
23obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o 24obj-$(CONFIG_SND_FSI_DA7210) += snd-soc-fsi-da7210.o
25obj-$(CONFIG_SND_FSI_HDMI) += snd-soc-fsi-hdmi.o
24obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o 26obj-$(CONFIG_SND_SIU_MIGOR) += snd-soc-migor.o
diff --git a/sound/soc/sh/dma-sh7760.c b/sound/soc/sh/dma-sh7760.c
index 0d8bdf07729c..c326d29992fe 100644
--- a/sound/soc/sh/dma-sh7760.c
+++ b/sound/soc/sh/dma-sh7760.c
@@ -137,7 +137,7 @@ static void camelot_rxdma(void *data)
137static int camelot_pcm_open(struct snd_pcm_substream *substream) 137static int camelot_pcm_open(struct snd_pcm_substream *substream)
138{ 138{
139 struct snd_soc_pcm_runtime *rtd = substream->private_data; 139 struct snd_soc_pcm_runtime *rtd = substream->private_data;
140 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 140 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
141 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1; 141 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1;
142 int ret, dmairq; 142 int ret, dmairq;
143 143
@@ -150,7 +150,7 @@ static int camelot_pcm_open(struct snd_pcm_substream *substream)
150 ret = dmabrg_request_irq(dmairq, camelot_rxdma, cam); 150 ret = dmabrg_request_irq(dmairq, camelot_rxdma, cam);
151 if (unlikely(ret)) { 151 if (unlikely(ret)) {
152 pr_debug("audio unit %d irqs already taken!\n", 152 pr_debug("audio unit %d irqs already taken!\n",
153 rtd->dai->cpu_dai->id); 153 rtd->cpu_dai->id);
154 return -EBUSY; 154 return -EBUSY;
155 } 155 }
156 (void)dmabrg_request_irq(dmairq + 1,camelot_rxdma, cam); 156 (void)dmabrg_request_irq(dmairq + 1,camelot_rxdma, cam);
@@ -159,7 +159,7 @@ static int camelot_pcm_open(struct snd_pcm_substream *substream)
159 ret = dmabrg_request_irq(dmairq, camelot_txdma, cam); 159 ret = dmabrg_request_irq(dmairq, camelot_txdma, cam);
160 if (unlikely(ret)) { 160 if (unlikely(ret)) {
161 pr_debug("audio unit %d irqs already taken!\n", 161 pr_debug("audio unit %d irqs already taken!\n",
162 rtd->dai->cpu_dai->id); 162 rtd->cpu_dai->id);
163 return -EBUSY; 163 return -EBUSY;
164 } 164 }
165 (void)dmabrg_request_irq(dmairq + 1, camelot_txdma, cam); 165 (void)dmabrg_request_irq(dmairq + 1, camelot_txdma, cam);
@@ -170,7 +170,7 @@ static int camelot_pcm_open(struct snd_pcm_substream *substream)
170static int camelot_pcm_close(struct snd_pcm_substream *substream) 170static int camelot_pcm_close(struct snd_pcm_substream *substream)
171{ 171{
172 struct snd_soc_pcm_runtime *rtd = substream->private_data; 172 struct snd_soc_pcm_runtime *rtd = substream->private_data;
173 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 173 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
174 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1; 174 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1;
175 int dmairq; 175 int dmairq;
176 176
@@ -191,7 +191,7 @@ static int camelot_hw_params(struct snd_pcm_substream *substream,
191 struct snd_pcm_hw_params *hw_params) 191 struct snd_pcm_hw_params *hw_params)
192{ 192{
193 struct snd_soc_pcm_runtime *rtd = substream->private_data; 193 struct snd_soc_pcm_runtime *rtd = substream->private_data;
194 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 194 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
195 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1; 195 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1;
196 int ret; 196 int ret;
197 197
@@ -219,7 +219,7 @@ static int camelot_prepare(struct snd_pcm_substream *substream)
219{ 219{
220 struct snd_pcm_runtime *runtime = substream->runtime; 220 struct snd_pcm_runtime *runtime = substream->runtime;
221 struct snd_soc_pcm_runtime *rtd = substream->private_data; 221 struct snd_soc_pcm_runtime *rtd = substream->private_data;
222 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 222 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
223 223
224 pr_debug("PCM data: addr 0x%08ulx len %d\n", 224 pr_debug("PCM data: addr 0x%08ulx len %d\n",
225 (u32)runtime->dma_addr, runtime->dma_bytes); 225 (u32)runtime->dma_addr, runtime->dma_bytes);
@@ -266,7 +266,7 @@ static inline void dmabrg_rec_dma_stop(struct camelot_pcm *cam)
266static int camelot_trigger(struct snd_pcm_substream *substream, int cmd) 266static int camelot_trigger(struct snd_pcm_substream *substream, int cmd)
267{ 267{
268 struct snd_soc_pcm_runtime *rtd = substream->private_data; 268 struct snd_soc_pcm_runtime *rtd = substream->private_data;
269 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 269 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
270 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1; 270 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1;
271 271
272 switch (cmd) { 272 switch (cmd) {
@@ -293,7 +293,7 @@ static snd_pcm_uframes_t camelot_pos(struct snd_pcm_substream *substream)
293{ 293{
294 struct snd_pcm_runtime *runtime = substream->runtime; 294 struct snd_pcm_runtime *runtime = substream->runtime;
295 struct snd_soc_pcm_runtime *rtd = substream->private_data; 295 struct snd_soc_pcm_runtime *rtd = substream->private_data;
296 struct camelot_pcm *cam = &cam_pcm_data[rtd->dai->cpu_dai->id]; 296 struct camelot_pcm *cam = &cam_pcm_data[rtd->cpu_dai->id];
297 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1; 297 int recv = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0:1;
298 unsigned long pos; 298 unsigned long pos;
299 299
@@ -342,25 +342,44 @@ static int camelot_pcm_new(struct snd_card *card,
342 return 0; 342 return 0;
343} 343}
344 344
345struct snd_soc_platform sh7760_soc_platform = { 345static struct snd_soc_platform sh7760_soc_platform = {
346 .name = "sh7760-pcm",
347 .pcm_ops = &camelot_pcm_ops, 346 .pcm_ops = &camelot_pcm_ops,
348 .pcm_new = camelot_pcm_new, 347 .pcm_new = camelot_pcm_new,
349 .pcm_free = camelot_pcm_free, 348 .pcm_free = camelot_pcm_free,
350}; 349};
351EXPORT_SYMBOL_GPL(sh7760_soc_platform);
352 350
353static int __init sh7760_soc_platform_init(void) 351static int __devinit sh7760_soc_platform_probe(struct platform_device *pdev)
354{ 352{
355 return snd_soc_register_platform(&sh7760_soc_platform); 353 return snd_soc_register_platform(&pdev->dev, &sh7760_soc_platform);
356} 354}
357module_init(sh7760_soc_platform_init);
358 355
359static void __exit sh7760_soc_platform_exit(void) 356static int __devexit sh7760_soc_platform_remove(struct platform_device *pdev)
360{ 357{
361 snd_soc_unregister_platform(&sh7760_soc_platform); 358 snd_soc_unregister_platform(&pdev->dev);
359 return 0;
360}
361
362static struct platform_driver sh7760_pcm_driver = {
363 .driver = {
364 .name = "sh7760-pcm-audio",
365 .owner = THIS_MODULE,
366 },
367
368 .probe = sh7760_soc_platform_probe,
369 .remove = __devexit_p(sh7760_soc_platform_remove),
370};
371
372static int __init snd_sh7760_pcm_init(void)
373{
374 return platform_driver_register(&sh7760_pcm_driver);
375}
376module_init(snd_sh7760_pcm_init);
377
378static void __exit snd_sh7760_pcm_exit(void)
379{
380 platform_driver_unregister(&sh7760_pcm_driver);
362} 381}
363module_exit(sh7760_soc_platform_exit); 382module_exit(snd_sh7760_pcm_exit);
364 383
365MODULE_LICENSE("GPL"); 384MODULE_LICENSE("GPL");
366MODULE_DESCRIPTION("SH7760 Audio DMA (DMABRG) driver"); 385MODULE_DESCRIPTION("SH7760 Audio DMA (DMABRG) driver");
diff --git a/sound/soc/sh/fsi-ak4642.c b/sound/soc/sh/fsi-ak4642.c
index dad575a22622..770a71a15366 100644
--- a/sound/soc/sh/fsi-ak4642.c
+++ b/sound/soc/sh/fsi-ak4642.c
@@ -11,55 +11,75 @@
11 11
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <sound/sh_fsi.h> 13#include <sound/sh_fsi.h>
14#include <../sound/soc/codecs/ak4642.h>
15 14
16static int fsi_ak4642_dai_init(struct snd_soc_codec *codec) 15struct fsi_ak4642_data {
16 const char *name;
17 const char *card;
18 const char *cpu_dai;
19 const char *codec;
20 const char *platform;
21 int id;
22};
23
24static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
17{ 25{
26 struct snd_soc_dai *codec = rtd->codec_dai;
27 struct snd_soc_dai *cpu = rtd->cpu_dai;
18 int ret; 28 int ret;
19 29
20 ret = snd_soc_dai_set_fmt(&ak4642_dai, SND_SOC_DAIFMT_CBM_CFM); 30 ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J |
31 SND_SOC_DAIFMT_CBM_CFM);
32 if (ret < 0)
33 return ret;
34
35 ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0);
21 if (ret < 0) 36 if (ret < 0)
22 return ret; 37 return ret;
23 38
24 ret = snd_soc_dai_set_sysclk(&ak4642_dai, 0, 11289600, 0); 39 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J |
40 SND_SOC_DAIFMT_CBS_CFS);
25 41
26 return ret; 42 return ret;
27} 43}
28 44
29static struct snd_soc_dai_link fsi_dai_link = { 45static struct snd_soc_dai_link fsi_dai_link = {
30 .name = "AK4642", 46 .codec_dai_name = "ak4642-hifi",
31 .stream_name = "AK4642",
32 .cpu_dai = &fsi_soc_dai[FSI_PORT_A],
33 .codec_dai = &ak4642_dai,
34 .init = fsi_ak4642_dai_init, 47 .init = fsi_ak4642_dai_init,
35 .ops = NULL,
36}; 48};
37 49
38static struct snd_soc_card fsi_soc_card = { 50static struct snd_soc_card fsi_soc_card = {
39 .name = "FSI",
40 .platform = &fsi_soc_platform,
41 .dai_link = &fsi_dai_link, 51 .dai_link = &fsi_dai_link,
42 .num_links = 1, 52 .num_links = 1,
43}; 53};
44 54
45static struct snd_soc_device fsi_snd_devdata = {
46 .card = &fsi_soc_card,
47 .codec_dev = &soc_codec_dev_ak4642,
48};
49
50static struct platform_device *fsi_snd_device; 55static struct platform_device *fsi_snd_device;
51 56
52static int __init fsi_ak4642_init(void) 57static int fsi_ak4642_probe(struct platform_device *pdev)
53{ 58{
54 int ret = -ENOMEM; 59 int ret = -ENOMEM;
60 const struct platform_device_id *id_entry;
61 struct fsi_ak4642_data *pdata;
55 62
56 fsi_snd_device = platform_device_alloc("soc-audio", FSI_PORT_A); 63 id_entry = pdev->id_entry;
64 if (!id_entry) {
65 dev_err(&pdev->dev, "unknown fsi ak4642\n");
66 return -ENODEV;
67 }
68
69 pdata = (struct fsi_ak4642_data *)id_entry->driver_data;
70
71 fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
57 if (!fsi_snd_device) 72 if (!fsi_snd_device)
58 goto out; 73 goto out;
59 74
60 platform_set_drvdata(fsi_snd_device, 75 fsi_dai_link.name = pdata->name;
61 &fsi_snd_devdata); 76 fsi_dai_link.stream_name = pdata->name;
62 fsi_snd_devdata.dev = &fsi_snd_device->dev; 77 fsi_dai_link.cpu_dai_name = pdata->cpu_dai;
78 fsi_dai_link.platform_name = pdata->platform;
79 fsi_dai_link.codec_name = pdata->codec;
80 fsi_soc_card.name = pdata->card;
81
82 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
63 ret = platform_device_add(fsi_snd_device); 83 ret = platform_device_add(fsi_snd_device);
64 84
65 if (ret) 85 if (ret)
@@ -69,9 +89,116 @@ out:
69 return ret; 89 return ret;
70} 90}
71 91
72static void __exit fsi_ak4642_exit(void) 92static int fsi_ak4642_remove(struct platform_device *pdev)
73{ 93{
74 platform_device_unregister(fsi_snd_device); 94 platform_device_unregister(fsi_snd_device);
95 return 0;
96}
97
98static struct fsi_ak4642_data fsi_a_ak4642 = {
99 .name = "AK4642",
100 .card = "FSIA-AK4642",
101 .cpu_dai = "fsia-dai",
102 .codec = "ak4642-codec.0-0012",
103 .platform = "sh_fsi.0",
104 .id = FSI_PORT_A,
105};
106
107static struct fsi_ak4642_data fsi_b_ak4642 = {
108 .name = "AK4642",
109 .card = "FSIB-AK4642",
110 .cpu_dai = "fsib-dai",
111 .codec = "ak4642-codec.0-0012",
112 .platform = "sh_fsi.0",
113 .id = FSI_PORT_B,
114};
115
116static struct fsi_ak4642_data fsi_a_ak4643 = {
117 .name = "AK4643",
118 .card = "FSIA-AK4643",
119 .cpu_dai = "fsia-dai",
120 .codec = "ak4642-codec.0-0013",
121 .platform = "sh_fsi.0",
122 .id = FSI_PORT_A,
123};
124
125static struct fsi_ak4642_data fsi_b_ak4643 = {
126 .name = "AK4643",
127 .card = "FSIB-AK4643",
128 .cpu_dai = "fsib-dai",
129 .codec = "ak4642-codec.0-0013",
130 .platform = "sh_fsi.0",
131 .id = FSI_PORT_B,
132};
133
134static struct fsi_ak4642_data fsi2_a_ak4642 = {
135 .name = "AK4642",
136 .card = "FSI2A-AK4642",
137 .cpu_dai = "fsia-dai",
138 .codec = "ak4642-codec.0-0012",
139 .platform = "sh_fsi2",
140 .id = FSI_PORT_A,
141};
142
143static struct fsi_ak4642_data fsi2_b_ak4642 = {
144 .name = "AK4642",
145 .card = "FSI2B-AK4642",
146 .cpu_dai = "fsib-dai",
147 .codec = "ak4642-codec.0-0012",
148 .platform = "sh_fsi2",
149 .id = FSI_PORT_B,
150};
151
152static struct fsi_ak4642_data fsi2_a_ak4643 = {
153 .name = "AK4643",
154 .card = "FSI2A-AK4643",
155 .cpu_dai = "fsia-dai",
156 .codec = "ak4642-codec.0-0013",
157 .platform = "sh_fsi2",
158 .id = FSI_PORT_A,
159};
160
161static struct fsi_ak4642_data fsi2_b_ak4643 = {
162 .name = "AK4643",
163 .card = "FSI2B-AK4643",
164 .cpu_dai = "fsib-dai",
165 .codec = "ak4642-codec.0-0013",
166 .platform = "sh_fsi2",
167 .id = FSI_PORT_B,
168};
169
170static struct platform_device_id fsi_id_table[] = {
171 /* FSI */
172 { "sh_fsi_a_ak4642", (kernel_ulong_t)&fsi_a_ak4642 },
173 { "sh_fsi_b_ak4642", (kernel_ulong_t)&fsi_b_ak4642 },
174 { "sh_fsi_a_ak4643", (kernel_ulong_t)&fsi_a_ak4643 },
175 { "sh_fsi_b_ak4643", (kernel_ulong_t)&fsi_b_ak4643 },
176
177 /* FSI 2 */
178 { "sh_fsi2_a_ak4642", (kernel_ulong_t)&fsi2_a_ak4642 },
179 { "sh_fsi2_b_ak4642", (kernel_ulong_t)&fsi2_b_ak4642 },
180 { "sh_fsi2_a_ak4643", (kernel_ulong_t)&fsi2_a_ak4643 },
181 { "sh_fsi2_b_ak4643", (kernel_ulong_t)&fsi2_b_ak4643 },
182 {},
183};
184
185static struct platform_driver fsi_ak4642 = {
186 .driver = {
187 .name = "fsi-ak4642-audio",
188 },
189 .probe = fsi_ak4642_probe,
190 .remove = fsi_ak4642_remove,
191 .id_table = fsi_id_table,
192};
193
194static int __init fsi_ak4642_init(void)
195{
196 return platform_driver_register(&fsi_ak4642);
197}
198
199static void __exit fsi_ak4642_exit(void)
200{
201 platform_driver_unregister(&fsi_ak4642);
75} 202}
76 203
77module_init(fsi_ak4642_init); 204module_init(fsi_ak4642_init);
diff --git a/sound/soc/sh/fsi-da7210.c b/sound/soc/sh/fsi-da7210.c
index 121bbb07bb03..59553fd8c2fb 100644
--- a/sound/soc/sh/fsi-da7210.c
+++ b/sound/soc/sh/fsi-da7210.c
@@ -12,35 +12,41 @@
12 12
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <sound/sh_fsi.h> 14#include <sound/sh_fsi.h>
15#include "../codecs/da7210.h"
16 15
17static int fsi_da7210_init(struct snd_soc_codec *codec) 16static int fsi_da7210_init(struct snd_soc_pcm_runtime *rtd)
18{ 17{
19 return snd_soc_dai_set_fmt(&da7210_dai, 18 struct snd_soc_dai *codec = rtd->codec_dai;
20 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | 19 struct snd_soc_dai *cpu = rtd->cpu_dai;
20 int ret;
21
22 ret = snd_soc_dai_set_fmt(codec,
23 SND_SOC_DAIFMT_I2S |
21 SND_SOC_DAIFMT_CBM_CFM); 24 SND_SOC_DAIFMT_CBM_CFM);
25 if (ret < 0)
26 return ret;
27
28 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_I2S |
29 SND_SOC_DAIFMT_CBS_CFS);
30
31 return ret;
22} 32}
23 33
24static struct snd_soc_dai_link fsi_da7210_dai = { 34static struct snd_soc_dai_link fsi_da7210_dai = {
25 .name = "DA7210", 35 .name = "DA7210",
26 .stream_name = "DA7210", 36 .stream_name = "DA7210",
27 .cpu_dai = &fsi_soc_dai[FSI_PORT_B], 37 .cpu_dai_name = "fsib-dai", /* FSI B */
28 .codec_dai = &da7210_dai, 38 .codec_dai_name = "da7210-hifi",
39 .platform_name = "sh_fsi.0",
40 .codec_name = "da7210-codec.0-001a",
29 .init = fsi_da7210_init, 41 .init = fsi_da7210_init,
30}; 42};
31 43
32static struct snd_soc_card fsi_soc_card = { 44static struct snd_soc_card fsi_soc_card = {
33 .name = "FSI", 45 .name = "FSI-DA7210",
34 .platform = &fsi_soc_platform,
35 .dai_link = &fsi_da7210_dai, 46 .dai_link = &fsi_da7210_dai,
36 .num_links = 1, 47 .num_links = 1,
37}; 48};
38 49
39static struct snd_soc_device fsi_da7210_snd_devdata = {
40 .card = &fsi_soc_card,
41 .codec_dev = &soc_codec_dev_da7210,
42};
43
44static struct platform_device *fsi_da7210_snd_device; 50static struct platform_device *fsi_da7210_snd_device;
45 51
46static int __init fsi_da7210_sound_init(void) 52static int __init fsi_da7210_sound_init(void)
@@ -51,8 +57,7 @@ static int __init fsi_da7210_sound_init(void)
51 if (!fsi_da7210_snd_device) 57 if (!fsi_da7210_snd_device)
52 return -ENOMEM; 58 return -ENOMEM;
53 59
54 platform_set_drvdata(fsi_da7210_snd_device, &fsi_da7210_snd_devdata); 60 platform_set_drvdata(fsi_da7210_snd_device, &fsi_soc_card);
55 fsi_da7210_snd_devdata.dev = &fsi_da7210_snd_device->dev;
56 ret = platform_device_add(fsi_da7210_snd_device); 61 ret = platform_device_add(fsi_da7210_snd_device);
57 if (ret) 62 if (ret)
58 platform_device_put(fsi_da7210_snd_device); 63 platform_device_put(fsi_da7210_snd_device);
diff --git a/sound/soc/sh/fsi-hdmi.c b/sound/soc/sh/fsi-hdmi.c
new file mode 100644
index 000000000000..d3d9fd880680
--- /dev/null
+++ b/sound/soc/sh/fsi-hdmi.c
@@ -0,0 +1,127 @@
1/*
2 * FSI - HDMI sound support
3 *
4 * Copyright (C) 2010 Renesas Solutions Corp.
5 * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
12#include <linux/platform_device.h>
13#include <sound/sh_fsi.h>
14
15struct fsi_hdmi_data {
16 const char *cpu_dai;
17 const char *card;
18 int id;
19};
20
21static int fsi_hdmi_dai_init(struct snd_soc_pcm_runtime *rtd)
22{
23 struct snd_soc_dai *cpu = rtd->cpu_dai;
24 int ret;
25
26 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_CBM_CFM);
27
28 return ret;
29}
30
31static struct snd_soc_dai_link fsi_dai_link = {
32 .name = "HDMI",
33 .stream_name = "HDMI",
34 .codec_dai_name = "sh_mobile_hdmi-hifi",
35 .platform_name = "sh_fsi2",
36 .codec_name = "sh-mobile-hdmi",
37 .init = fsi_hdmi_dai_init,
38};
39
40static struct snd_soc_card fsi_soc_card = {
41 .dai_link = &fsi_dai_link,
42 .num_links = 1,
43};
44
45static struct platform_device *fsi_snd_device;
46
47static int fsi_hdmi_probe(struct platform_device *pdev)
48{
49 int ret = -ENOMEM;
50 const struct platform_device_id *id_entry;
51 struct fsi_hdmi_data *pdata;
52
53 id_entry = pdev->id_entry;
54 if (!id_entry) {
55 dev_err(&pdev->dev, "unknown fsi hdmi\n");
56 return -ENODEV;
57 }
58
59 pdata = (struct fsi_hdmi_data *)id_entry->driver_data;
60
61 fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
62 if (!fsi_snd_device)
63 goto out;
64
65 fsi_dai_link.cpu_dai_name = pdata->cpu_dai;
66 fsi_soc_card.name = pdata->card;
67
68 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
69 ret = platform_device_add(fsi_snd_device);
70
71 if (ret)
72 platform_device_put(fsi_snd_device);
73
74out:
75 return ret;
76}
77
78static int fsi_hdmi_remove(struct platform_device *pdev)
79{
80 platform_device_unregister(fsi_snd_device);
81 return 0;
82}
83
84static struct fsi_hdmi_data fsi2_a_hdmi = {
85 .cpu_dai = "fsia-dai",
86 .card = "FSI2A-HDMI",
87 .id = FSI_PORT_A,
88};
89
90static struct fsi_hdmi_data fsi2_b_hdmi = {
91 .cpu_dai = "fsib-dai",
92 .card = "FSI2B-HDMI",
93 .id = FSI_PORT_B,
94};
95
96static struct platform_device_id fsi_id_table[] = {
97 /* FSI 2 */
98 { "sh_fsi2_a_hdmi", (kernel_ulong_t)&fsi2_a_hdmi },
99 { "sh_fsi2_b_hdmi", (kernel_ulong_t)&fsi2_b_hdmi },
100 {},
101};
102
103static struct platform_driver fsi_hdmi = {
104 .driver = {
105 .name = "fsi-hdmi-audio",
106 },
107 .probe = fsi_hdmi_probe,
108 .remove = fsi_hdmi_remove,
109 .id_table = fsi_id_table,
110};
111
112static int __init fsi_hdmi_init(void)
113{
114 return platform_driver_register(&fsi_hdmi);
115}
116
117static void __exit fsi_hdmi_exit(void)
118{
119 platform_driver_unregister(&fsi_hdmi);
120}
121
122module_init(fsi_hdmi_init);
123module_exit(fsi_hdmi_exit);
124
125MODULE_LICENSE("GPL");
126MODULE_DESCRIPTION("Generic SH4 FSI-HDMI sound card");
127MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 58c6bec642de..4a9da6b5f4e1 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -19,20 +19,26 @@
19#include <sound/soc.h> 19#include <sound/soc.h>
20#include <sound/sh_fsi.h> 20#include <sound/sh_fsi.h>
21 21
22#define DO_FMT 0x0000 22/* PortA/PortB register */
23#define DOFF_CTL 0x0004 23#define REG_DO_FMT 0x0000
24#define DOFF_ST 0x0008 24#define REG_DOFF_CTL 0x0004
25#define DI_FMT 0x000C 25#define REG_DOFF_ST 0x0008
26#define DIFF_CTL 0x0010 26#define REG_DI_FMT 0x000C
27#define DIFF_ST 0x0014 27#define REG_DIFF_CTL 0x0010
28#define CKG1 0x0018 28#define REG_DIFF_ST 0x0014
29#define CKG2 0x001C 29#define REG_CKG1 0x0018
30#define DIDT 0x0020 30#define REG_CKG2 0x001C
31#define DODT 0x0024 31#define REG_DIDT 0x0020
32#define MUTE_ST 0x0028 32#define REG_DODT 0x0024
33#define OUT_SEL 0x0030 33#define REG_MUTE_ST 0x0028
34#define REG_END OUT_SEL 34#define REG_OUT_SEL 0x0030
35 35
36/* master register */
37#define MST_CLK_RST 0x0210
38#define MST_SOFT_RST 0x0214
39#define MST_FIFO_SZ 0x0218
40
41/* core register (depend on FSI version) */
36#define A_MST_CTLR 0x0180 42#define A_MST_CTLR 0x0180
37#define B_MST_CTLR 0x01A0 43#define B_MST_CTLR 0x01A0
38#define CPU_INT_ST 0x01F4 44#define CPU_INT_ST 0x01F4
@@ -41,22 +47,23 @@
41#define INT_ST 0x0200 47#define INT_ST 0x0200
42#define IEMSK 0x0204 48#define IEMSK 0x0204
43#define IMSK 0x0208 49#define IMSK 0x0208
44#define MUTE 0x020C
45#define CLK_RST 0x0210
46#define SOFT_RST 0x0214
47#define FIFO_SZ 0x0218
48#define MREG_START A_MST_CTLR
49#define MREG_END FIFO_SZ
50 50
51/* DO_FMT */ 51/* DO_FMT */
52/* DI_FMT */ 52/* DI_FMT */
53#define CR_BWS_24 (0x0 << 20) /* FSI2 */
54#define CR_BWS_16 (0x1 << 20) /* FSI2 */
55#define CR_BWS_20 (0x2 << 20) /* FSI2 */
56
57#define CR_DTMD_PCM (0x0 << 8) /* FSI2 */
58#define CR_DTMD_SPDIF_PCM (0x1 << 8) /* FSI2 */
59#define CR_DTMD_SPDIF_STREAM (0x2 << 8) /* FSI2 */
60
53#define CR_MONO (0x0 << 4) 61#define CR_MONO (0x0 << 4)
54#define CR_MONO_D (0x1 << 4) 62#define CR_MONO_D (0x1 << 4)
55#define CR_PCM (0x2 << 4) 63#define CR_PCM (0x2 << 4)
56#define CR_I2S (0x3 << 4) 64#define CR_I2S (0x3 << 4)
57#define CR_TDM (0x4 << 4) 65#define CR_TDM (0x4 << 4)
58#define CR_TDM_D (0x5 << 4) 66#define CR_TDM_D (0x5 << 4)
59#define CR_SPDIF 0x00100120
60 67
61/* DOFF_CTL */ 68/* DOFF_CTL */
62/* DIFF_CTL */ 69/* DIFF_CTL */
@@ -71,20 +78,23 @@
71/* CKG1 */ 78/* CKG1 */
72#define ACKMD_MASK 0x00007000 79#define ACKMD_MASK 0x00007000
73#define BPFMD_MASK 0x00000700 80#define BPFMD_MASK 0x00000700
81#define DIMD (1 << 4)
82#define DOMD (1 << 0)
74 83
75/* A/B MST_CTLR */ 84/* A/B MST_CTLR */
76#define BP (1 << 4) /* Fix the signal of Biphase output */ 85#define BP (1 << 4) /* Fix the signal of Biphase output */
77#define SE (1 << 0) /* Fix the master clock */ 86#define SE (1 << 0) /* Fix the master clock */
78 87
79/* CLK_RST */ 88/* CLK_RST */
80#define B_CLK 0x00000010 89#define CRB (1 << 4)
81#define A_CLK 0x00000001 90#define CRA (1 << 0)
82 91
83/* INT_ST */ 92/* IO SHIFT / MACRO */
84#define INT_B_IN (1 << 12) 93#define BI_SHIFT 12
85#define INT_B_OUT (1 << 8) 94#define BO_SHIFT 8
86#define INT_A_IN (1 << 4) 95#define AI_SHIFT 4
87#define INT_A_OUT (1 << 0) 96#define AO_SHIFT 0
97#define AB_IO(param, shift) (param << shift)
88 98
89/* SOFT_RST */ 99/* SOFT_RST */
90#define PBSR (1 << 12) /* Port B Software Reset */ 100#define PBSR (1 << 12) /* Port B Software Reset */
@@ -92,36 +102,64 @@
92#define IR (1 << 4) /* Interrupt Reset */ 102#define IR (1 << 4) /* Interrupt Reset */
93#define FSISR (1 << 0) /* Software Reset */ 103#define FSISR (1 << 0) /* Software Reset */
94 104
105/* OUT_SEL (FSI2) */
106#define DMMD (1 << 4) /* SPDIF output timing 0: Biphase only */
107 /* 1: Biphase and serial */
108
95/* FIFO_SZ */ 109/* FIFO_SZ */
96#define OUT_SZ_MASK 0x7 110#define FIFO_SZ_MASK 0x7
97#define BO_SZ_SHIFT 8
98#define AO_SZ_SHIFT 0
99 111
100#define FSI_RATES SNDRV_PCM_RATE_8000_96000 112#define FSI_RATES SNDRV_PCM_RATE_8000_96000
101 113
102#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE) 114#define FSI_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
103 115
104/************************************************************************ 116typedef int (*set_rate_func)(struct device *dev, int is_porta, int rate, int enable);
117
118/*
119 * FSI driver use below type name for variable
120 *
121 * xxx_len : data length
122 * xxx_width : data width
123 * xxx_offset : data offset
124 * xxx_num : number of data
125 */
126
127/*
128 * struct
129 */
130
131struct fsi_stream {
132 struct snd_pcm_substream *substream;
105 133
134 int fifo_max_num;
106 135
107 struct 136 int buff_offset;
137 int buff_len;
138 int period_len;
139 int period_num;
108 140
141 int uerr_num;
142 int oerr_num;
143};
109 144
110************************************************************************/
111struct fsi_priv { 145struct fsi_priv {
112 void __iomem *base; 146 void __iomem *base;
113 struct snd_pcm_substream *substream;
114 struct fsi_master *master; 147 struct fsi_master *master;
115 148
116 int fifo_max; 149 struct fsi_stream playback;
117 int chan; 150 struct fsi_stream capture;
118 151
119 int byte_offset; 152 int chan_num:16;
120 int period_len; 153 int clk_master:1;
121 int buffer_len; 154
122 int periods; 155 long rate;
123 156
124 u32 mst_ctrl; 157 /* for suspend/resume */
158 u32 saved_do_fmt;
159 u32 saved_di_fmt;
160 u32 saved_ckg1;
161 u32 saved_ckg2;
162 u32 saved_out_sel;
125}; 163};
126 164
127struct fsi_core { 165struct fsi_core {
@@ -130,6 +168,8 @@ struct fsi_core {
130 u32 int_st; 168 u32 int_st;
131 u32 iemsk; 169 u32 iemsk;
132 u32 imsk; 170 u32 imsk;
171 u32 a_mclk;
172 u32 b_mclk;
133}; 173};
134 174
135struct fsi_master { 175struct fsi_master {
@@ -140,15 +180,20 @@ struct fsi_master {
140 struct fsi_core *core; 180 struct fsi_core *core;
141 struct sh_fsi_platform_info *info; 181 struct sh_fsi_platform_info *info;
142 spinlock_t lock; 182 spinlock_t lock;
143};
144
145/************************************************************************
146
147 183
148 basic read write function 184 /* for suspend/resume */
185 u32 saved_a_mclk;
186 u32 saved_b_mclk;
187 u32 saved_iemsk;
188 u32 saved_imsk;
189 u32 saved_clk_rst;
190 u32 saved_soft_rst;
191};
149 192
193/*
194 * basic read write function
195 */
150 196
151************************************************************************/
152static void __fsi_reg_write(u32 reg, u32 data) 197static void __fsi_reg_write(u32 reg, u32 data)
153{ 198{
154 /* valid data area is 24bit */ 199 /* valid data area is 24bit */
@@ -172,62 +217,22 @@ static void __fsi_reg_mask_set(u32 reg, u32 mask, u32 data)
172 __fsi_reg_write(reg, val); 217 __fsi_reg_write(reg, val);
173} 218}
174 219
175static void fsi_reg_write(struct fsi_priv *fsi, u32 reg, u32 data) 220#define fsi_reg_write(p, r, d)\
176{ 221 __fsi_reg_write((u32)(p->base + REG_##r), d)
177 if (reg > REG_END) {
178 pr_err("fsi: register access err (%s)\n", __func__);
179 return;
180 }
181
182 __fsi_reg_write((u32)(fsi->base + reg), data);
183}
184
185static u32 fsi_reg_read(struct fsi_priv *fsi, u32 reg)
186{
187 if (reg > REG_END) {
188 pr_err("fsi: register access err (%s)\n", __func__);
189 return 0;
190 }
191
192 return __fsi_reg_read((u32)(fsi->base + reg));
193}
194
195static void fsi_reg_mask_set(struct fsi_priv *fsi, u32 reg, u32 mask, u32 data)
196{
197 if (reg > REG_END) {
198 pr_err("fsi: register access err (%s)\n", __func__);
199 return;
200 }
201
202 __fsi_reg_mask_set((u32)(fsi->base + reg), mask, data);
203}
204
205static void fsi_master_write(struct fsi_master *master, u32 reg, u32 data)
206{
207 unsigned long flags;
208 222
209 if ((reg < MREG_START) || 223#define fsi_reg_read(p, r)\
210 (reg > MREG_END)) { 224 __fsi_reg_read((u32)(p->base + REG_##r))
211 pr_err("fsi: register access err (%s)\n", __func__);
212 return;
213 }
214 225
215 spin_lock_irqsave(&master->lock, flags); 226#define fsi_reg_mask_set(p, r, m, d)\
216 __fsi_reg_write((u32)(master->base + reg), data); 227 __fsi_reg_mask_set((u32)(p->base + REG_##r), m, d)
217 spin_unlock_irqrestore(&master->lock, flags);
218}
219 228
220static u32 fsi_master_read(struct fsi_master *master, u32 reg) 229#define fsi_master_read(p, r) _fsi_master_read(p, MST_##r)
230#define fsi_core_read(p, r) _fsi_master_read(p, p->core->r)
231static u32 _fsi_master_read(struct fsi_master *master, u32 reg)
221{ 232{
222 u32 ret; 233 u32 ret;
223 unsigned long flags; 234 unsigned long flags;
224 235
225 if ((reg < MREG_START) ||
226 (reg > MREG_END)) {
227 pr_err("fsi: register access err (%s)\n", __func__);
228 return 0;
229 }
230
231 spin_lock_irqsave(&master->lock, flags); 236 spin_lock_irqsave(&master->lock, flags);
232 ret = __fsi_reg_read((u32)(master->base + reg)); 237 ret = __fsi_reg_read((u32)(master->base + reg));
233 spin_unlock_irqrestore(&master->lock, flags); 238 spin_unlock_irqrestore(&master->lock, flags);
@@ -235,34 +240,32 @@ static u32 fsi_master_read(struct fsi_master *master, u32 reg)
235 return ret; 240 return ret;
236} 241}
237 242
238static void fsi_master_mask_set(struct fsi_master *master, 243#define fsi_master_mask_set(p, r, m, d) _fsi_master_mask_set(p, MST_##r, m, d)
244#define fsi_core_mask_set(p, r, m, d) _fsi_master_mask_set(p, p->core->r, m, d)
245static void _fsi_master_mask_set(struct fsi_master *master,
239 u32 reg, u32 mask, u32 data) 246 u32 reg, u32 mask, u32 data)
240{ 247{
241 unsigned long flags; 248 unsigned long flags;
242 249
243 if ((reg < MREG_START) ||
244 (reg > MREG_END)) {
245 pr_err("fsi: register access err (%s)\n", __func__);
246 return;
247 }
248
249 spin_lock_irqsave(&master->lock, flags); 250 spin_lock_irqsave(&master->lock, flags);
250 __fsi_reg_mask_set((u32)(master->base + reg), mask, data); 251 __fsi_reg_mask_set((u32)(master->base + reg), mask, data);
251 spin_unlock_irqrestore(&master->lock, flags); 252 spin_unlock_irqrestore(&master->lock, flags);
252} 253}
253 254
254/************************************************************************ 255/*
255 256 * basic function
256 257 */
257 basic function
258
259 258
260************************************************************************/
261static struct fsi_master *fsi_get_master(struct fsi_priv *fsi) 259static struct fsi_master *fsi_get_master(struct fsi_priv *fsi)
262{ 260{
263 return fsi->master; 261 return fsi->master;
264} 262}
265 263
264static int fsi_is_clk_master(struct fsi_priv *fsi)
265{
266 return fsi->clk_master;
267}
268
266static int fsi_is_port_a(struct fsi_priv *fsi) 269static int fsi_is_port_a(struct fsi_priv *fsi)
267{ 270{
268 return fsi->master->base == fsi->base; 271 return fsi->master->base == fsi->base;
@@ -271,16 +274,31 @@ static int fsi_is_port_a(struct fsi_priv *fsi)
271static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream) 274static struct snd_soc_dai *fsi_get_dai(struct snd_pcm_substream *substream)
272{ 275{
273 struct snd_soc_pcm_runtime *rtd = substream->private_data; 276 struct snd_soc_pcm_runtime *rtd = substream->private_data;
274 struct snd_soc_dai_link *machine = rtd->dai;
275 277
276 return machine->cpu_dai; 278 return rtd->cpu_dai;
279}
280
281static struct fsi_priv *fsi_get_priv_frm_dai(struct snd_soc_dai *dai)
282{
283 struct fsi_master *master = snd_soc_dai_get_drvdata(dai);
284
285 if (dai->id == 0)
286 return &master->fsia;
287 else
288 return &master->fsib;
277} 289}
278 290
279static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream) 291static struct fsi_priv *fsi_get_priv(struct snd_pcm_substream *substream)
280{ 292{
281 struct snd_soc_dai *dai = fsi_get_dai(substream); 293 return fsi_get_priv_frm_dai(fsi_get_dai(substream));
294}
295
296static set_rate_func fsi_get_info_set_rate(struct fsi_master *master)
297{
298 if (!master->info)
299 return NULL;
282 300
283 return dai->private_data; 301 return master->info->set_rate;
284} 302}
285 303
286static u32 fsi_get_info_flags(struct fsi_priv *fsi) 304static u32 fsi_get_info_flags(struct fsi_priv *fsi)
@@ -288,105 +306,219 @@ static u32 fsi_get_info_flags(struct fsi_priv *fsi)
288 int is_porta = fsi_is_port_a(fsi); 306 int is_porta = fsi_is_port_a(fsi);
289 struct fsi_master *master = fsi_get_master(fsi); 307 struct fsi_master *master = fsi_get_master(fsi);
290 308
309 if (!master->info)
310 return 0;
311
291 return is_porta ? master->info->porta_flags : 312 return is_porta ? master->info->porta_flags :
292 master->info->portb_flags; 313 master->info->portb_flags;
293} 314}
294 315
295static int fsi_is_master_mode(struct fsi_priv *fsi, int is_play) 316static inline int fsi_stream_is_play(int stream)
296{ 317{
297 u32 mode; 318 return stream == SNDRV_PCM_STREAM_PLAYBACK;
298 u32 flags = fsi_get_info_flags(fsi); 319}
299
300 mode = is_play ? SH_FSI_OUT_SLAVE_MODE : SH_FSI_IN_SLAVE_MODE;
301 320
302 /* return 321static inline int fsi_is_play(struct snd_pcm_substream *substream)
303 * 1 : master mode 322{
304 * 0 : slave mode 323 return fsi_stream_is_play(substream->stream);
305 */ 324}
306 325
307 return (mode & flags) != mode; 326static inline struct fsi_stream *fsi_get_stream(struct fsi_priv *fsi,
327 int is_play)
328{
329 return is_play ? &fsi->playback : &fsi->capture;
308} 330}
309 331
310static u32 fsi_port_ab_io_bit(struct fsi_priv *fsi, int is_play) 332static u32 fsi_get_port_shift(struct fsi_priv *fsi, int is_play)
311{ 333{
312 int is_porta = fsi_is_port_a(fsi); 334 int is_porta = fsi_is_port_a(fsi);
313 u32 data; 335 u32 shift;
314 336
315 if (is_porta) 337 if (is_porta)
316 data = is_play ? (1 << 0) : (1 << 4); 338 shift = is_play ? AO_SHIFT : AI_SHIFT;
317 else 339 else
318 data = is_play ? (1 << 8) : (1 << 12); 340 shift = is_play ? BO_SHIFT : BI_SHIFT;
319 341
320 return data; 342 return shift;
321} 343}
322 344
323static void fsi_stream_push(struct fsi_priv *fsi, 345static void fsi_stream_push(struct fsi_priv *fsi,
346 int is_play,
324 struct snd_pcm_substream *substream, 347 struct snd_pcm_substream *substream,
325 u32 buffer_len, 348 u32 buffer_len,
326 u32 period_len) 349 u32 period_len)
327{ 350{
328 fsi->substream = substream; 351 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
329 fsi->buffer_len = buffer_len; 352
330 fsi->period_len = period_len; 353 io->substream = substream;
331 fsi->byte_offset = 0; 354 io->buff_len = buffer_len;
332 fsi->periods = 0; 355 io->buff_offset = 0;
356 io->period_len = period_len;
357 io->period_num = 0;
358 io->oerr_num = -1; /* ignore 1st err */
359 io->uerr_num = -1; /* ignore 1st err */
333} 360}
334 361
335static void fsi_stream_pop(struct fsi_priv *fsi) 362static void fsi_stream_pop(struct fsi_priv *fsi, int is_play)
336{ 363{
337 fsi->substream = NULL; 364 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
338 fsi->buffer_len = 0; 365 struct snd_soc_dai *dai = fsi_get_dai(io->substream);
339 fsi->period_len = 0; 366
340 fsi->byte_offset = 0; 367
341 fsi->periods = 0; 368 if (io->oerr_num > 0)
369 dev_err(dai->dev, "over_run = %d\n", io->oerr_num);
370
371 if (io->uerr_num > 0)
372 dev_err(dai->dev, "under_run = %d\n", io->uerr_num);
373
374 io->substream = NULL;
375 io->buff_len = 0;
376 io->buff_offset = 0;
377 io->period_len = 0;
378 io->period_num = 0;
379 io->oerr_num = 0;
380 io->uerr_num = 0;
342} 381}
343 382
344static int fsi_get_fifo_residue(struct fsi_priv *fsi, int is_play) 383static int fsi_get_fifo_data_num(struct fsi_priv *fsi, int is_play)
345{ 384{
346 u32 status; 385 u32 status;
347 u32 reg = is_play ? DOFF_ST : DIFF_ST; 386 int data_num;
348 int residue; 387
388 status = is_play ?
389 fsi_reg_read(fsi, DOFF_ST) :
390 fsi_reg_read(fsi, DIFF_ST);
349 391
350 status = fsi_reg_read(fsi, reg); 392 data_num = 0x1ff & (status >> 8);
351 residue = 0x1ff & (status >> 8); 393 data_num *= fsi->chan_num;
352 residue *= fsi->chan;
353 394
354 return residue; 395 return data_num;
355} 396}
356 397
357/************************************************************************ 398static int fsi_len2num(int len, int width)
399{
400 return len / width;
401}
358 402
403#define fsi_num2offset(a, b) fsi_num2len(a, b)
404static int fsi_num2len(int num, int width)
405{
406 return num * width;
407}
408
409static int fsi_get_frame_width(struct fsi_priv *fsi, int is_play)
410{
411 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
412 struct snd_pcm_substream *substream = io->substream;
413 struct snd_pcm_runtime *runtime = substream->runtime;
414
415 return frames_to_bytes(runtime, 1) / fsi->chan_num;
416}
417
418static void fsi_count_fifo_err(struct fsi_priv *fsi)
419{
420 u32 ostatus = fsi_reg_read(fsi, DOFF_ST);
421 u32 istatus = fsi_reg_read(fsi, DIFF_ST);
422
423 if (ostatus & ERR_OVER)
424 fsi->playback.oerr_num++;
425
426 if (ostatus & ERR_UNDER)
427 fsi->playback.uerr_num++;
428
429 if (istatus & ERR_OVER)
430 fsi->capture.oerr_num++;
359 431
360 irq function 432 if (istatus & ERR_UNDER)
433 fsi->capture.uerr_num++;
361 434
435 fsi_reg_write(fsi, DOFF_ST, 0);
436 fsi_reg_write(fsi, DIFF_ST, 0);
437}
438
439/*
440 * dma function
441 */
442
443static u8 *fsi_dma_get_area(struct fsi_priv *fsi, int stream)
444{
445 int is_play = fsi_stream_is_play(stream);
446 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
447
448 return io->substream->runtime->dma_area + io->buff_offset;
449}
450
451static void fsi_dma_soft_push16(struct fsi_priv *fsi, int num)
452{
453 u16 *start;
454 int i;
455
456 start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK);
457
458 for (i = 0; i < num; i++)
459 fsi_reg_write(fsi, DODT, ((u32)*(start + i) << 8));
460}
461
462static void fsi_dma_soft_pop16(struct fsi_priv *fsi, int num)
463{
464 u16 *start;
465 int i;
466
467 start = (u16 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE);
468
469
470 for (i = 0; i < num; i++)
471 *(start + i) = (u16)(fsi_reg_read(fsi, DIDT) >> 8);
472}
473
474static void fsi_dma_soft_push32(struct fsi_priv *fsi, int num)
475{
476 u32 *start;
477 int i;
478
479 start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_PLAYBACK);
480
481
482 for (i = 0; i < num; i++)
483 fsi_reg_write(fsi, DODT, *(start + i));
484}
485
486static void fsi_dma_soft_pop32(struct fsi_priv *fsi, int num)
487{
488 u32 *start;
489 int i;
490
491 start = (u32 *)fsi_dma_get_area(fsi, SNDRV_PCM_STREAM_CAPTURE);
492
493 for (i = 0; i < num; i++)
494 *(start + i) = fsi_reg_read(fsi, DIDT);
495}
496
497/*
498 * irq function
499 */
362 500
363************************************************************************/
364static void fsi_irq_enable(struct fsi_priv *fsi, int is_play) 501static void fsi_irq_enable(struct fsi_priv *fsi, int is_play)
365{ 502{
366 u32 data = fsi_port_ab_io_bit(fsi, is_play); 503 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
367 struct fsi_master *master = fsi_get_master(fsi); 504 struct fsi_master *master = fsi_get_master(fsi);
368 505
369 fsi_master_mask_set(master, master->core->imsk, data, data); 506 fsi_core_mask_set(master, imsk, data, data);
370 fsi_master_mask_set(master, master->core->iemsk, data, data); 507 fsi_core_mask_set(master, iemsk, data, data);
371} 508}
372 509
373static void fsi_irq_disable(struct fsi_priv *fsi, int is_play) 510static void fsi_irq_disable(struct fsi_priv *fsi, int is_play)
374{ 511{
375 u32 data = fsi_port_ab_io_bit(fsi, is_play); 512 u32 data = AB_IO(1, fsi_get_port_shift(fsi, is_play));
376 struct fsi_master *master = fsi_get_master(fsi); 513 struct fsi_master *master = fsi_get_master(fsi);
377 514
378 fsi_master_mask_set(master, master->core->imsk, data, 0); 515 fsi_core_mask_set(master, imsk, data, 0);
379 fsi_master_mask_set(master, master->core->iemsk, data, 0); 516 fsi_core_mask_set(master, iemsk, data, 0);
380} 517}
381 518
382static u32 fsi_irq_get_status(struct fsi_master *master) 519static u32 fsi_irq_get_status(struct fsi_master *master)
383{ 520{
384 return fsi_master_read(master, master->core->int_st); 521 return fsi_core_read(master, int_st);
385}
386
387static void fsi_irq_clear_all_status(struct fsi_master *master)
388{
389 fsi_master_write(master, master->core->int_st, 0);
390} 522}
391 523
392static void fsi_irq_clear_status(struct fsi_priv *fsi) 524static void fsi_irq_clear_status(struct fsi_priv *fsi)
@@ -394,67 +526,90 @@ static void fsi_irq_clear_status(struct fsi_priv *fsi)
394 u32 data = 0; 526 u32 data = 0;
395 struct fsi_master *master = fsi_get_master(fsi); 527 struct fsi_master *master = fsi_get_master(fsi);
396 528
397 data |= fsi_port_ab_io_bit(fsi, 0); 529 data |= AB_IO(1, fsi_get_port_shift(fsi, 0));
398 data |= fsi_port_ab_io_bit(fsi, 1); 530 data |= AB_IO(1, fsi_get_port_shift(fsi, 1));
399 531
400 /* clear interrupt factor */ 532 /* clear interrupt factor */
401 fsi_master_mask_set(master, master->core->int_st, data, 0); 533 fsi_core_mask_set(master, int_st, data, 0);
402} 534}
403 535
404/************************************************************************ 536/*
405 537 * SPDIF master clock function
406 538 *
407 SPDIF master clock function 539 * These functions are used later FSI2
408 540 */
409These functions are used later FSI2
410************************************************************************/
411static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable) 541static void fsi_spdif_clk_ctrl(struct fsi_priv *fsi, int enable)
412{ 542{
413 struct fsi_master *master = fsi_get_master(fsi); 543 struct fsi_master *master = fsi_get_master(fsi);
414 u32 val = BP | SE; 544 u32 mask, val;
415 545
416 if (master->core->ver < 2) { 546 if (master->core->ver < 2) {
417 pr_err("fsi: register access err (%s)\n", __func__); 547 pr_err("fsi: register access err (%s)\n", __func__);
418 return; 548 return;
419 } 549 }
420 550
421 if (enable) 551 mask = BP | SE;
422 fsi_master_mask_set(master, fsi->mst_ctrl, val, val); 552 val = enable ? mask : 0;
423 else
424 fsi_master_mask_set(master, fsi->mst_ctrl, val, 0);
425}
426
427/************************************************************************
428 553
554 fsi_is_port_a(fsi) ?
555 fsi_core_mask_set(master, a_mclk, mask, val) :
556 fsi_core_mask_set(master, b_mclk, mask, val);
557}
429 558
430 ctrl function 559/*
560 * clock function
561 */
562#define fsi_module_init(m, d) __fsi_module_clk_ctrl(m, d, 1)
563#define fsi_module_kill(m, d) __fsi_module_clk_ctrl(m, d, 0)
564static void __fsi_module_clk_ctrl(struct fsi_master *master,
565 struct device *dev,
566 int enable)
567{
568 pm_runtime_get_sync(dev);
569
570 if (enable) {
571 /* enable only SR */
572 fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR);
573 fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0);
574 } else {
575 /* clear all registers */
576 fsi_master_mask_set(master, SOFT_RST, FSISR, 0);
577 }
431 578
579 pm_runtime_put_sync(dev);
580}
432 581
433************************************************************************/ 582#define fsi_port_start(f) __fsi_port_clk_ctrl(f, 1)
434static void fsi_clk_ctrl(struct fsi_priv *fsi, int enable) 583#define fsi_port_stop(f) __fsi_port_clk_ctrl(f, 0)
584static void __fsi_port_clk_ctrl(struct fsi_priv *fsi, int enable)
435{ 585{
436 u32 val = fsi_is_port_a(fsi) ? (1 << 0) : (1 << 4);
437 struct fsi_master *master = fsi_get_master(fsi); 586 struct fsi_master *master = fsi_get_master(fsi);
587 u32 soft = fsi_is_port_a(fsi) ? PASR : PBSR;
588 u32 clk = fsi_is_port_a(fsi) ? CRA : CRB;
589 int is_master = fsi_is_clk_master(fsi);
438 590
439 if (enable) 591 fsi_master_mask_set(master, SOFT_RST, soft, (enable) ? soft : 0);
440 fsi_master_mask_set(master, CLK_RST, val, val); 592 if (is_master)
441 else 593 fsi_master_mask_set(master, CLK_RST, clk, (enable) ? clk : 0);
442 fsi_master_mask_set(master, CLK_RST, val, 0);
443} 594}
444 595
596/*
597 * ctrl function
598 */
445static void fsi_fifo_init(struct fsi_priv *fsi, 599static void fsi_fifo_init(struct fsi_priv *fsi,
446 int is_play, 600 int is_play,
447 struct snd_soc_dai *dai) 601 struct snd_soc_dai *dai)
448{ 602{
449 struct fsi_master *master = fsi_get_master(fsi); 603 struct fsi_master *master = fsi_get_master(fsi);
450 u32 ctrl, shift, i; 604 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
605 u32 shift, i;
451 606
452 /* get on-chip RAM capacity */ 607 /* get on-chip RAM capacity */
453 shift = fsi_master_read(master, FIFO_SZ); 608 shift = fsi_master_read(master, FIFO_SZ);
454 shift >>= fsi_is_port_a(fsi) ? AO_SZ_SHIFT : BO_SZ_SHIFT; 609 shift >>= fsi_get_port_shift(fsi, is_play);
455 shift &= OUT_SZ_MASK; 610 shift &= FIFO_SZ_MASK;
456 fsi->fifo_max = 256 << shift; 611 io->fifo_max_num = 256 << shift;
457 dev_dbg(dai->dev, "fifo = %d words\n", fsi->fifo_max); 612 dev_dbg(dai->dev, "fifo = %d words\n", io->fifo_max_num);
458 613
459 /* 614 /*
460 * The maximum number of sample data varies depending 615 * The maximum number of sample data varies depending
@@ -475,109 +630,116 @@ static void fsi_fifo_init(struct fsi_priv *fsi,
475 * 7 channels: 32 ( 32 x 7 = 224) 630 * 7 channels: 32 ( 32 x 7 = 224)
476 * 8 channels: 32 ( 32 x 8 = 256) 631 * 8 channels: 32 ( 32 x 8 = 256)
477 */ 632 */
478 for (i = 1; i < fsi->chan; i <<= 1) 633 for (i = 1; i < fsi->chan_num; i <<= 1)
479 fsi->fifo_max >>= 1; 634 io->fifo_max_num >>= 1;
480 dev_dbg(dai->dev, "%d channel %d store\n", fsi->chan, fsi->fifo_max); 635 dev_dbg(dai->dev, "%d channel %d store\n",
481 636 fsi->chan_num, io->fifo_max_num);
482 ctrl = is_play ? DOFF_CTL : DIFF_CTL;
483 637
484 /* set interrupt generation factor */ 638 /*
485 fsi_reg_write(fsi, ctrl, IRQ_HALF); 639 * set interrupt generation factor
486 640 * clear FIFO
487 /* clear FIFO */ 641 */
488 fsi_reg_mask_set(fsi, ctrl, FIFO_CLR, FIFO_CLR); 642 if (is_play) {
489} 643 fsi_reg_write(fsi, DOFF_CTL, IRQ_HALF);
490 644 fsi_reg_mask_set(fsi, DOFF_CTL, FIFO_CLR, FIFO_CLR);
491static void fsi_soft_all_reset(struct fsi_master *master) 645 } else {
492{ 646 fsi_reg_write(fsi, DIFF_CTL, IRQ_HALF);
493 /* port AB reset */ 647 fsi_reg_mask_set(fsi, DIFF_CTL, FIFO_CLR, FIFO_CLR);
494 fsi_master_mask_set(master, SOFT_RST, PASR | PBSR, 0); 648 }
495 mdelay(10);
496
497 /* soft reset */
498 fsi_master_mask_set(master, SOFT_RST, FSISR, 0);
499 fsi_master_mask_set(master, SOFT_RST, FSISR, FSISR);
500 mdelay(10);
501} 649}
502 650
503/* playback interrupt */ 651static int fsi_fifo_data_ctrl(struct fsi_priv *fsi, int stream)
504static int fsi_data_push(struct fsi_priv *fsi, int startup)
505{ 652{
506 struct snd_pcm_runtime *runtime; 653 struct snd_pcm_runtime *runtime;
507 struct snd_pcm_substream *substream = NULL; 654 struct snd_pcm_substream *substream = NULL;
508 u32 status; 655 int is_play = fsi_stream_is_play(stream);
509 int send; 656 struct fsi_stream *io = fsi_get_stream(fsi, is_play);
510 int fifo_free; 657 int data_residue_num;
511 int width; 658 int data_num;
512 u8 *start; 659 int data_num_max;
513 int i, over_period; 660 int ch_width;
661 int over_period;
662 void (*fn)(struct fsi_priv *fsi, int size);
514 663
515 if (!fsi || 664 if (!fsi ||
516 !fsi->substream || 665 !io->substream ||
517 !fsi->substream->runtime) 666 !io->substream->runtime)
518 return -EINVAL; 667 return -EINVAL;
519 668
520 over_period = 0; 669 over_period = 0;
521 substream = fsi->substream; 670 substream = io->substream;
522 runtime = substream->runtime; 671 runtime = substream->runtime;
523 672
524 /* FSI FIFO has limit. 673 /* FSI FIFO has limit.
525 * So, this driver can not send periods data at a time 674 * So, this driver can not send periods data at a time
526 */ 675 */
527 if (fsi->byte_offset >= 676 if (io->buff_offset >=
528 fsi->period_len * (fsi->periods + 1)) { 677 fsi_num2offset(io->period_num + 1, io->period_len)) {
529 678
530 over_period = 1; 679 over_period = 1;
531 fsi->periods = (fsi->periods + 1) % runtime->periods; 680 io->period_num = (io->period_num + 1) % runtime->periods;
532 681
533 if (0 == fsi->periods) 682 if (0 == io->period_num)
534 fsi->byte_offset = 0; 683 io->buff_offset = 0;
535 } 684 }
536 685
537 /* get 1 channel data width */ 686 /* get 1 channel data width */
538 width = frames_to_bytes(runtime, 1) / fsi->chan; 687 ch_width = fsi_get_frame_width(fsi, is_play);
539 688
540 /* get send size for alsa */ 689 /* get residue data number of alsa */
541 send = (fsi->buffer_len - fsi->byte_offset) / width; 690 data_residue_num = fsi_len2num(io->buff_len - io->buff_offset,
542 691 ch_width);
543 /* get FIFO free size */ 692
544 fifo_free = (fsi->fifo_max * fsi->chan) - fsi_get_fifo_residue(fsi, 1); 693 if (is_play) {
545 694 /*
546 /* size check */ 695 * for play-back
547 if (fifo_free < send) 696 *
548 send = fifo_free; 697 * data_num_max : number of FSI fifo free space
549 698 * data_num : number of ALSA residue data
550 start = runtime->dma_area; 699 */
551 start += fsi->byte_offset; 700 data_num_max = io->fifo_max_num * fsi->chan_num;
552 701 data_num_max -= fsi_get_fifo_data_num(fsi, is_play);
553 switch (width) { 702
554 case 2: 703 data_num = data_residue_num;
555 for (i = 0; i < send; i++) 704
556 fsi_reg_write(fsi, DODT, 705 switch (ch_width) {
557 ((u32)*((u16 *)start + i) << 8)); 706 case 2:
558 break; 707 fn = fsi_dma_soft_push16;
559 case 4: 708 break;
560 for (i = 0; i < send; i++) 709 case 4:
561 fsi_reg_write(fsi, DODT, *((u32 *)start + i)); 710 fn = fsi_dma_soft_push32;
562 break; 711 break;
563 default: 712 default:
564 return -EINVAL; 713 return -EINVAL;
714 }
715 } else {
716 /*
717 * for capture
718 *
719 * data_num_max : number of ALSA free space
720 * data_num : number of data in FSI fifo
721 */
722 data_num_max = data_residue_num;
723 data_num = fsi_get_fifo_data_num(fsi, is_play);
724
725 switch (ch_width) {
726 case 2:
727 fn = fsi_dma_soft_pop16;
728 break;
729 case 4:
730 fn = fsi_dma_soft_pop32;
731 break;
732 default:
733 return -EINVAL;
734 }
565 } 735 }
566 736
567 fsi->byte_offset += send * width; 737 data_num = min(data_num, data_num_max);
568
569 status = fsi_reg_read(fsi, DOFF_ST);
570 if (!startup) {
571 struct snd_soc_dai *dai = fsi_get_dai(substream);
572 738
573 if (status & ERR_OVER) 739 fn(fsi, data_num);
574 dev_err(dai->dev, "over run\n");
575 if (status & ERR_UNDER)
576 dev_err(dai->dev, "under run\n");
577 }
578 fsi_reg_write(fsi, DOFF_ST, 0);
579 740
580 fsi_irq_enable(fsi, 1); 741 /* update buff_offset */
742 io->buff_offset += fsi_num2offset(data_num, ch_width);
581 743
582 if (over_period) 744 if (over_period)
583 snd_pcm_period_elapsed(substream); 745 snd_pcm_period_elapsed(substream);
@@ -585,87 +747,14 @@ static int fsi_data_push(struct fsi_priv *fsi, int startup)
585 return 0; 747 return 0;
586} 748}
587 749
588static int fsi_data_pop(struct fsi_priv *fsi, int startup) 750static int fsi_data_pop(struct fsi_priv *fsi)
589{ 751{
590 struct snd_pcm_runtime *runtime; 752 return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_CAPTURE);
591 struct snd_pcm_substream *substream = NULL; 753}
592 u32 status;
593 int free;
594 int fifo_fill;
595 int width;
596 u8 *start;
597 int i, over_period;
598
599 if (!fsi ||
600 !fsi->substream ||
601 !fsi->substream->runtime)
602 return -EINVAL;
603
604 over_period = 0;
605 substream = fsi->substream;
606 runtime = substream->runtime;
607
608 /* FSI FIFO has limit.
609 * So, this driver can not send periods data at a time
610 */
611 if (fsi->byte_offset >=
612 fsi->period_len * (fsi->periods + 1)) {
613
614 over_period = 1;
615 fsi->periods = (fsi->periods + 1) % runtime->periods;
616
617 if (0 == fsi->periods)
618 fsi->byte_offset = 0;
619 }
620
621 /* get 1 channel data width */
622 width = frames_to_bytes(runtime, 1) / fsi->chan;
623
624 /* get free space for alsa */
625 free = (fsi->buffer_len - fsi->byte_offset) / width;
626
627 /* get recv size */
628 fifo_fill = fsi_get_fifo_residue(fsi, 0);
629
630 if (free < fifo_fill)
631 fifo_fill = free;
632
633 start = runtime->dma_area;
634 start += fsi->byte_offset;
635
636 switch (width) {
637 case 2:
638 for (i = 0; i < fifo_fill; i++)
639 *((u16 *)start + i) =
640 (u16)(fsi_reg_read(fsi, DIDT) >> 8);
641 break;
642 case 4:
643 for (i = 0; i < fifo_fill; i++)
644 *((u32 *)start + i) = fsi_reg_read(fsi, DIDT);
645 break;
646 default:
647 return -EINVAL;
648 }
649
650 fsi->byte_offset += fifo_fill * width;
651
652 status = fsi_reg_read(fsi, DIFF_ST);
653 if (!startup) {
654 struct snd_soc_dai *dai = fsi_get_dai(substream);
655
656 if (status & ERR_OVER)
657 dev_err(dai->dev, "over run\n");
658 if (status & ERR_UNDER)
659 dev_err(dai->dev, "under run\n");
660 }
661 fsi_reg_write(fsi, DIFF_ST, 0);
662
663 fsi_irq_enable(fsi, 0);
664
665 if (over_period)
666 snd_pcm_period_elapsed(substream);
667 754
668 return 0; 755static int fsi_data_push(struct fsi_priv *fsi)
756{
757 return fsi_fifo_data_ctrl(fsi, SNDRV_PCM_STREAM_PLAYBACK);
669} 758}
670 759
671static irqreturn_t fsi_interrupt(int irq, void *data) 760static irqreturn_t fsi_interrupt(int irq, void *data)
@@ -677,49 +766,38 @@ static irqreturn_t fsi_interrupt(int irq, void *data)
677 fsi_master_mask_set(master, SOFT_RST, IR, 0); 766 fsi_master_mask_set(master, SOFT_RST, IR, 0);
678 fsi_master_mask_set(master, SOFT_RST, IR, IR); 767 fsi_master_mask_set(master, SOFT_RST, IR, IR);
679 768
680 if (int_st & INT_A_OUT) 769 if (int_st & AB_IO(1, AO_SHIFT))
681 fsi_data_push(&master->fsia, 0); 770 fsi_data_push(&master->fsia);
682 if (int_st & INT_B_OUT) 771 if (int_st & AB_IO(1, BO_SHIFT))
683 fsi_data_push(&master->fsib, 0); 772 fsi_data_push(&master->fsib);
684 if (int_st & INT_A_IN) 773 if (int_st & AB_IO(1, AI_SHIFT))
685 fsi_data_pop(&master->fsia, 0); 774 fsi_data_pop(&master->fsia);
686 if (int_st & INT_B_IN) 775 if (int_st & AB_IO(1, BI_SHIFT))
687 fsi_data_pop(&master->fsib, 0); 776 fsi_data_pop(&master->fsib);
777
778 fsi_count_fifo_err(&master->fsia);
779 fsi_count_fifo_err(&master->fsib);
688 780
689 fsi_irq_clear_all_status(master); 781 fsi_irq_clear_status(&master->fsia);
782 fsi_irq_clear_status(&master->fsib);
690 783
691 return IRQ_HANDLED; 784 return IRQ_HANDLED;
692} 785}
693 786
694/************************************************************************ 787/*
695 788 * dai ops
696 789 */
697 dai ops
698
699 790
700************************************************************************/
701static int fsi_dai_startup(struct snd_pcm_substream *substream, 791static int fsi_dai_startup(struct snd_pcm_substream *substream,
702 struct snd_soc_dai *dai) 792 struct snd_soc_dai *dai)
703{ 793{
704 struct fsi_priv *fsi = fsi_get_priv(substream); 794 struct fsi_priv *fsi = fsi_get_priv(substream);
705 u32 flags = fsi_get_info_flags(fsi); 795 u32 flags = fsi_get_info_flags(fsi);
706 struct fsi_master *master = fsi_get_master(fsi);
707 u32 fmt;
708 u32 reg;
709 u32 data; 796 u32 data;
710 int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); 797 int is_play = fsi_is_play(substream);
711 int is_master;
712 int ret = 0;
713 798
714 pm_runtime_get_sync(dai->dev); 799 pm_runtime_get_sync(dai->dev);
715 800
716 /* CKG1 */
717 data = is_play ? (1 << 0) : (1 << 4);
718 is_master = fsi_is_master_mode(fsi, is_play);
719 if (is_master)
720 fsi_reg_mask_set(fsi, CKG1, data, data);
721 else
722 fsi_reg_mask_set(fsi, CKG1, data, 0);
723 801
724 /* clock inversion (CKG2) */ 802 /* clock inversion (CKG2) */
725 data = 0; 803 data = 0;
@@ -734,53 +812,6 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
734 812
735 fsi_reg_write(fsi, CKG2, data); 813 fsi_reg_write(fsi, CKG2, data);
736 814
737 /* do fmt, di fmt */
738 data = 0;
739 reg = is_play ? DO_FMT : DI_FMT;
740 fmt = is_play ? SH_FSI_GET_OFMT(flags) : SH_FSI_GET_IFMT(flags);
741 switch (fmt) {
742 case SH_FSI_FMT_MONO:
743 data = CR_MONO;
744 fsi->chan = 1;
745 break;
746 case SH_FSI_FMT_MONO_DELAY:
747 data = CR_MONO_D;
748 fsi->chan = 1;
749 break;
750 case SH_FSI_FMT_PCM:
751 data = CR_PCM;
752 fsi->chan = 2;
753 break;
754 case SH_FSI_FMT_I2S:
755 data = CR_I2S;
756 fsi->chan = 2;
757 break;
758 case SH_FSI_FMT_TDM:
759 fsi->chan = is_play ?
760 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
761 data = CR_TDM | (fsi->chan - 1);
762 break;
763 case SH_FSI_FMT_TDM_DELAY:
764 fsi->chan = is_play ?
765 SH_FSI_GET_CH_O(flags) : SH_FSI_GET_CH_I(flags);
766 data = CR_TDM_D | (fsi->chan - 1);
767 break;
768 case SH_FSI_FMT_SPDIF:
769 if (master->core->ver < 2) {
770 dev_err(dai->dev, "This FSI can not use SPDIF\n");
771 return -EINVAL;
772 }
773 data = CR_SPDIF;
774 fsi->chan = 2;
775 fsi_spdif_clk_ctrl(fsi, 1);
776 fsi_reg_mask_set(fsi, OUT_SEL, 0x0010, 0x0010);
777 break;
778 default:
779 dev_err(dai->dev, "unknown format.\n");
780 return -EINVAL;
781 }
782 fsi_reg_write(fsi, reg, data);
783
784 /* irq clear */ 815 /* irq clear */
785 fsi_irq_disable(fsi, is_play); 816 fsi_irq_disable(fsi, is_play);
786 fsi_irq_clear_status(fsi); 817 fsi_irq_clear_status(fsi);
@@ -788,17 +819,23 @@ static int fsi_dai_startup(struct snd_pcm_substream *substream,
788 /* fifo init */ 819 /* fifo init */
789 fsi_fifo_init(fsi, is_play, dai); 820 fsi_fifo_init(fsi, is_play, dai);
790 821
791 return ret; 822 return 0;
792} 823}
793 824
794static void fsi_dai_shutdown(struct snd_pcm_substream *substream, 825static void fsi_dai_shutdown(struct snd_pcm_substream *substream,
795 struct snd_soc_dai *dai) 826 struct snd_soc_dai *dai)
796{ 827{
797 struct fsi_priv *fsi = fsi_get_priv(substream); 828 struct fsi_priv *fsi = fsi_get_priv(substream);
798 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 829 int is_play = fsi_is_play(substream);
830 struct fsi_master *master = fsi_get_master(fsi);
831 set_rate_func set_rate = fsi_get_info_set_rate(master);
799 832
800 fsi_irq_disable(fsi, is_play); 833 fsi_irq_disable(fsi, is_play);
801 fsi_clk_ctrl(fsi, 0); 834
835 if (fsi_is_clk_master(fsi))
836 set_rate(dai->dev, fsi_is_port_a(fsi), fsi->rate, 0);
837
838 fsi->rate = 0;
802 839
803 pm_runtime_put_sync(dai->dev); 840 pm_runtime_put_sync(dai->dev);
804} 841}
@@ -808,22 +845,117 @@ static int fsi_dai_trigger(struct snd_pcm_substream *substream, int cmd,
808{ 845{
809 struct fsi_priv *fsi = fsi_get_priv(substream); 846 struct fsi_priv *fsi = fsi_get_priv(substream);
810 struct snd_pcm_runtime *runtime = substream->runtime; 847 struct snd_pcm_runtime *runtime = substream->runtime;
811 int is_play = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; 848 int is_play = fsi_is_play(substream);
812 int ret = 0; 849 int ret = 0;
813 850
814 switch (cmd) { 851 switch (cmd) {
815 case SNDRV_PCM_TRIGGER_START: 852 case SNDRV_PCM_TRIGGER_START:
816 fsi_stream_push(fsi, substream, 853 fsi_stream_push(fsi, is_play, substream,
817 frames_to_bytes(runtime, runtime->buffer_size), 854 frames_to_bytes(runtime, runtime->buffer_size),
818 frames_to_bytes(runtime, runtime->period_size)); 855 frames_to_bytes(runtime, runtime->period_size));
819 ret = is_play ? fsi_data_push(fsi, 1) : fsi_data_pop(fsi, 1); 856 ret = is_play ? fsi_data_push(fsi) : fsi_data_pop(fsi);
857 fsi_irq_enable(fsi, is_play);
858 fsi_port_start(fsi);
820 break; 859 break;
821 case SNDRV_PCM_TRIGGER_STOP: 860 case SNDRV_PCM_TRIGGER_STOP:
861 fsi_port_stop(fsi);
822 fsi_irq_disable(fsi, is_play); 862 fsi_irq_disable(fsi, is_play);
823 fsi_stream_pop(fsi); 863 fsi_stream_pop(fsi, is_play);
864 break;
865 }
866
867 return ret;
868}
869
870static int fsi_set_fmt_dai(struct fsi_priv *fsi, unsigned int fmt)
871{
872 u32 data = 0;
873
874 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
875 case SND_SOC_DAIFMT_I2S:
876 data = CR_I2S;
877 fsi->chan_num = 2;
878 break;
879 case SND_SOC_DAIFMT_LEFT_J:
880 data = CR_PCM;
881 fsi->chan_num = 2;
882 break;
883 default:
884 return -EINVAL;
885 }
886
887 fsi_reg_write(fsi, DO_FMT, data);
888 fsi_reg_write(fsi, DI_FMT, data);
889
890 return 0;
891}
892
893static int fsi_set_fmt_spdif(struct fsi_priv *fsi)
894{
895 struct fsi_master *master = fsi_get_master(fsi);
896 u32 data = 0;
897
898 if (master->core->ver < 2)
899 return -EINVAL;
900
901 data = CR_BWS_16 | CR_DTMD_SPDIF_PCM | CR_PCM;
902 fsi->chan_num = 2;
903 fsi_spdif_clk_ctrl(fsi, 1);
904 fsi_reg_mask_set(fsi, OUT_SEL, DMMD, DMMD);
905
906 fsi_reg_write(fsi, DO_FMT, data);
907 fsi_reg_write(fsi, DI_FMT, data);
908
909 return 0;
910}
911
912static int fsi_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
913{
914 struct fsi_priv *fsi = fsi_get_priv_frm_dai(dai);
915 struct fsi_master *master = fsi_get_master(fsi);
916 set_rate_func set_rate = fsi_get_info_set_rate(master);
917 u32 flags = fsi_get_info_flags(fsi);
918 u32 data = 0;
919 int ret;
920
921 pm_runtime_get_sync(dai->dev);
922
923 /* set master/slave audio interface */
924 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
925 case SND_SOC_DAIFMT_CBM_CFM:
926 data = DIMD | DOMD;
927 fsi->clk_master = 1;
824 break; 928 break;
929 case SND_SOC_DAIFMT_CBS_CFS:
930 break;
931 default:
932 ret = -EINVAL;
933 goto set_fmt_exit;
934 }
935
936 if (fsi_is_clk_master(fsi) && !set_rate) {
937 dev_err(dai->dev, "platform doesn't have set_rate\n");
938 ret = -EINVAL;
939 goto set_fmt_exit;
825 } 940 }
826 941
942 fsi_reg_mask_set(fsi, CKG1, (DIMD | DOMD), data);
943
944 /* set format */
945 switch (flags & SH_FSI_FMT_MASK) {
946 case SH_FSI_FMT_DAI:
947 ret = fsi_set_fmt_dai(fsi, fmt & SND_SOC_DAIFMT_FORMAT_MASK);
948 break;
949 case SH_FSI_FMT_SPDIF:
950 ret = fsi_set_fmt_spdif(fsi);
951 break;
952 default:
953 ret = -EINVAL;
954 }
955
956set_fmt_exit:
957 pm_runtime_put_sync(dai->dev);
958
827 return ret; 959 return ret;
828} 960}
829 961
@@ -833,20 +965,19 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
833{ 965{
834 struct fsi_priv *fsi = fsi_get_priv(substream); 966 struct fsi_priv *fsi = fsi_get_priv(substream);
835 struct fsi_master *master = fsi_get_master(fsi); 967 struct fsi_master *master = fsi_get_master(fsi);
836 int (*set_rate)(int is_porta, int rate) = master->info->set_rate; 968 set_rate_func set_rate = fsi_get_info_set_rate(master);
837 int fsi_ver = master->core->ver; 969 int fsi_ver = master->core->ver;
838 int is_play = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK); 970 long rate = params_rate(params);
839 int ret; 971 int ret;
840 972
841 /* if slave mode, set_rate is not needed */ 973 if (!fsi_is_clk_master(fsi))
842 if (!fsi_is_master_mode(fsi, is_play))
843 return 0; 974 return 0;
844 975
845 /* it is error if no set_rate */ 976 ret = set_rate(dai->dev, fsi_is_port_a(fsi), rate, 1);
846 if (!set_rate) 977 if (ret < 0) /* error */
847 return -EIO; 978 return ret;
848 979
849 ret = set_rate(fsi_is_port_a(fsi), params_rate(params)); 980 fsi->rate = rate;
850 if (ret > 0) { 981 if (ret > 0) {
851 u32 data = 0; 982 u32 data = 0;
852 983
@@ -901,7 +1032,6 @@ static int fsi_dai_hw_params(struct snd_pcm_substream *substream,
901 1032
902 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data); 1033 fsi_reg_mask_set(fsi, CKG1, (ACKMD_MASK | BPFMD_MASK) , data);
903 udelay(10); 1034 udelay(10);
904 fsi_clk_ctrl(fsi, 1);
905 ret = 0; 1035 ret = 0;
906 } 1036 }
907 1037
@@ -913,16 +1043,14 @@ static struct snd_soc_dai_ops fsi_dai_ops = {
913 .startup = fsi_dai_startup, 1043 .startup = fsi_dai_startup,
914 .shutdown = fsi_dai_shutdown, 1044 .shutdown = fsi_dai_shutdown,
915 .trigger = fsi_dai_trigger, 1045 .trigger = fsi_dai_trigger,
1046 .set_fmt = fsi_dai_set_fmt,
916 .hw_params = fsi_dai_hw_params, 1047 .hw_params = fsi_dai_hw_params,
917}; 1048};
918 1049
919/************************************************************************ 1050/*
920 1051 * pcm ops
921 1052 */
922 pcm ops
923
924 1053
925************************************************************************/
926static struct snd_pcm_hardware fsi_pcm_hardware = { 1054static struct snd_pcm_hardware fsi_pcm_hardware = {
927 .info = SNDRV_PCM_INFO_INTERLEAVED | 1055 .info = SNDRV_PCM_INFO_INTERLEAVED |
928 SNDRV_PCM_INFO_MMAP | 1056 SNDRV_PCM_INFO_MMAP |
@@ -971,9 +1099,10 @@ static snd_pcm_uframes_t fsi_pointer(struct snd_pcm_substream *substream)
971{ 1099{
972 struct snd_pcm_runtime *runtime = substream->runtime; 1100 struct snd_pcm_runtime *runtime = substream->runtime;
973 struct fsi_priv *fsi = fsi_get_priv(substream); 1101 struct fsi_priv *fsi = fsi_get_priv(substream);
1102 struct fsi_stream *io = fsi_get_stream(fsi, fsi_is_play(substream));
974 long location; 1103 long location;
975 1104
976 location = (fsi->byte_offset - 1); 1105 location = (io->buff_offset - 1);
977 if (location < 0) 1106 if (location < 0)
978 location = 0; 1107 location = 0;
979 1108
@@ -988,13 +1117,10 @@ static struct snd_pcm_ops fsi_pcm_ops = {
988 .pointer = fsi_pointer, 1117 .pointer = fsi_pointer,
989}; 1118};
990 1119
991/************************************************************************ 1120/*
992 1121 * snd_soc_platform
993 1122 */
994 snd_soc_platform
995
996 1123
997************************************************************************/
998#define PREALLOC_BUFFER (32 * 1024) 1124#define PREALLOC_BUFFER (32 * 1024)
999#define PREALLOC_BUFFER_MAX (32 * 1024) 1125#define PREALLOC_BUFFER_MAX (32 * 1024)
1000 1126
@@ -1018,17 +1144,13 @@ static int fsi_pcm_new(struct snd_card *card,
1018 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX); 1144 PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
1019} 1145}
1020 1146
1021/************************************************************************ 1147/*
1022 1148 * alsa struct
1023 1149 */
1024 alsa struct
1025
1026 1150
1027************************************************************************/ 1151static struct snd_soc_dai_driver fsi_soc_dai[] = {
1028struct snd_soc_dai fsi_soc_dai[] = {
1029 { 1152 {
1030 .name = "FSIA", 1153 .name = "fsia-dai",
1031 .id = 0,
1032 .playback = { 1154 .playback = {
1033 .rates = FSI_RATES, 1155 .rates = FSI_RATES,
1034 .formats = FSI_FMTS, 1156 .formats = FSI_FMTS,
@@ -1044,8 +1166,7 @@ struct snd_soc_dai fsi_soc_dai[] = {
1044 .ops = &fsi_dai_ops, 1166 .ops = &fsi_dai_ops,
1045 }, 1167 },
1046 { 1168 {
1047 .name = "FSIB", 1169 .name = "fsib-dai",
1048 .id = 1,
1049 .playback = { 1170 .playback = {
1050 .rates = FSI_RATES, 1171 .rates = FSI_RATES,
1051 .formats = FSI_FMTS, 1172 .formats = FSI_FMTS,
@@ -1061,23 +1182,17 @@ struct snd_soc_dai fsi_soc_dai[] = {
1061 .ops = &fsi_dai_ops, 1182 .ops = &fsi_dai_ops,
1062 }, 1183 },
1063}; 1184};
1064EXPORT_SYMBOL_GPL(fsi_soc_dai);
1065 1185
1066struct snd_soc_platform fsi_soc_platform = { 1186static struct snd_soc_platform_driver fsi_soc_platform = {
1067 .name = "fsi-pcm", 1187 .ops = &fsi_pcm_ops,
1068 .pcm_ops = &fsi_pcm_ops,
1069 .pcm_new = fsi_pcm_new, 1188 .pcm_new = fsi_pcm_new,
1070 .pcm_free = fsi_pcm_free, 1189 .pcm_free = fsi_pcm_free,
1071}; 1190};
1072EXPORT_SYMBOL_GPL(fsi_soc_platform);
1073
1074/************************************************************************
1075
1076
1077 platform function
1078 1191
1192/*
1193 * platform function
1194 */
1079 1195
1080************************************************************************/
1081static int fsi_probe(struct platform_device *pdev) 1196static int fsi_probe(struct platform_device *pdev)
1082{ 1197{
1083 struct fsi_master *master; 1198 struct fsi_master *master;
@@ -1123,22 +1238,15 @@ static int fsi_probe(struct platform_device *pdev)
1123 /* FSI A setting */ 1238 /* FSI A setting */
1124 master->fsia.base = master->base; 1239 master->fsia.base = master->base;
1125 master->fsia.master = master; 1240 master->fsia.master = master;
1126 master->fsia.mst_ctrl = A_MST_CTLR;
1127 1241
1128 /* FSI B setting */ 1242 /* FSI B setting */
1129 master->fsib.base = master->base + 0x40; 1243 master->fsib.base = master->base + 0x40;
1130 master->fsib.master = master; 1244 master->fsib.master = master;
1131 master->fsib.mst_ctrl = B_MST_CTLR;
1132 1245
1133 pm_runtime_enable(&pdev->dev); 1246 pm_runtime_enable(&pdev->dev);
1134 pm_runtime_resume(&pdev->dev); 1247 dev_set_drvdata(&pdev->dev, master);
1135
1136 fsi_soc_dai[0].dev = &pdev->dev;
1137 fsi_soc_dai[0].private_data = &master->fsia;
1138 fsi_soc_dai[1].dev = &pdev->dev;
1139 fsi_soc_dai[1].private_data = &master->fsib;
1140 1248
1141 fsi_soft_all_reset(master); 1249 fsi_module_init(master, &pdev->dev);
1142 1250
1143 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, 1251 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED,
1144 id_entry->name, master); 1252 id_entry->name, master);
@@ -1147,14 +1255,23 @@ static int fsi_probe(struct platform_device *pdev)
1147 goto exit_iounmap; 1255 goto exit_iounmap;
1148 } 1256 }
1149 1257
1150 ret = snd_soc_register_platform(&fsi_soc_platform); 1258 ret = snd_soc_register_platform(&pdev->dev, &fsi_soc_platform);
1151 if (ret < 0) { 1259 if (ret < 0) {
1152 dev_err(&pdev->dev, "cannot snd soc register\n"); 1260 dev_err(&pdev->dev, "cannot snd soc register\n");
1153 goto exit_free_irq; 1261 goto exit_free_irq;
1154 } 1262 }
1155 1263
1156 return snd_soc_register_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); 1264 ret = snd_soc_register_dais(&pdev->dev, fsi_soc_dai,
1265 ARRAY_SIZE(fsi_soc_dai));
1266 if (ret < 0) {
1267 dev_err(&pdev->dev, "cannot snd dai register\n");
1268 goto exit_snd_soc;
1269 }
1270
1271 return ret;
1157 1272
1273exit_snd_soc:
1274 snd_soc_unregister_platform(&pdev->dev);
1158exit_free_irq: 1275exit_free_irq:
1159 free_irq(irq, master); 1276 free_irq(irq, master);
1160exit_iounmap: 1277exit_iounmap:
@@ -1171,22 +1288,94 @@ static int fsi_remove(struct platform_device *pdev)
1171{ 1288{
1172 struct fsi_master *master; 1289 struct fsi_master *master;
1173 1290
1174 master = fsi_get_master(fsi_soc_dai[0].private_data); 1291 master = dev_get_drvdata(&pdev->dev);
1175 1292
1176 snd_soc_unregister_dais(fsi_soc_dai, ARRAY_SIZE(fsi_soc_dai)); 1293 fsi_module_kill(master, &pdev->dev);
1177 snd_soc_unregister_platform(&fsi_soc_platform);
1178 1294
1295 free_irq(master->irq, master);
1179 pm_runtime_disable(&pdev->dev); 1296 pm_runtime_disable(&pdev->dev);
1180 1297
1181 free_irq(master->irq, master); 1298 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(fsi_soc_dai));
1299 snd_soc_unregister_platform(&pdev->dev);
1182 1300
1183 iounmap(master->base); 1301 iounmap(master->base);
1184 kfree(master); 1302 kfree(master);
1185 1303
1186 fsi_soc_dai[0].dev = NULL; 1304 return 0;
1187 fsi_soc_dai[0].private_data = NULL; 1305}
1188 fsi_soc_dai[1].dev = NULL; 1306
1189 fsi_soc_dai[1].private_data = NULL; 1307static void __fsi_suspend(struct fsi_priv *fsi,
1308 struct device *dev,
1309 set_rate_func set_rate)
1310{
1311 fsi->saved_do_fmt = fsi_reg_read(fsi, DO_FMT);
1312 fsi->saved_di_fmt = fsi_reg_read(fsi, DI_FMT);
1313 fsi->saved_ckg1 = fsi_reg_read(fsi, CKG1);
1314 fsi->saved_ckg2 = fsi_reg_read(fsi, CKG2);
1315 fsi->saved_out_sel = fsi_reg_read(fsi, OUT_SEL);
1316
1317 if (fsi_is_clk_master(fsi))
1318 set_rate(dev, fsi_is_port_a(fsi), fsi->rate, 0);
1319}
1320
1321static void __fsi_resume(struct fsi_priv *fsi,
1322 struct device *dev,
1323 set_rate_func set_rate)
1324{
1325 fsi_reg_write(fsi, DO_FMT, fsi->saved_do_fmt);
1326 fsi_reg_write(fsi, DI_FMT, fsi->saved_di_fmt);
1327 fsi_reg_write(fsi, CKG1, fsi->saved_ckg1);
1328 fsi_reg_write(fsi, CKG2, fsi->saved_ckg2);
1329 fsi_reg_write(fsi, OUT_SEL, fsi->saved_out_sel);
1330
1331 if (fsi_is_clk_master(fsi))
1332 set_rate(dev, fsi_is_port_a(fsi), fsi->rate, 1);
1333}
1334
1335static int fsi_suspend(struct device *dev)
1336{
1337 struct fsi_master *master = dev_get_drvdata(dev);
1338 set_rate_func set_rate = fsi_get_info_set_rate(master);
1339
1340 pm_runtime_get_sync(dev);
1341
1342 __fsi_suspend(&master->fsia, dev, set_rate);
1343 __fsi_suspend(&master->fsib, dev, set_rate);
1344
1345 master->saved_a_mclk = fsi_core_read(master, a_mclk);
1346 master->saved_b_mclk = fsi_core_read(master, b_mclk);
1347 master->saved_iemsk = fsi_core_read(master, iemsk);
1348 master->saved_imsk = fsi_core_read(master, imsk);
1349 master->saved_clk_rst = fsi_master_read(master, CLK_RST);
1350 master->saved_soft_rst = fsi_master_read(master, SOFT_RST);
1351
1352 fsi_module_kill(master, dev);
1353
1354 pm_runtime_put_sync(dev);
1355
1356 return 0;
1357}
1358
1359static int fsi_resume(struct device *dev)
1360{
1361 struct fsi_master *master = dev_get_drvdata(dev);
1362 set_rate_func set_rate = fsi_get_info_set_rate(master);
1363
1364 pm_runtime_get_sync(dev);
1365
1366 fsi_module_init(master, dev);
1367
1368 fsi_master_mask_set(master, SOFT_RST, 0xffff, master->saved_soft_rst);
1369 fsi_master_mask_set(master, CLK_RST, 0xffff, master->saved_clk_rst);
1370 fsi_core_mask_set(master, a_mclk, 0xffff, master->saved_a_mclk);
1371 fsi_core_mask_set(master, b_mclk, 0xffff, master->saved_b_mclk);
1372 fsi_core_mask_set(master, iemsk, 0xffff, master->saved_iemsk);
1373 fsi_core_mask_set(master, imsk, 0xffff, master->saved_imsk);
1374
1375 __fsi_resume(&master->fsia, dev, set_rate);
1376 __fsi_resume(&master->fsib, dev, set_rate);
1377
1378 pm_runtime_put_sync(dev);
1190 1379
1191 return 0; 1380 return 0;
1192} 1381}
@@ -1204,6 +1393,8 @@ static int fsi_runtime_nop(struct device *dev)
1204} 1393}
1205 1394
1206static struct dev_pm_ops fsi_pm_ops = { 1395static struct dev_pm_ops fsi_pm_ops = {
1396 .suspend = fsi_suspend,
1397 .resume = fsi_resume,
1207 .runtime_suspend = fsi_runtime_nop, 1398 .runtime_suspend = fsi_runtime_nop,
1208 .runtime_resume = fsi_runtime_nop, 1399 .runtime_resume = fsi_runtime_nop,
1209}; 1400};
@@ -1224,16 +1415,20 @@ static struct fsi_core fsi2_core = {
1224 .int_st = CPU_INT_ST, 1415 .int_st = CPU_INT_ST,
1225 .iemsk = CPU_IEMSK, 1416 .iemsk = CPU_IEMSK,
1226 .imsk = CPU_IMSK, 1417 .imsk = CPU_IMSK,
1418 .a_mclk = A_MST_CTLR,
1419 .b_mclk = B_MST_CTLR,
1227}; 1420};
1228 1421
1229static struct platform_device_id fsi_id_table[] = { 1422static struct platform_device_id fsi_id_table[] = {
1230 { "sh_fsi", (kernel_ulong_t)&fsi1_core }, 1423 { "sh_fsi", (kernel_ulong_t)&fsi1_core },
1231 { "sh_fsi2", (kernel_ulong_t)&fsi2_core }, 1424 { "sh_fsi2", (kernel_ulong_t)&fsi2_core },
1425 {},
1232}; 1426};
1427MODULE_DEVICE_TABLE(platform, fsi_id_table);
1233 1428
1234static struct platform_driver fsi_driver = { 1429static struct platform_driver fsi_driver = {
1235 .driver = { 1430 .driver = {
1236 .name = "sh_fsi", 1431 .name = "fsi-pcm-audio",
1237 .pm = &fsi_pm_ops, 1432 .pm = &fsi_pm_ops,
1238 }, 1433 },
1239 .probe = fsi_probe, 1434 .probe = fsi_probe,
@@ -1250,9 +1445,11 @@ static void __exit fsi_mobile_exit(void)
1250{ 1445{
1251 platform_driver_unregister(&fsi_driver); 1446 platform_driver_unregister(&fsi_driver);
1252} 1447}
1448
1253module_init(fsi_mobile_init); 1449module_init(fsi_mobile_init);
1254module_exit(fsi_mobile_exit); 1450module_exit(fsi_mobile_exit);
1255 1451
1256MODULE_LICENSE("GPL"); 1452MODULE_LICENSE("GPL");
1257MODULE_DESCRIPTION("SuperH onchip FSI audio driver"); 1453MODULE_DESCRIPTION("SuperH onchip FSI audio driver");
1258MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>"); 1454MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");
1455MODULE_ALIAS("platform:fsi-pcm-audio");
diff --git a/sound/soc/sh/hac.c b/sound/soc/sh/hac.c
index 41db75af3c69..c87e3ff28a0a 100644
--- a/sound/soc/sh/hac.c
+++ b/sound/soc/sh/hac.c
@@ -239,8 +239,7 @@ static int hac_hw_params(struct snd_pcm_substream *substream,
239 struct snd_pcm_hw_params *params, 239 struct snd_pcm_hw_params *params,
240 struct snd_soc_dai *dai) 240 struct snd_soc_dai *dai)
241{ 241{
242 struct snd_soc_pcm_runtime *rtd = substream->private_data; 242 struct hac_priv *hac = &hac_cpu_data[dai->id];
243 struct hac_priv *hac = &hac_cpu_data[rtd->dai->cpu_dai->id];
244 int d = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1; 243 int d = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1;
245 244
246 switch (params->msbits) { 245 switch (params->msbits) {
@@ -271,10 +270,9 @@ static struct snd_soc_dai_ops hac_dai_ops = {
271 .hw_params = hac_hw_params, 270 .hw_params = hac_hw_params,
272}; 271};
273 272
274struct snd_soc_dai sh4_hac_dai[] = { 273static struct snd_soc_dai_driver sh4_hac_dai[] = {
275{ 274{
276 .name = "HAC0", 275 .name = "hac-dai.0",
277 .id = 0,
278 .ac97_control = 1, 276 .ac97_control = 1,
279 .playback = { 277 .playback = {
280 .rates = AC97_RATES, 278 .rates = AC97_RATES,
@@ -292,8 +290,7 @@ struct snd_soc_dai sh4_hac_dai[] = {
292}, 290},
293#ifdef CONFIG_CPU_SUBTYPE_SH7760 291#ifdef CONFIG_CPU_SUBTYPE_SH7760
294{ 292{
295 .name = "HAC1", 293 .name = "hac-dai.1",
296 .ac97_control = 1,
297 .id = 1, 294 .id = 1,
298 .playback = { 295 .playback = {
299 .rates = AC97_RATES, 296 .rates = AC97_RATES,
@@ -312,19 +309,40 @@ struct snd_soc_dai sh4_hac_dai[] = {
312}, 309},
313#endif 310#endif
314}; 311};
315EXPORT_SYMBOL_GPL(sh4_hac_dai);
316 312
317static int __init sh4_hac_init(void) 313static int __devinit hac_soc_platform_probe(struct platform_device *pdev)
314{
315 return snd_soc_register_dais(&pdev->dev, sh4_hac_dai,
316 ARRAY_SIZE(sh4_hac_dai));
317}
318
319static int __devexit hac_soc_platform_remove(struct platform_device *pdev)
320{
321 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sh4_hac_dai));
322 return 0;
323}
324
325static struct platform_driver hac_pcm_driver = {
326 .driver = {
327 .name = "hac-pcm-audio",
328 .owner = THIS_MODULE,
329 },
330
331 .probe = hac_soc_platform_probe,
332 .remove = __devexit_p(hac_soc_platform_remove),
333};
334
335static int __init sh4_hac_pcm_init(void)
318{ 336{
319 return snd_soc_register_dais(sh4_hac_dai, ARRAY_SIZE(sh4_hac_dai)); 337 return platform_driver_register(&hac_pcm_driver);
320} 338}
321module_init(sh4_hac_init); 339module_init(sh4_hac_pcm_init);
322 340
323static void __exit sh4_hac_exit(void) 341static void __exit sh4_hac_pcm_exit(void)
324{ 342{
325 snd_soc_unregister_dais(sh4_hac_dai, ARRAY_SIZE(sh4_hac_dai)); 343 platform_driver_unregister(&hac_pcm_driver);
326} 344}
327module_exit(sh4_hac_exit); 345module_exit(sh4_hac_pcm_exit);
328 346
329MODULE_LICENSE("GPL"); 347MODULE_LICENSE("GPL");
330MODULE_DESCRIPTION("SuperH onchip HAC (AC97) audio driver"); 348MODULE_DESCRIPTION("SuperH onchip HAC (AC97) audio driver");
diff --git a/sound/soc/sh/migor.c b/sound/soc/sh/migor.c
index 87e2b7fcbf17..6088a6a3238a 100644
--- a/sound/soc/sh/migor.c
+++ b/sound/soc/sh/migor.c
@@ -8,11 +8,11 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/clkdev.h>
11#include <linux/device.h> 12#include <linux/device.h>
12#include <linux/firmware.h> 13#include <linux/firmware.h>
13#include <linux/module.h> 14#include <linux/module.h>
14 15
15#include <asm/clkdev.h>
16#include <asm/clock.h> 16#include <asm/clock.h>
17 17
18#include <cpu/sh7722.h> 18#include <cpu/sh7722.h>
@@ -20,7 +20,6 @@
20#include <sound/core.h> 20#include <sound/core.h>
21#include <sound/pcm.h> 21#include <sound/pcm.h>
22#include <sound/soc.h> 22#include <sound/soc.h>
23#include <sound/soc-dapm.h>
24 23
25#include "../codecs/wm8978.h" 24#include "../codecs/wm8978.h"
26#include "siu.h" 25#include "siu.h"
@@ -51,7 +50,7 @@ static int migor_hw_params(struct snd_pcm_substream *substream,
51 struct snd_pcm_hw_params *params) 50 struct snd_pcm_hw_params *params)
52{ 51{
53 struct snd_soc_pcm_runtime *rtd = substream->private_data; 52 struct snd_soc_pcm_runtime *rtd = substream->private_data;
54 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 53 struct snd_soc_dai *codec_dai = rtd->codec_dai;
55 int ret; 54 int ret;
56 unsigned int rate = params_rate(params); 55 unsigned int rate = params_rate(params);
57 56
@@ -69,7 +68,7 @@ static int migor_hw_params(struct snd_pcm_substream *substream,
69 if (ret < 0) 68 if (ret < 0)
70 return ret; 69 return ret;
71 70
72 ret = snd_soc_dai_set_fmt(rtd->dai->cpu_dai, SND_SOC_DAIFMT_NB_IF | 71 ret = snd_soc_dai_set_fmt(rtd->cpu_dai, SND_SOC_DAIFMT_NB_IF |
73 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS); 72 SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS);
74 if (ret < 0) 73 if (ret < 0)
75 return ret; 74 return ret;
@@ -82,7 +81,7 @@ static int migor_hw_params(struct snd_pcm_substream *substream,
82 clk_set_rate(&siumckb_clk, codec_freq); 81 clk_set_rate(&siumckb_clk, codec_freq);
83 dev_dbg(codec_dai->dev, "%s: configure %luHz\n", __func__, codec_freq); 82 dev_dbg(codec_dai->dev, "%s: configure %luHz\n", __func__, codec_freq);
84 83
85 ret = snd_soc_dai_set_sysclk(rtd->dai->cpu_dai, SIU_CLKB_EXT, 84 ret = snd_soc_dai_set_sysclk(rtd->cpu_dai, SIU_CLKB_EXT,
86 codec_freq / 2, SND_SOC_CLOCK_IN); 85 codec_freq / 2, SND_SOC_CLOCK_IN);
87 86
88 if (!ret) 87 if (!ret)
@@ -94,7 +93,7 @@ static int migor_hw_params(struct snd_pcm_substream *substream,
94static int migor_hw_free(struct snd_pcm_substream *substream) 93static int migor_hw_free(struct snd_pcm_substream *substream)
95{ 94{
96 struct snd_soc_pcm_runtime *rtd = substream->private_data; 95 struct snd_soc_pcm_runtime *rtd = substream->private_data;
97 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 96 struct snd_soc_dai *codec_dai = rtd->codec_dai;
98 97
99 if (use_count) { 98 if (use_count) {
100 use_count--; 99 use_count--;
@@ -137,12 +136,15 @@ static const struct snd_soc_dapm_route audio_map[] = {
137 { "Mic Bias", NULL, "External Microphone" }, 136 { "Mic Bias", NULL, "External Microphone" },
138}; 137};
139 138
140static int migor_dai_init(struct snd_soc_codec *codec) 139static int migor_dai_init(struct snd_soc_pcm_runtime *rtd)
141{ 140{
142 snd_soc_dapm_new_controls(codec, migor_dapm_widgets, 141 struct snd_soc_codec *codec = rtd->codec;
142 struct snd_soc_dapm_context *dapm = &codec->dapm;
143
144 snd_soc_dapm_new_controls(dapm, migor_dapm_widgets,
143 ARRAY_SIZE(migor_dapm_widgets)); 145 ARRAY_SIZE(migor_dapm_widgets));
144 146
145 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 147 snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
146 148
147 return 0; 149 return 0;
148} 150}
@@ -151,8 +153,10 @@ static int migor_dai_init(struct snd_soc_codec *codec)
151static struct snd_soc_dai_link migor_dai = { 153static struct snd_soc_dai_link migor_dai = {
152 .name = "wm8978", 154 .name = "wm8978",
153 .stream_name = "WM8978", 155 .stream_name = "WM8978",
154 .cpu_dai = &siu_i2s_dai, 156 .cpu_dai_name = "siu-i2s-dai",
155 .codec_dai = &wm8978_dai, 157 .codec_dai_name = "wm8978-hifi",
158 .platform_name = "siu-pcm-audio",
159 .codec_name = "wm8978.0-001a",
156 .ops = &migor_dai_ops, 160 .ops = &migor_dai_ops,
157 .init = migor_dai_init, 161 .init = migor_dai_init,
158}; 162};
@@ -160,17 +164,10 @@ static struct snd_soc_dai_link migor_dai = {
160/* migor audio machine driver */ 164/* migor audio machine driver */
161static struct snd_soc_card snd_soc_migor = { 165static struct snd_soc_card snd_soc_migor = {
162 .name = "Migo-R", 166 .name = "Migo-R",
163 .platform = &siu_platform,
164 .dai_link = &migor_dai, 167 .dai_link = &migor_dai,
165 .num_links = 1, 168 .num_links = 1,
166}; 169};
167 170
168/* migor audio subsystem */
169static struct snd_soc_device migor_snd_devdata = {
170 .card = &snd_soc_migor,
171 .codec_dev = &soc_codec_dev_wm8978,
172};
173
174static struct platform_device *migor_snd_device; 171static struct platform_device *migor_snd_device;
175 172
176static int __init migor_init(void) 173static int __init migor_init(void)
@@ -195,9 +192,7 @@ static int __init migor_init(void)
195 goto epdevalloc; 192 goto epdevalloc;
196 } 193 }
197 194
198 platform_set_drvdata(migor_snd_device, &migor_snd_devdata); 195 platform_set_drvdata(migor_snd_device, &snd_soc_migor);
199
200 migor_snd_devdata.dev = &migor_snd_device->dev;
201 196
202 ret = platform_device_add(migor_snd_device); 197 ret = platform_device_add(migor_snd_device);
203 if (ret) 198 if (ret)
diff --git a/sound/soc/sh/sh7760-ac97.c b/sound/soc/sh/sh7760-ac97.c
index ce7f95b59de3..917d3ceadc9d 100644
--- a/sound/soc/sh/sh7760-ac97.c
+++ b/sound/soc/sh/sh7760-ac97.c
@@ -12,44 +12,37 @@
12#include <sound/core.h> 12#include <sound/core.h>
13#include <sound/pcm.h> 13#include <sound/pcm.h>
14#include <sound/soc.h> 14#include <sound/soc.h>
15#include <sound/soc-dapm.h>
16#include <asm/io.h> 15#include <asm/io.h>
17 16
18#include "../codecs/ac97.h"
19
20#define IPSEL 0xFE400034 17#define IPSEL 0xFE400034
21 18
22/* platform specific structs can be declared here */ 19/* platform specific structs can be declared here */
23extern struct snd_soc_dai sh4_hac_dai[2]; 20extern struct snd_soc_dai_driver sh4_hac_dai[2];
24extern struct snd_soc_platform sh7760_soc_platform; 21extern struct snd_soc_platform_driver sh7760_soc_platform;
25 22
26static int machine_init(struct snd_soc_codec *codec) 23static int machine_init(struct snd_soc_pcm_runtime *rtd)
27{ 24{
28 snd_soc_dapm_sync(codec); 25 snd_soc_dapm_sync(&rtd->codec->dapm);
29 return 0; 26 return 0;
30} 27}
31 28
32static struct snd_soc_dai_link sh7760_ac97_dai = { 29static struct snd_soc_dai_link sh7760_ac97_dai = {
33 .name = "AC97", 30 .name = "AC97",
34 .stream_name = "AC97 HiFi", 31 .stream_name = "AC97 HiFi",
35 .cpu_dai = &sh4_hac_dai[0], /* HAC0 */ 32 .cpu_dai_name = "hac-dai.0", /* HAC0 */
36 .codec_dai = &ac97_dai, 33 .codec_dai_name = "ac97-hifi",
34 .platform_name = "sh7760-pcm-audio",
35 .codec_name = "ac97-codec",
37 .init = machine_init, 36 .init = machine_init,
38 .ops = NULL, 37 .ops = NULL,
39}; 38};
40 39
41static struct snd_soc_card sh7760_ac97_soc_machine = { 40static struct snd_soc_card sh7760_ac97_soc_machine = {
42 .name = "SH7760 AC97", 41 .name = "SH7760 AC97",
43 .platform = &sh7760_soc_platform,
44 .dai_link = &sh7760_ac97_dai, 42 .dai_link = &sh7760_ac97_dai,
45 .num_links = 1, 43 .num_links = 1,
46}; 44};
47 45
48static struct snd_soc_device sh7760_ac97_snd_devdata = {
49 .card = &sh7760_ac97_soc_machine,
50 .codec_dev = &soc_codec_dev_ac97,
51};
52
53static struct platform_device *sh7760_ac97_snd_device; 46static struct platform_device *sh7760_ac97_snd_device;
54 47
55static int __init sh7760_ac97_init(void) 48static int __init sh7760_ac97_init(void)
@@ -58,8 +51,8 @@ static int __init sh7760_ac97_init(void)
58 unsigned short ipsel; 51 unsigned short ipsel;
59 52
60 /* enable both AC97 controllers in pinmux reg */ 53 /* enable both AC97 controllers in pinmux reg */
61 ipsel = ctrl_inw(IPSEL); 54 ipsel = __raw_readw(IPSEL);
62 ctrl_outw(ipsel | (3 << 10), IPSEL); 55 __raw_writew(ipsel | (3 << 10), IPSEL);
63 56
64 ret = -ENOMEM; 57 ret = -ENOMEM;
65 sh7760_ac97_snd_device = platform_device_alloc("soc-audio", -1); 58 sh7760_ac97_snd_device = platform_device_alloc("soc-audio", -1);
@@ -67,8 +60,7 @@ static int __init sh7760_ac97_init(void)
67 goto out; 60 goto out;
68 61
69 platform_set_drvdata(sh7760_ac97_snd_device, 62 platform_set_drvdata(sh7760_ac97_snd_device,
70 &sh7760_ac97_snd_devdata); 63 &sh7760_ac97_soc_machine);
71 sh7760_ac97_snd_devdata.dev = &sh7760_ac97_snd_device->dev;
72 ret = platform_device_add(sh7760_ac97_snd_device); 64 ret = platform_device_add(sh7760_ac97_snd_device);
73 65
74 if (ret) 66 if (ret)
diff --git a/sound/soc/sh/siu.h b/sound/soc/sh/siu.h
index 492b1cae24cc..83c3430ad797 100644
--- a/sound/soc/sh/siu.h
+++ b/sound/soc/sh/siu.h
@@ -75,7 +75,7 @@ struct siu_firmware {
75 75
76#include <sound/core.h> 76#include <sound/core.h>
77#include <sound/pcm.h> 77#include <sound/pcm.h>
78#include <sound/soc-dai.h> 78#include <sound/soc.h>
79 79
80#define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */ 80#define SIU_PERIOD_BYTES_MAX 8192 /* DMA transfer/period size */
81#define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */ 81#define SIU_PERIOD_BYTES_MIN 256 /* DMA transfer/period size */
@@ -98,7 +98,9 @@ enum {
98 SIU_CLKB_EXT 98 SIU_CLKB_EXT
99}; 99};
100 100
101struct device;
101struct siu_info { 102struct siu_info {
103 struct device *dev;
102 int port_id; 104 int port_id;
103 u32 __iomem *pram; 105 u32 __iomem *pram;
104 u32 __iomem *xram; 106 u32 __iomem *xram;
@@ -181,8 +183,8 @@ static inline u32 siu_read32(u32 __iomem *addr)
181#define SIU_BRGBSEL (0x108 / sizeof(u32)) 183#define SIU_BRGBSEL (0x108 / sizeof(u32))
182#define SIU_BRRB (0x10c / sizeof(u32)) 184#define SIU_BRRB (0x10c / sizeof(u32))
183 185
184extern struct snd_soc_platform siu_platform; 186extern struct snd_soc_platform_driver siu_platform;
185extern struct snd_soc_dai siu_i2s_dai; 187extern struct siu_info *siu_i2s_data;
186 188
187int siu_init_port(int port, struct siu_port **port_info, struct snd_card *card); 189int siu_init_port(int port, struct siu_port **port_info, struct snd_card *card);
188void siu_free_port(struct siu_port *port_info); 190void siu_free_port(struct siu_port *port_info);
diff --git a/sound/soc/sh/siu_dai.c b/sound/soc/sh/siu_dai.c
index eeed5edd722b..4973c2939d79 100644
--- a/sound/soc/sh/siu_dai.c
+++ b/sound/soc/sh/siu_dai.c
@@ -28,7 +28,7 @@
28#include <asm/siu.h> 28#include <asm/siu.h>
29 29
30#include <sound/control.h> 30#include <sound/control.h>
31#include <sound/soc-dai.h> 31#include <sound/soc.h>
32 32
33#include "siu.h" 33#include "siu.h"
34 34
@@ -71,6 +71,8 @@ struct port_flag {
71 struct format_flag capture; 71 struct format_flag capture;
72}; 72};
73 73
74struct siu_info *siu_i2s_data;
75
74static struct port_flag siu_flags[SIU_PORT_NUM] = { 76static struct port_flag siu_flags[SIU_PORT_NUM] = {
75 [SIU_PORT_A] = { 77 [SIU_PORT_A] = {
76 .playback = { 78 .playback = {
@@ -104,13 +106,13 @@ static struct port_flag siu_flags[SIU_PORT_NUM] = {
104 106
105static void siu_dai_start(struct siu_port *port_info) 107static void siu_dai_start(struct siu_port *port_info)
106{ 108{
107 struct siu_info *info = siu_i2s_dai.private_data; 109 struct siu_info *info = siu_i2s_data;
108 u32 __iomem *base = info->reg; 110 u32 __iomem *base = info->reg;
109 111
110 dev_dbg(port_info->pcm->card->dev, "%s\n", __func__); 112 dev_dbg(port_info->pcm->card->dev, "%s\n", __func__);
111 113
112 /* Turn on SIU clock */ 114 /* Turn on SIU clock */
113 pm_runtime_get_sync(siu_i2s_dai.dev); 115 pm_runtime_get_sync(info->dev);
114 116
115 /* Issue software reset to siu */ 117 /* Issue software reset to siu */
116 siu_write32(base + SIU_SRCTL, 0); 118 siu_write32(base + SIU_SRCTL, 0);
@@ -148,21 +150,21 @@ static void siu_dai_start(struct siu_port *port_info)
148 siu_write32(base + SIU_SBDVCB, port_info->capture.volume); 150 siu_write32(base + SIU_SBDVCB, port_info->capture.volume);
149} 151}
150 152
151static void siu_dai_stop(void) 153static void siu_dai_stop(struct siu_port *port_info)
152{ 154{
153 struct siu_info *info = siu_i2s_dai.private_data; 155 struct siu_info *info = siu_i2s_data;
154 u32 __iomem *base = info->reg; 156 u32 __iomem *base = info->reg;
155 157
156 /* SIU software reset */ 158 /* SIU software reset */
157 siu_write32(base + SIU_SRCTL, 0); 159 siu_write32(base + SIU_SRCTL, 0);
158 160
159 /* Turn off SIU clock */ 161 /* Turn off SIU clock */
160 pm_runtime_put_sync(siu_i2s_dai.dev); 162 pm_runtime_put_sync(info->dev);
161} 163}
162 164
163static void siu_dai_spbAselect(struct siu_port *port_info) 165static void siu_dai_spbAselect(struct siu_port *port_info)
164{ 166{
165 struct siu_info *info = siu_i2s_dai.private_data; 167 struct siu_info *info = siu_i2s_data;
166 struct siu_firmware *fw = &info->fw; 168 struct siu_firmware *fw = &info->fw;
167 u32 *ydef = fw->yram0; 169 u32 *ydef = fw->yram0;
168 u32 idx; 170 u32 idx;
@@ -187,7 +189,7 @@ static void siu_dai_spbAselect(struct siu_port *port_info)
187 189
188static void siu_dai_spbBselect(struct siu_port *port_info) 190static void siu_dai_spbBselect(struct siu_port *port_info)
189{ 191{
190 struct siu_info *info = siu_i2s_dai.private_data; 192 struct siu_info *info = siu_i2s_data;
191 struct siu_firmware *fw = &info->fw; 193 struct siu_firmware *fw = &info->fw;
192 u32 *ydef = fw->yram0; 194 u32 *ydef = fw->yram0;
193 u32 idx; 195 u32 idx;
@@ -207,7 +209,7 @@ static void siu_dai_spbBselect(struct siu_port *port_info)
207 209
208static void siu_dai_open(struct siu_stream *siu_stream) 210static void siu_dai_open(struct siu_stream *siu_stream)
209{ 211{
210 struct siu_info *info = siu_i2s_dai.private_data; 212 struct siu_info *info = siu_i2s_data;
211 u32 __iomem *base = info->reg; 213 u32 __iomem *base = info->reg;
212 u32 srctl, ifctl; 214 u32 srctl, ifctl;
213 215
@@ -238,7 +240,7 @@ static void siu_dai_open(struct siu_stream *siu_stream)
238 */ 240 */
239static void siu_dai_pcmdatapack(struct siu_stream *siu_stream) 241static void siu_dai_pcmdatapack(struct siu_stream *siu_stream)
240{ 242{
241 struct siu_info *info = siu_i2s_dai.private_data; 243 struct siu_info *info = siu_i2s_data;
242 u32 __iomem *base = info->reg; 244 u32 __iomem *base = info->reg;
243 u32 dpak; 245 u32 dpak;
244 246
@@ -258,7 +260,7 @@ static void siu_dai_pcmdatapack(struct siu_stream *siu_stream)
258 260
259static int siu_dai_spbstart(struct siu_port *port_info) 261static int siu_dai_spbstart(struct siu_port *port_info)
260{ 262{
261 struct siu_info *info = siu_i2s_dai.private_data; 263 struct siu_info *info = siu_i2s_data;
262 u32 __iomem *base = info->reg; 264 u32 __iomem *base = info->reg;
263 struct siu_firmware *fw = &info->fw; 265 struct siu_firmware *fw = &info->fw;
264 u32 *ydef = fw->yram0; 266 u32 *ydef = fw->yram0;
@@ -323,7 +325,7 @@ static int siu_dai_spbstart(struct siu_port *port_info)
323 325
324static void siu_dai_spbstop(struct siu_port *port_info) 326static void siu_dai_spbstop(struct siu_port *port_info)
325{ 327{
326 struct siu_info *info = siu_i2s_dai.private_data; 328 struct siu_info *info = siu_i2s_data;
327 u32 __iomem *base = info->reg; 329 u32 __iomem *base = info->reg;
328 330
329 siu_write32(base + SIU_SBACTIV, 0); 331 siu_write32(base + SIU_SBACTIV, 0);
@@ -402,7 +404,7 @@ static int siu_dai_put_volume(struct snd_kcontrol *kctrl,
402{ 404{
403 struct siu_port *port_info = snd_kcontrol_chip(kctrl); 405 struct siu_port *port_info = snd_kcontrol_chip(kctrl);
404 struct device *dev = port_info->pcm->card->dev; 406 struct device *dev = port_info->pcm->card->dev;
405 struct siu_info *info = siu_i2s_dai.private_data; 407 struct siu_info *info = siu_i2s_data;
406 u32 __iomem *base = info->reg; 408 u32 __iomem *base = info->reg;
407 u32 new_vol; 409 u32 new_vol;
408 u32 cur_vol; 410 u32 cur_vol;
@@ -510,7 +512,7 @@ void siu_free_port(struct siu_port *port_info)
510static int siu_dai_startup(struct snd_pcm_substream *substream, 512static int siu_dai_startup(struct snd_pcm_substream *substream,
511 struct snd_soc_dai *dai) 513 struct snd_soc_dai *dai)
512{ 514{
513 struct siu_info *info = siu_i2s_dai.private_data; 515 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
514 struct snd_pcm_runtime *rt = substream->runtime; 516 struct snd_pcm_runtime *rt = substream->runtime;
515 struct siu_port *port_info = siu_port_info(substream); 517 struct siu_port *port_info = siu_port_info(substream);
516 int ret; 518 int ret;
@@ -532,7 +534,7 @@ static int siu_dai_startup(struct snd_pcm_substream *substream,
532static void siu_dai_shutdown(struct snd_pcm_substream *substream, 534static void siu_dai_shutdown(struct snd_pcm_substream *substream,
533 struct snd_soc_dai *dai) 535 struct snd_soc_dai *dai)
534{ 536{
535 struct siu_info *info = siu_i2s_dai.private_data; 537 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
536 struct siu_port *port_info = siu_port_info(substream); 538 struct siu_port *port_info = siu_port_info(substream);
537 539
538 dev_dbg(substream->pcm->card->dev, "%s: port=%d@%p\n", __func__, 540 dev_dbg(substream->pcm->card->dev, "%s: port=%d@%p\n", __func__,
@@ -548,7 +550,7 @@ static void siu_dai_shutdown(struct snd_pcm_substream *substream,
548 /* during stmread or stmwrite ? */ 550 /* during stmread or stmwrite ? */
549 BUG_ON(port_info->playback.rw_flg || port_info->capture.rw_flg); 551 BUG_ON(port_info->playback.rw_flg || port_info->capture.rw_flg);
550 siu_dai_spbstop(port_info); 552 siu_dai_spbstop(port_info);
551 siu_dai_stop(); 553 siu_dai_stop(port_info);
552 } 554 }
553} 555}
554 556
@@ -556,7 +558,7 @@ static void siu_dai_shutdown(struct snd_pcm_substream *substream,
556static int siu_dai_prepare(struct snd_pcm_substream *substream, 558static int siu_dai_prepare(struct snd_pcm_substream *substream,
557 struct snd_soc_dai *dai) 559 struct snd_soc_dai *dai)
558{ 560{
559 struct siu_info *info = siu_i2s_dai.private_data; 561 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
560 struct snd_pcm_runtime *rt = substream->runtime; 562 struct snd_pcm_runtime *rt = substream->runtime;
561 struct siu_port *port_info = siu_port_info(substream); 563 struct siu_port *port_info = siu_port_info(substream);
562 struct siu_stream *siu_stream; 564 struct siu_stream *siu_stream;
@@ -605,7 +607,7 @@ fail:
605static int siu_dai_set_fmt(struct snd_soc_dai *dai, 607static int siu_dai_set_fmt(struct snd_soc_dai *dai,
606 unsigned int fmt) 608 unsigned int fmt)
607{ 609{
608 struct siu_info *info = siu_i2s_dai.private_data; 610 struct siu_info *info = snd_soc_dai_get_drvdata(dai);
609 u32 __iomem *base = info->reg; 611 u32 __iomem *base = info->reg;
610 u32 ifctl; 612 u32 ifctl;
611 613
@@ -671,21 +673,37 @@ static int siu_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
671 return -EINVAL; 673 return -EINVAL;
672 } 674 }
673 675
674 siu_clk = clk_get(siu_i2s_dai.dev, siu_name); 676 siu_clk = clk_get(dai->dev, siu_name);
675 if (IS_ERR(siu_clk)) 677 if (IS_ERR(siu_clk)) {
678 dev_err(dai->dev, "%s: cannot get a SIU clock: %ld\n", __func__,
679 PTR_ERR(siu_clk));
676 return PTR_ERR(siu_clk); 680 return PTR_ERR(siu_clk);
681 }
682
683 parent_clk = clk_get(dai->dev, parent_name);
684 if (IS_ERR(parent_clk)) {
685 ret = PTR_ERR(parent_clk);
686 dev_err(dai->dev, "cannot get a SIU clock parent: %d\n", ret);
687 goto epclkget;
688 }
677 689
678 parent_clk = clk_get(siu_i2s_dai.dev, parent_name); 690 ret = clk_set_parent(siu_clk, parent_clk);
679 if (!IS_ERR(parent_clk)) { 691 if (ret < 0) {
680 ret = clk_set_parent(siu_clk, parent_clk); 692 dev_err(dai->dev, "cannot reparent the SIU clock: %d\n", ret);
681 if (!ret) 693 goto eclksetp;
682 clk_set_rate(siu_clk, freq);
683 clk_put(parent_clk);
684 } 694 }
685 695
696 ret = clk_set_rate(siu_clk, freq);
697 if (ret < 0)
698 dev_err(dai->dev, "cannot set SIU clock rate: %d\n", ret);
699
700 /* TODO: when clkdev gets reference counting we'll move these to siu_dai_shutdown() */
701eclksetp:
702 clk_put(parent_clk);
703epclkget:
686 clk_put(siu_clk); 704 clk_put(siu_clk);
687 705
688 return 0; 706 return ret;
689} 707}
690 708
691static struct snd_soc_dai_ops siu_dai_ops = { 709static struct snd_soc_dai_ops siu_dai_ops = {
@@ -696,9 +714,8 @@ static struct snd_soc_dai_ops siu_dai_ops = {
696 .set_fmt = siu_dai_set_fmt, 714 .set_fmt = siu_dai_set_fmt,
697}; 715};
698 716
699struct snd_soc_dai siu_i2s_dai = { 717static struct snd_soc_dai_driver siu_i2s_dai = {
700 .name = "sh-siu", 718 .name = "siu-i2s-dai",
701 .id = 0,
702 .playback = { 719 .playback = {
703 .channels_min = 2, 720 .channels_min = 2,
704 .channels_max = 2, 721 .channels_max = 2,
@@ -713,7 +730,6 @@ struct snd_soc_dai siu_i2s_dai = {
713 }, 730 },
714 .ops = &siu_dai_ops, 731 .ops = &siu_dai_ops,
715}; 732};
716EXPORT_SYMBOL_GPL(siu_i2s_dai);
717 733
718static int __devinit siu_probe(struct platform_device *pdev) 734static int __devinit siu_probe(struct platform_device *pdev)
719{ 735{
@@ -725,6 +741,8 @@ static int __devinit siu_probe(struct platform_device *pdev)
725 info = kmalloc(sizeof(*info), GFP_KERNEL); 741 info = kmalloc(sizeof(*info), GFP_KERNEL);
726 if (!info) 742 if (!info)
727 return -ENOMEM; 743 return -ENOMEM;
744 siu_i2s_data = info;
745 info->dev = &pdev->dev;
728 746
729 ret = request_firmware(&fw_entry, "siu_spb.bin", &pdev->dev); 747 ret = request_firmware(&fw_entry, "siu_spb.bin", &pdev->dev);
730 if (ret) 748 if (ret)
@@ -767,14 +785,14 @@ static int __devinit siu_probe(struct platform_device *pdev)
767 if (!info->reg) 785 if (!info->reg)
768 goto emapreg; 786 goto emapreg;
769 787
770 siu_i2s_dai.dev = &pdev->dev; 788 dev_set_drvdata(&pdev->dev, info);
771 siu_i2s_dai.private_data = info;
772 789
773 ret = snd_soc_register_dais(&siu_i2s_dai, 1); 790 /* register using ARRAY version so we can keep dai name */
791 ret = snd_soc_register_dais(&pdev->dev, &siu_i2s_dai, 1);
774 if (ret < 0) 792 if (ret < 0)
775 goto edaiinit; 793 goto edaiinit;
776 794
777 ret = snd_soc_register_platform(&siu_platform); 795 ret = snd_soc_register_platform(&pdev->dev, &siu_platform);
778 if (ret < 0) 796 if (ret < 0)
779 goto esocregp; 797 goto esocregp;
780 798
@@ -783,7 +801,7 @@ static int __devinit siu_probe(struct platform_device *pdev)
783 return ret; 801 return ret;
784 802
785esocregp: 803esocregp:
786 snd_soc_unregister_dais(&siu_i2s_dai, 1); 804 snd_soc_unregister_dai(&pdev->dev);
787edaiinit: 805edaiinit:
788 iounmap(info->reg); 806 iounmap(info->reg);
789emapreg: 807emapreg:
@@ -804,13 +822,13 @@ ereqfw:
804 822
805static int __devexit siu_remove(struct platform_device *pdev) 823static int __devexit siu_remove(struct platform_device *pdev)
806{ 824{
807 struct siu_info *info = siu_i2s_dai.private_data; 825 struct siu_info *info = dev_get_drvdata(&pdev->dev);
808 struct resource *res; 826 struct resource *res;
809 827
810 pm_runtime_disable(&pdev->dev); 828 pm_runtime_disable(&pdev->dev);
811 829
812 snd_soc_unregister_platform(&siu_platform); 830 snd_soc_unregister_platform(&pdev->dev);
813 snd_soc_unregister_dais(&siu_i2s_dai, 1); 831 snd_soc_unregister_dai(&pdev->dev);
814 832
815 iounmap(info->reg); 833 iounmap(info->reg);
816 iounmap(info->yram); 834 iounmap(info->yram);
@@ -826,7 +844,8 @@ static int __devexit siu_remove(struct platform_device *pdev)
826 844
827static struct platform_driver siu_driver = { 845static struct platform_driver siu_driver = {
828 .driver = { 846 .driver = {
829 .name = "sh_siu", 847 .owner = THIS_MODULE,
848 .name = "siu-pcm-audio",
830 }, 849 },
831 .probe = siu_probe, 850 .probe = siu_probe,
832 .remove = __devexit_p(siu_remove), 851 .remove = __devexit_p(siu_remove),
diff --git a/sound/soc/sh/siu_pcm.c b/sound/soc/sh/siu_pcm.c
index 36170be15aa7..a423babcf145 100644
--- a/sound/soc/sh/siu_pcm.c
+++ b/sound/soc/sh/siu_pcm.c
@@ -29,7 +29,7 @@
29#include <sound/core.h> 29#include <sound/core.h>
30#include <sound/pcm.h> 30#include <sound/pcm.h>
31#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
32#include <sound/soc-dai.h> 32#include <sound/soc.h>
33 33
34#include <asm/siu.h> 34#include <asm/siu.h>
35 35
@@ -48,7 +48,7 @@ struct siu_port *siu_ports[SIU_PORT_NUM];
48/* transfersize is number of u32 dma transfers per period */ 48/* transfersize is number of u32 dma transfers per period */
49static int siu_pcm_stmwrite_stop(struct siu_port *port_info) 49static int siu_pcm_stmwrite_stop(struct siu_port *port_info)
50{ 50{
51 struct siu_info *info = siu_i2s_dai.private_data; 51 struct siu_info *info = siu_i2s_data;
52 u32 __iomem *base = info->reg; 52 u32 __iomem *base = info->reg;
53 struct siu_stream *siu_stream = &port_info->playback; 53 struct siu_stream *siu_stream = &port_info->playback;
54 u32 stfifo; 54 u32 stfifo;
@@ -114,7 +114,7 @@ static void siu_dma_tx_complete(void *arg)
114static int siu_pcm_wr_set(struct siu_port *port_info, 114static int siu_pcm_wr_set(struct siu_port *port_info,
115 dma_addr_t buff, u32 size) 115 dma_addr_t buff, u32 size)
116{ 116{
117 struct siu_info *info = siu_i2s_dai.private_data; 117 struct siu_info *info = siu_i2s_data;
118 u32 __iomem *base = info->reg; 118 u32 __iomem *base = info->reg;
119 struct siu_stream *siu_stream = &port_info->playback; 119 struct siu_stream *siu_stream = &port_info->playback;
120 struct snd_pcm_substream *substream = siu_stream->substream; 120 struct snd_pcm_substream *substream = siu_stream->substream;
@@ -127,6 +127,7 @@ static int siu_pcm_wr_set(struct siu_port *port_info,
127 sg_init_table(&sg, 1); 127 sg_init_table(&sg, 1);
128 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buff)), 128 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buff)),
129 size, offset_in_page(buff)); 129 size, offset_in_page(buff));
130 sg_dma_len(&sg) = size;
130 sg_dma_address(&sg) = buff; 131 sg_dma_address(&sg) = buff;
131 132
132 desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan, 133 desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan,
@@ -161,7 +162,7 @@ static int siu_pcm_wr_set(struct siu_port *port_info,
161static int siu_pcm_rd_set(struct siu_port *port_info, 162static int siu_pcm_rd_set(struct siu_port *port_info,
162 dma_addr_t buff, size_t size) 163 dma_addr_t buff, size_t size)
163{ 164{
164 struct siu_info *info = siu_i2s_dai.private_data; 165 struct siu_info *info = siu_i2s_data;
165 u32 __iomem *base = info->reg; 166 u32 __iomem *base = info->reg;
166 struct siu_stream *siu_stream = &port_info->capture; 167 struct siu_stream *siu_stream = &port_info->capture;
167 struct snd_pcm_substream *substream = siu_stream->substream; 168 struct snd_pcm_substream *substream = siu_stream->substream;
@@ -176,6 +177,7 @@ static int siu_pcm_rd_set(struct siu_port *port_info,
176 sg_init_table(&sg, 1); 177 sg_init_table(&sg, 1);
177 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buff)), 178 sg_set_page(&sg, pfn_to_page(PFN_DOWN(buff)),
178 size, offset_in_page(buff)); 179 size, offset_in_page(buff));
180 sg_dma_len(&sg) = size;
179 sg_dma_address(&sg) = buff; 181 sg_dma_address(&sg) = buff;
180 182
181 desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan, 183 desc = siu_stream->chan->device->device_prep_slave_sg(siu_stream->chan,
@@ -270,7 +272,7 @@ static int siu_pcm_stmread_start(struct siu_port *port_info)
270 272
271static int siu_pcm_stmread_stop(struct siu_port *port_info) 273static int siu_pcm_stmread_stop(struct siu_port *port_info)
272{ 274{
273 struct siu_info *info = siu_i2s_dai.private_data; 275 struct siu_info *info = siu_i2s_data;
274 u32 __iomem *base = info->reg; 276 u32 __iomem *base = info->reg;
275 struct siu_stream *siu_stream = &port_info->capture; 277 struct siu_stream *siu_stream = &port_info->capture;
276 struct device *dev = siu_stream->substream->pcm->card->dev; 278 struct device *dev = siu_stream->substream->pcm->card->dev;
@@ -294,7 +296,7 @@ static int siu_pcm_stmread_stop(struct siu_port *port_info)
294static int siu_pcm_hw_params(struct snd_pcm_substream *ss, 296static int siu_pcm_hw_params(struct snd_pcm_substream *ss,
295 struct snd_pcm_hw_params *hw_params) 297 struct snd_pcm_hw_params *hw_params)
296{ 298{
297 struct siu_info *info = siu_i2s_dai.private_data; 299 struct siu_info *info = siu_i2s_data;
298 struct device *dev = ss->pcm->card->dev; 300 struct device *dev = ss->pcm->card->dev;
299 int ret; 301 int ret;
300 302
@@ -309,7 +311,7 @@ static int siu_pcm_hw_params(struct snd_pcm_substream *ss,
309 311
310static int siu_pcm_hw_free(struct snd_pcm_substream *ss) 312static int siu_pcm_hw_free(struct snd_pcm_substream *ss)
311{ 313{
312 struct siu_info *info = siu_i2s_dai.private_data; 314 struct siu_info *info = siu_i2s_data;
313 struct siu_port *port_info = siu_port_info(ss); 315 struct siu_port *port_info = siu_port_info(ss);
314 struct device *dev = ss->pcm->card->dev; 316 struct device *dev = ss->pcm->card->dev;
315 struct siu_stream *siu_stream; 317 struct siu_stream *siu_stream;
@@ -340,11 +342,12 @@ static bool filter(struct dma_chan *chan, void *slave)
340static int siu_pcm_open(struct snd_pcm_substream *ss) 342static int siu_pcm_open(struct snd_pcm_substream *ss)
341{ 343{
342 /* Playback / Capture */ 344 /* Playback / Capture */
343 struct siu_info *info = siu_i2s_dai.private_data; 345 struct snd_soc_pcm_runtime *rtd = ss->private_data;
346 struct siu_platform *pdata = rtd->platform->dev->platform_data;
347 struct siu_info *info = siu_i2s_data;
344 struct siu_port *port_info = siu_port_info(ss); 348 struct siu_port *port_info = siu_port_info(ss);
345 struct siu_stream *siu_stream; 349 struct siu_stream *siu_stream;
346 u32 port = info->port_id; 350 u32 port = info->port_id;
347 struct siu_platform *pdata = siu_i2s_dai.dev->platform_data;
348 struct device *dev = ss->pcm->card->dev; 351 struct device *dev = ss->pcm->card->dev;
349 dma_cap_mask_t mask; 352 dma_cap_mask_t mask;
350 struct sh_dmae_slave *param; 353 struct sh_dmae_slave *param;
@@ -381,7 +384,7 @@ static int siu_pcm_open(struct snd_pcm_substream *ss)
381 384
382static int siu_pcm_close(struct snd_pcm_substream *ss) 385static int siu_pcm_close(struct snd_pcm_substream *ss)
383{ 386{
384 struct siu_info *info = siu_i2s_dai.private_data; 387 struct siu_info *info = siu_i2s_data;
385 struct device *dev = ss->pcm->card->dev; 388 struct device *dev = ss->pcm->card->dev;
386 struct siu_port *port_info = siu_port_info(ss); 389 struct siu_port *port_info = siu_port_info(ss);
387 struct siu_stream *siu_stream; 390 struct siu_stream *siu_stream;
@@ -403,7 +406,7 @@ static int siu_pcm_close(struct snd_pcm_substream *ss)
403 406
404static int siu_pcm_prepare(struct snd_pcm_substream *ss) 407static int siu_pcm_prepare(struct snd_pcm_substream *ss)
405{ 408{
406 struct siu_info *info = siu_i2s_dai.private_data; 409 struct siu_info *info = siu_i2s_data;
407 struct siu_port *port_info = siu_port_info(ss); 410 struct siu_port *port_info = siu_port_info(ss);
408 struct device *dev = ss->pcm->card->dev; 411 struct device *dev = ss->pcm->card->dev;
409 struct snd_pcm_runtime *rt = ss->runtime; 412 struct snd_pcm_runtime *rt = ss->runtime;
@@ -449,7 +452,7 @@ static int siu_pcm_prepare(struct snd_pcm_substream *ss)
449 452
450static int siu_pcm_trigger(struct snd_pcm_substream *ss, int cmd) 453static int siu_pcm_trigger(struct snd_pcm_substream *ss, int cmd)
451{ 454{
452 struct siu_info *info = siu_i2s_dai.private_data; 455 struct siu_info *info = siu_i2s_data;
453 struct device *dev = ss->pcm->card->dev; 456 struct device *dev = ss->pcm->card->dev;
454 struct siu_port *port_info = siu_port_info(ss); 457 struct siu_port *port_info = siu_port_info(ss);
455 int ret; 458 int ret;
@@ -492,7 +495,7 @@ static int siu_pcm_trigger(struct snd_pcm_substream *ss, int cmd)
492static snd_pcm_uframes_t siu_pcm_pointer_dma(struct snd_pcm_substream *ss) 495static snd_pcm_uframes_t siu_pcm_pointer_dma(struct snd_pcm_substream *ss)
493{ 496{
494 struct device *dev = ss->pcm->card->dev; 497 struct device *dev = ss->pcm->card->dev;
495 struct siu_info *info = siu_i2s_dai.private_data; 498 struct siu_info *info = siu_i2s_data;
496 u32 __iomem *base = info->reg; 499 u32 __iomem *base = info->reg;
497 struct siu_port *port_info = siu_port_info(ss); 500 struct siu_port *port_info = siu_port_info(ss);
498 struct snd_pcm_runtime *rt = ss->runtime; 501 struct snd_pcm_runtime *rt = ss->runtime;
@@ -528,7 +531,7 @@ static int siu_pcm_new(struct snd_card *card, struct snd_soc_dai *dai,
528 struct snd_pcm *pcm) 531 struct snd_pcm *pcm)
529{ 532{
530 /* card->dev == socdev->dev, see snd_soc_new_pcms() */ 533 /* card->dev == socdev->dev, see snd_soc_new_pcms() */
531 struct siu_info *info = siu_i2s_dai.private_data; 534 struct siu_info *info = siu_i2s_data;
532 struct platform_device *pdev = to_platform_device(card->dev); 535 struct platform_device *pdev = to_platform_device(card->dev);
533 int ret; 536 int ret;
534 int i; 537 int i;
@@ -605,9 +608,8 @@ static struct snd_pcm_ops siu_pcm_ops = {
605 .pointer = siu_pcm_pointer_dma, 608 .pointer = siu_pcm_pointer_dma,
606}; 609};
607 610
608struct snd_soc_platform siu_platform = { 611struct snd_soc_platform_driver siu_platform = {
609 .name = "siu-audio", 612 .ops = &siu_pcm_ops,
610 .pcm_ops = &siu_pcm_ops,
611 .pcm_new = siu_pcm_new, 613 .pcm_new = siu_pcm_new,
612 .pcm_free = siu_pcm_free, 614 .pcm_free = siu_pcm_free,
613}; 615};
diff --git a/sound/soc/sh/ssi.c b/sound/soc/sh/ssi.c
index b378096cadb1..05192d97b377 100644
--- a/sound/soc/sh/ssi.c
+++ b/sound/soc/sh/ssi.c
@@ -92,8 +92,7 @@ struct ssi_priv {
92static int ssi_startup(struct snd_pcm_substream *substream, 92static int ssi_startup(struct snd_pcm_substream *substream,
93 struct snd_soc_dai *dai) 93 struct snd_soc_dai *dai)
94{ 94{
95 struct snd_soc_pcm_runtime *rtd = substream->private_data; 95 struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
96 struct ssi_priv *ssi = &ssi_cpu_data[rtd->dai->cpu_dai->id];
97 if (ssi->inuse) { 96 if (ssi->inuse) {
98 pr_debug("ssi: already in use!\n"); 97 pr_debug("ssi: already in use!\n");
99 return -EBUSY; 98 return -EBUSY;
@@ -105,8 +104,7 @@ static int ssi_startup(struct snd_pcm_substream *substream,
105static void ssi_shutdown(struct snd_pcm_substream *substream, 104static void ssi_shutdown(struct snd_pcm_substream *substream,
106 struct snd_soc_dai *dai) 105 struct snd_soc_dai *dai)
107{ 106{
108 struct snd_soc_pcm_runtime *rtd = substream->private_data; 107 struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
109 struct ssi_priv *ssi = &ssi_cpu_data[rtd->dai->cpu_dai->id];
110 108
111 ssi->inuse = 0; 109 ssi->inuse = 0;
112} 110}
@@ -114,8 +112,7 @@ static void ssi_shutdown(struct snd_pcm_substream *substream,
114static int ssi_trigger(struct snd_pcm_substream *substream, int cmd, 112static int ssi_trigger(struct snd_pcm_substream *substream, int cmd,
115 struct snd_soc_dai *dai) 113 struct snd_soc_dai *dai)
116{ 114{
117 struct snd_soc_pcm_runtime *rtd = substream->private_data; 115 struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
118 struct ssi_priv *ssi = &ssi_cpu_data[rtd->dai->cpu_dai->id];
119 116
120 switch (cmd) { 117 switch (cmd) {
121 case SNDRV_PCM_TRIGGER_START: 118 case SNDRV_PCM_TRIGGER_START:
@@ -135,8 +132,7 @@ static int ssi_hw_params(struct snd_pcm_substream *substream,
135 struct snd_pcm_hw_params *params, 132 struct snd_pcm_hw_params *params,
136 struct snd_soc_dai *dai) 133 struct snd_soc_dai *dai)
137{ 134{
138 struct snd_soc_pcm_runtime *rtd = substream->private_data; 135 struct ssi_priv *ssi = &ssi_cpu_data[dai->id];
139 struct ssi_priv *ssi = &ssi_cpu_data[rtd->dai->cpu_dai->id];
140 unsigned long ssicr = SSIREG(SSICR); 136 unsigned long ssicr = SSIREG(SSICR);
141 unsigned int bits, channels, swl, recv, i; 137 unsigned int bits, channels, swl, recv, i;
142 138
@@ -346,10 +342,9 @@ static struct snd_soc_dai_ops ssi_dai_ops = {
346 .set_fmt = ssi_set_fmt, 342 .set_fmt = ssi_set_fmt,
347}; 343};
348 344
349struct snd_soc_dai sh4_ssi_dai[] = { 345struct snd_soc_dai_driver sh4_ssi_dai[] = {
350{ 346{
351 .name = "SSI0", 347 .name = "ssi-dai.0",
352 .id = 0,
353 .playback = { 348 .playback = {
354 .rates = SSI_RATES, 349 .rates = SSI_RATES,
355 .formats = SSI_FMTS, 350 .formats = SSI_FMTS,
@@ -366,8 +361,7 @@ struct snd_soc_dai sh4_ssi_dai[] = {
366}, 361},
367#ifdef CONFIG_CPU_SUBTYPE_SH7760 362#ifdef CONFIG_CPU_SUBTYPE_SH7760
368{ 363{
369 .name = "SSI1", 364 .name = "ssi-dai.1",
370 .id = 1,
371 .playback = { 365 .playback = {
372 .rates = SSI_RATES, 366 .rates = SSI_RATES,
373 .formats = SSI_FMTS, 367 .formats = SSI_FMTS,
@@ -384,19 +378,40 @@ struct snd_soc_dai sh4_ssi_dai[] = {
384}, 378},
385#endif 379#endif
386}; 380};
387EXPORT_SYMBOL_GPL(sh4_ssi_dai);
388 381
389static int __init sh4_ssi_init(void) 382static int __devinit sh4_soc_dai_probe(struct platform_device *pdev)
383{
384 return snd_soc_register_dais(&pdev->dev, sh4_ssi_dai,
385 ARRAY_SIZE(sh4_ssi_dai));
386}
387
388static int __devexit sh4_soc_dai_remove(struct platform_device *pdev)
389{
390 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(sh4_ssi_dai));
391 return 0;
392}
393
394static struct platform_driver sh4_ssi_driver = {
395 .driver = {
396 .name = "sh4-ssi-dai",
397 .owner = THIS_MODULE,
398 },
399
400 .probe = sh4_soc_dai_probe,
401 .remove = __devexit_p(sh4_soc_dai_remove),
402};
403
404static int __init snd_sh4_ssi_init(void)
390{ 405{
391 return snd_soc_register_dais(sh4_ssi_dai, ARRAY_SIZE(sh4_ssi_dai)); 406 return platform_driver_register(&sh4_ssi_driver);
392} 407}
393module_init(sh4_ssi_init); 408module_init(snd_sh4_ssi_init);
394 409
395static void __exit sh4_ssi_exit(void) 410static void __exit snd_sh4_ssi_exit(void)
396{ 411{
397 snd_soc_unregister_dais(sh4_ssi_dai, ARRAY_SIZE(sh4_ssi_dai)); 412 platform_driver_unregister(&sh4_ssi_driver);
398} 413}
399module_exit(sh4_ssi_exit); 414module_exit(snd_sh4_ssi_exit);
400 415
401MODULE_LICENSE("GPL"); 416MODULE_LICENSE("GPL");
402MODULE_DESCRIPTION("SuperH onchip SSI (I2S) audio driver"); 417MODULE_DESCRIPTION("SuperH onchip SSI (I2S) audio driver");