Angel Pons | 60ec365 | 2020-04-03 01:22:13 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Ravi Sarawadi | ebb2d3c | 2019-12-19 23:01:48 -0800 | [diff] [blame] | 2 | |
| 3 | #include <boardid.h> |
| 4 | #include <ec/acpi/ec.h> |
| 5 | #include <ec/google/chromeec/ec.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | #include "board_id.h" |
| 9 | |
| 10 | static uint32_t get_board_id_via_ext_ec(void) |
| 11 | { |
| 12 | uint32_t id = BOARD_ID_INIT; |
| 13 | |
| 14 | if (google_chromeec_get_board_version(&id)) |
| 15 | id = BOARD_ID_UNKNOWN; |
| 16 | |
| 17 | return id; |
| 18 | } |
| 19 | |
| 20 | /* Get Board ID via EC I/O port write/read */ |
| 21 | int get_board_id(void) |
| 22 | { |
Jeremy Compostella | f65ae74 | 2023-09-06 10:57:56 -0700 | [diff] [blame] | 23 | static int id = -1; |
Ravi Sarawadi | ebb2d3c | 2019-12-19 23:01:48 -0800 | [diff] [blame] | 24 | |
| 25 | if (id < 0) { |
| 26 | if (CONFIG(EC_GOOGLE_CHROMEEC)) { |
| 27 | id = get_board_id_via_ext_ec(); |
| 28 | } else { |
| 29 | uint8_t buffer[2]; |
| 30 | uint8_t index; |
| 31 | if (send_ec_command(EC_FAB_ID_CMD) == 0) { |
| 32 | for (index = 0; index < sizeof(buffer); index++) |
| 33 | buffer[index] = recv_ec_data(); |
| 34 | id = (buffer[0] << 8) | buffer[1]; |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | return id; |
| 39 | } |