0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _SUN4I_BACKEND_H_
0010 #define _SUN4I_BACKEND_H_
0011
0012 #include <linux/clk.h>
0013 #include <linux/list.h>
0014 #include <linux/of.h>
0015 #include <linux/regmap.h>
0016 #include <linux/reset.h>
0017
0018 #include "sunxi_engine.h"
0019
0020 #define SUN4I_BACKEND_MODCTL_REG 0x800
0021 #define SUN4I_BACKEND_MODCTL_LINE_SEL BIT(29)
0022 #define SUN4I_BACKEND_MODCTL_ITLMOD_EN BIT(28)
0023 #define SUN4I_BACKEND_MODCTL_OUT_SEL GENMASK(22, 20)
0024 #define SUN4I_BACKEND_MODCTL_OUT_LCD0 (0 << 20)
0025 #define SUN4I_BACKEND_MODCTL_OUT_LCD1 (1 << 20)
0026 #define SUN4I_BACKEND_MODCTL_OUT_FE0 (6 << 20)
0027 #define SUN4I_BACKEND_MODCTL_OUT_FE1 (7 << 20)
0028 #define SUN4I_BACKEND_MODCTL_HWC_EN BIT(16)
0029 #define SUN4I_BACKEND_MODCTL_LAY_EN(l) BIT(8 + l)
0030 #define SUN4I_BACKEND_MODCTL_OCSC_EN BIT(5)
0031 #define SUN4I_BACKEND_MODCTL_DFLK_EN BIT(4)
0032 #define SUN4I_BACKEND_MODCTL_DLP_START_CTL BIT(2)
0033 #define SUN4I_BACKEND_MODCTL_START_CTL BIT(1)
0034 #define SUN4I_BACKEND_MODCTL_DEBE_EN BIT(0)
0035
0036 #define SUN4I_BACKEND_BACKCOLOR_REG 0x804
0037 #define SUN4I_BACKEND_BACKCOLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b))
0038
0039 #define SUN4I_BACKEND_DISSIZE_REG 0x808
0040 #define SUN4I_BACKEND_DISSIZE(w, h) (((((h) - 1) & 0xffff) << 16) | \
0041 (((w) - 1) & 0xffff))
0042
0043 #define SUN4I_BACKEND_LAYSIZE_REG(l) (0x810 + (0x4 * (l)))
0044 #define SUN4I_BACKEND_LAYSIZE(w, h) (((((h) - 1) & 0x1fff) << 16) | \
0045 (((w) - 1) & 0x1fff))
0046
0047 #define SUN4I_BACKEND_LAYCOOR_REG(l) (0x820 + (0x4 * (l)))
0048 #define SUN4I_BACKEND_LAYCOOR(x, y) ((((u32)(y) & 0xffff) << 16) | \
0049 ((u32)(x) & 0xffff))
0050
0051 #define SUN4I_BACKEND_LAYLINEWIDTH_REG(l) (0x840 + (0x4 * (l)))
0052
0053 #define SUN4I_BACKEND_LAYFB_L32ADD_REG(l) (0x850 + (0x4 * (l)))
0054
0055 #define SUN4I_BACKEND_LAYFB_H4ADD_REG 0x860
0056 #define SUN4I_BACKEND_LAYFB_H4ADD_MSK(l) GENMASK(3 + ((l) * 8), (l) * 8)
0057 #define SUN4I_BACKEND_LAYFB_H4ADD(l, val) ((val) << ((l) * 8))
0058
0059 #define SUN4I_BACKEND_REGBUFFCTL_REG 0x870
0060 #define SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS BIT(1)
0061 #define SUN4I_BACKEND_REGBUFFCTL_LOADCTL BIT(0)
0062
0063 #define SUN4I_BACKEND_CKMAX_REG 0x880
0064 #define SUN4I_BACKEND_CKMIN_REG 0x884
0065 #define SUN4I_BACKEND_CKCFG_REG 0x888
0066 #define SUN4I_BACKEND_ATTCTL_REG0(l) (0x890 + (0x4 * (l)))
0067 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA_MASK GENMASK(31, 24)
0068 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA(x) ((x) << 24)
0069 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL_MASK BIT(15)
0070 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL(x) ((x) << 15)
0071 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL_MASK GENMASK(11, 10)
0072 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL(x) ((x) << 10)
0073 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN BIT(2)
0074 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_VDOEN BIT(1)
0075 #define SUN4I_BACKEND_ATTCTL_REG0_LAY_GLBALPHA_EN BIT(0)
0076
0077 #define SUN4I_BACKEND_ATTCTL_REG1(l) (0x8a0 + (0x4 * (l)))
0078 #define SUN4I_BACKEND_ATTCTL_REG1_LAY_HSCAFCT GENMASK(15, 14)
0079 #define SUN4I_BACKEND_ATTCTL_REG1_LAY_WSCAFCT GENMASK(13, 12)
0080 #define SUN4I_BACKEND_ATTCTL_REG1_LAY_FBFMT GENMASK(11, 8)
0081 #define SUN4I_BACKEND_LAY_FBFMT_1BPP (0 << 8)
0082 #define SUN4I_BACKEND_LAY_FBFMT_2BPP (1 << 8)
0083 #define SUN4I_BACKEND_LAY_FBFMT_4BPP (2 << 8)
0084 #define SUN4I_BACKEND_LAY_FBFMT_8BPP (3 << 8)
0085 #define SUN4I_BACKEND_LAY_FBFMT_RGB655 (4 << 8)
0086 #define SUN4I_BACKEND_LAY_FBFMT_RGB565 (5 << 8)
0087 #define SUN4I_BACKEND_LAY_FBFMT_RGB556 (6 << 8)
0088 #define SUN4I_BACKEND_LAY_FBFMT_ARGB1555 (7 << 8)
0089 #define SUN4I_BACKEND_LAY_FBFMT_RGBA5551 (8 << 8)
0090 #define SUN4I_BACKEND_LAY_FBFMT_XRGB8888 (9 << 8)
0091 #define SUN4I_BACKEND_LAY_FBFMT_ARGB8888 (10 << 8)
0092 #define SUN4I_BACKEND_LAY_FBFMT_RGB888 (11 << 8)
0093 #define SUN4I_BACKEND_LAY_FBFMT_ARGB4444 (12 << 8)
0094 #define SUN4I_BACKEND_LAY_FBFMT_RGBA4444 (13 << 8)
0095
0096 #define SUN4I_BACKEND_DLCDPCTL_REG 0x8b0
0097 #define SUN4I_BACKEND_DLCDPFRMBUF_ADDRCTL_REG 0x8b4
0098 #define SUN4I_BACKEND_DLCDPCOOR_REG0 0x8b8
0099 #define SUN4I_BACKEND_DLCDPCOOR_REG1 0x8bc
0100
0101 #define SUN4I_BACKEND_INT_EN_REG 0x8c0
0102 #define SUN4I_BACKEND_INT_FLAG_REG 0x8c4
0103 #define SUN4I_BACKEND_REG_LOAD_FINISHED BIT(1)
0104
0105 #define SUN4I_BACKEND_HWCCTL_REG 0x8d8
0106 #define SUN4I_BACKEND_HWCFBCTL_REG 0x8e0
0107 #define SUN4I_BACKEND_WBCTL_REG 0x8f0
0108 #define SUN4I_BACKEND_WBADD_REG 0x8f4
0109 #define SUN4I_BACKEND_WBLINEWIDTH_REG 0x8f8
0110 #define SUN4I_BACKEND_SPREN_REG 0x900
0111 #define SUN4I_BACKEND_SPRFMTCTL_REG 0x908
0112 #define SUN4I_BACKEND_SPRALPHACTL_REG 0x90c
0113
0114 #define SUN4I_BACKEND_IYUVCTL_REG 0x920
0115 #define SUN4I_BACKEND_IYUVCTL_FBFMT_MASK GENMASK(14, 12)
0116 #define SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV444 (4 << 12)
0117 #define SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422 (3 << 12)
0118 #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV444 (2 << 12)
0119 #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV222 (1 << 12)
0120 #define SUN4I_BACKEND_IYUVCTL_FBFMT_PLANAR_YUV111 (0 << 12)
0121 #define SUN4I_BACKEND_IYUVCTL_FBPS_MASK GENMASK(9, 8)
0122 #define SUN4I_BACKEND_IYUVCTL_FBPS_YVYU (3 << 8)
0123 #define SUN4I_BACKEND_IYUVCTL_FBPS_VYUY (2 << 8)
0124 #define SUN4I_BACKEND_IYUVCTL_FBPS_YUYV (1 << 8)
0125 #define SUN4I_BACKEND_IYUVCTL_FBPS_UYVY (0 << 8)
0126 #define SUN4I_BACKEND_IYUVCTL_FBPS_VUYA (1 << 8)
0127 #define SUN4I_BACKEND_IYUVCTL_FBPS_AYUV (0 << 8)
0128 #define SUN4I_BACKEND_IYUVCTL_EN BIT(0)
0129
0130 #define SUN4I_BACKEND_IYUVADD_REG(c) (0x930 + (0x4 * (c)))
0131
0132 #define SUN4I_BACKEND_IYUVLINEWIDTH_REG(c) (0x940 + (0x4 * (c)))
0133
0134 #define SUN4I_BACKEND_YGCOEF_REG(c) (0x950 + (0x4 * (c)))
0135 #define SUN4I_BACKEND_YGCONS_REG 0x95c
0136 #define SUN4I_BACKEND_URCOEF_REG(c) (0x960 + (0x4 * (c)))
0137 #define SUN4I_BACKEND_URCONS_REG 0x96c
0138 #define SUN4I_BACKEND_VBCOEF_REG(c) (0x970 + (0x4 * (c)))
0139 #define SUN4I_BACKEND_VBCONS_REG 0x97c
0140 #define SUN4I_BACKEND_KSCTL_REG 0x980
0141 #define SUN4I_BACKEND_KSBKCOLOR_REG 0x984
0142 #define SUN4I_BACKEND_KSFSTLINEWIDTH_REG 0x988
0143 #define SUN4I_BACKEND_KSVSCAFCT_REG 0x98c
0144 #define SUN4I_BACKEND_KSHSCACOEF_REG(x) (0x9a0 + (0x4 * (x)))
0145 #define SUN4I_BACKEND_OCCTL_REG 0x9c0
0146 #define SUN4I_BACKEND_OCCTL_ENABLE BIT(0)
0147
0148 #define SUN4I_BACKEND_OCRCOEF_REG(x) (0x9d0 + (0x4 * (x)))
0149 #define SUN4I_BACKEND_OCRCONS_REG 0x9dc
0150 #define SUN4I_BACKEND_OCGCOEF_REG(x) (0x9e0 + (0x4 * (x)))
0151 #define SUN4I_BACKEND_OCGCONS_REG 0x9ec
0152 #define SUN4I_BACKEND_OCBCOEF_REG(x) (0x9f0 + (0x4 * (x)))
0153 #define SUN4I_BACKEND_OCBCONS_REG 0x9fc
0154 #define SUN4I_BACKEND_SPRCOORCTL_REG(s) (0xa00 + (0x4 * (s)))
0155 #define SUN4I_BACKEND_SPRATTCTL_REG(s) (0xb00 + (0x4 * (s)))
0156 #define SUN4I_BACKEND_SPRADD_REG(s) (0xc00 + (0x4 * (s)))
0157 #define SUN4I_BACKEND_SPRLINEWIDTH_REG(s) (0xd00 + (0x4 * (s)))
0158
0159 #define SUN4I_BACKEND_SPRPALTAB_OFF 0x4000
0160 #define SUN4I_BACKEND_GAMMATAB_OFF 0x4400
0161 #define SUN4I_BACKEND_HWCPATTERN_OFF 0x4800
0162 #define SUN4I_BACKEND_HWCCOLORTAB_OFF 0x4c00
0163 #define SUN4I_BACKEND_PIPE_OFF(p) (0x5000 + (0x400 * (p)))
0164
0165 #define SUN4I_BACKEND_NUM_LAYERS 4
0166 #define SUN4I_BACKEND_NUM_FRONTEND_LAYERS 1
0167 #define SUN4I_BACKEND_NUM_YUV_PLANES 1
0168
0169 struct sun4i_backend {
0170 struct sunxi_engine engine;
0171 struct sun4i_frontend *frontend;
0172
0173 struct reset_control *reset;
0174
0175 struct clk *bus_clk;
0176 struct clk *mod_clk;
0177 struct clk *ram_clk;
0178
0179 struct clk *sat_clk;
0180 struct reset_control *sat_reset;
0181
0182
0183 spinlock_t frontend_lock;
0184 bool frontend_teardown;
0185
0186 const struct sun4i_backend_quirks *quirks;
0187 };
0188
0189 static inline struct sun4i_backend *
0190 engine_to_sun4i_backend(struct sunxi_engine *engine)
0191 {
0192 return container_of(engine, struct sun4i_backend, engine);
0193 }
0194
0195 void sun4i_backend_layer_enable(struct sun4i_backend *backend,
0196 int layer, bool enable);
0197 bool sun4i_backend_format_is_supported(uint32_t fmt, uint64_t modifier);
0198 int sun4i_backend_update_layer_coord(struct sun4i_backend *backend,
0199 int layer, struct drm_plane *plane);
0200 int sun4i_backend_update_layer_formats(struct sun4i_backend *backend,
0201 int layer, struct drm_plane *plane);
0202 int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend,
0203 int layer, struct drm_plane *plane);
0204 int sun4i_backend_update_layer_frontend(struct sun4i_backend *backend,
0205 int layer, uint32_t in_fmt);
0206 int sun4i_backend_update_layer_zpos(struct sun4i_backend *backend,
0207 int layer, struct drm_plane *plane);
0208 void sun4i_backend_cleanup_layer(struct sun4i_backend *backend,
0209 int layer);
0210
0211 #endif