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#include <linux/slab.h>
27
28#include "dm_services.h"
29
30#include "include/gpio_interface.h"
31#include "include/gpio_types.h"
32#include "hw_gpio.h"
33#include "hw_hpd.h"
34
35#include "reg_helper.h"
36#include "hpd_regs.h"
37
38#undef FN
39#define FN(reg_name, field_name) \
40 hpd->shifts->field_name, hpd->masks->field_name
41
42#define CTX \
43 hpd->base.base.ctx
44#define REG(reg)\
45 (hpd->regs->reg)
46
47struct gpio;
48
49static void dal_hw_hpd_destruct(
50 struct hw_hpd *pin)
51{
52 dal_hw_gpio_destruct(&pin->base);
53}
54
55static void dal_hw_hpd_destroy(
56 struct hw_gpio_pin **ptr)
57{
58 struct hw_hpd *hpd = HW_HPD_FROM_BASE(*ptr);
59
60 dal_hw_hpd_destruct(hpd);
61
62 kfree(hpd);
63
64 *ptr = NULL;
65}
66
67static enum gpio_result get_value(
68 const struct hw_gpio_pin *ptr,
69 uint32_t *value)
70{
71 struct hw_hpd *hpd = HW_HPD_FROM_BASE(ptr);
72 uint32_t hpd_delayed = 0;
73
74
75
76 if (ptr->mode == GPIO_MODE_INTERRUPT) {
77
78 REG_GET(int_status,
79 DC_HPD_SENSE_DELAYED, &hpd_delayed);
80
81 *value = hpd_delayed;
82 return GPIO_RESULT_OK;
83 }
84
85
86
87 return dal_hw_gpio_get_value(ptr, value);
88}
89
90static enum gpio_result set_config(
91 struct hw_gpio_pin *ptr,
92 const struct gpio_config_data *config_data)
93{
94 struct hw_hpd *hpd = HW_HPD_FROM_BASE(ptr);
95
96 if (!config_data)
97 return GPIO_RESULT_INVALID_DATA;
98
99 REG_UPDATE_2(toggle_filt_cntl,
100 DC_HPD_CONNECT_INT_DELAY, config_data->config.hpd.delay_on_connect / 10,
101 DC_HPD_DISCONNECT_INT_DELAY, config_data->config.hpd.delay_on_disconnect / 10);
102
103 return GPIO_RESULT_OK;
104}
105
106static const struct hw_gpio_pin_funcs funcs = {
107 .destroy = dal_hw_hpd_destroy,
108 .open = dal_hw_gpio_open,
109 .get_value = get_value,
110 .set_value = dal_hw_gpio_set_value,
111 .set_config = set_config,
112 .change_mode = dal_hw_gpio_change_mode,
113 .close = dal_hw_gpio_close,
114};
115
116static void dal_hw_hpd_construct(
117 struct hw_hpd *pin,
118 enum gpio_id id,
119 uint32_t en,
120 struct dc_context *ctx)
121{
122 dal_hw_gpio_construct(&pin->base, id, en, ctx);
123 pin->base.base.funcs = &funcs;
124}
125
126void dal_hw_hpd_init(
127 struct hw_hpd **hw_hpd,
128 struct dc_context *ctx,
129 enum gpio_id id,
130 uint32_t en)
131{
132 if ((en < GPIO_DDC_LINE_MIN) || (en > GPIO_DDC_LINE_MAX)) {
133 ASSERT_CRITICAL(false);
134 *hw_hpd = NULL;
135 }
136
137 *hw_hpd = kzalloc(sizeof(struct hw_hpd), GFP_KERNEL);
138 if (!*hw_hpd) {
139 ASSERT_CRITICAL(false);
140 return;
141 }
142
143 dal_hw_hpd_construct(*hw_hpd, id, en, ctx);
144}
145
146struct hw_gpio_pin *dal_hw_hpd_get_pin(struct gpio *gpio)
147{
148 struct hw_hpd *hw_hpd = dal_gpio_get_hpd(gpio);
149
150 return &hw_hpd->base.base;
151}
152