blob: c6ef2c3b06ee169a0a8afa95c909004309091e2e [file] [log] [blame]
From 756cbbbd828bf0a5e67e9e95fb873155a0e00360 Mon Sep 17 00:00:00 2001
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
Date: Tue, 10 Jul 2018 23:42:16 +0200
Subject: [PATCH 1623/1795] i2c: recovery: require either get_sda or set_sda
For bus recovery, we either need to bail out early if we can read SDA or
we need to send STOP after every pulse. Otherwise recovery might be
misinterpreted as an unwanted write. So, require one of those SDA
handling functions to avoid this problem.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Acked-by: Peter Rosin <peda@axentia.se>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
(cherry picked from commit ffc59c496bf8498657321c59433f55bbcf2d9c38)
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
drivers/i2c/i2c-core-base.c | 7 ++++++-
include/linux/i2c.h | 12 ++++++------
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 4566f9dd26cf..ea4cc8defada 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -236,7 +236,8 @@ static int i2c_generic_recovery(struct i2c_adapter *adap)
/*
* If we can set SDA, we will always create STOP here to ensure
* the additional pulses will do no harm. This is achieved by
- * letting SDA follow SCL half a cycle later.
+ * letting SDA follow SCL half a cycle later. Check the
+ * 'incomplete_write_byte' fault injector for details.
*/
ndelay(RECOVERY_NDELAY / 2);
if (bri->set_sda)
@@ -342,6 +343,10 @@ static void i2c_init_recovery(struct i2c_adapter *adap)
err_str = "no {get|set}_scl() found";
goto err;
}
+ if (!bri->set_sda && !bri->get_sda) {
+ err_str = "either get_sda() or set_sda() needed";
+ goto err;
+ }
}
return;
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index fef505ecab2b..6bc0ddb850c8 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -488,12 +488,12 @@ struct i2c_timings {
* recovery. Populated internally for generic GPIO recovery.
* @set_scl: This sets/clears the SCL line. Mandatory for generic SCL recovery.
* Populated internally for generic GPIO recovery.
- * @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.
+ * @get_sda: This gets current value of SDA line. This or set_sda() is mandatory
+ * 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. This or get_sda() is mandatory 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
--
2.19.0