Raul E Rangel | b3c4132 | 2020-05-20 14:07:41 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <inttypes.h> |
| 5 | #include <baseboard/variants.h> |
| 6 | #include <ec/google/chromeec/ec.h> |
| 7 | |
| 8 | /* Global definitions for FW_CONFIG values */ |
| 9 | enum { |
| 10 | /* Daughterboard index for attributes. */ |
| 11 | FW_CONFIG_MASK_DB_INDEX = 0xf, |
| 12 | FW_CONFIG_DB_INDEX_SHIFT = 0, |
| 13 | /* Mainboard USB index for attributes. */ |
| 14 | FW_CONFIG_MASK_MB_USB_INDEX = 0xf, |
| 15 | FW_CONFIG_MB_USB_INDEX_SHIFT = 4, |
| 16 | /* Lid accelerometer properties. */ |
| 17 | FW_CONFIG_MASK_LID_ACCEL = 0x7, |
| 18 | FW_CONFIG_LID_ACCEL_SHIFT = 8, |
| 19 | /* Base gyro sensor properties. */ |
| 20 | FW_CONFIG_MASK_BASE_GYRO = 0x7, |
| 21 | FW_CONFIG_BASE_GYRO_SHIFT = 11, |
| 22 | /* Keyboard backlight presence */ |
| 23 | FW_CONFIG_MASK_KEYB_BL = 0x1, |
| 24 | FW_CONFIG_KEYB_BL_SHIFT = 14, |
| 25 | /* Tablet mode supported through lid angle */ |
| 26 | FW_CONFIG_MASK_LID_ANGLE_TABLET_MODE = 0x1, |
| 27 | FW_CONFIG_LID_ANGLE_TABLET_MODE_SHIFT = 15, |
| 28 | /* Stylus presence */ |
| 29 | FW_CONFIG_MASK_STYLUS = 0x1, |
| 30 | FW_CONFIG_STYLUS_SHIFT = 16, |
| 31 | /* Fingerprint sensor presence */ |
| 32 | FW_CONFIG_MASK_FP = 0x1, |
| 33 | FW_CONFIG_SHIFT_FP = 17, |
| 34 | /* NVME presence */ |
| 35 | FW_CONFIG_MASK_NVME = 0x1, |
| 36 | FW_CONFIG_SHIFT_NVME = 18, |
| 37 | /* EMMC presence */ |
| 38 | FW_CONFIG_MASK_EMMC = 0x1, |
| 39 | FW_CONFIG_SHIFT_EMMC = 19, |
| 40 | /* SD controller type */ |
| 41 | FW_CONFIG_MASK_SD_CTRLR = 0x7, |
| 42 | FW_CONFIG_SHIFT_SD_CTRLR = 20, |
| 43 | /* SPI speed value */ |
| 44 | FW_CONFIG_MASK_SPI_SPEED = 0xf, |
| 45 | FW_CONFIG_SHIFT_SPI_SPEED = 23, |
| 46 | /* Fan information */ |
| 47 | FW_CONFIG_MASK_FAN = 0x3, |
| 48 | FW_CONFIG_SHIFT_FAN = 27, |
| 49 | }; |
| 50 | |
Raul E Rangel | b3c4132 | 2020-05-20 14:07:41 -0600 | [diff] [blame] | 51 | static int get_fw_config(uint32_t *val) |
| 52 | { |
| 53 | static uint32_t known_value; |
| 54 | |
Raul E Rangel | b3c4132 | 2020-05-20 14:07:41 -0600 | [diff] [blame] | 55 | if (known_value) { |
| 56 | *val = known_value; |
| 57 | return 0; |
| 58 | } |
| 59 | |
Eric Lai | f209b18 | 2020-10-20 02:44:53 +0800 | [diff] [blame^] | 60 | if (google_chromeec_cbi_get_fw_config(&known_value) != 0) { |
Raul E Rangel | b3c4132 | 2020-05-20 14:07:41 -0600 | [diff] [blame] | 61 | printk(BIOS_ERR, "FW_CONFIG not set in CBI\n"); |
| 62 | return -1; |
| 63 | } |
| 64 | |
| 65 | *val = known_value; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static unsigned int extract_field(uint32_t mask, int shift) |
| 71 | { |
| 72 | uint32_t fw_config; |
| 73 | |
| 74 | /* On errors nothing is assumed to be set. */ |
| 75 | if (get_fw_config(&fw_config)) |
| 76 | return 0; |
| 77 | |
| 78 | return (fw_config >> shift) & mask; |
| 79 | } |
| 80 | |
| 81 | int variant_has_emmc(void) |
| 82 | { |
| 83 | return !!extract_field(FW_CONFIG_MASK_EMMC, FW_CONFIG_SHIFT_EMMC); |
| 84 | } |
| 85 | |
| 86 | int variant_has_nvme(void) |
| 87 | { |
| 88 | return !!extract_field(FW_CONFIG_MASK_NVME, FW_CONFIG_SHIFT_NVME); |
| 89 | } |
Furquan Shaikh | 30ee0d8 | 2020-07-07 12:50:55 -0700 | [diff] [blame] | 90 | |
| 91 | bool variant_uses_v3_schematics(void) |
| 92 | { |
| 93 | uint32_t board_version; |
| 94 | |
| 95 | if (!CONFIG(VARIANT_SUPPORTS_PRE_V3_SCHEMATICS)) |
| 96 | return true; |
| 97 | |
Eric Lai | f209b18 | 2020-10-20 02:44:53 +0800 | [diff] [blame^] | 98 | if (google_chromeec_cbi_get_board_version(&board_version) != 0) |
Furquan Shaikh | 30ee0d8 | 2020-07-07 12:50:55 -0700 | [diff] [blame] | 99 | return false; |
| 100 | |
| 101 | if ((int)board_version < CONFIG_VARIANT_MIN_BOARD_ID_V3_SCHEMATICS) |
| 102 | return false; |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
Josie Nordrum | c759e5e | 2020-08-03 11:05:14 -0600 | [diff] [blame] | 107 | bool variant_uses_v3_6_schematics(void) |
| 108 | { |
| 109 | uint32_t board_version; |
| 110 | |
| 111 | if (!CONFIG(VARIANT_SUPPORTS_PRE_V3_6_SCHEMATICS)) |
| 112 | return true; |
| 113 | |
Eric Lai | f209b18 | 2020-10-20 02:44:53 +0800 | [diff] [blame^] | 114 | if (google_chromeec_cbi_get_board_version(&board_version) != 0) |
Josie Nordrum | c759e5e | 2020-08-03 11:05:14 -0600 | [diff] [blame] | 115 | return false; |
| 116 | |
| 117 | if ((int)board_version < CONFIG_VARIANT_MIN_BOARD_ID_V3_6_SCHEMATICS) |
| 118 | return false; |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | |
| 123 | /* |
| 124 | * pre-v3.6, CODEC_GPI was used as headphone jack interrupt. |
| 125 | * Starting v3.6 this was changed to a separate GPIO. |
| 126 | */ |
| 127 | bool variant_uses_codec_gpi(void) |
| 128 | { |
| 129 | return !variant_uses_v3_6_schematics(); |
| 130 | } |
| 131 | |
Furquan Shaikh | 30ee0d8 | 2020-07-07 12:50:55 -0700 | [diff] [blame] | 132 | bool variant_has_active_low_wifi_power(void) |
| 133 | { |
| 134 | uint32_t board_version; |
| 135 | |
| 136 | if (!CONFIG(VARIANT_SUPPORTS_WIFI_POWER_ACTIVE_HIGH)) |
| 137 | return true; |
| 138 | |
Eric Lai | f209b18 | 2020-10-20 02:44:53 +0800 | [diff] [blame^] | 139 | if (google_chromeec_cbi_get_board_version(&board_version) != 0) |
Furquan Shaikh | 30ee0d8 | 2020-07-07 12:50:55 -0700 | [diff] [blame] | 140 | return false; |
| 141 | |
| 142 | if ((int)board_version < CONFIG_VARIANT_MIN_BOARD_ID_WIFI_POWER_ACTIVE_LOW) |
| 143 | return false; |
| 144 | |
| 145 | return true; |
| 146 | } |
Bhanu Prakash Maiya | a8e24f6 | 2020-08-12 13:04:27 -0700 | [diff] [blame] | 147 | |
| 148 | int variant_get_daughterboard_id(void) |
| 149 | { |
| 150 | return extract_field(FW_CONFIG_MASK_DB_INDEX, FW_CONFIG_DB_INDEX_SHIFT); |
| 151 | } |