Skip to contentSkip to conversation

Add spi control driver for Sunplus SP7021 SoC

PATCH Superseded Li-hao Kuo 5 participants 13 messages Jan 18, 2022 – Jan 27, 2022

Subsystems (3)

v6 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Li-hao Kuo

author maintainer
#0 lore raw

v6 cover Add spi control driver for Sunplus SP7021 SoC

This is a patch series for SPI driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

Li-hao Kuo (2):
spi: Add spi driver for Sunplus SP7021
dt-bindings:spi: Add Sunplus SP7021 schema

 .../bindings/spi/spi-sunplus-sp7021.yaml           |  81 +++
 MAINTAINERS                                        |   7 +
 drivers/spi/Kconfig                                |  11 +
 drivers/spi/Makefile                               |   1 +
 drivers/spi/spi-sunplus-sp7021.c                   | 602 +++++++++++++++++++++
 5 files changed, 702 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml
 create mode 100644 drivers/spi/spi-sunplus-sp7021.c
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH v6 1/2 spi: Add spi driver for Sunplus SP7021

Add spi driver for Sunplus SP7021.

---
Changes in v6:
- Change the interrupt-names
mas_risc to master_risc
- Addressed comments from Mr. Andy Shevchenko
Change the function name: mas is master and sla is slave.
Add temporary varilable (as suggested by Mr. Andy Shevchenko)
Modify clk setting
Modify the master-slave detection of the probe function.(as suggested by Mr. Andy Shevchenko) Modify the return value of the probe function.(as suggested by Mr. Andy Shevchenko) Change GPL version(as suggested by Mr. Andy Shevchenko)

 MAINTAINERS                      |   6 +
 drivers/spi/Kconfig              |  11 +
 drivers/spi/Makefile             |   1 +
 drivers/spi/spi-sunplus-sp7021.c | 602 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 620 insertions(+)
 create mode 100644 drivers/spi/spi-sunplus-sp7021.c
MAINTAINERS +6 -0
index a58544f..a07da20 100644
@@ -18493,6 +18493,12 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/net/ethernet/dlink/sundance.c
 
+SUNPLUS SPI CONTROLLER INTERFACE DRIVER
+M:	Li-hao Kuo <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/spi/spi-sunplus-sp7021.c
+
 SUPERH
 M:	Yoshinori Sato <[email protected]>
 M:	Rich Felker <[email protected]>
drivers/spi/Kconfig +11 -0
index b2a8821..203f4ec 100644
@@ -866,6 +866,17 @@ config SPI_SUN6I
 	help
 	  This enables using the SPI controller on the Allwinner A31 SoCs.
 
+config SPI_SUNPLUS_SP7021
+	tristate "Sunplus SP7021 SPI controller"
+	depends on SOC_SP7021 || COMPILE_TEST
+	help
+	  This enables Sunplus SP7021 SPI controller driver on the SP7021 SoCs.
+	  This driver can also be built as a module. If so, the module will be
+	  called as spi-sunplus-sp7021.
+
+	  If you have a  Sunplus SP7021 platform say Y here.
+	  If unsure, say N.
+
 config SPI_SYNQUACER
 	tristate "Socionext's SynQuacer HighSpeed SPI controller"
 	depends on ARCH_SYNQUACER || COMPILE_TEST
drivers/spi/Makefile +1 -0
index dd7393a..b455eaf 100644
@@ -119,6 +119,7 @@ obj-$(CONFIG_SPI_STM32_QSPI) 		+= spi-stm32-qspi.o
 obj-$(CONFIG_SPI_ST_SSC4)		+= spi-st-ssc4.o
 obj-$(CONFIG_SPI_SUN4I)			+= spi-sun4i.o
 obj-$(CONFIG_SPI_SUN6I)			+= spi-sun6i.o
+obj-$(CONFIG_SPI_SUNPLUS_SP7021)	+= spi-sunplus-sp7021.o
 obj-$(CONFIG_SPI_SYNQUACER)		+= spi-synquacer.o
 obj-$(CONFIG_SPI_TEGRA210_QUAD)		+= spi-tegra210-quad.o
 obj-$(CONFIG_SPI_TEGRA114)		+= spi-tegra114.o
drivers/spi/spi-sunplus-sp7021.c new file +602 -0

602 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

On Tue, Jan 18, 2022 at 04:42:38PM +0800, Li-hao Kuo wrote:

Looks mostly good - a couple of small nits below but nothing major.

drivers/spi/spi-sunplus-sp7021.c line 322

