blob: c68e2302cc42edaec880dd7bf07ccba1b8d5dec1 [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
22static const char * const phytec_som_type_str[] = {
23 "PCM",
24 "PCL",
25 "KSM",
26 "KSP",
27};
28
29struct 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
39struct 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
51struct 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
61int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data,
62 int bus_num, int addr,
63 int addr_fallback);
64int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
65 int bus_num, int addr);
66int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
67 int bus_num, int addr);
68void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
69
70char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
Teresa Remmete3d3ac42023-08-17 10:57:10 +020071u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020072
73#else
74
75inline int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
76 int bus_num, int addr)
77{
78 return PHYTEC_EEPROM_INVAL;
79}
80
81inline 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
88inline int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
89 int bus_num, int addr)
90{
91 return PHYTEC_EEPROM_INVAL;
92}
93
94inline void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data)
95{
96}
97
98inline char *__maybe_unused phytec_get_opt(struct phytec_eeprom_data *data)
99{
100 return NULL;
101}
102
Teresa Remmete3d3ac42023-08-17 10:57:10 +0200103u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data)
104{
105 return PHYTEC_EEPROM_INVAL;
106}
Teresa Remmeta6f8da52023-08-17 10:57:06 +0200107#endif /* IS_ENABLED(CONFIG_PHYTEC_SOM_DETECTION) */
108
109#endif /* _PHYTEC_SOM_DETECTION_H */