Skip to contentSkip to conversation

spi: Add Renesas R-Car Gen3 RPC SPI driver

PATCH Superseded Mason Yang 4 participants 33 messages Dec 3, 2018 – Dec 22, 2018 1 message not in the archive

Subsystems (2)

v2 of 17 Superseded Latest is v17 →

lore
Share & tools
lore

Mason Yang

author
#0 lore raw

v2 cover spi: Add Renesas R-Car Gen3 RPC SPI driver

Hi Mark,

This Renesas R-Car Gen3 RPC SPI driver is based on Boris's new spi-mem direct mapping read/write mode [1][2] and v2 patch is from Marek and Geert's comments including RPC clock control, run time PM, RPC module software reset, regmap and so on.

thanks for your review.

best regards,
Mason

[1] https://patchwork.kernel.org/patch/10670753
[2] https://patchwork.kernel.org/patch/10670747

Mason Yang (2):
spi: Add Renesas R-Car Gen3 RPC SPI controller driver
dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

 .../devicetree/bindings/spi/spi-renesas-rpc.txt    |  35 +
 drivers/spi/Kconfig                                |   6 +
 drivers/spi/Makefile                               |   1 +
 drivers/spi/spi-renesas-rpc.c                      | 808 +++++++++++++++++++++
 4 files changed, 850 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt
 create mode 100644 drivers/spi/spi-renesas-rpc.c
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 1/2 spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

---
 drivers/spi/Kconfig           |   6 +
 drivers/spi/Makefile          |   1 +
 drivers/spi/spi-renesas-rpc.c | 808 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 815 insertions(+)
 create mode 100644 drivers/spi/spi-renesas-rpc.c
drivers/spi/Kconfig +6 -0
index 7d3a5c9..8f826fe 100644
@@ -528,6 +528,12 @@ config SPI_RSPI
 	help
 	  SPI driver for Renesas RSPI and QSPI blocks.
 
+config SPI_RENESAS_RPC
+	tristate "Renesas R-Car Gen3 RPC SPI controller"
+	depends on SUPERH || ARCH_RENESAS || COMPILE_TEST
+	help
+	  SPI driver for Renesas R-Car Gen3 RPC.
+
 config SPI_QCOM_QSPI
 	tristate "QTI QSPI controller"
 	depends on ARCH_QCOM
drivers/spi/Makefile +1 -0
index 3575205..5d5c523 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_SPI_QUP)			+= spi-qup.o
 obj-$(CONFIG_SPI_ROCKCHIP)		+= spi-rockchip.o
 obj-$(CONFIG_SPI_RB4XX)			+= spi-rb4xx.o
 obj-$(CONFIG_SPI_RSPI)			+= spi-rspi.o
+obj-$(CONFIG_SPI_RENESAS_RPC)		+= spi-renesas-rpc.o
 obj-$(CONFIG_SPI_S3C24XX)		+= spi-s3c24xx-hw.o
 spi-s3c24xx-hw-y			:= spi-s3c24xx.o
 spi-s3c24xx-hw-$(CONFIG_SPI_S3C24XX_FIQ) += spi-s3c24xx-fiq.o
drivers/spi/spi-renesas-rpc.c new file +808 -0

808 lines not on this page · raw message

Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

What changed in this V2 ?

[...]

drivers/spi/spi-renesas-rpc.c line 153

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+struct rpc_spi {
+	struct clk *clk_rpc;
+	void __iomem *base;
+	struct {
+		void __iomem *map;
+		dma_addr_t dma;
+		size_t size;
+	} linear;

This is still here, see my review comments on the previous version.

Quoted 29 lines
drivers/spi/spi-renesas-rpc.c new file +29 -0
+	struct regmap *regmap;
+	u32 cur_speed_hz;
+	u32 cmd;
+	u32 addr;
+	u32 dummy;
+	u32 smcr;
+	u32 smenr;
+	u32 xferlen;
+	u32 totalxferlen;
+	enum spi_mem_data_dir xfer_dir;
+#ifdef CONFIG_RESET_CONTROLLER
+	struct reset_control *rstc;
+#endif
+};
+
+static int rpc_spi_set_freq(struct rpc_spi *rpc, unsigned long freq)
+{
+	int ret;
+
+	if (rpc->cur_speed_hz == freq)
+		return 0;
+
+	ret = clk_set_rate(rpc->clk_rpc, freq);
+	if (ret)
+		return ret;
+
+	rpc->cur_speed_hz = freq;
+	return ret;
+}

drivers/spi/spi-renesas-rpc.c line 192

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+	/*
+	 * NOTE: The 0x260 are undocumented bits, but they must be set.
+	 *	RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+	 *	0x0 : the delay is biggest,
+	 *	0x1 : the delay is 2nd biggest,
+	 *	0x3 or 0x6 is a recommended value.
+	 */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+				  RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
+	/*
+	 * NOTE: The 0x31511144 and 0x431 are undocumented bits,

drivers/spi/spi-renesas-rpc.c line 207

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	 *	 but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+	 */
+	regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+	regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);
+
+	regmap_write(rpc->regmap, RPC_SSLDR, RPC_SSLDR_SPNDL(7) |
+				  RPC_SSLDR_SLNDL(7) | RPC_SSLDR_SCKDL(7));
+}
+
+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

Quoted 26 lines
drivers/spi/spi-renesas-rpc.c new file +26 -0
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+	int i, ret;
+
+	ret = reset_control_reset(rpc->rstc);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < LOOP_TIMEOUT; i++) {
+		ret = reset_control_status(rpc->rstc);
+		if (ret == 0)
+			return 0;
+		usleep_range(0, 1);
+	}
+
+	return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+	return -ETIMEDOUT;
+}
+#endif
+
+static int wait_msg_xfer_end(struct rpc_spi *rpc)
+{

drivers/spi/spi-renesas-rpc.c line 243

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	u32 sts;
+
+	return regmap_read_poll_timeout(rpc->regmap, RPC_CMNSR, sts,
+					sts & RPC_CMNSR_TEND, 0, USEC_PER_SEC);
+}
+
+static u8 rpc_bits_xfer(u32 nbytes)
+{
+	if (nbytes > 4)
+		nbytes = 4;

Use clamp() ?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+	return GENMASK(3, 4 - nbytes);

Nice ;-)

Quoted 14 lines
drivers/spi/spi-renesas-rpc.c new file +14 -0
+}
+
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+			   const void *tx_buf, void *rx_buf)
+{
+	u32 smenr, smcr, data, pos = 0;
+	int ret = 0;
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+				  RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+				  RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+	regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);

drivers/spi/spi-renesas-rpc.c line 269

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+	if (tx_buf) {
+		smenr = rpc->smenr;
+
+		while (pos < rpc->xferlen) {
+			u32 nbytes = rpc->xferlen  - pos;
+
+			regmap_write(rpc->regmap, RPC_SMWDR0,
+				     *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 89 lines
drivers/spi/spi-renesas-rpc.c new file +89 -0
+			if (nbytes > 4) {
+				nbytes = 4;
+				smcr = rpc->smcr |
+				       RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+			} else {
+				smcr = rpc->smcr | RPC_SMCR_SPIE;
+			}
+
+			regmap_write(rpc->regmap, RPC_SMENR, smenr);
+			regmap_write(rpc->regmap, RPC_SMCR, smcr);
+			ret = wait_msg_xfer_end(rpc);
+			if (ret)
+				goto out;
+
+			pos += nbytes;
+			smenr = rpc->smenr & ~RPC_SMENR_CDE &
+					     ~RPC_SMENR_ADE(0xf);
+		}
+	} else if (rx_buf) {
+		while (pos < rpc->xferlen) {
+			u32 nbytes = rpc->xferlen  - pos;
+
+			if (nbytes > 4)
+				nbytes = 4;
+
+			regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+			regmap_write(rpc->regmap, RPC_SMCR,
+				     rpc->smcr | RPC_SMCR_SPIE);
+			ret = wait_msg_xfer_end(rpc);
+			if (ret)
+				goto out;
+
+			regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+			memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);
+			pos += nbytes;
+			regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+			regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+			regmap_write(rpc->regmap, RPC_SMADR, rpc->addr + pos);
+		}
+	} else {
+		regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+		regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+		ret = wait_msg_xfer_end(rpc);
+		if (ret)
+			goto out;
+	}
+
+	return ret;
+out:
+	return rpc_spi_do_reset(rpc);
+}
+
+static void rpc_spi_mem_set_prep_op_cfg(struct spi_device *spi,
+					const struct spi_mem_op *op,
+					u64 *offs, size_t *len)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(spi->master);
+
+	rpc->cmd = RPC_SMCMR_CMD(op->cmd.opcode);
+	rpc->smenr = RPC_SMENR_CDE |
+		     RPC_SMENR_CDB(fls(op->cmd.buswidth >> 1));
+	rpc->totalxferlen = 1;
+	rpc->xfer_dir = SPI_MEM_NO_DATA;
+	rpc->xferlen = 0;
+	rpc->addr = 0;
+
+	if (op->addr.nbytes) {
+		rpc->smenr |= RPC_SMENR_ADB(fls(op->addr.buswidth >> 1));
+		if (op->addr.nbytes == 4)
+			rpc->smenr |= RPC_SMENR_ADE(0xf);
+		else
+			rpc->smenr |= RPC_SMENR_ADE(0x7);
+
+		if (offs && len)
+			rpc->addr = *(u32 *)offs;
+		else
+			rpc->addr = op->addr.val;
+		rpc->totalxferlen += op->addr.nbytes;
+	}
+
+	if (op->dummy.nbytes) {
+		rpc->smenr |= RPC_SMENR_DME;
+		rpc->dummy = RPC_SMDMCR_DMCYC(op->dummy.nbytes);
+		rpc->totalxferlen += op->dummy.nbytes;
+	}
+
+	if (op->data.nbytes || (offs && len)) {
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rpc->smcr = RPC_SMCR_SPIRE;

drivers/spi/spi-renesas-rpc.c line 369

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+			rpc->xfer_dir = SPI_MEM_DATA_IN;
+		} else if (op->data.dir == SPI_MEM_DATA_OUT) {
+			rpc->smcr = RPC_SMCR_SPIWE;
+			rpc->xfer_dir = SPI_MEM_DATA_OUT;
+		}
+
+		if (offs && len) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+					(*(u32 *)len)) | RPC_SMENR_SPIDB
+					(fls(op->data.buswidth >> 1));

Fix the *(u32 *)

drivers/spi/spi-renesas-rpc.c line 376

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+			rpc->xferlen = *(u32 *)len;
+			rpc->totalxferlen += *(u32 *)len;
+		} else {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+					(op->data.nbytes)) | RPC_SMENR_SPIDB
+					(fls(op->data.buswidth >> 1));

Drop parenthesis around fls()

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+			rpc->xferlen = op->data.nbytes;
+			rpc->totalxferlen += op->data.nbytes;
+		}
+	}

drivers/spi/spi-renesas-rpc.c line 391

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+}
+
+static bool rpc_spi_mem_supports_op(struct spi_mem *mem,
+				    const struct spi_mem_op *op)
+{
+	if (op->data.buswidth > 4 || op->addr.buswidth > 4 ||
+	    op->dummy.buswidth > 4 || op->cmd.buswidth > 4)
+		return false;
+
+	if (op->addr.nbytes > 4)

Merge this into previous conditional statement.

Quoted 158 lines
drivers/spi/spi-renesas-rpc.c new file +158 -0
+		return false;
+
+	return true;
+}
+
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
+				       u64 offs, size_t len, void *buf)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+	int ret;
+
+	if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+		return -EINVAL;
+
+	ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+	if (ret)
+		return ret;
+
+	rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+				    &desc->info.op_tmpl, &offs, &len);
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+		     RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+		     RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |
+		     RPC_DRCR_RBE);
+	regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC);
+	regmap_write(rpc->regmap, RPC_DROPR, 0);
+	regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr);
+	regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
+	regmap_write(rpc->regmap, RPC_DRDRENR, 0);
+
+	memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, len);
+
+	return len;
+}
+
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
+					u64 offs, size_t len, const void *buf)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+	int ret;
+
+	if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+		return -EINVAL;
+
+	if (WARN_ON(len > RPC_WBUF_SIZE))
+		return -EIO;
+
+	ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+	if (ret)
+		return ret;
+
+	rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+				    &desc->info.op_tmpl, &offs, &len);
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+				  RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+				  RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_SMDRENR, 0);
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL | 0x260 |
+				  RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF);
+
+	memcpy_toio(rpc->base + RPC_WBUF, buf, len);
+
+	regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_SMADR, offs);
+	regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+	regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+	ret = wait_msg_xfer_end(rpc);
+	if (ret)
+		goto out;
+
+	regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RCF);
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+				  RPC_PHYCNT_STRTIM(6) | 0x260);
+
+	return len;
+out:
+	return rpc_spi_do_reset(rpc);
+}
+
+static int rpc_spi_mem_dirmap_create(struct spi_mem_dirmap_desc *desc)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+
+	if (desc->info.offset + desc->info.length > U32_MAX)
+		return -ENOTSUPP;
+
+	if (!rpc_spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
+		return -ENOTSUPP;
+
+	if (!rpc->linear.map &&
+	    desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN)
+		return -ENOTSUPP;
+
+	return 0;
+}
+
+static int rpc_spi_mem_exec_op(struct spi_mem *mem,
+			       const struct spi_mem_op *op)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(mem->spi->master);
+	int ret;
+
+	ret = rpc_spi_set_freq(rpc, mem->spi->max_speed_hz);
+	if (ret)
+		return ret;
+
+	rpc_spi_mem_set_prep_op_cfg(mem->spi, op, NULL, NULL);
+
+	ret = rpc_spi_io_xfer(rpc,
+			      op->data.dir == SPI_MEM_DATA_OUT ?
+			      op->data.buf.out : NULL,
+			      op->data.dir == SPI_MEM_DATA_IN ?
+			      op->data.buf.in : NULL);
+
+	return ret;
+}
+
+static const struct spi_controller_mem_ops rpc_spi_mem_ops = {
+	.supports_op = rpc_spi_mem_supports_op,
+	.exec_op = rpc_spi_mem_exec_op,
+	.dirmap_create = rpc_spi_mem_dirmap_create,
+	.dirmap_read = rpc_spi_mem_dirmap_read,
+	.dirmap_write = rpc_spi_mem_dirmap_write,
+};
+
+static void rpc_spi_transfer_setup(struct rpc_spi *rpc,
+				   struct spi_message *msg)
+{
+	struct spi_transfer *t, xfer[4] = { };
+	u32 i, xfercnt, xferpos = 0;
+
+	rpc->totalxferlen = 0;
+	rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		if (t->tx_buf) {
+			xfer[xferpos].tx_buf = t->tx_buf;
+			xfer[xferpos].tx_nbits = t->tx_nbits;
+		}
+
+		if (t->rx_buf) {
+			xfer[xferpos].rx_buf = t->rx_buf;
+			xfer[xferpos].rx_nbits = t->rx_nbits;
+		}
+
+		if (t->len) {
+			xfer[xferpos++].len = t->len;
+			rpc->totalxferlen += t->len;
+		}
+
+		if (list_is_last(&t->transfer_list, &msg->transfers)) {
+			if (xferpos > 1 && t->rx_buf) {
+				rpc->xfer_dir = SPI_MEM_DATA_IN;
+				rpc->smcr = RPC_SMCR_SPIRE;

drivers/spi/spi-renesas-rpc.c line 559

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+			} else if (xferpos > 1 && t->tx_buf) {
+				rpc->xfer_dir = SPI_MEM_DATA_OUT;
+				rpc->smcr = RPC_SMCR_SPIWE;
+			}
+		}
+	}
+
+	xfercnt = xferpos;
+	rpc->xferlen = xfer[--xferpos].len;
+	rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

Quoted 23 lines
drivers/spi/spi-renesas-rpc.c new file +23 -0
+	rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits >> 1));
+	rpc->addr = 0;
+
+	if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+		rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
+		for (i = 0; i < xfer[1].len; i++)
+			rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+					<< (8 * (xfer[1].len - i - 1));
+
+		if (xfer[1].len == 4)
+			rpc->smenr |= RPC_SMENR_ADE(0xf);
+		else
+			rpc->smenr |= RPC_SMENR_ADE(0x7);
+	}
+
+	switch (xfercnt) {
+	case 2:
+		if (xfer[1].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[1].rx_nbits >> 1));
+		} else if (xfer[1].tx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer

drivers/spi/spi-renesas-rpc.c line 592

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+				      (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[1].tx_nbits >> 1));
+		}
+		break;
+
+	case 3:
+		if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[2].rx_nbits >> 1));

It seems this SMENR pattern repeats itself throughout the driver, can this be improved / deduplicated ?

Quoted 59 lines
drivers/spi/spi-renesas-rpc.c new file +59 -0
+		} else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[2].tx_nbits >> 1));
+		}
+		break;
+
+	case 4:
+		if (xfer[2].len && xfer[2].tx_buf) {
+			rpc->smenr |= RPC_SMENR_DME;
+			rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+		}
+
+		if (xfer[3].len && xfer[3].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[3].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[3].rx_nbits >> 1));
+		}
+		break;
+
+	default:
+		break;
+	}
+}
+
+static int rpc_spi_xfer_message(struct rpc_spi *rpc, struct spi_transfer *t)
+{
+	int ret;
+
+	ret = rpc_spi_set_freq(rpc, t->speed_hz);
+	if (ret)
+		return ret;
+
+	ret = rpc_spi_io_xfer(rpc,
+			      rpc->xfer_dir == SPI_MEM_DATA_OUT ?
+			      t->tx_buf : NULL,
+			      rpc->xfer_dir == SPI_MEM_DATA_IN ?
+			      t->rx_buf : NULL);
+
+	return ret;
+}
+
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+					struct spi_message *msg)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(master);
+	struct spi_transfer *t;
+	int ret;
+
+	rpc_spi_transfer_setup(rpc, msg);
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		if (!list_is_last(&t->transfer_list, &msg->transfers))
+			continue;
+		ret = rpc_spi_xfer_message(rpc, t);
+		if (ret)
+			goto out;
+	}
+

drivers/spi/spi-renesas-rpc.c line 661

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	msg->status = 0;
+	msg->actual_length = rpc->totalxferlen;
+out:
+	spi_finalize_current_message(master);
+	return 0;
+}
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+	regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+	regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

Quoted 16 lines
drivers/spi/spi-renesas-rpc.c new file +16 -0
+	regmap_reg_range(RPC_CMNSR, RPC_CMNSR),
+};
+
+static const struct regmap_access_table rpc_spi_volatile_table = {
+	.yes_ranges	= rpc_spi_volatile_ranges,
+	.n_yes_ranges	= ARRAY_SIZE(rpc_spi_volatile_ranges),
+};
+
+static const struct regmap_config rpc_spi_regmap_config = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.fast_io = true,
+	.max_register = RPC_WBUF + RPC_WBUF_SIZE,
+	.volatile_table = &rpc_spi_volatile_table,
+};

drivers/spi/spi-renesas-rpc.c line 687

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+static int rpc_spi_probe(struct platform_device *pdev)
+{
+	struct spi_master *master;
+	struct resource *res;
+	struct rpc_spi *rpc;
+	const struct regmap_config *regmap_config;
+	int ret;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(struct rpc_spi));

sizeof(*rpc)

