Skip to contentSkip to conversation

Add support for extension boards detection and DT overlays application

PATCH Superseded Kory Maincent 3 participants 21 messages Feb 18, 2021 – Feb 23, 2021

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Add support for extension boards detection and DT overlays application

This series of patches aims at proposing a generic U-Boot mechanism to detect extension boards connected to the HW platform, and apply the appropriate Device Tree overlays depending on the detected extension boards.

Indeed, numerous popular platforms, such as the BeagleBone or the RaspberryPi, feature some kind of extension board mechanism. These extension boards are often discoverable through some kind of EEPROM (connected on I2C, 1-wire, etc.) and require Device Tree overlays to be applied at the U-Boot level to provide a complete HW description to the Linux kernel. However, currently this logic is usually implemented ad-hoc in downstream forks of U-Boot.

This series proposes to bring a HW-agnostic and generic solution to this problem to upstream U-Boot. The series shows that it is generic enough by implementing its usage for 2 different families of HW platforms and expansion boards:

- The BeagleBone Black and BeagleBone AI, that use extension boards where the EEPROM describing the extension boards is connected over I2C.

- The CHIP, that uses extension boards where the EEPROM describing the extension boards is connected over 1-wire.

The patch series implements a new command called "extension", with two sub-commands:

- "extension scan" to detect available extension boards

- "extension list" will simply list the detected extension boards

- "extension apply" will allow to apply the Device Tree overlays corresponding to one extension board or to all expansion boards

Note that the name "extension" has been chosen to not refer to any particular board-specific terminology for extension boards ("cape" for BeagleBone, "DIP" for CHIP, "hat" for RaspberryPi, etc.). However, we welcome suggestions of other names and are definitely willing to use a different naming.

The "extension apply" command requires two environment variables to be defined so that it knows how to apply DT overlays. This is described in more details in PATCH 1.

This generic code requires board-specific code for the detection and enumeration of extension boards. This is simply implemented in the form of a board-specific extension_board_scan() function, which fills in a list of detected extension boards.

In detail:

- PATCH 1 move fdt_valid function to fdt_support file
- PATCH 2 implements the generic command and logic
- PATCH 3 implements the python test for the "extension" command
- PATCH 4 implements the board-specific code for the BeagleBone platforms
- PATCH 5 enables the mechanism for the BeagleBone AI
- PATCH 6 to 8 enable the mechanism for the CHIP
- PATCH 9 and 10 enable the mechanism for the BeagleBone Black

Thanks in advance for your review and feedback

Kory Maincent (10):
fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c
cmd: add support for a new "extension" command
pytest: add sandbox test for "extension" command ti/common: add support for extension_scan_board function
am57xx: add support for cape detect functionality
arm: dts: sun5i: enable one-wire on the CHIP
arm: mach-sunxi: add CHIP board target
sun5i: add support for DIP detection to CHIP board
arm: am335x: add support for i2c2 bus
am335x: add support for cape detect functionality

 arch/Kconfig                              |   2 +
 arch/arm/dts/sun5i-r8-chip.dts            |   6 +
 arch/arm/mach-omap2/am33xx/Kconfig        |   1 +
 arch/arm/mach-omap2/am33xx/clock_am33xx.c |   1 +
 arch/arm/mach-omap2/omap5/Kconfig         |   1 +
 arch/arm/mach-sunxi/Kconfig               |  16 +++
 arch/sandbox/dts/Makefile                 |   1 +
 arch/sandbox/dts/overlay0.dts             |   9 ++
 arch/sandbox/dts/overlay1.dts             |   9 ++
 board/sandbox/sandbox.c                   |  23 +++
 board/sunxi/Makefile                      |   1 +
 board/sunxi/chip.c                        | 104 ++++++++++++++
 board/ti/am335x/board.c                   |   3 +
 board/ti/am335x/board.h                   |   1 +
 board/ti/am335x/mux.c                     |  15 ++
 board/ti/am57xx/board.c                   |   1 +
 board/ti/common/Kconfig                   |   3 +
 board/ti/common/Makefile                  |   1 +
 board/ti/common/cape_detect.c             |  96 +++++++++++++
 board/ti/common/cape_detect.h             |  28 ++++
 cmd/Kconfig                               |  12 ++
 cmd/Makefile                              |   1 +
 cmd/extension_board.c                     | 167 ++++++++++++++++++++++
 cmd/fdt.c                                 |  49 -------
 common/fdt_support.c                      |  46 ++++++
 configs/CHIP_defconfig                    |   1 +
 doc/README.extension                      |  80 +++++++++++
 include/configs/am335x_evm.h              |   2 +
 include/configs/am57xx_evm.h              |   2 +
 include/extension_board.h                 |  31 ++++
 include/fdt_support.h                     |   2 +
 test/py/tests/test_extension.py           |  52 +++++++
 32 files changed, 718 insertions(+), 49 deletions(-)
 create mode 100644 arch/sandbox/dts/overlay0.dts
 create mode 100644 arch/sandbox/dts/overlay1.dts
 create mode 100644 board/sunxi/chip.c
 create mode 100644 board/ti/common/cape_detect.c
 create mode 100644 board/ti/common/cape_detect.h
 create mode 100644 cmd/extension_board.c
 create mode 100644 doc/README.extension
 create mode 100644 include/extension_board.h
 create mode 100644 test/py/tests/test_extension.py
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/10 fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c

