blob: e97141ef730ad9f72542f8afebf49cc3a521f578 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef __USBAUDIO_H
3#define __USBAUDIO_H
4/*
5 * (Tentative) USB Audio Driver for ALSA
6 *
7 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
Clemens Ladisch27d10f52005-05-02 08:51:26 +020010/* handling of USB vendor/product ID pairs as 32-bit numbers */
Borislav Petkov1ef87152022-04-05 17:15:08 +020011#define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product))
Clemens Ladisch27d10f52005-05-02 08:51:26 +020012#define USB_ID_VENDOR(id) ((id) >> 16)
13#define USB_ID_PRODUCT(id) ((u16)(id))
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*
Daniel Macke5779992010-03-04 19:46:13 +010016 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
18
Shuah Khan66354f12019-04-01 20:40:22 -040019struct media_device;
20struct media_intf_devnode;
21
Takashi Iwai88d88222020-06-05 08:41:17 +020022#define MAX_CARD_INTERFACES 16
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024struct snd_usb_audio {
25 int index;
26 struct usb_device *dev;
Takashi Iwai86e07d32005-11-17 15:08:02 +010027 struct snd_card *card;
Takashi Iwai88d88222020-06-05 08:41:17 +020028 struct usb_interface *intf[MAX_CARD_INTERFACES];
Clemens Ladisch27d10f52005-05-02 08:51:26 +020029 u32 usb_id;
Kai-Heng Feng97991102021-03-04 12:34:16 +080030 uint16_t quirk_type;
Daniel Mack596580d2012-04-12 13:51:10 +020031 struct mutex mutex;
Takashi Iwai862b2502020-06-03 17:37:08 +020032 unsigned int system_suspend;
Takashi Iwai47ab1542015-08-25 16:09:00 +020033 atomic_t active;
34 atomic_t shutdown;
35 atomic_t usage_count;
36 wait_queue_head_t shutdown_wait;
Takashi Iwai4d4dee02021-07-29 09:38:47 +020037 unsigned int quirk_flags;
Takashi Iwaia4aad562020-03-25 11:33:21 +010038 unsigned int need_delayed_register:1; /* warn for delayed registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 int num_interfaces;
Takashi Iwai6392dcd2022-09-04 18:12:47 +020040 int last_iface;
Oliver Neukumf85bf292007-12-14 14:42:41 +010041 int num_suspended_intf;
Takashi Iwai57dd5412016-04-29 11:49:04 +020042 int sample_rate_read_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Ruslan Bilovol17156f22018-05-04 04:24:04 +030044 int badd_profile; /* UAC3 BADD profile */
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct list_head pcm_list; /* list of pcm streams */
Daniel Mack8fdff6a2012-04-12 13:51:11 +020047 struct list_head ep_list; /* list of audio-related endpoints */
Takashi Iwai00272c62021-01-08 08:52:17 +010048 struct list_head iface_ref_list; /* list of interface refcounts */
Takashi Iwaic11117b2022-05-16 12:48:07 +020049 struct list_head clock_ref_list; /* list of clock refcounts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 int pcm_devs;
51
52 struct list_head midi_list; /* list of midi interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Clemens Ladisch84957a82005-04-29 16:23:13 +020054 struct list_head mixer_list; /* list of mixer interfaces */
Daniel Macke5779992010-03-04 19:46:13 +010055
56 int setup; /* from the 'device_setup' module param */
Takashi Iwai62abd092020-11-23 09:53:45 +010057 bool generic_implicit_fb; /* from the 'implicit_fb' module param */
Eldad Zackef02e292013-04-03 23:18:56 +020058 bool autoclock; /* from the 'autoclock' module param */
Daniel Mack79f920f2010-05-31 14:51:31 +020059
Takashi Iwai4801bee2021-08-29 09:38:30 +020060 bool lowlatency; /* from the 'lowlatency' module param */
Daniel Mack79f920f2010-05-31 14:51:31 +020061 struct usb_host_interface *ctrl_intf; /* the audio control interface */
Shuah Khan66354f12019-04-01 20:40:22 -040062 struct media_device *media_dev;
63 struct media_intf_devnode *ctl_intf_media_devnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064};
65
Takashi Iwai5fb45412021-04-06 13:35:34 +020066#define USB_AUDIO_IFACE_UNUSED ((void *)-1L)
67
Takashi Iwai0ba41d92014-02-26 13:02:17 +010068#define usb_audio_err(chip, fmt, args...) \
69 dev_err(&(chip)->dev->dev, fmt, ##args)
70#define usb_audio_warn(chip, fmt, args...) \
71 dev_warn(&(chip)->dev->dev, fmt, ##args)
72#define usb_audio_info(chip, fmt, args...) \
73 dev_info(&(chip)->dev->dev, fmt, ##args)
74#define usb_audio_dbg(chip, fmt, args...) \
75 dev_dbg(&(chip)->dev->dev, fmt, ##args)
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077/*
78 * Information about devices with broken descriptors
79 */
80
81/* special values for .ifnum */
Takashi Iwaid7631452021-04-08 09:56:56 +020082#define QUIRK_NODEV_INTERFACE -3 /* return -ENODEV */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#define QUIRK_NO_INTERFACE -2
84#define QUIRK_ANY_INTERFACE -1
85
Clemens Ladisch854af952005-07-25 16:19:10 +020086enum quirk_type {
87 QUIRK_IGNORE_INTERFACE,
88 QUIRK_COMPOSITE,
Clemens Ladischaafe77c2013-03-31 23:43:12 +020089 QUIRK_AUTODETECT,
Clemens Ladisch854af952005-07-25 16:19:10 +020090 QUIRK_MIDI_STANDARD_INTERFACE,
91 QUIRK_MIDI_FIXED_ENDPOINT,
92 QUIRK_MIDI_YAMAHA,
Clemens Ladischaafe77c2013-03-31 23:43:12 +020093 QUIRK_MIDI_ROLAND,
Clemens Ladisch854af952005-07-25 16:19:10 +020094 QUIRK_MIDI_MIDIMAN,
95 QUIRK_MIDI_NOVATION,
Clemens Ladischc7f57212010-10-22 18:20:48 +020096 QUIRK_MIDI_RAW_BYTES,
Clemens Ladisch854af952005-07-25 16:19:10 +020097 QUIRK_MIDI_EMAGIC,
Clemens Ladischcc7a59b2006-02-07 17:11:06 +010098 QUIRK_MIDI_CME,
Krzysztof Foltman4434ade82010-05-20 20:31:10 +010099 QUIRK_MIDI_AKAI,
Karsten Wiese030a07e42008-07-30 15:13:29 +0200100 QUIRK_MIDI_US122L,
Kristian Amlie1ef0e0a2011-08-26 13:19:49 +0200101 QUIRK_MIDI_FTDI,
Clemens Ladisch1ca8b202015-11-15 22:38:29 +0100102 QUIRK_MIDI_CH345,
Clemens Ladisch854af952005-07-25 16:19:10 +0200103 QUIRK_AUDIO_STANDARD_INTERFACE,
104 QUIRK_AUDIO_FIXED_ENDPOINT,
Pedro Lopez-Cabanillas310e0dc2008-10-04 16:27:36 +0200105 QUIRK_AUDIO_EDIROL_UAXX,
Daniel Mack014950b2011-05-25 09:09:02 +0200106 QUIRK_AUDIO_STANDARD_MIXER,
Clemens Ladisch854af952005-07-25 16:19:10 +0200107
108 QUIRK_TYPE_COUNT
109};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111struct snd_usb_audio_quirk {
112 const char *vendor_name;
113 const char *product_name;
114 int16_t ifnum;
Clemens Ladisch854af952005-07-25 16:19:10 +0200115 uint16_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 const void *data;
117};
118
Julian Anastasovf4950882009-11-06 23:44:53 +0200119#define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
121#define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
122
Takashi Iwai47ab1542015-08-25 16:09:00 +0200123int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
124void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
125
Takashi Iwaif274baa2018-05-27 13:01:17 +0200126extern bool snd_usb_use_vmalloc;
Takashi Iwaif35ef592019-11-14 17:56:13 +0100127extern bool snd_usb_skip_validation;
Takashi Iwaif274baa2018-05-27 13:01:17 +0200128
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200129/*
130 * Driver behavior quirk flags, stored in chip->quirk_flags
131 *
132 * QUIRK_FLAG_GET_SAMPLE_RATE:
133 * Skip reading sample rate for devices, as some devices behave inconsistently
134 * or return error
Takashi Iwaice47d472021-07-29 09:38:48 +0200135 * QUIRK_FLAG_SHARE_MEDIA_DEVICE:
136 * Create Media Controller API entries
Takashi Iwaiaf158a72021-07-29 09:38:49 +0200137 * QUIRK_FLAG_ALIGN_TRANSFER:
138 * Allow alignment on audio sub-slot (channel samples) rather than on audio
139 * slots (audio frames)
Takashi Iwaic1b034a2021-07-29 09:38:50 +0200140 * QUIRK_TX_LENGTH:
141 * Add length specifier to transfers
Takashi Iwai019c7f92021-07-29 09:38:51 +0200142 * QUIRK_FLAG_PLAYBACK_FIRST:
143 * Start playback stream at first even in implement feedback mode
Takashi Iwaif21dca82021-07-29 09:38:52 +0200144 * QUIRK_FLAG_SKIP_CLOCK_SELECTOR:
145 * Skip clock selector setup; the device may reset to invalid state
146 * QUIRK_FLAG_IGNORE_CLOCK_SOURCE:
147 * Ignore errors from clock source search; i.e. hardcoded clock
Takashi Iwai2de00d52021-07-29 09:38:53 +0200148 * QUIRK_FLAG_ITF_USB_DSD_DAC:
149 * Indicates the device is for ITF-USB DSD based DACs that need a vendor cmd
150 * to switch between PCM and native DSD mode
Takashi Iwaif7483852021-07-29 09:38:54 +0200151 * QUIRK_FLAG_CTL_MSG_DELAY:
152 * Add a delay of 20ms at each control message handling
153 * QUIRK_FLAG_CTL_MSG_DELAY_1M:
154 * Add a delay of 1-2ms at each control message handling
155 * QUIRK_FLAG_CTL_MSG_DELAY_5M:
156 * Add a delay of 5-6ms at each control message handling
Takashi Iwai1f074fe2021-07-29 09:38:55 +0200157 * QUIRK_FLAG_IFACE_DELAY:
158 * Add a delay of 50ms at each interface setup
Takashi Iwai8bfe17a2021-07-29 09:43:59 +0200159 * QUIRK_FLAG_VALIDATE_RATES:
160 * Perform sample rate validations at probe
Takashi Iwai44e6fc62021-07-29 09:44:00 +0200161 * QUIRK_FLAG_DISABLE_AUTOSUSPEND:
162 * Disable runtime PM autosuspend
Takashi Iwai3c69dc92021-07-29 09:44:01 +0200163 * QUIRK_FLAG_IGNORE_CTL_ERROR:
164 * Ignore errors for mixer access
Takashi Iwai68e851e2021-07-29 09:44:02 +0200165 * QUIRK_FLAG_DSD_RAW:
166 * Support generic DSD raw U32_BE format
Takashi Iwai6e413402021-08-24 07:57:20 +0200167 * QUIRK_FLAG_SET_IFACE_FIRST:
168 * Set up the interface at first like UAC1
Takashi Iwai0f1f7a62022-04-21 08:41:00 +0200169 * QUIRK_FLAG_GENERIC_IMPLICIT_FB
170 * Apply the generic implicit feedback sync mode (same as implicit_fb=1 option)
171 * QUIRK_FLAG_SKIP_IMPLICIT_FB
172 * Don't apply implicit feedback sync mode
Ai Chaobf990c12022-11-10 14:34:52 +0800173 * QUIRK_FLAG_IFACE_SKIP_CLOSE
174 * Don't closed interface during setting sample rate
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200175 */
176
177#define QUIRK_FLAG_GET_SAMPLE_RATE (1U << 0)
Takashi Iwaice47d472021-07-29 09:38:48 +0200178#define QUIRK_FLAG_SHARE_MEDIA_DEVICE (1U << 1)
Takashi Iwaiaf158a72021-07-29 09:38:49 +0200179#define QUIRK_FLAG_ALIGN_TRANSFER (1U << 2)
Takashi Iwaic1b034a2021-07-29 09:38:50 +0200180#define QUIRK_FLAG_TX_LENGTH (1U << 3)
Takashi Iwai019c7f92021-07-29 09:38:51 +0200181#define QUIRK_FLAG_PLAYBACK_FIRST (1U << 4)
Takashi Iwaif21dca82021-07-29 09:38:52 +0200182#define QUIRK_FLAG_SKIP_CLOCK_SELECTOR (1U << 5)
183#define QUIRK_FLAG_IGNORE_CLOCK_SOURCE (1U << 6)
Takashi Iwai2de00d52021-07-29 09:38:53 +0200184#define QUIRK_FLAG_ITF_USB_DSD_DAC (1U << 7)
Takashi Iwaif7483852021-07-29 09:38:54 +0200185#define QUIRK_FLAG_CTL_MSG_DELAY (1U << 8)
186#define QUIRK_FLAG_CTL_MSG_DELAY_1M (1U << 9)
187#define QUIRK_FLAG_CTL_MSG_DELAY_5M (1U << 10)
Takashi Iwai1f074fe2021-07-29 09:38:55 +0200188#define QUIRK_FLAG_IFACE_DELAY (1U << 11)
Takashi Iwai8bfe17a2021-07-29 09:43:59 +0200189#define QUIRK_FLAG_VALIDATE_RATES (1U << 12)
Takashi Iwai44e6fc62021-07-29 09:44:00 +0200190#define QUIRK_FLAG_DISABLE_AUTOSUSPEND (1U << 13)
Takashi Iwai3c69dc92021-07-29 09:44:01 +0200191#define QUIRK_FLAG_IGNORE_CTL_ERROR (1U << 14)
Takashi Iwai68e851e2021-07-29 09:44:02 +0200192#define QUIRK_FLAG_DSD_RAW (1U << 15)
Takashi Iwai6e413402021-08-24 07:57:20 +0200193#define QUIRK_FLAG_SET_IFACE_FIRST (1U << 16)
Takashi Iwai0f1f7a62022-04-21 08:41:00 +0200194#define QUIRK_FLAG_GENERIC_IMPLICIT_FB (1U << 17)
195#define QUIRK_FLAG_SKIP_IMPLICIT_FB (1U << 18)
Ai Chaobf990c12022-11-10 14:34:52 +0800196#define QUIRK_FLAG_IFACE_SKIP_CLOSE (1U << 19)
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif /* __USBAUDIO_H */