Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 #ifndef __USBAUDIO_H
0003 #define __USBAUDIO_H
0004 /*
0005  *   (Tentative) USB Audio Driver for ALSA
0006  *
0007  *   Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
0008  */
0009 
0010 /* handling of USB vendor/product ID pairs as 32-bit numbers */
0011 #define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product))
0012 #define USB_ID_VENDOR(id) ((id) >> 16)
0013 #define USB_ID_PRODUCT(id) ((u16)(id))
0014 
0015 /*
0016  *
0017  */
0018 
0019 struct media_device;
0020 struct media_intf_devnode;
0021 
0022 #define MAX_CARD_INTERFACES 16
0023 
0024 struct snd_usb_audio {
0025     int index;
0026     struct usb_device *dev;
0027     struct snd_card *card;
0028     struct usb_interface *intf[MAX_CARD_INTERFACES];
0029     u32 usb_id;
0030     uint16_t quirk_type;
0031     struct mutex mutex;
0032     unsigned int system_suspend;
0033     atomic_t active;
0034     atomic_t shutdown;
0035     atomic_t usage_count;
0036     wait_queue_head_t shutdown_wait;
0037     unsigned int quirk_flags;
0038     unsigned int need_delayed_register:1; /* warn for delayed registration */
0039     int num_interfaces;
0040     int num_suspended_intf;
0041     int sample_rate_read_error;
0042 
0043     int badd_profile;       /* UAC3 BADD profile */
0044 
0045     struct list_head pcm_list;  /* list of pcm streams */
0046     struct list_head ep_list;   /* list of audio-related endpoints */
0047     struct list_head iface_ref_list; /* list of interface refcounts */
0048     struct list_head clock_ref_list; /* list of clock refcounts */
0049     int pcm_devs;
0050 
0051     struct list_head midi_list; /* list of midi interfaces */
0052 
0053     struct list_head mixer_list;    /* list of mixer interfaces */
0054 
0055     int setup;          /* from the 'device_setup' module param */
0056     bool generic_implicit_fb;   /* from the 'implicit_fb' module param */
0057     bool autoclock;         /* from the 'autoclock' module param */
0058 
0059     bool lowlatency;        /* from the 'lowlatency' module param */
0060     struct usb_host_interface *ctrl_intf;   /* the audio control interface */
0061     struct media_device *media_dev;
0062     struct media_intf_devnode *ctl_intf_media_devnode;
0063 };
0064 
0065 #define USB_AUDIO_IFACE_UNUSED  ((void *)-1L)
0066 
0067 #define usb_audio_err(chip, fmt, args...) \
0068     dev_err(&(chip)->dev->dev, fmt, ##args)
0069 #define usb_audio_warn(chip, fmt, args...) \
0070     dev_warn(&(chip)->dev->dev, fmt, ##args)
0071 #define usb_audio_info(chip, fmt, args...) \
0072     dev_info(&(chip)->dev->dev, fmt, ##args)
0073 #define usb_audio_dbg(chip, fmt, args...) \
0074     dev_dbg(&(chip)->dev->dev, fmt, ##args)
0075 
0076 /*
0077  * Information about devices with broken descriptors
0078  */
0079 
0080 /* special values for .ifnum */
0081 #define QUIRK_NODEV_INTERFACE       -3  /* return -ENODEV */
0082 #define QUIRK_NO_INTERFACE      -2
0083 #define QUIRK_ANY_INTERFACE     -1
0084 
0085 enum quirk_type {
0086     QUIRK_IGNORE_INTERFACE,
0087     QUIRK_COMPOSITE,
0088     QUIRK_AUTODETECT,
0089     QUIRK_MIDI_STANDARD_INTERFACE,
0090     QUIRK_MIDI_FIXED_ENDPOINT,
0091     QUIRK_MIDI_YAMAHA,
0092     QUIRK_MIDI_ROLAND,
0093     QUIRK_MIDI_MIDIMAN,
0094     QUIRK_MIDI_NOVATION,
0095     QUIRK_MIDI_RAW_BYTES,
0096     QUIRK_MIDI_EMAGIC,
0097     QUIRK_MIDI_CME,
0098     QUIRK_MIDI_AKAI,
0099     QUIRK_MIDI_US122L,
0100     QUIRK_MIDI_FTDI,
0101     QUIRK_MIDI_CH345,
0102     QUIRK_AUDIO_STANDARD_INTERFACE,
0103     QUIRK_AUDIO_FIXED_ENDPOINT,
0104     QUIRK_AUDIO_EDIROL_UAXX,
0105     QUIRK_AUDIO_STANDARD_MIXER,
0106 
0107     QUIRK_TYPE_COUNT
0108 };
0109 
0110 struct snd_usb_audio_quirk {
0111     const char *vendor_name;
0112     const char *product_name;
0113     int16_t ifnum;
0114     uint16_t type;
0115     const void *data;
0116 };
0117 
0118 #define combine_word(s)    ((*(s)) | ((unsigned int)(s)[1] << 8))
0119 #define combine_triple(s)  (combine_word(s) | ((unsigned int)(s)[2] << 16))
0120 #define combine_quad(s)    (combine_triple(s) | ((unsigned int)(s)[3] << 24))
0121 
0122 int snd_usb_lock_shutdown(struct snd_usb_audio *chip);
0123 void snd_usb_unlock_shutdown(struct snd_usb_audio *chip);
0124 
0125 extern bool snd_usb_use_vmalloc;
0126 extern bool snd_usb_skip_validation;
0127 
0128 /*
0129  * Driver behavior quirk flags, stored in chip->quirk_flags
0130  *
0131  * QUIRK_FLAG_GET_SAMPLE_RATE:
0132  *  Skip reading sample rate for devices, as some devices behave inconsistently
0133  *  or return error
0134  * QUIRK_FLAG_SHARE_MEDIA_DEVICE:
0135  *  Create Media Controller API entries
0136  * QUIRK_FLAG_ALIGN_TRANSFER:
0137  *  Allow alignment on audio sub-slot (channel samples) rather than on audio
0138  *  slots (audio frames)
0139  * QUIRK_TX_LENGTH:
0140  *  Add length specifier to transfers
0141  * QUIRK_FLAG_PLAYBACK_FIRST:
0142  *  Start playback stream at first even in implement feedback mode
0143  * QUIRK_FLAG_SKIP_CLOCK_SELECTOR:
0144  *  Skip clock selector setup; the device may reset to invalid state
0145  * QUIRK_FLAG_IGNORE_CLOCK_SOURCE:
0146  *  Ignore errors from clock source search; i.e. hardcoded clock
0147  * QUIRK_FLAG_ITF_USB_DSD_DAC:
0148  *  Indicates the device is for ITF-USB DSD based DACs that need a vendor cmd
0149  *  to switch between PCM and native DSD mode
0150  * QUIRK_FLAG_CTL_MSG_DELAY:
0151  *  Add a delay of 20ms at each control message handling
0152  * QUIRK_FLAG_CTL_MSG_DELAY_1M:
0153  *  Add a delay of 1-2ms at each control message handling
0154  * QUIRK_FLAG_CTL_MSG_DELAY_5M:
0155  *  Add a delay of 5-6ms at each control message handling
0156  * QUIRK_FLAG_IFACE_DELAY:
0157  *  Add a delay of 50ms at each interface setup
0158  * QUIRK_FLAG_VALIDATE_RATES:
0159  *  Perform sample rate validations at probe
0160  * QUIRK_FLAG_DISABLE_AUTOSUSPEND:
0161  *  Disable runtime PM autosuspend
0162  * QUIRK_FLAG_IGNORE_CTL_ERROR:
0163  *  Ignore errors for mixer access
0164  * QUIRK_FLAG_DSD_RAW:
0165  *  Support generic DSD raw U32_BE format
0166  * QUIRK_FLAG_SET_IFACE_FIRST:
0167  *  Set up the interface at first like UAC1
0168  * QUIRK_FLAG_GENERIC_IMPLICIT_FB
0169  *  Apply the generic implicit feedback sync mode (same as implicit_fb=1 option)
0170  * QUIRK_FLAG_SKIP_IMPLICIT_FB
0171  *  Don't apply implicit feedback sync mode
0172  */
0173 
0174 #define QUIRK_FLAG_GET_SAMPLE_RATE  (1U << 0)
0175 #define QUIRK_FLAG_SHARE_MEDIA_DEVICE   (1U << 1)
0176 #define QUIRK_FLAG_ALIGN_TRANSFER   (1U << 2)
0177 #define QUIRK_FLAG_TX_LENGTH        (1U << 3)
0178 #define QUIRK_FLAG_PLAYBACK_FIRST   (1U << 4)
0179 #define QUIRK_FLAG_SKIP_CLOCK_SELECTOR  (1U << 5)
0180 #define QUIRK_FLAG_IGNORE_CLOCK_SOURCE  (1U << 6)
0181 #define QUIRK_FLAG_ITF_USB_DSD_DAC  (1U << 7)
0182 #define QUIRK_FLAG_CTL_MSG_DELAY    (1U << 8)
0183 #define QUIRK_FLAG_CTL_MSG_DELAY_1M (1U << 9)
0184 #define QUIRK_FLAG_CTL_MSG_DELAY_5M (1U << 10)
0185 #define QUIRK_FLAG_IFACE_DELAY      (1U << 11)
0186 #define QUIRK_FLAG_VALIDATE_RATES   (1U << 12)
0187 #define QUIRK_FLAG_DISABLE_AUTOSUSPEND  (1U << 13)
0188 #define QUIRK_FLAG_IGNORE_CTL_ERROR (1U << 14)
0189 #define QUIRK_FLAG_DSD_RAW      (1U << 15)
0190 #define QUIRK_FLAG_SET_IFACE_FIRST  (1U << 16)
0191 #define QUIRK_FLAG_GENERIC_IMPLICIT_FB  (1U << 17)
0192 #define QUIRK_FLAG_SKIP_IMPLICIT_FB (1U << 18)
0193 
0194 #endif /* __USBAUDIO_H */