Move the fdt_valid function to fdt_support.
This changes allow to be able to test the validity of a devicetree in other c files.

Update code syntax.

---
 cmd/fdt.c             | 49 -------------------------------------------
 common/fdt_support.c  | 46 ++++++++++++++++++++++++++++++++++++++++
 include/fdt_support.h |  2 ++
 3 files changed, 48 insertions(+), 49 deletions(-)
cmd/fdt.c +0 -49
index 89ab572d8d..f1e2fc2fd8 100644
@@ -27,7 +27,6 @@
  */
 DECLARE_GLOBAL_DATA_PTR;
 
-static int fdt_valid(struct fdt_header **blobp);
 static int fdt_parse_prop(char *const*newval, int count, char *data, int *len);
 static int fdt_print(const char *pathp, char *prop, int depth);
 static int is_printable_string(const void *data, int len);
@@ -732,54 +731,6 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 /****************************************************************************/
 
-/**
- * fdt_valid() - Check if an FDT is valid. If not, change it to NULL
- *
- * @blobp: Pointer to FDT pointer
- * @return 1 if OK, 0 if bad (in which case *blobp is set to NULL)
- */
-static int fdt_valid(struct fdt_header **blobp)
-{
-	const void *blob = *blobp;
-	int err;
-
-	if (blob == NULL) {
-		printf ("The address of the fdt is invalid (NULL).\n");
-		return 0;
-	}
-
-	err = fdt_check_header(blob);
-	if (err == 0)
-		return 1;	/* valid */
-
-	if (err < 0) {
-		printf("libfdt fdt_check_header(): %s", fdt_strerror(err));
-		/*
-		 * Be more informative on bad version.
-		 */
-		if (err == -FDT_ERR_BADVERSION) {
-			if (fdt_version(blob) <
-			    FDT_FIRST_SUPPORTED_VERSION) {
-				printf (" - too old, fdt %d < %d",
-					fdt_version(blob),
-					FDT_FIRST_SUPPORTED_VERSION);
-			}
-			if (fdt_last_comp_version(blob) >
-			    FDT_LAST_SUPPORTED_VERSION) {
-				printf (" - too new, fdt %d > %d",
-					fdt_version(blob),
-					FDT_LAST_SUPPORTED_VERSION);
-			}
-		}
-		printf("\n");
-		*blobp = NULL;
-		return 0;
-	}
-	return 1;
-}
-
-/****************************************************************************/
-
 /*
  * Parse the user's input, partially heuristic.  Valid formats:
  * <0x00112233 4 05>	- an array of cells.  Numbers follow standard
common/fdt_support.c +46 -0

49 lines not on this page · raw message

include/fdt_support.h +2 -0
index dbbac0fb6a..fab8df0bcb 100644
@@ -328,6 +328,8 @@ int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width,
 
 int fdt_overlay_apply_verbose(void *fdt, void *fdto);
 
+int fdt_valid(struct fdt_header **blobp);
+
 /**
  * fdt_get_cells_len() - Get the length of a type of cell in top-level nodes
  *
Signature · 1 line
2.17.1
#2 lore raw

PATCH 1/10 fdt_support: move fdt_valid from cmd_fdt.c to fdt_support.c

Quoted 7 lines · Kory Maincent

Move the fdt_valid function to fdt_support.
This changes allow to be able to test the validity of a devicetree in other c files.

Update code syntax.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/583bbb62/attachment.sig>
#3 lore raw

PATCH 2/10 cmd: add support for a new "extension" command

In reply to Kory Maincent

This patch adds a new "extension" command, which aims at detecting extension boards connected to the hardware platform, and apply the Device Tree overlays that describe the hardware present on those extension boards.

In order to enable this mechanism, board-specific code must implement the extension_board_scan() function that fills in a linked list of "struct extension", each describing one extension board. In addition, the board-specific code must select the SUPPORT_EXTENSION_SCAN Kconfig boolean.

Based on this:

- "extension scan" makes the generic code call the board-specific extension_board_scan() function to retrieve the list of detected extension boards.

- "extension list" allows to list the detected extension boards.

- "extension apply <number>|all" allows to apply the Device Tree overlay(s) corresponding to one, or all, extension boards

The latter requires two environment variables to exist:

- extension_overlay_addr: the RAM address where to load the Device Tree overlays

- extension_overlay_cmd: the U-Boot command to load one overlay. Indeed, the location and mechanism to load DT overlays is very setup specific.

When calling the command described in the extension_overlay_cmd variable, the variable extension_overlay_name will be defined. So a typical extension_overlay_cmd will look like this:

extension_overlay_cmd=load mmc 0:1 $extension_overlay_addr /boot/$extension_overlay_name

Here is an example on how to use it:
=> run loadfdt
=> fdt addr $fdtaddr
=> setenv extension_overlay_addr 0x1000
=> setenv extension_overlay_cmd 'load mmc 0:1 ${extension_overlay_addr} /boot/${extension_overlay_name}' => extension scan
Found 1 extension board(s).
=> extension apply 0
519 bytes read in 3 ms (168.9 KiB/s)

---
 cmd/Kconfig               |  12 +++
 cmd/Makefile              |   1 +
 cmd/extension_board.c     | 167 ++++++++++++++++++++++++++++++++++++++
 doc/README.extension      |  80 ++++++++++++++++++
 include/extension_board.h |  31 +++++++
 5 files changed, 291 insertions(+)
 create mode 100644 cmd/extension_board.c
 create mode 100644 doc/README.extension
 create mode 100644 include/extension_board.h
cmd/Kconfig +12 -0
index 1595de999b..90be5c260a 100644
@@ -314,6 +314,18 @@ config CMD_FDT
 	help
 	  Do FDT related setup before booting into the Operating System.
 
+config SUPPORT_EXTENSION_SCAN
+	bool
+
+config CMD_EXTENSION
+	bool "Extension board management command"
+	select CMD_FDT
+	depends on SUPPORT_EXTENSION_SCAN
+	help
+	  Enables the "extension" command, which allows to detect
+	  extension boards connected to the system, and apply
+	  corresponding Device Tree overlays.
+
 config CMD_GO
 	bool "go"
 	default y
cmd/Makefile +1 -0
index dd86675bf2..87da67d27d 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_CMD_DIAG) += diag.o
 endif
 obj-$(CONFIG_CMD_ADTIMG) += adtimg.o
 obj-$(CONFIG_CMD_ABOOTIMG) += abootimg.o
+obj-$(CONFIG_CMD_EXTENSION) += extension_board.o
 obj-$(CONFIG_CMD_ECHO) += echo.o
 obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o
 obj-$(CONFIG_CMD_EEPROM) += eeprom.o
cmd/extension_board.c new file +167 -0

167 lines not on this page · raw message

doc/README.extension new file +80 -0

80 lines not on this page · raw message

include/extension_board.h new file +31 -0
new file mode 100644
index 0000000000..c530a0ad8a
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2021
+ * K?ry Maincent, Bootlin, <[email protected]>
+ */
+
+#ifndef __EXTENSION_SUPPORT_H
+#define __EXTENSION_SUPPORT_H
+
+struct extension {
+	struct list_head list;
+	char name[32];
+	char owner[32];
+	char version[32];
+	char overlay[32];
+	char other[32];
+};
+
+/**
+ * extension_board_scan - Add system-specific function to scan extension board.
+ * @param extension_list	List of extension board information to update.
+ * @return the number of extension.
+ *
+ * This function is called if CONFIG_CMD_EXTENSION is defined.
+ * Needs to fill the list extension_list with elements.
+ * Each element need to be allocated to an extension structure.
+ *
+ */
+int extension_board_scan(struct list_head *extension_list);
+
+#endif /* __EXTENSION_SUPPORT_H */
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/10 cmd: add support for a new "extension" command

