hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/gpu/drm/amd/display/dc/gpio/gpio_service.c
....@@ -27,6 +27,8 @@
2727 * Pre-requisites: headers required by header of this unit
2828 */
2929
30
+#include <linux/slab.h>
31
+
3032 #include "dm_services.h"
3133 #include "include/gpio_interface.h"
3234 #include "include/gpio_service_interface.h"
....@@ -51,12 +53,11 @@
5153 */
5254
5355 struct gpio_service *dal_gpio_service_create(
54
- enum dce_version dce_version_major,
55
- enum dce_version dce_version_minor,
56
+ enum dce_version dce_version,
57
+ enum dce_environment dce_environment,
5658 struct dc_context *ctx)
5759 {
5860 struct gpio_service *service;
59
-
6061 uint32_t index_of_id;
6162
6263 service = kzalloc(sizeof(struct gpio_service), GFP_KERNEL);
....@@ -66,56 +67,45 @@
6667 return NULL;
6768 }
6869
69
- if (!dal_hw_translate_init(&service->translate, dce_version_major,
70
- dce_version_minor)) {
70
+ if (!dal_hw_translate_init(&service->translate, dce_version,
71
+ dce_environment)) {
7172 BREAK_TO_DEBUGGER();
7273 goto failure_1;
7374 }
7475
75
- if (!dal_hw_factory_init(&service->factory, dce_version_major,
76
- dce_version_minor)) {
76
+ if (!dal_hw_factory_init(&service->factory, dce_version,
77
+ dce_environment)) {
7778 BREAK_TO_DEBUGGER();
7879 goto failure_1;
7980 }
8081
81
- /* allocate and initialize business storage */
82
+ /* allocate and initialize busyness storage */
8283 {
83
- const uint32_t bits_per_uint = sizeof(uint32_t) << 3;
84
-
8584 index_of_id = 0;
8685 service->ctx = ctx;
8786
8887 do {
8988 uint32_t number_of_bits =
9089 service->factory.number_of_pins[index_of_id];
90
+ uint32_t i = 0;
9191
92
- uint32_t number_of_uints =
93
- (number_of_bits + bits_per_uint - 1) /
94
- bits_per_uint;
92
+ if (number_of_bits) {
93
+ service->busyness[index_of_id] =
94
+ kcalloc(number_of_bits, sizeof(char),
95
+ GFP_KERNEL);
9596
96
- uint32_t *slot;
97
-
98
- if (number_of_bits) {
99
- uint32_t index_of_uint = 0;
100
-
101
- slot = kcalloc(number_of_uints,
102
- sizeof(uint32_t),
103
- GFP_KERNEL);
104
-
105
- if (!slot) {
97
+ if (!service->busyness[index_of_id]) {
10698 BREAK_TO_DEBUGGER();
10799 goto failure_2;
108100 }
109101
110102 do {
111
- slot[index_of_uint] = 0;
112
-
113
- ++index_of_uint;
114
- } while (index_of_uint < number_of_uints);
115
- } else
116
- slot = NULL;
117
-
118
- service->busyness[index_of_id] = slot;
103
+ service->busyness[index_of_id][i] = 0;
104
+ ++i;
105
+ } while (i < number_of_bits);
106
+ } else {
107
+ service->busyness[index_of_id] = NULL;
108
+ }
119109
120110 ++index_of_id;
121111 } while (index_of_id < GPIO_ID_COUNT);
....@@ -125,13 +115,8 @@
125115
126116 failure_2:
127117 while (index_of_id) {
128
- uint32_t *slot;
129
-
130118 --index_of_id;
131
-
132
- slot = service->busyness[index_of_id];
133
-
134
- kfree(slot);
119
+ kfree(service->busyness[index_of_id]);
135120 }
136121
137122 failure_1:
....@@ -156,6 +141,57 @@
156141 return dal_gpio_create_irq(service, id, en);
157142 }
158143
144
+struct gpio *dal_gpio_service_create_generic_mux(
145
+ struct gpio_service *service,
146
+ uint32_t offset,
147
+ uint32_t mask)
148
+{
149
+ enum gpio_id id;
150
+ uint32_t en;
151
+ struct gpio *generic;
152
+
153
+ if (!service->translate.funcs->offset_to_id(offset, mask, &id, &en)) {
154
+ ASSERT_CRITICAL(false);
155
+ return NULL;
156
+ }
157
+
158
+ generic = dal_gpio_create(
159
+ service, id, en, GPIO_PIN_OUTPUT_STATE_DEFAULT);
160
+
161
+ return generic;
162
+}
163
+
164
+void dal_gpio_destroy_generic_mux(
165
+ struct gpio **mux)
166
+{
167
+ if (!mux || !*mux) {
168
+ ASSERT_CRITICAL(false);
169
+ return;
170
+ }
171
+
172
+ dal_gpio_destroy(mux);
173
+ kfree(*mux);
174
+
175
+ *mux = NULL;
176
+}
177
+
178
+struct gpio_pin_info dal_gpio_get_generic_pin_info(
179
+ struct gpio_service *service,
180
+ enum gpio_id id,
181
+ uint32_t en)
182
+{
183
+ struct gpio_pin_info pin;
184
+
185
+ if (service->translate.funcs->id_to_offset) {
186
+ service->translate.funcs->id_to_offset(id, en, &pin);
187
+ } else {
188
+ pin.mask = 0xFFFFFFFF;
189
+ pin.offset = 0xFFFFFFFF;
190
+ }
191
+
192
+ return pin;
193
+}
194
+
159195 void dal_gpio_service_destroy(
160196 struct gpio_service **ptr)
161197 {
....@@ -169,9 +205,7 @@
169205 uint32_t index_of_id = 0;
170206
171207 do {
172
- uint32_t *slot = (*ptr)->busyness[index_of_id];
173
-
174
- kfree(slot);
208
+ kfree((*ptr)->busyness[index_of_id]);
175209
176210 ++index_of_id;
177211 } while (index_of_id < GPIO_ID_COUNT);
....@@ -180,6 +214,21 @@
180214 kfree(*ptr);
181215
182216 *ptr = NULL;
217
+}
218
+
219
+enum gpio_result dal_mux_setup_config(
220
+ struct gpio *mux,
221
+ struct gpio_generic_mux_config *config)
222
+{
223
+ struct gpio_config_data config_data;
224
+
225
+ if (!config)
226
+ return GPIO_RESULT_INVALID_DATA;
227
+
228
+ config_data.config.generic_mux = *config;
229
+ config_data.type = GPIO_CONFIG_TYPE_GENERIC_MUX;
230
+
231
+ return dal_gpio_set_config(mux, &config_data);
183232 }
184233
185234 /*
....@@ -192,11 +241,7 @@
192241 enum gpio_id id,
193242 uint32_t en)
194243 {
195
- const uint32_t bits_per_uint = sizeof(uint32_t) << 3;
196
-
197
- const uint32_t *slot = service->busyness[id] + (en / bits_per_uint);
198
-
199
- return 0 != (*slot & (1 << (en % bits_per_uint)));
244
+ return service->busyness[id][en];
200245 }
201246
202247 static void set_pin_busy(
....@@ -204,10 +249,7 @@
204249 enum gpio_id id,
205250 uint32_t en)
206251 {
207
- const uint32_t bits_per_uint = sizeof(uint32_t) << 3;
208
-
209
- service->busyness[id][en / bits_per_uint] |=
210
- (1 << (en % bits_per_uint));
252
+ service->busyness[id][en] = true;
211253 }
212254
213255 static void set_pin_free(
....@@ -215,20 +257,47 @@
215257 enum gpio_id id,
216258 uint32_t en)
217259 {
218
- const uint32_t bits_per_uint = sizeof(uint32_t) << 3;
260
+ service->busyness[id][en] = false;
261
+}
219262
220
- service->busyness[id][en / bits_per_uint] &=
221
- ~(1 << (en % bits_per_uint));
263
+enum gpio_result dal_gpio_service_lock(
264
+ struct gpio_service *service,
265
+ enum gpio_id id,
266
+ uint32_t en)
267
+{
268
+ if (!service->busyness[id]) {
269
+ ASSERT_CRITICAL(false);
270
+ return GPIO_RESULT_OPEN_FAILED;
271
+ }
272
+
273
+ set_pin_busy(service, id, en);
274
+ return GPIO_RESULT_OK;
275
+}
276
+
277
+enum gpio_result dal_gpio_service_unlock(
278
+ struct gpio_service *service,
279
+ enum gpio_id id,
280
+ uint32_t en)
281
+{
282
+ if (!service->busyness[id]) {
283
+ ASSERT_CRITICAL(false);
284
+ return GPIO_RESULT_OPEN_FAILED;
285
+ }
286
+
287
+ set_pin_free(service, id, en);
288
+ return GPIO_RESULT_OK;
222289 }
223290
224291 enum gpio_result dal_gpio_service_open(
225
- struct gpio_service *service,
226
- enum gpio_id id,
227
- uint32_t en,
228
- enum gpio_mode mode,
229
- struct hw_gpio_pin **ptr)
292
+ struct gpio *gpio)
230293 {
231
- struct hw_gpio_pin *pin;
294
+ struct gpio_service *service = gpio->service;
295
+ enum gpio_id id = gpio->id;
296
+ uint32_t en = gpio->en;
297
+ enum gpio_mode mode = gpio->mode;
298
+
299
+ struct hw_gpio_pin **pin = &gpio->pin;
300
+
232301
233302 if (!service->busyness[id]) {
234303 ASSERT_CRITICAL(false);
....@@ -242,50 +311,43 @@
242311
243312 switch (id) {
244313 case GPIO_ID_DDC_DATA:
245
- pin = service->factory.funcs->create_ddc_data(
246
- service->ctx, id, en);
247
- service->factory.funcs->define_ddc_registers(pin, en);
314
+ *pin = service->factory.funcs->get_ddc_pin(gpio);
315
+ service->factory.funcs->define_ddc_registers(*pin, en);
248316 break;
249317 case GPIO_ID_DDC_CLOCK:
250
- pin = service->factory.funcs->create_ddc_clock(
251
- service->ctx, id, en);
252
- service->factory.funcs->define_ddc_registers(pin, en);
318
+ *pin = service->factory.funcs->get_ddc_pin(gpio);
319
+ service->factory.funcs->define_ddc_registers(*pin, en);
253320 break;
254321 case GPIO_ID_GENERIC:
255
- pin = service->factory.funcs->create_generic(
256
- service->ctx, id, en);
322
+ *pin = service->factory.funcs->get_generic_pin(gpio);
323
+ service->factory.funcs->define_generic_registers(*pin, en);
257324 break;
258325 case GPIO_ID_HPD:
259
- pin = service->factory.funcs->create_hpd(
260
- service->ctx, id, en);
261
- service->factory.funcs->define_hpd_registers(pin, en);
326
+ *pin = service->factory.funcs->get_hpd_pin(gpio);
327
+ service->factory.funcs->define_hpd_registers(*pin, en);
262328 break;
329
+
330
+ //TODO: gsl and sync support? create_sync and create_gsl are NULL
263331 case GPIO_ID_SYNC:
264
- pin = service->factory.funcs->create_sync(
265
- service->ctx, id, en);
266
- break;
267332 case GPIO_ID_GSL:
268
- pin = service->factory.funcs->create_gsl(
269
- service->ctx, id, en);
270333 break;
271334 default:
272335 ASSERT_CRITICAL(false);
273336 return GPIO_RESULT_NON_SPECIFIC_ERROR;
274337 }
275338
276
- if (!pin) {
339
+ if (!*pin) {
277340 ASSERT_CRITICAL(false);
278341 return GPIO_RESULT_NON_SPECIFIC_ERROR;
279342 }
280343
281
- if (!pin->funcs->open(pin, mode)) {
344
+ if (!(*pin)->funcs->open(*pin, mode)) {
282345 ASSERT_CRITICAL(false);
283
- dal_gpio_service_close(service, &pin);
346
+ dal_gpio_service_close(service, pin);
284347 return GPIO_RESULT_OPEN_FAILED;
285348 }
286349
287350 set_pin_busy(service, id, en);
288
- *ptr = pin;
289351 return GPIO_RESULT_OK;
290352 }
291353
....@@ -307,10 +369,9 @@
307369
308370 pin->funcs->close(pin);
309371
310
- pin->funcs->destroy(ptr);
372
+ *ptr = NULL;
311373 }
312374 }
313
-
314375
315376 enum dc_irq_source dal_irq_get_source(
316377 const struct gpio *irq)
....@@ -398,7 +459,6 @@
398459 return;
399460 }
400461
401
- dal_gpio_close(*irq);
402462 dal_gpio_destroy(irq);
403463 kfree(*irq);
404464