From 25ee5081fa9d7d782420c1bf4ab2595df1fdf122 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Sat, 17 May 2025 22:15:28 +0100 Subject: [PATCH] kernel/mediatek: 6.12: adapt SPI calibration Fix build of downstream SPI calibration on Filogic SoCs for Linux 6.12. Signed-off-by: Daniel Golle --- ...xx-Move-chip_config-to-driver-s-priv.patch | 37 ++++++++++--------- ...-Add-support-for-dynamic-calibration.patch | 20 +++++----- ...ers-spi-mem-Add-spi-calibration-hook.patch | 6 +-- ...xx-Add-controller-s-calibration-para.patch | 22 +++++------ ...and-Add-calibration-support-for-spin.patch | 10 ++--- ...nor-Add-calibration-support-for-spi-.patch | 8 ++-- 6 files changed, 52 insertions(+), 51 deletions(-) diff --git a/target/linux/mediatek/patches-6.12/431-drivers-spi-mt65xx-Move-chip_config-to-driver-s-priv.patch b/target/linux/mediatek/patches-6.12/431-drivers-spi-mt65xx-Move-chip_config-to-driver-s-priv.patch index 9629dd85195..74e9bd9d7ac 100644 --- a/target/linux/mediatek/patches-6.12/431-drivers-spi-mt65xx-Move-chip_config-to-driver-s-priv.patch +++ b/target/linux/mediatek/patches-6.12/431-drivers-spi-mt65xx-Move-chip_config-to-driver-s-priv.patch @@ -1,4 +1,4 @@ -From bfd3acc428085742d754a6d328d1a93ebf9451df Mon Sep 17 00:00:00 2001 +From bfa7cf42e610d820b935b4805aa80484d591cb1f Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:29:51 +0800 Subject: [PATCH 1/6] drivers: spi-mt65xx: Move chip_config to driver's private @@ -6,22 +6,22 @@ Subject: [PATCH 1/6] drivers: spi-mt65xx: Move chip_config to driver's private Signed-off-by: SkyLake.Huang --- - drivers/spi/spi-mt65xx.c | 29 +++++++++--------------- + drivers/spi/spi-mt65xx.c | 28 ++++++++++-------------- include/linux/platform_data/spi-mt65xx.h | 17 -------------- - 2 files changed, 11 insertions(+), 35 deletions(-) + 2 files changed, 11 insertions(+), 34 deletions(-) delete mode 100644 include/linux/platform_data/spi-mt65xx.h --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c -@@ -14,7 +14,6 @@ - #include +@@ -15,7 +15,6 @@ #include + #include #include -#include #include #include #include -@@ -171,6 +170,8 @@ struct mtk_spi { +@@ -172,6 +171,8 @@ struct mtk_spi { struct device *dev; dma_addr_t tx_dma; dma_addr_t rx_dma; @@ -30,7 +30,7 @@ Signed-off-by: SkyLake.Huang }; static const struct mtk_spi_compatible mtk_common_compat; -@@ -216,15 +217,6 @@ static const struct mtk_spi_compatible m +@@ -217,15 +218,6 @@ static const struct mtk_spi_compatible m .no_need_unprepare = true, }; @@ -46,15 +46,15 @@ Signed-off-by: SkyLake.Huang static const struct of_device_id mtk_spi_of_match[] = { { .compatible = "mediatek,spi-ipm", .data = (void *)&mtk_ipm_compat, -@@ -352,7 +344,6 @@ static int mtk_spi_hw_init(struct spi_ma +@@ -353,7 +345,6 @@ static int mtk_spi_hw_init(struct spi_co { u16 cpha, cpol; u32 reg_val; - struct mtk_chip_config *chip_config = spi->controller_data; - struct mtk_spi *mdata = spi_master_get_devdata(master); + struct mtk_spi *mdata = spi_controller_get_devdata(host); cpha = spi->mode & SPI_CPHA ? 1 : 0; -@@ -402,7 +393,7 @@ static int mtk_spi_hw_init(struct spi_ma +@@ -403,7 +394,7 @@ static int mtk_spi_hw_init(struct spi_co else reg_val &= ~SPI_CMD_CS_POL; @@ -63,7 +63,7 @@ Signed-off-by: SkyLake.Huang reg_val |= SPI_CMD_SAMPLE_SEL; else reg_val &= ~SPI_CMD_SAMPLE_SEL; -@@ -429,20 +420,20 @@ static int mtk_spi_hw_init(struct spi_ma +@@ -430,20 +421,20 @@ static int mtk_spi_hw_init(struct spi_co if (mdata->dev_comp->ipm_design) { reg_val = readl(mdata->base + SPI_CMD_REG); reg_val &= ~SPI_CMD_IPM_GET_TICKDLY_MASK; @@ -87,9 +87,9 @@ Signed-off-by: SkyLake.Huang << SPI_CFG1_GET_TICK_DLY_OFFSET_V1); writel(reg_val, mdata->base + SPI_CFG1_REG); } -@@ -732,9 +723,6 @@ static int mtk_spi_setup(struct spi_devi +@@ -733,9 +724,6 @@ static int mtk_spi_setup(struct spi_devi { - struct mtk_spi *mdata = spi_master_get_devdata(spi->master); + struct mtk_spi *mdata = spi_controller_get_devdata(spi->controller); - if (!spi->controller_data) - spi->controller_data = (void *)&mtk_default_chip_info; @@ -97,17 +97,18 @@ Signed-off-by: SkyLake.Huang if (mdata->dev_comp->need_pad_sel && spi_get_csgpiod(spi, 0)) /* CS de-asserted, gpiolib will handle inversion */ gpiod_direction_output(spi_get_csgpiod(spi, 0), 0); -@@ -1140,6 +1128,10 @@ static int mtk_spi_probe(struct platform - mdata = spi_master_get_devdata(master); - mdata->dev_comp = device_get_match_data(dev); +@@ -1146,6 +1134,11 @@ static int mtk_spi_probe(struct platform + host->use_gpio_descriptors = true; + mdata = spi_controller_get_devdata(host); ++ + /* Set device configs to default first. Calibrate it later. */ + mdata->sample_sel = 0; + mdata->get_tick_dly = 2; + - if (mdata->dev_comp->enhance_timing) - master->mode_bits |= SPI_CS_HIGH; + mdata->dev_comp = device_get_match_data(dev); + if (mdata->dev_comp->enhance_timing) --- a/include/linux/platform_data/spi-mt65xx.h +++ /dev/null @@ -1,17 +0,0 @@ diff --git a/target/linux/mediatek/patches-6.12/432-drivers-spi-Add-support-for-dynamic-calibration.patch b/target/linux/mediatek/patches-6.12/432-drivers-spi-Add-support-for-dynamic-calibration.patch index 7ff7b05301a..4c5fdbbf0af 100644 --- a/target/linux/mediatek/patches-6.12/432-drivers-spi-Add-support-for-dynamic-calibration.patch +++ b/target/linux/mediatek/patches-6.12/432-drivers-spi-Add-support-for-dynamic-calibration.patch @@ -1,4 +1,4 @@ -From 2ade0172154e50c8a2bfd8634c6eff943cffea29 Mon Sep 17 00:00:00 2001 +From aaff78437f09d4b86da84ce5983fb7c5be0538d2 Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:35:52 +0800 Subject: [PATCH 2/6] drivers: spi: Add support for dynamic calibration @@ -11,7 +11,7 @@ Signed-off-by: SkyLake.Huang --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c -@@ -1380,6 +1380,70 @@ static int spi_transfer_wait(struct spi_ +@@ -1494,6 +1494,70 @@ static int spi_transfer_wait(struct spi_ return 0; } @@ -82,7 +82,7 @@ Signed-off-by: SkyLake.Huang static void _spi_transfer_delay_ns(u32 ns) { if (!ns) -@@ -2225,6 +2289,75 @@ void spi_flush_queue(struct spi_controll +@@ -2352,6 +2416,75 @@ void spi_flush_queue(struct spi_controll /*-------------------------------------------------------------------------*/ #if defined(CONFIG_OF) @@ -158,7 +158,7 @@ Signed-off-by: SkyLake.Huang static void of_spi_parse_dt_cs_delay(struct device_node *nc, struct spi_delay *delay, const char *prop) { -@@ -2364,6 +2497,10 @@ of_register_spi_device(struct spi_contro +@@ -2516,6 +2649,10 @@ of_register_spi_device(struct spi_contro if (rc) goto err_out; @@ -171,7 +171,7 @@ Signed-off-by: SkyLake.Huang --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h -@@ -330,6 +330,40 @@ struct spi_driver { +@@ -351,6 +351,40 @@ struct spi_driver { struct device_driver driver; }; @@ -209,10 +209,10 @@ Signed-off-by: SkyLake.Huang + struct list_head list; +}; + - static inline struct spi_driver *to_spi_driver(struct device_driver *drv) - { - return drv ? container_of(drv, struct spi_driver, driver) : NULL; -@@ -727,6 +761,11 @@ struct spi_controller { + #define to_spi_driver(__drv) \ + ( __drv ? container_of_const(__drv, struct spi_driver, driver) : NULL ) + +@@ -757,6 +791,11 @@ struct spi_controller { void *dummy_rx; void *dummy_tx; @@ -224,7 +224,7 @@ Signed-off-by: SkyLake.Huang int (*fw_translate_cs)(struct spi_controller *ctlr, unsigned cs); /* -@@ -1601,6 +1640,9 @@ spi_register_board_info(struct spi_board +@@ -1660,6 +1699,9 @@ spi_register_board_info(struct spi_board { return 0; } #endif diff --git a/target/linux/mediatek/patches-6.12/433-drivers-spi-mem-Add-spi-calibration-hook.patch b/target/linux/mediatek/patches-6.12/433-drivers-spi-mem-Add-spi-calibration-hook.patch index d9fe480b17e..e8377f5c4cb 100644 --- a/target/linux/mediatek/patches-6.12/433-drivers-spi-mem-Add-spi-calibration-hook.patch +++ b/target/linux/mediatek/patches-6.12/433-drivers-spi-mem-Add-spi-calibration-hook.patch @@ -1,4 +1,4 @@ -From 06640a5da2973318c06e516da16a5b579622e7c5 Mon Sep 17 00:00:00 2001 +From fa0aaf2a0532053b925f6fbb9c8d0e516370fb68 Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:37:55 +0800 Subject: [PATCH 3/6] drivers: spi-mem: Add spi calibration hook @@ -11,7 +11,7 @@ Signed-off-by: SkyLake.Huang --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c -@@ -419,6 +419,14 @@ int spi_mem_exec_op(struct spi_mem *mem, +@@ -466,6 +466,14 @@ int spi_mem_exec_op(struct spi_mem *mem, } EXPORT_SYMBOL_GPL(spi_mem_exec_op); @@ -28,7 +28,7 @@ Signed-off-by: SkyLake.Huang * upper layer if necessary --- a/include/linux/spi/spi-mem.h +++ b/include/linux/spi/spi-mem.h -@@ -370,6 +370,10 @@ bool spi_mem_supports_op(struct spi_mem +@@ -372,6 +372,10 @@ bool spi_mem_supports_op(struct spi_mem int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op); diff --git a/target/linux/mediatek/patches-6.12/434-drivers-spi-mt65xx-Add-controller-s-calibration-para.patch b/target/linux/mediatek/patches-6.12/434-drivers-spi-mt65xx-Add-controller-s-calibration-para.patch index dbdb1947aa2..a7815d5eadb 100644 --- a/target/linux/mediatek/patches-6.12/434-drivers-spi-mt65xx-Add-controller-s-calibration-para.patch +++ b/target/linux/mediatek/patches-6.12/434-drivers-spi-mt65xx-Add-controller-s-calibration-para.patch @@ -1,4 +1,4 @@ -From d278c7a0bf730318a7ccf8d0a8b434c813e23fd0 Mon Sep 17 00:00:00 2001 +From 655dfc90d438a8e223317f197b888a92de3df3a1 Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:39:03 +0800 Subject: [PATCH 4/6] drivers: spi-mt65xx: Add controller's calibration @@ -11,14 +11,14 @@ Signed-off-by: SkyLake.Huang --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c -@@ -834,6 +834,21 @@ static irqreturn_t mtk_spi_interrupt(int - return IRQ_HANDLED; +@@ -842,6 +842,21 @@ static irqreturn_t mtk_spi_interrupt(int + return IRQ_WAKE_THREAD; } +static int mtk_spi_append_caldata(struct spi_controller *ctlr) +{ + struct spi_cal_target *cal_target = kmalloc(sizeof(*cal_target), GFP_KERNEL); -+ struct mtk_spi *mdata = spi_master_get_devdata(ctlr); ++ struct mtk_spi *mdata = spi_controller_get_devdata(ctlr); + + cal_target->cal_item = &mdata->get_tick_dly; + cal_target->cal_min = 0; @@ -33,11 +33,11 @@ Signed-off-by: SkyLake.Huang static int mtk_spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) { -@@ -1124,6 +1139,7 @@ static int mtk_spi_probe(struct platform - master->setup = mtk_spi_setup; - master->set_cs_timing = mtk_spi_set_hw_cs_timing; - master->use_gpio_descriptors = true; -+ master->append_caldata = mtk_spi_append_caldata; +@@ -1132,6 +1147,7 @@ static int mtk_spi_probe(struct platform + host->setup = mtk_spi_setup; + host->set_cs_timing = mtk_spi_set_hw_cs_timing; + host->use_gpio_descriptors = true; ++ host->append_caldata = mtk_spi_append_caldata; + + mdata = spi_controller_get_devdata(host); - mdata = spi_master_get_devdata(master); - mdata->dev_comp = device_get_match_data(dev); diff --git a/target/linux/mediatek/patches-6.12/435-drivers-mtd-spinand-Add-calibration-support-for-spin.patch b/target/linux/mediatek/patches-6.12/435-drivers-mtd-spinand-Add-calibration-support-for-spin.patch index 50149fd8196..eda2d8366a7 100644 --- a/target/linux/mediatek/patches-6.12/435-drivers-mtd-spinand-Add-calibration-support-for-spin.patch +++ b/target/linux/mediatek/patches-6.12/435-drivers-mtd-spinand-Add-calibration-support-for-spin.patch @@ -1,4 +1,4 @@ -From 7670ec4a14891a1a182b98a9c403ffbf6b49e4b1 Mon Sep 17 00:00:00 2001 +From eef758fee8d25f56086eaaf7df1edb19929ced1a Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:39:56 +0800 Subject: [PATCH 5/6] drivers: mtd: spinand: Add calibration support for @@ -11,11 +11,11 @@ Signed-off-by: SkyLake.Huang --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c -@@ -980,6 +980,56 @@ static int spinand_manufacturer_match(st - return -ENOTSUPP; +@@ -1152,6 +1152,56 @@ static int spinand_manufacturer_match(st + return -EOPNOTSUPP; } -+int spinand_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen) { ++static int spinand_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen) { + struct spinand_device *spinand = (struct spinand_device *)priv; + struct device *dev = &spinand->spimem->spi->dev; + struct spi_mem_op op = SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, buf, readlen); @@ -68,7 +68,7 @@ Signed-off-by: SkyLake.Huang static int spinand_id_detect(struct spinand_device *spinand) { u8 *id = spinand->id.data; -@@ -1230,6 +1280,10 @@ static int spinand_init(struct spinand_d +@@ -1403,6 +1453,10 @@ static int spinand_init(struct spinand_d if (!spinand->scratchbuf) return -ENOMEM; diff --git a/target/linux/mediatek/patches-6.12/436-drivers-mtd-spi-nor-Add-calibration-support-for-spi-.patch b/target/linux/mediatek/patches-6.12/436-drivers-mtd-spi-nor-Add-calibration-support-for-spi-.patch index 27c5dfd5d66..4cc43333cd7 100644 --- a/target/linux/mediatek/patches-6.12/436-drivers-mtd-spi-nor-Add-calibration-support-for-spi-.patch +++ b/target/linux/mediatek/patches-6.12/436-drivers-mtd-spi-nor-Add-calibration-support-for-spi-.patch @@ -1,4 +1,4 @@ -From f3fe3b15eca7908eaac57f9b8387a5dbc45ec5b2 Mon Sep 17 00:00:00 2001 +From 7ec7de94c87654e6cc3f8f604b2f65c003f3e5dc Mon Sep 17 00:00:00 2001 From: "SkyLake.Huang" Date: Thu, 23 Jun 2022 18:40:59 +0800 Subject: [PATCH 6/6] drivers: mtd: spi-nor: Add calibration support for @@ -12,7 +12,7 @@ Signed-off-by: SkyLake.Huang --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c -@@ -1021,7 +1021,10 @@ int spinand_cal_read(void *priv, u32 *ad +@@ -1193,7 +1193,10 @@ static int spinand_cal_read(void *priv, if (ret) return ret; @@ -26,7 +26,7 @@ Signed-off-by: SkyLake.Huang --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c -@@ -3378,6 +3378,18 @@ static const struct flash_info *spi_nor_ +@@ -3300,6 +3300,18 @@ static const struct flash_info *spi_nor_ return NULL; } @@ -45,7 +45,7 @@ Signed-off-by: SkyLake.Huang static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, const char *name) { -@@ -3506,6 +3518,9 @@ int spi_nor_scan(struct spi_nor *nor, co +@@ -3474,6 +3486,9 @@ int spi_nor_scan(struct spi_nor *nor, co if (ret) return ret;