Quoted 10 lines · Kory Maincent

This patch adds a new "extension" command, which aims at detecting extension boards connected to the hardware platform, and apply the Device Tree overlays that describe the hardware present on those extension boards.

In order to enable this mechanism, board-specific code must implement the extension_board_scan() function that fills in a linked list of "struct extension", each describing one extension board. In addition, the board-specific code must select the SUPPORT_EXTENSION_SCAN Kconfig boolean.

[snip]

Quoted 1 line
 doc/README.extension      |  80 ++++++++++++++++++

This should be rST and under docs/ somewhere.

[snip]

cmd/extension_board.c line 26

Quoted 3 lines
cmd/extension_board.c new file +3 -0
+		puts(
+			"No FDT memory address configured. Please configure\n"
+			"the FDT address via \"fdt addr <address>\" command.\n");

This should be a printf() and line-formatted correctly so checkpatch.pl doesn't complain. Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/bc01f77d/attachment.sig>
#5 lore raw

PATCH 3/10 pytest: add sandbox test for "extension" command

In reply to Kory Maincent

This commit extends the sandbox to implement a dummy extension_board_scan() function and enables the extension command in the sandbox configuration. It then adds a test that checks the proper functionality of the extension command by applying two Device Tree overlays to the sandbox Device Tree.

---
 arch/Kconfig                    |  2 ++
 arch/sandbox/dts/Makefile       |  1 +
 arch/sandbox/dts/overlay0.dts   |  9 ++++++
 arch/sandbox/dts/overlay1.dts   |  9 ++++++
 board/sandbox/sandbox.c         | 23 +++++++++++++++
 test/py/tests/test_extension.py | 52 +++++++++++++++++++++++++++++++++
 6 files changed, 96 insertions(+)
 create mode 100644 arch/sandbox/dts/overlay0.dts
 create mode 100644 arch/sandbox/dts/overlay1.dts
 create mode 100644 test/py/tests/test_extension.py
arch/Kconfig +2 -0
index 3aa99e08fc..fbe969cce0 100644
@@ -109,6 +109,7 @@ config SANDBOX
 	select SPI
 	select SUPPORT_OF_CONTROL
 	select SYSRESET_CMD_POWEROFF
+	select SUPPORT_EXTENSION_SCAN
 	imply BITREVERSE
 	select BLOBLIST
 	imply CMD_DM
@@ -146,6 +147,7 @@ config SANDBOX
 	imply ACPI_PMC_SANDBOX
 	imply CMD_PMC
 	imply CMD_CLONE
+	imply CMD_EXTENSION
 
 config SH
 	bool "SuperH architecture"
