blob: 76f0b2bd91e264e9018c754ab5945c1ebd6adb62 [file] [log] [blame]
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +08001/*
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
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080019#define SUN8I_MIXER_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1))
20#define SUN8I_MIXER_COORD(x, y) ((y) << 16 | (x))
21
22#define SUN8I_MIXER_GLOBAL_CTL 0x0
23#define SUN8I_MIXER_GLOBAL_STATUS 0x4
24#define SUN8I_MIXER_GLOBAL_DBUFF 0x8
25#define SUN8I_MIXER_GLOBAL_SIZE 0xc
26
Jernej Skrabecbb940be2017-12-01 07:05:31 +010027#define SUN8I_MIXER_GLOBAL_CTL_RT_EN BIT(0)
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080028
Jernej Skrabecbb940be2017-12-01 07:05:31 +010029#define SUN8I_MIXER_GLOBAL_DBUFF_ENABLE BIT(0)
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080030
Jernej Skrabecbb940be2017-12-01 07:05:31 +010031#define SUN8I_MIXER_BLEND_PIPE_CTL 0x1000
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080032#define SUN8I_MIXER_BLEND_ATTR_FCOLOR(x) (0x1004 + 0x10 * (x) + 0x0)
33#define SUN8I_MIXER_BLEND_ATTR_INSIZE(x) (0x1004 + 0x10 * (x) + 0x4)
Jernej Skrabecbb940be2017-12-01 07:05:31 +010034#define SUN8I_MIXER_BLEND_ATTR_COORD(x) (0x1004 + 0x10 * (x) + 0x8)
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080035#define SUN8I_MIXER_BLEND_ROUTE 0x1080
36#define SUN8I_MIXER_BLEND_PREMULTIPLY 0x1084
37#define SUN8I_MIXER_BLEND_BKCOLOR 0x1088
38#define SUN8I_MIXER_BLEND_OUTSIZE 0x108c
39#define SUN8I_MIXER_BLEND_MODE(x) (0x1090 + 0x04 * (x))
40#define SUN8I_MIXER_BLEND_CK_CTL 0x10b0
41#define SUN8I_MIXER_BLEND_CK_CFG 0x10b4
42#define SUN8I_MIXER_BLEND_CK_MAX(x) (0x10c0 + 0x04 * (x))
43#define SUN8I_MIXER_BLEND_CK_MIN(x) (0x10e0 + 0x04 * (x))
44#define SUN8I_MIXER_BLEND_OUTCTL 0x10fc
45
Jernej Skrabecbb940be2017-12-01 07:05:31 +010046#define SUN8I_MIXER_BLEND_PIPE_CTL_EN(pipe) BIT(8 + pipe)
47#define SUN8I_MIXER_BLEND_PIPE_CTL_FC_EN(pipe) BIT(pipe)
Jernej Skrabec2f4cffe2017-12-01 07:05:29 +010048/* colors are always in AARRGGBB format */
49#define SUN8I_MIXER_BLEND_COLOR_BLACK 0xff000000
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080050/* The following numbers are some still unknown magic numbers */
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080051#define SUN8I_MIXER_BLEND_MODE_DEF 0x03010301
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080052
53#define SUN8I_MIXER_BLEND_OUTCTL_INTERLACED BIT(1)
54
55/*
56 * VI channels are not used now, but the support of them may be introduced in
57 * the future.
58 */
59
60#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR(ch, layer) \
61 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x0)
62#define SUN8I_MIXER_CHAN_UI_LAYER_SIZE(ch, layer) \
63 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x4)
64#define SUN8I_MIXER_CHAN_UI_LAYER_COORD(ch, layer) \
65 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x8)
66#define SUN8I_MIXER_CHAN_UI_LAYER_PITCH(ch, layer) \
67 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0xc)
68#define SUN8I_MIXER_CHAN_UI_LAYER_TOP_LADDR(ch, layer) \
69 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x10)
70#define SUN8I_MIXER_CHAN_UI_LAYER_BOT_LADDR(ch, layer) \
71 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x14)
72#define SUN8I_MIXER_CHAN_UI_LAYER_FCOLOR(ch, layer) \
73 (0x2000 + 0x1000 * (ch) + 0x20 * (layer) + 0x18)
74#define SUN8I_MIXER_CHAN_UI_TOP_HADDR(ch) (0x2000 + 0x1000 * (ch) + 0x80)
75#define SUN8I_MIXER_CHAN_UI_BOT_HADDR(ch) (0x2000 + 0x1000 * (ch) + 0x84)
76#define SUN8I_MIXER_CHAN_UI_OVL_SIZE(ch) (0x2000 + 0x1000 * (ch) + 0x88)
77
78#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_EN BIT(0)
79#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_ALPHA_MODE_MASK GENMASK(2, 1)
Jernej Skrabeca2407f42017-12-01 07:05:24 +010080#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_MASK GENMASK(12, 8)
Jernej Skrabeccbd2b692017-12-01 07:05:25 +010081#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_FBFMT_OFFSET 8
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080082#define SUN8I_MIXER_CHAN_UI_LAYER_ATTR_ALPHA_MASK GENMASK(31, 24)
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080083
Jernej Skrabeccbd2b692017-12-01 07:05:25 +010084#define SUN8I_MIXER_FBFMT_ARGB8888 0
85#define SUN8I_MIXER_FBFMT_XRGB8888 4
86#define SUN8I_MIXER_FBFMT_RGB888 8
87
Icenowy Zheng9d75b8c2017-05-17 22:47:20 +080088/*
89 * These sub-engines are still unknown now, the EN registers are here only to
90 * be used to disable these sub-engines.
91 */
92#define SUN8I_MIXER_VSU_EN 0x20000
93#define SUN8I_MIXER_GSU1_EN 0x30000
94#define SUN8I_MIXER_GSU2_EN 0x40000
95#define SUN8I_MIXER_GSU3_EN 0x50000
96#define SUN8I_MIXER_FCE_EN 0xa0000
97#define SUN8I_MIXER_BWS_EN 0xa2000
98#define SUN8I_MIXER_LTI_EN 0xa4000
99#define SUN8I_MIXER_PEAK_EN 0xa6000
100#define SUN8I_MIXER_ASE_EN 0xa8000
101#define SUN8I_MIXER_FCC_EN 0xaa000
102#define SUN8I_MIXER_DCSC_EN 0xb0000
103
104struct sun8i_mixer_cfg {
105 int vi_num;
106 int ui_num;
107};
108
109struct sun8i_mixer {
110 struct sunxi_engine engine;
111
112 const struct sun8i_mixer_cfg *cfg;
113
114 struct reset_control *reset;
115
116 struct clk *bus_clk;
117 struct clk *mod_clk;
118};
119
120static inline struct sun8i_mixer *
121engine_to_sun8i_mixer(struct sunxi_engine *engine)
122{
123 return container_of(engine, struct sun8i_mixer, engine);
124}
125
126void sun8i_mixer_layer_enable(struct sun8i_mixer *mixer,
127 int layer, bool enable);
128int sun8i_mixer_update_layer_coord(struct sun8i_mixer *mixer,
129 int layer, struct drm_plane *plane);
130int sun8i_mixer_update_layer_formats(struct sun8i_mixer *mixer,
131 int layer, struct drm_plane *plane);
132int sun8i_mixer_update_layer_buffer(struct sun8i_mixer *mixer,
133 int layer, struct drm_plane *plane);
134#endif /* _SUN8I_MIXER_H_ */