116ea975eSRob Clark /* 216ea975eSRob Clark * Copyright (C) 2012 Texas Instruments 316ea975eSRob Clark * Author: Rob Clark <robdclark@gmail.com> 416ea975eSRob Clark * 516ea975eSRob Clark * This program is free software; you can redistribute it and/or modify it 616ea975eSRob Clark * under the terms of the GNU General Public License version 2 as published by 716ea975eSRob Clark * the Free Software Foundation. 816ea975eSRob Clark * 916ea975eSRob Clark * This program is distributed in the hope that it will be useful, but WITHOUT 1016ea975eSRob Clark * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1116ea975eSRob Clark * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1216ea975eSRob Clark * more details. 1316ea975eSRob Clark * 1416ea975eSRob Clark * You should have received a copy of the GNU General Public License along with 1516ea975eSRob Clark * this program. If not, see <http://www.gnu.org/licenses/>. 1616ea975eSRob Clark */ 1716ea975eSRob Clark 1816ea975eSRob Clark #ifndef __TILCDC_REGS_H__ 1916ea975eSRob Clark #define __TILCDC_REGS_H__ 2016ea975eSRob Clark 2116ea975eSRob Clark /* LCDC register definitions, based on da8xx-fb */ 2216ea975eSRob Clark 2316ea975eSRob Clark #include <linux/bitops.h> 2416ea975eSRob Clark 2516ea975eSRob Clark #include "tilcdc_drv.h" 2616ea975eSRob Clark 2716ea975eSRob Clark /* LCDC Status Register */ 2816ea975eSRob Clark #define LCDC_END_OF_FRAME1 BIT(9) 2916ea975eSRob Clark #define LCDC_END_OF_FRAME0 BIT(8) 3016ea975eSRob Clark #define LCDC_PL_LOAD_DONE BIT(6) 3116ea975eSRob Clark #define LCDC_FIFO_UNDERFLOW BIT(5) 3216ea975eSRob Clark #define LCDC_SYNC_LOST BIT(2) 3316ea975eSRob Clark #define LCDC_FRAME_DONE BIT(0) 3416ea975eSRob Clark 3516ea975eSRob Clark /* LCDC DMA Control Register */ 3616ea975eSRob Clark #define LCDC_DMA_BURST_SIZE(x) ((x) << 4) 3716ea975eSRob Clark #define LCDC_DMA_BURST_1 0x0 3816ea975eSRob Clark #define LCDC_DMA_BURST_2 0x1 3916ea975eSRob Clark #define LCDC_DMA_BURST_4 0x2 4016ea975eSRob Clark #define LCDC_DMA_BURST_8 0x3 4116ea975eSRob Clark #define LCDC_DMA_BURST_16 0x4 4216ea975eSRob Clark #define LCDC_V1_END_OF_FRAME_INT_ENA BIT(2) 4316ea975eSRob Clark #define LCDC_V2_END_OF_FRAME0_INT_ENA BIT(8) 4416ea975eSRob Clark #define LCDC_V2_END_OF_FRAME1_INT_ENA BIT(9) 4516ea975eSRob Clark #define LCDC_DUAL_FRAME_BUFFER_ENABLE BIT(0) 4616ea975eSRob Clark 4716ea975eSRob Clark /* LCDC Control Register */ 4816ea975eSRob Clark #define LCDC_CLK_DIVISOR(x) ((x) << 8) 4916ea975eSRob Clark #define LCDC_RASTER_MODE 0x01 5016ea975eSRob Clark 5116ea975eSRob Clark /* LCDC Raster Control Register */ 5216ea975eSRob Clark #define LCDC_PALETTE_LOAD_MODE(x) ((x) << 20) 5316ea975eSRob Clark #define PALETTE_AND_DATA 0x00 5416ea975eSRob Clark #define PALETTE_ONLY 0x01 5516ea975eSRob Clark #define DATA_ONLY 0x02 5616ea975eSRob Clark 5716ea975eSRob Clark #define LCDC_MONO_8BIT_MODE BIT(9) 5816ea975eSRob Clark #define LCDC_RASTER_ORDER BIT(8) 5916ea975eSRob Clark #define LCDC_TFT_MODE BIT(7) 6016ea975eSRob Clark #define LCDC_V1_UNDERFLOW_INT_ENA BIT(6) 6116ea975eSRob Clark #define LCDC_V2_UNDERFLOW_INT_ENA BIT(5) 6216ea975eSRob Clark #define LCDC_V1_PL_INT_ENA BIT(4) 6316ea975eSRob Clark #define LCDC_V2_PL_INT_ENA BIT(6) 64*cba8844aSJyri Sarha #define LCDC_V1_SYNC_LOST_INT_ENA BIT(5) 6516ea975eSRob Clark #define LCDC_MONOCHROME_MODE BIT(1) 6616ea975eSRob Clark #define LCDC_RASTER_ENABLE BIT(0) 6716ea975eSRob Clark #define LCDC_TFT_ALT_ENABLE BIT(23) 6816ea975eSRob Clark #define LCDC_STN_565_ENABLE BIT(24) 6916ea975eSRob Clark #define LCDC_V2_DMA_CLK_EN BIT(2) 7016ea975eSRob Clark #define LCDC_V2_LIDD_CLK_EN BIT(1) 7116ea975eSRob Clark #define LCDC_V2_CORE_CLK_EN BIT(0) 7216ea975eSRob Clark #define LCDC_V2_LPP_B10 26 7316ea975eSRob Clark #define LCDC_V2_TFT_24BPP_MODE BIT(25) 7416ea975eSRob Clark #define LCDC_V2_TFT_24BPP_UNPACK BIT(26) 7516ea975eSRob Clark 7616ea975eSRob Clark /* LCDC Raster Timing 2 Register */ 7716ea975eSRob Clark #define LCDC_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16) 7816ea975eSRob Clark #define LCDC_AC_BIAS_FREQUENCY(x) ((x) << 8) 7916ea975eSRob Clark #define LCDC_SYNC_CTRL BIT(25) 8016ea975eSRob Clark #define LCDC_SYNC_EDGE BIT(24) 8116ea975eSRob Clark #define LCDC_INVERT_PIXEL_CLOCK BIT(22) 8216ea975eSRob Clark #define LCDC_INVERT_HSYNC BIT(21) 8316ea975eSRob Clark #define LCDC_INVERT_VSYNC BIT(20) 846bf02c66SDarren Etheridge #define LCDC_LPP_B10 BIT(26) 8516ea975eSRob Clark 8616ea975eSRob Clark /* LCDC Block */ 8716ea975eSRob Clark #define LCDC_PID_REG 0x0 8816ea975eSRob Clark #define LCDC_CTRL_REG 0x4 8916ea975eSRob Clark #define LCDC_STAT_REG 0x8 9016ea975eSRob Clark #define LCDC_RASTER_CTRL_REG 0x28 9116ea975eSRob Clark #define LCDC_RASTER_TIMING_0_REG 0x2c 9216ea975eSRob Clark #define LCDC_RASTER_TIMING_1_REG 0x30 9316ea975eSRob Clark #define LCDC_RASTER_TIMING_2_REG 0x34 9416ea975eSRob Clark #define LCDC_DMA_CTRL_REG 0x40 9516ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_0_REG 0x44 9616ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_0_REG 0x48 9716ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_1_REG 0x4c 9816ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_1_REG 0x50 9916ea975eSRob Clark 10016ea975eSRob Clark /* Interrupt Registers available only in Version 2 */ 10116ea975eSRob Clark #define LCDC_RAW_STAT_REG 0x58 10216ea975eSRob Clark #define LCDC_MASKED_STAT_REG 0x5c 10316ea975eSRob Clark #define LCDC_INT_ENABLE_SET_REG 0x60 10416ea975eSRob Clark #define LCDC_INT_ENABLE_CLR_REG 0x64 10516ea975eSRob Clark #define LCDC_END_OF_INT_IND_REG 0x68 10616ea975eSRob Clark 10716ea975eSRob Clark /* Clock registers available only on Version 2 */ 10816ea975eSRob Clark #define LCDC_CLK_ENABLE_REG 0x6c 10916ea975eSRob Clark #define LCDC_CLK_RESET_REG 0x70 11016ea975eSRob Clark #define LCDC_CLK_MAIN_RESET BIT(3) 11116ea975eSRob Clark 11216ea975eSRob Clark 11316ea975eSRob Clark /* 11416ea975eSRob Clark * Helpers: 11516ea975eSRob Clark */ 11616ea975eSRob Clark 11716ea975eSRob Clark static inline void tilcdc_write(struct drm_device *dev, u32 reg, u32 data) 11816ea975eSRob Clark { 11916ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 12016ea975eSRob Clark iowrite32(data, priv->mmio + reg); 12116ea975eSRob Clark } 12216ea975eSRob Clark 1237eb9f069SJyri Sarha static inline void tilcdc_write64(struct drm_device *dev, u32 reg, u64 data) 1247eb9f069SJyri Sarha { 1257eb9f069SJyri Sarha struct tilcdc_drm_private *priv = dev->dev_private; 1267eb9f069SJyri Sarha volatile void __iomem *addr = priv->mmio + reg; 1277eb9f069SJyri Sarha 1287eb9f069SJyri Sarha #ifdef iowrite64 1297eb9f069SJyri Sarha iowrite64(data, addr); 1307eb9f069SJyri Sarha #else 1317eb9f069SJyri Sarha __iowmb(); 1327eb9f069SJyri Sarha /* This compiles to strd (=64-bit write) on ARM7 */ 1337eb9f069SJyri Sarha *(volatile u64 __force *)addr = __cpu_to_le64(data); 1347eb9f069SJyri Sarha #endif 1357eb9f069SJyri Sarha } 1367eb9f069SJyri Sarha 13716ea975eSRob Clark static inline u32 tilcdc_read(struct drm_device *dev, u32 reg) 13816ea975eSRob Clark { 13916ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 14016ea975eSRob Clark return ioread32(priv->mmio + reg); 14116ea975eSRob Clark } 14216ea975eSRob Clark 14316ea975eSRob Clark static inline void tilcdc_set(struct drm_device *dev, u32 reg, u32 mask) 14416ea975eSRob Clark { 14516ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) | mask); 14616ea975eSRob Clark } 14716ea975eSRob Clark 14816ea975eSRob Clark static inline void tilcdc_clear(struct drm_device *dev, u32 reg, u32 mask) 14916ea975eSRob Clark { 15016ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) & ~mask); 15116ea975eSRob Clark } 15216ea975eSRob Clark 15316ea975eSRob Clark /* the register to read/clear irqstatus differs between v1 and v2 of the IP */ 15416ea975eSRob Clark static inline u32 tilcdc_irqstatus_reg(struct drm_device *dev) 15516ea975eSRob Clark { 15616ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 15716ea975eSRob Clark return (priv->rev == 2) ? LCDC_MASKED_STAT_REG : LCDC_STAT_REG; 15816ea975eSRob Clark } 15916ea975eSRob Clark 16016ea975eSRob Clark static inline u32 tilcdc_read_irqstatus(struct drm_device *dev) 16116ea975eSRob Clark { 16216ea975eSRob Clark return tilcdc_read(dev, tilcdc_irqstatus_reg(dev)); 16316ea975eSRob Clark } 16416ea975eSRob Clark 16516ea975eSRob Clark static inline void tilcdc_clear_irqstatus(struct drm_device *dev, u32 mask) 16616ea975eSRob Clark { 16716ea975eSRob Clark tilcdc_write(dev, tilcdc_irqstatus_reg(dev), mask); 16816ea975eSRob Clark } 16916ea975eSRob Clark 17016ea975eSRob Clark #endif /* __TILCDC_REGS_H__ */ 171