arch/sandbox/dts/Makefile +1 -0
index d231dc2877..3e5dc67d53 100644
@@ -6,6 +6,7 @@ else
 dtb-$(CONFIG_SANDBOX) += sandbox.dtb
 endif
 dtb-$(CONFIG_UT_DM) += test.dtb
+dtb-$(CONFIG_CMD_EXTENSION) += overlay0.dtbo overlay1.dtbo
 
 targets += $(dtb-y)
 
arch/sandbox/dts/overlay0.dts new file +9 -0
new file mode 100644
index 0000000000..70c6cf77aa
@@ -0,0 +1,9 @@
+/dts-v1/;
+/plugin/;
+
+&{/buttons} {
+	btn3 {
+		gpios = <&gpio_a 5 0>;
+		label = "button3";
+	};
+};
arch/sandbox/dts/overlay1.dts new file +9 -0
new file mode 100644
index 0000000000..51621b3110
@@ -0,0 +1,9 @@
+/dts-v1/;
+/plugin/;
+
+&{/buttons} {
+	btn4 {
+		gpios = <&gpio_a 5 0>;
+		label = "button4";
+	};
+};
board/sandbox/sandbox.c +23 -0
index 18a605de02..6ba1a7177d 100644
@@ -13,6 +13,9 @@
 #include <os.h>
 #include <asm/test.h>
 #include <asm/u-boot-sandbox.h>
+#include <malloc.h>
+
+#include <extension_board.h>
 
 /*
  * Pointer to initial global data area
@@ -81,6 +84,26 @@ int ft_board_setup(void *fdt, struct bd_info *bd)
 	return fdt_add_mem_rsv(fdt, 0x00d02000, 0x4000);
 }
 
+#ifdef CONFIG_CMD_EXTENSION
+int extension_board_scan(struct list_head *extension_list)
+{
+	struct extension *extension;
+	int i;
+
+	for (i = 0; i < 2; i++) {
+		extension = calloc(1, sizeof(struct extension));
+		snprintf(extension->overlay, sizeof(extension->overlay), "overlay%d.dtbo", i);
+		snprintf(extension->name, sizeof(extension->name), "extension board %d", i);
+		snprintf(extension->owner, sizeof(extension->owner), "sandbox");
+		snprintf(extension->version, sizeof(extension->version), "1.1");
+		snprintf(extension->other, sizeof(extension->other), "Fictionnal extension board");
+		list_add_tail(&extension->list, extension_list);
+	}
+
+	return i;
+}
+#endif
+
 #ifdef CONFIG_BOARD_LATE_INIT
 int board_late_init(void)
 {
test/py/tests/test_extension.py new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.17.1
#6 lore raw

PATCH 4/10 ti/common: add support for extension_scan_board function

In reply to Kory Maincent

The BeagleBone platforms all use a common mechanism to discover and identify extension boards (called "capes"): each extension board has an I2C-connected EEPROM describing itself.

This patch implements a generic extension_scan_board() feature that can be used by all BeagleBone platforms to read those I2C EEPROMs and fill in the list of "extension" structures.

Following commits will enable this common logic on two BeagleBone platforms.

---
 board/ti/common/Kconfig       |  3 ++
 board/ti/common/Makefile      |  1 +
 board/ti/common/cape_detect.c | 96 +++++++++++++++++++++++++++++++++++
 board/ti/common/cape_detect.h | 28 ++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 board/ti/common/cape_detect.c
 create mode 100644 board/ti/common/cape_detect.h
board/ti/common/Kconfig +3 -0
index 9ead7ca038..2e5b852a65 100644
@@ -16,6 +16,9 @@ config EEPROM_CHIP_ADDRESS
 	default 0x50
 	depends on TI_I2C_BOARD_DETECT
 
+config CAPE_EEPROM_BUS_NUM
+	int
+
 config TI_COMMON_CMD_OPTIONS
 	bool "Enable cmd options on TI platforms"
 	imply CMD_ASKENV
board/ti/common/Makefile +1 -0
index cb97f226ae..3172d87b46 100644
@@ -2,3 +2,4 @@
 # Copyright (C) 2015-2016 Texas Instruments Incorporated - http://www.ti.com/
 
 obj-${CONFIG_TI_I2C_BOARD_DETECT} += board_detect.o
+obj-${CONFIG_CMD_EXTENSION} += cape_detect.o
board/ti/common/cape_detect.c new file +96 -0

96 lines not on this page · raw message

board/ti/common/cape_detect.h new file +28 -0
new file mode 100644
index 0000000000..b0d5c9f18b
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2021
+ * K?ry Maincent, Bootlin, <[email protected]>
+ */
+
+#ifndef __CAPE_DETECT_H
+#define __CAPE_DETECT_H
+
+struct am335x_cape_eeprom_id {
+	unsigned int header;
+	char eeprom_rev[2];
+	char board_name[32];
+	char version[4];
+	char manufacturer[16];
+	char part_number[16];
+};
+
+#define CAPE_EEPROM_FIRST_ADDR	0x54
+#define CAPE_EEPROM_LAST_ADDR	0x57
+
+#define CAPE_EEPROM_ADDR_LEN 0x10
+
+#define CAPE_MAGIC 0xEE3355AA
+
+int extension_board_scan(struct list_head *extension_list);
+
+#endif /* __CAPE_DETECT_H */
Signature · 1 line
2.17.1
#7 lore raw

