Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2018 Intel Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/acpi.h> |
| 17 | #include <baseboard/variants.h> |
| 18 | #include <boardid.h> |
| 19 | #include <console/console.h> |
| 20 | #include <device/device.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame^] | 21 | #include <ec/google/chromeec/ec.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 22 | #include <ec/ec.h> |
| 23 | #include <nhlt.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame^] | 24 | #include <smbios.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 25 | #include <soc/gpio.h> |
| 26 | #include <soc/nhlt.h> |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame^] | 27 | #include <string.h> |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 28 | #include <vendorcode/google/chromeos/chromeos.h> |
| 29 | #include <variant/ec.h> |
| 30 | #include <variant/gpio.h> |
| 31 | |
| 32 | static void mainboard_init(void *chip_info) |
| 33 | { |
| 34 | int boardid; |
| 35 | const struct pad_config *pads; |
| 36 | size_t num; |
| 37 | |
| 38 | boardid = board_id(); |
| 39 | printk(BIOS_INFO, "Board ID: %d\n", boardid); |
| 40 | |
| 41 | pads = variant_gpio_table(&num); |
| 42 | gpio_configure_pads(pads, num); |
| 43 | |
| 44 | mainboard_ec_init(); |
| 45 | } |
| 46 | |
| 47 | static unsigned long mainboard_write_acpi_tables( |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 48 | struct device *device, unsigned long current, acpi_rsdp_t *rsdp) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 49 | { |
| 50 | uintptr_t start_addr; |
| 51 | uintptr_t end_addr; |
| 52 | struct nhlt *nhlt; |
| 53 | |
| 54 | start_addr = current; |
| 55 | |
| 56 | nhlt = nhlt_init(); |
| 57 | |
| 58 | if (nhlt == NULL) |
| 59 | return start_addr; |
| 60 | |
| 61 | variant_nhlt_init(nhlt); |
| 62 | |
| 63 | end_addr = nhlt_soc_serialize(nhlt, start_addr); |
| 64 | |
| 65 | if (end_addr != start_addr) |
| 66 | acpi_add_table(rsdp, (void *)start_addr); |
| 67 | |
| 68 | return end_addr; |
| 69 | } |
| 70 | |
Elyes HAOUAS | d129d43 | 2018-05-04 20:23:33 +0200 | [diff] [blame] | 71 | static void mainboard_enable(struct device *dev) |
Hannah Williams | 5e83e8b | 2018-02-09 18:35:17 -0800 | [diff] [blame] | 72 | { |
| 73 | dev->ops->write_acpi_tables = mainboard_write_acpi_tables; |
| 74 | dev->ops->acpi_inject_dsdt_generator = chromeos_dsdt_generator; |
| 75 | } |
| 76 | |
| 77 | struct chip_operations mainboard_ops = { |
| 78 | .init = mainboard_init, |
| 79 | .enable_dev = mainboard_enable, |
| 80 | }; |
Furquan Shaikh | 367956d5 | 2018-07-20 13:50:16 -0700 | [diff] [blame^] | 81 | |
| 82 | #define SKU_UNKNOWN 0xFFFFFFFF |
| 83 | #define SKU_MAX 255 |
| 84 | |
| 85 | static uint32_t get_board_sku(void) |
| 86 | { |
| 87 | static uint32_t sku_id = SKU_UNKNOWN; |
| 88 | |
| 89 | if (sku_id != SKU_UNKNOWN) |
| 90 | return sku_id; |
| 91 | |
| 92 | if (google_chromeec_cbi_get_sku_id(&sku_id)) |
| 93 | sku_id = SKU_UNKNOWN; |
| 94 | |
| 95 | return sku_id; |
| 96 | } |
| 97 | |
| 98 | const char *smbios_mainboard_sku(void) |
| 99 | { |
| 100 | static char sku_str[7]; /* sku{0..255} */ |
| 101 | uint32_t sku_id = get_board_sku(); |
| 102 | |
| 103 | if ((sku_id == SKU_UNKNOWN) || (sku_id > SKU_MAX)) { |
| 104 | printk(BIOS_ERR, "%s: Unexpected SKU ID %u\n", |
| 105 | __func__, sku_id); |
| 106 | return ""; |
| 107 | } |
| 108 | |
| 109 | snprintf(sku_str, sizeof(sku_str), "sku%u", sku_id); |
| 110 | |
| 111 | return sku_str; |
| 112 | } |