blob: 6d40b46c3c13ff9e868e705775d043d1eaa66f36 [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
Greg Kroah-Hartman37485a32021-07-02 15:58:26 +020015#include <linux/android_kabi.h>
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017/*
Daniel Macke5779992010-03-04 19:46:13 +010018 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 */
20
Shuah Khan66354f12019-04-01 20:40:22 -040021struct media_device;
22struct media_intf_devnode;
23
Takashi Iwai88d88222020-06-05 08:41:17 +020024#define MAX_CARD_INTERFACES 16
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct snd_usb_audio {
27 int index;
28 struct usb_device *dev;
Takashi Iwai86e07d32005-11-17 15:08:02 +010029 struct snd_card *card;
Takashi Iwai88d88222020-06-05 08:41:17 +020030 struct usb_interface *intf[MAX_CARD_INTERFACES];
Clemens Ladisch27d10f52005-05-02 08:51:26 +020031 u32 usb_id;
Kai-Heng Fenge4493972021-03-04 12:34:16 +080032 uint16_t quirk_type;
Daniel Mack596580d2012-04-12 13:51:10 +020033 struct mutex mutex;
Takashi Iwai862b2502020-06-03 17:37:08 +020034 unsigned int system_suspend;
Takashi Iwai47ab1542015-08-25 16:09:00 +020035 atomic_t active;
36 atomic_t shutdown;
37 atomic_t usage_count;
38 wait_queue_head_t shutdown_wait;
John S. Gruber98e89f62009-12-27 12:19:58 -050039 unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */
Ricard Wanderlofe0570442015-10-19 08:52:53 +020040 unsigned int tx_length_quirk:1; /* Put length specifier in transfers */
Hui Wang92adc962019-12-18 21:26:50 +080041 unsigned int setup_fmt_after_resume_quirk:1; /* setup the format to interface after resume */
Takashi Iwaia4aad562020-03-25 11:33:21 +010042 unsigned int need_delayed_register:1; /* warn for delayed registration */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 int num_interfaces;
Oliver Neukumf85bf292007-12-14 14:42:41 +010044 int num_suspended_intf;
Takashi Iwai57dd5412016-04-29 11:49:04 +020045 int sample_rate_read_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Ruslan Bilovol17156f22018-05-04 04:24:04 +030047 int badd_profile; /* UAC3 BADD profile */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 struct list_head pcm_list; /* list of pcm streams */
Daniel Mack8fdff6a2012-04-12 13:51:11 +020050 struct list_head ep_list; /* list of audio-related endpoints */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 int pcm_devs;
52
53 struct list_head midi_list; /* list of midi interfaces */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
Clemens Ladisch84957a82005-04-29 16:23:13 +020055 struct list_head mixer_list; /* list of mixer interfaces */
Daniel Macke5779992010-03-04 19:46:13 +010056
57 int setup; /* from the 'device_setup' module param */
Eldad Zackef02e292013-04-03 23:18:56 +020058 bool autoclock; /* from the 'autoclock' module param */
Takashi Iwai8a463222018-05-02 10:04:27 +020059 bool keep_iface; /* keep interface/altset after closing
60 * or parameter change
61 */
Daniel Mack79f920f2010-05-31 14:51:31 +020062
63 struct usb_host_interface *ctrl_intf; /* the audio control interface */
Shuah Khan66354f12019-04-01 20:40:22 -040064 struct media_device *media_dev;
65 struct media_intf_devnode *ctl_intf_media_devnode;
Hemant Kumar3f605462016-03-07 14:46:31 -080066 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-Hartman37485a32021-07-02 15:58:26 +020069
70 ANDROID_KABI_RESERVE(1);
71 ANDROID_KABI_RESERVE(2);
72 ANDROID_KABI_RESERVE(3);
73 ANDROID_KABI_RESERVE(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074};
75
Takashi Iwai716132e2021-04-06 13:35:34 +020076#define USB_AUDIO_IFACE_UNUSED ((void *)-1L)
77
Takashi Iwai0ba41d92014-02-26 13:02:17 +010078#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 Torvalds1da177e2005-04-16 15:20:36 -070087/*
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 Ladisch854af952005-07-25 16:19:10 +020095enum quirk_type {
96 QUIRK_IGNORE_INTERFACE,
97 QUIRK_COMPOSITE,
Clemens Ladischaafe77c2013-03-31 23:43:12 +020098 QUIRK_AUTODETECT,
Clemens Ladisch854af952005-07-25 16:19:10 +020099 QUIRK_MIDI_STANDARD_INTERFACE,
100 QUIRK_MIDI_FIXED_ENDPOINT,
101 QUIRK_MIDI_YAMAHA,
Clemens Ladischaafe77c2013-03-31 23:43:12 +0200102 QUIRK_MIDI_ROLAND,
Clemens Ladisch854af952005-07-25 16:19:10 +0200103 QUIRK_MIDI_MIDIMAN,
104 QUIRK_MIDI_NOVATION,
Clemens Ladischc7f57212010-10-22 18:20:48 +0200105 QUIRK_MIDI_RAW_BYTES,
Clemens Ladisch854af952005-07-25 16:19:10 +0200106 QUIRK_MIDI_EMAGIC,
Clemens Ladischcc7a59b2006-02-07 17:11:06 +0100107 QUIRK_MIDI_CME,
Krzysztof Foltman4434ade2010-05-20 20:31:10 +0100108 QUIRK_MIDI_AKAI,
Karsten Wiese030a07e42008-07-30 15:13:29 +0200109 QUIRK_MIDI_US122L,
Kristian Amlie1ef0e0a2011-08-26 13:19:49 +0200110 QUIRK_MIDI_FTDI,
Clemens Ladisch1ca8b202015-11-15 22:38:29 +0100111 QUIRK_MIDI_CH345,
Clemens Ladisch854af952005-07-25 16:19:10 +0200112 QUIRK_AUDIO_STANDARD_INTERFACE,
113 QUIRK_AUDIO_FIXED_ENDPOINT,
Pedro Lopez-Cabanillas310e0dc2008-10-04 16:27:36 +0200114 QUIRK_AUDIO_EDIROL_UAXX,
John S. Gruber52a7a582009-12-27 12:19:59 -0500115 QUIRK_AUDIO_ALIGN_TRANSFER,
Daniel Mack014950b2011-05-25 09:09:02 +0200116 QUIRK_AUDIO_STANDARD_MIXER,
Hui Wang92adc962019-12-18 21:26:50 +0800117 QUIRK_SETUP_FMT_AFTER_RESUME,
Kai-Heng Feng1965c432020-08-23 18:58:50 +0800118 QUIRK_SETUP_DISABLE_AUTOSUSPEND,
Clemens Ladisch854af952005-07-25 16:19:10 +0200119
120 QUIRK_TYPE_COUNT
121};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123struct snd_usb_audio_quirk {
124 const char *vendor_name;
125 const char *product_name;
126 int16_t ifnum;
Clemens Ladisch854af952005-07-25 16:19:10 +0200127 uint16_t type;
Shuah Khan66354f12019-04-01 20:40:22 -0400128 bool shares_media_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 const void *data;
130};
131
Julian Anastasovf4950882009-11-06 23:44:53 +0200132#define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#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 Iwai47ab1542015-08-25 16:09:00 +0200136int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
137void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
138
Takashi Iwaif274baa2018-05-27 13:01:17 +0200139extern bool snd_usb_use_vmalloc;
Takashi Iwaif35ef592019-11-14 17:56:13 +0100140extern bool snd_usb_skip_validation;
Takashi Iwaif274baa2018-05-27 13:01:17 +0200141
JaeHun Jung1eb18552020-05-26 16:53:38 +0900142struct audioformat;
143
144enum 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 */
167struct 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-Hartman37485a32021-07-02 15:58:26 +0200186
187 ANDROID_KABI_RESERVE(1);
188 ANDROID_KABI_RESERVE(2);
JaeHun Jung1eb18552020-05-26 16:53:38 +0900189};
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#endif /* __USBAUDIO_H */