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
16enum {
17	PHYTEC_API_REV0 = 0,
18	PHYTEC_API_REV1,
19	PHYTEC_API_REV2,
20};
21
22enum phytec_som_type_str {
23	SOM_TYPE_PCM = 0,
24	SOM_TYPE_PCL,
25	SOM_TYPE_KSM,
26	SOM_TYPE_KSP,
27};
28
29static 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
58struct phytec_eeprom_payload {
59	u8 api_rev;
60	union {
61		struct phytec_api0_data data_api0;
62		struct phytec_api2_data data_api2;
63	} data;
64} __packed;
65
66struct phytec_eeprom_data {
67	struct phytec_eeprom_payload payload;
68	bool valid;
69};
70
71int 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);
76int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num,
77			    int addr);
78void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
79
80char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
81u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
82u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data);
83
84#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
89#endif /* _PHYTEC_SOM_DETECTION_H */
90