[PATCH u-boot-marvell 00/11] Some mvebu comphy + mox + fdt_support changes

From: Marek Behún marek.behun@nic.cz
Hello Stefan,
Pali prepared patches that convert A3720 comphy driver to use Linux' DT bindings. (Yes, I have patches that convert the whole driver into using SMC calls into ATF, but haven't found time yet to rebase them since last year, and Pali has done this in the meantime :-D Maybe I'll look into my old patches sometimes, but this is now usable.)
These patches needed some changes in Turris MOX board code, and I added some more changes to handling device-tree fixups, and this lead to adding some code into fdt_support, which can hopefully be used by other people as well.
Marek
Marek Behún (8): treewide: Use fdt_create_phandle() where appropriate fdt_support: Remove fdt_alloc_phandle() in favor of fdt_generate_phandle() fdt_support: Remove FDT_STATUS_FAIL_ERROR_CODE fdt_support: Fix comment for fdt_create_phandle() fdt_support: Add some useful functions arm: mvebu: turris_mox: Find DT nodes by compatible or alias instead of path arm: mvebu: turris_mox: Fix unstable board topology reading fdt_support: Add fdt_delete_disabled_nodes() and use in Turris MOX
Pali Rohár (3): include/linux/byteorder: Fix compilation of __constant_cpu_to_be32() arm: mvebu: turris_mox: Enable eth1 in U-Boot if a network module is present phy: marvell: a3700: Use official DT bindings in COMPHY driver
arch/arm/cpu/armv7/ls102xa/fdt.c | 6 +- arch/arm/dts/armada-3720-espressobin.dts | 21 +-- arch/arm/dts/armada-3720-turris-mox.dts | 25 +-- arch/arm/dts/armada-3720-uDPU.dts | 23 +-- arch/arm/dts/armada-37xx.dtsi | 20 +- board/CZ.NIC/turris_mox/turris_mox.c | 223 ++++++++--------------- board/Marvell/octeon_ebb7304/board.c | 5 +- board/freescale/lx2160a/eth_lx2160aqds.c | 8 +- board/freescale/lx2160a/eth_lx2162aqds.c | 8 +- board/gateworks/gw_ventana/common.c | 3 +- board/kontron/sl28/sl28.c | 2 +- common/fdt_support.c | 174 +++++++++++++++--- drivers/misc/fsl_portals.c | 10 +- drivers/pci/pcie_layerscape_fixup.c | 8 +- drivers/pci/pcie_layerscape_gen4_fixup.c | 8 +- drivers/phy/marvell/comphy_a3700.c | 133 ++++++++++++++ drivers/phy/marvell/comphy_core.c | 59 +----- drivers/phy/marvell/comphy_core.h | 23 +++ drivers/phy/marvell/comphy_cp110.c | 58 ++++++ include/fdt_support.h | 51 ++++-- include/linux/byteorder/swab.h | 4 + 21 files changed, 551 insertions(+), 321 deletions(-)

From: Pali Rohár pali@kernel.org
The macro __constant_cpu_to_be32() uses ___constant_swab32(), which for some reason is not defined and causes the following error during compilation:
include/linux/byteorder/little_endian.h:28:52: warning: implicit declaration of function ‘___constant_swab32’; did you mean ‘__builtin_bswap32’? [-Wimplicit-function-declaration] #define __constant_cpu_to_be32(x) ((__force __be32)___constant_swab32((x)))
Declare all ___constant_swabXX() macros.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz --- include/linux/byteorder/swab.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/include/linux/byteorder/swab.h b/include/linux/byteorder/swab.h index 4334fa77e3..5efc252acf 100644 --- a/include/linux/byteorder/swab.h +++ b/include/linux/byteorder/swab.h @@ -39,6 +39,10 @@ (__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ (__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) ))
+#define ___constant_swab16(x) ___swab16(x) +#define ___constant_swab32(x) ___swab32(x) +#define ___constant_swab64(x) ___swab64(x) + /* * provide defaults when no architecture-specific optimization is detected */

