hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/gpu/drm/amd/display/dc/gpio/gpio_base.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
3234 #include "include/gpio_interface.h"
....@@ -61,14 +63,18 @@
6163 enum gpio_mode mode)
6264 {
6365 if (gpio->pin) {
64
- ASSERT_CRITICAL(false);
66
+ BREAK_TO_DEBUGGER();
6567 return GPIO_RESULT_ALREADY_OPENED;
6668 }
6769
70
+ // No action if allocation failed during gpio construct
71
+ if (!gpio->hw_container.ddc) {
72
+ BREAK_TO_DEBUGGER();
73
+ return GPIO_RESULT_NON_SPECIFIC_ERROR;
74
+ }
6875 gpio->mode = mode;
6976
70
- return dal_gpio_service_open(
71
- gpio->service, gpio->id, gpio->en, mode, &gpio->pin);
77
+ return dal_gpio_service_open(gpio);
7278 }
7379
7480 enum gpio_result dal_gpio_get_value(
....@@ -99,6 +105,18 @@
99105 const struct gpio *gpio)
100106 {
101107 return gpio->mode;
108
+}
109
+
110
+enum gpio_result dal_gpio_lock_pin(
111
+ struct gpio *gpio)
112
+{
113
+ return dal_gpio_service_lock(gpio->service, gpio->id, gpio->en);
114
+}
115
+
116
+enum gpio_result dal_gpio_unlock_pin(
117
+ struct gpio *gpio)
118
+{
119
+ return dal_gpio_service_unlock(gpio->service, gpio->id, gpio->en);
102120 }
103121
104122 enum gpio_result dal_gpio_change_mode(
....@@ -217,6 +235,21 @@
217235 return gpio->output_state;
218236 }
219237
238
+struct hw_ddc *dal_gpio_get_ddc(struct gpio *gpio)
239
+{
240
+ return gpio->hw_container.ddc;
241
+}
242
+
243
+struct hw_hpd *dal_gpio_get_hpd(struct gpio *gpio)
244
+{
245
+ return gpio->hw_container.hpd;
246
+}
247
+
248
+struct hw_generic *dal_gpio_get_generic(struct gpio *gpio)
249
+{
250
+ return gpio->hw_container.generic;
251
+}
252
+
220253 void dal_gpio_close(
221254 struct gpio *gpio)
222255 {
....@@ -253,6 +286,30 @@
253286 gpio->mode = GPIO_MODE_UNKNOWN;
254287 gpio->output_state = output_state;
255288
289
+ //initialize hw_container union based on id
290
+ switch (gpio->id) {
291
+ case GPIO_ID_DDC_DATA:
292
+ gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
293
+ break;
294
+ case GPIO_ID_DDC_CLOCK:
295
+ gpio->service->factory.funcs->init_ddc_data(&gpio->hw_container.ddc, service->ctx, id, en);
296
+ break;
297
+ case GPIO_ID_GENERIC:
298
+ gpio->service->factory.funcs->init_generic(&gpio->hw_container.generic, service->ctx, id, en);
299
+ break;
300
+ case GPIO_ID_HPD:
301
+ gpio->service->factory.funcs->init_hpd(&gpio->hw_container.hpd, service->ctx, id, en);
302
+ break;
303
+ // TODO: currently gpio for sync and gsl does not get created, might need it later
304
+ case GPIO_ID_SYNC:
305
+ break;
306
+ case GPIO_ID_GSL:
307
+ break;
308
+ default:
309
+ ASSERT_CRITICAL(false);
310
+ gpio->pin = NULL;
311
+ }
312
+
256313 return gpio;
257314 }
258315
....@@ -264,7 +321,32 @@
264321 return;
265322 }
266323
267
- dal_gpio_close(*gpio);
324
+ switch ((*gpio)->id) {
325
+ case GPIO_ID_DDC_DATA:
326
+ kfree((*gpio)->hw_container.ddc);
327
+ (*gpio)->hw_container.ddc = NULL;
328
+ break;
329
+ case GPIO_ID_DDC_CLOCK:
330
+ //TODO: might want to change it to init_ddc_clock
331
+ kfree((*gpio)->hw_container.ddc);
332
+ (*gpio)->hw_container.ddc = NULL;
333
+ break;
334
+ case GPIO_ID_GENERIC:
335
+ kfree((*gpio)->hw_container.generic);
336
+ (*gpio)->hw_container.generic = NULL;
337
+ break;
338
+ case GPIO_ID_HPD:
339
+ kfree((*gpio)->hw_container.hpd);
340
+ (*gpio)->hw_container.hpd = NULL;
341
+ break;
342
+ // TODO: currently gpio for sync and gsl does not get created, might need it later
343
+ case GPIO_ID_SYNC:
344
+ break;
345
+ case GPIO_ID_GSL:
346
+ break;
347
+ default:
348
+ break;
349
+ }
268350
269351 kfree(*gpio);
270352