18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2013 Texas Instruments Inc.
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * David Griego, <dagriego@biglakesoftware.com>
68c2ecf20Sopenharmony_ci * Dale Farnsworth, <dale@farnsworth.org>
78c2ecf20Sopenharmony_ci * Archit Taneja, <archit@ti.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef TI_SC_H
108c2ecf20Sopenharmony_ci#define TI_SC_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* Scaler regs */
138c2ecf20Sopenharmony_ci#define CFG_SC0				0x0
148c2ecf20Sopenharmony_ci#define CFG_INTERLACE_O			(1 << 0)
158c2ecf20Sopenharmony_ci#define CFG_LINEAR			(1 << 1)
168c2ecf20Sopenharmony_ci#define CFG_SC_BYPASS			(1 << 2)
178c2ecf20Sopenharmony_ci#define CFG_INVT_FID			(1 << 3)
188c2ecf20Sopenharmony_ci#define CFG_USE_RAV			(1 << 4)
198c2ecf20Sopenharmony_ci#define CFG_ENABLE_EV			(1 << 5)
208c2ecf20Sopenharmony_ci#define CFG_AUTO_HS			(1 << 6)
218c2ecf20Sopenharmony_ci#define CFG_DCM_2X			(1 << 7)
228c2ecf20Sopenharmony_ci#define CFG_DCM_4X			(1 << 8)
238c2ecf20Sopenharmony_ci#define CFG_HP_BYPASS			(1 << 9)
248c2ecf20Sopenharmony_ci#define CFG_INTERLACE_I			(1 << 10)
258c2ecf20Sopenharmony_ci#define CFG_ENABLE_SIN2_VER_INTP	(1 << 11)
268c2ecf20Sopenharmony_ci#define CFG_Y_PK_EN			(1 << 14)
278c2ecf20Sopenharmony_ci#define CFG_TRIM			(1 << 15)
288c2ecf20Sopenharmony_ci#define CFG_SELFGEN_FID			(1 << 16)
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#define CFG_SC1				0x4
318c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INC_MASK		0x07ffffff
328c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INC_SHIFT		0
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define CFG_SC2				0x08
358c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_OFFSET_MASK		0x0fffffff
368c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_OFFSET_SHIFT	0
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define CFG_SC3				0x0c
398c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_OFFSET_B_MASK	0x0fffffff
408c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_OFFSET_B_SHIFT	0
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define CFG_SC4				0x10
438c2ecf20Sopenharmony_ci#define CFG_TAR_H_MASK			0x07ff
448c2ecf20Sopenharmony_ci#define CFG_TAR_H_SHIFT			0
458c2ecf20Sopenharmony_ci#define CFG_TAR_W_MASK			0x07ff
468c2ecf20Sopenharmony_ci#define CFG_TAR_W_SHIFT			12
478c2ecf20Sopenharmony_ci#define CFG_LIN_ACC_INC_U_MASK		0x07
488c2ecf20Sopenharmony_ci#define CFG_LIN_ACC_INC_U_SHIFT		24
498c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INIT_U_MASK	0x07
508c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INIT_U_SHIFT	28
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci#define CFG_SC5				0x14
538c2ecf20Sopenharmony_ci#define CFG_SRC_H_MASK			0x07ff
548c2ecf20Sopenharmony_ci#define CFG_SRC_H_SHIFT			0
558c2ecf20Sopenharmony_ci#define CFG_SRC_W_MASK			0x07ff
568c2ecf20Sopenharmony_ci#define CFG_SRC_W_SHIFT			12
578c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INC_U_MASK		0x07
588c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INC_U_SHIFT	24
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define CFG_SC6				0x18
618c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INIT_RAV_MASK	0x03ff
628c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INIT_RAV_SHIFT	0
638c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INIT_RAV_B_MASK	0x03ff
648c2ecf20Sopenharmony_ci#define CFG_ROW_ACC_INIT_RAV_B_SHIFT	10
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci#define CFG_SC8				0x20
678c2ecf20Sopenharmony_ci#define CFG_NLIN_LEFT_MASK		0x07ff
688c2ecf20Sopenharmony_ci#define CFG_NLIN_LEFT_SHIFT		0
698c2ecf20Sopenharmony_ci#define CFG_NLIN_RIGHT_MASK		0x07ff
708c2ecf20Sopenharmony_ci#define CFG_NLIN_RIGHT_SHIFT		12
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define CFG_SC9				0x24
738c2ecf20Sopenharmony_ci#define CFG_LIN_ACC_INC			CFG_SC9
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define CFG_SC10			0x28
768c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INIT		CFG_SC10
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci#define CFG_SC11			0x2c
798c2ecf20Sopenharmony_ci#define CFG_NLIN_ACC_INC		CFG_SC11
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define CFG_SC12			0x30
828c2ecf20Sopenharmony_ci#define CFG_COL_ACC_OFFSET_MASK		0x01ffffff
838c2ecf20Sopenharmony_ci#define CFG_COL_ACC_OFFSET_SHIFT	0
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci#define CFG_SC13			0x34
868c2ecf20Sopenharmony_ci#define CFG_SC_FACTOR_RAV_MASK		0xff
878c2ecf20Sopenharmony_ci#define CFG_SC_FACTOR_RAV_SHIFT		0
888c2ecf20Sopenharmony_ci#define CFG_CHROMA_INTP_THR_MASK	0x03ff
898c2ecf20Sopenharmony_ci#define CFG_CHROMA_INTP_THR_SHIFT	12
908c2ecf20Sopenharmony_ci#define CFG_DELTA_CHROMA_THR_MASK	0x0f
918c2ecf20Sopenharmony_ci#define CFG_DELTA_CHROMA_THR_SHIFT	24
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define CFG_SC17			0x44
948c2ecf20Sopenharmony_ci#define CFG_EV_THR_MASK			0x03ff
958c2ecf20Sopenharmony_ci#define CFG_EV_THR_SHIFT		12
968c2ecf20Sopenharmony_ci#define CFG_DELTA_LUMA_THR_MASK		0x0f
978c2ecf20Sopenharmony_ci#define CFG_DELTA_LUMA_THR_SHIFT	24
988c2ecf20Sopenharmony_ci#define CFG_DELTA_EV_THR_MASK		0x0f
998c2ecf20Sopenharmony_ci#define CFG_DELTA_EV_THR_SHIFT		28
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define CFG_SC18			0x48
1028c2ecf20Sopenharmony_ci#define CFG_HS_FACTOR_MASK		0x03ff
1038c2ecf20Sopenharmony_ci#define CFG_HS_FACTOR_SHIFT		0
1048c2ecf20Sopenharmony_ci#define CFG_CONF_DEFAULT_MASK		0x01ff
1058c2ecf20Sopenharmony_ci#define CFG_CONF_DEFAULT_SHIFT		16
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define CFG_SC19			0x4c
1088c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF0_MASK		0xff
1098c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF0_SHIFT		0
1108c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF1_MASK		0xff
1118c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF1_SHIFT		8
1128c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF2_MASK		0xff
1138c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF2_SHIFT		16
1148c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF3_MASK		0xff
1158c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF3_SHIFT		23
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define CFG_SC20			0x50
1188c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF4_MASK		0xff
1198c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF4_SHIFT		0
1208c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF5_MASK		0xff
1218c2ecf20Sopenharmony_ci#define CFG_HPF_COEFF5_SHIFT		8
1228c2ecf20Sopenharmony_ci#define CFG_HPF_NORM_SHIFT_MASK		0x07
1238c2ecf20Sopenharmony_ci#define CFG_HPF_NORM_SHIFT_SHIFT	16
1248c2ecf20Sopenharmony_ci#define CFG_NL_LIMIT_MASK		0x1ff
1258c2ecf20Sopenharmony_ci#define CFG_NL_LIMIT_SHIFT		20
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#define CFG_SC21			0x54
1288c2ecf20Sopenharmony_ci#define CFG_NL_LO_THR_MASK		0x01ff
1298c2ecf20Sopenharmony_ci#define CFG_NL_LO_THR_SHIFT		0
1308c2ecf20Sopenharmony_ci#define CFG_NL_LO_SLOPE_MASK		0xff
1318c2ecf20Sopenharmony_ci#define CFG_NL_LO_SLOPE_SHIFT		16
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_ci#define CFG_SC22			0x58
1348c2ecf20Sopenharmony_ci#define CFG_NL_HI_THR_MASK		0x01ff
1358c2ecf20Sopenharmony_ci#define CFG_NL_HI_THR_SHIFT		0
1368c2ecf20Sopenharmony_ci#define CFG_NL_HI_SLOPE_SH_MASK		0x07
1378c2ecf20Sopenharmony_ci#define CFG_NL_HI_SLOPE_SH_SHIFT	16
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define CFG_SC23			0x5c
1408c2ecf20Sopenharmony_ci#define CFG_GRADIENT_THR_MASK		0x07ff
1418c2ecf20Sopenharmony_ci#define CFG_GRADIENT_THR_SHIFT		0
1428c2ecf20Sopenharmony_ci#define CFG_GRADIENT_THR_RANGE_MASK	0x0f
1438c2ecf20Sopenharmony_ci#define CFG_GRADIENT_THR_RANGE_SHIFT	12
1448c2ecf20Sopenharmony_ci#define CFG_MIN_GY_THR_MASK		0xff
1458c2ecf20Sopenharmony_ci#define CFG_MIN_GY_THR_SHIFT		16
1468c2ecf20Sopenharmony_ci#define CFG_MIN_GY_THR_RANGE_MASK	0x0f
1478c2ecf20Sopenharmony_ci#define CFG_MIN_GY_THR_RANGE_SHIFT	28
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define CFG_SC24			0x60
1508c2ecf20Sopenharmony_ci#define CFG_ORG_H_MASK			0x07ff
1518c2ecf20Sopenharmony_ci#define CFG_ORG_H_SHIFT			0
1528c2ecf20Sopenharmony_ci#define CFG_ORG_W_MASK			0x07ff
1538c2ecf20Sopenharmony_ci#define CFG_ORG_W_SHIFT			16
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define CFG_SC25			0x64
1568c2ecf20Sopenharmony_ci#define CFG_OFF_H_MASK			0x07ff
1578c2ecf20Sopenharmony_ci#define CFG_OFF_H_SHIFT			0
1588c2ecf20Sopenharmony_ci#define CFG_OFF_W_MASK			0x07ff
1598c2ecf20Sopenharmony_ci#define CFG_OFF_W_SHIFT			16
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* number of phases supported by the polyphase scalers */
1628c2ecf20Sopenharmony_ci#define SC_NUM_PHASES			32
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/* number of taps used by horizontal polyphase scaler */
1658c2ecf20Sopenharmony_ci#define SC_H_NUM_TAPS			7
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci/* number of taps used by vertical polyphase scaler */
1688c2ecf20Sopenharmony_ci#define SC_V_NUM_TAPS			5
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/* number of taps expected by the scaler in it's coefficient memory */
1718c2ecf20Sopenharmony_ci#define SC_NUM_TAPS_MEM_ALIGN		8
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/* Maximum frame width the scaler can handle (in pixels) */
1748c2ecf20Sopenharmony_ci#define SC_MAX_PIXEL_WIDTH		2047
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* Maximum frame height the scaler can handle (in lines) */
1778c2ecf20Sopenharmony_ci#define SC_MAX_PIXEL_HEIGHT		2047
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/*
1808c2ecf20Sopenharmony_ci * coefficient memory size in bytes:
1818c2ecf20Sopenharmony_ci * num phases x num sets(luma and chroma) x num taps(aligned) x coeff size
1828c2ecf20Sopenharmony_ci */
1838c2ecf20Sopenharmony_ci#define SC_COEF_SRAM_SIZE	(SC_NUM_PHASES * 2 * SC_NUM_TAPS_MEM_ALIGN * 2)
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistruct sc_data {
1868c2ecf20Sopenharmony_ci	void __iomem		*base;
1878c2ecf20Sopenharmony_ci	struct resource		*res;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	dma_addr_t		loaded_coeff_h; /* loaded h coeffs in SC */
1908c2ecf20Sopenharmony_ci	dma_addr_t		loaded_coeff_v; /* loaded v coeffs in SC */
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci	bool			load_coeff_h;	/* have new h SC coeffs */
1938c2ecf20Sopenharmony_ci	bool			load_coeff_v;	/* have new v SC coeffs */
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci	struct platform_device *pdev;
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_civoid sc_dump_regs(struct sc_data *sc);
1998c2ecf20Sopenharmony_civoid sc_set_hs_coeffs(struct sc_data *sc, void *addr, unsigned int src_w,
2008c2ecf20Sopenharmony_ci		unsigned int dst_w);
2018c2ecf20Sopenharmony_civoid sc_set_vs_coeffs(struct sc_data *sc, void *addr, unsigned int src_h,
2028c2ecf20Sopenharmony_ci		unsigned int dst_h);
2038c2ecf20Sopenharmony_civoid sc_config_scaler(struct sc_data *sc, u32 *sc_reg0, u32 *sc_reg8,
2048c2ecf20Sopenharmony_ci		u32 *sc_reg17, unsigned int src_w, unsigned int src_h,
2058c2ecf20Sopenharmony_ci		unsigned int dst_w, unsigned int dst_h);
2068c2ecf20Sopenharmony_cistruct sc_data *sc_create(struct platform_device *pdev, const char *res_name);
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci#endif
209