Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [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 sndw_disable_pads[] = { |
| 30 | PAD_NC(GPP_S0, NONE), |
| 31 | PAD_NC(GPP_S1, NONE), |
| 32 | PAD_NC(GPP_S4, NONE), |
| 33 | PAD_NC(GPP_S5, NONE), |
| 34 | }; |
| 35 | |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 36 | static const struct pad_config i2s0_enable_pads[] = { |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 37 | PAD_CFG_NF(GPP_R0, NONE, DEEP, NF2), /* I2S_HP_SCLK_R */ |
| 38 | PAD_CFG_NF(GPP_R1, NONE, DEEP, NF2), /* I2S_HP_SFRM_R */ |
| 39 | PAD_CFG_NF(GPP_R2, DN_20K, DEEP, NF2), /* I2S_PCH_TX_HP_RX_STRAP */ |
| 40 | PAD_CFG_NF(GPP_R3, NONE, DEEP, NF2), /* I2S_PCH_RX_HP_TX */ |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static const struct pad_config i2s2_enable_pads[] = { |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 44 | PAD_CFG_NF(GPP_R4, NONE, DEEP, NF2), /* I2S_SPKR_SCLK_R */ |
| 45 | PAD_CFG_NF(GPP_R5, NONE, DEEP, NF2), /* I2S_SPKR_SFRM_R */ |
| 46 | PAD_CFG_NF(GPP_R6, NONE, DEEP, NF2), /* I2S_PCH_TX_SPKR_RX_R */ |
| 47 | PAD_CFG_NF(GPP_R7, NONE, DEEP, NF2), /* I2S_PCH_RX_SPKR_TX */ |
| 48 | }; |
| 49 | |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 50 | static const struct pad_config i2s0_disable_pads[] = { |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 51 | PAD_NC(GPP_R0, NONE), |
| 52 | PAD_NC(GPP_R1, NONE), |
| 53 | PAD_NC(GPP_R2, NONE), |
| 54 | PAD_NC(GPP_R3, NONE), |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static const struct pad_config i2s2_disable_pads[] = { |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 58 | PAD_NC(GPP_R4, NONE), |
| 59 | PAD_NC(GPP_R5, NONE), |
| 60 | PAD_NC(GPP_R6, NONE), |
| 61 | PAD_NC(GPP_R7, NONE), |
| 62 | }; |
| 63 | |
Sugnan Prabhu S | 22618d9 | 2021-06-04 12:57:30 +0530 | [diff] [blame] | 64 | static const struct pad_config bt_i2s_enable_pads[] = { |
| 65 | PAD_CFG_NF(GPP_VGPIO_30, NONE, DEEP, NF3), /* BT_I2S_BCLK */ |
| 66 | PAD_CFG_NF(GPP_VGPIO_31, NONE, DEEP, NF3), /* BT_I2S_SYNC */ |
| 67 | PAD_CFG_NF(GPP_VGPIO_32, NONE, DEEP, NF3), /* BT_I2S_SDO */ |
| 68 | PAD_CFG_NF(GPP_VGPIO_33, NONE, DEEP, NF3), /* BT_I2S_SDI */ |
| 69 | PAD_CFG_NF(GPP_VGPIO_34, NONE, DEEP, NF1), /* SSP2_SCLK */ |
| 70 | PAD_CFG_NF(GPP_VGPIO_35, NONE, DEEP, NF1), /* SSP2_SFRM */ |
| 71 | PAD_CFG_NF(GPP_VGPIO_36, NONE, DEEP, NF1), /* SSP_TXD */ |
| 72 | PAD_CFG_NF(GPP_VGPIO_37, NONE, DEEP, NF1), /* SSP_RXD */ |
| 73 | }; |
| 74 | |
| 75 | static const struct pad_config bt_i2s_disable_pads[] = { |
| 76 | PAD_NC(GPP_VGPIO_30, NONE), |
| 77 | PAD_NC(GPP_VGPIO_31, NONE), |
| 78 | PAD_NC(GPP_VGPIO_32, NONE), |
| 79 | PAD_NC(GPP_VGPIO_33, NONE), |
| 80 | PAD_NC(GPP_VGPIO_34, NONE), |
| 81 | PAD_NC(GPP_VGPIO_35, NONE), |
| 82 | PAD_NC(GPP_VGPIO_36, NONE), |
| 83 | PAD_NC(GPP_VGPIO_37, NONE), |
| 84 | }; |
| 85 | |
Eric Lai | 312fb71 | 2021-08-18 15:47:20 +0800 | [diff] [blame] | 86 | static void enable_i2s(void) |
| 87 | { |
| 88 | gpio_configure_pads(dmic_enable_pads, ARRAY_SIZE(dmic_enable_pads)); |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 89 | gpio_configure_pads(i2s0_enable_pads, ARRAY_SIZE(i2s0_enable_pads)); |
| 90 | gpio_configure_pads(i2s2_enable_pads, ARRAY_SIZE(i2s2_enable_pads)); |
Eric Lai | 312fb71 | 2021-08-18 15:47:20 +0800 | [diff] [blame] | 91 | gpio_configure_pads(sndw_disable_pads, ARRAY_SIZE(sndw_disable_pads)); |
| 92 | } |
| 93 | |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 94 | static void fw_config_handle(void *unused) |
| 95 | { |
| 96 | if (!fw_config_is_provisioned() || fw_config_probe(FW_CONFIG(AUDIO, AUDIO_UNKNOWN))) { |
| 97 | printk(BIOS_INFO, "Disable audio related GPIO pins.\n"); |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 98 | gpio_configure_pads(i2s0_disable_pads, ARRAY_SIZE(i2s0_disable_pads)); |
| 99 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 100 | gpio_configure_pads(dmic_disable_pads, ARRAY_SIZE(dmic_disable_pads)); |
| 101 | gpio_configure_pads(sndw_disable_pads, ARRAY_SIZE(sndw_disable_pads)); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (fw_config_probe(FW_CONFIG(AUDIO, MAX98373_ALC5682_SNDW))) { |
| 106 | printk(BIOS_INFO, "Configure audio over SoundWire with MAX98373 ALC5682.\n"); |
| 107 | gpio_configure_pads(dmic_enable_pads, ARRAY_SIZE(dmic_enable_pads)); |
| 108 | gpio_configure_pads(sndw_enable_pads, ARRAY_SIZE(sndw_enable_pads)); |
Sugnan Prabhu S | 22618d9 | 2021-06-04 12:57:30 +0530 | [diff] [blame] | 109 | printk(BIOS_INFO, "BT offload enabled\n"); |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 110 | gpio_configure_pads(i2s0_enable_pads, ARRAY_SIZE(i2s0_enable_pads)); |
| 111 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
Sugnan Prabhu S | 22618d9 | 2021-06-04 12:57:30 +0530 | [diff] [blame] | 112 | gpio_configure_pads(bt_i2s_enable_pads, ARRAY_SIZE(bt_i2s_enable_pads)); |
| 113 | } else { |
| 114 | printk(BIOS_INFO, "BT offload disabled\n"); |
Sugnan Prabhu S | 1de9086 | 2021-10-06 18:42:43 +0530 | [diff] [blame] | 115 | gpio_configure_pads(i2s0_disable_pads, ARRAY_SIZE(i2s0_disable_pads)); |
| 116 | gpio_configure_pads(i2s2_disable_pads, ARRAY_SIZE(i2s2_disable_pads)); |
Sugnan Prabhu S | 22618d9 | 2021-06-04 12:57:30 +0530 | [diff] [blame] | 117 | gpio_configure_pads(bt_i2s_disable_pads, ARRAY_SIZE(bt_i2s_disable_pads)); |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | if (fw_config_probe(FW_CONFIG(AUDIO, MAX98357_ALC5682I_I2S))) { |
| 121 | printk(BIOS_INFO, "Configure audio over I2S with MAX98357 ALC5682I.\n"); |
Eric Lai | 312fb71 | 2021-08-18 15:47:20 +0800 | [diff] [blame] | 122 | enable_i2s(); |
| 123 | } |
| 124 | |
| 125 | if (fw_config_probe(FW_CONFIG(AUDIO, ALC1019_NAU88L25B_I2S))) { |
| 126 | printk(BIOS_INFO, "Configure audio over I2S with ALC1019 NAU88L25B.\n"); |
| 127 | enable_i2s(); |
Sugnan Prabhu S | 3bfa1bd | 2021-05-12 11:44:47 +0530 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, fw_config_handle, NULL); |