Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
Raul E Rangel | 6fce9cd | 2021-04-06 15:42:51 -0600 | [diff] [blame] | 5 | #include <amdblocks/acpimmio.h> |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 6 | #include <amdblocks/amd_pci_util.h> |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 7 | #include <baseboard/variants.h> |
Kyösti Mälkki | 89a5f0f | 2021-06-15 07:22:22 +0300 | [diff] [blame] | 8 | #include <console/console.h> |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 9 | #include <device/device.h> |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 10 | #include <gpio.h> |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 11 | #include <soc/acpi.h> |
Mathew King | ad83023 | 2021-02-23 13:08:15 -0700 | [diff] [blame] | 12 | #include <variant/ec.h> |
Mathew King | 5d47887 | 2021-02-16 14:05:15 -0700 | [diff] [blame] | 13 | #include <vendorcode/google/chromeos/chromeos.h> |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 14 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 15 | #define BACKLIGHT_GPIO GPIO_129 |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame^] | 16 | #define WWAN_AUX_RST_GPIO GPIO_18 |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 17 | #define METHOD_BACKLIGHT_ENABLE "\\_SB.BKEN" |
| 18 | #define METHOD_BACKLIGHT_DISABLE "\\_SB.BKDS" |
| 19 | #define METHOD_MAINBOARD_INI "\\_SB.MINI" |
| 20 | #define METHOD_MAINBOARD_WAK "\\_SB.MWAK" |
| 21 | #define METHOD_MAINBOARD_PTS "\\_SB.MPTS" |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame^] | 22 | #define METHOD_MAINBOARD_S0X "\\_SB.MS0X" |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 23 | |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 24 | /* |
| 25 | * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01. |
| 26 | * This table is responsible for physically routing the PIC and |
| 27 | * IOAPIC IRQs to the different PCI devices on the system. It |
| 28 | * is read and written via registers 0xC00/0xC01 as an |
| 29 | * Index/Data pair. These values are chipset and mainboard |
| 30 | * dependent and should be updated accordingly. |
| 31 | */ |
| 32 | static uint8_t fch_pic_routing[0x80]; |
| 33 | static uint8_t fch_apic_routing[0x80]; |
| 34 | |
| 35 | _Static_assert(sizeof(fch_pic_routing) == sizeof(fch_apic_routing), |
| 36 | "PIC and APIC FCH interrupt tables must be the same size"); |
| 37 | |
| 38 | /* |
| 39 | * This controls the device -> IRQ routing. |
| 40 | * |
| 41 | * Hardcoded IRQs: |
| 42 | * 0: timer < soc/amd/common/acpi/lpc.asl |
| 43 | * 1: i8042 - Keyboard |
| 44 | * 2: cascade |
| 45 | * 8: rtc0 <- soc/amd/common/acpi/lpc.asl |
| 46 | * 9: acpi <- soc/amd/common/acpi/lpc.asl |
| 47 | */ |
| 48 | static const struct fch_irq_routing { |
| 49 | uint8_t intr_index; |
| 50 | uint8_t pic_irq_num; |
| 51 | uint8_t apic_irq_num; |
| 52 | } guybrush_fch[] = { |
Raul E Rangel | 6d9a0ea | 2021-05-04 14:29:09 -0600 | [diff] [blame] | 53 | { PIRQ_A, 12, PIRQ_NC }, |
| 54 | { PIRQ_B, 14, PIRQ_NC }, |
| 55 | { PIRQ_C, 15, PIRQ_NC }, |
| 56 | { PIRQ_D, 12, PIRQ_NC }, |
| 57 | { PIRQ_E, 14, PIRQ_NC }, |
| 58 | { PIRQ_F, 15, PIRQ_NC }, |
| 59 | { PIRQ_G, 12, PIRQ_NC }, |
| 60 | { PIRQ_H, 14, PIRQ_NC }, |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 61 | |
| 62 | { PIRQ_SCI, ACPI_SCI_IRQ, ACPI_SCI_IRQ }, |
| 63 | { PIRQ_SD, PIRQ_NC, PIRQ_NC }, |
| 64 | { PIRQ_SDIO, PIRQ_NC, PIRQ_NC }, |
| 65 | { PIRQ_SATA, PIRQ_NC, PIRQ_NC }, |
| 66 | { PIRQ_EMMC, PIRQ_NC, PIRQ_NC }, |
Raul E Rangel | cce7d82 | 2021-03-30 15:50:43 -0600 | [diff] [blame] | 67 | { PIRQ_GPIO, 11, 11 }, |
| 68 | { PIRQ_I2C0, 10, 10 }, |
| 69 | { PIRQ_I2C1, 7, 7 }, |
| 70 | { PIRQ_I2C2, 6, 6 }, |
| 71 | { PIRQ_I2C3, 5, 5 }, |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 72 | { PIRQ_UART0, 4, 4 }, |
| 73 | { PIRQ_UART1, 3, 3 }, |
| 74 | |
| 75 | /* The MISC registers are not interrupt numbers */ |
| 76 | { PIRQ_MISC, 0xfa, 0x00 }, |
| 77 | { PIRQ_MISC0, 0x91, 0x00 }, |
| 78 | { PIRQ_HPET_L, 0x00, 0x00 }, |
| 79 | { PIRQ_HPET_H, 0x00, 0x00 }, |
| 80 | }; |
| 81 | |
| 82 | static void init_tables(void) |
| 83 | { |
| 84 | const struct fch_irq_routing *entry; |
| 85 | int i; |
| 86 | |
| 87 | memset(fch_pic_routing, PIRQ_NC, sizeof(fch_pic_routing)); |
| 88 | memset(fch_apic_routing, PIRQ_NC, sizeof(fch_apic_routing)); |
| 89 | |
| 90 | for (i = 0; i < ARRAY_SIZE(guybrush_fch); i++) { |
| 91 | entry = guybrush_fch + i; |
| 92 | fch_pic_routing[entry->intr_index] = entry->pic_irq_num; |
| 93 | fch_apic_routing[entry->intr_index] = entry->apic_irq_num; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | static void pirq_setup(void) |
| 98 | { |
| 99 | intr_data_ptr = fch_apic_routing; |
| 100 | picr_data_ptr = fch_pic_routing; |
| 101 | } |
| 102 | |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 103 | static void mainboard_configure_gpios(void) |
| 104 | { |
| 105 | size_t base_num_gpios, override_num_gpios; |
| 106 | const struct soc_amd_gpio *base_gpios, *override_gpios; |
| 107 | |
| 108 | base_gpios = variant_base_gpio_table(&base_num_gpios); |
| 109 | override_gpios = variant_override_gpio_table(&override_num_gpios); |
| 110 | |
| 111 | gpio_configure_pads_with_override(base_gpios, base_num_gpios, override_gpios, |
| 112 | override_num_gpios); |
| 113 | } |
| 114 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 115 | static void mainboard_init(void *chip_info) |
| 116 | { |
Mathew King | 10dd775 | 2021-01-26 16:08:14 -0700 | [diff] [blame] | 117 | mainboard_configure_gpios(); |
Mathew King | ad83023 | 2021-02-23 13:08:15 -0700 | [diff] [blame] | 118 | mainboard_ec_init(); |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 121 | static void mainboard_write_blken(void) |
| 122 | { |
| 123 | acpigen_write_method(METHOD_BACKLIGHT_ENABLE, 0); |
| 124 | acpigen_soc_clear_tx_gpio(BACKLIGHT_GPIO); |
| 125 | acpigen_pop_len(); |
| 126 | } |
| 127 | |
| 128 | static void mainboard_write_blkdis(void) |
| 129 | { |
| 130 | acpigen_write_method(METHOD_BACKLIGHT_DISABLE, 0); |
| 131 | acpigen_soc_set_tx_gpio(BACKLIGHT_GPIO); |
| 132 | acpigen_pop_len(); |
| 133 | } |
| 134 | |
| 135 | static void mainboard_write_mini(void) |
| 136 | { |
| 137 | acpigen_write_method(METHOD_MAINBOARD_INI, 0); |
| 138 | acpigen_emit_namestring(METHOD_BACKLIGHT_ENABLE); |
| 139 | acpigen_pop_len(); |
| 140 | } |
| 141 | |
| 142 | static void mainboard_write_mwak(void) |
| 143 | { |
| 144 | acpigen_write_method(METHOD_MAINBOARD_WAK, 0); |
| 145 | acpigen_emit_namestring(METHOD_BACKLIGHT_ENABLE); |
| 146 | acpigen_pop_len(); |
| 147 | } |
| 148 | |
| 149 | static void mainboard_write_mpts(void) |
| 150 | { |
| 151 | acpigen_write_method(METHOD_MAINBOARD_PTS, 0); |
| 152 | acpigen_emit_namestring(METHOD_BACKLIGHT_DISABLE); |
| 153 | acpigen_pop_len(); |
| 154 | } |
| 155 | |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame^] | 156 | static void mainboard_assert_wwan_aux_reset(void) |
| 157 | { |
| 158 | if (variant_has_pcie_wwan()) |
| 159 | acpigen_soc_clear_tx_gpio(WWAN_AUX_RST_GPIO); |
| 160 | } |
| 161 | |
| 162 | static void mainboard_deassert_wwan_aux_reset(void) |
| 163 | { |
| 164 | if (variant_has_pcie_wwan()) |
| 165 | acpigen_soc_set_tx_gpio(WWAN_AUX_RST_GPIO); |
| 166 | } |
| 167 | |
| 168 | static void mainboard_write_ms0x(void) |
| 169 | { |
| 170 | acpigen_write_method_serialized(METHOD_MAINBOARD_S0X, 1); |
| 171 | /* S0ix Entry */ |
| 172 | acpigen_write_if_lequal_op_int(ARG0_OP, 1); |
| 173 | mainboard_assert_wwan_aux_reset(); |
| 174 | /* S0ix Exit */ |
| 175 | acpigen_write_else(); |
| 176 | mainboard_deassert_wwan_aux_reset(); |
| 177 | acpigen_pop_len(); |
| 178 | acpigen_pop_len(); |
| 179 | } |
| 180 | |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 181 | static void mainboard_fill_ssdt(const struct device *dev) |
| 182 | { |
| 183 | mainboard_write_blken(); |
| 184 | mainboard_write_blkdis(); |
| 185 | mainboard_write_mini(); |
| 186 | mainboard_write_mpts(); |
| 187 | mainboard_write_mwak(); |
Karthikeyan Ramasubramanian | d086e3d | 2021-10-08 17:04:10 -0600 | [diff] [blame^] | 188 | mainboard_write_ms0x(); |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 189 | } |
| 190 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 191 | static void mainboard_enable(struct device *dev) |
| 192 | { |
Mathew King | 5d47887 | 2021-02-16 14:05:15 -0700 | [diff] [blame] | 193 | printk(BIOS_INFO, "Mainboard " CONFIG_MAINBOARD_PART_NUMBER " Enable.\n"); |
| 194 | |
| 195 | dev->ops->acpi_inject_dsdt = chromeos_dsdt_generator; |
Martin Roth | c7204b5 | 2021-03-31 19:15:33 -0600 | [diff] [blame] | 196 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Mathew King | 00b490d | 2021-03-12 15:48:32 -0700 | [diff] [blame] | 197 | |
| 198 | init_tables(); |
| 199 | /* Initialize the PIRQ data structures for consumption */ |
| 200 | pirq_setup(); |
Raul E Rangel | 6fce9cd | 2021-04-06 15:42:51 -0600 | [diff] [blame] | 201 | |
| 202 | /* TODO: b/184678786 - Move into espi_config */ |
| 203 | /* Unmask eSPI IRQ 1 (Keyboard) */ |
| 204 | pm_write32(PM_ESPI_INTR_CTRL, PM_ESPI_DEV_INTR_MASK & ~(BIT(1))); |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Martin Roth | 266dfc9 | 2021-07-21 13:31:48 -0600 | [diff] [blame] | 207 | static void mainboard_final(void *chip_info) |
| 208 | { |
| 209 | variant_finalize_gpios(); |
| 210 | } |
| 211 | |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 212 | struct chip_operations mainboard_ops = { |
| 213 | .init = mainboard_init, |
| 214 | .enable_dev = mainboard_enable, |
Martin Roth | 266dfc9 | 2021-07-21 13:31:48 -0600 | [diff] [blame] | 215 | .final = mainboard_final, |
Mathew King | 2e2fc7a | 2020-12-08 11:33:58 -0700 | [diff] [blame] | 216 | }; |