1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 25e1ddb48SDavid Howells /* 35e1ddb48SDavid Howells * <linux/usb/audio.h> -- USB Audio definitions. 45e1ddb48SDavid Howells * 55e1ddb48SDavid Howells * Copyright (C) 2006 Thumtronics Pty Ltd. 65e1ddb48SDavid Howells * Developed for Thumtronics by Grey Innovation 75e1ddb48SDavid Howells * Ben Williamson <ben.williamson@greyinnovation.com> 85e1ddb48SDavid Howells * 95e1ddb48SDavid Howells * This software is distributed under the terms of the GNU General Public 105e1ddb48SDavid Howells * License ("GPL") version 2, as published by the Free Software Foundation. 115e1ddb48SDavid Howells * 125e1ddb48SDavid Howells * This file holds USB constants and structures defined 135e1ddb48SDavid Howells * by the USB Device Class Definition for Audio Devices. 145e1ddb48SDavid Howells * Comments below reference relevant sections of that document: 155e1ddb48SDavid Howells * 165e1ddb48SDavid Howells * http://www.usb.org/developers/devclass_docs/audio10.pdf 175e1ddb48SDavid Howells * 185e1ddb48SDavid Howells * Types and defines in this file are either specific to version 1.0 of 195e1ddb48SDavid Howells * this standard or common for newer versions. 205e1ddb48SDavid Howells */ 215e1ddb48SDavid Howells 225e1ddb48SDavid Howells #ifndef _UAPI__LINUX_USB_AUDIO_H 235e1ddb48SDavid Howells #define _UAPI__LINUX_USB_AUDIO_H 245e1ddb48SDavid Howells 255e1ddb48SDavid Howells #include <linux/types.h> 265e1ddb48SDavid Howells 275e1ddb48SDavid Howells /* bInterfaceProtocol values to denote the version of the standard used */ 285e1ddb48SDavid Howells #define UAC_VERSION_1 0x00 295e1ddb48SDavid Howells #define UAC_VERSION_2 0x20 309a2fe9b8SRuslan Bilovol #define UAC_VERSION_3 0x30 315e1ddb48SDavid Howells 325e1ddb48SDavid Howells /* A.2 Audio Interface Subclass Codes */ 335e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOCONTROL 0x01 345e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOSTREAMING 0x02 355e1ddb48SDavid Howells #define USB_SUBCLASS_MIDISTREAMING 0x03 365e1ddb48SDavid Howells 375e1ddb48SDavid Howells /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ 385e1ddb48SDavid Howells #define UAC_HEADER 0x01 395e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL 0x02 405e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL 0x03 415e1ddb48SDavid Howells #define UAC_MIXER_UNIT 0x04 425e1ddb48SDavid Howells #define UAC_SELECTOR_UNIT 0x05 435e1ddb48SDavid Howells #define UAC_FEATURE_UNIT 0x06 445e1ddb48SDavid Howells #define UAC1_PROCESSING_UNIT 0x07 455e1ddb48SDavid Howells #define UAC1_EXTENSION_UNIT 0x08 465e1ddb48SDavid Howells 475e1ddb48SDavid Howells /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ 485e1ddb48SDavid Howells #define UAC_AS_GENERAL 0x01 495e1ddb48SDavid Howells #define UAC_FORMAT_TYPE 0x02 505e1ddb48SDavid Howells #define UAC_FORMAT_SPECIFIC 0x03 515e1ddb48SDavid Howells 525e1ddb48SDavid Howells /* A.7 Processing Unit Process Types */ 535e1ddb48SDavid Howells #define UAC_PROCESS_UNDEFINED 0x00 545e1ddb48SDavid Howells #define UAC_PROCESS_UP_DOWNMIX 0x01 555e1ddb48SDavid Howells #define UAC_PROCESS_DOLBY_PROLOGIC 0x02 565e1ddb48SDavid Howells #define UAC_PROCESS_STEREO_EXTENDER 0x03 575e1ddb48SDavid Howells #define UAC_PROCESS_REVERB 0x04 585e1ddb48SDavid Howells #define UAC_PROCESS_CHORUS 0x05 595e1ddb48SDavid Howells #define UAC_PROCESS_DYN_RANGE_COMP 0x06 605e1ddb48SDavid Howells 615e1ddb48SDavid Howells /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ 625e1ddb48SDavid Howells #define UAC_EP_GENERAL 0x01 635e1ddb48SDavid Howells 645e1ddb48SDavid Howells /* A.9 Audio Class-Specific Request Codes */ 655e1ddb48SDavid Howells #define UAC_SET_ 0x00 665e1ddb48SDavid Howells #define UAC_GET_ 0x80 675e1ddb48SDavid Howells 685e1ddb48SDavid Howells #define UAC__CUR 0x1 695e1ddb48SDavid Howells #define UAC__MIN 0x2 705e1ddb48SDavid Howells #define UAC__MAX 0x3 715e1ddb48SDavid Howells #define UAC__RES 0x4 725e1ddb48SDavid Howells #define UAC__MEM 0x5 735e1ddb48SDavid Howells 745e1ddb48SDavid Howells #define UAC_SET_CUR (UAC_SET_ | UAC__CUR) 755e1ddb48SDavid Howells #define UAC_GET_CUR (UAC_GET_ | UAC__CUR) 765e1ddb48SDavid Howells #define UAC_SET_MIN (UAC_SET_ | UAC__MIN) 775e1ddb48SDavid Howells #define UAC_GET_MIN (UAC_GET_ | UAC__MIN) 785e1ddb48SDavid Howells #define UAC_SET_MAX (UAC_SET_ | UAC__MAX) 795e1ddb48SDavid Howells #define UAC_GET_MAX (UAC_GET_ | UAC__MAX) 805e1ddb48SDavid Howells #define UAC_SET_RES (UAC_SET_ | UAC__RES) 815e1ddb48SDavid Howells #define UAC_GET_RES (UAC_GET_ | UAC__RES) 825e1ddb48SDavid Howells #define UAC_SET_MEM (UAC_SET_ | UAC__MEM) 835e1ddb48SDavid Howells #define UAC_GET_MEM (UAC_GET_ | UAC__MEM) 845e1ddb48SDavid Howells 855e1ddb48SDavid Howells #define UAC_GET_STAT 0xff 865e1ddb48SDavid Howells 875e1ddb48SDavid Howells /* A.10 Control Selector Codes */ 885e1ddb48SDavid Howells 895e1ddb48SDavid Howells /* A.10.1 Terminal Control Selectors */ 905e1ddb48SDavid Howells #define UAC_TERM_COPY_PROTECT 0x01 915e1ddb48SDavid Howells 925e1ddb48SDavid Howells /* A.10.2 Feature Unit Control Selectors */ 935e1ddb48SDavid Howells #define UAC_FU_MUTE 0x01 945e1ddb48SDavid Howells #define UAC_FU_VOLUME 0x02 955e1ddb48SDavid Howells #define UAC_FU_BASS 0x03 965e1ddb48SDavid Howells #define UAC_FU_MID 0x04 975e1ddb48SDavid Howells #define UAC_FU_TREBLE 0x05 985e1ddb48SDavid Howells #define UAC_FU_GRAPHIC_EQUALIZER 0x06 995e1ddb48SDavid Howells #define UAC_FU_AUTOMATIC_GAIN 0x07 1005e1ddb48SDavid Howells #define UAC_FU_DELAY 0x08 1015e1ddb48SDavid Howells #define UAC_FU_BASS_BOOST 0x09 1025e1ddb48SDavid Howells #define UAC_FU_LOUDNESS 0x0a 1035e1ddb48SDavid Howells 1045e1ddb48SDavid Howells #define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1)) 1055e1ddb48SDavid Howells 1065e1ddb48SDavid Howells /* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */ 1075e1ddb48SDavid Howells #define UAC_UD_ENABLE 0x01 1085e1ddb48SDavid Howells #define UAC_UD_MODE_SELECT 0x02 1095e1ddb48SDavid Howells 1105e1ddb48SDavid Howells /* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */ 1115e1ddb48SDavid Howells #define UAC_DP_ENABLE 0x01 1125e1ddb48SDavid Howells #define UAC_DP_MODE_SELECT 0x02 1135e1ddb48SDavid Howells 1145e1ddb48SDavid Howells /* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */ 1155e1ddb48SDavid Howells #define UAC_3D_ENABLE 0x01 1165e1ddb48SDavid Howells #define UAC_3D_SPACE 0x02 1175e1ddb48SDavid Howells 1185e1ddb48SDavid Howells /* A.10.3.4 Reverberation Processing Unit Control Selectors */ 1195e1ddb48SDavid Howells #define UAC_REVERB_ENABLE 0x01 1205e1ddb48SDavid Howells #define UAC_REVERB_LEVEL 0x02 1215e1ddb48SDavid Howells #define UAC_REVERB_TIME 0x03 1225e1ddb48SDavid Howells #define UAC_REVERB_FEEDBACK 0x04 1235e1ddb48SDavid Howells 1245e1ddb48SDavid Howells /* A.10.3.5 Chorus Processing Unit Control Selectors */ 1255e1ddb48SDavid Howells #define UAC_CHORUS_ENABLE 0x01 1265e1ddb48SDavid Howells #define UAC_CHORUS_LEVEL 0x02 1275e1ddb48SDavid Howells #define UAC_CHORUS_RATE 0x03 1285e1ddb48SDavid Howells #define UAC_CHORUS_DEPTH 0x04 1295e1ddb48SDavid Howells 1305e1ddb48SDavid Howells /* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */ 1315e1ddb48SDavid Howells #define UAC_DCR_ENABLE 0x01 1325e1ddb48SDavid Howells #define UAC_DCR_RATE 0x02 1335e1ddb48SDavid Howells #define UAC_DCR_MAXAMPL 0x03 1345e1ddb48SDavid Howells #define UAC_DCR_THRESHOLD 0x04 1355e1ddb48SDavid Howells #define UAC_DCR_ATTACK_TIME 0x05 1365e1ddb48SDavid Howells #define UAC_DCR_RELEASE_TIME 0x06 1375e1ddb48SDavid Howells 1385e1ddb48SDavid Howells /* A.10.4 Extension Unit Control Selectors */ 1395e1ddb48SDavid Howells #define UAC_XU_ENABLE 0x01 1405e1ddb48SDavid Howells 1415e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ 1425e1ddb48SDavid Howells #define UAC_MS_HEADER 0x01 1435e1ddb48SDavid Howells #define UAC_MIDI_IN_JACK 0x02 1445e1ddb48SDavid Howells #define UAC_MIDI_OUT_JACK 0x03 1455e1ddb48SDavid Howells 1465e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ 1475e1ddb48SDavid Howells #define UAC_MS_GENERAL 0x01 1485e1ddb48SDavid Howells 1495e1ddb48SDavid Howells /* Terminals - 2.1 USB Terminal Types */ 1505e1ddb48SDavid Howells #define UAC_TERMINAL_UNDEFINED 0x100 1515e1ddb48SDavid Howells #define UAC_TERMINAL_STREAMING 0x101 1525e1ddb48SDavid Howells #define UAC_TERMINAL_VENDOR_SPEC 0x1FF 1535e1ddb48SDavid Howells 1545e1ddb48SDavid Howells /* Terminal Control Selectors */ 1555e1ddb48SDavid Howells /* 4.3.2 Class-Specific AC Interface Descriptor */ 1565e1ddb48SDavid Howells struct uac1_ac_header_descriptor { 1575e1ddb48SDavid Howells __u8 bLength; /* 8 + n */ 1585e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 1595e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* UAC_MS_HEADER */ 1605e1ddb48SDavid Howells __le16 bcdADC; /* 0x0100 */ 1615e1ddb48SDavid Howells __le16 wTotalLength; /* includes Unit and Terminal desc. */ 1625e1ddb48SDavid Howells __u8 bInCollection; /* n */ 1635e1ddb48SDavid Howells __u8 baInterfaceNr[]; /* [n] */ 1645e1ddb48SDavid Howells } __attribute__ ((packed)); 1655e1ddb48SDavid Howells 1665e1ddb48SDavid Howells #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n)) 1675e1ddb48SDavid Howells 1685e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */ 1695e1ddb48SDavid Howells #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \ 1705e1ddb48SDavid Howells struct uac1_ac_header_descriptor_##n { \ 1715e1ddb48SDavid Howells __u8 bLength; \ 1725e1ddb48SDavid Howells __u8 bDescriptorType; \ 1735e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 1745e1ddb48SDavid Howells __le16 bcdADC; \ 1755e1ddb48SDavid Howells __le16 wTotalLength; \ 1765e1ddb48SDavid Howells __u8 bInCollection; \ 1775e1ddb48SDavid Howells __u8 baInterfaceNr[n]; \ 1785e1ddb48SDavid Howells } __attribute__ ((packed)) 1795e1ddb48SDavid Howells 1805e1ddb48SDavid Howells /* 4.3.2.1 Input Terminal Descriptor */ 1815e1ddb48SDavid Howells struct uac_input_terminal_descriptor { 1825e1ddb48SDavid Howells __u8 bLength; /* in bytes: 12 */ 1835e1ddb48SDavid Howells __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 1845e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */ 1855e1ddb48SDavid Howells __u8 bTerminalID; /* Constant uniquely terminal ID */ 1865e1ddb48SDavid Howells __le16 wTerminalType; /* USB Audio Terminal Types */ 1875e1ddb48SDavid Howells __u8 bAssocTerminal; /* ID of the Output Terminal associated */ 1885e1ddb48SDavid Howells __u8 bNrChannels; /* Number of logical output channels */ 1895e1ddb48SDavid Howells __le16 wChannelConfig; 1905e1ddb48SDavid Howells __u8 iChannelNames; 1915e1ddb48SDavid Howells __u8 iTerminal; 1925e1ddb48SDavid Howells } __attribute__ ((packed)); 1935e1ddb48SDavid Howells 1945e1ddb48SDavid Howells #define UAC_DT_INPUT_TERMINAL_SIZE 12 1955e1ddb48SDavid Howells 1965e1ddb48SDavid Howells /* Terminals - 2.2 Input Terminal Types */ 1975e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_UNDEFINED 0x200 1985e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE 0x201 1995e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202 2005e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203 2015e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204 2025e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205 2035e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206 2045e1ddb48SDavid Howells 2055e1ddb48SDavid Howells /* Terminals - control selectors */ 2065e1ddb48SDavid Howells 2075e1ddb48SDavid Howells #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01 2085e1ddb48SDavid Howells 2095e1ddb48SDavid Howells /* 4.3.2.2 Output Terminal Descriptor */ 2105e1ddb48SDavid Howells struct uac1_output_terminal_descriptor { 2115e1ddb48SDavid Howells __u8 bLength; /* in bytes: 9 */ 2125e1ddb48SDavid Howells __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 2135e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */ 2145e1ddb48SDavid Howells __u8 bTerminalID; /* Constant uniquely terminal ID */ 2155e1ddb48SDavid Howells __le16 wTerminalType; /* USB Audio Terminal Types */ 2165e1ddb48SDavid Howells __u8 bAssocTerminal; /* ID of the Input Terminal associated */ 2175e1ddb48SDavid Howells __u8 bSourceID; /* ID of the connected Unit or Terminal*/ 2185e1ddb48SDavid Howells __u8 iTerminal; 2195e1ddb48SDavid Howells } __attribute__ ((packed)); 2205e1ddb48SDavid Howells 2215e1ddb48SDavid Howells #define UAC_DT_OUTPUT_TERMINAL_SIZE 9 2225e1ddb48SDavid Howells 2235e1ddb48SDavid Howells /* Terminals - 2.3 Output Terminal Types */ 2245e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300 2255e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301 2265e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302 2275e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303 2285e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304 2295e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305 2305e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306 2315e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307 2325e1ddb48SDavid Howells 233*2dd5aa15SJorge Sanjuan /* Terminals - 2.4 Bi-directional Terminal Types */ 234*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_UNDEFINED 0x400 235*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_HANDSET 0x401 236*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_HEADSET 0x402 237*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_SPEAKER_PHONE 0x403 238*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_ECHO_SUPPRESSING 0x404 239*2dd5aa15SJorge Sanjuan #define UAC_BIDIR_TERMINAL_ECHO_CANCELING 0x405 240*2dd5aa15SJorge Sanjuan 2415e1ddb48SDavid Howells /* Set bControlSize = 2 as default setting */ 2425e1ddb48SDavid Howells #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) 2435e1ddb48SDavid Howells 2445e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */ 2455e1ddb48SDavid Howells #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \ 2465e1ddb48SDavid Howells struct uac_feature_unit_descriptor_##ch { \ 2475e1ddb48SDavid Howells __u8 bLength; \ 2485e1ddb48SDavid Howells __u8 bDescriptorType; \ 2495e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 2505e1ddb48SDavid Howells __u8 bUnitID; \ 2515e1ddb48SDavid Howells __u8 bSourceID; \ 2525e1ddb48SDavid Howells __u8 bControlSize; \ 2535e1ddb48SDavid Howells __le16 bmaControls[ch + 1]; \ 2545e1ddb48SDavid Howells __u8 iFeature; \ 2555e1ddb48SDavid Howells } __attribute__ ((packed)) 2565e1ddb48SDavid Howells 2575e1ddb48SDavid Howells /* 4.3.2.3 Mixer Unit Descriptor */ 2585e1ddb48SDavid Howells struct uac_mixer_unit_descriptor { 2595e1ddb48SDavid Howells __u8 bLength; 2605e1ddb48SDavid Howells __u8 bDescriptorType; 2615e1ddb48SDavid Howells __u8 bDescriptorSubtype; 2625e1ddb48SDavid Howells __u8 bUnitID; 2635e1ddb48SDavid Howells __u8 bNrInPins; 2645e1ddb48SDavid Howells __u8 baSourceID[]; 2655e1ddb48SDavid Howells } __attribute__ ((packed)); 2665e1ddb48SDavid Howells 2675e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc) 2685e1ddb48SDavid Howells { 2695e1ddb48SDavid Howells return desc->baSourceID[desc->bNrInPins]; 2705e1ddb48SDavid Howells } 2715e1ddb48SDavid Howells 2725e1ddb48SDavid Howells static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc, 2735e1ddb48SDavid Howells int protocol) 2745e1ddb48SDavid Howells { 2755e1ddb48SDavid Howells if (protocol == UAC_VERSION_1) 2765e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 2] << 8) | 2775e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 1]; 2785e1ddb48SDavid Howells else 2795e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 4] << 24) | 2805e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 3] << 16) | 2815e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 2] << 8) | 2825e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 1]); 2835e1ddb48SDavid Howells } 2845e1ddb48SDavid Howells 2855e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc, 2865e1ddb48SDavid Howells int protocol) 2875e1ddb48SDavid Howells { 2885e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 2895e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 3] : 2905e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 5]; 2915e1ddb48SDavid Howells } 2925e1ddb48SDavid Howells 2935e1ddb48SDavid Howells static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc, 2945e1ddb48SDavid Howells int protocol) 2955e1ddb48SDavid Howells { 2966cfd839aSJorge Sanjuan switch (protocol) { 2976cfd839aSJorge Sanjuan case UAC_VERSION_1: 2986cfd839aSJorge Sanjuan return &desc->baSourceID[desc->bNrInPins + 4]; 2996cfd839aSJorge Sanjuan case UAC_VERSION_2: 3006cfd839aSJorge Sanjuan return &desc->baSourceID[desc->bNrInPins + 6]; 3016cfd839aSJorge Sanjuan case UAC_VERSION_3: 3026cfd839aSJorge Sanjuan return &desc->baSourceID[desc->bNrInPins + 2]; 3036cfd839aSJorge Sanjuan default: 3046cfd839aSJorge Sanjuan return NULL; 3056cfd839aSJorge Sanjuan } 3066cfd839aSJorge Sanjuan } 3076cfd839aSJorge Sanjuan 3086cfd839aSJorge Sanjuan static inline __u16 uac3_mixer_unit_wClusterDescrID(struct uac_mixer_unit_descriptor *desc) 3096cfd839aSJorge Sanjuan { 3106cfd839aSJorge Sanjuan return (desc->baSourceID[desc->bNrInPins + 1] << 8) | 3116cfd839aSJorge Sanjuan desc->baSourceID[desc->bNrInPins]; 3125e1ddb48SDavid Howells } 3135e1ddb48SDavid Howells 3145e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc) 3155e1ddb48SDavid Howells { 3165e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 3175e1ddb48SDavid Howells return raw[desc->bLength - 1]; 3185e1ddb48SDavid Howells } 3195e1ddb48SDavid Howells 3205e1ddb48SDavid Howells /* 4.3.2.4 Selector Unit Descriptor */ 3215e1ddb48SDavid Howells struct uac_selector_unit_descriptor { 3225e1ddb48SDavid Howells __u8 bLength; 3235e1ddb48SDavid Howells __u8 bDescriptorType; 3245e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3255e1ddb48SDavid Howells __u8 bUintID; 3265e1ddb48SDavid Howells __u8 bNrInPins; 3275e1ddb48SDavid Howells __u8 baSourceID[]; 3285e1ddb48SDavid Howells } __attribute__ ((packed)); 3295e1ddb48SDavid Howells 3305e1ddb48SDavid Howells static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc) 3315e1ddb48SDavid Howells { 3325e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 3335e1ddb48SDavid Howells return raw[desc->bLength - 1]; 3345e1ddb48SDavid Howells } 3355e1ddb48SDavid Howells 3365e1ddb48SDavid Howells /* 4.3.2.5 Feature Unit Descriptor */ 3375e1ddb48SDavid Howells struct uac_feature_unit_descriptor { 3385e1ddb48SDavid Howells __u8 bLength; 3395e1ddb48SDavid Howells __u8 bDescriptorType; 3405e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3415e1ddb48SDavid Howells __u8 bUnitID; 3425e1ddb48SDavid Howells __u8 bSourceID; 3435e1ddb48SDavid Howells __u8 bControlSize; 3445e1ddb48SDavid Howells __u8 bmaControls[0]; /* variable length */ 3455e1ddb48SDavid Howells } __attribute__((packed)); 3465e1ddb48SDavid Howells 3475e1ddb48SDavid Howells static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc) 3485e1ddb48SDavid Howells { 3495e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 3505e1ddb48SDavid Howells return raw[desc->bLength - 1]; 3515e1ddb48SDavid Howells } 3525e1ddb48SDavid Howells 3535e1ddb48SDavid Howells /* 4.3.2.6 Processing Unit Descriptors */ 3545e1ddb48SDavid Howells struct uac_processing_unit_descriptor { 3555e1ddb48SDavid Howells __u8 bLength; 3565e1ddb48SDavid Howells __u8 bDescriptorType; 3575e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3585e1ddb48SDavid Howells __u8 bUnitID; 3598bd226f9SRuslan Bilovol __le16 wProcessType; 3605e1ddb48SDavid Howells __u8 bNrInPins; 3615e1ddb48SDavid Howells __u8 baSourceID[]; 3625e1ddb48SDavid Howells } __attribute__ ((packed)); 3635e1ddb48SDavid Howells 3645e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc) 3655e1ddb48SDavid Howells { 3665e1ddb48SDavid Howells return desc->baSourceID[desc->bNrInPins]; 3675e1ddb48SDavid Howells } 3685e1ddb48SDavid Howells 3695e1ddb48SDavid Howells static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc, 3705e1ddb48SDavid Howells int protocol) 3715e1ddb48SDavid Howells { 3725e1ddb48SDavid Howells if (protocol == UAC_VERSION_1) 3735e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 2] << 8) | 3745e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 1]; 3755e1ddb48SDavid Howells else 3765e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 4] << 24) | 3775e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 3] << 16) | 3785e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 2] << 8) | 3795e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 1]); 3805e1ddb48SDavid Howells } 3815e1ddb48SDavid Howells 3825e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc, 3835e1ddb48SDavid Howells int protocol) 3845e1ddb48SDavid Howells { 3855e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 3865e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 3] : 3875e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 5]; 3885e1ddb48SDavid Howells } 3895e1ddb48SDavid Howells 3905e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc, 3915e1ddb48SDavid Howells int protocol) 3925e1ddb48SDavid Howells { 3935e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 3945e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 4] : 395a6618f4aSKirill Marinushkin 2; /* in UAC2, this value is constant */ 3965e1ddb48SDavid Howells } 3975e1ddb48SDavid Howells 3985e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc, 3995e1ddb48SDavid Howells int protocol) 4005e1ddb48SDavid Howells { 4015e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 4025e1ddb48SDavid Howells &desc->baSourceID[desc->bNrInPins + 5] : 403a6618f4aSKirill Marinushkin &desc->baSourceID[desc->bNrInPins + 6]; 4045e1ddb48SDavid Howells } 4055e1ddb48SDavid Howells 4065e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc, 4075e1ddb48SDavid Howells int protocol) 4085e1ddb48SDavid Howells { 4095e1ddb48SDavid Howells __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); 410b531f81bSPawel Moll return *(uac_processing_unit_bmControls(desc, protocol) 411b531f81bSPawel Moll + control_size); 4125e1ddb48SDavid Howells } 4135e1ddb48SDavid Howells 4145e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc, 4155e1ddb48SDavid Howells int protocol) 4165e1ddb48SDavid Howells { 4175e1ddb48SDavid Howells __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); 418b531f81bSPawel Moll return uac_processing_unit_bmControls(desc, protocol) 419b531f81bSPawel Moll + control_size + 1; 4205e1ddb48SDavid Howells } 4215e1ddb48SDavid Howells 4225e1ddb48SDavid Howells /* 4.5.2 Class-Specific AS Interface Descriptor */ 4235e1ddb48SDavid Howells struct uac1_as_header_descriptor { 4245e1ddb48SDavid Howells __u8 bLength; /* in bytes: 7 */ 4255e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4265e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* AS_GENERAL */ 4275e1ddb48SDavid Howells __u8 bTerminalLink; /* Terminal ID of connected Terminal */ 4285e1ddb48SDavid Howells __u8 bDelay; /* Delay introduced by the data path */ 4295e1ddb48SDavid Howells __le16 wFormatTag; /* The Audio Data Format */ 4305e1ddb48SDavid Howells } __attribute__ ((packed)); 4315e1ddb48SDavid Howells 4325e1ddb48SDavid Howells #define UAC_DT_AS_HEADER_SIZE 7 4335e1ddb48SDavid Howells 4345e1ddb48SDavid Howells /* Formats - A.1.1 Audio Data Format Type I Codes */ 4355e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0 4365e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM 0x1 4375e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM8 0x2 4385e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3 4395e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_ALAW 0x4 4405e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_MULAW 0x5 4415e1ddb48SDavid Howells 4425e1ddb48SDavid Howells struct uac_format_type_i_continuous_descriptor { 4435e1ddb48SDavid Howells __u8 bLength; /* in bytes: 8 + (ns * 3) */ 4445e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4455e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 4465e1ddb48SDavid Howells __u8 bFormatType; /* FORMAT_TYPE_1 */ 4475e1ddb48SDavid Howells __u8 bNrChannels; /* physical channels in the stream */ 4485e1ddb48SDavid Howells __u8 bSubframeSize; /* */ 4495e1ddb48SDavid Howells __u8 bBitResolution; 4505e1ddb48SDavid Howells __u8 bSamFreqType; 4515e1ddb48SDavid Howells __u8 tLowerSamFreq[3]; 4525e1ddb48SDavid Howells __u8 tUpperSamFreq[3]; 4535e1ddb48SDavid Howells } __attribute__ ((packed)); 4545e1ddb48SDavid Howells 4555e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14 4565e1ddb48SDavid Howells 4575e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor { 4585e1ddb48SDavid Howells __u8 bLength; /* in bytes: 8 + (ns * 3) */ 4595e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4605e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 4615e1ddb48SDavid Howells __u8 bFormatType; /* FORMAT_TYPE_1 */ 4625e1ddb48SDavid Howells __u8 bNrChannels; /* physical channels in the stream */ 4635e1ddb48SDavid Howells __u8 bSubframeSize; /* */ 4645e1ddb48SDavid Howells __u8 bBitResolution; 4655e1ddb48SDavid Howells __u8 bSamFreqType; 4665e1ddb48SDavid Howells __u8 tSamFreq[][3]; 4675e1ddb48SDavid Howells } __attribute__ ((packed)); 4685e1ddb48SDavid Howells 4695e1ddb48SDavid Howells #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \ 4705e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor_##n { \ 4715e1ddb48SDavid Howells __u8 bLength; \ 4725e1ddb48SDavid Howells __u8 bDescriptorType; \ 4735e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 4745e1ddb48SDavid Howells __u8 bFormatType; \ 4755e1ddb48SDavid Howells __u8 bNrChannels; \ 4765e1ddb48SDavid Howells __u8 bSubframeSize; \ 4775e1ddb48SDavid Howells __u8 bBitResolution; \ 4785e1ddb48SDavid Howells __u8 bSamFreqType; \ 4795e1ddb48SDavid Howells __u8 tSamFreq[n][3]; \ 4805e1ddb48SDavid Howells } __attribute__ ((packed)) 4815e1ddb48SDavid Howells 4825e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3)) 4835e1ddb48SDavid Howells 4845e1ddb48SDavid Howells struct uac_format_type_i_ext_descriptor { 4855e1ddb48SDavid Howells __u8 bLength; 4865e1ddb48SDavid Howells __u8 bDescriptorType; 4875e1ddb48SDavid Howells __u8 bDescriptorSubtype; 4885e1ddb48SDavid Howells __u8 bFormatType; 4895e1ddb48SDavid Howells __u8 bSubslotSize; 4905e1ddb48SDavid Howells __u8 bBitResolution; 4915e1ddb48SDavid Howells __u8 bHeaderLength; 4925e1ddb48SDavid Howells __u8 bControlSize; 4935e1ddb48SDavid Howells __u8 bSideBandProtocol; 4945e1ddb48SDavid Howells } __attribute__((packed)); 4955e1ddb48SDavid Howells 4965e1ddb48SDavid Howells /* Formats - Audio Data Format Type I Codes */ 4975e1ddb48SDavid Howells 4985e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_MPEG 0x1001 4995e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_AC3 0x1002 5005e1ddb48SDavid Howells 5015e1ddb48SDavid Howells struct uac_format_type_ii_discrete_descriptor { 5025e1ddb48SDavid Howells __u8 bLength; 5035e1ddb48SDavid Howells __u8 bDescriptorType; 5045e1ddb48SDavid Howells __u8 bDescriptorSubtype; 5055e1ddb48SDavid Howells __u8 bFormatType; 5065e1ddb48SDavid Howells __le16 wMaxBitRate; 5075e1ddb48SDavid Howells __le16 wSamplesPerFrame; 5085e1ddb48SDavid Howells __u8 bSamFreqType; 5095e1ddb48SDavid Howells __u8 tSamFreq[][3]; 5105e1ddb48SDavid Howells } __attribute__((packed)); 5115e1ddb48SDavid Howells 5125e1ddb48SDavid Howells struct uac_format_type_ii_ext_descriptor { 5135e1ddb48SDavid Howells __u8 bLength; 5145e1ddb48SDavid Howells __u8 bDescriptorType; 5155e1ddb48SDavid Howells __u8 bDescriptorSubtype; 5165e1ddb48SDavid Howells __u8 bFormatType; 5178bd226f9SRuslan Bilovol __le16 wMaxBitRate; 5188bd226f9SRuslan Bilovol __le16 wSamplesPerFrame; 5195e1ddb48SDavid Howells __u8 bHeaderLength; 5205e1ddb48SDavid Howells __u8 bSideBandProtocol; 5215e1ddb48SDavid Howells } __attribute__((packed)); 5225e1ddb48SDavid Howells 5235e1ddb48SDavid Howells /* type III */ 5245e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001 5255e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002 5265e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003 5275e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004 5285e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005 5295e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006 5305e1ddb48SDavid Howells 5315e1ddb48SDavid Howells /* Formats - A.2 Format Type Codes */ 5325e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_UNDEFINED 0x0 5335e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I 0x1 5345e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II 0x2 5355e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III 0x3 5365e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_I 0x81 5375e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_II 0x82 5385e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_III 0x83 5395e1ddb48SDavid Howells 5405e1ddb48SDavid Howells struct uac_iso_endpoint_descriptor { 5415e1ddb48SDavid Howells __u8 bLength; /* in bytes: 7 */ 5425e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ 5435e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* EP_GENERAL */ 5445e1ddb48SDavid Howells __u8 bmAttributes; 5455e1ddb48SDavid Howells __u8 bLockDelayUnits; 5465e1ddb48SDavid Howells __le16 wLockDelay; 5475e1ddb48SDavid Howells } __attribute__((packed)); 5485e1ddb48SDavid Howells #define UAC_ISO_ENDPOINT_DESC_SIZE 7 5495e1ddb48SDavid Howells 5505e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01 5515e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02 5525e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_FILL_MAX 0x80 5535e1ddb48SDavid Howells 5545e1ddb48SDavid Howells /* status word format (3.7.1.1) */ 5555e1ddb48SDavid Howells 5565e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_MASK 0x0f 5575e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0 5585e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1 5595e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2 5605e1ddb48SDavid Howells 5615e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7) 5625e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6) 5635e1ddb48SDavid Howells 5645e1ddb48SDavid Howells struct uac1_status_word { 5655e1ddb48SDavid Howells __u8 bStatusType; 5665e1ddb48SDavid Howells __u8 bOriginator; 5675e1ddb48SDavid Howells } __attribute__((packed)); 5685e1ddb48SDavid Howells 5695e1ddb48SDavid Howells 5705e1ddb48SDavid Howells #endif /* _UAPI__LINUX_USB_AUDIO_H */ 571