Quoted 6 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+static int sp7021_spi_master_transfer_one(struct spi_controller *ctlr, struct spi_device *spi,
+				       struct spi_transfer *xfer)
+{
 
+	for (i = 0; i <= xfer_cnt; i++) {
+		mutex_lock(&pspim->buf_lock);

This lock is redundant: it is only ever held in this function which is guaranteed by the core to never be called twice concurrently.

drivers/spi/spi-sunplus-sp7021.c line 498

Quoted 9 lines
drivers/spi/spi-sunplus-sp7021.c new file +9 -0
+	ret = devm_request_irq(dev, pspim->m_irq, sp7021_spi_master_irq,
+			       IRQF_TRIGGER_RISING, pdev->name, pspim);
+	if (ret)
+		return ret;
+
+	ret = devm_request_irq(dev, pspim->s_irq, sp7021_spi_slave_irq,
+			       IRQF_TRIGGER_RISING, pdev->name, pspim);
+	if (ret)
+		return ret;

Are you sure the driver is ready to handle interrupts without any of the other resources? Normally interrupts are one of the last things to be requested.

#3 lore raw

RE: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

Hi Mr. Mark Brown :

Thanks for your comment, I will modify it in next next submission

Quoted 6 lines

drivers/spi/spi-sunplus-sp7021.c line 322

Quoted 3 lines
drivers/spi/spi-sunplus-sp7021.c new file +2 -0
+	for (i = 0; i <= xfer_cnt; i++) {
+		mutex_lock(&pspim->buf_lock);

This lock is redundant: it is only ever held in this function which is guaranteed by the core to never be called twice concurrently.

I will modify it in next next submission

Quoted 4 lines
Quoted 4 lines
drivers/spi/spi-sunplus-sp7021.c new file +4 -0
+	ret = devm_request_irq(dev, pspim->m_irq, sp7021_spi_master_irq,
+			       IRQF_TRIGGER_RISING, pdev->name, pspim);
+	if (ret)
+		return ret;
Quoted 8 lines

drivers/spi/spi-sunplus-sp7021.c line 498

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+
+	ret = devm_request_irq(dev, pspim->s_irq, sp7021_spi_slave_irq,
+			       IRQF_TRIGGER_RISING, pdev->name, pspim);
+	if (ret)
+		return ret;

Are you sure the driver is ready to handle interrupts without any of the other resources? Normally interrupts are one of the last things to be requested.

I will modify it in next next submission

#4 lore raw

Re: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

In reply to Li-hao Kuo
Quoted 2 lines · Li-hao Kuo

Add spi driver for Sunplus SP7021.

...

Quoted 1 line

Changes in v6:

Thanks for update, my comments below.

...

Quoted 11 lines
drivers/spi/spi-sunplus-sp7021.c new file +11 -0
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/reset.h>
+#include <linux/spi/spi.h>

...

drivers/spi/spi-sunplus-sp7021.c line 113

Quoted 2 lines
drivers/spi/spi-sunplus-sp7021.c new file +2 -0
+       data_status = readl(pspim->s_base + SP7021_DATA_RDY_REG);
+       writel(data_status | SP7021_SLAVE_CLR_INT, pspim->s_base + SP7021_DATA_RDY_REG);

Wouldn't be

       data_status = readl(pspim->s_base + SP7021_DATA_RDY_REG);
       data_status |= SP7021_SLAVE_CLR_INT;
       writel(data_status, pspim->s_base + SP7021_DATA_RDY_REG);

better to read? Same question to other places like this.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+       writel(SP7021_SLAVE_DMA_EN | SP7021_SLAVE_DMA_RW | FIELD_PREP(SP7021_SLAVE_DMA_CMD, 3),
+              pspim->s_base + SP7021_SLAVE_DMA_CTRL_REG);

Temporary variable?
var = ...

...

drivers/spi/spi-sunplus-sp7021.c line 137

Quoted 2 lines
drivers/spi/spi-sunplus-sp7021.c new file +2 -0
+       writel(readl(pspim->s_base + SP7021_DATA_RDY_REG) | SP7021_SLAVE_DATA_RDY,
+              pspim->s_base + SP7021_DATA_RDY_REG);

Ditto.

...

drivers/spi/spi-sunplus-sp7021.c line 148

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +4 -0
+int sp7021_spi_slave_rx(struct spi_device *spi, struct spi_transfer *xfer)
+{
+       struct sp7021_spi_ctlr *pspim = spi_controller_get_devdata(spi->controller);
 
+       int ret = 0;

Unused.

...

drivers/spi/spi-sunplus-sp7021.c line 152

Quoted 2 lines
drivers/spi/spi-sunplus-sp7021.c new file +2 -0
+       writel(SP7021_SLAVE_DMA_EN | FIELD_PREP(SP7021_SLAVE_DMA_CMD, 3),
+              pspim->s_base + SP7021_SLAVE_DMA_CTRL_REG);

Temporary variable?

...

drivers/spi/spi-sunplus-sp7021.c line 191

Quoted 8 lines
drivers/spi/spi-sunplus-sp7021.c new file +7 -0
+static irqreturn_t sp7021_spi_master_irq(int irq, void *dev)
+{
+       struct sp7021_spi_ctlr *pspim = dev;
+       unsigned int tx_cnt, total_len;
+       unsigned int tx_len, rx_cnt;
+       unsigned int fd_status;
 
+       unsigned long flags;

Why do you need this?

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +4 -0
+       bool isrdone = false;
+       u32 value;
 
+       return IRQ_HANDLED;
+}

...

drivers/spi/spi-sunplus-sp7021.c line 301

Quoted 3 lines
drivers/spi/spi-sunplus-sp7021.c new file +3 -0
+       div = clk_rate / xfer->speed_hz;
+       if (div < 2)
+               div = 2;

div = max(2U, clk_rate / xfer->speed_hz); ?

...

drivers/spi/spi-sunplus-sp7021.c line 316

Quoted 10 lines
drivers/spi/spi-sunplus-sp7021.c new file +9 -0
+static int sp7021_spi_master_transfer_one(struct spi_controller *ctlr, struct spi_device *spi,
+                                      struct spi_transfer *xfer)
+{
+       struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr);
+       unsigned long timeout = msecs_to_jiffies(1000);
+       unsigned int xfer_cnt, xfer_len, last_len;
+       unsigned int i, len_temp;
+       u32 reg_temp;
 
+       int ret;

Seems redundant.

Quoted 54 lines
drivers/spi/spi-sunplus-sp7021.c new file +53 -0
+       xfer_cnt = xfer->len / SP7021_SPI_DATA_SIZE;
+       last_len = xfer->len % SP7021_SPI_DATA_SIZE;
+
+       for (i = 0; i <= xfer_cnt; i++) {
+               mutex_lock(&pspim->buf_lock);
+               sp7021_prep_transfer(ctlr, spi);
+               sp7021_spi_setup_clk(ctlr, xfer);
+               reinit_completion(&pspim->isr_done);
 
+               if (i == xfer_cnt)
+                       xfer_len = last_len;
+               else
+                       xfer_len = SP7021_SPI_DATA_SIZE;
+
+               pspim->tx_buf = xfer->tx_buf + i * SP7021_SPI_DATA_SIZE;
+               pspim->rx_buf = xfer->rx_buf + i * SP7021_SPI_DATA_SIZE;
+
+               if (pspim->tx_cur_len < xfer_len) {
+                       len_temp = min(pspim->data_unit, xfer_len);
+                       sp7021_spi_master_wb(pspim, len_temp);
+               }
+               reg_temp = readl(pspim->m_base + SP7021_SPI_CONFIG_REG);
+               reg_temp &= ~SP7021_CLEAN_RW_BYTE;
+               reg_temp &= ~SP7021_CLEAN_FLUG_MASK;
+               reg_temp |= SP7021_FD_SEL | SP7021_FINISH_FLAG_MASK |
+                           SP7021_TX_EMP_FLAG_MASK | SP7021_RX_FULL_FLAG_MASK |
+                           FIELD_PREP(SP7021_TX_UNIT, 0) | FIELD_PREP(SP7021_RX_UNIT, 0);
+               writel(reg_temp, pspim->m_base + SP7021_SPI_CONFIG_REG);
+
+               reg_temp = FIELD_PREP(SP7021_SET_TX_LEN, xfer_len) |
+                                     FIELD_PREP(SP7021_SET_XFER_LEN, xfer_len) |
+                                     SP7021_SPI_START_FD;
+               writel(reg_temp, pspim->m_base + SP7021_SPI_STATUS_REG);
+
+               if (!wait_for_completion_interruptible_timeout(&pspim->isr_done, timeout)) {
+                       dev_err(&spi->dev, "wait_for_completion err\n");
+                       return -ETIMEDOUT;
+               }
+
+               reg_temp = readl(pspim->m_base + SP7021_SPI_STATUS_REG);
+               if (reg_temp & SP7021_FINISH_FLAG) {
+                       writel(SP7021_FINISH_FLAG, pspim->m_base + SP7021_SPI_STATUS_REG);
+                       writel(readl(pspim->m_base + SP7021_SPI_CONFIG_REG) &
+                               SP7021_CLEAN_FLUG_MASK, pspim->m_base + SP7021_SPI_CONFIG_REG);
+               }
+
+               if (pspim->xfer_conf & SP7021_CPOL_FD)
+                       writel(pspim->xfer_conf, pspim->m_base + SP7021_SPI_CONFIG_REG);
+
+               mutex_unlock(&pspim->buf_lock);
+               ret = 0;
+       }
+       return ret;
+}

...

drivers/spi/spi-sunplus-sp7021.c line 378

Quoted 7 lines
drivers/spi/spi-sunplus-sp7021.c new file +6 -0
+static int sp7021_spi_slave_transfer_one(struct spi_controller *ctlr, struct spi_device *spi,
+                                      struct spi_transfer *xfer)
+{
+       struct sp7021_spi_ctlr *pspim = spi_master_get_devdata(ctlr);
+       struct device *dev = pspim->dev;
 
+       int mode, ret = 0;

ret assignment can be moved to the default case below, where it will naturally fit.

drivers/spi/spi-sunplus-sp7021.c line 383

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +4 -0
+       mode = SP7021_SPI_IDLE;
 
+       if (xfer->tx_buf && xfer->rx_buf) {
+               dev_dbg(&ctlr->dev, "%s() wrong command\n", __func__);
+               ret = -EINVAL;

Do you need this check if you properly set the capabilities of the controller? If still needed, why not return here?

Quoted 18 lines
drivers/spi/spi-sunplus-sp7021.c new file +18 -0
+       } else if (xfer->tx_buf) {
+               xfer->tx_dma = dma_map_single(dev, (void *)xfer->tx_buf,
+                                             xfer->len, DMA_TO_DEVICE);
+               if (dma_mapping_error(dev, xfer->tx_dma))
+                       return -ENOMEM;
+               mode = SP7021_SLAVE_WRITE;
+       } else if (xfer->rx_buf) {
+               xfer->rx_dma = dma_map_single(dev, xfer->rx_buf, xfer->len,
+                                             DMA_FROM_DEVICE);
+               if (dma_mapping_error(dev, xfer->rx_dma))
+                       return -ENOMEM;
+               mode = SP7021_SLAVE_READ;
+       }
+
+       switch (mode) {
+       case SP7021_SLAVE_WRITE:
+               ret = sp7021_spi_slave_tx(spi, xfer);
+               break;

drivers/spi/spi-sunplus-sp7021.c line 411

Quoted 10 lines
drivers/spi/spi-sunplus-sp7021.c new file +10 -0
+       case SP7021_SLAVE_READ:
+               ret = sp7021_spi_slave_rx(spi, xfer);
+               break;
+       default:
+               break;
+       }
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len, DMA_FROM_DEVICE);

Why can't you use SPI core DMA mapping code?

Quoted 3 lines
drivers/spi/spi-sunplus-sp7021.c new file +3 -0
+       spi_finalize_current_transfer(ctlr);
+       return ret;
+}

...

Quoted 1 line

+ device_set_node(&ctlr->dev, pdev->dev.fwnode);

Use dev_fwnode() in the second argument.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

RE: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

Hi Andy Shevchenko :

Thanks for your comment, I have some questions as below.

Quoted 7 lines

drivers/spi/spi-sunplus-sp7021.c

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len,
+ DMA_FROM_DEVICE);

Why can't you use SPI core DMA mapping code?

I didn't find the SPI core DMA mapping code for single maping. The method currently used is the general DMA single-map code usage method.

Quoted 5 lines
Quoted 2 lines

+ device_set_node(&ctlr->dev, pdev->dev.fwnode);

Use dev_fwnode() in the second argument.

You mean as below ?

device_set_node(&ctlr->dev, dev_fwnode(dev));

Best Regards,
Li-hao Kuo

#6 lore raw

Re: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

On Thu, Jan 20, 2022 at 11:22 AM Lh Kuo 郭力豪 <[email protected]> wrote:

...

Quoted 10 lines
Quoted 7 lines

drivers/spi/spi-sunplus-sp7021.c

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len,
+ DMA_FROM_DEVICE);

