]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/soc/jz4740/qi_lb60.c
ASoC: multi-component - ASoC Multi-Component Support
[mv-sheeva.git] / sound / soc / jz4740 / qi_lb60.c
1 /*
2  * Copyright (C) 2009, Lars-Peter Clausen <lars@metafoo.de>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  *  You should have received a copy of the  GNU General Public License along
9  *  with this program; if not, write  to the Free Software Foundation, Inc.,
10  *  675 Mass Ave, Cambridge, MA 02139, USA.
11  *
12  */
13
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/timer.h>
17 #include <linux/interrupt.h>
18 #include <linux/platform_device.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/soc.h>
22 #include <sound/soc-dapm.h>
23 #include <linux/gpio.h>
24
25 #include "../codecs/jz4740.h"
26 #include "jz4740-pcm.h"
27 #include "jz4740-i2s.h"
28
29
30 #define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
31 #define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
32
33 static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
34                              struct snd_kcontrol *ctrl, int event)
35 {
36         int on = 0;
37         if (event & SND_SOC_DAPM_POST_PMU)
38                 on = 1;
39         else if (event & SND_SOC_DAPM_PRE_PMD)
40                 on = 0;
41
42         gpio_set_value(QI_LB60_SND_GPIO, on);
43         gpio_set_value(QI_LB60_AMP_GPIO, on);
44
45         return 0;
46 }
47
48 static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
49         SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
50         SND_SOC_DAPM_MIC("Mic", NULL),
51 };
52
53 static const struct snd_soc_dapm_route qi_lb60_routes[] = {
54         {"Mic", NULL, "MIC"},
55         {"Speaker", NULL, "LOUT"},
56         {"Speaker", NULL, "ROUT"},
57 };
58
59 #define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
60                         SND_SOC_DAIFMT_NB_NF | \
61                         SND_SOC_DAIFMT_CBM_CFM)
62
63 static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
64 {
65         struct snd_soc_codec *codec = rtd->codec;
66         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
67         int ret;
68
69         snd_soc_dapm_nc_pin(codec, "LIN");
70         snd_soc_dapm_nc_pin(codec, "RIN");
71
72         ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
73         if (ret < 0) {
74                 dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
75                 return ret;
76         }
77
78         snd_soc_dapm_new_controls(codec, qi_lb60_widgets, ARRAY_SIZE(qi_lb60_widgets));
79         snd_soc_dapm_add_routes(codec, qi_lb60_routes, ARRAY_SIZE(qi_lb60_routes));
80         snd_soc_dapm_sync(codec);
81
82         return 0;
83 }
84
85 static struct snd_soc_dai_link qi_lb60_dai = {
86         .name = "jz4740",
87         .stream_name = "jz4740",
88         .cpu_dai_name = "jz4740-i2s",
89         .platform_name = "jz4740-pmc-audio",
90         .codec_dai_name = "jz4740-hifi",
91         .codec_name = "jz4740-codec",
92         .init = qi_lb60_codec_init,
93 };
94
95 static struct snd_soc_card qi_lb60 = {
96         .name = "QI LB60",
97         .dai_link = &qi_lb60_dai,
98         .num_links = 1,
99 };
100
101 static struct platform_device *qi_lb60_snd_device;
102
103 static int __init qi_lb60_init(void)
104 {
105         int ret;
106
107         qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
108
109         if (!qi_lb60_snd_device)
110                 return -ENOMEM;
111
112         ret = gpio_request(QI_LB60_SND_GPIO, "SND");
113         if (ret) {
114                 pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
115                                 QI_LB60_SND_GPIO, ret);
116                 goto err_device_put;
117         }
118
119         ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
120         if (ret) {
121                 pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
122                                 QI_LB60_AMP_GPIO, ret);
123                 goto err_gpio_free_snd;
124         }
125
126         gpio_direction_output(QI_LB60_SND_GPIO, 0);
127         gpio_direction_output(QI_LB60_AMP_GPIO, 0);
128
129         platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
130
131         ret = platform_device_add(qi_lb60_snd_device);
132         if (ret) {
133                 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
134                 goto err_unset_pdata;
135         }
136
137          return 0;
138
139 err_unset_pdata:
140         platform_set_drvdata(qi_lb60_snd_device, NULL);
141 /*err_gpio_free_amp:*/
142         gpio_free(QI_LB60_AMP_GPIO);
143 err_gpio_free_snd:
144         gpio_free(QI_LB60_SND_GPIO);
145 err_device_put:
146         platform_device_put(qi_lb60_snd_device);
147
148         return ret;
149 }
150 module_init(qi_lb60_init);
151
152 static void __exit qi_lb60_exit(void)
153 {
154         gpio_free(QI_LB60_AMP_GPIO);
155         gpio_free(QI_LB60_SND_GPIO);
156         platform_device_unregister(qi_lb60_snd_device);
157 }
158 module_exit(qi_lb60_exit);
159
160 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
161 MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
162 MODULE_LICENSE("GPL v2");