18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/* Copyright 2018 IBM Corporation */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <drm/drm_device.h>
58c2ecf20Sopenharmony_ci#include <drm/drm_simple_kms_helper.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_cistruct aspeed_gfx {
88c2ecf20Sopenharmony_ci	struct drm_device		drm;
98c2ecf20Sopenharmony_ci	void __iomem			*base;
108c2ecf20Sopenharmony_ci	struct clk			*clk;
118c2ecf20Sopenharmony_ci	struct reset_control		*rst;
128c2ecf20Sopenharmony_ci	struct regmap			*scu;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci	struct drm_simple_display_pipe	pipe;
158c2ecf20Sopenharmony_ci	struct drm_connector		connector;
168c2ecf20Sopenharmony_ci};
178c2ecf20Sopenharmony_ci#define to_aspeed_gfx(x) container_of(x, struct aspeed_gfx, drm)
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciint aspeed_gfx_create_pipe(struct drm_device *drm);
208c2ecf20Sopenharmony_ciint aspeed_gfx_create_output(struct drm_device *drm);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define CRT_CTRL1		0x60 /* CRT Control I */
238c2ecf20Sopenharmony_ci#define CRT_CTRL2		0x64 /* CRT Control II */
248c2ecf20Sopenharmony_ci#define CRT_STATUS		0x68 /* CRT Status */
258c2ecf20Sopenharmony_ci#define CRT_MISC		0x6c /* CRT Misc Setting */
268c2ecf20Sopenharmony_ci#define CRT_HORIZ0		0x70 /* CRT Horizontal Total & Display Enable End */
278c2ecf20Sopenharmony_ci#define CRT_HORIZ1		0x74 /* CRT Horizontal Retrace Start & End */
288c2ecf20Sopenharmony_ci#define CRT_VERT0		0x78 /* CRT Vertical Total & Display Enable End */
298c2ecf20Sopenharmony_ci#define CRT_VERT1		0x7C /* CRT Vertical Retrace Start & End */
308c2ecf20Sopenharmony_ci#define CRT_ADDR		0x80 /* CRT Display Starting Address */
318c2ecf20Sopenharmony_ci#define CRT_OFFSET		0x84 /* CRT Display Offset & Terminal Count */
328c2ecf20Sopenharmony_ci#define CRT_THROD		0x88 /* CRT Threshold */
338c2ecf20Sopenharmony_ci#define CRT_XSCALE		0x8C /* CRT Scaling-Up Factor */
348c2ecf20Sopenharmony_ci#define CRT_CURSOR0		0x90 /* CRT Hardware Cursor X & Y Offset */
358c2ecf20Sopenharmony_ci#define CRT_CURSOR1		0x94 /* CRT Hardware Cursor X & Y Position */
368c2ecf20Sopenharmony_ci#define CRT_CURSOR2		0x98 /* CRT Hardware Cursor Pattern Address */
378c2ecf20Sopenharmony_ci#define CRT_9C			0x9C
388c2ecf20Sopenharmony_ci#define CRT_OSD_H		0xA0 /* CRT OSD Horizontal Start/End */
398c2ecf20Sopenharmony_ci#define CRT_OSD_V		0xA4 /* CRT OSD Vertical Start/End */
408c2ecf20Sopenharmony_ci#define CRT_OSD_ADDR		0xA8 /* CRT OSD Pattern Address */
418c2ecf20Sopenharmony_ci#define CRT_OSD_DISP		0xAC /* CRT OSD Offset */
428c2ecf20Sopenharmony_ci#define CRT_OSD_THRESH		0xB0 /* CRT OSD Threshold & Alpha */
438c2ecf20Sopenharmony_ci#define CRT_B4			0xB4
448c2ecf20Sopenharmony_ci#define CRT_STS_V		0xB8 /* CRT Status V */
458c2ecf20Sopenharmony_ci#define CRT_SCRATCH		0xBC /* Scratchpad */
468c2ecf20Sopenharmony_ci#define CRT_BB0_ADDR		0xD0 /* CRT Display BB0 Starting Address */
478c2ecf20Sopenharmony_ci#define CRT_BB1_ADDR		0xD4 /* CRT Display BB1 Starting Address */
488c2ecf20Sopenharmony_ci#define CRT_BB_COUNT		0xD8 /* CRT Display BB Terminal Count */
498c2ecf20Sopenharmony_ci#define OSD_COLOR1		0xE0 /* OSD Color Palette Index 1 & 0 */
508c2ecf20Sopenharmony_ci#define OSD_COLOR2		0xE4 /* OSD Color Palette Index 3 & 2 */
518c2ecf20Sopenharmony_ci#define OSD_COLOR3		0xE8 /* OSD Color Palette Index 5 & 4 */
528c2ecf20Sopenharmony_ci#define OSD_COLOR4		0xEC /* OSD Color Palette Index 7 & 6 */
538c2ecf20Sopenharmony_ci#define OSD_COLOR5		0xF0 /* OSD Color Palette Index 9 & 8 */
548c2ecf20Sopenharmony_ci#define OSD_COLOR6		0xF4 /* OSD Color Palette Index 11 & 10 */
558c2ecf20Sopenharmony_ci#define OSD_COLOR7		0xF8 /* OSD Color Palette Index 13 & 12 */
568c2ecf20Sopenharmony_ci#define OSD_COLOR8		0xFC /* OSD Color Palette Index 15 & 14 */
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci/* CTRL1 */
598c2ecf20Sopenharmony_ci#define CRT_CTRL_EN			BIT(0)
608c2ecf20Sopenharmony_ci#define CRT_CTRL_HW_CURSOR_EN		BIT(1)
618c2ecf20Sopenharmony_ci#define CRT_CTRL_OSD_EN			BIT(2)
628c2ecf20Sopenharmony_ci#define CRT_CTRL_INTERLACED		BIT(3)
638c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_RGB565		(0 << 7)
648c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_YUV444		(1 << 7)
658c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_XRGB8888		(2 << 7)
668c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_RGB888		(3 << 7)
678c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_YUV444_2RGB	(5 << 7)
688c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_YUV422		(7 << 7)
698c2ecf20Sopenharmony_ci#define CRT_CTRL_COLOR_MASK		GENMASK(9, 7)
708c2ecf20Sopenharmony_ci#define CRT_CTRL_HSYNC_NEGATIVE		BIT(16)
718c2ecf20Sopenharmony_ci#define CRT_CTRL_VSYNC_NEGATIVE		BIT(17)
728c2ecf20Sopenharmony_ci#define CRT_CTRL_VERTICAL_INTR_EN	BIT(30)
738c2ecf20Sopenharmony_ci#define CRT_CTRL_VERTICAL_INTR_STS	BIT(31)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci/* CTRL2 */
768c2ecf20Sopenharmony_ci#define CRT_CTRL_DAC_EN			BIT(0)
778c2ecf20Sopenharmony_ci#define CRT_CTRL_VBLANK_LINE(x)		(((x) << 20) & CRT_CTRL_VBLANK_LINE_MASK)
788c2ecf20Sopenharmony_ci#define CRT_CTRL_VBLANK_LINE_MASK	GENMASK(20, 31)
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/* CRT_HORIZ0 */
818c2ecf20Sopenharmony_ci#define CRT_H_TOTAL(x)			(x)
828c2ecf20Sopenharmony_ci#define CRT_H_DE(x)			((x) << 16)
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/* CRT_HORIZ1 */
858c2ecf20Sopenharmony_ci#define CRT_H_RS_START(x)		(x)
868c2ecf20Sopenharmony_ci#define CRT_H_RS_END(x)			((x) << 16)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/* CRT_VIRT0 */
898c2ecf20Sopenharmony_ci#define CRT_V_TOTAL(x)			(x)
908c2ecf20Sopenharmony_ci#define CRT_V_DE(x)			((x) << 16)
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci/* CRT_VIRT1 */
938c2ecf20Sopenharmony_ci#define CRT_V_RS_START(x)		(x)
948c2ecf20Sopenharmony_ci#define CRT_V_RS_END(x)			((x) << 16)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* CRT_OFFSET */
978c2ecf20Sopenharmony_ci#define CRT_DISP_OFFSET(x)		(x)
988c2ecf20Sopenharmony_ci#define CRT_TERM_COUNT(x)		((x) << 16)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/* CRT_THROD */
1018c2ecf20Sopenharmony_ci#define CRT_THROD_LOW(x)		(x)
1028c2ecf20Sopenharmony_ci#define CRT_THROD_HIGH(x)		((x) << 8)
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci/* Default Threshold Seting */
1058c2ecf20Sopenharmony_ci#define G5_CRT_THROD_VAL	(CRT_THROD_LOW(0x24) | CRT_THROD_HIGH(0x3C))
106