aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux/linux-yocto-4.14.71/4121-mp2-i2c-error-handling-in-read-write-operation.patch
blob: 55a56dded13f95a12e5f776006b5d4006290eb45 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
From 7363ed0c57b235e95e07d7c9bff6eeeee671203a Mon Sep 17 00:00:00 2001
From: Sudheesh Mavila <sudheesh.mavila@amd.com>
Date: Sun, 19 Aug 2018 10:45:25 +0530
Subject: [PATCH 4121/4131] mp2-i2c error handling in read/write operation

Signed-off-by: Sudheesh Mavila <sudheesh.mavila@amd.com>
---
 drivers/i2c/busses/i2c-amd-pci-mp2.c | 13 +++++++++++++
 drivers/i2c/busses/i2c-amd-platdrv.c | 37 ++++++++++++++++++++++++++++++++----
 2 files changed, 46 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-amd-pci-mp2.c b/drivers/i2c/busses/i2c-amd-pci-mp2.c
index 15d671a..1804141 100644
--- a/drivers/i2c/busses/i2c-amd-pci-mp2.c
+++ b/drivers/i2c/busses/i2c-amd-pci-mp2.c
@@ -270,6 +270,19 @@ static void amd_mp2_pci_work(struct work_struct *work)
 			privdata->ops->connect_complete(privdata->eventval,
 					privdata->i2c_dev_ctx);
 	} else {
+		if (sts == i2c_busenable_failed) {
+			if (privdata->ops->connect_complete)
+			privdata->ops->connect_complete(privdata->eventval,
+					privdata->i2c_dev_ctx);
+		}else if (sts == i2c_writefail_event) {
+			if (privdata->ops->write_complete)
+				privdata->ops->write_complete(privdata->eventval,
+					privdata->i2c_dev_ctx);
+		}else if (sts == i2c_readfail_event) {
+			if (privdata->ops->read_complete) 
+			privdata->ops->read_complete(privdata->eventval,
+						privdata->i2c_dev_ctx);
+		} else
 		dev_err(ndev_dev(privdata), "ERROR!!nothing to be handled !\n");
 	}
 }
diff --git a/drivers/i2c/busses/i2c-amd-platdrv.c b/drivers/i2c/busses/i2c-amd-platdrv.c
index 090f087..2f3d2ad 100644
--- a/drivers/i2c/busses/i2c-amd-platdrv.c
+++ b/drivers/i2c/busses/i2c-amd-platdrv.c
@@ -67,6 +67,7 @@ struct amd_i2c_dev {
 	struct i2c_msg *msg_buf;
 	bool is_configured;
 	u8 bus_id;
+	u16 err;
 
 };
 
@@ -102,7 +103,10 @@ static int i2c_amd_read_completion(struct i2c_event event, void *dev_ctx)
 					 DRIVER_NAME, __func__, ((unsigned int *)
 					commond->read_cfg.buf)[i]);
 		}
-
+		i2c_dev->err = i2c_readcomplete_event;
+		complete(&i2c_dev->msg_complete);
+	} else {
+		i2c_dev->err = i2c_readfail_event;
 		complete(&i2c_dev->msg_complete);
 	}
 
@@ -113,8 +117,13 @@ static int i2c_amd_write_completion(struct i2c_event event, void *dev_ctx)
 {
 	struct amd_i2c_dev *i2c_dev = (struct amd_i2c_dev *)dev_ctx;
 
-	if (event.base.r.status == i2c_writecomplete_event)
+	if (event.base.r.status == i2c_writecomplete_event) {
+		i2c_dev->err = i2c_writecomplete_event;
+		complete(&i2c_dev->msg_complete);
+	} else {
+		i2c_dev->err = i2c_writefail_event;
 		complete(&i2c_dev->msg_complete);
+	}
 
 	return 0;
 }
@@ -123,9 +132,13 @@ static int i2c_amd_connect_completion(struct i2c_event event, void *dev_ctx)
 {
 	struct amd_i2c_dev *i2c_dev = (struct amd_i2c_dev *)dev_ctx;
 
-	if (event.base.r.status == i2c_busenable_complete)
+	if (event.base.r.status == i2c_busenable_complete) {
+		i2c_dev->err = i2c_busenable_complete;
 		complete(&i2c_dev->msg_complete);
-
+	} else {
+		i2c_dev->err = i2c_busenable_failed;
+		complete(&i2c_dev->msg_complete);
+	}
 	return 0;
 }
 
@@ -211,6 +224,13 @@ static int i2c_amd_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 			else
 				dma_free_coherent(&i2c_common->pdev->dev,
 						  pmsg->len, buf, phys);
+						  
+			if((timeout == 0)||(dev->err != i2c_readcomplete_event)) {
+				if(dev->err != i2c_readcomplete_event) 
+					return -EIO;
+				else
+					return -ETIMEDOUT;
+			}
 		} else {
 			i2c_common->write_cfg.buf = (unsigned int *)pmsg->buf;
 			i2c_common->write_cfg.length = pmsg->len;
@@ -219,6 +239,12 @@ static int i2c_amd_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 			timeout = wait_for_completion_timeout
 						(&dev->msg_complete, 50);
+			if((timeout == 0)||(dev->err != i2c_writecomplete_event)) {
+				if(dev->err != i2c_writecomplete_event) 
+					return -EIO;
+				else 
+					return -ETIMEDOUT;
+			}
 		}
 	}
 	return num;
@@ -281,6 +307,9 @@ static int i2c_amd_probe(struct platform_device *pdev)
 		pr_err("%s Could not find pdev in i2c\n", __func__);
 		return -EINVAL;
 	}
+
+	i2c_dev->err = i2C_bus_notinitialized;
+
 	platform_set_drvdata(pdev, i2c_dev);
 
 	i2c_set_adapdata(&i2c_dev->adapter, i2c_dev);
-- 
2.7.4