-
Notifications
You must be signed in to change notification settings - Fork 11
/
ms912x_connector.c
80 lines (71 loc) · 2.18 KB
/
ms912x_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
#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_connector.h>
#include <drm/drm_edid.h>
#include <drm/drm_modeset_helper_vtables.h>
#include <drm/drm_probe_helper.h>
#include "ms912x.h"
static int ms912x_read_edid(void *data, u8 *buf, unsigned int block, size_t len)
{
struct ms912x_device *ms912x = data;
int offset = block * EDID_LENGTH;
int i, ret;
for (i = 0; i < len; i++) {
u16 address = 0xc000 + offset + i;
ret = ms912x_read_byte(ms912x, address);
if (ret < 0)
return ret;
buf[i] = ret;
}
return 0;
}
static int ms912x_connector_get_modes(struct drm_connector *connector)
{
int ret;
struct ms912x_device *ms912x = to_ms912x(connector->dev);
const struct drm_edid *edid;
edid = drm_edid_read_custom(connector, ms912x_read_edid, ms912x);
if (!edid)
return 0;
ret = drm_edid_connector_update(connector, edid);
if (ret < 0) {
ret = 0;
goto edid_free;
}
ret = drm_edid_connector_add_modes(connector);
edid_free:
drm_edid_free(edid);
return ret;
}
static enum drm_connector_status ms912x_detect(struct drm_connector *connector,
bool force)
{
struct ms912x_device *ms912x = to_ms912x(connector->dev);
int status = ms912x_read_byte(ms912x, 0x32);
if (status < 0)
return connector_status_unknown;
return status == 1 ? connector_status_connected :
connector_status_disconnected;
}
static const struct drm_connector_helper_funcs ms912x_connector_helper_funcs = {
.get_modes = ms912x_connector_get_modes,
};
static const struct drm_connector_funcs ms912x_connector_funcs = {
.fill_modes = drm_helper_probe_single_connector_modes,
.destroy = drm_connector_cleanup,
.detect = ms912x_detect,
.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 ms912x_connector_init(struct ms912x_device *ms912x)
{
int ret;
drm_connector_helper_add(&ms912x->connector,
&ms912x_connector_helper_funcs);
ret = drm_connector_init(&ms912x->drm, &ms912x->connector,
&ms912x_connector_funcs,
DRM_MODE_CONNECTOR_HDMIA);
ms912x->connector.polled =
DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT;
return ret;
}