ce058c749e6aa6e46db8689c861495aef6b00ad0
[linux-2.6.git] / sound / soc / sh / fsi-ak4642.c
1 /*
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
12 #include <linux/platform_device.h>
13 #include <sound/sh_fsi.h>
14
15 struct 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
24 static int fsi_ak4642_dai_init(struct snd_soc_pcm_runtime *rtd)
25 {
26         struct snd_soc_dai *codec = rtd->codec_dai;
27         struct snd_soc_dai *cpu = rtd->cpu_dai;
28         int ret;
29
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);
36         if (ret < 0)
37                 return ret;
38
39         ret = snd_soc_dai_set_fmt(cpu, SND_SOC_DAIFMT_CBS_CFS);
40
41         return ret;
42 }
43
44 static struct snd_soc_dai_link fsi_dai_link = {
45         .codec_dai_name = "ak4642-hifi",
46         .init           = fsi_ak4642_dai_init,
47 };
48
49 static struct snd_soc_card fsi_soc_card  = {
50         .dai_link       = &fsi_dai_link,
51         .num_links      = 1,
52 };
53
54 static struct platform_device *fsi_snd_device;
55
56 static int fsi_ak4642_probe(struct platform_device *pdev)
57 {
58         int ret = -ENOMEM;
59         const struct platform_device_id *id_entry;
60         struct fsi_ak4642_data *pdata;
61
62         id_entry = pdev->id_entry;
63         if (!id_entry) {
64                 dev_err(&pdev->dev, "unknown fsi ak4642\n");
65                 return -ENODEV;
66         }
67
68         pdata = (struct fsi_ak4642_data *)id_entry->driver_data;
69
70         fsi_snd_device = platform_device_alloc("soc-audio", pdata->id);
71         if (!fsi_snd_device)
72                 goto out;
73
74         fsi_dai_link.name               = pdata->name;
75         fsi_dai_link.stream_name        = pdata->name;
76         fsi_dai_link.cpu_dai_name       = pdata->cpu_dai;
77         fsi_dai_link.platform_name      = pdata->platform;
78         fsi_dai_link.codec_name         = pdata->codec;
79         fsi_soc_card.name               = pdata->card;
80
81         platform_set_drvdata(fsi_snd_device, &fsi_soc_card);
82         ret = platform_device_add(fsi_snd_device);
83
84         if (ret)
85                 platform_device_put(fsi_snd_device);
86
87 out:
88         return ret;
89 }
90
91 static int fsi_ak4642_remove(struct platform_device *pdev)
92 {
93         platform_device_unregister(fsi_snd_device);
94         return 0;
95 }
96
97 static struct fsi_ak4642_data fsi_a_ak4642 = {
98         .name           = "AK4642",
99         .card           = "FSIA (AK4642)",
100         .cpu_dai        = "fsia-dai",
101         .codec          = "ak4642-codec.0-0012",
102         .platform       = "sh_fsi.0",
103         .id             = FSI_PORT_A,
104 };
105
106 static struct fsi_ak4642_data fsi_b_ak4642 = {
107         .name           = "AK4642",
108         .card           = "FSIB (AK4642)",
109         .cpu_dai        = "fsib-dai",
110         .codec          = "ak4642-codec.0-0012",
111         .platform       = "sh_fsi.0",
112         .id             = FSI_PORT_B,
113 };
114
115 static struct fsi_ak4642_data fsi_a_ak4643 = {
116         .name           = "AK4643",
117         .card           = "FSIA (AK4643)",
118         .cpu_dai        = "fsia-dai",
119         .codec          = "ak4642-codec.0-0013",
120         .platform       = "sh_fsi.0",
121         .id             = FSI_PORT_A,
122 };
123
124 static struct fsi_ak4642_data fsi_b_ak4643 = {
125         .name           = "AK4643",
126         .card           = "FSIB (AK4643)",
127         .cpu_dai        = "fsib-dai",
128         .codec          = "ak4642-codec.0-0013",
129         .platform       = "sh_fsi.0",
130         .id             = FSI_PORT_B,
131 };
132
133 static struct fsi_ak4642_data fsi2_a_ak4642 = {
134         .name           = "AK4642",
135         .card           = "FSI2A (AK4642)",
136         .cpu_dai        = "fsia-dai",
137         .codec          = "ak4642-codec.0-0012",
138         .platform       = "sh_fsi2",
139         .id             = FSI_PORT_A,
140 };
141
142 static struct fsi_ak4642_data fsi2_b_ak4642 = {
143         .name           = "AK4642",
144         .card           = "FSI2B (AK4642)",
145         .cpu_dai        = "fsib-dai",
146         .codec          = "ak4642-codec.0-0012",
147         .platform       = "sh_fsi2",
148         .id             = FSI_PORT_B,
149 };
150
151 static struct fsi_ak4642_data fsi2_a_ak4643 = {
152         .name           = "AK4643",
153         .card           = "FSI2A (AK4643)",
154         .cpu_dai        = "fsia-dai",
155         .codec          = "ak4642-codec.0-0013",
156         .platform       = "sh_fsi2",
157         .id             = FSI_PORT_A,
158 };
159
160 static struct fsi_ak4642_data fsi2_b_ak4643 = {
161         .name           = "AK4643",
162         .card           = "FSI2B (AK4643)",
163         .cpu_dai        = "fsib-dai",
164         .codec          = "ak4642-codec.0-0013",
165         .platform       = "sh_fsi2",
166         .id             = FSI_PORT_B,
167 };
168
169 static struct platform_device_id fsi_id_table[] = {
170         /* FSI */
171         { "sh_fsi_a_ak4642",    (kernel_ulong_t)&fsi_a_ak4642 },
172         { "sh_fsi_b_ak4642",    (kernel_ulong_t)&fsi_b_ak4642 },
173         { "sh_fsi_a_ak4643",    (kernel_ulong_t)&fsi_a_ak4643 },
174         { "sh_fsi_b_ak4643",    (kernel_ulong_t)&fsi_b_ak4643 },
175
176         /* FSI 2 */
177         { "sh_fsi2_a_ak4642",   (kernel_ulong_t)&fsi2_a_ak4642 },
178         { "sh_fsi2_b_ak4642",   (kernel_ulong_t)&fsi2_b_ak4642 },
179         { "sh_fsi2_a_ak4643",   (kernel_ulong_t)&fsi2_a_ak4643 },
180         { "sh_fsi2_b_ak4643",   (kernel_ulong_t)&fsi2_b_ak4643 },
181         {},
182 };
183
184 static struct platform_driver fsi_ak4642 = {
185         .driver = {
186                 .name   = "fsi-ak4642-audio",
187         },
188         .probe          = fsi_ak4642_probe,
189         .remove         = fsi_ak4642_remove,
190         .id_table       = fsi_id_table,
191 };
192
193 static int __init fsi_ak4642_init(void)
194 {
195         return platform_driver_register(&fsi_ak4642);
196 }
197
198 static void __exit fsi_ak4642_exit(void)
199 {
200         platform_driver_unregister(&fsi_ak4642);
201 }
202
203 module_init(fsi_ak4642_init);
204 module_exit(fsi_ak4642_exit);
205
206 MODULE_LICENSE("GPL");
207 MODULE_DESCRIPTION("Generic SH4 FSI-AK4642 sound card");
208 MODULE_AUTHOR("Kuninori Morimoto <morimoto.kuninori@renesas.com>");