-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathevdi_connector.c
199 lines (170 loc) · 5.57 KB
/
evdi_connector.c
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2012 Red Hat
* Copyright (c) 2015 - 2020 DisplayLink (UK) Ltd.
*
* Based on parts on udlfb.c:
* Copyright (C) 2009 its respective authors
*
* This file is subject to the terms and conditions of the GNU General Public
* License v2. See the file COPYING in the main directory of this archive for
* more details.
*/
#include <linux/version.h>
#include <drm/drm_crtc.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_atomic_helper.h>
#include "evdi_drm_drv.h"
#if KERNEL_VERSION(5, 1, 0) <= LINUX_VERSION_CODE || defined(EL8)
#include <drm/drm_probe_helper.h>
#endif
/*
* dummy connector to just get EDID,
* all EVDI appear to have a DVI-D
*/
static int evdi_get_modes(struct drm_connector *connector)
{
struct evdi_device *evdi = connector->dev->dev_private;
int ret = 0;
struct drm_display_mode *new_mode;
EVDI_INFO("GET MODES");
new_mode = drm_mode_create(connector->dev);
strncpy(new_mode->name, "Lindroid", 8);
new_mode->clock = evdi->painter->height * evdi->painter->width * evdi->painter->refresh_rate / 1000;
new_mode->hdisplay = evdi->painter->width;
new_mode->hsync_start = evdi->painter->width;
new_mode->hsync_end = evdi->painter->width;
new_mode->htotal = evdi->painter->width;
new_mode->vdisplay = evdi->painter->height;
new_mode->vsync_start = evdi->painter->height;
new_mode->vsync_end = evdi->painter->height;
new_mode->vtotal = evdi->painter->height;
new_mode->flags = 0;
new_mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
drm_mode_probed_add(connector, new_mode);
if (ret) {
EVDI_ERROR("Failed to set edid property! error: %d", ret);
goto err;
}
EVDI_INFO("(card%d) Edid property set", evdi->dev_index);
err:
return ret;
}
static bool is_lowest_frequency_mode_of_given_resolution(
struct drm_connector *connector, struct drm_display_mode *mode)
{
struct drm_display_mode *modeptr;
list_for_each_entry(modeptr, &(connector->modes), head) {
if (modeptr->hdisplay == mode->hdisplay &&
modeptr->vdisplay == mode->vdisplay &&
drm_mode_vrefresh(modeptr) < drm_mode_vrefresh(mode)) {
return false;
}
}
return true;
}
static enum drm_mode_status evdi_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode)
{
struct evdi_device *evdi = connector->dev->dev_private;
uint32_t area_limit = mode->hdisplay * mode->vdisplay;
uint32_t mode_limit = area_limit * drm_mode_vrefresh(mode);
if (evdi->pixel_per_second_limit == 0)
return MODE_OK;
if (area_limit > evdi->pixel_area_limit) {
EVDI_WARN(
"(card%d) Mode %dx%d@%d rejected. Reason: mode area too big\n",
evdi->dev_index,
mode->hdisplay,
mode->vdisplay,
drm_mode_vrefresh(mode));
return MODE_BAD;
}
if (mode_limit <= evdi->pixel_per_second_limit)
return MODE_OK;
if (is_lowest_frequency_mode_of_given_resolution(connector, mode)) {
EVDI_WARN(
"(card%d) Mode exceeds maximal frame rate for the device. Mode %dx%d@%d may have a limited output frame rate",
evdi->dev_index,
mode->hdisplay,
mode->vdisplay,
drm_mode_vrefresh(mode));
return MODE_OK;
}
EVDI_WARN(
"(card%d) Mode %dx%d@%d rejected. Reason: mode pixel clock too high\n",
evdi->dev_index,
mode->hdisplay,
mode->vdisplay,
drm_mode_vrefresh(mode));
return MODE_BAD;
}
static enum drm_connector_status
evdi_detect(struct drm_connector *connector, __always_unused bool force)
{
struct evdi_device *evdi = connector->dev->dev_private;
EVDI_CHECKPT();
if (evdi_painter_is_connected(evdi->painter)) {
EVDI_INFO("(card%d) Connector state: connected\n",
evdi->dev_index);
return connector_status_connected;
}
EVDI_VERBOSE("(card%d) Connector state: disconnected\n",
evdi->dev_index);
return connector_status_disconnected;
}
static void evdi_connector_destroy(struct drm_connector *connector)
{
drm_connector_unregister(connector);
drm_connector_cleanup(connector);
kfree(connector);
}
static struct drm_encoder *evdi_best_encoder(struct drm_connector *connector)
{
#if KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE || defined(EL8)
struct drm_encoder *encoder;
drm_connector_for_each_possible_encoder(connector, encoder) {
return encoder;
}
return NULL;
#else
return drm_encoder_find(connector->dev,
NULL,
connector->encoder_ids[0]);
#endif
}
static struct drm_connector_helper_funcs evdi_connector_helper_funcs = {
.get_modes = evdi_get_modes,
.mode_valid = evdi_mode_valid,
.best_encoder = evdi_best_encoder,
};
static const struct drm_connector_funcs evdi_connector_funcs = {
.detect = evdi_detect,
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = evdi_connector_destroy,
.reset = drm_atomic_helper_connector_reset,
.atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state
};
int evdi_connector_init(struct drm_device *dev, struct drm_encoder *encoder)
{
struct drm_connector *connector;
struct evdi_device *evdi = dev->dev_private;
EVDI_INFO("Init connector");
connector = kzalloc(sizeof(struct drm_connector), GFP_KERNEL);
if (!connector)
return -ENOMEM;
/* TODO: Initialize connector with actual connector type */
drm_connector_init(dev, connector, &evdi_connector_funcs,
DRM_MODE_CONNECTOR_DisplayPort);
drm_connector_helper_add(connector, &evdi_connector_helper_funcs);
connector->polled = DRM_CONNECTOR_POLL_HPD;
drm_connector_register(connector);
evdi->conn = connector;
#if KERNEL_VERSION(4, 19, 0) <= LINUX_VERSION_CODE || defined(EL8)
drm_connector_attach_encoder(connector, encoder);
#else
drm_mode_connector_attach_encoder(connector, encoder);
#endif
return 0;
}