blob: 70afbfada9fdea0bd91618433b00f8e0d41caa32 [file] [log] [blame]
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +02001/*
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
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020025#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
26#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
27
28static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
29 struct snd_kcontrol *ctrl, int event)
30{
31 int on = 0;
32 if (event & SND_SOC_DAPM_POST_PMU)
33 on = 1;
34 else if (event & SND_SOC_DAPM_PRE_PMD)
35 on = 0;
36
37 gpio_set_value(QI_LB60_SND_GPIO, on);
38 gpio_set_value(QI_LB60_AMP_GPIO, on);
39
40 return 0;
41}
42
43static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
44 SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
45 SND_SOC_DAPM_MIC("Mic", NULL),
46};
47
48static const struct snd_soc_dapm_route qi_lb60_routes[] = {
49 {"Mic", NULL, "MIC"},
50 {"Speaker", NULL, "LOUT"},
51 {"Speaker", NULL, "ROUT"},
52};
53
54#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
55 SND_SOC_DAIFMT_NB_NF | \
56 SND_SOC_DAIFMT_CBM_CFM)
57
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000058static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020059{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000060 struct snd_soc_codec *codec = rtd->codec;
61 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
Liam Girdwoodce6120c2010-11-05 15:53:46 +020062 struct snd_soc_dapm_context *dapm = &codec->dapm;
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020063 int ret;
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020064
Liam Girdwoodce6120c2010-11-05 15:53:46 +020065 snd_soc_dapm_nc_pin(dapm, "LIN");
66 snd_soc_dapm_nc_pin(dapm, "RIN");
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020067
68 ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
69 if (ret < 0) {
70 dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
71 return ret;
72 }
73
Liam Girdwoodce6120c2010-11-05 15:53:46 +020074 snd_soc_dapm_new_controls(dapm, qi_lb60_widgets,
75 ARRAY_SIZE(qi_lb60_widgets));
76 snd_soc_dapm_add_routes(dapm, qi_lb60_routes,
77 ARRAY_SIZE(qi_lb60_routes));
78 snd_soc_dapm_sync(dapm);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020079
80 return 0;
81}
82
83static struct snd_soc_dai_link qi_lb60_dai = {
84 .name = "jz4740",
85 .stream_name = "jz4740",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000086 .cpu_dai_name = "jz4740-i2s",
Lars-Peter Clausen3ca2ecd2010-08-15 17:48:47 +020087 .platform_name = "jz4740-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000088 .codec_dai_name = "jz4740-hifi",
89 .codec_name = "jz4740-codec",
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020090 .init = qi_lb60_codec_init,
91};
92
93static struct snd_soc_card qi_lb60 = {
94 .name = "QI LB60",
95 .dai_link = &qi_lb60_dai,
96 .num_links = 1,
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020097};
98
99static struct platform_device *qi_lb60_snd_device;
100
101static int __init qi_lb60_init(void)
102{
103 int ret;
104
105 qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
106
107 if (!qi_lb60_snd_device)
108 return -ENOMEM;
109
110 ret = gpio_request(QI_LB60_SND_GPIO, "SND");
111 if (ret) {
112 pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
113 QI_LB60_SND_GPIO, ret);
114 goto err_device_put;
115 }
116
117 ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
118 if (ret) {
119 pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
120 QI_LB60_AMP_GPIO, ret);
121 goto err_gpio_free_snd;
122 }
123
124 gpio_direction_output(QI_LB60_SND_GPIO, 0);
125 gpio_direction_output(QI_LB60_AMP_GPIO, 0);
126
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000127 platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200128
129 ret = platform_device_add(qi_lb60_snd_device);
130 if (ret) {
131 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
132 goto err_unset_pdata;
133 }
134
135 return 0;
136
137err_unset_pdata:
138 platform_set_drvdata(qi_lb60_snd_device, NULL);
139/*err_gpio_free_amp:*/
140 gpio_free(QI_LB60_AMP_GPIO);
141err_gpio_free_snd:
142 gpio_free(QI_LB60_SND_GPIO);
143err_device_put:
144 platform_device_put(qi_lb60_snd_device);
145
146 return ret;
147}
148module_init(qi_lb60_init);
149
150static void __exit qi_lb60_exit(void)
151{
152 gpio_free(QI_LB60_AMP_GPIO);
153 gpio_free(QI_LB60_SND_GPIO);
154 platform_device_unregister(qi_lb60_snd_device);
155}
156module_exit(qi_lb60_exit);
157
158MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
159MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
160MODULE_LICENSE("GPL v2");