All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhaojh329@gmail.com" <zhaojh329@gmail.com>
To: sr <sr@denx.de>
Cc: matthias.bgg <matthias.bgg@gmail.com>,
	 linux-i2c <linux-i2c@vger.kernel.org>,
	 linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	 linux-mediatek <linux-mediatek@lists.infradead.org>,
	 linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] i2c: mt76xx: add I2C_FUNC_NOSTART and I2C_M_REV_DIR_ADDR
Date: Wed, 20 Oct 2021 00:07:16 +0800	[thread overview]
Message-ID: <202110200007146639874@gmail.com> (raw)

 This patch adds I2C_FUNC_NOSTART and I2C_M_REV_DIR_ADDR support for
MediaTek MT7621/7628/7688. This is useful for some I2C slave chips,
such as 'drivers/input/joystick/as5011.c'.

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
---
 drivers/i2c/busses/i2c-mt7621.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 45fe4a7fe0c0..3d2763d9c090 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -150,6 +150,9 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 	for (i = 0; i < num; i++) {
 		pmsg = &msgs[i];
 
+		if (pmsg->flags & I2C_M_NOSTART)
+			goto nostart;
+
 		/* wait hardware idle */
 		ret = mtk_i2c_wait_idle(i2c);
 		if (ret)
@@ -174,6 +177,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 		} else {
 			/* 7 bits address */
 			addr = i2c_8bit_addr_from_msg(pmsg);
+			if (pmsg->flags & I2C_M_REV_DIR_ADDR)
+				addr ^= 1;
 			iowrite32(addr, i2c->base + REG_SM0D0_REG);
 			ret = mtk_i2c_master_cmd(i2c, SM0CTL1_WRITE, 1);
 			if (ret)
@@ -187,6 +192,7 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 				goto err_ack;
 		}
 
+nostart:
 		/* transfer data */
 		for (len = pmsg->len, j = 0; len > 0; len -= 8, j += 8) {
 			page_len = (len >= 8) ? 8 : len;
@@ -242,7 +248,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 
 static u32 mtk_i2c_func(struct i2c_adapter *a)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR
+		| I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
 }
 
 static const struct i2c_algorithm mtk_i2c_algo = {
-- 
2.25.1

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

WARNING: multiple messages have this Message-ID (diff)
From: "zhaojh329@gmail.com" <zhaojh329@gmail.com>
To: sr <sr@denx.de>
Cc: matthias.bgg <matthias.bgg@gmail.com>,
	 linux-i2c <linux-i2c@vger.kernel.org>,
	 linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	 linux-mediatek <linux-mediatek@lists.infradead.org>,
	 linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] i2c: mt76xx: add I2C_FUNC_NOSTART and I2C_M_REV_DIR_ADDR
Date: Wed, 20 Oct 2021 00:07:16 +0800	[thread overview]
Message-ID: <202110200007146639874@gmail.com> (raw)

 This patch adds I2C_FUNC_NOSTART and I2C_M_REV_DIR_ADDR support for
MediaTek MT7621/7628/7688. This is useful for some I2C slave chips,
such as 'drivers/input/joystick/as5011.c'.

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
---
 drivers/i2c/busses/i2c-mt7621.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-mt7621.c b/drivers/i2c/busses/i2c-mt7621.c
index 45fe4a7fe0c0..3d2763d9c090 100644
--- a/drivers/i2c/busses/i2c-mt7621.c
+++ b/drivers/i2c/busses/i2c-mt7621.c
@@ -150,6 +150,9 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 	for (i = 0; i < num; i++) {
 		pmsg = &msgs[i];
 
+		if (pmsg->flags & I2C_M_NOSTART)
+			goto nostart;
+
 		/* wait hardware idle */
 		ret = mtk_i2c_wait_idle(i2c);
 		if (ret)
@@ -174,6 +177,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 		} else {
 			/* 7 bits address */
 			addr = i2c_8bit_addr_from_msg(pmsg);
+			if (pmsg->flags & I2C_M_REV_DIR_ADDR)
+				addr ^= 1;
 			iowrite32(addr, i2c->base + REG_SM0D0_REG);
 			ret = mtk_i2c_master_cmd(i2c, SM0CTL1_WRITE, 1);
 			if (ret)
@@ -187,6 +192,7 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 				goto err_ack;
 		}
 
+nostart:
 		/* transfer data */
 		for (len = pmsg->len, j = 0; len > 0; len -= 8, j += 8) {
 			page_len = (len >= 8) ? 8 : len;
@@ -242,7 +248,8 @@ static int mtk_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
 
 static u32 mtk_i2c_func(struct i2c_adapter *a)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR
+		| I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_NOSTART;
 }
 
 static const struct i2c_algorithm mtk_i2c_algo = {
-- 
2.25.1

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

             reply	other threads:[~2021-10-19 16:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-19 16:07 zhaojh329 [this message]
2021-10-19 16:07 ` [PATCH] i2c: mt76xx: add I2C_FUNC_NOSTART and I2C_M_REV_DIR_ADDR zhaojh329
2021-10-22  6:44 ` Stefan Roese
2021-10-22  6:44   ` Stefan Roese
2021-10-22  6:44   ` Stefan Roese

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=202110200007146639874@gmail.com \
    --to=zhaojh329@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=sr@denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.