On 11/3/21 03:02, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The macro __constant_cpu_to_be32() uses ___constant_swab32(), which for some reason is not defined and causes the following error during compilation:
include/linux/byteorder/little_endian.h:28:52: warning: implicit declaration of function ‘___constant_swab32’; did you mean ‘__builtin_bswap32’? [-Wimplicit-function-declaration] #define __constant_cpu_to_be32(x) ((__force __be32)___constant_swab32((x)))
Declare all ___constant_swabXX() macros.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
include/linux/byteorder/swab.h | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/include/linux/byteorder/swab.h b/include/linux/byteorder/swab.h index 4334fa77e3..5efc252acf 100644 --- a/include/linux/byteorder/swab.h +++ b/include/linux/byteorder/swab.h @@ -39,6 +39,10 @@ (__u64)(((__u64)(x) & (__u64)0x00ff000000000000ULL) >> 40) | \ (__u64)(((__u64)(x) & (__u64)0xff00000000000000ULL) >> 56) ))
+#define ___constant_swab16(x) ___swab16(x) +#define ___constant_swab32(x) ___swab32(x) +#define ___constant_swab64(x) ___swab64(x)
- /*
*/
- provide defaults when no architecture-specific optimization is detected
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
Replace fdt_alloc_phandle() with subsequent fdt_set_phandle() by fdt_create_phandle().
Signed-off-by: Marek Behún marek.behun@nic.cz --- board/Marvell/octeon_ebb7304/board.c | 5 ++--- drivers/misc/fsl_portals.c | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/board/Marvell/octeon_ebb7304/board.c b/board/Marvell/octeon_ebb7304/board.c index e8e2d547c1..c6c7c13483 100644 --- a/board/Marvell/octeon_ebb7304/board.c +++ b/board/Marvell/octeon_ebb7304/board.c @@ -205,7 +205,7 @@ static int fdt_fix_mix(const void *fdt) int env_lmac = -1; int lmac_fdt_node = -1; int mix_fdt_node = -1; - int lmac_phandle; + unsigned int lmac_phandle; char *compat;
/* Get the lmac for this environment variable */ @@ -229,8 +229,7 @@ static int fdt_fix_mix(const void *fdt) } }
- lmac_phandle = fdt_alloc_phandle((void *)fdt); - fdt_set_phandle((void *)fdt, lmac_fdt_node, lmac_phandle); + lmac_phandle = fdt_create_phandle((void *)fdt, lmac_fdt_node);
/* Get the fdt mix node corresponding to this lmac */ mix_fdt_node = get_mix_fdt_node(fdt, env_node, env_lmac); diff --git a/drivers/misc/fsl_portals.c b/drivers/misc/fsl_portals.c index 632430e420..02bc3f86ca 100644 --- a/drivers/misc/fsl_portals.c +++ b/drivers/misc/fsl_portals.c @@ -106,7 +106,7 @@ static int fdt_qportal(void *blob, int off, int id, char *name, enum fsl_dpaa_dev dev, int create) { int childoff, dev_off, ret = 0; - u32 dev_handle; + unsigned int dev_handle; #ifdef CONFIG_FSL_CORENET int num; u32 liodns[2]; @@ -142,11 +142,9 @@ static int fdt_qportal(void *blob, int off, int id, char *name, if (childoff > 0) { dev_handle = fdt_get_phandle(blob, dev_off); if (dev_handle <= 0) { - dev_handle = fdt_alloc_phandle(blob); - ret = fdt_set_phandle(blob, dev_off, - dev_handle); - if (ret < 0) - return ret; + dev_handle = fdt_create_phandle(blob, dev_off); + if (!dev_handle) + return -FDT_ERR_NOPHANDLES; }
ret = fdt_setprop(blob, childoff, "dev-handle",

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Replace fdt_alloc_phandle() with subsequent fdt_set_phandle() by fdt_create_phandle().
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
board/Marvell/octeon_ebb7304/board.c | 5 ++--- drivers/misc/fsl_portals.c | 10 ++++------ 2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/board/Marvell/octeon_ebb7304/board.c b/board/Marvell/octeon_ebb7304/board.c index e8e2d547c1..c6c7c13483 100644 --- a/board/Marvell/octeon_ebb7304/board.c +++ b/board/Marvell/octeon_ebb7304/board.c @@ -205,7 +205,7 @@ static int fdt_fix_mix(const void *fdt) int env_lmac = -1; int lmac_fdt_node = -1; int mix_fdt_node = -1;
int lmac_phandle;
unsigned int lmac_phandle;
char *compat;
/* Get the lmac for this environment variable */
@@ -229,8 +229,7 @@ static int fdt_fix_mix(const void *fdt) } }
lmac_phandle = fdt_alloc_phandle((void *)fdt);
fdt_set_phandle((void *)fdt, lmac_fdt_node, lmac_phandle);
lmac_phandle = fdt_create_phandle((void *)fdt, lmac_fdt_node);
/* Get the fdt mix node corresponding to this lmac */ mix_fdt_node = get_mix_fdt_node(fdt, env_node, env_lmac);
diff --git a/drivers/misc/fsl_portals.c b/drivers/misc/fsl_portals.c index 632430e420..02bc3f86ca 100644 --- a/drivers/misc/fsl_portals.c +++ b/drivers/misc/fsl_portals.c @@ -106,7 +106,7 @@ static int fdt_qportal(void *blob, int off, int id, char *name, enum fsl_dpaa_dev dev, int create) { int childoff, dev_off, ret = 0;
- u32 dev_handle;
- unsigned int dev_handle; #ifdef CONFIG_FSL_CORENET int num; u32 liodns[2];
@@ -142,11 +142,9 @@ static int fdt_qportal(void *blob, int off, int id, char *name, if (childoff > 0) { dev_handle = fdt_get_phandle(blob, dev_off); if (dev_handle <= 0) {
dev_handle = fdt_alloc_phandle(blob);
ret = fdt_set_phandle(blob, dev_off,
dev_handle);
if (ret < 0)
return ret;
dev_handle = fdt_create_phandle(blob, dev_off);
if (!dev_handle)
return -FDT_ERR_NOPHANDLES; } ret = fdt_setprop(blob, childoff, "dev-handle",
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
Commit f0921f5098d ("fdt: Sync up to the latest libfdt") introduced fdt_generate_phandle() in libfdt, making fdt_alloc_phandle() obsolete in fdt_support.
Signed-off-by: Marek Behún marek.behun@nic.cz --- board/freescale/lx2160a/eth_lx2160aqds.c | 8 +++++-- board/freescale/lx2160a/eth_lx2162aqds.c | 8 +++++-- common/fdt_support.c | 28 +++++++----------------- include/fdt_support.h | 1 - 4 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/board/freescale/lx2160a/eth_lx2160aqds.c b/board/freescale/lx2160a/eth_lx2160aqds.c index a2b6442b54..1819b27561 100644 --- a/board/freescale/lx2160a/eth_lx2160aqds.c +++ b/board/freescale/lx2160a/eth_lx2160aqds.c @@ -775,10 +775,11 @@ int fdt_fixup_board_phy(void *fdt) int fpga_offset, offset, subnodeoffset; struct mii_dev *mii_dev; struct list_head *mii_devs, *entry; - int ret, dpmac_id, phandle, i; + int ret, dpmac_id, i; struct phy_device *phy_dev; char ethname[ETH_NAME_LEN]; phy_interface_t phy_iface; + uint32_t phandle;
ret = 0; /* we know FPGA is connected to i2c0, therefore search path directly, @@ -794,7 +795,10 @@ int fdt_fixup_board_phy(void *fdt) return fpga_offset; }
- phandle = fdt_alloc_phandle(fdt); + ret = fdt_generate_phandle(fdt, &phandle); + if (ret < 0) + return ret; + mii_devs = mdio_get_list_head();
list_for_each(entry, mii_devs) { diff --git a/board/freescale/lx2160a/eth_lx2162aqds.c b/board/freescale/lx2160a/eth_lx2162aqds.c index 3b04dea39c..ac6218ebe4 100644 --- a/board/freescale/lx2160a/eth_lx2162aqds.c +++ b/board/freescale/lx2160a/eth_lx2162aqds.c @@ -787,10 +787,11 @@ int fdt_fixup_board_phy(void *fdt) int fpga_offset, offset, subnodeoffset; struct mii_dev *mii_dev; struct list_head *mii_devs, *entry; - int ret, dpmac_id, phandle, i; + int ret, dpmac_id, i; struct phy_device *phy_dev; char ethname[ETH_NAME_LEN]; phy_interface_t phy_iface; + uint32_t phandle;
ret = 0; /* we know FPGA is connected to i2c0, therefore search path directly, @@ -806,7 +807,10 @@ int fdt_fixup_board_phy(void *fdt) return fpga_offset; }
- phandle = fdt_alloc_phandle(fdt); + ret = fdt_generate_phandle(fdt, &phandle); + if (ret < 0) + return ret; + mii_devs = mdio_get_list_head();
list_for_each(entry, mii_devs) { diff --git a/common/fdt_support.c b/common/fdt_support.c index 8992ac5d3f..be03a87d42 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1463,24 +1463,6 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, return -FDT_ERR_NOTFOUND; }
-/** - * fdt_alloc_phandle: Return next free phandle value - * - * @blob: ptr to device tree - */ -int fdt_alloc_phandle(void *blob) -{ - int offset; - uint32_t phandle = 0; - - for (offset = fdt_next_node(blob, -1, NULL); offset >= 0; - offset = fdt_next_node(blob, offset, NULL)) { - phandle = max(phandle, fdt_get_phandle(blob, offset)); - } - - return phandle + 1; -} - /* * fdt_set_phandle: Create a phandle property for the given node * @@ -1530,13 +1512,19 @@ int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle) unsigned int fdt_create_phandle(void *fdt, int nodeoffset) { /* see if there is a phandle already */ - int phandle = fdt_get_phandle(fdt, nodeoffset); + uint32_t phandle = fdt_get_phandle(fdt, nodeoffset);
/* if we got 0, means no phandle so create one */ if (phandle == 0) { int ret;
- phandle = fdt_alloc_phandle(fdt); + ret = fdt_generate_phandle(fdt, &phandle); + if (ret < 0) { + printf("Can't generate phandle: %s\n", + fdt_strerror(ret)); + return 0; + } + ret = fdt_set_phandle(fdt, nodeoffset, phandle); if (ret < 0) { printf("Can't set phandle %u: %s\n", phandle, diff --git a/include/fdt_support.h b/include/fdt_support.h index 88d129c803..90f5a4c28c 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -285,7 +285,6 @@ int fdt_get_dma_range(const void *blob, int node_offset, phys_addr_t *cpu,
int fdt_node_offset_by_compat_reg(void *blob, const char *compat, phys_addr_t compat_off); -int fdt_alloc_phandle(void *blob); int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); unsigned int fdt_create_phandle(void *fdt, int nodeoffset); int fdt_add_edid(void *blob, const char *compat, unsigned char *buf);

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Commit f0921f5098d ("fdt: Sync up to the latest libfdt") introduced fdt_generate_phandle() in libfdt, making fdt_alloc_phandle() obsolete in fdt_support.
Signed-off-by: Marek Behún marek.behun@nic.cz
board/freescale/lx2160a/eth_lx2160aqds.c | 8 +++++-- board/freescale/lx2160a/eth_lx2162aqds.c | 8 +++++-- common/fdt_support.c | 28 +++++++----------------- include/fdt_support.h | 1 - 4 files changed, 20 insertions(+), 25 deletions(-)
Could you please add the maintainers for the boards, if there are such changes in the board specific code? Otherwise such changes just "slip" by and might not be tested on these platforms.
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
diff --git a/board/freescale/lx2160a/eth_lx2160aqds.c b/board/freescale/lx2160a/eth_lx2160aqds.c index a2b6442b54..1819b27561 100644 --- a/board/freescale/lx2160a/eth_lx2160aqds.c +++ b/board/freescale/lx2160a/eth_lx2160aqds.c @@ -775,10 +775,11 @@ int fdt_fixup_board_phy(void *fdt) int fpga_offset, offset, subnodeoffset; struct mii_dev *mii_dev; struct list_head *mii_devs, *entry;
- int ret, dpmac_id, phandle, i;
int ret, dpmac_id, i; struct phy_device *phy_dev; char ethname[ETH_NAME_LEN]; phy_interface_t phy_iface;
uint32_t phandle;
ret = 0; /* we know FPGA is connected to i2c0, therefore search path directly,
@@ -794,7 +795,10 @@ int fdt_fixup_board_phy(void *fdt) return fpga_offset; }
- phandle = fdt_alloc_phandle(fdt);
ret = fdt_generate_phandle(fdt, &phandle);
if (ret < 0)
return ret;
mii_devs = mdio_get_list_head();
list_for_each(entry, mii_devs) {
diff --git a/board/freescale/lx2160a/eth_lx2162aqds.c b/board/freescale/lx2160a/eth_lx2162aqds.c index 3b04dea39c..ac6218ebe4 100644 --- a/board/freescale/lx2160a/eth_lx2162aqds.c +++ b/board/freescale/lx2160a/eth_lx2162aqds.c @@ -787,10 +787,11 @@ int fdt_fixup_board_phy(void *fdt) int fpga_offset, offset, subnodeoffset; struct mii_dev *mii_dev; struct list_head *mii_devs, *entry;
- int ret, dpmac_id, phandle, i;
int ret, dpmac_id, i; struct phy_device *phy_dev; char ethname[ETH_NAME_LEN]; phy_interface_t phy_iface;
uint32_t phandle;
ret = 0; /* we know FPGA is connected to i2c0, therefore search path directly,
@@ -806,7 +807,10 @@ int fdt_fixup_board_phy(void *fdt) return fpga_offset; }
- phandle = fdt_alloc_phandle(fdt);
ret = fdt_generate_phandle(fdt, &phandle);
if (ret < 0)
return ret;
mii_devs = mdio_get_list_head();
list_for_each(entry, mii_devs) {
diff --git a/common/fdt_support.c b/common/fdt_support.c index 8992ac5d3f..be03a87d42 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1463,24 +1463,6 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, return -FDT_ERR_NOTFOUND; }
-/**
- fdt_alloc_phandle: Return next free phandle value
- @blob: ptr to device tree
- */
-int fdt_alloc_phandle(void *blob) -{
- int offset;
- uint32_t phandle = 0;
- for (offset = fdt_next_node(blob, -1, NULL); offset >= 0;
offset = fdt_next_node(blob, offset, NULL)) {
phandle = max(phandle, fdt_get_phandle(blob, offset));
- }
- return phandle + 1;
-}
- /*
- fdt_set_phandle: Create a phandle property for the given node
@@ -1530,13 +1512,19 @@ int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle) unsigned int fdt_create_phandle(void *fdt, int nodeoffset) { /* see if there is a phandle already */
- int phandle = fdt_get_phandle(fdt, nodeoffset);
uint32_t phandle = fdt_get_phandle(fdt, nodeoffset);
/* if we got 0, means no phandle so create one */ if (phandle == 0) { int ret;
phandle = fdt_alloc_phandle(fdt);
ret = fdt_generate_phandle(fdt, &phandle);
if (ret < 0) {
printf("Can't generate phandle: %s\n",
fdt_strerror(ret));
return 0;
}
- ret = fdt_set_phandle(fdt, nodeoffset, phandle); if (ret < 0) { printf("Can't set phandle %u: %s\n", phandle,
diff --git a/include/fdt_support.h b/include/fdt_support.h index 88d129c803..90f5a4c28c 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -285,7 +285,6 @@ int fdt_get_dma_range(const void *blob, int node_offset, phys_addr_t *cpu,
int fdt_node_offset_by_compat_reg(void *blob, const char *compat, phys_addr_t compat_off); -int fdt_alloc_phandle(void *blob); int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); unsigned int fdt_create_phandle(void *fdt, int nodeoffset); int fdt_add_edid(void *blob, const char *compat, unsigned char *buf);
Viele Grüße, Stefan Roese

On Fri, 12 Nov 2021 13:42:29 +0100 Stefan Roese sr@denx.de wrote:
On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Commit f0921f5098d ("fdt: Sync up to the latest libfdt") introduced fdt_generate_phandle() in libfdt, making fdt_alloc_phandle() obsolete in fdt_support.
Signed-off-by: Marek Behún marek.behun@nic.cz
board/freescale/lx2160a/eth_lx2160aqds.c | 8 +++++-- board/freescale/lx2160a/eth_lx2162aqds.c | 8 +++++-- common/fdt_support.c | 28 +++++++----------------- include/fdt_support.h | 1 - 4 files changed, 20 insertions(+), 25 deletions(-)
Could you please add the maintainers for the boards, if there are such changes in the board specific code? Otherwise such changes just "slip" by and might not be tested on these platforms.
Reviewed-by: Stefan Roese sr@denx.de
OK. Should I resend this series? Or just send them reply to this patch?
Marek

From: Marek Behún marek.behun@nic.cz
Since no one uses this feature and I am not aware of any parsers of this in Linux, remove it.
Signed-off-by: Marek Behún marek.behun@nic.cz --- arch/arm/cpu/armv7/ls102xa/fdt.c | 6 +++--- board/gateworks/gw_ventana/common.c | 3 +-- board/kontron/sl28/sl28.c | 2 +- common/fdt_support.c | 20 +++++--------------- drivers/pci/pcie_layerscape_fixup.c | 8 ++++---- drivers/pci/pcie_layerscape_gen4_fixup.c | 8 ++++---- include/fdt_support.h | 18 ++++++++---------- 7 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/arch/arm/cpu/armv7/ls102xa/fdt.c b/arch/arm/cpu/armv7/ls102xa/fdt.c index 0daf8234fb..bf6cc6d4e7 100644 --- a/arch/arm/cpu/armv7/ls102xa/fdt.c +++ b/arch/arm/cpu/armv7/ls102xa/fdt.c @@ -184,13 +184,13 @@ void ft_cpu_setup(void *blob, struct bd_info *bd) #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI) off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT, CONFIG_SYS_IFC_ADDR); - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); #else off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT, QSPI0_BASE_ADDR); - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT, DSPI1_BASE_ADDR); - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); #endif } diff --git a/board/gateworks/gw_ventana/common.c b/board/gateworks/gw_ventana/common.c index 2be921f47a..7ec931c8a8 100644 --- a/board/gateworks/gw_ventana/common.c +++ b/board/gateworks/gw_ventana/common.c @@ -1681,8 +1681,7 @@ void ft_early_fixup(void *blob, int board_type) * disable serial2 node for GW54xx for compatibility with older * 3.10.x kernel that improperly had this node enabled in the DT */ - fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED, - 0); + fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED);
/* GW54xx-E adds WDOG2_B external reset */ if (rev < 'E') diff --git a/board/kontron/sl28/sl28.c b/board/kontron/sl28/sl28.c index c8ed7ac81a..e84b356918 100644 --- a/board/kontron/sl28/sl28.c +++ b/board/kontron/sl28/sl28.c @@ -75,7 +75,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (CONFIG_IS_ENABLED(SL28_SPL_LOADS_OPTEE_BL32)) { node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz"); if (node) - fdt_set_node_status(blob, node, FDT_STATUS_OKAY, 0); + fdt_set_node_status(blob, node, FDT_STATUS_OKAY); }
return 0; diff --git a/common/fdt_support.c b/common/fdt_support.c index be03a87d42..8ac905011c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1541,14 +1541,10 @@ unsigned int fdt_create_phandle(void *fdt, int nodeoffset) * * @fdt: ptr to device tree * @nodeoffset: node to update - * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, - * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE - * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL */ -int fdt_set_node_status(void *fdt, int nodeoffset, - enum fdt_status status, unsigned int error_code) +int fdt_set_node_status(void *fdt, int nodeoffset, enum fdt_status status) { - char buf[16]; int ret = 0;
if (nodeoffset < 0) @@ -1564,10 +1560,6 @@ int fdt_set_node_status(void *fdt, int nodeoffset, case FDT_STATUS_FAIL: ret = fdt_setprop_string(fdt, nodeoffset, "status", "fail"); break; - case FDT_STATUS_FAIL_ERROR_CODE: - sprintf(buf, "fail-%d", error_code); - ret = fdt_setprop_string(fdt, nodeoffset, "status", buf); - break; default: printf("Invalid fdt status: %x\n", status); ret = -1; @@ -1582,16 +1574,14 @@ int fdt_set_node_status(void *fdt, int nodeoffset, * * @fdt: ptr to device tree * @alias: alias of node to update - * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, - * FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE - * @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL */ int fdt_set_status_by_alias(void *fdt, const char* alias, - enum fdt_status status, unsigned int error_code) + enum fdt_status status) { int offset = fdt_path_offset(fdt, alias);
- return fdt_set_node_status(fdt, offset, status, error_code); + return fdt_set_node_status(fdt, offset, status); }
#if defined(CONFIG_VIDEO) || defined(CONFIG_LCD) diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index a58e7a3892..92105a7103 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -582,9 +582,9 @@ static void ft_pcie_rc_fix(void *blob, struct ls_pcie_rc *pcie_rc) return;
if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE) - fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0); + fdt_set_node_status(blob, off, FDT_STATUS_OKAY); else - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); }
static void ft_pcie_ep_fix(void *blob, struct ls_pcie_rc *pcie_rc) @@ -598,9 +598,9 @@ static void ft_pcie_ep_fix(void *blob, struct ls_pcie_rc *pcie_rc) return;
if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_NORMAL) - fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0); + fdt_set_node_status(blob, off, FDT_STATUS_OKAY); else - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); }
static void ft_pcie_ls_setup(void *blob, struct ls_pcie_rc *pcie_rc) diff --git a/drivers/pci/pcie_layerscape_gen4_fixup.c b/drivers/pci/pcie_layerscape_gen4_fixup.c index e9ee15558e..39579b1269 100644 --- a/drivers/pci/pcie_layerscape_gen4_fixup.c +++ b/drivers/pci/pcie_layerscape_gen4_fixup.c @@ -193,9 +193,9 @@ static void ft_pcie_ep_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie) }
if (pcie->enabled && pcie->mode == PCI_HEADER_TYPE_NORMAL) - fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0); + fdt_set_node_status(blob, off, FDT_STATUS_OKAY); else - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); }
static void ft_pcie_rc_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie) @@ -214,9 +214,9 @@ static void ft_pcie_rc_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie) }
if (pcie->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE) - fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0); + fdt_set_node_status(blob, off, FDT_STATUS_OKAY); else - fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0); + fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); }
static void ft_pcie_layerscape_gen4_setup(void *blob, struct ls_pcie_g4 *pcie) diff --git a/include/fdt_support.h b/include/fdt_support.h index 90f5a4c28c..850c860bd4 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -299,36 +299,34 @@ enum fdt_status { FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL, - FDT_STATUS_FAIL_ERROR_CODE, }; -int fdt_set_node_status(void *fdt, int nodeoffset, - enum fdt_status status, unsigned int error_code); +int fdt_set_node_status(void *fdt, int nodeoffset, enum fdt_status status); static inline int fdt_status_okay(void *fdt, int nodeoffset) { - return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0); + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY); } static inline int fdt_status_disabled(void *fdt, int nodeoffset) { - return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0); + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED); } static inline int fdt_status_fail(void *fdt, int nodeoffset) { - return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0); + return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL); }
int fdt_set_status_by_alias(void *fdt, const char *alias, - enum fdt_status status, unsigned int error_code); + enum fdt_status status); static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) { - return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0); + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY); } static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) { - return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0); + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED); } static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) { - return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0); + return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL); }
/* Helper to read a big number; size is in cells (not bytes) */

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Since no one uses this feature and I am not aware of any parsers of this in Linux, remove it.
Signed-off-by: Marek Behún marek.behun@nic.cz
arch/arm/cpu/armv7/ls102xa/fdt.c | 6 +++--- board/gateworks/gw_ventana/common.c | 3 +-- board/kontron/sl28/sl28.c | 2 +- common/fdt_support.c | 20 +++++--------------- drivers/pci/pcie_layerscape_fixup.c | 8 ++++---- drivers/pci/pcie_layerscape_gen4_fixup.c | 8 ++++---- include/fdt_support.h | 18 ++++++++---------- 7 files changed, 26 insertions(+), 39 deletions(-)
Again, please add the board / platform / driver maintainers as well to Cc.
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
diff --git a/arch/arm/cpu/armv7/ls102xa/fdt.c b/arch/arm/cpu/armv7/ls102xa/fdt.c index 0daf8234fb..bf6cc6d4e7 100644 --- a/arch/arm/cpu/armv7/ls102xa/fdt.c +++ b/arch/arm/cpu/armv7/ls102xa/fdt.c @@ -184,13 +184,13 @@ void ft_cpu_setup(void *blob, struct bd_info *bd) #if defined(CONFIG_QSPI_BOOT) || defined(CONFIG_SD_BOOT_QSPI) off = fdt_node_offset_by_compat_reg(blob, FSL_IFC_COMPAT, CONFIG_SYS_IFC_ADDR);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); #else off = fdt_node_offset_by_compat_reg(blob, FSL_QSPI_COMPAT, QSPI0_BASE_ADDR);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); off = fdt_node_offset_by_compat_reg(blob, FSL_DSPI_COMPAT, DSPI1_BASE_ADDR);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
- fdt_set_node_status(blob, off, FDT_STATUS_DISABLED); #endif }
diff --git a/board/gateworks/gw_ventana/common.c b/board/gateworks/gw_ventana/common.c index 2be921f47a..7ec931c8a8 100644 --- a/board/gateworks/gw_ventana/common.c +++ b/board/gateworks/gw_ventana/common.c @@ -1681,8 +1681,7 @@ void ft_early_fixup(void *blob, int board_type) * disable serial2 node for GW54xx for compatibility with older * 3.10.x kernel that improperly had this node enabled in the DT */
fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
0);
fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED);
/* GW54xx-E adds WDOG2_B external reset */ if (rev < 'E')
diff --git a/board/kontron/sl28/sl28.c b/board/kontron/sl28/sl28.c index c8ed7ac81a..e84b356918 100644 --- a/board/kontron/sl28/sl28.c +++ b/board/kontron/sl28/sl28.c @@ -75,7 +75,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (CONFIG_IS_ENABLED(SL28_SPL_LOADS_OPTEE_BL32)) { node = fdt_node_offset_by_compatible(blob, -1, "linaro,optee-tz"); if (node)
fdt_set_node_status(blob, node, FDT_STATUS_OKAY, 0);
fdt_set_node_status(blob, node, FDT_STATUS_OKAY);
}
return 0;
diff --git a/common/fdt_support.c b/common/fdt_support.c index be03a87d42..8ac905011c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1541,14 +1541,10 @@ unsigned int fdt_create_phandle(void *fdt, int nodeoffset)
- @fdt: ptr to device tree
- @nodeoffset: node to update
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED,
FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE
- @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE
*/
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL
-int fdt_set_node_status(void *fdt, int nodeoffset,
enum fdt_status status, unsigned int error_code)
+int fdt_set_node_status(void *fdt, int nodeoffset, enum fdt_status status) {
char buf[16]; int ret = 0;
if (nodeoffset < 0)
@@ -1564,10 +1560,6 @@ int fdt_set_node_status(void *fdt, int nodeoffset, case FDT_STATUS_FAIL: ret = fdt_setprop_string(fdt, nodeoffset, "status", "fail"); break;
- case FDT_STATUS_FAIL_ERROR_CODE:
sprintf(buf, "fail-%d", error_code);
ret = fdt_setprop_string(fdt, nodeoffset, "status", buf);
default: printf("Invalid fdt status: %x\n", status); ret = -1;break;
@@ -1582,16 +1574,14 @@ int fdt_set_node_status(void *fdt, int nodeoffset,
- @fdt: ptr to device tree
- @alias: alias of node to update
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED,
FDT_STATUS_FAIL, FDT_STATUS_FAIL_ERROR_CODE
- @error_code: optional, only used if status is FDT_STATUS_FAIL_ERROR_CODE
*/ int fdt_set_status_by_alias(void *fdt, const char* alias,
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL
enum fdt_status status, unsigned int error_code)
{ int offset = fdt_path_offset(fdt, alias);enum fdt_status status)
- return fdt_set_node_status(fdt, offset, status, error_code);
return fdt_set_node_status(fdt, offset, status); }
#if defined(CONFIG_VIDEO) || defined(CONFIG_LCD)
diff --git a/drivers/pci/pcie_layerscape_fixup.c b/drivers/pci/pcie_layerscape_fixup.c index a58e7a3892..92105a7103 100644 --- a/drivers/pci/pcie_layerscape_fixup.c +++ b/drivers/pci/pcie_layerscape_fixup.c @@ -582,9 +582,9 @@ static void ft_pcie_rc_fix(void *blob, struct ls_pcie_rc *pcie_rc) return;
if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE)
fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0);
elsefdt_set_node_status(blob, off, FDT_STATUS_OKAY);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
}
static void ft_pcie_ep_fix(void *blob, struct ls_pcie_rc *pcie_rc)
@@ -598,9 +598,9 @@ static void ft_pcie_ep_fix(void *blob, struct ls_pcie_rc *pcie_rc) return;
if (pcie_rc->enabled && pcie->mode == PCI_HEADER_TYPE_NORMAL)
fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0);
elsefdt_set_node_status(blob, off, FDT_STATUS_OKAY);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
}
static void ft_pcie_ls_setup(void *blob, struct ls_pcie_rc *pcie_rc)
diff --git a/drivers/pci/pcie_layerscape_gen4_fixup.c b/drivers/pci/pcie_layerscape_gen4_fixup.c index e9ee15558e..39579b1269 100644 --- a/drivers/pci/pcie_layerscape_gen4_fixup.c +++ b/drivers/pci/pcie_layerscape_gen4_fixup.c @@ -193,9 +193,9 @@ static void ft_pcie_ep_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie) }
if (pcie->enabled && pcie->mode == PCI_HEADER_TYPE_NORMAL)
fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0);
elsefdt_set_node_status(blob, off, FDT_STATUS_OKAY);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
}
static void ft_pcie_rc_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie)
@@ -214,9 +214,9 @@ static void ft_pcie_rc_layerscape_gen4_fix(void *blob, struct ls_pcie_g4 *pcie) }
if (pcie->enabled && pcie->mode == PCI_HEADER_TYPE_BRIDGE)
fdt_set_node_status(blob, off, FDT_STATUS_OKAY, 0);
elsefdt_set_node_status(blob, off, FDT_STATUS_OKAY);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED, 0);
fdt_set_node_status(blob, off, FDT_STATUS_DISABLED);
}
static void ft_pcie_layerscape_gen4_setup(void *blob, struct ls_pcie_g4 *pcie)
diff --git a/include/fdt_support.h b/include/fdt_support.h index 90f5a4c28c..850c860bd4 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -299,36 +299,34 @@ enum fdt_status { FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL,
- FDT_STATUS_FAIL_ERROR_CODE, };
-int fdt_set_node_status(void *fdt, int nodeoffset,
enum fdt_status status, unsigned int error_code);
+int fdt_set_node_status(void *fdt, int nodeoffset, enum fdt_status status); static inline int fdt_status_okay(void *fdt, int nodeoffset) {
- return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY, 0);
- return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_OKAY); } static inline int fdt_status_disabled(void *fdt, int nodeoffset) {
- return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED, 0);
- return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_DISABLED); } static inline int fdt_status_fail(void *fdt, int nodeoffset) {
- return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL, 0);
return fdt_set_node_status(fdt, nodeoffset, FDT_STATUS_FAIL); }
int fdt_set_status_by_alias(void *fdt, const char *alias,
enum fdt_status status, unsigned int error_code);
static inline int fdt_status_okay_by_alias(void *fdt, const char *alias) {enum fdt_status status);
- return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY, 0);
- return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_OKAY); } static inline int fdt_status_disabled_by_alias(void *fdt, const char *alias) {
- return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED, 0);
- return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_DISABLED); } static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) {
- return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL, 0);
return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL); }
/* Helper to read a big number; size is in cells (not bytes) */
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
This function does not necessarily create a new phandle. If a phandle exists, no new phandle is created.
Signed-off-by: Marek Behún marek.behun@nic.cz --- common/fdt_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c index 8ac905011c..df111f708c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1504,7 +1504,7 @@ int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle) }
/* - * fdt_create_phandle: Create a phandle property for the given node + * fdt_create_phandle: Get or create a phandle property for the given node * * @fdt: ptr to device tree * @nodeoffset: node to update

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
This function does not necessarily create a new phandle. If a phandle exists, no new phandle is created.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
common/fdt_support.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/common/fdt_support.c b/common/fdt_support.c index 8ac905011c..df111f708c 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1504,7 +1504,7 @@ int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle) }
/*
- fdt_create_phandle: Create a phandle property for the given node
- fdt_create_phandle: Get or create a phandle property for the given node
- @fdt: ptr to device tree
- @nodeoffset: node to update
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
Add functions fdt_node_offset_by_pathf(), fdt_create_phandle_by_pathf(), fdt_set_status_by_pathf() to get node offset, get/create node phandle and set status for node given by path/alias formatted with sprintf.
Add functions fdt_create_phandle_by_compatible(), fdt_set_status_by_compatible() to get/create node phandle and set status for first node given by compatible.
Signed-off-by: Marek Behún marek.behun@nic.cz --- common/fdt_support.c | 119 ++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 30 +++++++++++ 2 files changed, 149 insertions(+)
diff --git a/common/fdt_support.c b/common/fdt_support.c index df111f708c..c2e16727e1 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1463,6 +1463,37 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, return -FDT_ERR_NOTFOUND; }
+static int vnode_offset_by_pathf(void *blob, const char *fmt, va_list ap) +{ + char path[512]; + int len; + + len = vsnprintf(path, sizeof(path), fmt, ap); + if (len < 0 || len + 1 > sizeof(path)) + return -FDT_ERR_NOSPACE; + + return fdt_path_offset(blob, path); +} + +/** + * fdt_node_offset_by_pathf: Find node offset by sprintf formatted path + * + * @blob: ptr to device tree + * @fmt: path format + * @ap: vsnprintf arguments + */ +int fdt_node_offset_by_pathf(void *blob, const char *fmt, ...) +{ + va_list ap; + int res; + + va_start(ap, fmt); + res = vnode_offset_by_pathf(blob, fmt, ap); + va_end(ap); + + return res; +} + /* * fdt_set_phandle: Create a phandle property for the given node * @@ -1536,6 +1567,51 @@ unsigned int fdt_create_phandle(void *fdt, int nodeoffset) return phandle; }
+/** + * fdt_create_phandle_by_compatible: Get or create a phandle for first node with + * given compatible + * + * @fdt: ptr to device tree + * @compat: node's compatible string + */ +unsigned int fdt_create_phandle_by_compatible(void *fdt, const char *compat) +{ + int offset = fdt_node_offset_by_compatible(fdt, -1, compat); + + if (offset < 0) { + printf("Can't find node with compatible "%s": %s\n", compat, + fdt_strerror(offset)); + return 0; + } + + return fdt_create_phandle(fdt, offset); +} + +/** + * fdt_create_phandle_by_pathf: Get or create a phandle for node given by + * sprintf-formatted path + * + * @fdt: ptr to device tree + * @fmt, ...: path format string and arguments to pass to sprintf + */ +unsigned int fdt_create_phandle_by_pathf(void *fdt, const char *fmt, ...) +{ + va_list ap; + int offset; + + va_start(ap, fmt); + offset = vnode_offset_by_pathf(fdt, fmt, ap); + va_end(ap); + + if (offset < 0) { + printf("Can't find node by given path: %s\n", + fdt_strerror(offset)); + return 0; + } + + return fdt_create_phandle(fdt, offset); +} + /* * fdt_set_node_status: Set status for the given node * @@ -1584,6 +1660,49 @@ int fdt_set_status_by_alias(void *fdt, const char* alias, return fdt_set_node_status(fdt, offset, status); }
+/** + * fdt_set_status_by_compatible: Set node status for first node with given + * compatible + * + * @fdt: ptr to device tree + * @compat: node's compatible string + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL + */ +int fdt_set_status_by_compatible(void *fdt, const char *compat, + enum fdt_status status) +{ + int offset = fdt_node_offset_by_compatible(fdt, -1, compat); + + if (offset < 0) + return offset; + + return fdt_set_node_status(fdt, offset, status); +} + +/** + * fdt_set_status_by_pathf: Set node status for node given by sprintf-formatted + * path + * + * @fdt: ptr to device tree + * @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL + * @fmt, ...: path format string and arguments to pass to sprintf + */ +int fdt_set_status_by_pathf(void *fdt, enum fdt_status status, const char *fmt, + ...) +{ + va_list ap; + int offset; + + va_start(ap, fmt); + offset = vnode_offset_by_pathf(fdt, fmt, ap); + va_end(ap); + + if (offset < 0) + return offset; + + return fdt_set_node_status(fdt, offset, status); +} + #if defined(CONFIG_VIDEO) || defined(CONFIG_LCD) int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf) { diff --git a/include/fdt_support.h b/include/fdt_support.h index 850c860bd4..d40586725b 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -285,8 +285,13 @@ int fdt_get_dma_range(const void *blob, int node_offset, phys_addr_t *cpu,
int fdt_node_offset_by_compat_reg(void *blob, const char *compat, phys_addr_t compat_off); +int fdt_node_offset_by_pathf(void *blob, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); unsigned int fdt_create_phandle(void *fdt, int nodeoffset); +unsigned int fdt_create_phandle_by_compatible(void *fdt, const char *compat); +unsigned int fdt_create_phandle_by_pathf(void *fdt, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); int fdt_add_edid(void *blob, const char *compat, unsigned char *buf);
int fdt_verify_alias_address(void *fdt, int anode, const char *alias, @@ -329,6 +334,31 @@ static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL); }
+int fdt_set_status_by_compatible(void *fdt, const char *compat, + enum fdt_status status); +static inline int fdt_status_okay_by_compatible(void *fdt, const char *compat) +{ + return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_OKAY); +} +static inline int fdt_status_disabled_by_compatible(void *fdt, + const char *compat) +{ + return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_DISABLED); +} +static inline int fdt_status_fail_by_compatible(void *fdt, const char *compat) +{ + return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_FAIL); +} + +int fdt_set_status_by_pathf(void *fdt, enum fdt_status status, const char *fmt, + ...) __attribute__ ((format (printf, 3, 4))); +#define fdt_status_okay_by_pathf(fdt, fmt, ...) \ + fdt_set_status_by_pathf((fdt), FDT_STATUS_OKAY, (fmt), ##__VA_ARGS__) +#define fdt_status_disabled_by_pathf(fdt, fmt, ...) \ + fdt_set_status_by_pathf((fdt), FDT_STATUS_DISABLED, (fmt), ##__VA_ARGS__) +#define fdt_status_fail_by_pathf(fdt, fmt, ...) \ + fdt_set_status_by_pathf((fdt), FDT_STATUS_FAIL, (fmt), ##__VA_ARGS__) + /* Helper to read a big number; size is in cells (not bytes) */ static inline u64 fdt_read_number(const fdt32_t *cell, int size) {

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Add functions fdt_node_offset_by_pathf(), fdt_create_phandle_by_pathf(), fdt_set_status_by_pathf() to get node offset, get/create node phandle and set status for node given by path/alias formatted with sprintf.
Add functions fdt_create_phandle_by_compatible(), fdt_set_status_by_compatible() to get/create node phandle and set status for first node given by compatible.
Signed-off-by: Marek Behún marek.behun@nic.cz
My only concern here, that this might blow up the code size. But as these new functions are unused by current boards, this should not be the case. So
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
common/fdt_support.c | 119 ++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 30 +++++++++++ 2 files changed, 149 insertions(+)
diff --git a/common/fdt_support.c b/common/fdt_support.c index df111f708c..c2e16727e1 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1463,6 +1463,37 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, return -FDT_ERR_NOTFOUND; }
+static int vnode_offset_by_pathf(void *blob, const char *fmt, va_list ap) +{
- char path[512];
- int len;
- len = vsnprintf(path, sizeof(path), fmt, ap);
- if (len < 0 || len + 1 > sizeof(path))
return -FDT_ERR_NOSPACE;
- return fdt_path_offset(blob, path);
+}
+/**
- fdt_node_offset_by_pathf: Find node offset by sprintf formatted path
- @blob: ptr to device tree
- @fmt: path format
- @ap: vsnprintf arguments
- */
+int fdt_node_offset_by_pathf(void *blob, const char *fmt, ...) +{
- va_list ap;
- int res;
- va_start(ap, fmt);
- res = vnode_offset_by_pathf(blob, fmt, ap);
- va_end(ap);
- return res;
+}
- /*
- fdt_set_phandle: Create a phandle property for the given node
@@ -1536,6 +1567,51 @@ unsigned int fdt_create_phandle(void *fdt, int nodeoffset) return phandle; }
+/**
- fdt_create_phandle_by_compatible: Get or create a phandle for first node with
given compatible
- @fdt: ptr to device tree
- @compat: node's compatible string
- */
+unsigned int fdt_create_phandle_by_compatible(void *fdt, const char *compat) +{
- int offset = fdt_node_offset_by_compatible(fdt, -1, compat);
- if (offset < 0) {
printf("Can't find node with compatible \"%s\": %s\n", compat,
fdt_strerror(offset));
return 0;
- }
- return fdt_create_phandle(fdt, offset);
+}
+/**
- fdt_create_phandle_by_pathf: Get or create a phandle for node given by
sprintf-formatted path
- @fdt: ptr to device tree
- @fmt, ...: path format string and arguments to pass to sprintf
- */
+unsigned int fdt_create_phandle_by_pathf(void *fdt, const char *fmt, ...) +{
- va_list ap;
- int offset;
- va_start(ap, fmt);
- offset = vnode_offset_by_pathf(fdt, fmt, ap);
- va_end(ap);
- if (offset < 0) {
printf("Can't find node by given path: %s\n",
fdt_strerror(offset));
return 0;
- }
- return fdt_create_phandle(fdt, offset);
+}
- /*
- fdt_set_node_status: Set status for the given node
@@ -1584,6 +1660,49 @@ int fdt_set_status_by_alias(void *fdt, const char* alias, return fdt_set_node_status(fdt, offset, status); }
+/**
- fdt_set_status_by_compatible: Set node status for first node with given
compatible
- @fdt: ptr to device tree
- @compat: node's compatible string
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL
- */
+int fdt_set_status_by_compatible(void *fdt, const char *compat,
enum fdt_status status)
+{
- int offset = fdt_node_offset_by_compatible(fdt, -1, compat);
- if (offset < 0)
return offset;
- return fdt_set_node_status(fdt, offset, status);
+}
+/**
- fdt_set_status_by_pathf: Set node status for node given by sprintf-formatted
path
- @fdt: ptr to device tree
- @status: FDT_STATUS_OKAY, FDT_STATUS_DISABLED, FDT_STATUS_FAIL
- @fmt, ...: path format string and arguments to pass to sprintf
- */
+int fdt_set_status_by_pathf(void *fdt, enum fdt_status status, const char *fmt,
...)
+{
- va_list ap;
- int offset;
- va_start(ap, fmt);
- offset = vnode_offset_by_pathf(fdt, fmt, ap);
- va_end(ap);
- if (offset < 0)
return offset;
- return fdt_set_node_status(fdt, offset, status);
+}
- #if defined(CONFIG_VIDEO) || defined(CONFIG_LCD) int fdt_add_edid(void *blob, const char *compat, unsigned char *edid_buf) {
diff --git a/include/fdt_support.h b/include/fdt_support.h index 850c860bd4..d40586725b 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -285,8 +285,13 @@ int fdt_get_dma_range(const void *blob, int node_offset, phys_addr_t *cpu,
int fdt_node_offset_by_compat_reg(void *blob, const char *compat, phys_addr_t compat_off); +int fdt_node_offset_by_pathf(void *blob, const char *fmt, ...)
- __attribute__ ((format (printf, 2, 3))); int fdt_set_phandle(void *fdt, int nodeoffset, uint32_t phandle); unsigned int fdt_create_phandle(void *fdt, int nodeoffset);
+unsigned int fdt_create_phandle_by_compatible(void *fdt, const char *compat); +unsigned int fdt_create_phandle_by_pathf(void *fdt, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3))); int fdt_add_edid(void *blob, const char *compat, unsigned char *buf);
int fdt_verify_alias_address(void *fdt, int anode, const char *alias,
@@ -329,6 +334,31 @@ static inline int fdt_status_fail_by_alias(void *fdt, const char *alias) return fdt_set_status_by_alias(fdt, alias, FDT_STATUS_FAIL); }
+int fdt_set_status_by_compatible(void *fdt, const char *compat,
enum fdt_status status);
+static inline int fdt_status_okay_by_compatible(void *fdt, const char *compat) +{
- return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_OKAY);
+} +static inline int fdt_status_disabled_by_compatible(void *fdt,
const char *compat)
+{
- return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_DISABLED);
+} +static inline int fdt_status_fail_by_compatible(void *fdt, const char *compat) +{
- return fdt_set_status_by_compatible(fdt, compat, FDT_STATUS_FAIL);
+}
+int fdt_set_status_by_pathf(void *fdt, enum fdt_status status, const char *fmt,
...) __attribute__ ((format (printf, 3, 4)));
+#define fdt_status_okay_by_pathf(fdt, fmt, ...) \
- fdt_set_status_by_pathf((fdt), FDT_STATUS_OKAY, (fmt), ##__VA_ARGS__)
+#define fdt_status_disabled_by_pathf(fdt, fmt, ...) \
- fdt_set_status_by_pathf((fdt), FDT_STATUS_DISABLED, (fmt), ##__VA_ARGS__)
+#define fdt_status_fail_by_pathf(fdt, fmt, ...) \
- fdt_set_status_by_pathf((fdt), FDT_STATUS_FAIL, (fmt), ##__VA_ARGS__)
- /* Helper to read a big number; size is in cells (not bytes) */ static inline u64 fdt_read_number(const fdt32_t *cell, int size) {
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
It is better to find DT nodes by compatible strings or aliases instead of path.
There were issues with Linux some DTBs having different names of some nodes, e.g. internal-regs instead of internal-regs@d0000000
This should be a generic fix for such issues.
Also since fdt_support now contains needed functions, we can drop our own implementations.
Signed-off-by: Marek Behún marek.behun@nic.cz --- board/CZ.NIC/turris_mox/turris_mox.c | 186 +++++++++------------------ 1 file changed, 63 insertions(+), 123 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 2202eb8cfb..03c923969e 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -41,22 +41,14 @@ #define ARMADA_37XX_SPI_DOUT (MVEBU_REGISTER(0x10608)) #define ARMADA_37XX_SPI_DIN (MVEBU_REGISTER(0x1060c))
-#define ETH1_PATH "/soc/internal-regs@d0000000/ethernet@40000" -#define MDIO_PATH "/soc/internal-regs@d0000000/mdio@32004" -#define SFP_GPIO_PATH "/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0" -#define PCIE_PATH "/soc/pcie@d0070000" -#define SFP_PATH "/sfp" -#define LED_PATH "/leds/led" -#define BUTTON_PATH "/gpio-keys/reset" - DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_OF_BOARD_FIXUP) int board_fix_fdt(void *blob) { u8 topology[MAX_MOX_MODULES]; - int i, size, node; - bool enable; + enum fdt_status status; + int i, size, ret;
/* * SPI driver is not loaded in driver model yet, but we have to find out @@ -94,21 +86,15 @@ int board_fix_fdt(void *blob) if (size > 1 && (topology[1] == MOX_MODULE_PCI || topology[1] == MOX_MODULE_USB3 || topology[1] == MOX_MODULE_PASSPCI)) - enable = true; + status = FDT_STATUS_OKAY; else - enable = false; - - node = fdt_path_offset(blob, PCIE_PATH); + status = FDT_STATUS_DISABLED;
- if (node < 0) { - printf("Cannot find PCIe node in U-Boot's device tree!\n"); - return 0; - } - - if (fdt_setprop_string(blob, node, "status", - enable ? "okay" : "disabled") < 0) { - printf("Cannot %s PCIe in U-Boot's device tree!\n", - enable ? "enable" : "disable"); + ret = fdt_set_status_by_compatible(blob, "marvell,armada-3700-pcie", + status); + if (ret < 0) { + printf("Cannot set status for PCIe in U-Boot's device tree: %s!\n", + fdt_strerror(ret)); return 0; }
@@ -416,12 +402,18 @@ static bool read_reset_button(void) struct udevice *button, *led; int i;
- if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) { + if (device_get_global_by_ofnode( + ofnode_first_subnode(ofnode_by_compatible(ofnode_null(), + "gpio-keys")), + &button)) { printf("Cannot find reset button!\n"); return false; }
- if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) { + if (device_get_global_by_ofnode( + ofnode_first_subnode(ofnode_by_compatible(ofnode_null(), + "gpio-leds")), + &led)) { printf("Cannot find status LED!\n"); return false; } @@ -664,92 +656,34 @@ handle_reset_btn:
#if defined(CONFIG_OF_BOARD_SETUP)
-static int vnode_by_path(void *blob, const char *fmt, va_list ap) +static bool is_topaz(int id) { - char path[128]; - - vsnprintf(path, 128, fmt, ap); - return fdt_path_offset(blob, path); + return topaz && id == peridot + topaz - 1; }
-static int node_by_path(void *blob, const char *fmt, ...) +static int switch_addr(int id) { - va_list ap; - int res; - - va_start(ap, fmt); - res = vnode_by_path(blob, fmt, ap); - va_end(ap); - - return res; + return is_topaz(id) ? 0x2 : 0x10 + id; }
-static int phandle_by_path(void *blob, const char *fmt, ...) +static int setup_switch(void *blob, int id) { - va_list ap; - int node, phandle, res; - - va_start(ap, fmt); - node = vnode_by_path(blob, fmt, ap); - va_end(ap); + int res, addr, i, node; + char mdio_path[64];
+ node = fdt_node_offset_by_compatible(blob, -1, "marvell,orion-mdio"); if (node < 0) return node;
- phandle = fdt_get_phandle(blob, node); - if (phandle > 0) - return phandle; - - phandle = fdt_get_max_phandle(blob); - if (phandle < 0) - return phandle; - - phandle += 1; - - res = fdt_setprop_u32(blob, node, "linux,phandle", phandle); + res = fdt_get_path(blob, node, mdio_path, sizeof(mdio_path)); if (res < 0) return res;
- res = fdt_setprop_u32(blob, node, "phandle", phandle); - if (res < 0) - return res; - - return phandle; -} - -static int enable_by_path(void *blob, const char *fmt, ...) -{ - va_list ap; - int node; - - va_start(ap, fmt); - node = vnode_by_path(blob, fmt, ap); - va_end(ap); - - if (node < 0) - return node; - - return fdt_setprop_string(blob, node, "status", "okay"); -} - -static bool is_topaz(int id) -{ - return topaz && id == peridot + topaz - 1; -} - -static int switch_addr(int id) -{ - return is_topaz(id) ? 0x2 : 0x10 + id; -} - -static int setup_switch(void *blob, int id) -{ - int res, addr, i, node, phandle; - addr = switch_addr(id);
/* first enable the switch by setting status = "okay" */ - res = enable_by_path(blob, MDIO_PATH "/switch%i@%x", id, addr); + res = fdt_status_okay_by_pathf(blob, "%s/switch%i@%x", mdio_path, id, + addr); if (res < 0) return res;
@@ -758,13 +692,13 @@ static int setup_switch(void *blob, int id) * enable corresponding ports */ if (id < peridot + topaz - 1) { - res = enable_by_path(blob, - MDIO_PATH "/switch%i@%x/ports/port@a", - id, addr); + res = fdt_status_okay_by_pathf(blob, + "%s/switch%i@%x/ports/port@a", + mdio_path, id, addr); } else if (id == peridot - 1 && !topaz && sfp) { - res = enable_by_path(blob, - MDIO_PATH "/switch%i@%x/ports/port-sfp@a", - id, addr); + res = fdt_status_okay_by_pathf(blob, + "%s/switch%i@%x/ports/port-sfp@a", + mdio_path, id, addr); } else { res = 0; } @@ -775,18 +709,21 @@ static int setup_switch(void *blob, int id) return 0;
/* finally change link property if needed */ - node = node_by_path(blob, MDIO_PATH "/switch%i@%x/ports/port@a", id, - addr); + node = fdt_node_offset_by_pathf(blob, "%s/switch%i@%x/ports/port@a", + mdio_path, id, addr); if (node < 0) return node;
for (i = id + 1; i < peridot + topaz; ++i) { - phandle = phandle_by_path(blob, - MDIO_PATH "/switch%i@%x/ports/port@%x", - i, switch_addr(i), - is_topaz(i) ? 5 : 9); - if (phandle < 0) - return phandle; + unsigned int phandle; + + phandle = fdt_create_phandle_by_pathf(blob, + "%s/switch%i@%x/ports/port@%x", + mdio_path, i, + switch_addr(i), + is_topaz(i) ? 5 : 9); + if (!phandle) + return -FDT_ERR_NOPHANDLES;
if (i == id + 1) res = fdt_setprop_u32(blob, node, "link", phandle); @@ -819,18 +756,15 @@ static int remove_disabled_nodes(void *blob)
int ft_board_setup(void *blob, struct bd_info *bd) { - int node, phandle, res; + int res;
/* * If MOX B (PCI), MOX F (USB) or MOX G (Passthrough PCI) modules are * connected, enable the PCIe node. */ if (pci || usb || passpci) { - node = fdt_path_offset(blob, PCIE_PATH); - if (node < 0) - return node; - - res = fdt_setprop_string(blob, node, "status", "okay"); + res = fdt_status_okay_by_compatible(blob, + "marvell,armada-3700-pcie"); if (res < 0) return res;
@@ -847,7 +781,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (peridot || topaz) { int i;
- res = enable_by_path(blob, ETH1_PATH); + res = fdt_status_okay_by_alias(blob, "ethernet1"); if (res < 0) return res;
@@ -865,20 +799,25 @@ int ft_board_setup(void *blob, struct bd_info *bd) * Also enable and configure SFP GPIO controller node. */ if (sfp) { - res = enable_by_path(blob, SFP_PATH); + int node; + + res = fdt_status_okay_by_compatible(blob, "sff,sfp"); if (res < 0) return res;
- res = enable_by_path(blob, ETH1_PATH); + res = fdt_status_okay_by_alias(blob, "ethernet1"); if (res < 0) return res;
if (!peridot) { - phandle = phandle_by_path(blob, SFP_PATH); - if (phandle < 0) - return res; + unsigned int phandle; + + phandle = fdt_create_phandle_by_compatible(blob, + "sff,sfp"); + if (!phandle) + return -FDT_ERR_NOPHANDLES;
- node = node_by_path(blob, ETH1_PATH); + node = fdt_path_offset(blob, "ethernet1"); if (node < 0) return node;
@@ -892,7 +831,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) return res; }
- res = enable_by_path(blob, SFP_GPIO_PATH); + res = fdt_status_okay_by_compatible(blob, "cznic,moxtet-gpio"); if (res < 0) return res;
@@ -900,7 +839,8 @@ int ft_board_setup(void *blob, struct bd_info *bd) char newname[16];
/* moxtet-sfp is on non-zero position, change default */ - node = node_by_path(blob, SFP_GPIO_PATH); + node = fdt_node_offset_by_compatible(blob, -1, + "cznic,moxtet-gpio"); if (node < 0) return node;

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
It is better to find DT nodes by compatible strings or aliases instead of path.
There were issues with Linux some DTBs having different names of some nodes, e.g. internal-regs instead of internal-regs@d0000000
This should be a generic fix for such issues.
Also since fdt_support now contains needed functions, we can drop our own implementations.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
board/CZ.NIC/turris_mox/turris_mox.c | 186 +++++++++------------------ 1 file changed, 63 insertions(+), 123 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 2202eb8cfb..03c923969e 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -41,22 +41,14 @@ #define ARMADA_37XX_SPI_DOUT (MVEBU_REGISTER(0x10608)) #define ARMADA_37XX_SPI_DIN (MVEBU_REGISTER(0x1060c))
-#define ETH1_PATH "/soc/internal-regs@d0000000/ethernet@40000" -#define MDIO_PATH "/soc/internal-regs@d0000000/mdio@32004" -#define SFP_GPIO_PATH "/soc/internal-regs@d0000000/spi@10600/moxtet@1/gpio@0" -#define PCIE_PATH "/soc/pcie@d0070000" -#define SFP_PATH "/sfp" -#define LED_PATH "/leds/led" -#define BUTTON_PATH "/gpio-keys/reset"
DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_OF_BOARD_FIXUP) int board_fix_fdt(void *blob) { u8 topology[MAX_MOX_MODULES];
int i, size, node;
bool enable;
enum fdt_status status;
int i, size, ret;
/*
- SPI driver is not loaded in driver model yet, but we have to find out
@@ -94,21 +86,15 @@ int board_fix_fdt(void *blob) if (size > 1 && (topology[1] == MOX_MODULE_PCI || topology[1] == MOX_MODULE_USB3 || topology[1] == MOX_MODULE_PASSPCI))
enable = true;
elsestatus = FDT_STATUS_OKAY;
enable = false;
- node = fdt_path_offset(blob, PCIE_PATH);
status = FDT_STATUS_DISABLED;
- if (node < 0) {
printf("Cannot find PCIe node in U-Boot's device tree!\n");
return 0;
- }
- if (fdt_setprop_string(blob, node, "status",
enable ? "okay" : "disabled") < 0) {
printf("Cannot %s PCIe in U-Boot's device tree!\n",
enable ? "enable" : "disable");
- ret = fdt_set_status_by_compatible(blob, "marvell,armada-3700-pcie",
status);
- if (ret < 0) {
printf("Cannot set status for PCIe in U-Boot's device tree: %s!\n",
return 0; }fdt_strerror(ret));
@@ -416,12 +402,18 @@ static bool read_reset_button(void) struct udevice *button, *led; int i;
- if (device_get_global_by_ofnode(ofnode_path(BUTTON_PATH), &button)) {
- if (device_get_global_by_ofnode(
ofnode_first_subnode(ofnode_by_compatible(ofnode_null(),
"gpio-keys")),
printf("Cannot find reset button!\n"); return false; }&button)) {
- if (device_get_global_by_ofnode(ofnode_path(LED_PATH), &led)) {
- if (device_get_global_by_ofnode(
ofnode_first_subnode(ofnode_by_compatible(ofnode_null(),
"gpio-leds")),
printf("Cannot find status LED!\n"); return false; }&led)) {
@@ -664,92 +656,34 @@ handle_reset_btn:
#if defined(CONFIG_OF_BOARD_SETUP)
-static int vnode_by_path(void *blob, const char *fmt, va_list ap) +static bool is_topaz(int id) {
- char path[128];
- vsnprintf(path, 128, fmt, ap);
- return fdt_path_offset(blob, path);
- return topaz && id == peridot + topaz - 1; }
-static int node_by_path(void *blob, const char *fmt, ...) +static int switch_addr(int id) {
- va_list ap;
- int res;
- va_start(ap, fmt);
- res = vnode_by_path(blob, fmt, ap);
- va_end(ap);
- return res;
- return is_topaz(id) ? 0x2 : 0x10 + id; }
-static int phandle_by_path(void *blob, const char *fmt, ...) +static int setup_switch(void *blob, int id) {
- va_list ap;
- int node, phandle, res;
- va_start(ap, fmt);
- node = vnode_by_path(blob, fmt, ap);
- va_end(ap);
int res, addr, i, node;
char mdio_path[64];
node = fdt_node_offset_by_compatible(blob, -1, "marvell,orion-mdio"); if (node < 0) return node;
- phandle = fdt_get_phandle(blob, node);
- if (phandle > 0)
return phandle;
- phandle = fdt_get_max_phandle(blob);
- if (phandle < 0)
return phandle;
- phandle += 1;
- res = fdt_setprop_u32(blob, node, "linux,phandle", phandle);
- res = fdt_get_path(blob, node, mdio_path, sizeof(mdio_path)); if (res < 0) return res;
- res = fdt_setprop_u32(blob, node, "phandle", phandle);
- if (res < 0)
return res;
- return phandle;
-}
-static int enable_by_path(void *blob, const char *fmt, ...) -{
- va_list ap;
- int node;
- va_start(ap, fmt);
- node = vnode_by_path(blob, fmt, ap);
- va_end(ap);
- if (node < 0)
return node;
- return fdt_setprop_string(blob, node, "status", "okay");
-}
-static bool is_topaz(int id) -{
- return topaz && id == peridot + topaz - 1;
-}
-static int switch_addr(int id) -{
- return is_topaz(id) ? 0x2 : 0x10 + id;
-}
-static int setup_switch(void *blob, int id) -{
int res, addr, i, node, phandle;
addr = switch_addr(id);
/* first enable the switch by setting status = "okay" */
res = enable_by_path(blob, MDIO_PATH "/switch%i@%x", id, addr);
- res = fdt_status_okay_by_pathf(blob, "%s/switch%i@%x", mdio_path, id,
if (res < 0) return res;addr);
@@ -758,13 +692,13 @@ static int setup_switch(void *blob, int id) * enable corresponding ports */ if (id < peridot + topaz - 1) {
res = enable_by_path(blob,
MDIO_PATH "/switch%i@%x/ports/port@a",
id, addr);
res = fdt_status_okay_by_pathf(blob,
"%s/switch%i@%x/ports/port@a",
} else if (id == peridot - 1 && !topaz && sfp) {mdio_path, id, addr);
res = enable_by_path(blob,
MDIO_PATH "/switch%i@%x/ports/port-sfp@a",
id, addr);
res = fdt_status_okay_by_pathf(blob,
"%s/switch%i@%x/ports/port-sfp@a",
} else { res = 0; }mdio_path, id, addr);
@@ -775,18 +709,21 @@ static int setup_switch(void *blob, int id) return 0;
/* finally change link property if needed */
- node = node_by_path(blob, MDIO_PATH "/switch%i@%x/ports/port@a", id,
addr);
node = fdt_node_offset_by_pathf(blob, "%s/switch%i@%x/ports/port@a",
mdio_path, id, addr);
if (node < 0) return node;
for (i = id + 1; i < peridot + topaz; ++i) {
phandle = phandle_by_path(blob,
MDIO_PATH "/switch%i@%x/ports/port@%x",
i, switch_addr(i),
is_topaz(i) ? 5 : 9);
if (phandle < 0)
return phandle;
unsigned int phandle;
phandle = fdt_create_phandle_by_pathf(blob,
"%s/switch%i@%x/ports/port@%x",
mdio_path, i,
switch_addr(i),
is_topaz(i) ? 5 : 9);
if (!phandle)
return -FDT_ERR_NOPHANDLES;
if (i == id + 1) res = fdt_setprop_u32(blob, node, "link", phandle);
@@ -819,18 +756,15 @@ static int remove_disabled_nodes(void *blob)
int ft_board_setup(void *blob, struct bd_info *bd) {
- int node, phandle, res;
int res;
/*
- If MOX B (PCI), MOX F (USB) or MOX G (Passthrough PCI) modules are
- connected, enable the PCIe node.
*/ if (pci || usb || passpci) {
node = fdt_path_offset(blob, PCIE_PATH);
if (node < 0)
return node;
res = fdt_setprop_string(blob, node, "status", "okay");
res = fdt_status_okay_by_compatible(blob,
if (res < 0) return res;"marvell,armada-3700-pcie");
@@ -847,7 +781,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) if (peridot || topaz) { int i;
res = enable_by_path(blob, ETH1_PATH);
if (res < 0) return res;res = fdt_status_okay_by_alias(blob, "ethernet1");
@@ -865,20 +799,25 @@ int ft_board_setup(void *blob, struct bd_info *bd) * Also enable and configure SFP GPIO controller node. */ if (sfp) {
res = enable_by_path(blob, SFP_PATH);
int node;
if (res < 0) return res;res = fdt_status_okay_by_compatible(blob, "sff,sfp");
res = enable_by_path(blob, ETH1_PATH);
res = fdt_status_okay_by_alias(blob, "ethernet1");
if (res < 0) return res;
if (!peridot) {
phandle = phandle_by_path(blob, SFP_PATH);
if (phandle < 0)
return res;
unsigned int phandle;
phandle = fdt_create_phandle_by_compatible(blob,
"sff,sfp");
if (!phandle)
return -FDT_ERR_NOPHANDLES;
node = node_by_path(blob, ETH1_PATH);
node = fdt_path_offset(blob, "ethernet1"); if (node < 0) return node;
@@ -892,7 +831,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) return res; }
res = enable_by_path(blob, SFP_GPIO_PATH);
if (res < 0) return res;res = fdt_status_okay_by_compatible(blob, "cznic,moxtet-gpio");
@@ -900,7 +839,8 @@ int ft_board_setup(void *blob, struct bd_info *bd) char newname[16];
/* moxtet-sfp is on non-zero position, change default */
node = node_by_path(blob, SFP_GPIO_PATH);
node = fdt_node_offset_by_compatible(blob, -1,
"cznic,moxtet-gpio"); if (node < 0) return node;
Viele Grüße, Stefan Roese

From: Pali Rohár pali@kernel.org
Enable eth1 node in U-Boot's device-tree if a network module (SFP, Topaz or Peridot) is detected.
This is required for proper detection of eth1 comphy in a3700 comphy driver by the following patches.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz --- board/CZ.NIC/turris_mox/turris_mox.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 03c923969e..502f6fc010 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -46,8 +46,8 @@ DECLARE_GLOBAL_DATA_PTR; #if defined(CONFIG_OF_BOARD_FIXUP) int board_fix_fdt(void *blob) { + enum fdt_status status_pcie, status_eth1; u8 topology[MAX_MOX_MODULES]; - enum fdt_status status; int i, size, ret;
/* @@ -65,6 +65,9 @@ int board_fix_fdt(void *blob) while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2)) udelay(1);
+ status_pcie = FDT_STATUS_DISABLED; + status_eth1 = FDT_STATUS_DISABLED; + for (i = 0; i < MAX_MOX_MODULES; ++i) { writel(0x0, ARMADA_37XX_SPI_DOUT);
@@ -76,6 +79,11 @@ int board_fix_fdt(void *blob) break;
topology[i] &= 0xf; + + if (topology[i] == MOX_MODULE_SFP || + topology[i] == MOX_MODULE_TOPAZ || + topology[i] == MOX_MODULE_PERIDOT) + status_eth1 = FDT_STATUS_OKAY; }
size = i; @@ -83,15 +91,18 @@ int board_fix_fdt(void *blob) /* disable SPI CS1 */ clrbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));
+ ret = fdt_set_status_by_alias(blob, "ethernet1", status_eth1); + if (ret < 0) + printf("Cannot set status for eth1 in U-Boot's device tree: %s!\n", + fdt_strerror(ret)); + if (size > 1 && (topology[1] == MOX_MODULE_PCI || topology[1] == MOX_MODULE_USB3 || topology[1] == MOX_MODULE_PASSPCI)) - status = FDT_STATUS_OKAY; - else - status = FDT_STATUS_DISABLED; + status_pcie = FDT_STATUS_OKAY;
ret = fdt_set_status_by_compatible(blob, "marvell,armada-3700-pcie", - status); + status_pcie); if (ret < 0) { printf("Cannot set status for PCIe in U-Boot's device tree: %s!\n", fdt_strerror(ret));

On 11/3/21 03:02, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Enable eth1 node in U-Boot's device-tree if a network module (SFP, Topaz or Peridot) is detected.
This is required for proper detection of eth1 comphy in a3700 comphy driver by the following patches.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
board/CZ.NIC/turris_mox/turris_mox.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 03c923969e..502f6fc010 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -46,8 +46,8 @@ DECLARE_GLOBAL_DATA_PTR; #if defined(CONFIG_OF_BOARD_FIXUP) int board_fix_fdt(void *blob) {
- enum fdt_status status_pcie, status_eth1; u8 topology[MAX_MOX_MODULES];
enum fdt_status status; int i, size, ret;
/*
@@ -65,6 +65,9 @@ int board_fix_fdt(void *blob) while (!(readl(ARMADA_37XX_SPI_CTRL) & 0x2)) udelay(1);
- status_pcie = FDT_STATUS_DISABLED;
- status_eth1 = FDT_STATUS_DISABLED;
- for (i = 0; i < MAX_MOX_MODULES; ++i) { writel(0x0, ARMADA_37XX_SPI_DOUT);
@@ -76,6 +79,11 @@ int board_fix_fdt(void *blob) break;
topology[i] &= 0xf;
if (topology[i] == MOX_MODULE_SFP ||
topology[i] == MOX_MODULE_TOPAZ ||
topology[i] == MOX_MODULE_PERIDOT)
status_eth1 = FDT_STATUS_OKAY;
}
size = i;
@@ -83,15 +91,18 @@ int board_fix_fdt(void *blob) /* disable SPI CS1 */ clrbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));
- ret = fdt_set_status_by_alias(blob, "ethernet1", status_eth1);
- if (ret < 0)
printf("Cannot set status for eth1 in U-Boot's device tree: %s!\n",
fdt_strerror(ret));
- if (size > 1 && (topology[1] == MOX_MODULE_PCI || topology[1] == MOX_MODULE_USB3 || topology[1] == MOX_MODULE_PASSPCI))
status = FDT_STATUS_OKAY;
- else
status = FDT_STATUS_DISABLED;
status_pcie = FDT_STATUS_OKAY;
ret = fdt_set_status_by_compatible(blob, "marvell,armada-3700-pcie",
status);
if (ret < 0) { printf("Cannot set status for PCIe in U-Boot's device tree: %s!\n", fdt_strerror(ret));status_pcie);
Viele Grüße, Stefan Roese

From: Pali Rohár pali@kernel.org
Convert A3720 common PHY driver to official DT bindings.
This puts us closer to be able to synchronize A3720 device-trees with those from Linux.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz --- arch/arm/dts/armada-3720-espressobin.dts | 21 +--- arch/arm/dts/armada-3720-turris-mox.dts | 25 ++--- arch/arm/dts/armada-3720-uDPU.dts | 23 +--- arch/arm/dts/armada-37xx.dtsi | 20 +++- drivers/phy/marvell/comphy_a3700.c | 133 +++++++++++++++++++++++ drivers/phy/marvell/comphy_core.c | 59 +--------- drivers/phy/marvell/comphy_core.h | 23 ++++ drivers/phy/marvell/comphy_cp110.c | 58 ++++++++++ 8 files changed, 250 insertions(+), 112 deletions(-)
diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index cba6139be6..360d521bba 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -80,24 +80,6 @@ }; };
-&comphy { - max-lanes = <3>; - phy0 { - phy-type = <COMPHY_TYPE_USB3_HOST0>; - phy-speed = <COMPHY_SPEED_5G>; - }; - - phy1 { - phy-type = <COMPHY_TYPE_PEX0>; - phy-speed = <COMPHY_SPEED_2_5G>; - }; - - phy2 { - phy-type = <COMPHY_TYPE_SATA0>; - phy-speed = <COMPHY_SPEED_5G>; - }; -}; - ð0 { status = "okay"; pinctrl-names = "default"; @@ -119,6 +101,7 @@ /* CON3 */ &sata { status = "okay"; + phys = <&comphy2 0>; };
&sdhci0 { @@ -200,6 +183,7 @@ /* CON31 */ &usb3 { status = "okay"; + phys = <&comphy0 0>; };
&pcie0 { @@ -207,4 +191,5 @@ pinctrl-0 = <&pcie_pins>; reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay"; + phys = <&comphy1 0>; }; diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index f47ced05c5..d01757062f 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -94,24 +94,6 @@ }; };
-&comphy { - max-lanes = <3>; - phy0 { - phy-type = <COMPHY_TYPE_SGMII1>; - phy-speed = <COMPHY_SPEED_3_125G>; - }; - - phy1 { - phy-type = <COMPHY_TYPE_PEX0>; - phy-speed = <COMPHY_SPEED_5G>; - }; - - phy2 { - phy-type = <COMPHY_TYPE_USB3_HOST0>; - phy-speed = <COMPHY_SPEED_5G>; - }; -}; - ð0 { status = "okay"; pinctrl-names = "default"; @@ -120,6 +102,11 @@ phy = <ð_phy1>; };
+ð1 { + phy-mode = "2500base-x"; + phys = <&comphy0 1>; +}; + &i2c0 { pinctrl-names = "default"; pinctrl-0 = <&i2c1_pins>; @@ -222,6 +209,7 @@ &usb3 { vbus-supply = <®_usb3_vbus>; status = "okay"; + phys = <&comphy2 0>; };
&pcie0 { @@ -229,4 +217,5 @@ pinctrl-0 = <&pcie_pins>; reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "disabled"; + phys = <&comphy1 0>; }; diff --git a/arch/arm/dts/armada-3720-uDPU.dts b/arch/arm/dts/armada-3720-uDPU.dts index 4bf6d2eac7..58557c680a 100644 --- a/arch/arm/dts/armada-3720-uDPU.dts +++ b/arch/arm/dts/armada-3720-uDPU.dts @@ -106,36 +106,21 @@ }; };
-&comphy { - phy0 { - phy-type = <COMPHY_TYPE_SGMII1>; - phy-speed = <COMPHY_SPEED_1_25G>; - }; - - phy1 { - phy-type = <COMPHY_TYPE_SGMII0>; - phy-speed = <COMPHY_SPEED_1_25G>; - }; - - phy2 { - phy-type = <COMPHY_TYPE_USB3_HOST1>; - phy-speed = <COMPHY_SPEED_5G>; - }; -}; - ð0 { pinctrl-0 = <&pcie_pins>; status = "okay"; - phy-mode = "2500base-x"; + phy-mode = "sgmii"; managed = "in-band-status"; phy = <ðphy0>; + phys = <&comphy1 0>; };
ð1 { status = "okay"; - phy-mode = "2500base-x"; + phy-mode = "sgmii"; managed = "in-band-status"; phy = <ðphy1>; + phys = <&comphy0 1>; };
&i2c0 { diff --git a/arch/arm/dts/armada-37xx.dtsi b/arch/arm/dts/armada-37xx.dtsi index fec34609cf..bef6ef03df 100644 --- a/arch/arm/dts/armada-37xx.dtsi +++ b/arch/arm/dts/armada-37xx.dtsi @@ -316,9 +316,23 @@ compatible = "marvell,mvebu-comphy", "marvell,comphy-armada-3700"; reg = <0x18300 0x28>, <0x1f300 0x3d000>; - mux-bitcount = <4>; - mux-lane-order = <1 0 2>; - max-lanes = <3>; + #address-cells = <1>; + #size-cells = <0>; + + comphy0: phy@0 { + reg = <0>; + #phy-cells = <1>; + }; + + comphy1: phy@1 { + reg = <1>; + #phy-cells = <1>; + }; + + comphy2: phy@2 { + reg = <2>; + #phy-cells = <1>; + }; }; };
diff --git a/drivers/phy/marvell/comphy_a3700.c b/drivers/phy/marvell/comphy_a3700.c index 047c8bb045..4104353555 100644 --- a/drivers/phy/marvell/comphy_a3700.c +++ b/drivers/phy/marvell/comphy_a3700.c @@ -11,6 +11,7 @@ #include <asm/arch/cpu.h> #include <asm/arch/soc.h> #include <linux/delay.h> +#include <phy.h>
#include "comphy_a3700.h"
@@ -982,6 +983,138 @@ void comphy_dedicated_phys_init(void) debug_exit(); }
+static int find_available_node_by_compatible(int offset, const char *compatible) +{ + do { + offset = fdt_node_offset_by_compatible(gd->fdt_blob, offset, + compatible); + } while (offset > 0 && !fdtdec_get_is_enabled(gd->fdt_blob, offset)); + + return offset; +} + +static bool comphy_a3700_find_lane(const int nodes[3], int node, + int port, int *lane, int *invert) +{ + int res, i, j; + + for (i = 0; ; i++) { + struct fdtdec_phandle_args args; + + res = fdtdec_parse_phandle_with_args(gd->fdt_blob, node, "phys", + "#phy-cells", 0, i, &args); + if (res) + return false; + + for (j = 0; j < 3; j++) { + if (nodes[j] >= 0 && args.node == nodes[j] && + (args.args_count >= 1 ? args.args[0] : 0) == port) { + *lane = j; + *invert = args.args_count >= 2 ? args.args[1] + : 0; + return true; + } + } + } + + return false; +} + +static void comphy_a3700_fill_cfg(struct chip_serdes_phy_config *cfg, + const int nodes[3], const char *compatible, + int type) +{ + int node, lane, port, speed, invert; + + port = (type == COMPHY_TYPE_SGMII1) ? 1 : 0; + + node = -1; + while (1) { + node = find_available_node_by_compatible(node, compatible); + if (node < 0) + return; + + if (comphy_a3700_find_lane(nodes, node, port, &lane, &invert)) + break; + } + + if (cfg->comphy_map_data[lane].type != COMPHY_TYPE_UNCONNECTED) { + printf("Error: More PHYs defined for lane %d, skipping\n", + lane); + return; + } + + if (type == COMPHY_TYPE_SGMII0 || type == COMPHY_TYPE_SGMII1) { + const char *phy_mode; + + phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); + if (phy_mode && + !strcmp(phy_mode, + phy_string_for_interface(PHY_INTERFACE_MODE_2500BASEX))) + speed = COMPHY_SPEED_3_125G; + else + speed = COMPHY_SPEED_1_25G; + } else if (type == COMPHY_TYPE_SATA0) { + speed = COMPHY_SPEED_6G; + } else { + speed = COMPHY_SPEED_5G; + } + + cfg->comphy_map_data[lane].type = type; + cfg->comphy_map_data[lane].speed = speed; + cfg->comphy_map_data[lane].invert = invert; +} + +static const fdt32_t comphy_a3700_mux_lane_order[3] = { + __constant_cpu_to_be32(1), + __constant_cpu_to_be32(0), + __constant_cpu_to_be32(2), +}; + +int comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{ + int comphy_nodes[3]; + int child, i; + + for (i = 0; i < ARRAY_SIZE(comphy_nodes); i++) + comphy_nodes[i] = -FDT_ERR_NOTFOUND; + + fdt_for_each_subnode(child, gd->fdt_blob, node) { + if (!fdtdec_get_is_enabled(gd->fdt_blob, child)) + continue; + + i = fdtdec_get_int(gd->fdt_blob, child, "reg", -1); + if (i < 0 || i >= ARRAY_SIZE(comphy_nodes)) + continue; + + comphy_nodes[i] = child; + } + + for (i = 0; i < ARRAY_SIZE(comphy_nodes); i++) { + cfg->comphy_map_data[i].type = COMPHY_TYPE_UNCONNECTED; + cfg->comphy_map_data[i].speed = COMPHY_SPEED_INVALID; + } + + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada3700-u3d", + COMPHY_TYPE_USB3_DEVICE); + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada3700-xhci", + COMPHY_TYPE_USB3_HOST0); + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-pcie", + COMPHY_TYPE_PEX0); + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-ahci", + COMPHY_TYPE_SATA0); + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-neta", + COMPHY_TYPE_SGMII0); + comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-neta", + COMPHY_TYPE_SGMII1); + + cfg->comphy_lanes_count = 3; + cfg->comphy_mux_bitcount = 4; + cfg->comphy_mux_lane_order = comphy_a3700_mux_lane_order; + + return 0; +} + int comphy_a3700_init(struct chip_serdes_phy_config *chip_cfg, struct comphy_map *serdes_map) { diff --git a/drivers/phy/marvell/comphy_core.c b/drivers/phy/marvell/comphy_core.c index 2c9d7b2288..233a973035 100644 --- a/drivers/phy/marvell/comphy_core.c +++ b/drivers/phy/marvell/comphy_core.c @@ -86,11 +86,8 @@ __weak int comphy_update_map(struct comphy_map *serdes_map, int count)
static int comphy_probe(struct udevice *dev) { - const void *blob = gd->fdt_blob; int node = dev_of_offset(dev); struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev); - int subnode; - int lane; int last_idx = 0; static int current_idx; int res; @@ -104,30 +101,14 @@ static int comphy_probe(struct udevice *dev) if (IS_ERR(chip_cfg->hpipe3_base_addr)) return PTR_ERR(chip_cfg->hpipe3_base_addr);
- chip_cfg->comphy_lanes_count = fdtdec_get_int(blob, node, - "max-lanes", 0); - if (chip_cfg->comphy_lanes_count <= 0) { - dev_err(dev, "comphy max lanes is wrong\n"); - return -EINVAL; - } - - chip_cfg->comphy_mux_bitcount = fdtdec_get_int(blob, node, - "mux-bitcount", 0); - if (chip_cfg->comphy_mux_bitcount <= 0) { - dev_err(dev, "comphy mux bit count is wrong\n"); - return -EINVAL; - } - - chip_cfg->comphy_mux_lane_order = - fdtdec_locate_array(blob, node, "mux-lane-order", - chip_cfg->comphy_lanes_count); - if (device_is_compatible(dev, "marvell,comphy-armada-3700")) { + chip_cfg->comphy_init_map = comphy_a3700_init_serdes_map; chip_cfg->ptr_comphy_chip_init = comphy_a3700_init; chip_cfg->rx_training = NULL; }
if (device_is_compatible(dev, "marvell,comphy-cp110")) { + chip_cfg->comphy_init_map = comphy_cp110_init_serdes_map; chip_cfg->ptr_comphy_chip_init = comphy_cp110_init; chip_cfg->rx_training = comphy_cp110_sfi_rx_training; } @@ -141,39 +122,9 @@ static int comphy_probe(struct udevice *dev) return -ENODEV; }
- lane = 0; - fdt_for_each_subnode(subnode, blob, node) { - /* Skip disabled ports */ - if (!fdtdec_get_is_enabled(blob, subnode)) - continue; - - chip_cfg->comphy_map_data[lane].type = - fdtdec_get_int(blob, subnode, "phy-type", - COMPHY_TYPE_INVALID); - - if (chip_cfg->comphy_map_data[lane].type == - COMPHY_TYPE_INVALID) { - printf("no phy type for lane %d, setting lane as unconnected\n", - lane + 1); - continue; - } - - chip_cfg->comphy_map_data[lane].speed = - fdtdec_get_int(blob, subnode, "phy-speed", - COMPHY_SPEED_INVALID); - - chip_cfg->comphy_map_data[lane].invert = - fdtdec_get_int(blob, subnode, "phy-invert", - COMPHY_POLARITY_NO_INVERT); - - chip_cfg->comphy_map_data[lane].clk_src = - fdtdec_get_bool(blob, subnode, "clk-src"); - - chip_cfg->comphy_map_data[lane].end_point = - fdtdec_get_bool(blob, subnode, "end_point"); - - lane++; - } + res = chip_cfg->comphy_init_map(node, chip_cfg); + if (res < 0) + return res;
res = comphy_update_map(chip_cfg->comphy_map_data, chip_cfg->comphy_lanes_count); if (res < 0) diff --git a/drivers/phy/marvell/comphy_core.h b/drivers/phy/marvell/comphy_core.h index 9bbd7f8f35..d573776c05 100644 --- a/drivers/phy/marvell/comphy_core.h +++ b/drivers/phy/marvell/comphy_core.h @@ -32,6 +32,7 @@ struct comphy_mux_data {
struct chip_serdes_phy_config { struct comphy_mux_data *mux_data; + int (*comphy_init_map)(int, struct chip_serdes_phy_config *); int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *, struct comphy_map *); int (*rx_training)(struct chip_serdes_phy_config *, u32); @@ -85,9 +86,20 @@ static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
/* SoC specific init functions */ #ifdef CONFIG_ARMADA_3700 +int comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg); int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map); #else +static inline int +comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{ + /* + * This function should never be called in this configuration, so + * lets return an error here. + */ + return -1; +} + static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) { @@ -100,11 +112,22 @@ static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, #endif
#ifdef CONFIG_ARMADA_8K +int comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg); int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map); int comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config *ptr_chip_cfg, u32 lane); #else +static inline int +comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{ + /* + * This function should never be called in this configuration, so + * lets return an error here. + */ + return -1; +} + static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) { diff --git a/drivers/phy/marvell/comphy_cp110.c b/drivers/phy/marvell/comphy_cp110.c index 4fe2dfcdd1..e063b51c6d 100644 --- a/drivers/phy/marvell/comphy_cp110.c +++ b/drivers/phy/marvell/comphy_cp110.c @@ -554,6 +554,64 @@ void comphy_dedicated_phys_init(void) debug_exit(); }
+int comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{ + int lane, subnode; + + cfg->comphy_lanes_count = fdtdec_get_int(gd->fdt_blob, node, + "max-lanes", 0); + if (cfg->comphy_lanes_count <= 0) { + printf("comphy max lanes is wrong\n"); + return -EINVAL; + } + + cfg->comphy_mux_bitcount = fdtdec_get_int(gd->fdt_blob, node, + "mux-bitcount", 0); + if (cfg->comphy_mux_bitcount <= 0) { + printf("comphy mux bit count is wrong\n"); + return -EINVAL; + } + + cfg->comphy_mux_lane_order = fdtdec_locate_array(gd->fdt_blob, node, + "mux-lane-order", + cfg->comphy_lanes_count); + + lane = 0; + fdt_for_each_subnode(subnode, gd->fdt_blob, node) { + /* Skip disabled ports */ + if (!fdtdec_get_is_enabled(gd->fdt_blob, subnode)) + continue; + + cfg->comphy_map_data[lane].type = + fdtdec_get_int(gd->fdt_blob, subnode, "phy-type", + COMPHY_TYPE_INVALID); + + if (cfg->comphy_map_data[lane].type == COMPHY_TYPE_INVALID) { + printf("no phy type for lane %d, setting lane as unconnected\n", + lane + 1); + continue; + } + + cfg->comphy_map_data[lane].speed = + fdtdec_get_int(gd->fdt_blob, subnode, "phy-speed", + COMPHY_SPEED_INVALID); + + cfg->comphy_map_data[lane].invert = + fdtdec_get_int(gd->fdt_blob, subnode, "phy-invert", + COMPHY_POLARITY_NO_INVERT); + + cfg->comphy_map_data[lane].clk_src = + fdtdec_get_bool(gd->fdt_blob, subnode, "clk-src"); + + cfg->comphy_map_data[lane].end_point = + fdtdec_get_bool(gd->fdt_blob, subnode, "end_point"); + + lane++; + } + + return 0; +} + int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) {

On 11/3/21 03:02, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Convert A3720 common PHY driver to official DT bindings.
This puts us closer to be able to synchronize A3720 device-trees with those from Linux.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz
arch/arm/dts/armada-3720-espressobin.dts | 21 +--- arch/arm/dts/armada-3720-turris-mox.dts | 25 ++--- arch/arm/dts/armada-3720-uDPU.dts | 23 +--- arch/arm/dts/armada-37xx.dtsi | 20 +++- drivers/phy/marvell/comphy_a3700.c | 133 +++++++++++++++++++++++ drivers/phy/marvell/comphy_core.c | 59 +--------- drivers/phy/marvell/comphy_core.h | 23 ++++ drivers/phy/marvell/comphy_cp110.c | 58 ++++++++++ 8 files changed, 250 insertions(+), 112 deletions(-)
Frankly, these changes are huge and hard for me to review.
Could you please add board maintainers to such patches, that are affected here? Like the developers form Sartura as maintainers for the armada-3720-uDPU.
Thanks, Stefan
diff --git a/arch/arm/dts/armada-3720-espressobin.dts b/arch/arm/dts/armada-3720-espressobin.dts index cba6139be6..360d521bba 100644 --- a/arch/arm/dts/armada-3720-espressobin.dts +++ b/arch/arm/dts/armada-3720-espressobin.dts @@ -80,24 +80,6 @@ }; };
-&comphy {
- max-lanes = <3>;
- phy0 {
phy-type = <COMPHY_TYPE_USB3_HOST0>;
phy-speed = <COMPHY_SPEED_5G>;
- };
- phy1 {
phy-type = <COMPHY_TYPE_PEX0>;
phy-speed = <COMPHY_SPEED_2_5G>;
- };
- phy2 {
phy-type = <COMPHY_TYPE_SATA0>;
phy-speed = <COMPHY_SPEED_5G>;
- };
-};
- ð0 { status = "okay"; pinctrl-names = "default";
@@ -119,6 +101,7 @@ /* CON3 */ &sata { status = "okay";
phys = <&comphy2 0>; };
&sdhci0 {
@@ -200,6 +183,7 @@ /* CON31 */ &usb3 { status = "okay";
phys = <&comphy0 0>; };
&pcie0 {
@@ -207,4 +191,5 @@ pinctrl-0 = <&pcie_pins>; reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "okay";
- phys = <&comphy1 0>; };
diff --git a/arch/arm/dts/armada-3720-turris-mox.dts b/arch/arm/dts/armada-3720-turris-mox.dts index f47ced05c5..d01757062f 100644 --- a/arch/arm/dts/armada-3720-turris-mox.dts +++ b/arch/arm/dts/armada-3720-turris-mox.dts @@ -94,24 +94,6 @@ }; };
-&comphy {
- max-lanes = <3>;
- phy0 {
phy-type = <COMPHY_TYPE_SGMII1>;
phy-speed = <COMPHY_SPEED_3_125G>;
- };
- phy1 {
phy-type = <COMPHY_TYPE_PEX0>;
phy-speed = <COMPHY_SPEED_5G>;
- };
- phy2 {
phy-type = <COMPHY_TYPE_USB3_HOST0>;
phy-speed = <COMPHY_SPEED_5G>;
- };
-};
- ð0 { status = "okay"; pinctrl-names = "default";
@@ -120,6 +102,11 @@ phy = <ð_phy1>; };
+ð1 {
- phy-mode = "2500base-x";
- phys = <&comphy0 1>;
+};
- &i2c0 { pinctrl-names = "default"; pinctrl-0 = <&i2c1_pins>;
@@ -222,6 +209,7 @@ &usb3 { vbus-supply = <®_usb3_vbus>; status = "okay";
phys = <&comphy2 0>; };
&pcie0 {
@@ -229,4 +217,5 @@ pinctrl-0 = <&pcie_pins>; reset-gpios = <&gpiosb 3 GPIO_ACTIVE_LOW>; status = "disabled";
- phys = <&comphy1 0>; };
diff --git a/arch/arm/dts/armada-3720-uDPU.dts b/arch/arm/dts/armada-3720-uDPU.dts index 4bf6d2eac7..58557c680a 100644 --- a/arch/arm/dts/armada-3720-uDPU.dts +++ b/arch/arm/dts/armada-3720-uDPU.dts @@ -106,36 +106,21 @@ }; };
-&comphy {
- phy0 {
phy-type = <COMPHY_TYPE_SGMII1>;
phy-speed = <COMPHY_SPEED_1_25G>;
- };
- phy1 {
phy-type = <COMPHY_TYPE_SGMII0>;
phy-speed = <COMPHY_SPEED_1_25G>;
- };
- phy2 {
phy-type = <COMPHY_TYPE_USB3_HOST1>;
phy-speed = <COMPHY_SPEED_5G>;
- };
-};
- ð0 { pinctrl-0 = <&pcie_pins>; status = "okay";
- phy-mode = "2500base-x";
phy-mode = "sgmii"; managed = "in-band-status"; phy = <ðphy0>;
phys = <&comphy1 0>; };
ð1 { status = "okay";
- phy-mode = "2500base-x";
phy-mode = "sgmii"; managed = "in-band-status"; phy = <ðphy1>;
phys = <&comphy0 1>; };
&i2c0 {
diff --git a/arch/arm/dts/armada-37xx.dtsi b/arch/arm/dts/armada-37xx.dtsi index fec34609cf..bef6ef03df 100644 --- a/arch/arm/dts/armada-37xx.dtsi +++ b/arch/arm/dts/armada-37xx.dtsi @@ -316,9 +316,23 @@ compatible = "marvell,mvebu-comphy", "marvell,comphy-armada-3700"; reg = <0x18300 0x28>, <0x1f300 0x3d000>;
mux-bitcount = <4>;
mux-lane-order = <1 0 2>;
max-lanes = <3>;
#address-cells = <1>;
#size-cells = <0>;
comphy0: phy@0 {
reg = <0>;
#phy-cells = <1>;
};
comphy1: phy@1 {
reg = <1>;
#phy-cells = <1>;
};
comphy2: phy@2 {
reg = <2>;
#phy-cells = <1>;
};}; };
diff --git a/drivers/phy/marvell/comphy_a3700.c b/drivers/phy/marvell/comphy_a3700.c index 047c8bb045..4104353555 100644 --- a/drivers/phy/marvell/comphy_a3700.c +++ b/drivers/phy/marvell/comphy_a3700.c @@ -11,6 +11,7 @@ #include <asm/arch/cpu.h> #include <asm/arch/soc.h> #include <linux/delay.h> +#include <phy.h>
#include "comphy_a3700.h"
@@ -982,6 +983,138 @@ void comphy_dedicated_phys_init(void) debug_exit(); }
+static int find_available_node_by_compatible(int offset, const char *compatible) +{
- do {
offset = fdt_node_offset_by_compatible(gd->fdt_blob, offset,
compatible);
- } while (offset > 0 && !fdtdec_get_is_enabled(gd->fdt_blob, offset));
- return offset;
+}
+static bool comphy_a3700_find_lane(const int nodes[3], int node,
int port, int *lane, int *invert)
+{
- int res, i, j;
- for (i = 0; ; i++) {
struct fdtdec_phandle_args args;
res = fdtdec_parse_phandle_with_args(gd->fdt_blob, node, "phys",
"#phy-cells", 0, i, &args);
if (res)
return false;
for (j = 0; j < 3; j++) {
if (nodes[j] >= 0 && args.node == nodes[j] &&
(args.args_count >= 1 ? args.args[0] : 0) == port) {
*lane = j;
*invert = args.args_count >= 2 ? args.args[1]
: 0;
return true;
}
}
- }
- return false;
+}
+static void comphy_a3700_fill_cfg(struct chip_serdes_phy_config *cfg,
const int nodes[3], const char *compatible,
int type)
+{
- int node, lane, port, speed, invert;
- port = (type == COMPHY_TYPE_SGMII1) ? 1 : 0;
- node = -1;
- while (1) {
node = find_available_node_by_compatible(node, compatible);
if (node < 0)
return;
if (comphy_a3700_find_lane(nodes, node, port, &lane, &invert))
break;
- }
- if (cfg->comphy_map_data[lane].type != COMPHY_TYPE_UNCONNECTED) {
printf("Error: More PHYs defined for lane %d, skipping\n",
lane);
return;
- }
- if (type == COMPHY_TYPE_SGMII0 || type == COMPHY_TYPE_SGMII1) {
const char *phy_mode;
phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
if (phy_mode &&
!strcmp(phy_mode,
phy_string_for_interface(PHY_INTERFACE_MODE_2500BASEX)))
speed = COMPHY_SPEED_3_125G;
else
speed = COMPHY_SPEED_1_25G;
- } else if (type == COMPHY_TYPE_SATA0) {
speed = COMPHY_SPEED_6G;
- } else {
speed = COMPHY_SPEED_5G;
- }
- cfg->comphy_map_data[lane].type = type;
- cfg->comphy_map_data[lane].speed = speed;
- cfg->comphy_map_data[lane].invert = invert;
+}
+static const fdt32_t comphy_a3700_mux_lane_order[3] = {
- __constant_cpu_to_be32(1),
- __constant_cpu_to_be32(0),
- __constant_cpu_to_be32(2),
+};
+int comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{
- int comphy_nodes[3];
- int child, i;
- for (i = 0; i < ARRAY_SIZE(comphy_nodes); i++)
comphy_nodes[i] = -FDT_ERR_NOTFOUND;
- fdt_for_each_subnode(child, gd->fdt_blob, node) {
if (!fdtdec_get_is_enabled(gd->fdt_blob, child))
continue;
i = fdtdec_get_int(gd->fdt_blob, child, "reg", -1);
if (i < 0 || i >= ARRAY_SIZE(comphy_nodes))
continue;
comphy_nodes[i] = child;
- }
- for (i = 0; i < ARRAY_SIZE(comphy_nodes); i++) {
cfg->comphy_map_data[i].type = COMPHY_TYPE_UNCONNECTED;
cfg->comphy_map_data[i].speed = COMPHY_SPEED_INVALID;
- }
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada3700-u3d",
COMPHY_TYPE_USB3_DEVICE);
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada3700-xhci",
COMPHY_TYPE_USB3_HOST0);
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-pcie",
COMPHY_TYPE_PEX0);
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-ahci",
COMPHY_TYPE_SATA0);
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-neta",
COMPHY_TYPE_SGMII0);
- comphy_a3700_fill_cfg(cfg, comphy_nodes, "marvell,armada-3700-neta",
COMPHY_TYPE_SGMII1);
- cfg->comphy_lanes_count = 3;
- cfg->comphy_mux_bitcount = 4;
- cfg->comphy_mux_lane_order = comphy_a3700_mux_lane_order;
- return 0;
+}
- int comphy_a3700_init(struct chip_serdes_phy_config *chip_cfg, struct comphy_map *serdes_map) {
diff --git a/drivers/phy/marvell/comphy_core.c b/drivers/phy/marvell/comphy_core.c index 2c9d7b2288..233a973035 100644 --- a/drivers/phy/marvell/comphy_core.c +++ b/drivers/phy/marvell/comphy_core.c @@ -86,11 +86,8 @@ __weak int comphy_update_map(struct comphy_map *serdes_map, int count)
static int comphy_probe(struct udevice *dev) {
- const void *blob = gd->fdt_blob; int node = dev_of_offset(dev); struct chip_serdes_phy_config *chip_cfg = dev_get_priv(dev);
- int subnode;
- int lane; int last_idx = 0; static int current_idx; int res;
@@ -104,30 +101,14 @@ static int comphy_probe(struct udevice *dev) if (IS_ERR(chip_cfg->hpipe3_base_addr)) return PTR_ERR(chip_cfg->hpipe3_base_addr);
- chip_cfg->comphy_lanes_count = fdtdec_get_int(blob, node,
"max-lanes", 0);
- if (chip_cfg->comphy_lanes_count <= 0) {
dev_err(dev, "comphy max lanes is wrong\n");
return -EINVAL;
- }
- chip_cfg->comphy_mux_bitcount = fdtdec_get_int(blob, node,
"mux-bitcount", 0);
- if (chip_cfg->comphy_mux_bitcount <= 0) {
dev_err(dev, "comphy mux bit count is wrong\n");
return -EINVAL;
- }
- chip_cfg->comphy_mux_lane_order =
fdtdec_locate_array(blob, node, "mux-lane-order",
chip_cfg->comphy_lanes_count);
- if (device_is_compatible(dev, "marvell,comphy-armada-3700")) {
chip_cfg->comphy_init_map = comphy_a3700_init_serdes_map;
chip_cfg->ptr_comphy_chip_init = comphy_a3700_init; chip_cfg->rx_training = NULL; }
if (device_is_compatible(dev, "marvell,comphy-cp110")) {
chip_cfg->comphy_init_map = comphy_cp110_init_serdes_map;
chip_cfg->ptr_comphy_chip_init = comphy_cp110_init; chip_cfg->rx_training = comphy_cp110_sfi_rx_training; }
@@ -141,39 +122,9 @@ static int comphy_probe(struct udevice *dev) return -ENODEV; }
- lane = 0;
- fdt_for_each_subnode(subnode, blob, node) {
/* Skip disabled ports */
if (!fdtdec_get_is_enabled(blob, subnode))
continue;
chip_cfg->comphy_map_data[lane].type =
fdtdec_get_int(blob, subnode, "phy-type",
COMPHY_TYPE_INVALID);
if (chip_cfg->comphy_map_data[lane].type ==
COMPHY_TYPE_INVALID) {
printf("no phy type for lane %d, setting lane as unconnected\n",
lane + 1);
continue;
}
chip_cfg->comphy_map_data[lane].speed =
fdtdec_get_int(blob, subnode, "phy-speed",
COMPHY_SPEED_INVALID);
chip_cfg->comphy_map_data[lane].invert =
fdtdec_get_int(blob, subnode, "phy-invert",
COMPHY_POLARITY_NO_INVERT);
chip_cfg->comphy_map_data[lane].clk_src =
fdtdec_get_bool(blob, subnode, "clk-src");
chip_cfg->comphy_map_data[lane].end_point =
fdtdec_get_bool(blob, subnode, "end_point");
lane++;
- }
res = chip_cfg->comphy_init_map(node, chip_cfg);
if (res < 0)
return res;
res = comphy_update_map(chip_cfg->comphy_map_data, chip_cfg->comphy_lanes_count); if (res < 0)
diff --git a/drivers/phy/marvell/comphy_core.h b/drivers/phy/marvell/comphy_core.h index 9bbd7f8f35..d573776c05 100644 --- a/drivers/phy/marvell/comphy_core.h +++ b/drivers/phy/marvell/comphy_core.h @@ -32,6 +32,7 @@ struct comphy_mux_data {
struct chip_serdes_phy_config { struct comphy_mux_data *mux_data;
- int (*comphy_init_map)(int, struct chip_serdes_phy_config *); int (*ptr_comphy_chip_init)(struct chip_serdes_phy_config *, struct comphy_map *); int (*rx_training)(struct chip_serdes_phy_config *, u32);
@@ -85,9 +86,20 @@ static inline void reg_set16(void __iomem *addr, u16 data, u16 mask)
/* SoC specific init functions */ #ifdef CONFIG_ARMADA_3700 +int comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg); int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map); #else +static inline int +comphy_a3700_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{
- /*
* This function should never be called in this configuration, so
* lets return an error here.
*/
- return -1;
+}
- static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) {
@@ -100,11 +112,22 @@ static inline int comphy_a3700_init(struct chip_serdes_phy_config *ptr_chip_cfg, #endif
#ifdef CONFIG_ARMADA_8K +int comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg); int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map); int comphy_cp110_sfi_rx_training(struct chip_serdes_phy_config *ptr_chip_cfg, u32 lane); #else +static inline int +comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{
- /*
* This function should never be called in this configuration, so
* lets return an error here.
*/
- return -1;
+}
- static inline int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) {
diff --git a/drivers/phy/marvell/comphy_cp110.c b/drivers/phy/marvell/comphy_cp110.c index 4fe2dfcdd1..e063b51c6d 100644 --- a/drivers/phy/marvell/comphy_cp110.c +++ b/drivers/phy/marvell/comphy_cp110.c @@ -554,6 +554,64 @@ void comphy_dedicated_phys_init(void) debug_exit(); }
+int comphy_cp110_init_serdes_map(int node, struct chip_serdes_phy_config *cfg) +{
- int lane, subnode;
- cfg->comphy_lanes_count = fdtdec_get_int(gd->fdt_blob, node,
"max-lanes", 0);
- if (cfg->comphy_lanes_count <= 0) {
printf("comphy max lanes is wrong\n");
return -EINVAL;
- }
- cfg->comphy_mux_bitcount = fdtdec_get_int(gd->fdt_blob, node,
"mux-bitcount", 0);
- if (cfg->comphy_mux_bitcount <= 0) {
printf("comphy mux bit count is wrong\n");
return -EINVAL;
- }
- cfg->comphy_mux_lane_order = fdtdec_locate_array(gd->fdt_blob, node,
"mux-lane-order",
cfg->comphy_lanes_count);
- lane = 0;
- fdt_for_each_subnode(subnode, gd->fdt_blob, node) {
/* Skip disabled ports */
if (!fdtdec_get_is_enabled(gd->fdt_blob, subnode))
continue;
cfg->comphy_map_data[lane].type =
fdtdec_get_int(gd->fdt_blob, subnode, "phy-type",
COMPHY_TYPE_INVALID);
if (cfg->comphy_map_data[lane].type == COMPHY_TYPE_INVALID) {
printf("no phy type for lane %d, setting lane as unconnected\n",
lane + 1);
continue;
}
cfg->comphy_map_data[lane].speed =
fdtdec_get_int(gd->fdt_blob, subnode, "phy-speed",
COMPHY_SPEED_INVALID);
cfg->comphy_map_data[lane].invert =
fdtdec_get_int(gd->fdt_blob, subnode, "phy-invert",
COMPHY_POLARITY_NO_INVERT);
cfg->comphy_map_data[lane].clk_src =
fdtdec_get_bool(gd->fdt_blob, subnode, "clk-src");
cfg->comphy_map_data[lane].end_point =
fdtdec_get_bool(gd->fdt_blob, subnode, "end_point");
lane++;
- }
- return 0;
+}
- int comphy_cp110_init(struct chip_serdes_phy_config *ptr_chip_cfg, struct comphy_map *serdes_map) {
Viele Grüße, Stefan Roese

On Fri, 12 Nov 2021 14:29:54 +0100 Stefan Roese sr@denx.de wrote:
On 11/3/21 03:02, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Convert A3720 common PHY driver to official DT bindings.
This puts us closer to be able to synchronize A3720 device-trees with those from Linux.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz
arch/arm/dts/armada-3720-espressobin.dts | 21 +--- arch/arm/dts/armada-3720-turris-mox.dts | 25 ++--- arch/arm/dts/armada-3720-uDPU.dts | 23 +--- arch/arm/dts/armada-37xx.dtsi | 20 +++- drivers/phy/marvell/comphy_a3700.c | 133 +++++++++++++++++++++++ drivers/phy/marvell/comphy_core.c | 59 +--------- drivers/phy/marvell/comphy_core.h | 23 ++++ drivers/phy/marvell/comphy_cp110.c | 58 ++++++++++ 8 files changed, 250 insertions(+), 112 deletions(-)
Frankly, these changes are huge and hard for me to review.
Could you please add board maintainers to such patches, that are affected here? Like the developers form Sartura as maintainers for the armada-3720-uDPU.
OK, Stefan, I will rensend this series with those maintainers added.
Marek

On 11/12/21 18:27, Marek Behún wrote:
On Fri, 12 Nov 2021 14:29:54 +0100 Stefan Roese sr@denx.de wrote:
On 11/3/21 03:02, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
Convert A3720 common PHY driver to official DT bindings.
This puts us closer to be able to synchronize A3720 device-trees with those from Linux.
Signed-off-by: Pali Rohár pali@kernel.org Signed-off-by: Marek Behún marek.behun@nic.cz
arch/arm/dts/armada-3720-espressobin.dts | 21 +--- arch/arm/dts/armada-3720-turris-mox.dts | 25 ++--- arch/arm/dts/armada-3720-uDPU.dts | 23 +--- arch/arm/dts/armada-37xx.dtsi | 20 +++- drivers/phy/marvell/comphy_a3700.c | 133 +++++++++++++++++++++++ drivers/phy/marvell/comphy_core.c | 59 +--------- drivers/phy/marvell/comphy_core.h | 23 ++++ drivers/phy/marvell/comphy_cp110.c | 58 ++++++++++ 8 files changed, 250 insertions(+), 112 deletions(-)
Frankly, these changes are huge and hard for me to review.
Could you please add board maintainers to such patches, that are affected here? Like the developers form Sartura as maintainers for the armada-3720-uDPU.
OK, Stefan, I will rensend this series with those maintainers added.
Yes, please wait a few more days and re-send this series with a broader Cc list then.
Thanks, Stefan

From: Marek Behún marek.behun@nic.cz
The pre-relocation board topology reading in board_fix_fdt() is unstable: sometimes wrong data are read from the SPI bus.
This is due to wrong order of SPI bus configuration instructions: we first need to set the pins to SPI mode, and only after that configure the bus.
Also add a 1ms delay before enabling chip-select, so that the clock pin is high for some time before reading the bus.
Signed-off-by: Marek Behún marek.behun@nic.cz --- board/CZ.NIC/turris_mox/turris_mox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 502f6fc010..809ce82d20 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -56,9 +56,11 @@ int board_fix_fdt(void *blob) * to read SPI by reading/writing SPI registers directly */
- writel(0x10df, ARMADA_37XX_SPI_CFG); /* put pin from GPIO to SPI mode */ clrbits_le32(ARMADA_37XX_NB_GPIO_SEL, BIT(12)); + /* configure cpol, cpha, prescale */ + writel(0x10df, ARMADA_37XX_SPI_CFG); + mdelay(1); /* enable SPI CS1 */ setbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
The pre-relocation board topology reading in board_fix_fdt() is unstable: sometimes wrong data are read from the SPI bus.
This is due to wrong order of SPI bus configuration instructions: we first need to set the pins to SPI mode, and only after that configure the bus.
Also add a 1ms delay before enabling chip-select, so that the clock pin is high for some time before reading the bus.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
board/CZ.NIC/turris_mox/turris_mox.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 502f6fc010..809ce82d20 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -56,9 +56,11 @@ int board_fix_fdt(void *blob) * to read SPI by reading/writing SPI registers directly */
- writel(0x10df, ARMADA_37XX_SPI_CFG); /* put pin from GPIO to SPI mode */ clrbits_le32(ARMADA_37XX_NB_GPIO_SEL, BIT(12));
- /* configure cpol, cpha, prescale */
- writel(0x10df, ARMADA_37XX_SPI_CFG);
- mdelay(1); /* enable SPI CS1 */ setbits_le32(ARMADA_37XX_SPI_CTRL, BIT(17));
Viele Grüße, Stefan Roese

From: Marek Behún marek.behun@nic.cz
Move Turris MOX specific remove_disabled_nodes() to fdt_support with name fdt_delete_disabled_nodes(), so that others can potentially use it.
Signed-off-by: Marek Behún marek.behun@nic.cz --- board/CZ.NIC/turris_mox/turris_mox.c | 20 +------------------- common/fdt_support.c | 23 +++++++++++++++++++++++ include/fdt_support.h | 2 ++ 3 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 809ce82d20..b61c5b1cb6 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -749,24 +749,6 @@ static int setup_switch(void *blob, int id) return 0; }
-static int remove_disabled_nodes(void *blob) -{ - while (1) { - int res, offset; - - offset = fdt_node_offset_by_prop_value(blob, -1, "status", - "disabled", 9); - if (offset < 0) - break; - - res = fdt_del_node(blob, offset); - if (res < 0) - return res; - } - - return 0; -} - int ft_board_setup(void *blob, struct bd_info *bd) { int res; @@ -872,7 +854,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) fdt_fixup_ethernet(blob);
/* Finally remove disabled nodes, as per Rob Herring's request. */ - remove_disabled_nodes(blob); + fdt_delete_disabled_nodes(blob);
return 0; } diff --git a/common/fdt_support.c b/common/fdt_support.c index c2e16727e1..b2ba0825df 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -695,6 +695,29 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize) return actualsize; }
+/** + * fdt_delete_disabled_nodes: Delete all nodes with status == "disabled" + * + * @blob: ptr to device tree + */ +int fdt_delete_disabled_nodes(void *blob) +{ + while (1) { + int ret, offset; + + offset = fdt_node_offset_by_prop_value(blob, -1, "status", + "disabled", 9); + if (offset < 0) + break; + + ret = fdt_del_node(blob, offset); + if (ret < 0) + return ret; + } + + return 0; +} + #ifdef CONFIG_PCI #define CONFIG_SYS_PCI_NR_INBOUND_WIN 4
diff --git a/include/fdt_support.h b/include/fdt_support.h index d40586725b..8ec461af6c 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -228,6 +228,8 @@ void set_working_fdt_addr(ulong addr); int fdt_shrink_to_minimum(void *blob, uint extrasize); int fdt_increase_size(void *fdt, int add_len);
+int fdt_delete_disabled_nodes(void *blob); + int fdt_fixup_nor_flash_size(void *blob);
struct node_info;

