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