]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/amd/display/dc/gpio/hw_hpd.c
drm/amd/dc: Add dc display driver (v2)
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / amd / display / dc / gpio / hw_hpd.c
1 /*
2 * Copyright 2012-15 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: AMD
23 *
24 */
25
26 #include "dm_services.h"
27
28 #include "include/gpio_types.h"
29 #include "hw_gpio.h"
30 #include "hw_hpd.h"
31
32 #include "reg_helper.h"
33 #include "hpd_regs.h"
34
35 #undef FN
36 #define FN(reg_name, field_name) \
37 hpd->shifts->field_name, hpd->masks->field_name
38
39 #define CTX \
40 hpd->base.base.ctx
41 #define REG(reg)\
42 (hpd->regs->reg)
43
44 static bool dal_hw_hpd_construct(
45 struct hw_hpd *pin,
46 enum gpio_id id,
47 uint32_t en,
48 struct dc_context *ctx)
49 {
50 if (!dal_hw_gpio_construct(&pin->base, id, en, ctx))
51 return false;
52 return true;
53 }
54
55 static void dal_hw_hpd_destruct(
56 struct hw_hpd *pin)
57 {
58 dal_hw_gpio_destruct(&pin->base);
59 }
60
61
62 static void destruct(
63 struct hw_hpd *hpd)
64 {
65 dal_hw_hpd_destruct(hpd);
66 }
67
68 static 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 dm_free(hpd);
76
77 *ptr = NULL;
78 }
79
80 static 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 /* in Interrupt mode we ask for SENSE bit */
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 /* in any other modes, operate as normal GPIO */
99
100 return dal_hw_gpio_get_value(ptr, value);
101 }
102
103 static 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
119 static 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
129 static bool construct(
130 struct hw_hpd *hpd,
131 enum gpio_id id,
132 uint32_t en,
133 struct dc_context *ctx)
134 {
135 if (id != GPIO_ID_HPD) {
136 ASSERT_CRITICAL(false);
137 return false;
138 }
139
140 if ((en < GPIO_HPD_MIN) || (en > GPIO_HPD_MAX)) {
141 ASSERT_CRITICAL(false);
142 return false;
143 }
144
145 if (!dal_hw_hpd_construct(hpd, id, en, ctx)) {
146 ASSERT_CRITICAL(false);
147 return false;
148 }
149
150 hpd->base.base.funcs = &funcs;
151
152 return true;
153 }
154
155 struct hw_gpio_pin *dal_hw_hpd_create(
156 struct dc_context *ctx,
157 enum gpio_id id,
158 uint32_t en)
159 {
160 struct hw_hpd *hpd = dm_alloc(sizeof(struct hw_hpd));
161
162 if (!hpd) {
163 ASSERT_CRITICAL(false);
164 return NULL;
165 }
166
167 if (construct(hpd, id, en, ctx))
168 return &hpd->base.base;
169
170 ASSERT_CRITICAL(false);
171
172 dm_free(hpd);
173
174 return NULL;
175 }