162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2017 Icenowy Zheng <icenowy@aosc.io> 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _SUN8I_MIXER_H_ 762306a36Sopenharmony_ci#define _SUN8I_MIXER_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/clk.h> 1062306a36Sopenharmony_ci#include <linux/regmap.h> 1162306a36Sopenharmony_ci#include <linux/reset.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include "sunxi_engine.h" 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define SUN8I_MIXER_SIZE(w, h) (((h) - 1) << 16 | ((w) - 1)) 1662306a36Sopenharmony_ci#define SUN8I_MIXER_COORD(x, y) ((y) << 16 | (x)) 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_CTL 0x0 1962306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_STATUS 0x4 2062306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_DBUFF 0x8 2162306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_SIZE 0xc 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_CTL_RT_EN BIT(0) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define SUN8I_MIXER_GLOBAL_DBUFF_ENABLE BIT(0) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define DE2_MIXER_UNIT_SIZE 0x6000 2862306a36Sopenharmony_ci#define DE3_MIXER_UNIT_SIZE 0x3000 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define DE2_BLD_BASE 0x1000 3162306a36Sopenharmony_ci#define DE2_CH_BASE 0x2000 3262306a36Sopenharmony_ci#define DE2_CH_SIZE 0x1000 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define DE3_BLD_BASE 0x0800 3562306a36Sopenharmony_ci#define DE3_CH_BASE 0x1000 3662306a36Sopenharmony_ci#define DE3_CH_SIZE 0x0800 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL(base) ((base) + 0) 3962306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_FCOLOR(base, x) ((base) + 0x4 + 0x10 * (x)) 4062306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_INSIZE(base, x) ((base) + 0x8 + 0x10 * (x)) 4162306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ATTR_COORD(base, x) ((base) + 0xc + 0x10 * (x)) 4262306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE(base) ((base) + 0x80) 4362306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_PREMULTIPLY(base) ((base) + 0x84) 4462306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_BKCOLOR(base) ((base) + 0x88) 4562306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTSIZE(base) ((base) + 0x8c) 4662306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_MODE(base, x) ((base) + 0x90 + 0x04 * (x)) 4762306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_CTL(base) ((base) + 0xb0) 4862306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_CFG(base) ((base) + 0xb4) 4962306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_MAX(base, x) ((base) + 0xc0 + 0x04 * (x)) 5062306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_CK_MIN(base, x) ((base) + 0xe0 + 0x04 * (x)) 5162306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTCTL(base) ((base) + 0xfc) 5262306a36Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CTL(base) ((base) + 0x100) 5362306a36Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_COEFF(base, layer, x) \ 5462306a36Sopenharmony_ci ((base) + 0x110 + (layer) * 0x30 + (x) * 4) 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_EN_MSK GENMASK(12, 8) 5762306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_EN(pipe) BIT(8 + pipe) 5862306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_PIPE_CTL_FC_EN(pipe) BIT(pipe) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci/* colors are always in AARRGGBB format */ 6162306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_COLOR_BLACK 0xff000000 6262306a36Sopenharmony_ci/* The following numbers are some still unknown magic numbers */ 6362306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_MODE_DEF 0x03010301 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE_PIPE_MSK(n) (0xf << ((n) << 2)) 6662306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_ROUTE_PIPE_SHIFT(n) ((n) << 2) 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#define SUN8I_MIXER_BLEND_OUTCTL_INTERLACED BIT(1) 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CTL_EN(ch) BIT(ch) 7162306a36Sopenharmony_ci#define SUN50I_MIXER_BLEND_CSC_CONST_VAL(d, c) (((d) << 16) | ((c) & 0xffff)) 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB8888 0 7462306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR8888 1 7562306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA8888 2 7662306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA8888 3 7762306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_XRGB8888 4 7862306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_XBGR8888 5 7962306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBX8888 6 8062306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRX8888 7 8162306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGB888 8 8262306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGR888 9 8362306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGB565 10 8462306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGR565 11 8562306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB4444 12 8662306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR4444 13 8762306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA4444 14 8862306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA4444 15 8962306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB1555 16 9062306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR1555 17 9162306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA5551 18 9262306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA5551 19 9362306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ARGB2101010 20 9462306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_ABGR2101010 21 9562306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_RGBA1010102 22 9662306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_BGRA1010102 23 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUYV 0 9962306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_UYVY 1 10062306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YVYU 2 10162306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_VYUY 3 10262306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV16 4 10362306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV61 5 10462306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV422 6 10562306a36Sopenharmony_ci/* format 7 doesn't exist */ 10662306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV12 8 10762306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_NV21 9 10862306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV420 10 10962306a36Sopenharmony_ci/* format 11 doesn't exist */ 11062306a36Sopenharmony_ci/* format 12 is semi-planar YUV411 UVUV */ 11162306a36Sopenharmony_ci/* format 13 is semi-planar YUV411 VUVU */ 11262306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_YUV411 14 11362306a36Sopenharmony_ci/* format 15 doesn't exist */ 11462306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_P010_YUV 16 11562306a36Sopenharmony_ci/* format 17 is P010 YVU */ 11662306a36Sopenharmony_ci#define SUN8I_MIXER_FBFMT_P210_YUV 18 11762306a36Sopenharmony_ci/* format 19 is P210 YVU */ 11862306a36Sopenharmony_ci/* format 20 is packed YVU444 10-bit */ 11962306a36Sopenharmony_ci/* format 21 is packed YUV444 10-bit */ 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/* 12262306a36Sopenharmony_ci * Sub-engines listed bellow are unused for now. The EN registers are here only 12362306a36Sopenharmony_ci * to be used to disable these sub-engines. 12462306a36Sopenharmony_ci */ 12562306a36Sopenharmony_ci#define SUN8I_MIXER_FCE_EN 0xa0000 12662306a36Sopenharmony_ci#define SUN8I_MIXER_BWS_EN 0xa2000 12762306a36Sopenharmony_ci#define SUN8I_MIXER_LTI_EN 0xa4000 12862306a36Sopenharmony_ci#define SUN8I_MIXER_PEAK_EN 0xa6000 12962306a36Sopenharmony_ci#define SUN8I_MIXER_ASE_EN 0xa8000 13062306a36Sopenharmony_ci#define SUN8I_MIXER_FCC_EN 0xaa000 13162306a36Sopenharmony_ci#define SUN8I_MIXER_DCSC_EN 0xb0000 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci#define SUN50I_MIXER_FCE_EN 0x70000 13462306a36Sopenharmony_ci#define SUN50I_MIXER_PEAK_EN 0x70800 13562306a36Sopenharmony_ci#define SUN50I_MIXER_LCTI_EN 0x71000 13662306a36Sopenharmony_ci#define SUN50I_MIXER_BLS_EN 0x71800 13762306a36Sopenharmony_ci#define SUN50I_MIXER_FCC_EN 0x72000 13862306a36Sopenharmony_ci#define SUN50I_MIXER_DNS_EN 0x80000 13962306a36Sopenharmony_ci#define SUN50I_MIXER_DRC_EN 0xa0000 14062306a36Sopenharmony_ci#define SUN50I_MIXER_FMT_EN 0xa8000 14162306a36Sopenharmony_ci#define SUN50I_MIXER_CDC0_EN 0xd0000 14262306a36Sopenharmony_ci#define SUN50I_MIXER_CDC1_EN 0xd8000 14362306a36Sopenharmony_ci 14462306a36Sopenharmony_cienum { 14562306a36Sopenharmony_ci /* First mixer or second mixer with VEP support. */ 14662306a36Sopenharmony_ci CCSC_MIXER0_LAYOUT, 14762306a36Sopenharmony_ci /* Second mixer without VEP support. */ 14862306a36Sopenharmony_ci CCSC_MIXER1_LAYOUT, 14962306a36Sopenharmony_ci /* First mixer with the MMIO layout found in the D1 SoC. */ 15062306a36Sopenharmony_ci CCSC_D1_MIXER0_LAYOUT, 15162306a36Sopenharmony_ci}; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_ci/** 15462306a36Sopenharmony_ci * struct sun8i_mixer_cfg - mixer HW configuration 15562306a36Sopenharmony_ci * @vi_num: number of VI channels 15662306a36Sopenharmony_ci * @ui_num: number of UI channels 15762306a36Sopenharmony_ci * @scaler_mask: bitmask which tells which channel supports scaling 15862306a36Sopenharmony_ci * First, scaler supports for VI channels is defined and after that, scaler 15962306a36Sopenharmony_ci * support for UI channels. For example, if mixer has 2 VI channels without 16062306a36Sopenharmony_ci * scaler and 2 UI channels with scaler, bitmask would be 0xC. 16162306a36Sopenharmony_ci * @ccsc: select set of CCSC base addresses from the enumeration above. 16262306a36Sopenharmony_ci * @mod_rate: module clock rate that needs to be set in order to have 16362306a36Sopenharmony_ci * a functional block. 16462306a36Sopenharmony_ci * @is_de3: true, if this is next gen display engine 3.0, false otherwise. 16562306a36Sopenharmony_ci * @scaline_yuv: size of a scanline for VI scaler for YUV formats. 16662306a36Sopenharmony_ci */ 16762306a36Sopenharmony_cistruct sun8i_mixer_cfg { 16862306a36Sopenharmony_ci int vi_num; 16962306a36Sopenharmony_ci int ui_num; 17062306a36Sopenharmony_ci int scaler_mask; 17162306a36Sopenharmony_ci int ccsc; 17262306a36Sopenharmony_ci unsigned long mod_rate; 17362306a36Sopenharmony_ci unsigned int is_de3 : 1; 17462306a36Sopenharmony_ci unsigned int scanline_yuv; 17562306a36Sopenharmony_ci}; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_cistruct sun8i_mixer { 17862306a36Sopenharmony_ci struct sunxi_engine engine; 17962306a36Sopenharmony_ci 18062306a36Sopenharmony_ci const struct sun8i_mixer_cfg *cfg; 18162306a36Sopenharmony_ci 18262306a36Sopenharmony_ci struct reset_control *reset; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci struct clk *bus_clk; 18562306a36Sopenharmony_ci struct clk *mod_clk; 18662306a36Sopenharmony_ci}; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_cistatic inline struct sun8i_mixer * 18962306a36Sopenharmony_ciengine_to_sun8i_mixer(struct sunxi_engine *engine) 19062306a36Sopenharmony_ci{ 19162306a36Sopenharmony_ci return container_of(engine, struct sun8i_mixer, engine); 19262306a36Sopenharmony_ci} 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cistatic inline u32 19562306a36Sopenharmony_cisun8i_blender_base(struct sun8i_mixer *mixer) 19662306a36Sopenharmony_ci{ 19762306a36Sopenharmony_ci return mixer->cfg->is_de3 ? DE3_BLD_BASE : DE2_BLD_BASE; 19862306a36Sopenharmony_ci} 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_cistatic inline u32 20162306a36Sopenharmony_cisun8i_channel_base(struct sun8i_mixer *mixer, int channel) 20262306a36Sopenharmony_ci{ 20362306a36Sopenharmony_ci if (mixer->cfg->is_de3) 20462306a36Sopenharmony_ci return DE3_CH_BASE + channel * DE3_CH_SIZE; 20562306a36Sopenharmony_ci else 20662306a36Sopenharmony_ci return DE2_CH_BASE + channel * DE2_CH_SIZE; 20762306a36Sopenharmony_ci} 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_ciint sun8i_mixer_drm_format_to_hw(u32 format, u32 *hw_format); 21062306a36Sopenharmony_ci#endif /* _SUN8I_MIXER_H_ */ 211