On 11/3/21 03:02, Marek Behún wrote:
From: Marek Behún marek.behun@nic.cz
Move Turris MOX specific remove_disabled_nodes() to fdt_support with name fdt_delete_disabled_nodes(), so that others can potentially use it.
Signed-off-by: Marek Behún marek.behun@nic.cz
Reviewed-by: Stefan Roese sr@denx.de
Thanks, Stefan
board/CZ.NIC/turris_mox/turris_mox.c | 20 +------------------- common/fdt_support.c | 23 +++++++++++++++++++++++ include/fdt_support.h | 2 ++ 3 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/board/CZ.NIC/turris_mox/turris_mox.c b/board/CZ.NIC/turris_mox/turris_mox.c index 809ce82d20..b61c5b1cb6 100644 --- a/board/CZ.NIC/turris_mox/turris_mox.c +++ b/board/CZ.NIC/turris_mox/turris_mox.c @@ -749,24 +749,6 @@ static int setup_switch(void *blob, int id) return 0; }
-static int remove_disabled_nodes(void *blob) -{
- while (1) {
int res, offset;
offset = fdt_node_offset_by_prop_value(blob, -1, "status",
"disabled", 9);
if (offset < 0)
break;
res = fdt_del_node(blob, offset);
if (res < 0)
return res;
- }
- return 0;
-}
- int ft_board_setup(void *blob, struct bd_info *bd) { int res;
@@ -872,7 +854,7 @@ int ft_board_setup(void *blob, struct bd_info *bd) fdt_fixup_ethernet(blob);
/* Finally remove disabled nodes, as per Rob Herring's request. */
- remove_disabled_nodes(blob);
fdt_delete_disabled_nodes(blob);
return 0; }
diff --git a/common/fdt_support.c b/common/fdt_support.c index c2e16727e1..b2ba0825df 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -695,6 +695,29 @@ int fdt_shrink_to_minimum(void *blob, uint extrasize) return actualsize; }
+/**
- fdt_delete_disabled_nodes: Delete all nodes with status == "disabled"
- @blob: ptr to device tree
- */
+int fdt_delete_disabled_nodes(void *blob) +{
- while (1) {
int ret, offset;
offset = fdt_node_offset_by_prop_value(blob, -1, "status",
"disabled", 9);
if (offset < 0)
break;
ret = fdt_del_node(blob, offset);
if (ret < 0)
return ret;
- }
- return 0;
+}
- #ifdef CONFIG_PCI #define CONFIG_SYS_PCI_NR_INBOUND_WIN 4
diff --git a/include/fdt_support.h b/include/fdt_support.h index d40586725b..8ec461af6c 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -228,6 +228,8 @@ void set_working_fdt_addr(ulong addr); int fdt_shrink_to_minimum(void *blob, uint extrasize); int fdt_increase_size(void *fdt, int add_len);
+int fdt_delete_disabled_nodes(void *blob);
int fdt_fixup_nor_flash_size(void *blob);
struct node_info;
Viele Grüße, Stefan Roese
participants (2)
-
Marek Behún
-
Stefan Roese