summaryrefslogtreecommitdiff
path: root/driver/product/kernel/drivers/gpu/drm/pl111/pl111_drm_connector.c
blob: c7c3a226a868bba5f381e6291364fec5c385b989 (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
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
/*
 *
 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 *
 * A copy of the licence is included with the program, and can also be obtained
 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 */



/**
 * pl111_drm_connector.c
 * Implementation of the connector functions for PL111 DRM
 */
#include <linux/amba/bus.h>
#include <linux/amba/clcd.h>
#include <linux/version.h>
#include <linux/shmem_fs.h>
#include <linux/dma-buf.h>
#include <linux/module.h>

#include <drm/drmP.h>
#include <drm/drm_crtc_helper.h>

#include "pl111_drm.h"


static struct {
	int w, h, type;
} pl111_drm_modes[] = {
	{ 640, 480,  DRM_MODE_TYPE_PREFERRED},
	{ 800, 600,  0},
	{1024, 768,  0},
	{  -1,  -1, -1}
};

void pl111_connector_destroy(struct drm_connector *connector)
{
	struct pl111_drm_connector *pl111_connector =
				PL111_CONNECTOR_FROM_CONNECTOR(connector);

	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);

	drm_sysfs_connector_remove(connector);
	drm_connector_cleanup(connector);
	kfree(pl111_connector);
}

enum drm_connector_status pl111_connector_detect(struct drm_connector
							*connector, bool force)
{
	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);
	return connector_status_connected;
}

void pl111_connector_dpms(struct drm_connector *connector, int mode)
{
	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);
}

struct drm_encoder *
pl111_connector_helper_best_encoder(struct drm_connector *connector)
{
	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);

	if (connector->encoder != NULL) {
		return connector->encoder; /* Return attached encoder */
	} else {
		/*
		 * If there is no attached encoder we choose the best candidate
		 * from the list.
		 * For PL111 there is only one encoder so we return the first
		 * one we find.
		 * Other h/w would require a suitable criterion below.
		 */
		struct drm_encoder *encoder = NULL;
		struct drm_device *dev = connector->dev;

		list_for_each_entry(encoder, &dev->mode_config.encoder_list,
					head) {
			if (1) { /* criterion ? */
				break;
			}
		}
		return encoder; /* return best candidate encoder */
	}
}

int pl111_connector_helper_get_modes(struct drm_connector *connector)
{
	int i = 0;
	int count = 0;

	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);

	while (pl111_drm_modes[i].w != -1) {
		struct drm_display_mode *mode =
				drm_mode_find_dmt(connector->dev,
						pl111_drm_modes[i].w,
						pl111_drm_modes[i].h,
						60
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0))
						, false
#endif
						);

		if (mode != NULL) {
			mode->type |= pl111_drm_modes[i].type;
			drm_mode_probed_add(connector, mode);
			count++;
		}

		i++;
	}

	DRM_DEBUG_KMS("found %d modes\n", count);

	return count;
}

int pl111_connector_helper_mode_valid(struct drm_connector *connector,
					struct drm_display_mode *mode)
{
	DRM_DEBUG_KMS("DRM %s on connector=%p\n", __func__, connector);
	return MODE_OK;
}

const struct drm_connector_funcs connector_funcs = {
	.fill_modes = drm_helper_probe_single_connector_modes,
	.destroy = pl111_connector_destroy,
	.detect = pl111_connector_detect,
	.dpms = pl111_connector_dpms,
};

const struct drm_connector_helper_funcs connector_helper_funcs = {
	.get_modes = pl111_connector_helper_get_modes,
	.mode_valid = pl111_connector_helper_mode_valid,
	.best_encoder = pl111_connector_helper_best_encoder,
};

struct pl111_drm_connector *pl111_connector_create(struct drm_device *dev)
{
	struct pl111_drm_connector *pl111_connector;

	pl111_connector = kzalloc(sizeof(struct pl111_drm_connector),
					GFP_KERNEL);

	if (pl111_connector == NULL) {
		pr_err("Failed to allocated pl111_drm_connector\n");
		return NULL;
	}

	drm_connector_init(dev, &pl111_connector->connector, &connector_funcs,
				DRM_MODE_CONNECTOR_DVII);

	drm_connector_helper_add(&pl111_connector->connector,
					&connector_helper_funcs);

	drm_sysfs_connector_add(&pl111_connector->connector);

	return pl111_connector;
}