blob: 187424a2b44c0ae59842473e52a14ebc4cfc8ebe [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"
Daniel Schultzbda39152025-01-23 06:43:49 -080011#include <fdtdec.h>
Daniel Schultz03e619d2024-05-21 23:18:25 -070012
Teresa Remmeta6f8da52023-08-17 10:57:06 +020013#define PHYTEC_MAX_OPTIONS 17
14#define PHYTEC_EEPROM_INVAL 0xff
15
Daniel Schultz794aec62024-05-21 23:18:23 -070016#define PHYTEC_API2_DATA_LEN 32
17
Teresa Remmeta6f8da52023-08-17 10:57:06 +020018#define PHYTEC_GET_OPTION(option) \
19 (((option) > '9') ? (option) - 'A' + 10 : (option) - '0')
20
Daniel Schultzbda39152025-01-23 06:43:49 -080021#define PHYTEC_PRODUCT_NAME_STD_LEN 7 // PCx-000
22#define PHYTEC_PRODUCT_NAME_KSP_LEN 8 // KSP-0000
23#define PHYTEC_PRODUCT_NAME_MAX_LEN PHYTEC_PRODUCT_NAME_KSP_LEN
24#define PHYTEC_PART_NUMBER_STD_LEN 11 // PCx-000-\w{1,17}.Ax
25#define PHYTEC_PART_NUMBER_KSP_LEN 11 // KSP-0000.Ax
26#define PHYTEC_PART_NUMBER_STD_KSP_LEN 16 // PCx-000-KSx00.Ax
27#define PHYTEC_PART_NUMBER_MAX_LEN PHYTEC_PRODUCT_NAME_MAX_LEN + 21
28
Teresa Remmeta6f8da52023-08-17 10:57:06 +020029enum {
30 PHYTEC_API_REV0 = 0,
31 PHYTEC_API_REV1,
32 PHYTEC_API_REV2,
Daniel Schultz03e619d2024-05-21 23:18:25 -070033 PHYTEC_API_REV3,
Teresa Remmeta6f8da52023-08-17 10:57:06 +020034};
35
Benjamin Hahn455dcf72024-03-06 17:18:31 +010036enum phytec_som_type_str {
37 SOM_TYPE_PCM = 0,
38 SOM_TYPE_PCL,
39 SOM_TYPE_KSM,
40 SOM_TYPE_KSP,
41};
42
Teresa Remmeta6f8da52023-08-17 10:57:06 +020043static const char * const phytec_som_type_str[] = {
44 "PCM",
45 "PCL",
46 "KSM",
47 "KSP",
48};
49
50struct phytec_api0_data {
51 u8 pcb_rev; /* PCB revision of SoM */
52 u8 som_type; /* SoM type */
53 u8 ksp_no; /* KSP no */
54 char opt[16]; /* SoM options */
55 u8 mac[6]; /* MAC address (optional) */
56 u8 pad[5]; /* padding */
57 u8 cksum; /* checksum */
58} __packed;
59
60struct phytec_api2_data {
61 u8 pcb_rev; /* PCB revision of SoM */
62 u8 pcb_sub_opt_rev; /* PCB subrevision and opt revision */
63 u8 som_type; /* SoM type */
64 u8 som_no; /* SoM number */
65 u8 ksp_no; /* KSP information */
66 char opt[PHYTEC_MAX_OPTIONS]; /* SoM options */
67 char bom_rev[2]; /* BOM revision */
68 u8 mac[6]; /* MAC address (optional) */
69 u8 crc8; /* checksum */
70} __packed;
71
Yannic Moogdb2dfb02024-04-19 08:55:37 -070072struct phytec_eeprom_payload {
Teresa Remmeta6f8da52023-08-17 10:57:06 +020073 u8 api_rev;
74 union {
75 struct phytec_api0_data data_api0;
76 struct phytec_api2_data data_api2;
77 } data;
Daniel Schultz03e619d2024-05-21 23:18:25 -070078 struct phytec_api3_element *block_head;
Teresa Remmeta6f8da52023-08-17 10:57:06 +020079} __packed;
80
Yannic Moogdb2dfb02024-04-19 08:55:37 -070081struct phytec_eeprom_data {
82 struct phytec_eeprom_payload payload;
83 bool valid;
84};
85
Teresa Remmeta6f8da52023-08-17 10:57:06 +020086int phytec_eeprom_data_setup_fallback(struct phytec_eeprom_data *data,
87 int bus_num, int addr,
88 int addr_fallback);
89int phytec_eeprom_data_setup(struct phytec_eeprom_data *data,
90 int bus_num, int addr);
Yannic Moogdb2dfb02024-04-19 08:55:37 -070091int phytec_eeprom_data_init(struct phytec_eeprom_data *data, int bus_num,
92 int addr);
Teresa Remmeta6f8da52023-08-17 10:57:06 +020093void __maybe_unused phytec_print_som_info(struct phytec_eeprom_data *data);
94
95char * __maybe_unused phytec_get_opt(struct phytec_eeprom_data *data);
Teresa Remmete3d3ac42023-08-17 10:57:10 +020096u8 __maybe_unused phytec_get_rev(struct phytec_eeprom_data *data);
Benjamin Hahn455dcf72024-03-06 17:18:31 +010097u8 __maybe_unused phytec_get_som_type(struct phytec_eeprom_data *data);
Daniel Schultzbda39152025-01-23 06:43:49 -080098#if IS_ENABLED(CONFIG_OF_LIBFDT)
99int phytec_ft_board_fixup(struct phytec_eeprom_data *data, void *blob);
100#endif /* IS_ENABLED(CONFIG_OF_LIBFDT) */
Teresa Remmeta6f8da52023-08-17 10:57:06 +0200101
Daniel Schultza440ec22024-04-19 08:55:36 -0700102#if IS_ENABLED(CONFIG_CMD_EXTENSION)
103struct extension *phytec_add_extension(const char *name, const char *overlay,
104 const char *other);
105#endif /* IS_ENABLED(CONFIG_CMD_EXTENSION) */
106
Daniel Schultz03e619d2024-05-21 23:18:25 -0700107struct phytec_api3_element *
108 __maybe_unused phytec_get_block_head(struct phytec_eeprom_data *data);
109
Teresa Remmeta6f8da52023-08-17 10:57:06 +0200110#endif /* _PHYTEC_SOM_DETECTION_H */