Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/sound/soc/jz4740/qi_lb60.c
10817 views
1
/*
2
* Copyright (C) 2009, Lars-Peter Clausen <[email protected]>
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 <linux/gpio.h>
23
24
#define QI_LB60_SND_GPIO JZ_GPIO_PORTB(29)
25
#define QI_LB60_AMP_GPIO JZ_GPIO_PORTD(4)
26
27
static int qi_lb60_spk_event(struct snd_soc_dapm_widget *widget,
28
struct snd_kcontrol *ctrl, int event)
29
{
30
int on = !SND_SOC_DAPM_EVENT_OFF(event);
31
32
gpio_set_value(QI_LB60_SND_GPIO, on);
33
gpio_set_value(QI_LB60_AMP_GPIO, on);
34
35
return 0;
36
}
37
38
static const struct snd_soc_dapm_widget qi_lb60_widgets[] = {
39
SND_SOC_DAPM_SPK("Speaker", qi_lb60_spk_event),
40
SND_SOC_DAPM_MIC("Mic", NULL),
41
};
42
43
static const struct snd_soc_dapm_route qi_lb60_routes[] = {
44
{"Mic", NULL, "MIC"},
45
{"Speaker", NULL, "LOUT"},
46
{"Speaker", NULL, "ROUT"},
47
};
48
49
#define QI_LB60_DAIFMT (SND_SOC_DAIFMT_I2S | \
50
SND_SOC_DAIFMT_NB_NF | \
51
SND_SOC_DAIFMT_CBM_CFM)
52
53
static int qi_lb60_codec_init(struct snd_soc_pcm_runtime *rtd)
54
{
55
struct snd_soc_codec *codec = rtd->codec;
56
struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
57
struct snd_soc_dapm_context *dapm = &codec->dapm;
58
int ret;
59
60
snd_soc_dapm_nc_pin(dapm, "LIN");
61
snd_soc_dapm_nc_pin(dapm, "RIN");
62
63
ret = snd_soc_dai_set_fmt(cpu_dai, QI_LB60_DAIFMT);
64
if (ret < 0) {
65
dev_err(codec->dev, "Failed to set cpu dai format: %d\n", ret);
66
return ret;
67
}
68
69
return 0;
70
}
71
72
static struct snd_soc_dai_link qi_lb60_dai = {
73
.name = "jz4740",
74
.stream_name = "jz4740",
75
.cpu_dai_name = "jz4740-i2s",
76
.platform_name = "jz4740-pcm-audio",
77
.codec_dai_name = "jz4740-hifi",
78
.codec_name = "jz4740-codec",
79
.init = qi_lb60_codec_init,
80
};
81
82
static struct snd_soc_card qi_lb60 = {
83
.name = "QI LB60",
84
.dai_link = &qi_lb60_dai,
85
.num_links = 1,
86
87
.dapm_widgets = qi_lb60_widgets,
88
.num_dapm_widgets = ARRAY_SIZE(qi_lb60_widgets),
89
.dapm_routes = qi_lb60_routes,
90
.num_dapm_routes = ARRAY_SIZE(qi_lb60_routes),
91
};
92
93
static struct platform_device *qi_lb60_snd_device;
94
95
static const struct gpio qi_lb60_gpios[] = {
96
{ QI_LB60_SND_GPIO, GPIOF_OUT_INIT_LOW, "SND" },
97
{ QI_LB60_AMP_GPIO, GPIOF_OUT_INIT_LOW, "AMP" },
98
};
99
100
static 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_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
110
if (ret) {
111
pr_err("qi_lb60 snd: Failed to request gpios: %d\n", ret);
112
goto err_device_put;
113
}
114
115
platform_set_drvdata(qi_lb60_snd_device, &qi_lb60);
116
117
ret = platform_device_add(qi_lb60_snd_device);
118
if (ret) {
119
pr_err("qi_lb60 snd: Failed to add snd soc device: %d\n", ret);
120
goto err_unset_pdata;
121
}
122
123
return 0;
124
125
err_unset_pdata:
126
platform_set_drvdata(qi_lb60_snd_device, NULL);
127
/*err_gpio_free_array:*/
128
gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
129
err_device_put:
130
platform_device_put(qi_lb60_snd_device);
131
132
return ret;
133
}
134
module_init(qi_lb60_init);
135
136
static void __exit qi_lb60_exit(void)
137
{
138
platform_device_unregister(qi_lb60_snd_device);
139
gpio_free_array(qi_lb60_gpios, ARRAY_SIZE(qi_lb60_gpios));
140
}
141
module_exit(qi_lb60_exit);
142
143
MODULE_AUTHOR("Lars-Peter Clausen <[email protected]>");
144
MODULE_DESCRIPTION("ALSA SoC QI LB60 Audio support");
145
MODULE_LICENSE("GPL v2");
146
147