diff options
-rw-r--r-- | include/sound/soc.h | 32 | ||||
-rw-r--r-- | sound/soc/Kconfig | 1 | ||||
-rw-r--r-- | sound/soc/Makefile | 2 | ||||
-rw-r--r-- | sound/soc/soc-jack.c | 138 |
4 files changed, 172 insertions, 1 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h index 9b930d342116..9c3ef6a3e9fb 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h | |||
@@ -154,6 +154,8 @@ enum snd_soc_bias_level { | |||
154 | SND_SOC_BIAS_OFF, | 154 | SND_SOC_BIAS_OFF, |
155 | }; | 155 | }; |
156 | 156 | ||
157 | struct snd_jack; | ||
158 | struct snd_soc_card; | ||
157 | struct snd_soc_device; | 159 | struct snd_soc_device; |
158 | struct snd_soc_pcm_stream; | 160 | struct snd_soc_pcm_stream; |
159 | struct snd_soc_ops; | 161 | struct snd_soc_ops; |
@@ -164,6 +166,8 @@ struct snd_soc_platform; | |||
164 | struct snd_soc_codec; | 166 | struct snd_soc_codec; |
165 | struct soc_enum; | 167 | struct soc_enum; |
166 | struct snd_soc_ac97_ops; | 168 | struct snd_soc_ac97_ops; |
169 | struct snd_soc_jack; | ||
170 | struct snd_soc_jack_pin; | ||
167 | 171 | ||
168 | typedef int (*hw_write_t)(void *,const char* ,int); | 172 | typedef int (*hw_write_t)(void *,const char* ,int); |
169 | typedef int (*hw_read_t)(void *,char* ,int); | 173 | typedef int (*hw_read_t)(void *,char* ,int); |
@@ -184,6 +188,13 @@ int snd_soc_init_card(struct snd_soc_device *socdev); | |||
184 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, | 188 | int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, |
185 | const struct snd_pcm_hardware *hw); | 189 | const struct snd_pcm_hardware *hw); |
186 | 190 | ||
191 | /* Jack reporting */ | ||
192 | int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type, | ||
193 | struct snd_soc_jack *jack); | ||
194 | void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); | ||
195 | int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, | ||
196 | struct snd_soc_jack_pin *pins); | ||
197 | |||
187 | /* codec IO */ | 198 | /* codec IO */ |
188 | #define snd_soc_read(codec, reg) codec->read(codec, reg) | 199 | #define snd_soc_read(codec, reg) codec->read(codec, reg) |
189 | #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value) | 200 | #define snd_soc_write(codec, reg, value) codec->write(codec, reg, value) |
@@ -239,6 +250,27 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol, | |||
239 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, | 250 | int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, |
240 | struct snd_ctl_elem_value *ucontrol); | 251 | struct snd_ctl_elem_value *ucontrol); |
241 | 252 | ||
253 | /** | ||
254 | * struct snd_soc_jack_pin - Describes a pin to update based on jack detection | ||
255 | * | ||
256 | * @pin: name of the pin to update | ||
257 | * @mask: bits to check for in reported jack status | ||
258 | * @invert: if non-zero then pin is enabled when status is not reported | ||
259 | */ | ||
260 | struct snd_soc_jack_pin { | ||
261 | struct list_head list; | ||
262 | const char *pin; | ||
263 | int mask; | ||
264 | bool invert; | ||
265 | }; | ||
266 | |||
267 | struct snd_soc_jack { | ||
268 | struct snd_jack *jack; | ||
269 | struct snd_soc_card *card; | ||
270 | struct list_head pins; | ||
271 | int status; | ||
272 | }; | ||
273 | |||
242 | /* SoC PCM stream information */ | 274 | /* SoC PCM stream information */ |
243 | struct snd_soc_pcm_stream { | 275 | struct snd_soc_pcm_stream { |
244 | char *stream_name; | 276 | char *stream_name; |
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index ef025c66cc66..3d2bb6fc6dcc 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig | |||
@@ -6,6 +6,7 @@ menuconfig SND_SOC | |||
6 | tristate "ALSA for SoC audio support" | 6 | tristate "ALSA for SoC audio support" |
7 | select SND_PCM | 7 | select SND_PCM |
8 | select AC97_BUS if SND_SOC_AC97_BUS | 8 | select AC97_BUS if SND_SOC_AC97_BUS |
9 | select SND_JACK if INPUT=y || INPUT=SND | ||
9 | ---help--- | 10 | ---help--- |
10 | 11 | ||
11 | If you want ASoC support, you should say Y here and also to the | 12 | If you want ASoC support, you should say Y here and also to the |
diff --git a/sound/soc/Makefile b/sound/soc/Makefile index 86a9b1f5b0f3..0237879fd412 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | snd-soc-core-objs := soc-core.o soc-dapm.o | 1 | snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o |
2 | 2 | ||
3 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o | 3 | obj-$(CONFIG_SND_SOC) += snd-soc-core.o |
4 | obj-$(CONFIG_SND_SOC) += codecs/ | 4 | obj-$(CONFIG_SND_SOC) += codecs/ |
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c new file mode 100644 index 000000000000..8cc00c3cdf34 --- /dev/null +++ b/sound/soc/soc-jack.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* | ||
2 | * soc-jack.c -- ALSA SoC jack handling | ||
3 | * | ||
4 | * Copyright 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
11 | * option) any later version. | ||
12 | */ | ||
13 | |||
14 | #include <sound/jack.h> | ||
15 | #include <sound/soc.h> | ||
16 | #include <sound/soc-dapm.h> | ||
17 | |||
18 | /** | ||
19 | * snd_soc_jack_new - Create a new jack | ||
20 | * @card: ASoC card | ||
21 | * @id: an identifying string for this jack | ||
22 | * @type: a bitmask of enum snd_jack_type values that can be detected by | ||
23 | * this jack | ||
24 | * @jack: structure to use for the jack | ||
25 | * | ||
26 | * Creates a new jack object. | ||
27 | * | ||
28 | * Returns zero if successful, or a negative error code on failure. | ||
29 | * On success jack will be initialised. | ||
30 | */ | ||
31 | int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type, | ||
32 | struct snd_soc_jack *jack) | ||
33 | { | ||
34 | jack->card = card; | ||
35 | INIT_LIST_HEAD(&jack->pins); | ||
36 | |||
37 | return snd_jack_new(card->socdev->codec->card, id, type, &jack->jack); | ||
38 | } | ||
39 | EXPORT_SYMBOL_GPL(snd_soc_jack_new); | ||
40 | |||
41 | /** | ||
42 | * snd_soc_jack_report - Report the current status for a jack | ||
43 | * | ||
44 | * @jack: the jack | ||
45 | * @status: a bitmask of enum snd_jack_type values that are currently detected. | ||
46 | * @mask: a bitmask of enum snd_jack_type values that being reported. | ||
47 | * | ||
48 | * If configured using snd_soc_jack_add_pins() then the associated | ||
49 | * DAPM pins will be enabled or disabled as appropriate and DAPM | ||
50 | * synchronised. | ||
51 | * | ||
52 | * Note: This function uses mutexes and should be called from a | ||
53 | * context which can sleep (such as a workqueue). | ||
54 | */ | ||
55 | void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) | ||
56 | { | ||
57 | struct snd_soc_codec *codec = jack->card->socdev->codec; | ||
58 | struct snd_soc_jack_pin *pin; | ||
59 | int enable; | ||
60 | int oldstatus; | ||
61 | |||
62 | if (!jack) { | ||
63 | WARN_ON_ONCE(!jack); | ||
64 | return; | ||
65 | } | ||
66 | |||
67 | mutex_lock(&codec->mutex); | ||
68 | |||
69 | oldstatus = jack->status; | ||
70 | |||
71 | jack->status &= ~mask; | ||
72 | jack->status |= status; | ||
73 | |||
74 | /* The DAPM sync is expensive enough to be worth skipping */ | ||
75 | if (jack->status == oldstatus) | ||
76 | goto out; | ||
77 | |||
78 | list_for_each_entry(pin, &jack->pins, list) { | ||
79 | enable = pin->mask & status; | ||
80 | |||
81 | if (pin->invert) | ||
82 | enable = !enable; | ||
83 | |||
84 | if (enable) | ||
85 | snd_soc_dapm_enable_pin(codec, pin->pin); | ||
86 | else | ||
87 | snd_soc_dapm_disable_pin(codec, pin->pin); | ||
88 | } | ||
89 | |||
90 | snd_soc_dapm_sync(codec); | ||
91 | |||
92 | snd_jack_report(jack->jack, status); | ||
93 | |||
94 | out: | ||
95 | mutex_unlock(&codec->mutex); | ||
96 | } | ||
97 | EXPORT_SYMBOL_GPL(snd_soc_jack_report); | ||
98 | |||
99 | /** | ||
100 | * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack | ||
101 | * | ||
102 | * @jack: ASoC jack | ||
103 | * @count: Number of pins | ||
104 | * @pins: Array of pins | ||
105 | * | ||
106 | * After this function has been called the DAPM pins specified in the | ||
107 | * pins array will have their status updated to reflect the current | ||
108 | * state of the jack whenever the jack status is updated. | ||
109 | */ | ||
110 | int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, | ||
111 | struct snd_soc_jack_pin *pins) | ||
112 | { | ||
113 | int i; | ||
114 | |||
115 | for (i = 0; i < count; i++) { | ||
116 | if (!pins[i].pin) { | ||
117 | printk(KERN_ERR "No name for pin %d\n", i); | ||
118 | return -EINVAL; | ||
119 | } | ||
120 | if (!pins[i].mask) { | ||
121 | printk(KERN_ERR "No mask for pin %d (%s)\n", i, | ||
122 | pins[i].pin); | ||
123 | return -EINVAL; | ||
124 | } | ||
125 | |||
126 | INIT_LIST_HEAD(&pins[i].list); | ||
127 | list_add(&(pins[i].list), &jack->pins); | ||
128 | } | ||
129 | |||
130 | /* Update to reflect the last reported status; canned jack | ||
131 | * implementations are likely to set their state before the | ||
132 | * card has an opportunity to associate pins. | ||
133 | */ | ||
134 | snd_soc_jack_report(jack, 0, 0); | ||
135 | |||
136 | return 0; | ||
137 | } | ||
138 | EXPORT_SYMBOL_GPL(snd_soc_jack_add_pins); | ||