blob: 770a71a15366252066a773357028e862abe9101d [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>
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090013#include <sound/sh_fsi.h>
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090014
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090015struct fsi_ak4642_data {
16 const char *name;
Kuninori Morimoto806bfed2010-12-01 15:50:52 +090017 const char *card;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090018 const char *cpu_dai;
19 const char *codec;
20 const char *platform;
Kuninori Morimotoa1934362011-01-12 15:32:07 +090021 int id;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090022};
23
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000024static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090025{
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090026 struct snd_soc_dai *codec = rtd->codec_dai;
27 struct snd_soc_dai *cpu = rtd->cpu_dai;
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090028 int ret;
29
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090030 ret = snd_soc_dai_set_fmt(codec, SND_SOC_DAIFMT_LEFT_J |
31 SND_SOC_DAIFMT_CBM_CFM);
Kuninori Morimoto0643ce82010-03-15 18:10:50 +090032 if (ret < 0)
33 return ret;
34
Kuninori Morimoto4d805f72011-01-20 11:46:02 +090035 ret = snd_soc_dai_set_sysclk(codec, 0, 11289600, 0);
36 if (ret < 0)
37 return ret;
38
Kuninori Morimotof17c13c2011-01-24 10:43:19 +090039 ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_LEFT_J |
40 SND_SOC_DAIFMT_CBS_CFS);
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090041
42 return ret;
43}
44
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090045static struct snd_soc_dai_link fsi_dai_link = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000046 .codec_dai_name = "ak4642-hifi",
Kuninori Morimoto4b6316b2010-03-23 16:27:28 +090047 .init = fsi_ak4642_dai_init,
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090048};
49
50static struct snd_soc_card fsi_soc_card = {
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090051 .dai_link = &fsi_dai_link,
52 .num_links = 1,
53};
54
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090055static struct platform_device *fsi_snd_device;
56
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090057static int fsi_ak4642_probe(struct platform_device *pdev)
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090058{
59 int ret = -ENOMEM;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090060 const struct platform_device_id *id_entry;
61 struct fsi_ak4642_data *pdata;
62
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;
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090070
Kuninori Morimotoa1934362011-01-12 15:32:07 +090071 fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090072 if (!fsi_snd_device)
73 goto out;
74
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090075 fsi_dai_link.name = pdata->name;
76 fsi_dai_link.stream_name = pdata->name;
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;
Kuninori Morimoto806bfed2010-12-01 15:50:52 +090080 fsi_soc_card.name = pdata->card;
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090081
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000082 platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090083 ret = platform_device_add(fsi_snd_device);
84
85 if (ret)
86 platform_device_put(fsi_snd_device);
87
88out:
89 return ret;
90}
91
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090092static int fsi_ak4642_remove(struct platform_device *pdev)
Kuninori Morimotob8e583f2009-08-21 09:42:59 +090093{
94 platform_device_unregister(fsi_snd_device);
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +090095 return 0;
96}
97
98static struct fsi_ak4642_data fsi_a_ak4642 = {
99 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700100 .card = "FSIA-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900101 .cpu_dai = "fsia-dai",
102 .codec = "ak4642-codec.0-0012",
103 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900104 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900105};
106
107static struct fsi_ak4642_data fsi_b_ak4642 = {
108 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700109 .card = "FSIB-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900110 .cpu_dai = "fsib-dai",
111 .codec = "ak4642-codec.0-0012",
112 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900113 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900114};
115
116static struct fsi_ak4642_data fsi_a_ak4643 = {
117 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700118 .card = "FSIA-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900119 .cpu_dai = "fsia-dai",
120 .codec = "ak4642-codec.0-0013",
121 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900122 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900123};
124
125static struct fsi_ak4642_data fsi_b_ak4643 = {
126 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700127 .card = "FSIB-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900128 .cpu_dai = "fsib-dai",
129 .codec = "ak4642-codec.0-0013",
130 .platform = "sh_fsi.0",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900131 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900132};
133
134static struct fsi_ak4642_data fsi2_a_ak4642 = {
135 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700136 .card = "FSI2A-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900137 .cpu_dai = "fsia-dai",
138 .codec = "ak4642-codec.0-0012",
139 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900140 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900141};
142
143static struct fsi_ak4642_data fsi2_b_ak4642 = {
144 .name = "AK4642",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700145 .card = "FSI2B-AK4642",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900146 .cpu_dai = "fsib-dai",
147 .codec = "ak4642-codec.0-0012",
148 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900149 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900150};
151
152static struct fsi_ak4642_data fsi2_a_ak4643 = {
153 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700154 .card = "FSI2A-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900155 .cpu_dai = "fsia-dai",
156 .codec = "ak4642-codec.0-0013",
157 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900158 .id = FSI_PORT_A,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900159};
160
161static struct fsi_ak4642_data fsi2_b_ak4643 = {
162 .name = "AK4643",
Kuninori Morimoto505b04e2011-07-05 00:15:04 -0700163 .card = "FSI2B-AK4643",
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900164 .cpu_dai = "fsib-dai",
165 .codec = "ak4642-codec.0-0013",
166 .platform = "sh_fsi2",
Kuninori Morimotoa1934362011-01-12 15:32:07 +0900167 .id = FSI_PORT_B,
Kuninori Morimotoc8d6bf92010-11-30 11:32:04 +0900168};
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);
Kuninori Morimotob8e583f2009-08-21 09:42:59 +0900202}
203
204module_init(fsi_ak4642_init);
205module_exit(fsi_ak4642_exit);
206
207MODULE_LICENSE("GPL");
208MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card");
209MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");