spi-geni-qcom: QUP SPI GENI driver and SPI device tree bindings
Subsystems (4)
v4 cover spi-geni-qcom: QUP SPI GENI driver and SPI device tree bindings
In this V4 series, submitted changes to remove SPI controller max-frquency device tree binding as it is controller specific property.
Move the GENI SE SPI controller device tree bindings documentation to devicetree/bindings/spi/qcom,spi-geni-qcom.txt.
Address the reviewer comments to spi-geni-qcom.c in patch-V3.
Adds changes in spi-geni-qcom.c to plugin set_cs API to SPI framework.
Dilip Kota (3):
dt-bindings: soc: qcom: Remove SPI controller maximum frequency entry
dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
spi: spi-geni-qcom: Plugin API to assert and de-assert Chipselect
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 | 680 +++++++++++++++++++++ include/linux/spi/spi-geni-qcom.h | 14 + 6 files changed, 748 insertions(+), 27 deletions(-) create mode 100644 Documentation/devicetree/bindings/spi/qcom,spi-geni-qcom.txt create mode 100644 drivers/spi/spi-geni-qcom.c create mode 100644 include/linux/spi/spi-geni-qcom.h
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
PATCH v4 1/4 dt-bindings: soc: qcom: Remove SPI controller maximum frequency binding
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 · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH V4 1/4] dt-bindings: soc: qcom: Remove SPI controller maximum frequency binding
Hi,
Quoted 10 lines · Dilip Kota
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.
Signed-off-by Dilip Kota <[email protected]>--- Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt | 2 -- 1 file changed, 2 deletions(-)
Re: [PATCH V4 1/4] dt-bindings: soc: qcom: Remove SPI controller maximum frequency binding
In reply to Dilip KotaQuoting Dilip Kota (2018-09-18 11:07:23)
Quoted 7 lines
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.
Signed-off-by Dilip Kota <[email protected]>---
Re: [PATCH V4 1/4] dt-bindings: soc: qcom: Remove SPI controller maximum frequency binding
In reply to Dilip KotaQuoted 10 lines · Dilip Kota
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.
Signed-off-by Dilip Kota <[email protected]>--- Documentation/devicetree/bindings/soc/qcom/qcom,geni-se.txt | 2 -- 1 file changed, 2 deletions(-)
PATCH v4 2/4 dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
In reply to Dilip KotaMove 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 · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH V4 2/4] dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
Hi,
Quoted 10 lines · Dilip Kota
Move GENI SE SPI controller device-tree bindings from
devicetree/bindings/soc/qcom/qcom,geni-se.txttodevicetree/bindings/spi/qcom,spi-geni-qcom.txt.Signed-off-by Dilip Kota <[email protected]>--- .../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(-)
IMO this matches what Mark Brown requested in a previous email and seems like a good idea.
Re: [PATCH V4 2/4] dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
In reply to Dilip KotaQuoting Dilip Kota (2018-09-18 11:07:24)
Quoted 6 lines
Move GENI SE SPI controller device-tree bindings from
devicetree/bindings/soc/qcom/qcom,geni-se.txttodevicetree/bindings/spi/qcom,spi-geni-qcom.txt.Signed-off-by Dilip Kota <[email protected]>---
Re: [PATCH V4 2/4] dt-bindings: soc: qcom: GENI SE SPI controller device tree binding
In reply to Dilip KotaQuoted 11 lines · Dilip Kota
Move GENI SE SPI controller device-tree bindings from
devicetree/bindings/soc/qcom/qcom,geni-se.txttodevicetree/bindings/spi/qcom,spi-geni-qcom.txt.Signed-off-by Dilip Kota <[email protected]>--- .../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
PATCH v4 3/4 spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Dilip KotaFrom: 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.
---
Addressing all the reviewer commets given in Patchset1. Summerizing the chages below:
Move prepare_transfer_hardware to probe
Fix the unbind failure
Add Spinlock
Use readl/writel() instead of _relaxed()
Remove __func__ in dev_err
Declare register variables as u32
Don't initialize variables and then overwrite them Remove unused step
Remove IRQ entry in geni struct
Remove extra paranthesis
Reframe probe errors
Change the tx_fifo_width naming in handle_rx and handle_tx Declare spi_geni_master as 'mas' in complete driver. Correcting the punctuation in the comments.
Adding comments in the code while setting Tx WaterMark Register. get_spi_clk_cfg() fixes
Rewrite the geni_spi_handle_tx() and geni_spi_handle_rx()
Regarding the suspend/resume and loopback failures, i am working to update in next patch seriesdrivers/spi/Kconfig | 12 +
drivers/spi/Makefile | 1 + drivers/spi/spi-geni-qcom.c | 653 ++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi-geni-qcom.h | 14 + 4 files changed, 680 insertions(+) create mode 100644 drivers/spi/spi-geni-qcom.c create mode 100644 include/linux/spi/spi-geni-qcom.h
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 +653 -0
653 lines not on this page · raw message
include/linux/spi/spi-geni-qcom.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. +*/ + +#ifndef __SPI_GENI_QCOM_HEADER___ +#define __SPI_GENI_QCOM_HEADER___ + +struct spi_geni_qcom_ctrl_data { +u32 spi_cs_clk_delay; +u32 spi_inter_words_delay; +}; + +#endif /*__SPI_GENI_QCOM_HEADER___*/
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 32 lines · Dilip Kota
From: 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.
Signed-off-by Girish Mahadevan <[email protected]>Signed-off-by Dilip Kota <[email protected]>---
Addressing all the reviewer commets given in Patchset1. Summerizing the chages below:Move
prepare_transfer_hardwareto probe
Fix the unbind failure
Add Spinlock
Use readl/writel() instead of_relaxed()
Remove__func__indev_err
Declare register variables as u32
Don't initialize variables and then overwrite them Remove unused step
Remove IRQ entry in geni struct
Remove extra paranthesis
Reframe probe errors
Change thetx_fifo_widthnaming inhandle_rxandhandle_txDeclarespi_geni_masteras 'mas' in complete driver. Correcting the punctuation in the comments.
Adding comments in the code while setting Tx WaterMark Register.get_spi_clk_cfg()fixes
Rewrite thegeni_spi_handle_tx()andgeni_spi_handle_rx()
Quoted 6 lines
Regarding the suspend/resume and loopback failures, i am working to update in next patch series
drivers/spi/Kconfig| 12 +drivers/spi/Makefile | 1 + drivers/spi/spi-geni-qcom.c | 653 ++++++++++++++++++++++++++++++++++++++ include/linux/spi/spi-geni-qcom.h | 14 + 4 files changed, 680 insertions(+)
I've confirmed that all the feedback I'm aware of from previous versions of this patch has now been addressed, except as noted above:
* suspend callback still looks a little wonky.
* loopback doesn't actually work
IMO it would be OK to land this patch and address the suspend callback / loopback issues in later patches, but obviously that's for Mark to decide.
NOTE: for this patch to land it must be based on a tree that includes the patch ("soc: qcom: geni: Make version macros simpler") [1] in order to compile. It would also be nice if it was also based upon the patches ("soc: qcom: geni: Don't ignore clk_round_rate() errors in geni_se_clk_tbl_get()") [2] and ("soc: qcom: geni:geni_se_clk_freq_match() should always accept multiples") [3]. Those aren't needed for things to compile but are technically needed for correctness. +Andy Gross has said he'll put that the above 3 patches in his tree in a way that it would be easy to pull in
Mark: it would be super if you had a chance to take a look at this patch now and see what you think.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://lkml.kernel.org/r/[email protected]
[3] https://lkml.kernel.org/r/[email protected]
With all that said, I'm happy adding:
-Doug
kbuild test robot
build botRe: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Dilip KotaThank you for the patch! Yet something to improve:
Hi Girish,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on spi/for-next]
[also build test ERROR on v4.19-rc4 next-20180918]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Dilip-Kota/spi-geni-qcom-QUP-SPI-GENI-driver-and-SPI-device-tree-bindings/20180919-043055 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next config: xtensa-allyesconfig (attached as .config) compiler: xtensa-linux-gcc (GCC) 8.1.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=8.1.0 make.cross ARCH=xtensa
All errors (new ones prefixed by >>):
drivers/spi/spi-geni-qcom.c: In function 'spi_geni_init':
>> drivers/spi/spi-geni-qcom.c:236:10: error: implicit declaration of function 'GENI_SE_VERSION_MAJOR'; did you mean 'XCHAL_HW_VERSION_MAJOR'? [-Werror=implicit-function-declaration]
major = GENI_SE_VERSION_MAJOR(ver);
^~~~~~~~~~~~~~~~~~~~~
XCHAL_HW_VERSION_MAJOR
>> drivers/spi/spi-geni-qcom.c:237:10: error: implicit declaration of function 'GENI_SE_VERSION_MINOR'; did you mean 'XCHAL_HW_VERSION_MINOR'? [-Werror=implicit-function-declaration]
minor = GENI_SE_VERSION_MINOR(ver);
^~~~~~~~~~~~~~~~~~~~~
XCHAL_HW_VERSION_MINORcc1: some warnings being treated as errors
vim +236 drivers/spi/spi-geni-qcom.c
208
209 static int spi_geni_init(struct spi_geni_master *mas)
210 {
211 struct geni_se *se = &mas->se;
212 unsigned int proto, major, minor, ver;
213
214 pm_runtime_get_sync(mas->dev);
215
216 proto = geni_se_read_proto(se);
217 if (proto != GENI_SE_SPI) {
218 dev_err(mas->dev, "Invalid proto %d\n", proto);
219 pm_runtime_put(mas->dev);
220 return -ENXIO;
221 }
222 mas->tx_fifo_depth = geni_se_get_tx_fifo_depth(se);
223 mas->rx_fifo_depth = geni_se_get_rx_fifo_depth(se);
224
225 /* Width of Tx and Rx FIFO is same */
226 mas->fifo_width_bits = geni_se_get_tx_fifo_width(se);
227
228 /*
229 * Hardware programming guide suggests to configure
230 * RX FIFO RFR level to fifo_depth-2.
231 */
232 geni_se_init(se, 0x0, mas->tx_fifo_depth - 2);
233 /* Transmit an entire FIFO worth of data per IRQ */
234 mas->tx_wm = 1;
235 ver = geni_se_get_qup_hw_version(se);
> 236 major = GENI_SE_VERSION_MAJOR(ver); > 237 minor = GENI_SE_VERSION_MINOR(ver);
238
239 if (major == 1 && minor == 0)
240 mas->oversampling = 2;
241 else
242 mas->oversampling = 1;
243
244 pm_runtime_put(mas->dev);
245 return 0;
246 }
247
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
In reply to Dilip KotaQuoting Dilip Kota (2018-09-18 11:07:25)
Quoted 63 lines
drivers/spi/spi-geni-qcom.c new file +57
-0@@ -0,0 +1,653 @@ +// SPDX-License-Identifier: GPL-2.0 +// Copyright (c) 2017-2018, The Linux foundation. All rights reserved. + +#include <linux/clk.h> +#include <linux/interrupt.h> +#include <linux/io.h> +#include <linux/log2.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/pm_runtime.h> +#include <linux/qcom-geni-se.h> +#include <linux/spi/spi.h> +#include <linux/spinlock.h> + +/* SPI SE specific registers and respective register fields */ +#define SE_SPI_CPHA 0x224 +#define CPHA BIT(0) + +#define SE_SPI_LOOPBACK 0x22c +#define LOOPBACK_ENABLE 0x1 +#define NORMAL_MODE 0x0 +#define LOOPBACK_MSK GENMASK(1, 0) + +#define SE_SPI_CPOL 0x230 +#define CPOL BIT(2) + +#define SE_SPI_DEMUX_OUTPUT_INV 0x24c +#define CS_DEMUX_OUTPUT_INV_MSK GENMASK(3, 0) + +#define SE_SPI_DEMUX_SEL 0x250 +#define CS_DEMUX_OUTPUT_SEL GENMASK(3, 0) + +#define SE_SPI_TRANS_CFG 0x25c +#define CS_TOGGLE BIT(0) + +#define SE_SPI_WORD_LEN 0x268 +#define WORD_LEN_MSK GENMASK(9, 0) +#define MIN_WORD_LEN 4 + +#define SE_SPI_TX_TRANS_LEN 0x26c +#define SE_SPI_RX_TRANS_LEN 0x270 +#define TRANS_LEN_MSK GENMASK(23, 0) + +#define SE_SPI_PRE_POST_CMD_DLY 0x274 + +#define SE_SPI_DELAY_COUNTERS 0x278 +#define SPI_INTER_WORDS_DELAY_MSK GENMASK(9, 0) +#define SPI_CS_CLK_DELAY_MSK GENMASK(19, 10) +#define SPI_CS_CLK_DELAY_SHFT 10 + +/* M_CMD OP codes for SPI */ +#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
drivers/spi/spi-geni-qcom.c line 67
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+#define SPI_CS_DEASSERT 9 +#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) + +static irqreturn_t geni_spi_isr (int irq,void *data);
Does this need to be forward declared?
drivers/spi/spi-geni-qcom.c line 72
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 rx_fifo_depth;
Is this used?
drivers/spi/spi-geni-qcom.c line 76
Quoted 4 lines
drivers/spi/spi-geni-qcom.c new file +4
-0+u32 tx_fifo_depth; +u32 fifo_width_bits; +u32 tx_wm; +unsigned int cur_speed_hz;
unsigned long for Hz? The clk framework uses that type.
drivers/spi/spi-geni-qcom.c line 80
Quoted 4 lines
drivers/spi/spi-geni-qcom.c new file +4
-0+unsigned int cur_bits_per_word; +unsigned int tx_rem_bytes; +unsigned int rx_rem_bytes; +struct spi_transfer *cur_xfer;
const?
Quoted 5 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+struct completion xfer_done; +unsigned int oversampling; +spinlock_t lock; +}; +
[...]
drivers/spi/spi-geni-qcom.c line 205
Quoted 13 lines
drivers/spi/spi-geni-qcom.c new file +13
-0+ +static int spi_geni_prepare_message (struct spi_master *spi, +struct spi_message *spi_msg) +{ +int ret; +struct spi_geni_master *mas =spi_master_get_devdata (spi); +struct geni_se *se = &mas->se; + +geni_se_select_mode (se,GENI_SE_FIFO ); +reinit_completion (&mas->xfer_done); + ret =setup_fifo_params (spi_msg->spi, spi); +if (ret) +dev_err (mas->dev,"Couldn't select mode %d" , ret);
Missing newline on error print.
Quoted 3 lines
drivers/spi/spi-geni-qcom.c new file +3
-0+return ret; +} +
[...]
Quoted 21 lines
drivers/spi/spi-geni-qcom.c new file +21
-0+ +static void setup_fifo_xfer (struct spi_transfer *xfer, +struct spi_geni_master *mas, +u16 mode,struct spi_master *spi) +{ +u32 m_cmd =0 , m_param =0 ; +u32 spi_tx_cfg, trans_len; +struct geni_se *se = &mas->se; + + spi_tx_cfg =readl (se->base +SE_SPI_TRANS_CFG ); +if (xfer->bits_per_word != mas->cur_bits_per_word) { +spi_setup_word_len (mas, mode, xfer->bits_per_word); + mas->cur_bits_per_word = xfer->bits_per_word; + } + +/* Speed and bits per word can be overridden per transfer */ +if (xfer->speed_hz != mas->cur_speed_hz) { +int ret; +u32 clk_sel, m_clk_cfg; +unsigned int idx, div; +
drivers/spi/spi-geni-qcom.c line 277
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+ ret =get_spi_clk_cfg (xfer->speed_hz, mas, &idx, &div); +if (ret) { +dev_err (mas->dev,"Err setting clks:%d\n" , ret); +return ; + } +/* +* SPI core clock gets configured with the requested frequency +* or the frequency closer to the requested frequency. +* For that reason requested frequency is stored in the +* cur_speed_hz and referred in the consicutive transfer instead
s/consicutive/consecutive/
Quoted 19 lines
drivers/spi/spi-geni-qcom.c new file +19
-0+* of calling clk_get_rate() API. +*/ + mas->cur_speed_hz = xfer->speed_hz; + clk_sel = idx &CLK_SEL_MSK ; + m_clk_cfg = (div <<CLK_DIV_SHFT ) |SER_CLK_EN ; +writel (clk_sel, se->base +SE_GENI_CLK_SEL ); +writel (m_clk_cfg, se->base +GENI_SER_M_CLK_CFG ); + } + + mas->tx_rem_bytes =0 ; + mas->rx_rem_bytes =0 ; +if (xfer->tx_buf && xfer->rx_buf) + m_cmd =SPI_FULL_DUPLEX ; +else if (xfer->tx_buf) + m_cmd =SPI_TX_ONLY ; +else if (xfer->rx_buf) + m_cmd =SPI_RX_ONLY ; + + spi_tx_cfg &= ~CS_TOGGLE ;
drivers/spi/spi-geni-qcom.c line 306
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+if (!(mas->cur_bits_per_word %MIN_WORD_LEN )) { + trans_len = + (xfer->len *BITS_PER_BYTE / + mas->cur_bits_per_word) &TRANS_LEN_MSK ; + }else { +unsigned int bytes_per_word = + mas->cur_bits_per_word /BITS_PER_BYTE +1 ; + + trans_len = (xfer->len / bytes_per_word) &TRANS_LEN_MSK ; + }
Rename 'trans_len' to 'len' and shorten some lines by taking out the mask to get:
if (!(mas->cur_bits_per_word % MIN_WORD_LEN))
len = xfer->len * BITS_PER_BYTE / mas->cur_bits_per_word
else
len = xfer->len / (mas->cur_bits_per_word / BITS_PER_BYTE + 1);
len &= TRANS_LEN_MSK;Quoted 42 lines
drivers/spi/spi-geni-qcom.c new file +42
-0+ +/* +* If CS change flag is set, then toggle the CS line in between +* transfers and keep CS asserted after the last transfer. +* Else if keep CS flag asserted in between transfers and de-assert +* CS after the last message. +*/ +if (xfer->cs_change) { +if (list_is_last (&xfer->transfer_list, + &spi->cur_msg->transfers)) + m_param =FRAGMENTATION ; + }else { +if (!list_is_last (&xfer->transfer_list, + &spi->cur_msg->transfers)) + m_param =FRAGMENTATION ; + } + + mas->cur_xfer = xfer; +if (m_cmd &SPI_TX_ONLY ) { + mas->tx_rem_bytes = xfer->len; +writel (trans_len, se->base +SE_SPI_TX_TRANS_LEN ); + } + +if (m_cmd &SPI_RX_ONLY ) { +writel (trans_len, se->base +SE_SPI_RX_TRANS_LEN ); + mas->rx_rem_bytes = xfer->len; + } +writel (spi_tx_cfg, se->base +SE_SPI_TRANS_CFG ); +geni_se_setup_m_cmd (se, m_cmd, m_param); + +/* +* TX_WATERMARK_REG should be set after SPI configuration and +* setting up GENI SE engine, as driver starts data transfer +* for the watermark interrupt. +*/ +if (m_cmd &SPI_TX_ONLY ) +writel (mas->tx_wm, se->base +SE_GENI_TX_WATERMARK_REG ); +} + +static void handle_fifo_timeout (struct spi_master *spi, +struct spi_message *msg) +{
drivers/spi/spi-geni-qcom.c line 358
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+struct spi_geni_master *mas =spi_master_get_devdata (spi); +unsigned long timeout, flags; +struct geni_se *se = &mas->se; + +spin_lock_irqsave (&mas->lock, flags); +reinit_completion (&mas->xfer_done); +geni_se_cancel_m_cmd (se); +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); +spin_unlock_irqrestore (&mas->lock, flags); + timeout =wait_for_completion_timeout (&mas->xfer_done,HZ );
Can you rename this time_left or completed? Then the if condition reads properly as "if not time left" or "if not completed". And then invert that logic so things aren't so indented?
time_left = wait_for_completion_timeout(..) if (time_left) return; spin_lock_irqsave(&mas->lock, flags); reinit_completion(..) ...
Quoted 25 lines
drivers/spi/spi-geni-qcom.c new file +25
-0+if (!timeout) { +spin_lock_irqsave (&mas->lock, flags); +reinit_completion (&mas->xfer_done); +geni_se_abort_m_cmd (se); +spin_unlock_irqrestore (&mas->lock, flags); + timeout =wait_for_completion_timeout (&mas->xfer_done, +HZ ); +if (!timeout) +dev_err (mas->dev, +"Failed to cancel/abort m_cmd\n" ); + } +} + +static int spi_geni_transfer_one (struct spi_master *spi, +struct spi_device *slv, +struct spi_transfer *xfer) +{ +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +setup_fifo_xfer (xfer, mas, slv->mode, spi); +return 1 ; +} + +static unsigned int geni_byte_per_fifo_word (struct spi_geni_master *mas) +{
drivers/spi/spi-geni-qcom.c line 393
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+/* +* Calculate how many bytes we'll put in each FIFO word. If the +* transfer words don't pack cleanly into a FIFO word we'll just put +* one transfer word in each FIFO word. If they do pack we'll pack 'em. +*/ +if (mas->fifo_width_bits % mas->cur_bits_per_word) +return roundup_pow_of_two (DIV_ROUND_UP (mas->cur_bits_per_word, +BITS_PER_BYTE )); +else +return mas->fifo_width_bits /BITS_PER_BYTE ;
Just do a return. No else please.
Quoted 39 lines
drivers/spi/spi-geni-qcom.c new file +39
-0+} + +static irqreturn_t geni_spi_handle_tx (struct spi_geni_master *mas) +{ +struct geni_se *se = &mas->se; +unsigned int max_bytes; +const u8 *tx_buf; +unsigned int bytes_per_fifo_word =geni_byte_per_fifo_word (mas); +unsigned int i =0 ; + +if (!mas->cur_xfer) +return IRQ_NONE ; + + max_bytes = (mas->tx_fifo_depth - mas->tx_wm) * bytes_per_fifo_word; +if (mas->tx_rem_bytes < max_bytes) + max_bytes = mas->tx_rem_bytes; + + tx_buf = mas->cur_xfer->tx_buf + mas->cur_xfer->len - mas->tx_rem_bytes; +while (i < max_bytes) { +unsigned int j; +unsigned int bytes_to_write; +u32 fifo_word =0 ; +u8 *fifo_byte = (u8 *)&fifo_word; + + bytes_to_write =min (bytes_per_fifo_word, max_bytes - i); +for (j =0 ; j < bytes_to_write; j++) + fifo_byte[j] = tx_buf[i++]; +iowrite32_rep (se->base + SE_GENI_TX_FIFOn, &fifo_word,1 ); + } + mas->tx_rem_bytes -= max_bytes; +if (!mas->tx_rem_bytes) +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); + +return IRQ_HANDLED ; +} + +static irqreturn_t geni_spi_handle_rx (struct spi_geni_master *mas) +{ +struct geni_se *se = &mas->se;
drivers/spi/spi-geni-qcom.c line 442
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+u32 rx_fifo_status; +unsigned int rx_bytes; +u8 *rx_buf; +unsigned int bytes_per_fifo_word =geni_byte_per_fifo_word (mas); +unsigned int i =0 ; + +if (!mas->cur_xfer) +return IRQ_NONE ; + + rx_fifo_status =readl (se->base +SE_GENI_RX_FIFO_STATUS );
Rename to 'status'? rx_fifo is implicit in the register macro.
drivers/spi/spi-geni-qcom.c line 447
Quoted 5 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+ rx_bytes = (rx_fifo_status &RX_FIFO_WC_MSK ) * bytes_per_fifo_word; +if (rx_fifo_status &RX_LAST ) { +unsigned int rx_last_byte_valid = + (rx_fifo_status &RX_LAST_BYTE_VALID_MSK ) + >>RX_LAST_BYTE_VALID_SHFT ;
Hoist this variable into function scope? So then the line is:
last_valid = status & RX_LAST_BYTE_VALID_MSK; last_valid >>= RX_LAST_BYTE_VALID_SHFT;
Quoted 1 line
+ if (
rx_last_byte_valid&& (rx_last_byte_valid< 4))
Drop useless parenthesis please.
Quoted 31 lines
drivers/spi/spi-geni-qcom.c new file +31
-0+ rx_bytes -= bytes_per_fifo_word - rx_last_byte_valid; + } +if (mas->rx_rem_bytes < rx_bytes) + rx_bytes = mas->rx_rem_bytes; + + rx_buf = mas->cur_xfer->rx_buf + mas->cur_xfer->len - mas->rx_rem_bytes; +while (i < rx_bytes) { +u32 fifo_word =0 ; +u8 *fifo_byte = (u8 *)&fifo_word; +unsigned int bytes_to_read; +unsigned int j; + + bytes_to_read =min (bytes_per_fifo_word, rx_bytes - i); +ioread32_rep (se->base + SE_GENI_RX_FIFOn, &fifo_word,1 ); +for (j =0 ; j < bytes_to_read; j++) + rx_buf[i++] = fifo_byte[j]; + } + mas->rx_rem_bytes -= rx_bytes; + +return IRQ_HANDLED ; +} + +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 ; +
drivers/spi/spi-geni-qcom.c line 489
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+if (pm_runtime_status_suspended (mas->dev)) +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 )) + ret =geni_spi_handle_rx (mas); + +if (m_irq &M_TX_FIFO_WATERMARK_EN ) + ret =geni_spi_handle_tx (mas);
Is it possible for all three conditions above to happen in one interrupt? I ask because 'ret' is overwritten and so what may have been IRQ_HANDLED may become IRQ_NONE which will lead to confusion in the irq layer. Maybe the handle tx/rx functions can return a bool, that gets orred together each time so that we know if something handled an interrupt?
Quoted 7 lines
drivers/spi/spi-geni-qcom.c new file +7
-0+ +if (m_irq &M_CMD_DONE_EN ) { +spi_finalize_current_transfer (spi); +/* +* 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
drivers/spi/spi-geni-qcom.c line 506
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+* 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",
Why isn't there a space after "Done."? And why is 'done' capitalized? Should 'tx_rem' be 'tx_rem='?
Quoted 14 lines
drivers/spi/spi-geni-qcom.c new file +14
-0+ 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); + } + +if ((m_irq &M_CMD_CANCEL_EN ) || (m_irq &M_CMD_ABORT_EN )) +complete (&mas->xfer_done); + +writel (m_irq, se->base +SE_GENI_M_IRQ_CLEAR ); +spin_unlock_irqrestore (&mas->lock, flags); +return ret; +}
drivers/spi/spi-geni-qcom.c line 530
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-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 (struct spi_geni_master ));
sizeof(*mas) for code clarity?
Quoted 13 lines
drivers/spi/spi-geni-qcom.c new file +13
-0+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" );
drivers/spi/spi-geni-qcom.c line 553
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+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 = -ENOMEM ;
ret = PTR_ERR(se->base);
so we don't lose the error value.
drivers/spi/spi-geni-qcom.c line 565
Quoted 12 lines
drivers/spi/spi-geni-qcom.c new file +12
-0+ goto spi_geni_probe_err; + } + + ret =platform_get_irq (pdev,0 ); +if (ret <0 ) { +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_err; + } + ret =devm_request_irq (&pdev->dev, ret, geni_spi_isr, +IRQF_TRIGGER_HIGH ,"spi_geni" , spi); +if (ret) + goto spi_geni_probe_err;
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_NONE returned because the device is runtime suspended.
Quoted 64 lines
drivers/spi/spi-geni-qcom.c new file +64
-0+ + 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; + +init_completion (&mas->xfer_done); +spin_lock_init (&mas->lock); +pm_runtime_enable (&pdev->dev); + + ret =spi_geni_init (mas); +if (ret) + goto spi_geni_probe_runtime_disable; + + ret =spi_register_master (spi); +if (ret) + goto spi_geni_probe_runtime_disable; + +return 0 ; +spi_geni_probe_runtime_disable: +pm_runtime_disable (&pdev->dev); +spi_geni_probe_err: +spi_master_put (spi); +return ret; +} + +static int spi_geni_remove (struct platform_device *pdev) +{ +struct spi_master *spi =platform_get_drvdata (pdev); + +/* Unregister _before_ disabling pm_runtime() so we stop transfers */ +spi_unregister_master (spi); + +pm_runtime_disable (&pdev->dev); +return 0 ; +} + +static int __maybe_unused spi_geni_runtime_suspend (struct device *dev) +{ +struct spi_master *spi =dev_get_drvdata (dev); +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +return geni_se_resources_off (&mas->se); +} + +static int __maybe_unused spi_geni_runtime_resume (struct device *dev) +{ +struct spi_master *spi =dev_get_drvdata (dev); +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +return geni_se_resources_on (&mas->se); +} + +static int __maybe_unused spi_geni_suspend (struct device *dev) +{ +if (!pm_runtime_status_suspended (dev)) +return -EBUSY ; +return 0 ; +} +
drivers/spi/spi-geni-qcom.c line 639
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+static const struct dev_pm_ops spi_geni_pm_ops = { + SET_RUNTIME_PM_OPS(spi_geni_runtime_suspend, + spi_geni_runtime_resume, NULL) +SET_SYSTEM_SLEEP_PM_OPS (spi_geni_suspend,NULL ) +}; + +static const struct of_device_id spi_geni_dt_match[] = { + { .compatible ="qcom,geni-spi" }, + {} +};
Please add a MODULE_DEVICE_TABLE(of, spi_geni_dt_match) here.
Quoted 21 lines
drivers/spi/spi-geni-qcom.c new file +14
-0+ +static struct platform_driver spi_geni_driver = { + .probe = spi_geni_probe, + .remove = spi_geni_remove, + .driver = { + .name ="geni_spi" , + .pm = &spi_geni_pm_ops, + .of_match_table = spi_geni_dt_match, + }, +}; +module_platform_driver (spi_geni_driver); + +MODULE_DESCRIPTION ("SPI driver for GENI based QUP cores" ); +MODULE_LICENSE ("GPL v2" );include/linux/spi/spi-geni-qcom.h new file +1
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
include/linux/spi/spi-geni-qcom.h line 11
Quoted 10 lines
include/linux/spi/spi-geni-qcom.h new file +10
-0+/* +* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. +*/ + +#ifndef __SPI_GENI_QCOM_HEADER___ +#define __SPI_GENI_QCOM_HEADER___ + +struct spi_geni_qcom_ctrl_data { + u32 spi_cs_clk_delay; + u32 spi_inter_words_delay;
It was decided we still needed this? I don't see it in v3 so please remove this file unless it's needed.
Re: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
[...]
Quoted 8 lines
drivers/spi/spi-geni-qcom.c line 67
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+#define TIMESTAMP_BEFORE BIT(1) +#define FRAGMENTATION BIT(2) +#define TIMESTAMP_AFTER BIT(3) +#define POST_CMD_DELAY BIT(4) + +static irqreturn_t geni_spi_isr (int irq,void *data);Does this need to be forward declared?
Not required, will remove it.
Quoted 8 lines
drivers/spi/spi-geni-qcom.c line 72
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+ +struct spi_geni_master { +struct geni_se se; +struct device *dev; +u32 rx_fifo_depth;Is this used?
It can be removed.
Quoted 7 lines
drivers/spi/spi-geni-qcom.c line 76
Quoted 5 lines
drivers/spi/spi-geni-qcom.c new file +4
-0+u32 tx_fifo_depth; +u32 fifo_width_bits; +u32 tx_wm; +unsigned int cur_speed_hz;unsigned long for Hz? The clk framework uses that type.
cur_speed_hz stores the speed value requested as part of transfer (not the resultant or rounded off frequency got from clk framework. It is u32 type, i will change cur_speed_hz to u32 type instead of unsigned long. Code snippet:
mas->cur_speed_hz = xfer->speed_hz;
Quoted 7 lines
drivers/spi/spi-geni-qcom.c line 80
Quoted 5 lines
drivers/spi/spi-geni-qcom.c new file +4
-0+unsigned int cur_bits_per_word; +unsigned int tx_rem_bytes; +unsigned int rx_rem_bytes; +struct spi_transfer *cur_xfer;const?
Yes can be marked as const, will update it.
Quoted 7 lines
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+struct completion xfer_done; +unsigned int oversampling; +spinlock_t lock; +}; +[...]
Quoted 16 lines
drivers/spi/spi-geni-qcom.c line 205
Quoted 13 lines
drivers/spi/spi-geni-qcom.c new file +13
-0+ +static int spi_geni_prepare_message (struct spi_master *spi, +struct spi_message *spi_msg) +{ +int ret; +struct spi_geni_master *mas =spi_master_get_devdata (spi); +struct geni_se *se = &mas->se; + +geni_se_select_mode (se,GENI_SE_FIFO ); +reinit_completion (&mas->xfer_done); + ret =setup_fifo_params (spi_msg->spi, spi); +if (ret) +dev_err (mas->dev,"Couldn't select mode %d" , ret);Missing newline on error print.
Will add it.
Quoted 34 lines
Quoted 3 lines
drivers/spi/spi-geni-qcom.c new file +3
-0+return ret; +} +[...]
Quoted 30 lines
drivers/spi/spi-geni-qcom.c new file +22
-0+ +static void setup_fifo_xfer (struct spi_transfer *xfer, +struct spi_geni_master *mas, +u16 mode,struct spi_master *spi) +{ +u32 m_cmd =0 , m_param =0 ; +u32 spi_tx_cfg, trans_len; +struct geni_se *se = &mas->se; + + spi_tx_cfg =readl (se->base +SE_SPI_TRANS_CFG ); +if (xfer->bits_per_word != mas->cur_bits_per_word) { +spi_setup_word_len (mas, mode, xfer->bits_per_word); + mas->cur_bits_per_word = xfer->bits_per_word; + } + +/* Speed and bits per word can be overridden per transfer */ +if (xfer->speed_hz != mas->cur_speed_hz) { +int ret; +u32 clk_sel, m_clk_cfg; +unsigned int idx, div; + + ret = get_spi_clk_cfg(xfer->speed_hz, mas, &idx,&div);
(quoted diff) +2
-0+ if (ret) { + dev_err(mas->dev, "Err setting clks:%d\n",ret);
drivers/spi/spi-geni-qcom.c new file +4
-0+return ; + } +/* +* SPI core clock gets configured with the requested
Quoted 8 lines
Quoted 6 lines
frequency
(quoted diff) +2
-0+ * or the frequency closer to the requested frequency. + * For that reason requested frequency is stored inthe
+ *cur_speed_hzand referred in the consicutive
transfer insteads/consicutive/consecutive/
will correct it.
Quoted 36 lines
Quoted 30 lines
drivers/spi/spi-geni-qcom.c new file +23
-0+* of calling clk_get_rate() API. +*/ + mas->cur_speed_hz = xfer->speed_hz; + clk_sel = idx &CLK_SEL_MSK ; + m_clk_cfg = (div <<CLK_DIV_SHFT ) |SER_CLK_EN ; +writel (clk_sel, se->base +SE_GENI_CLK_SEL ); +writel (m_clk_cfg, se->base +GENI_SER_M_CLK_CFG ); + } + + mas->tx_rem_bytes =0 ; + mas->rx_rem_bytes =0 ; +if (xfer->tx_buf && xfer->rx_buf) + m_cmd =SPI_FULL_DUPLEX ; +else if (xfer->tx_buf) + m_cmd =SPI_TX_ONLY ; +else if (xfer->rx_buf) + m_cmd =SPI_RX_ONLY ; + + spi_tx_cfg &= ~CS_TOGGLE ; +if (!(mas->cur_bits_per_word %MIN_WORD_LEN )) { + trans_len = + (xfer->len *BITS_PER_BYTE / + mas->cur_bits_per_word) &
TRANS_LEN_MSK;drivers/spi/spi-geni-qcom.c new file +5
-0+ }else { +unsigned int bytes_per_word = + mas->cur_bits_per_word /BITS_PER_BYTE +1 ; + + trans_len = (xfer->len / bytes_per_word) &Quoted 2 lines
TRANS_LEN_MSK;
+ }Rename '
trans_len' to 'len' and shorten some lines by taking out the mask to get:
Quoted 7 lines
if (!(mas->cur_bits_per_word % MIN_WORD_LEN))
len = xfer->len * BITS_PER_BYTE / mas->cur_bits_per_word
else
len = xfer->len / (mas->cur_bits_per_word /
BITS_PER_BYTE + 1);
len &= TRANS_LEN_MSK;OK
Quoted 60 lines
Quoted 45 lines
drivers/spi/spi-geni-qcom.c new file +3
-0+ +/* +* If CS change flag is set, then toggle the CS line in between
(quoted diff) +2
-0+ * transfers and keep CS asserted after the last transfer. + * Else if keep CS flag asserted in between transfers andde-assert
drivers/spi/spi-geni-qcom.c new file +32
-0+* CS after the last message. +*/ +if (xfer->cs_change) { +if (list_is_last (&xfer->transfer_list, + &spi->cur_msg->transfers)) + m_param =FRAGMENTATION ; + }else { +if (!list_is_last (&xfer->transfer_list, + &spi->cur_msg->transfers)) + m_param =FRAGMENTATION ; + } + + mas->cur_xfer = xfer; +if (m_cmd &SPI_TX_ONLY ) { + mas->tx_rem_bytes = xfer->len; +writel (trans_len, se->base +SE_SPI_TX_TRANS_LEN ); + } + +if (m_cmd &SPI_RX_ONLY ) { +writel (trans_len, se->base +SE_SPI_RX_TRANS_LEN ); + mas->rx_rem_bytes = xfer->len; + } +writel (spi_tx_cfg, se->base +SE_SPI_TRANS_CFG ); +geni_se_setup_m_cmd (se, m_cmd, m_param); + +/* +* TX_WATERMARK_REG should be set after SPI configuration and +* setting up GENI SE engine, as driver starts data transfer +* for the watermark interrupt. +*/ +if (m_cmd &SPI_TX_ONLY ) + writel(mas->tx_wm, se->base +
SE_GENI_TX_WATERMARK_REG);drivers/spi/spi-geni-qcom.c new file +5
-0+} + +static void handle_fifo_timeout (struct spi_master *spi, +struct spi_message *msg) +{drivers/spi/spi-geni-qcom.c line 358
Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10
-0+struct spi_geni_master *mas =spi_master_get_devdata (spi); +unsigned long timeout, flags; +struct geni_se *se = &mas->se; + +spin_lock_irqsave (&mas->lock, flags); +reinit_completion (&mas->xfer_done); +geni_se_cancel_m_cmd (se); +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); +spin_unlock_irqrestore (&mas->lock, flags); + timeout =wait_for_completion_timeout (&mas->xfer_done,HZ );Can you rename this
time_leftor completed? Then the if condition reads properly as "if not time left" or "if not completed". And then invert that logic so things aren't so indented?
Quoted 8 lines
time_left = wait_for_completion_timeout(..) if (time_left) return; spin_lock_irqsave(&mas->lock, flags); reinit_completion(..) ...
Ok
Quoted 35 lines
Quoted 35 lines
drivers/spi/spi-geni-qcom.c new file +24
-0+if (!timeout) { +spin_lock_irqsave (&mas->lock, flags); +reinit_completion (&mas->xfer_done); +geni_se_abort_m_cmd (se); +spin_unlock_irqrestore (&mas->lock, flags); + timeout =wait_for_completion_timeout (&mas->xfer_done, +HZ ); +if (!timeout) +dev_err (mas->dev, +"Failed to cancel/abort m_cmd\n" ); + } +} + +static int spi_geni_transfer_one (struct spi_master *spi, +struct spi_device *slv, +struct spi_transfer *xfer) +{ +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +setup_fifo_xfer (xfer, mas, slv->mode, spi); +return 1 ; +} + +static unsigned int geni_byte_per_fifo_word(struct spi_geni_master*mas)
drivers/spi/spi-geni-qcom.c new file +3
-0+{ +/* +* Calculate how many bytes we'll put in each FIFO word. If the
+ * transfer words don't pack cleanly into a FIFO word we'll
just put
+ * one transfer word in each FIFO word. If they do pack we'll
pack 'em.(quoted diff) +2
-0+ */ + if (mas->fifo_width_bits % mas->cur_bits_per_word)
Quoted 9 lines
drivers/spi/spi-geni-qcom.c line 393
Quoted 6 lines
+ return
roundup_pow_of_two(DIV_ROUND_UP(mas->cur_bits_per_word, +BITS_PER_BYTE));drivers/spi/spi-geni-qcom.c new file +2
-0+else +return mas->fifo_width_bits /BITS_PER_BYTE ;Just do a return. No else please.
Ok
Quoted 49 lines
Quoted 49 lines
drivers/spi/spi-geni-qcom.c new file +8
-0+} + +static irqreturn_t geni_spi_handle_tx (struct spi_geni_master *mas) +{ +struct geni_se *se = &mas->se; +unsigned int max_bytes; +const u8 *tx_buf; + unsigned int bytes_per_fifo_word =
geni_byte_per_fifo_word(mas);drivers/spi/spi-geni-qcom.c new file +6
-0+unsigned int i =0 ; + +if (!mas->cur_xfer) +return IRQ_NONE ; + + max_bytes = (mas->tx_fifo_depth - mas->tx_wm) *
bytes_per_fifo_word;drivers/spi/spi-geni-qcom.c new file +4
-0+if (mas->tx_rem_bytes < max_bytes) + max_bytes = mas->tx_rem_bytes; + + tx_buf = mas->cur_xfer->tx_buf + mas->cur_xfer->len -
mas->tx_rem_bytes;drivers/spi/spi-geni-qcom.c new file +7
-0+while (i < max_bytes) { +unsigned int j; +unsigned int bytes_to_write; +u32 fifo_word =0 ; +u8 *fifo_byte = (u8 *)&fifo_word; + + bytes_to_write = min(bytes_per_fifo_word, max_bytes -i);
drivers/spi/spi-geni-qcom.c new file +3
-0+for (j =0 ; j < bytes_to_write; j++) + fifo_byte[j] = tx_buf[i++]; + iowrite32_rep(se->base + SE_GENI_TX_FIFOn, &fifo_word,1);
drivers/spi/spi-geni-qcom.c new file +15
-0+ } + mas->tx_rem_bytes -= max_bytes; +if (!mas->tx_rem_bytes) +writel (0 , se->base +SE_GENI_TX_WATERMARK_REG ); + +return IRQ_HANDLED ; +} + +static irqreturn_t geni_spi_handle_rx (struct spi_geni_master *mas) +{ +struct geni_se *se = &mas->se; +u32 rx_fifo_status; +unsigned int rx_bytes; +u8 *rx_buf; + unsigned int bytes_per_fifo_word =
geni_byte_per_fifo_word(mas);
Quoted 8 lines
drivers/spi/spi-geni-qcom.c line 442
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+unsigned int i =0 ; + +if (!mas->cur_xfer) +return IRQ_NONE ; + + rx_fifo_status =readl (se->base +SE_GENI_RX_FIFO_STATUS );Rename to 'status'?
rx_fifois implicit in the register macro.
Declared as "rx_fifo_status" for code readability.
Quoted 8 lines
drivers/spi/spi-geni-qcom.c line 447
Quoted 7 lines
+
rx_bytes= (rx_fifo_status&RX_FIFO_WC_MSK) *bytes_per_fifo_word;drivers/spi/spi-geni-qcom.c new file +4
-0+if (rx_fifo_status &RX_LAST ) { +unsigned int rx_last_byte_valid = + (rx_fifo_status &RX_LAST_BYTE_VALID_MSK ) + >>RX_LAST_BYTE_VALID_SHFT ;
Quoted 5 lines
Hoist this variable into function scope? So then the line is:
last_valid = status & RX_LAST_BYTE_VALID_MSK; last_valid >>= RX_LAST_BYTE_VALID_SHFT;
Ok
Quoted 4 lines
Quoted 1 line
+ if (
rx_last_byte_valid&& (rx_last_byte_valid< 4))Drop useless parenthesis please.
Ok
Quoted 45 lines
Quoted 45 lines
+
rx_bytes-=bytes_per_fifo_word-rx_last_byte_valid;drivers/spi/spi-geni-qcom.c new file +5
-0+ } +if (mas->rx_rem_bytes < rx_bytes) + rx_bytes = mas->rx_rem_bytes; + + rx_buf = mas->cur_xfer->rx_buf + mas->cur_xfer->len -
mas->rx_rem_bytes;drivers/spi/spi-geni-qcom.c new file +7
-0+while (i < rx_bytes) { +u32 fifo_word =0 ; +u8 *fifo_byte = (u8 *)&fifo_word; +unsigned int bytes_to_read; +unsigned int j; + + bytes_to_read = min(bytes_per_fifo_word, rx_bytes -i);
+ ioread32_rep(se->base +SE_GENI_RX_FIFOn,&fifo_word,
1);drivers/spi/spi-geni-qcom.c new file +23
-0+for (j =0 ; j < bytes_to_read; j++) + rx_buf[i++] = fifo_byte[j]; + } + mas->rx_rem_bytes -= rx_bytes; + +return IRQ_HANDLED ; +} + +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 (pm_runtime_status_suspended (mas->dev)) +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 +3
-0+ ret =geni_spi_handle_rx (mas); + +if (m_irq &M_TX_FIFO_WATERMARK_EN )
Quoted 9 lines
Quoted 1 line
+ ret =
geni_spi_handle_tx(mas);Is it possible for all three conditions above to happen in one interrupt? I ask because 'ret' is overwritten and so what may have been
IRQ_HANDLEDmay becomeIRQ_NONEwhich will lead to confusion in the irq layer. Maybe the handle tx/rx functions can return a bool, that gets orred together each time so that we know if something handled an interrupt?
Will check it again by running fullduplex transfer and update.
Quoted 26 lines
Quoted 22 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+ +if (m_irq &M_CMD_DONE_EN ) { +spi_finalize_current_transfer (spi); +/* +* 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 +Quoted 3 lines
SE_GENI_TX_WATERMARK_REG);
+ dev_err(mas->dev, "Premature Done.tx_rem%d
bpw%d\n",
Quoted 2 lines
Why isn't there a space after "Done."? And why is 'done' capitalized? Should '
tx_rem' be 'tx_rem='?
Yes, will update.
Quoted 23 lines
Quoted 23 lines
+
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 +14
-0+ } + +if ((m_irq &M_CMD_CANCEL_EN ) || (m_irq &M_CMD_ABORT_EN )) +complete (&mas->xfer_done); + +writel (m_irq, se->base +SE_GENI_M_IRQ_CLEAR ); +spin_unlock_irqrestore (&mas->lock, flags); +return ret; +} + +static int spi_geni_probe (struct platform_device *pdev) +{ +int ret; +struct spi_master *spi;
Quoted 9 lines
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +5
-0+struct spi_geni_master *mas; +struct resource *res; +struct geni_se *se; + + spi = spi_alloc_master(&pdev->dev, sizeof(struct
spi_geni_master));
sizeof(*mas)for code clarity?
Ok
Quoted 27 lines
Quoted 17 lines
drivers/spi/spi-geni-qcom.c new file +16
-0+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);
drivers/spi/spi-geni-qcom.c line 553
Quoted 7 lines
drivers/spi/spi-geni-qcom.c new file +7
-0+ 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 = -ENOMEM ;ret = PTR_ERR(se->base);
Quoted 2 lines
so we don't lose the error value.
Ok
Quoted 13 lines
drivers/spi/spi-geni-qcom.c line 565
Quoted 12 lines
drivers/spi/spi-geni-qcom.c new file +12
-0+ goto spi_geni_probe_err; + } + + ret =platform_get_irq (pdev,0 ); +if (ret <0 ) { +dev_err (&pdev->dev,"Err getting IRQ %d\n" , ret); + goto spi_geni_probe_err; + } + ret =devm_request_irq (&pdev->dev, ret, geni_spi_isr, +IRQF_TRIGGER_HIGH ,"spi_geni" , spi); +if (ret) + goto spi_geni_probe_err;
Quoted 5 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.
Ok; will call it after spi_register_master()
Quoted 70 lines
Quoted 70 lines
drivers/spi/spi-geni-qcom.c new file +35
-0+ + 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; + +init_completion (&mas->xfer_done); +spin_lock_init (&mas->lock); +pm_runtime_enable (&pdev->dev); + + ret =spi_geni_init (mas); +if (ret) + goto spi_geni_probe_runtime_disable; + + ret =spi_register_master (spi); +if (ret) + goto spi_geni_probe_runtime_disable; + +return 0 ; +spi_geni_probe_runtime_disable: +pm_runtime_disable (&pdev->dev); +spi_geni_probe_err: +spi_master_put (spi); +return ret; +} + +static int spi_geni_remove (struct platform_device *pdev) +{ +struct spi_master *spi =platform_get_drvdata (pdev); + +/* Unregister _before_ disabling pm_runtime() so we stop transfers */
drivers/spi/spi-geni-qcom.c new file +7
-0+spi_unregister_master (spi); + +pm_runtime_disable (&pdev->dev); +return 0 ; +} + +static int __maybe_unused spi_geni_runtime_suspend(struct device*dev)
drivers/spi/spi-geni-qcom.c new file +26
-0+{ +struct spi_master *spi =dev_get_drvdata (dev); +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +return geni_se_resources_off (&mas->se); +} + +static int __maybe_unused spi_geni_runtime_resume (struct device *dev) +{ +struct spi_master *spi =dev_get_drvdata (dev); +struct spi_geni_master *mas =spi_master_get_devdata (spi); + +return geni_se_resources_on (&mas->se); +} + +static int __maybe_unused spi_geni_suspend (struct device *dev) +{ +if (!pm_runtime_status_suspended (dev)) +return -EBUSY ; +return 0 ; +} + +static const struct dev_pm_ops spi_geni_pm_ops = { + SET_RUNTIME_PM_OPS(spi_geni_runtime_suspend, + spi_geni_runtime_resume, NULL) +SET_SYSTEM_SLEEP_PM_OPS (spi_geni_suspend,NULL )
Quoted 9 lines
drivers/spi/spi-geni-qcom.c line 639
Quoted 6 lines
drivers/spi/spi-geni-qcom.c new file +6
-0+}; + +static const struct of_device_id spi_geni_dt_match[] = { + { .compatible ="qcom,geni-spi" }, + {} +};Please add a
MODULE_DEVICE_TABLE(of, spi_geni_dt_match)here.
Ok
Quoted 27 lines
Quoted 27 lines
drivers/spi/spi-geni-qcom.c new file +14
-0+ +static struct platform_driver spi_geni_driver = { + .probe = spi_geni_probe, + .remove = spi_geni_remove, + .driver = { + .name ="geni_spi" , + .pm = &spi_geni_pm_ops, + .of_match_table = spi_geni_dt_match, + }, +}; +module_platform_driver (spi_geni_driver); + +MODULE_DESCRIPTION ("SPI driver for GENI based QUP cores" ); +MODULE_LICENSE ("GPL v2" );include/linux/spi/spi-geni-qcom.h new file +3
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ */include/linux/spi/spi-geni-qcom.h new file +2
-0+ +#ifndef __SPI_GENI_QCOM_HEADER___
Quoted 8 lines
include/linux/spi/spi-geni-qcom.h line 11
Quoted 5 lines
include/linux/spi/spi-geni-qcom.h new file +5
-0+#define __SPI_GENI_QCOM_HEADER___ + +struct spi_geni_qcom_ctrl_data { +u32 spi_cs_clk_delay; +u32 spi_inter_words_delay;It was decided we still needed this? I don't see it in v3 so please remove this file unless it's needed.
Its not required; I will remove it.
Along with these changes, i will submit the fixes of loopback issue and suspend/resume issue.
--Dilip
Re: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Hi,
Quoted 9 lines · On Tue, Sep 25, 2018 at 12:36 PM <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line
+ unsigned int
cur_speed_hz;unsigned long for Hz? The clk framework uses that type.
cur_speed_hzstores the speed value requested as part of transfer (not the resultant or rounded off frequency got from clk framework. It is u32 type, i will changecur_speed_hzto u32 type instead of unsigned long. Code snippet:mas->cur_speed_hz = xfer->speed_hz;
Change it to "unsigned long" anyway to match the clock framework. In theory maybe the "xfer" structure will be updated eventually.
-Doug
Re: [PATCH V4 3/4] spi: spi-geni-qcom: Add SPI driver support for GENI based QUP
Quoted 7 lines · Doug Anderson
Hi,
Quoted 4 lines · On Tue, Sep 25, 2018 at 12:36 PM <[email protected]> wrote:
Quoted 3 lines
Quoted 1 line
+ unsigned int
cur_speed_hz;unsigned long for Hz? The clk framework uses that type.
Quoted 8 lines
Quoted 5 lines
cur_speed_hzstores the speed value requested as part of transfer (not the resultant or rounded off frequency got from clk framework. It is u32 type, i will changecur_speed_hzto u32 type instead of unsigned long. Code snippet:mas->cur_speed_hz = xfer->speed_hz;Change it to "unsigned long" anyway to match the clock framework. In theory maybe the "xfer" structure will be updated eventually.
Ok. WIll update it
Quoted 11 lines
Quoted 10 lines
Is it possible for all three conditions above to happen in one interrupt? I ask because 'ret' is overwritten and so what may have been
IRQ_HANDLEDmay becomeIRQ_NONEwhich will lead to confusion in the irq layer. Maybe the handle tx/rx functions can return a bool, that gets orred together each time so that we know if something handled an interrupt?Will check it again by running fullduplex transfer and update.
Added the changes in V5 to ensure return value doesn't get overwritten.
--Dilip
PATCH v4 4/4 spi: spi-geni-qcom: Plugin API to assert and de-assert Chipselect
In reply to Dilip KotaPlugin set cs API to the SPI framework so that
framework can do chipselect assert de-assert
during SPI transfers.
--- drivers/spi/spi-geni-qcom.c | 65 ++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-)
drivers/spi/spi-geni-qcom.c +46 -19
@@ -66,6 +66,13 @@static irqreturn_t geni_spi_isr (int irq,void *data); +/* SPI M_COMMAND OPCODE */ +enum spi_mcmd_code { +CMD_NONE , +CMD_XFER , +CMD_CS , +}; +struct spi_geni_master {struct geni_se se;struct device *dev;
@@ -81,8 +88,12 @@ struct spi_geni_master {struct completion xfer_done;unsigned int oversampling;spinlock_t lock; +unsigned int cur_mcmd; }; +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,
@@ -113,6 +124,31 @@ static int get_spi_clk_cfg(unsigned int speed_hz,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); +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 ); +if (!timeout) +handle_fifo_timeout (spi,NULL ); + +pm_runtime_put (mas->dev); +} +static void spi_setup_word_len (struct spi_geni_master *mas,u16 mode,unsigned int bits_per_word) {
@@ -249,7 +285,7 @@ static void setup_fifo_xfer(struct spi_transfer *xfer,struct spi_geni_master *mas, u16 mode, struct spi_master *spi) { - u32 m_cmd = 0, m_param = 0; + u32 m_cmd = 0;u32 spi_tx_cfg, trans_len;struct geni_se *se = &mas->se;
@@ -305,21 +341,7 @@ static void setup_fifo_xfer(struct spi_transfer *xfer, trans_len = (xfer->len / bytes_per_word) &TRANS_LEN_MSK ; } -/* -* If CS change flag is set, then toggle the CS line in between -* transfers and keep CS asserted after the last transfer. -* Else if keep CS flag asserted in between transfers and de-assert -* CS after the last message. -*/ -if (xfer->cs_change) { -if (list_is_last (&xfer->transfer_list, - &spi->cur_msg->transfers)) - m_param =FRAGMENTATION ; - }else { -if (!list_is_last (&xfer->transfer_list, - &spi->cur_msg->transfers)) - m_param =FRAGMENTATION ; - } + mas->cur_xfer = xfer;if (m_cmd &SPI_TX_ONLY ) {
@@ -332,8 +354,8 @@ static void setup_fifo_xfer(struct spi_transfer *xfer, mas->rx_rem_bytes = xfer->len; }writel (spi_tx_cfg, se->base +SE_SPI_TRANS_CFG ); -geni_se_setup_m_cmd (se, m_cmd, m_param); - + mas->cur_mcmd =CMD_XFER ; +geni_se_setup_m_cmd (se, m_cmd,FRAGMENTATION );/* * TX_WATERMARK_REG should be set after SPI configuration and * setting up GENI SE engine, as driver starts data transfer
@@ -489,7 +511,11 @@ static irqreturn_t geni_spi_isr(int irq, void *data) ret =geni_spi_handle_tx (mas);if (m_irq &M_CMD_DONE_EN ) { -spi_finalize_current_transfer (spi); +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
@@ -572,6 +598,7 @@ static int spi_geni_probe(struct platform_device *pdev) 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);
Signature · 3 lines
Qualcomm Datacenter Technologies as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
Re: [PATCH V4 4/4] spi: spi-geni-qcom: Plugin API to assert and de-assert Chipselect
Hi,
Quoted 9 lines · Dilip Kota
Plugin set cs API to the SPI framework so that
framework can do chipselect assert de-assert
during SPI transfers.Signed-off-by Dilip Kota <[email protected]>--- drivers/spi/spi-geni-qcom.c | 65 ++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 19 deletions(-)
As I mentioned in out-of-band I don't see a huge reason why this can't be squashed into patch #3. Logically patch #3 has a bug where it can't handle setting the chip select without a non-zero transfer and that bug isn't fixed until patch #4. ...but if folks really feel like it should be a separate patch then I won't object too loudly since the end result is the same.
...so feel free to add:
-Doug