blob: 11009240875c1085f5a92402b8f7450329c20868 [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
Teresa Remmeta6f8da52023-08-17 10:57:06 +020059int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data,
60 int bus_num, int addr,
61 int addr_fallback);
62int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
63 int bus_num, int addr);
64int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
65 int bus_num, int addr);
66void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
67
68char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
Teresa Remmete3d3ac42023-08-17 10:57:10 +020069u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020070
Teresa Remmeta6f8da52023-08-17 10:57:06 +020071#endif /* _PHYTEC_SOM_DETECTION_H */