blob: 05cf55e4291daedc9134b77e0a51cf90ed4a193f [file] [log] [blame]
Jonas Karlman5bbf0452024-10-17 20:00:27 +00001// SPDX-License-Identifier: GPL-2.0+
2
3#include <adc.h>
4#include <env.h>
5#include <linux/errno.h>
6#include <linux/kernel.h>
7
8#define HW_ID_CHANNEL 5
9
10struct board_model {
11 unsigned int low;
12 unsigned int high;
13 const char *fdtfile;
14};
15
16static const struct board_model board_models[] = {
17 { 348, 528, "rockchip/rk3588-nanopc-t6.dtb" },
18 { 1957, 2137, "rockchip/rk3588-nanopc-t6-lts.dtb" },
19};
20
21static const struct board_model *get_board_model(void)
22{
23 unsigned int val;
24 int i, ret;
25
26 ret = adc_channel_single_shot("adc@fec10000", HW_ID_CHANNEL, &val);
27 if (ret)
28 return NULL;
29
30 for (i = 0; i < ARRAY_SIZE(board_models); i++) {
31 unsigned int min = board_models[i].low;
32 unsigned int max = board_models[i].high;
33
34 if (min <= val && val <= max)
35 return &board_models[i];
36 }
37
38 return NULL;
39}
40
41int rk_board_late_init(void)
42{
43 const struct board_model *model = get_board_model();
44
45 if (model)
46 env_set("fdtfile", model->fdtfile);
47
48 return 0;
49}
50
51int board_fit_config_name_match(const char *name)
52{
53 const struct board_model *model = get_board_model();
54
55 if (model && !strcmp(name, model->fdtfile))
56 return 0;
57
58 return -EINVAL;
59}