^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __USBAUDIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __USBAUDIO_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (Tentative) USB Audio Driver for ALSA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /* handling of USB vendor/product ID pairs as 32-bit numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define USB_ID(vendor, product) (((vendor) << 16) | (product))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define USB_ID_VENDOR(id) ((id) >> 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define USB_ID_PRODUCT(id) ((u16)(id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/android_kabi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct media_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct media_intf_devnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define MAX_CARD_INTERFACES 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct snd_usb_audio {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct usb_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct usb_interface *intf[MAX_CARD_INTERFACES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u32 usb_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) uint16_t quirk_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct mutex mutex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned int system_suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) atomic_t active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) atomic_t shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) atomic_t usage_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) wait_queue_head_t shutdown_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned int txfr_quirk:1; /* Subframe boundaries on transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) unsigned int tx_length_quirk:1; /* Put length specifier in transfers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) unsigned int setup_fmt_after_resume_quirk:1; /* setup the format to interface after resume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned int need_delayed_register:1; /* warn for delayed registration */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int num_interfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int num_suspended_intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int sample_rate_read_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int badd_profile; /* UAC3 BADD profile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct list_head pcm_list; /* list of pcm streams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct list_head ep_list; /* list of audio-related endpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int pcm_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct list_head midi_list; /* list of midi interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct list_head mixer_list; /* list of mixer interfaces */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) int setup; /* from the 'device_setup' module param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) bool autoclock; /* from the 'autoclock' module param */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) bool keep_iface; /* keep interface/altset after closing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * or parameter change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct usb_host_interface *ctrl_intf; /* the audio control interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct media_device *media_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct media_intf_devnode *ctl_intf_media_devnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct mutex dev_lock; /* to protect any race with disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int card_num; /* cache pcm card number to use upon disconnect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) void (*disconnect_cb)(struct snd_usb_audio *chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ANDROID_KABI_RESERVE(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) ANDROID_KABI_RESERVE(3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ANDROID_KABI_RESERVE(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define USB_AUDIO_IFACE_UNUSED ((void *)-1L)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define usb_audio_err(chip, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) dev_err(&(chip)->dev->dev, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define usb_audio_warn(chip, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) dev_warn(&(chip)->dev->dev, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define usb_audio_info(chip, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) dev_info(&(chip)->dev->dev, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define usb_audio_dbg(chip, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) dev_dbg(&(chip)->dev->dev, fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Information about devices with broken descriptors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* special values for .ifnum */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define QUIRK_NO_INTERFACE -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define QUIRK_ANY_INTERFACE -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) enum quirk_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) QUIRK_IGNORE_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) QUIRK_COMPOSITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) QUIRK_AUTODETECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) QUIRK_MIDI_STANDARD_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) QUIRK_MIDI_FIXED_ENDPOINT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) QUIRK_MIDI_YAMAHA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) QUIRK_MIDI_ROLAND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) QUIRK_MIDI_MIDIMAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) QUIRK_MIDI_NOVATION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) QUIRK_MIDI_RAW_BYTES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) QUIRK_MIDI_EMAGIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) QUIRK_MIDI_CME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) QUIRK_MIDI_AKAI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) QUIRK_MIDI_US122L,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) QUIRK_MIDI_FTDI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) QUIRK_MIDI_CH345,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) QUIRK_AUDIO_STANDARD_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) QUIRK_AUDIO_FIXED_ENDPOINT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) QUIRK_AUDIO_EDIROL_UAXX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) QUIRK_AUDIO_ALIGN_TRANSFER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) QUIRK_AUDIO_STANDARD_MIXER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) QUIRK_SETUP_FMT_AFTER_RESUME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) QUIRK_SETUP_DISABLE_AUTOSUSPEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) QUIRK_TYPE_COUNT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct snd_usb_audio_quirk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) const char *vendor_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const char *product_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int16_t ifnum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) uint16_t type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) bool shares_media_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) const void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) #define combine_word(s) ((*(s)) | ((unsigned int)(s)[1] << 8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) #define combine_triple(s) (combine_word(s) | ((unsigned int)(s)[2] << 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #define combine_quad(s) (combine_triple(s) | ((unsigned int)(s)[3] << 24))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) extern bool snd_usb_use_vmalloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) extern bool snd_usb_skip_validation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct audioformat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) enum snd_vendor_pcm_open_close {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) SOUND_PCM_CLOSE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) SOUND_PCM_OPEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * struct snd_usb_audio_vendor_ops - function callbacks for USB audio accelerators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * @connect: called when a new interface is found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * @disconnect: called when an interface is removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * @set_interface: called when an interface is initialized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * @set_rate: called when the rate is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * @set_pcm_buf: called when the pcm buffer is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @set_pcm_intf: called when the pcm interface is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @set_pcm_connection: called when pcm is opened/closed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * @set_pcm_binterval: called when the pcm binterval is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * @usb_add_ctls: called when USB controls are added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * Set of callbacks for some accelerated USB audio streaming hardware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * TODO: make this USB host-controller specific, right now this only works for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * one USB controller in the system at a time, which is only realistic for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * self-contained systems like phones.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct snd_usb_audio_vendor_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int (*connect)(struct usb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) void (*disconnect)(struct usb_interface *intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int (*set_interface)(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct usb_host_interface *alts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int iface, int alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int (*set_rate)(struct usb_interface *intf, int iface, int rate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int (*set_pcm_buf)(struct usb_device *udev, int iface);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int (*set_pcm_intf)(struct usb_interface *intf, int iface, int alt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int (*set_pcm_connection)(struct usb_device *udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) enum snd_vendor_pcm_open_close onoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int (*set_pcm_binterval)(struct audioformat *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct audioformat *found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int *cur_attr, int *attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int (*usb_add_ctls)(struct snd_usb_audio *chip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ANDROID_KABI_RESERVE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ANDROID_KABI_RESERVE(2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #endif /* __USBAUDIO_H */