• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  *
5  * Handles finding and monitoring ALSA Jack controls.  These controls represent
6  * external jacks and report back when the plugged state of teh hack changes.
7  */
8 
9 #ifndef CRAS_ALSA_JACK_H_
10 #define CRAS_ALSA_JACK_H_
11 
12 #include "cras_types.h"
13 #include "cras_alsa_ucm.h"
14 
15 struct cras_alsa_jack;
16 struct cras_alsa_jack_list;
17 struct cras_alsa_mixer;
18 
19 /* Callback type for users of jack_list to define, it will be called when the
20  * jack state changes.
21  * Args:
22  *    jack - The jack that has changed.
23  *    plugged - non-zero if the jack is attached.
24  *    data - User defined pointer passed to cras_alsa_jack_create.
25  */
26 typedef void (jack_state_change_callback)(const struct cras_alsa_jack *jack,
27 					  int plugged,
28 					  void *data);
29 
30 /* Creates a jack list. The jacks can be added later by name matching or
31  * fully specified UCM.
32  * Args:
33  *    card_index - Index ALSA uses to refer to the card.  The X in "hw:X".
34  *    card_name - The name of the card (used to find gpio jacks).
35  *    device_index - Index ALSA uses to refer to the device.  The Y in "hw:X".
36  *    is_first_device - whether this device is the first device on the card.
37  *    mixer - The mixer associated with this card, used to find controls that
38  *      correspond to jacks.  For instance "Headphone switch" for "Headphone
39  *      Jack".
40  *    ucm - CRAS use case manager if available.
41  *    hctl - ALSA high-level control interface if available.
42  *    direction - Input or output, look for mic or headphone jacks.
43  *    cb - Function to call when a jack state changes.
44  *    cb_data - Passed to the callback when called.
45  * Returns:
46  *    A pointer to a new jack list on success, NULL if there is a failure.
47  */
48 struct cras_alsa_jack_list *cras_alsa_jack_list_create(
49 		unsigned int card_index,
50 		const char *card_name,
51 		unsigned int device_index,
52 		int is_first_device,
53 		struct cras_alsa_mixer *mixer,
54 		struct cras_use_case_mgr *ucm,
55 		snd_hctl_t *hctl,
56 		enum CRAS_STREAM_DIRECTION direction,
57 		jack_state_change_callback *cb,
58 		void *cb_data);
59 
60 /* Finds jacks by name matching.
61  * The list holds all the interesting ALSA jacks for this
62  * device. These jacks will be for headphones, speakers, HDMI, etc.
63  * Args:
64  *   jack_list - A pointer to a jack list.
65  * Returns:
66  *   0 on success. Error code if there is a failure.
67  */
68 int cras_alsa_jack_list_find_jacks_by_name_matching(
69 	struct cras_alsa_jack_list *jack_list);
70 
71 /* Add the jack defined by the UCM section information.
72  * Args:
73  *   jack_list - A pointer to a jack list.
74  *   ucm_section - UCM section data.
75  *   result_jack - Resulting jack that was added.
76  * Returns:
77  *   0 on success. Error code if there is a failure.
78  */
79 int cras_alsa_jack_list_add_jack_for_section(
80 	struct cras_alsa_jack_list *jack_list,
81 	struct ucm_section *ucm_section,
82 	struct cras_alsa_jack **result_jack);
83 
84 /* Destroys a jack list created with cras_alsa_jack_list_create.
85  * Args:
86  *    jack_list - The list to destroy.
87  */
88 void cras_alsa_jack_list_destroy(struct cras_alsa_jack_list *jack_list);
89 
90 /* Returns non-zero if the jack list has hctl jacks.
91  * Args:
92  *    jack_list - The list check.
93  */
94 int cras_alsa_jack_list_has_hctl_jacks(struct cras_alsa_jack_list *jack_list);
95 
96 /* Gets the mixer output associated with the given jack.
97  * Args:
98  *    jack - The jack to query for a mixer output.
99  * Returns:
100  *    A pointer to the mixer output if it exists, otherwise NULL.
101  */
102 struct mixer_control *cras_alsa_jack_get_mixer_output(
103 		const struct cras_alsa_jack *jack);
104 
105 /* Gets the mixer input associated with given jack.
106  * Args:
107  *    jack - The jack to query for a mixer input.
108  * Returns:
109  *    A pointer to the mixer input if it exists, otherwise NULL.
110  */
111 struct mixer_control *cras_alsa_jack_get_mixer_input(
112 		const struct cras_alsa_jack *jack);
113 
114 /* Query all jacks in the list and report the state to the callback.
115  * Args:
116  *    jack_list - The jack list to query.
117  */
118 void cras_alsa_jack_list_report(const struct cras_alsa_jack_list *jack_list);
119 
120 /* Gets the name of a jack.
121  * Args:
122  *    jack_list - The jack list to query.
123  */
124 const char *cras_alsa_jack_get_name(const struct cras_alsa_jack *jack);
125 
126 /* Gets the ucm device of a jack.
127  * Args:
128  *    jack - The alsa jack.
129  */
130 const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack);
131 
132 
133 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack,
134 					char *name_buf,
135 					unsigned int buf_size);
136 
137 /* Updates the node type according to override_type_name in jack.
138  * Currently this method only supports updating the node type to
139  * CRAS_NODE_TYPE_INTERNAL_SPEAKER when override_type_name is
140  * "Internal Speaker". This is used in All-In-One device where
141  * output is an HDMI device, but it should be internal speaker from
142  * user point of view.
143  * Args:
144  *    jack - The jack to query node type.
145  *    type - The node type to be overwritten.
146  */
147 void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack,
148 				     enum CRAS_NODE_TYPE *type);
149 
150 /* Gets the dsp name of a jack.
151  * Args:
152  *    jack_list - The jack list to query.
153  */
154 const char *cras_alsa_jack_get_dsp_name(const struct cras_alsa_jack *jack);
155 
156 /* Enables the ucm device for this jack if any.
157  * Args:
158  *    jack - The jack to query for a mixer output.
159  */
160 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable);
161 
162 
163 /* Find out whether the specified card has a jack with the given name.
164  * Args:
165  *    card_index - Index ALSA uses to refer to the card.  The X in "hw:X".
166  *    jack_name - The name of the jack (for example, "Speaker Phantom Jack").
167  */
168 int cras_alsa_jack_exists(unsigned int card_index, const char *jack_name);
169 
170 #endif /* CRAS_ALSA_JACK_H_ */
171