18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org> 48c2ecf20Sopenharmony_ci * Parts of this file were based on sources as follows: 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2006-2008 Intel Corporation 78c2ecf20Sopenharmony_ci * Copyright (C) 2007 Amos Lee <amos_lee@storlinksemi.com> 88c2ecf20Sopenharmony_ci * Copyright (C) 2007 Dave Airlie <airlied@linux.ie> 98c2ecf20Sopenharmony_ci * Copyright (C) 2011 Texas Instruments 108c2ecf20Sopenharmony_ci * Copyright (C) 2017 Eric Anholt 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifndef _TVE200_DRM_H_ 148c2ecf20Sopenharmony_ci#define _TVE200_DRM_H_ 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#include <linux/irqreturn.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <drm/drm_simple_kms_helper.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct clk; 218c2ecf20Sopenharmony_cistruct drm_bridge; 228c2ecf20Sopenharmony_cistruct drm_connector; 238c2ecf20Sopenharmony_cistruct drm_device; 248c2ecf20Sopenharmony_cistruct drm_file; 258c2ecf20Sopenharmony_cistruct drm_mode_create_dumb; 268c2ecf20Sopenharmony_cistruct drm_panel; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* Bits 2-31 are valid physical base addresses */ 298c2ecf20Sopenharmony_ci#define TVE200_Y_FRAME_BASE_ADDR 0x00 308c2ecf20Sopenharmony_ci#define TVE200_U_FRAME_BASE_ADDR 0x04 318c2ecf20Sopenharmony_ci#define TVE200_V_FRAME_BASE_ADDR 0x08 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#define TVE200_INT_EN 0x0C 348c2ecf20Sopenharmony_ci#define TVE200_INT_CLR 0x10 358c2ecf20Sopenharmony_ci#define TVE200_INT_STAT 0x14 368c2ecf20Sopenharmony_ci#define TVE200_INT_BUS_ERR BIT(7) 378c2ecf20Sopenharmony_ci#define TVE200_INT_V_STATUS BIT(6) /* vertical blank */ 388c2ecf20Sopenharmony_ci#define TVE200_INT_V_NEXT_FRAME BIT(5) 398c2ecf20Sopenharmony_ci#define TVE200_INT_U_NEXT_FRAME BIT(4) 408c2ecf20Sopenharmony_ci#define TVE200_INT_Y_NEXT_FRAME BIT(3) 418c2ecf20Sopenharmony_ci#define TVE200_INT_V_FIFO_UNDERRUN BIT(2) 428c2ecf20Sopenharmony_ci#define TVE200_INT_U_FIFO_UNDERRUN BIT(1) 438c2ecf20Sopenharmony_ci#define TVE200_INT_Y_FIFO_UNDERRUN BIT(0) 448c2ecf20Sopenharmony_ci#define TVE200_FIFO_UNDERRUNS (TVE200_INT_V_FIFO_UNDERRUN | \ 458c2ecf20Sopenharmony_ci TVE200_INT_U_FIFO_UNDERRUN | \ 468c2ecf20Sopenharmony_ci TVE200_INT_Y_FIFO_UNDERRUN) 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci#define TVE200_CTRL 0x18 498c2ecf20Sopenharmony_ci#define TVE200_CTRL_YUV420 BIT(31) 508c2ecf20Sopenharmony_ci#define TVE200_CTRL_CSMODE BIT(30) 518c2ecf20Sopenharmony_ci#define TVE200_CTRL_NONINTERLACE BIT(28) /* 0 = non-interlace CCIR656 */ 528c2ecf20Sopenharmony_ci#define TVE200_CTRL_TVCLKP BIT(27) /* Inverted clock phase */ 538c2ecf20Sopenharmony_ci/* Bits 24..26 define the burst size after arbitration on the bus */ 548c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_4_WORDS (0 << 24) 558c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_8_WORDS (1 << 24) 568c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_16_WORDS (2 << 24) 578c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_32_WORDS (3 << 24) 588c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_64_WORDS (4 << 24) 598c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_128_WORDS (5 << 24) 608c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_256_WORDS (6 << 24) 618c2ecf20Sopenharmony_ci#define TVE200_CTRL_BURST_0_WORDS (7 << 24) /* ? */ 628c2ecf20Sopenharmony_ci/* 638c2ecf20Sopenharmony_ci * Bits 16..23 is the retry count*16 before issueing a new AHB transfer 648c2ecf20Sopenharmony_ci * on the AHB bus. 658c2ecf20Sopenharmony_ci */ 668c2ecf20Sopenharmony_ci#define TVE200_CTRL_RETRYCNT_MASK GENMASK(23, 16) 678c2ecf20Sopenharmony_ci#define TVE200_CTRL_RETRYCNT_16 (1 << 16) 688c2ecf20Sopenharmony_ci#define TVE200_CTRL_BBBP BIT(15) /* 0 = little-endian */ 698c2ecf20Sopenharmony_ci/* Bits 12..14 define the YCbCr ordering */ 708c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CB0Y0CR0Y1 (0 << 12) 718c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y0CB0Y1CR0 (1 << 12) 728c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CR0Y0CB0Y1 (2 << 12) 738c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y1CB0Y0CR0 (3 << 12) 748c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CR0Y1CB0Y0 (4 << 12) 758c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y1CR0Y0CB0 (5 << 12) 768c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_CB0Y1CR0Y0 (6 << 12) 778c2ecf20Sopenharmony_ci#define TVE200_CTRL_YCBCRODR_Y0CR0Y1CB0 (7 << 12) 788c2ecf20Sopenharmony_ci/* Bits 10..11 define the input resolution (framebuffer size) */ 798c2ecf20Sopenharmony_ci#define TVE200_CTRL_IPRESOL_CIF (0 << 10) 808c2ecf20Sopenharmony_ci#define TVE200_CTRL_IPRESOL_VGA (1 << 10) 818c2ecf20Sopenharmony_ci#define TVE200_CTRL_IPRESOL_D1 (2 << 10) 828c2ecf20Sopenharmony_ci#define TVE200_CTRL_NTSC BIT(9) /* 0 = PAL, 1 = NTSC */ 838c2ecf20Sopenharmony_ci#define TVE200_CTRL_INTERLACE BIT(8) /* 1 = interlace, only for D1 */ 848c2ecf20Sopenharmony_ci#define TVE200_IPDMOD_RGB555 (0 << 6) /* TVE200_CTRL_YUV420 = 0 */ 858c2ecf20Sopenharmony_ci#define TVE200_IPDMOD_RGB565 (1 << 6) 868c2ecf20Sopenharmony_ci#define TVE200_IPDMOD_RGB888 (2 << 6) 878c2ecf20Sopenharmony_ci#define TVE200_IPDMOD_YUV420 (2 << 6) /* TVE200_CTRL_YUV420 = 1 */ 888c2ecf20Sopenharmony_ci#define TVE200_IPDMOD_YUV422 (3 << 6) 898c2ecf20Sopenharmony_ci/* Bits 4 & 5 define when to fire the vblank IRQ */ 908c2ecf20Sopenharmony_ci#define TVE200_VSTSTYPE_VSYNC (0 << 4) /* start of vsync */ 918c2ecf20Sopenharmony_ci#define TVE200_VSTSTYPE_VBP (1 << 4) /* start of v back porch */ 928c2ecf20Sopenharmony_ci#define TVE200_VSTSTYPE_VAI (2 << 4) /* start of v active image */ 938c2ecf20Sopenharmony_ci#define TVE200_VSTSTYPE_VFP (3 << 4) /* start of v front porch */ 948c2ecf20Sopenharmony_ci#define TVE200_VSTSTYPE_BITS (BIT(4) | BIT(5)) 958c2ecf20Sopenharmony_ci#define TVE200_BGR BIT(1) /* 0 = RGB, 1 = BGR */ 968c2ecf20Sopenharmony_ci#define TVE200_TVEEN BIT(0) /* Enable TVE block */ 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define TVE200_CTRL_2 0x1c 998c2ecf20Sopenharmony_ci#define TVE200_CTRL_3 0x20 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#define TVE200_CTRL_4 0x24 1028c2ecf20Sopenharmony_ci#define TVE200_CTRL_4_RESET BIT(0) /* triggers reset of TVE200 */ 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_cistruct tve200_drm_dev_private { 1058c2ecf20Sopenharmony_ci struct drm_device *drm; 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci struct drm_connector *connector; 1088c2ecf20Sopenharmony_ci struct drm_panel *panel; 1098c2ecf20Sopenharmony_ci struct drm_bridge *bridge; 1108c2ecf20Sopenharmony_ci struct drm_simple_display_pipe pipe; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci void *regs; 1138c2ecf20Sopenharmony_ci struct clk *pclk; 1148c2ecf20Sopenharmony_ci struct clk *clk; 1158c2ecf20Sopenharmony_ci}; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci#define to_tve200_connector(x) \ 1188c2ecf20Sopenharmony_ci container_of(x, struct tve200_drm_connector, connector) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ciint tve200_display_init(struct drm_device *dev); 1218c2ecf20Sopenharmony_ciirqreturn_t tve200_irq(int irq, void *data); 1228c2ecf20Sopenharmony_ciint tve200_connector_init(struct drm_device *dev); 1238c2ecf20Sopenharmony_ciint tve200_encoder_init(struct drm_device *dev); 1248c2ecf20Sopenharmony_ciint tve200_dumb_create(struct drm_file *file_priv, 1258c2ecf20Sopenharmony_ci struct drm_device *dev, 1268c2ecf20Sopenharmony_ci struct drm_mode_create_dumb *args); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci#endif /* _TVE200_DRM_H_ */ 129