public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
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 2/2] i2c: ocores: add be/le support for gaisler
Date: Fri, 14 Aug 2020 12:31:34 -0400	[thread overview]
Message-ID: <20200814163134.29493-2-mab@mab-labs.com> (raw)
In-Reply-To: <20200814163134.29493-1-mab@mab-labs.com>

Add be/le accessors for grlib (as is done for the standard ocore
accessors).

Signed-off-by: Mohammed Billoo <mab@mab-labs.com>
---
 arch/arm/configs/socfpga_defconfig |  1 +
 drivers/i2c/busses/i2c-ocores.c    | 55 ++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/arch/arm/configs/socfpga_defconfig b/arch/arm/configs/socfpga_defconfig
index e73c97b0f5b0..55bf9cfcf75c 100644
--- a/arch/arm/configs/socfpga_defconfig
+++ b/arch/arm/configs/socfpga_defconfig
@@ -162,3 +162,4 @@ CONFIG_DETECT_HUNG_TASK=y
 # CONFIG_SCHED_DEBUG is not set
 CONFIG_FUNCTION_TRACER=y
 CONFIG_DEBUG_USER=y
+CONFIG_I2C_OCORES=y
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 0975f6797069..a5f9e6cb4814 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -492,7 +492,7 @@ MODULE_DEVICE_TABLE(of, ocores_i2c_match);
  * 32-bit big endian and the 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 +506,7 @@ 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 void oc_setreg_grlib_be(struct ocores_i2c *i2c, int reg, u8 value)
 {
 	u32 curr, wr;
 	int rreg = reg;
@@ -525,6 +525,39 @@ static void oc_setreg_grlib(struct ocores_i2c *i2c, int reg, u8 value)
 	iowrite32be(wr, i2c->base + (rreg << i2c->reg_shift));
 }
 
+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_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 +625,13 @@ 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;
+		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;
@@ -648,8 +686,13 @@ static int ocores_i2c_probe(struct platform_device *pdev)
 		else
 			i2c->bus_clock_khz = 100;
 		if (pdata->gaisler) {
-			i2c->setreg = oc_setreg_grlib;
-			i2c->getreg = oc_getreg_grlib;
+			if (pdata->big_endian) {
+				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;
+			}
 		}
 	} else {
 		ret = ocores_i2c_of_probe(pdev, i2c);
-- 
2.17.1


  reply	other threads:[~2020-08-14 16:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14 16:31 [PATCH 1/2] i2c: ocores: add gaisler to platform data Mohammed Billoo
2020-08-14 16:31 ` Mohammed Billoo [this message]
2020-08-14 16:50   ` [PATCH 2/2] i2c: ocores: add be/le support for gaisler Andrew Lunn
     [not found]     ` <CALkjhPppeOwekp-ZJZ9QGfNGa=K5g6P+TWs42Anrb+QvFSrspQ@mail.gmail.com>
2020-08-14 19:02       ` Andrew Lunn
2020-08-14 19:05         ` Wolfram Sang
2020-08-14 16:49 ` [PATCH 1/2] i2c: ocores: add gaisler to platform data Andrew Lunn
     [not found]   ` <CALkjhPo3BGRDao=Rz9S5Xxf1bubBXv7WEGu6B=5V1WvnmGUmwg@mail.gmail.com>
2020-08-14 19:04     ` Andrew Lunn

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=20200814163134.29493-2-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