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