blob: 0ad5c14ef4e25cdd60aa0285efd01e0d85faf3ac [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
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
16enum {
17 PHYTEC_API_REV0 = 0,
18 PHYTEC_API_REV1,
19 PHYTEC_API_REV2,
20};
21
Benjamin Hahn455dcf72024-03-06 17:18:31 +010022enum phytec_som_type_str {
23 SOM_TYPE_PCM = 0,
24 SOM_TYPE_PCL,
25 SOM_TYPE_KSM,
26 SOM_TYPE_KSP,
27};
28
Teresa Remmeta6f8da52023-08-17 10:57:06 +020029static const char * const phytec_som_type_str[] = {
30 "PCM",
31 "PCL",
32 "KSM",
33 "KSP",
34};
35
36struct phytec_api0_data {
37 u8 pcb_rev; /* PCB revision of SoM */
38 u8 som_type; /* SoM type */
39 u8 ksp_no; /* KSP no */
40 char opt[16]; /* SoM options */
41 u8 mac[6]; /* MAC address (optional) */
42 u8 pad[5]; /* padding */
43 u8 cksum; /* checksum */
44} __packed;
45
46struct phytec_api2_data {
47 u8 pcb_rev; /* PCB revision of SoM */
48 u8 pcb_sub_opt_rev; /* PCB subrevision and opt revision */
49 u8 som_type; /* SoM type */
50 u8 som_no; /* SoM number */
51 u8 ksp_no; /* KSP information */
52 char opt[PHYTEC_MAX_OPTIONS]; /* SoM options */
53 char bom_rev[2]; /* BOM revision */
54 u8 mac[6]; /* MAC address (optional) */
55 u8 crc8; /* checksum */
56} __packed;
57
Yannic Moogdb2dfb02024-04-19 08:55:37 -070058struct phytec_eeprom_payload {
Teresa Remmeta6f8da52023-08-17 10:57:06 +020059 u8 api_rev;
60 union {
61 struct phytec_api0_data data_api0;
62 struct phytec_api2_data data_api2;
63 } data;
64} __packed;
65
Yannic Moogdb2dfb02024-04-19 08:55:37 -070066struct phytec_eeprom_data {
67 struct phytec_eeprom_payload payload;
68 bool valid;
69};
70
Teresa Remmeta6f8da52023-08-17 10:57:06 +020071int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data,
72 int bus_num, int addr,
73 int addr_fallback);
74int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
75 int bus_num, int addr);
Yannic Moogdb2dfb02024-04-19 08:55:37 -070076int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num,
77 int addr);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020078void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
79
80char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
Teresa Remmete3d3ac42023-08-17 10:57:10 +020081u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
Benjamin Hahn455dcf72024-03-06 17:18:31 +010082u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020083
Daniel Schultza440ec22024-04-19 08:55:36 -070084#if IS_ENABLED(CONFIG_CMD_EXTENSION)
85struct extension *phytec_add_extension(const char *name, const char *overlay,
86 const char *other);
87#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */
88
Teresa Remmeta6f8da52023-08-17 10:57:06 +020089#endif /* _PHYTEC_SOM_DETECTION_H */