mtd: spi-nor / spi / MFD: Convert intel-spi to SPI MEM
Subsystems (7)
PATCH v3 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 · 1 line
2.33.0
v3 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:
v2: https://lore.kernel.org/linux-mtd/[email protected]/
v1: https://lore.kernel.org/linux-mtd/[email protected]/
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} | 357 +++++++++++-------
drivers/spi/spi-intel.h | 19 +
include/linux/mfd/lpc_ich.h | 2 +-
.../x86/{intel-spi.h => spi-intel.h} | 12 +-
14 files changed, 367 insertions(+), 264 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} (77%)
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.33.0
PATCH v3 2/3 mtd: spi-nor: intel-spi: Convert to SPI MEM
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.
---
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} | 316 +++++++++++-------
drivers/spi/spi-intel.h | 19 ++
include/linux/mfd/lpc_ich.h | 2 +-
.../x86/{intel-spi.h => spi-intel.h} | 6 +-
11 files changed, 266 insertions(+), 220 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} (79%)
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
@@ -406,6 +406,45 @@ config SPI_IMX help This enables support for the Freescale i.MX SPI controllers. +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
@@ -59,6 +59,9 @@ obj-$(CONFIG_SPI_HISI_KUNPENG) += spi-hisi-kunpeng.o 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_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 +195 -121
470 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.33.0
PATCH v3 1/3 mtd: spi-nor: intel-spi: Disable write protection only if asked
In reply to Mika WesterbergCurrently 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.33.0
Hi all,
Quoted 70 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.
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:
v2: https://lore.kernel.org/linux-mtd/[email protected]/
v1: https://lore.kernel.org/linux-mtd/[email protected]/Changes from v2:
* Added tag from Andy
* Check buswidth inintel_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
Kconfigentries the same way in both glue drivers.
* Added empty lines between different subsystem includes.
*dev_err()to single line
* Returnintel_spi_sw_cycle()directly inintel_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 driverDocumentation/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} | 357 +++++++++++------- drivers/spi/spi-intel.h | 19 + include/linux/mfd/lpc_ich.h | 2 +- .../x86/{intel-spi.h => spi-intel.h} | 12 +- 14 files changed, 367 insertions(+), 264 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} (77%) create mode 100644 drivers/spi/spi-intel.h rename include/linux/platform_data/x86/{intel-spi.h => spi-intel.h} (64%)
Quoted 3 lines
--
2.33.0
$ ./scripts/checkpatch.pl --file --strict drivers/spi/spi-intel.c CHECK: Alignment should match open parenthesis #215: FILE: drivers/spi/spi-intel.c:215: + dev_dbg(ispi->dev, " %02d base: 0x%08x limit: 0x%08x [%c%c]\n", + i, base << 12, (limit << 12) | 0xfff,
CHECK: Alignment should match open parenthesis #232: FILE: drivers/spi/spi-intel.c:232:
+ dev_dbg(ispi->dev, " %02d base: 0x%08x limit: 0x%08x\n",
+ i, base << 12, (limit << 12) | 0xfff);
CHECK: Comparison to NULL could be written "!ispi->sregs" #378: FILE: drivers/spi/spi-intel.c:378:
+ if (ispi->sregs == NULL && (ispi->swseq_reg || ispi->swseq_erase)) {
CHECK: Blank lines aren't necessary before a close brace '}' #534: FILE: drivers/spi/spi-intel.c:534:
+
+ }
Beside these checks,
Thanks
Re: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Mika WesterbergQuoted 29 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.
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- 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} | 316 +++++++++++------- drivers/spi/spi-intel.h | 19 ++ include/linux/mfd/lpc_ich.h | 2 +- .../x86/{intel-spi.h => spi-intel.h} | 6 +- 11 files changed, 266 insertions(+), 220 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} (79%) create mode 100644 drivers/spi/spi-intel.h rename include/linux/platform_data/x86/{intel-spi.h => spi-intel.h} (89%)
[...]
Quoted 6 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +6
-0+static bool intel_spi_supports_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); + +if (op->cmd.dtr)
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 809
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +10
-0+return false; + +/* +* The Intel controller supports widths up to 4 but it handles +* them automatically and does not expose them to software. Here +* we accept anything up to 4. +*/ +if (op->cmd.buswidth >4 || + (op->addr.nbytes && op->addr.buswidth >4 ) || + (op->dummy.nbytes && op->dummy.buswidth >4 ))
Also need to check data buswidth here?
Other than this,
Quoted 66 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +36
-21+return false; + +if (ispi->swseq_reg && ispi->locked) { +int i; + +/* Check if it is in the locked opcodes list */ +for (i =0 ; i <ARRAY_SIZE (ispi->opcodes); i++) { +if (ispi->opcodes[i] == op->cmd.opcode) + goto check_opcode; } -return 0 ; +return false; } -/* Not needed with HW sequencer erase, make sure it is cleared */ - ispi->atomic_preopcode =0 ; +check_opcode: +switch (op->cmd.opcode) { +case SPINOR_OP_RDID : +case SPINOR_OP_RDSR : +case SPINOR_OP_WRSR : +return true; -while (len >0 ) { -writel (offs, ispi->base +FADDR ); +case SPINOR_OP_READ : +case SPINOR_OP_READ_FAST : +case SPINOR_OP_READ_4B : +case SPINOR_OP_READ_FAST_4B : +return true; - 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 ); +case SPINOR_OP_PP : +case SPINOR_OP_PP_4B : +case SPINOR_OP_WREN : +case SPINOR_OP_WRDI : +return true; - ret =intel_spi_wait_hw_busy (ispi); -if (ret) -return ret; +case SPINOR_OP_SE : +case SPINOR_OP_SE_4B : +return ispi->erase_64k; - status =readl (ispi->base +HSFSTS_CTL ); -if (status &HSFSTS_CTL_FCERR ) -return -EIO ; -else if (status &HSFSTS_CTL_AEL ) -return -EACCES ; +case SPINOR_OP_BE_4K : +case SPINOR_OP_BE_4K_4B : +return true; + } - offs += erase_size; - len -= erase_size; +return false; +} +
[...]
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Mika WesterbergQuoted 7 lines · On Wed, 13 Oct 2021 14:44:31 +0300 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.
I skimmed over the driver changes, and I'm skeptical about this "let's convert all spi-nor controller drivers into spi-mem drivers even if they don't fit the spi-mem model" strategy. Clearly, the intel controller is much more limited than any other spi-mem controller (I mean feature-wise not perf-wise of course). The fact that you have to check the opcode to decide whether the operation is supported or not, or the way you deduce when to issue an erase vs a regular read/write is kind of hack-ish. Not saying we shouldn't support this case in spi-mem, but it should at least be done in a more controlled way. Maybe with an explicit array of supported spi_mem operations, and driver specific hooks for each of these operations so anything falling outside is clearly identified and rejected (we have this sort of things in the raw NAND framework).
Quoted 33 lines
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +26
-1+static bool intel_spi_supports_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); + +if (op->cmd.dtr) +return false; + +/* +* The Intel controller supports widths up to 4 but it handles +* them automatically and does not expose them to software. Here +* we accept anything up to 4. +*/ +if (op->cmd.buswidth >4 || + (op->addr.nbytes && op->addr.buswidth >4 ) || + (op->dummy.nbytes && op->dummy.buswidth >4 )) +return false; + +if (ispi->swseq_reg && ispi->locked) { +int i; + +/* Check if it is in the locked opcodes list */ +for (i =0 ; i <ARRAY_SIZE (ispi->opcodes); i++) { +if (ispi->opcodes[i] == op->cmd.opcode) + goto check_opcode; } -return 0 ; +return false;
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 829
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +6
-2} -/* Not needed with HW sequencer erase, make sure it is cleared */ - ispi->atomic_preopcode =0 ; +check_opcode: +switch (op->cmd.opcode) { +case SPINOR_OP_RDID : +case SPINOR_OP_RDSR : +case SPINOR_OP_WRSR : +return true;
Ouch. I hate how spi-nor specific stuff leak into the supposedly spi-mem generic driver. Now if we want to allow such specialization, we should at least make sure the whole operation is consistent instead of checking the opcode, address, dummy and data cycles separately.
Quoted 48 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +25
-18-while (len >0 ) { -writel (offs, ispi->base +FADDR ); +case SPINOR_OP_READ : +case SPINOR_OP_READ_FAST : +case SPINOR_OP_READ_4B : +case SPINOR_OP_READ_FAST_4B : +return true; - 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 ); +case SPINOR_OP_PP : +case SPINOR_OP_PP_4B : +case SPINOR_OP_WREN : +case SPINOR_OP_WRDI : +return true; - ret =intel_spi_wait_hw_busy (ispi); -if (ret) -return ret; +case SPINOR_OP_SE : +case SPINOR_OP_SE_4B : +return ispi->erase_64k; - status =readl (ispi->base +HSFSTS_CTL ); -if (status &HSFSTS_CTL_FCERR ) -return -EIO ; -else if (status &HSFSTS_CTL_AEL ) -return -EACCES ; +case SPINOR_OP_BE_4K : +case SPINOR_OP_BE_4K_4B : +return true; + } - offs += erase_size; - len -= erase_size; +return false; +} + +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); +size_t nbytes = op->data.nbytes; +u8 opcode = op->cmd.opcode;
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 869
Quoted 10 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +10
-0+ +if (op->addr.nbytes) { +if (op->data.dir ==SPI_MEM_DATA_IN ) +return intel_spi_read (ispi, op->addr.val, nbytes, + op->data.buf.in); +if (op->data.dir ==SPI_MEM_DATA_OUT ) +return intel_spi_write (ispi, op->addr.val, nbytes, + op->data.buf.out); +if (op->data.dir ==SPI_MEM_NO_DATA ) +return intel_spi_erase (ispi, opcode, op->addr.val);
That's risky IMHO, how can you be sure that NO_DATA means erase? Again, it looks like the whole operation should be checked, not just the data field.
Quoted 15 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +12
-1+ }else { +if (op->data.dir ==SPI_MEM_DATA_IN ) +return intel_spi_read_reg (ispi, opcode, op->data.buf.in, + nbytes); +if (op->data.dir ==SPI_MEM_DATA_OUT ) +return intel_spi_write_reg (ispi, opcode, op->data.buf.out, + nbytes); +if (op->data.dir ==SPI_MEM_NO_DATA ) +return intel_spi_write_reg (ispi, opcode,NULL ,0 ); } -return 0 ; +return -EINVAL ; +} +
Re: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
Quoted 11 lines · Boris Brezillon
Quoted 7 lines · On Wed, 13 Oct 2021 14:44:31 +0300 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 13 lines
I skimmed over the driver changes, and I'm skeptical about this "let's convert all spi-nor controller drivers into spi-mem drivers even if they don't fit the spi-mem model" strategy. Clearly, the intel controller is much more limited than any other spi-mem controller (I mean feature-wise not perf-wise of course). The fact that you have to check the opcode to decide whether the operation is supported or not, or the way you deduce when to issue an erase vs a regular read/write is kind of hack-ish. Not saying we shouldn't support this case in spi-mem, but it should at least be done in a more controlled way. Maybe with an explicit array of supported
spi_memoperations, and driver specific hooks for each of these operations so anything falling outside is clearly identified and rejected (we have this sort of things in the raw NAND framework).
I am curious about how we can solve this. Any pointers to functions/drivers in raw NAND framework that follow this model?
[...]
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
Quoted 26 lines · On Wed, 20 Oct 2021 17:29:15 +0530 Pratyush Yadav <[email protected]> wrote:
Quoted 11 lines · Boris Brezillon
Quoted 7 lines · On Wed, 13 Oct 2021 14:44:31 +0300 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 13 lines
I skimmed over the driver changes, and I'm skeptical about this "let's convert all spi-nor controller drivers into spi-mem drivers even if they don't fit the spi-mem model" strategy. Clearly, the intel controller is much more limited than any other spi-mem controller (I mean feature-wise not perf-wise of course). The fact that you have to check the opcode to decide whether the operation is supported or not, or the way you deduce when to issue an erase vs a regular read/write is kind of hack-ish. Not saying we shouldn't support this case in spi-mem, but it should at least be done in a more controlled way. Maybe with an explicit array of supported
spi_memoperations, and driver specific hooks for each of these operations so anything falling outside is clearly identified and rejected (we have this sort of things in the raw NAND framework).
Quoted 2 lines
I am curious about how we can solve this. Any pointers to functions/drivers in raw NAND framework that follow this model?
It's not quite what you'd need, but nand_op_parser_pattern follows the same philosophy: describe a pattern and attach a hook to be executed when this pattern is found. Then you pass this pattern table to a helper that tries to match the operation against the supported patterns. If it finds one that matches, the operation is reported as supported and/or executed, otherwise it's rejected.
In this particular case, the pattern must be very specific:
* matching opcode
* matching direction
* matching number of address cycles
* matching number of dummy cycles?
* max/min number of data cycles?
Miquel Raynal
maintainerRe: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Pratyush YadavHi Pratyush,
[email protected] wrote on Wed, 20 Oct 2021 17:29:15 +0530:
Quoted 26 lines · Boris Brezillon
Quoted 11 lines
Quoted 7 lines · On Wed, 13 Oct 2021 14:44:31 +0300 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 13 lines
I skimmed over the driver changes, and I'm skeptical about this "let's convert all spi-nor controller drivers into spi-mem drivers even if they don't fit the spi-mem model" strategy. Clearly, the intel controller is much more limited than any other spi-mem controller (I mean feature-wise not perf-wise of course). The fact that you have to check the opcode to decide whether the operation is supported or not, or the way you deduce when to issue an erase vs a regular read/write is kind of hack-ish. Not saying we shouldn't support this case in spi-mem, but it should at least be done in a more controlled way. Maybe with an explicit array of supported
spi_memoperations, and driver specific hooks for each of these operations so anything falling outside is clearly identified and rejected (we have this sort of things in the raw NAND framework).
Quoted 2 lines
I am curious about how we can solve this. Any pointers to functions/drivers in raw NAND framework that follow this model?
->exec_op() should be implemented by controller drivers, there is a check_only flag to verify that the operation is supported by the controller, the entire operation is provided so that the controller driver knows exactly where we are going and does not try to guess anything. There is also a parser in the core that allows "complicated"/"constrained" drivers to just give a number of patterns they support and the parser will do the job of finding how the operation should be split.
I believe this was what Boris referred to. If not, please correct me.
Thanks,
Miquèl
Re: [PATCH v3 2/3] mtd: spi-nor: intel-spi: Convert to SPI MEM
In reply to Boris BrezillonQuoted 11 lines · Boris Brezillon
Quoted 7 lines · On Wed, 13 Oct 2021 14:44:31 +0300 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 13 lines
I skimmed over the driver changes, and I'm skeptical about this "let's convert all spi-nor controller drivers into spi-mem drivers even if they don't fit the spi-mem model" strategy. Clearly, the intel controller is much more limited than any other spi-mem controller (I mean feature-wise not perf-wise of course). The fact that you have to check the opcode to decide whether the operation is supported or not, or the way you deduce when to issue an erase vs a regular read/write is kind of hack-ish. Not saying we shouldn't support this case in spi-mem, but it should at least be done in a more controlled way. Maybe with an explicit array of supported
spi_memoperations, and driver specific hooks for each of these operations so anything falling outside is clearly identified and rejected (we have this sort of things in the raw NAND framework).
I'm not fan of this either but this was requirement from the SPI-NOR maintainers before any new features can be added, and we have a bunch of new hardware that needs to be supported :(
Sure, I can take a look at the array you suggest if that helps to get things moving. Any objections anyone for doing this?
Quoted 35 lines
Quoted 35 lines
Signed-off-by Mika Westerberg <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>---
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +26
-1+static bool intel_spi_supports_mem_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct intel_spi *ispi =spi_master_get_devdata (mem->spi->master); + +if (op->cmd.dtr) +return false; + +/* +* The Intel controller supports widths up to 4 but it handles +* them automatically and does not expose them to software. Here +* we accept anything up to 4. +*/ +if (op->cmd.buswidth >4 || + (op->addr.nbytes && op->addr.buswidth >4 ) || + (op->dummy.nbytes && op->dummy.buswidth >4 )) +return false; + +if (ispi->swseq_reg && ispi->locked) { +int i; + +/* Check if it is in the locked opcodes list */ +for (i =0 ; i <ARRAY_SIZE (ispi->opcodes); i++) { +if (ispi->opcodes[i] == op->cmd.opcode) + goto check_opcode; } -return 0 ; +return false; }
Quoted 13 lines
drivers/spi/spi-intel.c static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len, · line 829
Quoted 8 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +6
-2-/* Not needed with HW sequencer erase, make sure it is cleared */ - ispi->atomic_preopcode =0 ; +check_opcode: +switch (op->cmd.opcode) { +case SPINOR_OP_RDID : +case SPINOR_OP_RDSR : +case SPINOR_OP_WRSR : +return true;Ouch. I hate how spi-nor specific stuff leak into the supposedly spi-mem generic driver. Now if we want to allow such specialization, we should at least make sure the whole operation is consistent instead of checking the opcode, address, dummy and data cycles separately.
OK.
Quoted 53 lines
Quoted 53 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +31
-18-while (len >0 ) { -writel (offs, ispi->base +FADDR ); +case SPINOR_OP_READ : +case SPINOR_OP_READ_FAST : +case SPINOR_OP_READ_4B : +case SPINOR_OP_READ_FAST_4B : +return true; - 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 ); +case SPINOR_OP_PP : +case SPINOR_OP_PP_4B : +case SPINOR_OP_WREN : +case SPINOR_OP_WRDI : +return true; - ret =intel_spi_wait_hw_busy (ispi); -if (ret) -return ret; +case SPINOR_OP_SE : +case SPINOR_OP_SE_4B : +return ispi->erase_64k; - status =readl (ispi->base +HSFSTS_CTL ); -if (status &HSFSTS_CTL_FCERR ) -return -EIO ; -else if (status &HSFSTS_CTL_AEL ) -return -EACCES ; +case SPINOR_OP_BE_4K : +case SPINOR_OP_BE_4K_4B : +return true; + } - offs += erase_size; - len -= erase_size; +return false; +} + +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); +size_t nbytes = op->data.nbytes; +u8 opcode = op->cmd.opcode; + +if (op->addr.nbytes) { +if (op->data.dir ==SPI_MEM_DATA_IN ) +return intel_spi_read (ispi, op->addr.val, nbytes, + op->data.buf.in); +if (op->data.dir ==SPI_MEM_DATA_OUT )
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 869
Quoted 4 lines
drivers/spi/spi-intel.c renamed from drivers/mtd/spi-nor/controllers/intel-spi.c +4
-0+return intel_spi_write (ispi, op->addr.val, nbytes, + op->data.buf.out); +if (op->data.dir ==SPI_MEM_NO_DATA ) +return intel_spi_erase (ispi, opcode, op->addr.val);That's risky IMHO, how can you be sure that
NO_DATAmeans erase? Again, it looks like the whole operation should be checked, not just the data field.
intel_spi_erase() does further checks based on the opcode:
switch (opcode) {
case SPINOR_OP_SE:
cmd = HSFSTS_CTL_FCYCLE_ERASE_64K;
break;
case SPINOR_OP_BE_4K:
cmd = HSFSTS_CTL_FCYCLE_ERASE;
break;
default:
return -EINVAL;
}I should probably add comment on the caller to make it clear though.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/