Skip to contentSkip to conversation

spi: dw: Cleanup macros/funcs naming and add IP-core version support

PATCH In review Serge Semin 4 participants 12 messages Nov 15, 2021 – Nov 16, 2021 SPI

lore
Share & tools
lore
#0 lore raw

v3 cover spi: dw: Cleanup macros/funcs naming and add IP-core version support

I was going to submit a cleanup patchset for the DW SSI driver for a long time, but due to lack of free time couldn't make it so far. Nandhini's series [1] made me to proceed with this task so mate would finally have his patchset accepted and merged into the mainline kernel.

There are four cleanup patches here and three feature patches. In the framework of the former patches we convert the DW SPI driver to using module namespaces and provide a better code organization. In particular the second part concerns the methods and macros naming unification (using a unified prefixes of the code object names) and the CSR fields macro implementation using the bitfield helpers available in the kernel. The later patches introduce the DW SSI IP-core versions interface so it could be used for a version-specific features implementation. Nandhini will be mostly interested in the later patches in the framework of his series [1].

Nandhini, could you please test the patchset out on your DWC SSI hardware? After it's merged into the spi/for-next branch of the Mark' repository you will be able to rebase your series on top of it and use the last IP-core version interface for your benefit.

Andy, I have added your tag to all the patches except the last one since it's new (though suggested by you).

[1] https://lore.kernel.org/linux-spi/[email protected]

Changelog v2:
- Replace "assi" suffixes with "pssi" in the spi-dw-mmio.c methods. (Thanks Andy for noticing this pity mistake)
- Add new patches:
[PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker [PATCH v2 1/6] spi: dw: Add symbol namespaces for the core and DMA modules
- Replace the ASCII-to-integer conversion with a unified IP-core versioning interface (Suggested by Andy).

Changelog v3:
- Discard the symbols importing from the spi-dw-dma object since it's linked into the spi-dw-core module anyway thus having the same symbols namespace.
- Move the DW_SPI_CAP_DFS32 capability flag position fix to a separate patch.

Serge Semin (7):
spi: dw: Add a symbols namespace for the core module
spi: dw: Discard redundant DW SSI Frame Formats enumeration
spi: dw: Put the driver entities naming in order
spi: dw: Convert to using the Bitfield access macros
spi: dw: Introduce Synopsys IP-core versions interface
spi: dw: Replace DWC_HSSI capability with IP-core version checker
spi: dw: Define the capabilities in a continuous bit-flags set

 drivers/spi/spi-dw-bt1.c  |   9 +-
 drivers/spi/spi-dw-core.c | 175 ++++++++++++++++++++----------------
 drivers/spi/spi-dw-dma.c  |  55 ++++++------
 drivers/spi/spi-dw-mmio.c |  22 ++---
 drivers/spi/spi-dw-pci.c  |  60 ++++++-------
 drivers/spi/spi-dw.h      | 182 ++++++++++++++++++++------------------
 6 files changed, 271 insertions(+), 232 deletions(-)
Signature · 1 line
2.33.0
#1 lore raw

PATCH v3 1/7 spi: dw: Add a symbols namespace for the core module

The exported from the DW SPI driver core/DMA symbols are only used by the spi-dw-{mmio,pci,bt1}.o objects. Add these symbols to a separate namespace then and make sure the depended modules have it imported.

---

Changelog v2:
- This is a new patch created as of Andy' suggestion.

Changelog v3:
- Discard the symbols importing from the spi-dw-dma object since it's linked into the spi-dw-core module anyway thus having the same symbols namespace.

---
 drivers/spi/spi-dw-bt1.c  |  1 +
 drivers/spi/spi-dw-core.c | 14 +++++++-------
 drivers/spi/spi-dw-dma.c  |  5 +++--
 drivers/spi/spi-dw-mmio.c |  1 +
 drivers/spi/spi-dw-pci.c  |  1 +
 5 files changed, 13 insertions(+), 9 deletions(-)
drivers/spi/spi-dw-bt1.c +1 -0
index 5be6b7b80c21..ac7e4f30d1da 100644
@@ -339,3 +339,4 @@ module_platform_driver(dw_spi_bt1_driver);
 MODULE_AUTHOR("Serge Semin <[email protected]>");
 MODULE_DESCRIPTION("Baikal-T1 System Boot SPI Controller driver");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(SPI_DW_CORE);
drivers/spi/spi-dw-core.c +7 -7
index a305074c482e..a14940403ab4 100644
@@ -106,7 +106,7 @@ void dw_spi_set_cs(struct spi_device *spi, bool enable)
 	else
 		dw_writel(dws, DW_SPI_SER, 0);
 }
-EXPORT_SYMBOL_GPL(dw_spi_set_cs);
+EXPORT_SYMBOL_NS_GPL(dw_spi_set_cs, SPI_DW_CORE);
 
 /* Return the max entries we can fill into tx fifo */
 static inline u32 tx_max(struct dw_spi *dws)
@@ -210,7 +210,7 @@ int dw_spi_check_status(struct dw_spi *dws, bool raw)
 
 	return ret;
 }
-EXPORT_SYMBOL_GPL(dw_spi_check_status);
+EXPORT_SYMBOL_NS_GPL(dw_spi_check_status, SPI_DW_CORE);
 
 static irqreturn_t dw_spi_transfer_handler(struct dw_spi *dws)
 {
@@ -345,7 +345,7 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
 		dws->cur_rx_sample_dly = chip->rx_sample_dly;
 	}
 }
-EXPORT_SYMBOL_GPL(dw_spi_update_config);
+EXPORT_SYMBOL_NS_GPL(dw_spi_update_config, SPI_DW_CORE);
 
 static void dw_spi_irq_setup(struct dw_spi *dws)
 {
@@ -945,7 +945,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
 	spi_controller_put(master);
 	return ret;
 }
