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