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