Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dts automatic select #45

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions board/rockchip/evb_rk3568/evb_rk3568.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,84 @@
/*
* (C) Copyright 2021 Rockchip Electronics Co., Ltd
*/
#include <common.h>
#include <dm.h>
#include <adc.h>
#include <asm/global_data.h>

#define SARADC_ADDR "saradc@fe720000"
#define HW_ID_CHANNEL 1
#define BOM_ID_CHANNEL 2

#define countof(x) (sizeof(x) / sizeof(x[0]))

struct variant_def {
char *compatible;
unsigned int hw_id_lower_bound;
unsigned int hw_id_upper_bound;
unsigned int bom_id_lower_bound;
unsigned int bom_id_upper_bound;
char *fdtfile;
};

static struct variant_def variants[] = {
{"radxa,zero3", 230, 270, 0, -1, "rockchip/rk3566-radxa-zero-3w-aic8800ds2.dtb"},
{"radxa,zero3", 400, 450, 0, -1, "rockchip/rk3566-radxa-zero-3e.dtb"},
{"radxa,zero3", 451, 510, 0, -1, "rockchip/rk3566-radxa-zero-3w-ap6212.dtb"},
{"radxa,rock-3c", 300, 360, 0, -1, "rockchip/rk3566-rock-3c-aic8800ds2.dtb"},
};

void set_fdtfile(void)
{
int i, ret;
unsigned int hw_id, bom_id;
struct variant_def *v;

ret = adc_channel_single_shot(SARADC_ADDR, HW_ID_CHANNEL, &hw_id);
if (ret) {
pr_err("%s: adc_channel_single_shot fail for HW_ID: %i!\n", __func__, ret);
return;
}
ret = adc_channel_single_shot(SARADC_ADDR, BOM_ID_CHANNEL, &bom_id);
if (ret) {
pr_err("%s: adc_channel_single_shot fail for BOM_ID: %i!\n", __func__, ret);
return;
}

for(i = 0; i < countof(variants); i++) {
v = &variants[i];
if (of_machine_is_compatible(v->compatible) &&
hw_id >= v->hw_id_lower_bound &&
hw_id <= v->hw_id_upper_bound &&
bom_id >= v->bom_id_lower_bound &&
bom_id >= v->bom_id_lower_bound) {
printf("Override default fdtfile to %s\n", v->fdtfile);
env_set("fdtfile", v->fdtfile);
break;
}
}
}

/**
* mac_read_from_eeprom() - read the MAC address & the serial number in EEPROM
*
* This function reads the MAC address and the serial number from EEPROM and
* sets the appropriate environment variables for each one read.
*
* The environment variables are only set if they haven't been set already.
* This ensures that any user-saved variables are never overwritten.
*
* If CONFIG_ID_EEPROM is enabled, this function will be called in
* "static init_fnc_t init_sequence_r[]" of u-boot/common/board_r.c.
*/
int mac_read_from_eeprom(void)
{
set_fdtfile();
return 0;
}

int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
RadxaYuntian marked this conversation as resolved.
Show resolved Hide resolved
{
printf("This device does not support user programmable EEPROM.\n");
return -1;
}
1 change: 1 addition & 0 deletions configs/radxa-zero3-rk3566_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ CONFIG_CMD_SF=y
CONFIG_SYS_SATA_MAX_DEVICE=2
CONFIG_USB_GADGET=y
CONFIG_USB_DWC3_GENERIC=y
CONFIG_ID_EEPROM=y
1 change: 1 addition & 0 deletions configs/rock-3c-rk3566_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,4 @@ CONFIG_CMD_SF=y
CONFIG_SYS_SATA_MAX_DEVICE=2
CONFIG_USB_GADGET=y
CONFIG_USB_DWC3_GENERIC=y
CONFIG_ID_EEPROM=y