Quoted 47 lines
drivers/spi/spi-renesas-rpc.c new file +47 -0
+	if (!master)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, master);
+
+	rpc = spi_master_get_devdata(master);
+
+	master->dev.of_node = pdev->dev.of_node;
+
+	rpc->clk_rpc = devm_clk_get(&pdev->dev, "clk_rpc");
+	if (IS_ERR(rpc->clk_rpc))
+		return PTR_ERR(rpc->clk_rpc);
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rpc_regs");
+	rpc->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rpc->base))
+		return PTR_ERR(rpc->base);
+
+	regmap_config = &rpc_spi_regmap_config;
+	rpc->regmap = devm_regmap_init_mmio(&pdev->dev, rpc->base,
+					    regmap_config);
+	if (IS_ERR(rpc->regmap)) {
+		dev_err(&pdev->dev, "failed to init regmap %ld for rpc-spi\n",
+			PTR_ERR(rpc->regmap));
+		return PTR_ERR(rpc->regmap);
+	}
+
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap");
+	rpc->linear.map = devm_ioremap_resource(&pdev->dev, res);
+	if (!IS_ERR(rpc->linear.map)) {
+		rpc->linear.dma = res->start;
+		rpc->linear.size = resource_size(res);
+	} else {
+		rpc->linear.map = NULL;
+	}
+
+	rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+	if (IS_ERR(rpc->rstc))
+		return PTR_ERR(rpc->rstc);
+
+	pm_runtime_enable(&pdev->dev);
+	master->auto_runtime_pm = true;
+
+	master->num_chipselect = 1;
+	master->mem_ops = &rpc_spi_mem_ops;
+	master->transfer_one_message = rpc_spi_transfer_one_message;
+

drivers/spi/spi-renesas-rpc.c line 744

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	master->bits_per_word_mask = SPI_BPW_MASK(8);
+	master->mode_bits = SPI_CPOL | SPI_CPHA |
+			SPI_RX_DUAL | SPI_TX_DUAL |
+			SPI_RX_QUAD | SPI_TX_QUAD;
+
+	rpc_spi_hw_init(rpc);
+
+	ret = spi_register_master(master);
+	if (ret) {
+		dev_err(&pdev->dev, "spi_register_master failed\n");

Knowing the return value would be useful.

Quoted 24 lines
drivers/spi/spi-renesas-rpc.c new file +24 -0
+		goto err_put_master;
+	}
+	return 0;
+
+err_put_master:
+	spi_master_put(master);
+	pm_runtime_disable(&pdev->dev);
+
+	return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	pm_runtime_disable(&pdev->dev);
+	spi_unregister_master(master);
+
+	return 0;
+}
+
+static const struct of_device_id rpc_spi_of_ids[] = {
+	{ .compatible = "renesas,r8a77995-rpc", },
+	{ /* sentinel */ }

drivers/spi/spi-renesas-rpc.c line 778

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+};
+MODULE_DEVICE_TABLE(of, rpc_spi_of_ids);
+
+#ifdef CONFIG_PM_SLEEP
+static int rpc_spi_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

Quoted 31 lines
drivers/spi/spi-renesas-rpc.c new file +30 -0
+}
+
+static int rpc_spi_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	return spi_master_resume(master);
+}
+
+static SIMPLE_DEV_PM_OPS(rpc_spi_pm_ops, rpc_spi_suspend, rpc_spi_resume);
+#define DEV_PM_OPS	(&rpc_spi_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif
+
+static struct platform_driver rpc_spi_driver = {
+	.probe = rpc_spi_probe,
+	.remove = rpc_spi_remove,
+	.driver = {
+		.name = "rpc-spi",
+		.of_match_table = rpc_spi_of_ids,
+		.pm = DEV_PM_OPS,
+	},
+};
+module_platform_driver(rpc_spi_driver);
+
+MODULE_AUTHOR("Mason Yang <[email protected]>");
+MODULE_DESCRIPTION("Renesas R-Car Gen3 RPC SPI controller driver");
+MODULE_LICENSE("GPL v2");
Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Marek,

thanks for your review.

Quoted 19 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

To

"Mason Yang" <[email protected]>, [email protected], linux- [email protected], [email protected], [email protected], [email protected], "Geert Uytterhoeven" <[email protected]>,

cc

[email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 8 lines
Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

What changed in this V2 ?

[...]

see some description in [PATH v2 0/2]

Quoted 46 lines

drivers/spi/spi-renesas-rpc.c line 153

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+struct rpc_spi {
+   struct clk *clk_rpc;
+   void __iomem *base;
+   struct {
+      void __iomem *map;
+      dma_addr_t dma;
+      size_t size;
+   } linear;

This is still here, see my review comments on the previous version.

Quoted 34 lines
drivers/spi/spi-renesas-rpc.c new file +34 -0
+   struct regmap *regmap;
+   u32 cur_speed_hz;
+   u32 cmd;
+   u32 addr;
+   u32 dummy;
+   u32 smcr;
+   u32 smenr;
+   u32 xferlen;
+   u32 totalxferlen;
+   enum spi_mem_data_dir xfer_dir;
+#ifdef CONFIG_RESET_CONTROLLER
+   struct reset_control *rstc;
+#endif
+};
+
+static int rpc_spi_set_freq(struct rpc_spi *rpc, unsigned long freq)
+{
+   int ret;
+
+   if (rpc->cur_speed_hz == freq)
+      return 0;
+
+   ret = clk_set_rate(rpc->clk_rpc, freq);
+   if (ret)
+      return ret;
+
+   rpc->cur_speed_hz = freq;
+   return ret;
+}
+
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 192

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
+   /*
+    * NOTE: The 0x31511144 and 0x431 are undocumented bits,
+    *    but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+    */
+   regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+   regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 207

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+   regmap_write(rpc->regmap, RPC_SSLDR, RPC_SSLDR_SPNDL(7) |
+              RPC_SSLDR_SLNDL(7) | RPC_SSLDR_SCKDL(7));
+}
+
+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c
line 124 ~ 126

Quoted 31 lines
Quoted 31 lines
drivers/spi/spi-renesas-rpc.c new file +30 -0
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   int i, ret;
+
+   ret = reset_control_reset(rpc->rstc);
+   if (ret)
+      return ret;
+
+   for (i = 0; i < LOOP_TIMEOUT; i++) {
+      ret = reset_control_status(rpc->rstc);
+      if (ret == 0)
+         return 0;
+      usleep_range(0, 1);
+   }
+
+   return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   return -ETIMEDOUT;
+}
+#endif
+
+static int wait_msg_xfer_end(struct rpc_spi *rpc)
+{
+   u32 sts;
+
+   return regmap_read_poll_timeout(rpc->regmap, RPC_CMNSR, sts,
+               sts & RPC_CMNSR_TEND, 0, USEC_PER_SEC);
Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 243

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+}
+
+static u8 rpc_bits_xfer(u32 nbytes)
+{
+   if (nbytes > 4)
+      nbytes = 4;

Use clamp() ?

nbytes = clamp(nbytes, 1, 4);

got many warnings, something like, ./include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+   return GENMASK(3, 4 - nbytes);

Nice ;-)

Quoted 9 lines

drivers/spi/spi-renesas-rpc.c

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+}
+
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE 

|

Quoted 9 lines
Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 269

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

It must have it!

Quoted 103 lines
Quoted 90 lines
drivers/spi/spi-renesas-rpc.c new file +89 -0
+         if (nbytes > 4) {
+            nbytes = 4;
+            smcr = rpc->smcr |
+                   RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+         } else {
+            smcr = rpc->smcr | RPC_SMCR_SPIE;
+         }
+
+         regmap_write(rpc->regmap, RPC_SMENR, smenr);
+         regmap_write(rpc->regmap, RPC_SMCR, smcr);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
+            goto out;
+
+         pos += nbytes;
+         smenr = rpc->smenr & ~RPC_SMENR_CDE &
+                    ~RPC_SMENR_ADE(0xf);
+      }
+   } else if (rx_buf) {
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         if (nbytes > 4)
+            nbytes = 4;
+
+         regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+         regmap_write(rpc->regmap, RPC_SMCR,
+                 rpc->smcr | RPC_SMCR_SPIE);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
+            goto out;
+
+         regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+         memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);
+         pos += nbytes;
+         regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+         regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+         regmap_write(rpc->regmap, RPC_SMADR, rpc->addr + pos);
+      }
+   } else {
+      regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+      regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+      ret = wait_msg_xfer_end(rpc);
+      if (ret)
+         goto out;
+   }
+
+   return ret;
+out:
+   return rpc_spi_do_reset(rpc);
+}
+
+static void rpc_spi_mem_set_prep_op_cfg(struct spi_device *spi,
+               const struct spi_mem_op *op,
+               u64 *offs, size_t *len)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(spi->master);
+
+   rpc->cmd = RPC_SMCMR_CMD(op->cmd.opcode);
+   rpc->smenr = RPC_SMENR_CDE |
+           RPC_SMENR_CDB(fls(op->cmd.buswidth >> 1));
+   rpc->totalxferlen = 1;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+   rpc->xferlen = 0;
+   rpc->addr = 0;
+
+   if (op->addr.nbytes) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(op->addr.buswidth >> 1));
+      if (op->addr.nbytes == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+
+      if (offs && len)
+         rpc->addr = *(u32 *)offs;
+      else
+         rpc->addr = op->addr.val;
+      rpc->totalxferlen += op->addr.nbytes;
+   }
+
+   if (op->dummy.nbytes) {
+      rpc->smenr |= RPC_SMENR_DME;
+      rpc->dummy = RPC_SMDMCR_DMCYC(op->dummy.nbytes);
+      rpc->totalxferlen += op->dummy.nbytes;
+   }
+
+   if (op->data.nbytes || (offs && len)) {
+      if (op->data.dir == SPI_MEM_DATA_IN) {
+         rpc->smcr = RPC_SMCR_SPIRE;

drivers/spi/spi-renesas-rpc.c line 369

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+         rpc->xfer_dir = SPI_MEM_DATA_IN;
+      } else if (op->data.dir == SPI_MEM_DATA_OUT) {
+         rpc->smcr = RPC_SMCR_SPIWE;
+         rpc->xfer_dir = SPI_MEM_DATA_OUT;
+      }
+
+      if (offs && len) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (*(u32 *)len)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Fix the *(u32 *)

Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 376

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+         rpc->xferlen = *(u32 *)len;
+         rpc->totalxferlen += *(u32 *)len;
+      } else {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Drop parenthesis around fls()

?
no way.

Quoted 19 lines
Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+         rpc->xferlen = op->data.nbytes;
+         rpc->totalxferlen += op->data.nbytes;
+      }
+   }

drivers/spi/spi-renesas-rpc.c line 391

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+}
+
+static bool rpc_spi_mem_supports_op(struct spi_mem *mem,
+                const struct spi_mem_op *op)
+{
+   if (op->data.buswidth > 4 || op->addr.buswidth > 4 ||
+       op->dummy.buswidth > 4 || op->cmd.buswidth > 4)
+      return false;
+
+   if (op->addr.nbytes > 4)

Merge this into previous conditional statement.

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+      return false;
+
+   return true;
+}
+
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc 

*desc,

Quoted 3 lines

drivers/spi/spi-renesas-rpc.c

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+                   u64 offs, size_t len, void *buf)
+{
+   struct rpc_spi *rpc = 

spi_master_get_devdata(desc->mem->spi->master);

Quoted 17 lines
Quoted 17 lines
drivers/spi/spi-renesas-rpc.c new file +17 -0
+   int ret;
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+           RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+           RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |
+           RPC_DRCR_RBE);
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+   regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC);
+   regmap_write(rpc->regmap, RPC_DROPR, 0);
+   regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr);
+   regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_DRDRENR, 0);
+
+   memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, 

len);

Quoted 5 lines

drivers/spi/spi-renesas-rpc.c

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+   return len;
+}
+
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc 

*desc,

Quoted 3 lines

drivers/spi/spi-renesas-rpc.c

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+               u64 offs, size_t len, const void *buf)
+{
+   struct rpc_spi *rpc = 

spi_master_get_devdata(desc->mem->spi->master);

Quoted 8 lines
Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+   int ret;
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   if (WARN_ON(len > RPC_WBUF_SIZE))
+      return -EIO;
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE 

|

Quoted 18 lines
Quoted 18 lines
drivers/spi/spi-renesas-rpc.c new file +18 -0
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL | 0x260 |
+              RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF);
+
+   memcpy_toio(rpc->base + RPC_WBUF, buf, len);
+
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMADR, offs);
+   regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+   regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+   ret = wait_msg_xfer_end(rpc);
+   if (ret)
+      goto out;
+
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RCF);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+              RPC_PHYCNT_STRTIM(6) | 0x260);
+
+   return len;
+out:
+   return rpc_spi_do_reset(rpc);
+}
+
+static int rpc_spi_mem_dirmap_create(struct spi_mem_dirmap_desc 

*desc)

Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+   struct rpc_spi *rpc = 

spi_master_get_devdata(desc->mem->spi->master);

Quoted 76 lines
Quoted 76 lines
drivers/spi/spi-renesas-rpc.c new file +76 -0
+
+   if (desc->info.offset + desc->info.length > U32_MAX)
+      return -ENOTSUPP;
+
+   if (!rpc_spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
+      return -ENOTSUPP;
+
+   if (!rpc->linear.map &&
+       desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN)
+      return -ENOTSUPP;
+
+   return 0;
+}
+
+static int rpc_spi_mem_exec_op(struct spi_mem *mem,
+                const struct spi_mem_op *op)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(mem->spi->master);
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(mem->spi, op, NULL, NULL);
+
+   ret = rpc_spi_io_xfer(rpc,
+               op->data.dir == SPI_MEM_DATA_OUT ?
+               op->data.buf.out : NULL,
+               op->data.dir == SPI_MEM_DATA_IN ?
+               op->data.buf.in : NULL);
+
+   return ret;
+}
+
+static const struct spi_controller_mem_ops rpc_spi_mem_ops = {
+   .supports_op = rpc_spi_mem_supports_op,
+   .exec_op = rpc_spi_mem_exec_op,
+   .dirmap_create = rpc_spi_mem_dirmap_create,
+   .dirmap_read = rpc_spi_mem_dirmap_read,
+   .dirmap_write = rpc_spi_mem_dirmap_write,
+};
+
+static void rpc_spi_transfer_setup(struct rpc_spi *rpc,
+               struct spi_message *msg)
+{
+   struct spi_transfer *t, xfer[4] = { };
+   u32 i, xfercnt, xferpos = 0;
+
+   rpc->totalxferlen = 0;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (t->tx_buf) {
+         xfer[xferpos].tx_buf = t->tx_buf;
+         xfer[xferpos].tx_nbits = t->tx_nbits;
+      }
+
+      if (t->rx_buf) {
+         xfer[xferpos].rx_buf = t->rx_buf;
+         xfer[xferpos].rx_nbits = t->rx_nbits;
+      }
+
+      if (t->len) {
+         xfer[xferpos++].len = t->len;
+         rpc->totalxferlen += t->len;
+      }
+
+      if (list_is_last(&t->transfer_list, &msg->transfers)) {
+         if (xferpos > 1 && t->rx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_IN;
+            rpc->smcr = RPC_SMCR_SPIRE;
+         } else if (xferpos > 1 && t->tx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_OUT;
+            rpc->smcr = RPC_SMCR_SPIWE;
+         }
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 559

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+      }
+   }
+
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

yes!

Quoted 2 lines
Quoted 2 lines

+ rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits >>

1));

Quoted 27 lines
Quoted 27 lines
drivers/spi/spi-renesas-rpc.c new file +27 -0
+   rpc->addr = 0;
+
+   if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
+
+      if (xfer[1].len == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+   }
+
+   switch (xfercnt) {
+   case 2:
+      if (xfer[1].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].rx_nbits >> 1));
+      } else if (xfer[1].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].tx_nbits >> 1));
+      }
+      break;
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 592

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+   case 3:
+      if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].rx_nbits >> 1));

It seems this SMENR pattern repeats itself throughout the driver, can this be improved / deduplicated ?

It seems no way!

Quoted 65 lines
Quoted 17 lines
drivers/spi/spi-renesas-rpc.c new file +16 -0
+      } else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].tx_nbits >> 1));
+      }
+      break;
+
+   case 4:
+      if (xfer[2].len && xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_DME;
+         rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+      }
+
+      if (xfer[3].len && xfer[3].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[3].len)) | RPC_SMENR_SPIDB(fls

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[3].rx_nbits >> 1));
+      }
+      break;
+
+   default:
+      break;
+   }
+}
+
+static int rpc_spi_xfer_message(struct rpc_spi *rpc, struct 

spi_transfer *t)

Quoted 37 lines
drivers/spi/spi-renesas-rpc.c new file +37 -0
+{
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, t->speed_hz);
+   if (ret)
+      return ret;
+
+   ret = rpc_spi_io_xfer(rpc,
+               rpc->xfer_dir == SPI_MEM_DATA_OUT ?
+               t->tx_buf : NULL,
+               rpc->xfer_dir == SPI_MEM_DATA_IN ?
+               t->rx_buf : NULL);
+
+   return ret;
+}
+
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+               struct spi_message *msg)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(master);
+   struct spi_transfer *t;
+   int ret;
+
+   rpc_spi_transfer_setup(rpc, msg);
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (!list_is_last(&t->transfer_list, &msg->transfers))
+         continue;
+      ret = rpc_spi_xfer_message(rpc, t);
+      if (ret)
+         goto out;
+   }
+
+   msg->status = 0;
+   msg->actual_length = rpc->totalxferlen;
+out:
+   spi_finalize_current_message(master);
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 661

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+   return 0;
+}
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

No matter is write-back or write-through.

Quoted 30 lines
Quoted 17 lines
drivers/spi/spi-renesas-rpc.c new file +16 -0
+   regmap_reg_range(RPC_CMNSR, RPC_CMNSR),
+};
+
+static const struct regmap_access_table rpc_spi_volatile_table = {
+   .yes_ranges   = rpc_spi_volatile_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(rpc_spi_volatile_ranges),
+};
+
+static const struct regmap_config rpc_spi_regmap_config = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 4,
+   .fast_io = true,
+   .max_register = RPC_WBUF + RPC_WBUF_SIZE,
+   .volatile_table = &rpc_spi_volatile_table,
+};

drivers/spi/spi-renesas-rpc.c line 687

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+static int rpc_spi_probe(struct platform_device *pdev)
+{
+   struct spi_master *master;
+   struct resource *res;
+   struct rpc_spi *rpc;
+   const struct regmap_config *regmap_config;
+   int ret;
+
+   master = spi_alloc_master(&pdev->dev, sizeof(struct rpc_spi));

sizeof(*rpc)

Quoted 14 lines
Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+   if (!master)
+      return -ENOMEM;
+
+   platform_set_drvdata(pdev, master);

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+   rpc = spi_master_get_devdata(master);
+
+   master->dev.of_node = pdev->dev.of_node;
+
+   rpc->clk_rpc = devm_clk_get(&pdev->dev, "clk_rpc");
+   if (IS_ERR(rpc->clk_rpc))
+      return PTR_ERR(rpc->clk_rpc);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 

"rpc_regs");

Quoted 6 lines
Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+   rpc->base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(rpc->base))
+      return PTR_ERR(rpc->base);
+
+   regmap_config = &rpc_spi_regmap_config;
+   rpc->regmap = devm_regmap_init_mmio(&pdev->dev, rpc->base,
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+                   regmap_config);
+   if (IS_ERR(rpc->regmap)) {
+      dev_err(&pdev->dev, "failed to init regmap %ld for rpc-spi\n",
+         PTR_ERR(rpc->regmap));
+      return PTR_ERR(rpc->regmap);
+   }
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 

"dirmap");

Quoted 60 lines
Quoted 19 lines
drivers/spi/spi-renesas-rpc.c new file +19 -0
+   rpc->linear.map = devm_ioremap_resource(&pdev->dev, res);
+   if (!IS_ERR(rpc->linear.map)) {
+      rpc->linear.dma = res->start;
+      rpc->linear.size = resource_size(res);
+   } else {
+      rpc->linear.map = NULL;
+   }
+
+   rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+   if (IS_ERR(rpc->rstc))
+      return PTR_ERR(rpc->rstc);
+
+   pm_runtime_enable(&pdev->dev);
+   master->auto_runtime_pm = true;
+
+   master->num_chipselect = 1;
+   master->mem_ops = &rpc_spi_mem_ops;
+   master->transfer_one_message = rpc_spi_transfer_one_message;
+

