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