public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Mohammed Billoo <mab@mab-labs.com>
Cc: peter@korsgaard.com, linux-i2c@vger.kernel.org
Subject: Re: [PATCH] i2c: ocores: Allow endian-specific grlib accessors
Date: Tue, 18 Aug 2020 03:34:10 +0200	[thread overview]
Message-ID: <20200818013410.GG2294711@lunn.ch> (raw)
In-Reply-To: <20200814210154.14402-1-mab@mab-labs.com>

On Fri, Aug 14, 2020 at 05:01:54PM -0400, Mohammed Billoo wrote:
> Due to inconsistent/broken HW, SW may need to set the appropriate
> endianess of the grlib accessors (instead of defaulting to big endian).

I think you have this wrong.

> -static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg)
> +static u8 oc_getreg_grlib_be(struct ocores_i2c *i2c, int reg)
>  {
>  	u32 rd;
>  	int rreg = reg;
> @@ -506,7 +507,21 @@ static u8 oc_getreg_grlib(struct ocores_i2c *i2c, int reg)
>  		return (u8)rd;
>  }

So the existing code is big endian.


> -static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value)
> +static u8 oc_getreg_grlib_le(struct ocores_i2c *i2c, int reg)
> +{
> +	u32 rd;
> +	int rreg = reg;
> +
> +	if (reg != OCI2C_PRELOW)
> +		rreg--;
> +	rd = ioread32(i2c->base + (rreg << i2c->reg_shift));
> +	if (reg == OCI2C_PREHIGH)
> +		return (u8)(rd >> 8);
> +	else
> +		return (u8)rd;
> +}

You are adding little endian accesses.

> @@ -592,8 +626,17 @@ static int ocores_i2c_of_probe(struct platform_device *pdev,
>  	match = of_match_node(ocores_i2c_match, pdev->dev.of_node);
>  	if (match && (long)match->data == TYPE_GRLIB) {
>  		dev_dbg(&pdev->dev, "GRLIB variant of i2c-ocores\n");
> -		i2c->setreg = oc_setreg_grlib;
> -		i2c->getreg = oc_getreg_grlib;
> +		/*
> +		 * This is a workaround for inconsistent/broken HW,
> +		 * where SW has to set the appropriate endianess
> +		 */
> +		if (of_device_is_big_endian(pdev->dev.of_node)) {
> +			i2c->setreg = oc_setreg_grlib_be;
> +			i2c->getreg = oc_getreg_grlib_be;
> +		} else {
> +			i2c->setreg = oc_setreg_grlib_le;
> +			i2c->getreg = oc_getreg_grlib_le;
> +		}

Existing device tree blobs won't indicate an endianess. They assume
big endian is the default. But you are changing that, they now need to
indicate they are big endian. And they won't, so you will break them.

For you specific platform, you need to indicate in device tree it
needs little endian, by adding a property.

Please also document the property you add in i2c-ocores.txt.

      Andrew

  reply	other threads:[~2020-08-18  1:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 21:01 [PATCH] i2c: ocores: Allow endian-specific grlib accessors Mohammed Billoo
2020-08-18  1:34 ` Andrew Lunn [this message]
2020-08-18 22:14   ` Mohammed Billoo
2020-08-19  2:14     ` Andrew Lunn
2020-08-19 23:57       ` Mohammed Billoo

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=20200818013410.GG2294711@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=linux-i2c@vger.kernel.org \
    --cc=mab@mab-labs.com \
    --cc=peter@korsgaard.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