arm: mvebu: turris_mox: Find DT nodes by compatible or alias instead of path

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>
This commit is contained in:
Marek Behún
2021-11-26 14:57:11 +01:00
committed by Stefan Roese
parent 9ab0c2f837
commit bcf6971d53

View File

@@ -41,22 +41,14 @@
#define ARMADA_37XX_SPI_DOUT (MVEBU_REGISTER(0x10608)) #define ARMADA_37XX_SPI_DOUT (MVEBU_REGISTER(0x10608))
#define ARMADA_37XX_SPI_DIN (MVEBU_REGISTER(0x1060c)) #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; DECLARE_GLOBAL_DATA_PTR;
#if defined(CONFIG_OF_BOARD_FIXUP) #if defined(CONFIG_OF_BOARD_FIXUP)
int board_fix_fdt(void *blob) int board_fix_fdt(void *blob)
{ {
u8 topology[MAX_MOX_MODULES]; u8 topology[MAX_MOX_MODULES];
int i, size, node; enum fdt_status status;
bool enable; int i, size, ret;
/* /*
* SPI driver is not loaded in driver model yet, but we have to find out * 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 || if (size > 1 && (topology[1] == MOX_MODULE_PCI ||
topology[1] == MOX_MODULE_USB3 || topology[1] == MOX_MODULE_USB3 ||
topology[1] == MOX_MODULE_PASSPCI)) topology[1] == MOX_MODULE_PASSPCI))
enable = true; status = FDT_STATUS_OKAY;
else else
enable = false; status = FDT_STATUS_DISABLED;
node = fdt_path_offset(blob, PCIE_PATH); ret = fdt_set_status_by_compatible(blob, "marvell,armada-3700-pcie",
status);
if (node < 0) { if (ret < 0) {
printf("Cannot find PCIe node in U-Boot's device tree!\n"); printf("Cannot set status for PCIe in U-Boot's device tree: %s!\n",
return 0; fdt_strerror(ret));
}
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");
return 0; return 0;
} }
@@ -416,12 +402,18 @@ static bool read_reset_button(void)
struct udevice *button, *led; struct udevice *button, *led;
int i; 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"); printf("Cannot find reset button!\n");
return false; 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"); printf("Cannot find status LED!\n");
return false; return false;
} }
@@ -664,74 +656,6 @@ handle_reset_btn:
#if defined(CONFIG_OF_BOARD_SETUP) #if defined(CONFIG_OF_BOARD_SETUP)
static int vnode_by_path(void *blob, const char *fmt, va_list ap)
{
char path[128];
vsnprintf(path, 128, fmt, ap);
return fdt_path_offset(blob, path);
}
static int node_by_path(void *blob, const char *fmt, ...)
{
va_list ap;
int res;
va_start(ap, fmt);
res = vnode_by_path(blob, fmt, ap);
va_end(ap);
return res;
}
static int phandle_by_path(void *blob, const char *fmt, ...)
{
va_list ap;
int node, phandle, res;
va_start(ap, fmt);
node = vnode_by_path(blob, fmt, ap);
va_end(ap);
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);
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) static bool is_topaz(int id)
{ {
return topaz && id == peridot + topaz - 1; return topaz && id == peridot + topaz - 1;
@@ -744,12 +668,22 @@ static int switch_addr(int id)
static int setup_switch(void *blob, int id) static int setup_switch(void *blob, int id)
{ {
int res, addr, i, node, phandle; 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;
res = fdt_get_path(blob, node, mdio_path, sizeof(mdio_path));
if (res < 0)
return res;
addr = switch_addr(id); addr = switch_addr(id);
/* first enable the switch by setting status = "okay" */ /* 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) if (res < 0)
return res; return res;
@@ -758,13 +692,13 @@ static int setup_switch(void *blob, int id)
* enable corresponding ports * enable corresponding ports
*/ */
if (id < peridot + topaz - 1) { if (id < peridot + topaz - 1) {
res = enable_by_path(blob, res = fdt_status_okay_by_pathf(blob,
MDIO_PATH "/switch%i@%x/ports/port@a", "%s/switch%i@%x/ports/port@a",
id, addr); mdio_path, id, addr);
} else if (id == peridot - 1 && !topaz && sfp) { } else if (id == peridot - 1 && !topaz && sfp) {
res = enable_by_path(blob, res = fdt_status_okay_by_pathf(blob,
MDIO_PATH "/switch%i@%x/ports/port-sfp@a", "%s/switch%i@%x/ports/port-sfp@a",
id, addr); mdio_path, id, addr);
} else { } else {
res = 0; res = 0;
} }
@@ -775,18 +709,21 @@ static int setup_switch(void *blob, int id)
return 0; return 0;
/* finally change link property if needed */ /* finally change link property if needed */
node = node_by_path(blob, MDIO_PATH "/switch%i@%x/ports/port@a", id, node = fdt_node_offset_by_pathf(blob, "%s/switch%i@%x/ports/port@a",
addr); mdio_path, id, addr);
if (node < 0) if (node < 0)
return node; return node;
for (i = id + 1; i < peridot + topaz; ++i) { for (i = id + 1; i < peridot + topaz; ++i) {
phandle = phandle_by_path(blob, unsigned int phandle;
MDIO_PATH "/switch%i@%x/ports/port@%x",
i, switch_addr(i), phandle = fdt_create_phandle_by_pathf(blob,
is_topaz(i) ? 5 : 9); "%s/switch%i@%x/ports/port@%x",
if (phandle < 0) mdio_path, i,
return phandle; switch_addr(i),
is_topaz(i) ? 5 : 9);
if (!phandle)
return -FDT_ERR_NOPHANDLES;
if (i == id + 1) if (i == id + 1)
res = fdt_setprop_u32(blob, node, "link", phandle); 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 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 * If MOX B (PCI), MOX F (USB) or MOX G (Passthrough PCI) modules are
* connected, enable the PCIe node. * connected, enable the PCIe node.
*/ */
if (pci || usb || passpci) { if (pci || usb || passpci) {
node = fdt_path_offset(blob, PCIE_PATH); res = fdt_status_okay_by_compatible(blob,
if (node < 0) "marvell,armada-3700-pcie");
return node;
res = fdt_setprop_string(blob, node, "status", "okay");
if (res < 0) if (res < 0)
return res; return res;
@@ -847,7 +781,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
if (peridot || topaz) { if (peridot || topaz) {
int i; int i;
res = enable_by_path(blob, ETH1_PATH); res = fdt_status_okay_by_alias(blob, "ethernet1");
if (res < 0) if (res < 0)
return res; return res;
@@ -865,20 +799,25 @@ int ft_board_setup(void *blob, struct bd_info *bd)
* Also enable and configure SFP GPIO controller node. * Also enable and configure SFP GPIO controller node.
*/ */
if (sfp) { if (sfp) {
res = enable_by_path(blob, SFP_PATH); int node;
res = fdt_status_okay_by_compatible(blob, "sff,sfp");
if (res < 0) if (res < 0)
return res; return res;
res = enable_by_path(blob, ETH1_PATH); res = fdt_status_okay_by_alias(blob, "ethernet1");
if (res < 0) if (res < 0)
return res; return res;
if (!peridot) { if (!peridot) {
phandle = phandle_by_path(blob, SFP_PATH); unsigned int phandle;
if (phandle < 0)
return res;
node = node_by_path(blob, ETH1_PATH); phandle = fdt_create_phandle_by_compatible(blob,
"sff,sfp");
if (!phandle)
return -FDT_ERR_NOPHANDLES;
node = fdt_path_offset(blob, "ethernet1");
if (node < 0) if (node < 0)
return node; return node;
@@ -892,7 +831,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
return res; return res;
} }
res = enable_by_path(blob, SFP_GPIO_PATH); res = fdt_status_okay_by_compatible(blob, "cznic,moxtet-gpio");
if (res < 0) if (res < 0)
return res; return res;
@@ -900,7 +839,8 @@ int ft_board_setup(void *blob, struct bd_info *bd)
char newname[16]; char newname[16];
/* moxtet-sfp is on non-zero position, change default */ /* 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) if (node < 0)
return node; return node;