Why can't you use SPI core DMA mapping code?

I didn't find the SPI core DMA mapping code for single maping. The method currently used is the general DMA single-map code usage method.

Why do you need single page mapping?
What's wrong with SG mapping that SPI core provides?

...

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

+ device_set_node(&ctlr->dev, pdev->dev.fwnode);

Use dev_fwnode() in the second argument.

You mean as below ?

device_set_node(&ctlr->dev, dev_fwnode(dev));

Yes.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw

RE: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len,
+ DMA_FROM_DEVICE);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Why can't you use SPI core DMA mapping code?

I didn't find the SPI core DMA mapping code for single maping. The method currently used is the general DMA single-map code usage method.

Why do you need single page mapping?
What's wrong with SG mapping that SPI core provides?

SP7021 SPI slave dma only supports single dma in one trigger. It is not suitable for using SG mapping.
If the length of the transfer is larger than the length of the SG-mapping, Slave-mode will get error in the transfer.

#8 lore raw

Re: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

Quoted 12 lines · Lh Kuo 郭力豪
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

drivers/spi/spi-sunplus-sp7021.c

Quoted 6 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len,
+ DMA_FROM_DEVICE);

Why can't you use SPI core DMA mapping code?

I didn't find the SPI core DMA mapping code for single maping. The method currently used is the general DMA single-map code usage method.

