blob: 875abc94a00b5cd9803ff7ca3f06712304df2236 [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
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020073 return 0;
74}
75
76static struct snd_soc_dai_link qi_lb60_dai = {
77 .name = "jz4740",
78 .stream_name = "jz4740",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000079 .cpu_dai_name = "jz4740-i2s",
Lars-Peter Clausen3ca2ecd2010-08-15 17:48:47 +020080 .platform_name = "jz4740-pcm-audio",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000081 .codec_dai_name = "jz4740-hifi",
82 .codec_name = "jz4740-codec",
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020083 .init = qi_lb60_codec_init,
84};
85
86static struct snd_soc_card qi_lb60 = {
87 .name = "QI LB60",
88 .dai_link = &qi_lb60_dai,
89 .num_links = 1,
Lars-Peter Clausen13319692011-04-12 19:31:03 +020090
91 .dapm_widgets = qi_lb60_widgets,
92 .num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
93 .dapm_routes = qi_lb60_routes,
94 .num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +020095};
96
97static struct platform_device *qi_lb60_snd_device;
98
99static int __init qi_lb60_init(void)
100{
101 int ret;
102
103 qi_lb60_snd_device = platform_device_alloc("soc-audio", -1);
104
105 if (!qi_lb60_snd_device)
106 return -ENOMEM;
107
108 ret = gpio_request(QI_LB60_SND_GPIO, "SND");
109 if (ret) {
110 pr_err("qi_lb60 snd: Failed to request SND GPIO(%d): %d\n",
111 QI_LB60_SND_GPIO, ret);
112 goto err_device_put;
113 }
114
115 ret = gpio_request(QI_LB60_AMP_GPIO, "AMP");
116 if (ret) {
117 pr_err("qi_lb60 snd: Failed to request AMP GPIO(%d): %d\n",
118 QI_LB60_AMP_GPIO, ret);
119 goto err_gpio_free_snd;
120 }
121
122 gpio_direction_output(QI_LB60_SND_GPIO, 0);
123 gpio_direction_output(QI_LB60_AMP_GPIO, 0);
124
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000125 platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
Lars-Peter Clausen5898dd92010-06-19 16:52:51 +0200126
127 ret = platform_device_add(qi_lb60_snd_device);
128 if (ret) {
129 pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
130 goto err_unset_pdata;
131 }
132
133 return 0;
134
135err_unset_pdata:
136 platform_set_drvdata(qi_lb60_snd_device, NULL);
137/*err_gpio_free_amp:*/
138 gpio_free(QI_LB60_AMP_GPIO);
139err_gpio_free_snd:
140 gpio_free(QI_LB60_SND_GPIO);
141err_device_put:
142 platform_device_put(qi_lb60_snd_device);
143
144 return ret;
145}
146module_init(qi_lb60_init);
147
148static void __exit qi_lb60_exit(void)
149{
150 gpio_free(QI_LB60_AMP_GPIO);
151 gpio_free(QI_LB60_SND_GPIO);
152 platform_device_unregister(qi_lb60_snd_device);
153}
154module_exit(qi_lb60_exit);
155
156MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
157MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
158MODULE_LICENSE("GPL v2");