History

drm/sun4i: Add basic support for DE3

Display Engine 3 is an upgrade of DE2 with new features like support for 10 bit color formats and support for AFBC. Most of DE2 code works with DE3, except some small details. Implement basic support for DE3. Support for 10 bit colort formats and AFBC, among others missing features, will be added later.

Jernej Skrabec committed 8 years ago

Commit c50519e1 parent 97eb57f9 files · +202 −17Browse files

Unified · Split

9 files
  1. drivers/gpu/drm/sun4i/sun8i_csc.c +83 −0
  2. drivers/gpu/drm/sun4i/sun8i_mixer.c +27 −12
  3. drivers/gpu/drm/sun4i/sun8i_mixer.h +32 −2
  4. drivers/gpu/drm/sun4i/sun8i_ui_scaler.c +8 −2
  5. drivers/gpu/drm/sun4i/sun8i_ui_scaler.h +1 −0
  6. drivers/gpu/drm/sun4i/sun8i_vi_layer.c +8 −0
  7. drivers/gpu/drm/sun4i/sun8i_vi_layer.h +2 −0
  8. drivers/gpu/drm/sun4i/sun8i_vi_scaler.c +18 −1
  9. drivers/gpu/drm/sun4i/sun8i_vi_scaler.h +23 −0
drivers/gpu/drm/sun4i/sun8i_csc.c+83−0
@@ -34,6 +34,41 @@ static const u32 yvu2rgb[] = { · 33 unmodified lines
3434 0x000004A8, 0x00000000, 0x00000813, 0xFFFBAC4A,
3535 };
3636
37+/*
38+ * DE3 has a bit different CSC units. Factors are in two's complement format.
39+ * First three factors in a row are multiplication factors which have 17 bits
40+ * for fractional part. Fourth value in a row is comprised of two factors.
41+ * Upper 16 bits represents difference, which is subtracted from the input
42+ * value before multiplication and lower 16 bits represents constant, which
43+ * is addes at the end.
44+ *
45+ * x' = c00 * (x + d0) + c01 * (y + d1) + c02 * (z + d2) + const0
46+ * y' = c10 * (x + d0) + c11 * (y + d1) + c12 * (z + d2) + const1
47+ * z' = c20 * (x + d0) + c21 * (y + d1) + c22 * (z + d2) + const2
48+ *
49+ * Please note that above formula is true only for Blender CSC. Other DE3 CSC
50+ * units takes only positive value for difference. From what can be deducted
51+ * from BSP driver code, those units probably automatically assume that
52+ * difference has to be subtracted.
53+ *
54+ * Layout of factors in table:
55+ * c00 c01 c02 [d0 const0]
56+ * c10 c11 c12 [d1 const1]
57+ * c20 c21 c22 [d2 const2]
58+ */
59+
60+static const u32 yuv2rgb_de3[] = {
61+ 0x0002542a, 0x00000000, 0x0003312a, 0xffc00000,
62+ 0x0002542a, 0xffff376b, 0xfffe5fc3, 0xfe000000,
63+ 0x0002542a, 0x000408d3, 0x00000000, 0xfe000000,
64+};
65+
66+static const u32 yvu2rgb_de3[] = {
67+ 0x0002542a, 0x0003312a, 0x00000000, 0xffc00000,
68+ 0x0002542a, 0xfffe5fc3, 0xffff376b, 0xfe000000,
69+ 0x0002542a, 0x00000000, 0x000408d3, 0xfe000000,
70+};
71+
3772 static void sun8i_csc_set_coefficients(struct regmap *map, u32 base,
3873 enum sun8i_csc_mode mode)
3974 {
@@ -61,6 +96,28 @@ static void sun8i_csc_set_coefficients(struct regmap *map, u32 base, · 21 unmodified lines
6196 }
6297 }
6398
99+static void sun8i_de3_ccsc_set_coefficients(struct regmap *map, int layer,
100+ enum sun8i_csc_mode mode)
101+{
102+ const u32 *table;
103+ u32 base_reg;
104+
105+ switch (mode) {
106+ case SUN8I_CSC_MODE_YUV2RGB:
107+ table = yuv2rgb_de3;
108+ break;
109+ case SUN8I_CSC_MODE_YVU2RGB:
110+ table = yvu2rgb_de3;
111+ break;
112+ default:
113+ DRM_WARN("Wrong CSC mode specified.\n");
114+ return;
115+ }
116+
117+ base_reg = SUN50I_MIXER_BLEND_CSC_COEFF(DE3_BLD_BASE, layer, 0, 0);
118+ regmap_bulk_write(map, base_reg, table, 12);
119+}
120+
64121 static void sun8i_csc_enable(struct regmap *map, u32 base, bool enable)
65122 {
66123 u32 val;
@@ -73,11 +130,32 @@ static void sun8i_csc_enable(struct regmap *map, u32 base, bool enable) · 6 unmodified lines
73130 regmap_update_bits(map, SUN8I_CSC_CTRL(base), SUN8I_CSC_CTRL_EN, val);
74131 }
75132
133+static void sun8i_de3_ccsc_enable(struct regmap *map, int layer, bool enable)
134+{
135+ u32 val, mask;
136+
137+ mask = SUN50I_MIXER_BLEND_CSC_CTL_EN(layer);
138+
139+ if (enable)
140+ val = mask;
141+ else
142+ val = 0;
143+
144+ regmap_update_bits(map, SUN50I_MIXER_BLEND_CSC_CTL(DE3_BLD_BASE),
145+ mask, val);
146+}
147+
76148 void sun8i_csc_set_ccsc_coefficients(struct sun8i_mixer *mixer, int layer,
77149 enum sun8i_csc_mode mode)
78150 {
79151 u32 base;
80152
153+ if (mixer->cfg->is_de3) {
154+ sun8i_de3_ccsc_set_coefficients(mixer->engine.regs,
155+ layer, mode);
156+ return;
157+ }
158+
81159 base = ccsc_base[mixer->cfg->ccsc][layer];
82160
83161 sun8i_csc_set_coefficients(mixer->engine.regs, base, mode);
@@ -87,6 +165,11 @@ void sun8i_csc_enable_ccsc(struct sun8i_mixer *mixer, int layer, bool enable) · 3 unmodified lines
87165 {
88166 u32 base;
89167
168+ if (mixer->cfg->is_de3) {
169+ sun8i_de3_ccsc_enable(mixer->engine.regs, layer, enable);
170+ return;
171+ }
172+
90173 base = ccsc_base[mixer->cfg->ccsc][layer];
91174
92175 sun8i_csc_enable(mixer->engine.regs, base, enable);
drivers/gpu/drm/sun4i/sun8i_mixer.c+27−12
@@ -459,18 +459,33 @@ static int sun8i_mixer_bind(struct device *dev, struct device *master, · 458 unmodified lines
459459
460460 base = sun8i_blender_base(mixer);
461461
462− /* Reset the registers */
463− for (i = 0; i < DE2_MIXER_UNIT_SIZE; i += 4)
464− regmap_write(mixer->engine.regs, i, 0);
465−
466− /* Disable unused sub-engines */
467− regmap_write(mixer->engine.regs, SUN8I_MIXER_FCE_EN, 0);
468− regmap_write(mixer->engine.regs, SUN8I_MIXER_BWS_EN, 0);
469− regmap_write(mixer->engine.regs, SUN8I_MIXER_LTI_EN, 0);
470− regmap_write(mixer->engine.regs, SUN8I_MIXER_PEAK_EN, 0);
471− regmap_write(mixer->engine.regs, SUN8I_MIXER_ASE_EN, 0);
472− regmap_write(mixer->engine.regs, SUN8I_MIXER_FCC_EN, 0);
473− regmap_write(mixer->engine.regs, SUN8I_MIXER_DCSC_EN, 0);
462+ /* Reset registers and disable unused sub-engines */
463+ if (mixer->cfg->is_de3) {
464+ for (i = 0; i < DE3_MIXER_UNIT_SIZE; i += 4)
465+ regmap_write(mixer->engine.regs, i, 0);
466+
467+ regmap_write(mixer->engine.regs, SUN50I_MIXER_FCE_EN, 0);
468+ regmap_write(mixer->engine.regs, SUN50I_MIXER_PEAK_EN, 0);
469+ regmap_write(mixer->engine.regs, SUN50I_MIXER_LCTI_EN, 0);
470+ regmap_write(mixer->engine.regs, SUN50I_MIXER_BLS_EN, 0);
471+ regmap_write(mixer->engine.regs, SUN50I_MIXER_FCC_EN, 0);
472+ regmap_write(mixer->engine.regs, SUN50I_MIXER_DNS_EN, 0);
473+ regmap_write(mixer->engine.regs, SUN50I_MIXER_DRC_EN, 0);
474+ regmap_write(mixer->engine.regs, SUN50I_MIXER_FMT_EN, 0);
475+ regmap_write(mixer->engine.regs, SUN50I_MIXER_CDC0_EN, 0);
476+ regmap_write(mixer->engine.regs, SUN50I_MIXER_CDC1_EN, 0);
477+ } else {
478+ for (i = 0; i < DE2_MIXER_UNIT_SIZE; i += 4)
479+ regmap_write(mixer->engine.regs, i, 0);
480+
481+ regmap_write(mixer->engine.regs, SUN8I_MIXER_FCE_EN, 0);
482+ regmap_write(mixer->engine.regs, SUN8I_MIXER_BWS_EN, 0);
483+ regmap_write(mixer->engine.regs, SUN8I_MIXER_LTI_EN, 0);
484+ regmap_write(mixer->engine.regs, SUN8I_MIXER_PEAK_EN, 0);
485+ regmap_write(mixer->engine.regs, SUN8I_MIXER_ASE_EN, 0);
486+ regmap_write(mixer->engine.regs, SUN8I_MIXER_FCC_EN, 0);
487+ regmap_write(mixer->engine.regs, SUN8I_MIXER_DCSC_EN, 0);
488+ }
474489
475490 /* Enable the mixer */
476491 regmap_write(mixer->engine.regs, SUN8I_MIXER_GLOBAL_CTL,
drivers/gpu/drm/sun4i/sun8i_mixer.h+32−2
@@ -30,11 +30,16 @@ · 29 unmodified lines
3030 #define SUN8I_MIXER_GLOBAL_DBUFF_ENABLE BIT(0)
3131
3232 #define DE2_MIXER_UNIT_SIZE 0x6000
33+#define DE3_MIXER_UNIT_SIZE 0x3000
3334
3435 #define DE2_BLD_BASE 0x1000
3536 #define DE2_CH_BASE 0x2000
3637 #define DE2_CH_SIZE 0x1000
3738
39+#define DE3_BLD_BASE 0x0800
40+#define DE3_CH_BASE 0x1000
41+#define DE3_CH_SIZE 0x0800
42+
3843 #define SUN8I_MIXER_BLEND_PIPE_CTL(base) ((base) + 0)
3944 #define SUN8I_MIXER_BLEND_ATTR_FCOLOR(base, x) ((base) + 0x4 + 0x10 * (x))
4045 #define SUN8I_MIXER_BLEND_ATTR_INSIZE(base, x) ((base) + 0x8 + 0x10 * (x))
@@ -49,10 +54,16 @@ · 8 unmodified lines
4954 #define SUN8I_MIXER_BLEND_CK_MAX(base, x) ((base) + 0xc0 + 0x04 * (x))
5055 #define SUN8I_MIXER_BLEND_CK_MIN(base, x) ((base) + 0xe0 + 0x04 * (x))
5156 #define SUN8I_MIXER_BLEND_OUTCTL(base) ((base) + 0xfc)
57+#define SUN50I_MIXER_BLEND_CSC_CTL(base) ((base) + 0x100)
58+#define SUN50I_MIXER_BLEND_CSC_COEFF(base, layer, x, y) \
59+ ((base) + 0x110 + (layer) * 0x30 + (x) * 0x10 + 4 * (y))
60+#define SUN50I_MIXER_BLEND_CSC_CONST(base, layer, i) \
61+ ((base) + 0x110 + (layer) * 0x30 + (i) * 0x10 + 0x0c)
5262
5363 #define SUN8I_MIXER_BLEND_PIPE_CTL_EN_MSK GENMASK(12, 8)
5464 #define SUN8I_MIXER_BLEND_PIPE_CTL_EN(pipe) BIT(8 + pipe)
5565 #define SUN8I_MIXER_BLEND_PIPE_CTL_FC_EN(pipe) BIT(pipe)
66+
5667 /* colors are always in AARRGGBB format */
5768 #define SUN8I_MIXER_BLEND_COLOR_BLACK 0xff000000
5869 /* The following numbers are some still unknown magic numbers */
@@ -63,6 +74,9 @@ · 4 unmodified lines
6374
6475 #define SUN8I_MIXER_BLEND_OUTCTL_INTERLACED BIT(1)
6576
77+#define SUN50I_MIXER_BLEND_CSC_CTL_EN(ch) BIT(ch)
78+#define SUN50I_MIXER_BLEND_CSC_CONST_VAL(d, c) (((d) << 16) | ((c) & 0xffff))
79+
6680 #define SUN8I_MIXER_FBFMT_ARGB8888 0
6781 #define SUN8I_MIXER_FBFMT_ABGR8888 1
6882 #define SUN8I_MIXER_FBFMT_RGBA8888 2
@@ -112,6 +126,17 @@ · 43 unmodified lines
112126 #define SUN8I_MIXER_FCC_EN 0xaa000
113127 #define SUN8I_MIXER_DCSC_EN 0xb0000
114128
129+#define SUN50I_MIXER_FCE_EN 0x70000
130+#define SUN50I_MIXER_PEAK_EN 0x70800
131+#define SUN50I_MIXER_LCTI_EN 0x71000
132+#define SUN50I_MIXER_BLS_EN 0x71800
133+#define SUN50I_MIXER_FCC_EN 0x72000
134+#define SUN50I_MIXER_DNS_EN 0x80000
135+#define SUN50I_MIXER_DRC_EN 0xa0000
136+#define SUN50I_MIXER_FMT_EN 0xa8000
137+#define SUN50I_MIXER_CDC0_EN 0xd0000
138+#define SUN50I_MIXER_CDC1_EN 0xd8000
139+
115140 struct de2_fmt_info {
116141 u32 drm_fmt;
117142 u32 de2_fmt;
@@ -133,6 +158,7 @@ struct de2_fmt_info { · 15 unmodified lines
133158 * are invalid.
134159 * @mod_rate: module clock rate that needs to be set in order to have
135160 * a functional block.
161+ * @is_de3: true, if this is next gen display engine 3.0, false otherwise.
136162 */
137163 struct sun8i_mixer_cfg {
138164 int vi_num;
@@ -140,6 +166,7 @@ struct sun8i_mixer_cfg { · 1 unmodified line
140166 int scaler_mask;
141167 int ccsc;
142168 unsigned long mod_rate;
169+ unsigned int is_de3 : 1;
143170 };
144171
145172 struct sun8i_mixer {
@@ -162,13 +189,16 @@ engine_to_sun8i_mixer(struct sunxi_engine *engine) · 16 unmodified lines
162189 static inline u32
163190 sun8i_blender_base(struct sun8i_mixer *mixer)
164191 {
165− return DE2_BLD_BASE;
192+ return mixer->cfg->is_de3 ? DE3_BLD_BASE : DE2_BLD_BASE;
166193 }
167194
168195 static inline u32
169196 sun8i_channel_base(struct sun8i_mixer *mixer, int channel)
170197 {
171− return DE2_CH_BASE + channel * DE2_CH_SIZE;
198+ if (mixer->cfg->is_de3)
199+ return DE3_CH_BASE + channel * DE3_CH_SIZE;
200+ else
201+ return DE2_CH_BASE + channel * DE2_CH_SIZE;
172202 }
173203
174204 const struct de2_fmt_info *sun8i_mixer_format_info(u32 format);
drivers/gpu/drm/sun4i/sun8i_ui_scaler.c+8−2
@@ -93,8 +93,14 @@ static u32 sun8i_ui_scaler_base(struct sun8i_mixer *mixer, int channel) · 92 unmodified lines
9393 {
9494 int vi_num = mixer->cfg->vi_num;
9595
96− return DE2_VI_SCALER_UNIT_BASE + DE2_VI_SCALER_UNIT_SIZE * vi_num +
97− DE2_UI_SCALER_UNIT_SIZE * (channel - vi_num);
96+ if (mixer->cfg->is_de3)
97+ return DE3_VI_SCALER_UNIT_BASE +
98+ DE3_VI_SCALER_UNIT_SIZE * vi_num +
99+ DE3_UI_SCALER_UNIT_SIZE * (channel - vi_num);
100+ else
101+ return DE2_VI_SCALER_UNIT_BASE +
102+ DE2_VI_SCALER_UNIT_SIZE * vi_num +
103+ DE2_UI_SCALER_UNIT_SIZE * (channel - vi_num);
98104 }
99105
100106 static int sun8i_ui_scaler_coef_index(unsigned int step)
drivers/gpu/drm/sun4i/sun8i_ui_scaler.h+1−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
1212 #include "sun8i_mixer.h"
1313
1414 #define DE2_UI_SCALER_UNIT_SIZE 0x10000
15+#define DE3_UI_SCALER_UNIT_SIZE 0x08000
1516
1617 /* this two macros assumes 16 fractional bits which is standard in DRM */
1718 #define SUN8I_UI_SCALER_SCALE_MIN 1
drivers/gpu/drm/sun4i/sun8i_vi_layer.c+8−0
@@ -202,6 +202,14 @@ static int sun8i_vi_layer_update_formats(struct sun8i_mixer *mixer, int channel, · 201 unmodified lines
202202 SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base, overlay),
203203 SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE, val);
204204
205+ /* It seems that YUV formats use global alpha setting. */
206+ if (mixer->cfg->is_de3)
207+ regmap_update_bits(mixer->engine.regs,
208+ SUN8I_MIXER_CHAN_VI_LAYER_ATTR(ch_base,
209+ overlay),
210+ SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MASK,
211+ SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA(0xff));
212+
205213 return 0;
206214 }
207215
drivers/gpu/drm/sun4i/sun8i_vi_layer.h+2−0
@@ -30,6 +30,8 @@ · 29 unmodified lines
3030 #define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_RGB_MODE BIT(15)
3131 #define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_OFFSET 8
3232 #define SUN8I_MIXER_CHAN_VI_LAYER_ATTR_FBFMT_MASK GENMASK(12, 8)
33+#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA_MASK GENMASK(31, 24)
34+#define SUN50I_MIXER_CHAN_VI_LAYER_ATTR_ALPHA(x) ((x) << 24)
3335
3436 struct sun8i_mixer;
3537
drivers/gpu/drm/sun4i/sun8i_vi_scaler.c+18−1
@@ -835,7 +835,12 @@ static const u32 bicubic4coefftab32[480] = { · 834 unmodified lines
835835
836836 static u32 sun8i_vi_scaler_base(struct sun8i_mixer *mixer, int channel)
837837 {
838− return DE2_VI_SCALER_UNIT_BASE + DE2_VI_SCALER_UNIT_SIZE * channel;
838+ if (mixer->cfg->is_de3)
839+ return DE3_VI_SCALER_UNIT_BASE +
840+ DE3_VI_SCALER_UNIT_SIZE * channel;
841+ else
842+ return DE2_VI_SCALER_UNIT_BASE +
843+ DE2_VI_SCALER_UNIT_SIZE * channel;
839844 }
840845
841846 static int sun8i_vi_scaler_coef_index(unsigned int step)
@@ -951,6 +956,18 @@ void sun8i_vi_scaler_setup(struct sun8i_mixer *mixer, int layer, · 109 unmodified lines
951956 cvphase = vphase;
952957 }
953958
959+ if (mixer->cfg->is_de3) {
960+ u32 val;
961+
962+ if (format->hsub == 1 && format->vsub == 1)
963+ val = SUN50I_SCALER_VSU_SCALE_MODE_UI;
964+ else
965+ val = SUN50I_SCALER_VSU_SCALE_MODE_NORMAL;
966+
967+ regmap_write(mixer->engine.regs,
968+ SUN50I_SCALER_VSU_SCALE_MODE(base), val);
969+ }
970+
954971 regmap_write(mixer->engine.regs,
955972 SUN8I_SCALER_VSU_OUTSIZE(base), outsize);
956973 regmap_write(mixer->engine.regs,
drivers/gpu/drm/sun4i/sun8i_vi_scaler.h+23−0
@@ -15,6 +15,9 @@ · 14 unmodified lines
1515 #define DE2_VI_SCALER_UNIT_BASE 0x20000
1616 #define DE2_VI_SCALER_UNIT_SIZE 0x20000
1717
18+#define DE3_VI_SCALER_UNIT_BASE 0x20000
19+#define DE3_VI_SCALER_UNIT_SIZE 0x08000
20+
1821 /* this two macros assumes 16 fractional bits which is standard in DRM */
1922 #define SUN8I_VI_SCALER_SCALE_MIN 1
2023 #define SUN8I_VI_SCALER_SCALE_MAX ((1UL << 20) - 1)
@@ -25,6 +28,11 @@ · 4 unmodified lines
2528 #define SUN8I_VI_SCALER_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1))
2629
2730 #define SUN8I_SCALER_VSU_CTRL(base) ((base) + 0x0)
31+#define SUN50I_SCALER_VSU_SCALE_MODE(base) ((base) + 0x10)
32+#define SUN50I_SCALER_VSU_DIR_THR(base) ((base) + 0x20)
33+#define SUN50I_SCALER_VSU_EDGE_THR(base) ((base) + 0x24)
34+#define SUN50I_SCALER_VSU_EDSCL_CTRL(base) ((base) + 0x28)
35+#define SUN50I_SCALER_VSU_ANGLE_THR(base) ((base) + 0x2c)
2836 #define SUN8I_SCALER_VSU_OUTSIZE(base) ((base) + 0x40)
2937 #define SUN8I_SCALER_VSU_YINSIZE(base) ((base) + 0x80)
3038 #define SUN8I_SCALER_VSU_YHSTEP(base) ((base) + 0x88)
@@ -46,6 +54,21 @@ · 15 unmodified lines
4654 #define SUN8I_SCALER_VSU_CTRL_EN BIT(0)
4755 #define SUN8I_SCALER_VSU_CTRL_COEFF_RDY BIT(4)
4856
57+#define SUN50I_SCALER_VSU_SUB_ZERO_DIR_THR(x) (((x) << 24) & 0xFF)
58+#define SUN50I_SCALER_VSU_ZERO_DIR_THR(x) (((x) << 16) & 0xFF)
59+#define SUN50I_SCALER_VSU_HORZ_DIR_THR(x) (((x) << 8) & 0xFF)
60+#define SUN50I_SCALER_VSU_VERT_DIR_THR(x) ((x) & 0xFF)
61+
62+#define SUN50I_SCALER_VSU_SCALE_MODE_UI 0
63+#define SUN50I_SCALER_VSU_SCALE_MODE_NORMAL 1
64+#define SUN50I_SCALER_VSU_SCALE_MODE_ED_SCALE 2
65+
66+#define SUN50I_SCALER_VSU_EDGE_SHIFT(x) (((x) << 16) & 0xF)
67+#define SUN50I_SCALER_VSU_EDGE_OFFSET(x) ((x) & 0xFF)
68+
69+#define SUN50I_SCALER_VSU_ANGLE_SHIFT(x) (((x) << 16) & 0xF)
70+#define SUN50I_SCALER_VSU_ANGLE_OFFSET(x) ((x) & 0xFF)
71+
4972 void sun8i_vi_scaler_enable(struct sun8i_mixer *mixer, int layer, bool enable);
5073 void sun8i_vi_scaler_setup(struct sun8i_mixer *mixer, int layer,
5174 u32 src_w, u32 src_h, u32 dst_w, u32 dst_h,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t