Quoted 7 lines
Quoted 2 lines

Why do you need single page mapping?
What's wrong with SG mapping that SPI core provides?

SP7021 SPI slave dma only supports single dma in one trigger. It is not suitable for using SG mapping.
If the length of the transfer is larger than the length of the SG-mapping, Slave-mode will get error in the transfer.

Same story for SPI DesignWare on Intel Medfield, where no SG transfers are supported by hardware. Nevertheless, the DMA driver takes care of this and on each interrupt recharges a channel to continue. Why can't the same be implemented here?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw

RE: [PATCH v6 1/2] spi: Add spi driver for Sunplus SP7021

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 10 lines
Quoted 7 lines

drivers/spi/spi-sunplus-sp7021.c

Quoted 5 lines
drivers/spi/spi-sunplus-sp7021.c new file +5 -0
+       if (xfer->tx_buf)
+               dma_unmap_single(dev, xfer->tx_dma, xfer->len, DMA_TO_DEVICE);
+       if (xfer->rx_buf)
+               dma_unmap_single(dev, xfer->rx_dma, xfer->len,
+ DMA_FROM_DEVICE);

Why can't you use SPI core DMA mapping code?

I didn't find the SPI core DMA mapping code for single maping. The method currently used is the general DMA single-map code usage method.

