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, void *data); 28 29 /* Creates a jack list. The jacks can be added later by name matching or 30 * fully specified UCM. 31 * Args: 32 * card_index - Index ALSA uses to refer to the card. The X in "hw:X". 33 * card_name - The name of the card (used to find gpio jacks). 34 * device_index - Index ALSA uses to refer to the device. The Y in "hw:X". 35 * is_first_device - whether this device is the first device on the card. 36 * mixer - The mixer associated with this card, used to find controls that 37 * correspond to jacks. For instance "Headphone switch" for "Headphone 38 * Jack". 39 * ucm - CRAS use case manager if available. 40 * hctl - ALSA high-level control interface if available. 41 * direction - Input or output, look for mic or headphone jacks. 42 * cb - Function to call when a jack state changes. 43 * cb_data - Passed to the callback when called. 44 * Returns: 45 * A pointer to a new jack list on success, NULL if there is a failure. 46 */ 47 struct cras_alsa_jack_list * 48 cras_alsa_jack_list_create(unsigned int card_index, const char *card_name, 49 unsigned int device_index, int is_first_device, 50 struct cras_alsa_mixer *mixer, 51 struct cras_use_case_mgr *ucm, snd_hctl_t *hctl, 52 enum CRAS_STREAM_DIRECTION direction, 53 jack_state_change_callback *cb, void *cb_data); 54 55 /* Finds jacks by name matching. 56 * The list holds all the interesting ALSA jacks for this 57 * device. These jacks will be for headphones, speakers, HDMI, etc. 58 * Args: 59 * jack_list - A pointer to a jack list. 60 * Returns: 61 * 0 on success. Error code if there is a failure. 62 */ 63 int cras_alsa_jack_list_find_jacks_by_name_matching( 64 struct cras_alsa_jack_list *jack_list); 65 66 /* Add the jack defined by the UCM section information. 67 * Args: 68 * jack_list - A pointer to a jack list. 69 * ucm_section - UCM section data. 70 * result_jack - Resulting jack that was added. 71 * Returns: 72 * 0 on success. Error code if there is a failure. 73 */ 74 int cras_alsa_jack_list_add_jack_for_section( 75 struct cras_alsa_jack_list *jack_list, struct ucm_section *ucm_section, 76 struct cras_alsa_jack **result_jack); 77 78 /* Destroys a jack list created with cras_alsa_jack_list_create. 79 * Args: 80 * jack_list - The list to destroy. 81 */ 82 void cras_alsa_jack_list_destroy(struct cras_alsa_jack_list *jack_list); 83 84 /* Returns non-zero if the jack list has hctl jacks. 85 * Args: 86 * jack_list - The list check. 87 */ 88 int cras_alsa_jack_list_has_hctl_jacks(struct cras_alsa_jack_list *jack_list); 89 90 /* Gets the mixer output associated with the given jack. 91 * Args: 92 * jack - The jack to query for a mixer output. 93 * Returns: 94 * A pointer to the mixer output if it exists, otherwise NULL. 95 */ 96 struct mixer_control * 97 cras_alsa_jack_get_mixer_output(const struct cras_alsa_jack *jack); 98 99 /* Gets the mixer input associated with given jack. 100 * Args: 101 * jack - The jack to query for a mixer input. 102 * Returns: 103 * A pointer to the mixer input if it exists, otherwise NULL. 104 */ 105 struct mixer_control * 106 cras_alsa_jack_get_mixer_input(const struct cras_alsa_jack *jack); 107 108 /* Query all jacks in the list and report the state to the callback. 109 * Args: 110 * jack_list - The jack list to query. 111 */ 112 void cras_alsa_jack_list_report(const struct cras_alsa_jack_list *jack_list); 113 114 /* Gets the name of a jack. 115 * Args: 116 * jack_list - The jack list to query. 117 */ 118 const char *cras_alsa_jack_get_name(const struct cras_alsa_jack *jack); 119 120 /* Gets the ucm device of a jack. 121 * Args: 122 * jack - The alsa jack. 123 */ 124 const char *cras_alsa_jack_get_ucm_device(const struct cras_alsa_jack *jack); 125 126 void cras_alsa_jack_update_monitor_name(const struct cras_alsa_jack *jack, 127 char *name_buf, unsigned int buf_size); 128 129 /* Updates the node type according to override_type_name in jack. 130 * Currently this method only supports updating the node type to 131 * CRAS_NODE_TYPE_INTERNAL_SPEAKER when override_type_name is 132 * "Internal Speaker". This is used in All-In-One device where 133 * output is an HDMI device, but it should be internal speaker from 134 * user point of view. 135 * Args: 136 * jack - The jack to query node type. 137 * type - The node type to be overwritten. 138 */ 139 void cras_alsa_jack_update_node_type(const struct cras_alsa_jack *jack, 140 enum CRAS_NODE_TYPE *type); 141 142 /* Enables the ucm device for this jack if any. 143 * Args: 144 * jack - The jack to query for a mixer output. 145 */ 146 void cras_alsa_jack_enable_ucm(const struct cras_alsa_jack *jack, int enable); 147 148 /* Find out whether the specified card has a jack with the given name. 149 * Args: 150 * card_index - Index ALSA uses to refer to the card. The X in "hw:X". 151 * jack_name - The name of the jack (for example, "Speaker Phantom Jack"). 152 */ 153 int cras_alsa_jack_exists(unsigned int card_index, const char *jack_name); 154 155 #endif /* CRAS_ALSA_JACK_H_ */ 156