vcu: UserInterface detetion
Detect availability of user interface using a dummy i2c access. Change of DTS led depending on presence of UI boards. Signed-off-by: Patrick Zysset <patrick.zysset@netmodule.com>
This commit is contained in:
parent
92bdea79bc
commit
1923f7f14d
|
|
@ -10,4 +10,4 @@ ifeq ($(CONFIG_SKIP_LOWLEVEL_INIT),)
|
|||
obj-y := mux.o
|
||||
endif
|
||||
|
||||
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o fileaccess.o da9063.o sja1105.o
|
||||
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o fileaccess.o da9063.o sja1105.o ui.o
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@
|
|||
#include "board.h"
|
||||
#include "da9063.h"
|
||||
#include "sja1105.h"
|
||||
|
||||
#include "ui.h"
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
|
||||
|
|
@ -142,6 +142,7 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
|
|||
|
||||
static BD_Context bdctx[3]; /* The descriptor contexts */
|
||||
|
||||
#define CONFIG_OF_BOARD_SETUP
|
||||
|
||||
#if !defined(CONFIG_SPL_BUILD)
|
||||
|
||||
|
|
@ -630,6 +631,8 @@ int board_init(void)
|
|||
init_i2c();
|
||||
|
||||
da9063_init(CONFIG_PMIC_I2C_BUS);
|
||||
ui_i2c_init(CONFIG_UI_I2C_BUS);
|
||||
|
||||
|
||||
/* Let user know we're starting */
|
||||
init_leds();
|
||||
|
|
@ -836,11 +839,15 @@ static void check_reset_button(void)
|
|||
|
||||
int board_late_init(void)
|
||||
{
|
||||
|
||||
#if !defined(CONFIG_SPL_BUILD)
|
||||
if (read_eeprom() < 0) {
|
||||
puts("Could not get board ID.\n");
|
||||
}
|
||||
|
||||
int rc = -1;
|
||||
int bus;
|
||||
int ret;
|
||||
uint8_t val;
|
||||
get_hw_version();
|
||||
get_pmic_version();
|
||||
set_root_partition();
|
||||
|
|
@ -853,7 +860,21 @@ int board_late_init(void)
|
|||
REQUEST_AND_SET_GPIO(CAN0_TERM_N);
|
||||
REQUEST_AND_SET_GPIO(CAN1_TERM_N);
|
||||
|
||||
REQUEST_AND_CLEAR_GPIO(GPIO_RST_UI_N);
|
||||
/* UI configuration and detection */
|
||||
REQUEST_AND_SET_GPIO(GPIO_RST_UI_N);
|
||||
|
||||
|
||||
|
||||
ret = ui_claim_i2c_bus(&bus);
|
||||
if (ret == 0)
|
||||
rc = ui_i2c_get_reg(0x00, &val);
|
||||
if (rc==0 && ret == 0 )
|
||||
printf("UI interface detected\n");
|
||||
else
|
||||
printf("UI interface NOT detected\n");
|
||||
|
||||
if (ret == 0)
|
||||
ui_release_i2c_bus(bus);
|
||||
|
||||
/* FIXME: Problem switch reset lines of switch and PHY
|
||||
* Clocks for PHY are only present once switch is configured
|
||||
|
|
@ -877,6 +898,7 @@ int board_late_init(void)
|
|||
init_gsm();
|
||||
init_gnss();
|
||||
|
||||
|
||||
/*
|
||||
check_reset_button();
|
||||
*/
|
||||
|
|
@ -1027,12 +1049,49 @@ static void ft_hw_version(void *blob)
|
|||
if (node_offset != -1) {
|
||||
fdt_setprop_string(blob, node_offset, "nm,carrierboard,version", hw_version);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
static void ft_led(void *blob)
|
||||
{
|
||||
int rc = -1;
|
||||
int bus;
|
||||
int ret;
|
||||
uint8_t val;
|
||||
int node_offset;
|
||||
|
||||
ret = ui_claim_i2c_bus(&bus);
|
||||
if (ret == 0){
|
||||
rc = ui_i2c_get_reg(0x00, &val);
|
||||
ui_release_i2c_bus(bus);
|
||||
}
|
||||
if (rc==0 && ret == 0){
|
||||
printf ("ft access to change the led status to okay \n");
|
||||
node_offset = fdt_path_offset(blob, "/leds/led@4/");
|
||||
if (node_offset != -1) {
|
||||
fdt_setprop_string(blob, node_offset, "status", "okay");
|
||||
}
|
||||
node_offset = fdt_path_offset(blob, "/leds/led@5/");
|
||||
if (node_offset != -1) {
|
||||
fdt_setprop_string(blob, node_offset, "status", "okay");
|
||||
}
|
||||
node_offset = fdt_path_offset(blob, "/leds/led@6/");
|
||||
if (node_offset != -1) {
|
||||
fdt_setprop_string(blob, node_offset, "status", "okay");
|
||||
}
|
||||
node_offset = fdt_path_offset(blob, "/leds/led@7/");
|
||||
if (node_offset != -1) {
|
||||
fdt_setprop_string(blob, node_offset, "status", "okay");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int ft_board_setup(void *blob, bd_t *bd)
|
||||
{
|
||||
printf ("ft_board_setup called\n");
|
||||
ft_hw_version(blob);
|
||||
|
||||
ft_led(blob);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ static int switch_i2c_bus(void)
|
|||
|
||||
old_bus = i2c_get_bus_num();
|
||||
if (old_bus != da9063_i2c_bus) {
|
||||
printf("i2c sw from %d\n", old_bus);
|
||||
i2c_set_bus_num(da9063_i2c_bus);
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +36,6 @@ static int switch_i2c_bus(void)
|
|||
static void revert_i2c_bus(int bus)
|
||||
{
|
||||
if (da9063_i2c_bus != bus) {
|
||||
printf("i2c sw back to %d\n", bus);
|
||||
i2c_set_bus_num(bus);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* ui.c
|
||||
*
|
||||
* User Interface access
|
||||
*
|
||||
* Copyright (C) 2018 NetModule AG - http://www.netmodule.com/
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <errno.h>
|
||||
#include <i2c.h>
|
||||
|
||||
#include "ui.h"
|
||||
|
||||
|
||||
static int ui_i2c_bus = 0;
|
||||
static int ui_bus_claimed = false;
|
||||
|
||||
|
||||
static int switch_i2c_bus(int* old_bus)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (old_bus == 0)
|
||||
return -1;
|
||||
|
||||
*old_bus = i2c_get_bus_num();
|
||||
if (*old_bus != ui_i2c_bus) {
|
||||
ret = i2c_set_bus_num(ui_i2c_bus);
|
||||
}
|
||||
|
||||
ui_bus_claimed = true;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int revert_i2c_bus(int bus)
|
||||
{
|
||||
int ret = 0;
|
||||
if (ui_i2c_bus != bus) {
|
||||
ret = i2c_set_bus_num(bus);
|
||||
}
|
||||
|
||||
ui_bus_claimed = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void ui_i2c_init(int i2c_bus)
|
||||
{
|
||||
ui_i2c_bus = i2c_bus;
|
||||
}
|
||||
|
||||
int ui_claim_i2c_bus(int* old_bus)
|
||||
{
|
||||
return switch_i2c_bus(old_bus);
|
||||
}
|
||||
|
||||
int ui_release_i2c_bus(int bus)
|
||||
{
|
||||
return revert_i2c_bus(bus);
|
||||
}
|
||||
|
||||
int ui_i2c_get_reg(uint32_t reg, u8* val)
|
||||
{
|
||||
int ret;
|
||||
u8 temp;
|
||||
|
||||
/* Argument check */
|
||||
if ((reg >= 8)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* State check. Has bus been claimed */
|
||||
if (ui_bus_claimed == false) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
*val = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* ui.c
|
||||
*
|
||||
* User Interface access
|
||||
*
|
||||
* Copyright (C) 2018 NetModule AG - http://www.netmodule.com/
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0+
|
||||
*/
|
||||
|
||||
#ifndef UI_H
|
||||
#define UI_H
|
||||
|
||||
|
||||
#define CONFIG_UI_I2C_BUS 1
|
||||
#define CONFIG_UI_I2C_ADDR 0x74 /* 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);
|
||||
|
||||
|
||||
|
||||
#endif /* UI_H */
|
||||
Loading…
Reference in New Issue