162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2017 Free Electrons 462306a36Sopenharmony_ci * Maxime Ripard <maxime.ripard@free-electrons.com> 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci#ifndef _SUN4I_FRONTEND_H_ 862306a36Sopenharmony_ci#define _SUN4I_FRONTEND_H_ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/list.h> 1162306a36Sopenharmony_ci#include <linux/mod_devicetable.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define SUN4I_FRONTEND_EN_REG 0x000 1462306a36Sopenharmony_ci#define SUN4I_FRONTEND_EN_EN BIT(0) 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_REG 0x004 1762306a36Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_COEF_ACCESS_CTRL BIT(23) 1862306a36Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_FRM_START BIT(16) 1962306a36Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_COEF_RDY BIT(1) 2062306a36Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_REG_RDY BIT(0) 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#define SUN4I_FRONTEND_BYPASS_REG 0x008 2362306a36Sopenharmony_ci#define SUN4I_FRONTEND_BYPASS_CSC_EN BIT(1) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR0_REG 0x020 2662306a36Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR1_REG 0x024 2762306a36Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR2_REG 0x028 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF0_REG 0x030 3062306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF1_REG 0x034 3162306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF2_REG 0x038 3262306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_X1(x1) ((x1) << 16) 3362306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_Y0(y0) ((y0) << 8) 3462306a36Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_X0(x0) (x0) 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD0_REG 0x040 3762306a36Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD1_REG 0x044 3862306a36Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD2_REG 0x048 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci/* 4162306a36Sopenharmony_ci * In tiled mode, the stride is defined as the distance between the start of the 4262306a36Sopenharmony_ci * end line of the current tile and the start of the first line in the next 4362306a36Sopenharmony_ci * vertical tile. 4462306a36Sopenharmony_ci * 4562306a36Sopenharmony_ci * Tiles are represented in row-major order, thus the end line of current tile 4662306a36Sopenharmony_ci * starts at: 31 * 32 (31 lines of 32 cols), the next vertical tile starts at: 4762306a36Sopenharmony_ci * 32-bit-aligned-width * 32 and the distance is: 4862306a36Sopenharmony_ci * 32 * (32-bit-aligned-width - 31). 4962306a36Sopenharmony_ci */ 5062306a36Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD_TILED(stride) (((stride) - 31) * 32) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_REG 0x04c 5362306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PLANAR (0 << 8) 5462306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PACKED (1 << 8) 5562306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_SEMIPLANAR (2 << 8) 5662306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_MB32_PLANAR (4 << 8) 5762306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_MB32_SEMIPLANAR (6 << 8) 5862306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV444 (0 << 4) 5962306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV422 (1 << 4) 6062306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV420 (2 << 4) 6162306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV411 (3 << 4) 6262306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_RGB (5 << 4) 6362306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UYVY 0 6462306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YUYV 1 6562306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VYUY 2 6662306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YVYU 3 6762306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UV 0 6862306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VU 1 6962306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_BGRX 0 7062306a36Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_XRGB 1 7162306a36Sopenharmony_ci 7262306a36Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_REG 0x05c 7362306a36Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_DATA_FMT_BGRX8888 1 7462306a36Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_DATA_FMT_XRGB8888 2 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define SUN4I_FRONTEND_CSC_COEF_REG(c) (0x070 + (0x4 * (c))) 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_INSIZE_REG 0x100 7962306a36Sopenharmony_ci#define SUN4I_FRONTEND_INSIZE(h, w) ((((h) - 1) << 16) | (((w) - 1))) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_OUTSIZE_REG 0x104 8262306a36Sopenharmony_ci#define SUN4I_FRONTEND_OUTSIZE(h, w) ((((h) - 1) << 16) | (((w) - 1))) 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZFACT_REG 0x108 8562306a36Sopenharmony_ci#define SUN4I_FRONTEND_HORZFACT(i, f) (((i) << 16) | (f)) 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTFACT_REG 0x10c 8862306a36Sopenharmony_ci#define SUN4I_FRONTEND_VERTFACT(i, f) (((i) << 16) | (f)) 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZPHASE_REG 0x110 9162306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTPHASE0_REG 0x114 9262306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTPHASE1_REG 0x118 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_INSIZE_REG 0x200 9562306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_OUTSIZE_REG 0x204 9662306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZFACT_REG 0x208 9762306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTFACT_REG 0x20c 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZPHASE_REG 0x210 10062306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTPHASE0_REG 0x214 10162306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTPHASE1_REG 0x218 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZCOEF0_REG(i) (0x400 + i * 4) 10462306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZCOEF1_REG(i) (0x480 + i * 4) 10562306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTCOEF_REG(i) (0x500 + i * 4) 10662306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZCOEF0_REG(i) (0x600 + i * 4) 10762306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZCOEF1_REG(i) (0x680 + i * 4) 10862306a36Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTCOEF_REG(i) (0x700 + i * 4) 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_cistruct clk; 11162306a36Sopenharmony_cistruct device_node; 11262306a36Sopenharmony_cistruct drm_plane; 11362306a36Sopenharmony_cistruct regmap; 11462306a36Sopenharmony_cistruct reset_control; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_cistruct sun4i_frontend_data { 11762306a36Sopenharmony_ci bool has_coef_access_ctrl; 11862306a36Sopenharmony_ci bool has_coef_rdy; 11962306a36Sopenharmony_ci u32 ch_phase[2]; 12062306a36Sopenharmony_ci}; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_cistruct sun4i_frontend { 12362306a36Sopenharmony_ci struct list_head list; 12462306a36Sopenharmony_ci struct device *dev; 12562306a36Sopenharmony_ci struct device_node *node; 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci struct clk *bus_clk; 12862306a36Sopenharmony_ci struct clk *mod_clk; 12962306a36Sopenharmony_ci struct clk *ram_clk; 13062306a36Sopenharmony_ci struct regmap *regs; 13162306a36Sopenharmony_ci struct reset_control *reset; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci const struct sun4i_frontend_data *data; 13462306a36Sopenharmony_ci}; 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ciextern const struct of_device_id sun4i_frontend_of_table[]; 13762306a36Sopenharmony_ciextern const u32 sunxi_bt601_yuv2rgb_coef[12]; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_ciint sun4i_frontend_init(struct sun4i_frontend *frontend); 14062306a36Sopenharmony_civoid sun4i_frontend_exit(struct sun4i_frontend *frontend); 14162306a36Sopenharmony_ciint sun4i_frontend_enable(struct sun4i_frontend *frontend); 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_civoid sun4i_frontend_update_buffer(struct sun4i_frontend *frontend, 14462306a36Sopenharmony_ci struct drm_plane *plane); 14562306a36Sopenharmony_civoid sun4i_frontend_update_coord(struct sun4i_frontend *frontend, 14662306a36Sopenharmony_ci struct drm_plane *plane); 14762306a36Sopenharmony_ciint sun4i_frontend_update_formats(struct sun4i_frontend *frontend, 14862306a36Sopenharmony_ci struct drm_plane *plane, uint32_t out_fmt); 14962306a36Sopenharmony_cibool sun4i_frontend_format_is_supported(uint32_t fmt, uint64_t modifier); 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#endif /* _SUN4I_FRONTEND_H_ */ 152