Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 10 | /* 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 | |
Greg Kroah-Hartman | 37485a3 | 2021-07-02 15:58:26 +0200 | [diff] [blame] | 15 | #include <linux/android_kabi.h> |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | /* |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Shuah Khan | 66354f1 | 2019-04-01 20:40:22 -0400 | [diff] [blame] | 21 | struct media_device; |
| 22 | struct media_intf_devnode; |
| 23 | |
Takashi Iwai | 88d8822 | 2020-06-05 08:41:17 +0200 | [diff] [blame] | 24 | #define MAX_CARD_INTERFACES 16 |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | struct snd_usb_audio { |
| 27 | int index; |
| 28 | struct usb_device *dev; |
Takashi Iwai | 86e07d3 | 2005-11-17 15:08:02 +0100 | [diff] [blame] | 29 | struct snd_card *card; |
Takashi Iwai | 88d8822 | 2020-06-05 08:41:17 +0200 | [diff] [blame] | 30 | struct usb_interface *intf[MAX_CARD_INTERFACES]; |
Clemens Ladisch | 27d10f5 | 2005-05-02 08:51:26 +0200 | [diff] [blame] | 31 | u32 usb_id; |
Kai-Heng Feng | e449397 | 2021-03-04 12:34:16 +0800 | [diff] [blame] | 32 | uint16_t quirk_type; |
Daniel Mack | 596580d | 2012-04-12 13:51:10 +0200 | [diff] [blame] | 33 | struct mutex mutex; |
Takashi Iwai | 862b250 | 2020-06-03 17:37:08 +0200 | [diff] [blame] | 34 | unsigned int system_suspend; |
Takashi Iwai | 47ab154 | 2015-08-25 16:09:00 +0200 | [diff] [blame] | 35 | atomic_t active; |
| 36 | atomic_t shutdown; |
| 37 | atomic_t usage_count; |
| 38 | wait_queue_head_t shutdown_wait; |
John S. Gruber | 98e89f6 | 2009-12-27 12:19:58 -0500 | [diff] [blame] | 39 | unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */ |
Ricard Wanderlof | e057044 | 2015-10-19 08:52:53 +0200 | [diff] [blame] | 40 | unsigned int tx_length_quirk:1; /* Put length specifier in transfers */ |
Hui Wang | 92adc96 | 2019-12-18 21:26:50 +0800 | [diff] [blame] | 41 | unsigned int setup_fmt_after_resume_quirk:1; /* setup the format to interface after resume */ |
Takashi Iwai | a4aad56 | 2020-03-25 11:33:21 +0100 | [diff] [blame] | 42 | unsigned int need_delayed_register:1; /* warn for delayed registration */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | int num_interfaces; |
Oliver Neukum | f85bf29 | 2007-12-14 14:42:41 +0100 | [diff] [blame] | 44 | int num_suspended_intf; |
Takashi Iwai | 57dd541 | 2016-04-29 11:49:04 +0200 | [diff] [blame] | 45 | int sample_rate_read_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Ruslan Bilovol | 17156f2 | 2018-05-04 04:24:04 +0300 | [diff] [blame] | 47 | int badd_profile; /* UAC3 BADD profile */ |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct list_head pcm_list; /* list of pcm streams */ |
Daniel Mack | 8fdff6a | 2012-04-12 13:51:11 +0200 | [diff] [blame] | 50 | struct list_head ep_list; /* list of audio-related endpoints */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | int pcm_devs; |
| 52 | |
| 53 | struct list_head midi_list; /* list of midi interfaces */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Clemens Ladisch | 84957a8 | 2005-04-29 16:23:13 +0200 | [diff] [blame] | 55 | struct list_head mixer_list; /* list of mixer interfaces */ |
Daniel Mack | e577999 | 2010-03-04 19:46:13 +0100 | [diff] [blame] | 56 | |
| 57 | int setup; /* from the 'device_setup' module param */ |
Eldad Zack | ef02e29 | 2013-04-03 23:18:56 +0200 | [diff] [blame] | 58 | bool autoclock; /* from the 'autoclock' module param */ |
Takashi Iwai | 8a46322 | 2018-05-02 10:04:27 +0200 | [diff] [blame] | 59 | bool keep_iface; /* keep interface/altset after closing |
| 60 | * or parameter change |
| 61 | */ |
Daniel Mack | 79f920f | 2010-05-31 14:51:31 +0200 | [diff] [blame] | 62 | |
| 63 | struct usb_host_interface *ctrl_intf; /* the audio control interface */ |
Shuah Khan | 66354f1 | 2019-04-01 20:40:22 -0400 | [diff] [blame] | 64 | struct media_device *media_dev; |
| 65 | struct media_intf_devnode *ctl_intf_media_devnode; |
Hemant Kumar | 3f60546 | 2016-03-07 14:46:31 -0800 | [diff] [blame] | 66 | struct mutex dev_lock; /* to protect any race with disconnect */ |
| 67 | int card_num; /* cache pcm card number to use upon disconnect */ |
| 68 | void (*disconnect_cb)(struct snd_usb_audio *chip); |
Greg Kroah-Hartman | 37485a3 | 2021-07-02 15:58:26 +0200 | [diff] [blame] | 69 | |
| 70 | ANDROID_KABI_RESERVE(1); |
| 71 | ANDROID_KABI_RESERVE(2); |
| 72 | ANDROID_KABI_RESERVE(3); |
| 73 | ANDROID_KABI_RESERVE(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
Takashi Iwai | 716132e | 2021-04-06 13:35:34 +0200 | [diff] [blame] | 76 | #define USB_AUDIO_IFACE_UNUSED ((void *)-1L) |
| 77 | |
Takashi Iwai | 0ba41d9 | 2014-02-26 13:02:17 +0100 | [diff] [blame] | 78 | #define usb_audio_err(chip, fmt, args...) \ |
| 79 | dev_err(&(chip)->dev->dev, fmt, ##args) |
| 80 | #define usb_audio_warn(chip, fmt, args...) \ |
| 81 | dev_warn(&(chip)->dev->dev, fmt, ##args) |
| 82 | #define usb_audio_info(chip, fmt, args...) \ |
| 83 | dev_info(&(chip)->dev->dev, fmt, ##args) |
| 84 | #define usb_audio_dbg(chip, fmt, args...) \ |
| 85 | dev_dbg(&(chip)->dev->dev, fmt, ##args) |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | /* |
| 88 | * Information about devices with broken descriptors |
| 89 | */ |
| 90 | |
| 91 | /* special values for .ifnum */ |
| 92 | #define QUIRK_NO_INTERFACE -2 |
| 93 | #define QUIRK_ANY_INTERFACE -1 |
| 94 | |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 95 | enum quirk_type { |
| 96 | QUIRK_IGNORE_INTERFACE, |
| 97 | QUIRK_COMPOSITE, |
Clemens Ladisch | aafe77c | 2013-03-31 23:43:12 +0200 | [diff] [blame] | 98 | QUIRK_AUTODETECT, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 99 | QUIRK_MIDI_STANDARD_INTERFACE, |
| 100 | QUIRK_MIDI_FIXED_ENDPOINT, |
| 101 | QUIRK_MIDI_YAMAHA, |
Clemens Ladisch | aafe77c | 2013-03-31 23:43:12 +0200 | [diff] [blame] | 102 | QUIRK_MIDI_ROLAND, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 103 | QUIRK_MIDI_MIDIMAN, |
| 104 | QUIRK_MIDI_NOVATION, |
Clemens Ladisch | c7f5721 | 2010-10-22 18:20:48 +0200 | [diff] [blame] | 105 | QUIRK_MIDI_RAW_BYTES, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 106 | QUIRK_MIDI_EMAGIC, |
Clemens Ladisch | cc7a59b | 2006-02-07 17:11:06 +0100 | [diff] [blame] | 107 | QUIRK_MIDI_CME, |
Krzysztof Foltman | 4434ade | 2010-05-20 20:31:10 +0100 | [diff] [blame] | 108 | QUIRK_MIDI_AKAI, |
Karsten Wiese | 030a07e4 | 2008-07-30 15:13:29 +0200 | [diff] [blame] | 109 | QUIRK_MIDI_US122L, |
Kristian Amlie | 1ef0e0a | 2011-08-26 13:19:49 +0200 | [diff] [blame] | 110 | QUIRK_MIDI_FTDI, |
Clemens Ladisch | 1ca8b20 | 2015-11-15 22:38:29 +0100 | [diff] [blame] | 111 | QUIRK_MIDI_CH345, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 112 | QUIRK_AUDIO_STANDARD_INTERFACE, |
| 113 | QUIRK_AUDIO_FIXED_ENDPOINT, |
Pedro Lopez-Cabanillas | 310e0dc | 2008-10-04 16:27:36 +0200 | [diff] [blame] | 114 | QUIRK_AUDIO_EDIROL_UAXX, |
John S. Gruber | 52a7a58 | 2009-12-27 12:19:59 -0500 | [diff] [blame] | 115 | QUIRK_AUDIO_ALIGN_TRANSFER, |
Daniel Mack | 014950b | 2011-05-25 09:09:02 +0200 | [diff] [blame] | 116 | QUIRK_AUDIO_STANDARD_MIXER, |
Hui Wang | 92adc96 | 2019-12-18 21:26:50 +0800 | [diff] [blame] | 117 | QUIRK_SETUP_FMT_AFTER_RESUME, |
Kai-Heng Feng | 1965c43 | 2020-08-23 18:58:50 +0800 | [diff] [blame] | 118 | QUIRK_SETUP_DISABLE_AUTOSUSPEND, |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 119 | |
| 120 | QUIRK_TYPE_COUNT |
| 121 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct snd_usb_audio_quirk { |
| 124 | const char *vendor_name; |
| 125 | const char *product_name; |
| 126 | int16_t ifnum; |
Clemens Ladisch | 854af95 | 2005-07-25 16:19:10 +0200 | [diff] [blame] | 127 | uint16_t type; |
Shuah Khan | 66354f1 | 2019-04-01 20:40:22 -0400 | [diff] [blame] | 128 | bool shares_media_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | const void *data; |
| 130 | }; |
| 131 | |
Julian Anastasov | f495088 | 2009-11-06 23:44:53 +0200 | [diff] [blame] | 132 | #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16)) |
| 134 | #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24)) |
| 135 | |
Takashi Iwai | 47ab154 | 2015-08-25 16:09:00 +0200 | [diff] [blame] | 136 | int snd_usb_lock_shutdown(struct snd_usb_audio *chip); |
| 137 | void snd_usb_unlock_shutdown(struct snd_usb_audio *chip); |
| 138 | |
Takashi Iwai | f274baa | 2018-05-27 13:01:17 +0200 | [diff] [blame] | 139 | extern bool snd_usb_use_vmalloc; |
Takashi Iwai | f35ef59 | 2019-11-14 17:56:13 +0100 | [diff] [blame] | 140 | extern bool snd_usb_skip_validation; |
Takashi Iwai | f274baa | 2018-05-27 13:01:17 +0200 | [diff] [blame] | 141 | |
JaeHun Jung | 1eb1855 | 2020-05-26 16:53:38 +0900 | [diff] [blame] | 142 | struct audioformat; |
| 143 | |
| 144 | enum snd_vendor_pcm_open_close { |
| 145 | SOUND_PCM_CLOSE = 0, |
| 146 | SOUND_PCM_OPEN, |
| 147 | }; |
| 148 | |
| 149 | /** |
| 150 | * struct snd_usb_audio_vendor_ops - function callbacks for USB audio accelerators |
| 151 | * @connect: called when a new interface is found |
| 152 | * @disconnect: called when an interface is removed |
| 153 | * @set_interface: called when an interface is initialized |
| 154 | * @set_rate: called when the rate is set |
| 155 | * @set_pcm_buf: called when the pcm buffer is set |
| 156 | * @set_pcm_intf: called when the pcm interface is set |
| 157 | * @set_pcm_connection: called when pcm is opened/closed |
| 158 | * @set_pcm_binterval: called when the pcm binterval is set |
| 159 | * @usb_add_ctls: called when USB controls are added |
| 160 | * |
| 161 | * Set of callbacks for some accelerated USB audio streaming hardware. |
| 162 | * |
| 163 | * TODO: make this USB host-controller specific, right now this only works for |
| 164 | * one USB controller in the system at a time, which is only realistic for |
| 165 | * self-contained systems like phones. |
| 166 | */ |
| 167 | struct snd_usb_audio_vendor_ops { |
| 168 | int (*connect)(struct usb_interface *intf); |
| 169 | void (*disconnect)(struct usb_interface *intf); |
| 170 | |
| 171 | int (*set_interface)(struct usb_device *udev, |
| 172 | struct usb_host_interface *alts, |
| 173 | int iface, int alt); |
| 174 | int (*set_rate)(struct usb_interface *intf, int iface, int rate, |
| 175 | int alt); |
| 176 | int (*set_pcm_buf)(struct usb_device *udev, int iface); |
| 177 | int (*set_pcm_intf)(struct usb_interface *intf, int iface, int alt, |
| 178 | int direction); |
| 179 | int (*set_pcm_connection)(struct usb_device *udev, |
| 180 | enum snd_vendor_pcm_open_close onoff, |
| 181 | int direction); |
| 182 | int (*set_pcm_binterval)(struct audioformat *fp, |
| 183 | struct audioformat *found, |
| 184 | int *cur_attr, int *attr); |
| 185 | int (*usb_add_ctls)(struct snd_usb_audio *chip); |
Greg Kroah-Hartman | 37485a3 | 2021-07-02 15:58:26 +0200 | [diff] [blame] | 186 | |
| 187 | ANDROID_KABI_RESERVE(1); |
| 188 | ANDROID_KABI_RESERVE(2); |
JaeHun Jung | 1eb1855 | 2020-05-26 16:53:38 +0900 | [diff] [blame] | 189 | }; |
| 190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #endif /* __USBAUDIO_H */ |