Why do you need single page mapping?
What's wrong with SG mapping that SPI core provides?

Quoted 10 lines
Quoted 4 lines

SP7021 SPI slave dma only supports single dma in one trigger. It is not suitable for using SG mapping.
If the length of the transfer is larger than the length of the SG-mapping, Slave-mode will get error in the transfer.

Same story for SPI DesignWare on Intel Medfield, where no SG transfers are supported by hardware. Nevertheless, the DMA driver takes care of this and on each interrupt recharges a channel to continue. Why can't the same be implemented here?

I think it should work in master. spi master must actively send clk and date to slave device.
And yes, in the "master" mode it can handle SG-DMA on each interrupt.
But if working in "slave" mode, the master will not know the state of the slave. Slaves work on interrupt and recharge channels. When master send clk and date in the same time. It may lose data and errors occur

author maintainer
#10 lore raw

PATCH v6 2/2 dt-bindings:spi: Add Sunplus SP7021 schema

In reply to Li-hao Kuo

Add bindings for Sunplus SP7021 spi driver

---
Changes in v6:
- Change the interrupt-names
mas_risc to master_risc
- Addressed comments from Mr. Andy Shevchenko
Change the function name: mas is master and sla is slave.
Add temporary varilable (as suggested by Mr. Andy Shevchenko)
Modify clk setting
Modify the master-slave detection of the probe function.(as suggested by Mr. Andy Shevchenko) Modify the return value of the probe function.(as suggested by Mr. Andy Shevchenko) Change GPL version(as suggested by Mr. Andy Shevchenko)

 .../bindings/spi/spi-sunplus-sp7021.yaml           | 81 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml
Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml new file +81 -0
new file mode 100644
index 0000000..24382cd
@@ -0,0 +1,81 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+# Copyright (C) Sunplus Co., Ltd. 2021
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/spi/spi-sunplus-sp7021.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sunplus sp7021 SPI controller
+
+allOf:
+  - $ref: "spi-controller.yaml"
+
+maintainers:
+  - Li-hao Kuo <[email protected]>
+
+properties:
+  compatible:
+    enum:
+      - sunplus,sp7021-spi
+
+  reg:
+    items:
+      - the SPI master registers
+      - the SPI slave registers
+
+  reg-names:
+    items:
+      - const: master
+      - const: slave
+
+  interrupt-names:
+    items:
+      - const: dma_w
+      - const: master_risc
+      - const: slave_risc
+
+  interrupts:
+    minItems: 3
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - interrupt-names
+  - clocks
+  - clocks-names
+  - resets
+  - pinctrl-names
+  - pinctrl-0
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/sp-sp7021.h>
+    #include <dt-bindings/reset/sp-sp7021.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    spi@9C002D80 {
+        compatible = "sunplus,sp7021-spi";
+        reg = <0x9C002D80 0x80>, <0x9C002E00 0x80>;
+        reg-names = "master", "slave";
+        interrupt-parent = <&intc>;
+        interrupt-names = "dma_w",
+                          "master_risc",
+                          "slave_risc";
+        interrupts = <144 IRQ_TYPE_LEVEL_HIGH>,
+                     <146 IRQ_TYPE_LEVEL_HIGH>,
+                     <145 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&clkc SPI_COMBO_0>;
+        resets = <&rstc RST_SPI_COMBO_0>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&pins_spi0>;
+    };
+...
MAINTAINERS +1 -0
index a07da20..2e14650 100644
@@ -18497,6 +18497,7 @@ SUNPLUS SPI CONTROLLER INTERFACE DRIVER
 M:	Li-hao Kuo <[email protected]>
 L:	[email protected]
 S:	Maintained