PATCH 5/10 am57xx: add support for cape detect functionality

In reply to Kory Maincent

This commit enables using the extension board detection mechanism on AM57xx based platforms.

---
 arch/arm/mach-omap2/omap5/Kconfig | 1 +
 board/ti/am57xx/board.c           | 1 +
 include/configs/am57xx_evm.h      | 2 ++
 3 files changed, 4 insertions(+)
arch/arm/mach-omap2/omap5/Kconfig +1 -0
index a7132dae09..4c2f990b28 100644
@@ -36,6 +36,7 @@ config TARGET_AM57XX_EVM
 	select CMD_DDR3
 	select DRA7XX
 	select TI_I2C_BOARD_DETECT
+	select SUPPORT_EXTENSION_SCAN
 	imply DM_THERMAL
 	imply SCSI
 	imply SPL_THERMAL
board/ti/am57xx/board.c +1 -0
index 7809875510..a2df4def78 100644
@@ -42,6 +42,7 @@
 #include <hang.h>
 
 #include "../common/board_detect.h"
+#include "../common/cape_detect.h"
 #include "mux_data.h"
 
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
include/configs/am57xx_evm.h +2 -0
index c47ffccff1..0413d171c4 100644
@@ -26,6 +26,8 @@
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
 
+#define CONFIG_CAPE_EEPROM_BUS_NUM	3
+
 #define CONFIG_SYS_OMAP_ABE_SYSCK
 
 #ifndef CONFIG_SPL_BUILD
Signature · 1 line
2.17.1
#8 lore raw

PATCH 6/10 arm: dts: sun5i: enable one-wire on the CHIP

In reply to Kory Maincent

Add the EEPROM description in the devicetree for the CHIP board.

---
 arch/arm/dts/sun5i-r8-chip.dts | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/dts/sun5i-r8-chip.dts +6 -0
index 879a4b0f3b..d915eb3eb7 100644
@@ -89,6 +89,12 @@
 		gpios = <&pio 3 2 GPIO_ACTIVE_HIGH>; /* PD2 */
 		pinctrl-names = "default";
 		pinctrl-0 = <&chip_w1_pin>;
+
+		w1_eeprom: w1_eeprom at 0 {
+			compatible = "maxim,ds2431";
+			status = "okay";
+		};
+
 	};
 };
 
Signature · 1 line
2.17.1
#9 lore raw

PATCH 6/10 arm: dts: sun5i: enable one-wire on the CHIP

Quoted 13 lines · Kory Maincent

Add the EEPROM description in the devicetree for the CHIP board.

---
 arch/arm/dts/sun5i-r8-chip.dts | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/dts/sun5i-r8-chip.dts +0 -0
index 879a4b0f3b..d915eb3eb7 100644
@@ -89,6 +89,12 @@
 		gpios = <&pio 3 2 GPIO_ACTIVE_HIGH>; /* PD2 */

arch/arm/dts/sun5i-r8-chip.dts line 99

Quoted 10 lines
arch/arm/dts/sun5i-r8-chip.dts +6 -0
 		pinctrl-names = "default";
 		pinctrl-0 = <&chip_w1_pin>;
+
+		w1_eeprom: w1_eeprom at 0 {
+			compatible = "maxim,ds2431";
+			status = "okay";
+		};
+
 	};
 };

This should be in, or re-synced from, the Linux dts file.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/462a1c43/attachment.sig>
#10 lore raw

PATCH 7/10 arm: mach-sunxi: add CHIP board target

In reply to Kory Maincent

The CHIP board use one-wire EEPROM to discover and identify extension boards (called "DIPs").

This commit add the configuration for the CHIP board target to enable the EEPROM one-wire driver.

---

Need the following patches series to fix a one-wire gpio issue.
https://lists.denx.de/pipermail/u-boot/2021-February/440073.html

 arch/arm/mach-sunxi/Kconfig | 14 ++++++++++++++
 configs/CHIP_defconfig      |  1 +
 2 files changed, 15 insertions(+)
arch/arm/mach-sunxi/Kconfig +14 -0
index 49ef217f08..37a4294d88 100644
@@ -1,5 +1,19 @@
 if ARCH_SUNXI
 
+choice
+	prompt "Sunxi board select"
+	optional
+
+config TARGET_CHIP
+	bool "CHIP board"
+	select W1
+	select W1_GPIO
+	select W1_EEPROM
+	select W1_EEPROM_DS24XXX
+
+endchoice
+
+
 config SPL_LDSCRIPT
 	default "arch/arm/cpu/armv7/sunxi/u-boot-spl.lds" if !ARM64
 
configs/CHIP_defconfig +1 -0
index a70ee31d40..6810797b19 100644
@@ -1,6 +1,7 @@
 CONFIG_ARM=y
 CONFIG_ARCH_SUNXI=y
 CONFIG_SPL=y
+CONFIG_TARGET_CHIP=y
 CONFIG_MACH_SUN5I=y
 CONFIG_DRAM_TIMINGS_DDR3_800E_1066G_1333J=y
 CONFIG_USB0_VBUS_PIN="PB10"
Signature · 1 line
2.17.1
#11 lore raw

PATCH 7/10 arm: mach-sunxi: add CHIP board target

