]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
net: ti: icssg: Read firmware name from device-tree
authorMD Danish Anwar <danishanwar@ti.com>
Wed, 2 Jul 2025 11:35:45 +0000 (17:05 +0530)
committerTom Rini <trini@konsulko.com>
Thu, 10 Jul 2025 14:41:18 +0000 (08:41 -0600)
Update the ICSSG PRU Ethernet driver to read PRU/RTU/TXPRU firmware names
from the Device Tree using the "firmware-name" property, instead of relying
on the hard-coded firmware names. The firmware names are parsed during
prueth_probe() and stored in the prueth->firmwares for each slice. The
driver now uses these dynamically loaded names when starting the PRU cores.

This change improves flexibility and allows firmware selection to be
controlled via the device tree, making the driver more adaptable to
different platforms and firmware configurations.

Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
drivers/net/ti/icssg_prueth.c
drivers/net/ti/icssg_prueth.h

index 2639f96063197c75aca996a68b70574959aa38b3..d8df3c9afb068e255ffd6d5080617c4b317fd9f9 100644 (file)
@@ -63,6 +63,7 @@
 
 /* Number of PRU Cores per Slice */
 #define ICSSG_NUM_PRU_CORES            3
+#define ICSSG_NUM_FIRMWARES            6
 
 static int icssg_gmii_select(struct prueth_priv *priv)
 {
@@ -192,25 +193,6 @@ static int icssg_update_link(struct prueth_priv *priv)
        return phy->link;
 }
 
-struct icssg_firmwares {
-       char *pru;
-       char *rtu;
-       char *txpru;
-};
-
-static struct icssg_firmwares icssg_emac_firmwares[] = {
-       {
-               .pru = "/lib/firmware/ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
-               .rtu = "/lib/firmware/ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
-               .txpru = "/lib/firmware/ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
-       },
-       {
-               .pru = "/lib/firmware/ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
-               .rtu = "/lib/firmware/ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
-               .txpru = "/lib/firmware/ti-pruss/am65x-sr2-txpru1-prueth-fw.elf",
-       }
-};
-
 static int icssg_start_pru_cores(struct udevice *dev)
 {
        struct prueth_priv *priv = dev_get_priv(dev);
@@ -223,7 +205,7 @@ static int icssg_start_pru_cores(struct udevice *dev)
 
        slice = priv->port_id;
        index = slice * ICSSG_NUM_PRU_CORES;
-       firmwares = icssg_emac_firmwares;
+       firmwares = prueth->firmwares;
 
        ofnode_read_u32_index(dev_ofnode(prueth->dev), "ti,prus", index, &phandle);
        ret = uclass_get_device_by_phandle_id(UCLASS_REMOTEPROC, phandle, &rproc_dev);
@@ -476,6 +458,24 @@ static const struct eth_ops prueth_ops = {
        .stop           = prueth_stop,
 };
 
+static char *prepend_fw_path(const char *fw_name)
+{
+       static const char fw_dir[] = "/lib/firmware/";
+       char *result;
+       int len;
+
+       if (!fw_name)
+               return NULL;
+
+       len = strlen(fw_dir) + strlen(fw_name) + 1;
+       result = malloc(len);
+       if (!result)
+               return NULL;
+
+       sprintf(result, "%s%s", fw_dir, fw_name);
+       return result;
+}
+
 static int icssg_ofdata_parse_phy(struct udevice *dev)
 {
        struct prueth_priv *priv = dev_get_priv(dev);
@@ -534,6 +534,8 @@ static int prueth_probe(struct udevice *dev)
        struct udevice **prussdev = NULL;
        ofnode eth_ports_node, eth_node;
        struct udevice *port_dev;
+       const char **fw_names;
+       int fw_count, i;
        int ret = 0;
 
        prueth->dev = dev;
@@ -659,6 +661,18 @@ static int prueth_probe(struct udevice *dev)
                }
        }
 
+       /* Parse firmware-name property from DT */
+       fw_count = dev_read_string_list(dev, "firmware-name", &fw_names);
+       if (fw_count != ICSSG_NUM_FIRMWARES) {
+               dev_err(dev, "Expected %d firmware names, got %d\n", ICSSG_NUM_FIRMWARES, fw_count);
+               return -EINVAL;
+       }
+       for (i = 0; i < 2; i++) {
+               prueth->firmwares[i].pru   = prepend_fw_path(fw_names[i * 3 + 0]);
+               prueth->firmwares[i].rtu   = prepend_fw_path(fw_names[i * 3 + 1]);
+               prueth->firmwares[i].txpru = prepend_fw_path(fw_names[i * 3 + 2]);
+       }
+
        return 0;
 out:
        clk_disable(&prueth->mdiofck);
index c69cfd4f162215ed7c144bef5c97f0b438846364..d88b6fa88e76ea1ce2c416c2ee22825d8166d959 100644 (file)
@@ -38,6 +38,12 @@ enum prueth_port {
        PRUETH_PORT_MII1,       /* physical port MII 1 */
 };
 
+struct icssg_firmwares {
+       char *pru;
+       char *rtu;
+       char *txpru;
+};
+
 struct prueth {
        struct udevice          *dev;
        struct udevice          *pruss;
@@ -66,6 +72,7 @@ struct prueth {
        u8                      rtu_core_id;
        u8                      txpru_core_id;
        u8                      icssg_hwcmdseq;
+       struct icssg_firmwares  firmwares[PRUETH_NUM_MACS];
 };
 
 struct prueth_priv {