07b6ecaed2f292a73965478165466935fb752029
[linux-2.6-microblaze.git] / sound / soc / kirkwood / kirkwood-t5325.c
1 /*
2  * kirkwood-t5325.c
3  *
4  * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
5  *
6  *  This program is free software; you can redistribute  it and/or modify it
7  *  under  the terms of  the GNU General  Public License as published by the
8  *  Free Software Foundation;  either version 2 of the  License, or (at your
9  *  option) any later version.
10  */
11
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/interrupt.h>
15 #include <linux/platform_device.h>
16 #include <linux/slab.h>
17 #include <sound/soc.h>
18 #include <sound/soc-dapm.h>
19 #include <mach/kirkwood.h>
20 #include <plat/audio.h>
21 #include <asm/mach-types.h>
22 #include "../codecs/alc5623.h"
23
24 static int t5325_hw_params(struct snd_pcm_substream *substream,
25                 struct snd_pcm_hw_params *params)
26 {
27         struct snd_soc_pcm_runtime *rtd = substream->private_data;
28         struct snd_soc_dai *codec_dai = rtd->codec_dai;
29         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
30         int ret;
31         unsigned int freq, fmt;
32
33         fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
34         ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
35         if (ret < 0)
36                 return ret;
37
38         ret = snd_soc_dai_set_fmt(codec_dai, fmt);
39         if (ret < 0)
40                 return ret;
41
42         freq = params_rate(params) * 256;
43
44         return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
45
46 }
47
48 static struct snd_soc_ops t5325_ops = {
49         .hw_params = t5325_hw_params,
50 };
51
52 static const struct snd_soc_dapm_widget t5325_dapm_widgets[] = {
53         SND_SOC_DAPM_HP("Headphone Jack", NULL),
54         SND_SOC_DAPM_SPK("Speaker", NULL),
55         SND_SOC_DAPM_MIC("Mic Jack", NULL),
56 };
57
58 static const struct snd_soc_dapm_route t5325_route[] = {
59         { "Headphone Jack",     NULL,   "HPL" },
60         { "Headphone Jack",     NULL,   "HPR" },
61
62         {"Speaker",             NULL,   "SPKOUT"},
63         {"Speaker",             NULL,   "SPKOUTN"},
64
65         { "MIC1",               NULL,   "Mic Jack" },
66         { "MIC2",               NULL,   "Mic Jack" },
67 };
68
69 static int t5325_dai_init(struct snd_soc_pcm_runtime *rtd)
70 {
71         struct snd_soc_codec *codec = rtd->codec;
72         struct snd_soc_dapm_context *dapm = &codec->dapm;
73
74         snd_soc_dapm_new_controls(dapm, t5325_dapm_widgets,
75                                 ARRAY_SIZE(t5325_dapm_widgets));
76
77         snd_soc_dapm_add_routes(dapm, t5325_route, ARRAY_SIZE(t5325_route));
78
79         snd_soc_dapm_enable_pin(dapm, "Mic Jack");
80         snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
81         snd_soc_dapm_enable_pin(dapm, "Speaker");
82
83         snd_soc_dapm_sync(dapm);
84
85         return 0;
86 }
87
88 static struct snd_soc_dai_link t5325_dai[] = {
89 {
90         .name = "ALC5621",
91         .stream_name = "ALC5621 HiFi",
92         .cpu_dai_name = "kirkwood-i2s",
93         .platform_name = "kirkwood-pcm-audio",
94         .codec_dai_name = "alc5621-hifi",
95         .codec_name = "alc562x-codec.0-001a",
96         .ops = &t5325_ops,
97         .init = t5325_dai_init,
98 },
99 };
100
101
102 static struct snd_soc_card t5325 = {
103         .name = "t5325",
104         .dai_link = t5325_dai,
105         .num_links = ARRAY_SIZE(t5325_dai),
106 };
107
108 static struct platform_device *t5325_snd_device;
109
110 static int __init t5325_init(void)
111 {
112         int ret;
113
114         if (!machine_is_t5325())
115                 return 0;
116
117         t5325_snd_device = platform_device_alloc("soc-audio", -1);
118         if (!t5325_snd_device)
119                 return -ENOMEM;
120
121         platform_set_drvdata(t5325_snd_device,
122                         &t5325);
123
124         ret = platform_device_add(t5325_snd_device);
125         if (ret) {
126                 printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
127                 platform_device_put(t5325_snd_device);
128         }
129
130         return ret;
131 }
132 module_init(t5325_init);
133
134 static void __exit t5325_exit(void)
135 {
136         platform_device_unregister(t5325_snd_device);
137 }
138 module_exit(t5325_exit);
139
140 MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
141 MODULE_DESCRIPTION("ALSA SoC t5325 audio client");
142 MODULE_LICENSE("GPL");