soc: microchip: mpfs: enable access to the system controller's flash
authorConor Dooley <conor.dooley@microchip.com>
Fri, 20 Oct 2023 13:18:40 +0000 (14:18 +0100)
committerConor Dooley <conor.dooley@microchip.com>
Wed, 6 Dec 2023 12:06:18 +0000 (12:06 +0000)
The system controller has a flash that contains images used to reprogram
the FPGA using IAP (In-Application Programming).
Introduce a function that allows a driver with a reference to the system
controller to get one to a flash device attached to it.

Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
drivers/soc/microchip/Kconfig
drivers/soc/microchip/mpfs-sys-controller.c
include/soc/microchip/mpfs.h

index eb656b33156ba405c7d452dc29540462f1636c20..9b0fdd95276e4e017d32012d1f2de3107556e242 100644 (file)
@@ -1,6 +1,7 @@
 config POLARFIRE_SOC_SYS_CTRL
        tristate "POLARFIRE_SOC_SYS_CTRL"
        depends on POLARFIRE_SOC_MAILBOX
+       depends on MTD
        help
          This driver adds support for the PolarFire SoC (MPFS) system controller.
 
index 0935e9e94172abba0bf78b1d07ce49283a9c7662..c7e063993d9274da1cff9aa70d12cd63f58c0934 100644 (file)
@@ -12,6 +12,8 @@
 #include <linux/kref.h>
 #include <linux/module.h>
 #include <linux/jiffies.h>
+#include <linux/mtd/mtd.h>
+#include <linux/spi/spi.h>
 #include <linux/interrupt.h>
 #include <linux/of.h>
 #include <linux/mailbox_client.h>
@@ -30,6 +32,7 @@ struct mpfs_sys_controller {
        struct mbox_client client;
        struct mbox_chan *chan;
        struct completion c;
+       struct mtd_info *flash;
        struct kref consumers;
 };
 
@@ -99,6 +102,12 @@ static void mpfs_sys_controller_put(void *data)
        kref_put(&sys_controller->consumers, mpfs_sys_controller_delete);
 }
 
+struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_client)
+{
+       return mpfs_client->flash;
+}
+EXPORT_SYMBOL(mpfs_sys_controller_get_flash);
+
 static struct platform_device subdevs[] = {
        {
                .name           = "mpfs-rng",
@@ -114,12 +123,23 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
        struct mpfs_sys_controller *sys_controller;
+       struct device_node *np;
        int i, ret;
 
        sys_controller = kzalloc(sizeof(*sys_controller), GFP_KERNEL);
        if (!sys_controller)
                return -ENOMEM;
 
+       np = of_parse_phandle(dev->of_node, "microchip,bitstream-flash", 0);
+       if (!np)
+               goto no_flash;
+
+       sys_controller->flash = of_get_mtd_device_by_node(np);
+       of_node_put(np);
+       if (IS_ERR(sys_controller->flash))
+               return dev_err_probe(dev, PTR_ERR(sys_controller->flash), "Failed to get flash\n");
+
+no_flash:
        sys_controller->client.dev = dev;
        sys_controller->client.rx_callback = mpfs_sys_controller_rx_callback;
        sys_controller->client.tx_block = 1U;
index f916dcde457f4cadf5fe75ece9b438d211c0462d..09722f83b0ca88547f2478fd88602ded20a5199a 100644 (file)
@@ -38,6 +38,8 @@ int mpfs_blocking_transaction(struct mpfs_sys_controller *mpfs_client, struct mp
 
 struct mpfs_sys_controller *mpfs_sys_controller_get(struct device *dev);
 
+struct mtd_info *mpfs_sys_controller_get_flash(struct mpfs_sys_controller *mpfs_client);
+
 #endif /* if IS_ENABLED(CONFIG_POLARFIRE_SOC_SYS_CTRL) */
 
 #if IS_ENABLED(CONFIG_MCHP_CLK_MPFS)