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