blob: 167834133b9bc8b81a8333f32938fceba6eb7810 [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 */
11#define USB_ID(vendor, product) (((vendor) << 16) | (product))
12#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;
Oliver Neukumf85bf292007-12-14 14:42:41 +010040 int num_suspended_intf;
Takashi Iwai57dd5412016-04-29 11:49:04 +020041 int sample_rate_read_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Ruslan Bilovol17156f22018-05-04 04:24:04 +030043 int badd_profile; /* UAC3 BADD profile */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 struct list_head pcm_list; /* list of pcm streams */
Daniel Mack8fdff6a2012-04-12 13:51:11 +020046 struct list_head ep_list; /* list of audio-related endpoints */
Takashi Iwai00272c62021-01-08 08:52:17 +010047 struct list_head iface_ref_list; /* list of interface refcounts */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 int pcm_devs;
49
50 struct list_head midi_list; /* list of midi interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Clemens Ladisch84957a82005-04-29 16:23:13 +020052 struct list_head mixer_list; /* list of mixer interfaces */
Daniel Macke5779992010-03-04 19:46:13 +010053
54 int setup; /* from the 'device_setup' module param */
Takashi Iwai62abd092020-11-23 09:53:45 +010055 bool generic_implicit_fb; /* from the 'implicit_fb' module param */
Eldad Zackef02e292013-04-03 23:18:56 +020056 bool autoclock; /* from the 'autoclock' module param */
Daniel Mack79f920f2010-05-31 14:51:31 +020057
Takashi Iwai4801bee2021-08-29 09:38:30 +020058 bool lowlatency; /* from the 'lowlatency' module param */
Daniel Mack79f920f2010-05-31 14:51:31 +020059 struct usb_host_interface *ctrl_intf; /* the audio control interface */
Shuah Khan66354f12019-04-01 20:40:22 -040060 struct media_device *media_dev;
61 struct media_intf_devnode *ctl_intf_media_devnode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
Takashi Iwai5fb45412021-04-06 13:35:34 +020064#define USB_AUDIO_IFACE_UNUSED ((void *)-1L)
65
Takashi Iwai0ba41d92014-02-26 13:02:17 +010066#define usb_audio_err(chip, fmt, args...) \
67 dev_err(&(chip)->dev->dev, fmt, ##args)
68#define usb_audio_warn(chip, fmt, args...) \
69 dev_warn(&(chip)->dev->dev, fmt, ##args)
70#define usb_audio_info(chip, fmt, args...) \
71 dev_info(&(chip)->dev->dev, fmt, ##args)
72#define usb_audio_dbg(chip, fmt, args...) \
73 dev_dbg(&(chip)->dev->dev, fmt, ##args)
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/*
76 * Information about devices with broken descriptors
77 */
78
79/* special values for .ifnum */
Takashi Iwaid7631452021-04-08 09:56:56 +020080#define QUIRK_NODEV_INTERFACE -3 /* return -ENODEV */
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define QUIRK_NO_INTERFACE -2
82#define QUIRK_ANY_INTERFACE -1
83
Clemens Ladisch854af952005-07-25 16:19:10 +020084enum quirk_type {
85 QUIRK_IGNORE_INTERFACE,
86 QUIRK_COMPOSITE,
Clemens Ladischaafe77c2013-03-31 23:43:12 +020087 QUIRK_AUTODETECT,
Clemens Ladisch854af952005-07-25 16:19:10 +020088 QUIRK_MIDI_STANDARD_INTERFACE,
89 QUIRK_MIDI_FIXED_ENDPOINT,
90 QUIRK_MIDI_YAMAHA,
Clemens Ladischaafe77c2013-03-31 23:43:12 +020091 QUIRK_MIDI_ROLAND,
Clemens Ladisch854af952005-07-25 16:19:10 +020092 QUIRK_MIDI_MIDIMAN,
93 QUIRK_MIDI_NOVATION,
Clemens Ladischc7f57212010-10-22 18:20:48 +020094 QUIRK_MIDI_RAW_BYTES,
Clemens Ladisch854af952005-07-25 16:19:10 +020095 QUIRK_MIDI_EMAGIC,
Clemens Ladischcc7a59b2006-02-07 17:11:06 +010096 QUIRK_MIDI_CME,
Krzysztof Foltman4434ade2010-05-20 20:31:10 +010097 QUIRK_MIDI_AKAI,
Karsten Wiese030a07e42008-07-30 15:13:29 +020098 QUIRK_MIDI_US122L,
Kristian Amlie1ef0e0a2011-08-26 13:19:49 +020099 QUIRK_MIDI_FTDI,
Clemens Ladisch1ca8b202015-11-15 22:38:29 +0100100 QUIRK_MIDI_CH345,
Clemens Ladisch854af952005-07-25 16:19:10 +0200101 QUIRK_AUDIO_STANDARD_INTERFACE,
102 QUIRK_AUDIO_FIXED_ENDPOINT,
Pedro Lopez-Cabanillas310e0dc2008-10-04 16:27:36 +0200103 QUIRK_AUDIO_EDIROL_UAXX,
Daniel Mack014950b2011-05-25 09:09:02 +0200104 QUIRK_AUDIO_STANDARD_MIXER,
Clemens Ladisch854af952005-07-25 16:19:10 +0200105
106 QUIRK_TYPE_COUNT
107};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109struct snd_usb_audio_quirk {
110 const char *vendor_name;
111 const char *product_name;
112 int16_t ifnum;
Clemens Ladisch854af952005-07-25 16:19:10 +0200113 uint16_t type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 const void *data;
115};
116
Julian Anastasovf4950882009-11-06 23:44:53 +0200117#define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
119#define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
120
Takashi Iwai47ab1542015-08-25 16:09:00 +0200121int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
122void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
123
Takashi Iwaif274baa2018-05-27 13:01:17 +0200124extern bool snd_usb_use_vmalloc;
Takashi Iwaif35ef592019-11-14 17:56:13 +0100125extern bool snd_usb_skip_validation;
Takashi Iwaif274baa2018-05-27 13:01:17 +0200126
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200127/*
128 * Driver behavior quirk flags, stored in chip->quirk_flags
129 *
130 * QUIRK_FLAG_GET_SAMPLE_RATE:
131 * Skip reading sample rate for devices, as some devices behave inconsistently
132 * or return error
Takashi Iwaice47d472021-07-29 09:38:48 +0200133 * QUIRK_FLAG_SHARE_MEDIA_DEVICE:
134 * Create Media Controller API entries
Takashi Iwaiaf158a72021-07-29 09:38:49 +0200135 * QUIRK_FLAG_ALIGN_TRANSFER:
136 * Allow alignment on audio sub-slot (channel samples) rather than on audio
137 * slots (audio frames)
Takashi Iwaic1b034a2021-07-29 09:38:50 +0200138 * QUIRK_TX_LENGTH:
139 * Add length specifier to transfers
Takashi Iwai019c7f92021-07-29 09:38:51 +0200140 * QUIRK_FLAG_PLAYBACK_FIRST:
141 * Start playback stream at first even in implement feedback mode
Takashi Iwaif21dca82021-07-29 09:38:52 +0200142 * QUIRK_FLAG_SKIP_CLOCK_SELECTOR:
143 * Skip clock selector setup; the device may reset to invalid state
144 * QUIRK_FLAG_IGNORE_CLOCK_SOURCE:
145 * Ignore errors from clock source search; i.e. hardcoded clock
Takashi Iwai2de00d52021-07-29 09:38:53 +0200146 * QUIRK_FLAG_ITF_USB_DSD_DAC:
147 * Indicates the device is for ITF-USB DSD based DACs that need a vendor cmd
148 * to switch between PCM and native DSD mode
Takashi Iwaif7483852021-07-29 09:38:54 +0200149 * QUIRK_FLAG_CTL_MSG_DELAY:
150 * Add a delay of 20ms at each control message handling
151 * QUIRK_FLAG_CTL_MSG_DELAY_1M:
152 * Add a delay of 1-2ms at each control message handling
153 * QUIRK_FLAG_CTL_MSG_DELAY_5M:
154 * Add a delay of 5-6ms at each control message handling
Takashi Iwai1f074fe2021-07-29 09:38:55 +0200155 * QUIRK_FLAG_IFACE_DELAY:
156 * Add a delay of 50ms at each interface setup
Takashi Iwai8bfe17a2021-07-29 09:43:59 +0200157 * QUIRK_FLAG_VALIDATE_RATES:
158 * Perform sample rate validations at probe
Takashi Iwai44e6fc62021-07-29 09:44:00 +0200159 * QUIRK_FLAG_DISABLE_AUTOSUSPEND:
160 * Disable runtime PM autosuspend
Takashi Iwai3c69dc92021-07-29 09:44:01 +0200161 * QUIRK_FLAG_IGNORE_CTL_ERROR:
162 * Ignore errors for mixer access
Takashi Iwai68e851e2021-07-29 09:44:02 +0200163 * QUIRK_FLAG_DSD_RAW:
164 * Support generic DSD raw U32_BE format
Takashi Iwai6e413402021-08-24 07:57:20 +0200165 * QUIRK_FLAG_SET_IFACE_FIRST:
166 * Set up the interface at first like UAC1
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200167 */
168
169#define QUIRK_FLAG_GET_SAMPLE_RATE (1U << 0)
Takashi Iwaice47d472021-07-29 09:38:48 +0200170#define QUIRK_FLAG_SHARE_MEDIA_DEVICE (1U << 1)
Takashi Iwaiaf158a72021-07-29 09:38:49 +0200171#define QUIRK_FLAG_ALIGN_TRANSFER (1U << 2)
Takashi Iwaic1b034a2021-07-29 09:38:50 +0200172#define QUIRK_FLAG_TX_LENGTH (1U << 3)
Takashi Iwai019c7f92021-07-29 09:38:51 +0200173#define QUIRK_FLAG_PLAYBACK_FIRST (1U << 4)
Takashi Iwaif21dca82021-07-29 09:38:52 +0200174#define QUIRK_FLAG_SKIP_CLOCK_SELECTOR (1U << 5)
175#define QUIRK_FLAG_IGNORE_CLOCK_SOURCE (1U << 6)
Takashi Iwai2de00d52021-07-29 09:38:53 +0200176#define QUIRK_FLAG_ITF_USB_DSD_DAC (1U << 7)
Takashi Iwaif7483852021-07-29 09:38:54 +0200177#define QUIRK_FLAG_CTL_MSG_DELAY (1U << 8)
178#define QUIRK_FLAG_CTL_MSG_DELAY_1M (1U << 9)
179#define QUIRK_FLAG_CTL_MSG_DELAY_5M (1U << 10)
Takashi Iwai1f074fe2021-07-29 09:38:55 +0200180#define QUIRK_FLAG_IFACE_DELAY (1U << 11)
Takashi Iwai8bfe17a2021-07-29 09:43:59 +0200181#define QUIRK_FLAG_VALIDATE_RATES (1U << 12)
Takashi Iwai44e6fc62021-07-29 09:44:00 +0200182#define QUIRK_FLAG_DISABLE_AUTOSUSPEND (1U << 13)
Takashi Iwai3c69dc92021-07-29 09:44:01 +0200183#define QUIRK_FLAG_IGNORE_CTL_ERROR (1U << 14)
Takashi Iwai68e851e2021-07-29 09:44:02 +0200184#define QUIRK_FLAG_DSD_RAW (1U << 15)
Takashi Iwai6e413402021-08-24 07:57:20 +0200185#define QUIRK_FLAG_SET_IFACE_FIRST (1U << 16)
Takashi Iwai4d4dee02021-07-29 09:38:47 +0200186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif /* __USBAUDIO_H */