1 // Copyright 2017 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <zircon/device/audio.h> 8 #include <stdint.h> 9 10 namespace audio { 11 namespace intel_hda { 12 13 /* Bitfield definitions for the PCM Size/Rate property. See section 7.3.4.7 */ 14 static constexpr uint32_t IHDA_PCM_SIZE_32BITS = (1u << 20); // 32-bit PCM samples supported 15 static constexpr uint32_t IHDA_PCM_SIZE_24BITS = (1u << 19); // 24-bit PCM samples supported 16 static constexpr uint32_t IHDA_PCM_SIZE_20BITS = (1u << 18); // 20-bit PCM samples supported 17 static constexpr uint32_t IHDA_PCM_SIZE_16BITS = (1u << 17); // 16-bit PCM samples supported 18 static constexpr uint32_t IHDA_PCM_SIZE_8BITS = (1u << 16); // 8-bit PCM samples supported 19 20 static constexpr uint32_t IHDA_PCM_RATE_384000 = (1u << 11); // 384000 Hz 21 static constexpr uint32_t IHDA_PCM_RATE_192000 = (1u << 10); // 192000 Hz 22 static constexpr uint32_t IHDA_PCM_RATE_176400 = (1u << 9); // 176400 Hz 23 static constexpr uint32_t IHDA_PCM_RATE_96000 = (1u << 8); // 96000 Hz 24 static constexpr uint32_t IHDA_PCM_RATE_88200 = (1u << 7); // 88200 Hz 25 static constexpr uint32_t IHDA_PCM_RATE_48000 = (1u << 6); // 48000 Hz 26 static constexpr uint32_t IHDA_PCM_RATE_44100 = (1u << 5); // 44100 Hz 27 static constexpr uint32_t IHDA_PCM_RATE_32000 = (1u << 4); // 32000 Hz 28 static constexpr uint32_t IHDA_PCM_RATE_22050 = (1u << 3); // 22050 Hz 29 static constexpr uint32_t IHDA_PCM_RATE_16000 = (1u << 2); // 16000 Hz 30 static constexpr uint32_t IHDA_PCM_RATE_11025 = (1u << 1); // 11025 Hz 31 static constexpr uint32_t IHDA_PCM_RATE_8000 = (1u << 0); // 8000 Hz 32 33 /* Bitfield definitions for the PCM Formats property. See section 7.3.4.8 */ 34 static constexpr uint32_t IHDA_PCM_FORMAT_AC3 = (1u << 2); // Dolby Digital AC-3 / ATSC A.52 35 static constexpr uint32_t IHDA_PCM_FORMAT_FLOAT32 = (1u << 1); // 32-bit float 36 static constexpr uint32_t IHDA_PCM_FORMAT_PCM = (1u << 0); // PCM 37 38 /* Bitfield definitions for Supported Power States. See section 7.3.4.12 */ 39 static constexpr uint32_t IHDA_PWR_STATE_EPSS = (1u << 31); 40 static constexpr uint32_t IHDA_PWR_STATE_CLKSTOP = (1u << 30); 41 static constexpr uint32_t IHDA_PWR_STATE_S3D3COLD = (1u << 29); 42 static constexpr uint32_t IHDA_PWR_STATE_D3COLD = (1u << 4); 43 static constexpr uint32_t IHDA_PWR_STATE_D3 = (1u << 3); 44 static constexpr uint32_t IHDA_PWR_STATE_D2 = (1u << 2); 45 static constexpr uint32_t IHDA_PWR_STATE_D1 = (1u << 1); 46 static constexpr uint32_t IHDA_PWR_STATE_D0 = (1u << 0); 47 48 /* Defined pin capability flags. See section 7.3.4.9 and Fig. 90 */ 49 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_IMPEDANCE_SENSE = (1u << 0); 50 static constexpr uint32_t AW_PIN_CAPS_FLAG_TRIGGER_REQUIRED = (1u << 1); 51 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_PRESENCE_DETECT = (1u << 2); 52 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_DRIVE_HEADPHONES = (1u << 3); 53 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_OUTPUT = (1u << 4); 54 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_INPUT = (1u << 5); 55 static constexpr uint32_t AW_PIN_CAPS_FLAG_BALANCED_IO = (1u << 6); 56 static constexpr uint32_t AW_PIN_CAPS_FLAG_HDMI = (1u << 7); 57 static constexpr uint32_t AW_PIN_CAPS_FLAG_VREF_HIZ = (1u << 8); 58 static constexpr uint32_t AW_PIN_CAPS_FLAG_VREF_50_PERCENT = (1u << 9); 59 static constexpr uint32_t AW_PIN_CAPS_FLAG_VREF_GROUND = (1u << 10); 60 static constexpr uint32_t AW_PIN_CAPS_FLAG_VREF_80_PERCENT = (1u << 12); 61 static constexpr uint32_t AW_PIN_CAPS_FLAG_VREF_100_PERCENT = (1u << 13); 62 static constexpr uint32_t AW_PIN_CAPS_FLAG_CAN_EAPD = (1u << 16); 63 static constexpr uint32_t AW_PIN_CAPS_FLAG_DISPLAY_PORT = (1u << 24); 64 static constexpr uint32_t AW_PIN_CAPS_FLAG_HIGH_BIT_RATE = (1u << 27); 65 66 // Section 7.3.4.5 : AFG Caps 67 // Note: delays are expressed in audio frames. If a path delay value is 0, 68 // the delay should be computed by summing the delays of the widget chain 69 // used to create either the input or output paths. 70 struct AudioFunctionGroupCaps { 71 static constexpr uint32_t FLAG_HAS_BEEP_GEN = (1u << 16); 72 AudioFunctionGroupCapsAudioFunctionGroupCaps73 AudioFunctionGroupCaps() { } AudioFunctionGroupCapsAudioFunctionGroupCaps74 explicit AudioFunctionGroupCaps(uint32_t raw_data) : raw_data_(raw_data) { } 75 has_beep_genAudioFunctionGroupCaps76 bool has_beep_gen() const { return (raw_data_ & FLAG_HAS_BEEP_GEN) != 0; } path_input_delayAudioFunctionGroupCaps77 uint8_t path_input_delay() const { return static_cast<uint8_t>((raw_data_ >> 8) & 0xF); } path_output_delayAudioFunctionGroupCaps78 uint8_t path_output_delay() const { return static_cast<uint8_t>(raw_data_ & 0xF); } 79 80 uint32_t raw_data_ = 0; 81 }; 82 83 struct AudioWidgetCaps { 84 /* Defined audio widget types. See Table 138 */ 85 enum class Type : uint8_t { 86 OUTPUT = 0x0, 87 INPUT = 0x1, 88 MIXER = 0x2, 89 SELECTOR = 0x3, 90 PIN_COMPLEX = 0x4, 91 POWER = 0x5, 92 VOLUME_KNOB = 0x6, 93 BEEP_GEN = 0x7, 94 VENDOR = 0xf, 95 }; 96 97 static constexpr uint32_t FLAG_INPUT_AMP_PRESENT = (1u << 1); 98 static constexpr uint32_t FLAG_OUTPUT_AMP_PRESENT = (1u << 2); 99 static constexpr uint32_t FLAG_AMP_PARAM_OVERRIDE = (1u << 3); 100 static constexpr uint32_t FLAG_FORMAT_OVERRIDE = (1u << 4); 101 static constexpr uint32_t FLAG_STRIPE_SUPPORTED = (1u << 5); 102 static constexpr uint32_t FLAG_PROC_WIDGET = (1u << 6); 103 static constexpr uint32_t FLAG_CAN_SEND_UNSOL = (1u << 7); 104 static constexpr uint32_t FLAG_HAS_CONN_LIST = (1u << 8); 105 static constexpr uint32_t FLAG_DIGITAL = (1u << 9); 106 static constexpr uint32_t FLAG_HAS_POWER_CTL = (1u << 10); 107 static constexpr uint32_t FLAG_CAN_LR_SWAP = (1u << 11); 108 static constexpr uint32_t FLAG_HAS_CONTENT_PROT = (1u << 12); 109 AudioWidgetCapsAudioWidgetCaps110 AudioWidgetCaps() { } AudioWidgetCapsAudioWidgetCaps111 explicit AudioWidgetCaps(uint32_t raw_data) : raw_data_(raw_data) { } 112 113 /* Raw data format documented in section 7.3.4.6 */ typeAudioWidgetCaps114 Type type() const { return static_cast<Type>((raw_data_ >> 20) & 0xF); } delayAudioWidgetCaps115 uint8_t delay() const { return static_cast<uint8_t>((raw_data_ >> 16) & 0xF); } ch_countAudioWidgetCaps116 uint8_t ch_count() const { return static_cast<uint8_t>((((raw_data_ >> 12) & 0xE) | 117 (raw_data_ & 0x1)) + 1); } 118 input_amp_presentAudioWidgetCaps119 bool input_amp_present() const { return (raw_data_ & FLAG_INPUT_AMP_PRESENT) != 0; } output_amp_presentAudioWidgetCaps120 bool output_amp_present() const { return (raw_data_ & FLAG_OUTPUT_AMP_PRESENT) != 0; } amp_param_overrideAudioWidgetCaps121 bool amp_param_override() const { return (raw_data_ & FLAG_AMP_PARAM_OVERRIDE) != 0; } format_overrideAudioWidgetCaps122 bool format_override() const { return (raw_data_ & FLAG_FORMAT_OVERRIDE) != 0; } stripe_supportedAudioWidgetCaps123 bool stripe_supported() const { return (raw_data_ & FLAG_STRIPE_SUPPORTED) != 0; } proc_widgetAudioWidgetCaps124 bool proc_widget() const { return (raw_data_ & FLAG_PROC_WIDGET) != 0; } can_send_unsolAudioWidgetCaps125 bool can_send_unsol() const { return (raw_data_ & FLAG_CAN_SEND_UNSOL) != 0; } has_conn_listAudioWidgetCaps126 bool has_conn_list() const { return (raw_data_ & FLAG_HAS_CONN_LIST) != 0; } digitalAudioWidgetCaps127 bool digital() const { return (raw_data_ & FLAG_DIGITAL) != 0; } has_power_ctlAudioWidgetCaps128 bool has_power_ctl() const { return (raw_data_ & FLAG_HAS_POWER_CTL) != 0; } can_lr_swapAudioWidgetCaps129 bool can_lr_swap() const { return (raw_data_ & FLAG_CAN_LR_SWAP) != 0; } has_content_protAudioWidgetCaps130 bool has_content_prot() const { return (raw_data_ & FLAG_HAS_CONTENT_PROT) != 0; } 131 132 uint32_t raw_data_ = 0; 133 }; 134 135 struct SampleCaps { 136 // Bit packing documented in Sections 7.3.4.7 (size/rate) and 7.3.4.8 (format) SampleCapsSampleCaps137 SampleCaps() { } SampleCapsSampleCaps138 SampleCaps(uint32_t size_rate, uint32_t formats) 139 : pcm_size_rate_(size_rate), 140 pcm_formats_(formats) { } 141 142 bool SupportsRate(uint32_t rate) const; 143 bool SupportsFormat(audio_sample_format_t sample_format) const; 144 145 uint32_t pcm_size_rate_ = 0; 146 uint32_t pcm_formats_ = 0; 147 }; 148 149 struct AmpCaps { 150 // Bit packing documented in Section 7.3.4.10 AmpCapsAmpCaps151 AmpCaps() { } AmpCapsAmpCaps152 explicit AmpCaps(uint32_t raw_data) : raw_data_(raw_data) { } 153 uint32_t raw_data_ = 0; 154 can_muteAmpCaps155 bool can_mute() const { return (raw_data_ & 0x80000000) != 0; } step_sizeAmpCaps156 uint32_t step_size() const { return ((raw_data_ >> 16) & 0x7f) + 1; } num_stepsAmpCaps157 uint32_t num_steps() const { return ((raw_data_ >> 8) & 0x7f) + 1; } offsetAmpCaps158 uint32_t offset() const { return ((raw_data_ >> 0) & 0x7f); } 159 step_size_dbAmpCaps160 float step_size_db() const { return 0.25f * static_cast<float>(step_size()); } min_gain_dbAmpCaps161 float min_gain_db() const { return -step_size_db() * static_cast<float>(offset()); } max_gain_dbAmpCaps162 float max_gain_db() const { return min_gain_db() + (step_size_db() * 163 static_cast<float>((num_steps() - 1))); } 164 }; 165 166 struct PinCaps { 167 // Bit packing documented in Section 7.3.4.10 PinCapsPinCaps168 PinCaps() { } PinCapsPinCaps169 explicit PinCaps(uint32_t raw_data) : raw_data_(raw_data) { } 170 can_imp_sensePinCaps171 bool can_imp_sense() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_IMPEDANCE_SENSE; } trig_requiredPinCaps172 bool trig_required() const { return raw_data_ & AW_PIN_CAPS_FLAG_TRIGGER_REQUIRED; } can_pres_detectPinCaps173 bool can_pres_detect() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_PRESENCE_DETECT; } can_drive_headphonesPinCaps174 bool can_drive_headphones() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_DRIVE_HEADPHONES; } can_outputPinCaps175 bool can_output() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_OUTPUT; } can_inputPinCaps176 bool can_input() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_INPUT; } balanced_ioPinCaps177 bool balanced_io() const { return raw_data_ & AW_PIN_CAPS_FLAG_BALANCED_IO; } is_hdmiPinCaps178 bool is_hdmi() const { return raw_data_ & AW_PIN_CAPS_FLAG_HDMI; } vref_hi_zPinCaps179 bool vref_hi_z() const { return raw_data_ & AW_PIN_CAPS_FLAG_VREF_HIZ; } vref_50PinCaps180 bool vref_50() const { return raw_data_ & AW_PIN_CAPS_FLAG_VREF_50_PERCENT; } vref_gndPinCaps181 bool vref_gnd() const { return raw_data_ & AW_PIN_CAPS_FLAG_VREF_GROUND; } vref_80PinCaps182 bool vref_80() const { return raw_data_ & AW_PIN_CAPS_FLAG_VREF_80_PERCENT; } vref_100PinCaps183 bool vref_100() const { return raw_data_ & AW_PIN_CAPS_FLAG_VREF_100_PERCENT; } has_eapdPinCaps184 bool has_eapd() const { return raw_data_ & AW_PIN_CAPS_FLAG_CAN_EAPD; } is_display_portPinCaps185 bool is_display_port() const { return raw_data_ & AW_PIN_CAPS_FLAG_DISPLAY_PORT; } hdmi_hbrPinCaps186 bool hdmi_hbr() const { return raw_data_ & AW_PIN_CAPS_FLAG_HIGH_BIT_RATE; } 187 188 uint32_t raw_data_ = 0; 189 }; 190 191 192 struct ConfigDefaults { 193 // Bit packing documented in Section 7.3.3.31. Present only in pin complexes port_connectivityConfigDefaults194 uint8_t port_connectivity() const { return static_cast<uint8_t>((raw_data_ >> 30) & 0x03); } locationConfigDefaults195 uint8_t location() const { return static_cast<uint8_t>((raw_data_ >> 24) & 0x3F); } default_deviceConfigDefaults196 uint8_t default_device() const { return static_cast<uint8_t>((raw_data_ >> 20) & 0x0F); } connection_typeConfigDefaults197 uint8_t connection_type() const { return static_cast<uint8_t>((raw_data_ >> 16) & 0x0F); } colorConfigDefaults198 uint8_t color() const { return static_cast<uint8_t>((raw_data_ >> 12) & 0x0F); } miscConfigDefaults199 uint8_t misc() const { return static_cast<uint8_t>((raw_data_ >> 8) & 0x0F); } default_assocConfigDefaults200 uint8_t default_assoc() const { return static_cast<uint8_t>((raw_data_ >> 4) & 0x0F); } sequenceConfigDefaults201 uint8_t sequence() const { return static_cast<uint8_t>((raw_data_ >> 0) & 0x0F); } jack_detect_overrideConfigDefaults202 bool jack_detect_override() const { return (misc() & 0x01) != 0; } 203 204 uint32_t raw_data_; 205 }; 206 207 } // namespace audio 208 } // namespace intel_hda 209