Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* |
| 3 | * Copyright (C) 2023 PHYTEC Messtechnik GmbH |
| 4 | * Author: Teresa Remmet <t.remmet@phytec.de> |
| 5 | */ |
| 6 | |
| 7 | #ifndef _PHYTEC_SOM_DETECTION_H |
| 8 | #define _PHYTEC_SOM_DETECTION_H |
| 9 | |
Daniel Schultz | 03e619d | 2024-05-21 23:18:25 -0700 | [diff] [blame] | 10 | #include "phytec_som_detection_blocks.h" |
| 11 | |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 12 | #define PHYTEC_MAX_OPTIONS 17 |
| 13 | #define PHYTEC_EEPROM_INVAL 0xff |
| 14 | |
Daniel Schultz | 794aec6 | 2024-05-21 23:18:23 -0700 | [diff] [blame] | 15 | #define PHYTEC_API2_DATA_LEN 32 |
| 16 | |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 17 | #define PHYTEC_GET_OPTION(option) \ |
| 18 | (((option) > '9') ? (option) - 'A' + 10 : (option) - '0') |
| 19 | |
| 20 | enum { |
| 21 | PHYTEC_API_REV0 = 0, |
| 22 | PHYTEC_API_REV1, |
| 23 | PHYTEC_API_REV2, |
Daniel Schultz | 03e619d | 2024-05-21 23:18:25 -0700 | [diff] [blame] | 24 | PHYTEC_API_REV3, |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
Benjamin Hahn | 455dcf7 | 2024-03-06 17:18:31 +0100 | [diff] [blame] | 27 | enum phytec_som_type_str { |
| 28 | SOM_TYPE_PCM = 0, |
| 29 | SOM_TYPE_PCL, |
| 30 | SOM_TYPE_KSM, |
| 31 | SOM_TYPE_KSP, |
| 32 | }; |
| 33 | |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 34 | static const char * const phytec_som_type_str[] = { |
| 35 | "PCM", |
| 36 | "PCL", |
| 37 | "KSM", |
| 38 | "KSP", |
| 39 | }; |
| 40 | |
| 41 | struct phytec_api0_data { |
| 42 | u8 pcb_rev; /* PCB revision of SoM */ |
| 43 | u8 som_type; /* SoM type */ |
| 44 | u8 ksp_no; /* KSP no */ |
| 45 | char opt[16]; /* SoM options */ |
| 46 | u8 mac[6]; /* MAC address (optional) */ |
| 47 | u8 pad[5]; /* padding */ |
| 48 | u8 cksum; /* checksum */ |
| 49 | } __packed; |
| 50 | |
| 51 | struct phytec_api2_data { |
| 52 | u8 pcb_rev; /* PCB revision of SoM */ |
| 53 | u8 pcb_sub_opt_rev; /* PCB subrevision and opt revision */ |
| 54 | u8 som_type; /* SoM type */ |
| 55 | u8 som_no; /* SoM number */ |
| 56 | u8 ksp_no; /* KSP information */ |
| 57 | char opt[PHYTEC_MAX_OPTIONS]; /* SoM options */ |
| 58 | char bom_rev[2]; /* BOM revision */ |
| 59 | u8 mac[6]; /* MAC address (optional) */ |
| 60 | u8 crc8; /* checksum */ |
| 61 | } __packed; |
| 62 | |
Yannic Moog | db2dfb0 | 2024-04-19 08:55:37 -0700 | [diff] [blame] | 63 | struct phytec_eeprom_payload { |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 64 | u8 api_rev; |
| 65 | union { |
| 66 | struct phytec_api0_data data_api0; |
| 67 | struct phytec_api2_data data_api2; |
| 68 | } data; |
Daniel Schultz | 03e619d | 2024-05-21 23:18:25 -0700 | [diff] [blame] | 69 | struct phytec_api3_element *block_head; |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 70 | } __packed; |
| 71 | |
Yannic Moog | db2dfb0 | 2024-04-19 08:55:37 -0700 | [diff] [blame] | 72 | struct phytec_eeprom_data { |
| 73 | struct phytec_eeprom_payload payload; |
| 74 | bool valid; |
| 75 | }; |
| 76 | |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 77 | int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data, |
| 78 | int bus_num, int addr, |
| 79 | int addr_fallback); |
| 80 | int phytec_eeprom_data_setup(struct phytec_eeprom_data *data, |
| 81 | int bus_num, int addr); |
Yannic Moog | db2dfb0 | 2024-04-19 08:55:37 -0700 | [diff] [blame] | 82 | int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num, |
| 83 | int addr); |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 84 | void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data); |
| 85 | |
| 86 | char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data); |
Teresa Remmet | e3d3ac4 | 2023-08-17 10:57:10 +0200 | [diff] [blame] | 87 | u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data); |
Benjamin Hahn | 455dcf7 | 2024-03-06 17:18:31 +0100 | [diff] [blame] | 88 | u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data); |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 89 | |
Daniel Schultz | a440ec2 | 2024-04-19 08:55:36 -0700 | [diff] [blame] | 90 | #if IS_ENABLED(CONFIG_CMD_EXTENSION) |
| 91 | struct extension *phytec_add_extension(const char *name, const char *overlay, |
| 92 | const char *other); |
| 93 | #endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */ |
| 94 | |
Daniel Schultz | 03e619d | 2024-05-21 23:18:25 -0700 | [diff] [blame] | 95 | struct phytec_api3_element * |
| 96 | __maybe_unused phytec_get_block_head(struct phytec_eeprom_data *data); |
| 97 | |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 98 | #endif /* _PHYTEC_SOM_DETECTION_H */ |