Quoted 45 lines · Kory Maincent

The CHIP board use one-wire EEPROM to discover and identify extension boards (called "DIPs").

This commit add the configuration for the CHIP board target to enable the EEPROM one-wire driver.

---

Need the following patches series to fix a one-wire gpio issue.
https://lists.denx.de/pipermail/u-boot/2021-February/440073.html

 arch/arm/mach-sunxi/Kconfig | 14 ++++++++++++++
 configs/CHIP_defconfig      |  1 +
 2 files changed, 15 insertions(+)
arch/arm/mach-sunxi/Kconfig +14 -0
index 49ef217f08..37a4294d88 100644
@@ -1,5 +1,19 @@
 if ARCH_SUNXI
 
+choice
+	prompt "Sunxi board select"
+	optional
+
+config TARGET_CHIP
+	bool "CHIP board"
+	select W1
+	select W1_GPIO
+	select W1_EEPROM
+	select W1_EEPROM_DS24XXX
+
+endchoice
+
+
 config SPL_LDSCRIPT
 	default "arch/arm/cpu/armv7/sunxi/u-boot-spl.lds" if !ARM64
 
configs/CHIP_defconfig +0 -0
index a70ee31d40..6810797b19 100644

configs/CHIP_defconfig line 7

Quoted 7 lines
configs/CHIP_defconfig +1 -0
@@ -1,6 +1,7 @@
 CONFIG_ARM=y
 CONFIG_ARCH_SUNXI=y
 CONFIG_SPL=y
+CONFIG_TARGET_CHIP=y
 CONFIG_MACH_SUN5I=y
 CONFIG_DRAM_TIMINGS_DDR3_800E_1066G_1333J=y
 CONFIG_USB0_VBUS_PIN="PB10"

I think you should really just be adding options to the defconfig directly, sunxi has been avoiding adding TARGET_xxx options.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/ffa70b5f/attachment.sig>
#12 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

In reply to Kory Maincent

Add the extension_board_scan specific function to scan the information of the EEPROM on one-wire and fill the extension struct.

---
 arch/arm/mach-sunxi/Kconfig |   2 +
 board/sunxi/Makefile        |   1 +
 board/sunxi/chip.c          | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 board/sunxi/chip.c
arch/arm/mach-sunxi/Kconfig +2 -0
index 37a4294d88..3bb8a08b34 100644
@@ -6,10 +6,12 @@ choice
 
 config TARGET_CHIP
 	bool "CHIP board"
+	select SUPPORT_EXTENSION_SCAN
 	select W1
 	select W1_GPIO
 	select W1_EEPROM
 	select W1_EEPROM_DS24XXX
+	imply CMD_EXTENSION
 
 endchoice
 
board/sunxi/Makefile +1 -0
index c4e13f8c38..e6dcc9fca5 100644
@@ -11,3 +11,4 @@ obj-$(CONFIG_SUN7I_GMAC)	+= gmac.o
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
 obj-$(CONFIG_MACH_SUN7I)	+= dram_sun5i_auto.o
+obj-$(CONFIG_TARGET_CHIP)	+= chip.o
board/sunxi/chip.c new file +104 -0

104 lines not on this page · raw message

Signature · 1 line
2.17.1
#13 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

Quoted 16 lines · Kory Maincent

Add the extension_board_scan specific function to scan the information of the EEPROM on one-wire and fill the extension struct.

---
 arch/arm/mach-sunxi/Kconfig |   2 +
 board/sunxi/Makefile        |   1 +
 board/sunxi/chip.c          | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 board/sunxi/chip.c
arch/arm/mach-sunxi/Kconfig +0 -0
index 37a4294d88..3bb8a08b34 100644

arch/arm/mach-sunxi/Kconfig choice · line 14

Quoted 9 lines
arch/arm/mach-sunxi/Kconfig +2 -0
@@ -6,10 +6,12 @@ choice
 
 config TARGET_CHIP
 	bool "CHIP board"
+	select SUPPORT_EXTENSION_SCAN
 	select W1
 	select W1_GPIO
 	select W1_EEPROM
 	select W1_EEPROM_DS24XXX
+	imply CMD_EXTENSION

And then based on my comment in the previous patch, similar to PINEPHONE_DT_SELECTION and other board-specific options, add a CHIP_DIP_SCAN option or similar.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/85258fa5/attachment.sig>
#14 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

On Fri, 19 Feb 2021 11:54:54 -0500
Tom Rini <[email protected]> wrote:

Hi,

Quoted 19 lines · Kory Maincent
Quoted 18 lines

Add the extension_board_scan specific function to scan the information of the EEPROM on one-wire and fill the extension struct.

---
 arch/arm/mach-sunxi/Kconfig |   2 +
 board/sunxi/Makefile        |   1 +
 board/sunxi/chip.c          | 104 ++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 board/sunxi/chip.c
arch/arm/mach-sunxi/Kconfig +0 -0
index 37a4294d88..3bb8a08b34 100644
@@ -6,10 +6,12 @@ choice
 
Quoted 12 lines

arch/arm/mach-sunxi/Kconfig choice · line 14

Quoted 8 lines
arch/arm/mach-sunxi/Kconfig +2 -0
 config TARGET_CHIP
 	bool "CHIP board"
+	select SUPPORT_EXTENSION_SCAN
 	select W1
 	select W1_GPIO
 	select W1_EEPROM
 	select W1_EEPROM_DS24XXX
+	imply CMD_EXTENSION  

And then based on my comment in the previous patch, similar to PINEPHONE_DT_SELECTION and other board-specific options, add a CHIP_DIP_SCAN option or similar.

Yes, indeed, thanks Tom.

The idea of making this extension scheme generic is great, it's just that sunxi is using a different approach to board specific code here. Normally we expect U-Boot-proper board specific code to be DT driven, and where this does not really work, use those symbols that Tom pointed to.

Thanks,
Andre

#15 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

Hi Tom, Andre

Thanks for your reviews.

Quoted 5 lines · On Fri, 19 Feb 2021 17:29:26 +0000 Andre Przywara <[email protected]>…
Quoted 4 lines

And then based on my comment in the previous patch, similar to PINEPHONE_DT_SELECTION and other board-specific options, add a CHIP_DIP_SCAN option or similar.

Quoted 7 lines

Yes, indeed, thanks Tom.

The idea of making this extension scheme generic is great, it's just that sunxi is using a different approach to board specific code here. Normally we expect U-Boot-proper board specific code to be DT driven, and where this does not really work, use those symbols that Tom pointed to.

For my extension_board_scan board specific function, would you prefer if I move to callback like below instead of Kconfig?

if (of_machine_is_compatible("nextthing,chip"))

	extension_board_register_callback(chip_extension_board_scan);

Regards,
K?ry

#16 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

On Mon, 22 Feb 2021 15:23:08 +0100
K?ry Maincent <[email protected]> wrote:

Hi K?ry,

Quoted 18 lines

Thanks for your reviews.

Quoted 5 lines · On Fri, 19 Feb 2021 17:29:26 +0000 Andre Przywara <[email protected]>…
Quoted 4 lines

And then based on my comment in the previous patch, similar to PINEPHONE_DT_SELECTION and other board-specific options, add a CHIP_DIP_SCAN option or similar.

Quoted 7 lines

Yes, indeed, thanks Tom.

The idea of making this extension scheme generic is great, it's just that sunxi is using a different approach to board specific code here. Normally we expect U-Boot-proper board specific code to be DT driven, and where this does not really work, use those symbols that Tom pointed to.

Quoted 5 lines

For my extension_board_scan board specific function, would you prefer if I move to callback like below instead of Kconfig?

if (of_machine_is_compatible("nextthing,chip"))

	extension_board_register_callback(chip_extension_board_scan);

Well, the CHIP Pro uses a different compatible string, so you would need to check for that too.
I am not fully decided if checking for the machine compatible is the right approach. The more traditional U-Boot way would be to define a config symbol (as Tom already pointed out), that would also keep the code out of other board builds.
We do this already with CONFIG_PINE64_DT_SELECTION and CONFIG_PINEPHONE_DT_SELECTION.

Cheers,
Andre

#17 lore raw

PATCH 8/10 sun5i: add support for DIP detection to CHIP board

Hello Andre,

On Tue, 23 Feb 2021 13:30:38 +0000
Andre Przywara <[email protected]> wrote:
y extension_board_scan board specific function, would you prefer if I

Quoted 5 lines
Quoted 4 lines

move to callback like below instead of Kconfig?

if (of_machine_is_compatible("nextthing,chip"))

	extension_board_register_callback(chip_extension_board_scan);  
Quoted 8 lines

Well, the CHIP Pro uses a different compatible string, so you would need to check for that too.
I am not fully decided if checking for the machine compatible is the right approach. The more traditional U-Boot way would be to define a config symbol (as Tom already pointed out), that would also keep the code out of other board builds.
We do this already with CONFIG_PINE64_DT_SELECTION and CONFIG_PINEPHONE_DT_SELECTION.

Okay, I will move on to the traditional config symbol.

Thanks.

K?ry

#18 lore raw

PATCH 9/10 arm: am335x: add support for i2c2 bus

In reply to Kory Maincent

The am335x from BeagleBone use i2c EEPROM to detect capes. The memory is wired to i2c bus 2 therefore it need to be enabled.

Add i2c2 clock, pinmux description and pinmux enable function.

---
 arch/arm/mach-omap2/am33xx/clock_am33xx.c |  1 +
 board/ti/am335x/board.c                   |  2 ++
 board/ti/am335x/board.h                   |  1 +
 board/ti/am335x/mux.c                     | 15 +++++++++++++++
 4 files changed, 19 insertions(+)
arch/arm/mach-omap2/am33xx/clock_am33xx.c +1 -0
index 2427933c8b..7c67444024 100644
@@ -220,6 +220,7 @@ void enable_basic_clocks(void)
 		&cmper->gpio2clkctrl,
 		&cmper->gpio3clkctrl,
 		&cmper->i2c1clkctrl,
+		&cmper->i2c2clkctrl,
 		&cmper->cpgmac0clkctrl,
 		&cmper->spi0clkctrl,
 		&cmrtc->rtcclkctrl,
