From a9e615e7ae856976f24647485fae8578199dd448 Mon Sep 17 00:00:00 2001 From: Rene Straub Date: Thu, 14 Apr 2022 10:38:41 +0200 Subject: [PATCH] hw21/26: add support for hw v3.2 Support uart4 for added RS232/485 interface Move led0.green to new pin --- board/nm/nmhw21/board.c | 166 ++++++++++++++++++++++++++++++++++++---- board/nm/nmhw21/board.h | 4 +- board/nm/nmhw21/mux.c | 85 ++++++++++++++------ 3 files changed, 216 insertions(+), 39 deletions(-) diff --git a/board/nm/nmhw21/board.c b/board/nm/nmhw21/board.c index 92ec727c10..ada24b31d0 100644 --- a/board/nm/nmhw21/board.c +++ b/board/nm/nmhw21/board.c @@ -48,10 +48,11 @@ DECLARE_GLOBAL_DATA_PTR; /* * CPU GPIOs * +* (C15) GPIO0_6: MB_LED_PWM * (J18) GPIO0_16: ETH_SW_RST~ (V2.0) * (K15) GPIO0_17: CTRL.INT~ * (T10) GPIO0_23: CAN_TERM1~ (V1.0) -* (T17) GPIO0_30: LED0.RD +* (T17) GPIO0_30: LED0.GN (= 0x0302; + + return res; +} + static void init_leds(void) { REQUEST_AND_SET_GPIO(GPIO_LED0_RED); - REQUEST_AND_SET_GPIO(GPIO_LED0_GREEN); + if (is_v32_or_newer()) { + REQUEST_AND_SET_GPIO(GPIO_LED_PWM_V32); + REQUEST_AND_SET_GPIO(GPIO_LED0_GREEN_V32); + } + else { + REQUEST_AND_SET_GPIO(GPIO_LED0_GREEN); + } REQUEST_AND_SET_GPIO(GPIO_LED1_RED); REQUEST_AND_SET_GPIO(GPIO_LED1_GREEN); } @@ -231,7 +251,12 @@ static void init_leds(void) static void set_status_led(int red, int green) { gpio_set_value(GPIO_LED0_RED, red); - gpio_set_value(GPIO_LED0_GREEN, green); + if (is_v32_or_newer()) { + gpio_set_value(GPIO_LED0_GREEN_V32, green); + } + else { + gpio_set_value(GPIO_LED0_GREEN, green); + } } static void set_indicator_led(int red, int green) @@ -734,6 +759,8 @@ static void init_bd_spl(void) if (read_eeprom() >= 0) { int hw_type_from_bd = -1; + bd_get_hw_version(&hw_ver, &hw_rev); + /* If entry is found returns value, otherwise 0 */ bd_get_hw_type(&hw_type_from_bd); if (hw_type_from_bd != 0) { @@ -776,6 +803,14 @@ void am33xx_spl_board_init(void) stop_if_ignition_is_off(); } + if (is_v32_or_newer()) { + enable_led_mux_v32(); + enable_uart4_pin_mux(); + } + else { + enable_led_mux(); + } + init_leds(); set_status_led(1, 0); /* Red */ set_indicator_led(1, 0); /* Red */ @@ -1155,16 +1190,6 @@ int board_init(void) ui_init(CONFIG_UI_I2C_BUS); #endif - /* Let user know we're starting */ - init_leds(); - set_status_led(1, 1); /* Orange */ - set_indicator_led(0, 0); /* Off */ - -#ifndef CONFIG_NRSW_BUILD - ui_set_status_led(1, 1); /* Orange */ - ui_set_indicator_led(0, 0); /* Off */ -#endif - printf("OSC: %lu MHz\n", get_osclk()/1000000); return 0; @@ -1808,6 +1833,16 @@ int board_late_init(void) get_hw_version(); get_pmic_version(); + /* Let user know we're starting */ + init_leds(); + set_status_led(1, 1); /* Orange */ + set_indicator_led(0, 0); /* Off */ + +#ifndef CONFIG_NRSW_BUILD + ui_set_status_led(1, 1); /* Orange */ + ui_set_indicator_led(0, 0); /* Off */ +#endif + #ifdef CONFIG_NRSW_BUILD set_root_partition(); set_devicetree_name(); @@ -2054,6 +2089,74 @@ int board_fit_config_name_match(const char *name) #if defined(CONFIG_OF_BOARD_SETUP) && !defined(CONFIG_SPL_BUILD) +static void ft_enable_node(void* blob, const char* name) +{ + int node_ofs = -1; + + node_ofs = fdt_path_offset(blob, name); + printf("ft_enable_node %s -> %d\n", name, node_ofs); + if (node_ofs >= 0) { + fdt_setprop_string(blob, node_ofs, "status", "okay"); + } +} + +/* + * 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 < 0) { + 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 RS232 mode + * RTSn = RS485_DE: Default = Low -> RS485 transmitter disabled + * Configure as GPIO in U-Boot to keep disabled, Linux will change to RTSn + */ + {OFFSET(gpmc_wait0), (MODE(6) | PULLUDEN | PULLUP_EN | RXACTIVE)}, /* (T17) UART4_RXD */ + {OFFSET(gpmc_wpn), (MODE(6) | PULLUDEN | PULLUP_EN | SLEWCTRL)}, /* (U17) UART4_TXD */ + {OFFSET(lcd_data12), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* (V2) uart4_ctsn */ + {OFFSET(lcd_data13), (MODE(7) | PULLUDEN | PULLDOWN_EN)}, /* (V3) uart4_rtsn */ + {-1} +}; + /* UART5: Highspeed UART for Bluetooth (no SLEWCTRL) */ static struct module_pin_mux uart5_pin_mux[] = { {OFFSET(lcd_data9), (MODE(4) | PULLUDEN | PULLUP_EN | RXACTIVE)}, /* (U2) UART5_RXD */ @@ -268,7 +292,22 @@ void enable_uart2_pin_mux(void) configure_module_pin_mux(uart2_pin_mux); } +void enable_uart4_pin_mux(void) +{ + configure_module_pin_mux(uart4_pin_mux); +} + void enable_spi1_mux(void) { configure_module_pin_mux(spi1_pin_mux); } + +void enable_led_mux(void) +{ + configure_module_pin_mux(led_pin_mux); +} + +void enable_led_mux_v32(void) +{ + configure_module_pin_mux(led_pin_mux_v32); +}