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(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;

View File

@ -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;
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 {
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;
}

View File

@ -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 */