nmhw21 : add V2.0 UI detection along V1.0

You will find a UI: xxx output in the startup log of U-Boot.

BugzID: 53817

Signed-off-by: Patrick Zysset <patrick.zysset@netmodule.com>
This commit is contained in:
mikaeltrigo 2018-10-25 20:38:52 +02:00 committed by Patrick Zysset
parent 57c634da98
commit a7647131e0
3 changed files with 28 additions and 43 deletions

View File

@ -857,11 +857,14 @@ int board_late_init(void)
REQUEST_AND_SET_GPIO(CAN0_TERM_N); REQUEST_AND_SET_GPIO(CAN0_TERM_N);
REQUEST_AND_SET_GPIO(CAN1_TERM_N); REQUEST_AND_SET_GPIO(CAN1_TERM_N);
/* UI configuration and detection */ /* UI configuration and detection */
REQUEST_AND_SET_GPIO(GPIO_RST_UI_N); REQUEST_AND_SET_GPIO(GPIO_RST_UI_N);
int ui_version = detect_ui();
if ( detect_ui() ) if ( ui_version == 2 )
printf("UI: ready\n"); printf("UI: V2.0\n");
else if ( ui_version == 1 )
printf("UI: V1.0\n");
else else
printf("UI: n/a\n"); printf("UI: n/a\n");
@ -1046,9 +1049,8 @@ static void ft_led(void *blob)
{ {
int node_offset; int node_offset;
int ui_version = detect_ui();
if ( detect_ui() ){ if ( ui_version >= 1){
printf ("ft access to change the led status to okay \n");
node_offset = fdt_path_offset(blob, "/leds/led@4/"); node_offset = fdt_path_offset(blob, "/leds/led@4/");
if (node_offset != -1) { if (node_offset != -1) {
fdt_setprop_string(blob, node_offset, "status", "okay"); 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) int ft_board_setup(void *blob, bd_t *bd)
{ {
printf ("ft_board_setup called\n");
ft_hw_version(blob); ft_hw_version(blob);
ft_led(blob); ft_led(blob);
return 0; return 0;

View File

@ -63,7 +63,7 @@ int ui_release_i2c_bus(int bus)
return revert_i2c_bus(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; int ret;
u8 temp; u8 temp;
@ -79,54 +79,40 @@ int ui_i2c_get_reg(uint32_t reg, u8* val)
} }
*val = 0; *val = 0;
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); ret = i2c_read(CONFIG_UI_I2C_ADDR, reg & 0xFF, 1, &temp, 1);
}
if (ret == 0) if (ret == 0)
*val = temp; *val = temp;
return ret; return ret;
} }
int ui_i2c_set_reg(uint32_t reg, u8 val) /* version 2: V2.0 UI , 1: V1.0 UI */
{ int detect_ui(void)
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)
{ {
int bus; int bus;
int claim; int claim;
uint8_t val; 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) { if (ui_detected < 0) {
claim = ui_claim_i2c_bus(&bus); claim = ui_claim_i2c_bus(&bus);
if (claim == 0) { if (claim == 0) {
if ( 0 == ui_i2c_get_reg(0x00, &val)) if ( 0 == ui_i2c_get_reg(0x00, &val,1))
ui_detected = 1; ui_detected = 1;
else {
if ( 0 == ui_i2c_get_reg(0x00, &val,2))
ui_detected = 2;
else else
ui_detected = 0; ui_detected = 0;
}
ui_release_i2c_bus(bus); ui_release_i2c_bus(bus);
} }
} }
return ui_detected;
return (ui_detected == 1);
} }

View File

@ -15,16 +15,14 @@
#define CONFIG_UI_I2C_BUS 1 #define CONFIG_UI_I2C_BUS 1
#define CONFIG_UI_I2C_ADDR 0x74 /* Pages 0 and 1, Pages 2 and 3 -> 0x59 */ #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 void ui_i2c_init(int i2c_bus);
extern int ui_claim_i2c_bus(int* old_bus); extern int ui_claim_i2c_bus(int* old_bus);
extern int ui_release_i2c_bus(int bus); extern int ui_release_i2c_bus(int bus);
extern int ui_i2c_get_reg(uint32_t reg, u8* val); extern int detect_ui(void);
extern int ui_i2c_set_reg(uint32_t reg, u8 val);
extern bool detect_ui(void);
#endif /* UI_H */ #endif /* UI_H */