Angel Pons | 952f6b0 | 2020-04-05 13:22:37 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Aaron Durbin | 10d67cb | 2016-09-02 16:56:03 -0500 | [diff] [blame] | 4 | #include <baseboard/variants.h> |
Aaron Durbin | 8d3c4d1 | 2016-07-06 23:16:01 -0500 | [diff] [blame] | 5 | #include <boardid.h> |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 6 | #include <console/console.h> |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 7 | #include <device/device.h> |
Aaron Durbin | 91fa9d7 | 2016-09-23 16:38:27 -0500 | [diff] [blame] | 8 | #include <ec/ec.h> |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 9 | #include <gpio.h> |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 10 | #include <nhlt.h> |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 11 | #include <smbios.h> |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 12 | #include <soc/nhlt.h> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame^] | 13 | #include <stdio.h> |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 14 | #include <string.h> |
Aaron Durbin | 114d7c3 | 2016-09-02 15:58:16 -0500 | [diff] [blame] | 15 | #include <variant/ec.h> |
| 16 | #include <variant/gpio.h> |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 17 | |
Chris Wang | 97ac471 | 2017-12-06 18:43:46 +0800 | [diff] [blame] | 18 | /* override specific gpio by sku id */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 19 | const struct pad_config __weak |
Chris Wang | 97ac471 | 2017-12-06 18:43:46 +0800 | [diff] [blame] | 20 | *variant_sku_gpio_table(size_t *num) |
| 21 | { |
| 22 | *num = 0; |
| 23 | return NULL; |
| 24 | } |
| 25 | |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 26 | static void mainboard_init(void *chip_info) |
| 27 | { |
Aaron Durbin | 8d3c4d1 | 2016-07-06 23:16:01 -0500 | [diff] [blame] | 28 | int boardid; |
Aaron Durbin | 10d67cb | 2016-09-02 16:56:03 -0500 | [diff] [blame] | 29 | const struct pad_config *pads; |
| 30 | size_t num; |
Aaron Durbin | 8d3c4d1 | 2016-07-06 23:16:01 -0500 | [diff] [blame] | 31 | |
| 32 | boardid = board_id(); |
| 33 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
| 34 | |
Aaron Durbin | 10d67cb | 2016-09-02 16:56:03 -0500 | [diff] [blame] | 35 | pads = variant_gpio_table(&num); |
| 36 | gpio_configure_pads(pads, num); |
Aaron Durbin | 8d3c4d1 | 2016-07-06 23:16:01 -0500 | [diff] [blame] | 37 | |
Chris Wang | 97ac471 | 2017-12-06 18:43:46 +0800 | [diff] [blame] | 38 | pads = variant_sku_gpio_table(&num); |
| 39 | gpio_configure_pads(pads, num); |
| 40 | |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 41 | mainboard_ec_init(); |
Kevin Chiu | 82fbb1c | 2017-09-05 16:10:10 +0800 | [diff] [blame] | 42 | |
| 43 | variant_board_ec_set_skuid(); |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 44 | } |
| 45 | |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 46 | /* |
| 47 | * There are 2 pins on reef-like boards that can be used for SKU'ing |
| 48 | * board differences. They each have optional stuffing for a pullup and |
| 49 | * a pulldown. This way we can generate 9 different values with the |
| 50 | * 2 pins. |
| 51 | */ |
Aaron Durbin | a871059 | 2017-09-22 17:05:59 -0600 | [diff] [blame] | 52 | uint8_t sku_strapping_value(void) |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 53 | { |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 54 | gpio_t board_sku_gpios[] = { |
| 55 | [1] = GPIO_17, [0] = GPIO_16, |
| 56 | }; |
| 57 | const size_t num = ARRAY_SIZE(board_sku_gpios); |
| 58 | |
Aaron Durbin | a871059 | 2017-09-22 17:05:59 -0600 | [diff] [blame] | 59 | return gpio_base3_value(board_sku_gpios, num); |
| 60 | } |
| 61 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 62 | uint8_t __weak variant_board_sku(void) |
Aaron Durbin | a871059 | 2017-09-22 17:05:59 -0600 | [diff] [blame] | 63 | { |
| 64 | static int board_sku_num = -1; |
| 65 | |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 66 | if (board_sku_num < 0) |
Aaron Durbin | a871059 | 2017-09-22 17:05:59 -0600 | [diff] [blame] | 67 | board_sku_num = sku_strapping_value(); |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 68 | |
| 69 | return board_sku_num; |
| 70 | } |
| 71 | |
Jonathan Neuschäfer | 482d16f | 2017-11-20 02:09:19 +0100 | [diff] [blame] | 72 | /* Set variant board sku to ec by sku id */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 73 | void __weak variant_board_ec_set_skuid(void) |
Kevin Chiu | 82fbb1c | 2017-09-05 16:10:10 +0800 | [diff] [blame] | 74 | { |
| 75 | } |
| 76 | |
Nico Huber | ebd8a4f | 2017-11-01 09:49:16 +0100 | [diff] [blame] | 77 | const char *smbios_system_sku(void) |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 78 | { |
Patrick Georgi | b09933a | 2017-06-02 21:48:01 +0200 | [diff] [blame] | 79 | static char sku_str[7]; /* sku{0..255} */ |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 80 | |
Patrick Georgi | b09933a | 2017-06-02 21:48:01 +0200 | [diff] [blame] | 81 | snprintf(sku_str, sizeof(sku_str), "sku%d", variant_board_sku()); |
Aaron Durbin | 2b3a6be | 2016-12-07 17:34:06 -0600 | [diff] [blame] | 82 | |
| 83 | return sku_str; |
| 84 | } |
| 85 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 86 | void __weak variant_nhlt_oem_overrides(const char **oem_id, |
Aaron Durbin | d0a648e | 2016-11-29 23:20:07 -0600 | [diff] [blame] | 87 | const char **oem_table_id, |
| 88 | uint32_t *oem_revision) |
Aaron Durbin | 083e2e4 | 2016-10-27 13:24:06 -0500 | [diff] [blame] | 89 | { |
Aaron Durbin | eb9c639 | 2016-12-07 17:39:09 -0600 | [diff] [blame] | 90 | *oem_id = "reef"; |
| 91 | *oem_table_id = CONFIG_VARIANT_DIR; |
Patrick Georgi | b09933a | 2017-06-02 21:48:01 +0200 | [diff] [blame] | 92 | *oem_revision = variant_board_sku(); |
Aaron Durbin | 083e2e4 | 2016-10-27 13:24:06 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 95 | static unsigned long mainboard_write_acpi_tables( |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 96 | const struct device *device, unsigned long current, acpi_rsdp_t *rsdp) |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 97 | { |
| 98 | uintptr_t start_addr; |
| 99 | uintptr_t end_addr; |
| 100 | struct nhlt *nhlt; |
Aaron Durbin | 083e2e4 | 2016-10-27 13:24:06 -0500 | [diff] [blame] | 101 | const char *oem_id = NULL; |
| 102 | const char *oem_table_id = NULL; |
Aaron Durbin | b4afe3c | 2016-11-29 23:14:25 -0600 | [diff] [blame] | 103 | uint32_t oem_revision = 0; |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 104 | |
| 105 | start_addr = current; |
| 106 | |
| 107 | nhlt = nhlt_init(); |
| 108 | |
| 109 | if (nhlt == NULL) |
| 110 | return start_addr; |
| 111 | |
Aaron Durbin | 8db1f8d | 2016-09-02 20:19:59 -0500 | [diff] [blame] | 112 | variant_nhlt_init(nhlt); |
Aaron Durbin | d0a648e | 2016-11-29 23:20:07 -0600 | [diff] [blame] | 113 | variant_nhlt_oem_overrides(&oem_id, &oem_table_id, &oem_revision); |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 114 | |
Aaron Durbin | 083e2e4 | 2016-10-27 13:24:06 -0500 | [diff] [blame] | 115 | end_addr = nhlt_soc_serialize_oem_overrides(nhlt, start_addr, |
Aaron Durbin | b4afe3c | 2016-11-29 23:14:25 -0600 | [diff] [blame] | 116 | oem_id, oem_table_id, oem_revision); |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 117 | |
| 118 | if (end_addr != start_addr) |
| 119 | acpi_add_table(rsdp, (void *)start_addr); |
| 120 | |
| 121 | return end_addr; |
| 122 | } |
| 123 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 124 | static void mainboard_enable(struct device *dev) |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 125 | { |
| 126 | dev->ops->write_acpi_tables = mainboard_write_acpi_tables; |
| 127 | } |
| 128 | |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 129 | struct chip_operations mainboard_ops = { |
| 130 | .init = mainboard_init, |
Saurabh Satija | af9f35a | 2016-06-26 18:25:34 -0700 | [diff] [blame] | 131 | .enable_dev = mainboard_enable, |
Aaron Durbin | e065bb4 | 2016-05-10 15:09:44 -0500 | [diff] [blame] | 132 | }; |