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 | |
| 10 | #define PHYTEC_MAX_OPTIONS 17 |
| 11 | #define PHYTEC_EEPROM_INVAL 0xff |
| 12 | |
| 13 | #define PHYTEC_GET_OPTION(option) \ |
| 14 | (((option) > '9') ? (option) - 'A' + 10 : (option) - '0') |
| 15 | |
| 16 | enum { |
| 17 | PHYTEC_API_REV0 = 0, |
| 18 | PHYTEC_API_REV1, |
| 19 | PHYTEC_API_REV2, |
| 20 | }; |
| 21 | |
| 22 | static const char * const phytec_som_type_str[] = { |
| 23 | "PCM", |
| 24 | "PCL", |
| 25 | "KSM", |
| 26 | "KSP", |
| 27 | }; |
| 28 | |
| 29 | struct phytec_api0_data { |
| 30 | u8 pcb_rev; /* PCB revision of SoM */ |
| 31 | u8 som_type; /* SoM type */ |
| 32 | u8 ksp_no; /* KSP no */ |
| 33 | char opt[16]; /* SoM options */ |
| 34 | u8 mac[6]; /* MAC address (optional) */ |
| 35 | u8 pad[5]; /* padding */ |
| 36 | u8 cksum; /* checksum */ |
| 37 | } __packed; |
| 38 | |
| 39 | struct phytec_api2_data { |
| 40 | u8 pcb_rev; /* PCB revision of SoM */ |
| 41 | u8 pcb_sub_opt_rev; /* PCB subrevision and opt revision */ |
| 42 | u8 som_type; /* SoM type */ |
| 43 | u8 som_no; /* SoM number */ |
| 44 | u8 ksp_no; /* KSP information */ |
| 45 | char opt[PHYTEC_MAX_OPTIONS]; /* SoM options */ |
| 46 | char bom_rev[2]; /* BOM revision */ |
| 47 | u8 mac[6]; /* MAC address (optional) */ |
| 48 | u8 crc8; /* checksum */ |
| 49 | } __packed; |
| 50 | |
| 51 | struct phytec_eeprom_data { |
| 52 | u8 api_rev; |
| 53 | union { |
| 54 | struct phytec_api0_data data_api0; |
| 55 | struct phytec_api2_data data_api2; |
| 56 | } data; |
| 57 | } __packed; |
| 58 | |
| 59 | #if IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION) |
| 60 | |
| 61 | int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data, |
| 62 | int bus_num, int addr, |
| 63 | int addr_fallback); |
| 64 | int phytec_eeprom_data_setup(struct phytec_eeprom_data *data, |
| 65 | int bus_num, int addr); |
| 66 | int phytec_eeprom_data_init(struct phytec_eeprom_data *data, |
| 67 | int bus_num, int addr); |
| 68 | void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data); |
| 69 | |
| 70 | char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data); |
Teresa Remmet | e3d3ac4 | 2023-08-17 10:57:10 +0200 | [diff] [blame] | 71 | u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data); |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 72 | |
| 73 | #else |
| 74 | |
| 75 | inline int phytec_eeprom_data_setup(struct phytec_eeprom_data *data, |
| 76 | int bus_num, int addr) |
| 77 | { |
| 78 | return PHYTEC_EEPROM_INVAL; |
| 79 | } |
| 80 | |
| 81 | inline int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data, |
| 82 | int bus_num, int addr, |
| 83 | int addr_fallback) |
| 84 | { |
| 85 | return PHYTEC_EEPROM_INVAL; |
| 86 | } |
| 87 | |
| 88 | inline int phytec_eeprom_data_init(struct phytec_eeprom_data *data, |
| 89 | int bus_num, int addr) |
| 90 | { |
| 91 | return PHYTEC_EEPROM_INVAL; |
| 92 | } |
| 93 | |
| 94 | inline void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | inline char *__maybe_unused phytec_get_opt(struct phytec_eeprom_data *data) |
| 99 | { |
| 100 | return NULL; |
| 101 | } |
| 102 | |
Teresa Remmet | e3d3ac4 | 2023-08-17 10:57:10 +0200 | [diff] [blame] | 103 | u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data) |
| 104 | { |
| 105 | return PHYTEC_EEPROM_INVAL; |
| 106 | } |
Teresa Remmet | a6f8da5 | 2023-08-17 10:57:06 +0200 | [diff] [blame] | 107 | #endif /* IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION) */ |
| 108 | |
| 109 | #endif /* _PHYTEC_SOM_DETECTION_H */ |