From: Mohammed Billoo <mab@mab-labs.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Mohammed Billoo <mab@mab-labs.com>,
peter@korsgaard.com, andrew@lunn.ch, linux-i2c@vger.kernel.org
Subject: [PATCH] i2c: ocores: Allow endian-specific grlib accessors
Date: Fri, 14 Aug 2020 17:01:54 -0400 [thread overview]
Message-ID: <20200814210154.14402-1-mab@mab-labs.com> (raw)
Due to inconsistent/broken HW, SW may need to set the appropriate
endianess of the grlib accessors (instead of defaulting to big endian).
This patch adds such a capability.
Signed-off-by: Mohammed Billoo <mab@mab-labs.com>
---
drivers/i2c/busses/i2c-ocores.c | 55 +++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 6 deletions(-)
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index f5fc75b65a19..2ef735f8c71f 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -488,11 +488,12 @@ MODULE_DEVICE_TABLE(of, ocores_i2c_match);
#ifdef CONFIG_OF
/*
- * Read and write functions for the GRLIB port of the controller. Registers are
- * 32-bit big endian and the PRELOW and PREHIGH registers are merged into one
+ * Read and write functions for the GRLIB port of the controller. Unfortunately,
+ * do to some broken/inconsistent HW, SW may need to account for different
+ * endianess of GRLIB. PRELOW and PREHIGH registers are merged into one
* register. The subsequent registers have their offsets decreased accordingly.
*/
-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;
}
-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;
+}
+
+static void oc_setreg_grlib_be(struct ocores_i2c *i2c, int reg, u8 value)
{
u32 curr, wr;
int rreg = reg;
@@ -525,6 +540,25 @@ static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value)
iowrite32be(wr, i2c->base + (rreg << i2c->reg_shift));
}
+static void oc_setreg_grlib_le(struct ocores_i2c *i2c, int reg, u8 value)
+{
+ u32 curr, wr;
+ int rreg = reg;
+
+ if (reg != OCI2C_PRELOW)
+ rreg--;
+ if (reg == OCI2C_PRELOW || reg == OCI2C_PREHIGH) {
+ curr = ioread32(i2c->base + (rreg << i2c->reg_shift));
+ if (reg == OCI2C_PRELOW)
+ wr = (curr & 0xff00) | value;
+ else
+ wr = (((u32)value) << 8) | (curr & 0xff);
+ } else {
+ wr = value;
+ }
+ iowrite32(wr, i2c->base + (rreg << i2c->reg_shift));
+}
+
static int ocores_i2c_of_probe(struct platform_device *pdev,
struct ocores_i2c *i2c)
{
@@ -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;
+ }
}
return 0;
--
2.17.1
next reply other threads:[~2020-08-14 21:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-14 21:01 Mohammed Billoo [this message]
2020-08-18 1:34 ` [PATCH] i2c: ocores: Allow endian-specific grlib accessors Andrew Lunn
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=20200814210154.14402-1-mab@mab-labs.com \
--to=mab@mab-labs.com \
--cc=andrew@lunn.ch \
--cc=linux-i2c@vger.kernel.org \
--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