dt: bindings: spi-bcm-qspi: NSP, NS2, BRCMSTB SoC bindings
Subsystems (5)
PATCH v3 1/4 dt: bindings: spi-bcm-qspi: NSP, NS2, BRCMSTB SoC bindings
Added device tree bindings documentation for SoCs supported by the new spi-bcm-qspi driver.
---
V3 chnage fixes checkpatch errors and warnings
V2 change renames file to brcm,spi-bcm-qspi.txt
--- .../devicetree/bindings/spi/brcm,spi-bcm-qspi.txt | 227 +++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/brcm,spi-bcm-qspi.txt
Documentation/devicetree/bindings/spi/brcm,spi-bcm-qspi.txt new file +227 -0
@@ -0,0 +1,227 @@ +Broadcom SPI controller + +The Broadcom SPI controller is a SPI master found on various SOCs, including +BRCMSTB (BCM7XXX), Cygnus, NSP and NS2. + +Required properties: + +- #address-cells: + Must be <1>, as required by generic SPI binding. + +- #size-cells: + Must be <0>, also as required by generic SPI binding. + +- compatible: + Must be one of : + "brcm,spi-bcm-qspi" + "brcm,spi-brmstb" spi-nor and/or "brcm,spi-brmstb-mspi" unmanaged SPI Master + +- reg: + Define the bases and ranges of the associated I/O address spaces. + The required range is MSPI controller registers and interrupt registers, the others + are optional Boot SPI (BSPI) portion for fast flash reads. + +- reg-names: + First name does not matter, but must be reserved for the MSPI controller + register range as mentioned in 'reg' above, and will typically contain + - "bspi_regs": BSPI register range + - "mspi_regs": MSPI register range + - "intr_regs", "intr_status_reg" : Interrupt and status register for NSP, NS2 SoC + - "hif_spi_intr2" : Interrupt and status register for BRCMSTB SoC + +- interrupts + The interrupts used by the MSPI and/or BSPI controller. + +- interrupt-names: + Names of interrupts associated with this MSPI and/or BSPI controller. + - "mspi_halted" : + - "mspi_done": Indicates that the requested SPI operation is complete. + - "spi_lr_fullness_reached" : Linear read BSPI pipe full + - "spi_lr_session_aborted" : Linear read BSPI pipe aborted + - "spi_lr_impatient" : Linear read BSPI requested when pipe empty + - "spi_lr_session_done" : Linear read BSPI session done + +Optional properties: + +- clocks: + A phandle to the reference clock for this block. If not present, will + assume a 27 MHz fixed clock (default for UPG). + + +Optional properties: + +- clocks: + A phandle to the reference clock for this block. + +- bspi-sel: + Chip selects that requires bspi support. + +Examples: + +BRCMSTB SoC Example: + + SPI Master for SPI-NOR: + + spi@f03e3400 { + #address-cells = <0x1>; + #size-cells = <0x0>; + compatible = "brcm,qspi-brcmstb"; + reg = <0xf03e0920 0x4 0xf03e3400 0x188 0xf03e3200 0x50>; + reg-names = "cs_reg", "hif_mspi", "bspi"; + interrupts = <0x6 0x5 0x4 0x3 0x2 0x1 0x0>; + interrupt-parent = <0x1c>; + interrupt-names = "mspi_halted", + "mspi_done", + "spi_lr_overread", + "spi_lr_session_done", + "spi_lr_impatient", + "spi_lr_session_aborted", + "spi_lr_fullness_reached"; + + clocks = <0x1b>; + clock-names = "sw_spi"; + + m25p80@0 { + #size-cells = <0x2>; + #address-cells = <0x2>; + compatible = "m25p80"; + reg = <0x0>; + spi-max-frequency = <0x2625a00>; + spi-cpol; + spi-cpha; + use-bspi; + m25p,fast-read; + + flash0.bolt@0 { + reg = <0x0 0x0 0x0 0x100000>; + }; + + flash0.macadr@100000 { + reg = <0x0 0x100000 0x0 0x10000>; + }; + + flash0.nvram@110000 { + reg = <0x0 0x110000 0x0 0x10000>; + }; + + flash0.kernel@120000 { + reg = <0x0 0x120000 0x0 0x400000>; + }; + + flash0.devtree@520000 { + reg = <0x0 0x520000 0x0 0x10000>; + }; + + flash0.splash@530000 { + reg = <0x0 0x530000 0x0 0x80000>; + }; + + flash0@0 { + reg = <0x0 0x0 0x0 0x4000000>; + }; + }; + }; + + + MSPI master: + + spi@f0416000 { + #address-cells = <1>; + #size-cells = <0>; + clocks = <&upg_fixed>; + compatible = "brcm,spi-brcmstb-mspi"; + reg = <0xf0416000 0x180>; + reg-names = "mspi"; + interrupts = <0x14>; + interrupt-parent = <&irq0_aon_intc>; + interrupt-names = "mspi_done"; + }; + + + +iProc SoC Example: + + qspi: spi@18027200 { + compatible = "brcm,spi-bcm-qspi"; + reg = <0x18027200 0x184>, + <0x18027000 0x124>, + <0x1811c408 0x004>, + <0x180273a0 0x01c>; + reg-names = "mspi_regs", "bspi_regs", "intr_regs", "intr_status_reg"; + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = + "spi_lr_fullness_reached", + "spi_lr_session_aborted", + "spi_lr_impatient", + "spi_lr_session_done", + "mspi_done", + "mspi_halted"; + clocks = <&iprocmed>; + clock-names = "iprocmed"; + clock-frequency = <12500000>; + num-cs = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + + NS2 SoC Example: + + qspi: spi@66470200 { + compatible = "brcm,spi-bcm-qspi"; + reg = <0x66470200 0x184>, + <0x66470000 0x124>, + <0x67017408 0x004>, + <0x664703a0 0x01c>; + reg-names = "mspi", "bspi", "intr_regs", "intr_status_reg"; + interrupts = <GIC_SPI 419 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "spi_l1_intr"; + clocks = <&iprocmed>; + clock-names = "iprocmed"; + clock-frequency = <12500000>; + num-cs = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + + + m25p80 node for NSP, NS2 and iProc + + &qspi { + bspi-sel = <0>; + flash: m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "m25p80"; + reg = <0x0>; + spi-max-frequency = <12500000>; + m25p,fast-read; + spi-cpol; + spi-cpha; + + partition@0 { + label = "boot"; + reg = <0x00000000 0x000a0000>; + }; + + partition@1 { + label = "env"; + reg = <0x000a0000 0x00060000>; + }; + + partition@2 { + label = "system"; + reg = <0x00100000 0x00600000>; + }; + + partition@3 { + label = "rootfs"; + reg = <0x00700000 0x01900000>; + }; + };
Signature · 6 lines
1.9.1 -- 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
A message that is not in the archive (sent off-list or not yet received): 1465589171-25575-1-git-send-email-kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH v3 2/4 spi: bcm-qspi: Add SPI flash and MSPI driver
Adding unified SPI flash and MSPI driver for Broadcom BRCMSTB, NS2, NSP SoCs. Driver shall work with brcm,7120-l2-intc or brcm-l2-intc or with a single muxed L1 interrupt source. Driver implements the queued transfer_one_message() method for reading from and writing to spi device.
---
V3 changes:
add GPL v2 header
Add depends to SPI_BCM_QSPI in Kconfig
fixes checkpatch warnings
V2 changes:
Implemented transfer_one_message() method, removed deprecated transfer() method Refactored MSPI hw read write code to handle spi transfers Refactored BSPI reads to handle spi transfers
Better handling of LE and BE archtectures via register rw inline functions Removed all uneceesary code related to message queue handling
--- drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-bcm-qspi.c | 1831 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1842 insertions(+) create mode 100644 drivers/spi/spi-bcm-qspi.c
drivers/spi/Kconfig +10 -0
@@ -153,6 +153,16 @@ config SPI_BCM63XX_HSSPI This enables support for the High Speed SPI controller present on newer Broadcom BCM63XX SoCs. +config SPI_BCM_QSPI + tristate "Broadcom BSPI and MSPI controller support" + depends on ARCH_BRCMSTB || ARCH_BCM || ARCH_BCM_NSP || \ + ARCH_BCM_CYGNUS || COMPILE_TEST + help + Enables support for the Broadcom SPI flash and MSPI controller. + Select this option for any one of BRCMSTB, Cygnus, NSP, NS2 SoCs + based platforms. This driver works for both SPI master for spi-nor + flash device as well as MSPI device. + config SPI_BITBANG tristate "Utilities for Bitbanging SPI masters" help
drivers/spi/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_SPI_BCM2835AUX) += spi-bcm2835aux.o obj-$(CONFIG_SPI_BCM53XX) += spi-bcm53xx.o obj-$(CONFIG_SPI_BCM63XX) += spi-bcm63xx.o obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o +obj-$(CONFIG_SPI_BCM_QSPI) += spi-bcm-qspi.o obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o obj-$(CONFIG_SPI_ADI_V3) += spi-adi-v3.o obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
drivers/spi/spi-bcm-qspi.c new file +1831 -0
1,831 lines not on this page · raw message
Signature · 6 lines
1.9.1 -- 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
A message that is not in the archive (sent off-list or not yet received): 1465589171-25575-2-git-send-email-kdasu.kdev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Quoted 7 lines · Kamal Dasu
drivers/spi/spi-bcm-qspi.c new file +7
-0+/* Read qspi controller register*/ +static inline u32 bcm_qspi_read (struct bcm_qspi *qspi,enum base_type type, +unsigned int offset) +{ +if (!qspi->base[type]) +return 0 ; +
drivers/spi/spi-bcm-qspi.c line 289
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+/* +* MIPS endianness is configured by boot strap, which also reverses all +* bus endianness (i.e., big-endian CPU + big endian bus ==> native +* endian I/O). +* +* Other architectures (e.g., ARM) either do not support big endian, or +* else leave I/O in little endian mode. +*/ +if (IS_ENABLED (CONFIG_MIPS ) &&IS_ENABLED (CONFIG_CPU_BIG_ENDIAN )) +return __raw_readl (qspi->base[type] + offset);
You shouldn't use raw accessors outside of arch code. Use ioread32be() to read big endian values, and similarly for the writes.
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!qspi->base[INTR]) + return;
All these bits where we just silently ignore operations if some value isn't initialized are a bit worrying - why is this safe and robust? I'd expect chip feature selection to be done at a higher level.
drivers/spi/spi-bcm-qspi.c line 318
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+ +if (qspi->hif_spi_mode) +bcm_qspi_write (qspi,INTR ,HIF_SPI_INTR2_CPU_MASK_CLEAR , mask); +else {
Coding style { } on both sides of the if if they're on one.
drivers/spi/spi-bcm-qspi.c line 447
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static void bcm_qspi_bspi_lr_data_read (struct bcm_qspi *qspi) +{ +u32 *buf = (u32 *)qspi->bspi_xfer->rx_buf; +u32 data =0 ; + +DBG ("xfer %p rx %p rxlen %d\n" , + qspi->bspi_xfer, qspi->bspi_xfer->rx_buf, qspi->bspi_xfer_len);
Use the standard kernel trace infrastructure, don't invent your own.
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+static int bcm_qspi_bspi_set_flex_mode (struct bcm_qspi *qspi,int width, +int addrlen,int hp) +{ +int bpc =0 , bpp =0 ; +u8 command =SPINOR_OP_READ_FAST ; +int flex_mode =1 , rv =0 ;
drivers/spi/spi-bcm-qspi.c line 498
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+bool spans_4byte = false; + +DBG ("set flex mode w %x addrlen %x hp %d\n" , width, addrlen, hp); + +if (addrlen ==BSPI_ADDRLEN_4BYTES ) { + bpp =BSPI_BPP_ADDR_SELECT_MASK ; + spans_4byte = true; + } + + bpp |=8 ;/* dummy cycles */
Dummy cycles?
drivers/spi/spi-bcm-qspi.c line 538
Quoted 2 lines
drivers/spi/spi-bcm-qspi.c new file +2
-0+default : + rv =-1 ;
Real error codes please.
drivers/spi/spi-bcm-qspi.c line 639
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c new file +9
-0+if (!error) { + qspi->xfer_mode.width = width; + qspi->xfer_mode.addrlen = addrlen; + qspi->xfer_mode.hp = hp; +dev_info (&qspi->pdev->dev, +"%d-lane output, %d-byte address%s\n" , + qspi->xfer_mode.width, + qspi->xfer_mode.addrlen, + qspi->xfer_mode.hp ?", high-performance mode" :"" );
This is far too noisy, it's going to spam the logs on every transfer.
drivers/spi/spi-bcm-qspi.c line 643
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+ }else +dev_warn (&qspi->pdev->dev, +"INVALID COMBINATION: width=%d addrlen=%d hp=%d\n" , + width, addrlen, hp);
Why isn't this returning an error?
drivers/spi/spi-bcm-qspi.c line 725
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c new file +9
-0+static int bcm_qspi_update_parms (struct bcm_qspi *qspi, +struct spi_device *spidev, +struct spi_transfer *trans,int override) +{ +struct bcm_qspi_parms xp; + + xp.speed_hz =min (trans->speed_hz ? trans->speed_hz : + (spidev->max_speed_hz ? spidev->max_speed_hz : + qspi->max_speed_hz), qspi->max_speed_hz);
This is marginally legible, and you should just be able to trust what's in the transfer anyway as the core should be doing this - there's nothing device specific.
drivers/spi/spi-bcm-qspi.c line 740
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+if ((override ==PARMS_OVERRIDE ) || + ((xp.speed_hz == qspi->last_parms.speed_hz) && + (xp.chip_select == qspi->last_parms.chip_select) && + (xp.mode == qspi->last_parms.mode) && + (xp.bits_per_word == qspi->last_parms.bits_per_word))) { +bcm_qspi_hw_set_parms (qspi, &xp); +return 0 ; + } +/* no override, and parms do not match */ +return 1 ;
What is an override
drivers/spi/spi-bcm-qspi.c line 788
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+static int find_next_byte (struct bcm_qspi *qspi,struct position *p, +int flags) +{ +int ret =FNB_BREAK_NONE ;
What is this supposed to be doing?
drivers/spi/spi-bcm-qspi.c line 964
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+/* deassert CS on the final byte */ +if (fnb &FNB_BREAK_DESELECT ) { + mspi_cdram =read_cdram_slot (qspi, slot -1 ) & + ~MSPI_CDRAM_CONT_BIT ; +write_cdram_slot (qspi, slot -1 , mspi_cdram); + }
Let the core handle asserting and deasserting chip select.
drivers/spi/spi-bcm-qspi.c line 991
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+/* BSPI helpers */ +static int bcm_qspi_emulate_flash_read (struct bcm_qspi *qspi, +struct spi_device *spi,struct spi_transfer *t) +{ +u32 addr, len, len_words; +u8 *buf;
What is this doing? This seems very worrying...
drivers/spi/spi-bcm-qspi.c line 1113
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c new file +9
-0+if (trans && trans->len && trans->tx_buf) { +u8 command = ((u8 *)trans->tx_buf)[0 ]; + +if (trans->rx_nbits) + nbits = trans->rx_nbits; + +switch (command) { +case SPINOR_OP_READ4_FAST : +if (!bcm_qspi_is_4_byte_mode (qspi))
No, this is not a good idea. You should not be attempting to parse the data stream. If your controller has flash support it should implement the flash interfaces, otherwise it should just pass the data streams through.
drivers/spi/spi-bcm-qspi.c line 1229
Quoted 2 lines
drivers/spi/spi-bcm-qspi.c new file +2
-0+static int bcm_qspi_transfer_one_message (struct spi_master *master, +struct spi_message *msg)
Implement transfer_one(), not transfer_one_message().
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c new file +9
-0+static int bcm_qspi_simple_transaction (struct bcm_qspi *qspi, +const void *tx_buf,int tx_len,void *rx_buf,int rx_len) +{ + +struct bcm_qspi_parms *xp = &qspi->last_parms; +struct spi_message m; +struct spi_transfer t_tx, t_rx; +struct spi_device spi; +int ret;
drivers/spi/spi-bcm-qspi.c line 1438
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+ +memset (&spi,0 ,sizeof (spi)); + spi.max_speed_hz = xp->speed_hz; + spi.chip_select = xp->chip_select; + spi.mode = xp->mode; + spi.bits_per_word = xp->bits_per_word; + spi.master = qspi->master; + +spi_message_init (&m); + m.spi = &spi;
I don't know why your driver is creating and trying to do SPI transfers but that is completely inappropriate for a SPI controller. Whatever functionality this is implementing should be in a separate SPI device driver.
drivers/spi/spi-bcm-qspi.c line 1813
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static const struct of_device_id bcm_qspi_of_match[] = { + { .compatible ="brcm,spi-bcm-qspi" }, + { .compatible ="brcm,qspi-brcmstb" }, + { .compatible ="brcm,spi-brcmstb-mspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm_qspi_of_match);
This is adding new DT bindings but there is no documentation, documentation is required for all DT bindings.
drivers/spi/spi-bcm-qspi.c line 1819
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c new file +5
-0+static struct platform_driver bcm_qspi_driver = { + .driver = { + .name =DRIVER_NAME , + .bus = &platform_bus_type, + .owner =THIS_MODULE ,
You don't need to initalize bus or owner.
Quoted 1 line
+MODULE_AUTHOR("Broadcom");
This should be a person if it's going to be included.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Quoted 10 lines · Mark Brown
drivers/spi/spi-bcm-qspi.c line 1813
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static const struct of_device_id bcm_qspi_of_match[] = { + { .compatible ="brcm,spi-bcm-qspi" }, + { .compatible ="brcm,qspi-brcmstb" }, + { .compatible ="brcm,spi-brcmstb-mspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm_qspi_of_match);This is adding new DT bindings but there is no documentation, documentation is required for all DT bindings.
The binding documentation is added to patch 1, which you are listed as a recipient for.
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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Quoted 12 lines · Florian Fainelli
Quoted 10 lines · Mark Brown
drivers/spi/spi-bcm-qspi.c line 1813
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static const struct of_device_id bcm_qspi_of_match[] = { + { .compatible ="brcm,spi-bcm-qspi" }, + { .compatible ="brcm,qspi-brcmstb" }, + { .compatible ="brcm,spi-brcmstb-mspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm_qspi_of_match);This is adding new DT bindings but there is no documentation, documentation is required for all DT bindings.
Quoted 2 lines
The binding documentation is added to patch 1, which you are listed as a recipient for.
So this is a perfect example of why you should use standard formats for subject lines, if things don't look relevant they're likely to get missed. In this case it's both the prefix and the fact that the version is added in a weird way. Frankly I didn't even notice that it wasn't a cover letter.
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
In reply to a message not in the archiveMark,
My comments are inline.
Quoted 14 lines · Mark Brown
Quoted 12 lines · Kamal Dasu
drivers/spi/spi-bcm-qspi.c new file +12
-0+/* Read qspi controller register*/ +static inline u32 bcm_qspi_read (struct bcm_qspi *qspi,enum base_type type, +unsigned int offset) +{ +if (!qspi->base[type]) +return 0 ; + +/* +* MIPS endianness is configured by boot strap, which also reverses all +* bus endianness (i.e., big-endian CPU + big endian bus ==> native +* endian I/O). +*
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 289
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c new file +5
-0+* Other architectures (e.g., ARM) either do not support big endian, or +* else leave I/O in little endian mode. +*/ +if (IS_ENABLED (CONFIG_MIPS ) &&IS_ENABLED (CONFIG_CPU_BIG_ENDIAN )) +return __raw_readl (qspi->base[type] + offset);You shouldn't use raw accessors outside of arch code. Use
ioread32be()to read big endian values, and similarly for the writes.
Will fix this.
,
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!qspi->base[INTR]) + return;All these bits where we just silently ignore operations if some value isn't initialized are a bit worrying - why is this safe and robust? I'd expect chip feature selection to be done at a higher level.
The driver can work if interrupt controller driver is used, in that case the interrupt and status registers are handled by the controller driver. I can change to have this check at a higher level.
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c line 318
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+ +if (qspi->hif_spi_mode) +bcm_qspi_write (qspi,INTR ,HIF_SPI_INTR2_CPU_MASK_CLEAR , mask); +else {Coding style { } on both sides of the if if they're on one.
Will fix this.
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 447
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static void bcm_qspi_bspi_lr_data_read (struct bcm_qspi *qspi) +{ +u32 *buf = (u32 *)qspi->bspi_xfer->rx_buf; +u32 data =0 ; + +DBG ("xfer %p rx %p rxlen %d\n" , + qspi->bspi_xfer, qspi->bspi_xfer->rx_buf, qspi->bspi_xfer_len);Use the standard kernel trace infrastructure, don't invent your own.
Ok will do.
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+static int bcm_qspi_bspi_set_flex_mode (struct bcm_qspi *qspi,int width, +int addrlen,int hp) +{ +int bpc =0 , bpp =0 ; +u8 command =SPINOR_OP_READ_FAST ; +int flex_mode =1 , rv =0 ; +bool spans_4byte = false; + +DBG ("set flex mode w %x addrlen %x hp %d\n" , width, addrlen, hp); +
Quoted 8 lines
drivers/spi/spi-bcm-qspi.c line 498
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+if (addrlen ==BSPI_ADDRLEN_4BYTES ) { + bpp =BSPI_BPP_ADDR_SELECT_MASK ; + spans_4byte = true; + } + + bpp |=8 ;/* dummy cycles */ Dummy cycles?
We have a BSPI block that does address write and read in one shot stil uses the SPI. For reads we need to to setup the SoC controller BSPI_BITS_PER_PHASE register with the dummy clock cycles during reads.
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c line 538
Quoted 2 lines
drivers/spi/spi-bcm-qspi.c new file +2
-0+default : + rv =-1 ;Real error codes please.
Will return -EINVAL
Quoted 11 lines
drivers/spi/spi-bcm-qspi.c line 639
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c new file +9
-0+if (!error) { + qspi->xfer_mode.width = width; + qspi->xfer_mode.addrlen = addrlen; + qspi->xfer_mode.hp = hp; +dev_info (&qspi->pdev->dev, +"%d-lane output, %d-byte address%s\n" , + qspi->xfer_mode.width, + qspi->xfer_mode.addrlen, + qspi->xfer_mode.hp ?", high-performance mode" :"" );This is far too noisy, it's going to spam the logs on every transfer.
The caller only calls this on mode change as in as in 3/4 byte addressing or single, dual, quad io mode. Ideally for a given flash should only happen once during probe.
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c line 643
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+ }else +dev_warn (&qspi->pdev->dev, +"INVALID COMBINATION: width=%d addrlen=%d hp=%d\n" , + width, addrlen, hp);Why isn't this returning an error?
This should not occur, we operate in default 3 addr byte and single lane io mode. However I can return error in this case and handle it accordingly.
Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c new file +5
-0+static int bcm_qspi_update_parms (struct bcm_qspi *qspi, +struct spi_device *spidev, +struct spi_transfer *trans,int override) +{ +struct bcm_qspi_parms xp;
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 725
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+ + xp.speed_hz =min (trans->speed_hz ? trans->speed_hz : + (spidev->max_speed_hz ? spidev->max_speed_hz : + qspi->max_speed_hz), qspi->max_speed_hz);This is marginally legible, and you should just be able to trust what's in the transfer anyway as the core should be doing this - there's nothing device specific.
Will change this to use what is passed.
Quoted 11 lines
drivers/spi/spi-bcm-qspi.c line 740
Quoted 10 lines
drivers/spi/spi-bcm-qspi.c new file +10
-0+if ((override ==PARMS_OVERRIDE ) || + ((xp.speed_hz == qspi->last_parms.speed_hz) && + (xp.chip_select == qspi->last_parms.chip_select) && + (xp.mode == qspi->last_parms.mode) && + (xp.bits_per_word == qspi->last_parms.bits_per_word))) { +bcm_qspi_hw_set_parms (qspi, &xp); +return 0 ; + } +/* no override, and parms do not match */ +return 1 ;
Quoted 2 lines
What is an override
This code is not needed if I make the previous change as proposed.
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c line 788
Quoted 4 lines
drivers/spi/spi-bcm-qspi.c new file +4
-0+static int find_next_byte (struct bcm_qspi *qspi,struct position *p, +int flags) +{ +int ret =FNB_BREAK_NONE ;What is this supposed to be doing?
This one is advancing the data pointer (used for both MSPI rx and tx). Used for both RX and TX.
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 964
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+/* deassert CS on the final byte */ +if (fnb &FNB_BREAK_DESELECT ) { + mspi_cdram =read_cdram_slot (qspi, slot -1 ) & + ~MSPI_CDRAM_CONT_BIT ; +write_cdram_slot (qspi, slot -1 , mspi_cdram); + }Let the core handle asserting and deasserting chip select.
Its actually a peripheral CS (PCS) bit in the MSPI block. Peripheral chip selects are used to select an external device for serial data transfer. PCS[i] corresponds to pin SS[i].
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 991
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+/* BSPI helpers */ +static int bcm_qspi_emulate_flash_read (struct bcm_qspi *qspi, +struct spi_device *spi,struct spi_transfer *t) +{ +u32 addr, len, len_words; +u8 *buf;What is this doing? This seems very worrying...
Broadcom SoCs accelerates transfers by pairing both the address writes tx buf and the rx buf, sets up the transfer parameters and interrupts the driver till all the rx data bytes are received. For all other commands the data passes as is via the MSPI registers.
Quoted 6 lines
Quoted 6 lines
drivers/spi/spi-bcm-qspi.c new file +6
-0+if (trans && trans->len && trans->tx_buf) { +u8 command = ((u8 *)trans->tx_buf)[0 ]; + +if (trans->rx_nbits) + nbits = trans->rx_nbits; +
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 1113
Quoted 3 lines
drivers/spi/spi-bcm-qspi.c new file +3
-0+switch (command) { +case SPINOR_OP_READ4_FAST : +if (!bcm_qspi_is_4_byte_mode (qspi))No, this is not a good idea. You should not be attempting to parse the data stream. If your controller has flash support it should implement the flash interfaces, otherwise it should just pass the data streams through.
This is only for read command we need to setup both tx and rx at the same time for improved performance.
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c line 1229
Quoted 2 lines
drivers/spi/spi-bcm-qspi.c new file +2
-0+static int bcm_qspi_transfer_one_message (struct spi_master *master, +struct spi_message *msg)Implement
transfer_one(), nottransfer_one_message().
I need both the tx and rx transfers for read commands hence I implemented the transfer_one_message().
It is my understanding that transfer_one() gives me one transaction at a time. So for a read command I will get the tx buffer first and then rx buffer to fill. However I am trying to do a tx/rx in one shot with the Broadcom BSPI hw.
Quoted 16 lines
Quoted 16 lines
drivers/spi/spi-bcm-qspi.c new file +16
-0+static int bcm_qspi_simple_transaction (struct bcm_qspi *qspi, +const void *tx_buf,int tx_len,void *rx_buf,int rx_len) +{ + +struct bcm_qspi_parms *xp = &qspi->last_parms; +struct spi_message m; +struct spi_transfer t_tx, t_rx; +struct spi_device spi; +int ret; + +memset (&spi,0 ,sizeof (spi)); + spi.max_speed_hz = xp->speed_hz; + spi.chip_select = xp->chip_select; + spi.mode = xp->mode; + spi.bits_per_word = xp->bits_per_word; + spi.master = qspi->master;
Quoted 9 lines
drivers/spi/spi-bcm-qspi.c line 1438
Quoted 3 lines
drivers/spi/spi-bcm-qspi.c new file +3
-0+ +spi_message_init (&m); + m.spi = &spi;I don't know why your driver is creating and trying to do SPI transfers but that is completely inappropriate for a SPI controller. Whatever functionality this is implementing should be in a separate SPI device driver.
Currently not used. But I did not see a good way to be able to send commands, like finding the ID, setting 3/4 byte addressing mode , quad mode, on a PM resume(). Are you suggesting I make a driver similar to m25p80 ?.
Quoted 11 lines
drivers/spi/spi-bcm-qspi.c line 1813
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c new file +7
-0+static const struct of_device_id bcm_qspi_of_match[] = { + { .compatible ="brcm,spi-bcm-qspi" }, + { .compatible ="brcm,qspi-brcmstb" }, + { .compatible ="brcm,spi-brcmstb-mspi" }, + {}, +}; +MODULE_DEVICE_TABLE (of, bcm_qspi_of_match);This is adding new DT bindings but there is no documentation, documentation is required for all DT bindings.
This was part of Patch 1/4 as pointed to by Florian
Quoted 11 lines
drivers/spi/spi-bcm-qspi.c line 1819
Quoted 5 lines
drivers/spi/spi-bcm-qspi.c new file +5
-0+static struct platform_driver bcm_qspi_driver = { + .driver = { + .name =DRIVER_NAME , + .bus = &platform_bus_type, + .owner =THIS_MODULE ,You don't need to initalize bus or owner.
Quoted 1 line
+MODULE_AUTHOR("Broadcom");
This should be a person if it's going to be included.
I will fix the above.
---
Kamal Dasu
--
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
A message that is not in the archive (sent off-list or not yet received): CAKekbesr2i3N+yw0VV1aYqJONbBraKTNpibzm7NO_+sBbwENyw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Quoted 10 lines · Kamal Dasu
Quoted 8 lines · Mark Brown
Quoted 6 lines · Kamal Dasu
drivers/spi/spi-bcm-qspi.c new file +6
-0+/* deassert CS on the final byte */ +if (fnb &FNB_BREAK_DESELECT ) { + mspi_cdram =read_cdram_slot (qspi, slot -1 ) & + ~MSPI_CDRAM_CONT_BIT ; +write_cdram_slot (qspi, slot -1 , mspi_cdram); + }
Quoted 5 lines
Quoted 1 line
Let the core handle asserting and deasserting chip select.
Its actually a peripheral CS (PCS) bit in the MSPI block. Peripheral chip selects are used to select an external device for serial data transfer. PCS[i] corresponds to pin SS[i].
That doesn't appear to address the issue, what you're describing sounds like the normal function of the chip select?
Quoted 11 lines
Quoted 8 lines
drivers/spi/spi-bcm-qspi.c line 1113
Quoted 3 lines
drivers/spi/spi-bcm-qspi.c new file +3
-0+switch (command) { +case SPINOR_OP_READ4_FAST : +if (!bcm_qspi_is_4_byte_mode (qspi))No, this is not a good idea. You should not be attempting to parse the data stream. If your controller has flash support it should implement the flash interfaces, otherwise it should just pass the data streams through.
This is only for read command we need to setup both tx and rx at the same time for improved performance.
No, to repeat what I said if you want to support accelerated flash reads implement the standard accelerated flash read operation we have (spi_flash_read()). This is a fairly common feature and trying to open code this in individual drivers would at the very least lead to a lot of duplicated code and is the source of most of the problems in the code.
Quoted 8 lines
Quoted 7 lines
drivers/spi/spi-bcm-qspi.c line 1438
Quoted 2 lines
drivers/spi/spi-bcm-qspi.c new file +2
-0+spi_message_init (&m); + m.spi = &spi;I don't know why your driver is creating and trying to do SPI transfers but that is completely inappropriate for a SPI controller. Whatever functionality this is implementing should be in a separate SPI device driver.
Quoted 4 lines
Currently not used. But I did not see a good way to be able to send commands, like finding the ID, setting 3/4 byte addressing mode , quad mode, on a PM
resume(). Are you suggesting I make a driver similar to m25p80 ?.
I am suggesting you implement the standard flash interfaces and as a result directly use m25p80.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
+MODULE_DEVICE_TABLE(of,
bcm_qspi_of_match);This is adding new DT bindings but there is no documentation, documentation is required for all DT bindings.
This was part of Patch 1/4 as pointed to by Florian
Please use standard formatting when posting patches.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Mark,
I have implemented most of your suggestions. A few of them, actually just a couple, I wanted to discuss further. More importantly related to the spi_flash_read(). Please see my questions inline.
Quoted 11 lines · Mark Brown
Quoted 9 lines · Kamal Dasu
Quoted 8 lines · Mark Brown
Quoted 6 lines · Kamal Dasu
(quoted diff) +6
-0+ /* deassert CS on the final byte */ + if (fnb & FNB_BREAK_DESELECT) { + mspi_cdram = read_cdram_slot(qspi, slot - 1) & + ~MSPI_CDRAM_CONT_BIT; + write_cdram_slot(qspi, slot - 1, mspi_cdram); + }
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Let the core handle asserting and deasserting chip select.
Its actually a peripheral CS (PCS) bit in the MSPI block. Peripheral chip selects are used to select an external device for serial data transfer. PCS[i] corresponds to pin SS[i].
That doesn't appear to address the issue, what you're describing sounds like the normal function of the chip select?
This bit has no effect and is not connected actually although software is manipulating it. The real CS is the one we use via the dt cs_reg. I will fix the comments/code to reflect this accordingly.
Quoted 10 lines
Quoted 9 lines
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+ switch (command) { + case SPINOR_OP_READ4_FAST: + if (!bcm_qspi_is_4_byte_mode(qspi))No, this is not a good idea. You should not be attempting to parse the data stream. If your controller has flash support it should implement the flash interfaces, otherwise it should just pass the data streams through.
Quoted 8 lines
Quoted 2 lines
This is only for read command we need to setup both tx and rx at the same time for improved performance.
No, to repeat what I said if you want to support accelerated flash reads implement the standard accelerated flash read operation we have (
spi_flash_read()). This is a fairly common feature and trying to open code this in individual drivers would at the very least lead to a lot of duplicated code and is the source of most of the problems in the code.
I was looking at spi_flash_read() caled from m25p80_read() and spi core implementation. I have a case where when we have very small reads or unaligned buffers and addresses passed then I have to fall back to using standard MSPI reads. How best to handle this ?. One of the options without having to replicate code involves a minor change to m25p80 driver as shown below.
---
drivers/mtd/devices/m25p80.c +0 -0
@@ -149,8 +149,11 @@ static int m25p80_read(struct spi_nor *nor,
loff_t from, size_t len,
msg.data_nbits = m25p80_rx_nbits(nor);
ret = spi_flash_read(spi, &msg);
- *retlen = msg.retlen;
- return ret;
+ /* check we need to fallback to normal spi read */
+ if (ret != -EAGAIN) {
+ *retlen = msg.retlen;
+ return ret;
+ }
}
spi_message_init(&m);---
I am open to any other suggestion that I can implement in my driver. In the previous version of using transfer_one_message() I could fallback in such cases.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ spi_message_init(&m); + m.spi = &spi;I don't know why your driver is creating and trying to do SPI transfers but that is completely inappropriate for a SPI controller. Whatever functionality this is implementing should be in a separate SPI device driver.
Quoted 7 lines
Quoted 4 lines
Currently not used. But I did not see a good way to be able to send commands, like finding the ID, setting 3/4 byte addressing mode , quad mode, on a PM
resume(). Are you suggesting I make a driver similar to m25p80 ?.I am suggesting you implement the standard flash interfaces and as a result directly use m25p80.
Are you suggesting to use something like spi_read_then_write() in cases where I want to set the addressing and single/quad modes ?.
Thanks
Kamal
--
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
A message that is not in the archive (sent off-list or not yet received): CAKekbesG+_9wOuP4HXGKJdK-kmEn443g=vUdyu6Zdn==NO-YHw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Re: [V3, 2/4] spi: bcm-qspi: Add SPI flash and MSPI driver
Quoted 6 lines · Kamal Dasu
I was looking at
spi_flash_read()caled fromm25p80_read()and spi core implementation. I have a case where when we have very small reads or unaligned buffers and addresses passed then I have to fall back to using standard MSPI reads. How best to handle this ?. One of the options without having to replicate code involves a minor change to m25p80 driver as shown below.
That looks reasonable. Another option might be to provide a way for m25p80 to discover the constraints itself.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Currently not used. But I did not see a good way to be able to send commands, like finding the ID, setting 3/4 byte addressing mode , quad mode, on a PM
resume(). Are you suggesting I make a driver similar to m25p80 ?.I am suggesting you implement the standard flash interfaces and as a result directly use m25p80.
Are you suggesting to use something like
spi_read_then_write()in cases where I want to set the addressing and single/quad modes ?.
Or an explicit series of transfers.
PATCH v3 3/4 arm: dts: Add bcm-nsp and bcm958625k support
In reply to a message not in the archiveAdding qspi node compatible with the new spi-bcm-qspi driver for the broadcom's northstar SoCwq.
---
V3 chnage fixes checkpatch errors and warnings
V2 no change
--- arch/arm/boot/dts/bcm-nsp.dtsi | 30 ++++++++++++++++++++++++++++++ arch/arm/boot/dts/bcm958625k.dts | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+)
arch/arm/boot/dts/bcm-nsp.dtsi +30 -0
@@ -206,6 +206,36 @@ brcm,nand-has-wp; }; + qspi: qspi@27200 { + compatible = "brcm,spi-bcm-qspi"; + reg = <0x027200 0x184>, + <0x027000 0x124>, + <0x11c408 0x004>, + <0x0273a0 0x01c>; + reg-names = "mspi", "bspi", "intr_regs", + "intr_status_reg"; + interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>, + <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "spi_lr_fullness_reached", + "spi_lr_session_aborted", + "spi_lr_impatient", + "spi_lr_session_done", + "spi_lr_overhead", + "mspi_done", + "mspi_halted"; + clocks = <&iprocmed>; + clock-names = "iprocmed"; + clock-frequency = <12500000>; + num-cs = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + ccbtimer0: timer@34000 { compatible = "arm,sp804"; reg = <0x34000 0x1000>;
arch/arm/boot/dts/bcm958625k.dts +34 -0
@@ -114,3 +114,37 @@ groups = "nand_grp"; }; }; + +&qspi { + bspi-sel = <0>; + flash: m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "m25p80"; + reg = <0x0>; + spi-max-frequency = <12500000>; + m25p,fast-read; + spi-cpol; + spi-cpha; + + partition@0 { + label = "boot"; + reg = <0x00000000 0x000a0000>; + }; + + partition@1 { + label = "env"; + reg = <0x000a0000 0x00060000>; + }; + + partition@2 { + label = "system"; + reg = <0x00100000 0x00600000>; + }; + + partition@3 { + label = "rootfs"; + reg = <0x00700000 0x01900000>; + }; + }; +};
Signature · 6 lines
1.9.1 -- 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
PATCH v3 4/4 arm64: dts: Add ns2 SoC support
In reply to a message not in the archiveAdding qspi node compatible with the new spi-bcm-qspi driver for the broadcom's northstar2 SoC.
---
V3 chnage fixes checkpatch errors and warnings
V2 no change
--- arch/arm64/boot/dts/broadcom/ns2-svk.dts | 34 ++++++++++++++++++++++++++++++++ arch/arm64/boot/dts/broadcom/ns2.dtsi | 19 ++++++++++++++++++ 2 files changed, 53 insertions(+)
arch/arm64/boot/dts/broadcom/ns2-svk.dts +34 -0
@@ -132,3 +132,37 @@ #size-cells = <1>; }; }; + +&qspi { + bspi-sel = <0>; + flash: m25p80@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "m25p80"; + reg = <0x0>; + spi-max-frequency = <12500000>; + m25p,fast-read; + spi-cpol; + spi-cpha; + + partition@0 { + label = "boot"; + reg = <0x00000000 0x000a0000>; + }; + + partition@1 { + label = "env"; + reg = <0x000a0000 0x00060000>; + }; + + partition@2 { + label = "system"; + reg = <0x00100000 0x00600000>; + }; + + partition@3 { + label = "rootfs"; + reg = <0x00700000 0x01900000>; + }; + }; +};
arch/arm64/boot/dts/broadcom/ns2.dtsi +19 -0
@@ -399,5 +399,24 @@ brcm,nand-has-wp; }; + + qspi: spi@66470200 { + compatible = "brcm,spi-bcm-qspi"; + reg = <0x66470200 0x184>, + <0x66470000 0x124>, + <0x67017408 0x004>, + <0x664703a0 0x01c>; + reg-names = "mspi", "bspi", "intr_regs", + "intr_status_reg"; + interrupts = <GIC_SPI 419 IRQ_TYPE_LEVEL_HIGH>; + interrupt-names = "spi_l1_intr"; + clocks = <&iprocmed>; + clock-names = "iprocmed"; + clock-frequency = <12500000>; + num-cs = <2>; + #address-cells = <1>; + #size-cells = <0>; + }; + }; };
Signature · 6 lines
1.9.1 -- 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