hw25: add variant handling
get variant information from product descriptor
configure device-tree accordingly
BugzId: 66001
(cherry picked from commit e85e9ffa83)
This commit is contained in:
parent
604a8ea642
commit
00c9af8001
|
|
@ -120,6 +120,8 @@ static int hw_rev = -1;
|
|||
static int hw_patch = -1;
|
||||
static int hw_type = -1;
|
||||
static char hw_variant_name[64];
|
||||
static bool hw_has_tty = false;
|
||||
static int hw_num_ios = -1;
|
||||
#else
|
||||
static int hw_type = -1;
|
||||
static uint32_t sys_start_event = 0x0;
|
||||
|
|
@ -812,6 +814,43 @@ static void get_hw_version(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void get_dio(void)
|
||||
{
|
||||
/*
|
||||
* Check digital I/O variant
|
||||
* - 2xin, 1xout -> port0=in,port1=in,port2=out
|
||||
* - 4xin, 2xout -> port0=in,port1=in,port2=in,port3=in,port4=out,port5=out
|
||||
*/
|
||||
char dio_conf[128];
|
||||
|
||||
dio_conf[0] = 0;
|
||||
bd_get_pd_dio(dio_conf, sizeof(dio_conf));
|
||||
|
||||
if (strstr(dio_conf, "port2=in,port3=in,port4=out,port5=out") != 0) {
|
||||
hw_num_ios = 6;
|
||||
}
|
||||
else if (strstr(dio_conf, "port0=in,port1=in,port2=out") != 0) {
|
||||
hw_num_ios = 3;
|
||||
}
|
||||
else {
|
||||
hw_num_ios = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void get_serial(void)
|
||||
{
|
||||
/* Check if the variant implements ttyS5 */
|
||||
char serial_conf[128];
|
||||
|
||||
serial_conf[0] = 0;
|
||||
bd_get_pd_serial(serial_conf, sizeof(serial_conf));
|
||||
|
||||
// AddItemString('pd_serial', 'port0=ttyS0,port1=ttyS5')
|
||||
if (strstr(serial_conf, "ttyS5") != 0) {
|
||||
hw_has_tty = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void get_pmic_version(void)
|
||||
{
|
||||
uint8_t val = 0x00;
|
||||
|
|
@ -976,6 +1015,8 @@ int board_late_init(void)
|
|||
|
||||
get_variant_name();
|
||||
get_hw_version();
|
||||
get_dio();
|
||||
get_serial();
|
||||
get_pmic_version();
|
||||
|
||||
set_root_partition();
|
||||
|
|
@ -1152,7 +1193,6 @@ int board_fit_config_name_match(const char *name)
|
|||
|
||||
#if defined(CONFIG_OF_BOARD_SETUP) && !defined(CONFIG_SPL_BUILD)
|
||||
|
||||
#if 0
|
||||
static void ft_enable_node(void* blob, const char* name)
|
||||
{
|
||||
int node_ofs = -1;
|
||||
|
|
@ -1163,64 +1203,6 @@ static void ft_enable_node(void* blob, const char* name)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Modify the name of a gpio in a gpio-line-names string list.
|
||||
*/
|
||||
static void ft_set_gpio_name(void *blob, const char* gpio, int pin, const char* name)
|
||||
{
|
||||
int node_ofs = fdt_path_offset(blob, gpio);
|
||||
int gpios = -1;
|
||||
const char* text;
|
||||
int pos = 0;
|
||||
int i;
|
||||
char buffer[512];
|
||||
|
||||
if (node_ofs == -1) {
|
||||
printf("Can't find node %s\n", gpio);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* get number of IOs in node */
|
||||
gpios = fdt_getprop_u32_default_node(blob, node_ofs, 0, "ngpios", -1);
|
||||
if (gpios == -1 || gpios > 64) {
|
||||
printf("Illegal number of gpios %d\n", gpios);
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* get string array with names */
|
||||
const struct fdt_property* prop = fdt_get_property(blob, node_ofs, "gpio-line-names", NULL);
|
||||
if (prop == NULL) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
/* modify given name */
|
||||
for (i=0; i<gpios; i++) {
|
||||
if (i == pin) {
|
||||
/* Take provided name if GPIO pin is matched */
|
||||
text = name;
|
||||
}
|
||||
else {
|
||||
/* Take existing name from string list */
|
||||
(void)fdt_get_string_index(blob, node_ofs, "gpio-line-names", i, &text);
|
||||
}
|
||||
|
||||
/* Add name to new string list */
|
||||
if ((pos + strlen(text) + 1) < sizeof(buffer)) {
|
||||
strncpy(buffer+pos, text, sizeof(buffer)-pos);
|
||||
pos += strlen(text) + 1;
|
||||
}
|
||||
else {
|
||||
printf("ft_set_gpio_name() Buffer too small\n");
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
(void)fdt_setprop(blob, node_ofs, "gpio-line-names", buffer, pos);
|
||||
|
||||
end: ;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ft_bootloader_version(void *blob)
|
||||
{
|
||||
int node_offset;
|
||||
|
|
@ -1249,6 +1231,32 @@ static void ft_hw_info(void *blob)
|
|||
}
|
||||
}
|
||||
|
||||
static void ft_dio(void *blob)
|
||||
{
|
||||
switch (hw_num_ios) {
|
||||
case 6:
|
||||
printf("configuring 4+2 IOs\n");
|
||||
ft_enable_node(blob, "/netbox_dio_4in_2out");
|
||||
break;
|
||||
|
||||
case 3:
|
||||
printf("configuring 2+1 IOs\n");
|
||||
ft_enable_node(blob, "/netbox_dio_2in_1out");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ft_tty(void *blob)
|
||||
{
|
||||
if (hw_has_tty) {
|
||||
/* TODO: Should use alias uart5 */
|
||||
ft_enable_node(blob, "/ocp/serial@481aa000");
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void ft_override_thermal(void *blob)
|
||||
{
|
||||
|
|
@ -1286,6 +1294,8 @@ int ft_board_setup(void *blob, bd_t *bd)
|
|||
ft_bootloader_version(blob);
|
||||
ft_hw_info(blob);
|
||||
|
||||
ft_dio(blob);
|
||||
ft_tty(blob);
|
||||
/* ft_override_thermal(blob); */
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue