blob: eb9574d43b5871945948a906048feb537a158724 [file] [log] [blame]
Christoph Stoidner5b7d7012024-11-20 17:31:42 +01001// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2024 PHYTEC Messtechnik GmbH
4 * Author: Primoz Fiser <primoz.fiser@norik.com>
5 */
6
7#include <asm/arch/sys_proto.h>
8#include <dm/device.h>
9#include <dm/uclass.h>
10#include <i2c.h>
11#include <u-boot/crc.h>
12
13#include "imx93_som_detection.h"
14
15extern struct phytec_eeprom_data eeprom_data;
16
17#if IS_ENABLED(CONFIG_PHYTEC_IMX93_SOM_DETECTION)
18
19/* Check if the SoM is actually one of the following products:
20 * - i.MX93
21 *
22 * Returns 0 in case it's a known SoM. Otherwise, returns 1.
23 */
24u8 __maybe_unused phytec_imx93_detect(struct phytec_eeprom_data *data)
25{
26 u8 som;
27
28 if (!data)
29 data = &eeprom_data;
30
31 /* Early API revisions are not supported */
32 if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
33 return 1;
34
35 som = data->payload.data.data_api2.som_no;
36 debug("%s: som id: %u\n", __func__, som);
37
38 if (som == PHYTEC_IMX93_SOM && is_imx93())
39 return 0;
40
41 pr_err("%s: SoM ID does not match. Wrong EEPROM data?\n", __func__);
42 return 1;
43}
44
45/*
46 * Filter PHYTEC i.MX93 SoM options by option index
47 *
48 * Returns:
49 * - option value
50 * - PHYTEC_EEPROM_INVAL when the data is invalid
51 *
52 */
53u8 __maybe_unused phytec_imx93_get_opt(struct phytec_eeprom_data *data,
54 enum phytec_imx93_option_index idx)
55{
56 char *opt;
57 u8 opt_id;
58
59 if (!data)
60 data = &eeprom_data;
61
62 if (!data->valid || data->payload.api_rev < PHYTEC_API_REV2)
63 return PHYTEC_EEPROM_INVAL;
64
65 opt = phytec_get_opt(data);
66 if (opt)
67 opt_id = PHYTEC_GET_OPTION(opt[idx]);
68 else
69 opt_id = PHYTEC_EEPROM_INVAL;
70
71 debug("%s: opt[%d] id: %u\n", __func__, idx, opt_id);
72 return opt_id;
73}
74
75/*
76 * Filter PHYTEC i.MX93 SoM voltage
77 *
78 * Returns:
79 * - PHYTEC_IMX93_VOLTAGE_1V8 or PHYTEC_IMX93_VOLTAGE_3V3
80 * - PHYTEC_EEPROM_INVAL when the data is invalid
81 *
82 */
83enum phytec_imx93_voltage __maybe_unused phytec_imx93_get_voltage(struct phytec_eeprom_data *data)
84{
85 u8 option = phytec_imx93_get_opt(data, PHYTEC_IMX93_OPT_FEAT);
86
87 if (option == PHYTEC_EEPROM_INVAL)
88 return PHYTEC_IMX93_VOLTAGE_INVALID;
89 return (option & 0x01) ? PHYTEC_IMX93_VOLTAGE_1V8 : PHYTEC_IMX93_VOLTAGE_3V3;
90}
91
92#else
93
94inline u8 __maybe_unused phytec_imx93_detect(struct phytec_eeprom_data *data)
95{
96 return 1;
97}
98
99inline u8 __maybe_unused phytec_imx93_get_opt(struct phytec_eeprom_data *data,
100 enum phytec_imx93_option_index idx)
101{
102 return PHYTEC_EEPROM_INVAL;
103}
104
105inline enum phytec_imx93_voltage __maybe_unused phytec_imx93_get_voltage
106 (struct phytec_eeprom_data *data)
107{
108 return PHYTEC_EEPROM_INVAL;
109}
110
111#endif /* IS_ENABLED(CONFIG_PHYTEC_IMX93_SOM_DETECTION) */