drivers/spi/spi-renesas-rpc.c line 744

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   master->bits_per_word_mask = SPI_BPW_MASK(8);
+   master->mode_bits = SPI_CPOL | SPI_CPHA |
+         SPI_RX_DUAL | SPI_TX_DUAL |
+         SPI_RX_QUAD | SPI_TX_QUAD;
+
+   rpc_spi_hw_init(rpc);
+
+   ret = spi_register_master(master);
+   if (ret) {
+      dev_err(&pdev->dev, "spi_register_master failed\n");

Knowing the return value would be useful.

Quoted 28 lines
drivers/spi/spi-renesas-rpc.c new file +28 -0
+      goto err_put_master;
+   }
+   return 0;
+
+err_put_master:
+   spi_master_put(master);
+   pm_runtime_disable(&pdev->dev);
+
+   return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   pm_runtime_disable(&pdev->dev);
+   spi_unregister_master(master);
+
+   return 0;
+}
+
+static const struct of_device_id rpc_spi_of_ids[] = {
+   { .compatible = "renesas,r8a77995-rpc", },
+   { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, rpc_spi_of_ids);
+
+#ifdef CONFIG_PM_SLEEP
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 778

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#4 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Mason,

Quoted 15 lines · On Wed, Dec 5, 2018 at 8:44 AM <[email protected]> wrote:
Quoted 5 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

Quoted 2 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 243

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+static u8 rpc_bits_xfer(u32 nbytes)
+{
+   if (nbytes > 4)
+      nbytes = 4;

Use clamp() ?

Quoted 4 lines

nbytes = clamp(nbytes, 1, 4);

got many warnings, something like,
./include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast

You can either make the constants unsigned (1U and 4U), or use clamp_t(u32, ...).

Quoted 8 lines
Quoted 5 lines

drivers/spi/spi-renesas-rpc.c line 376

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Drop parenthesis around fls()

?
no way.

Please split the line before RPC_SMENR_SPIDB, and join the next line with the parameters, so it becomes obvious the parentheses are needed because RPC_SMENR_SPIDB() is a macro taking parameters.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 30 lines · Geert Uytterhoeven

Hi Mason,

Quoted 15 lines · On Wed, Dec 5, 2018 at 8:44 AM <[email protected]> wrote:
Quoted 5 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

Quoted 2 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 243

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+static u8 rpc_bits_xfer(u32 nbytes)
+{
+   if (nbytes > 4)
+      nbytes = 4;

Use clamp() ?

Quoted 4 lines

nbytes = clamp(nbytes, 1, 4);

got many warnings, something like,
./include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast

You can either make the constants unsigned (1U and 4U), or use clamp_t(u32, ...).

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Drop parenthesis around fls()

?
no way.

Please split the line before RPC_SMENR_SPIDB, and join the next line with the parameters, so it becomes obvious the parentheses are needed because RPC_SMENR_SPIDB() is a macro taking parameters.

Oh, I didn't notice that, right.

Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to [email protected]
Quoted 1 line · On 12/05/2018 08:44 AM, [email protected] wrote:

Hi Marek,

Hi,

Quoted 24 lines

thanks for your review.

Quoted 22 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

To

"Mason Yang" <[email protected]>, [email protected], linux- [email protected], [email protected], [email protected], [email protected], "Geert Uytterhoeven" <[email protected]>,

cc

[email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 2 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

What changed in this V2 ?

[...]

see some description in [PATH v2 0/2]

I don't see any V2: list there.

Quoted 54 lines
Quoted 45 lines
Quoted 8 lines

+struct rpc_spi {
+   struct clk *clk_rpc;
+   void __iomem *base;
+   struct {
+      void __iomem *map;
+      dma_addr_t dma;
+      size_t size;
+   } linear;

This is still here, see my review comments on the previous version.

Quoted 34 lines

+   struct regmap *regmap;
+   u32 cur_speed_hz;
+   u32 cmd;
+   u32 addr;
+   u32 dummy;
+   u32 smcr;
+   u32 smenr;
+   u32 xferlen;
+   u32 totalxferlen;
+   enum spi_mem_data_dir xfer_dir;

drivers/spi/spi-renesas-rpc.c new file +24 -0
+#ifdef CONFIG_RESET_CONTROLLER
+   struct reset_control *rstc;
+#endif
+};
+
+static int rpc_spi_set_freq(struct rpc_spi *rpc, unsigned long freq)
+{
+   int ret;
+
+   if (rpc->cur_speed_hz == freq)
+      return 0;
+
+   ret = clk_set_rate(rpc->clk_rpc, freq);
+   if (ret)
+      return ret;
+
+   rpc->cur_speed_hz = freq;
+   return ret;
+}
+
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
Quoted 8 lines
Quoted 5 lines

+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

Quoted 2 lines

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Shouldn't this somehow use the soc_device_match() then and configure it accordingly for various chips ? Like eg. the r8a7795-cpg-mssr driver does.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines

+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
+   /*
+    * NOTE: The 0x31511144 and 0x431 are undocumented bits,
+    *    but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+    */
+   regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+   regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);

Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 207

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+   regmap_write(rpc->regmap, RPC_SSLDR, RPC_SSLDR_SPNDL(7) |
+              RPC_SSLDR_SLNDL(7) | RPC_SSLDR_SCKDL(7));
+}
+
+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

Quoted 5 lines

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c

line 124 ~ 126

This seems like a stopgap measure for systems which do not have a reset api compatible controller. Geert ?

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
drivers/spi/spi-renesas-rpc.c new file +30 -0
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   int i, ret;
+
+   ret = reset_control_reset(rpc->rstc);
+   if (ret)
+      return ret;
+
+   for (i = 0; i < LOOP_TIMEOUT; i++) {
+      ret = reset_control_status(rpc->rstc);
+      if (ret == 0)
+         return 0;
+      usleep_range(0, 1);
+   }
+
+   return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   return -ETIMEDOUT;
+}
+#endif
+
+static int wait_msg_xfer_end(struct rpc_spi *rpc)
+{
+   u32 sts;
+
+   return regmap_read_poll_timeout(rpc->regmap, RPC_CMNSR, sts,
+               sts & RPC_CMNSR_TEND, 0, USEC_PER_SEC);
Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 243

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+}
+
+static u8 rpc_bits_xfer(u32 nbytes)
+{
+   if (nbytes > 4)
+      nbytes = 4;

Use clamp() ?

Quoted 6 lines


nbytes = clamp(nbytes, 1, 4);

got many warnings, something like, ./include/linux/kernel.h:845:29: warning: comparison of distinct pointer types lacks a cast

Geert already replied.

Quoted 32 lines
Quoted 23 lines
Quoted 2 lines

+
+   return GENMASK(3, 4 - nbytes);

Nice ;-)

Quoted 18 lines
drivers/spi/spi-renesas-rpc.c new file +18 -0
+}
+
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 269

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 1 line

It must have it!

Why ?

Quoted 109 lines
Quoted 109 lines
Quoted 89 lines

+         if (nbytes > 4) {
+            nbytes = 4;
+            smcr = rpc->smcr |
+                   RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+         } else {
+            smcr = rpc->smcr | RPC_SMCR_SPIE;
+         }

drivers/spi/spi-renesas-rpc.c new file +82 -0
+
+         regmap_write(rpc->regmap, RPC_SMENR, smenr);
+         regmap_write(rpc->regmap, RPC_SMCR, smcr);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
+            goto out;
+
+         pos += nbytes;
+         smenr = rpc->smenr & ~RPC_SMENR_CDE &
+                    ~RPC_SMENR_ADE(0xf);
+      }
+   } else if (rx_buf) {
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         if (nbytes > 4)
+            nbytes = 4;
+
+         regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+         regmap_write(rpc->regmap, RPC_SMCR,
+                 rpc->smcr | RPC_SMCR_SPIE);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
+            goto out;
+
+         regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+         memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);
+         pos += nbytes;
+         regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+         regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+         regmap_write(rpc->regmap, RPC_SMADR, rpc->addr + pos);
+      }
+   } else {
+      regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+      regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+      ret = wait_msg_xfer_end(rpc);
+      if (ret)
+         goto out;
+   }
+
+   return ret;
+out:
+   return rpc_spi_do_reset(rpc);
+}
+
+static void rpc_spi_mem_set_prep_op_cfg(struct spi_device *spi,
+               const struct spi_mem_op *op,
+               u64 *offs, size_t *len)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(spi->master);
+
+   rpc->cmd = RPC_SMCMR_CMD(op->cmd.opcode);
+   rpc->smenr = RPC_SMENR_CDE |
+           RPC_SMENR_CDB(fls(op->cmd.buswidth >> 1));
+   rpc->totalxferlen = 1;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+   rpc->xferlen = 0;
+   rpc->addr = 0;
+
+   if (op->addr.nbytes) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(op->addr.buswidth >> 1));
+      if (op->addr.nbytes == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+
+      if (offs && len)
+         rpc->addr = *(u32 *)offs;
+      else
+         rpc->addr = op->addr.val;
+      rpc->totalxferlen += op->addr.nbytes;
+   }
+
+   if (op->dummy.nbytes) {
+      rpc->smenr |= RPC_SMENR_DME;
+      rpc->dummy = RPC_SMDMCR_DMCYC(op->dummy.nbytes);
+      rpc->totalxferlen += op->dummy.nbytes;
+   }
+
+   if (op->data.nbytes || (offs && len)) {
+      if (op->data.dir == SPI_MEM_DATA_IN) {
+         rpc->smcr = RPC_SMCR_SPIRE;

drivers/spi/spi-renesas-rpc.c line 369

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+         rpc->xfer_dir = SPI_MEM_DATA_IN;
+      } else if (op->data.dir == SPI_MEM_DATA_OUT) {
+         rpc->smcr = RPC_SMCR_SPIWE;
+         rpc->xfer_dir = SPI_MEM_DATA_OUT;
+      }
+
+      if (offs && len) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (*(u32 *)len)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Fix the *(u32 *)

Quoted 6 lines

+         rpc->xferlen = *(u32 *)len;
+         rpc->totalxferlen += *(u32 *)len;
+      } else {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Quoted 4 lines
Quoted 1 line

Drop parenthesis around fls()

?
no way.

I would really appreciate it if you could explain things instead.

Geert already did so, by pointing out this is a confusing code formatting problem and how it should be fixed, so no need to repeat that. But I hope you understand how that sort of explanation is far more valuable than "no way" kind of reply.

Quoted 194 lines
Quoted 18 lines
Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+         rpc->xferlen = op->data.nbytes;
+         rpc->totalxferlen += op->data.nbytes;
+      }
+   }

drivers/spi/spi-renesas-rpc.c line 391

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+}
+
+static bool rpc_spi_mem_supports_op(struct spi_mem *mem,
+                const struct spi_mem_op *op)
+{
+   if (op->data.buswidth > 4 || op->addr.buswidth > 4 ||
+       op->dummy.buswidth > 4 || op->cmd.buswidth > 4)
+      return false;
+
+   if (op->addr.nbytes > 4)

Merge this into previous conditional statement.

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c

Quoted 6 lines

+      return false;

drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+   return true;
+}
+
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc

*desc,

Quoted 3 lines
Quoted 3 lines

+                   u64 offs, size_t len, void *buf) +{
+   struct rpc_spi *rpc =

spi_master_get_devdata(desc->mem->spi->master);

Quoted 22 lines
Quoted 22 lines

+   int ret;

drivers/spi/spi-renesas-rpc.c new file +21 -0
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+           RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+           RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |
+           RPC_DRCR_RBE);
+   regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC);
+   regmap_write(rpc->regmap, RPC_DROPR, 0);
+   regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr);
+   regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines

+   regmap_write(rpc->regmap, RPC_DRDRENR, 0);

drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+   memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, len);
+
+   return len;
+}
+
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc

*desc,

Quoted 3 lines
Quoted 3 lines

+               u64 offs, size_t len, const void *buf) +{
+   struct rpc_spi *rpc =

spi_master_get_devdata(desc->mem->spi->master);

Quoted 36 lines
Quoted 36 lines

+   int ret;

drivers/spi/spi-renesas-rpc.c new file +35 -0
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   if (WARN_ON(len > RPC_WBUF_SIZE))
+      return -EIO;
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL | 0x260 |
+              RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF);
+
+   memcpy_toio(rpc->base + RPC_WBUF, buf, len);
+
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMADR, offs);
+   regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+   regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+   ret = wait_msg_xfer_end(rpc);
+   if (ret)
+      goto out;
+
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RCF);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(6) | 0x260);
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c

Quoted 8 lines

+   return len;

drivers/spi/spi-renesas-rpc.c new file +7 -0
+out:
+   return rpc_spi_do_reset(rpc);
+}
+
+static int rpc_spi_mem_dirmap_create(struct spi_mem_dirmap_desc *desc)
+{
+   struct rpc_spi *rpc =

spi_master_get_devdata(desc->mem->spi->master);

Quoted 76 lines
Quoted 76 lines
drivers/spi/spi-renesas-rpc.c new file +76 -0
+
+   if (desc->info.offset + desc->info.length > U32_MAX)
+      return -ENOTSUPP;
+
+   if (!rpc_spi_mem_supports_op(desc->mem, &desc->info.op_tmpl))
+      return -ENOTSUPP;
+
+   if (!rpc->linear.map &&
+       desc->info.op_tmpl.data.dir == SPI_MEM_DATA_IN)
+      return -ENOTSUPP;
+
+   return 0;
+}
+
+static int rpc_spi_mem_exec_op(struct spi_mem *mem,
+                const struct spi_mem_op *op)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(mem->spi->master);
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(mem->spi, op, NULL, NULL);
+
+   ret = rpc_spi_io_xfer(rpc,
+               op->data.dir == SPI_MEM_DATA_OUT ?
+               op->data.buf.out : NULL,
+               op->data.dir == SPI_MEM_DATA_IN ?
+               op->data.buf.in : NULL);
+
+   return ret;
+}
+
+static const struct spi_controller_mem_ops rpc_spi_mem_ops = {
+   .supports_op = rpc_spi_mem_supports_op,
+   .exec_op = rpc_spi_mem_exec_op,
+   .dirmap_create = rpc_spi_mem_dirmap_create,
+   .dirmap_read = rpc_spi_mem_dirmap_read,
+   .dirmap_write = rpc_spi_mem_dirmap_write,
+};
+
+static void rpc_spi_transfer_setup(struct rpc_spi *rpc,
+               struct spi_message *msg)
+{
+   struct spi_transfer *t, xfer[4] = { };
+   u32 i, xfercnt, xferpos = 0;
+
+   rpc->totalxferlen = 0;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (t->tx_buf) {
+         xfer[xferpos].tx_buf = t->tx_buf;
+         xfer[xferpos].tx_nbits = t->tx_nbits;
+      }
+
+      if (t->rx_buf) {
+         xfer[xferpos].rx_buf = t->rx_buf;
+         xfer[xferpos].rx_nbits = t->rx_nbits;
+      }
+
+      if (t->len) {
+         xfer[xferpos++].len = t->len;
+         rpc->totalxferlen += t->len;
+      }
+
+      if (list_is_last(&t->transfer_list, &msg->transfers)) {
+         if (xferpos > 1 && t->rx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_IN;
+            rpc->smcr = RPC_SMCR_SPIRE;
+         } else if (xferpos > 1 && t->tx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_OUT;
+            rpc->smcr = RPC_SMCR_SPIWE;
+         }
Quoted 8 lines
Quoted 6 lines

+      }
+   }
+
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

Quoted 1 line

yes!

Why ?

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines

+   rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits 1));
+   rpc->addr = 0;

drivers/spi/spi-renesas-rpc.c new file +26 -0
+
+   if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
+
+      if (xfer[1].len == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+   }
+
+   switch (xfercnt) {
+   case 2:
+      if (xfer[1].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].rx_nbits >> 1));
+      } else if (xfer[1].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].tx_nbits >> 1));
+      }
+      break;
+
Quoted 8 lines
Quoted 5 lines

+   case 3:
+      if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].rx_nbits >> 1));

It seems this SMENR pattern repeats itself throughout the driver, can this be improved / deduplicated ?

Quoted 1 line

It seems no way!

Why ?

Quoted 73 lines
Quoted 64 lines
Quoted 16 lines

+      } else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].tx_nbits >> 1));
+      }
+      break;

drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+   case 4:
+      if (xfer[2].len && xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_DME;
+         rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+      }
+
+      if (xfer[3].len && xfer[3].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[3].len)) | RPC_SMENR_SPIDB(fls

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[3].rx_nbits >> 1));
+      }
+      break;
+
+   default:
+      break;
+   }
+}
+
+static int rpc_spi_xfer_message(struct rpc_spi *rpc, struct

spi_transfer *t)

Quoted 37 lines
drivers/spi/spi-renesas-rpc.c new file +37 -0
+{
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, t->speed_hz);
+   if (ret)
+      return ret;
+
+   ret = rpc_spi_io_xfer(rpc,
+               rpc->xfer_dir == SPI_MEM_DATA_OUT ?
+               t->tx_buf : NULL,
+               rpc->xfer_dir == SPI_MEM_DATA_IN ?
+               t->rx_buf : NULL);
+
+   return ret;
+}
+
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+               struct spi_message *msg)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(master);
+   struct spi_transfer *t;
+   int ret;
+
+   rpc_spi_transfer_setup(rpc, msg);
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (!list_is_last(&t->transfer_list, &msg->transfers))
+         continue;
+      ret = rpc_spi_xfer_message(rpc, t);
+      if (ret)
+         goto out;
+   }
+
+   msg->status = 0;
+   msg->actual_length = rpc->totalxferlen;
+out:
+   spi_finalize_current_message(master);
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 661

Quoted 6 lines

+   return 0;

drivers/spi/spi-renesas-rpc.c new file +5 -0
+}
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

Quoted 1 line

No matter is write-back or write-through.

Oh, do you want to assure the SMWDR value is always written directly to the hardware ?

btw. I think SMRDR should be precious ?

Quoted 127 lines
Quoted 29 lines
Quoted 16 lines

+   regmap_reg_range(RPC_CMNSR, RPC_CMNSR),

drivers/spi/spi-renesas-rpc.c new file +15 -0
+};
+
+static const struct regmap_access_table rpc_spi_volatile_table = {
+   .yes_ranges   = rpc_spi_volatile_ranges,
+   .n_yes_ranges   = ARRAY_SIZE(rpc_spi_volatile_ranges),
+};
+
+static const struct regmap_config rpc_spi_regmap_config = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 4,
+   .fast_io = true,
+   .max_register = RPC_WBUF + RPC_WBUF_SIZE,
+   .volatile_table = &rpc_spi_volatile_table,
+};

drivers/spi/spi-renesas-rpc.c line 687

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+static int rpc_spi_probe(struct platform_device *pdev)
+{
+   struct spi_master *master;
+   struct resource *res;
+   struct rpc_spi *rpc;
+   const struct regmap_config *regmap_config;
+   int ret;
+
+   master = spi_alloc_master(&pdev->dev, sizeof(struct rpc_spi));

sizeof(*rpc)

Quoted 14 lines
Quoted 4 lines

+   if (!master)
+      return -ENOMEM;

drivers/spi/spi-renesas-rpc.c new file +2 -0
+
+   platform_set_drvdata(pdev, master);

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+   rpc = spi_master_get_devdata(master);
+
+   master->dev.of_node = pdev->dev.of_node;
+
+   rpc->clk_rpc = devm_clk_get(&pdev->dev, "clk_rpc");
+   if (IS_ERR(rpc->clk_rpc))
+      return PTR_ERR(rpc->clk_rpc);
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"rpc_regs");

