aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/linux-yocto-4.14.71/5256-drm-amd-display-Flatten-unnecessary-i2c-functions.patch
blob: 172e8799727da8031230b8e428f5c34666f886d8 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
From 96288a7d1c7be36f49c31fba17f25b192223ae73 Mon Sep 17 00:00:00 2001
From: David Francis <David.Francis@amd.com>
Date: Fri, 3 Aug 2018 13:24:28 -0400
Subject: [PATCH 5256/5725] drm/amd/display: Flatten unnecessary i2c functions

[Why]
The dce_i2c_hw code contained four funtcions that were only
called in one place and did not have a clearly delineated
purpose.

[How]
Inline these functions, keeping the same functionality.

This is not a functional change.

The functions disable_i2c_hw_engine and release_engine_dce_hw were
pulled into their respective callers.

The most interesting part of this change is the acquire functions.
dce_i2c_hw_engine_acquire_engine was pulled into
dce_i2c_engine_acquire_hw, and dce_i2c_engine_acquire_hw was pulled
into acquire_i2c_hw_engine.

Some notes to show that this change is not functional:
-Failure conditions in any function resulted in a cascade of calls that
ended in a 'return NULL'.
Those are replaced with a direct 'return NULL'.

-The variable result is the one from dce_i2c_hw_engine_acquire_engine.
The boolean result used as part of return logic was removed.

-As the second half of dce_i2c_hw_engine_acquire_engine is only executed
if that function is returning true and therefore exiting the do-while
loop in dce_i2c_engine_acquire_hw, those lines were moved outside
of the loop.

Signed-off-by: David Francis <David.Francis@amd.com>
Acked-by: Leo Li <sunpeng.li@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 drivers/gpu/drm/amd/display/dc/dce/dce_i2c_hw.c | 111 ++++++++----------------
 1 file changed, 34 insertions(+), 77 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/dc/dce/dce_i2c_hw.c b/drivers/gpu/drm/amd/display/dc/dce/dce_i2c_hw.c
index 2800d3f..40f2d6e 100644
--- a/drivers/gpu/drm/amd/display/dc/dce/dce_i2c_hw.c
+++ b/drivers/gpu/drm/amd/display/dc/dce/dce_i2c_hw.c
@@ -36,12 +36,6 @@
 #define FN(reg_name, field_name) \
 	dce_i2c_hw->shifts->field_name, dce_i2c_hw->masks->field_name
 
-static void disable_i2c_hw_engine(
-	struct dce_i2c_hw *dce_i2c_hw)
-{
-	REG_UPDATE_N(SETUP, 1, FN(SETUP, DC_I2C_DDC1_ENABLE), 0);
-}
-
 static void execute_transaction(
 	struct dce_i2c_hw *dce_i2c_hw)
 {
@@ -348,60 +342,40 @@ static void release_engine(
 		REG_UPDATE(DC_I2C_CONTROL, DC_I2C_SW_STATUS_RESET, 1);
 	/* HW I2c engine - clock gating feature */
 	if (!dce_i2c_hw->engine_keep_power_up_count)
-		disable_i2c_hw_engine(dce_i2c_hw);
+		REG_UPDATE_N(SETUP, 1, FN(SETUP, DC_I2C_DDC1_ENABLE), 0);
 
 }
 
-static void release_engine_dce_hw(
+struct dce_i2c_hw *acquire_i2c_hw_engine(
 	struct resource_pool *pool,
-	struct dce_i2c_hw *dce_i2c_hw)
-{
-	pool->i2c_hw_buffer_in_use = false;
-
-	release_engine(dce_i2c_hw);
-	dal_ddc_close(dce_i2c_hw->ddc);
-
-	dce_i2c_hw->ddc = NULL;
-}
-
-bool dce_i2c_hw_engine_acquire_engine(
-	struct dce_i2c_hw *dce_i2c_hw,
 	struct ddc *ddc)
 {
-
+	uint32_t counter = 0;
 	enum gpio_result result;
 	uint32_t current_speed;
+	struct dce_i2c_hw *dce_i2c_hw = NULL;
 
-	result = dal_ddc_open(ddc, GPIO_MODE_HARDWARE,
-		GPIO_DDC_CONFIG_TYPE_MODE_I2C);
-
-	if (result != GPIO_RESULT_OK)
-		return false;
-
-	dce_i2c_hw->ddc = ddc;
-
-
-	current_speed = get_speed(dce_i2c_hw);
+	if (!ddc)
+		return NULL;
 
-	if (current_speed)
-		dce_i2c_hw->original_speed = current_speed;
+	if (ddc->hw_info.hw_supported) {
+		enum gpio_ddc_line line = dal_ddc_get_line(ddc);
 
-	return true;
-}
+		if (line < pool->pipe_count)
+			dce_i2c_hw = pool->hw_i2cs[line];
+	}
 
-bool dce_i2c_engine_acquire_hw(
-	struct dce_i2c_hw *dce_i2c_hw,
-	struct ddc *ddc_handle)
-{
+	if (!dce_i2c_hw)
+		return NULL;
 
-	uint32_t counter = 0;
-	bool result;
+	if (pool->i2c_hw_buffer_in_use)
+		return NULL;
 
 	do {
-		result = dce_i2c_hw_engine_acquire_engine(
-				dce_i2c_hw, ddc_handle);
+		result = dal_ddc_open(ddc, GPIO_MODE_HARDWARE,
+			GPIO_DDC_CONFIG_TYPE_MODE_I2C);
 
-		if (result)
+		if (result == GPIO_RESULT_OK)
 			break;
 
 		/* i2c_engine is busy by VBios, lets wait and retry */
@@ -411,45 +385,23 @@ bool dce_i2c_engine_acquire_hw(
 		++counter;
 	} while (counter < 2);
 
-	if (result) {
-		if (!setup_engine(dce_i2c_hw)) {
-			release_engine(dce_i2c_hw);
-			result = false;
-		}
-	}
-
-	return result;
-}
-
-struct dce_i2c_hw *acquire_i2c_hw_engine(
-	struct resource_pool *pool,
-	struct ddc *ddc)
-{
-
-	struct dce_i2c_hw *engine = NULL;
-
-	if (!ddc)
+	if (result != GPIO_RESULT_OK)
 		return NULL;
 
-	if (ddc->hw_info.hw_supported) {
-		enum gpio_ddc_line line = dal_ddc_get_line(ddc);
-
-		if (line < pool->pipe_count)
-			engine = pool->hw_i2cs[line];
-	}
+	dce_i2c_hw->ddc = ddc;
 
-	if (!engine)
-		return NULL;
+	current_speed = get_speed(dce_i2c_hw);
 
+	if (current_speed)
+		dce_i2c_hw->original_speed = current_speed;
 
-	if (!pool->i2c_hw_buffer_in_use &&
-			dce_i2c_engine_acquire_hw(engine, ddc)) {
-		pool->i2c_hw_buffer_in_use = true;
-		return engine;
+	if (!setup_engine(dce_i2c_hw)) {
+		release_engine(dce_i2c_hw);
+		return NULL;
 	}
 
-
-	return NULL;
+	pool->i2c_hw_buffer_in_use = true;
+	return dce_i2c_hw;
 }
 
 enum i2c_channel_operation_result dce_i2c_hw_engine_wait_on_operation_result(
@@ -619,7 +571,12 @@ bool dce_i2c_submit_command_hw(
 		++index_of_payload;
 	}
 
-	release_engine_dce_hw(pool, dce_i2c_hw);
+	pool->i2c_hw_buffer_in_use = false;
+
+	release_engine(dce_i2c_hw);
+	dal_ddc_close(dce_i2c_hw->ddc);
+
+	dce_i2c_hw->ddc = NULL;
 
 	return result;
 }
-- 
2.7.4