summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/sti/sti_layer.c
blob: 899104f9d4bcf364d27d2ca9ba572b98baddb943 (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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
 * Copyright (C) STMicroelectronics SA 2014
 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
 *          Fabien Dessenne <fabien.dessenne@st.com>
 *          for STMicroelectronics.
 * License terms:  GNU General Public License (GPL), version 2
 */

#include <drm/drmP.h>
#include <drm/drm_gem_cma_helper.h>
#include <drm/drm_fb_cma_helper.h>

#include "sti_compositor.h"
#include "sti_cursor.h"
#include "sti_gdp.h"
#include "sti_hqvdp.h"
#include "sti_layer.h"
#include "sti_vid.h"

const char *sti_layer_to_str(struct sti_layer *layer)
{
	switch (layer->desc) {
	case STI_GDP_0:
		return "GDP0";
	case STI_GDP_1:
		return "GDP1";
	case STI_GDP_2:
		return "GDP2";
	case STI_GDP_3:
		return "GDP3";
	case STI_VID_0:
		return "VID0";
	case STI_VID_1:
		return "VID1";
	case STI_CURSOR:
		return "CURSOR";
	case STI_HQVDP_0:
		return "HQVDP0";
	default:
		return "<UNKNOWN LAYER>";
	}
}
EXPORT_SYMBOL(sti_layer_to_str);

struct sti_layer *sti_layer_create(struct device *dev, int desc,
				   void __iomem *baseaddr)
{

	struct sti_layer *layer = NULL;

	switch (desc & STI_LAYER_TYPE_MASK) {
	case STI_GDP:
		layer = sti_gdp_create(dev, desc);
		break;
	case STI_VID:
		layer = sti_vid_create(dev);
		break;
	case STI_CUR:
		layer = sti_cursor_create(dev);
		break;
	case STI_VDP:
		layer = sti_hqvdp_create(dev);
		break;
	}

	if (!layer) {
		DRM_ERROR("Failed to create layer\n");
		return NULL;
	}

	layer->desc = desc;
	layer->dev = dev;
	layer->regs = baseaddr;

	layer->ops->init(layer);

	DRM_DEBUG_DRIVER("%s created\n", sti_layer_to_str(layer));

	return layer;
}
EXPORT_SYMBOL(sti_layer_create);

int sti_layer_prepare(struct sti_layer *layer,
		      struct drm_crtc *crtc,
		      struct drm_framebuffer *fb,
		      struct drm_display_mode *mode, int mixer_id,
		      int dest_x, int dest_y, int dest_w, int dest_h,
		      int src_x, int src_y, int src_w, int src_h)
{
	int ret;
	unsigned int i;
	struct drm_gem_cma_object *cma_obj;

	if (!layer || !fb || !mode) {
		DRM_ERROR("Null fb, layer or mode\n");
		return 1;
	}

	cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
	if (!cma_obj) {
		DRM_ERROR("Can't get CMA GEM object for fb\n");
		return 1;
	}

	layer->crtc = crtc;
	layer->fb = fb;
	layer->mode = mode;
	layer->mixer_id = mixer_id;
	layer->dst_x = dest_x;
	layer->dst_y = dest_y;
	layer->dst_w = clamp_val(dest_w, 0, mode->crtc_hdisplay - dest_x);
	layer->dst_h = clamp_val(dest_h, 0, mode->crtc_vdisplay - dest_y);
	layer->src_x = src_x;
	layer->src_y = src_y;
	layer->src_w = src_w;
	layer->src_h = src_h;
	layer->format = fb->pixel_format;
	layer->vaddr = cma_obj->vaddr;
	layer->paddr = cma_obj->paddr;
	for (i = 0; i < 4; i++) {
		layer->pitches[i] = fb->pitches[i];
		layer->offsets[i] = fb->offsets[i];
	}

	DRM_DEBUG_DRIVER("%s is associated with mixer_id %d\n",
			 sti_layer_to_str(layer),
			 layer->mixer_id);
	DRM_DEBUG_DRIVER("%s dst=(%dx%d)@(%d,%d) - src=(%dx%d)@(%d,%d)\n",
			 sti_layer_to_str(layer),
			 layer->dst_w, layer->dst_h, layer->dst_x, layer->dst_y,
			 layer->src_w, layer->src_h, layer->src_x,
			 layer->src_y);

	DRM_DEBUG_DRIVER("drm FB:%d format:%.4s phys@:0x%lx\n", fb->base.id,
			 (char *)&layer->format, (unsigned long)layer->paddr);

	if (!layer->ops->prepare)
		goto err_no_prepare;

	ret = layer->ops->prepare(layer, !layer->enabled);
	if (!ret)
		layer->enabled = true;

	return ret;

err_no_prepare:
	DRM_ERROR("Cannot prepare\n");
	return 1;
}

int sti_layer_commit(struct sti_layer *layer)
{
	if (!layer)
		return 1;

	if (!layer->ops->commit)
		goto err_no_commit;

	return layer->ops->commit(layer);

err_no_commit:
	DRM_ERROR("Cannot commit\n");
	return 1;
}

int sti_layer_disable(struct sti_layer *layer)
{
	int ret;

	DRM_DEBUG_DRIVER("%s\n", sti_layer_to_str(layer));
	if (!layer)
		return 1;

	if (!layer->enabled)
		return 0;

	if (!layer->ops->disable)
		goto err_no_disable;

	ret = layer->ops->disable(layer);
	if (!ret)
		layer->enabled = false;
	else
		DRM_ERROR("Disable failed\n");

	return ret;

err_no_disable:
	DRM_ERROR("Cannot disable\n");
	return 1;
}

const uint32_t *sti_layer_get_formats(struct sti_layer *layer)
{
	if (!layer)
		return NULL;

	if (!layer->ops->get_formats)
		return NULL;

	return layer->ops->get_formats(layer);
}

unsigned int sti_layer_get_nb_formats(struct sti_layer *layer)
{
	if (!layer)
		return 0;

	if (!layer->ops->get_nb_formats)
		return 0;

	return layer->ops->get_nb_formats(layer);
}
OpenPOWER on IntegriCloud