spi: dw: Cleanup macros/funcs naming and add IP-core version support
v2 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 two 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 introduces 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 haven't added your tag to the new patches and to the patch with the IP-core version interface.
[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).
Serge Semin (6):
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
drivers/spi/spi-dw-bt1.c | 9 +- drivers/spi/spi-dw-core.c | 175 ++++++++++++++++++++---------------- drivers/spi/spi-dw-dma.c | 57 ++++++------ drivers/spi/spi-dw-mmio.c | 22 ++--- drivers/spi/spi-dw-pci.c | 60 ++++++------- drivers/spi/spi-dw.h | 182 ++++++++++++++++++++------------------ 6 files changed, 273 insertions(+), 232 deletions(-)
Signature · 1 line
2.33.0
PATCH v2 1/6 spi: dw: Add a symbols namespace for the core module
The exported from the DW SPI driver core symbols are only used by the spi-dw-{dma,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.
--- drivers/spi/spi-dw-bt1.c | 1 + drivers/spi/spi-dw-core.c | 14 +++++++------- drivers/spi/spi-dw-dma.c | 7 +++++-- drivers/spi/spi-dw-mmio.c | 1 + drivers/spi/spi-dw-pci.c | 1 + 5 files changed, 15 insertions(+), 9 deletions(-)
drivers/spi/spi-dw-bt1.c +1 -0
@@ -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
@@ -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 +5 -2
@@ -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>
@@ -17,6 +18,8 @@#include "spi-dw.h" +MODULE_IMPORT_NS (SPI_DW_CORE ); +#define RX_BUSY 0#define RX_BURST_LEVEL 16#define TX_BUSY 1
@@ -638,7 +641,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 +656,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
@@ -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
@@ -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
Re: [PATCH v2 1/6] spi: dw: Add a symbols namespace for the core module
Quoted 6 lines · Serge Semin
The exported from the DW SPI driver core symbols are only used by the spi-dw-{dma,mmio,pci,bt1}.o objects. Add these symbols to a separate namespace then and make sure the depended modules have it imported.
Signed-off-by Serge Semin <[email protected]>Suggested-by Andy Shevchenko <[email protected]>
Thanks!
See also below.
Quoted 100 lines
---
Changelog v2:
- This is a new patch created as of Andy' suggestion.--- drivers/spi/spi-dw-bt1.c | 1 + drivers/spi/spi-dw-core.c | 14 +++++++------- drivers/spi/spi-dw-dma.c | 7 +++++-- drivers/spi/spi-dw-mmio.c | 1 + drivers/spi/spi-dw-pci.c | 1 + 5 files changed, 15 insertions(+), 9 deletions(-)drivers/spi/spi-dw-bt1.c +1
-0@@ -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@@ -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 +1
-0@@ -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>
drivers/spi/spi-dw-dma.c line 21
Quoted 4 lines
drivers/spi/spi-dw-dma.c +1
-0@@ -17,6 +18,8 @@#include "spi-dw.h" +MODULE_IMPORT_NS (SPI_DW_CORE );
I would rather see this at the end of file, but it should work either way.
Quoted 39 lines
drivers/spi/spi-dw-dma.c +2
-2#define RX_BUSY 0#define RX_BURST_LEVEL 16#define TX_BUSY 1@@ -638,7 +641,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 +656,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@@ -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@@ -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
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/6] spi: dw: Add a symbols namespace for the core module
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Serge Semin
The exported from the DW SPI driver core symbols are only used by the spi-dw-{dma,mmio,pci,bt1}.o objects. Add these symbols to a separate namespace then and make sure the depended modules have it imported.
Signed-off-by Serge Semin <[email protected]>Suggested-by Andy Shevchenko <[email protected]>
Quoted 6 lines
Thanks!
Reviewed-by Andy Shevchenko <[email protected]>See also below.
Thanks. But see below.
Quoted 102 lines
Quoted 102 lines
---
Changelog v2:
- This is a new patch created as of Andy' suggestion.--- drivers/spi/spi-dw-bt1.c | 1 + drivers/spi/spi-dw-core.c | 14 +++++++------- drivers/spi/spi-dw-dma.c | 7 +++++-- drivers/spi/spi-dw-mmio.c | 1 + drivers/spi/spi-dw-pci.c | 1 + 5 files changed, 15 insertions(+), 9 deletions(-)drivers/spi/spi-dw-bt1.c +1
-0@@ -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@@ -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 +1
-0@@ -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> @@ -17,6 +18,8 @@
Quoted 6 lines
drivers/spi/spi-dw-dma.c line 21
Quoted 4 lines
drivers/spi/spi-dw-dma.c +1
-0#include "spi-dw.h" +MODULE_IMPORT_NS (SPI_DW_CORE );I would rather see this at the end of file, but it should work either way.
I've just realized it, do I really need the
namespace imported in this object at all?.. It's linked into the spi-dw-core.ko. See drivers/spi/Makefile:
obj-$(CONFIG_SPI_DESIGNWARE) += spi-dw.o spi-dw-y := spi-dw-core.o spi-dw-$(CONFIG_SPI_DW_DMA) += spi-dw-dma.o
so the object must have got the same namespace.
Yeah, most likely I shouldn't have used the MODULE_IMPORT_NS() here...
-Sergey
Quoted 46 lines
Quoted 40 lines
drivers/spi/spi-dw-dma.c +2
-2#define RX_BUSY 0#define RX_BURST_LEVEL 16#define TX_BUSY 1@@ -638,7 +641,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 +656,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@@ -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@@ -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.0Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/6] spi: dw: Add a symbols namespace for the core module
Quoted 2 lines · Serge Semin
Quoted 1 line · Andy Shevchenko
On Mon, Nov 15, 2021 at 01:30:21AM +0300, Serge Semin wrote:
...
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+MODULE_IMPORT_NS(SPI_DW_CORE);
I would rather see this at the end of file, but it should work either way.
I've just realized it, do I really need the
namespace imported in this object at all?.. It's linked into the spi-dw-core.ko. Seedrivers/spi/Makefile:
Quoted 6 lines
obj-$(CONFIG_SPI_DESIGNWARE) += spi-dw.o spi-dw-y := spi-dw-core.o spi-dw-$(CONFIG_SPI_DW_DMA) += spi-dw-dma.oso the object must have got the same namespace.
Yeah, most likely I shouldn't have used the
MODULE_IMPORT_NS()here...
Indeed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 2/6 spi: dw: Discard redundant DW SSI Frame Formats enumeration
In reply to Serge SeminThe 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
@@ -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
@@ -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
PATCH v2 3/6 spi: dw: Put the driver entities naming in order
In reply to Serge SeminMostly 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
@@ -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
@@ -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
PATCH v2 4/6 spi: dw: Convert to using the Bitfield access macros
In reply to Serge SeminThe 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
@@ -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
PATCH v2 5/6 spi: dw: Introduce Synopsys IP-core versions interface
In reply to Serge SeminThe 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
@@ -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
@@ -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
Re: [PATCH v2 5/6] spi: dw: Introduce Synopsys IP-core versions interface
Quoted 25 lines · 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_HSSIcapability 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.
Quoted 3 lines
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.
Thanks! Fine with me
Quoted 5 lines
Signed-off-by Serge Semin <[email protected]>Suggested-by Andy Shevchenko <[email protected]>---
Quoted 9 lines
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.
Yeah, I guess we might need a specific FourCC for Synopsys IPs. But it's another story.
Quoted 104 lines
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@@ -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@@ -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
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 6/6 spi: dw: Replace DWC_HSSI capability with IP-core version checker
In reply to Serge SeminSince 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.
--- drivers/spi/spi-dw-core.c | 8 ++++---- drivers/spi/spi-dw-mmio.c | 5 +++-- drivers/spi/spi-dw.h | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/spi/spi-dw-core.c +4 -4
@@ -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
@@ -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 +1 -2
@@ -32,8 +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_DWC_HSSI BIT(2) -#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
Re: [PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker
Quoted 4 lines · 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_HSSIcapability flag then and use thedw_spi_ip_is()macro instead.
But see below.
Quoted 81 lines
Signed-off-by Serge Semin <[email protected]>---
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.--- drivers/spi/spi-dw-core.c | 8 ++++---- drivers/spi/spi-dw-mmio.c | 5 +++-- drivers/spi/spi-dw.h | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-)drivers/spi/spi-dw-core.c +4
-4@@ -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@@ -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
-0
drivers/spi/spi-dw.h line 35
Quoted 6 lines
drivers/spi/spi-dw.h +1
-2@@ -32,8 +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_DWC_HSSI BIT(2) -#define DW_SPI_CAP_DFS32 BIT(3) +#define DW_SPI_CAP_DFS32 BIT(2)
In one patch you move this in the file upper.
Here you reshuffling it due to dropping one bit.
Now I'm wondering if you may split these two into a separate patch, which brings us to simple
-#define DW_SPI_CAP_DWC_HSSI BIT(3)
here.
Quoted 3 lines
drivers/spi/spi-dw.h +0
-0/* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */ #define DW_SPI_CTRLR0 0x00
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker
Quoted 102 lines · Andy Shevchenko
Quoted 4 lines · 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_HSSIcapability flag then and use thedw_spi_ip_is()macro instead.Reviewed-by Andy Shevchenko <[email protected]>But see below.
Quoted 81 lines
Signed-off-by Serge Semin <[email protected]>---
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.--- drivers/spi/spi-dw-core.c | 8 ++++---- drivers/spi/spi-dw-mmio.c | 5 +++-- drivers/spi/spi-dw.h | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-)drivers/spi/spi-dw-core.c +4
-4@@ -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@@ -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
-0drivers/spi/spi-dw.h line 35
Quoted 6 lines
drivers/spi/spi-dw.h +1
-2@@ -32,8 +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_DWC_HSSI BIT(2) -#define DW_SPI_CAP_DFS32 BIT(3) +#define DW_SPI_CAP_DFS32 BIT(2)In one patch you move this in the file upper.
Here you reshuffling it due to dropping one bit.
Quoted 6 lines
Now I'm wondering if you may split these two into a separate patch, which brings us to simple
-#define
DW_SPI_CAP_DWC_HSSIBIT(3)here.
I can change the bit-numbers assignment in the previous patch, which moves this block of macros up to the top of the file. Thus we'll have just a single
-#define DW_SPI_CAP_DWC_HSSI BIT(3)
here. What do you think? Is that what you meant?
-Sergey
Quoted 10 lines
Quoted 4 lines
drivers/spi/spi-dw.h +0
-0/* Register offsets (Generic for both DWC APB SSI and DWC SSI IP-cores) */ #define DW_SPI_CTRLR0 0x00Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker
Quoted 2 lines · Serge Semin
Quoted 1 line · Andy Shevchenko
On Mon, Nov 15, 2021 at 01:30:26AM +0300, Serge Semin wrote:
...
Quoted 15 lines
Quoted 15 lines
drivers/spi/spi-dw.h line 35
Quoted 6 lines
/* DW SPI controller capabilities */
#defineDW_SPI_CAP_CS_OVERRIDEBIT(0)
#defineDW_SPI_CAP_KEEMBAY_MSTBIT(1)drivers/spi/spi-dw.h +1
-2-#define DW_SPI_CAP_DWC_HSSI BIT(2) -#define DW_SPI_CAP_DFS32 BIT(3) +#define DW_SPI_CAP_DFS32 BIT(2)In one patch you move this in the file upper.
Here you reshuffling it due to dropping one bit.Now I'm wondering if you may split these two into a separate patch, which brings us to simple
-#define
DW_SPI_CAP_DWC_HSSIBIT(3)
Quoted 7 lines
Quoted 1 line
here.
I can change the bit-numbers assignment in the previous patch, which moves this block of macros up to the top of the file. Thus we'll have just a single
-#defineDW_SPI_CAP_DWC_HSSIBIT(3)
here. What do you think? Is that what you meant?
I think that reassignment doesn't fit the previous patch per se, hence I proposed to have yet another one, But in any case it's a minor thingy.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 6/6] spi: dw: Replace DWC_HSSI capability with IP-core version checker
Quoted 29 lines · Andy Shevchenko
Quoted 2 lines · Serge Semin
Quoted 1 line · Andy Shevchenko
On Mon, Nov 15, 2021 at 01:30:26AM +0300, Serge Semin wrote:
...
Quoted 15 lines
Quoted 15 lines
drivers/spi/spi-dw.h line 35
Quoted 6 lines
/* DW SPI controller capabilities */
#defineDW_SPI_CAP_CS_OVERRIDEBIT(0)
#defineDW_SPI_CAP_KEEMBAY_MSTBIT(1)drivers/spi/spi-dw.h +1
-2-#define DW_SPI_CAP_DWC_HSSI BIT(2) -#define DW_SPI_CAP_DFS32 BIT(3) +#define DW_SPI_CAP_DFS32 BIT(2)In one patch you move this in the file upper.
Here you reshuffling it due to dropping one bit.Now I'm wondering if you may split these two into a separate patch, which brings us to simple
-#define
DW_SPI_CAP_DWC_HSSIBIT(3)Quoted 7 lines
Quoted 1 line
here.
I can change the bit-numbers assignment in the previous patch, which moves this block of macros up to the top of the file. Thus we'll have just a single
-#defineDW_SPI_CAP_DWC_HSSIBIT(3)
here. What do you think? Is that what you meant?
Quoted 5 lines
I think that reassignment doesn't fit the previous patch per se, hence I proposed to have yet another one,
But in any case it's a minor
thingy.
Since I have to resend the series one more time I'll do as you suggested and unpin the bit numbering change into a separate patch.
-Sergey
Quoted 4 lines
Signature · 3 lines
-- With Best Regards, Andy Shevchenko