From 3b18df525d21f9d18d072d1a197ff1b37db68beb Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Wed, 2 Dec 2020 08:11:59 +0100 Subject: [PATCH] hw25: handle gpio variants --- board/nm/hw25/board.c | 91 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/board/nm/hw25/board.c b/board/nm/hw25/board.c index 659940ea7b..24266069b4 100644 --- a/board/nm/hw25/board.c +++ b/board/nm/hw25/board.c @@ -1205,6 +1205,63 @@ 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 remove IOs not present */ + ft_set_gpio_name(blob, "/ocp/gpio@44e07000", 27, ""); /* gpio0_27: IO_OUT1n */ + ft_set_gpio_name(blob, "/ocp/gpio@4804c000", 14, ""); /* gpio1_14: IO_IN2 */ + ft_set_gpio_name(blob, "/ocp/gpio@4804c000", 15, ""); /* gpio1_15: IO_IN3 */ + + /* pmic_gpios: 5: IO_IN2_WAKE3n, 6: IO_IN2_WAKE3n */ + ft_set_gpio_name(blob, "/ocp/i2c@44e0b000/da9063@58/gpio", 5, ""); + ft_set_gpio_name(blob, "/ocp/i2c@44e0b000/da9063@58/gpio", 6, ""); + break; + + default: + break; } } @@ -1257,6 +1323,11 @@ static void ft_tty(void *blob) /* TODO: Should use alias uart5 */ ft_enable_node(blob, "/ocp/serial@481aa000"); } + else { + /* OEM Linux gpios -> remove IOs not present */ + ft_set_gpio_name(blob, "/ocp/gpio@44e07000", 22, ""); /* gpio0_22: SEL_RS232_RS485n */ + ft_set_gpio_name(blob, "/ocp/gpio@44e07000", 23, ""); /* gpio0_23: RS485_TERM_ENn */ + } } #if 0