Linux-i2c Archive mirror
 help / color / mirror / Atom feed
From: Andi Shyti <andi.shyti@kernel.org>
To: Aryan Srivastava <aryan.srivastava@alliedtelesis.co.nz>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] i2c:octeon:Add block-mode r/w
Date: Tue, 5 Sep 2023 12:22:34 +0200	[thread overview]
Message-ID: <20230905102234.nlaeskxbbvu74co2@zenone.zhora.eu> (raw)
In-Reply-To: <20230904231439.485925-1-aryan.srivastava@alliedtelesis.co.nz>

Hi Aryan,

In the title, please leave a space after the ':'

   i2c: octeon: Add block-mode r/w

Please check with "git log drivers..." to see what's the rule in
a particular community.

I guess Wolfram can fix this, though, before pushing.

[...]

> +/* high-level-controller composite block write+read, msg0=addr, msg1=data */

I think this comment is fine and great to have it, but it's
missing a bit of clarity, can you please expand the concept?

> +static int octeon_i2c_hlc_block_comp_read(struct octeon_i2c *i2c, struct i2c_msg *msgs)
> +{
> +	int i, j, len, ret = 0;
> +	u64 cmd = 0, rd = 0;

can please you move rd, j inside the for loop? The basic common
sense is to have all variable declared in the innermost section
in order to avoid confusion.

It's a nitpick though, not a strong comment and, afaik, not a
real rule.

Same comment for the function below.

> +
> +	octeon_i2c_hlc_enable(i2c);
> +	octeon_i2c_block_enable(i2c);
> +
> +	/* Write (size - 1) into block control register */
> +	len = msgs[1].len - 1;
> +	octeon_i2c_writeq_flush((u64)(len), i2c->twsi_base + TWSI_BLOCK_CTL(i2c));
> +
> +	/* Prepare core command */
> +	cmd = SW_TWSI_V | SW_TWSI_R | SW_TWSI_SOVR;
> +	cmd |= (u64)(msgs[0].addr & 0x7full) << SW_TWSI_ADDR_SHIFT;
> +
> +	if (msgs[0].flags & I2C_M_TEN)
> +		cmd |= SW_TWSI_OP_10_IA;
> +	else
> +		cmd |= SW_TWSI_OP_7_IA;
> +
> +	if (msgs[0].len == 2) {
> +		u64 ext = 0;
> +
> +		cmd |= SW_TWSI_EIA;
> +		ext = (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT;
> +		cmd |= (u64)msgs[0].buf[1] << SW_TWSI_IA_SHIFT;
> +		octeon_i2c_writeq_flush(ext, i2c->twsi_base + SW_TWSI_EXT(i2c));
> +	} else {
> +		cmd |= (u64)msgs[0].buf[0] << SW_TWSI_IA_SHIFT;
> +	}

This first part is basically a copy/paste with the write()
function... can we put them together in a common function?

Can we put as much as we can in a single function?

> +	/* Send command to core (send data to FIFO) */
> +	octeon_i2c_hlc_int_clear(i2c);
> +	octeon_i2c_writeq_flush(cmd, i2c->twsi_base + SW_TWSI(i2c));
> +
> +	/* Wait for transaction to complete */
> +	ret = octeon_i2c_hlc_wait(i2c);
> +	if (ret)
> +		return ret;
> +
> +	cmd = __raw_readq(i2c->twsi_base + SW_TWSI(i2c));
> +	if ((cmd & SW_TWSI_R) == 0)
> +		return octeon_i2c_check_status(i2c, false);
> +
> +	/* read data in FIFO */
> +	octeon_i2c_writeq_flush(TWSI_BLOCK_STS_RESET_PTR, i2c->twsi_base + TWSI_BLOCK_STS(i2c));
> +	for (i = 0; i < len; i += 8) {
> +		rd = __raw_readq(i2c->twsi_base + TWSI_BLOCK_FIFO(i2c));
> +		for (j = 7; j >= 0; j--)

is len always a multiple of 8?

> +			msgs[1].buf[i + (7 - j)] = (rd >> (8 * j)) & 0xff;
> +	}
> +
> +	octeon_i2c_block_disable(i2c);
> +	return ret;
> +}

[...]

> -		    msgs[1].len > 0 && msgs[1].len <= 8 &&
> +		    msgs[1].len > 0 &&
>  		    msgs[0].addr == msgs[1].addr) {
> -			if (msgs[1].flags & I2C_M_RD)
> -				ret = octeon_i2c_hlc_comp_read(i2c, msgs);
> -			else
> -				ret = octeon_i2c_hlc_comp_write(i2c, msgs);
> -			goto out;
> +			if (msgs[1].len <= 8) {
> +				if (msgs[1].flags & I2C_M_RD)
> +					ret = octeon_i2c_hlc_comp_read(i2c, msgs);
> +				else
> +					ret = octeon_i2c_hlc_comp_write(i2c, msgs);
> +				goto out;
> +			} else if (msgs[1].len <= 1024 && TWSI_BLOCK_CTL(i2c)) {
> +				if (msgs[1].flags & I2C_M_RD)
> +					ret = octeon_i2c_hlc_block_comp_read(i2c, msgs);
> +				else
> +					ret = octeon_i2c_hlc_block_comp_write(i2c, msgs);
> +				goto out;
> +			}

the rest looks good...

Thanks,
Andi

  parent reply	other threads:[~2023-09-05 16:20 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 23:45 [PATCH] i2c:octeon:Add block-mode r/w Aryan Srivastava
2023-07-25 22:33 ` Andi Shyti
2023-08-16 23:07   ` Aryan Srivastava
2023-09-03 12:34     ` Andi Shyti
2023-09-04 23:14       ` Aryan Srivastava
2023-09-05  6:27         ` kernel test robot
2023-09-05  7:52         ` kernel test robot
2023-09-05 10:22         ` Andi Shyti [this message]
2023-09-12  0:27           ` [PATCH] THUNDERX_I2C_BLOCK_MODE Aryan Srivastava
2023-09-12  3:38             ` kernel test robot
2023-09-12  0:28           ` [PATCH] i2c:octeon:Add block-mode r/w Aryan Srivastava
2023-09-12  1:16             ` [PATCH] i2c: octeon: Add " Aryan Srivastava
2024-01-16  1:38               ` Aryan Srivastava
     [not found]           ` <9882daa4945914886b21642837816c2d99c027ac.camel@alliedtelesis.co.nz>
2023-10-25 21:20             ` [PATCH] i2c:octeon:Add " Aryan Srivastava
2024-04-15  0:52           ` [PATCH v4] i2c: octeon: Add " Aryan Srivastava
2024-04-15 21:59             ` Andi Shyti
2024-06-10  2:59               ` Aryan Srivastava

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=20230905102234.nlaeskxbbvu74co2@zenone.zhora.eu \
    --to=andi.shyti@kernel.org \
    --cc=aryan.srivastava@alliedtelesis.co.nz \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).