2 * Copyright (C) STMicroelectronics SA 2014
3 * Authors: Benjamin Gaignard <benjamin.gaignard@st.com>
4 * Fabien Dessenne <fabien.dessenne@st.com>
5 * for STMicroelectronics.
6 * License terms: GNU General Public License (GPL), version 2
10 #include <drm/drm_gem_cma_helper.h>
11 #include <drm/drm_fb_cma_helper.h>
13 #include "sti_compositor.h"
14 #include "sti_cursor.h"
16 #include "sti_hqvdp.h"
17 #include "sti_layer.h"
20 const char *sti_layer_to_str(struct sti_layer
*layer
)
22 switch (layer
->desc
) {
40 return "<UNKNOWN LAYER>";
43 EXPORT_SYMBOL(sti_layer_to_str
);
45 struct sti_layer
*sti_layer_create(struct device
*dev
, int desc
,
46 void __iomem
*baseaddr
)
49 struct sti_layer
*layer
= NULL
;
51 switch (desc
& STI_LAYER_TYPE_MASK
) {
53 layer
= sti_gdp_create(dev
, desc
);
56 layer
= sti_vid_create(dev
);
59 layer
= sti_cursor_create(dev
);
62 layer
= sti_hqvdp_create(dev
);
67 DRM_ERROR("Failed to create layer\n");
73 layer
->regs
= baseaddr
;
75 layer
->ops
->init(layer
);
77 DRM_DEBUG_DRIVER("%s created\n", sti_layer_to_str(layer
));
81 EXPORT_SYMBOL(sti_layer_create
);
83 int sti_layer_prepare(struct sti_layer
*layer
,
84 struct drm_crtc
*crtc
,
85 struct drm_framebuffer
*fb
,
86 struct drm_display_mode
*mode
, int mixer_id
,
87 int dest_x
, int dest_y
, int dest_w
, int dest_h
,
88 int src_x
, int src_y
, int src_w
, int src_h
)
92 struct drm_gem_cma_object
*cma_obj
;
94 if (!layer
|| !fb
|| !mode
) {
95 DRM_ERROR("Null fb, layer or mode\n");
99 cma_obj
= drm_fb_cma_get_gem_obj(fb
, 0);
101 DRM_ERROR("Can't get CMA GEM object for fb\n");
108 layer
->mixer_id
= mixer_id
;
109 layer
->dst_x
= dest_x
;
110 layer
->dst_y
= dest_y
;
111 layer
->dst_w
= clamp_val(dest_w
, 0, mode
->crtc_hdisplay
- dest_x
);
112 layer
->dst_h
= clamp_val(dest_h
, 0, mode
->crtc_vdisplay
- dest_y
);
113 layer
->src_x
= src_x
;
114 layer
->src_y
= src_y
;
115 layer
->src_w
= src_w
;
116 layer
->src_h
= src_h
;
117 layer
->format
= fb
->pixel_format
;
118 layer
->vaddr
= cma_obj
->vaddr
;
119 layer
->paddr
= cma_obj
->paddr
;
120 for (i
= 0; i
< 4; i
++) {
121 layer
->pitches
[i
] = fb
->pitches
[i
];
122 layer
->offsets
[i
] = fb
->offsets
[i
];
125 DRM_DEBUG_DRIVER("%s is associated with mixer_id %d\n",
126 sti_layer_to_str(layer
),
128 DRM_DEBUG_DRIVER("%s dst=(%dx%d)@(%d,%d) - src=(%dx%d)@(%d,%d)\n",
129 sti_layer_to_str(layer
),
130 layer
->dst_w
, layer
->dst_h
, layer
->dst_x
, layer
->dst_y
,
131 layer
->src_w
, layer
->src_h
, layer
->src_x
,
134 DRM_DEBUG_DRIVER("drm FB:%d format:%.4s phys@:0x%lx\n", fb
->base
.id
,
135 (char *)&layer
->format
, (unsigned long)layer
->paddr
);
137 if (!layer
->ops
->prepare
)
140 ret
= layer
->ops
->prepare(layer
, !layer
->enabled
);
142 layer
->enabled
= true;
147 DRM_ERROR("Cannot prepare\n");
151 int sti_layer_commit(struct sti_layer
*layer
)
156 if (!layer
->ops
->commit
)
159 return layer
->ops
->commit(layer
);
162 DRM_ERROR("Cannot commit\n");
166 int sti_layer_disable(struct sti_layer
*layer
)
170 DRM_DEBUG_DRIVER("%s\n", sti_layer_to_str(layer
));
177 if (!layer
->ops
->disable
)
180 ret
= layer
->ops
->disable(layer
);
182 layer
->enabled
= false;
184 DRM_ERROR("Disable failed\n");
189 DRM_ERROR("Cannot disable\n");
193 const uint32_t *sti_layer_get_formats(struct sti_layer
*layer
)
198 if (!layer
->ops
->get_formats
)
201 return layer
->ops
->get_formats(layer
);
204 unsigned int sti_layer_get_nb_formats(struct sti_layer
*layer
)
209 if (!layer
->ops
->get_nb_formats
)
212 return layer
->ops
->get_nb_formats(layer
);