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 6 #ifndef CRAS_ALSA_IO_H_ 7 #define CRAS_ALSA_IO_H_ 8 9 #include <alsa/asoundlib.h> 10 11 #include "cras_card_config.h" 12 #include "cras_types.h" 13 14 struct cras_alsa_mixer; 15 struct cras_ionode; 16 struct cras_use_case_mgr; 17 struct ucm_section; 18 19 /* Initializes an alsa iodev. 20 * Args: 21 * card_index - 0 based index, value of "XX" in "hw:XX,YY". 22 * card_name - The name of the card. 23 * device_index - 0 based index, value of "YY" in "hw:XX,YY". 24 * dev_name - The name of the device. 25 * dev_id - The id string of the device. 26 * card_type - the type of the card this iodev belongs. 27 * is_first - if this is the first iodev on the card. 28 * mixer - The mixer for the alsa device. 29 * config - Card config for this alsa device. 30 * ucm - CRAS use case manager if available. 31 * hctl - high-level control manager if available. 32 * direction - input or output. 33 * usb_vid - vendor ID of USB device. 34 * usb_pid - product ID of USB device. 35 * usb_serial_number - serial number of USB device. 36 * Returns: 37 * A pointer to the newly created iodev if successful, NULL otherwise. 38 */ 39 struct cras_iodev *alsa_iodev_create(size_t card_index, 40 const char *card_name, 41 size_t device_index, 42 const char *dev_name, 43 const char *dev_id, 44 enum CRAS_ALSA_CARD_TYPE card_type, 45 int is_first, 46 struct cras_alsa_mixer *mixer, 47 const struct cras_card_config *config, 48 struct cras_use_case_mgr *ucm, 49 snd_hctl_t *hctl, 50 enum CRAS_STREAM_DIRECTION direction, 51 size_t usb_vid, 52 size_t usb_pid, 53 char *usb_serial_number); 54 55 /* Complete initializeation of this iodev with the legacy method. 56 * Add IO nodes and find jacks for this iodev with magic sauce, then choose 57 * the current active node. 58 * Args: 59 * iodev - ALSA io device associated with the IO nodes. 60 * section - UCM section information if available (or NULL). 61 * Returns: 62 * 0 for success, negative error code on error. 63 */ 64 int alsa_iodev_legacy_complete_init(struct cras_iodev *iodev); 65 66 /* Add IO nodes and jacks for this iodev using UCM data. 67 * Args: 68 * iodev - ALSA io device associated with the given section. 69 * section - UCM section information. 70 * Returns: 71 * 0 for success, negative error code on error. 72 */ 73 int alsa_iodev_ucm_add_nodes_and_jacks(struct cras_iodev *iodev, 74 struct ucm_section *section); 75 76 /* Complete initialization of this iodev with fully-spec UCM data. 77 * After all UCM devices associated with the same iodev have been processed 78 * this is called to finish iodev setup. 79 * Args: 80 * iodev - ALSA io device. 81 */ 82 void alsa_iodev_ucm_complete_init(struct cras_iodev *iodev); 83 84 /* Destroys an alsa_iodev created with alsa_iodev_create. */ 85 void alsa_iodev_destroy(struct cras_iodev *iodev); 86 87 /* Returns the ALSA device index for the given ALSA iodev. */ 88 unsigned alsa_iodev_index(struct cras_iodev *iodev); 89 90 /* Returns whether this IODEV has ALSA hctl jacks. */ 91 int alsa_iodev_has_hctl_jacks(struct cras_iodev *iodev); 92 93 #endif /* CRAS_ALSA_IO_H_ */ 94