spi-geni-qcom: QUP SPI GENI driver and SPI device tree bindings
Subsystems (4)
v5 cover spi-geni-qcom: QUP SPI GENI driver and SPI device tree bindings
This patch series adds the driver for GENI based Qualcomm Universal Peripheral (QUP) Serial Peripheral Interface (SPI) and SPI device tree bindings.
An overview of the GENI SE SPI controller device tree components are in patch 2 and 1. Patch 3 adds the SPI driver for GENI QUP HW.
changes from v4:
- Patch 1/3 and 2/3 are unchanged
- squashed patch 4/4 into 3/4 as suggested
- Patch 3/3 changes are follows:
* Add SPI M_COMMAND OPCODE to handle different geni command handling
* Remove forward declaration of ISR
* Remove unused variable rx_fifo_depth in spi_master structure
* Declare cur_speed_hz as unsigned long to match clock framework
* Declare cur_xfer as const pointer
* Newline in error print
* Correct consecutive spelling
* Rename trans_len to len and restructure the lines in setup_fifo_xfer()
* Rename timeout to time_left and restructure the handle_fifo_timeout()
* Add check for '0' bytes transfer as part of spi_geni_transfer_one()
* Correct if-else check in geni_byte_per_fifo_word()
* Remove NULL current transfer check in geni_spi_handle_tx()/geni_spi_handle_rx() and make these functions as void.
* Hoist rx_last_byte_valid variable into function scope
* Remove RT check in ISR and add cur_mcmd handling
* Correct the error prints in ISR
* In spi_alloc_master() pass 2nd arg as sizeof(*mas) for code clarity
* Use ret = PTR_ERR(se->base) for devm_ioremap_resource() err return
* Move request irq code to probe() and used request_irq() in place of devm_request_irq()
* Rewrite suspend/resume function
* Add MODULE_DEVICE_TABLE(of, spi_geni_dt_match);
* Remove include/linux/spi/spi-geni-qcom.h file
Dilip Kota (2):
dt-bindings: soc: qcom: Remove SPI controller maximum frequency
binding
dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
Girish Mahadevan (1):
spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
.../devicetree/bindings/soc/qcom/qcom,geni-se.txt | 29 +- .../devicetree/bindings/spi/qcom,spi-geni-qcom.txt | 39 ++ drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-geni-qcom.c | 703 +++++++++++++++++++++ 5 files changed, 757 insertions(+), 27 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.txt create mode 100644 drivers/spi/spi-geni-qcom.c
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 1/3 dt-bindings: soc: qcom: Remove SPI controller maximum frequency binding
From: Dilip Kota <[email protected]>
SPI controller driver should maintain the maximum frequency of the controller instead of relying on device tree bindings. Because maximum frequency is specific property of SPI controller.
--- Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt | 2 -- 1 file changed, 2 deletions(-)
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt +0 -2
@@ -60,7 +60,6 @@ Required properties: - interrupts: Must contain SPI controller interrupts. - clock-names: Must contain "se". - clocks: Serial engine core clock needed by the device. -- spi-max-frequency: Specifies maximum SPI clock frequency, units - Hz. - #address-cells: Must be <1> to define a chip select address on the SPI bus. - #size-cells: Must be <0>.
@@ -112,7 +111,6 @@ Example: pinctrl-names = "default", "sleep"; pinctrl-0 = <&qup_1_spi_2_active>; pinctrl-1 = <&qup_1_spi_2_sleep>; - spi-max-frequency = <19200000>; #address-cells = <1>; #size-cells = <0>; };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 2/3 dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
In reply to Alok ChauhanFrom: Dilip Kota <[email protected]>
Move GENI SE SPI controller device-tree bindings from devicetree/bindings/soc/qcom/qcom,geni-se.txt to devicetree/bindings/spi/qcom,spi-geni-qcom.txt.
--- .../devicetree/bindings/soc/qcom/qcom,geni-se.txt | 27 ++------------- .../devicetree/bindings/spi/qcom,spi-geni-qcom.txt | 39 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 25 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.txt
Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt +2 -25
@@ -53,19 +53,8 @@ Required properties: - clocks: Serial engine core clock needed by the device. Qualcomm Technologies Inc. GENI Serial Engine based SPI Controller - -Required properties: -- compatible: Must contain "qcom,geni-spi". -- reg: Must contain SPI register location and length. -- interrupts: Must contain SPI controller interrupts. -- clock-names: Must contain "se". -- clocks: Serial engine core clock needed by the device. -- #address-cells: Must be <1> to define a chip select address on - the SPI bus. -- #size-cells: Must be <0>. - -SPI slave nodes must be children of the SPI master node and conform to SPI bus -binding as described in Documentation/devicetree/bindings/spi/spi-bus.txt. +node binding is described in +Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.txt. Example: geniqup@8c0000 {
@@ -102,16 +91,4 @@ Example: pinctrl-1 = <&qup_1_uart_3_sleep>; }; - spi0: spi@a84000 { - compatible = "qcom,geni-spi"; - reg = <0xa84000 0x4000>; - interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>; - clock-names = "se"; - clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>; - pinctrl-names = "default", "sleep"; - pinctrl-0 = <&qup_1_spi_2_active>; - pinctrl-1 = <&qup_1_spi_2_sleep>; - #address-cells = <1>; - #size-cells = <0>; - }; }
Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.txt new file +39 -0
@@ -0,0 +1,39 @@ +GENI based Qualcomm Universal Peripheral (QUP) Serial Peripheral Interface (SPI) + +The QUP v3 core is a GENI based AHB slave that provides a common data path +(an output FIFO and an input FIFO) for serial peripheral interface (SPI) +mini-core. + +SPI in master mode supports up to 50MHz, up to four chip selects, programmable +data path from 4 bits to 32 bits and numerous protocol variants. + +Required properties: +- compatible: Must contain "qcom,geni-spi". +- reg: Must contain SPI register location and length. +- interrupts: Must contain SPI controller interrupts. +- clock-names: Must contain "se". +- clocks: Serial engine core clock needed by the device. +- #address-cells: Must be <1> to define a chip select address on + the SPI bus. +- #size-cells: Must be <0>. + +SPI Controller nodes must be child of GENI based Qualcomm Universal +Peripharal. Please refer GENI based QUP wrapper controller node bindings +described in Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt. + +SPI slave nodes must be children of the SPI master node and conform to SPI bus +binding as described in Documentation/devicetree/bindings/spi/spi-bus.txt. + +Example: + spi0: spi@a84000 { + compatible = "qcom,geni-spi"; + reg = <0xa84000 0x4000>; + interrupts = <GIC_SPI 354 IRQ_TYPE_LEVEL_HIGH>; + clock-names = "se"; + clocks = <&clock_gcc GCC_QUPV3_WRAP0_S0_CLK>; + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&qup_1_spi_2_active>; + pinctrl-1 = <&qup_1_spi_2_sleep>; + #address-cells = <1>; + #size-cells = <0>; + };
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v5 3/3 spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Alok ChauhanFrom: Girish Mahadevan <[email protected]>
This driver supports GENI based SPI Controller in the Qualcomm SOCs. The Qualcomm Generic Interface (GENI) is a programmable module supporting a wide range of serial interfaces including SPI. This driver supports SPI operations using FIFO mode of transfer.
--- drivers/spi/Kconfig | 12 + drivers/spi/Makefile | 1 + drivers/spi/spi-geni-qcom.c | 703 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 716 insertions(+) create mode 100644 drivers/spi/spi-geni-qcom.c
drivers/spi/Kconfig +12 -0
@@ -533,6 +533,18 @@ config SPI_QUP This driver can also be built as a module. If so, the module will be called spi_qup. +config SPI_QCOM_GENI + tristate "Qualcomm GENI based SPI controller" + depends on QCOM_GENI_SE + help + This driver supports GENI serial engine based SPI controller in + master mode on the Qualcomm Technologies Inc.'s SoCs. If you say + yes to this option, support will be included for the built-in SPI + interface on the Qualcomm Technologies Inc.'s SoCs. + + This driver can also be built as a module. If so, the module + will be called spi-geni-qcom. + config SPI_S3C24XX tristate "Samsung S3C24XX series SPI" depends on ARCH_S3C24XX
drivers/spi/Makefile +1 -0
@@ -74,6 +74,7 @@ obj-$(CONFIG_SPI_PPC4xx) += spi-ppc4xx.o spi-pxa2xx-platform-objs := spi-pxa2xx.o spi-pxa2xx-dma.o obj-$(CONFIG_SPI_PXA2XX) += spi-pxa2xx-platform.o obj-$(CONFIG_SPI_PXA2XX_PCI) += spi-pxa2xx-pci.o +obj-$(CONFIG_SPI_QCOM_GENI) += spi-geni-qcom.o obj-$(CONFIG_SPI_QUP) += spi-qup.o obj-$(CONFIG_SPI_ROCKCHIP) += spi-rockchip.o obj-$(CONFIG_SPI_RB4XX) += spi-rb4xx.o
drivers/spi/spi-geni-qcom.c new file +703 -0
703 lines not on this page · raw message
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 46 lines · Alok Chauhan
drivers/spi/spi-geni-qcom.c new file +46
-0+static irqreturn_t geni_spi_isr (int irq,void *data) +{ +struct spi_master *spi = data; +struct spi_geni_master *mas =spi_master_get_devdata (spi); +struct geni_se *se = &mas->se; +u32 m_irq; +unsigned long flags; +irqreturn_t ret =IRQ_HANDLED ; + +if (mas->cur_mcmd ==CMD_NONE ) +return IRQ_NONE ; + +spin_lock_irqsave (&mas->lock, flags); + m_irq =readl (se->base +SE_GENI_M_IRQ_STATUS ); + +if ((m_irq &M_RX_FIFO_WATERMARK_EN ) || (m_irq &M_RX_FIFO_LAST_EN )) +geni_spi_handle_rx (mas); + +if (m_irq &M_TX_FIFO_WATERMARK_EN ) +geni_spi_handle_tx (mas); + +if (m_irq &M_CMD_DONE_EN ) { +if (mas->cur_mcmd ==CMD_XFER ) +spi_finalize_current_transfer (spi); +else if (mas->cur_mcmd ==CMD_CS ) +complete (&mas->xfer_done); + mas->cur_mcmd =CMD_NONE ; +/* +* If this happens, then a CMD_DONE came before all the Tx +* buffer bytes were sent out. This is unusual, log this +* condition and disable the WM interrupt to prevent the +* system from stalling due an interrupt storm. +* If this happens when all Rx bytes haven't been received, log +* the condition. +* The only known time this can happen is if bits_per_word != 8 +* and some registers that expect xfer lengths in num spi_words +* weren't written correctly. +*/ +if (mas->tx_rem_bytes) { +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); +dev_err (mas->dev,"Premature done. tx_rem = %d bpw%d\n" , + mas->tx_rem_bytes, mas->cur_bits_per_word); + } +if (mas->rx_rem_bytes) +dev_err (mas->dev,"Premature done. rx_rem = %d bpw%d\n" , + mas->rx_rem_bytes, mas->cur_bits_per_word);
drivers/spi/spi-geni-qcom.c line 536
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+ } + +if ((m_irq &M_CMD_CANCEL_EN ) || (m_irq &M_CMD_ABORT_EN )) { + mas->cur_mcmd =CMD_NONE ; +complete (&mas->xfer_done); + } + +writel (m_irq, se->base +SE_GENI_M_IRQ_CLEAR ); +spin_unlock_irqrestore (&mas->lock, flags); +return ret;
nit: you no longer need the "ret" variable. Just return IRQ_HANDLED here and remove the "ret" local variable from this function. It'd be nice if you put a blank line before the return too.
I'm not convinced it's worth spinning the patch to fix that one nit, but if you spin it for some other reason please fix it. I believe this fixes all outstanding feedback that I'm aware of. Thus:
-Doug
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Alok ChauhanQuoting Alok Chauhan (2018-10-03 06:44:25)
Quoted 1 line
I just have a handful of nitpicks which can be fixed later in follow-ups. Otherwise:
Quoted 9 lines
drivers/spi/spi-geni-qcom.c new file +3
-0@@ -0,0 +1,703 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017-2018, The Linux foundation. All rights reserved. +
[...]
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+#define SPI_TX_ONLY 1 +#define SPI_RX_ONLY 2 +#define SPI_FULL_DUPLEX 3 +#define SPI_TX_RX 7 +#define SPI_CS_ASSERT 8 +#define SPI_CS_DEASSERT 9
drivers/spi/spi-geni-qcom.c line 68
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+#define SPI_SCK_ONLY 10 +/* M_CMD params for SPI */ +#define SPI_PRE_CMD_DELAY BIT(0) +#define TIMESTAMP_BEFORE BIT(1) +#define FRAGMENTATION BIT(2) +#define TIMESTAMP_AFTER BIT(3) +#define POST_CMD_DELAY BIT(4) + +/* SPI M_COMMAND OPCODE */ +enum spi_mcmd_code {
Nitpick: rename spi_m_cmd_opcode and drop the comment?
drivers/spi/spi-geni-qcom.c line 75
Quoted 7 lines
drivers/spi/spi-geni-qcom.c new file +7
-0+CMD_NONE , +CMD_XFER , +CMD_CS , + CMD_CANCEL, +}; + +
Nitpick: Drop double newline.
Quoted 5 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+struct spi_geni_master { +struct geni_se se; +struct device *dev; +u32 tx_fifo_depth; +u32 fifo_width_bits;
drivers/spi/spi-geni-qcom.c line 90
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+u32 tx_wm; +unsigned long cur_speed_hz; +unsigned int cur_bits_per_word; +unsigned int tx_rem_bytes; +unsigned int rx_rem_bytes; +const struct spi_transfer *cur_xfer; +struct completion xfer_done; +unsigned int oversampling; +spinlock_t lock; +unsigned int cur_mcmd;
Niptick: Use the enum?
Quoted 45 lines
drivers/spi/spi-geni-qcom.c new file +45
-0+int irq; +}; + +static void handle_fifo_timeout (struct spi_master *spi, +struct spi_message *msg); + +static int get_spi_clk_cfg (unsigned int speed_hz, +struct spi_geni_master *mas, +unsigned int *clk_idx, +unsigned int *clk_div) +{ +unsigned long sclk_freq; +unsigned int actual_hz; +struct geni_se *se = &mas->se; +int ret; + + ret =geni_se_clk_freq_match (&mas->se, + speed_hz * mas->oversampling, + clk_idx, &sclk_freq, false); +if (ret) { +dev_err (mas->dev,"Failed(%d) to find src clk for %dHz\n" , + ret, speed_hz); +return ret; + } + + *clk_div =DIV_ROUND_UP (sclk_freq, mas->oversampling * speed_hz); + actual_hz = sclk_freq / (mas->oversampling * *clk_div); + +dev_dbg (mas->dev,"req %u=>%u sclk %lu, idx %d, div %d\n" , speed_hz, + actual_hz, sclk_freq, *clk_idx, *clk_div); + ret =clk_set_rate (se->clk, sclk_freq); +if (ret) +dev_err (mas->dev,"clk_set_rate failed %d\n" , ret); +return ret; +} + +static void spi_geni_set_cs (struct spi_device *slv,bool set_flag) +{ +struct spi_geni_master *mas =spi_master_get_devdata (slv->master); +struct spi_master *spi =dev_get_drvdata (mas->dev); +struct geni_se *se = &mas->se; +unsigned long timeout; + +reinit_completion (&mas->xfer_done); +pm_runtime_get_sync (mas->dev);
drivers/spi/spi-geni-qcom.c line 145
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+if (!(slv->mode &SPI_CS_HIGH )) + set_flag = !set_flag; + + mas->cur_mcmd =CMD_CS ; +if (set_flag) +geni_se_setup_m_cmd (se,SPI_CS_ASSERT ,0 ); +else +geni_se_setup_m_cmd (se,SPI_CS_DEASSERT ,0 ); + + timeout =wait_for_completion_timeout (&mas->xfer_done,HZ );
Nitpick: s/timeout/time_left/
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+if (!timeout) +handle_fifo_timeout (spi,NULL ); + +pm_runtime_put (mas->dev); +} +
[...]
Quoted 47 lines
drivers/spi/spi-geni-qcom.c new file +47
-0+ +static irqreturn_t geni_spi_isr (int irq,void *data) +{ +struct spi_master *spi = data; +struct spi_geni_master *mas =spi_master_get_devdata (spi); +struct geni_se *se = &mas->se; +u32 m_irq; +unsigned long flags; +irqreturn_t ret =IRQ_HANDLED ; + +if (mas->cur_mcmd ==CMD_NONE ) +return IRQ_NONE ; + +spin_lock_irqsave (&mas->lock, flags); + m_irq =readl (se->base +SE_GENI_M_IRQ_STATUS ); + +if ((m_irq &M_RX_FIFO_WATERMARK_EN ) || (m_irq &M_RX_FIFO_LAST_EN )) +geni_spi_handle_rx (mas); + +if (m_irq &M_TX_FIFO_WATERMARK_EN ) +geni_spi_handle_tx (mas); + +if (m_irq &M_CMD_DONE_EN ) { +if (mas->cur_mcmd ==CMD_XFER ) +spi_finalize_current_transfer (spi); +else if (mas->cur_mcmd ==CMD_CS ) +complete (&mas->xfer_done); + mas->cur_mcmd =CMD_NONE ; +/* +* If this happens, then a CMD_DONE came before all the Tx +* buffer bytes were sent out. This is unusual, log this +* condition and disable the WM interrupt to prevent the +* system from stalling due an interrupt storm. +* If this happens when all Rx bytes haven't been received, log +* the condition. +* The only known time this can happen is if bits_per_word != 8 +* and some registers that expect xfer lengths in num spi_words +* weren't written correctly. +*/ +if (mas->tx_rem_bytes) { +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); +dev_err (mas->dev,"Premature done. tx_rem = %d bpw%d\n" , + mas->tx_rem_bytes, mas->cur_bits_per_word); + } +if (mas->rx_rem_bytes) +dev_err (mas->dev,"Premature done. rx_rem = %d bpw%d\n" , + mas->rx_rem_bytes, mas->cur_bits_per_word);
drivers/spi/spi-geni-qcom.c line 536
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+ } + +if ((m_irq &M_CMD_CANCEL_EN ) || (m_irq &M_CMD_ABORT_EN )) { + mas->cur_mcmd =CMD_NONE ; +complete (&mas->xfer_done); + } + +writel (m_irq, se->base +SE_GENI_M_IRQ_CLEAR ); +spin_unlock_irqrestore (&mas->lock, flags); +return ret;
Nitpick: Now this always returns IRQ_HANDLED, and we assign ret just to do that. Perhaps only return IRQ_HANDLED if one of the above if conditions is taken?
Quoted 51 lines
drivers/spi/spi-geni-qcom.c new file +51
-0+} + +static int spi_geni_probe (struct platform_device *pdev) +{ +int ret; +struct spi_master *spi; +struct spi_geni_master *mas; +struct resource *res; +struct geni_se *se; + + spi =spi_alloc_master (&pdev->dev,sizeof (*mas)); +if (!spi) +return -ENOMEM ; + +platform_set_drvdata (pdev, spi); + mas =spi_master_get_devdata (spi); + mas->dev = &pdev->dev; + mas->se.dev = &pdev->dev; + mas->se.wrapper =dev_get_drvdata (pdev->dev.parent); + se = &mas->se; + + spi->bus_num =-1 ; + spi->dev.of_node = pdev->dev.of_node; + mas->se.clk =devm_clk_get (&pdev->dev,"se" ); +if (IS_ERR (mas->se.clk)) { + ret =PTR_ERR (mas->se.clk); +dev_err (&pdev->dev,"Err getting SE Core clk %d\n" , ret); + goto spi_geni_probe_err; + } + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + se->base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (se->base)) { + ret =PTR_ERR (se->base); + goto spi_geni_probe_err; + } + + spi->mode_bits =SPI_CPOL |SPI_CPHA |SPI_LOOP |SPI_CS_HIGH ; + spi->bits_per_word_mask =SPI_BPW_RANGE_MASK (4 ,32 ); + spi->num_chipselect =4 ; + spi->max_speed_hz =50000000 ; + spi->prepare_message = spi_geni_prepare_message; + spi->transfer_one = spi_geni_transfer_one; + spi->auto_runtime_pm = true; + spi->handle_err = handle_fifo_timeout; + spi->set_cs = spi_geni_set_cs; + +init_completion (&mas->xfer_done); +spin_lock_init (&mas->lock); +pm_runtime_enable (&pdev->dev); +
drivers/spi/spi-geni-qcom.c line 597
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+ ret =spi_geni_init (mas); +if (ret) + goto spi_geni_probe_runtime_disable; + + mas->irq =platform_get_irq (pdev,0 ); +if (mas->irq <0 ) { + ret = mas->irq; +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_runtime_disable; + }
Nitpick: If you got the irq earlier before allocating anything then nothing has to be put on failure path.
Quoted 19 lines
drivers/spi/spi-geni-qcom.c new file +19
-0+ + ret =request_irq (mas->irq, geni_spi_isr, +IRQF_TRIGGER_HIGH ,"spi_geni" , spi); +if (ret) + goto spi_geni_probe_runtime_disable; + + ret =spi_register_master (spi); +if (ret) + goto spi_geni_probe_free_irq; + +return 0 ; +spi_geni_probe_free_irq: +free_irq (mas->irq, spi); +spi_geni_probe_runtime_disable: +pm_runtime_disable (&pdev->dev); +spi_geni_probe_err: +spi_master_put (spi); +return ret; +}
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 9 lines · Stephen Boyd
drivers/spi/spi-geni-qcom.c line 597
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+ mas->irq =platform_get_irq (pdev,0 ); +if (mas->irq <0 ) { + ret = mas->irq; +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_runtime_disable; + }Nitpick: If you got the irq earlier before allocating anything then nothing has to be put on failure path.
I think this might have been in response to previous feedback from you suggesting that we should get the irq as late as possible. Ah, here ya go:
https://lkml.kernel.org/r/153780767551.119890.9339380838620508307@swboyd.mtv.corp.google.com
Quoted 4 lines
Can you request this irq as late as possible in the probe function? I worry there may be some pending irq line set and then this will cause an interrupt storm with
IRQ_NONEreturned because the device is runtime suspended.
I'd rather handle the failure path then get the IRQ too early.
-Doug
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Quoting Doug Anderson (2018-10-08 16:52:36)
Quoted 10 lines
Hi,
Quoted 7 lines · Stephen Boyd
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+ mas->irq =platform_get_irq (pdev,0 ); +if (mas->irq <0 ) { + ret = mas->irq; +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_runtime_disable; + }
Quoted 8 lines
Quoted 2 lines
Nitpick: If you got the irq earlier before allocating anything then nothing has to be put on failure path.
I think this might have been in response to previous feedback from you suggesting that we should get the irq as late as possible. Ah, here ya go:
https://lkml.kernel.org/r/153780767551.119890.9339380838620508307@swboyd.mtv.corp.google.com
Yes I suggested we register for the irq as last as possible, but I didn't suggest calling platform_get_irq() this late. It could be called earlier so that if there isn't any irq then nothing to do besides return failure.
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 19 lines · Stephen Boyd
Quoting Doug Anderson (2018-10-08 16:52:36)
Quoted 17 lines
Hi,
Quoted 9 lines · Stephen Boyd
drivers/spi/spi-geni-qcom.c line 597
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+ mas->irq =platform_get_irq (pdev,0 ); +if (mas->irq <0 ) { + ret = mas->irq; +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_runtime_disable; + }Nitpick: If you got the irq earlier before allocating anything then nothing has to be put on failure path.
I think this might have been in response to previous feedback from you suggesting that we should get the irq as late as possible. Ah, here ya go:
Quoted 6 lines
Quoted 1 line
https://lkml.kernel.org/r/153780767551.119890.9339380838620508307@swboyd.mtv.corp.google.com
Yes I suggested we register for the irq as last as possible, but I didn't suggest calling
platform_get_irq()this late. It could be called earlier so that if there isn't any irq then nothing to do besides return failure.
Ah, you're suggesting separating the platform_get_irq() and the request_irq() so that we call platform_get_irq() as the first thing in the function but don't do the request_irq() until later. Yeah, that could be done and I guess if you feel strongly about it I wouldn't object to the change, but I don't feel it buys us a lot and I kind of like keeping the two next to each other. Specifically why I don't think it buys us a lot:
1. You still need the "dev_err" print, right? platform_get_irq() doesn't automatically print errors for you I think.
2. You now need a local variable "irq". By putting the platform_get_irq() before the memory allocation you now can't store it directly in mas->irq. We could try using "ret" as a temporary variable but that seems worse in this case since it'd be a bit fragile.
3. You don't get rid of any error labels / error handling so we don't really save any code
When I tried this my diffstat says 8 lines added and 7 removed, so a net increase in LOC FWIW. I'm relying in gmail so my patch will be whitespace-damaged (sigh), but you can find a clean one at:
...the basic idea is this though:
@@ -543,6 +543,13 @@
struct spi_geni_master *mas;
struct resource *res;
struct geni_se *se;
+ int irq;
+
+ irq = platform_get_irq(pdev, 0);
+ if (irq < 0) {
+ dev_err(&pdev->dev, "Err getting IRQ %d\n", irq);
+ return irq;
+ }
spi = spi_alloc_master(&pdev->dev, sizeof(*mas)); if (!spi)
@@ -553,6 +560,7 @@
mas->dev = &pdev->dev;
mas->se.dev = &pdev->dev;
mas->se.wrapper = dev_get_drvdata(pdev->dev.parent);
+ mas->irq = irq;
se = &mas->se;
spi->bus_num = -1;
@@ -589,13 +597,6 @@
if (ret)
goto spi_geni_probe_runtime_disable;
- mas->irq = platform_get_irq(pdev, 0);
- if (mas->irq < 0) {
- ret = mas->irq;
- dev_err(&pdev->dev, "Err getting IRQ %d\n", ret);
- goto spi_geni_probe_runtime_disable;
- }
-
ret = request_irq(mas->irq, geni_spi_isr,
IRQF_TRIGGER_HIGH, "spi_geni", spi);if (ret)
-Doug
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Quoting Doug Anderson (2018-10-09 10:48:55)
Quoted 11 lines
Ah, you're suggesting separating the
platform_get_irq()and therequest_irq()so that we callplatform_get_irq()as the first thing in the function but don't do therequest_irq()until later. Yeah, that could be done and I guess if you feel strongly about it I wouldn't object to the change, but I don't feel it buys us a lot and I kind of like keeping the two next to each other. Specifically why I don't think it buys us a lot:1. You still need the "
dev_err" print, right?platform_get_irq()doesn't automatically print errors for you I think.
I usually leave it out. Who cares? Maybe we should throw a dev_err() into platform_get_irq() on failure so we can keep drivers cleaner and reduce a bunch of "can't find my IRQ" messages throughout the kernel.
Quoted 10 lines
2. You now need a local variable "irq". By putting the
platform_get_irq()before the memory allocation you now can't store it directly inmas->irq. We could try using "ret" as a temporary variable but that seems worse in this case since it'd be a bit fragile.3. You don't get rid of any error labels / error handling so we don't really save any code
Quoted 8 lines
When I tried this my diffstat says 8 lines added and 7 removed, so a net increase in LOC FWIW. I'm relying in gmail so my patch will be whitespace-damaged (sigh), but you can find a clean one at:
...the basic idea is this though:
Thanks! Here's an updated patch that I haven't compile tested in any way that hoists up the IO mapping part too, which shows that the 'se' local variable is almost entirely useless.
drivers/spi/spi-geni-qcom.c | 49 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 25 deletions(-)
drivers/spi/spi-geni-qcom.c +24 -25
@@ -538,11 +538,30 @@ static irqreturn_t geni_spi_isr(int irq, void *data)static int spi_geni_probe (struct platform_device *pdev) { -int ret; +int ret, irq;struct spi_master *spi;struct spi_geni_master *mas;struct resource *res; -struct geni_se *se; +void __iomem *base; +struct clk *clk; + + irq =platform_get_irq (pdev,0 ); +if (irq <0 ) { +dev_err (&pdev->dev,"Err getting IRQ %d\n" , irq); +return irq; + } + + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + base =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (base)) +return PTR_ERR (base); + + clk =devm_clk_get (&pdev->dev,"se" ); +if (IS_ERR (clk)) { + ret =PTR_ERR (mas->se.clk); +dev_err (&pdev->dev,"Err getting SE Core clk %d\n" , ret); +return ret; + } spi =spi_alloc_master (&pdev->dev,sizeof (*mas));if (!spi)
@@ -550,27 +569,15 @@ static int spi_geni_probe(struct platform_device *pdev)platform_set_drvdata (pdev, spi); mas =spi_master_get_devdata (spi); + mas->irq = irq; mas->dev = &pdev->dev; mas->se.dev = &pdev->dev; mas->se.wrapper =dev_get_drvdata (pdev->dev.parent); - se = &mas->se; + mas->se.base = base; + mas->se.clk = clk; spi->bus_num =-1 ; spi->dev.of_node = pdev->dev.of_node; - mas->se.clk =devm_clk_get (&pdev->dev,"se" ); -if (IS_ERR (mas->se.clk)) { - ret =PTR_ERR (mas->se.clk); -dev_err (&pdev->dev,"Err getting SE Core clk %d\n" , ret); - goto spi_geni_probe_err; - } - - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); - se->base =devm_ioremap_resource (&pdev->dev, res); -if (IS_ERR (se->base)) { - ret =PTR_ERR (se->base); - goto spi_geni_probe_err; - } - spi->mode_bits =SPI_CPOL |SPI_CPHA |SPI_LOOP |SPI_CS_HIGH ; spi->bits_per_word_mask =SPI_BPW_RANGE_MASK (4 ,32 ); spi->num_chipselect =4 ;
@@ -589,13 +596,6 @@ static int spi_geni_probe(struct platform_device *pdev)if (ret) goto spi_geni_probe_runtime_disable; - mas->irq =platform_get_irq (pdev,0 ); -if (mas->irq <0 ) { - ret = mas->irq; -dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); - goto spi_geni_probe_runtime_disable; - } - ret =request_irq (mas->irq, geni_spi_isr,IRQF_TRIGGER_HIGH ,"spi_geni" , spi);if (ret)
@@ -610,7 +610,6 @@ static int spi_geni_probe(struct platform_device *pdev)free_irq (mas->irq, spi); spi_geni_probe_runtime_disable:pm_runtime_disable (&pdev->dev); -spi_geni_probe_err:spi_master_put (spi);return ret; }
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 11 lines · Stephen Boyd
Quoting Doug Anderson (2018-10-09 10:48:55)
Quoted 9 lines
Ah, you're suggesting separating the
platform_get_irq()and therequest_irq()so that we callplatform_get_irq()as the first thing in the function but don't do therequest_irq()until later. Yeah, that could be done and I guess if you feel strongly about it I wouldn't object to the change, but I don't feel it buys us a lot and I kind of like keeping the two next to each other. Specifically why I don't think it buys us a lot:
Quoted 6 lines
Quoted 2 lines
1. You still need the "
dev_err" print, right?platform_get_irq()doesn't automatically print errors for you I think.I usually leave it out. Who cares? Maybe we should throw a
dev_err()intoplatform_get_irq()on failure so we can keep drivers cleaner and reduce a bunch of "can't find my IRQ" messages throughout the kernel.
Yeah, all the boilerplate code is annoying. ...of course by hoisting it up then you get a whole bunch of people that have "optional" IRQs suddenly getting error messages spewed which is also no good. IMO the convention of Linux drivers I've always reviewed is to print errors like this, so unless that changes my vote is to follow convention.
Quoted 13 lines
Quoted 13 lines
2. You now need a local variable "irq". By putting the
platform_get_irq()before the memory allocation you now can't store it directly inmas->irq. We could try using "ret" as a temporary variable but that seems worse in this case since it'd be a bit fragile.3. You don't get rid of any error labels / error handling so we don't really save any code
When I tried this my diffstat says 8 lines added and 7 removed, so a net increase in LOC FWIW. I'm relying in gmail so my patch will be whitespace-damaged (sigh), but you can find a clean one at:
Quoted 8 lines
Quoted 4 lines
...the basic idea is this though:
Thanks! Here's an updated patch that I haven't compile tested in any way that hoists up the IO mapping part too, which shows that the 'se' local variable is almost entirely useless.
Yeah, I'd be all for getting rid of "se". I'm still not really seeing the benefit of hoisting all the rest of the stuff up. Do you feel strongly about it?
In any case I think we've both said that all of our comments so far are just nits and could be addressed in a followup patch. Unless Mark Brown wants these nits fixed ahead of time or has other changes he'd like, I don't think we're expecting another spin of this patch from Alok or Dilip, right? We'd just expect them to post some follow-up patches after Mark lands it?
-Doug
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Quoting Doug Anderson (2018-10-09 14:18:26)
Quoted 53 lines
Hi,
Quoted 11 lines · Stephen Boyd
Quoting Doug Anderson (2018-10-09 10:48:55)
Quoted 9 lines
Ah, you're suggesting separating the
platform_get_irq()and therequest_irq()so that we callplatform_get_irq()as the first thing in the function but don't do therequest_irq()until later. Yeah, that could be done and I guess if you feel strongly about it I wouldn't object to the change, but I don't feel it buys us a lot and I kind of like keeping the two next to each other. Specifically why I don't think it buys us a lot:Quoted 6 lines
Quoted 2 lines
1. You still need the "
dev_err" print, right?platform_get_irq()doesn't automatically print errors for you I think.I usually leave it out. Who cares? Maybe we should throw a
dev_err()intoplatform_get_irq()on failure so we can keep drivers cleaner and reduce a bunch of "can't find my IRQ" messages throughout the kernel.Yeah, all the boilerplate code is annoying. ...of course by hoisting it up then you get a whole bunch of people that have "optional" IRQs suddenly getting error messages spewed which is also no good. IMO the convention of Linux drivers I've always reviewed is to print errors like this, so unless that changes my vote is to follow convention.
Quoted 13 lines
Quoted 13 lines
2. You now need a local variable "irq". By putting the
platform_get_irq()before the memory allocation you now can't store it directly inmas->irq. We could try using "ret" as a temporary variable but that seems worse in this case since it'd be a bit fragile.3. You don't get rid of any error labels / error handling so we don't really save any code
When I tried this my diffstat says 8 lines added and 7 removed, so a net increase in LOC FWIW. I'm relying in gmail so my patch will be whitespace-damaged (sigh), but you can find a clean one at:
Quoted 8 lines
Quoted 4 lines
...the basic idea is this though:
Thanks! Here's an updated patch that I haven't compile tested in any way that hoists up the IO mapping part too, which shows that the 'se' local variable is almost entirely useless.
Yeah, I'd be all for getting rid of "se". I'm still not really seeing the benefit of hoisting all the rest of the stuff up. Do you feel strongly about it?
Quoted 8 lines
In any case I think we've both said that all of our comments so far are just nits and could be addressed in a followup patch. Unless Mark Brown wants these nits fixed ahead of time or has other changes he'd like, I don't think we're expecting another spin of this patch from Alok or Dilip, right? We'd just expect them to post some follow-up patches after Mark lands it?
Yes this is all nits territory. I don't really care too much, but the patch is already written, so might as well roll it all in and make things shiny.
Time to get back to real work :P
Re: [PATCH V5 3/3] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Stephen BoydQuoted 64 lines
Quoted 64 lines
drivers/spi/spi-geni-qcom.c new file +16
-0+static irqreturn_t geni_spi_isr (int irq,void *data) +{ +struct spi_master *spi = data; +struct spi_geni_master *mas =spi_master_get_devdata (spi); +struct geni_se *se = &mas->se; +u32 m_irq; +unsigned long flags; +irqreturn_t ret =IRQ_HANDLED ; + +if (mas->cur_mcmd ==CMD_NONE ) +return IRQ_NONE ; + +spin_lock_irqsave (&mas->lock, flags); + m_irq =readl (se->base +SE_GENI_M_IRQ_STATUS ); + + if ((m_irq & M_RX_FIFO_WATERMARK_EN) || (m_irq &
M_RX_FIFO_LAST_EN))drivers/spi/spi-geni-qcom.c new file +13
-0+geni_spi_handle_rx (mas); + +if (m_irq &M_TX_FIFO_WATERMARK_EN ) +geni_spi_handle_tx (mas); + +if (m_irq &M_CMD_DONE_EN ) { +if (mas->cur_mcmd ==CMD_XFER ) +spi_finalize_current_transfer (spi); +else if (mas->cur_mcmd ==CMD_CS ) +complete (&mas->xfer_done); + mas->cur_mcmd =CMD_NONE ; +/* +* If this happens, then a CMD_DONE came before all the Tx
+ * buffer bytes were sent out. This is unusual, log
this
+ * condition and disable the WM interrupt to prevent
the(quoted diff) +2
-0+ * system from stalling due an interrupt storm. + * If this happens when all Rx bytes haven't beenreceived, log
(quoted diff) +2
-0+ * the condition. + * The only known time this can happen is if
bits_per_word!= 8
+ * and some registers that expect xfer lengths in numspi_wordsdrivers/spi/spi-geni-qcom.c new file +4
-0+* weren't written correctly. +*/ +if (mas->tx_rem_bytes) { + writel(0, se->base +
SE_GENI_TX_WATERMARK_REG);
+ dev_err(mas->dev, "Premature done.tx_rem= %d
bpw%d\n",
+mas->tx_rem_bytes,mas->cur_bits_per_word);drivers/spi/spi-geni-qcom.c new file +3
-0+ } +if (mas->rx_rem_bytes) + dev_err(mas->dev, "Premature done. rx_rem = %dbpw%d\n",
+mas->rx_rem_bytes,mas->cur_bits_per_word);drivers/spi/spi-geni-qcom.c new file +6
-0+ } + +if ((m_irq &M_CMD_CANCEL_EN ) || (m_irq &M_CMD_ABORT_EN )) { + mas->cur_mcmd =CMD_NONE ; +complete (&mas->xfer_done); + }
Quoted 8 lines
drivers/spi/spi-geni-qcom.c line 536
Quoted 4 lines
drivers/spi/spi-geni-qcom.c new file +4
-0+ +writel (m_irq, se->base +SE_GENI_M_IRQ_CLEAR ); +spin_unlock_irqrestore (&mas->lock, flags); +return ret;Nitpick: Now this always returns
IRQ_HANDLED, and we assign ret just to do that. Perhaps only returnIRQ_HANDLEDif one of the above if conditions is taken?
Not always. If ISR get triggered without setting proper cur_mcmd then it will return IRQ_NONE.