1 /*
2  * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  */
9 
10 #ifndef _SUN8I_MIXER_H_
11 #define _SUN8I_MIXER_H_
12 
13 #include <linux/clk.h>
14 #include <linux/regmap.h>
15 #include <linux/reset.h>
16 
17 #include "sunxi_engine.h"
18 
19 #define SUN8I_MIXER_MAX_CHAN_COUNT		4
20 
21 #define SUN8I_MIXER_SIZE(w, h)			(((h) - 1) << 16 | ((w) - 1))
22 #define SUN8I_MIXER_COORD(x, y)			((y) << 16 | (x))
23 
24 #define SUN8I_MIXER_GLOBAL_CTL			0x0
25 #define SUN8I_MIXER_GLOBAL_STATUS		0x4
26 #define SUN8I_MIXER_GLOBAL_DBUFF		0x8
27 #define SUN8I_MIXER_GLOBAL_SIZE			0xc
28 
29 #define SUN8I_MIXER_GLOBAL_CTL_RT_EN		0x1
30 
31 #define SUN8I_MIXER_GLOBAL_DBUFF_ENABLE		0x1
32 
33 #define SUN8I_MIXER_BLEND_FCOLOR_CTL		0x1000
34 #define SUN8I_MIXER_BLEND_ATTR_FCOLOR(x)	(0x1004 + 0x10 * (x) + 0x0)
35 #define SUN8I_MIXER_BLEND_ATTR_INSIZE(x)	(0x1004 + 0x10 * (x) + 0x4)
36 #define SUN8I_MIXER_BLEND_ATTR_OFFSET(x)	(0x1004 + 0x10 * (x) + 0x8)
37 #define SUN8I_MIXER_BLEND_ROUTE			0x1080
38 #define SUN8I_MIXER_BLEND_PREMULTIPLY		0x1084
39 #define SUN8I_MIXER_BLEND_BKCOLOR		0x1088
40 #define SUN8I_MIXER_BLEND_OUTSIZE		0x108c
41 #define SUN8I_MIXER_BLEND_MODE(x)		(0x1090 + 0x04 * (x))
42 #define SUN8I_MIXER_BLEND_CK_CTL		0x10b0
43 #define SUN8I_MIXER_BLEND_CK_CFG		0x10b4
44 #define SUN8I_MIXER_BLEND_CK_MAX(x)		(0x10c0 + 0x04 * (x))
45 #define SUN8I_MIXER_BLEND_CK_MIN(x)		(0x10e0 + 0x04 * (x))
46 #define SUN8I_MIXER_BLEND_OUTCTL		0x10fc
47 
48 /* colors are always in AARRGGBB format */
49 #define SUN8I_MIXER_BLEND_COLOR_BLACK		0xff000000
50 /* The following numbers are some still unknown magic numbers */
51 #define SUN8I_MIXER_BLEND_FCOLOR_CTL_DEF	0x00000101
52 #define SUN8I_MIXER_BLEND_MODE_DEF		0x03010301
53 
54 #define SUN8I_MIXER_BLEND_OUTCTL_INTERLACED	BIT(1)
55 
56 /*
57  * VI channels are not used now, but the support of them may be introduced in
58  * the future.
59  */
60 
61 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR(ch, layer) \
62 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x0)
63 #define SUN8I_MIXER_CHAN_UI_LAYER_SIZE(ch, layer) \
64 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x4)
65 #define SUN8I_MIXER_CHAN_UI_LAYER_COORD(ch, layer) \
66 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x8)
67 #define SUN8I_MIXER_CHAN_UI_LAYER_PITCH(ch, layer) \
68 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0xc)
69 #define SUN8I_MIXER_CHAN_UI_LAYER_TOP_LADDR(ch, layer) \
70 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x10)
71 #define SUN8I_MIXER_CHAN_UI_LAYER_BOT_LADDR(ch, layer) \
72 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x14)
73 #define SUN8I_MIXER_CHAN_UI_LAYER_FCOLOR(ch, layer) \
74 			(0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x18)
75 #define SUN8I_MIXER_CHAN_UI_TOP_HADDR(ch)	(0x2000 + 0x1000 * (ch) + 0x80)
76 #define SUN8I_MIXER_CHAN_UI_BOT_HADDR(ch)	(0x2000 + 0x1000 * (ch) + 0x84)
77 #define SUN8I_MIXER_CHAN_UI_OVL_SIZE(ch)	(0x2000 + 0x1000 * (ch) + 0x88)
78 
79 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_EN		BIT(0)
80 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_ALPHA_MODE_MASK	GENMASK(2, 1)
81 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_MASK	GENMASK(12, 8)
82 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_OFFSET	8
83 #define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_ALPHA_MASK	GENMASK(31, 24)
84 
85 #define SUN8I_MIXER_FBFMT_ARGB8888	0
86 #define SUN8I_MIXER_FBFMT_XRGB8888	4
87 #define SUN8I_MIXER_FBFMT_RGB888	8
88 
89 /*
90  * These sub-engines are still unknown now, the EN registers are here only to
91  * be used to disable these sub-engines.
92  */
93 #define SUN8I_MIXER_VSU_EN			0x20000
94 #define SUN8I_MIXER_GSU1_EN			0x30000
95 #define SUN8I_MIXER_GSU2_EN			0x40000
96 #define SUN8I_MIXER_GSU3_EN			0x50000
97 #define SUN8I_MIXER_FCE_EN			0xa0000
98 #define SUN8I_MIXER_BWS_EN			0xa2000
99 #define SUN8I_MIXER_LTI_EN			0xa4000
100 #define SUN8I_MIXER_PEAK_EN			0xa6000
101 #define SUN8I_MIXER_ASE_EN			0xa8000
102 #define SUN8I_MIXER_FCC_EN			0xaa000
103 #define SUN8I_MIXER_DCSC_EN			0xb0000
104 
105 struct sun8i_mixer_cfg {
106 	int		vi_num;
107 	int		ui_num;
108 };
109 
110 struct sun8i_mixer {
111 	struct sunxi_engine		engine;
112 
113 	const struct sun8i_mixer_cfg	*cfg;
114 
115 	struct reset_control		*reset;
116 
117 	struct clk			*bus_clk;
118 	struct clk			*mod_clk;
119 };
120 
121 static inline struct sun8i_mixer *
122 engine_to_sun8i_mixer(struct sunxi_engine *engine)
123 {
124 	return container_of(engine, struct sun8i_mixer, engine);
125 }
126 
127 void sun8i_mixer_layer_enable(struct sun8i_mixer *mixer,
128 				int layer, bool enable);
129 int sun8i_mixer_update_layer_coord(struct sun8i_mixer *mixer,
130 				     int layer, struct drm_plane *plane);
131 int sun8i_mixer_update_layer_formats(struct sun8i_mixer *mixer,
132 				       int layer, struct drm_plane *plane);
133 int sun8i_mixer_update_layer_buffer(struct sun8i_mixer *mixer,
134 				      int layer, struct drm_plane *plane);
135 #endif /* _SUN8I_MIXER_H_ */
136