+F:	Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml
 F:	drivers/spi/spi-sunplus-sp7021.c
 
 SUPERH
Signature · 1 line
2.7.4
#11 lore raw

Re: [PATCH v6 2/2] dt-bindings:spi: Add Sunplus SP7021 schema

Quoted 16 lines · Li-hao Kuo

Add bindings for Sunplus SP7021 spi driver

---
Changes in v6:
- Change the interrupt-names
mas_risc to master_risc
- Addressed comments from Mr. Andy Shevchenko
Change the function name: mas is master and sla is slave.
Add temporary varilable (as suggested by Mr. Andy Shevchenko)
Modify clk setting
Modify the master-slave detection of the probe function.(as suggested by Mr. Andy Shevchenko) Modify the return value of the probe function.(as suggested by Mr. Andy Shevchenko) Change GPL version(as suggested by Mr. Andy Shevchenko)

Quoted 4 lines
 .../bindings/spi/spi-sunplus-sp7021.yaml           | 81 ++++++++++++++++++++++
 MAINTAINERS                                        |  1 +
 2 files changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml

This is now failing in linux-next, please fix:

/builds/robherring/linux-dt/Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml:
properties:reg:items: 'anyOf' conditional failed, one must be fixed:
['the SPI master registers', 'the SPI slave registers'] is not of
type 'object', 'boolean'
'the SPI master registers' is not of type 'object', 'boolean'
'the SPI slave registers' is not of type 'object', 'boolean'
from schema $id: http://json-schema.org/draft-07/schema#
/builds/robherring/linux-dt/Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.yaml:
ignoring, error in schema: properties: reg: items Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.example.dts:19:18:
fatal error: dt-bindings/clock/sp-sp7021.h: No such file or directory
19 | #include <dt-bindings/clock/sp-sp7021.h>

    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compilation terminated.
make[1]: *** [scripts/Makefile.lib:390:
Documentation/devicetree/bindings/spi/spi-sunplus-sp7021.example.dt.yaml] Error 1

maintainer
#12 lore raw
In reply to Li-hao Kuo
Quoted 11 lines · Li-hao Kuo

This is a patch series for SPI driver for Sunplus SP7021 SoC.

Sunplus SP7021 is an ARM Cortex A7 (4 cores) based SoC. It integrates many peripherals (ex: UART, I2C, SPI, SDIO, eMMC, USB, SD card and etc.) into a single chip. It is designed for industrial control.

Refer to:
https://sunplus-tibbo.atlassian.net/wiki/spaces/doc/overview
https://tibbo.com/store/plus1.html

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/2] spi: Add spi driver for Sunplus SP7021

      commit: f62ca4e2a863033d9b3b5a00a0d897557c9da6c5

[2/2] dt-bindings:spi: Add Sunplus SP7021 schema
(no commit info)

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark