]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
spi: mtk_snor: support newer SOCs
authorNoah.Shen <noah.shen@mediatek.com>
Mon, 6 Apr 2026 20:13:32 +0000 (15:13 -0500)
committerDavid Lechner <dlechner@baylibre.com>
Tue, 28 Apr 2026 18:11:19 +0000 (13:11 -0500)
Add support for some newer SOCs. New compatible strings are added to the
lookup table. Some SOCs also need a extra bit clocked out as a hardware
quirk, so a new capability structure and code is added to support that.

Signed-off-by: Noah.Shen <noah.shen@mediatek.com>
Reviewed-by: Julien Stephan <jstephan@baylibre.com>
Link: https://patch.msgid.link/20260406-mtk-spi-nor-improvements-v1-6-66f675cbbd3e@baylibre.com
Signed-off-by: David Lechner <dlechner@baylibre.com>
drivers/spi/mtk_snor.c

index 77f94827568adc71b412bac4dbdaa3e67d323095..649bca5716c1f55b380fdd899d24fef6d9f31240 100644 (file)
 
 #define MTK_NOR_UNLOCK_ALL 0x0
 
+struct mtk_snor_caps {
+       /*
+        * Some new SoCs modify the timing of fetching registers' values and IDs
+        * of NOR flash, they need a extra_bit which can add more clock cycles
+        * for fetching data.
+        */
+       u8 extra_bit;
+};
+
 struct mtk_snor_priv {
        struct device *dev;
        void __iomem *base;
+       const struct mtk_snor_caps *caps;
        u8 *buffer;
        struct clk spi_clk;
        struct clk ctlr_clk;
@@ -448,7 +458,11 @@ static int mtk_snor_cmd_program(struct mtk_snor_priv *priv,
        }
 
        /* trigger op */
-       writel(prg_len * BITS_PER_BYTE, priv->base + MTK_NOR_REG_PRG_CNT);
+       if (rx_len)
+               writel(prg_len * BITS_PER_BYTE + priv->caps->extra_bit,
+                      priv->base + MTK_NOR_REG_PRG_CNT);
+       else
+               writel(prg_len * BITS_PER_BYTE, priv->base + MTK_NOR_REG_PRG_CNT);
 
        ret = mtk_snor_cmd_exec(priv, MTK_NOR_CMD_PROGRAM, prg_len * BITS_PER_BYTE);
        if (ret)
@@ -508,6 +522,8 @@ static int mtk_snor_probe(struct udevice *bus)
        if (!priv->base)
                return -EINVAL;
 
+       priv->caps = (const void *)dev_get_driver_data(bus);
+
        ret = clk_get_by_name(bus, "spi", &priv->spi_clk);
        if (ret < 0)
                return ret;
@@ -584,8 +600,19 @@ static const struct dm_spi_ops mtk_snor_ops = {
        .set_mode = mtk_snor_set_mode,
 };
 
+static const struct mtk_snor_caps mtk_snor_caps_default = {
+       .extra_bit = 0,
+};
+
+static const struct mtk_snor_caps mtk_snor_caps_extra_bit = {
+       .extra_bit = 1,
+};
+
 static const struct udevice_id mtk_snor_ids[] = {
-       { .compatible = "mediatek,mtk-snor" },
+       { .compatible = "mediatek,mtk-snor", .data = (ulong)&mtk_snor_caps_default },
+       { .compatible = "mediatek,mt8188-nor", .data = (ulong)&mtk_snor_caps_extra_bit },
+       { .compatible = "mediatek,mt8189-nor", .data = (ulong)&mtk_snor_caps_extra_bit },
+       { .compatible = "mediatek,mt8195-nor", .data = (ulong)&mtk_snor_caps_default },
        {}
 };