Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <bootstate.h> |
| 4 | #include <console/console.h> |
| 5 | #include <fw_config.h> |
| 6 | #include <gpio.h> |
| 7 | |
| 8 | static const struct pad_config dmic_enable_pads[] = { |
| 9 | PAD_CFG_NF(GPP_S2, NONE, DEEP, NF2), /* DMIC_CLK0_R */ |
| 10 | PAD_CFG_NF(GPP_S3, NONE, DEEP, NF2), /* DMIC_DATA0_R */ |
| 11 | PAD_CFG_NF(GPP_S6, NONE, DEEP, NF2), /* DMIC_CLK1_R */ |
| 12 | PAD_CFG_NF(GPP_S7, NONE, DEEP, NF2), /* DMIC_DATA1_R */ |
| 13 | }; |
| 14 | |
| 15 | static const struct pad_config dmic_disable_pads[] = { |
| 16 | PAD_NC(GPP_S2, NONE), |
| 17 | PAD_NC(GPP_S3, NONE), |
| 18 | PAD_NC(GPP_S6, NONE), |
| 19 | PAD_NC(GPP_S7, NONE), |
| 20 | }; |
| 21 | |
| 22 | static const struct pad_config sndw_enable_pads[] = { |
| 23 | PAD_CFG_NF(GPP_S0, NONE, DEEP, NF1), /* SDW_HP_CLK_R */ |
| 24 | PAD_CFG_NF(GPP_S1, NONE, DEEP, NF1), /* SDW_HP_DATA_R */ |
| 25 | PAD_CFG_NF(GPP_S4, NONE, DEEP, NF1), /* SDW_SPKR_CLK */ |
| 26 | PAD_CFG_NF(GPP_S5, NONE, DEEP, NF1), /* SDW_SPKR_DATA */ |
| 27 | }; |
| 28 | |
| 29 | static const struct pad_config max98360_enable_pads[] = { |
| 30 | PAD_CFG_NF(GPP_S0, NONE, DEEP, NF4), /* I2S_SPKR_SCLK_R */ |
| 31 | PAD_CFG_NF(GPP_S1, NONE, DEEP, NF4), /* I2S_SPKR_SFRM_R */ |
| 32 | PAD_CFG_NF(GPP_S2, NONE, DEEP, NF4), /* I2S_PCH_TX_SPKR_RX_R */ |
| 33 | PAD_CFG_NF(GPP_S3, NONE, DEEP, NF4), /* I2S_PCH_RX_SPKR_TX */ |
| 34 | PAD_CFG_NF(GPP_S6, NONE, DEEP, NF2), /* DMIC_CLK0_R */ |
| 35 | PAD_CFG_NF(GPP_S7, NONE, DEEP, NF2), /* DMIC_DATA0_R */ |
| 36 | PAD_CFG_NF(GPP_R4, NONE, DEEP, NF3), /* DMIC_CLK1_R */ |
| 37 | PAD_CFG_NF(GPP_R5, NONE, DEEP, NF3), /* DMIC_DATA1_R */ |
| 38 | PAD_NC(GPP_R6, NONE), |
| 39 | PAD_NC(GPP_R7, NONE), |
| 40 | }; |
| 41 | |
Mac Chiang | eefdfb5 | 2023-06-20 04:30:40 -0400 | [diff] [blame] | 42 | static const struct pad_config nau8318_enable_pads[] = { |
| 43 | PAD_CFG_GPO(GPP_R7, 0, DEEP), /* SPK_BEEP_EN */ |
| 44 | }; |
| 45 | |
Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 46 | static const struct pad_config sndw_disable_pads[] = { |
| 47 | PAD_NC(GPP_S0, NONE), |
| 48 | PAD_NC(GPP_S1, NONE), |
| 49 | PAD_NC(GPP_S4, NONE), |
| 50 | PAD_NC(GPP_S5, NONE), |
| 51 | }; |
| 52 | |
| 53 | static const struct pad_config i2s0_enable_pads[] = { |
| 54 | PAD_CFG_NF(GPP_R0, NONE, DEEP, NF2), /* I2S_HP_SCLK_R */ |
| 55 | PAD_CFG_NF(GPP_R1, NONE, DEEP, NF2), /* I2S_HP_SFRM_R */ |
| 56 | PAD_CFG_NF(GPP_R2, DN_20K, DEEP, NF2), /* I2S_PCH_TX_HP_RX_STRAP */ |
| 57 | PAD_CFG_NF(GPP_R3, NONE, DEEP, NF2), /* I2S_PCH_RX_HP_TX */ |
| 58 | }; |
| 59 | |
| 60 | static const struct pad_config i2s2_enable_pads[] = { |
| 61 | PAD_CFG_NF(GPP_R4, NONE, DEEP, NF2), /* I2S_SPKR_SCLK_R */ |
| 62 | PAD_CFG_NF(GPP_R5, NONE, DEEP, NF2), /* I2S_SPKR_SFRM_R */ |
| 63 | PAD_CFG_NF(GPP_R6, NONE, DEEP, NF2), /* I2S_PCH_TX_SPKR_RX_R */ |
| 64 | PAD_CFG_NF(GPP_R7, NONE, DEEP, NF2), /* I2S_PCH_RX_SPKR_TX */ |
| 65 | }; |
| 66 | |
| 67 | static const struct pad_config i2s0_disable_pads[] = { |
| 68 | PAD_NC(GPP_R0, NONE), |
| 69 | PAD_NC(GPP_R1, NONE), |
| 70 | PAD_NC(GPP_R2, NONE), |
| 71 | PAD_NC(GPP_R3, NONE), |
| 72 | }; |
| 73 | |
| 74 | static const struct pad_config i2s2_disable_pads[] = { |
| 75 | PAD_NC(GPP_R4, NONE), |
| 76 | PAD_NC(GPP_R5, NONE), |
| 77 | PAD_NC(GPP_R6, NONE), |
| 78 | PAD_NC(GPP_R7, NONE), |
| 79 | }; |
| 80 | |
| 81 | static const struct pad_config bt_i2s_enable_pads[] = { |
| 82 | PAD_CFG_NF(GPP_VGPIO_30, NONE, DEEP, NF3), /* BT_I2S_BCLK */ |
| 83 | PAD_CFG_NF(GPP_VGPIO_31, NONE, DEEP, NF3), /* BT_I2S_SYNC */ |
| 84 | PAD_CFG_NF(GPP_VGPIO_32, NONE, DEEP, NF3), /* BT_I2S_SDO */ |
| 85 | PAD_CFG_NF(GPP_VGPIO_33, NONE, DEEP, NF3), /* BT_I2S_SDI */ |
| 86 | PAD_CFG_NF(GPP_VGPIO_34, NONE, DEEP, NF1), /* SSP2_SCLK */ |
| 87 | PAD_CFG_NF(GPP_VGPIO_35, NONE, DEEP, NF1), /* SSP2_SFRM */ |
| 88 | PAD_CFG_NF(GPP_VGPIO_36, NONE, DEEP, NF1), /* SSP_TXD */ |
| 89 | PAD_CFG_NF(GPP_VGPIO_37, NONE, DEEP, NF1), /* SSP_RXD */ |
| 90 | }; |
| 91 | |
| 92 | static const struct pad_config bt_i2s_disable_pads[] = { |
| 93 | PAD_NC(GPP_VGPIO_30, NONE), |
| 94 | PAD_NC(GPP_VGPIO_31, NONE), |
| 95 | PAD_NC(GPP_VGPIO_32, NONE), |
| 96 | PAD_NC(GPP_VGPIO_33, NONE), |
| 97 | PAD_NC(GPP_VGPIO_34, NONE), |
| 98 | PAD_NC(GPP_VGPIO_35, NONE), |
| 99 | PAD_NC(GPP_VGPIO_36, NONE), |
| 100 | PAD_NC(GPP_VGPIO_37, NONE), |
| 101 | }; |
| 102 | |
Nick Vaccaro | 6615c60 | 2023-11-17 10:36:49 -0800 | [diff] [blame^] | 103 | static const struct pad_config lte_disable_pads[] = { |
| 104 | /* A7 : WWAN_PCIE_WAKE_ODL */ |
| 105 | PAD_NC(GPP_A7, NONE), |
| 106 | /* A8 : WWAN_RF_DISABLE_ODL */ |
| 107 | PAD_NC(GPP_A8, NONE), |
| 108 | /* D5 : SRCCLKREQ0# ==> WWAN_DPR_SAR_ODL */ |
| 109 | PAD_NC(GPP_D5, NONE), |
| 110 | /* E0 : SATAXPCIE0 ==> WWAN_PERST_L */ |
| 111 | PAD_NC(GPP_E0, NONE), |
| 112 | /* E10 : THC0_SPI1_CS# ==> WWAN_CONFIG0 */ |
| 113 | PAD_NC_LOCK(GPP_E10, NONE, LOCK_CONFIG), |
| 114 | /* E16 : WWAN_RST_L */ |
| 115 | PAD_NC(GPP_E16, NONE), |
| 116 | /* E17 : THC0_SPI1_INT# ==> WWAN_CONFIG3 */ |
| 117 | PAD_NC_LOCK(GPP_E17, NONE, LOCK_CONFIG), |
| 118 | /* F21 : EXT_PWR_GATE2# ==> WWAN_FCPO_L */ |
| 119 | PAD_NC(GPP_F21, NONE), |
| 120 | /* H23 : SRCCLKREQ5# ==> WWAN_CLKREQ_ODL */ |
| 121 | PAD_NC(GPP_H23, NONE), |
| 122 | /* GPD11 : LANPHYC ==> WWAN_CONFIG1 */ |
| 123 | PAD_NC(GPD11, NONE), |
| 124 | }; |
| 125 | |
Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 126 | static void enable_i2s(void) |
| 127 | { |
| 128 | gpio_configure_pads(dmic_enable_pads, ARRAY_SIZE(dmic_enable_pads)); |
| 129 | gpio_configure_pads(i2s0_enable_pads, ARRAY_SIZE(i2s0_enable_pads)); |
| 130 | gpio_configure_pads(i2s2_enable_pads, ARRAY_SIZE(i2s2_enable_pads)); |
| 131 | gpio_configure_pads(sndw_disable_pads, ARRAY_SIZE(sndw_disable_pads)); |
| 132 | } |
| 133 | |
| 134 | static void fw_config_handle(void *unused) |
| 135 | { |
| 136 | if (!fw_config_is_provisioned() || fw_config_probe(FW_CONFIG(AUDIO, AUDIO_UNKNOWN))) { |
| 137 | printk(BIOS_INFO, "Disable audio related GPIO pins.\n"); |
| 138 | gpio_configure_pads(i2s0_disable_pads, ARRAY_SIZE(i2s0_disable_pads)); |
| 139 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
| 140 | gpio_configure_pads(dmic_disable_pads, ARRAY_SIZE(dmic_disable_pads)); |
| 141 | gpio_configure_pads(sndw_disable_pads, ARRAY_SIZE(sndw_disable_pads)); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | if (fw_config_probe(FW_CONFIG(AUDIO, MAX98373_ALC5682_SNDW))) { |
| 146 | printk(BIOS_INFO, "Configure audio over SoundWire with MAX98373 ALC5682.\n"); |
| 147 | gpio_configure_pads(dmic_enable_pads, ARRAY_SIZE(dmic_enable_pads)); |
| 148 | gpio_configure_pads(sndw_enable_pads, ARRAY_SIZE(sndw_enable_pads)); |
| 149 | printk(BIOS_INFO, "BT offload enabled\n"); |
| 150 | gpio_configure_pads(i2s0_enable_pads, ARRAY_SIZE(i2s0_enable_pads)); |
| 151 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
| 152 | gpio_configure_pads(bt_i2s_enable_pads, ARRAY_SIZE(bt_i2s_enable_pads)); |
| 153 | } else if (!fw_config_probe(FW_CONFIG(AUDIO, MAX98360_ALC5682I_I2S))) { |
| 154 | printk(BIOS_INFO, "BT offload disabled\n"); |
| 155 | gpio_configure_pads(i2s0_disable_pads, ARRAY_SIZE(i2s0_disable_pads)); |
| 156 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
| 157 | gpio_configure_pads(bt_i2s_disable_pads, ARRAY_SIZE(bt_i2s_disable_pads)); |
| 158 | } |
| 159 | |
| 160 | if (fw_config_probe(FW_CONFIG(AUDIO, MAX98357_ALC5682I_I2S))) { |
| 161 | printk(BIOS_INFO, "Configure audio over I2S with MAX98357 ALC5682I.\n"); |
| 162 | enable_i2s(); |
| 163 | } |
| 164 | |
| 165 | if (fw_config_probe(FW_CONFIG(AUDIO, ALC1019_NAU88L25B_I2S))) { |
| 166 | printk(BIOS_INFO, "Configure audio over I2S with ALC1019 NAU88L25B.\n"); |
| 167 | enable_i2s(); |
| 168 | } |
| 169 | |
Mac Chiang | eefdfb5 | 2023-06-20 04:30:40 -0400 | [diff] [blame] | 170 | if (fw_config_probe(FW_CONFIG(AUDIO, MAX98360_ALC5682I_I2S)) || |
| 171 | fw_config_probe(FW_CONFIG(AUDIO, NAU8318_NAU88L25B_I2S))) { |
Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 172 | printk(BIOS_INFO, "Configure audio over I2S with MAX98360 ALC5682I.\n"); |
| 173 | gpio_configure_pads(max98360_enable_pads, ARRAY_SIZE(max98360_enable_pads)); |
| 174 | printk(BIOS_INFO, "BT offload enabled\n"); |
| 175 | gpio_configure_pads(i2s0_enable_pads, ARRAY_SIZE(i2s0_enable_pads)); |
| 176 | gpio_configure_pads(bt_i2s_enable_pads, ARRAY_SIZE(bt_i2s_enable_pads)); |
Mac Chiang | eefdfb5 | 2023-06-20 04:30:40 -0400 | [diff] [blame] | 177 | |
| 178 | if (fw_config_probe(FW_CONFIG(AUDIO, NAU8318_NAU88L25B_I2S))) |
| 179 | gpio_configure_pads(nau8318_enable_pads, ARRAY_SIZE(nau8318_enable_pads)); |
Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 180 | } |
Nick Vaccaro | 6615c60 | 2023-11-17 10:36:49 -0800 | [diff] [blame^] | 181 | |
| 182 | if (fw_config_probe(FW_CONFIG(DB_LTE, LTE_ABSENT))) { |
| 183 | printk(BIOS_INFO, "Disable LTE related GPIO pins.\n"); |
| 184 | gpio_configure_pads(lte_disable_pads, ARRAY_SIZE(lte_disable_pads)); |
| 185 | } |
Nick Vaccaro | 6afd727 | 2022-08-17 12:55:24 -0700 | [diff] [blame] | 186 | } |
| 187 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fw_config_handle, NULL); |