Quoted 74 lines
Quoted 33 lines

+   rpc->base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(rpc->base))
+      return PTR_ERR(rpc->base);

drivers/spi/spi-renesas-rpc.c new file +30 -0
+
+   regmap_config = &rpc_spi_regmap_config;
+   rpc->regmap = devm_regmap_init_mmio(&pdev->dev, rpc->base,
+                   regmap_config);
+   if (IS_ERR(rpc->regmap)) {
+      dev_err(&pdev->dev, "failed to init regmap %ld for rpc-spi\n",
+         PTR_ERR(rpc->regmap));
+      return PTR_ERR(rpc->regmap);
+   }
+
+   res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dirmap");
+   rpc->linear.map = devm_ioremap_resource(&pdev->dev, res);
+   if (!IS_ERR(rpc->linear.map)) {
+      rpc->linear.dma = res->start;
+      rpc->linear.size = resource_size(res);
+   } else {
+      rpc->linear.map = NULL;
+   }
+
+   rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+   if (IS_ERR(rpc->rstc))
+      return PTR_ERR(rpc->rstc);
+
+   pm_runtime_enable(&pdev->dev);
+   master->auto_runtime_pm = true;
+
+   master->num_chipselect = 1;
+   master->mem_ops = &rpc_spi_mem_ops;
+   master->transfer_one_message = rpc_spi_transfer_one_message;
+

drivers/spi/spi-renesas-rpc.c line 744

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   master->bits_per_word_mask = SPI_BPW_MASK(8);
+   master->mode_bits = SPI_CPOL | SPI_CPHA |
+         SPI_RX_DUAL | SPI_TX_DUAL |
+         SPI_RX_QUAD | SPI_TX_QUAD;
+
+   rpc_spi_hw_init(rpc);
+
+   ret = spi_register_master(master);
+   if (ret) {
+      dev_err(&pdev->dev, "spi_register_master failed\n");

Knowing the return value would be useful.

Quoted 28 lines

+      goto err_put_master;
+   }
+   return 0;

drivers/spi/spi-renesas-rpc.c new file +25 -0
+
+err_put_master:
+   spi_master_put(master);
+   pm_runtime_disable(&pdev->dev);
+
+   return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   pm_runtime_disable(&pdev->dev);
+   spi_unregister_master(master);
+
+   return 0;
+}
+
+static const struct of_device_id rpc_spi_of_ids[] = {
+   { .compatible = "renesas,r8a77995-rpc", },
+   { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, rpc_spi_of_ids);
+
+#ifdef CONFIG_PM_SLEEP
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 778

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

Quoted 3 lines

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

Is the power to the SPI NOR retained ?

Quoted 18 lines

best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

Signature · 2 lines
Best regards,
Marek Vasut
#7 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Marek,

Quoted 21 lines · Marek Vasut
Quoted 20 lines · On 12/05/2018 08:44 AM, [email protected] wrote:
Quoted 19 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

drivers/spi/spi-renesas-rpc.c line 192

Quoted 13 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

drivers/spi/spi-renesas-rpc.c new file +9 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

Quoted 5 lines
Quoted 2 lines

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Shouldn't this somehow use the soc_device_match() then and configure it accordingly for various chips ? Like eg. the r8a7795-cpg-mssr driver does.

Please don't use soc_device_match() for per-SoC configuration, if you already have of_device_id.data.

BTW, this drivers support r8a7795 only (for now), as per the compatible value.

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

Quoted 8 lines
Quoted 5 lines

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c

line 124 ~ 126

This seems like a stopgap measure for systems which do not have a reset api compatible controller. Geert ?

So far CONFIG_RESET_CONTROLLER is optional.

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);

drivers/spi/spi-renesas-rpc.c line 269

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 3 lines
Quoted 1 line

It must have it!

Why ?

Else you get a compiler warning, as tx_bug is void *.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 778

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+#ifdef CONFIG_PM_SLEEP
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

Quoted 5 lines
Quoted 3 lines

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

Is the power to the SPI NOR retained ?

Not if PSCI system suspend turns of power to the SoC.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#8 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 1 line · Geert Uytterhoeven

Hi Marek,

Hi,

Quoted 22 lines · Marek Vasut
Quoted 21 lines · On 12/05/2018 08:44 AM, [email protected] wrote:
Quoted 20 lines
Quoted 19 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

drivers/spi/spi-renesas-rpc.c line 192

Quoted 13 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

drivers/spi/spi-renesas-rpc.c new file +9 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Shouldn't this somehow use the soc_device_match() then and configure it accordingly for various chips ? Like eg. the r8a7795-cpg-mssr driver does.

Please don't use soc_device_match() for per-SoC configuration, if you already have of_device_id.data.

I mean, the value is different on H3 ES1 and ES2 iirc, that's what soc_device_match() is for, right ?

Quoted 2 lines

BTW, this drivers support r8a7795 only (for now), as per the compatible value.

77995

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

line 124 ~ 126

This seems like a stopgap measure for systems which do not have a reset api compatible controller. Geert ?

So far CONFIG_RESET_CONTROLLER is optional.

My understanding is that for this IP, it can well be mandatory, since all the chips have a reset wired to the IP internally.

Quoted 25 lines
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);

drivers/spi/spi-renesas-rpc.c line 269

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It must have it!

Why ?

Else you get a compiler warning, as tx_bug is void *.

Don't you need some get_unaligned() in that case ? txbuf+pos can well be unaligned if it's void * .

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 778

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+#ifdef CONFIG_PM_SLEEP
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

Is the power to the SPI NOR retained ?

Not if PSCI system suspend turns of power to the SoC.

And is that a problem ?

Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Marek,

Quoted 26 lines · Marek Vasut
Quoted 25 lines · Geert Uytterhoeven
Quoted 24 lines · Marek Vasut
Quoted 22 lines · On 12/05/2018 08:44 AM, [email protected] wrote:
Quoted 7 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 12 lines

drivers/spi/spi-renesas-rpc.c line 192

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Shouldn't this somehow use the soc_device_match() then and configure it accordingly for various chips ? Like eg. the r8a7795-cpg-mssr driver does.

Please don't use soc_device_match() for per-SoC configuration, if you already have of_device_id.data.

I mean, the value is different on H3 ES1 and ES2 iirc, that's what soc_device_match() is for, right ?

Oh, it differs between revisions, too?
Yes, in that case you need soc_device_match().

Quoted 4 lines
Quoted 2 lines

BTW, this drivers support r8a7795 only (for now), as per the compatible value.

77995

Sorry, typo on my side. So H3 is not yet supported ;-)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c

line 124 ~ 126

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This seems like a stopgap measure for systems which do not have a reset api compatible controller. Geert ?

So far CONFIG_RESET_CONTROLLER is optional.

My understanding is that for this IP, it can well be mandatory, since all the chips have a reset wired to the IP internally.

That's what I was trying to find out, hence my question about the purpose.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

drivers/spi/spi-renesas-rpc.c line 269

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It must have it!

Why ?

Else you get a compiler warning, as tx_bug is void *.

Don't you need some get_unaligned() in that case ? txbuf+pos can well be unaligned if it's void * .

True, but IIRC, arm64 can handle that, right?
Don't know about SuperH.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 778

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+#ifdef CONFIG_PM_SLEEP
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Is the power to the SPI NOR retained ?

Not if PSCI system suspend turns of power to the SoC.

And is that a problem ?

Good question!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#10 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 1 line · Geert Uytterhoeven

Hi Marek,

Hi,

Quoted 39 lines · Marek Vasut
Quoted 26 lines · Geert Uytterhoeven
Quoted 25 lines · Marek Vasut
Quoted 24 lines · On 12/05/2018 08:44 AM, [email protected] wrote:
Quoted 22 lines
Quoted 7 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 12 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */

Doesn't this vary by SoC ? I think H3 ES1.0 had different value here, but I might be wrong.

I check the Renesas bare-metal code, mini_monitor v4.01. It set 0x03 or 0x0 and I test them w/ 0x0, 0x3 and 0x6 are all OK.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Shouldn't this somehow use the soc_device_match() then and configure it accordingly for various chips ? Like eg. the r8a7795-cpg-mssr driver does.

Please don't use soc_device_match() for per-SoC configuration, if you already have of_device_id.data.

I mean, the value is different on H3 ES1 and ES2 iirc, that's what soc_device_match() is for, right ?

Oh, it differs between revisions, too?
Yes, in that case you need soc_device_match().

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

BTW, this drivers support r8a7795 only (for now), as per the compatible value.

77995

Sorry, typo on my side. So H3 is not yet supported ;-)

It's coming the minute this lands mainline, so we should make it easy to add.

Quoted 29 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 3 lines
Quoted 1 line

+#ifdef CONFIG_RESET_CONTROLLER

Just make the driver depend on reset controller.

?
please refer to
https://github.com/torvalds/linux/blob/master/drivers/clk/renesas/renesas-cpg-mssr.c

line 124 ~ 126

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

This seems like a stopgap measure for systems which do not have a reset api compatible controller. Geert ?

So far CONFIG_RESET_CONTROLLER is optional.

My understanding is that for this IP, it can well be mandatory, since all the chips have a reset wired to the IP internally.

That's what I was trying to find out, hence my question about the purpose.

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

It must have it!

Why ?

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Else you get a compiler warning, as tx_bug is void *.

Don't you need some get_unaligned() in that case ? txbuf+pos can well be unaligned if it's void * .

True, but IIRC, arm64 can handle that, right?
Don't know about SuperH.

Oh, that's right, there are SH systems with RPC. Right.

Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
Quoted 9 lines

Review

Quoted 7 lines
(quoted diff) +7 -0
+#ifdef CONFIG_PM_SLEEP
+static int rpc_spi_suspend(struct device *dev)
+{
+   struct platform_device *pdev = to_platform_device(dev);
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   return spi_master_suspend(master);

Won't the SPI NOR lose state across suspend ? Is that a problem ?

I don't think so.
Because when the device is not in operation and CS# is high, it is put in stand-by mode.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Is the power to the SPI NOR retained ?

Not if PSCI system suspend turns of power to the SoC.

And is that a problem ?

Good question!

That's what we need an answer to :)

Signature · 2 lines
Best regards,
Marek Vasut
#11 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to Marek Vasut

Hi Marek,

Quoted 1 line
Quoted 1 line
Quoted 1 line

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller

driver

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Mason Yang
Quoted 3 lines

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

What changed in this V2 ?

[...]

see some description in [PATH v2 0/2]

I don't see any V2: list there.

including
1) remove RPC clock enable/dis-able control,
2) patch run time PM,
3) add RPC module software reset,
4) add regmap,
5) other coding style and so on.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/spi/spi-renesas-rpc.c

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | 

RPC_CMNCR_SFDE |

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);

drivers/spi/spi-renesas-rpc.c line 269

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 3 lines
Quoted 1 line

It must have it!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

Using get_unaligned(), patched code would be
-----------------------------------------------------
regmap_write(rpc->regmap, RPC_SMWDR0,

                 get_unaligned((u32 *)(tx_buf + pos))); 

----------------------------------------------------

Quoted 12 lines
Quoted 11 lines
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 376

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+         rpc->xferlen = *(u32 *)len;
+         rpc->totalxferlen += *(u32 *)len;
+      } else {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Drop parenthesis around fls()

?
no way.

Quoted 6 lines

I would really appreciate it if you could explain things instead.

Geert already did so, by pointing out this is a confusing code formatting problem and how it should be fixed, so no need to repeat that. But I hope you understand how that sort of explanation is far more valuable than "no way" kind of reply.

okay, understood.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 559

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

yes!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

Using get_unaligned(), patched code would be
---------------------------------------------------------------
rpc->cmd = RPC_SMCMR_CMD(get_unaligned((u8 *)xfer[0].tx_buf));
----------------------------------------------------------------

Quoted 39 lines
Quoted 39 lines
Quoted 38 lines
Quoted 25 lines

+ rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits
1));

drivers/spi/spi-renesas-rpc.c new file +22 -0
+   rpc->addr = 0;
+
+   if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
+
+      if (xfer[1].len == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+   }
+
+   switch (xfercnt) {
+   case 2:
+      if (xfer[1].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].rx_nbits >> 1));
+      } else if (xfer[1].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer

drivers/spi/spi-renesas-rpc.c line 592

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].tx_nbits >> 1));
+      }
+      break;
+
+   case 3:
+      if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].rx_nbits >> 1));

It seems this SMENR pattern repeats itself throughout the driver, can this be improved / deduplicated ?

Quoted 3 lines
Quoted 1 line

It seems no way!

Why ?

okay, I patch this with for( ) loop.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+ } else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf)

{

Quoted 72 lines
Quoted 72 lines
Quoted 71 lines
Quoted 15 lines
drivers/spi/spi-renesas-rpc.c new file +15 -0
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].tx_nbits >> 1));
+      }
+      break;
+
+   case 4:
+      if (xfer[2].len && xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_DME;
+         rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+      }
+
+      if (xfer[3].len && xfer[3].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[3].len)) | RPC_SMENR_SPIDB(fls

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[3].rx_nbits >> 1));
+      }
+      break;
+
+   default:
+      break;
+   }
+}
+
+static int rpc_spi_xfer_message(struct rpc_spi *rpc, struct

spi_transfer *t)

Quoted 33 lines
drivers/spi/spi-renesas-rpc.c new file +33 -0
+{
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, t->speed_hz);
+   if (ret)
+      return ret;
+
+   ret = rpc_spi_io_xfer(rpc,
+               rpc->xfer_dir == SPI_MEM_DATA_OUT ?
+               t->tx_buf : NULL,
+               rpc->xfer_dir == SPI_MEM_DATA_IN ?
+               t->rx_buf : NULL);
+
+   return ret;
+}
+
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+               struct spi_message *msg)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(master);
+   struct spi_transfer *t;
+   int ret;
+
+   rpc_spi_transfer_setup(rpc, msg);
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (!list_is_last(&t->transfer_list, &msg->transfers))
+         continue;
+      ret = rpc_spi_xfer_message(rpc, t);
+      if (ret)
+         goto out;
+   }
+

drivers/spi/spi-renesas-rpc.c line 661

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   msg->status = 0;
+   msg->actual_length = rpc->totalxferlen;
+out:
+   spi_finalize_current_message(master);
+   return 0;
+}
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

Quoted 4 lines
Quoted 1 line

No matter is write-back or write-through.

Oh, do you want to assure the SMWDR value is always written directly to the hardware ?

yes,

Quoted 2 lines

btw. I think SMRDR should be precious ?

so, you think I should drop
regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0)

thanks again for your review.
best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#12 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 1 line · On 12/06/2018 08:30 AM, [email protected] wrote:

Hi Marek,

Hi,

Quoted 17 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller

driver

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines · Mason Yang
Quoted 3 lines

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

What changed in this V2 ?

[...]

see some description in [PATH v2 0/2]

I don't see any V2: list there.

Quoted 6 lines

including
1) remove RPC clock enable/dis-able control,
2) patch run time PM,
3) add RPC module software reset,
4) add regmap,
5) other coding style and so on.

Please include a detailed changelog in each subsequent patch series.

Quoted 26 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/spi/spi-renesas-rpc.c

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD |

RPC_CMNCR_SFDE |

Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 6 lines

+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);

drivers/spi/spi-renesas-rpc.c line 269

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It must have it!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

The compiler warning is usually an indication that this is something to check, not silence with a type cast.

Quoted 5 lines

Using get_unaligned(), patched code would be
-----------------------------------------------------
regmap_write(rpc->regmap, RPC_SMWDR0, get_unaligned((u32 *)(tx_buf + pos)));
----------------------------------------------------

Do you need the cast if you use get_unaligned() ?

Quoted 31 lines
Quoted 12 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

+         rpc->xferlen = *(u32 *)len;
+         rpc->totalxferlen += *(u32 *)len;
+      } else {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

Drop parenthesis around fls()

?
no way.

Quoted 6 lines

I would really appreciate it if you could explain things instead.

Geert already did so, by pointing out this is a confusing code formatting problem and how it should be fixed, so no need to repeat that. But I hope you understand how that sort of explanation is far more valuable than "no way" kind of reply.

okay, understood.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

+
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

yes!

Quoted 8 lines
Quoted 1 line

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

Using get_unaligned(), patched code would be
---------------------------------------------------------------
 rpc->cmd = RPC_SMCMR_CMD(get_unaligned((u8 *)xfer[0].tx_buf));
----------------------------------------------------------------

See above

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 24 lines

+   rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits 1));
+   rpc->addr = 0;

drivers/spi/spi-renesas-rpc.c new file +21 -0
+
+   if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
+
+      if (xfer[1].len == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+   }
+
+   switch (xfercnt) {
+   case 2:
+      if (xfer[1].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].rx_nbits >> 1));
+      } else if (xfer[1].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer

drivers/spi/spi-renesas-rpc.c line 592

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].tx_nbits >> 1));
+      }
+      break;
+
+   case 3:
+      if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].rx_nbits >> 1));

It seems this SMENR pattern repeats itself throughout the driver, can this be improved / deduplicated ?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

It seems no way!

Why ?

okay, I patch this with for( ) loop.

Please do, let's see how it looks .

Quoted 78 lines
Quoted 73 lines
Quoted 73 lines
Quoted 72 lines
Quoted 16 lines

+      } else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].tx_nbits >> 1));
+      }
+      break;

drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+   case 4:
+      if (xfer[2].len && xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_DME;
+         rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+      }
+
+      if (xfer[3].len && xfer[3].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[3].len)) | RPC_SMENR_SPIDB(fls

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+                  (xfer[3].rx_nbits >> 1));
+      }
+      break;
+
+   default:
+      break;
+   }
+}
+
+static int rpc_spi_xfer_message(struct rpc_spi *rpc, struct

spi_transfer *t)

Quoted 33 lines
drivers/spi/spi-renesas-rpc.c new file +33 -0
+{
+   int ret;
+
+   ret = rpc_spi_set_freq(rpc, t->speed_hz);
+   if (ret)
+      return ret;
+
+   ret = rpc_spi_io_xfer(rpc,
+               rpc->xfer_dir == SPI_MEM_DATA_OUT ?
+               t->tx_buf : NULL,
+               rpc->xfer_dir == SPI_MEM_DATA_IN ?
+               t->rx_buf : NULL);
+
+   return ret;
+}
+
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+               struct spi_message *msg)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(master);
+   struct spi_transfer *t;
+   int ret;
+
+   rpc_spi_transfer_setup(rpc, msg);
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (!list_is_last(&t->transfer_list, &msg->transfers))
+         continue;
+      ret = rpc_spi_xfer_message(rpc, t);
+      if (ret)
+         goto out;
+   }
+

drivers/spi/spi-renesas-rpc.c line 661

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   msg->status = 0;
+   msg->actual_length = rpc->totalxferlen;
+out:
+   spi_finalize_current_message(master);
+   return 0;
+}
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

Quoted 4 lines
Quoted 1 line

No matter is write-back or write-through.

Oh, do you want to assure the SMWDR value is always written directly to the hardware ?

Quoted 7 lines

yes,

Quoted 2 lines

btw. I think SMRDR should be precious ?

so, you think I should drop
regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0)

No, I am asking whether SMRDR should be marked precious or not.

[...]

Quoted 12 lines

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Quoted 1 line

Macronix International Co., Ltd.

Can you do something about this ^ please ?

Signature · 2 lines
Best regards,
Marek Vasut
#13 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Marek,

Quoted 15 lines
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines

drivers/spi/spi-renesas-rpc.c line 269

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

It must have it!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

The compiler warning is usually an indication that this is something to check, not silence with a type cast.

