2 * Copyright (C) 2014 Free Electrons
3 * Copyright (C) 2014 Atmel
5 * Author: Boris BREZILLON <boris.brezillon@free-electrons.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along with
17 * this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef DRM_ATMEL_HLCDC_LAYER_H
21 #define DRM_ATMEL_HLCDC_LAYER_H
23 #include <linux/mfd/atmel-hlcdc.h>
25 #include <drm/drm_crtc.h>
26 #include <drm/drm_flip_work.h>
29 #define ATMEL_HLCDC_LAYER_CHER 0x0
30 #define ATMEL_HLCDC_LAYER_CHDR 0x4
31 #define ATMEL_HLCDC_LAYER_CHSR 0x8
32 #define ATMEL_HLCDC_LAYER_DMA_CHAN BIT(0)
33 #define ATMEL_HLCDC_LAYER_UPDATE BIT(1)
34 #define ATMEL_HLCDC_LAYER_A2Q BIT(2)
35 #define ATMEL_HLCDC_LAYER_RST BIT(8)
37 #define ATMEL_HLCDC_LAYER_IER 0xc
38 #define ATMEL_HLCDC_LAYER_IDR 0x10
39 #define ATMEL_HLCDC_LAYER_IMR 0x14
40 #define ATMEL_HLCDC_LAYER_ISR 0x18
41 #define ATMEL_HLCDC_LAYER_DFETCH BIT(0)
42 #define ATMEL_HLCDC_LAYER_LFETCH BIT(1)
43 #define ATMEL_HLCDC_LAYER_DMA_IRQ BIT(2)
44 #define ATMEL_HLCDC_LAYER_DSCR_IRQ BIT(3)
45 #define ATMEL_HLCDC_LAYER_ADD_IRQ BIT(4)
46 #define ATMEL_HLCDC_LAYER_DONE_IRQ BIT(5)
47 #define ATMEL_HLCDC_LAYER_OVR_IRQ BIT(6)
49 #define ATMEL_HLCDC_LAYER_PLANE_HEAD(n) (((n) * 0x10) + 0x1c)
50 #define ATMEL_HLCDC_LAYER_PLANE_ADDR(n) (((n) * 0x10) + 0x20)
51 #define ATMEL_HLCDC_LAYER_PLANE_CTRL(n) (((n) * 0x10) + 0x24)
52 #define ATMEL_HLCDC_LAYER_PLANE_NEXT(n) (((n) * 0x10) + 0x28)
53 #define ATMEL_HLCDC_LAYER_CFG(p, c) (((c) * 4) + ((p)->max_planes * 0x10) + 0x1c)
55 #define ATMEL_HLCDC_LAYER_DMA_CFG_ID 0
56 #define ATMEL_HLCDC_LAYER_DMA_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, ATMEL_HLCDC_LAYER_DMA_CFG_ID)
57 #define ATMEL_HLCDC_LAYER_DMA_SIF BIT(0)
58 #define ATMEL_HLCDC_LAYER_DMA_BLEN_MASK GENMASK(5, 4)
59 #define ATMEL_HLCDC_LAYER_DMA_BLEN_SINGLE (0 << 4)
60 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR4 (1 << 4)
61 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR8 (2 << 4)
62 #define ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 (3 << 4)
63 #define ATMEL_HLCDC_LAYER_DMA_DLBO BIT(8)
64 #define ATMEL_HLCDC_LAYER_DMA_ROTDIS BIT(12)
65 #define ATMEL_HLCDC_LAYER_DMA_LOCKDIS BIT(13)
67 #define ATMEL_HLCDC_LAYER_FORMAT_CFG_ID 1
68 #define ATMEL_HLCDC_LAYER_FORMAT_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, ATMEL_HLCDC_LAYER_FORMAT_CFG_ID)
69 #define ATMEL_HLCDC_LAYER_RGB (0 << 0)
70 #define ATMEL_HLCDC_LAYER_CLUT (1 << 0)
71 #define ATMEL_HLCDC_LAYER_YUV (2 << 0)
72 #define ATMEL_HLCDC_RGB_MODE(m) (((m) & 0xf) << 4)
73 #define ATMEL_HLCDC_CLUT_MODE(m) (((m) & 0x3) << 8)
74 #define ATMEL_HLCDC_YUV_MODE(m) (((m) & 0xf) << 12)
75 #define ATMEL_HLCDC_YUV422ROT BIT(16)
76 #define ATMEL_HLCDC_YUV422SWP BIT(17)
77 #define ATMEL_HLCDC_DSCALEOPT BIT(20)
79 #define ATMEL_HLCDC_XRGB4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(0))
80 #define ATMEL_HLCDC_ARGB4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(1))
81 #define ATMEL_HLCDC_RGBA4444_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(2))
82 #define ATMEL_HLCDC_RGB565_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(3))
83 #define ATMEL_HLCDC_ARGB1555_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(4))
84 #define ATMEL_HLCDC_XRGB8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(9))
85 #define ATMEL_HLCDC_RGB888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(10))
86 #define ATMEL_HLCDC_ARGB8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(12))
87 #define ATMEL_HLCDC_RGBA8888_MODE (ATMEL_HLCDC_LAYER_RGB | ATMEL_HLCDC_RGB_MODE(13))
89 #define ATMEL_HLCDC_AYUV_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(0))
90 #define ATMEL_HLCDC_YUYV_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(1))
91 #define ATMEL_HLCDC_UYVY_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(2))
92 #define ATMEL_HLCDC_YVYU_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(3))
93 #define ATMEL_HLCDC_VYUY_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(4))
94 #define ATMEL_HLCDC_NV61_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(5))
95 #define ATMEL_HLCDC_YUV422_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(6))
96 #define ATMEL_HLCDC_NV21_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(7))
97 #define ATMEL_HLCDC_YUV420_MODE (ATMEL_HLCDC_LAYER_YUV | ATMEL_HLCDC_YUV_MODE(8))
99 #define ATMEL_HLCDC_LAYER_POS_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.pos)
100 #define ATMEL_HLCDC_LAYER_SIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.size)
101 #define ATMEL_HLCDC_LAYER_MEMSIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.memsize)
102 #define ATMEL_HLCDC_LAYER_XSTRIDE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.xstride)
103 #define ATMEL_HLCDC_LAYER_PSTRIDE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.pstride)
104 #define ATMEL_HLCDC_LAYER_DFLTCOLOR_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.default_color)
105 #define ATMEL_HLCDC_LAYER_CRKEY_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.chroma_key)
106 #define ATMEL_HLCDC_LAYER_CRKEY_MASK_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.chroma_key_mask)
108 #define ATMEL_HLCDC_LAYER_GENERAL_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.general_config)
109 #define ATMEL_HLCDC_LAYER_CRKEY BIT(0)
110 #define ATMEL_HLCDC_LAYER_INV BIT(1)
111 #define ATMEL_HLCDC_LAYER_ITER2BL BIT(2)
112 #define ATMEL_HLCDC_LAYER_ITER BIT(3)
113 #define ATMEL_HLCDC_LAYER_REVALPHA BIT(4)
114 #define ATMEL_HLCDC_LAYER_GAEN BIT(5)
115 #define ATMEL_HLCDC_LAYER_LAEN BIT(6)
116 #define ATMEL_HLCDC_LAYER_OVR BIT(7)
117 #define ATMEL_HLCDC_LAYER_DMA BIT(8)
118 #define ATMEL_HLCDC_LAYER_REP BIT(9)
119 #define ATMEL_HLCDC_LAYER_DSTKEY BIT(10)
120 #define ATMEL_HLCDC_LAYER_DISCEN BIT(11)
121 #define ATMEL_HLCDC_LAYER_GA_SHIFT 16
122 #define ATMEL_HLCDC_LAYER_GA_MASK GENMASK(23, ATMEL_HLCDC_LAYER_GA_SHIFT)
124 #define ATMEL_HLCDC_LAYER_CSC_CFG(p, o) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.csc + o)
126 #define ATMEL_HLCDC_LAYER_DISC_POS_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_pos)
128 #define ATMEL_HLCDC_LAYER_DISC_SIZE_CFG(p) ATMEL_HLCDC_LAYER_CFG(p, (p)->desc->layout.disc_size)
130 #define ATMEL_HLCDC_MAX_PLANES 3
132 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_RESERVED BIT(0)
133 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_LOADED BIT(1)
134 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_DONE BIT(2)
135 #define ATMEL_HLCDC_DMA_CHANNEL_DSCR_OVERRUN BIT(3)
138 * Atmel HLCDC Layer registers layout structure
140 * Each HLCDC layer has its own register organization and a given register
141 * can be placed differently on 2 different layers depending on its
143 * This structure stores common registers layout for a given layer and is
144 * used by HLCDC layer code to choose the appropriate register to write to
147 * For all fields, a value of zero means "unsupported".
149 * See Atmel's datasheet for a detailled description of these registers.
151 * @xstride: xstride registers
152 * @pstride: pstride registers
153 * @pos: position register
154 * @size: displayed size register
155 * @memsize: memory size register
156 * @default_color: default color register
157 * @chroma_key: chroma key register
158 * @chroma_key_mask: chroma key mask register
159 * @general_config: general layer config register
160 * @disc_pos: discard area position register
161 * @disc_size: discard area size register
162 * @csc: color space conversion register
164 struct atmel_hlcdc_layer_cfg_layout
{
165 int xstride
[ATMEL_HLCDC_MAX_PLANES
];
166 int pstride
[ATMEL_HLCDC_MAX_PLANES
];
180 * Atmel HLCDC framebuffer flip structure
182 * This structure is allocated when someone asked for a layer update (most
183 * likely a DRM plane update, either primary, overlay or cursor plane) and
184 * released when the layer do not need to reference the framebuffer object
185 * anymore (i.e. the layer was disabled or updated).
187 * @dscrs: DMA descriptors
188 * @fb: the referenced framebuffer object
189 * @ngems: number of GEM objects referenced by the fb element
190 * @status: fb flip operation status
192 struct atmel_hlcdc_layer_fb_flip
{
193 struct atmel_hlcdc_dma_channel_dscr
*dscrs
[ATMEL_HLCDC_MAX_PLANES
];
194 struct drm_flip_task
*task
;
195 struct drm_framebuffer
*fb
;
201 * Atmel HLCDC DMA descriptor structure
203 * This structure is used by the HLCDC DMA engine to schedule a DMA transfer.
205 * The structure fields must remain in this specific order, because they're
206 * used by the HLCDC DMA engine, which expect them in this order.
207 * HLCDC DMA descriptors must be aligned on 64 bits.
209 * @addr: buffer DMA address
210 * @ctrl: DMA transfer options
211 * @next: next DMA descriptor to fetch
212 * @gem_flip: the attached gem_flip operation
214 struct atmel_hlcdc_dma_channel_dscr
{
219 } __aligned(sizeof(u64
));
222 * Atmel HLCDC layer types
224 enum atmel_hlcdc_layer_type
{
225 ATMEL_HLCDC_BASE_LAYER
,
226 ATMEL_HLCDC_OVERLAY_LAYER
,
227 ATMEL_HLCDC_CURSOR_LAYER
,
228 ATMEL_HLCDC_PP_LAYER
,
232 * Atmel HLCDC Supported formats structure
234 * This structure list all the formats supported by a given layer.
236 * @nformats: number of supported formats
237 * @formats: supported formats
239 struct atmel_hlcdc_formats
{
245 * Atmel HLCDC Layer description structure
247 * This structure describe the capabilities provided by a given layer.
252 * @regs_offset: offset of the layer registers from the HLCDC registers base
253 * @nconfigs: number of config registers provided by this layer
254 * @formats: supported formats
255 * @layout: config registers layout
256 * @max_width: maximum width supported by this layer (0 means unlimited)
257 * @max_height: maximum height supported by this layer (0 means unlimited)
259 struct atmel_hlcdc_layer_desc
{
261 enum atmel_hlcdc_layer_type type
;
265 struct atmel_hlcdc_formats
*formats
;
266 struct atmel_hlcdc_layer_cfg_layout layout
;
272 * Atmel HLCDC Layer Update Slot structure
274 * This structure stores layer update requests to be applied on next frame.
275 * This is the base structure behind the atomic layer update infrastructure.
277 * Atomic layer update provides a way to update all layer's parameters
278 * simultaneously. This is needed to avoid incompatible sequential updates
280 * 1) update layer format from RGB888 (1 plane/buffer) to YUV422
282 * 2) the format update is applied but the DMA channel for the second
283 * plane/buffer is not enabled
284 * 3) enable the DMA channel for the second plane
286 * @fb_flip: fb_flip object
287 * @updated_configs: bitmask used to record modified configs
288 * @configs: new config values
290 struct atmel_hlcdc_layer_update_slot
{
291 struct atmel_hlcdc_layer_fb_flip
*fb_flip
;
292 unsigned long *updated_configs
;
297 * Atmel HLCDC Layer Update structure
299 * This structure provides a way to queue layer update requests.
301 * At a given time there is at most:
302 * - one pending update request, which means the update request has been
303 * committed (or validated) and is waiting for the DMA channel(s) to be
305 * - one request being prepared, which means someone started a layer update
306 * but has not committed it yet. There cannot be more than one started
307 * request, because the update lock is taken when starting a layer update
308 * and release when committing or rolling back the request.
310 * @slots: update slots. One is used for pending request and the other one
311 * for started update request
312 * @pending: the pending slot index or -1 if no request is pending
313 * @next: the started update slot index or -1 no update has been started
315 struct atmel_hlcdc_layer_update
{
316 struct atmel_hlcdc_layer_update_slot slots
[2];
321 enum atmel_hlcdc_layer_dma_channel_status
{
322 ATMEL_HLCDC_LAYER_DISABLED
,
323 ATMEL_HLCDC_LAYER_ENABLED
,
324 ATMEL_HLCDC_LAYER_DISABLING
,
328 * Atmel HLCDC Layer DMA channel structure
330 * This structure stores information on the DMA channel associated to a
333 * @status: DMA channel status
334 * @cur: current framebuffer
335 * @queue: next framebuffer
336 * @dscrs: allocated DMA descriptors
338 struct atmel_hlcdc_layer_dma_channel
{
339 enum atmel_hlcdc_layer_dma_channel_status status
;
340 struct atmel_hlcdc_layer_fb_flip
*cur
;
341 struct atmel_hlcdc_layer_fb_flip
*queue
;
342 struct atmel_hlcdc_dma_channel_dscr
*dscrs
;
346 * Atmel HLCDC Layer structure
348 * This structure stores information on the layer instance.
350 * @desc: layer description
351 * @max_planes: maximum planes/buffers that can be associated with this layer.
352 * This depends on the supported formats.
353 * @hlcdc: pointer to the atmel_hlcdc structure provided by the MFD device
355 * @gc: fb flip garbage collector
356 * @update: update handler
359 struct atmel_hlcdc_layer
{
360 const struct atmel_hlcdc_layer_desc
*desc
;
362 struct atmel_hlcdc
*hlcdc
;
363 struct workqueue_struct
*wq
;
364 struct drm_flip_work gc
;
365 struct atmel_hlcdc_layer_dma_channel dma
;
366 struct atmel_hlcdc_layer_update update
;
370 void atmel_hlcdc_layer_irq(struct atmel_hlcdc_layer
*layer
);
372 int atmel_hlcdc_layer_init(struct drm_device
*dev
,
373 struct atmel_hlcdc_layer
*layer
,
374 const struct atmel_hlcdc_layer_desc
*desc
);
376 void atmel_hlcdc_layer_cleanup(struct drm_device
*dev
,
377 struct atmel_hlcdc_layer
*layer
);
379 int atmel_hlcdc_layer_disable(struct atmel_hlcdc_layer
*layer
);
381 int atmel_hlcdc_layer_update_start(struct atmel_hlcdc_layer
*layer
);
383 void atmel_hlcdc_layer_update_cfg(struct atmel_hlcdc_layer
*layer
, int cfg
,
386 void atmel_hlcdc_layer_update_set_fb(struct atmel_hlcdc_layer
*layer
,
387 struct drm_framebuffer
*fb
,
388 unsigned int *offsets
);
390 void atmel_hlcdc_layer_update_set_finished(struct atmel_hlcdc_layer
*layer
,
391 void (*finished
)(void *data
),
392 void *finished_data
);
394 void atmel_hlcdc_layer_update_rollback(struct atmel_hlcdc_layer
*layer
);
396 void atmel_hlcdc_layer_update_commit(struct atmel_hlcdc_layer
*layer
);
398 #endif /* DRM_ATMEL_HLCDC_LAYER_H */