diff --git a/board/nm/hancock/board.c b/board/nm/hancock/board.c index 35416653e2..796a0df4be 100644 --- a/board/nm/hancock/board.c +++ b/board/nm/hancock/board.c @@ -857,11 +857,14 @@ int board_late_init(void) REQUEST_AND_SET_GPIO(CAN0_TERM_N); REQUEST_AND_SET_GPIO(CAN1_TERM_N); + /* UI configuration and detection */ REQUEST_AND_SET_GPIO(GPIO_RST_UI_N); - - if ( detect_ui() ) - printf("UI: ready\n"); + int ui_version = detect_ui(); + if ( ui_version == 2 ) + printf("UI: V2.0\n"); + else if ( ui_version == 1 ) + printf("UI: V1.0\n"); else printf("UI: n/a\n"); @@ -1046,9 +1049,8 @@ static void ft_led(void *blob) { int node_offset; - - if ( detect_ui() ){ - printf ("ft access to change the led status to okay \n"); + int ui_version = detect_ui(); + if ( ui_version >= 1){ node_offset = fdt_path_offset(blob, "/leds/led@4/"); if (node_offset != -1) { fdt_setprop_string(blob, node_offset, "status", "okay"); @@ -1071,7 +1073,6 @@ static void ft_led(void *blob) int ft_board_setup(void *blob, bd_t *bd) { - printf ("ft_board_setup called\n"); ft_hw_version(blob); ft_led(blob); return 0; diff --git a/board/nm/hancock/ui.c b/board/nm/hancock/ui.c index fa30be30c9..e6b94c805c 100644 --- a/board/nm/hancock/ui.c +++ b/board/nm/hancock/ui.c @@ -63,7 +63,7 @@ int ui_release_i2c_bus(int bus) return revert_i2c_bus(bus); } -int ui_i2c_get_reg(uint32_t reg, u8* val) +static int ui_i2c_get_reg(uint32_t reg, u8* val, int version) { int ret; u8 temp; @@ -79,54 +79,40 @@ int ui_i2c_get_reg(uint32_t reg, u8* val) } *val = 0; - ret = i2c_read(CONFIG_UI_I2C_ADDR, reg & 0xFF, 1, &temp, 1); + if (version == 2) { + ret = i2c_read(CONFIG_UIV2_I2C_ADDR, reg & 0xFF, 1, &temp, 1); + } + else{ + ret = i2c_read(CONFIG_UI_I2C_ADDR, reg & 0xFF, 1, &temp, 1); + } if (ret == 0) *val = temp; return ret; } -int ui_i2c_set_reg(uint32_t reg, u8 val) -{ - int ret; - - /* Argument check */ - if ((reg >= 0x8)) { - return -1; - } - - /* State check. Has bus been claimed */ - if (ui_bus_claimed == false) { - return -2; - } - - ret = i2c_write(CONFIG_UI_I2C_ADDR, reg & 0xFF, 1, &val, 1); - - if (ret != 0) - puts("ui i2c write error\n"); - - return ret; -} - -bool detect_ui(void) +/* version 2: V2.0 UI , 1: V1.0 UI */ +int detect_ui(void) { int bus; int claim; uint8_t val; - static int ui_detected = -1; /* -1: unitialized, 0: UI not available, 1: UI detected */ - + static int ui_detected = -1; /* -1: unitialized, 0: UI not available, 1: UI V1 detected ,2: UI V2 detected */ if (ui_detected < 0) { claim = ui_claim_i2c_bus(&bus); if (claim == 0) { - if ( 0 == ui_i2c_get_reg(0x00, &val)) + if ( 0 == ui_i2c_get_reg(0x00, &val,1)) ui_detected = 1; - else - ui_detected = 0; + else { + if ( 0 == ui_i2c_get_reg(0x00, &val,2)) + ui_detected = 2; + else + ui_detected = 0; + } ui_release_i2c_bus(bus); } } - - return (ui_detected == 1); + return ui_detected; } diff --git a/board/nm/hancock/ui.h b/board/nm/hancock/ui.h index f181b5d43f..106d889377 100644 --- a/board/nm/hancock/ui.h +++ b/board/nm/hancock/ui.h @@ -15,16 +15,14 @@ #define CONFIG_UI_I2C_BUS 1 #define CONFIG_UI_I2C_ADDR 0x74 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */ - +#define CONFIG_UIV2_I2C_ADDR 0x70 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */ extern void ui_i2c_init(int i2c_bus); extern int ui_claim_i2c_bus(int* old_bus); extern int ui_release_i2c_bus(int bus); -extern int ui_i2c_get_reg(uint32_t reg, u8* val); -extern int ui_i2c_set_reg(uint32_t reg, u8 val); -extern bool detect_ui(void); +extern int detect_ui(void); #endif /* UI_H */