blob: dff64b95f5dcf11671c282f850ea83af520c365b [file] [log] [blame]
Kuninori Morimotob8e583f2009-08-21 09:42:59 +09001/*
2 * FSI-AK464x sound support for ms7724se
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@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
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090012#include <linux/platform_device.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040013#include <linux/module.h>
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090014#include <sound/sh_fsi.h>
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090015
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090016struct fsi_ak4642_data {
17 const char *name;
Kuninori Morimoto806bfed2010-12-01 15:50:52 +090018 const char *card;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090019 const char *cpu_dai;
20 const char *codec;
21 const char *platform;
Kuninori Morimotoa1934362011-01-12 15:32:07 +090022 int id;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090023};
24
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000025static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090026{
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090027 struct snd_soc_dai *codec = rtd->codec_dai;
28 struct snd_soc_dai *cpu = rtd->cpu_dai;
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090029 int ret;
30
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090031 ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J |
32 SND_SOC_DAIFMT_CBM_CFM);
Kuninori Morimoto0643ce82010-03-15 18:10:50 +090033 if (ret < 0)
34 return ret;
35
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090036 ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0);
37 if (ret < 0)
38 return ret;
39
Kuninori Morimotof17c13c2011-01-24 10:43:19 +090040 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J |
41 SND_SOC_DAIFMT_CBS_CFS);
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090042
43 return ret;
44}
45
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090046static struct snd_soc_dai_link fsi_dai_link = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000047 .codec_dai_name = "ak4642-hifi",
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090048 .init = fsi_ak4642_dai_init,
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090049};
50
51static struct snd_soc_card fsi_soc_card = {
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090052 .dai_link = &fsi_dai_link,
53 .num_links = 1,
54};
55
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090056static struct platform_device *fsi_snd_device;
57
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090058static int fsi_ak4642_probe(struct platform_device *pdev)
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090059{
60 int ret = -ENOMEM;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090061 const struct platform_device_id *id_entry;
62 struct fsi_ak4642_data *pdata;
63
64 id_entry = pdev->id_entry;
65 if (!id_entry) {
66 dev_err(&pdev->dev, "unknown fsi ak4642\n");
67 return -ENODEV;
68 }
69
70 pdata = (struct fsi_ak4642_data *)id_entry->driver_data;
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090071
Kuninori Morimotoa1934362011-01-12 15:32:07 +090072 fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090073 if (!fsi_snd_device)
74 goto out;
75
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090076 fsi_dai_link.name = pdata->name;
77 fsi_dai_link.stream_name = pdata->name;
78 fsi_dai_link.cpu_dai_name = pdata->cpu_dai;
79 fsi_dai_link.platform_name = pdata->platform;
80 fsi_dai_link.codec_name = pdata->codec;
Kuninori Morimoto806bfed2010-12-01 15:50:52 +090081 fsi_soc_card.name = pdata->card;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090082
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000083 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090084 ret = platform_device_add(fsi_snd_device);
85
86 if (ret)
87 platform_device_put(fsi_snd_device);
88
89out:
90 return ret;
91}
92
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090093static int fsi_ak4642_remove(struct platform_device *pdev)
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090094{
95 platform_device_unregister(fsi_snd_device);
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090096 return 0;
97}
98
99static struct fsi_ak4642_data fsi_a_ak4642 = {
100 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700101 .card = "FSIA-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900102 .cpu_dai = "fsia-dai",
103 .codec = "ak4642-codec.0-0012",
104 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900105 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900106};
107
108static struct fsi_ak4642_data fsi_b_ak4642 = {
109 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700110 .card = "FSIB-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900111 .cpu_dai = "fsib-dai",
112 .codec = "ak4642-codec.0-0012",
113 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900114 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900115};
116
117static struct fsi_ak4642_data fsi_a_ak4643 = {
118 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700119 .card = "FSIA-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900120 .cpu_dai = "fsia-dai",
121 .codec = "ak4642-codec.0-0013",
122 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900123 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900124};
125
126static struct fsi_ak4642_data fsi_b_ak4643 = {
127 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700128 .card = "FSIB-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900129 .cpu_dai = "fsib-dai",
130 .codec = "ak4642-codec.0-0013",
131 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900132 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900133};
134
135static struct fsi_ak4642_data fsi2_a_ak4642 = {
136 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700137 .card = "FSI2A-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900138 .cpu_dai = "fsia-dai",
139 .codec = "ak4642-codec.0-0012",
140 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900141 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900142};
143
144static struct fsi_ak4642_data fsi2_b_ak4642 = {
145 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700146 .card = "FSI2B-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900147 .cpu_dai = "fsib-dai",
148 .codec = "ak4642-codec.0-0012",
149 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900150 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900151};
152
153static struct fsi_ak4642_data fsi2_a_ak4643 = {
154 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700155 .card = "FSI2A-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900156 .cpu_dai = "fsia-dai",
157 .codec = "ak4642-codec.0-0013",
158 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900159 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900160};
161
162static struct fsi_ak4642_data fsi2_b_ak4643 = {
163 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700164 .card = "FSI2B-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900165 .cpu_dai = "fsib-dai",
166 .codec = "ak4642-codec.0-0013",
167 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900168 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900169};
170
171static struct platform_device_id fsi_id_table[] = {
172 /* FSI */
173 { "sh_fsi_a_ak4642", (kernel_ulong_t)&fsi_a_ak4642 },
174 { "sh_fsi_b_ak4642", (kernel_ulong_t)&fsi_b_ak4642 },
175 { "sh_fsi_a_ak4643", (kernel_ulong_t)&fsi_a_ak4643 },
176 { "sh_fsi_b_ak4643", (kernel_ulong_t)&fsi_b_ak4643 },
177
178 /* FSI 2 */
179 { "sh_fsi2_a_ak4642", (kernel_ulong_t)&fsi2_a_ak4642 },
180 { "sh_fsi2_b_ak4642", (kernel_ulong_t)&fsi2_b_ak4642 },
181 { "sh_fsi2_a_ak4643", (kernel_ulong_t)&fsi2_a_ak4643 },
182 { "sh_fsi2_b_ak4643", (kernel_ulong_t)&fsi2_b_ak4643 },
183 {},
184};
185
186static struct platform_driver fsi_ak4642 = {
187 .driver = {
188 .name = "fsi-ak4642-audio",
189 },
190 .probe = fsi_ak4642_probe,
191 .remove = fsi_ak4642_remove,
192 .id_table = fsi_id_table,
193};
194
195static int __init fsi_ak4642_init(void)
196{
197 return platform_driver_register(&fsi_ak4642);
198}
199
200static void __exit fsi_ak4642_exit(void)
201{
202 platform_driver_unregister(&fsi_ak4642);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +0900203}
204
205module_init(fsi_ak4642_init);
206module_exit(fsi_ak4642_exit);
207
208MODULE_LICENSE("GPL");
209MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card");
210MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");