18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io> 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _SUN8I_MIXER_H_ 78c2ecf20Sopenharmony_ci#define _SUN8I_MIXER_H_ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/clk.h> 108c2ecf20Sopenharmony_ci#include <linux/regmap.h> 118c2ecf20Sopenharmony_ci#include <linux/reset.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "sunxi_engine.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#define SUN8I_MIXER_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1)) 168c2ecf20Sopenharmony_ci#define SUN8I_MIXER_COORD(x, y) ((y) << 16 | (x)) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_CTL 0x0 198c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_STATUS 0x4 208c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_DBUFF 0x8 218c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_SIZE 0xc 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_CTL_RT_EN BIT(0) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_DBUFF_ENABLE BIT(0) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define DE2_MIXER_UNIT_SIZE 0x6000 288c2ecf20Sopenharmony_ci#define DE3_MIXER_UNIT_SIZE 0x3000 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci#define DE2_BLD_BASE 0x1000 318c2ecf20Sopenharmony_ci#define DE2_CH_BASE 0x2000 328c2ecf20Sopenharmony_ci#define DE2_CH_SIZE 0x1000 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define DE3_BLD_BASE 0x0800 358c2ecf20Sopenharmony_ci#define DE3_CH_BASE 0x1000 368c2ecf20Sopenharmony_ci#define DE3_CH_SIZE 0x0800 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL(base) ((base) + 0) 398c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_FCOLOR(base, x) ((base) + 0x4 + 0x10 * (x)) 408c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_INSIZE(base, x) ((base) + 0x8 + 0x10 * (x)) 418c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_COORD(base, x) ((base) + 0xc + 0x10 * (x)) 428c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE(base) ((base) + 0x80) 438c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_PREMULTIPLY(base) ((base) + 0x84) 448c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_BKCOLOR(base) ((base) + 0x88) 458c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTSIZE(base) ((base) + 0x8c) 468c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_MODE(base, x) ((base) + 0x90 + 0x04 * (x)) 478c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_CTL(base) ((base) + 0xb0) 488c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_CFG(base) ((base) + 0xb4) 498c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_MAX(base, x) ((base) + 0xc0 + 0x04 * (x)) 508c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_MIN(base, x) ((base) + 0xe0 + 0x04 * (x)) 518c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTCTL(base) ((base) + 0xfc) 528c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CTL(base) ((base) + 0x100) 538c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_COEFF(base, layer, x, y) \ 548c2ecf20Sopenharmony_ci ((base) + 0x110 + (layer) * 0x30 + (x) * 0x10 + 4 * (y)) 558c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CONST(base, layer, i) \ 568c2ecf20Sopenharmony_ci ((base) + 0x110 + (layer) * 0x30 + (i) * 0x10 + 0x0c) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_EN_MSK GENMASK(12, 8) 598c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_EN(pipe) BIT(8 + pipe) 608c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_FC_EN(pipe) BIT(pipe) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* colors are always in AARRGGBB format */ 638c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_COLOR_BLACK 0xff000000 648c2ecf20Sopenharmony_ci/* The following numbers are some still unknown magic numbers */ 658c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_MODE_DEF 0x03010301 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE_PIPE_MSK(n) (0xf << ((n) << 2)) 688c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE_PIPE_SHIFT(n) ((n) << 2) 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTCTL_INTERLACED BIT(1) 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CTL_EN(ch) BIT(ch) 738c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CONST_VAL(d, c) (((d) << 16) | ((c) & 0xffff)) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB8888 0 768c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR8888 1 778c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA8888 2 788c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA8888 3 798c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_XRGB8888 4 808c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_XBGR8888 5 818c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBX8888 6 828c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRX8888 7 838c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGB888 8 848c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGR888 9 858c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGB565 10 868c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGR565 11 878c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB4444 12 888c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR4444 13 898c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA4444 14 908c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA4444 15 918c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB1555 16 928c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR1555 17 938c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA5551 18 948c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA5551 19 958c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB2101010 20 968c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR2101010 21 978c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA1010102 22 988c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA1010102 23 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUYV 0 1018c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_UYVY 1 1028c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YVYU 2 1038c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_VYUY 3 1048c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV16 4 1058c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV61 5 1068c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV422 6 1078c2ecf20Sopenharmony_ci/* format 7 doesn't exist */ 1088c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV12 8 1098c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV21 9 1108c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV420 10 1118c2ecf20Sopenharmony_ci/* format 11 doesn't exist */ 1128c2ecf20Sopenharmony_ci/* format 12 is semi-planar YUV411 UVUV */ 1138c2ecf20Sopenharmony_ci/* format 13 is semi-planar YUV411 VUVU */ 1148c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV411 14 1158c2ecf20Sopenharmony_ci/* format 15 doesn't exist */ 1168c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_P010_YUV 16 1178c2ecf20Sopenharmony_ci/* format 17 is P010 YVU */ 1188c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FBFMT_P210_YUV 18 1198c2ecf20Sopenharmony_ci/* format 19 is P210 YVU */ 1208c2ecf20Sopenharmony_ci/* format 20 is packed YVU444 10-bit */ 1218c2ecf20Sopenharmony_ci/* format 21 is packed YUV444 10-bit */ 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* 1248c2ecf20Sopenharmony_ci * Sub-engines listed bellow are unused for now. The EN registers are here only 1258c2ecf20Sopenharmony_ci * to be used to disable these sub-engines. 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FCE_EN 0xa0000 1288c2ecf20Sopenharmony_ci#define SUN8I_MIXER_BWS_EN 0xa2000 1298c2ecf20Sopenharmony_ci#define SUN8I_MIXER_LTI_EN 0xa4000 1308c2ecf20Sopenharmony_ci#define SUN8I_MIXER_PEAK_EN 0xa6000 1318c2ecf20Sopenharmony_ci#define SUN8I_MIXER_ASE_EN 0xa8000 1328c2ecf20Sopenharmony_ci#define SUN8I_MIXER_FCC_EN 0xaa000 1338c2ecf20Sopenharmony_ci#define SUN8I_MIXER_DCSC_EN 0xb0000 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci#define SUN50I_MIXER_FCE_EN 0x70000 1368c2ecf20Sopenharmony_ci#define SUN50I_MIXER_PEAK_EN 0x70800 1378c2ecf20Sopenharmony_ci#define SUN50I_MIXER_LCTI_EN 0x71000 1388c2ecf20Sopenharmony_ci#define SUN50I_MIXER_BLS_EN 0x71800 1398c2ecf20Sopenharmony_ci#define SUN50I_MIXER_FCC_EN 0x72000 1408c2ecf20Sopenharmony_ci#define SUN50I_MIXER_DNS_EN 0x80000 1418c2ecf20Sopenharmony_ci#define SUN50I_MIXER_DRC_EN 0xa0000 1428c2ecf20Sopenharmony_ci#define SUN50I_MIXER_FMT_EN 0xa8000 1438c2ecf20Sopenharmony_ci#define SUN50I_MIXER_CDC0_EN 0xd0000 1448c2ecf20Sopenharmony_ci#define SUN50I_MIXER_CDC1_EN 0xd8000 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/** 1478c2ecf20Sopenharmony_ci * struct sun8i_mixer_cfg - mixer HW configuration 1488c2ecf20Sopenharmony_ci * @vi_num: number of VI channels 1498c2ecf20Sopenharmony_ci * @ui_num: number of UI channels 1508c2ecf20Sopenharmony_ci * @scaler_mask: bitmask which tells which channel supports scaling 1518c2ecf20Sopenharmony_ci * First, scaler supports for VI channels is defined and after that, scaler 1528c2ecf20Sopenharmony_ci * support for UI channels. For example, if mixer has 2 VI channels without 1538c2ecf20Sopenharmony_ci * scaler and 2 UI channels with scaler, bitmask would be 0xC. 1548c2ecf20Sopenharmony_ci * @ccsc: select set of CCSC base addresses 1558c2ecf20Sopenharmony_ci * Set value to 0 if this is first mixer or second mixer with VEP support. 1568c2ecf20Sopenharmony_ci * Set value to 1 if this is second mixer without VEP support. Other values 1578c2ecf20Sopenharmony_ci * are invalid. 1588c2ecf20Sopenharmony_ci * @mod_rate: module clock rate that needs to be set in order to have 1598c2ecf20Sopenharmony_ci * a functional block. 1608c2ecf20Sopenharmony_ci * @is_de3: true, if this is next gen display engine 3.0, false otherwise. 1618c2ecf20Sopenharmony_ci * @scaline_yuv: size of a scanline for VI scaler for YUV formats. 1628c2ecf20Sopenharmony_ci */ 1638c2ecf20Sopenharmony_cistruct sun8i_mixer_cfg { 1648c2ecf20Sopenharmony_ci int vi_num; 1658c2ecf20Sopenharmony_ci int ui_num; 1668c2ecf20Sopenharmony_ci int scaler_mask; 1678c2ecf20Sopenharmony_ci int ccsc; 1688c2ecf20Sopenharmony_ci unsigned long mod_rate; 1698c2ecf20Sopenharmony_ci unsigned int is_de3 : 1; 1708c2ecf20Sopenharmony_ci unsigned int scanline_yuv; 1718c2ecf20Sopenharmony_ci}; 1728c2ecf20Sopenharmony_ci 1738c2ecf20Sopenharmony_cistruct sun8i_mixer { 1748c2ecf20Sopenharmony_ci struct sunxi_engine engine; 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci const struct sun8i_mixer_cfg *cfg; 1778c2ecf20Sopenharmony_ci 1788c2ecf20Sopenharmony_ci struct reset_control *reset; 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci struct clk *bus_clk; 1818c2ecf20Sopenharmony_ci struct clk *mod_clk; 1828c2ecf20Sopenharmony_ci}; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic inline struct sun8i_mixer * 1858c2ecf20Sopenharmony_ciengine_to_sun8i_mixer(struct sunxi_engine *engine) 1868c2ecf20Sopenharmony_ci{ 1878c2ecf20Sopenharmony_ci return container_of(engine, struct sun8i_mixer, engine); 1888c2ecf20Sopenharmony_ci} 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_cistatic inline u32 1918c2ecf20Sopenharmony_cisun8i_blender_base(struct sun8i_mixer *mixer) 1928c2ecf20Sopenharmony_ci{ 1938c2ecf20Sopenharmony_ci return mixer->cfg->is_de3 ? DE3_BLD_BASE : DE2_BLD_BASE; 1948c2ecf20Sopenharmony_ci} 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic inline u32 1978c2ecf20Sopenharmony_cisun8i_channel_base(struct sun8i_mixer *mixer, int channel) 1988c2ecf20Sopenharmony_ci{ 1998c2ecf20Sopenharmony_ci if (mixer->cfg->is_de3) 2008c2ecf20Sopenharmony_ci return DE3_CH_BASE + channel * DE3_CH_SIZE; 2018c2ecf20Sopenharmony_ci else 2028c2ecf20Sopenharmony_ci return DE2_CH_BASE + channel * DE2_CH_SIZE; 2038c2ecf20Sopenharmony_ci} 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ciint sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format); 2068c2ecf20Sopenharmony_ci#endif /* _SUN8I_MIXER_H_ */ 207