From: Lorenzo Bianconi <lorenzo@kernel.org>
To: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
Cc: Ray Liu <ray.liu@airoha.com>, Mark Brown <broonie@kernel.org>,
Jyothi Kumar Seerapu <quic_jseerapu@quicinc.com>,
linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 03/13] spi: airoha: add support of dual/quad wires spi modes
Date: Sat, 23 Aug 2025 16:42:40 +0200 [thread overview]
Message-ID: <aKnTYNsaBIkh6OBS@lore-rh-laptop> (raw)
In-Reply-To: <68130d82-edbe-4e23-9538-733f9c52123c@iopsys.eu>
[-- Attachment #1: Type: text/plain, Size: 5419 bytes --]
>
> On 23.08.2025 11:16, Lorenzo Bianconi wrote:
> > [...]
> >> -static int airoha_snand_write_data(struct airoha_snand_ctrl *as_ctrl, u8 cmd,
> >> - const u8 *data, int len)
> >> +static int airoha_snand_write_data(struct airoha_snand_ctrl *as_ctrl,
> >> + const u8 *data, int len, int buswidth)
> >> {
> >> int i, data_len;
> >> + u8 cmd;
> >> +
> >> + switch (buswidth) {
> >> + case 0:
> >> + case 1:
> >> + cmd = SNAND_FIFO_TX_BUSWIDTH_SINGLE;
> >> + break;
> >> + case 2:
> >> + cmd = SNAND_FIFO_TX_BUSWIDTH_DUAL;
> >> + break;
> >> + case 4:
> >> + cmd = SNAND_FIFO_TX_BUSWIDTH_QUAD;
> >> + break;
> >> + default:
> >> + return -EINVAL;
> >> + }
> > Since this is used in airoha_snand_write_data() and in airoha_snand_read_data()
> > I guess you can define a routine for it.
>
> It's not the same. It looks similar, but different constants are used
> for rx and tx cases.
ops, I missed TX vs RX.
Regards,
Lorenzo
>
> >
> >>
> >> for (i = 0; i < len; i += data_len) {
> >> int err;
> >> @@ -409,16 +433,32 @@ static int airoha_snand_write_data(struct airoha_snand_ctrl *as_ctrl, u8 cmd,
> >> return 0;
> >> }
> >>
> >> -static int airoha_snand_read_data(struct airoha_snand_ctrl *as_ctrl, u8 *data,
> >> - int len)
> >> +static int airoha_snand_read_data(struct airoha_snand_ctrl *as_ctrl,
> >> + u8 *data, int len, int buswidth)
> >> {
> >> int i, data_len;
> >> + u8 cmd;
> >> +
> >> + switch (buswidth) {
> >> + case 0:
> >> + case 1:
> >> + cmd = SNAND_FIFO_RX_BUSWIDTH_SINGLE;
> >> + break;
> >> + case 2:
> >> + cmd = SNAND_FIFO_RX_BUSWIDTH_DUAL;
> >> + break;
> >> + case 4:
> >> + cmd = SNAND_FIFO_RX_BUSWIDTH_QUAD;
> >> + break;
> >> + default:
> >> + return -EINVAL;
> >> + }
> >>
> >> for (i = 0; i < len; i += data_len) {
> >> int err;
> >>
> >> data_len = min(len - i, SPI_MAX_TRANSFER_SIZE);
> >> - err = airoha_snand_set_fifo_op(as_ctrl, 0xc, data_len);
> >> + err = airoha_snand_set_fifo_op(as_ctrl, cmd, data_len);
> >> if (err)
> >> return err;
> >>
> >> @@ -895,12 +935,27 @@ static ssize_t airoha_snand_dirmap_write(struct spi_mem_dirmap_desc *desc,
> >> static int airoha_snand_exec_op(struct spi_mem *mem,
> >> const struct spi_mem_op *op)
> >> {
> >> - u8 data[8], cmd, opcode = op->cmd.opcode;
> >> struct airoha_snand_ctrl *as_ctrl;
> >> - int i, err;
> >> + char buf[20], *data;
> >> + int i, err, op_len, addr_len, dummy_len;
> > nit: can you please respect the 'reverse christmas tree' here?
> will fix
> >
> >>
> >> as_ctrl = spi_controller_get_devdata(mem->spi->controller);
> >>
> >> + op_len = op->cmd.nbytes;
> >> + addr_len = op->addr.nbytes;
> >> + dummy_len = op->dummy.nbytes;
> >> +
> >> + if (op_len + dummy_len + addr_len > sizeof(buf))
> >> + return -EIO;
> >> +
> >> + data = buf;
> >> + for (i = 0; i < op_len; i++)
> >> + *data++ = op->cmd.opcode >> (8 * (op_len - i - 1));
> >> + for (i = 0; i < addr_len; i++)
> >> + *data++ = op->addr.val >> (8 * (addr_len - i - 1));
> >> + for (i = 0; i < dummy_len; i++)
> >> + *data++ = 0xff;
> >> +
> >> /* switch to manual mode */
> >> err = airoha_snand_set_mode(as_ctrl, SPI_MODE_MANUAL);
> >> if (err < 0)
> >> @@ -911,40 +966,40 @@ static int airoha_snand_exec_op(struct spi_mem *mem,
> >> return err;
> >>
> >> /* opcode */
> >> - err = airoha_snand_write_data(as_ctrl, 0x8, &opcode, sizeof(opcode));
> >> + data = buf;
> >> + err = airoha_snand_write_data(as_ctrl, data, op_len,
> >> + op->cmd.buswidth);
> >> if (err)
> >> return err;
> >>
> >> /* addr part */
> >> - cmd = opcode == SPI_NAND_OP_GET_FEATURE ? 0x11 : 0x8;
> >> - put_unaligned_be64(op->addr.val, data);
> >> -
> >> - for (i = ARRAY_SIZE(data) - op->addr.nbytes;
> >> - i < ARRAY_SIZE(data); i++) {
> >> - err = airoha_snand_write_data(as_ctrl, cmd, &data[i],
> >> - sizeof(data[0]));
> >> + data += op_len;
> >> + if (addr_len) {
> >> + err = airoha_snand_write_data(as_ctrl, data, addr_len,
> >> + op->addr.buswidth);
> >> if (err)
> >> return err;
> >> }
> >>
> >> /* dummy */
> >> - data[0] = 0xff;
> >> - for (i = 0; i < op->dummy.nbytes; i++) {
> >> - err = airoha_snand_write_data(as_ctrl, 0x8, &data[0],
> >> - sizeof(data[0]));
> >> + data += addr_len;
> >> + if (dummy_len) {
> >> + err = airoha_snand_write_data(as_ctrl, data, dummy_len,
> >> + op->dummy.buswidth);
> >> if (err)
> >> return err;
> >> }
> >>
> >> /* data */
> >> - if (op->data.dir == SPI_MEM_DATA_IN) {
> >> - err = airoha_snand_read_data(as_ctrl, op->data.buf.in,
> >> - op->data.nbytes);
> >> - if (err)
> >> - return err;
> >> - } else {
> >> - err = airoha_snand_write_data(as_ctrl, 0x8, op->data.buf.out,
> >> - op->data.nbytes);
> >> + if (op->data.nbytes) {
> >> + if (op->data.dir == SPI_MEM_DATA_IN)
> >> + err = airoha_snand_read_data(as_ctrl, op->data.buf.in,
> >> + op->data.nbytes,
> >> + op->data.buswidth);
> >> + else
> >> + err = airoha_snand_write_data(as_ctrl, op->data.buf.out,
> >> + op->data.nbytes,
> >> + op->data.buswidth);
> >> if (err)
> >> return err;
> >> }
> >> --
> >> 2.50.1
> >>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2025-08-23 14:47 UTC|newest]
Thread overview: 65+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-20 12:33 [PATCH v3 00/14] spi: airoha: driver fixes & improvements Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 01/14] spi: airoha: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 02/14] spi: airoha: remove unnecessary restriction length Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 03/14] spi: airoha: add support of dual/quad wires spi modes Mikhail Kshevetskiy
2025-08-20 12:48 ` Jyothi Kumar Seerapu
2025-08-20 12:33 ` [PATCH v3 04/14] spi: airoha: remove unnecessary switch to non-dma mode Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 05/14] spi: airoha: unify dirmap read/write code Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 06/14] spi: airoha: switch back to non-dma mode in the case of error Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 07/14] spi: airoha: fix reading/writing of flashes with more than one plane per lun Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 08/14] spi: airoha: support of dualio/quadio flash reading commands Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 09/14] spi: airoha: allow reading/writing of oob area Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 10/14] spi: airoha: buffer must be 0xff-ed before writing Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 11/14] spi: airoha: avoid setting of page/oob sizes in REG_SPI_NFI_PAGEFMT Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 12/14] spi: airoha: reduce the number of modification of REG_SPI_NFI_CNFG and REG_SPI_NFI_SECCUS_SIZE registers Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 13/14] spi: airoha: set custom sector size equal to flash page size Mikhail Kshevetskiy
2025-08-20 12:33 ` [PATCH v3 14/14] spi: airoha: avoid reading flash page settings from SNFI registers during driver startup Mikhail Kshevetskiy
2025-08-21 6:58 ` [PATCH v3 00/14] spi: airoha: driver fixes & improvements Lorenzo Bianconi
2025-08-21 11:13 ` Mikhail Kshevetskiy
2025-08-21 11:34 ` Lorenzo Bianconi
2025-08-21 12:24 ` Mikhail Kshevetskiy
2025-08-22 3:31 ` Mikhail Kshevetskiy
2025-08-22 6:46 ` Lorenzo Bianconi
2025-08-22 11:22 ` Mikhail Kshevetskiy
2025-08-22 13:14 ` Lorenzo Bianconi
2025-08-22 14:36 ` Mikhail Kshevetskiy
2025-08-22 20:00 ` Mikhail Kshevetskiy
2025-08-22 11:27 ` Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 00/13] " Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 01/13] spi: airoha: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-08-23 8:04 ` Lorenzo Bianconi
2025-08-23 13:52 ` Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 02/13] spi: airoha: remove unnecessary restriction length Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 03/13] spi: airoha: add support of dual/quad wires spi modes Mikhail Kshevetskiy
2025-08-23 8:16 ` Lorenzo Bianconi
2025-08-23 13:54 ` Mikhail Kshevetskiy
2025-08-23 14:42 ` Lorenzo Bianconi [this message]
2025-08-23 0:16 ` [PATCH v4 04/13] spi: airoha: remove unnecessary switch to non-dma mode Mikhail Kshevetskiy
2025-08-23 8:29 ` Lorenzo Bianconi
2025-08-23 0:16 ` [PATCH v4 05/13] spi: airoha: unify dirmap read/write code Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 06/13] spi: airoha: switch back to non-dma mode in the case of error Mikhail Kshevetskiy
2025-08-23 8:34 ` Lorenzo Bianconi
2025-08-23 0:16 ` [PATCH v4 07/13] spi: airoha: fix reading/writing of flashes with more than one plane per lun Mikhail Kshevetskiy
2025-08-23 8:36 ` Lorenzo Bianconi
2025-08-23 0:16 ` [PATCH v4 08/13] spi: airoha: support of dualio/quadio flash reading commands Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 09/13] spi: airoha: avoid setting of page/oob sizes in REG_SPI_NFI_PAGEFMT Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 10/13] spi: airoha: reduce the number of modification of REG_SPI_NFI_CNFG and REG_SPI_NFI_SECCUS_SIZE registers Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 11/13] spi: airoha: set custom sector size equal to flash page size Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 12/13] spi: airoha: avoid reading flash page settings from SNFI registers during driver startup Mikhail Kshevetskiy
2025-08-23 0:16 ` [PATCH v4 13/13] spi: airoha: buffer must be 0xff-ed before writing Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 00/13] spi: airoha: driver fixes & improvements Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 01/13] spi: airoha: return an error for continuous mode dirmap creation cases Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 02/13] spi: airoha: remove unnecessary restriction length Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 03/13] spi: airoha: add support of dual/quad wires spi modes to exec_op() handler Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 04/13] spi: airoha: remove unnecessary switch to non-dma mode Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 05/13] spi: airoha: switch back to non-dma mode in the case of error Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 06/13] spi: airoha: fix reading/writing of flashes with more than one plane per lun Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 07/13] spi: airoha: unify dirmap read/write code Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 08/13] spi: airoha: support of dualio/quadio flash reading commands Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 09/13] spi: airoha: avoid setting of page/oob sizes in REG_SPI_NFI_PAGEFMT Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 10/13] spi: airoha: reduce the number of modification of REG_SPI_NFI_CNFG and REG_SPI_NFI_SECCUS_SIZE registers Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 11/13] spi: airoha: set custom sector size equal to flash page size Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 12/13] spi: airoha: avoid reading flash page settings from SNFI registers during driver startup Mikhail Kshevetskiy
2025-08-23 16:01 ` [PATCH v5 13/13] spi: airoha: buffer must be 0xff-ed before writing Mikhail Kshevetskiy
2025-08-29 7:14 ` [PATCH v5 00/13] spi: airoha: driver fixes & improvements Mikhail Kshevetskiy
2025-08-29 8:45 ` Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aKnTYNsaBIkh6OBS@lore-rh-laptop \
--to=lorenzo@kernel.org \
--cc=broonie@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mikhail.kshevetskiy@iopsys.eu \
--cc=quic_jseerapu@quicinc.com \
--cc=ray.liu@airoha.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox