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 <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle 2025-05-17 22:15:28 +01:00
parent f9206d1111
commit 25ee5081fa
6 changed files with 52 additions and 51 deletions

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:29:51 +0800 Date: Thu, 23 Jun 2022 18:29:51 +0800
Subject: [PATCH 1/6] drivers: spi-mt65xx: Move chip_config to driver's private 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 <skylake.huang@mediatek.com> Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- ---
drivers/spi/spi-mt65xx.c | 29 +++++++++--------------- drivers/spi/spi-mt65xx.c | 28 ++++++++++--------------
include/linux/platform_data/spi-mt65xx.h | 17 -------------- 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 delete mode 100644 include/linux/platform_data/spi-mt65xx.h
--- a/drivers/spi/spi-mt65xx.c --- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c
@@ -14,7 +14,6 @@ @@ -15,7 +15,6 @@
#include <linux/of.h>
#include <linux/gpio/consumer.h> #include <linux/gpio/consumer.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
-#include <linux/platform_data/spi-mt65xx.h> -#include <linux/platform_data/spi-mt65xx.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/spi/spi-mem.h> #include <linux/spi/spi-mem.h>
@@ -171,6 +170,8 @@ struct mtk_spi { @@ -172,6 +171,8 @@ struct mtk_spi {
struct device *dev; struct device *dev;
dma_addr_t tx_dma; dma_addr_t tx_dma;
dma_addr_t rx_dma; dma_addr_t rx_dma;
@ -30,7 +30,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
}; };
static const struct mtk_spi_compatible mtk_common_compat; 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, .no_need_unprepare = true,
}; };
@ -46,15 +46,15 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
static const struct of_device_id mtk_spi_of_match[] = { static const struct of_device_id mtk_spi_of_match[] = {
{ .compatible = "mediatek,spi-ipm", { .compatible = "mediatek,spi-ipm",
.data = (void *)&mtk_ipm_compat, .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; u16 cpha, cpol;
u32 reg_val; u32 reg_val;
- struct mtk_chip_config *chip_config = spi->controller_data; - 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; 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 else
reg_val &= ~SPI_CMD_CS_POL; reg_val &= ~SPI_CMD_CS_POL;
@ -63,7 +63,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
reg_val |= SPI_CMD_SAMPLE_SEL; reg_val |= SPI_CMD_SAMPLE_SEL;
else else
reg_val &= ~SPI_CMD_SAMPLE_SEL; 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) { if (mdata->dev_comp->ipm_design) {
reg_val = readl(mdata->base + SPI_CMD_REG); reg_val = readl(mdata->base + SPI_CMD_REG);
reg_val &= ~SPI_CMD_IPM_GET_TICKDLY_MASK; reg_val &= ~SPI_CMD_IPM_GET_TICKDLY_MASK;
@ -87,9 +87,9 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
<< SPI_CFG1_GET_TICK_DLY_OFFSET_V1); << SPI_CFG1_GET_TICK_DLY_OFFSET_V1);
writel(reg_val, mdata->base + SPI_CFG1_REG); 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) - if (!spi->controller_data)
- spi->controller_data = (void *)&mtk_default_chip_info; - spi->controller_data = (void *)&mtk_default_chip_info;
@ -97,17 +97,18 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
if (mdata->dev_comp->need_pad_sel && spi_get_csgpiod(spi, 0)) if (mdata->dev_comp->need_pad_sel && spi_get_csgpiod(spi, 0))
/* CS de-asserted, gpiolib will handle inversion */ /* CS de-asserted, gpiolib will handle inversion */
gpiod_direction_output(spi_get_csgpiod(spi, 0), 0); gpiod_direction_output(spi_get_csgpiod(spi, 0), 0);
@@ -1140,6 +1128,10 @@ static int mtk_spi_probe(struct platform @@ -1146,6 +1134,11 @@ static int mtk_spi_probe(struct platform
mdata = spi_master_get_devdata(master); host->use_gpio_descriptors = true;
mdata->dev_comp = device_get_match_data(dev);
mdata = spi_controller_get_devdata(host);
+
+ /* Set device configs to default first. Calibrate it later. */ + /* Set device configs to default first. Calibrate it later. */
+ mdata->sample_sel = 0; + mdata->sample_sel = 0;
+ mdata->get_tick_dly = 2; + mdata->get_tick_dly = 2;
+ +
if (mdata->dev_comp->enhance_timing) mdata->dev_comp = device_get_match_data(dev);
master->mode_bits |= SPI_CS_HIGH;
if (mdata->dev_comp->enhance_timing)
--- a/include/linux/platform_data/spi-mt65xx.h --- a/include/linux/platform_data/spi-mt65xx.h
+++ /dev/null +++ /dev/null
@@ -1,17 +0,0 @@ @@ -1,17 +0,0 @@

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:35:52 +0800 Date: Thu, 23 Jun 2022 18:35:52 +0800
Subject: [PATCH 2/6] drivers: spi: Add support for dynamic calibration Subject: [PATCH 2/6] drivers: spi: Add support for dynamic calibration
@ -11,7 +11,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/spi/spi.c --- a/drivers/spi/spi.c
+++ b/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; return 0;
} }
@ -82,7 +82,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
static void _spi_transfer_delay_ns(u32 ns) static void _spi_transfer_delay_ns(u32 ns)
{ {
if (!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) #if defined(CONFIG_OF)
@ -158,7 +158,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
static void of_spi_parse_dt_cs_delay(struct device_node *nc, static void of_spi_parse_dt_cs_delay(struct device_node *nc,
struct spi_delay *delay, const char *prop) 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) if (rc)
goto err_out; goto err_out;
@ -171,7 +171,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/include/linux/spi/spi.h --- a/include/linux/spi/spi.h
+++ b/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; struct device_driver driver;
}; };
@ -209,10 +209,10 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
+ struct list_head list; + struct list_head list;
+}; +};
+ +
static inline struct spi_driver *to_spi_driver(struct device_driver *drv) #define to_spi_driver(__drv) \
{ ( __drv ? container_of_const(__drv, struct spi_driver, driver) : NULL )
return drv ? container_of(drv, struct spi_driver, driver) : NULL;
@@ -727,6 +761,11 @@ struct spi_controller { @@ -757,6 +791,11 @@ struct spi_controller {
void *dummy_rx; void *dummy_rx;
void *dummy_tx; void *dummy_tx;
@ -224,7 +224,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
int (*fw_translate_cs)(struct spi_controller *ctlr, unsigned cs); 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; } { return 0; }
#endif #endif

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:37:55 +0800 Date: Thu, 23 Jun 2022 18:37:55 +0800
Subject: [PATCH 3/6] drivers: spi-mem: Add spi calibration hook Subject: [PATCH 3/6] drivers: spi-mem: Add spi calibration hook
@ -11,7 +11,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/spi/spi-mem.c --- a/drivers/spi/spi-mem.c
+++ b/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); EXPORT_SYMBOL_GPL(spi_mem_exec_op);
@ -28,7 +28,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
* upper layer if necessary * upper layer if necessary
--- a/include/linux/spi/spi-mem.h --- a/include/linux/spi/spi-mem.h
+++ b/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, int spi_mem_exec_op(struct spi_mem *mem,
const struct spi_mem_op *op); const struct spi_mem_op *op);

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:39:03 +0800 Date: Thu, 23 Jun 2022 18:39:03 +0800
Subject: [PATCH 4/6] drivers: spi-mt65xx: Add controller's calibration Subject: [PATCH 4/6] drivers: spi-mt65xx: Add controller's calibration
@ -11,14 +11,14 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/spi/spi-mt65xx.c --- a/drivers/spi/spi-mt65xx.c
+++ b/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c
@@ -834,6 +834,21 @@ static irqreturn_t mtk_spi_interrupt(int @@ -842,6 +842,21 @@ static irqreturn_t mtk_spi_interrupt(int
return IRQ_HANDLED; return IRQ_WAKE_THREAD;
} }
+static int mtk_spi_append_caldata(struct spi_controller *ctlr) +static int mtk_spi_append_caldata(struct spi_controller *ctlr)
+{ +{
+ struct spi_cal_target *cal_target = kmalloc(sizeof(*cal_target), GFP_KERNEL); + 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_item = &mdata->get_tick_dly;
+ cal_target->cal_min = 0; + cal_target->cal_min = 0;
@ -33,11 +33,11 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
static int mtk_spi_mem_adjust_op_size(struct spi_mem *mem, static int mtk_spi_mem_adjust_op_size(struct spi_mem *mem,
struct spi_mem_op *op) struct spi_mem_op *op)
{ {
@@ -1124,6 +1139,7 @@ static int mtk_spi_probe(struct platform @@ -1132,6 +1147,7 @@ static int mtk_spi_probe(struct platform
master->setup = mtk_spi_setup; host->setup = mtk_spi_setup;
master->set_cs_timing = mtk_spi_set_hw_cs_timing; host->set_cs_timing = mtk_spi_set_hw_cs_timing;
master->use_gpio_descriptors = true; host->use_gpio_descriptors = true;
+ master->append_caldata = mtk_spi_append_caldata; + 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);

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:39:56 +0800 Date: Thu, 23 Jun 2022 18:39:56 +0800
Subject: [PATCH 5/6] drivers: mtd: spinand: Add calibration support for Subject: [PATCH 5/6] drivers: mtd: spinand: Add calibration support for
@ -11,11 +11,11 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/mtd/nand/spi/core.c --- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c
@@ -980,6 +980,56 @@ static int spinand_manufacturer_match(st @@ -1152,6 +1152,56 @@ static int spinand_manufacturer_match(st
return -ENOTSUPP; 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 spinand_device *spinand = (struct spinand_device *)priv;
+ struct device *dev = &spinand->spimem->spi->dev; + struct device *dev = &spinand->spimem->spi->dev;
+ struct spi_mem_op op = SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, buf, readlen); + 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 <skylake.huang@mediatek.com>
static int spinand_id_detect(struct spinand_device *spinand) static int spinand_id_detect(struct spinand_device *spinand)
{ {
u8 *id = spinand->id.data; 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) if (!spinand->scratchbuf)
return -ENOMEM; return -ENOMEM;

View file

@ -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" <skylake.huang@mediatek.com> From: "SkyLake.Huang" <skylake.huang@mediatek.com>
Date: Thu, 23 Jun 2022 18:40:59 +0800 Date: Thu, 23 Jun 2022 18:40:59 +0800
Subject: [PATCH 6/6] drivers: mtd: spi-nor: Add calibration support for Subject: [PATCH 6/6] drivers: mtd: spi-nor: Add calibration support for
@ -12,7 +12,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/mtd/nand/spi/core.c --- a/drivers/mtd/nand/spi/core.c
+++ b/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) if (ret)
return ret; return ret;
@ -26,7 +26,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
--- a/drivers/mtd/spi-nor/core.c --- a/drivers/mtd/spi-nor/core.c
+++ b/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; return NULL;
} }
@ -45,7 +45,7 @@ Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor, static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
const char *name) 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) if (ret)
return ret; return ret;