[PATCH 0/4] Add support for LX TestBox

The Testbox board is an open hardware enhancement for the Lamobo R1 router board. The Testbox board is used in the CI-RT project to manage devices under test (https://ci-rt.linutronix.de).
Add support for the LX TestBox.
Benedikt Spranger (4): sunxi: pmic_bus: Refactor pmic_bus_read() and pmic_bus_write() i2c: mvtwsi: Add Allwinner sun4i compatible sunxi: pmic_bus: Add DM I2C support common: Add LX TestBox checks
arch/arm/mach-sunxi/Kconfig | 15 +++++++++++ arch/arm/mach-sunxi/pmic_bus.c | 48 +++++++++++++++++++++++++--------- board/sunxi/board.c | 47 +++++++++++++++++++++++++++++++++ configs/Lamobo_R1_defconfig | 1 + drivers/i2c/mvtwsi.c | 1 + 5 files changed, 100 insertions(+), 12 deletions(-)

Unify I2C calls to ease the driver model conversion.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de --- arch/arm/mach-sunxi/pmic_bus.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c index dea42de833..091c59331b 100644 --- a/arch/arm/mach-sunxi/pmic_bus.c +++ b/arch/arm/mach-sunxi/pmic_bus.c @@ -26,6 +26,14 @@ #define AXP223_DEVICE_ADDR 0x3a3 #define AXP223_RUNTIME_ADDR 0x2d
+#ifdef CONFIG_AXP152_POWER +#define PMIC_I2C_ADDR AXP152_I2C_ADDR +#elif defined CONFIG_AXP209_POWER +#define PMIC_I2C_ADDR AXP209_I2C_ADDR +#else +#undef PMIC_I2C_ADDR +#endif + int pmic_bus_init(void) { /* This cannot be 0 because it is used in SPL before BSS is ready */ @@ -60,35 +68,31 @@ int pmic_bus_init(void)
int pmic_bus_read(u8 reg, u8 *data) { -#ifdef CONFIG_AXP152_POWER - return i2c_read(AXP152_I2C_ADDR, reg, 1, data, 1); -#elif defined CONFIG_AXP209_POWER - return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1); +#ifdef PMIC_I2C_ADDR + return i2c_read(PMIC_I2C_ADDR, reg, 1, data, 1); #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_read(reg, data); -# elif defined CONFIG_MACH_SUN8I_R40 - return i2c_read(AXP209_I2C_ADDR, reg, 1, data, 1); # else return rsb_read(AXP223_RUNTIME_ADDR, reg, data); # endif +#else +#error "unknown PMIC" #endif }
int pmic_bus_write(u8 reg, u8 data) { -#ifdef CONFIG_AXP152_POWER - return i2c_write(AXP152_I2C_ADDR, reg, 1, &data, 1); -#elif defined CONFIG_AXP209_POWER - return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1); +#ifdef PMIC_I2C_ADDR + return i2c_write(PMIC_I2C_ADDR, reg, 1, &data, 1); #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_write(reg, data); -# elif defined CONFIG_MACH_SUN8I_R40 - return i2c_write(AXP209_I2C_ADDR, reg, 1, &data, 1); # else return rsb_write(AXP223_RUNTIME_ADDR, reg, data); # endif +#else +#error "unknown PMIC" #endif }

Add the compatible string for the Allwinner A10 i2c controller.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de --- drivers/i2c/mvtwsi.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c index d3cc9b9d83..57cd442eee 100644 --- a/drivers/i2c/mvtwsi.c +++ b/drivers/i2c/mvtwsi.c @@ -878,6 +878,7 @@ static const struct udevice_id mvtwsi_i2c_ids[] = { { .compatible = "marvell,mv64xxx-i2c", }, { .compatible = "marvell,mv78230-i2c", }, { .compatible = "allwinner,sun6i-a31-i2c", }, + { .compatible = "allwinner,sun4i-a10-i2c", }, { /* sentinel */ } };

Add support for U-Boot DM.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de --- arch/arm/mach-sunxi/pmic_bus.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
diff --git a/arch/arm/mach-sunxi/pmic_bus.c b/arch/arm/mach-sunxi/pmic_bus.c index 091c59331b..8ecd037528 100644 --- a/arch/arm/mach-sunxi/pmic_bus.c +++ b/arch/arm/mach-sunxi/pmic_bus.c @@ -34,6 +34,8 @@ #undef PMIC_I2C_ADDR #endif
+struct udevice *pmic_dev __section(.data) = NULL; + int pmic_bus_init(void) { /* This cannot be 0 because it is used in SPL before BSS is ready */ @@ -43,6 +45,16 @@ int pmic_bus_init(void) if (!needs_init) return 0;
+#if defined PMIC_I2C_ADDR && defined CONFIG_DM_I2C + struct udevice *dev = NULL; + int rc; + + rc = i2c_get_chip_for_busnum(0, PMIC_I2C_ADDR, 1, &dev); + if (rc) + return rc; + pmic_dev = dev; +#endif + #if defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I p2wi_init(); @@ -69,7 +81,11 @@ int pmic_bus_init(void) int pmic_bus_read(u8 reg, u8 *data) { #ifdef PMIC_I2C_ADDR +#ifndef CONFIG_DM_I2C return i2c_read(PMIC_I2C_ADDR, reg, 1, data, 1); +#else + return dm_i2c_read(pmic_dev, reg, data, 1); +#endif #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_read(reg, data); @@ -84,7 +100,11 @@ int pmic_bus_read(u8 reg, u8 *data) int pmic_bus_write(u8 reg, u8 data) { #ifdef PMIC_I2C_ADDR +#ifndef CONFIG_DM_I2C return i2c_write(PMIC_I2C_ADDR, reg, 1, &data, 1); +#else + return dm_i2c_read(pmic_dev, reg, &data, 1); +#endif #elif defined CONFIG_AXP221_POWER || defined CONFIG_AXP809_POWER || defined CONFIG_AXP818_POWER # ifdef CONFIG_MACH_SUN6I return p2wi_write(reg, data);

The TestBox board is an open hardware enhancement for the Lamobo R1 router board. The Testbox board is used in the CI-RT project to manage devices under test (https://ci-rt.linutronix.de).
The hardware project is located at https://github.com/ci-rt/testbox-shield Check if the hardware is present and use the appropriate device tree file.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de --- arch/arm/mach-sunxi/Kconfig | 15 ++++++++++++ board/sunxi/board.c | 47 +++++++++++++++++++++++++++++++++++++ configs/Lamobo_R1_defconfig | 1 + 3 files changed, 63 insertions(+)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be0822bfb7..970fa0fae2 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -1010,4 +1010,19 @@ config PINE64_DT_SELECTION option, the device tree selection code specific to Pine64 which utilizes the DRAM size will be enabled.
+config LXTESTBOX + bool "Support for LX TestBox" + depends on MACH_SUN7I + select I2C2_ENABLE + select DM_I2C + help + The LX TestBox board is an open hardware enhancement for the + Lamobo R1 router board. The TestBox board is used in the CI-RT + project to manage devices under test (https://ci-rt.linutronix.de). + +config LXTESTBOX_DEVICE_TREE + string "LX TestBox default device tree" + default "sun7i-a20-linutronix-testbox-v2.dtb" + help + LX TestBox default device tree name. endif diff --git a/board/sunxi/board.c b/board/sunxi/board.c index f32e8f582f..4645798bcd 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -43,6 +43,17 @@ #include <spl.h> #include <sy8106a.h> #include <asm/setup.h> +#include <dm/uclass.h> +#include <i2c.h> + +struct lxtestbox_eeprom { + u32 magic; + u8 version; + char serial[7]; + u32 crc; +} __packed; + +#define LXTESTBOX_I2C_EEPROM_MAGIC 0x6274584c
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ @@ -839,6 +850,42 @@ static void setup_environment(const void *fdt) env_set("serial#", serial_string); } } + +#ifdef CONFIG_LXTESTBOX + debug("Check for LX TestBox..."); + if (!strcmp(env_get("fdtfile"), CONFIG_DEFAULT_DEVICE_TREE ".dtb")) { + struct lxtestbox_eeprom moep; + struct udevice *bus, *dev; + int ret; + + ret = uclass_get_device_by_name(UCLASS_I2C, + "i2c@1c2b400", &bus); + if (ret) { + printf("Cannot get I2C bus: %i\n", ret); + return; + } + + ret = i2c_get_chip(bus, 0x50, 1, &dev); + if (ret) { + printf("Cannot get I2C chip: %i\n", ret); + return; + } + + ret = dm_i2c_read(dev, 0, (u8 *)&moep, sizeof(moep)); + if (ret) { + printf("cannot read EEPROM: %i\n", ret); + return; + } + + if (moep.magic != LXTESTBOX_I2C_EEPROM_MAGIC) { + printf("bad EEPROM magic number (%08x, should be %08x)\n", + moep.magic, LXTESTBOX_I2C_EEPROM_MAGIC); + return; + } + debug("found.\n"); + env_set("fdtfile", CONFIG_LXTESTBOX_DEVICE_TREE); + } +#endif }
int misc_init_r(void) diff --git a/configs/Lamobo_R1_defconfig b/configs/Lamobo_R1_defconfig index 34db56f79b..d74032e1e5 100644 --- a/configs/Lamobo_R1_defconfig +++ b/configs/Lamobo_R1_defconfig @@ -7,6 +7,7 @@ CONFIG_MACPWR="PH23" CONFIG_MMC0_CD_PIN="PH10" CONFIG_SATAPWR="PB3" CONFIG_GMAC_TX_DELAY=4 +CONFIG_LXTESTBOX=y CONFIG_AHCI=y # CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set CONFIG_SPL_I2C_SUPPORT=y

On Fri, May 29, 2020 at 11:08 PM Benedikt Spranger b.spranger@linutronix.de wrote:
The TestBox board is an open hardware enhancement for the Lamobo R1 router board. The Testbox board is used in the CI-RT project to manage devices under test (https://ci-rt.linutronix.de).
The hardware project is located at https://github.com/ci-rt/testbox-shield Check if the hardware is present and use the appropriate device tree file.
Signed-off-by: Benedikt Spranger b.spranger@linutronix.de Reviewed-by: Kurt Kanzenbach kurt@linutronix.de
arch/arm/mach-sunxi/Kconfig | 15 ++++++++++++ board/sunxi/board.c | 47 +++++++++++++++++++++++++++++++++++++ configs/Lamobo_R1_defconfig | 1 + 3 files changed, 63 insertions(+)
diff --git a/arch/arm/mach-sunxi/Kconfig b/arch/arm/mach-sunxi/Kconfig index be0822bfb7..970fa0fae2 100644 --- a/arch/arm/mach-sunxi/Kconfig +++ b/arch/arm/mach-sunxi/Kconfig @@ -1010,4 +1010,19 @@ config PINE64_DT_SELECTION option, the device tree selection code specific to Pine64 which utilizes the DRAM size will be enabled.
+config LXTESTBOX
bool "Support for LX TestBox"
depends on MACH_SUN7I
select I2C2_ENABLE
select DM_I2C
help
The LX TestBox board is an open hardware enhancement for the
Lamobo R1 router board. The TestBox board is used in the CI-RT
project to manage devices under test (https://ci-rt.linutronix.de).
+config LXTESTBOX_DEVICE_TREE
string "LX TestBox default device tree"
default "sun7i-a20-linutronix-testbox-v2.dtb"
help
LX TestBox default device tree name.
endif diff --git a/board/sunxi/board.c b/board/sunxi/board.c index f32e8f582f..4645798bcd 100644 --- a/board/sunxi/board.c +++ b/board/sunxi/board.c @@ -43,6 +43,17 @@ #include <spl.h> #include <sy8106a.h> #include <asm/setup.h> +#include <dm/uclass.h> +#include <i2c.h>
+struct lxtestbox_eeprom {
u32 magic;
u8 version;
char serial[7];
u32 crc;
+} __packed;
+#define LXTESTBOX_I2C_EEPROM_MAGIC 0x6274584c
#if defined CONFIG_VIDEO_LCD_PANEL_I2C && !(defined CONFIG_SPL_BUILD) /* So that we can use pin names in Kconfig and sunxi_name_to_gpio() */ @@ -839,6 +850,42 @@ static void setup_environment(const void *fdt) env_set("serial#", serial_string); } }
+#ifdef CONFIG_LXTESTBOX
debug("Check for LX TestBox...");
if (!strcmp(env_get("fdtfile"), CONFIG_DEFAULT_DEVICE_TREE ".dtb")) {
struct lxtestbox_eeprom moep;
struct udevice *bus, *dev;
int ret;
ret = uclass_get_device_by_name(UCLASS_I2C,
"i2c@1c2b400", &bus);
if (ret) {
printf("Cannot get I2C bus: %i\n", ret);
return;
}
ret = i2c_get_chip(bus, 0x50, 1, &dev);
if (ret) {
printf("Cannot get I2C chip: %i\n", ret);
return;
}
ret = dm_i2c_read(dev, 0, (u8 *)&moep, sizeof(moep));
if (ret) {
printf("cannot read EEPROM: %i\n", ret);
return;
}
if (moep.magic != LXTESTBOX_I2C_EEPROM_MAGIC) {
printf("bad EEPROM magic number (%08x, should be %08x)\n",
moep.magic, LXTESTBOX_I2C_EEPROM_MAGIC);
return;
}
debug("found.\n");
env_set("fdtfile", CONFIG_LXTESTBOX_DEVICE_TREE);
}
We have a board driver to do board-specific functionalities, try to add that and get the board during _r instead of adding ifdef code in the common board.
participants (2)
-
Benedikt Spranger
-
Jagan Teki