-EXPORT_SYMBOL_GPL(dw_spi_add_host);
+EXPORT_SYMBOL_NS_GPL(dw_spi_add_host, SPI_DW_CORE);
 
 void dw_spi_remove_host(struct dw_spi *dws)
 {
@@ -960,7 +960,7 @@ void dw_spi_remove_host(struct dw_spi *dws)
 
 	free_irq(dws->irq, dws->master);
 }
-EXPORT_SYMBOL_GPL(dw_spi_remove_host);
+EXPORT_SYMBOL_NS_GPL(dw_spi_remove_host, SPI_DW_CORE);
 
 int dw_spi_suspend_host(struct dw_spi *dws)
 {
@@ -973,14 +973,14 @@ int dw_spi_suspend_host(struct dw_spi *dws)
 	spi_shutdown_chip(dws);
 	return 0;
 }
-EXPORT_SYMBOL_GPL(dw_spi_suspend_host);
+EXPORT_SYMBOL_NS_GPL(dw_spi_suspend_host, SPI_DW_CORE);
 
 int dw_spi_resume_host(struct dw_spi *dws)
 {
 	spi_hw_init(&dws->master->dev, dws);
 	return spi_controller_resume(dws->master);
 }
-EXPORT_SYMBOL_GPL(dw_spi_resume_host);
+EXPORT_SYMBOL_NS_GPL(dw_spi_resume_host, SPI_DW_CORE);
 
 MODULE_AUTHOR("Feng Tang <[email protected]>");
 MODULE_DESCRIPTION("Driver for DesignWare SPI controller core");
drivers/spi/spi-dw-dma.c +3 -2
index a09831c62192..ca199eee0f13 100644
@@ -10,6 +10,7 @@
 #include <linux/dmaengine.h>
 #include <linux/irqreturn.h>
 #include <linux/jiffies.h>
+#include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/platform_data/dma-dw.h>
 #include <linux/spi/spi.h>
@@ -638,7 +639,7 @@ void dw_spi_dma_setup_mfld(struct dw_spi *dws)
 {
 	dws->dma_ops = &dw_spi_dma_mfld_ops;
 }
-EXPORT_SYMBOL_GPL(dw_spi_dma_setup_mfld);
+EXPORT_SYMBOL_NS_GPL(dw_spi_dma_setup_mfld, SPI_DW_CORE);
 
 static const struct dw_spi_dma_ops dw_spi_dma_generic_ops = {
 	.dma_init	= dw_spi_dma_init_generic,
@@ -653,4 +654,4 @@ void dw_spi_dma_setup_generic(struct dw_spi *dws)
 {
 	dws->dma_ops = &dw_spi_dma_generic_ops;
 }
-EXPORT_SYMBOL_GPL(dw_spi_dma_setup_generic);
+EXPORT_SYMBOL_NS_GPL(dw_spi_dma_setup_generic, SPI_DW_CORE);
drivers/spi/spi-dw-mmio.c +1 -0
index 17c06039a74d..711f4d3404c5 100644
@@ -377,3 +377,4 @@ module_platform_driver(dw_spi_mmio_driver);
 MODULE_AUTHOR("Jean-Hugues Deschenes <[email protected]>");
 MODULE_DESCRIPTION("Memory-mapped I/O interface driver for DW SPI Core");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(SPI_DW_CORE);
drivers/spi/spi-dw-pci.c +1 -0
index 8a91cd58102f..5552240fee55 100644
@@ -213,3 +213,4 @@ module_pci_driver(dw_spi_driver);
 MODULE_AUTHOR("Feng Tang <[email protected]>");
 MODULE_DESCRIPTION("PCI interface driver for DW SPI Core");
 MODULE_LICENSE("GPL v2");
+MODULE_IMPORT_NS(SPI_DW_CORE);
Signature · 1 line
2.33.0
#2 lore raw

PATCH v3 2/7 spi: dw: Discard redundant DW SSI Frame Formats enumeration

In reply to Serge Semin

The dw_ssi_type enumeration describes the SPI frame formats the controller supports, like Motorola SPI, Texas Instruments SSP and National Semiconductors Microwire, that is the serial protocol utilized for the SPI-transfers. Depending on the DW SSI IP-core configuration the protocol could be either fixed or selectable. If it is changebale the protocol can be selected by means of the CTRL0.FRF field, which possible values encoded by the dw_ssi_type enumeration. Aside with the denoted enum the field values are also described by a set of SPI_FRF_{SPI,SSP,MICROWIRE} macros. Thus currently the DW SPI driver has got two entities describing the same data. Let's get rid of the enumeration one then, since first it hasn't been used as enumeration-type but merely as a parametrized values set and second that would unify the macro-based CSR read/write interface of the driver. While at it convert the macro names to be more descriptive about the protocols they represent.

---
 drivers/spi/spi-dw-core.c |  4 ++--
 drivers/spi/spi-dw.h      | 12 +++---------
 2 files changed, 5 insertions(+), 11 deletions(-)
drivers/spi/spi-dw-core.c +2 -2
index a14940403ab4..da6100fd185f 100644
@@ -273,7 +273,7 @@ static u32 dw_spi_prepare_cr0(struct dw_spi *dws, struct spi_device *spi)
 
 	if (!(dws->caps & DW_SPI_CAP_DWC_SSI)) {
 		/* CTRLR0[ 5: 4] Frame Format */
-		cr0 |= SSI_MOTO_SPI << SPI_FRF_OFFSET;
+		cr0 |= SPI_FRF_MOTO_SPI << SPI_FRF_OFFSET;
 
 		/*
 		 * SPI mode (SCPOL|SCPH)
@@ -287,7 +287,7 @@ static u32 dw_spi_prepare_cr0(struct dw_spi *dws, struct spi_device *spi)
 		cr0 |= ((spi->mode & SPI_LOOP) ? 1 : 0) << SPI_SRL_OFFSET;
 	} else {
 		/* CTRLR0[ 7: 6] Frame Format */
-		cr0 |= SSI_MOTO_SPI << DWC_SSI_CTRLR0_FRF_OFFSET;
+		cr0 |= SPI_FRF_MOTO_SPI << DWC_SSI_CTRLR0_FRF_OFFSET;
 
 		/*
 		 * SPI mode (SCPOL|SCPH)
drivers/spi/spi-dw.h +3 -9
index b665e040862c..467c342bfe56 100644
@@ -46,9 +46,9 @@
 #define SPI_DFS32_OFFSET		16
 
 #define SPI_FRF_OFFSET			4
-#define SPI_FRF_SPI			0x0
-#define SPI_FRF_SSP			0x1
-#define SPI_FRF_MICROWIRE		0x2
+#define SPI_FRF_MOTO_SPI		0x0
+#define SPI_FRF_TI_SSP			0x1
+#define SPI_FRF_NS_MICROWIRE		0x2
 #define SPI_FRF_RESV			0x3
 
 #define SPI_MODE_OFFSET			6
@@ -114,12 +114,6 @@
 #define SPI_GET_BYTE(_val, _idx) \
 	((_val) >> (BITS_PER_BYTE * (_idx)) & 0xff)
 
-enum dw_ssi_type {
-	SSI_MOTO_SPI = 0,
-	SSI_TI_SSP,
-	SSI_NS_MICROWIRE,
-};
-
 /* DW SPI capabilities */
 #define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
 #define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
Signature · 1 line
2.33.0
#3 lore raw

PATCH v3 3/7 spi: dw: Put the driver entities naming in order

In reply to Serge Semin

Mostly due to a long driver history it's methods and macro names look a bit messy. In particularly that concerns the code their prefixes. A biggest part of the driver functions and macros have got the dw_spi/DW_SPI prefixes. But there are some entities which have been just "spi_/SPI_"-prefixed. Especially that concerns the CSR and their fields macro definitions. It makes the code harder to comprehend since such methods and macros can be easily confused with the global SPI-subsystem exports. In this case the only possible way to more or less quickly distinguish one naming space from another is either by context or by the argument type, which most of the times isn't that easy anyway. In addition to that a new DW SSI IP-core support has been added in the framework of commit e539f435cb9c ("spi: dw: Add support for DesignWare DWC_ssi"), which introduced a new set or macro-prefixes to describe CTRLR0-specific fields and worsen the situation. Finally there are methods with
no DW SPI driver-reference prefix at all, that make the code reading even harder. So in order to ease the driver hacking let's bring the code naming to a common base:
1) Each method is supposed to have "dw_spi_" prefix so to be easily distinguished from the kernel API, e.g. SPI-subsystem methods and macros. (Exception is the local implementation of the readl/writel methods since being just the regspace accessors.)
2) Each generically used macro should have DW_SPI_-prefix thus being easily comprehended as the local driver definition.
3) DW APB SSI and DW SSI specific macros should have prefixes as DW_PSSI_ and DW_HSSI_ respectively so referring to the system buses they support (APB and AHB similarly to the DT clocks naming like pclk, hclk).

