2 * soc-jack.c -- ALSA SoC jack handling
4 * Copyright 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
14 #include <sound/jack.h>
15 #include <sound/soc.h>
16 #include <sound/soc-dapm.h>
19 * snd_soc_jack_new - Create a new jack
21 * @id: an identifying string for this jack
22 * @type: a bitmask of enum snd_jack_type values that can be detected by
24 * @jack: structure to use for the jack
26 * Creates a new jack object.
28 * Returns zero if successful, or a negative error code on failure.
29 * On success jack will be initialised.
31 int snd_soc_jack_new(struct snd_soc_card
*card
, const char *id
, int type
,
32 struct snd_soc_jack
*jack
)
35 INIT_LIST_HEAD(&jack
->pins
);
37 return snd_jack_new(card
->socdev
->codec
->card
, id
, type
, &jack
->jack
);
39 EXPORT_SYMBOL_GPL(snd_soc_jack_new
);
42 * snd_soc_jack_report - Report the current status for a 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.
48 * If configured using snd_soc_jack_add_pins() then the associated
49 * DAPM pins will be enabled or disabled as appropriate and DAPM
52 * Note: This function uses mutexes and should be called from a
53 * context which can sleep (such as a workqueue).
55 void snd_soc_jack_report(struct snd_soc_jack
*jack
, int status
, int mask
)
57 struct snd_soc_codec
*codec
= jack
->card
->socdev
->codec
;
58 struct snd_soc_jack_pin
*pin
;
67 mutex_lock(&codec
->mutex
);
69 oldstatus
= jack
->status
;
71 jack
->status
&= ~mask
;
72 jack
->status
|= status
;
74 /* The DAPM sync is expensive enough to be worth skipping */
75 if (jack
->status
== oldstatus
)
78 list_for_each_entry(pin
, &jack
->pins
, list
) {
79 enable
= pin
->mask
& status
;
85 snd_soc_dapm_enable_pin(codec
, pin
->pin
);
87 snd_soc_dapm_disable_pin(codec
, pin
->pin
);
90 snd_soc_dapm_sync(codec
);
92 snd_jack_report(jack
->jack
, status
);
95 mutex_unlock(&codec
->mutex
);
97 EXPORT_SYMBOL_GPL(snd_soc_jack_report
);
100 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
103 * @count: Number of pins
104 * @pins: Array of pins
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.
110 int snd_soc_jack_add_pins(struct snd_soc_jack
*jack
, int count
,
111 struct snd_soc_jack_pin
*pins
)
115 for (i
= 0; i
< count
; i
++) {
117 printk(KERN_ERR
"No name for pin %d\n", i
);
121 printk(KERN_ERR
"No mask for pin %d (%s)\n", i
,
126 INIT_LIST_HEAD(&pins
[i
].list
);
127 list_add(&(pins
[i
].list
), &jack
->pins
);
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.
134 snd_soc_jack_report(jack
, 0, 0);
138 EXPORT_SYMBOL_GPL(snd_soc_jack_add_pins
);
This page took 0.036146 seconds and 6 git commands to generate.