162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
462306a36Sopenharmony_ci * Parts of this file were based on sources as follows:
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright (C) 2006-2008 Intel Corporation
762306a36Sopenharmony_ci * Copyright (C) 2007 Amos Lee <amos_lee@storlinksemi.com>
862306a36Sopenharmony_ci * Copyright (C) 2007 Dave Airlie <airlied@linux.ie>
962306a36Sopenharmony_ci * Copyright (C) 2011 Texas Instruments
1062306a36Sopenharmony_ci * Copyright (C) 2017 Eric Anholt
1162306a36Sopenharmony_ci */
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#ifndef _TVE200_DRM_H_
1462306a36Sopenharmony_ci#define _TVE200_DRM_H_
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#include <linux/irqreturn.h>
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#include <drm/drm_simple_kms_helper.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_cistruct clk;
2162306a36Sopenharmony_cistruct drm_bridge;
2262306a36Sopenharmony_cistruct drm_connector;
2362306a36Sopenharmony_cistruct drm_device;
2462306a36Sopenharmony_cistruct drm_file;
2562306a36Sopenharmony_cistruct drm_mode_create_dumb;
2662306a36Sopenharmony_cistruct drm_panel;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* Bits 2-31 are valid physical base addresses */
2962306a36Sopenharmony_ci#define TVE200_Y_FRAME_BASE_ADDR	0x00
3062306a36Sopenharmony_ci#define TVE200_U_FRAME_BASE_ADDR	0x04
3162306a36Sopenharmony_ci#define TVE200_V_FRAME_BASE_ADDR	0x08
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define TVE200_INT_EN			0x0C
3462306a36Sopenharmony_ci#define TVE200_INT_CLR			0x10
3562306a36Sopenharmony_ci#define TVE200_INT_STAT			0x14
3662306a36Sopenharmony_ci#define TVE200_INT_BUS_ERR		BIT(7)
3762306a36Sopenharmony_ci#define TVE200_INT_V_STATUS		BIT(6) /* vertical blank */
3862306a36Sopenharmony_ci#define TVE200_INT_V_NEXT_FRAME		BIT(5)
3962306a36Sopenharmony_ci#define TVE200_INT_U_NEXT_FRAME		BIT(4)
4062306a36Sopenharmony_ci#define TVE200_INT_Y_NEXT_FRAME		BIT(3)
4162306a36Sopenharmony_ci#define TVE200_INT_V_FIFO_UNDERRUN	BIT(2)
4262306a36Sopenharmony_ci#define TVE200_INT_U_FIFO_UNDERRUN	BIT(1)
4362306a36Sopenharmony_ci#define TVE200_INT_Y_FIFO_UNDERRUN	BIT(0)
4462306a36Sopenharmony_ci#define TVE200_FIFO_UNDERRUNS		(TVE200_INT_V_FIFO_UNDERRUN | \
4562306a36Sopenharmony_ci					 TVE200_INT_U_FIFO_UNDERRUN | \
4662306a36Sopenharmony_ci					 TVE200_INT_Y_FIFO_UNDERRUN)
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define TVE200_CTRL			0x18
4962306a36Sopenharmony_ci#define TVE200_CTRL_YUV420		BIT(31)
5062306a36Sopenharmony_ci#define TVE200_CTRL_CSMODE		BIT(30)
5162306a36Sopenharmony_ci#define TVE200_CTRL_NONINTERLACE	BIT(28) /* 0 = non-interlace CCIR656 */
5262306a36Sopenharmony_ci#define TVE200_CTRL_TVCLKP		BIT(27) /* Inverted clock phase */
5362306a36Sopenharmony_ci/* Bits 24..26 define the burst size after arbitration on the bus */
5462306a36Sopenharmony_ci#define TVE200_CTRL_BURST_4_WORDS	(0 << 24)
5562306a36Sopenharmony_ci#define TVE200_CTRL_BURST_8_WORDS	(1 << 24)
5662306a36Sopenharmony_ci#define TVE200_CTRL_BURST_16_WORDS	(2 << 24)
5762306a36Sopenharmony_ci#define TVE200_CTRL_BURST_32_WORDS	(3 << 24)
5862306a36Sopenharmony_ci#define TVE200_CTRL_BURST_64_WORDS	(4 << 24)
5962306a36Sopenharmony_ci#define TVE200_CTRL_BURST_128_WORDS	(5 << 24)
6062306a36Sopenharmony_ci#define TVE200_CTRL_BURST_256_WORDS	(6 << 24)
6162306a36Sopenharmony_ci#define TVE200_CTRL_BURST_0_WORDS	(7 << 24) /* ? */
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci * Bits 16..23 is the retry count*16 before issueing a new AHB transfer
6462306a36Sopenharmony_ci * on the AHB bus.
6562306a36Sopenharmony_ci */
6662306a36Sopenharmony_ci#define TVE200_CTRL_RETRYCNT_MASK	GENMASK(23, 16)
6762306a36Sopenharmony_ci#define TVE200_CTRL_RETRYCNT_16		(1 << 16)
6862306a36Sopenharmony_ci#define TVE200_CTRL_BBBP		BIT(15) /* 0 = little-endian */
6962306a36Sopenharmony_ci/* Bits 12..14 define the YCbCr ordering */
7062306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CB0Y0CR0Y1	(0 << 12)
7162306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y0CB0Y1CR0	(1 << 12)
7262306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CR0Y0CB0Y1	(2 << 12)
7362306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y1CB0Y0CR0	(3 << 12)
7462306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CR0Y1CB0Y0	(4 << 12)
7562306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y1CR0Y0CB0	(5 << 12)
7662306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CB0Y1CR0Y0	(6 << 12)
7762306a36Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y0CR0Y1CB0	(7 << 12)
7862306a36Sopenharmony_ci/* Bits 10..11 define the input resolution (framebuffer size) */
7962306a36Sopenharmony_ci#define TVE200_CTRL_IPRESOL_CIF		(0 << 10)
8062306a36Sopenharmony_ci#define TVE200_CTRL_IPRESOL_VGA		(1 << 10)
8162306a36Sopenharmony_ci#define TVE200_CTRL_IPRESOL_D1		(2 << 10)
8262306a36Sopenharmony_ci#define TVE200_CTRL_NTSC		BIT(9) /* 0 = PAL, 1 = NTSC */
8362306a36Sopenharmony_ci#define TVE200_CTRL_INTERLACE		BIT(8) /* 1 = interlace, only for D1 */
8462306a36Sopenharmony_ci#define TVE200_IPDMOD_RGB555		(0 << 6) /* TVE200_CTRL_YUV420 = 0 */
8562306a36Sopenharmony_ci#define TVE200_IPDMOD_RGB565		(1 << 6)
8662306a36Sopenharmony_ci#define TVE200_IPDMOD_RGB888		(2 << 6)
8762306a36Sopenharmony_ci#define TVE200_IPDMOD_YUV420		(2 << 6) /* TVE200_CTRL_YUV420 = 1 */
8862306a36Sopenharmony_ci#define TVE200_IPDMOD_YUV422		(3 << 6)
8962306a36Sopenharmony_ci/* Bits 4 & 5 define when to fire the vblank IRQ */
9062306a36Sopenharmony_ci#define TVE200_VSTSTYPE_VSYNC		(0 << 4) /* start of vsync */
9162306a36Sopenharmony_ci#define TVE200_VSTSTYPE_VBP		(1 << 4) /* start of v back porch */
9262306a36Sopenharmony_ci#define TVE200_VSTSTYPE_VAI		(2 << 4) /* start of v active image */
9362306a36Sopenharmony_ci#define TVE200_VSTSTYPE_VFP		(3 << 4) /* start of v front porch */
9462306a36Sopenharmony_ci#define TVE200_VSTSTYPE_BITS		(BIT(4) | BIT(5))
9562306a36Sopenharmony_ci#define TVE200_BGR			BIT(1) /* 0 = RGB, 1 = BGR */
9662306a36Sopenharmony_ci#define TVE200_TVEEN			BIT(0) /* Enable TVE block */
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci#define TVE200_CTRL_2			0x1c
9962306a36Sopenharmony_ci#define TVE200_CTRL_3			0x20
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define TVE200_CTRL_4			0x24
10262306a36Sopenharmony_ci#define TVE200_CTRL_4_RESET		BIT(0) /* triggers reset of TVE200 */
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_cistruct tve200_drm_dev_private {
10562306a36Sopenharmony_ci	struct drm_device *drm;
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci	struct drm_connector *connector;
10862306a36Sopenharmony_ci	struct drm_panel *panel;
10962306a36Sopenharmony_ci	struct drm_bridge *bridge;
11062306a36Sopenharmony_ci	struct drm_simple_display_pipe pipe;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	void *regs;
11362306a36Sopenharmony_ci	struct clk *pclk;
11462306a36Sopenharmony_ci	struct clk *clk;
11562306a36Sopenharmony_ci};
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#define to_tve200_connector(x) \
11862306a36Sopenharmony_ci	container_of(x, struct tve200_drm_connector, connector)
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ciint tve200_display_init(struct drm_device *dev);
12162306a36Sopenharmony_ciirqreturn_t tve200_irq(int irq, void *data);
12262306a36Sopenharmony_ciint tve200_connector_init(struct drm_device *dev);
12362306a36Sopenharmony_ciint tve200_encoder_init(struct drm_device *dev);
12462306a36Sopenharmony_ciint tve200_dumb_create(struct drm_file *file_priv,
12562306a36Sopenharmony_ci		      struct drm_device *dev,
12662306a36Sopenharmony_ci		      struct drm_mode_create_dumb *args);
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci#endif /* _TVE200_DRM_H_ */
129