2 * Copyright 2015 Freescale Semiconductor, Inc.
4 * Freescale DCU drm device driver
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
12 #include <linux/regmap.h>
15 #include <drm/drm_atomic_helper.h>
16 #include <drm/drm_crtc.h>
17 #include <drm/drm_crtc_helper.h>
18 #include <drm/drm_fb_cma_helper.h>
19 #include <drm/drm_gem_cma_helper.h>
20 #include <drm/drm_plane_helper.h>
22 #include "fsl_dcu_drm_drv.h"
23 #include "fsl_dcu_drm_plane.h"
25 static int fsl_dcu_drm_plane_index(struct drm_plane
*plane
)
27 struct fsl_dcu_drm_device
*fsl_dev
= plane
->dev
->dev_private
;
28 unsigned int total_layer
= fsl_dev
->soc
->total_layer
;
31 index
= drm_plane_index(plane
);
32 if (index
< total_layer
)
33 return total_layer
- index
- 1;
35 dev_err(fsl_dev
->dev
, "No more layer left\n");
39 static int fsl_dcu_drm_plane_atomic_check(struct drm_plane
*plane
,
40 struct drm_plane_state
*state
)
42 struct drm_framebuffer
*fb
= state
->fb
;
44 switch (fb
->pixel_format
) {
45 case DRM_FORMAT_RGB565
:
46 case DRM_FORMAT_RGB888
:
47 case DRM_FORMAT_ARGB8888
:
48 case DRM_FORMAT_BGRA4444
:
49 case DRM_FORMAT_ARGB1555
:
50 case DRM_FORMAT_YUV422
:
57 static void fsl_dcu_drm_plane_atomic_disable(struct drm_plane
*plane
,
58 struct drm_plane_state
*old_state
)
60 struct fsl_dcu_drm_device
*fsl_dev
= plane
->dev
->dev_private
;
64 index
= fsl_dcu_drm_plane_index(plane
);
68 ret
= regmap_read(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 4), &value
);
70 dev_err(fsl_dev
->dev
, "read DCU_INT_MASK failed\n");
71 value
&= ~DCU_LAYER_EN
;
72 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 4), value
);
74 dev_err(fsl_dev
->dev
, "set DCU register failed\n");
77 static void fsl_dcu_drm_plane_atomic_update(struct drm_plane
*plane
,
78 struct drm_plane_state
*old_state
)
81 struct fsl_dcu_drm_device
*fsl_dev
= plane
->dev
->dev_private
;
82 struct drm_plane_state
*state
= plane
->state
;
83 struct drm_framebuffer
*fb
= plane
->state
->fb
;
84 struct drm_gem_cma_object
*gem
;
85 unsigned int alpha
, bpp
;
91 index
= fsl_dcu_drm_plane_index(plane
);
95 gem
= drm_fb_cma_get_gem_obj(fb
, 0);
97 switch (fb
->pixel_format
) {
98 case DRM_FORMAT_RGB565
:
102 case DRM_FORMAT_RGB888
:
103 bpp
= FSL_DCU_RGB888
;
106 case DRM_FORMAT_ARGB8888
:
107 bpp
= FSL_DCU_ARGB8888
;
110 case DRM_FORMAT_BGRA4444
:
111 bpp
= FSL_DCU_ARGB4444
;
114 case DRM_FORMAT_ARGB1555
:
115 bpp
= FSL_DCU_ARGB1555
;
118 case DRM_FORMAT_YUV422
:
119 bpp
= FSL_DCU_YUV422
;
126 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 1),
127 DCU_LAYER_HEIGHT(state
->crtc_h
) |
128 DCU_LAYER_WIDTH(state
->crtc_w
));
131 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 2),
132 DCU_LAYER_POSY(state
->crtc_y
) |
133 DCU_LAYER_POSX(state
->crtc_x
));
136 ret
= regmap_write(fsl_dev
->regmap
,
137 DCU_CTRLDESCLN(index
, 3), gem
->paddr
);
140 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 4),
142 DCU_LAYER_TRANS(alpha
) |
147 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 5),
148 DCU_LAYER_CKMAX_R(0xFF) |
149 DCU_LAYER_CKMAX_G(0xFF) |
150 DCU_LAYER_CKMAX_B(0xFF));
153 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 6),
154 DCU_LAYER_CKMIN_R(0) |
155 DCU_LAYER_CKMIN_G(0) |
156 DCU_LAYER_CKMIN_B(0));
159 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 7), 0);
162 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 8),
163 DCU_LAYER_FG_FCOLOR(0));
166 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 9),
167 DCU_LAYER_BG_BCOLOR(0));
170 if (!strcmp(fsl_dev
->soc
->name
, "ls1021a")) {
171 ret
= regmap_write(fsl_dev
->regmap
, DCU_CTRLDESCLN(index
, 10),
172 DCU_LAYER_POST_SKIP(0) |
173 DCU_LAYER_PRE_SKIP(0));
177 ret
= regmap_update_bits(fsl_dev
->regmap
, DCU_DCU_MODE
,
178 DCU_MODE_DCU_MODE_MASK
,
179 DCU_MODE_DCU_MODE(DCU_MODE_NORMAL
));
182 ret
= regmap_write(fsl_dev
->regmap
,
183 DCU_UPDATE_MODE
, DCU_UPDATE_MODE_READREG
);
189 dev_err(fsl_dev
->dev
, "set DCU register failed\n");
193 fsl_dcu_drm_plane_cleanup_fb(struct drm_plane
*plane
,
194 const struct drm_plane_state
*new_state
)
199 fsl_dcu_drm_plane_prepare_fb(struct drm_plane
*plane
,
200 const struct drm_plane_state
*new_state
)
205 static const struct drm_plane_helper_funcs fsl_dcu_drm_plane_helper_funcs
= {
206 .atomic_check
= fsl_dcu_drm_plane_atomic_check
,
207 .atomic_disable
= fsl_dcu_drm_plane_atomic_disable
,
208 .atomic_update
= fsl_dcu_drm_plane_atomic_update
,
209 .cleanup_fb
= fsl_dcu_drm_plane_cleanup_fb
,
210 .prepare_fb
= fsl_dcu_drm_plane_prepare_fb
,
213 static void fsl_dcu_drm_plane_destroy(struct drm_plane
*plane
)
215 drm_plane_cleanup(plane
);
218 static const struct drm_plane_funcs fsl_dcu_drm_plane_funcs
= {
219 .atomic_duplicate_state
= drm_atomic_helper_plane_duplicate_state
,
220 .atomic_destroy_state
= drm_atomic_helper_plane_destroy_state
,
221 .destroy
= fsl_dcu_drm_plane_destroy
,
222 .disable_plane
= drm_atomic_helper_disable_plane
,
223 .reset
= drm_atomic_helper_plane_reset
,
224 .update_plane
= drm_atomic_helper_update_plane
,
227 static const u32 fsl_dcu_drm_plane_formats
[] = {
236 struct drm_plane
*fsl_dcu_drm_primary_create_plane(struct drm_device
*dev
)
238 struct drm_plane
*primary
;
241 primary
= kzalloc(sizeof(*primary
), GFP_KERNEL
);
243 DRM_DEBUG_KMS("Failed to allocate primary plane\n");
247 /* possible_crtc's will be filled in later by crtc_init */
248 ret
= drm_universal_plane_init(dev
, primary
, 0,
249 &fsl_dcu_drm_plane_funcs
,
250 fsl_dcu_drm_plane_formats
,
251 ARRAY_SIZE(fsl_dcu_drm_plane_formats
),
252 DRM_PLANE_TYPE_PRIMARY
);
257 drm_plane_helper_add(primary
, &fsl_dcu_drm_plane_helper_funcs
);