1*e2be04c7SGreg 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 305e1ddb48SDavid Howells 315e1ddb48SDavid Howells /* A.2 Audio Interface Subclass Codes */ 325e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOCONTROL 0x01 335e1ddb48SDavid Howells #define USB_SUBCLASS_AUDIOSTREAMING 0x02 345e1ddb48SDavid Howells #define USB_SUBCLASS_MIDISTREAMING 0x03 355e1ddb48SDavid Howells 365e1ddb48SDavid Howells /* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ 375e1ddb48SDavid Howells #define UAC_HEADER 0x01 385e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL 0x02 395e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL 0x03 405e1ddb48SDavid Howells #define UAC_MIXER_UNIT 0x04 415e1ddb48SDavid Howells #define UAC_SELECTOR_UNIT 0x05 425e1ddb48SDavid Howells #define UAC_FEATURE_UNIT 0x06 435e1ddb48SDavid Howells #define UAC1_PROCESSING_UNIT 0x07 445e1ddb48SDavid Howells #define UAC1_EXTENSION_UNIT 0x08 455e1ddb48SDavid Howells 465e1ddb48SDavid Howells /* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ 475e1ddb48SDavid Howells #define UAC_AS_GENERAL 0x01 485e1ddb48SDavid Howells #define UAC_FORMAT_TYPE 0x02 495e1ddb48SDavid Howells #define UAC_FORMAT_SPECIFIC 0x03 505e1ddb48SDavid Howells 515e1ddb48SDavid Howells /* A.7 Processing Unit Process Types */ 525e1ddb48SDavid Howells #define UAC_PROCESS_UNDEFINED 0x00 535e1ddb48SDavid Howells #define UAC_PROCESS_UP_DOWNMIX 0x01 545e1ddb48SDavid Howells #define UAC_PROCESS_DOLBY_PROLOGIC 0x02 555e1ddb48SDavid Howells #define UAC_PROCESS_STEREO_EXTENDER 0x03 565e1ddb48SDavid Howells #define UAC_PROCESS_REVERB 0x04 575e1ddb48SDavid Howells #define UAC_PROCESS_CHORUS 0x05 585e1ddb48SDavid Howells #define UAC_PROCESS_DYN_RANGE_COMP 0x06 595e1ddb48SDavid Howells 605e1ddb48SDavid Howells /* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ 615e1ddb48SDavid Howells #define UAC_EP_GENERAL 0x01 625e1ddb48SDavid Howells 635e1ddb48SDavid Howells /* A.9 Audio Class-Specific Request Codes */ 645e1ddb48SDavid Howells #define UAC_SET_ 0x00 655e1ddb48SDavid Howells #define UAC_GET_ 0x80 665e1ddb48SDavid Howells 675e1ddb48SDavid Howells #define UAC__CUR 0x1 685e1ddb48SDavid Howells #define UAC__MIN 0x2 695e1ddb48SDavid Howells #define UAC__MAX 0x3 705e1ddb48SDavid Howells #define UAC__RES 0x4 715e1ddb48SDavid Howells #define UAC__MEM 0x5 725e1ddb48SDavid Howells 735e1ddb48SDavid Howells #define UAC_SET_CUR (UAC_SET_ | UAC__CUR) 745e1ddb48SDavid Howells #define UAC_GET_CUR (UAC_GET_ | UAC__CUR) 755e1ddb48SDavid Howells #define UAC_SET_MIN (UAC_SET_ | UAC__MIN) 765e1ddb48SDavid Howells #define UAC_GET_MIN (UAC_GET_ | UAC__MIN) 775e1ddb48SDavid Howells #define UAC_SET_MAX (UAC_SET_ | UAC__MAX) 785e1ddb48SDavid Howells #define UAC_GET_MAX (UAC_GET_ | UAC__MAX) 795e1ddb48SDavid Howells #define UAC_SET_RES (UAC_SET_ | UAC__RES) 805e1ddb48SDavid Howells #define UAC_GET_RES (UAC_GET_ | UAC__RES) 815e1ddb48SDavid Howells #define UAC_SET_MEM (UAC_SET_ | UAC__MEM) 825e1ddb48SDavid Howells #define UAC_GET_MEM (UAC_GET_ | UAC__MEM) 835e1ddb48SDavid Howells 845e1ddb48SDavid Howells #define UAC_GET_STAT 0xff 855e1ddb48SDavid Howells 865e1ddb48SDavid Howells /* A.10 Control Selector Codes */ 875e1ddb48SDavid Howells 885e1ddb48SDavid Howells /* A.10.1 Terminal Control Selectors */ 895e1ddb48SDavid Howells #define UAC_TERM_COPY_PROTECT 0x01 905e1ddb48SDavid Howells 915e1ddb48SDavid Howells /* A.10.2 Feature Unit Control Selectors */ 925e1ddb48SDavid Howells #define UAC_FU_MUTE 0x01 935e1ddb48SDavid Howells #define UAC_FU_VOLUME 0x02 945e1ddb48SDavid Howells #define UAC_FU_BASS 0x03 955e1ddb48SDavid Howells #define UAC_FU_MID 0x04 965e1ddb48SDavid Howells #define UAC_FU_TREBLE 0x05 975e1ddb48SDavid Howells #define UAC_FU_GRAPHIC_EQUALIZER 0x06 985e1ddb48SDavid Howells #define UAC_FU_AUTOMATIC_GAIN 0x07 995e1ddb48SDavid Howells #define UAC_FU_DELAY 0x08 1005e1ddb48SDavid Howells #define UAC_FU_BASS_BOOST 0x09 1015e1ddb48SDavid Howells #define UAC_FU_LOUDNESS 0x0a 1025e1ddb48SDavid Howells 1035e1ddb48SDavid Howells #define UAC_CONTROL_BIT(CS) (1 << ((CS) - 1)) 1045e1ddb48SDavid Howells 1055e1ddb48SDavid Howells /* A.10.3.1 Up/Down-mix Processing Unit Controls Selectors */ 1065e1ddb48SDavid Howells #define UAC_UD_ENABLE 0x01 1075e1ddb48SDavid Howells #define UAC_UD_MODE_SELECT 0x02 1085e1ddb48SDavid Howells 1095e1ddb48SDavid Howells /* A.10.3.2 Dolby Prologic (tm) Processing Unit Controls Selectors */ 1105e1ddb48SDavid Howells #define UAC_DP_ENABLE 0x01 1115e1ddb48SDavid Howells #define UAC_DP_MODE_SELECT 0x02 1125e1ddb48SDavid Howells 1135e1ddb48SDavid Howells /* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */ 1145e1ddb48SDavid Howells #define UAC_3D_ENABLE 0x01 1155e1ddb48SDavid Howells #define UAC_3D_SPACE 0x02 1165e1ddb48SDavid Howells 1175e1ddb48SDavid Howells /* A.10.3.4 Reverberation Processing Unit Control Selectors */ 1185e1ddb48SDavid Howells #define UAC_REVERB_ENABLE 0x01 1195e1ddb48SDavid Howells #define UAC_REVERB_LEVEL 0x02 1205e1ddb48SDavid Howells #define UAC_REVERB_TIME 0x03 1215e1ddb48SDavid Howells #define UAC_REVERB_FEEDBACK 0x04 1225e1ddb48SDavid Howells 1235e1ddb48SDavid Howells /* A.10.3.5 Chorus Processing Unit Control Selectors */ 1245e1ddb48SDavid Howells #define UAC_CHORUS_ENABLE 0x01 1255e1ddb48SDavid Howells #define UAC_CHORUS_LEVEL 0x02 1265e1ddb48SDavid Howells #define UAC_CHORUS_RATE 0x03 1275e1ddb48SDavid Howells #define UAC_CHORUS_DEPTH 0x04 1285e1ddb48SDavid Howells 1295e1ddb48SDavid Howells /* A.10.3.6 Dynamic Range Compressor Unit Control Selectors */ 1305e1ddb48SDavid Howells #define UAC_DCR_ENABLE 0x01 1315e1ddb48SDavid Howells #define UAC_DCR_RATE 0x02 1325e1ddb48SDavid Howells #define UAC_DCR_MAXAMPL 0x03 1335e1ddb48SDavid Howells #define UAC_DCR_THRESHOLD 0x04 1345e1ddb48SDavid Howells #define UAC_DCR_ATTACK_TIME 0x05 1355e1ddb48SDavid Howells #define UAC_DCR_RELEASE_TIME 0x06 1365e1ddb48SDavid Howells 1375e1ddb48SDavid Howells /* A.10.4 Extension Unit Control Selectors */ 1385e1ddb48SDavid Howells #define UAC_XU_ENABLE 0x01 1395e1ddb48SDavid Howells 1405e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Interface Descriptor Subtypes */ 1415e1ddb48SDavid Howells #define UAC_MS_HEADER 0x01 1425e1ddb48SDavid Howells #define UAC_MIDI_IN_JACK 0x02 1435e1ddb48SDavid Howells #define UAC_MIDI_OUT_JACK 0x03 1445e1ddb48SDavid Howells 1455e1ddb48SDavid Howells /* MIDI - A.1 MS Class-Specific Endpoint Descriptor Subtypes */ 1465e1ddb48SDavid Howells #define UAC_MS_GENERAL 0x01 1475e1ddb48SDavid Howells 1485e1ddb48SDavid Howells /* Terminals - 2.1 USB Terminal Types */ 1495e1ddb48SDavid Howells #define UAC_TERMINAL_UNDEFINED 0x100 1505e1ddb48SDavid Howells #define UAC_TERMINAL_STREAMING 0x101 1515e1ddb48SDavid Howells #define UAC_TERMINAL_VENDOR_SPEC 0x1FF 1525e1ddb48SDavid Howells 1535e1ddb48SDavid Howells /* Terminal Control Selectors */ 1545e1ddb48SDavid Howells /* 4.3.2 Class-Specific AC Interface Descriptor */ 1555e1ddb48SDavid Howells struct uac1_ac_header_descriptor { 1565e1ddb48SDavid Howells __u8 bLength; /* 8 + n */ 1575e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 1585e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* UAC_MS_HEADER */ 1595e1ddb48SDavid Howells __le16 bcdADC; /* 0x0100 */ 1605e1ddb48SDavid Howells __le16 wTotalLength; /* includes Unit and Terminal desc. */ 1615e1ddb48SDavid Howells __u8 bInCollection; /* n */ 1625e1ddb48SDavid Howells __u8 baInterfaceNr[]; /* [n] */ 1635e1ddb48SDavid Howells } __attribute__ ((packed)); 1645e1ddb48SDavid Howells 1655e1ddb48SDavid Howells #define UAC_DT_AC_HEADER_SIZE(n) (8 + (n)) 1665e1ddb48SDavid Howells 1675e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */ 1685e1ddb48SDavid Howells #define DECLARE_UAC_AC_HEADER_DESCRIPTOR(n) \ 1695e1ddb48SDavid Howells struct uac1_ac_header_descriptor_##n { \ 1705e1ddb48SDavid Howells __u8 bLength; \ 1715e1ddb48SDavid Howells __u8 bDescriptorType; \ 1725e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 1735e1ddb48SDavid Howells __le16 bcdADC; \ 1745e1ddb48SDavid Howells __le16 wTotalLength; \ 1755e1ddb48SDavid Howells __u8 bInCollection; \ 1765e1ddb48SDavid Howells __u8 baInterfaceNr[n]; \ 1775e1ddb48SDavid Howells } __attribute__ ((packed)) 1785e1ddb48SDavid Howells 1795e1ddb48SDavid Howells /* 4.3.2.1 Input Terminal Descriptor */ 1805e1ddb48SDavid Howells struct uac_input_terminal_descriptor { 1815e1ddb48SDavid Howells __u8 bLength; /* in bytes: 12 */ 1825e1ddb48SDavid Howells __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 1835e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* INPUT_TERMINAL descriptor subtype */ 1845e1ddb48SDavid Howells __u8 bTerminalID; /* Constant uniquely terminal ID */ 1855e1ddb48SDavid Howells __le16 wTerminalType; /* USB Audio Terminal Types */ 1865e1ddb48SDavid Howells __u8 bAssocTerminal; /* ID of the Output Terminal associated */ 1875e1ddb48SDavid Howells __u8 bNrChannels; /* Number of logical output channels */ 1885e1ddb48SDavid Howells __le16 wChannelConfig; 1895e1ddb48SDavid Howells __u8 iChannelNames; 1905e1ddb48SDavid Howells __u8 iTerminal; 1915e1ddb48SDavid Howells } __attribute__ ((packed)); 1925e1ddb48SDavid Howells 1935e1ddb48SDavid Howells #define UAC_DT_INPUT_TERMINAL_SIZE 12 1945e1ddb48SDavid Howells 1955e1ddb48SDavid Howells /* Terminals - 2.2 Input Terminal Types */ 1965e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_UNDEFINED 0x200 1975e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE 0x201 1985e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_DESKTOP_MICROPHONE 0x202 1995e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PERSONAL_MICROPHONE 0x203 2005e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_OMNI_DIR_MICROPHONE 0x204 2015e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_MICROPHONE_ARRAY 0x205 2025e1ddb48SDavid Howells #define UAC_INPUT_TERMINAL_PROC_MICROPHONE_ARRAY 0x206 2035e1ddb48SDavid Howells 2045e1ddb48SDavid Howells /* Terminals - control selectors */ 2055e1ddb48SDavid Howells 2065e1ddb48SDavid Howells #define UAC_TERMINAL_CS_COPY_PROTECT_CONTROL 0x01 2075e1ddb48SDavid Howells 2085e1ddb48SDavid Howells /* 4.3.2.2 Output Terminal Descriptor */ 2095e1ddb48SDavid Howells struct uac1_output_terminal_descriptor { 2105e1ddb48SDavid Howells __u8 bLength; /* in bytes: 9 */ 2115e1ddb48SDavid Howells __u8 bDescriptorType; /* CS_INTERFACE descriptor type */ 2125e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* OUTPUT_TERMINAL descriptor subtype */ 2135e1ddb48SDavid Howells __u8 bTerminalID; /* Constant uniquely terminal ID */ 2145e1ddb48SDavid Howells __le16 wTerminalType; /* USB Audio Terminal Types */ 2155e1ddb48SDavid Howells __u8 bAssocTerminal; /* ID of the Input Terminal associated */ 2165e1ddb48SDavid Howells __u8 bSourceID; /* ID of the connected Unit or Terminal*/ 2175e1ddb48SDavid Howells __u8 iTerminal; 2185e1ddb48SDavid Howells } __attribute__ ((packed)); 2195e1ddb48SDavid Howells 2205e1ddb48SDavid Howells #define UAC_DT_OUTPUT_TERMINAL_SIZE 9 2215e1ddb48SDavid Howells 2225e1ddb48SDavid Howells /* Terminals - 2.3 Output Terminal Types */ 2235e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_UNDEFINED 0x300 2245e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_SPEAKER 0x301 2255e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEADPHONES 0x302 2265e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_HEAD_MOUNTED_DISPLAY_AUDIO 0x303 2275e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_DESKTOP_SPEAKER 0x304 2285e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_ROOM_SPEAKER 0x305 2295e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_COMMUNICATION_SPEAKER 0x306 2305e1ddb48SDavid Howells #define UAC_OUTPUT_TERMINAL_LOW_FREQ_EFFECTS_SPEAKER 0x307 2315e1ddb48SDavid Howells 2325e1ddb48SDavid Howells /* Set bControlSize = 2 as default setting */ 2335e1ddb48SDavid Howells #define UAC_DT_FEATURE_UNIT_SIZE(ch) (7 + ((ch) + 1) * 2) 2345e1ddb48SDavid Howells 2355e1ddb48SDavid Howells /* As above, but more useful for defining your own descriptors: */ 2365e1ddb48SDavid Howells #define DECLARE_UAC_FEATURE_UNIT_DESCRIPTOR(ch) \ 2375e1ddb48SDavid Howells struct uac_feature_unit_descriptor_##ch { \ 2385e1ddb48SDavid Howells __u8 bLength; \ 2395e1ddb48SDavid Howells __u8 bDescriptorType; \ 2405e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 2415e1ddb48SDavid Howells __u8 bUnitID; \ 2425e1ddb48SDavid Howells __u8 bSourceID; \ 2435e1ddb48SDavid Howells __u8 bControlSize; \ 2445e1ddb48SDavid Howells __le16 bmaControls[ch + 1]; \ 2455e1ddb48SDavid Howells __u8 iFeature; \ 2465e1ddb48SDavid Howells } __attribute__ ((packed)) 2475e1ddb48SDavid Howells 2485e1ddb48SDavid Howells /* 4.3.2.3 Mixer Unit Descriptor */ 2495e1ddb48SDavid Howells struct uac_mixer_unit_descriptor { 2505e1ddb48SDavid Howells __u8 bLength; 2515e1ddb48SDavid Howells __u8 bDescriptorType; 2525e1ddb48SDavid Howells __u8 bDescriptorSubtype; 2535e1ddb48SDavid Howells __u8 bUnitID; 2545e1ddb48SDavid Howells __u8 bNrInPins; 2555e1ddb48SDavid Howells __u8 baSourceID[]; 2565e1ddb48SDavid Howells } __attribute__ ((packed)); 2575e1ddb48SDavid Howells 2585e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_bNrChannels(struct uac_mixer_unit_descriptor *desc) 2595e1ddb48SDavid Howells { 2605e1ddb48SDavid Howells return desc->baSourceID[desc->bNrInPins]; 2615e1ddb48SDavid Howells } 2625e1ddb48SDavid Howells 2635e1ddb48SDavid Howells static inline __u32 uac_mixer_unit_wChannelConfig(struct uac_mixer_unit_descriptor *desc, 2645e1ddb48SDavid Howells int protocol) 2655e1ddb48SDavid Howells { 2665e1ddb48SDavid Howells if (protocol == UAC_VERSION_1) 2675e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 2] << 8) | 2685e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 1]; 2695e1ddb48SDavid Howells else 2705e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 4] << 24) | 2715e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 3] << 16) | 2725e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 2] << 8) | 2735e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 1]); 2745e1ddb48SDavid Howells } 2755e1ddb48SDavid Howells 2765e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iChannelNames(struct uac_mixer_unit_descriptor *desc, 2775e1ddb48SDavid Howells int protocol) 2785e1ddb48SDavid Howells { 2795e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 2805e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 3] : 2815e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 5]; 2825e1ddb48SDavid Howells } 2835e1ddb48SDavid Howells 2845e1ddb48SDavid Howells static inline __u8 *uac_mixer_unit_bmControls(struct uac_mixer_unit_descriptor *desc, 2855e1ddb48SDavid Howells int protocol) 2865e1ddb48SDavid Howells { 2875e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 2885e1ddb48SDavid Howells &desc->baSourceID[desc->bNrInPins + 4] : 2895e1ddb48SDavid Howells &desc->baSourceID[desc->bNrInPins + 6]; 2905e1ddb48SDavid Howells } 2915e1ddb48SDavid Howells 2925e1ddb48SDavid Howells static inline __u8 uac_mixer_unit_iMixer(struct uac_mixer_unit_descriptor *desc) 2935e1ddb48SDavid Howells { 2945e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 2955e1ddb48SDavid Howells return raw[desc->bLength - 1]; 2965e1ddb48SDavid Howells } 2975e1ddb48SDavid Howells 2985e1ddb48SDavid Howells /* 4.3.2.4 Selector Unit Descriptor */ 2995e1ddb48SDavid Howells struct uac_selector_unit_descriptor { 3005e1ddb48SDavid Howells __u8 bLength; 3015e1ddb48SDavid Howells __u8 bDescriptorType; 3025e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3035e1ddb48SDavid Howells __u8 bUintID; 3045e1ddb48SDavid Howells __u8 bNrInPins; 3055e1ddb48SDavid Howells __u8 baSourceID[]; 3065e1ddb48SDavid Howells } __attribute__ ((packed)); 3075e1ddb48SDavid Howells 3085e1ddb48SDavid Howells static inline __u8 uac_selector_unit_iSelector(struct uac_selector_unit_descriptor *desc) 3095e1ddb48SDavid Howells { 3105e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 3115e1ddb48SDavid Howells return raw[desc->bLength - 1]; 3125e1ddb48SDavid Howells } 3135e1ddb48SDavid Howells 3145e1ddb48SDavid Howells /* 4.3.2.5 Feature Unit Descriptor */ 3155e1ddb48SDavid Howells struct uac_feature_unit_descriptor { 3165e1ddb48SDavid Howells __u8 bLength; 3175e1ddb48SDavid Howells __u8 bDescriptorType; 3185e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3195e1ddb48SDavid Howells __u8 bUnitID; 3205e1ddb48SDavid Howells __u8 bSourceID; 3215e1ddb48SDavid Howells __u8 bControlSize; 3225e1ddb48SDavid Howells __u8 bmaControls[0]; /* variable length */ 3235e1ddb48SDavid Howells } __attribute__((packed)); 3245e1ddb48SDavid Howells 3255e1ddb48SDavid Howells static inline __u8 uac_feature_unit_iFeature(struct uac_feature_unit_descriptor *desc) 3265e1ddb48SDavid Howells { 3275e1ddb48SDavid Howells __u8 *raw = (__u8 *) desc; 3285e1ddb48SDavid Howells return raw[desc->bLength - 1]; 3295e1ddb48SDavid Howells } 3305e1ddb48SDavid Howells 3315e1ddb48SDavid Howells /* 4.3.2.6 Processing Unit Descriptors */ 3325e1ddb48SDavid Howells struct uac_processing_unit_descriptor { 3335e1ddb48SDavid Howells __u8 bLength; 3345e1ddb48SDavid Howells __u8 bDescriptorType; 3355e1ddb48SDavid Howells __u8 bDescriptorSubtype; 3365e1ddb48SDavid Howells __u8 bUnitID; 3378bd226f9SRuslan Bilovol __le16 wProcessType; 3385e1ddb48SDavid Howells __u8 bNrInPins; 3395e1ddb48SDavid Howells __u8 baSourceID[]; 3405e1ddb48SDavid Howells } __attribute__ ((packed)); 3415e1ddb48SDavid Howells 3425e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bNrChannels(struct uac_processing_unit_descriptor *desc) 3435e1ddb48SDavid Howells { 3445e1ddb48SDavid Howells return desc->baSourceID[desc->bNrInPins]; 3455e1ddb48SDavid Howells } 3465e1ddb48SDavid Howells 3475e1ddb48SDavid Howells static inline __u32 uac_processing_unit_wChannelConfig(struct uac_processing_unit_descriptor *desc, 3485e1ddb48SDavid Howells int protocol) 3495e1ddb48SDavid Howells { 3505e1ddb48SDavid Howells if (protocol == UAC_VERSION_1) 3515e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 2] << 8) | 3525e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 1]; 3535e1ddb48SDavid Howells else 3545e1ddb48SDavid Howells return (desc->baSourceID[desc->bNrInPins + 4] << 24) | 3555e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 3] << 16) | 3565e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 2] << 8) | 3575e1ddb48SDavid Howells (desc->baSourceID[desc->bNrInPins + 1]); 3585e1ddb48SDavid Howells } 3595e1ddb48SDavid Howells 3605e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iChannelNames(struct uac_processing_unit_descriptor *desc, 3615e1ddb48SDavid Howells int protocol) 3625e1ddb48SDavid Howells { 3635e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 3645e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 3] : 3655e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 5]; 3665e1ddb48SDavid Howells } 3675e1ddb48SDavid Howells 3685e1ddb48SDavid Howells static inline __u8 uac_processing_unit_bControlSize(struct uac_processing_unit_descriptor *desc, 3695e1ddb48SDavid Howells int protocol) 3705e1ddb48SDavid Howells { 3715e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 3725e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 4] : 3735e1ddb48SDavid Howells desc->baSourceID[desc->bNrInPins + 6]; 3745e1ddb48SDavid Howells } 3755e1ddb48SDavid Howells 3765e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_bmControls(struct uac_processing_unit_descriptor *desc, 3775e1ddb48SDavid Howells int protocol) 3785e1ddb48SDavid Howells { 3795e1ddb48SDavid Howells return (protocol == UAC_VERSION_1) ? 3805e1ddb48SDavid Howells &desc->baSourceID[desc->bNrInPins + 5] : 3815e1ddb48SDavid Howells &desc->baSourceID[desc->bNrInPins + 7]; 3825e1ddb48SDavid Howells } 3835e1ddb48SDavid Howells 3845e1ddb48SDavid Howells static inline __u8 uac_processing_unit_iProcessing(struct uac_processing_unit_descriptor *desc, 3855e1ddb48SDavid Howells int protocol) 3865e1ddb48SDavid Howells { 3875e1ddb48SDavid Howells __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); 388b531f81bSPawel Moll return *(uac_processing_unit_bmControls(desc, protocol) 389b531f81bSPawel Moll + control_size); 3905e1ddb48SDavid Howells } 3915e1ddb48SDavid Howells 3925e1ddb48SDavid Howells static inline __u8 *uac_processing_unit_specific(struct uac_processing_unit_descriptor *desc, 3935e1ddb48SDavid Howells int protocol) 3945e1ddb48SDavid Howells { 3955e1ddb48SDavid Howells __u8 control_size = uac_processing_unit_bControlSize(desc, protocol); 396b531f81bSPawel Moll return uac_processing_unit_bmControls(desc, protocol) 397b531f81bSPawel Moll + control_size + 1; 3985e1ddb48SDavid Howells } 3995e1ddb48SDavid Howells 4005e1ddb48SDavid Howells /* 4.5.2 Class-Specific AS Interface Descriptor */ 4015e1ddb48SDavid Howells struct uac1_as_header_descriptor { 4025e1ddb48SDavid Howells __u8 bLength; /* in bytes: 7 */ 4035e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4045e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* AS_GENERAL */ 4055e1ddb48SDavid Howells __u8 bTerminalLink; /* Terminal ID of connected Terminal */ 4065e1ddb48SDavid Howells __u8 bDelay; /* Delay introduced by the data path */ 4075e1ddb48SDavid Howells __le16 wFormatTag; /* The Audio Data Format */ 4085e1ddb48SDavid Howells } __attribute__ ((packed)); 4095e1ddb48SDavid Howells 4105e1ddb48SDavid Howells #define UAC_DT_AS_HEADER_SIZE 7 4115e1ddb48SDavid Howells 4125e1ddb48SDavid Howells /* Formats - A.1.1 Audio Data Format Type I Codes */ 4135e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_UNDEFINED 0x0 4145e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM 0x1 4155e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_PCM8 0x2 4165e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_IEEE_FLOAT 0x3 4175e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_ALAW 0x4 4185e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_MULAW 0x5 4195e1ddb48SDavid Howells 4205e1ddb48SDavid Howells struct uac_format_type_i_continuous_descriptor { 4215e1ddb48SDavid Howells __u8 bLength; /* in bytes: 8 + (ns * 3) */ 4225e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4235e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 4245e1ddb48SDavid Howells __u8 bFormatType; /* FORMAT_TYPE_1 */ 4255e1ddb48SDavid Howells __u8 bNrChannels; /* physical channels in the stream */ 4265e1ddb48SDavid Howells __u8 bSubframeSize; /* */ 4275e1ddb48SDavid Howells __u8 bBitResolution; 4285e1ddb48SDavid Howells __u8 bSamFreqType; 4295e1ddb48SDavid Howells __u8 tLowerSamFreq[3]; 4305e1ddb48SDavid Howells __u8 tUpperSamFreq[3]; 4315e1ddb48SDavid Howells } __attribute__ ((packed)); 4325e1ddb48SDavid Howells 4335e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_CONTINUOUS_DESC_SIZE 14 4345e1ddb48SDavid Howells 4355e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor { 4365e1ddb48SDavid Howells __u8 bLength; /* in bytes: 8 + (ns * 3) */ 4375e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_INTERFACE */ 4385e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* FORMAT_TYPE */ 4395e1ddb48SDavid Howells __u8 bFormatType; /* FORMAT_TYPE_1 */ 4405e1ddb48SDavid Howells __u8 bNrChannels; /* physical channels in the stream */ 4415e1ddb48SDavid Howells __u8 bSubframeSize; /* */ 4425e1ddb48SDavid Howells __u8 bBitResolution; 4435e1ddb48SDavid Howells __u8 bSamFreqType; 4445e1ddb48SDavid Howells __u8 tSamFreq[][3]; 4455e1ddb48SDavid Howells } __attribute__ ((packed)); 4465e1ddb48SDavid Howells 4475e1ddb48SDavid Howells #define DECLARE_UAC_FORMAT_TYPE_I_DISCRETE_DESC(n) \ 4485e1ddb48SDavid Howells struct uac_format_type_i_discrete_descriptor_##n { \ 4495e1ddb48SDavid Howells __u8 bLength; \ 4505e1ddb48SDavid Howells __u8 bDescriptorType; \ 4515e1ddb48SDavid Howells __u8 bDescriptorSubtype; \ 4525e1ddb48SDavid Howells __u8 bFormatType; \ 4535e1ddb48SDavid Howells __u8 bNrChannels; \ 4545e1ddb48SDavid Howells __u8 bSubframeSize; \ 4555e1ddb48SDavid Howells __u8 bBitResolution; \ 4565e1ddb48SDavid Howells __u8 bSamFreqType; \ 4575e1ddb48SDavid Howells __u8 tSamFreq[n][3]; \ 4585e1ddb48SDavid Howells } __attribute__ ((packed)) 4595e1ddb48SDavid Howells 4605e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I_DISCRETE_DESC_SIZE(n) (8 + (n * 3)) 4615e1ddb48SDavid Howells 4625e1ddb48SDavid Howells struct uac_format_type_i_ext_descriptor { 4635e1ddb48SDavid Howells __u8 bLength; 4645e1ddb48SDavid Howells __u8 bDescriptorType; 4655e1ddb48SDavid Howells __u8 bDescriptorSubtype; 4665e1ddb48SDavid Howells __u8 bFormatType; 4675e1ddb48SDavid Howells __u8 bSubslotSize; 4685e1ddb48SDavid Howells __u8 bBitResolution; 4695e1ddb48SDavid Howells __u8 bHeaderLength; 4705e1ddb48SDavid Howells __u8 bControlSize; 4715e1ddb48SDavid Howells __u8 bSideBandProtocol; 4725e1ddb48SDavid Howells } __attribute__((packed)); 4735e1ddb48SDavid Howells 4745e1ddb48SDavid Howells /* Formats - Audio Data Format Type I Codes */ 4755e1ddb48SDavid Howells 4765e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_MPEG 0x1001 4775e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II_AC3 0x1002 4785e1ddb48SDavid Howells 4795e1ddb48SDavid Howells struct uac_format_type_ii_discrete_descriptor { 4805e1ddb48SDavid Howells __u8 bLength; 4815e1ddb48SDavid Howells __u8 bDescriptorType; 4825e1ddb48SDavid Howells __u8 bDescriptorSubtype; 4835e1ddb48SDavid Howells __u8 bFormatType; 4845e1ddb48SDavid Howells __le16 wMaxBitRate; 4855e1ddb48SDavid Howells __le16 wSamplesPerFrame; 4865e1ddb48SDavid Howells __u8 bSamFreqType; 4875e1ddb48SDavid Howells __u8 tSamFreq[][3]; 4885e1ddb48SDavid Howells } __attribute__((packed)); 4895e1ddb48SDavid Howells 4905e1ddb48SDavid Howells struct uac_format_type_ii_ext_descriptor { 4915e1ddb48SDavid Howells __u8 bLength; 4925e1ddb48SDavid Howells __u8 bDescriptorType; 4935e1ddb48SDavid Howells __u8 bDescriptorSubtype; 4945e1ddb48SDavid Howells __u8 bFormatType; 4958bd226f9SRuslan Bilovol __le16 wMaxBitRate; 4968bd226f9SRuslan Bilovol __le16 wSamplesPerFrame; 4975e1ddb48SDavid Howells __u8 bHeaderLength; 4985e1ddb48SDavid Howells __u8 bSideBandProtocol; 4995e1ddb48SDavid Howells } __attribute__((packed)); 5005e1ddb48SDavid Howells 5015e1ddb48SDavid Howells /* type III */ 5025e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_AC3 0x2001 5035e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG1_LAYER1 0x2002 5045e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_NOEXT 0x2003 5055e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_EXT 0x2004 5065e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER1_LS 0x2005 5075e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III_IEC1937_MPEG2_LAYER23_LS 0x2006 5085e1ddb48SDavid Howells 5095e1ddb48SDavid Howells /* Formats - A.2 Format Type Codes */ 5105e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_UNDEFINED 0x0 5115e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_I 0x1 5125e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_II 0x2 5135e1ddb48SDavid Howells #define UAC_FORMAT_TYPE_III 0x3 5145e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_I 0x81 5155e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_II 0x82 5165e1ddb48SDavid Howells #define UAC_EXT_FORMAT_TYPE_III 0x83 5175e1ddb48SDavid Howells 5185e1ddb48SDavid Howells struct uac_iso_endpoint_descriptor { 5195e1ddb48SDavid Howells __u8 bLength; /* in bytes: 7 */ 5205e1ddb48SDavid Howells __u8 bDescriptorType; /* USB_DT_CS_ENDPOINT */ 5215e1ddb48SDavid Howells __u8 bDescriptorSubtype; /* EP_GENERAL */ 5225e1ddb48SDavid Howells __u8 bmAttributes; 5235e1ddb48SDavid Howells __u8 bLockDelayUnits; 5245e1ddb48SDavid Howells __le16 wLockDelay; 5255e1ddb48SDavid Howells } __attribute__((packed)); 5265e1ddb48SDavid Howells #define UAC_ISO_ENDPOINT_DESC_SIZE 7 5275e1ddb48SDavid Howells 5285e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_SAMPLE_RATE 0x01 5295e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_PITCH_CONTROL 0x02 5305e1ddb48SDavid Howells #define UAC_EP_CS_ATTR_FILL_MAX 0x80 5315e1ddb48SDavid Howells 5325e1ddb48SDavid Howells /* status word format (3.7.1.1) */ 5335e1ddb48SDavid Howells 5345e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_MASK 0x0f 5355e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_CONTROL_IF 0x0 5365e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_IF 0x1 5375e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_ORIG_AUDIO_STREAM_EP 0x2 5385e1ddb48SDavid Howells 5395e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_IRQ_PENDING (1 << 7) 5405e1ddb48SDavid Howells #define UAC1_STATUS_TYPE_MEM_CHANGED (1 << 6) 5415e1ddb48SDavid Howells 5425e1ddb48SDavid Howells struct uac1_status_word { 5435e1ddb48SDavid Howells __u8 bStatusType; 5445e1ddb48SDavid Howells __u8 bOriginator; 5455e1ddb48SDavid Howells } __attribute__((packed)); 5465e1ddb48SDavid Howells 5475e1ddb48SDavid Howells 5485e1ddb48SDavid Howells #endif /* _UAPI__LINUX_USB_AUDIO_H */ 549