Quoted 8 lines
Quoted 6 lines

Using get_unaligned(), patched code would be
-----------------------------------------------------
regmap_write(rpc->regmap, RPC_SMWDR0,

                 get_unaligned((u32 *)(tx_buf + pos)));               

----------------------------------------------------

Do you need the cast if you use get_unaligned() ?

yes!

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 661

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

No matter is write-back or write-through.

Oh, do you want to assure the SMWDR value is always written directly

to

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

the hardware ?

yes,

Quoted 1 line
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

btw. I think SMRDR should be precious ?

so, you think I should drop
regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0)

No, I am asking whether SMRDR should be marked precious or not.

I don't think so,
precious_reg: the register should not be read outside of call from driver, i.e,. a clear on read interrupt status register.

Quoted 11 lines

[...]

Quoted 9 lines

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use

of

Quoted 1 line
Quoted 1 line

personal data is prohibited unless expressly permitted by personal

data

Quoted 6 lines
Quoted 3 lines

protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

Can you do something about this ^ please ?

I submit the patch file is by another remote git-server, which supports git-format patch, git send-mail and so on. But it can't receive email.

I get/send email are by office PC w/ Notes system and this "CONFx NOTE:" is appended automatically by Notes mail-server.

Please just never mind it.

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#14 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 2 lines · On 12/07/2018 08:24 AM, [email protected] wrote:

Hi Marek,

Hi,

Quoted 21 lines
Quoted 21 lines
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

*(u32 *) cast is probably not needed , fix casts globally.

It must have it!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

The compiler warning is usually an indication that this is something to check, not silence with a type cast.

Quoted 5 lines

Using get_unaligned(), patched code would be
-----------------------------------------------------
regmap_write(rpc->regmap, RPC_SMWDR0, get_unaligned((u32 *)(tx_buf + pos)));
----------------------------------------------------

Quoted 3 lines
Quoted 1 line

Do you need the cast if you use get_unaligned() ?

yes!

Why ? (you can drop one iteration here by explaining why right away, since I'll ask for that explanation for sure)

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

Review

Quoted 4 lines
(quoted diff) +4 -0
+
+static const struct regmap_range rpc_spi_volatile_ranges[] = {
+   regmap_reg_range(RPC_SMRDR0, RPC_SMRDR0),
+   regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0),

Why is SMWDR volatile ?

No matter is write-back or write-through.

Oh, do you want to assure the SMWDR value is always written directly to the hardware ?

yes,

Quoted 2 lines

btw. I think SMRDR should be precious ?

so, you think I should drop
regmap_reg_range(RPC_SMWDR0, RPC_SMWDR0)

Quoted 6 lines
Quoted 2 lines

No, I am asking whether SMRDR should be marked precious or not.

I don't think so,
precious_reg: the register should not be read outside of call from driver, i.e,. a clear on read interrupt status register.

If you read the reg outside of the call from driver, it will mess up the internal FIFO and the whole driver will get into undefined state, right? Maybe Mark can chime in ?

Quoted 19 lines
Quoted 14 lines

[...]

Quoted 12 lines

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Quoted 4 lines
Quoted 1 line

Macronix International Co., Ltd.

Can you do something about this ^ please ?

Quoted 8 lines

I submit the patch file is by another remote git-server, which supports git-format patch, git send-mail and so on. But it can't receive email.

I get/send email are by office PC w/ Notes system and this "CONFx NOTE:" is appended automatically by Notes mail-server.

Please just never mind it.

I am concerned MXIC can sue everyone on the CC list of this email based solely on your suggestion to ignore this paragraph. That's not a good position to be in.

Signature · 2 lines
Best regards,
Marek Vasut
#15 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to [email protected]

Hi Mason,

Quoted 15 lines · On Thu, Dec 6, 2018 at 8:31 AM <[email protected]> wrote:
Quoted 15 lines
Quoted 14 lines
Quoted 5 lines

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 2 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Quoted 7 lines

drivers/spi/spi-renesas-rpc.c line 559

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);

Is the cast needed ?

yes!

Quoted 8 lines
Quoted 1 line

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

Using get_unaligned(), patched code would be
---------------------------------------------------------------
rpc->cmd = RPC_SMCMR_CMD(get_unaligned((u8 *)xfer[0].tx_buf));
----------------------------------------------------------------

Using get_unaligned(0 is a bit strange for accessing a single byte quantity. Please keep the normal pointer dereference (including the cast).

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#16 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 22 lines · Geert Uytterhoeven

Hi Mason,

Quoted 19 lines · On Thu, Dec 6, 2018 at 8:31 AM <[email protected]> wrote:
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 7 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

drivers/spi/spi-renesas-rpc.c new file +3 -0
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Is the cast needed ?

yes!

Why ?

Get a compiler warning due to tx_bug is void *, as Geert replied.

Quoted 7 lines
Quoted 4 lines

Using get_unaligned(), patched code would be
---------------------------------------------------------------
rpc->cmd = RPC_SMCMR_CMD(get_unaligned((u8 *)xfer[0].tx_buf));
----------------------------------------------------------------

Using get_unaligned(0 is a bit strange for accessing a single byte quantity. Please keep the normal pointer dereference (including the cast).

Oh, right, for single bytes this is OK.

Signature · 2 lines
Best regards,
Marek Vasut
#17 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to Mason Yang

Hi Mason,

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Thanks for your patch!

drivers/spi/Kconfig config SPI_RSPI · line 533

Quoted 9 lines
drivers/spi/Kconfig +3 -0
@@ -528,6 +528,12 @@ config SPI_RSPI
        help
          SPI driver for Renesas RSPI and QSPI blocks.
 
+config SPI_RENESAS_RPC
+       tristate "Renesas R-Car Gen3 RPC SPI controller"
+       depends on SUPERH || ARCH_RENESAS || COMPILE_TEST

So this driver is intended for SuperH SoCs, too?
If not, please drop the dependency.

drivers/spi/spi-renesas-rpc.c line 208

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
 
+#ifdef CONFIG_RESET_CONTROLLER
+static int rpc_spi_do_reset(struct rpc_spi *rpc)

What's the purpose of the reset routine?
Given the #ifdef, is it optional or required?

drivers/spi/spi-renesas-rpc.c line 221

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+{
+       int i, ret;
+
+       ret = reset_control_reset(rpc->rstc);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < LOOP_TIMEOUT; i++) {
+               ret = reset_control_status(rpc->rstc);
+               if (ret == 0)
+                       return 0;
+               usleep_range(0, 1);
+       }

Why do you need this loop?
The delay in cpg_mssr_reset() should be sufficient.

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+
+       return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+       return -ETIMEDOUT;
+}
+#endif
 
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+                                       struct spi_message *msg)
+{

drivers/spi/spi-renesas-rpc.c line 647

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+       struct rpc_spi *rpc = spi_master_get_devdata(master);
+       struct spi_transfer *t;
+       int ret;
+
+       rpc_spi_transfer_setup(rpc, msg);
+
+       list_for_each_entry(t, &msg->transfers, transfer_list) {
+               if (!list_is_last(&t->transfer_list, &msg->transfers))
+                       continue;
+               ret = rpc_spi_xfer_message(rpc, t);

rpc_spi_xfer_message() sounds like a bad name to me, given it operates on a transfer, not on a message.

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+               if (ret)
+                       goto out;
+       }
+
+       msg->status = 0;
+       msg->actual_length = rpc->totalxferlen;
+out:
+       spi_finalize_current_message(master);

drivers/spi/spi-renesas-rpc.c line 726

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+       return 0;
+}
 
 
+static int rpc_spi_probe(struct platform_device *pdev)
+{
 
+       rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+       if (IS_ERR(rpc->rstc))
+               return PTR_ERR(rpc->rstc);

This will return an error if CONFIG_RESET_CONTROLLER is not set, hence the #ifdef above is moot.

drivers/spi/spi-renesas-rpc.c line 733

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+       pm_runtime_enable(&pdev->dev);
+       master->auto_runtime_pm = true;
+
+       master->num_chipselect = 1;
+       master->mem_ops = &rpc_spi_mem_ops;
+       master->transfer_one_message = rpc_spi_transfer_one_message;

Is there any reason you cannot use the standard spi_transfer_one_message, i.e. provide spi_controller.transfer_one() instead of spi_controller.transfer_one_message()?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#18 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Geert,

Quoted 24 lines

"Geert Uytterhoeven" <[email protected]>
2018/12/05 下午 05:06

To

[email protected],

cc

"Mark Brown" <[email protected]>, "Marek Vasut" <[email protected]>, "Linux Kernel Mailing List" <linux- [email protected]>, "linux-spi" <[email protected]>, "Boris Brezillon" <[email protected]>, "Linux-Renesas" <[email protected]>, "Geert Uytterhoeven" <geert [email protected]>, [email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Mason,

On Mon, Dec 3, 2018 at 10:19 AM Mason Yang <[email protected]>

Quoted 12 lines · wrote:
Quoted 3 lines

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Thanks for your patch!

Quoted 6 lines
drivers/spi/Kconfig +0 -0
@@ -528,6 +528,12 @@ config SPI_RSPI
        help
          SPI driver for Renesas RSPI and QSPI blocks.
 
Quoted 7 lines

drivers/spi/Kconfig config SPI_RSPI · line 533

Quoted 3 lines
drivers/spi/Kconfig +3 -0
+config SPI_RENESAS_RPC
+       tristate "Renesas R-Car Gen3 RPC SPI controller"
+       depends on SUPERH || ARCH_RENESAS || COMPILE_TEST

So this driver is intended for SuperH SoCs, too?
If not, please drop the dependency.

okay, I will drop "SUPERH".

Quoted 7 lines

drivers/spi/spi-renesas-rpc.c line 208

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
 
+#ifdef CONFIG_RESET_CONTROLLER
+static int rpc_spi_do_reset(struct rpc_spi *rpc)

What's the purpose of the reset routine?

in case RPC xfer is time-out due to something wrong in RPC module, as Marek comments.

Quoted 19 lines

Given the #ifdef, is it optional or required?

drivers/spi/spi-renesas-rpc.c line 221

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+{
+       int i, ret;
+
+       ret = reset_control_reset(rpc->rstc);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < LOOP_TIMEOUT; i++) {
+               ret = reset_control_status(rpc->rstc);
+               if (ret == 0)
+                       return 0;
+               usleep_range(0, 1);
+       }

Why do you need this loop?
The delay in cpg_mssr_reset() should be sufficient.

yup, I know there is already 35 us delay in cpg_mssr_reset(). If you think reset_control_status()checking is not necessary, I will drop it.

Quoted 10 lines
Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+       return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+       return -ETIMEDOUT;
+}
+#endif
Quoted 17 lines

drivers/spi/spi-renesas-rpc.c line 647

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+                                       struct spi_message *msg)
+{
+       struct rpc_spi *rpc = spi_master_get_devdata(master);
+       struct spi_transfer *t;
+       int ret;
+
+       rpc_spi_transfer_setup(rpc, msg);
+
+       list_for_each_entry(t, &msg->transfers, transfer_list) {
+               if (!list_is_last(&t->transfer_list, &msg->transfers))
+                       continue;
+               ret = rpc_spi_xfer_message(rpc, t);

rpc_spi_xfer_message() sounds like a bad name to me, given it operates on a transfer, not on a message.

Because RPC send a entire SPI message at one time, not separately, that is the 1'st transfer is for command, the 2'nd transfer is for address/data
and so on.
The reason is CS# pin control restriction in RPC HW module.

Quoted 12 lines
Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+               if (ret)
+                       goto out;
+       }
+
+       msg->status = 0;
+       msg->actual_length = rpc->totalxferlen;
+out:
+       spi_finalize_current_message(master);
+       return 0;
+}
Quoted 4 lines

drivers/spi/spi-renesas-rpc.c

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+static int rpc_spi_probe(struct platform_device *pdev)
+{
 
+       rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, 

NULL);

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 726

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+       if (IS_ERR(rpc->rstc))
+               return PTR_ERR(rpc->rstc);

This will return an error if CONFIG_RESET_CONTROLLER is not set, hence the #ifdef above is moot.

You are right.
so, I should do
Option 1: remove #CONFIG_RESET_CONTROLLER
Option 2: add #CONFIG_RESET_CONTROLLER for
devm_reset_control_get_exclusive()

please comments on it, thanks.

Quoted 12 lines

drivers/spi/spi-renesas-rpc.c line 733

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+       pm_runtime_enable(&pdev->dev);
+       master->auto_runtime_pm = true;
+
+       master->num_chipselect = 1;
+       master->mem_ops = &rpc_spi_mem_ops;
+       master->transfer_one_message = rpc_spi_transfer_one_message;

Is there any reason you cannot use the standard spi_transfer_one_message, i.e. provide spi_controller.transfer_one() instead of spi_controller.transfer_one_message()?

It seems there is a RPC HW restriction in CS# pin control. Therefore, it can't send the 1'st spi-transfer for command and then keeping CS# pin goes low for the 2'nd spi-transfer for address/data and so on.

Quoted 9 lines

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker.

But

Quoted 1 line

when I'm talking to journalists I just say "programmer" or somethinglike

that.

Quoted 1 line

-- Linus Torvalds

thanks again for your review & help.
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#19 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 164 lines · On 12/06/2018 06:56 AM, [email protected] wrote:

Hi Geert,

Quoted 24 lines

"Geert Uytterhoeven" <[email protected]>
2018/12/05 下午 05:06

To

[email protected],

cc

"Mark Brown" <[email protected]>, "Marek Vasut" <[email protected]>, "Linux Kernel Mailing List" <linux- [email protected]>, "linux-spi" <[email protected]>, "Boris Brezillon" <[email protected]>, "Linux-Renesas" <[email protected]>, "Geert Uytterhoeven" <geert [email protected]>, [email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Mason,

On Mon, Dec 3, 2018 at 10:19 AM Mason Yang <[email protected]>

Quoted 12 lines · wrote:
Quoted 3 lines

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

Thanks for your patch!

Quoted 6 lines
drivers/spi/Kconfig +0 -0
@@ -528,6 +528,12 @@ config SPI_RSPI

        help
          SPI driver for Renesas RSPI and QSPI blocks.

Quoted 7 lines
Quoted 3 lines

+config SPI_RENESAS_RPC
+       tristate "Renesas R-Car Gen3 RPC SPI controller"
+       depends on SUPERH || ARCH_RENESAS || COMPILE_TEST

So this driver is intended for SuperH SoCs, too?
If not, please drop the dependency.

okay, I will drop "SUPERH".

Quoted 7 lines

drivers/spi/spi-renesas-rpc.c line 208

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
 
+#ifdef CONFIG_RESET_CONTROLLER
+static int rpc_spi_do_reset(struct rpc_spi *rpc)

What's the purpose of the reset routine?

in case RPC xfer is time-out due to something wrong in RPC module, as Marek comments.

Quoted 19 lines

Given the #ifdef, is it optional or required?

drivers/spi/spi-renesas-rpc.c line 221

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+{
+       int i, ret;
+
+       ret = reset_control_reset(rpc->rstc);
+       if (ret)
+               return ret;
+
+       for (i = 0; i < LOOP_TIMEOUT; i++) {
+               ret = reset_control_status(rpc->rstc);
+               if (ret == 0)
+                       return 0;
+               usleep_range(0, 1);
+       }

Why do you need this loop?
The delay in cpg_mssr_reset() should be sufficient.

yup, I know there is already 35 us delay in cpg_mssr_reset(). If you think reset_control_status()checking is not necessary, I will drop it.

Quoted 10 lines
Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+       return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+       return -ETIMEDOUT;
+}
+#endif
Quoted 17 lines

drivers/spi/spi-renesas-rpc.c line 647

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+static int rpc_spi_transfer_one_message(struct spi_master *master,
+                                       struct spi_message *msg)
+{
+       struct rpc_spi *rpc = spi_master_get_devdata(master);
+       struct spi_transfer *t;
+       int ret;
+
+       rpc_spi_transfer_setup(rpc, msg);
+
+       list_for_each_entry(t, &msg->transfers, transfer_list) {
+               if (!list_is_last(&t->transfer_list, &msg->transfers))
+                       continue;
+               ret = rpc_spi_xfer_message(rpc, t);

rpc_spi_xfer_message() sounds like a bad name to me, given it operates on a transfer, not on a message.

Because RPC send a entire SPI message at one time, not separately, that is the 1'st transfer is for command, the 2'nd transfer is for address/data
and so on.
The reason is CS# pin control restriction in RPC HW module.

Quoted 15 lines
Quoted 14 lines

+               if (ret)
+                       goto out;
+       }

drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+       msg->status = 0;
+       msg->actual_length = rpc->totalxferlen;
+out:
+       spi_finalize_current_message(master);
+       return 0;
+}
 
 
+static int rpc_spi_probe(struct platform_device *pdev)
+{
Quoted 7 lines
Quoted 3 lines

+       rpc->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+       if (IS_ERR(rpc->rstc))
+               return PTR_ERR(rpc->rstc);

This will return an error if CONFIG_RESET_CONTROLLER is not set, hence the #ifdef above is moot.

You are right.
so, I should do
Option 1: remove #CONFIG_RESET_CONTROLLER
Option 2: add #CONFIG_RESET_CONTROLLER for
devm_reset_control_get_exclusive()

please comments on it, thanks.

Quoted 12 lines

drivers/spi/spi-renesas-rpc.c line 733

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+       pm_runtime_enable(&pdev->dev);
+       master->auto_runtime_pm = true;
+
+       master->num_chipselect = 1;
+       master->mem_ops = &rpc_spi_mem_ops;
+       master->transfer_one_message = rpc_spi_transfer_one_message;

Is there any reason you cannot use the standard spi_transfer_one_message, i.e. provide spi_controller.transfer_one() instead of spi_controller.transfer_one_message()?

Quoted 4 lines

It seems there is a RPC HW restriction in CS# pin control. Therefore, it can't send the 1'st spi-transfer for command and then keeping CS# pin goes low for the 2'nd spi-transfer for address/data and so on.

Isn't register DRCR bit SSLN/SSLE exactly for this purpose ?

Signature · 2 lines
Best regards,
Marek Vasut
#20 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hi Marek,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

drivers/spi/spi-renesas-rpc.c

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+       pm_runtime_enable(&pdev->dev);
+       master->auto_runtime_pm = true;
+
+       master->num_chipselect = 1;
+       master->mem_ops = &rpc_spi_mem_ops;
+       master->transfer_one_message = 

rpc_spi_transfer_one_message;

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

Is there any reason you cannot use the standard spi_transfer_one_message, i.e. provide spi_controller.transfer_one() instead of spi_controller.transfer_one_message()?

It seems there is a RPC HW restriction in CS# pin control. Therefore, it can't send the 1'st spi-transfer for command and then keeping CS# pin goes low for the 2'nd spi-transfer for address/data

and

Quoted 4 lines
Quoted 1 line

so on.

Isn't register DRCR bit SSLN/SSLE exactly for this purpose ?

DRCR is for RPC module works in external space read mode, using memcpy( ). It is not for _spi_sync().

I only could use manual I/O mode by SMCR@bit-8 SSLKP and I found it has some
restrictions in manual I/O mode to control CS# pin.

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#21 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 1 line · On 12/06/2018 10:17 AM, [email protected] wrote:

Hi Marek,

Hi,

Quoted 21 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines

drivers/spi/spi-renesas-rpc.c line 733

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+       pm_runtime_enable(&pdev->dev);
+       master->auto_runtime_pm = true;
+
+       master->num_chipselect = 1;
+       master->mem_ops = &rpc_spi_mem_ops;
+       master->transfer_one_message = rpc_spi_transfer_one_message;

Is there any reason you cannot use the standard spi_transfer_one_message, i.e. provide spi_controller.transfer_one() instead of spi_controller.transfer_one_message()?

Quoted 7 lines
Quoted 4 lines

It seems there is a RPC HW restriction in CS# pin control. Therefore, it can't send the 1'st spi-transfer for command and then keeping CS# pin goes low for the 2'nd spi-transfer for address/data and so on.

Isn't register DRCR bit SSLN/SSLE exactly for this purpose ?

Quoted 6 lines

DRCR is for RPC module works in external space read mode, using memcpy( ). It is not for _spi_sync().

I only could use manual I/O mode by SMCR@bit-8 SSLKP and I found it has some
restrictions in manual I/O mode to control CS# pin.

What restrictions are those ? I am aware of some, maybe there is more.

Signature · 2 lines
Best regards,
Marek Vasut
#22 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to Mason Yang

Hello!

I'd already started the v2 driver review before you posted v3, so here goes...

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

[...]

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +0 -0
new file mode 100644
index 0000000..ac9094e
@@ -0,0 +1,808 @@

[...]

drivers/spi/spi-renesas-rpc.c line 25

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_CMNCR		0x0000	/* R/W */
+#define RPC_CMNCR_MD		BIT(31)
+#define RPC_CMNCR_SFDE		BIT(24)

This bit is undocumented as of the gen3 manual v1.0. I'd like this to be reflected
in a comment...

[...]

drivers/spi/spi-renesas-rpc.c line 33

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+#define RPC_CMNCR_IO3FV(val)	(((val) & 0x3) << 14)
+#define RPC_CMNCR_IO2FV(val)	(((val) & 0x3) << 12)

These 2 are also undocumented.

[...]

drivers/spi/spi-renesas-rpc.c line 40

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+#define RPC_CMNCR_CPHAT		BIT(6)
+#define RPC_CMNCR_CPHAR		BIT(5)
+#define RPC_CMNCR_SSLP		BIT(4)
+#define RPC_CMNCR_CPOL		BIT(3)

And these 4...

drivers/spi/spi-renesas-rpc.c line 50

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_DRCR		0x000C	/* R/W */
+#define RPC_DRCR_SSLN		BIT(24)
+#define RPC_DRCR_RBURST(v)	(((v) & 0x1F) << 16)

More like ((v) - 1), like in another register...

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_DRCR_RCF		BIT(9)
+#define RPC_DRCR_RBE		BIT(8)
+#define RPC_DRCR_SSLE		BIT(0)

[...]

drivers/spi/spi-renesas-rpc.c line 60

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+#define RPC_DREAR		0x0014	/* R/W */
+#define RPC_DREAR_EAC		BIT(0)

The manual says it takes bits 0 to 2...

[...]

drivers/spi/spi-renesas-rpc.c line 91

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+#define RPC_SMADR		0x0028	/* R/W */
+#define RPC_SMOPR		0x002C	/* R/W */
+#define RPC_SMOPR_OPD0(o)	(((o) & 0xFF) << 0)
+#define RPC_SMOPR_OPD1(o)	(((o) & 0xFF) << 8)
+#define RPC_SMOPR_OPD2(o)	(((o) & 0xFF) << 16)
+#define RPC_SMOPR_OPD3(o)	(((o) & 0xFF) << 24)

You either go in descending or ascending order, not both. :-)

[...]

drivers/spi/spi-renesas-rpc.c line 136

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+#define RPC_PHYCNT		0x007C	/* R/W */
+#define RPC_PHYCNT_CAL		BIT(31)
+#define PRC_PHYCNT_OCTA_AA	BIT(22)
+#define PRC_PHYCNT_OCTA_SA	BIT(23)
+#define PRC_PHYCNT_EXDS		BIT(21)
+#define RPC_PHYCNT_OCT		BIT(20)
+#define RPC_PHYCNT_STRTIM(v)	(((v) & 0x7) << 15)
+#define RPC_PHYCNT_WBUF2	BIT(4)
+#define RPC_PHYCNT_WBUF		BIT(2)
+#define RPC_PHYCNT_MEM(v)	(((v) & 0x3) << 0)

The manual calls this field PHYMEM...

[...]

Quoted 1 line

+#define LOOP_TIMEOUT 1024

It's more like TIMEOUT_LOOPS. :-)

[...]

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+	/*
+	 * NOTE: The 0x260 are undocumented bits, but they must be set.
+	 *	RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+	 *	0x0 : the delay is biggest,
+	 *	0x1 : the delay is 2nd biggest,
+	 *	0x3 or 0x6 is a recommended value.

drivers/spi/spi-renesas-rpc.c line 201

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	 */
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+				  RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
+	/*
+	 * NOTE: The 0x31511144 and 0x431 are undocumented bits,
+	 *	 but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+	 */
+	regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+	regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);

