14f2a8f58SJoel Stanley /* SPDX-License-Identifier: GPL-2.0+ */
24f2a8f58SJoel Stanley /* Copyright 2018 IBM Corporation */
34f2a8f58SJoel Stanley 
44f2a8f58SJoel Stanley #include <drm/drm_device.h>
54f2a8f58SJoel Stanley #include <drm/drm_simple_kms_helper.h>
64f2a8f58SJoel Stanley 
74f2a8f58SJoel Stanley struct aspeed_gfx {
8cd829454SDaniel Vetter 	struct drm_device		drm;
94f2a8f58SJoel Stanley 	void __iomem			*base;
104f2a8f58SJoel Stanley 	struct clk			*clk;
114f2a8f58SJoel Stanley 	struct reset_control		*rst;
124f2a8f58SJoel Stanley 	struct regmap			*scu;
134f2a8f58SJoel Stanley 
14bce724faSJoel Stanley 	u32				dac_reg;
15d525d3d0STommy Haung 	u32				int_clr_reg;
16bce724faSJoel Stanley 	u32				vga_scratch_reg;
17bce724faSJoel Stanley 	u32				throd_val;
18bce724faSJoel Stanley 	u32				scan_line_max;
19bce724faSJoel Stanley 
204f2a8f58SJoel Stanley 	struct drm_simple_display_pipe	pipe;
214f2a8f58SJoel Stanley 	struct drm_connector		connector;
224f2a8f58SJoel Stanley };
23cd829454SDaniel Vetter #define to_aspeed_gfx(x) container_of(x, struct aspeed_gfx, drm)
244f2a8f58SJoel Stanley 
254f2a8f58SJoel Stanley int aspeed_gfx_create_pipe(struct drm_device *drm);
264f2a8f58SJoel Stanley int aspeed_gfx_create_output(struct drm_device *drm);
274f2a8f58SJoel Stanley 
284f2a8f58SJoel Stanley #define CRT_CTRL1		0x60 /* CRT Control I */
294f2a8f58SJoel Stanley #define CRT_CTRL2		0x64 /* CRT Control II */
304f2a8f58SJoel Stanley #define CRT_STATUS		0x68 /* CRT Status */
314f2a8f58SJoel Stanley #define CRT_MISC		0x6c /* CRT Misc Setting */
324f2a8f58SJoel Stanley #define CRT_HORIZ0		0x70 /* CRT Horizontal Total & Display Enable End */
334f2a8f58SJoel Stanley #define CRT_HORIZ1		0x74 /* CRT Horizontal Retrace Start & End */
344f2a8f58SJoel Stanley #define CRT_VERT0		0x78 /* CRT Vertical Total & Display Enable End */
354f2a8f58SJoel Stanley #define CRT_VERT1		0x7C /* CRT Vertical Retrace Start & End */
364f2a8f58SJoel Stanley #define CRT_ADDR		0x80 /* CRT Display Starting Address */
374f2a8f58SJoel Stanley #define CRT_OFFSET		0x84 /* CRT Display Offset & Terminal Count */
384f2a8f58SJoel Stanley #define CRT_THROD		0x88 /* CRT Threshold */
394f2a8f58SJoel Stanley #define CRT_XSCALE		0x8C /* CRT Scaling-Up Factor */
404f2a8f58SJoel Stanley #define CRT_CURSOR0		0x90 /* CRT Hardware Cursor X & Y Offset */
414f2a8f58SJoel Stanley #define CRT_CURSOR1		0x94 /* CRT Hardware Cursor X & Y Position */
424f2a8f58SJoel Stanley #define CRT_CURSOR2		0x98 /* CRT Hardware Cursor Pattern Address */
434f2a8f58SJoel Stanley #define CRT_9C			0x9C
444f2a8f58SJoel Stanley #define CRT_OSD_H		0xA0 /* CRT OSD Horizontal Start/End */
454f2a8f58SJoel Stanley #define CRT_OSD_V		0xA4 /* CRT OSD Vertical Start/End */
464f2a8f58SJoel Stanley #define CRT_OSD_ADDR		0xA8 /* CRT OSD Pattern Address */
474f2a8f58SJoel Stanley #define CRT_OSD_DISP		0xAC /* CRT OSD Offset */
484f2a8f58SJoel Stanley #define CRT_OSD_THRESH		0xB0 /* CRT OSD Threshold & Alpha */
494f2a8f58SJoel Stanley #define CRT_B4			0xB4
504f2a8f58SJoel Stanley #define CRT_STS_V		0xB8 /* CRT Status V */
514f2a8f58SJoel Stanley #define CRT_SCRATCH		0xBC /* Scratchpad */
524f2a8f58SJoel Stanley #define CRT_BB0_ADDR		0xD0 /* CRT Display BB0 Starting Address */
534f2a8f58SJoel Stanley #define CRT_BB1_ADDR		0xD4 /* CRT Display BB1 Starting Address */
544f2a8f58SJoel Stanley #define CRT_BB_COUNT		0xD8 /* CRT Display BB Terminal Count */
554f2a8f58SJoel Stanley #define OSD_COLOR1		0xE0 /* OSD Color Palette Index 1 & 0 */
564f2a8f58SJoel Stanley #define OSD_COLOR2		0xE4 /* OSD Color Palette Index 3 & 2 */
574f2a8f58SJoel Stanley #define OSD_COLOR3		0xE8 /* OSD Color Palette Index 5 & 4 */
584f2a8f58SJoel Stanley #define OSD_COLOR4		0xEC /* OSD Color Palette Index 7 & 6 */
594f2a8f58SJoel Stanley #define OSD_COLOR5		0xF0 /* OSD Color Palette Index 9 & 8 */
604f2a8f58SJoel Stanley #define OSD_COLOR6		0xF4 /* OSD Color Palette Index 11 & 10 */
614f2a8f58SJoel Stanley #define OSD_COLOR7		0xF8 /* OSD Color Palette Index 13 & 12 */
624f2a8f58SJoel Stanley #define OSD_COLOR8		0xFC /* OSD Color Palette Index 15 & 14 */
634f2a8f58SJoel Stanley 
644f2a8f58SJoel Stanley /* CTRL1 */
654f2a8f58SJoel Stanley #define CRT_CTRL_EN			BIT(0)
664f2a8f58SJoel Stanley #define CRT_CTRL_HW_CURSOR_EN		BIT(1)
674f2a8f58SJoel Stanley #define CRT_CTRL_OSD_EN			BIT(2)
684f2a8f58SJoel Stanley #define CRT_CTRL_INTERLACED		BIT(3)
694f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_RGB565		(0 << 7)
704f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_YUV444		(1 << 7)
714f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_XRGB8888		(2 << 7)
724f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_RGB888		(3 << 7)
734f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_YUV444_2RGB	(5 << 7)
744f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_YUV422		(7 << 7)
754f2a8f58SJoel Stanley #define CRT_CTRL_COLOR_MASK		GENMASK(9, 7)
764f2a8f58SJoel Stanley #define CRT_CTRL_HSYNC_NEGATIVE		BIT(16)
774f2a8f58SJoel Stanley #define CRT_CTRL_VSYNC_NEGATIVE		BIT(17)
784f2a8f58SJoel Stanley #define CRT_CTRL_VERTICAL_INTR_EN	BIT(30)
794f2a8f58SJoel Stanley #define CRT_CTRL_VERTICAL_INTR_STS	BIT(31)
804f2a8f58SJoel Stanley 
814f2a8f58SJoel Stanley /* CTRL2 */
824f2a8f58SJoel Stanley #define CRT_CTRL_DAC_EN			BIT(0)
834f2a8f58SJoel Stanley #define CRT_CTRL_VBLANK_LINE(x)		(((x) << 20) & CRT_CTRL_VBLANK_LINE_MASK)
84c76eb355SOndrej Jirman #define CRT_CTRL_VBLANK_LINE_MASK	GENMASK(31, 20)
854f2a8f58SJoel Stanley 
864f2a8f58SJoel Stanley /* CRT_HORIZ0 */
874f2a8f58SJoel Stanley #define CRT_H_TOTAL(x)			(x)
884f2a8f58SJoel Stanley #define CRT_H_DE(x)			((x) << 16)
894f2a8f58SJoel Stanley 
904f2a8f58SJoel Stanley /* CRT_HORIZ1 */
914f2a8f58SJoel Stanley #define CRT_H_RS_START(x)		(x)
924f2a8f58SJoel Stanley #define CRT_H_RS_END(x)			((x) << 16)
934f2a8f58SJoel Stanley 
944f2a8f58SJoel Stanley /* CRT_VIRT0 */
954f2a8f58SJoel Stanley #define CRT_V_TOTAL(x)			(x)
964f2a8f58SJoel Stanley #define CRT_V_DE(x)			((x) << 16)
974f2a8f58SJoel Stanley 
984f2a8f58SJoel Stanley /* CRT_VIRT1 */
994f2a8f58SJoel Stanley #define CRT_V_RS_START(x)		(x)
1004f2a8f58SJoel Stanley #define CRT_V_RS_END(x)			((x) << 16)
1014f2a8f58SJoel Stanley 
1024f2a8f58SJoel Stanley /* CRT_OFFSET */
1034f2a8f58SJoel Stanley #define CRT_DISP_OFFSET(x)		(x)
1044f2a8f58SJoel Stanley #define CRT_TERM_COUNT(x)		((x) << 16)
1054f2a8f58SJoel Stanley 
1064f2a8f58SJoel Stanley /* CRT_THROD */
1074f2a8f58SJoel Stanley #define CRT_THROD_LOW(x)		(x)
1084f2a8f58SJoel Stanley #define CRT_THROD_HIGH(x)		((x) << 8)
109