[][kernel][mt7986][spi][spi-calibration: Add support for 4B mode NOR flashes]
[Description]
Add support for 4B mode NOR flashes:
* For NOR flash, we'll calibrate with 3 bytes mode first and then 4 bytes mode.
* Remove controller's calibration data each time after calibration. We'll
append them again if another calibration is needed.
* Correct error code.
[Release-log]
N/A
Change-Id: Ia647cfa9b1e6228555b568184a5944a592ebe0c1
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/7104709
diff --git a/target/linux/mediatek/patches-5.4/9014-drivers-spi-Add-support-for-dynamic-calibration.patch b/target/linux/mediatek/patches-5.4/9014-drivers-spi-Add-support-for-dynamic-calibration.patch
index 688f33f..8a71a9c 100644
--- a/target/linux/mediatek/patches-5.4/9014-drivers-spi-Add-support-for-dynamic-calibration.patch
+++ b/target/linux/mediatek/patches-5.4/9014-drivers-spi-Add-support-for-dynamic-calibration.patch
@@ -9,11 +9,9 @@
include/linux/spi/spi.h | 42 ++++++++++++
2 files changed, 179 insertions(+)
-diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
-index e562735a3..d548036b1 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
-@@ -1109,6 +1109,70 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
+@@ -1109,6 +1109,72 @@ static int spi_transfer_wait(struct spi_
return 0;
}
@@ -34,7 +32,7 @@
+
+ /* Make sure we can start calibration */
+ if(!ctlr->cal_target || !ctlr->cal_rule || !ctlr->append_caldata)
-+ return 0;
++ return -EINVAL;
+
+ buf = kzalloc(datalen * sizeof(u8), GFP_KERNEL);
+ if(!buf)
@@ -72,8 +70,10 @@
+ } else {
+ *target->cal_item = origin;
+ dev_warn(&spi->dev, "calibration failed, fallback to default: 0x%x", origin);
++ ret = -EIO;
+ }
+ }
++ list_del(&target->list);
+
+cal_end:
+ kfree(buf);
@@ -84,7 +84,7 @@
static void _spi_transfer_delay_ns(u32 ns)
{
if (!ns)
-@@ -1720,6 +1784,75 @@ void spi_flush_queue(struct spi_controller *ctlr)
+@@ -1720,6 +1786,75 @@ void spi_flush_queue(struct spi_controll
/*-------------------------------------------------------------------------*/
#if defined(CONFIG_OF)
@@ -160,7 +160,7 @@
static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
struct device_node *nc)
{
-@@ -1841,6 +1974,10 @@ of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc)
+@@ -1841,6 +1976,10 @@ of_register_spi_device(struct spi_contro
if (rc)
goto err_out;
@@ -171,8 +171,6 @@
/* Store a pointer to the node in the device structure */
of_node_get(nc);
spi->dev.of_node = nc;
-diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
-index 7067f85ce..5330cd9b0 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -264,6 +264,40 @@ struct spi_driver {
@@ -228,7 +226,7 @@
int (*fw_translate_cs)(struct spi_controller *ctlr, unsigned cs);
};
-@@ -1369,6 +1408,9 @@ spi_register_board_info(struct spi_board_info const *info, unsigned n)
+@@ -1369,6 +1408,9 @@ spi_register_board_info(struct spi_board
{ return 0; }
#endif
@@ -238,6 +236,3 @@
/* If you're hotplugging an adapter with devices (parport, usb, etc)
* use spi_new_device() to describe each device. You can also call
* spi_unregister_device() to start making that device vanish, but
---
-2.18.0
-
diff --git a/target/linux/mediatek/patches-5.4/9018-drivers-mtd-spi-nor-Add-calibration-support-for-spi-nor.patch b/target/linux/mediatek/patches-5.4/9018-drivers-mtd-spi-nor-Add-calibration-support-for-spi-nor.patch
index 023f52e..fd1bd1a 100644
--- a/target/linux/mediatek/patches-5.4/9018-drivers-mtd-spi-nor-Add-calibration-support-for-spi-nor.patch
+++ b/target/linux/mediatek/patches-5.4/9018-drivers-mtd-spi-nor-Add-calibration-support-for-spi-nor.patch
@@ -8,11 +8,9 @@
drivers/mtd/spi-nor/spi-nor.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
-diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
-index 945833cbb..38a8948b3 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
-@@ -4893,6 +4893,20 @@ static void spi_nor_debugfs_init(struct spi_nor *nor,
+@@ -4897,6 +4897,35 @@ static void spi_nor_debugfs_init(struct
info->id_len, info->id);
}
@@ -30,19 +28,39 @@
+ return spi_nor_read_raw(nor, *addr, readlen, buf);
+}
+
++static int spi_nor_cal_read_4B(void *priv, u32 *addr, int addrlen, u8 *buf,
++ int readlen)
++{
++ int ret;
++ struct spi_nor *nor = (struct spi_nor *)priv;
++
++ nor->reg_proto = SNOR_PROTO_1_1_1;
++ nor->read_proto = SNOR_PROTO_1_1_1;
++ nor->read_opcode = SPINOR_OP_READ_4B;
++ nor->addr_width = 4;
++ nor->read_dummy = 0;
++
++ return spi_nor_read_raw(nor, *addr, readlen, buf);
++}
++
static const struct flash_info *spi_nor_get_flash_info(struct spi_nor *nor,
const char *name)
{
-@@ -4967,6 +4981,9 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
+@@ -4971,6 +5000,17 @@ int spi_nor_scan(struct spi_nor *nor, co
if (!nor->bouncebuf)
return -ENOMEM;
-+ if(nor->spimem)
-+ spi_mem_do_calibration(nor->spimem, spi_nor_cal_read, nor);
++ if(nor->spimem) {
++ ret = spi_mem_do_calibration(nor->spimem,
++ spi_nor_cal_read, nor);
++ if (ret) {
++ ret = spi_mem_do_calibration(nor->spimem,
++ spi_nor_cal_read_4B, nor);
++ if (ret)
++ return ret;
++ }
++ }
+
info = spi_nor_get_flash_info(nor, name);
if (IS_ERR(info))
return PTR_ERR(info);
---
-2.18.0
-
diff --git a/target/linux/mediatek/patches-5.4/9019-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch b/target/linux/mediatek/patches-5.4/9019-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch
index 8b39b12..5635f55 100644
--- a/target/linux/mediatek/patches-5.4/9019-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch
+++ b/target/linux/mediatek/patches-5.4/9019-drivers-char-tpm-Add-calibration-example-for-SPI-TPM-module.patch
@@ -11,11 +11,9 @@
drivers/char/tpm/tpm_tis_spi.c | 7 +++++++
3 files changed, 28 insertions(+)
-diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
-index 70f785994..b9898a56d 100644
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
-@@ -817,6 +817,21 @@ static const struct tpm_class_ops tpm_tis = {
+@@ -817,6 +817,21 @@ static const struct tpm_class_ops tpm_ti
.clk_enable = tpm_tis_clkrun_enable,
};
@@ -37,7 +35,7 @@
int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
const struct tpm_tis_phy_ops *phy_ops,
acpi_handle acpi_dev_handle)
-@@ -864,6 +879,10 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
+@@ -864,6 +879,10 @@ int tpm_tis_core_init(struct device *dev
if (chip->ops->clk_enable != NULL)
chip->ops->clk_enable(chip, true);
@@ -48,8 +46,6 @@
if (wait_startup(chip, 0) != 0) {
rc = -ENODEV;
goto out_err;
-diff --git a/drivers/char/tpm/tpm_tis_core.h b/drivers/char/tpm/tpm_tis_core.h
-index 7337819f5..7bb0bc8b6 100644
--- a/drivers/char/tpm/tpm_tis_core.h
+++ b/drivers/char/tpm/tpm_tis_core.h
@@ -106,6 +106,7 @@ struct tpm_tis_phy_ops {
@@ -68,11 +64,9 @@
int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
const struct tpm_tis_phy_ops *phy_ops,
acpi_handle acpi_dev_handle);
-diff --git a/drivers/char/tpm/tpm_tis_spi.c b/drivers/char/tpm/tpm_tis_spi.c
-index 19513e622..3be2d53a5 100644
--- a/drivers/char/tpm/tpm_tis_spi.c
+++ b/drivers/char/tpm/tpm_tis_spi.c
-@@ -184,12 +184,19 @@ static int tpm_tis_spi_write32(struct tpm_tis_data *data, u32 addr, u32 value)
+@@ -184,12 +184,19 @@ static int tpm_tis_spi_write32(struct tp
return rc;
}
@@ -92,6 +86,3 @@
};
static int tpm_tis_spi_probe(struct spi_device *dev)
---
-2.18.0
-