0x400 is actually documented, bits 0..7 are read only and default to 0x31...

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+#ifdef CONFIG_RESET_CONTROLLER
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+	int i, ret;

drivers/spi/spi-renesas-rpc.c line 220

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+	ret = reset_control_reset(rpc->rstc);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < LOOP_TIMEOUT; i++) {
+		ret = reset_control_status(rpc->rstc);
+		if (ret == 0)
+			return 0;
+		usleep_range(0, 1);

Are you serious? :-)

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	}
+
+	return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+	return -ETIMEDOUT;
+}
+#endif

[...]

drivers/spi/spi-renesas-rpc.c line 257

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+			   const void *tx_buf, void *rx_buf)
+{
+	u32 smenr, smcr, data, pos = 0;
+	int ret = 0;
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+				  RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+				  RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);

Just 0, please.

drivers/spi/spi-renesas-rpc.c line 266

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+	regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+	regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+	if (tx_buf) {
+		smenr = rpc->smenr;
+
+		while (pos < rpc->xferlen) {
+			u32 nbytes = rpc->xferlen  - pos;

One space before '-' is enough. :-)

drivers/spi/spi-renesas-rpc.c line 269

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+
+			regmap_write(rpc->regmap, RPC_SMWDR0,
+				     *(u32 *)(tx_buf + pos));

Ugh... what about the data endianness?

drivers/spi/spi-renesas-rpc.c line 277

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+
+			if (nbytes > 4) {
+				nbytes = 4;
+				smcr = rpc->smcr |
+				       RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+			} else {
+				smcr = rpc->smcr | RPC_SMCR_SPIE;
+			}

Please do this repeated part outside *if*:

			smcr = rpc->smcr | RPC_SMCR_SPIE;
			if (nbytes > 4) {
				nbytes = 4;
				smcr |= RPC_SMCR_SSLKP;
			}

[...]

drivers/spi/spi-renesas-rpc.c line 291

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+	} else if (rx_buf) {
+		while (pos < rpc->xferlen) {
+			u32 nbytes = rpc->xferlen  - pos;

Again, 1 space is enough...

drivers/spi/spi-renesas-rpc.c line 304

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+
+			if (nbytes > 4)
+				nbytes = 4;
+
+			regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+			regmap_write(rpc->regmap, RPC_SMCR,
+				     rpc->smcr | RPC_SMCR_SPIE);
+			ret = wait_msg_xfer_end(rpc);
+			if (ret)
+				goto out;
+
+			regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+			memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);

What?! The 'data' variable is not in a MMIO region, you can use plain memcpy().
Not sure about the endianness tho...

[...]

drivers/spi/spi-renesas-rpc.c line 312

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+	} else {
+		regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+		regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);

Er... what's this for?

drivers/spi/spi-renesas-rpc.c line 318

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+		ret = wait_msg_xfer_end(rpc);
+		if (ret)
+			goto out;
+	}
+
+	return ret;

Need empty line here...

drivers/spi/spi-renesas-rpc.c line 331

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+out:
+	return rpc_spi_do_reset(rpc);
+}
+
+static void rpc_spi_mem_set_prep_op_cfg(struct spi_device *spi,
+					const struct spi_mem_op *op,
+					u64 *offs, size_t *len)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(spi->master);
+
+	rpc->cmd = RPC_SMCMR_CMD(op->cmd.opcode);
+	rpc->smenr = RPC_SMENR_CDE |
+		     RPC_SMENR_CDB(fls(op->cmd.buswidth >> 1));
    Maybe ilog2()?

drivers/spi/spi-renesas-rpc.c line 338

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+	rpc->totalxferlen = 1;
+	rpc->xfer_dir = SPI_MEM_NO_DATA;
+	rpc->xferlen = 0;
+	rpc->addr = 0;
+
+	if (op->addr.nbytes) {
+		rpc->smenr |= RPC_SMENR_ADB(fls(op->addr.buswidth >> 1));

Again, ilog2()?

[...]

drivers/spi/spi-renesas-rpc.c line 364

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+	if (op->data.nbytes || (offs && len)) {
+		if (op->data.dir == SPI_MEM_DATA_IN) {
+			rpc->smcr = RPC_SMCR_SPIRE;
+			rpc->xfer_dir = SPI_MEM_DATA_IN;
+		} else if (op->data.dir == SPI_MEM_DATA_OUT) {
+			rpc->smcr = RPC_SMCR_SPIWE;
+			rpc->xfer_dir = SPI_MEM_DATA_OUT;
+		}

This code is asking for using *switch*...

drivers/spi/spi-renesas-rpc.c line 368

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+
+		if (offs && len) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+					(*(u32 *)len)) | RPC_SMENR_SPIDB

Unobvious line breaks...

drivers/spi/spi-renesas-rpc.c

Quoted 1 line
drivers/spi/spi-renesas-rpc.c new file +1 -0
+					(fls(op->data.buswidth >> 1));

ilog2()?

drivers/spi/spi-renesas-rpc.c line 376

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+			rpc->xferlen = *(u32 *)len;
+			rpc->totalxferlen += *(u32 *)len;
+		} else {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+					(op->data.nbytes)) | RPC_SMENR_SPIDB
+					(fls(op->data.buswidth >> 1));

You can factor out a large part of this expression and calculate it before *if*...

drivers/spi/spi-renesas-rpc.c line 388

Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+
+			rpc->xferlen = op->data.nbytes;
+			rpc->totalxferlen += op->data.nbytes;
+		}
+	}
+}
+
+static bool rpc_spi_mem_supports_op(struct spi_mem *mem,
+				    const struct spi_mem_op *op)
+{
+	if (op->data.buswidth > 4 || op->addr.buswidth > 4 ||
+	    op->dummy.buswidth > 4 || op->cmd.buswidth > 4)

Hm, the manual doesn't mention 2-wire SPI mode...

Quoted 18 lines
drivers/spi/spi-renesas-rpc.c new file +18 -0
+		return false;
+
+	if (op->addr.nbytes > 4)
+		return false;
+
+	return true;
+}
+
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
+				       u64 offs, size_t len, void *buf)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+	int ret;
+
+	if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+		return -EINVAL;
+
+	ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);

drivers/spi/spi-renesas-rpc.c line 416

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	if (ret)
+		return ret;
+
+	rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+				    &desc->info.op_tmpl, &offs, &len);
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+		     RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+		     RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |

RPC_DRCR_RBURST(32), please.

drivers/spi/spi-renesas-rpc.c line 421

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+		     RPC_DRCR_RBE);
+	regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC);
+	regmap_write(rpc->regmap, RPC_DROPR, 0);
+	regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr);

Looks liky you need a more generic field name (like rpc->cmd)...

drivers/spi/spi-renesas-rpc.c line 425

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+	regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
+	regmap_write(rpc->regmap, RPC_DRDRENR, 0);
+
+	memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, len);

What if the read direct-mapped area is less than U32_MAX in size (and it will be,
according to your bindings)?

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+	return len;
+}
+
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,

drivers/spi/spi-renesas-rpc.c line 440

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+					u64 offs, size_t len, const void *buf)
+{
+	struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+	int ret;
+
+	if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+		return -EINVAL;
+
+	if (WARN_ON(len > RPC_WBUF_SIZE))
+		return -EIO;

Why not write 256 bytes and return w/that?

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+
+	ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+	if (ret)
+		return ret;

drivers/spi/spi-renesas-rpc.c line 454

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+	rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+				    &desc->info.op_tmpl, &offs, &len);
+
+	regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE |
+				  RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+				  RPC_CMNCR_BSZ(0));
+	regmap_write(rpc->regmap, RPC_SMDRENR, 0);
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL | 0x260 |
+				  RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF);

Didn't understand this 2-write-buffers thing...

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+	memcpy_toio(rpc->base + RPC_WBUF, buf, len);
+
+	regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+	regmap_write(rpc->regmap, RPC_SMADR, offs);
+	regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);

drivers/spi/spi-renesas-rpc.c line 470

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+	ret = wait_msg_xfer_end(rpc);
+	if (ret)
+		goto out;
+
+	regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RCF);
+	regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+				  RPC_PHYCNT_STRTIM(6) | 0x260);
+
+	return len;

Need empty line here.

drivers/spi/spi-renesas-rpc.c line 321

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+out:
+	return rpc_spi_do_reset(rpc);
+}

[...]> +static void rpc_spi_transfer_setup(struct rpc_spi *rpc,

Quoted 19 lines
drivers/spi/spi-renesas-rpc.c new file +19 -0
+				   struct spi_message *msg)
+{
+	struct spi_transfer *t, xfer[4] = { };
+	u32 i, xfercnt, xferpos = 0;
+
+	rpc->totalxferlen = 0;
+	rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+	list_for_each_entry(t, &msg->transfers, transfer_list) {
+		if (t->tx_buf) {
+			xfer[xferpos].tx_buf = t->tx_buf;
+			xfer[xferpos].tx_nbits = t->tx_nbits;
+		}
+
+		if (t->rx_buf) {
+			xfer[xferpos].rx_buf = t->rx_buf;
+			xfer[xferpos].rx_nbits = t->rx_nbits;
+		}
+

drivers/spi/spi-renesas-rpc.c line 550

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+		if (t->len) {
+			xfer[xferpos++].len = t->len;
+			rpc->totalxferlen += t->len;
+		}
+
+		if (list_is_last(&t->transfer_list, &msg->transfers)) {
+			if (xferpos > 1 && t->rx_buf) {
+				rpc->xfer_dir = SPI_MEM_DATA_IN;
+				rpc->smcr = RPC_SMCR_SPIRE;
+			} else if (xferpos > 1 && t->tx_buf) {

Why check 'xferpos' twice?

drivers/spi/spi-renesas-rpc.c line 560

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+				rpc->xfer_dir = SPI_MEM_DATA_OUT;
+				rpc->smcr = RPC_SMCR_SPIWE;
+			}
+		}
+	}
+
+	xfercnt = xferpos;
+	rpc->xferlen = xfer[--xferpos].len;
+	rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);
+	rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits >> 1));

ilog2()?

drivers/spi/spi-renesas-rpc.c line 564

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+	rpc->addr = 0;
+
+	if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+		rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));

ilog2()?

drivers/spi/spi-renesas-rpc.c line 567

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+		for (i = 0; i < xfer[1].len; i++)
+			rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+					<< (8 * (xfer[1].len - i - 1));

Ugh, you need get_unaligned_*()...

Quoted 37 lines
drivers/spi/spi-renesas-rpc.c new file +37 -0
+
+		if (xfer[1].len == 4)
+			rpc->smenr |= RPC_SMENR_ADE(0xf);
+		else
+			rpc->smenr |= RPC_SMENR_ADE(0x7);
+	}
+
+	switch (xfercnt) {
+	case 2:
+		if (xfer[1].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[1].rx_nbits >> 1));
+		} else if (xfer[1].tx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[1].tx_nbits >> 1));
+		}
+		break;
+
+	case 3:
+		if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[2].rx_nbits >> 1));
+		} else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[2].tx_nbits >> 1));
+		}
+		break;
+
+	case 4:
+		if (xfer[2].len && xfer[2].tx_buf) {
+			rpc->smenr |= RPC_SMENR_DME;
+			rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+		}

drivers/spi/spi-renesas-rpc.c line 614

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+		if (xfer[3].len && xfer[3].rx_buf) {
+			rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+				      (xfer[3].len)) | RPC_SMENR_SPIDB(fls
+				      (xfer[3].rx_nbits >> 1));
+		}
+		break;
+
+	default:
+		break;

Ugh... don't want to repeat after Marek. :-)

[...]

drivers/spi/spi-renesas-rpc.c line 675

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static const struct regmap_config rpc_spi_regmap_config = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.fast_io = true,
+	.max_register = RPC_WBUF + RPC_WBUF_SIZE,

Ugh... 0x8100/4 regs, of which the majority isn't used... :-/

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+	.volatile_table = &rpc_spi_volatile_table,
+};
+
+static int rpc_spi_probe(struct platform_device *pdev)
+{
+	struct spi_master *master;
+	struct resource *res;
+	struct rpc_spi *rpc;
+	const struct regmap_config *regmap_config;
+	int ret;

[...]

drivers/spi/spi-renesas-rpc.c line 701

Quoted 1 line
drivers/spi/spi-renesas-rpc.c new file +1 -0
+	res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rpc_regs");

I'd suggest just "regs".

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+	rpc->base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(rpc->base))
+		return PTR_ERR(rpc->base);

[...]

drivers/spi/spi-renesas-rpc.c line 761

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+err_put_master:
+	spi_master_put(master);
+	pm_runtime_disable(&pdev->dev);
+
+	return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	pm_runtime_disable(&pdev->dev);
+	spi_unregister_master(master);

No spi_master_put() here?

[...]

MBR, Sergei

#23 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Quoted 17 lines · Sergei Shtylyov

Hello!

I'd already started the v2 driver review before you posted v3, so here goes...

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

[...]

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +0 -0
new file mode 100644
index 0000000..ac9094e
@@ -0,0 +1,808 @@

[...]

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 25

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_CMNCR		0x0000	/* R/W */
+#define RPC_CMNCR_MD		BIT(31)
+#define RPC_CMNCR_SFDE		BIT(24)

This bit is undocumented as of the gen3 manual v1.0. I'd like this to be reflected
in a comment...

FYI, not even in v1.50 .

Signature · 2 lines
Best regards,
Marek Vasut
#24 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

In reply to Sergei Shtylyov

Hi Sergei,

thanks for your review,

Quoted 24 lines

"Sergei Shtylyov" <[email protected]> 2018/12/08 上午 02:18

To

"Mason Yang" <[email protected]>, [email protected], [email protected], [email protected], linux- [email protected], [email protected], linux-renesas- [email protected], "Geert Uytterhoeven" <[email protected]>,

cc

[email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hello!

I'd already started the v2 driver review before you posted v3, so
here goes...

Quoted 7 lines
Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

[...]

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/spi/spi-renesas-rpc.c

Quoted 34 lines
Quoted 5 lines

new file mode 100644
index 0000000..ac9094e

drivers/spi/spi-renesas-rpc.c new file +0 -0
@@ -0,0 +1,808 @@

[...]

drivers/spi/spi-renesas-rpc.c line 25

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_CMNCR      0x0000   /* R/W */
+#define RPC_CMNCR_MD      BIT(31)
+#define RPC_CMNCR_SFDE      BIT(24)

This bit is undocumented as of the gen3 manual v1.0. I'd like
this to be reflected
in a comment...

[...]

drivers/spi/spi-renesas-rpc.c line 33

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+#define RPC_CMNCR_IO3FV(val)   (((val) & 0x3) << 14)
+#define RPC_CMNCR_IO2FV(val)   (((val) & 0x3) << 12)

These 2 are also undocumented.

[...]

drivers/spi/spi-renesas-rpc.c line 40

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+#define RPC_CMNCR_CPHAT      BIT(6)
+#define RPC_CMNCR_CPHAR      BIT(5)
+#define RPC_CMNCR_SSLP      BIT(4)
+#define RPC_CMNCR_CPOL      BIT(3)
   And these 4...

drivers/spi/spi-renesas-rpc.c line 50

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_DRCR      0x000C   /* R/W */
+#define RPC_DRCR_SSLN      BIT(24)
+#define RPC_DRCR_RBURST(v)   (((v) & 0x1F) << 16)

More like ((v) - 1), like in another register...

Quoted 8 lines
Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_DRCR_RCF      BIT(9)
+#define RPC_DRCR_RBE      BIT(8)
+#define RPC_DRCR_SSLE      BIT(0)

[...]

drivers/spi/spi-renesas-rpc.c line 60

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+#define RPC_DREAR      0x0014   /* R/W */
+#define RPC_DREAR_EAC      BIT(0)

The manual says it takes bits 0 to 2...

yup, EAC[2:0]
but as datasheet description, either 0 or 1 is OK to BIT(0), other than above setting is prohibited

Quoted 10 lines

[...]

drivers/spi/spi-renesas-rpc.c line 91

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+#define RPC_SMADR      0x0028   /* R/W */
+#define RPC_SMOPR      0x002C   /* R/W */
+#define RPC_SMOPR_OPD0(o)   (((o) & 0xFF) << 0)
+#define RPC_SMOPR_OPD1(o)   (((o) & 0xFF) << 8)
+#define RPC_SMOPR_OPD2(o)   (((o) & 0xFF) << 16)
+#define RPC_SMOPR_OPD3(o)   (((o) & 0xFF) << 24)

You either go in descending or ascending order, not both. :-)

