Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Arthur Heymans | b1c1996 | 2023-04-13 16:04:48 +0200 | [diff] [blame] | 3 | #include <acpi/acpigen.h> |
Maximilian Brune | 97a8673 | 2022-10-07 18:29:29 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 5 | #include <device/device.h> |
Maximilian Brune | 97a8673 | 2022-10-07 18:29:29 +0200 | [diff] [blame] | 6 | #include <gpio.h> |
David Milosevic | 0f5b87c | 2022-10-20 16:47:48 +0200 | [diff] [blame] | 7 | #include <smbios.h> |
Elyes Haouas | bdd03c2 | 2024-05-27 11:20:07 +0200 | [diff] [blame] | 8 | #include <stdio.h> |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 9 | #include <types.h> |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 10 | |
| 11 | #include "gpio.h" |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 12 | #include "vpd.h" |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 13 | |
David Milosevic | 0f5b87c | 2022-10-20 16:47:48 +0200 | [diff] [blame] | 14 | void smbios_fill_dimm_locator(const struct dimm_info *dimm, struct smbios_type17 *t) |
| 15 | { |
| 16 | const u8 mc = dimm->ctrlr_num; |
| 17 | const u8 ch = dimm->channel_num; |
| 18 | const u8 mm = dimm->dimm_num; |
| 19 | |
| 20 | char dev_loc[40] = { "\x00" }; |
| 21 | snprintf(dev_loc, sizeof(dev_loc), "SO-DIMM %c%u", 'A' + mc, mm); |
| 22 | t->device_locator = smbios_add_string(t->eos, dev_loc); |
| 23 | |
| 24 | char bnk_loc[40] = { "\x00" }; |
| 25 | snprintf(bnk_loc, sizeof(bnk_loc), "BANK-%u-%u-%u", mc, ch, mm); |
| 26 | t->bank_locator = smbios_add_string(t->eos, bnk_loc); |
| 27 | } |
| 28 | |
| 29 | void smbios_fill_dimm_asset_tag(const struct dimm_info *dimm, struct smbios_type17 *t) |
| 30 | { |
| 31 | const u8 mc = dimm->ctrlr_num; |
| 32 | const u8 ch = dimm->channel_num; |
| 33 | const u8 mm = dimm->dimm_num; |
| 34 | |
| 35 | char tag[40] = { "\x00" }; |
| 36 | snprintf(tag, sizeof(tag), "MC-%u-CH-%u-DIMM-%u", mc, ch, mm); |
| 37 | t->asset_tag = smbios_add_string(t->eos, tag); |
| 38 | } |
| 39 | |
Maximilian Brune | 97a8673 | 2022-10-07 18:29:29 +0200 | [diff] [blame] | 40 | static uint8_t get_hsid(void) |
| 41 | { |
| 42 | const gpio_t hsid_gpios[] = { |
| 43 | GPP_A8, |
| 44 | GPP_F19, |
| 45 | GPP_H23, |
| 46 | GPP_H19, |
| 47 | }; |
| 48 | return gpio_base2_value(hsid_gpios, ARRAY_SIZE(hsid_gpios)); |
| 49 | } |
| 50 | |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 51 | static void mainboard_init(void *chip_info) |
| 52 | { |
| 53 | configure_gpio_pads(); |
Maximilian Brune | 97a8673 | 2022-10-07 18:29:29 +0200 | [diff] [blame] | 54 | printk(BIOS_INFO, "HSID: 0x%x\n", get_hsid()); |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 57 | static const char *get_formatted_pn(void) |
| 58 | { |
| 59 | static char buffer[32 + ATLAS_SN_PN_LENGTH] = {0}; |
| 60 | const char *prefix = "P/N: "; |
| 61 | snprintf(buffer, sizeof(buffer), "%s%s", prefix, get_emi_eeprom_vpd()->part_number); |
| 62 | return buffer; |
| 63 | } |
| 64 | |
| 65 | static void mainboard_smbios_strings(struct device *dev, struct smbios_type11 *t) |
| 66 | { |
| 67 | t->count = smbios_add_string(t->eos, get_formatted_pn()); |
| 68 | } |
| 69 | |
Arthur Heymans | b1c1996 | 2023-04-13 16:04:48 +0200 | [diff] [blame] | 70 | static void mainboard_fill_ssdt(const struct device *dev) |
| 71 | { |
| 72 | const struct emi_eeprom_vpd *eeprom = get_emi_eeprom_vpd(); |
| 73 | const bool sleep_enable = eeprom->profile != ATLAS_PROF_REALTIME_PERFORMANCE ? 1 : 0; |
| 74 | acpigen_ssdt_override_sleep_states(false, false, |
| 75 | CONFIG(HAVE_ACPI_RESUME) && sleep_enable, |
| 76 | sleep_enable); |
| 77 | } |
| 78 | |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 79 | static void mainboard_enable(struct device *dev) |
| 80 | { |
| 81 | dev->ops->get_smbios_strings = mainboard_smbios_strings; |
Arthur Heymans | b1c1996 | 2023-04-13 16:04:48 +0200 | [diff] [blame] | 82 | dev->ops->acpi_fill_ssdt = mainboard_fill_ssdt; |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 85 | struct chip_operations mainboard_ops = { |
Angel Pons | 56c1c4d | 2023-03-22 13:25:09 +0100 | [diff] [blame] | 86 | .init = mainboard_init, |
| 87 | .enable_dev = mainboard_enable, |
Lean Sheng Tan | 5352d22 | 2022-01-07 13:48:13 +0100 | [diff] [blame] | 88 | }; |