mtd: spi-nor / spi / MFD: Convert intel-spi to SPI MEM
Subsystems (7)
v5 cover mtd: spi-nor / spi / MFD: Convert intel-spi to SPI MEM
Hi all,
Based on discussion on the patch I sent some time ago here:
http://lists.infradead.org/pipermail/linux-mtd/2021-June/086867.html
it turns out that the preferred way to deal with the SPI flash controller drivers is through SPI MEM which is part of Linux SPI subsystem.
This series does that for the intel-spi driver. This also renames the driver to follow the convention used in the SPI subsystem. The first patch improves the write protection handling to be slightly more safer. The following two patches do the conversion itself. Note the Intel SPI flash controller only allows commands such as read, write and so on and it internally uses whatever addressing etc. it figured from the SFDP on the flash device.
Previous versions of the patch series can be found here:
v4: https://lore.kernel.org/linux-mtd/[email protected]/
v3: https://lore.kernel.org/linux-mtd/[email protected]/
v2: https://lore.kernel.org/linux-mtd/[email protected]/
v1: https://lore.kernel.org/linux-mtd/[email protected]/
Changes from v4:
* Correct check in intel_spi_cmp_mem_op()
* Added tag from Boris
Changes from v3:
* Create an array of supported opcodes and reject everything else.
* Fix checkpatch warnings reported by Mauro
* Added tags from Lee and Mauro
Changes from v2:
* Added tag from Andy
* Check buswidth in intel_spi_supports_mem_op() and return false if octal mode is asked. The Intel controllers support buswidths 1-4 but this is not exposed to software. It figures this itself through SFDP tables.
* In case of software sequencer, support same opcodes than we support with the hardware sequencer if found in the opcodes table.
Changes from v1:
* Arrange dependencies in Kconfig entries the same way in both glue drivers.
* Added empty lines between different subsystem includes.
* dev_err() to single line
* Return intel_spi_sw_cycle() directly in intel_spi_erase().
* Drop redundant elses.
* Fixed typo in the commit message of the patch 3/3.
Mika Westerberg (3):
mtd: spi-nor: intel-spi: Disable write protection only if asked
mtd: spi-nor: intel-spi: Convert to SPI MEM Documentation / MTD: Rename the intel-spi driver
Documentation/driver-api/mtd/index.rst | 2 +-
.../mtd/{intel-spi.rst => spi-intel.rst} | 8 +-
drivers/mfd/lpc_ich.c | 59 +-
drivers/mtd/spi-nor/controllers/Kconfig | 36 -
drivers/mtd/spi-nor/controllers/Makefile | 3 -
drivers/mtd/spi-nor/controllers/intel-spi.h | 21 -
drivers/spi/Kconfig | 39 +
drivers/spi/Makefile | 3 +
.../intel-spi-pci.c => spi/spi-intel-pci.c} | 49 +-
.../spi-intel-platform.c} | 21 +-
.../intel-spi.c => spi/spi-intel.c} | 827 ++++++++++++------
drivers/spi/spi-intel.h | 19 +
include/linux/mfd/lpc_ich.h | 2 +-
.../x86/{intel-spi.h => spi-intel.h} | 12 +-
14 files changed, 699 insertions(+), 402 deletions(-)
rename Documentation/driver-api/mtd/{intel-spi.rst => spi-intel.rst} (94%)
delete mode 100644 drivers/mtd/spi-nor/controllers/intel-spi.h
rename drivers/{mtd/spi-nor/controllers/intel-spi-pci.c => spi/spi-intel-pci.c} (84%)
rename drivers/{mtd/spi-nor/controllers/intel-spi-platform.c => spi/spi-intel-platform.c} (65%)
rename drivers/{mtd/spi-nor/controllers/intel-spi.c => spi/spi-intel.c} (57%)
create mode 100644 drivers/spi/spi-intel.h
rename include/linux/platform_data/x86/{intel-spi.h => spi-intel.h} (64%)Signature · 1 line
2.34.1
PATCH v5 1/3 mtd: spi-nor: intel-spi: Disable write protection only if asked
Currently the driver tries to disable the BIOS write protection automatically even if this is not what the user wants. For this reason modify the driver so that by default it does not touch the write protection. Only if specifically asked by the user (setting writeable=1 command line parameter) the driver tries to disable the BIOS write protection.
--- drivers/mfd/lpc_ich.c | 59 +++++++++++++++++-- .../mtd/spi-nor/controllers/intel-spi-pci.c | 29 +++++---- drivers/mtd/spi-nor/controllers/intel-spi.c | 41 ++++++------- include/linux/platform_data/x86/intel-spi.h | 6 +- 4 files changed, 96 insertions(+), 39 deletions(-)
drivers/mfd/lpc_ich.c +54 -5
@@ -63,6 +63,8 @@#define SPIBASE_BYT 0x54#define SPIBASE_BYT_SZ 512#define SPIBASE_BYT_EN BIT(1) +#define BYT_BCR 0xfc +#define BYT_BCR_WPD BIT(0)#define SPIBASE_LPT 0x3800#define SPIBASE_LPT_SZ 512
@@ -1084,12 +1086,57 @@ static int lpc_ich_init_wdt(struct pci_dev *dev)return ret; } +static bool lpc_ich_byt_set_writeable (void __iomem *base,void *data) +{ +u32 val; + + val =readl (base +BYT_BCR ); +if (!(val &BYT_BCR_WPD )) { + val |=BYT_BCR_WPD ; +writel (val, base +BYT_BCR ); + val =readl (base +BYT_BCR ); + } + +return val &BYT_BCR_WPD ; +} + +static bool lpc_ich_lpt_set_writeable (void __iomem *base,void *data) +{ +struct pci_dev *pdev = data; +u32 bcr; + +pci_read_config_dword (pdev,BCR , &bcr); +if (!(bcr &BCR_WPD )) { + bcr |=BCR_WPD ; +pci_write_config_dword (pdev,BCR , bcr); +pci_read_config_dword (pdev,BCR , &bcr); + } + +return bcr &BCR_WPD ; +} + +static bool lpc_ich_bxt_set_writeable (void __iomem *base,void *data) +{ +unsigned int spi =PCI_DEVFN (13 ,2 ); +struct pci_bus *bus = data; +u32 bcr; + +pci_bus_read_config_dword (bus, spi,BCR , &bcr); +if (!(bcr &BCR_WPD )) { + bcr |=BCR_WPD ; +pci_bus_write_config_dword (bus, spi,BCR , bcr); +pci_bus_read_config_dword (bus, spi,BCR , &bcr); + } + +return bcr &BCR_WPD ; +} +static int lpc_ich_init_spi (struct pci_dev *dev) {struct lpc_ich_priv *priv =pci_get_drvdata (dev);struct resource *res = &intel_spi_res[0 ];struct intel_spi_boardinfo *info; -u32 spi_base, rcba, bcr; +u32 spi_base, rcba; info =devm_kzalloc (&dev->dev,sizeof (*info),GFP_KERNEL );if (!info)
@@ -1103,6 +1150,8 @@ static int lpc_ich_init_spi(struct pci_dev *dev)if (spi_base &SPIBASE_BYT_EN ) { res->start = spi_base & ~(SPIBASE_BYT_SZ -1 ); res->end = res->start +SPIBASE_BYT_SZ -1 ; + + info->set_writeable = lpc_ich_byt_set_writeable; }break ;
@@ -1113,8 +1162,8 @@ static int lpc_ich_init_spi(struct pci_dev *dev) res->start = spi_base +SPIBASE_LPT ; res->end = res->start +SPIBASE_LPT_SZ -1 ; -pci_read_config_dword (dev,BCR , &bcr); - info->writeable = !!(bcr &BCR_WPD ); + info->set_writeable = lpc_ich_lpt_set_writeable; + info->data = dev; }break ;
@@ -1135,8 +1184,8 @@ static int lpc_ich_init_spi(struct pci_dev *dev) res->start = spi_base &0xfffffff0 ; res->end = res->start +SPIBASE_APL_SZ -1 ; -pci_bus_read_config_dword (bus, spi,BCR , &bcr); - info->writeable = !!(bcr &BCR_WPD ); + info->set_writeable = lpc_ich_bxt_set_writeable; + info->data = bus; }pci_bus_write_config_byte (bus, p2sb,0xe1 ,0x1 );
drivers/mtd/spi-nor/controllers/intel-spi-pci.c +19 -10
@@ -16,12 +16,30 @@#define BCR 0xdc#define BCR_WPD BIT(0) +static bool intel_spi_pci_set_writeable (void __iomem *base,void *data) +{ +struct pci_dev *pdev = data; +u32 bcr; + +/* Try to make the chip read/write */ +pci_read_config_dword (pdev,BCR , &bcr); +if (!(bcr &BCR_WPD )) { + bcr |=BCR_WPD ; +pci_write_config_dword (pdev,BCR , bcr); +pci_read_config_dword (pdev,BCR , &bcr); + } + +return bcr &BCR_WPD ; +} +static const struct intel_spi_boardinfo bxt_info = { .type =INTEL_SPI_BXT , + .set_writeable = intel_spi_pci_set_writeable, };static const struct intel_spi_boardinfo cnl_info = { .type =INTEL_SPI_CNL , + .set_writeable = intel_spi_pci_set_writeable, }; static int intel_spi_pci_probe(struct pci_dev *pdev,
@@ -29,7 +47,6 @@ static int intel_spi_pci_probe(struct pci_dev *pdev, {struct intel_spi_boardinfo *info;struct intel_spi *ispi; -u32 bcr;int ret; ret =pcim_enable_device (pdev);
@@ -41,15 +58,7 @@ static int intel_spi_pci_probe(struct pci_dev *pdev,if (!info)return -ENOMEM ; -/* Try to make the chip read/write */ -pci_read_config_dword (pdev,BCR , &bcr); -if (!(bcr &BCR_WPD )) { - bcr |=BCR_WPD ; -pci_write_config_dword (pdev,BCR , bcr); -pci_read_config_dword (pdev,BCR , &bcr); - } - info->writeable = !!(bcr &BCR_WPD ); - + info->data = pdev; ispi =intel_spi_probe (&pdev->dev, &pdev->resource[0 ], info);if (IS_ERR (ispi))return PTR_ERR (ispi);
drivers/mtd/spi-nor/controllers/intel-spi.c +19 -22
90 lines not on this page · raw message
include/linux/platform_data/x86/intel-spi.h +4 -2
@@ -19,11 +19,13 @@ enum intel_spi_type {/** * struct intel_spi_boardinfo - Board specific data for Intel SPI driver * @type: Type which this controller is compatible with -* @writeable: The chip is writeable +* @set_writeable: Try to make the chip writeable (optional) +* @data: Data to be passed to @set_writeable can be %NULL */ struct intel_spi_boardinfo {enum intel_spi_type type; -bool writeable; +bool (*set_writeable)(void __iomem *base,void *data); +void *data; };#endif /* INTEL_SPI_PDATA_H */
Signature · 1 line
2.34.1
Re: [PATCH v5 1/3] mtd: spi-nor: intel-spi: Disable write protection only if asked
Quoted 9 lines · Mika Westerberg
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Currently the driver tries to disable the BIOS write protection automatically even if this is not what the user wants. For this reason modify the driver so that by default it does not touch the write protection. Only if specifically asked by the user (setting writeable=1 command line parameter) the driver tries to disable the BIOS write protection.
Quoted 4 lines
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Mauro Lima <[email protected]>Acked-by Lee Jones <[email protected]>
Quoted 7 lines
--- drivers/mfd/lpc_ich.c | 59 +++++++++++++++++-- .../mtd/spi-nor/controllers/intel-spi-pci.c | 29 +++++---- drivers/mtd/spi-nor/controllers/intel-spi.c | 41 ++++++------- include/linux/platform_data/x86/intel-spi.h | 6 +- 4 files changed, 96 insertions(+), 39 deletions(-)
PATCH v5 2/3 mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Mika WesterbergThe preferred way to implement SPI-NOR controller drivers is through SPI subsubsystem utilizing the SPI MEM core functions. This converts the Intel SPI flash controller driver over the SPI MEM by moving the driver from SPI-NOR subsystem to SPI subsystem and in one go make it use the SPI MEM functions. The driver name will be changed from intel-spi to spi-intel to match the convention used in the SPI subsystem.
---
drivers/mtd/spi-nor/controllers/Kconfig | 36 -
drivers/mtd/spi-nor/controllers/Makefile | 3 -
drivers/mtd/spi-nor/controllers/intel-spi.h | 21 -
drivers/spi/Kconfig | 39 +
drivers/spi/Makefile | 3 +
.../intel-spi-pci.c => spi/spi-intel-pci.c} | 20 +-
.../spi-intel-platform.c} | 21 +-
.../intel-spi.c => spi/spi-intel.c} | 806 ++++++++++++------
drivers/spi/spi-intel.h | 19 +
include/linux/mfd/lpc_ich.h | 2 +-
.../x86/{intel-spi.h => spi-intel.h} | 6 +-
11 files changed, 608 insertions(+), 368 deletions(-)
delete mode 100644 drivers/mtd/spi-nor/controllers/intel-spi.h
rename drivers/{mtd/spi-nor/controllers/intel-spi-pci.c => spi/spi-intel-pci.c} (86%)
rename drivers/{mtd/spi-nor/controllers/intel-spi-platform.c => spi/spi-intel-platform.c} (65%)
rename drivers/{mtd/spi-nor/controllers/intel-spi.c => spi/spi-intel.c} (59%)
create mode 100644 drivers/spi/spi-intel.h
rename include/linux/platform_data/x86/{intel-spi.h => spi-intel.h} (89%)drivers/mtd/spi-nor/controllers/Kconfig +0 -36
@@ -26,39 +26,3 @@ config SPI_NXP_SPIFI SPIFI is a specialized controller for connecting serial SPI Flash. Enable this option if you have a device with a SPIFI controller and want to access the Flash as a mtd device. - -config SPI_INTEL_SPI - tristate - -config SPI_INTEL_SPI_PCI - tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)" - depends on X86 && PCI - select SPI_INTEL_SPI - help - This enables PCI support for the Intel PCH/PCU SPI controller in - master mode. This controller is present in modern Intel hardware - and is used to hold BIOS and other persistent settings. Using - this driver it is possible to upgrade BIOS directly from Linux. - - Say N here unless you know what you are doing. Overwriting the - SPI flash may render the system unbootable. - - To compile this driver as a module, choose M here: the module - will be called intel-spi-pci. - -config SPI_INTEL_SPI_PLATFORM - tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)" - depends on X86 - select SPI_INTEL_SPI - help - This enables platform support for the Intel PCH/PCU SPI - controller in master mode. This controller is present in modern - Intel hardware and is used to hold BIOS and other persistent - settings. Using this driver it is possible to upgrade BIOS - directly from Linux. - - Say N here unless you know what you are doing. Overwriting the - SPI flash may render the system unbootable. - - To compile this driver as a module, choose M here: the module - will be called intel-spi-platform.
drivers/mtd/spi-nor/controllers/Makefile +0 -3
@@ -2,6 +2,3 @@ obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o -obj-$(CONFIG_SPI_INTEL_SPI) += intel-spi.o -obj-$(CONFIG_SPI_INTEL_SPI_PCI) += intel-spi-pci.o -obj-$(CONFIG_SPI_INTEL_SPI_PLATFORM) += intel-spi-platform.o
drivers/mtd/spi-nor/controllers/intel-spi.h deleted +0 -21
@@ -1,21 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* -* Intel PCH/PCU SPI flash driver. -* -* Copyright (C) 2016, Intel Corporation -* Author: Mika Westerberg <[email protected]> -*/ - -#ifndef INTEL_SPI_H -#define INTEL_SPI_H - -#include <linux/platform_data/x86/intel-spi.h> - -struct intel_spi ; -struct resource ; - -struct intel_spi *intel_spi_probe (struct device *dev, -struct resource *mem,const struct intel_spi_boardinfo *info); -int intel_spi_remove (struct intel_spi *ispi); - -#endif /* INTEL_SPI_H */
drivers/spi/Kconfig +39 -0
@@ -427,6 +427,45 @@ config SPI_INGENIC To compile this driver as a module, choose M here: the module will be called spi-ingenic. +config SPI_INTEL + tristate + +config SPI_INTEL_PCI + tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)" + depends on PCI + depends on X86 || COMPILE_TEST + depends on SPI_MEM + select SPI_INTEL + help + This enables PCI support for the Intel PCH/PCU SPI controller in + master mode. This controller is present in modern Intel hardware + and is used to hold BIOS and other persistent settings. Using + this driver it is possible to upgrade BIOS directly from Linux. + + Say N here unless you know what you are doing. Overwriting the + SPI flash may render the system unbootable. + + To compile this driver as a module, choose M here: the module + will be called spi-intel-pci. + +config SPI_INTEL_PLATFORM + tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)" + depends on X86 || COMPILE_TEST + depends on SPI_MEM + select SPI_INTEL + help + This enables platform support for the Intel PCH/PCU SPI + controller in master mode. This controller is present in modern + Intel hardware and is used to hold BIOS and other persistent + settings. Using this driver it is possible to upgrade BIOS + directly from Linux. + + Say N here unless you know what you are doing. Overwriting the + SPI flash may render the system unbootable. + + To compile this driver as a module, choose M here: the module + will be called spi-intel-platform. + config SPI_JCORE tristate "J-Core SPI Master" depends on OF && (SUPERH || COMPILE_TEST)
drivers/spi/Makefile +3 -0
@@ -61,6 +61,9 @@ obj-$(CONFIG_SPI_HISI_SFC_V3XX) += spi-hisi-sfc-v3xx.o obj-$(CONFIG_SPI_IMG_SPFI) += spi-img-spfi.o obj-$(CONFIG_SPI_IMX) += spi-imx.o obj-$(CONFIG_SPI_INGENIC) += spi-ingenic.o +obj-$(CONFIG_SPI_INTEL) += spi-intel.o +obj-$(CONFIG_SPI_INTEL_PCI) += spi-intel-pci.o +obj-$(CONFIG_SPI_INTEL_PLATFORM) += spi-intel-platform.o obj-$(CONFIG_SPI_LANTIQ_SSC) += spi-lantiq-ssc.o obj-$(CONFIG_SPI_JCORE) += spi-jcore.o obj-$(CONFIG_SPI_LM70_LLP) += spi-lm70llp.o
drivers/spi/spi-intel-pci.c renamed from drivers/mtd/spi-nor/controllers/intel-spi-pci.c +3 -17
@@ -2,16 +2,14 @@/* * Intel PCH/PCU SPI flash PCI driver. * -* Copyright (C) 2016, Intel Corporation +* Copyright (C) 2016 - 2021 Intel Corporation * Author: Mika Westerberg <[email protected]> */ -#include <linux/ioport.h> -#include <linux/kernel.h> #include <linux/module.h> #include <linux/pci.h> -#include "intel-spi.h" +#include "spi-intel.h" #define BCR 0xdc#define BCR_WPD BIT(0)
@@ -46,7 +44,6 @@ static int intel_spi_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) {struct intel_spi_boardinfo *info; -struct intel_spi *ispi;int ret; ret =pcim_enable_device (pdev);
@@ -59,17 +56,7 @@ static int intel_spi_pci_probe(struct pci_dev *pdev,return -ENOMEM ; info->data = pdev; - ispi =intel_spi_probe (&pdev->dev, &pdev->resource[0 ], info); -if (IS_ERR (ispi)) -return PTR_ERR (ispi); - -pci_set_drvdata (pdev, ispi); -return 0 ; -} - -static void intel_spi_pci_remove (struct pci_dev *pdev) -{ -intel_spi_remove (pci_get_drvdata (pdev)); +return intel_spi_probe (&pdev->dev, &pdev->resource[0 ], info); }static const struct pci_device_id intel_spi_pci_ids[] = {
@@ -98,7 +85,6 @@ static struct pci_driver intel_spi_pci_driver = { .name = "intel-spi", .id_table = intel_spi_pci_ids, .probe = intel_spi_pci_probe, - .remove = intel_spi_pci_remove, };module_pci_driver (intel_spi_pci_driver);
drivers/spi/spi-intel-platform.c renamed from drivers/mtd/spi-nor/controllers/intel-spi-platform.c +3 -18
@@ -2,20 +2,18 @@/* * Intel PCH/PCU SPI flash platform driver. * -* Copyright (C) 2016, Intel Corporation +* Copyright (C) 2016 - 2021 Intel Corporation * Author: Mika Westerberg <[email protected]> */ -#include <linux/ioport.h> #include <linux/module.h> #include <linux/platform_device.h> -#include "intel-spi.h" +#include "spi-intel.h" static int intel_spi_platform_probe (struct platform_device *pdev) {struct intel_spi_boardinfo *info; -struct intel_spi *ispi;struct resource *mem; info =dev_get_platdata (&pdev->dev);
@@ -23,24 +21,11 @@ static int intel_spi_platform_probe(struct platform_device *pdev)return -EINVAL ; mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - ispi =intel_spi_probe (&pdev->dev, mem, info); -if (IS_ERR (ispi)) -return PTR_ERR (ispi); - -platform_set_drvdata (pdev, ispi); -return 0 ; -} - -static int intel_spi_platform_remove (struct platform_device *pdev) -{ -struct intel_spi *ispi =platform_get_drvdata (pdev); - -return intel_spi_remove (ispi); +return intel_spi_probe (&pdev->dev, mem, info); }static struct platform_driver intel_spi_platform_driver = { .probe = intel_spi_platform_probe, - .remove = intel_spi_platform_remove, .driver = { .name ="intel-spi" , },
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +537 -269
1,021 lines not on this page · raw message
drivers/spi/spi-intel.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Intel PCH/PCU SPI flash driver. +* +* Copyright (C) 2016 - 2021, Intel Corporation +* Author: Mika Westerberg <[email protected]> +*/ + +#ifndef SPI_INTEL_H +#define SPI_INTEL_H + +#include <linux/platform_data/x86/spi-intel.h> + +struct resource ; + +int intel_spi_probe (struct device *dev,struct resource *mem, +const struct intel_spi_boardinfo *info); + +#endif /* SPI_INTEL_H */
include/linux/mfd/lpc_ich.h +1 -1
@@ -8,7 +8,7 @@#ifndef LPC_ICH_H #define LPC_ICH_H -#include <linux/platform_data/x86/intel-spi.h> +#include <linux/platform_data/x86/spi-intel.h> /* GPIO resources */ #define ICH_RES_GPIO 0
include/linux/platform_data/x86/spi-intel.h renamed from include/linux/platform_data/x86/intel-spi.h +3 -3
@@ -6,8 +6,8 @@* Author: Mika Westerberg <[email protected]> */ -#ifndef INTEL_SPI_PDATA_H -#define INTEL_SPI_PDATA_H +#ifndef SPI_INTEL_PDATA_H +#define SPI_INTEL_PDATA_H enum intel_spi_type { INTEL_SPI_BYT = 1,
@@ -28,4 +28,4 @@ struct intel_spi_boardinfo { void *data; }; -#endif /* INTEL_SPI_PDATA_H */ +#endif /* SPI_INTEL_PDATA_H */
Signature · 1 line
2.34.1
Re: [PATCH v5 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
Quoted 7 lines · Mika Westerberg
The preferred way to implement SPI-NOR controller drivers is through SPI subsubsystem utilizing the SPI MEM core functions. This converts the Intel SPI flash controller driver over the SPI MEM by moving the driver from SPI-NOR subsystem to SPI subsystem and in one go make it use the SPI MEM functions. The driver name will be changed from intel-spi to spi-intel to match the convention used in the SPI subsystem.
Quoted 5 lines
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Mauro Lima <[email protected]>Reviewed-by Boris Brezillon <[email protected]>Acked-by Lee Jones <[email protected]>
I remember acking this patch but maybe it got dropped along the way. Anyway,
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v5 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Mika WesterbergQuoted 8 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +0
-0
cut
Quoted 4 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +1
-2-static int intel_spi_erase (struct spi_nor *nor,loff_t offs) +static int intel_spi_erase (struct intel_spi *ispi,const struct spi_mem_op *op) { -size_t erase_size, len = nor->mtd.erasesize;
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 648
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +4
-3-struct intel_spi *ispi = nor->priv; +u8 opcode = op->cmd.opcode; +u32 addr = op->addr.val;u32 val, status, cmd;int ret; -/* If the hardware can do 64k erase use that when possible */ -if (len >=SZ_64K && ispi->erase_64k) { +switch (opcode) { +case SPINOR_OP_SE :
Would it worth to extend the intel_spi_mem_op struct and introduce an u32 replacement_op; member and use it directly here without doing the switch, so that we don't mix SPI NOR code in the driver?
Also the cmd assignement can be done after if (ispi->swseq_erase), right?
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 657
Quoted 12 lines
cmd = HSFSTS_CTL_FCYCLE_ERASE_64K;drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +7
-3- erase_size =SZ_64K ; - }else { +break ; + +case SPINOR_OP_BE_4K : cmd =HSFSTS_CTL_FCYCLE_ERASE ; - erase_size =SZ_4K ; +break ; + +default : +return -EINVAL ;
you have a INTEL_SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_BE_4K_4B, 1), ...) defined. supported_op will return true, but you get an -EINVAL here.
Quoted 34 lines
}drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +29
-3-if (ispi->swseq_erase) { -while (len >0 ) { -writel (offs, ispi->base +FADDR ); +writel (addr, ispi->base +FADDR ); + +if (ispi->swseq_erase) +return intel_spi_sw_cycle (ispi, opcode,0 , +OPTYPE_WRITE_WITH_ADDR ); + +/* Not needed with HW sequencer erase, make sure it is cleared */ + ispi->atomic_preopcode =0 ; + + val =readl (ispi->base +HSFSTS_CTL ); + val &= ~(HSFSTS_CTL_FDBC_MASK |HSFSTS_CTL_FCYCLE_MASK ); + val |=HSFSTS_CTL_AEL |HSFSTS_CTL_FCERR |HSFSTS_CTL_FDONE ; + val |=HSFSTS_CTL_FGO ; + val |= cmd; +writel (val, ispi->base +HSFSTS_CTL ); + + ret =intel_spi_wait_hw_busy (ispi); +if (ret) +return ret; + + status =readl (ispi->base +HSFSTS_CTL ); +if (status &HSFSTS_CTL_FCERR ) +return -EIO ; +if (status &HSFSTS_CTL_AEL ) +return -EACCES ; + +return 0 ; +} +
cut
Quoted 4 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +4
-0+static int intel_spi_exec_mem_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); +const struct intel_spi_mem_op *iop;
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 766
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +3
-6- val =readl (ispi->base +HSFSTS_CTL ); - val &= ~(HSFSTS_CTL_FDBC_MASK |HSFSTS_CTL_FCYCLE_MASK ); - val |=HSFSTS_CTL_AEL |HSFSTS_CTL_FCERR |HSFSTS_CTL_FDONE ; - val |= cmd; - val |=HSFSTS_CTL_FGO ; -writel (val, ispi->base +HSFSTS_CTL ); + iop =intel_spi_match_mem_op (ispi, op); +if (!iop) +return -EINVAL ;
return -EOPNOTSUPP?
Quoted 58 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +48
-8- ret =intel_spi_wait_hw_busy (ispi); -if (ret) -return ret; +return iop->exec_op (ispi, op); +} - status =readl (ispi->base +HSFSTS_CTL ); -if (status &HSFSTS_CTL_FCERR ) -return -EIO ; -else if (status &HSFSTS_CTL_AEL ) -return -EACCES ; +static const char *intel_spi_get_name (struct spi_mem *mem) +{ +const struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); + +/* +* Return name of the flash controller device to be compatible +* with the MTD version. +*/ +return dev_name (ispi->dev); +} + +static const struct spi_controller_mem_ops intel_spi_mem_ops = { + .supports_op = intel_spi_supports_mem_op, + .exec_op = intel_spi_exec_mem_op, + .get_name = intel_spi_get_name, +}; + +#define INTEL_SPI_OP_ADDR (__nbytes) \ + { \ + .nbytes = __nbytes, \ + } + +#define INTEL_SPI_OP_NO_DATA \ + { \ + .dir = SPI_MEM_NO_DATA, \ + } + +#define INTEL_SPI_OP_DATA_IN (__buswidth) \ + { \ + .dir = SPI_MEM_DATA_IN, \ + .buswidth = __buswidth, \ + } + +#define INTEL_SPI_OP_DATA_OUT (__buswidth) \ + { \ + .dir = SPI_MEM_DATA_OUT, \ + .buswidth = __buswidth, \ + } + +#define INTEL_SPI_MEM_OP (__cmd, __addr, __data, __exec_op) \ + { \ + .mem_op = { \ + .cmd = __cmd, \ + .addr = __addr, \ + .data = __data, \ + }, \
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len,
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +10
-0+ .exec_op = __exec_op, \ + } + +/* +* The controller handles pretty much everything internally based on the +* SFDP data but we want to make sure we only support the operations +* actually possible. Only check buswidth and transfer direction, the +* core validates data. +*/ +#define INTEL_SPI_GENERIC_OPS
checkpatch --strict complains:
ERROR: Macros with complex values should be enclosed in parentheses #955: FILE: drivers/spi/spi-intel.c:826:
+#define INTEL_SPI_GENERIC_OPS
\
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 831
Quoted 5 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +5
-0+/* Status register operations */ \ +INTEL_SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_RDID ,1 ), \ +SPI_MEM_OP_NO_ADDR , \ +INTEL_SPI_OP_DATA_IN (1 ), \ + intel_spi_read_reg), \
I like the idea with the array of ops. Maybe you'd like to order the ops and
put the ops that are highly used as the first elements in the array, so that you speed up a bit the op selection at run-time. No hard requirement.
Neat work. Thanks for the patience.
ta
Re: [PATCH v5 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
Hi,
Quoted 21 lines · On Tue, Feb 01, 2022 at 03:24:58PM +0000, [email protected] wrote:
Quoted 8 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +0
-0cut
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +3
-3-static int intel_spi_erase (struct spi_nor *nor,loff_t offs) +static int intel_spi_erase (struct intel_spi *ispi,const struct spi_mem_op *op) { -size_t erase_size, len = nor->mtd.erasesize; -struct intel_spi *ispi = nor->priv; +u8 opcode = op->cmd.opcode; +u32 addr = op->addr.val;u32 val, status, cmd;int ret;
Quoted 8 lines
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 648
Quoted 4 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +2
-2-/* If the hardware can do 64k erase use that when possible */ -if (len >=SZ_64K && ispi->erase_64k) { +switch (opcode) { +case SPINOR_OP_SE :Would it worth to extend the
intel_spi_mem_opstruct and introduce an u32replacement_op; member and use it directly here without doing the switch, so that we don't mix SPI NOR code in the driver?
Sure.
Quoted 17 lines
Also the cmd assignement can be done after if (
ispi->swseq_erase), right?drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 657
Quoted 12 lines
cmd = HSFSTS_CTL_FCYCLE_ERASE_64K;drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +7
-3- erase_size =SZ_64K ; - }else { +break ; + +case SPINOR_OP_BE_4K : cmd =HSFSTS_CTL_FCYCLE_ERASE ; - erase_size =SZ_4K ; +break ; + +default : +return -EINVAL ;you have a
INTEL_SPI_MEM_OP(SPI_MEM_OP_CMD(SPINOR_OP_BE_4K_4B, 1), ...)defined.supported_opwill return true, but you get an-EINVALhere.
Good catch. This will be dealt with the iop->replacement_op too (so the switch will be dropped completely) in v6.
Quoted 42 lines
Quoted 34 lines
}drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +29
-3-if (ispi->swseq_erase) { -while (len >0 ) { -writel (offs, ispi->base +FADDR ); +writel (addr, ispi->base +FADDR ); + +if (ispi->swseq_erase) +return intel_spi_sw_cycle (ispi, opcode,0 , +OPTYPE_WRITE_WITH_ADDR ); + +/* Not needed with HW sequencer erase, make sure it is cleared */ + ispi->atomic_preopcode =0 ; + + val =readl (ispi->base +HSFSTS_CTL ); + val &= ~(HSFSTS_CTL_FDBC_MASK |HSFSTS_CTL_FCYCLE_MASK ); + val |=HSFSTS_CTL_AEL |HSFSTS_CTL_FCERR |HSFSTS_CTL_FDONE ; + val |=HSFSTS_CTL_FGO ; + val |= cmd; +writel (val, ispi->base +HSFSTS_CTL ); + + ret =intel_spi_wait_hw_busy (ispi); +if (ret) +return ret; + + status =readl (ispi->base +HSFSTS_CTL ); +if (status &HSFSTS_CTL_FCERR ) +return -EIO ; +if (status &HSFSTS_CTL_AEL ) +return -EACCES ; + +return 0 ; +} +cut
Quoted 5 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +4
-0+static int intel_spi_exec_mem_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); +const struct intel_spi_mem_op *iop;
Quoted 11 lines
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 766
Quoted 9 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +3
-6- val =readl (ispi->base +HSFSTS_CTL ); - val &= ~(HSFSTS_CTL_FDBC_MASK |HSFSTS_CTL_FCYCLE_MASK ); - val |=HSFSTS_CTL_AEL |HSFSTS_CTL_FCERR |HSFSTS_CTL_FDONE ; - val |= cmd; - val |=HSFSTS_CTL_FGO ; -writel (val, ispi->base +HSFSTS_CTL ); + iop =intel_spi_match_mem_op (ispi, op); +if (!iop) +return -EINVAL ;return
-EOPNOTSUPP?
OK
Quoted 65 lines
Quoted 65 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +55
-8- ret =intel_spi_wait_hw_busy (ispi); -if (ret) -return ret; +return iop->exec_op (ispi, op); +} - status =readl (ispi->base +HSFSTS_CTL ); -if (status &HSFSTS_CTL_FCERR ) -return -EIO ; -else if (status &HSFSTS_CTL_AEL ) -return -EACCES ; +static const char *intel_spi_get_name (struct spi_mem *mem) +{ +const struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); + +/* +* Return name of the flash controller device to be compatible +* with the MTD version. +*/ +return dev_name (ispi->dev); +} + +static const struct spi_controller_mem_ops intel_spi_mem_ops = { + .supports_op = intel_spi_supports_mem_op, + .exec_op = intel_spi_exec_mem_op, + .get_name = intel_spi_get_name, +}; + +#define INTEL_SPI_OP_ADDR (__nbytes) \ + { \ + .nbytes = __nbytes, \ + } + +#define INTEL_SPI_OP_NO_DATA \ + { \ + .dir = SPI_MEM_NO_DATA, \ + } + +#define INTEL_SPI_OP_DATA_IN (__buswidth) \ + { \ + .dir = SPI_MEM_DATA_IN, \ + .buswidth = __buswidth, \ + } + +#define INTEL_SPI_OP_DATA_OUT (__buswidth) \ + { \ + .dir = SPI_MEM_DATA_OUT, \ + .buswidth = __buswidth, \ + } + +#define INTEL_SPI_MEM_OP (__cmd, __addr, __data, __exec_op) \ + { \ + .mem_op = { \ + .cmd = __cmd, \ + .addr = __addr, \ + .data = __data, \ + }, \ + .exec_op = __exec_op, \ + } + +/* +* The controller handles pretty much everything internally based on the +* SFDP data but we want to make sure we only support the operations +* actually possible. Only check buswidth and transfer direction, the
Quoted 8 lines
Quoted 3 lines
+ * core validates data.
+ */
+#defineINTEL_SPI_GENERIC_OPScheckpatch --strict complains:
ERROR: Macros with complex values should be enclosed in parentheses #955: FILE:drivers/spi/spi-intel.c:826:
+#defineINTEL_SPI_GENERIC_OPS
I saw that too but to be honest, I have no idea how this could be applied to the macros here. Therefore I chose to ignore this one.
Quoted 10 lines
\drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 831
Quoted 5 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +5
-0+/* Status register operations */ \ +INTEL_SPI_MEM_OP (SPI_MEM_OP_CMD (SPINOR_OP_RDID ,1 ), \ +SPI_MEM_OP_NO_ADDR , \ +INTEL_SPI_OP_DATA_IN (1 ), \ + intel_spi_read_reg), \I like the idea with the array of ops. Maybe you'd like to order the ops and
put the ops that are highly used as the first elements in the array, so that you speed up a bit the op selection at run-time. No hard requirement.
I think for better maintainability ordering them by type is better. I will be adding dirmap support in subsequent patches which should then use cached ->exec_op for read/write so there is no need to look up the op more than once.
Quoted 1 line
Neat work. Thanks for the patience.
Thanks for the review! :)
PATCH v5 3/3 Documentation / MTD: Rename the intel-spi driver
In reply to Mika WesterbergSince the driver is renamed (and moved) update the BIOS upgrade guide accordingly from intel-spi to spi-intel. Keep the guide under MTD documentation because this is pretty much still about MTD and SPI-NOR.
---
Documentation/driver-api/mtd/index.rst | 2 +-
.../driver-api/mtd/{intel-spi.rst => spi-intel.rst} | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
rename Documentation/driver-api/mtd/{intel-spi.rst => spi-intel.rst} (94%)Documentation/driver-api/mtd/index.rst +1 -1
@@ -7,6 +7,6 @@ Memory Technology Device (MTD) .. toctree:: :maxdepth: 1 - intel-spi + spi-intel nand_ecc spi-nor
Documentation/driver-api/mtd/spi-intel.rst renamed from Documentation/driver-api/mtd/intel-spi.rst +4 -4
@@ -1,5 +1,5 @@ ============================== -Upgrading BIOS using intel-spi +Upgrading BIOS using spi-intel ============================== Many Intel CPUs like Baytrail and Braswell include SPI serial flash host
@@ -11,12 +11,12 @@ avoid accidental (or on purpose) overwrite of the content. Not all manufacturers protect the SPI serial flash, mainly because it allows upgrading the BIOS image directly from an OS. -The intel-spi driver makes it possible to read and write the SPI serial +The spi-intel driver makes it possible to read and write the SPI serial flash, if certain protection bits are not set and locked. If it finds any of them set, the whole MTD device is made read-only to prevent partial overwrites. By default the driver exposes SPI serial flash contents as read-only but it can be changed from kernel command line, -passing "intel-spi.writeable=1". +passing "spi_intel.writeable=1". Please keep in mind that overwriting the BIOS image on SPI serial flash might render the machine unbootable and requires special equipment like
@@ -32,7 +32,7 @@ Linux. serial flash. Distros like Debian and Fedora have this prepackaged with name "mtd-utils". - 3) Add "intel-spi.writeable=1" to the kernel command line and reboot + 3) Add "spi_intel.writeable=1" to the kernel command line and reboot the board (you can also reload the driver passing "writeable=1" as module parameter to modprobe).
Signature · 6 lines
2.34.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
Re: [PATCH v5 3/3] Documentation / MTD: Rename the intel-spi driver
Quoted 9 lines · Mika Westerberg
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Since the driver is renamed (and moved) update the BIOS upgrade guide accordingly from intel-spi to spi-intel. Keep the guide under MTD documentation because this is pretty much still about MTD and SPI-NOR.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Mauro Lima <[email protected]>
Quoted 59 lines
--- Documentation/driver-api/mtd/index.rst | 2 +- .../driver-api/mtd/{intel-spi.rst => spi-intel.rst} | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) rename Documentation/driver-api/mtd/{intel-spi.rst => spi-intel.rst} (94%)Documentation/driver-api/mtd/index.rst +1
-1@@ -7,6 +7,6 @@ Memory Technology Device (MTD) .. toctree:: :maxdepth: 1 - intel-spi + spi-intel nand_ecc spi-norDocumentation/driver-api/mtd/spi-intel.rst renamed from Documentation/driver-api/mtd/intel-spi.rst +4
-5@@ -1,5 +1,5 @@ ============================== -Upgrading BIOS using intel-spi +Upgrading BIOS using spi-intel ============================== Many Intel CPUs like Baytrail and Braswell include SPI serial flash host@@ -11,12 +11,12 @@ avoid accidental (or on purpose) overwrite of the content. Not all manufacturers protect the SPI serial flash, mainly because it allows upgrading the BIOS image directly from an OS. -The intel-spi driver makes it possible to read and write the SPI serial +The spi-intel driver makes it possible to read and write the SPI serial flash, if certain protection bits are not set and locked. If it finds any of them set, the whole MTD device is made read-only to prevent partial overwrites. By default the driver exposes SPI serial flash contents as read-only but it can be changed from kernel command line, -passing "intel-spi.writeable=1". +passing "spi_intel.writeable=1". Please keep in mind that overwriting the BIOS image on SPI serial flash might render the machine unbootable and requires special equipment like@@ -32,7 +32,7 @@ Linux. serial flash. Distros like Debian and Fedora have this prepackaged with name "mtd-utils". - 3) Add "intel-spi.writeable=1" to the kernel command line and reboot + 3) Add "spi_intel.writeable=1" to the kernel command line and reboot the board (you can also reload the driver passing "writeable=1" as module parameter to modprobe). --2.34.1
Hi Tudor and Mark,
Quoted 9 lines · Mika Westerberg
Hi all,
Based on discussion on the patch I sent some time ago here:
http://lists.infradead.org/pipermail/linux-mtd/2021-June/086867.html
it turns out that the preferred way to deal with the SPI flash controller drivers is through SPI MEM which is part of Linux SPI subsystem.
Quoted 7 lines
This series does that for the intel-spi driver. This also renames the driver to follow the convention used in the SPI subsystem. The first patch improves the write protection handling to be slightly more safer. The following two patches do the conversion itself. Note the Intel SPI flash controller only allows commands such as read, write and so on and it internally uses whatever addressing etc. it figured from the SFDP on the flash device.
Any chance to get this one merged?
Thanks!
Quoted 3 lines · Mika Westerberg
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Hi Tudor and Mark,
Hi!
Quoted 19 lines · Mika Westerberg
Quoted 9 lines
Hi all,
Based on discussion on the patch I sent some time ago here:
http://lists.infradead.org/pipermail/linux-mtd/2021-June/086867.html
it turns out that the preferred way to deal with the SPI flash controller drivers is through SPI MEM which is part of Linux SPI subsystem.
Quoted 7 lines
This series does that for the intel-spi driver. This also renames the driver to follow the convention used in the SPI subsystem. The first patch improves the write protection handling to be slightly more safer. The following two patches do the conversion itself. Note the Intel SPI flash controller only allows commands such as read, write and so on and it internally uses whatever addressing etc. it figured from the SFDP on the flash device.
Quoted 2 lines
Any chance to get this one merged?
Sure, it's a candidate for 5.18. I don't have anything against the move to SPI, but I didn't get the chance to go through your series. Will try to do it.
Cheers,
ta