Add MSPI support for Cygnus
Subsystems (2)
cover Add MSPI support for Cygnus
This patchset adds support for the MSPI controller on Cygnus. The existing MSPI driver in the kernel was written for BCMA which is a Broadcom AMBA bus variant used on certain chips such as the 53xx.
This patch makes BCMA support optional. The current config is being renamed to make it chip nonspecific supporting BCMA, and a new config is added to support non-BCMA chips. DT support is now mandatory to allow removal of a hardcoded SPI device.
Support is also added to set the baud rate. The controller currently runs at the slowest speed possible.
Jonathan Richardson (4):
ARM: dts: Add binding for Broadcom MSPI driver.
spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
spi: bcm-mspi: Add support to set serial baud clock rate
.../devicetree/bindings/spi/brcm,mspi-spi.txt | 38 ++ drivers/spi/Kconfig | 12 +- drivers/spi/Makefile | 3 +- drivers/spi/spi-bcm-mspi.c | 453 ++++++++++++++++++++ drivers/spi/spi-bcm-mspi.h | 84 ++++ drivers/spi/spi-bcm53xx.c | 299 ------------- drivers/spi/spi-bcm53xx.h | 72 ---- 7 files changed, 585 insertions(+), 376 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt create mode 100644 drivers/spi/spi-bcm-mspi.c create mode 100644 drivers/spi/spi-bcm-mspi.h delete mode 100644 drivers/spi/spi-bcm53xx.c delete mode 100644 drivers/spi/spi-bcm53xx.h
Signature · 1 line
1.7.9.5
PATCH 1/4 ARM: dts: Add binding for Broadcom MSPI driver.
--- .../devicetree/bindings/spi/brcm,mspi-spi.txt | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +38 -0
@@ -0,0 +1,38 @@ +Broadcom MSPI controller + +Required properties: +- compatible: Must be either "brcm,mspi" or "brcm,bcma-mspi". Use + "brcm,bcma-mspi" for controllers on a bcma bus and "brcm,mspi" otherwise. + +- reg: Physical base address and length of the controller's registers. + +- interrupts: The interrupt id for the controller. + +- #address-cells: should be 1. + +- #size-cells: should be 0. + +Optional properties: +- clocks: The MSPI reference clock. If not provided then it is assumed a clock + is enabled by default and no control of clock-frequency (see below) is + possible. + +- clock-names: The name of the reference clock. + +- clock-frequency: Desired frequency of the clock. This will set the serial + clock baud rate (SPBR) based on the reference clock frequency. The frequency + of the SPBR is mspi_clk / (2 * SPBR) where SPBR is a value between 1-255 + determined by the desired 'clock-frequency'. If not provided then the default + baud rate of the controller is used. + +Example: + +mspi@18047000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,mspi"; + reg = <0x18047000 0x1000>; + clocks = <&axi41_clk>; + clock-names = "mspi_clk"; + clock-frequency = <12500000>; +};
Signature · 1 line
1.7.9.5
PATCH 4/4 spi: bcm-mspi: Add support to set serial baud clock rate
In reply to Jonathan RichardsonThe driver wasn't setting the SPBR (serial clock baud rate) which caused it to run at the slowest speed possible. The driver now calculates the SPBR based on the reference clock frequency resulting in much faster SPI transfers.
--- drivers/spi/spi-bcm-mspi.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
drivers/spi/spi-bcm-mspi.c +48 -0
@@ -18,10 +18,15 @@#include <linux/bcma/bcma.h> #include <linux/spi/spi.h> #include <linux/of.h> +#include <linux/clk.h> #include "spi-bcm-mspi.h" #define BCM_MSPI_MAX_SPI_BAUD 13500000/* 216 MHz? */ +#define SPBR_MIN 8U +#define SPBR_MAX 255U +#define MSPI_SPCR0_LSB_OFFSET 0x200 +#define MSPI_SPCR0_LSB_SHIFT 0/* The longest observed required wait was 19 ms */ #define BCM_MSPI_SPE_TIMEOUT_MS 80
@@ -33,7 +38,9 @@ struct bcm_mspi {void __iomem *base;struct spi_master *master; +struct clk *clk;size_t read_offset; +u32 spbr;void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value);u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset);
@@ -45,6 +52,15 @@ static inline unsigned int bcm_mspi_calc_timeout(size_t len)return (len *9000 /BCM_MSPI_MAX_SPI_BAUD *110 /100 ) +1 ; } +static void bcm_mspi_hw_init (struct bcm_mspi *mspi) +{ +/* Set SPBR (serial clock baud rate). */ +if (mspi->spbr) { + mspi->mspi_write (mspi,MSPI_SPCR0_LSB_OFFSET , + mspi->spbr <<MSPI_SPCR0_LSB_SHIFT ); + } +} +static int bcm_mspi_wait (struct bcm_mspi *mspi,unsigned int timeout_ms) {unsigned long deadline;
@@ -221,6 +237,7 @@ static struct bcm_mspi *bcm_mspi_init(struct device *dev) {struct bcm_mspi *data;struct spi_master *master; +u32 desired_rate; master =spi_alloc_master (dev,sizeof (*data));if (!master) {
@@ -235,6 +252,31 @@ static struct bcm_mspi *bcm_mspi_init(struct device *dev) master->dev.of_node = dev->of_node; master->transfer_one = bcm_mspi_transfer_one; +/* +* Enable clock if provided. The frequency can be changed by setting +* SPBR (serial clock baud rate) based on the desired 'clock-frequency'. +* +* Baud rate is calculated as: mspi_clk / (2 * SPBR) where SPBR is a +* value between 1-255. If not set then it is left at the h/w default. +*/ + data->clk =devm_clk_get (dev,"mspi_clk" ); +if (!IS_ERR (data->clk)) { +int ret =clk_prepare_enable (data->clk); + +if (ret <0 ) { +dev_err (dev,"failed to enable clock: %d\n" , ret); +return 0 ; + } + +/* Calculate SPBR if clock-frequency provided. */ +if (of_property_read_u32 (dev->of_node,"clock-frequency" , + &desired_rate) >=0 ) { +u32 spbr =clk_get_rate (data->clk) / (2 * desired_rate); + + data->spbr =clamp_val (spbr,SPBR_MIN ,SPBR_MAX ); + } + } +return data; }
@@ -286,6 +328,9 @@ static int bcm_mspi_probe(struct platform_device *pdev) data->mspi_write = bcm_mspi_write;platform_set_drvdata (pdev, data); +/* Initialize SPI controller. */ +bcm_mspi_hw_init (data); + err =devm_spi_register_master (dev, data->master);if (err) goto out;
@@ -360,6 +405,9 @@ static int bcm_mspi_bcma_probe(struct bcma_device *core) data->core = core;bcma_set_drvdata (core, data); +/* Initialize SPI controller. */ +bcm_mspi_hw_init (data); + err =devm_spi_register_master (&core->dev, data->master);if (err) {spi_master_put (data->master);
Signature · 1 line
1.7.9.5
PATCH 3/4 spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Jonathan RichardsonThe Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
--- drivers/spi/Kconfig | 5 ++ drivers/spi/Makefile | 1 + drivers/spi/spi-bcm-mspi.c | 200 +++++++++++++++++++++++++++++++++----------- 3 files changed, 155 insertions(+), 51 deletions(-)
drivers/spi/Kconfig +5 -0
@@ -120,6 +120,11 @@ config SPI_BCMA_MSPI help Enable support for the Broadcom BCMA MSPI controller. +config SPI_BCM_MSPI + tristate "Broadcom MSPI controller" + help + Enable support for the Broadcom MSPI controller. + config SPI_BCM63XX tristate "Broadcom BCM63xx SPI controller" depends on BCM63XX
drivers/spi/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o obj-$(CONFIG_SPI_BCMA_MSPI) += spi-bcm-mspi.o +obj-$(CONFIG_SPI_BCM_MSPI) += spi-bcm-mspi.o obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
drivers/spi/spi-bcm-mspi.c +149 -51
349 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH 2/4 spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
In reply to Jonathan RichardsonThe Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
--- drivers/spi/Kconfig | 7 +- drivers/spi/Makefile | 2 +- drivers/spi/spi-bcm-mspi.c | 307 ++++++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-bcm-mspi.h | 84 ++++++++++++ drivers/spi/spi-bcm53xx.c | 299 ------------------------------------------ drivers/spi/spi-bcm53xx.h | 72 ----------- 6 files changed, 395 insertions(+), 376 deletions(-) create mode 100644 drivers/spi/spi-bcm-mspi.c create mode 100644 drivers/spi/spi-bcm-mspi.h delete mode 100644 drivers/spi/spi-bcm53xx.c delete mode 100644 drivers/spi/spi-bcm53xx.h
drivers/spi/Kconfig +3 -4
@@ -113,13 +113,12 @@ config SPI_AU1550 If you say yes to this option, support will be included for the PSC SPI controller found on Au1550, Au1200 and Au1300 series. -config SPI_BCM53XX - tristate "Broadcom BCM53xx SPI controller" - depends on ARCH_BCM_5301X +config SPI_BCMA_MSPI + tristate "Broadcom BCMA MSPI controller" depends on BCMA_POSSIBLE select BCMA help - Enable support for the SPI controller on Broadcom BCM53xx ARM SoCs. + Enable support for the Broadcom BCMA MSPI controller. config SPI_BCM63XX tristate "Broadcom BCM63xx SPI controller"
drivers/spi/Makefile +1 -1
@@ -15,7 +15,7 @@ obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o obj-$(CONFIG_SPI_BCM2835) += spi-bcm2835.o -obj-$(CONFIG_SPI_BCM53XX) += spi-bcm53xx.o +obj-$(CONFIG_SPI_BCMA_MSPI) += spi-bcm-mspi.o obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
drivers/spi/spi-bcm-mspi.c new file +307 -0
307 lines not on this page · raw message
drivers/spi/spi-bcm-mspi.h new file +84 -0
84 lines not on this page · raw message
drivers/spi/spi-bcm53xx.c deleted +0 -299
299 lines not on this page · raw message
drivers/spi/spi-bcm53xx.h deleted +0 -72
72 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH 2/4] spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
Quoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
What if you resend this one with -M -C applied?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Jonathan RichardsonQuoted 8 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +1
-0+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core;
drivers/spi/spi-bcm-mspi.c line 40
Quoted 10 lines
drivers/spi/spi-bcm-mspi.c +6
-1-struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset; +void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};
To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like mspi-core.c mspi-53xx.c mspi-whatever.c. Check for example spi-dw*.c
Signature · 6 lines
With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
Quoted 17 lines · Andy Shevchenko
Quoted 14 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +4
-1+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core; -struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset;
Quoted 8 lines
drivers/spi/spi-bcm-mspi.c line 40
Quoted 3 lines
drivers/spi/spi-bcm-mspi.c +3
-0+void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like
mspi-core.cmspi-53xx.cmspi-whatever.c. Check for example spi-dw*.c
Actually, I am really curious whether we need the special BCMA I/O accessors in the first place, cannot we just access the MSPI core on BCM53xx chips using regular MMIO? That would probably solve the "problem" entirely. Rafal, did you try this before?
As for splitting the driver into a "library" driver which is mostly independent from the bus and a bus-specific wrapper, I think BCMA is really the only special case here, which is why I suggested earlier to Jonathan that we might just prefer ifdefing things out instead of creating a separate layer just for BCMA.
Signature · 5 lines
Florian -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 4/4] spi: bcm-mspi: Add support to set serial baud clock rate
In reply to Jonathan RichardsonQuoted 7 lines · Jonathan Richardson
The driver wasn't setting the SPBR (serial clock baud rate) which caused it to run at the slowest speed possible. The driver now calculates the SPBR based on the reference clock frequency resulting in much faster SPI transfers.
---
[snip]
drivers/spi/spi-bcm-mspi.c static struct bcm_mspi *bcm_mspi_init(struct device *dev) · line 274
Quoted 13 lines
drivers/spi/spi-bcm-mspi.c +13
-0+ data->clk =devm_clk_get (dev,"mspi_clk" ); +if (!IS_ERR (data->clk)) { +int ret =clk_prepare_enable (data->clk); + +if (ret <0 ) { +dev_err (dev,"failed to enable clock: %d\n" , ret); +return 0 ; + } + +/* Calculate SPBR if clock-frequency provided. */ +if (of_property_read_u32 (dev->of_node,"clock-frequency" , + &desired_rate) >=0 ) { +u32 spbr =clk_get_rate (data->clk) / (2 * desired_rate);
Usually, specifying a "clock-frequency" property is done when there is no clock provider available, yet we take this code path only if we could find a "mspi_clk" which sounds a litle weird.
Once there is a proper "mspi_clk" clock, I would make it mandatory for the clock provider to be able to provide the rate as well?
--
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/4] ARM: dts: Add binding for Broadcom MSPI driver.
In reply to Jonathan RichardsonQuoted 13 lines · Jonathan Richardson
Signed-off-by Jonathan Richardson <[email protected]>--- .../devicetree/bindings/spi/brcm,mspi-spi.txt | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/brcm,mspi-spi.txtDocumentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +0
-0
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +5
-0@@ -0,0 +1,38 @@ +Broadcom MSPI controller + +Required properties: +- compatible: Must be either "brcm,mspi" or "brcm,bcma-mspi". Use + "brcm,bcma-mspi" for controllers on a bcma bus and "brcm,mspi" otherwise.
We need a more specific compatible property here since there are at least 3 known SoCs families within Broadcom (Cygnus, BCM53xx, BCM7xxx) that use this controller, also older versions of the core did not have a revision register, yet they had an internal version numbering that we might want to reflect here. This does not need to be fixed immediately though, we can add compatible strings as we start adding support for older cores.
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 9
Quoted 4 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +4
-0+ +- reg: Physical base address and length of the controller's registers. + +- interrupts: The interrupt id for the controller.
I think this should be two cells, on BCM7xxx chips there is a MSPI_DONE and a MSPI_ERROR interrupt bit, we typically only use the first one, but since we are describing the hardware here, we need to be exhaustive.
Quoted 7 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +7
-0+ +- #address-cells: should be 1. + +- #size-cells: should be 0. + +Optional properties: +- clocks: The MSPI reference clock. If not provided then it is assumed a clock
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 26
Quoted 10 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +10
-0+ is enabled by default and no control of clock-frequency (see below) is + possible. + +- clock-names: The name of the reference clock. + +- clock-frequency: Desired frequency of the clock. This will set the serial + clock baud rate (SPBR) based on the reference clock frequency. The frequency + of the SPBR is mspi_clk / (2 * SPBR) where SPBR is a value between 1-255 + determined by the desired 'clock-frequency'. If not provided then the default + baud rate of the controller is used.
See my reply to the patch 4, that does not seem to match the "clock-frequency" vs. clock phandles practices in DT.
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 37
Quoted 11 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +11
-0+ +Example: + +mspi@18047000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,mspi"; + reg = <0x18047000 0x1000>; + clocks = <&axi41_clk>; + clock-names = "mspi_clk"; + clock-frequency = <12500000>;
Since "interrupts" is a mandatory property you might want the example to show it for consistency.
--
Florian
Mark Brown
maintainerRe: [PATCH 4/4] spi: bcm-mspi: Add support to set serial baud clock rate
In reply to Florian FainelliQuoted 11 lines · Florian Fainelli
drivers/spi/spi-bcm-mspi.c static struct bcm_mspi *bcm_mspi_init(struct device *dev) · line 274
Quoted 4 lines · Jonathan Richardson
drivers/spi/spi-bcm-mspi.c +4
-0+/* Calculate SPBR if clock-frequency provided. */ +if (of_property_read_u32 (dev->of_node,"clock-frequency" , + &desired_rate) >=0 ) { +u32 spbr =clk_get_rate (data->clk) / (2 * desired_rate);Usually, specifying a "clock-frequency" property is done when there is no clock provider available, yet we take this code path only if we could find a "
mspi_clk" which sounds a litle weird.
Quoted 2 lines
Once there is a proper "
mspi_clk" clock, I would make it mandatory for the clock provider to be able to provide the rate as well?
As far as I can tell it's already mandatory if the property is present - it's taking the clock presented to the block and then using an internal divider to bring that down to the desired rate.
We are missing error handling though.
Re: [PATCH 2/4] spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
In reply to Andy ShevchenkoQuoted 7 lines · Andy Shevchenko
Quoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
What if you resend this one with -M -C applied?
Definitely, right now I can't really review this patch (and I want to).
Signature · 5 lines
Rafał -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Jonathan RichardsonQuoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
I think this patch provides 3 changes instead of just one described above. You refactored R/W ops (pointers), made bcma optional and added DT support. What about patch-per-change?
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Andy ShevchenkoQuoted 17 lines · Andy Shevchenko
Quoted 14 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +4
-1+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core; -struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset;
Quoted 7 lines
drivers/spi/spi-bcm-mspi.c line 40
Quoted 3 lines
drivers/spi/spi-bcm-mspi.c +3
-0+void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like
mspi-core.cmspi-53xx.cmspi-whatever.c. Check for example spi-dw*.c
I also believe we usually (always?) don't align any #if-s (no indent/tabs).
Signature · 5 lines
Rafał -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Florian FainelliQuoted 22 lines · Florian Fainelli
Quoted 21 lines · Andy Shevchenko
Quoted 18 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +7
-1+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core; -struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset; +void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};
Quoted 8 lines
Quoted 3 lines
To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like
mspi-core.cmspi-53xx.cmspi-whatever.c. Check for example spi-dw*.cActually, I am really curious whether we need the special BCMA I/O accessors in the first place, cannot we just access the MSPI core on BCM53xx chips using regular MMIO? That would probably solve the "problem" entirely. Rafal, did you try this before?
It's a matter of choice between:
1) Using one design for all bcma users
2) Using one design for all bcm-mspi users
I believe no matter which one you choose, you'll break another one.
If you take a look at drivers/bcma/host_soc.c, you'll see we've there core->io_addr. I guess you could use it as the base in bcm-mspi. That of course will make you a bit less compatible with other bcma drivers (skipping bcma R/W layer).
Quoted 5 lines
As for splitting the driver into a "library" driver which is mostly independent from the bus and a bus-specific wrapper, I think BCMA is really the only special case here, which is why I suggested earlier to Jonathan that we might just prefer ifdefing things out instead of creating a separate layer just for BCMA.
I think you may be right, this #if for bcma shouldn't be that bad and it shouldn't grow in the future.
Still, I'd like to get this patch split nicely to review independent changes.
Signature · 5 lines
Rafał -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
In reply to Andy ShevchenkoQuoted 9 lines · Andy Shevchenko
Quoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
What if you resend this one with -M -C applied?
I'm not seeing any difference in the patches unfortunately. I'll keep playing with it and re-send if I can find a way to improve it.
The changes are just renaming variables, structures, functions, file name to get rid of 53xx and replace with mspi. The config is renamed from SPI_BCM53XX to SPI_BCMA_MSPI.
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Florian FainelliQuoted 32 lines · Florian Fainelli
Quoted 17 lines · Andy Shevchenko
Quoted 14 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +4
-1+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core; -struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset;Quoted 8 lines
drivers/spi/spi-bcm-mspi.c line 40
Quoted 3 lines
drivers/spi/spi-bcm-mspi.c +3
-0+void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like
mspi-core.cmspi-53xx.cmspi-whatever.c. Check for example spi-dw*.cActually, I am really curious whether we need the special BCMA I/O accessors in the first place, cannot we just access the MSPI core on BCM53xx chips using regular MMIO? That would probably solve the "problem" entirely. Rafal, did you try this before?
Quoted 6 lines
As for splitting the driver into a "library" driver which is mostly independent from the bus and a bus-specific wrapper, I think BCMA is really the only special case here, which is why I suggested earlier to Jonathan that we might just prefer ifdefing things out instead of creating a separate layer just for BCMA.
I cringed adding the ifdefs to the driver but didn't think the small amount of code that wouldn't be used again warranted 3 files. I could also handle the two different probe routines by doing some DT parsing in init, but then BCMA would have to be compiled for the non-BCMA MSPI driver and I didn't want to do that either.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/4] ARM: dts: Add binding for Broadcom MSPI driver.
In reply to Florian FainelliQuoted 28 lines · Florian Fainelli
Quoted 13 lines · Jonathan Richardson
Signed-off-by Jonathan Richardson <[email protected]>--- .../devicetree/bindings/spi/brcm,mspi-spi.txt | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/brcm,mspi-spi.txtDocumentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +0
-0Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 5
Quoted 5 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +5
-0@@ -0,0 +1,38 @@ +Broadcom MSPI controller + +Required properties: +- compatible: Must be either "brcm,mspi" or "brcm,bcma-mspi". Use + "brcm,bcma-mspi" for controllers on a bcma bus and "brcm,mspi" otherwise.We need a more specific compatible property here since there are at least 3 known SoCs families within Broadcom (Cygnus, BCM53xx, BCM7xxx) that use this controller, also older versions of the core did not have a revision register, yet they had an internal version numbering that we might want to reflect here. This does not need to be fixed immediately though, we can add compatible strings as we start adding support for older cores.
Quoted 8 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 9
Quoted 4 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +4
-0+ +- reg: Physical base address and length of the controller's registers. + +- interrupts: The interrupt id for the controller.I think this should be two cells, on BCM7xxx chips there is a
MSPI_DONEand aMSPI_ERRORinterrupt bit, we typically only use the first one, but since we are describing the hardware here, we need to be exhaustive.
My mistake. Interrupts are not supported by this driver yet. I intend on adding this later. I will remove this from the docs.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +12
-0+ +- #address-cells: should be 1. + +- #size-cells: should be 0. + +Optional properties: +- clocks: The MSPI reference clock. If not provided then it is assumed a clock + is enabled by default and no control of clock-frequency (see below) is + possible. + +- clock-names: The name of the reference clock. +
Quoted 8 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 26
Quoted 5 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +5
-0+- clock-frequency: Desired frequency of the clock. This will set the serial + clock baud rate (SPBR) based on the reference clock frequency. The frequency + of the SPBR is mspi_clk / (2 * SPBR) where SPBR is a value between 1-255 + determined by the desired 'clock-frequency'. If not provided then the default + baud rate of the controller is used.See my reply to the patch 4, that does not seem to match the "clock-frequency" vs. clock phandles practices in DT.
I could use a different property for it. I agree it's a bit weird since we're not changing the frequency of the reference clock but the clock derived from it for the baud rate of the controller. Does this warrant adding a different property though?
Quoted 18 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt line 37
Quoted 12 lines
Documentation/devicetree/bindings/spi/brcm,mspi-spi.txt new file +11
-0+ +Example: + +mspi@18047000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,mspi"; + reg = <0x18047000 0x1000>; + clocks = <&axi41_clk>; + clock-names = "mspi_clk"; + clock-frequency = <12500000>;Since "interrupts" is a mandatory property you might want the example to show it for consistency.
--
Florian
Re: [PATCH 4/4] spi: bcm-mspi: Add support to set serial baud clock rate
In reply to Mark BrownQuoted 12 lines · Mark Brown
Quoted 10 lines · Florian Fainelli
drivers/spi/spi-bcm-mspi.c static struct bcm_mspi *bcm_mspi_init(struct device *dev) · line 274
Quoted 4 lines · Jonathan Richardson
drivers/spi/spi-bcm-mspi.c +4
-0+/* Calculate SPBR if clock-frequency provided. */ +if (of_property_read_u32 (dev->of_node,"clock-frequency" , + &desired_rate) >=0 ) { +u32 spbr =clk_get_rate (data->clk) / (2 * desired_rate);Usually, specifying a "clock-frequency" property is done when there is no clock provider available, yet we take this code path only if we could find a "
mspi_clk" which sounds a litle weird.
Quoted 9 lines
Quoted 2 lines
Once there is a proper "
mspi_clk" clock, I would make it mandatory for the clock provider to be able to provide the rate as well?As far as I can tell it's already mandatory if the property is present - it's taking the clock presented to the block and then using an internal divider to bring that down to the desired rate.
We are missing error handling though.
Thanks for the review. Yes that's correct. I also tried to make it backwards compatible with the current version of the driver where you can ignore configuring the frequency. The result being ref clock frequency / 2 * 255. If you provide the clock then it will enable/prepare it. If you also provide clock-frequency then it will configure the SPBR. If you don't provide anything then it works as before - it assumes the clock is already enabled and uses the h/w default SPBR.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/4] spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
In reply to Rafał MiłeckiQuoted 11 lines · Rafał Miłecki
Quoted 7 lines · Andy Shevchenko
Quoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
What if you resend this one with -M -C applied?
Definitely, right now I can't really review this patch (and I want to).
Thanks Rafal for the review. Please see previous reply to Andy and let me know if I'm missing something.
Re: [PATCH 3/4] spi: bcm-mspi: Make BCMA optional to support non-BCMA chips
In reply to Rafał MiłeckiQuoted 37 lines · Rafał Miłecki
Quoted 22 lines · Florian Fainelli
Quoted 21 lines · Andy Shevchenko
Quoted 18 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various chips. The driver only supported BCM53xx chips with BCMA (an AMBA bus variant). The driver is refactored to make BCMA optional and provides a new config for non BCMA systems.
struct
bcm_mspi{drivers/spi/spi-bcm-mspi.c +7
-1+#ifdef CONFIG_SPI_BCMA_MSPI struct bcma_device *core; -struct spi_master *master; +#endif +void __iomem *base; +struct spi_master *master;size_t read_offset; +void (*mspi_write)(struct bcm_mspi *mspi,u16 offset,u32 value); +u32 (*mspi_read)(struct bcm_mspi *mspi,u16 offset); +};Quoted 8 lines
Quoted 3 lines
To avoid ugly ifdefs I think better to split driver to core part and the actual driver part, at the end you will have something like
mspi-core.cmspi-53xx.cmspi-whatever.c. Check for example spi-dw*.cActually, I am really curious whether we need the special BCMA I/O accessors in the first place, cannot we just access the MSPI core on BCM53xx chips using regular MMIO? That would probably solve the "problem" entirely. Rafal, did you try this before?
It's a matter of choice between:
1) Using one design for all bcma users
2) Using one design for all bcm-mspi users
I believe no matter which one you choose, you'll break another one.
Quoted 4 lines
If you take a look at
drivers/bcma/host_soc.c, you'll see we've therecore->io_addr. I guess you could use it as the base in bcm-mspi. That of course will make you a bit less compatible with other bcma drivers (skipping bcma R/W layer).
That would require compiling in BCMA for a driver/chip that doesn't use BCMA but then I could do DT parsing in init only anyway. I don't think that's really an option so I'm going to leave as is unless there is further opinion on it.
Quoted 8 lines
Quoted 7 lines
As for splitting the driver into a "library" driver which is mostly independent from the bus and a bus-specific wrapper, I think BCMA is really the only special case here, which is why I suggested earlier to Jonathan that we might just prefer ifdefing things out instead of creating a separate layer just for BCMA.
Quoted 4 lines
I think you may be right, this #if for bcma shouldn't be that bad and it shouldn't grow in the future.
Still, I'd like to get this patch split nicely to review independent changes.
Making BCMA optional was made possible by using DT. I'm not sure I could split it into two commits. I would have to add a hard coded SPI device for non-BMCA as well. I thought the driver was a bit odd in that this was hard coded. Normally this should be in a separate driver. How would you use it if you wanted to use m25p80 for example?
Re: [PATCH 2/4] spi: bcm53xx: Refactor to make driver nonspecific to 53xx SoCs
In reply to Jonathan RichardsonQuoted 11 lines · Jonathan Richardson
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · Jonathan Richardson
The Broadcom MSPI controller is used on various SoCs. It is being renamed so that it can be extended and reused on other chips. It is renamed to bcm-mspi.
What if you resend this one with -M -C applied?
Quoted 7 lines
I'm not seeing any difference in the patches unfortunately. I'll keep playing with it and re-send if I can find a way to improve it.
The changes are just renaming variables, structures, functions, file name to get rid of 53xx and replace with mspi. The config is renamed from
SPI_BCM53XXtoSPI_BCMA_MSPI.
Better to split: a) moving, b) renaming something inside.
Signature · 6 lines
With Best Regards, Andy Shevchenko -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html