I can't get your point.

Quoted 15 lines

[...]

drivers/spi/spi-renesas-rpc.c line 136

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+#define RPC_PHYCNT      0x007C   /* R/W */
+#define RPC_PHYCNT_CAL      BIT(31)
+#define PRC_PHYCNT_OCTA_AA   BIT(22)
+#define PRC_PHYCNT_OCTA_SA   BIT(23)
+#define PRC_PHYCNT_EXDS      BIT(21)
+#define RPC_PHYCNT_OCT      BIT(20)
+#define RPC_PHYCNT_STRTIM(v)   (((v) & 0x7) << 15)
+#define RPC_PHYCNT_WBUF2   BIT(4)
+#define RPC_PHYCNT_WBUF      BIT(2)
+#define RPC_PHYCNT_MEM(v)   (((v) & 0x3) << 0)

The manual calls this field PHYMEM...

ok, patch it in v4, thanks.

Quoted 4 lines

[...]

Quoted 1 line

+#define LOOP_TIMEOUT 1024

It's more like TIMEOUT_LOOPS. :-)

drop it in PATH v3 already.

Quoted 14 lines

[...]

Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 201

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+   /*
+    * NOTE: The 0x31511144 and 0x431 are undocumented bits,
+    *    but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+    */
+   regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+   regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);

0x400 is actually documented, bits 0..7 are read only and defaultto

0x31...

I got these values from R-Car bare-metal code, mini-Monitor v4.01.

What should I describe these bits 0x400 and 0x31 if it is needed?

Quoted 17 lines
Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+#ifdef CONFIG_RESET_CONTROLLER
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   int i, ret;

drivers/spi/spi-renesas-rpc.c line 220

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+
+   ret = reset_control_reset(rpc->rstc);
+   if (ret)
+      return ret;
+
+   for (i = 0; i < LOOP_TIMEOUT; i++) {
+      ret = reset_control_status(rpc->rstc);
+      if (ret == 0)
+         return 0;
+      usleep_range(0, 1);

Are you serious? :-)

drop this LOOP_TIMEOUT loop as Geert comments in PATCH v3.

Quoted 12 lines
Quoted 11 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   }
+
+   return -ETIMEDOUT;
+}
+#else
+static int rpc_spi_do_reset(struct rpc_spi *rpc)
+{
+   return -ETIMEDOUT;
+}
+#endif

[...]

Quoted 7 lines

drivers/spi/spi-renesas-rpc.c

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+static int rpc_spi_io_xfer(struct rpc_spi *rpc,
+            const void *tx_buf, void *rx_buf)
+{
+   u32 smenr, smcr, data, pos = 0;
+   int ret = 0;
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE 

|

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 257

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0x0);

Just 0, please.

Quoted 11 lines

drivers/spi/spi-renesas-rpc.c line 266

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_SMADR, rpc->addr);
+
+   if (tx_buf) {
+      smenr = rpc->smenr;
+
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;

One space before '-' is enough. :-)

above two.
okay, thanks~

Quoted 16 lines

drivers/spi/spi-renesas-rpc.c line 269

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+
+         regmap_write(rpc->regmap, RPC_SMWDR0,
+                 *(u32 *)(tx_buf + pos));

Ugh... what about the data endianness?

drivers/spi/spi-renesas-rpc.c line 277

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+
+         if (nbytes > 4) {
+            nbytes = 4;
+            smcr = rpc->smcr |
+                   RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+         } else {
+            smcr = rpc->smcr | RPC_SMCR_SPIE;
+         }
Quoted 1 line

Please do this repeated part outside *if*:

?
The procedure is different !

Quoted 23 lines
         smcr = rpc->smcr | RPC_SMCR_SPIE;
         if (nbytes > 4) {
            nbytes = 4;
            smcr |= RPC_SMCR_SSLKP;
         }

[...]

drivers/spi/spi-renesas-rpc.c line 291

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+   } else if (rx_buf) {
+      while (pos < rpc->xferlen) {
+         u32 nbytes = rpc->xferlen  - pos;

Again, 1 space is enough...

Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+         if (nbytes > 4)
+            nbytes = 4;
+
+         regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+         regmap_write(rpc->regmap, RPC_SMCR,
+                 rpc->smcr | RPC_SMCR_SPIE);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 304

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+            goto out;
+
+         regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+         memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);

What?! The 'data' variable is not in a MMIO region, you can use
plain memcpy().
Not sure about the endianness tho...

yup, the 'data' variable is not in MMIO region!
patch it to memcpy() rather than memcpy_fromio().

Quoted 7 lines

[...]

drivers/spi/spi-renesas-rpc.c line 312

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+   } else {
+      regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+      regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);

Er... what's this for?

for one SPI-command only.

Quoted 70 lines

drivers/spi/spi-renesas-rpc.c line 318

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+      ret = wait_msg_xfer_end(rpc);
+      if (ret)
+         goto out;
+   }
+
+   return ret;

Need empty line here...

drivers/spi/spi-renesas-rpc.c line 331

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+out:
+   return rpc_spi_do_reset(rpc);
+}
+
+static void rpc_spi_mem_set_prep_op_cfg(struct spi_device *spi,
+               const struct spi_mem_op *op,
+               u64 *offs, size_t *len)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(spi->master);
+
+   rpc->cmd = RPC_SMCMR_CMD(op->cmd.opcode);
+   rpc->smenr = RPC_SMENR_CDE |
+           RPC_SMENR_CDB(fls(op->cmd.buswidth >> 1));
    Maybe ilog2()?

drivers/spi/spi-renesas-rpc.c line 338

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+   rpc->totalxferlen = 1;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+   rpc->xferlen = 0;
+   rpc->addr = 0;
+
+   if (op->addr.nbytes) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(op->addr.buswidth >> 1));
   Again, ilog2()?

[...]

drivers/spi/spi-renesas-rpc.c line 364

Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+   if (op->data.nbytes || (offs && len)) {
+      if (op->data.dir == SPI_MEM_DATA_IN) {
+         rpc->smcr = RPC_SMCR_SPIRE;
+         rpc->xfer_dir = SPI_MEM_DATA_IN;
+      } else if (op->data.dir == SPI_MEM_DATA_OUT) {
+         rpc->smcr = RPC_SMCR_SPIWE;
+         rpc->xfer_dir = SPI_MEM_DATA_OUT;
+      }

This code is asking for using *switch*...

drivers/spi/spi-renesas-rpc.c line 368

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+
+      if (offs && len) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (*(u32 *)len)) | RPC_SMENR_SPIDB

Unobvious line breaks...

Quoted 1 line

+ (fls(op->data.buswidth >> 1));

   ilog2()?

drivers/spi/spi-renesas-rpc.c line 376

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+
+         rpc->xferlen = *(u32 *)len;
+         rpc->totalxferlen += *(u32 *)len;
+      } else {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+               (op->data.nbytes)) | RPC_SMENR_SPIDB
+               (fls(op->data.buswidth >> 1));

You can factor out a large part of this expression and calculate
it before *if*...

Quoted 14 lines

drivers/spi/spi-renesas-rpc.c line 388

Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+
+         rpc->xferlen = op->data.nbytes;
+         rpc->totalxferlen += op->data.nbytes;
+      }
+   }
+}
+
+static bool rpc_spi_mem_supports_op(struct spi_mem *mem,
+                const struct spi_mem_op *op)
+{
+   if (op->data.buswidth > 4 || op->addr.buswidth > 4 ||
+       op->dummy.buswidth > 4 || op->cmd.buswidth > 4)

Hm, the manual doesn't mention 2-wire SPI mode...

yup, If SPI flash supports Quad I/O mode and driver will run in Quad I/O mode
and not in dual I/O mode even if it supports dual I/O mode.

I think I will patch master->mode_bits in rpc_spi_probe()

    master->mode_bits = SPI_CPOL | SPI_CPHA |
                          SPI_RX_QUAD | SPI_TX_QUAD;
Quoted 10 lines

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+      return false;
+
+   if (op->addr.nbytes > 4)
+      return false;
+
+   return true;
+}
+
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc 

*desc,

Quoted 3 lines

drivers/spi/spi-renesas-rpc.c

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+                   u64 offs, size_t len, void *buf)
+{
+   struct rpc_spi *rpc = 

spi_master_get_devdata(desc->mem->spi->master);

Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   int ret;
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 416

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+           RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+           RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |
   RPC_DRCR_RBURST(32), please.

?
the max value is 31 = 0x1f

Quoted 13 lines

drivers/spi/spi-renesas-rpc.c line 421

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+           RPC_DRCR_RBE);
+   regmap_write(rpc->regmap, RPC_DRCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_DREAR, RPC_DREAR_EAC);
+   regmap_write(rpc->regmap, RPC_DROPR, 0);
+   regmap_write(rpc->regmap, RPC_DRENR, rpc->smenr);

Looks liky you need a more generic field name (like rpc->cmd)...

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+   regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_DRDRENR, 0);
+
+   memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, 

len);

Quoted 4 lines

What if the read direct-mapped area is less than U32_MAX in size
(and it will be,
according to your bindings)?

the max direct mapping read area is 64 KByte description in DTS.

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+   return len;
+}
+
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc 

*desc,

Quoted 3 lines

drivers/spi/spi-renesas-rpc.c

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+               u64 offs, size_t len, const void *buf)
+{
+   struct rpc_spi *rpc = 

spi_master_get_devdata(desc->mem->spi->master);

Quoted 9 lines

drivers/spi/spi-renesas-rpc.c line 440

Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+   int ret;
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   if (WARN_ON(len > RPC_WBUF_SIZE))
+      return -EIO;

Why not write 256 bytes and return w/that?

in manual 62.3.13 Write Buffer Operation,
transfer size to device is 256-byte unit.

Quoted 10 lines

drivers/spi/spi-renesas-rpc.c

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_MD | RPC_CMNCR_SFDE 

|

Quoted 7 lines

drivers/spi/spi-renesas-rpc.c line 454

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+              RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+              RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_SMDRENR, 0);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL | 0x260 |
+              RPC_PHYCNT_WBUF2 | RPC_PHYCNT_WBUF);

Didn't understand this 2-write-buffers thing...

This is refer to R-Car bare-metal,mini-Monitor v4.01

Quoted 47 lines
Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+   memcpy_toio(rpc->base + RPC_WBUF, buf, len);
+
+   regmap_write(rpc->regmap, RPC_SMCMR, rpc->cmd);
+   regmap_write(rpc->regmap, RPC_SMADR, offs);
+   regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);

drivers/spi/spi-renesas-rpc.c line 470

Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   regmap_write(rpc->regmap, RPC_SMCR, rpc->smcr | RPC_SMCR_SPIE);
+   ret = wait_msg_xfer_end(rpc);
+   if (ret)
+      goto out;
+
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RCF);
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(6) | 0x260);
+
+   return len;

Need empty line here.

drivers/spi/spi-renesas-rpc.c line 321

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+out:
+   return rpc_spi_do_reset(rpc);
+}

[...]> +static void rpc_spi_transfer_setup(struct rpc_spi *rpc,

Quoted 23 lines
drivers/spi/spi-renesas-rpc.c new file +23 -0
+               struct spi_message *msg)
+{
+   struct spi_transfer *t, xfer[4] = { };
+   u32 i, xfercnt, xferpos = 0;
+
+   rpc->totalxferlen = 0;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (t->tx_buf) {
+         xfer[xferpos].tx_buf = t->tx_buf;
+         xfer[xferpos].tx_nbits = t->tx_nbits;
+      }
+
+      if (t->rx_buf) {
+         xfer[xferpos].rx_buf = t->rx_buf;
+         xfer[xferpos].rx_nbits = t->rx_nbits;
+      }
+
+      if (t->len) {
+         xfer[xferpos++].len = t->len;
+         rpc->totalxferlen += t->len;
+      }
Quoted 14 lines

drivers/spi/spi-renesas-rpc.c line 550

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+      if (list_is_last(&t->transfer_list, &msg->transfers)) {
+         if (xferpos > 1 && t->rx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_IN;
+            rpc->smcr = RPC_SMCR_SPIRE;
+         } else if (xferpos > 1 && t->tx_buf) {

Why check 'xferpos' twice?

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+            rpc->xfer_dir = SPI_MEM_DATA_OUT;
+            rpc->smcr = RPC_SMCR_SPIWE;
+         }
+      }
+   }

patch it to check 'xferpos' only one time.
-------------------------------------------------------------

                 if (list_is_last(&t->transfer_list, &msg->transfers)) {
                         if (xferpos > 1) {
                                        if (tx->rx_buf) {  
                                 rpc->xfer_dir = SPI_MEM_DATA_IN;
                                 rpc->smcr = RPC_SMCR_SPIRE;
                                } else if (t->tx_buf) {
                                 rpc->xfer_dir = SPI_MEM_DATA_OUT;
                                 rpc->smcr = RPC_SMCR_SPIWE;
                                }
                                }
                 }

----------------------------------------------------------

Quoted 5 lines

drivers/spi/spi-renesas-rpc.c

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+
+   xfercnt = xferpos;
+   rpc->xferlen = xfer[--xferpos].len;
+   rpc->cmd = RPC_SMCMR_CMD(((u8 *)xfer[0].tx_buf)[0]);
+   rpc->smenr = RPC_SMENR_CDE | RPC_SMENR_CDB(fls(xfer[0].tx_nbits >> 

1));

Quoted 9 lines
   ilog2()?

drivers/spi/spi-renesas-rpc.c line 564

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+   rpc->addr = 0;
+
+   if (xfercnt > 2 && xfer[1].len && xfer[1].tx_buf) {
+      rpc->smenr |= RPC_SMENR_ADB(fls(xfer[1].tx_nbits >> 1));
   ilog2()?

patch it to
------------------------------------------------------------
rpc->smenr |= RPC_SMENR_ADB(ilog2((unsigned)xfer[1].tx_nbits));
------------------------------------------------------------
due to tx_nbits is bit-field.

Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 567

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
   Ugh, you need get_unaligned_*()...

for accessing a single byte quantity, ((u8 *)xfer[1].tx_buf)[i] ?

Quoted 42 lines
Quoted 42 lines
drivers/spi/spi-renesas-rpc.c new file +41 -0
+
+      if (xfer[1].len == 4)
+         rpc->smenr |= RPC_SMENR_ADE(0xf);
+      else
+         rpc->smenr |= RPC_SMENR_ADE(0x7);
+   }
+
+   switch (xfercnt) {
+   case 2:
+      if (xfer[1].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].rx_nbits >> 1));
+      } else if (xfer[1].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[1].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[1].tx_nbits >> 1));
+      }
+      break;
+
+   case 3:
+      if (xfer[2].len && xfer[2].rx_buf && !xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].rx_nbits >> 1));
+      } else if (xfer[2].len && xfer[2].tx_buf && !xfer[2].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[2].len)) | RPC_SMENR_SPIDB(fls
+                  (xfer[2].tx_nbits >> 1));
+      }
+      break;
+
+   case 4:
+      if (xfer[2].len && xfer[2].tx_buf) {
+         rpc->smenr |= RPC_SMENR_DME;
+         rpc->dummy = RPC_SMDMCR_DMCYC(xfer[2].len);
+      }
+
+      if (xfer[3].len && xfer[3].rx_buf) {
+         rpc->smenr |= RPC_SMENR_SPIDE(rpc_bits_xfer
+                  (xfer[3].len)) | RPC_SMENR_SPIDB(fls
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 614

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+                  (xfer[3].rx_nbits >> 1));
+      }
+      break;
+
+   default:
+      break;

Ugh... don't want to repeat after Marek. :-)

patch it in PATCH v3 already.

Quoted 11 lines

[...]

drivers/spi/spi-renesas-rpc.c line 675

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static const struct regmap_config rpc_spi_regmap_config = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 4,
+   .fast_io = true,
+   .max_register = RPC_WBUF + RPC_WBUF_SIZE,

Ugh... 0x8100/4 regs, of which the majority isn't used... :-/

Quoted 12 lines
Quoted 10 lines
drivers/spi/spi-renesas-rpc.c new file +10 -0
+   .volatile_table = &rpc_spi_volatile_table,
+};
+
+static int rpc_spi_probe(struct platform_device *pdev)
+{
+   struct spi_master *master;
+   struct resource *res;
+   struct rpc_spi *rpc;
+   const struct regmap_config *regmap_config;
+   int ret;

[...]

Quoted 1 line

+ res = platform_get_resource_byname(pdev, IORESOURCE_MEM,

"rpc_regs");

Quoted 7 lines

I'd suggest just "regs".

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+   rpc->base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(rpc->base))
+      return PTR_ERR(rpc->base);

[...]

Quoted 15 lines

drivers/spi/spi-renesas-rpc.c line 761

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+err_put_master:
+   spi_master_put(master);
+   pm_runtime_disable(&pdev->dev);
+
+   return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   pm_runtime_disable(&pdev->dev);
+   spi_unregister_master(master);

No spi_master_put() here?

put_device() in spi_unregister_master().

best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#25 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hello!

On 12/11/2018 12:26 PM, [email protected] wrote:

[...]

Quoted 16 lines
Quoted 16 lines

I'd already started the v2 driver review before you posted v3, so
here goes...

Quoted 3 lines · Mason Yang

Add a driver for Renesas R-Car Gen3 RPC SPI controller.

[...]

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +0 -0
new file mode 100644
index 0000000..ac9094e
@@ -0,0 +1,808 @@

[...]

Quoted 5 lines
Quoted 5 lines

drivers/spi/spi-renesas-rpc.c line 50

Quoted 3 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+#define RPC_DRCR      0x000C   /* R/W */
+#define RPC_DRCR_SSLN      BIT(24)
+#define RPC_DRCR_RBURST(v)   (((v) & 0x1F) << 16)

More like ((v) - 1), like in another register...

I mean you can pass the read data burst length as a # of data units,
thus just substracting 1, like you did in the other case...

Quoted 9 lines
Quoted 5 lines

[...]

drivers/spi/spi-renesas-rpc.c line 60

Quoted 2 lines
drivers/spi/spi-renesas-rpc.c new file +2 -0
+#define RPC_DREAR      0x0014   /* R/W */
+#define RPC_DREAR_EAC      BIT(0)

The manual says it takes bits 0 to 2...

yup, EAC[2:0]
but as datasheet description, either 0 or 1 is OK to BIT(0), other than above setting is prohibited

I'd prefer that this matches the manual. #define the values or
just pass them to RPC_DREAR_EAC(v).

Quoted 11 lines
Quoted 9 lines

[...]

