summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/msm/ekms/edrm_connector.c
blob: 1a9a930a3974569f30bada54f46dc5871732b17e (plain)
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
/* Copyright (c) 2019, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include "edrm_connector.h"

struct edrm_connector {
	struct drm_connector base;
	struct drm_encoder *encoder;
	struct msm_edrm_display *display;
};

#define to_edrm_connector(x) container_of(x, struct edrm_connector, base)

static enum drm_connector_status
edrm_connector_detect(struct drm_connector *conn, bool force)
{
	return connector_status_connected;
}

static int
edrm_connector_get_modes(struct drm_connector *connector)
{
	struct edrm_connector *edrm_conn = to_edrm_connector(connector);
	struct drm_display_mode *m;

	m = drm_mode_duplicate(connector->dev, &edrm_conn->display->mode);
	if (m == NULL) {
		pr_err("edrm drm_mode_duplicate failed\n");
		return 0;
	}
	drm_mode_set_name(m);
	drm_mode_probed_add(connector, m);

	return 1;
}

static enum drm_mode_status
edrm_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode)
{
	return MODE_OK;
}

static struct drm_encoder *
edrm_connector_best_encoder(struct drm_connector *connector)
{
	struct edrm_connector *edrm_conn = to_edrm_connector(connector);

	return edrm_conn->encoder;
}

void edrm_connector_destroy(struct drm_connector *connector)
{
	struct edrm_connector *edrm_conn = to_edrm_connector(connector);

	drm_connector_unregister(connector);
	drm_connector_cleanup(connector);
	kfree(edrm_conn);
}

static const struct drm_connector_helper_funcs edrm_connector_helper_funcs = {
	.get_modes =    edrm_connector_get_modes,
	.mode_valid =   edrm_mode_valid,
	.best_encoder = edrm_connector_best_encoder,
};

static const struct drm_connector_funcs edrm_connector_funcs = {
	.fill_modes = drm_helper_probe_single_connector_modes,
	.detect = edrm_connector_detect,
	.destroy = edrm_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,
};

struct drm_connector *edrm_connector_init(struct drm_device *dev,
			struct drm_encoder *encoder,
			struct msm_edrm_display *display)
{
	struct edrm_connector *edrm_conn;
	struct drm_connector *connector;
	int ret;

	edrm_conn = kzalloc(sizeof(*edrm_conn), GFP_KERNEL);
	if (!edrm_conn)
		return ERR_PTR(-ENOMEM);
	connector = &edrm_conn->base;

	ret = drm_connector_init(dev, connector,
			&edrm_connector_funcs,
			display->connector_type);
	if (ret) {
		pr_err("edrm drm_connector_init failed\n");
		goto fail;
	}

	drm_connector_helper_add(connector, &edrm_connector_helper_funcs);

	edrm_conn->display = display;
	edrm_conn->encoder = encoder;

	ret = drm_connector_register(&edrm_conn->base);
	if (ret) {
		pr_err("failed to register drm connector, %d\n", ret);
		goto fail;
	}

	ret = drm_mode_connector_attach_encoder(&edrm_conn->base, encoder);
	if (ret) {
		pr_err("failed to attach encoder to connector, %d\n", ret);
		goto fail;
	}

	return connector;
fail:
	kfree(edrm_conn);
	return ERR_PTR(ret);

}