Philip Oberfichtner | 62a0992 | 2022-07-26 15:04:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ |
| 2 | * |
| 3 | * Copyright 2022 DENX Software Engineering GmbH, Philip Oberfichtner <pro@denx.de> |
| 4 | */ |
| 5 | |
Christoph Niedermaier | 276458b | 2024-12-07 00:04:18 +0100 | [diff] [blame] | 6 | #define DH_EEPROM_ID_PAGE_MAX_SIZE 64 |
| 7 | |
| 8 | enum eip_request_values { |
| 9 | DH_MAC0, |
| 10 | DH_MAC1, |
| 11 | DH_ITEM_NUMBER, |
| 12 | DH_SERIAL_NUMBER, |
| 13 | }; |
| 14 | |
| 15 | /* DH item: Vendor coding */ |
| 16 | #define DH_ITEM_PREFIX_NXP 0x01 |
| 17 | #define DH_ITEM_PREFIX_NXP_CHR 'I' |
| 18 | #define DH_ITEM_PREFIX_ST 0x02 |
| 19 | #define DH_ITEM_PREFIX_ST_CHR 'S' |
| 20 | |
| 21 | /* |
| 22 | * DH item: Finished state coding |
| 23 | * Bit = 0 means half finished |
| 24 | * Prefix is 'H' |
| 25 | * Bit = 1 means finished with a customer image flashed |
| 26 | * Prefix is 'F' |
| 27 | */ |
| 28 | #define DH_ITEM_PREFIX_FIN_BIT BIT(7) |
| 29 | #define DH_ITEM_PREFIX_FIN_HALF_CHR 'H' |
| 30 | #define DH_ITEM_PREFIX_FIN_FLASHED_CHR 'F' |
| 31 | |
| 32 | struct eeprom_id_page { |
| 33 | /* Header */ |
| 34 | struct { |
| 35 | u8 id[3]; /* Identifier 'D', 'H', 'E' - 'D' is at index 0 */ |
| 36 | u8 version; /* 0x10 -- Version 1.0 */ |
| 37 | u8 crc16_pl[2]; /* Checksum payload, [1] is MSbyte */ |
| 38 | u8 crc8_hdr; /* Checksum header */ |
| 39 | } hdr; |
| 40 | /* Payload */ |
| 41 | struct { |
| 42 | u8 mac0[6]; |
| 43 | u8 mac1[6]; |
| 44 | u8 item_prefix; /* H/F is coded in MSbits, Vendor coding starts at LSbits */ |
| 45 | u8 item_num[3]; /* [2] is MSbyte */ |
| 46 | u8 serial[9]; /* [8] is MSbyte */ |
| 47 | } pl; |
| 48 | }; |
| 49 | |
| 50 | #define DH_EEPROM_ID_PAGE_V1_0 0x10 |
| 51 | |
Philip Oberfichtner | 62a0992 | 2022-07-26 15:04:50 +0200 | [diff] [blame] | 52 | /* |
| 53 | * dh_mac_is_in_env - Check if MAC address is already set |
| 54 | * |
| 55 | * @env: name of environment variable |
| 56 | * Return: true if MAC is set, false otherwise |
| 57 | */ |
| 58 | bool dh_mac_is_in_env(const char *env); |
| 59 | |
| 60 | /* |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 61 | * dh_get_mac_is_enabled - Test if ethernet MAC is enabled in DT |
| 62 | * |
| 63 | * @alias: alias for ethernet MAC device tree node |
| 64 | * Return: 0 if OK, other value on error |
| 65 | */ |
| 66 | int dh_get_mac_is_enabled(const char *alias); |
| 67 | |
| 68 | /* |
Philip Oberfichtner | 62a0992 | 2022-07-26 15:04:50 +0200 | [diff] [blame] | 69 | * dh_get_mac_from_eeprom - Get MAC address from eeprom and write it to enetaddr |
| 70 | * |
| 71 | * @enetaddr: buffer where address is to be stored |
| 72 | * @alias: alias for EEPROM device tree node |
| 73 | * Return: 0 if OK, other value on error |
| 74 | */ |
| 75 | int dh_get_mac_from_eeprom(unsigned char *enetaddr, const char *alias); |
| 76 | |
| 77 | /* |
Christoph Niedermaier | 276458b | 2024-12-07 00:04:18 +0100 | [diff] [blame] | 78 | * dh_read_eeprom_id_page() - Read EEPROM ID page content into given buffer |
| 79 | * @eeprom_buffer: Buffer for EEPROM ID page content |
| 80 | * @alias: Alias for EEPROM ID page device tree node |
| 81 | * |
| 82 | * Read the content of the EEPROM ID page into the given buffer (parameter |
| 83 | * eeprom_buffer). The EEPROM ID page device is selected via alias device |
| 84 | * tree name (parameter alias). The data of the EEPROM ID page is verified. |
| 85 | * An error is returned for reading failures and invalid data. |
| 86 | * |
| 87 | * Return: 0 if OK, other value on error |
| 88 | */ |
| 89 | int dh_read_eeprom_id_page(u8 *eeprom_buffer, const char *alias); |
| 90 | |
| 91 | /* |
| 92 | * dh_get_value_from_eeprom_buffer() - Get value from EEPROM buffer |
| 93 | * @eip_request_values: Requested value as enum |
| 94 | * @data: Buffer where value is to be stored |
| 95 | * @data_len: Length of the value buffer |
| 96 | * @eip: Pointer to EEPROM ID page struct from which the data is parsed |
| 97 | * |
| 98 | * Gets the value specified by the parameter eip_request_values from the EEPROM |
| 99 | * data struct (parameter eip). The data is written to the specified data |
| 100 | * buffer (parameter data). If the length of the data (parameter data_len) is |
| 101 | * not sufficient to copy the data into the buffer, an error is returned. |
| 102 | * |
| 103 | * Return: 0 if OK, other value on error |
| 104 | */ |
| 105 | int dh_get_value_from_eeprom_buffer(enum eip_request_values request, u8 *data, int data_len, |
| 106 | struct eeprom_id_page *eip); |
| 107 | |
| 108 | /* |
Philip Oberfichtner | 62a0992 | 2022-07-26 15:04:50 +0200 | [diff] [blame] | 109 | * dh_setup_mac_address - Try to get MAC address from various locations and write it to env |
| 110 | * |
| 111 | * Return: 0 if OK, other value on error |
| 112 | */ |
Christoph Niedermaier | 276458b | 2024-12-07 00:04:18 +0100 | [diff] [blame] | 113 | int dh_setup_mac_address(struct eeprom_id_page *eip); |