drivers/spi/spi-renesas-rpc.c line 91

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+#define RPC_SMADR      0x0028   /* R/W */
+#define RPC_SMOPR      0x002C   /* R/W */
+#define RPC_SMOPR_OPD0(o)   (((o) & 0xFF) << 0)
+#define RPC_SMOPR_OPD1(o)   (((o) & 0xFF) << 8)
+#define RPC_SMOPR_OPD2(o)   (((o) & 0xFF) << 16)
+#define RPC_SMOPR_OPD3(o)   (((o) & 0xFF) << 24)

You either go in descending or ascending order, not both. :-)

I can't get your point.

You #define in the ascending order of the bit # (shift count) here and
in the descending order elsewhere.

[...]

Quoted 21 lines
Quoted 12 lines
Quoted 12 lines
drivers/spi/spi-renesas-rpc.c new file +12 -0
+static void rpc_spi_hw_init(struct rpc_spi *rpc)
+{
+   /*
+    * NOTE: The 0x260 are undocumented bits, but they must be set.
+    *   RPC_PHYCNT_STRTIM is strobe timing adjustment bit,
+    *   0x0 : the delay is biggest,
+    *   0x1 : the delay is 2nd biggest,
+    *   0x3 or 0x6 is a recommended value.
+    */
+   regmap_write(rpc->regmap, RPC_PHYCNT, RPC_PHYCNT_CAL |
+              RPC_PHYCNT_STRTIM(0x6) | 0x260);
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 201

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+   /*
+    * NOTE: The 0x31511144 and 0x431 are undocumented bits,
+    *    but they must be set for RPC_PHYOFFSET1 & RPC_PHYOFFSET2.
+    */
+   regmap_write(rpc->regmap, RPC_PHYOFFSET1, 0x31511144);
+   regmap_write(rpc->regmap, RPC_PHYOFFSET2, 0x431);

0x400 is actually documented, bits 0..7 are read only and defaultto 0x31...

Quoted 3 lines

I got these values from R-Car bare-metal code, mini-Monitor v4.01.

What should I describe these bits 0x400 and 0x31 if it is needed?

#define PHYOFFSET2_OCTTMG(v) ((v) & 0x7) << 8)

The read-modify-write operation ios preferred in this casa, so that
0x31 doesn't appear anywhere.

[...]

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
drivers/spi/spi-renesas-rpc.c new file +8 -0
+
+         if (nbytes > 4) {
+            nbytes = 4;
+            smcr = rpc->smcr |
+                   RPC_SMCR_SPIE | RPC_SMCR_SSLKP;
+         } else {
+            smcr = rpc->smcr | RPC_SMCR_SPIE;
+         }
Quoted 4 lines
Quoted 1 line

Please do this repeated part outside *if*:

?
The procedure is different !

Where?!

Quoted 5 lines
Quoted 5 lines
         smcr = rpc->smcr | RPC_SMCR_SPIE;
         if (nbytes > 4) {
            nbytes = 4;
            smcr |= RPC_SMCR_SSLKP;
         }

[...]

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/spi/spi-renesas-rpc.c new file +9 -0
+
+         if (nbytes > 4)
+            nbytes = 4;
+
+         regmap_write(rpc->regmap, RPC_SMENR, rpc->smenr);
+         regmap_write(rpc->regmap, RPC_SMCR,
+                 rpc->smcr | RPC_SMCR_SPIE);
+         ret = wait_msg_xfer_end(rpc);
+         if (ret)
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 304

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+            goto out;
+
+         regmap_read(rpc->regmap, RPC_SMRDR0, &data);
+         memcpy_fromio(rx_buf + pos, (void *)&data, nbytes);

What?! The 'data' variable is not in a MMIO region, you can use
plain memcpy().
Not sure about the endianness tho...

Quoted 2 lines

yup, the 'data' variable is not in MMIO region!
patch it to memcpy() rather than memcpy_fromio().

Also, pointer casts to 'void *' are automatic...

[...]

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/spi/spi-renesas-rpc.c new file +14 -0
+static ssize_t rpc_spi_mem_dirmap_read(struct spi_mem_dirmap_desc *desc,
+                   u64 offs, size_t len, void *buf)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+   int ret;
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   ret = rpc_spi_set_freq(rpc, desc->mem->spi->max_speed_hz);
+   if (ret)
+      return ret;
+
+   rpc_spi_mem_set_prep_op_cfg(desc->mem->spi,
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 416

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+                &desc->info.op_tmpl, &offs, &len);
+
+   regmap_write(rpc->regmap, RPC_CMNCR, RPC_CMNCR_SFDE |
+           RPC_CMNCR_MOIIO_HIZ | RPC_CMNCR_IOFV_HIZ |
+           RPC_CMNCR_BSZ(0));
+   regmap_write(rpc->regmap, RPC_DRCR, RPC_DRCR_RBURST(0x1f) |
   RPC_DRCR_RBURST(32), please.
Quoted 2 lines

?
the max value is 31 = 0x1f

See above!

[...]

Quoted 10 lines
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 425

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +4 -0
+   regmap_write(rpc->regmap, RPC_DRDMCR, rpc->dummy);
+   regmap_write(rpc->regmap, RPC_DRDRENR, 0);
+
+   memcpy_fromio(buf, rpc->linear.map + desc->info.offset + offs, len);

What if the read direct-mapped area is less than U32_MAX in size
(and it will be,
according to your bindings)?

the max direct mapping read area is 64 KByte description in DTS.

You don't check for this before reading (but you do for writing)!

[...]

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
+               u64 offs, size_t len, const void *buf)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+   int ret;
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 440

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   if (WARN_ON(len > RPC_WBUF_SIZE))
+      return -EIO;

Why not write 256 bytes and return w/that?

Quoted 2 lines

in manual 62.3.13 Write Buffer Operation,
transfer size to device is 256-byte unit.

Why not write 256 bytes max and just return 256?

[...]

Quoted 54 lines
Quoted 26 lines

[...]

Quoted 24 lines
drivers/spi/spi-renesas-rpc.c new file +24 -0
+static void rpc_spi_transfer_setup(struct rpc_spi *rpc,
+               struct spi_message *msg)
+{
+   struct spi_transfer *t, xfer[4] = { };
+   u32 i, xfercnt, xferpos = 0;
+
+   rpc->totalxferlen = 0;
+   rpc->xfer_dir = SPI_MEM_NO_DATA;
+
+   list_for_each_entry(t, &msg->transfers, transfer_list) {
+      if (t->tx_buf) {
+         xfer[xferpos].tx_buf = t->tx_buf;
+         xfer[xferpos].tx_nbits = t->tx_nbits;
+      }
+
+      if (t->rx_buf) {
+         xfer[xferpos].rx_buf = t->rx_buf;
+         xfer[xferpos].rx_nbits = t->rx_nbits;
+      }
+
+      if (t->len) {
+         xfer[xferpos++].len = t->len;
+         rpc->totalxferlen += t->len;
+      }
Quoted 14 lines

drivers/spi/spi-renesas-rpc.c line 550

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+      if (list_is_last(&t->transfer_list, &msg->transfers)) {
+         if (xferpos > 1 && t->rx_buf) {
+            rpc->xfer_dir = SPI_MEM_DATA_IN;
+            rpc->smcr = RPC_SMCR_SPIRE;
+         } else if (xferpos > 1 && t->tx_buf) {

Why check 'xferpos' twice?

Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+            rpc->xfer_dir = SPI_MEM_DATA_OUT;
+            rpc->smcr = RPC_SMCR_SPIWE;
+         }
+      }
+   }

patch it to check 'xferpos' only one time.
-------------------------------------------------------------

                 if (list_is_last(&t->transfer_list, &msg->transfers)) {
                         if (xferpos > 1) {
                                        if (tx->rx_buf) {                                                
                                 rpc->xfer_dir = SPI_MEM_DATA_IN;
                                 rpc->smcr = RPC_SMCR_SPIRE;
                                 } else if (t->tx_buf) {
                                 rpc->xfer_dir = SPI_MEM_DATA_OUT;
                                 rpc->smcr = RPC_SMCR_SPIWE;
                                 }
                                }
                 }
Quoted 1 line

----------------------------------------------------------

You got the idea but please reformat this properly..

[...]

Quoted 8 lines
Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 567

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
   Ugh, you need get_unaligned_*()...

for accessing a single byte quantity, ((u8 *)xfer[1].tx_buf)[i] ?

Ugh, never start a new line with an operator, lease it on a 1st, broken up line.

[...]

Quoted 8 lines
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 675

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static const struct regmap_config rpc_spi_regmap_config = {
+   .reg_bits = 32,
+   .val_bits = 32,
+   .reg_stride = 4,
+   .fast_io = true,
+   .max_register = RPC_WBUF + RPC_WBUF_SIZE,

Ugh... 0x8100/4 regs, of which the majority isn't used... :-/

Seriously, you don't use regmap for the write buffer anyway...

[...]

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-renesas-rpc.c new file +7 -0
+err_put_master:
+   spi_master_put(master);
+   pm_runtime_disable(&pdev->dev);
+
+   return ret;
+}
+
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 761

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   pm_runtime_disable(&pdev->dev);
+   spi_unregister_master(master);

No spi_master_put() here?

Quoted 1 line

put_device() in spi_unregister_master().

Why call spi_master_put() in the probe() method's error path?

Quoted 10 lines

best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

Please consider sending patches from e.g. your GMail account to avoid this legelese
crap.

MBR, Sergei

A message that is not in the archive (sent off-list or not yet received): OF719DFBAE.D0F9F117-ON4825836A.0039EEA3-4825836A.003B28D8@mxic.com.tw

#27 lore raw

Re: [PATCH v2 1/2] spi: Add Renesas R-Car Gen3 RPC SPI controller driver

Hello!

Quoted 17 lines · On 12/21/2018 01:46 PM, [email protected] wrote:
Quoted 17 lines
Quoted 16 lines
Quoted 5 lines
Quoted 5 lines
drivers/spi/spi-renesas-rpc.c new file +5 -0
+static ssize_t rpc_spi_mem_dirmap_write(struct spi_mem_dirmap_desc *desc,
+               u64 offs, size_t len, const void *buf)
+{
+   struct rpc_spi *rpc = spi_master_get_devdata(desc->mem->spi->master);
+   int ret;
Quoted 8 lines

drivers/spi/spi-renesas-rpc.c line 440

Quoted 6 lines
drivers/spi/spi-renesas-rpc.c new file +6 -0
+
+   if (WARN_ON(offs + desc->info.offset + len > U32_MAX))
+      return -EINVAL;
+
+   if (WARN_ON(len > RPC_WBUF_SIZE))
+      return -EIO;

Why not write 256 bytes and return w/that?

in manual 62.3.13 Write Buffer Operation,
transfer size to device is 256-byte unit.

Quoted 7 lines
Quoted 2 lines

Why not write 256 bytes max and just return 256?

?
I don't get your point.

here writes 256 byte each time and return 256 (len).

I mean not aborting the requests for >256 bytes right away (like you do) but
write only 256 bytes and return 256, not -EIO.

[...]

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

drivers/spi/spi-renesas-rpc.c line 567

Quoted 4 lines
drivers/spi/spi-renesas-rpc.c new file +3 -0
+      for (i = 0; i < xfer[1].len; i++)
+         rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i]
+               << (8 * (xfer[1].len - i - 1));
   Ugh, you need get_unaligned_*()...

for accessing a single byte quantity, ((u8 *)xfer[1].tx_buf)[i] ?

Ugh, never start a new line with an operator, lease it on a 1st,

Sorry -- leave, not lease.

Quoted 6 lines
Quoted 1 line

broken up line.

okay, patch it to:

rpc->addr |= (u32)((u8 *)xfer[1].tx_buf)[i] <<

                 (8 * (xfer[1].len - i - 1));

OK, thanks.

[...]

Quoted 17 lines
Quoted 17 lines

[...]

Quoted 16 lines
Quoted 15 lines

drivers/spi/spi-renesas-rpc.c line 761

Quoted 13 lines
drivers/spi/spi-renesas-rpc.c new file +13 -0
+err_put_master:
+   spi_master_put(master);
+   pm_runtime_disable(&pdev->dev);
+
+   return ret;
+}
+
+static int rpc_spi_remove(struct platform_device *pdev)
+{
+   struct spi_master *master = platform_get_drvdata(pdev);
+
+   pm_runtime_disable(&pdev->dev);
+   spi_unregister_master(master);

No spi_master_put() here?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

put_device() in spi_unregister_master().

Why call spi_master_put() in the probe() method's error path?

called get_device() in spi_register_master() !

Hm, this is somewhat asymmetric...

Quoted 2 lines

thanks & best regards,
Mason

[...]

MBR, Sergei

author
#28 lore raw

PATCH v2 2/2 dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

In reply to Mason Yang

Document the bindings used by the Renesas R-Car Gen3 RPC SPI controller.

---
 .../devicetree/bindings/spi/spi-renesas-rpc.txt    | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt
Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt new file +35 -0
new file mode 100644
index 0000000..c6c6d9c
@@ -0,0 +1,35 @@
+Renesas R-Car Gen3 RPC controller Device Tree Bindings
+------------------------------------------------------
+
+Required properties:
+- compatible: should be "renesas,r8a77995-rpc"
+- #address-cells: should be 1
+- #size-cells: should be 0
+- reg: should contain 2 entries, one for the registers and one for the direct
+       mapping area
+- reg-names: should contain "rpc_regs" and "dirmap"
+- interrupts: interrupt line connected to the RPC SPI controller
+- clock-names: should contain "clk_rpc"
+- clocks: should contain 1 entries for the module's clock
+
+Example:
+
+	rpc: spi@ee200000 {
+		compatible = "renesas,r8a77995-rpc";
+		reg = <0 0xee200000 0 0x8100>, <0 0x08000000 0 0x4000000>;
+		reg-names = "rpc_regs", "dirmap";
+		clocks = <&cpg CPG_MOD 917>;
+		power-domains = <&sysc R8A77995_PD_ALWAYS_ON>;
+		resets = <&cpg 917>;
+		clock-names = "clk_rpc";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		flash@0 {
+			compatible = "jedec,spi-nor";
+			reg = <0>;
+			spi-max-frequency = <40000000>;
+			spi-tx-bus-width = <1>;
+			spi-rx-bus-width = <1>;
+		};
+	};
Signature · 1 line
1.9.1
#29 lore raw

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Quoted 1 line · Mason Yang

Document the bindings used by the Renesas R-Car Gen3 RPC SPI controller.

RPC is SPI and HF controller, it is not a pure SPI controller.

How does this deal with the HF part ? Keep in mind the bindings are ABI and it will be difficult to redo them later.

Quoted 13 lines
---
 .../devicetree/bindings/spi/spi-renesas-rpc.txt    | 35 ++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt
Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt new file +1 -0
new file mode 100644
index 0000000..c6c6d9c
@@ -0,0 +1,35 @@
+Renesas R-Car Gen3 RPC controller Device Tree Bindings

Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt line 11

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt new file +10 -0
+------------------------------------------------------
+
+Required properties:
+- compatible: should be "renesas,r8a77995-rpc"
+- #address-cells: should be 1
+- #size-cells: should be 0
+- reg: should contain 2 entries, one for the registers and one for the direct
+       mapping area
+- reg-names: should contain "rpc_regs" and "dirmap"
+- interrupts: interrupt line connected to the RPC SPI controller

Not a SPI controller.

Quoted 25 lines
Documentation/devicetree/bindings/spi/spi-renesas-rpc.txt new file +24 -0
+- clock-names: should contain "clk_rpc"
+- clocks: should contain 1 entries for the module's clock
+
+Example:
+
+	rpc: spi@ee200000 {
+		compatible = "renesas,r8a77995-rpc";
+		reg = <0 0xee200000 0 0x8100>, <0 0x08000000 0 0x4000000>;
+		reg-names = "rpc_regs", "dirmap";
+		clocks = <&cpg CPG_MOD 917>;
+		power-domains = <&sysc R8A77995_PD_ALWAYS_ON>;
+		resets = <&cpg 917>;
+		clock-names = "clk_rpc";
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		flash@0 {
+			compatible = "jedec,spi-nor";
+			reg = <0>;
+			spi-max-frequency = <40000000>;
+			spi-tx-bus-width = <1>;
+			spi-rx-bus-width = <1>;
+		};
+	};
Signature · 2 lines
Best regards,
Marek Vasut
#30 lore raw

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Hi Marek,

Quoted 15 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

To

"Mason Yang" <[email protected]>, [email protected], linux- [email protected], [email protected], [email protected], [email protected], "Geert Uytterhoeven" <[email protected]>,

cc

[email protected], "Simon Horman" <[email protected]>, [email protected]

Quoted 7 lines

Subject

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Quoted 1 line · Mason Yang

Document the bindings used by the Renesas R-Car Gen3 RPC SPI

controller.

Quoted 5 lines

RPC is SPI and HF controller, it is not a pure SPI controller.

How does this deal with the HF part ? Keep in mind the bindings are ABI and it will be difficult to redo them later.

After checking HF datasheet, 512_MBIT_256_MBIT_128_MBIT_HYPERFLASH_FAMILY_Datasheet.pdf.

From my point of view,
HyperFlash is a kind of standard NOR Flash with high-speed SPI interface. But I might be wrong.

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#31 lore raw

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Quoted 1 line · On 12/05/2018 09:39 AM, [email protected] wrote:

Hi Marek,

Hi,

Quoted 28 lines
Quoted 20 lines

"Marek Vasut" <[email protected]>
2018/12/05 上午 10:04

To

"Mason Yang" <[email protected]>, [email protected], linux- [email protected], [email protected], [email protected], [email protected], "Geert Uytterhoeven" <[email protected]>,

cc

[email protected], "Simon Horman" <[email protected]>, [email protected]

Subject

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Quoted 7 lines
Quoted 1 line · Mason Yang

Document the bindings used by the Renesas R-Car Gen3 RPC SPI controller.

RPC is SPI and HF controller, it is not a pure SPI controller.

How does this deal with the HF part ? Keep in mind the bindings are ABI and it will be difficult to redo them later.

Quoted 8 lines

After checking HF datasheet, 512_MBIT_256_MBIT_128_MBIT_HYPERFLASH_FAMILY_Datasheet.pdf.

From my point of view,
HyperFlash is a kind of standard NOR Flash with high-speed SPI interface. But I might be wrong.

It behaves as a Parallel CFI NOR internally, and so it fits and works with the CFI NOR drivers (see the U-Boot driver), except the interface between the HF controller and the chip is custom. It's not SPI per-se.

Signature · 2 lines
Best regards,
Marek Vasut
#32 lore raw

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

In reply to Marek Vasut
Quoted 6 lines · Marek Vasut
Quoted 1 line

Document the bindings used by the Renesas R-Car Gen3 RPC SPI controller.

RPC is SPI and HF controller, it is not a pure SPI controller.

How does this deal with the HF part ? Keep in mind the bindings are ABI and it will be difficult to redo them later.

Perhaps we need a "mode" prop, maybe w/vendor prefix?

Quoted 1 line
Quoted 1 line

[...]

MBR, Sergei

#33 lore raw

Re: [PATCH v2 2/2] dt-binding: spi: Document Renesas R-Car Gen3 RPC controller bindings

Quoted 10 lines · Sergei Shtylyov
Quoted 6 lines · Marek Vasut
Quoted 1 line

Document the bindings used by the Renesas R-Car Gen3 RPC SPI controller.

RPC is SPI and HF controller, it is not a pure SPI controller.

How does this deal with the HF part ? Keep in mind the bindings are ABI and it will be difficult to redo them later.

Perhaps we need a "mode" prop, maybe w/vendor prefix?

Or, like I said last time, discern it based on the DT subnode. It can be either SPI NOR or CFI NOR.

Quoted 5 lines
Quoted 1 line
Quoted 1 line

[...]

MBR, Sergei

Signature · 2 lines
Best regards,
Marek Vasut