---

Folks, any ideas of a better naming scheme especially for the DW APB SSI and DW SSI specific macros are very welcome.

Changelog v2:
- Replace "assi" suffixes with "pssi" in the spi-dw-mmio.c methods. (Thanks Andy for noticing this pity mistake)

---
 drivers/spi/spi-dw-bt1.c  |   8 +--
 drivers/spi/spi-dw-core.c | 138 ++++++++++++++++++------------------
 drivers/spi/spi-dw-dma.c  |  50 ++++++-------
 drivers/spi/spi-dw-mmio.c |  20 +++---
 drivers/spi/spi-dw-pci.c  |  59 ++++++++--------
 drivers/spi/spi-dw.h      | 145 +++++++++++++++++++-------------------
 6 files changed, 211 insertions(+), 209 deletions(-)
drivers/spi/spi-dw-bt1.c +4 -4
index ac7e4f30d1da..c06553416123 100644
@@ -123,7 +123,7 @@ static ssize_t dw_spi_bt1_dirmap_read(struct spi_mem_dirmap_desc *desc,
 	len = min_t(size_t, len, dwsbt1->map_len - offs);
 
 	/* Collect the controller configuration required by the operation */
-	cfg.tmode = SPI_TMOD_EPROMREAD;
+	cfg.tmode = DW_SPI_CTRLR0_TMOD_EPROMREAD;
 	cfg.dfs = 8;
 	cfg.ndf = 4;
 	cfg.freq = mem->spi->max_speed_hz;
@@ -131,13 +131,13 @@ static ssize_t dw_spi_bt1_dirmap_read(struct spi_mem_dirmap_desc *desc,
 	/* Make sure the corresponding CS is de-asserted on transmission */
 	dw_spi_set_cs(mem->spi, false);
 
-	spi_enable_chip(dws, 0);
+	dw_spi_enable_chip(dws, 0);
 
 	dw_spi_update_config(dws, mem->spi, &cfg);
 
-	spi_umask_intr(dws, SPI_INT_RXFI);
+	dw_spi_umask_intr(dws, DW_SPI_INT_RXFI);
 
-	spi_enable_chip(dws, 1);
+	dw_spi_enable_chip(dws, 1);
 
 	/*
 	 * Enable the transparent mode of the System Boot Controller.
drivers/spi/spi-dw-core.c +70 -68

427 lines not on this page · raw message

drivers/spi/spi-dw-dma.c +25 -25

133 lines not on this page · raw message

drivers/spi/spi-dw-mmio.c +10 -10
index 711f4d3404c5..0b37bd32b041 100644
@@ -196,18 +196,18 @@ static int dw_spi_alpine_init(struct platform_device *pdev,
 	return 0;
 }
 
-static int dw_spi_dw_apb_init(struct platform_device *pdev,
-			      struct dw_spi_mmio *dwsmmio)
+static int dw_spi_pssi_init(struct platform_device *pdev,
+			    struct dw_spi_mmio *dwsmmio)
 {
 	dw_spi_dma_setup_generic(&dwsmmio->dws);
 
 	return 0;
 }
 
-static int dw_spi_dwc_ssi_init(struct platform_device *pdev,
-			       struct dw_spi_mmio *dwsmmio)
+static int dw_spi_hssi_init(struct platform_device *pdev,
+			    struct dw_spi_mmio *dwsmmio)
 {
-	dwsmmio->dws.caps = DW_SPI_CAP_DWC_SSI;
+	dwsmmio->dws.caps = DW_SPI_CAP_DWC_HSSI;
 
 	dw_spi_dma_setup_generic(&dwsmmio->dws);
 
@@ -217,7 +217,7 @@ static int dw_spi_dwc_ssi_init(struct platform_device *pdev,
 static int dw_spi_keembay_init(struct platform_device *pdev,
 			       struct dw_spi_mmio *dwsmmio)
 {
-	dwsmmio->dws.caps = DW_SPI_CAP_KEEMBAY_MST | DW_SPI_CAP_DWC_SSI;
+	dwsmmio->dws.caps = DW_SPI_CAP_KEEMBAY_MST | DW_SPI_CAP_DWC_HSSI;
 
 	return 0;
 }
@@ -342,12 +342,12 @@ static int dw_spi_mmio_remove(struct platform_device *pdev)
 }
 
 static const struct of_device_id dw_spi_mmio_of_match[] = {
-	{ .compatible = "snps,dw-apb-ssi", .data = dw_spi_dw_apb_init},
+	{ .compatible = "snps,dw-apb-ssi", .data = dw_spi_pssi_init},
 	{ .compatible = "mscc,ocelot-spi", .data = dw_spi_mscc_ocelot_init},
 	{ .compatible = "mscc,jaguar2-spi", .data = dw_spi_mscc_jaguar2_init},
 	{ .compatible = "amazon,alpine-dw-apb-ssi", .data = dw_spi_alpine_init},
-	{ .compatible = "renesas,rzn1-spi", .data = dw_spi_dw_apb_init},
-	{ .compatible = "snps,dwc-ssi-1.01a", .data = dw_spi_dwc_ssi_init},
+	{ .compatible = "renesas,rzn1-spi", .data = dw_spi_pssi_init},
+	{ .compatible = "snps,dwc-ssi-1.01a", .data = dw_spi_hssi_init},
 	{ .compatible = "intel,keembay-ssi", .data = dw_spi_keembay_init},
 	{ .compatible = "microchip,sparx5-spi", dw_spi_mscc_sparx5_init},
 	{ .compatible = "canaan,k210-spi", dw_spi_canaan_k210_init},
@@ -357,7 +357,7 @@ MODULE_DEVICE_TABLE(of, dw_spi_mmio_of_match);
 
 #ifdef CONFIG_ACPI
 static const struct acpi_device_id dw_spi_mmio_acpi_match[] = {
-	{"HISI0173", (kernel_ulong_t)dw_spi_dw_apb_init},
+	{"HISI0173", (kernel_ulong_t)dw_spi_pssi_init},
 	{},
 };
 MODULE_DEVICE_TABLE(acpi, dw_spi_mmio_acpi_match);
drivers/spi/spi-dw-pci.c +29 -30

138 lines not on this page · raw message

drivers/spi/spi-dw.h +73 -72

225 lines not on this page · raw message

Signature · 1 line
2.33.0
#4 lore raw

PATCH v3 4/7 spi: dw: Convert to using the Bitfield access macros

In reply to Serge Semin

The driver has been using the offset/bitwise-shift-based approach for the CSR fields R/W operations since it was merged into the kernel. It can be simplified by using the macros defined in the linux/bitfield.h and linux/bit.h header files like BIT(), GENMASK(), FIELD_PREP(), FIELD_GET(), etc where it is required, for instance in the cached cr0 preparation method. Thus in order to have the FIELD_*()-macros utilized we just need to convert the macros with the CSR-fields offsets to the masks with the corresponding registers fields definition. That's where the GENMASK() and BIT() macros come in handy. After that the masks can be used in the FIELD_*()-macros where it's appropriate.

We also need to convert the macros with the CRS-bit flags using the manual bitwise shift operations (x << y) to using the BIT() macro. Thus we'll have a more coherent set of the CSR-related macros.

---
 drivers/spi/spi-dw-core.c | 31 +++++++++++--------
 drivers/spi/spi-dw.h      | 64 +++++++++++++++++++--------------------
 2 files changed, 50 insertions(+), 45 deletions(-)
drivers/spi/spi-dw-core.c +19 -12
index 57bbffe6d6f9..b9f809989fda 100644
@@ -5,6 +5,7 @@
  * Copyright (c) 2009, Intel Corporation.
  */
 
+#include <linux/bitfield.h>
 #include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
 #include <linux/module.h>
@@ -254,7 +255,7 @@ static irqreturn_t dw_spi_irq(int irq, void *dev_id)
 {
 	struct spi_controller *master = dev_id;
 	struct dw_spi *dws = spi_controller_get_devdata(master);
-	u16 irq_status = dw_readl(dws, DW_SPI_ISR) & 0x3f;
+	u16 irq_status = dw_readl(dws, DW_SPI_ISR) & DW_SPI_INT_MASK;
 
 	if (!irq_status)
 		return IRQ_NONE;
@@ -273,32 +274,38 @@ static u32 dw_spi_prepare_cr0(struct dw_spi *dws, struct spi_device *spi)
 
 	if (!(dws->caps & DW_SPI_CAP_DWC_HSSI)) {
 		/* CTRLR0[ 5: 4] Frame Format */
-		cr0 |= DW_SPI_CTRLR0_FRF_MOTO_SPI << DW_PSSI_CTRLR0_FRF_OFFSET;
+		cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_FRF_MASK, DW_SPI_CTRLR0_FRF_MOTO_SPI);
 
 		/*
 		 * SPI mode (SCPOL|SCPH)
 		 * CTRLR0[ 6] Serial Clock Phase
 		 * CTRLR0[ 7] Serial Clock Polarity
 		 */
-		cr0 |= ((spi->mode & SPI_CPOL) ? 1 : 0) << DW_PSSI_CTRLR0_SCOL_OFFSET;
-		cr0 |= ((spi->mode & SPI_CPHA) ? 1 : 0) << DW_PSSI_CTRLR0_SCPH_OFFSET;
+		if (spi->mode & SPI_CPOL)
+			cr0 |= DW_PSSI_CTRLR0_SCPOL;
+		if (spi->mode & SPI_CPHA)
+			cr0 |= DW_PSSI_CTRLR0_SCPHA;
 
 		/* CTRLR0[11] Shift Register Loop */
-		cr0 |= ((spi->mode & SPI_LOOP) ? 1 : 0) << DW_PSSI_CTRLR0_SRL_OFFSET;
+		if (spi->mode & SPI_LOOP)
+			cr0 |= DW_PSSI_CTRLR0_SRL;
 	} else {
 		/* CTRLR0[ 7: 6] Frame Format */
-		cr0 |= DW_SPI_CTRLR0_FRF_MOTO_SPI << DW_HSSI_CTRLR0_FRF_OFFSET;
+		cr0 |= FIELD_PREP(DW_HSSI_CTRLR0_FRF_MASK, DW_SPI_CTRLR0_FRF_MOTO_SPI);
 
 		/*
 		 * SPI mode (SCPOL|SCPH)
 		 * CTRLR0[ 8] Serial Clock Phase
 		 * CTRLR0[ 9] Serial Clock Polarity
 		 */
-		cr0 |= ((spi->mode & SPI_CPOL) ? 1 : 0) << DW_HSSI_CTRLR0_SCPOL_OFFSET;
-		cr0 |= ((spi->mode & SPI_CPHA) ? 1 : 0) << DW_HSSI_CTRLR0_SCPH_OFFSET;
+		if (spi->mode & SPI_CPOL)
+			cr0 |= DW_HSSI_CTRLR0_SCPOL;
+		if (spi->mode & SPI_CPHA)
+			cr0 |= DW_HSSI_CTRLR0_SCPHA;
 
 		/* CTRLR0[13] Shift Register Loop */
-		cr0 |= ((spi->mode & SPI_LOOP) ? 1 : 0) << DW_HSSI_CTRLR0_SRL_OFFSET;
+		if (spi->mode & SPI_LOOP)
+			cr0 |= DW_HSSI_CTRLR0_SRL;
 
 		if (dws->caps & DW_SPI_CAP_KEEMBAY_MST)
 			cr0 |= DW_HSSI_CTRLR0_KEEMBAY_MST;
@@ -320,10 +327,10 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
 
 	if (!(dws->caps & DW_SPI_CAP_DWC_HSSI))
 		/* CTRLR0[ 9:8] Transfer Mode */
-		cr0 |= cfg->tmode << DW_PSSI_CTRLR0_TMOD_OFFSET;
+		cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_TMOD_MASK, cfg->tmode);
 	else
 		/* CTRLR0[11:10] Transfer Mode */
-		cr0 |= cfg->tmode << DW_HSSI_CTRLR0_TMOD_OFFSET;
+		cr0 |= FIELD_PREP(DW_HSSI_CTRLR0_TMOD_MASK, cfg->tmode);
 
 	dw_writel(dws, DW_SPI_CTRLR0, cr0);
 
@@ -850,7 +857,7 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
 
 		if (!(cr0 & DW_PSSI_CTRLR0_DFS_MASK)) {
 			dws->caps |= DW_SPI_CAP_DFS32;
-			dws->dfs_offset = DW_PSSI_CTRLR0_DFS32_OFFSET;
+			dws->dfs_offset = __bf_shf(DW_PSSI_CTRLR0_DFS32_MASK);
 			dev_dbg(dev, "Detected 32-bits max data frame size\n");
 		}
 	} else {
drivers/spi/spi-dw.h +31 -33

96 lines not on this page · raw message

Signature · 1 line
2.33.0
#5 lore raw

PATCH v3 5/7 spi: dw: Introduce Synopsys IP-core versions interface

In reply to Serge Semin

The driver currently supports two IP-core versions. It's DW APB SSI which is older version of the controller with APB system bus interface, and DW SSI controller with AHB bus interface. The later one is supposed to be a new generation high-speed SSI. Even though both of these IP-cores have got an almost identical registers space there are some differences. The driver differentiates these distinctions by the DW_SPI_CAP_DWC_HSSI capability flag. In addition to that each DW SSI IP-core is equipped with a Synopsys Component version register, which encodes the IP-core release ID the has been synthesized from. Seeing we are going to need the later one to differentiate some controller peculiarities it would be better to have a unified interface for both IP-core line and release versions instead of using each of them separately.

Introduced here IP-core versioning interface consists of two parts:
1) IDs of the IP-core (virtual) and component versions.
2) a set of macro helpers to identify current IP-core and component versions.

So the platform code is supposed to assign a proper IP-core version based on it's platform -knowledge. The main driver initialization method reads the IP-core release ID from the SSI component version register. That data is used by the helpers to distinguish one IP-core release from another. Thus the rest of the driver can use these macros to implement the conditional code execution based on the specified IP-core and version IDs.

Collect the IP-core versions interface and the defined capabilities at the top of the header file since they represent a common device description data and so to immediately available for the driver hackers.

---

Note I intentionally haven't used the "%p4cc" format specifier due to three reasons. First the component version 4cc string is preserved in the little endian format in the DW SSI register thus having '*' in the least significant byte. Such representation do look well when you print it in hex, but that's not what the 4cc format print implementation expects (fourcc_string() wants to see a most-significant char at the lowest byte). Second the 4cc format also prints some pixel-format specific info like endiannes, which is irrelevant to the synopsys component version. Finally a string in the "v%c.%c%c" format represents the component version better.

Changelog v2:
- Replace the ASCII-to-integer conversion with a unified IP-core versions interface.

---
 drivers/spi/spi-dw-core.c | 14 ++++++++++++++
 drivers/spi/spi-dw.h      | 36 ++++++++++++++++++++++++++++--------
 2 files changed, 42 insertions(+), 8 deletions(-)
drivers/spi/spi-dw-core.c +14 -0
index b9f809989fda..42536b448ddd 100644
@@ -823,6 +823,20 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
 {
 	dw_spi_reset_chip(dws);
 
+	/*
+	 * Retrieve the Synopsys component version if it hasn't been specified
+	 * by the platform. CoreKit version ID is encoded as a 3-chars ASCII
+	 * code enclosed with '*' (typical for the most of Synopsys IP-cores).
+	 */
+	if (!dws->ver) {
+		dws->ver = dw_readl(dws, DW_SPI_VERSION);
+
+		dev_dbg(dev, "Synopsys DWC%sSSI v%c.%c%c\n",
+			(dws->caps & DW_SPI_CAP_DWC_HSSI) ? " " : " APB ",
+			DW_SPI_GET_BYTE(dws->ver, 3), DW_SPI_GET_BYTE(dws->ver, 2),
+			DW_SPI_GET_BYTE(dws->ver, 1));
+	}
+
 	/*
 	 * Try to detect the FIFO depth if not set by interface driver,
 	 * the depth could be from 2 to 256 from HW spec
drivers/spi/spi-dw.h +28 -8
index 634085eadad1..2f7d77024b48 100644
@@ -11,6 +11,30 @@
 #include <linux/spi/spi-mem.h>
 #include <linux/bitfield.h>
 
+/* Synopsys DW SSI IP-core virtual IDs */
+#define DW_PSSI_ID			0
+#define DW_HSSI_ID			1
+
+/* Synopsys DW SSI component versions (FourCC sequence) */
+#define DW_HSSI_102A			0x3130322a
+
+/* DW SSI IP-core ID and version check helpers */
+#define dw_spi_ip_is(_dws, _ip) \
+	((_dws)->ip == DW_ ## _ip ## _ID)
+
+#define __dw_spi_ver_cmp(_dws, _ip, _ver, _op) \
+	(dw_spi_ip_is(_dws, _ip) && (_dws)->ver _op DW_ ## _ip ## _ver)
+
+#define dw_spi_ver_is(_dws, _ip, _ver) __dw_spi_ver_cmp(_dws, _ip, _ver, ==)
+
+#define dw_spi_ver_is_ge(_dws, _ip, _ver) __dw_spi_ver_cmp(_dws, _ip, _ver, >=)
+
+/* DW SPI controller capabilities */
+#define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
+#define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
+#define DW_SPI_CAP_DWC_HSSI		BIT(2)
+#define DW_SPI_CAP_DFS32		BIT(3)
+
 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */
 #define DW_SPI_CTRLR0			0x00
 #define DW_SPI_CTRLR1			0x04
@@ -113,12 +137,6 @@
 #define DW_SPI_GET_BYTE(_val, _idx) \
 	((_val) >> (BITS_PER_BYTE * (_idx)) & 0xff)
 
-/* DW SPI capabilities */
-#define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
-#define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
-#define DW_SPI_CAP_DWC_HSSI		BIT(2)
-#define DW_SPI_CAP_DFS32		BIT(3)
-
 /* Slave spi_transfer/spi_mem_op related */
 struct dw_spi_cfg {
 	u8 tmode;
@@ -141,6 +159,10 @@ struct dw_spi_dma_ops {
 struct dw_spi {
 	struct spi_controller	*master;
 
+	u32			ip;		/* Synopsys DW SSI IP-core ID */
+	u32			ver;		/* Synopsys component version */
+	u32			caps;		/* DW SPI capabilities */
+
 	void __iomem		*regs;
 	unsigned long		paddr;
 	int			irq;
@@ -149,8 +171,6 @@ struct dw_spi {
 	u32			max_mem_freq;	/* max mem-ops bus freq */
 	u32			max_freq;	/* max bus freq supported */
 
-	u32			caps;		/* DW SPI capabilities */
-
 	u32			reg_io_width;	/* DR I/O width in bytes */
 	u16			bus_num;
 	u16			num_cs;		/* supported slave numbers */
Signature · 1 line
2.33.0
#6 lore raw

PATCH v3 6/7 spi: dw: Replace DWC_HSSI capability with IP-core version checker

In reply to Serge Semin

Since there is a common IP-core and component versions interface available we can use it to differentiate the DW HSSI device features in the code. Let's remove the corresponding DWC_HSSI capability flag then and use the dw_spi_ip_is() macro instead.

---

Changelog v2:
- This is a new patch created as a logical result of a new DW SSI IP-core versions internal interface introduced in the previous patch.

Changelog v3:
- Move the DW_SPI_CAP_DFS32 capability flag position fix to a separate patch.

---
 drivers/spi/spi-dw-core.c | 8 ++++----
 drivers/spi/spi-dw-mmio.c | 5 +++--
 drivers/spi/spi-dw.h      | 1 -
 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/spi/spi-dw-core.c +4 -4
index 42536b448ddd..934cc7a922e8 100644
@@ -272,7 +272,7 @@ static u32 dw_spi_prepare_cr0(struct dw_spi *dws, struct spi_device *spi)
 {
 	u32 cr0 = 0;
 
-	if (!(dws->caps & DW_SPI_CAP_DWC_HSSI)) {
+	if (dw_spi_ip_is(dws, PSSI)) {
 		/* CTRLR0[ 5: 4] Frame Format */
 		cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_FRF_MASK, DW_SPI_CTRLR0_FRF_MOTO_SPI);
 
@@ -325,7 +325,7 @@ void dw_spi_update_config(struct dw_spi *dws, struct spi_device *spi,
 	/* CTRLR0[ 4/3: 0] or CTRLR0[ 20: 16] Data Frame Size */
 	cr0 |= (cfg->dfs - 1) << dws->dfs_offset;
 
-	if (!(dws->caps & DW_SPI_CAP_DWC_HSSI))
+	if (dw_spi_ip_is(dws, PSSI))
 		/* CTRLR0[ 9:8] Transfer Mode */
 		cr0 |= FIELD_PREP(DW_PSSI_CTRLR0_TMOD_MASK, cfg->tmode);
 	else
@@ -832,7 +832,7 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
 		dws->ver = dw_readl(dws, DW_SPI_VERSION);
 
 		dev_dbg(dev, "Synopsys DWC%sSSI v%c.%c%c\n",
-			(dws->caps & DW_SPI_CAP_DWC_HSSI) ? " " : " APB ",
+			dw_spi_ip_is(dws, PSSI) ? " APB " : " ",
 			DW_SPI_GET_BYTE(dws->ver, 3), DW_SPI_GET_BYTE(dws->ver, 2),
 			DW_SPI_GET_BYTE(dws->ver, 1));
 	}
@@ -860,7 +860,7 @@ static void dw_spi_hw_init(struct device *dev, struct dw_spi *dws)
 	 * writability. Note DWC SSI controller also has the extended DFS, but
 	 * with zero offset.
 	 */
-	if (!(dws->caps & DW_SPI_CAP_DWC_HSSI)) {
+	if (dw_spi_ip_is(dws, PSSI)) {
 		u32 cr0, tmp = dw_readl(dws, DW_SPI_CTRLR0);
 
 		dw_spi_enable_chip(dws, 0);
drivers/spi/spi-dw-mmio.c +3 -2
index 0b37bd32b041..c0e5bb6add0a 100644
@@ -207,7 +207,7 @@ static int dw_spi_pssi_init(struct platform_device *pdev,
 static int dw_spi_hssi_init(struct platform_device *pdev,
 			    struct dw_spi_mmio *dwsmmio)
 {
-	dwsmmio->dws.caps = DW_SPI_CAP_DWC_HSSI;
+	dwsmmio->dws.ip = DW_HSSI_ID;
 
 	dw_spi_dma_setup_generic(&dwsmmio->dws);
 
@@ -217,7 +217,8 @@ static int dw_spi_hssi_init(struct platform_device *pdev,
 static int dw_spi_keembay_init(struct platform_device *pdev,
 			       struct dw_spi_mmio *dwsmmio)
 {
-	dwsmmio->dws.caps = DW_SPI_CAP_KEEMBAY_MST | DW_SPI_CAP_DWC_HSSI;
+	dwsmmio->dws.ip = DW_HSSI_ID;
+	dwsmmio->dws.caps = DW_SPI_CAP_KEEMBAY_MST;
 
 	return 0;
 }
drivers/spi/spi-dw.h +0 -1
index 2f7d77024b48..8334e6b35f89 100644
@@ -32,7 +32,6 @@
 /* DW SPI controller capabilities */
 #define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
 #define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
-#define DW_SPI_CAP_DWC_HSSI		BIT(2)
 #define DW_SPI_CAP_DFS32		BIT(3)
 
 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */
Signature · 1 line
2.33.0
#7 lore raw

PATCH v3 7/7 spi: dw: Define the capabilities in a continuous bit-flags set

In reply to Serge Semin

Since the DW_SPI_CAP_DWC_HSSI capability has just been replaced with using the DW SSI IP-core versions interface, the DW SPI capability flags are now represented with a gap. Let's fix it by redefining the DW_SPI_CAP_DFS32 macro to setting BIT(2) of the capabilities field.

---

Changelog v3:
- This is a new patch unpinned from the previous one as of Andy suggested.

---
 drivers/spi/spi-dw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-dw.h +1 -1
index 8334e6b35f89..d5ee5130601e 100644
@@ -32,7 +32,7 @@
 /* DW SPI controller capabilities */
 #define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
 #define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
-#define DW_SPI_CAP_DFS32		BIT(3)
+#define DW_SPI_CAP_DFS32		BIT(2)
 
 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */
 #define DW_SPI_CTRLR0			0x00
Signature · 1 line
2.33.0
Reviewed-by on v3 7/7
#8 lore raw

Re: [PATCH v3 7/7] spi: dw: Define the capabilities in a continuous bit-flags set

Quoted 7 lines · Serge Semin

Since the DW_SPI_CAP_DWC_HSSI capability has just been replaced with using the DW SSI IP-core versions interface, the DW SPI capability flags are now represented with a gap. Let's fix it by redefining the DW_SPI_CAP_DFS32 macro to setting BIT(2) of the capabilities field.

Fine with me, thanks!

Quoted 25 lines

---

Changelog v3:
- This is a new patch unpinned from the previous one as of Andy suggested.

---
 drivers/spi/spi-dw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-dw.h +1 -1
index 8334e6b35f89..d5ee5130601e 100644
@@ -32,7 +32,7 @@
 /* DW SPI controller capabilities */
 #define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
 #define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
-#define DW_SPI_CAP_DFS32		BIT(3)
+#define DW_SPI_CAP_DFS32		BIT(2)
 
 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */
 #define DW_SPI_CTRLR0			0x00
Signature · 1 line
2.33.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

Re: [PATCH v3 7/7] spi: dw: Define the capabilities in a continuous bit-flags set

Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Serge Semin

Since the DW_SPI_CAP_DWC_HSSI capability has just been replaced with using the DW SSI IP-core versions interface, the DW SPI capability flags are now represented with a gap. Let's fix it by redefining the DW_SPI_CAP_DFS32 macro to setting BIT(2) of the capabilities field.

Quoted 6 lines
Quoted 2 lines

Fine with me, thanks!

Great! Thanks to you too for very fast responses and thorough review.

-Sergey

Quoted 32 lines
Quoted 26 lines

---

Changelog v3:
- This is a new patch unpinned from the previous one as of Andy suggested.

---
 drivers/spi/spi-dw.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/spi-dw.h +1 -1
index 8334e6b35f89..d5ee5130601e 100644
@@ -32,7 +32,7 @@
 /* DW SPI controller capabilities */
 #define DW_SPI_CAP_CS_OVERRIDE		BIT(0)
 #define DW_SPI_CAP_KEEMBAY_MST		BIT(1)
-#define DW_SPI_CAP_DFS32		BIT(3)
+#define DW_SPI_CAP_DFS32		BIT(2)
 
 /* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */
 #define DW_SPI_CTRLR0			0x00
Signature · 1 line
2.33.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw
In reply to Serge Semin

Hello Mark,

I think Andy is done with reviewing this patchset. If you are ok with what is introduced here please consider merging the series in.

-Sergey

Quoted 70 lines · Serge Semin

I was going to submit a cleanup patchset for the DW SSI driver for a long time, but due to lack of free time couldn't make it so far. Nandhini's series [1] made me to proceed with this task so mate would finally have his patchset accepted and merged into the mainline kernel.

There are four cleanup patches here and three feature patches. In the framework of the former patches we convert the DW SPI driver to using module namespaces and provide a better code organization. In particular the second part concerns the methods and macros naming unification (using a unified prefixes of the code object names) and the CSR fields macro implementation using the bitfield helpers available in the kernel. The later patches introduce the DW SSI IP-core versions interface so it could be used for a version-specific features implementation. Nandhini will be mostly interested in the later patches in the framework of his series [1].

Nandhini, could you please test the patchset out on your DWC SSI hardware? After it's merged into the spi/for-next branch of the Mark' repository you will be able to rebase your series on top of it and use the last IP-core version interface for your benefit.

Andy, I have added your tag to all the patches except the last one since it's new (though suggested by you).

[1] https://lore.kernel.org/linux-spi/[email protected]

Changelog v2:
- Replace "assi" suffixes with "pssi" in the spi-dw-mmio.c methods. (Thanks Andy for noticing this pity mistake)
- Add new patches:
[PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker [PATCH v2 1/6] spi: dw: Add symbol namespaces for the core and DMA modules
- Replace the ASCII-to-integer conversion with a unified IP-core versioning interface (Suggested by Andy).

Changelog v3:
- Discard the symbols importing from the spi-dw-dma object since it's linked into the spi-dw-core module anyway thus having the same symbols namespace.
- Move the DW_SPI_CAP_DFS32 capability flag position fix to a separate patch.

Serge Semin (7):
spi: dw: Add a symbols namespace for the core module
spi: dw: Discard redundant DW SSI Frame Formats enumeration
spi: dw: Put the driver entities naming in order
spi: dw: Convert to using the Bitfield access macros
spi: dw: Introduce Synopsys IP-core versions interface
spi: dw: Replace DWC_HSSI capability with IP-core version checker
spi: dw: Define the capabilities in a continuous bit-flags set

 drivers/spi/spi-dw-bt1.c  |   9 +-
 drivers/spi/spi-dw-core.c | 175 ++++++++++++++++++++----------------
 drivers/spi/spi-dw-dma.c  |  55 ++++++------
 drivers/spi/spi-dw-mmio.c |  22 ++---
 drivers/spi/spi-dw-pci.c  |  60 ++++++-------
 drivers/spi/spi-dw.h      | 182 ++++++++++++++++++++------------------
 6 files changed, 271 insertions(+), 232 deletions(-)
Signature · 1 line
2.33.0
maintainer
#11 lore raw
In reply to Serge Semin
Quoted 16 lines · Serge Semin

I was going to submit a cleanup patchset for the DW SSI driver for a long time, but due to lack of free time couldn't make it so far. Nandhini's series [1] made me to proceed with this task so mate would finally have his patchset accepted and merged into the mainline kernel.

There are four cleanup patches here and three feature patches. In the framework of the former patches we convert the DW SPI driver to using module namespaces and provide a better code organization. In particular the second part concerns the methods and macros naming unification (using a unified prefixes of the code object names) and the CSR fields macro implementation using the bitfield helpers available in the kernel. The later patches introduce the DW SSI IP-core versions interface so it could be used for a version-specific features implementation. Nandhini will be mostly interested in the later patches in the framework of his series [1].

Quoted 1 line

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/7] spi: dw: Add a symbols namespace for the core module

      commit: a62bacba81c477a6fd8f15da593ad02305a3d6da
[2/7] spi: dw: Discard redundant DW SSI Frame Formats enumeration
      commit: 21b6b3809b840ad3d3f0689aac227929c04e9518
[3/7] spi: dw: Put the driver entities naming in order
      commit: 725b0e3ea899ff1cb799756ade302e7bc13a8559
[4/7] spi: dw: Convert to using the Bitfield access macros
      commit: ec77c086dc5b2eb422ff588f91cc011137fa9ea3
[5/7] spi: dw: Introduce Synopsys IP-core versions interface
      commit: 2cc8d9227bbba7d6f3790a86f1ff0d665a75f3b8
[6/7] spi: dw: Replace DWC_HSSI capability with IP-core version checker
      commit: 2b8a47e0b6984b9795baa20ddcbd37e9ea9b2a91
[7/7] spi: dw: Define the capabilities in a continuous bit-flags set
      commit: 44ebcb44584f81d1d38fafb45cf57d651f44616e

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark