From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-i2c@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Phil Reid <preid@electromag.com.au>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Jarkko Nikula <jarkko.nikula@linux.intel.com>,
Claudio Foellmi <claudio.foellmi@ergon.ch>,
Andrzej Hajda <a.hajda@samsung.com>
Subject: [PATCH 3/6] i2c: add 'set_sda' to bus_recovery_info
Date: Mon, 4 Dec 2017 13:36:37 +0100 [thread overview]
Message-ID: <20171204123640.3382-4-wsa+renesas@sang-engineering.com> (raw)
In-Reply-To: <20171204123640.3382-1-wsa+renesas@sang-engineering.com>
This will be needed when we want to create STOP conditions, too, later.
Create the needed fields and populate them for the GPIO case if the GPIO
is set to output.
Cc: Phil Reid <preid@electromag.com.au>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Cc: Claudio Foellmi <claudio.foellmi@ergon.ch>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core-base.c | 11 ++++++++++-
include/linux/i2c.h | 4 ++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index bb34a5d4113331..f4313801a0aaba 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -27,6 +27,7 @@
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/errno.h>
+#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/i2c-smbus.h>
@@ -147,6 +148,11 @@ static int get_sda_gpio_value(struct i2c_adapter *adap)
return gpiod_get_value_cansleep(adap->bus_recovery_info->sda_gpiod);
}
+static void set_sda_gpio_value(struct i2c_adapter *adap, int val)
+{
+ gpiod_set_value_cansleep(adap->bus_recovery_info->sda_gpiod, val);
+}
+
/*
* We are generating clock pulses. ndelay() determines durating of clk pulses.
* We will generate clock with rate 100 KHz and so duration of both clock levels
@@ -225,8 +231,11 @@ static void i2c_init_recovery(struct i2c_adapter *adap)
if (bri->scl_gpiod && bri->recover_bus == i2c_generic_scl_recovery) {
bri->get_scl = get_scl_gpio_value;
bri->set_scl = set_scl_gpio_value;
- if (bri->sda_gpiod)
+ if (bri->sda_gpiod) {
bri->get_sda = get_sda_gpio_value;
+ if (gpiod_get_direction(bri->sda_gpiod) == GPIOF_DIR_OUT)
+ bri->set_sda = set_sda_gpio_value;
+ }
return;
}
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 8a020617b4e780..c3e402e647791c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -551,6 +551,9 @@ struct i2c_timings {
* @get_sda: This gets current value of SDA line. Optional for generic SCL
* recovery. Populated internally, if sda_gpio is a valid GPIO, for generic
* GPIO recovery.
+ * @set_sda: This sets/clears the SDA line. Optional for generic SCL recovery.
+ * Populated internally, if sda_gpio is a valid GPIO, for generic GPIO
+ * recovery.
* @prepare_recovery: This will be called before starting recovery. Platform may
* configure padmux here for SDA/SCL line or something else they want.
* @unprepare_recovery: This will be called after completing recovery. Platform
@@ -564,6 +567,7 @@ struct i2c_bus_recovery_info {
int (*get_scl)(struct i2c_adapter *adap);
void (*set_scl)(struct i2c_adapter *adap, int val);
int (*get_sda)(struct i2c_adapter *adap);
+ void (*set_sda)(struct i2c_adapter *adap, int val);
void (*prepare_recovery)(struct i2c_adapter *);
void (*unprepare_recovery)(struct i2c_adapter *);
--
2.11.0
next prev parent reply other threads:[~2017-12-04 12:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20171204123700epcas2p4273f3313a4c52e7685bbf04d776cbcef@epcas2p4.samsung.com>
2017-12-04 12:36 ` [PATCH 0/6] i2c: send STOP after recovery; use it for i2c-rcar Wolfram Sang
2017-12-04 12:36 ` [PATCH 1/6] i2c: make kerneldoc about bus recovery more precise Wolfram Sang
2017-12-04 12:36 ` [PATCH 2/6] i2c: add identifier in declarations for i2c_bus_recovery Wolfram Sang
2017-12-13 15:23 ` Andy Shevchenko
2018-01-09 11:17 ` Wolfram Sang
2017-12-04 12:36 ` Wolfram Sang [this message]
2017-12-05 1:12 ` [PATCH 3/6] i2c: add 'set_sda' to bus_recovery_info Phil Reid
2017-12-05 8:39 ` Linus Walleij
2017-12-05 9:57 ` Phil Reid
2017-12-05 10:32 ` Wolfram Sang
2017-12-05 10:34 ` Linus Walleij
2017-12-05 13:38 ` Wolfram Sang
2017-12-05 15:31 ` Linus Walleij
2017-12-05 16:43 ` Wolfram Sang
2017-12-07 11:25 ` Wolfram Sang
2017-12-10 0:24 ` Linus Walleij
2017-12-13 15:30 ` Andy Shevchenko
2018-01-09 11:23 ` Wolfram Sang
2017-12-13 15:27 ` Andy Shevchenko
2017-12-04 12:36 ` [PATCH 4/6] i2c: ensure SDA is released in recovery if SDA is controllable Wolfram Sang
2017-12-04 12:36 ` [PATCH 5/6] i2c: send STOP after successful bus recovery Wolfram Sang
2017-12-04 12:36 ` [PATCH 6/6] i2c: rcar: implement " Wolfram Sang
2017-12-05 1:13 ` [PATCH 0/6] i2c: send STOP after recovery; use it for i2c-rcar Phil Reid
2017-12-05 9:21 ` Andrzej Hajda
2018-01-09 11:15 ` Wolfram Sang
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=20171204123640.3382-4-wsa+renesas@sang-engineering.com \
--to=wsa+renesas@sang-engineering.com \
--cc=a.hajda@samsung.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=claudio.foellmi@ergon.ch \
--cc=jarkko.nikula@linux.intel.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=preid@electromag.com.au \
/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 NNTP newsgroup(s).