summaryrefslogtreecommitdiffstats
path: root/target/linux/bcm27xx/patches-6.1/950-0737-i2c-bcm2835-Implement-I2C_M_IGNORE_NAK.patch
blob: 7238b0293d869f97abb8f1fbdc5e0b8d602ed297 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From 5faad0781d619f13723886e36dfed3ea7eeff00f Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Tue, 23 May 2023 14:31:03 +0100
Subject: [PATCH] i2c-bcm2835: Implement I2C_M_IGNORE_NAK

Now that transfers aren't aborted immediately (and uncleanly) on
errors, and the FIFOs are always drained after all transfers, we
can implement I2C_M_IGNORE_NAK by ignoring the returned error
value.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/i2c/busses/i2c-bcm2835.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

--- a/drivers/i2c/busses/i2c-bcm2835.c
+++ b/drivers/i2c/busses/i2c-bcm2835.c
@@ -443,6 +443,7 @@ static int bcm2835_i2c_xfer(struct i2c_a
 {
 	struct bcm2835_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
 	unsigned long time_left;
+	bool ignore_nak = false;
 	int i;
 
 	if (debug)
@@ -452,12 +453,15 @@ static int bcm2835_i2c_xfer(struct i2c_a
 		for (i = 0; i < num; i++)
 			bcm2835_debug_print_msg(i2c_dev, &msgs[i], i + 1, num, __func__);
 
-	for (i = 0; i < (num - 1); i++)
+	for (i = 0; i < (num - 1); i++) {
 		if (msgs[i].flags & I2C_M_RD) {
 			dev_warn_once(i2c_dev->dev,
 				      "only one read message supported, has to be last\n");
 			return -EOPNOTSUPP;
 		}
+		if (msgs[i].flags & I2C_M_IGNORE_NAK)
+			ignore_nak = true;
+	}
 
 	i2c_dev->curr_msg = msgs;
 	i2c_dev->num_msgs = num;
@@ -471,6 +475,9 @@ static int bcm2835_i2c_xfer(struct i2c_a
 
 	bcm2835_i2c_finish_transfer(i2c_dev);
 
+	if (ignore_nak)
+		i2c_dev->msg_err &= ~BCM2835_I2C_S_ERR;
+
 	if (debug > 1 || (debug && (!time_left || i2c_dev->msg_err)))
 		bcm2835_debug_print(i2c_dev);
 	i2c_dev->debug_num_msgs = 0;
@@ -497,7 +504,7 @@ static int bcm2835_i2c_xfer(struct i2c_a
 
 static u32 bcm2835_i2c_func(struct i2c_adapter *adap)
 {
-	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING;
 }
 
 static const struct i2c_algorithm bcm2835_i2c_algo = {