blob: 5e35a13cb2184aac411dc23ba8994e07669b115d [file] [log] [blame]
Teresa Remmeta6f8da52023-08-17 10:57:06 +02001/* 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 Schultz03e619d2024-05-21 23:18:25 -070010#include "phytec_som_detection_blocks.h"
11
Teresa Remmeta6f8da52023-08-17 10:57:06 +020012#define PHYTEC_MAX_OPTIONS 17
13#define PHYTEC_EEPROM_INVAL 0xff
14
Daniel Schultz794aec62024-05-21 23:18:23 -070015#define PHYTEC_API2_DATA_LEN 32
16
Teresa Remmeta6f8da52023-08-17 10:57:06 +020017#define PHYTEC_GET_OPTION(option) \
18 (((option) > '9') ? (option) - 'A' + 10 : (option) - '0')
19
20enum {
21 PHYTEC_API_REV0 = 0,
22 PHYTEC_API_REV1,
23 PHYTEC_API_REV2,
Daniel Schultz03e619d2024-05-21 23:18:25 -070024 PHYTEC_API_REV3,
Teresa Remmeta6f8da52023-08-17 10:57:06 +020025};
26
Benjamin Hahn455dcf72024-03-06 17:18:31 +010027enum phytec_som_type_str {
28 SOM_TYPE_PCM = 0,
29 SOM_TYPE_PCL,
30 SOM_TYPE_KSM,
31 SOM_TYPE_KSP,
32};
33
Teresa Remmeta6f8da52023-08-17 10:57:06 +020034static const char * const phytec_som_type_str[] = {
35 "PCM",
36 "PCL",
37 "KSM",
38 "KSP",
39};
40
41struct 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
51struct 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 Moogdb2dfb02024-04-19 08:55:37 -070063struct phytec_eeprom_payload {
Teresa Remmeta6f8da52023-08-17 10:57:06 +020064 u8 api_rev;
65 union {
66 struct phytec_api0_data data_api0;
67 struct phytec_api2_data data_api2;
68 } data;
Daniel Schultz03e619d2024-05-21 23:18:25 -070069 struct phytec_api3_element *block_head;
Teresa Remmeta6f8da52023-08-17 10:57:06 +020070} __packed;
71
Yannic Moogdb2dfb02024-04-19 08:55:37 -070072struct phytec_eeprom_data {
73 struct phytec_eeprom_payload payload;
74 bool valid;
75};
76
Teresa Remmeta6f8da52023-08-17 10:57:06 +020077int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data,
78 int bus_num, int addr,
79 int addr_fallback);
80int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
81 int bus_num, int addr);
Yannic Moogdb2dfb02024-04-19 08:55:37 -070082int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num,
83 int addr);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020084void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
85
86char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
Teresa Remmete3d3ac42023-08-17 10:57:10 +020087u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
Benjamin Hahn455dcf72024-03-06 17:18:31 +010088u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020089
Daniel Schultza440ec22024-04-19 08:55:36 -070090#if IS_ENABLED(CONFIG_CMD_EXTENSION)
91struct extension *phytec_add_extension(const char *name, const char *overlay,
92 const char *other);
93#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */
94
Daniel Schultz03e619d2024-05-21 23:18:25 -070095struct phytec_api3_element *
96 __maybe_unused phytec_get_block_head(struct phytec_eeprom_data *data);
97
Teresa Remmeta6f8da52023-08-17 10:57:06 +020098#endif /* _PHYTEC_SOM_DETECTION_H */