18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Free Electrons
48c2ecf20Sopenharmony_ci * Maxime Ripard <maxime.ripard@free-electrons.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#ifndef _SUN4I_FRONTEND_H_
88c2ecf20Sopenharmony_ci#define _SUN4I_FRONTEND_H_
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/list.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_EN_REG			0x000
138c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_EN_EN				BIT(0)
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_REG		0x004
168c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_COEF_ACCESS_CTRL	BIT(23)
178c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_FRM_START		BIT(16)
188c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_COEF_RDY		BIT(1)
198c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_FRM_CTRL_REG_RDY			BIT(0)
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_BYPASS_REG		0x008
228c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_BYPASS_CSC_EN			BIT(1)
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR0_REG		0x020
258c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR1_REG		0x024
268c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_BUF_ADDR2_REG		0x028
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF0_REG		0x030
298c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF1_REG		0x034
308c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF2_REG		0x038
318c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_X1(x1)			((x1) << 16)
328c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_Y0(y0)			((y0) << 8)
338c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_TB_OFF_X0(x0)			(x0)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD0_REG		0x040
368c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD1_REG		0x044
378c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD2_REG		0x048
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci * In tiled mode, the stride is defined as the distance between the start of the
418c2ecf20Sopenharmony_ci * end line of the current tile and the start of the first line in the next
428c2ecf20Sopenharmony_ci * vertical tile.
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * Tiles are represented in row-major order, thus the end line of current tile
458c2ecf20Sopenharmony_ci * starts at: 31 * 32 (31 lines of 32 cols), the next vertical tile starts at:
468c2ecf20Sopenharmony_ci * 32-bit-aligned-width * 32 and the distance is:
478c2ecf20Sopenharmony_ci * 32 * (32-bit-aligned-width - 31).
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_LINESTRD_TILED(stride)		(((stride) - 31) * 32)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_REG		0x04c
528c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PLANAR	(0 << 8)
538c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_PACKED	(1 << 8)
548c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_SEMIPLANAR	(2 << 8)
558c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_MB32_PLANAR	(4 << 8)
568c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_MOD_MB32_SEMIPLANAR (6 << 8)
578c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV444	(0 << 4)
588c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV422	(1 << 4)
598c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV420	(2 << 4)
608c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV411	(3 << 4)
618c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_RGB		(5 << 4)
628c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UYVY		0
638c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YUYV		1
648c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VYUY		2
658c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_YVYU		3
668c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_UV		0
678c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_VU		1
688c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_BGRX		0
698c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INPUT_FMT_DATA_PS_XRGB		1
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_REG		0x05c
728c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_DATA_FMT_BGRX8888	1
738c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_OUTPUT_FMT_DATA_FMT_XRGB8888	2
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CSC_COEF_REG(c)		(0x070 + (0x4 * (c)))
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_INSIZE_REG		0x100
788c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_INSIZE(h, w)			((((h) - 1) << 16) | (((w) - 1)))
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_OUTSIZE_REG		0x104
818c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_OUTSIZE(h, w)			((((h) - 1) << 16) | (((w) - 1)))
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZFACT_REG		0x108
848c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_HORZFACT(i, f)			(((i) << 16) | (f))
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTFACT_REG		0x10c
878c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_VERTFACT(i, f)			(((i) << 16) | (f))
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZPHASE_REG	0x110
908c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTPHASE0_REG	0x114
918c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTPHASE1_REG	0x118
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_INSIZE_REG		0x200
948c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_OUTSIZE_REG		0x204
958c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZFACT_REG		0x208
968c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTFACT_REG		0x20c
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZPHASE_REG	0x210
998c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTPHASE0_REG	0x214
1008c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTPHASE1_REG	0x218
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZCOEF0_REG(i)	(0x400 + i * 4)
1038c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_HORZCOEF1_REG(i)	(0x480 + i * 4)
1048c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH0_VERTCOEF_REG(i)	(0x500 + i * 4)
1058c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZCOEF0_REG(i)	(0x600 + i * 4)
1068c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_HORZCOEF1_REG(i)	(0x680 + i * 4)
1078c2ecf20Sopenharmony_ci#define SUN4I_FRONTEND_CH1_VERTCOEF_REG(i)	(0x700 + i * 4)
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistruct clk;
1108c2ecf20Sopenharmony_cistruct device_node;
1118c2ecf20Sopenharmony_cistruct drm_plane;
1128c2ecf20Sopenharmony_cistruct regmap;
1138c2ecf20Sopenharmony_cistruct reset_control;
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistruct sun4i_frontend_data {
1168c2ecf20Sopenharmony_ci	bool	has_coef_access_ctrl;
1178c2ecf20Sopenharmony_ci	bool	has_coef_rdy;
1188c2ecf20Sopenharmony_ci	u32	ch_phase[2];
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistruct sun4i_frontend {
1228c2ecf20Sopenharmony_ci	struct list_head	list;
1238c2ecf20Sopenharmony_ci	struct device		*dev;
1248c2ecf20Sopenharmony_ci	struct device_node	*node;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	struct clk		*bus_clk;
1278c2ecf20Sopenharmony_ci	struct clk		*mod_clk;
1288c2ecf20Sopenharmony_ci	struct clk		*ram_clk;
1298c2ecf20Sopenharmony_ci	struct regmap		*regs;
1308c2ecf20Sopenharmony_ci	struct reset_control	*reset;
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci	const struct sun4i_frontend_data	*data;
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ciextern const struct of_device_id sun4i_frontend_of_table[];
1368c2ecf20Sopenharmony_ciextern const u32 sunxi_bt601_yuv2rgb_coef[12];
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ciint sun4i_frontend_init(struct sun4i_frontend *frontend);
1398c2ecf20Sopenharmony_civoid sun4i_frontend_exit(struct sun4i_frontend *frontend);
1408c2ecf20Sopenharmony_ciint sun4i_frontend_enable(struct sun4i_frontend *frontend);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_civoid sun4i_frontend_update_buffer(struct sun4i_frontend *frontend,
1438c2ecf20Sopenharmony_ci				  struct drm_plane *plane);
1448c2ecf20Sopenharmony_civoid sun4i_frontend_update_coord(struct sun4i_frontend *frontend,
1458c2ecf20Sopenharmony_ci				 struct drm_plane *plane);
1468c2ecf20Sopenharmony_ciint sun4i_frontend_update_formats(struct sun4i_frontend *frontend,
1478c2ecf20Sopenharmony_ci				  struct drm_plane *plane, uint32_t out_fmt);
1488c2ecf20Sopenharmony_cibool sun4i_frontend_format_is_supported(uint32_t fmt, uint64_t modifier);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#endif /* _SUN4I_FRONTEND_H_ */
151