board/ti/am335x/board.c +2 -0
index 984cc5e3ba..56cdda856c 100644
@@ -76,8 +76,10 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
 void do_board_detect(void)
 {
 	enable_i2c0_pin_mux();
+	enable_i2c2_pin_mux();
 #ifndef CONFIG_DM_I2C
 	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
+	i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED2, CONFIG_SYS_OMAP24_I2C_SLAVE2);
 #endif
 	if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
 				 CONFIG_EEPROM_CHIP_ADDRESS))
board/ti/am335x/board.h +1 -0
index 48df914af9..c2962111c1 100644
@@ -93,5 +93,6 @@ void enable_uart3_pin_mux(void);
 void enable_uart4_pin_mux(void);
 void enable_uart5_pin_mux(void);
 void enable_i2c0_pin_mux(void);
+void enable_i2c2_pin_mux(void);
 void enable_board_pin_mux(void);
 #endif
board/ti/am335x/mux.c +15 -0
index 6fb2c009ba..78dc0cca42 100644
@@ -124,6 +124,14 @@ static struct module_pin_mux i2c1_pin_mux[] = {
 	{-1},
 };
 
+static struct module_pin_mux i2c2_pin_mux[] = {
+	{OFFSET(uart1_ctsn), (MODE(3) | RXACTIVE |
+			PULLUDEN | PULLUP_EN | SLEWCTRL)},	/* I2C_DATA */
+	{OFFSET(uart1_rtsn), (MODE(3) | RXACTIVE |
+			PULLUDEN | PULLUP_EN | SLEWCTRL)},	/* I2C_SCLK */
+	{-1},
+};
+
 static struct module_pin_mux spi0_pin_mux[] = {
 	{OFFSET(spi0_sclk), (MODE(0) | RXACTIVE | PULLUDEN)},	/* SPI0_SCLK */
 	{OFFSET(spi0_d0), (MODE(0) | RXACTIVE |
@@ -308,6 +316,11 @@ void enable_i2c0_pin_mux(void)
 	configure_module_pin_mux(i2c0_pin_mux);
 }
 
+void enable_i2c2_pin_mux(void)
+{
+	configure_module_pin_mux(i2c2_pin_mux);
+}
+
 /*
  * The AM335x GP EVM, if daughter card(s) are connected, can have 8
  * different profiles.  These profiles determine what peripherals are
@@ -367,6 +380,7 @@ void enable_board_pin_mux(void)
 #else
 		configure_module_pin_mux(mmc1_pin_mux);
 #endif
+		configure_module_pin_mux(i2c2_pin_mux);
 	} else if (board_is_gp_evm()) {
 		/* General Purpose EVM */
 		unsigned short profile = detect_daughter_board_profile();
@@ -411,6 +425,7 @@ void enable_board_pin_mux(void)
 #else
 		configure_module_pin_mux(mmc1_pin_mux);
 #endif
+		configure_module_pin_mux(i2c2_pin_mux);
 	} else if (board_is_pb()) {
 		configure_module_pin_mux(mii1_pin_mux);
 		configure_module_pin_mux(mmc0_pin_mux);
Signature · 1 line
2.17.1
#19 lore raw

PATCH 10/10 am335x: add support for cape detect functionality

In reply to Kory Maincent

Update the Kconfig and the board file to make the am335x board compatible with cape detection.

---
 arch/arm/mach-omap2/am33xx/Kconfig | 1 +
 board/ti/am335x/board.c            | 1 +
 include/configs/am335x_evm.h       | 2 ++
 3 files changed, 4 insertions(+)
arch/arm/mach-omap2/am33xx/Kconfig +1 -0
index 9a98e8a0a9..11e54cd293 100644
@@ -34,6 +34,7 @@ config TARGET_AM335X_EVM
 	select DM_GPIO
 	select DM_SERIAL
 	select TI_I2C_BOARD_DETECT
+	select SUPPORT_EXTENSION_SCAN
 	imply CMD_DM
 	imply SPL_DM
 	imply SPL_DM_SEQ_ALIAS
board/ti/am335x/board.c +1 -0
index 56cdda856c..eb5cbd3b30 100644
@@ -43,6 +43,7 @@
 #include <env_internal.h>
 #include <watchdog.h>
 #include "../common/board_detect.h"
+#include "../common/cape_detect.h"
 #include "board.h"
 
 DECLARE_GLOBAL_DATA_PTR;
include/configs/am335x_evm.h +2 -0
index 5af90d932d..65835e094d 100644
@@ -188,6 +188,8 @@
 #define CONFIG_SYS_I2C_EEPROM_ADDR	0x50	/* Main EEPROM */
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
 
+#define CONFIG_CAPE_EEPROM_BUS_NUM	2
+
 /* PMIC support */
 #define CONFIG_POWER_TPS65217
 #define CONFIG_POWER_TPS65910
Signature · 1 line
2.17.1
#20 lore raw

PATCH 10/10 am335x: add support for cape detect functionality

Quoted 9 lines · Kory Maincent

Update the Kconfig and the board file to make the am335x board compatible with cape detection.

---
 arch/arm/mach-omap2/am33xx/Kconfig | 1 +
 board/ti/am335x/board.c            | 1 +
 include/configs/am335x_evm.h       | 2 ++
 3 files changed, 4 insertions(+)

[snip]

Quoted 1 line

+#define CONFIG_CAPE_EEPROM_BUS_NUM 2

You can't add new CONFIG options like that outside of Kconfig.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210219/1923fea7/attachment.sig>