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) 370f92e898SJyri Sarha #define LCDC_DMA_BURST_SIZE_MASK ((0x7) << 4) 3816ea975eSRob Clark #define LCDC_DMA_BURST_1 0x0 3916ea975eSRob Clark #define LCDC_DMA_BURST_2 0x1 4016ea975eSRob Clark #define LCDC_DMA_BURST_4 0x2 4116ea975eSRob Clark #define LCDC_DMA_BURST_8 0x3 4216ea975eSRob Clark #define LCDC_DMA_BURST_16 0x4 430f92e898SJyri Sarha #define LCDC_DMA_FIFO_THRESHOLD(x) ((x) << 8) 440f92e898SJyri Sarha #define LCDC_DMA_FIFO_THRESHOLD_MASK ((0x3) << 8) 4516ea975eSRob Clark #define LCDC_V1_END_OF_FRAME_INT_ENA BIT(2) 4616ea975eSRob Clark #define LCDC_V2_END_OF_FRAME0_INT_ENA BIT(8) 4716ea975eSRob Clark #define LCDC_V2_END_OF_FRAME1_INT_ENA BIT(9) 4816ea975eSRob Clark #define LCDC_DUAL_FRAME_BUFFER_ENABLE BIT(0) 4916ea975eSRob Clark 5016ea975eSRob Clark /* LCDC Control Register */ 5116ea975eSRob Clark #define LCDC_CLK_DIVISOR(x) ((x) << 8) 520f92e898SJyri Sarha #define LCDC_CLK_DIVISOR_MASK ((0xFF) << 8) 5316ea975eSRob Clark #define LCDC_RASTER_MODE 0x01 5416ea975eSRob Clark 5516ea975eSRob Clark /* LCDC Raster Control Register */ 5616ea975eSRob Clark #define LCDC_PALETTE_LOAD_MODE(x) ((x) << 20) 570f92e898SJyri Sarha #define LCDC_PALETTE_LOAD_MODE_MASK ((0x3) << 20) 5816ea975eSRob Clark #define PALETTE_AND_DATA 0x00 5916ea975eSRob Clark #define PALETTE_ONLY 0x01 6016ea975eSRob Clark #define DATA_ONLY 0x02 6116ea975eSRob Clark 6216ea975eSRob Clark #define LCDC_MONO_8BIT_MODE BIT(9) 6316ea975eSRob Clark #define LCDC_RASTER_ORDER BIT(8) 6416ea975eSRob Clark #define LCDC_TFT_MODE BIT(7) 6516ea975eSRob Clark #define LCDC_V1_UNDERFLOW_INT_ENA BIT(6) 6616ea975eSRob Clark #define LCDC_V2_UNDERFLOW_INT_ENA BIT(5) 6716ea975eSRob Clark #define LCDC_V1_PL_INT_ENA BIT(4) 6816ea975eSRob Clark #define LCDC_V2_PL_INT_ENA BIT(6) 69cba8844aSJyri Sarha #define LCDC_V1_SYNC_LOST_INT_ENA BIT(5) 703672583fSJyri Sarha #define LCDC_V1_FRAME_DONE_INT_ENA BIT(3) 7116ea975eSRob Clark #define LCDC_MONOCHROME_MODE BIT(1) 7216ea975eSRob Clark #define LCDC_RASTER_ENABLE BIT(0) 7316ea975eSRob Clark #define LCDC_TFT_ALT_ENABLE BIT(23) 7416ea975eSRob Clark #define LCDC_STN_565_ENABLE BIT(24) 7516ea975eSRob Clark #define LCDC_V2_DMA_CLK_EN BIT(2) 7616ea975eSRob Clark #define LCDC_V2_LIDD_CLK_EN BIT(1) 7716ea975eSRob Clark #define LCDC_V2_CORE_CLK_EN BIT(0) 7816ea975eSRob Clark #define LCDC_V2_LPP_B10 26 7916ea975eSRob Clark #define LCDC_V2_TFT_24BPP_MODE BIT(25) 8016ea975eSRob Clark #define LCDC_V2_TFT_24BPP_UNPACK BIT(26) 8116ea975eSRob Clark 8216ea975eSRob Clark /* LCDC Raster Timing 2 Register */ 8316ea975eSRob Clark #define LCDC_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16) 840f92e898SJyri Sarha #define LCDC_AC_BIAS_TRANSITIONS_PER_INT_MASK ((0xF) << 16) 8516ea975eSRob Clark #define LCDC_AC_BIAS_FREQUENCY(x) ((x) << 8) 860f92e898SJyri Sarha #define LCDC_AC_BIAS_FREQUENCY_MASK ((0xFF) << 8) 8716ea975eSRob Clark #define LCDC_SYNC_CTRL BIT(25) 8816ea975eSRob Clark #define LCDC_SYNC_EDGE BIT(24) 8916ea975eSRob Clark #define LCDC_INVERT_PIXEL_CLOCK BIT(22) 9016ea975eSRob Clark #define LCDC_INVERT_HSYNC BIT(21) 9116ea975eSRob Clark #define LCDC_INVERT_VSYNC BIT(20) 926bf02c66SDarren Etheridge #define LCDC_LPP_B10 BIT(26) 9316ea975eSRob Clark 9416ea975eSRob Clark /* LCDC Block */ 9516ea975eSRob Clark #define LCDC_PID_REG 0x0 9616ea975eSRob Clark #define LCDC_CTRL_REG 0x4 9716ea975eSRob Clark #define LCDC_STAT_REG 0x8 9816ea975eSRob Clark #define LCDC_RASTER_CTRL_REG 0x28 9916ea975eSRob Clark #define LCDC_RASTER_TIMING_0_REG 0x2c 10016ea975eSRob Clark #define LCDC_RASTER_TIMING_1_REG 0x30 10116ea975eSRob Clark #define LCDC_RASTER_TIMING_2_REG 0x34 10216ea975eSRob Clark #define LCDC_DMA_CTRL_REG 0x40 10316ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_0_REG 0x44 10416ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_0_REG 0x48 10516ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_1_REG 0x4c 10616ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_1_REG 0x50 10716ea975eSRob Clark 10816ea975eSRob Clark /* Interrupt Registers available only in Version 2 */ 10916ea975eSRob Clark #define LCDC_RAW_STAT_REG 0x58 11016ea975eSRob Clark #define LCDC_MASKED_STAT_REG 0x5c 11116ea975eSRob Clark #define LCDC_INT_ENABLE_SET_REG 0x60 11216ea975eSRob Clark #define LCDC_INT_ENABLE_CLR_REG 0x64 11316ea975eSRob Clark #define LCDC_END_OF_INT_IND_REG 0x68 11416ea975eSRob Clark 11516ea975eSRob Clark /* Clock registers available only on Version 2 */ 11616ea975eSRob Clark #define LCDC_CLK_ENABLE_REG 0x6c 11716ea975eSRob Clark #define LCDC_CLK_RESET_REG 0x70 11816ea975eSRob Clark #define LCDC_CLK_MAIN_RESET BIT(3) 11916ea975eSRob Clark 12016ea975eSRob Clark 12116ea975eSRob Clark /* 12216ea975eSRob Clark * Helpers: 12316ea975eSRob Clark */ 12416ea975eSRob Clark 12516ea975eSRob Clark static inline void tilcdc_write(struct drm_device *dev, u32 reg, u32 data) 12616ea975eSRob Clark { 12716ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 12816ea975eSRob Clark iowrite32(data, priv->mmio + reg); 12916ea975eSRob Clark } 13016ea975eSRob Clark 1317eb9f069SJyri Sarha static inline void tilcdc_write64(struct drm_device *dev, u32 reg, u64 data) 1327eb9f069SJyri Sarha { 1337eb9f069SJyri Sarha struct tilcdc_drm_private *priv = dev->dev_private; 1347eb9f069SJyri Sarha volatile void __iomem *addr = priv->mmio + reg; 1357eb9f069SJyri Sarha 136*4e5ca2d9SLogan Gunthorpe #if defined(iowrite64) && !defined(iowrite64_is_nonatomic) 1377eb9f069SJyri Sarha iowrite64(data, addr); 1387eb9f069SJyri Sarha #else 1397eb9f069SJyri Sarha __iowmb(); 1407eb9f069SJyri Sarha /* This compiles to strd (=64-bit write) on ARM7 */ 1417eb9f069SJyri Sarha *(volatile u64 __force *)addr = __cpu_to_le64(data); 1427eb9f069SJyri Sarha #endif 1437eb9f069SJyri Sarha } 1447eb9f069SJyri Sarha 14516ea975eSRob Clark static inline u32 tilcdc_read(struct drm_device *dev, u32 reg) 14616ea975eSRob Clark { 14716ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 14816ea975eSRob Clark return ioread32(priv->mmio + reg); 14916ea975eSRob Clark } 15016ea975eSRob Clark 1510f92e898SJyri Sarha static inline void tilcdc_write_mask(struct drm_device *dev, u32 reg, 1520f92e898SJyri Sarha u32 val, u32 mask) 1530f92e898SJyri Sarha { 1540f92e898SJyri Sarha tilcdc_write(dev, reg, (tilcdc_read(dev, reg) & ~mask) | (val & mask)); 1550f92e898SJyri Sarha } 1560f92e898SJyri Sarha 15716ea975eSRob Clark static inline void tilcdc_set(struct drm_device *dev, u32 reg, u32 mask) 15816ea975eSRob Clark { 15916ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) | mask); 16016ea975eSRob Clark } 16116ea975eSRob Clark 16216ea975eSRob Clark static inline void tilcdc_clear(struct drm_device *dev, u32 reg, u32 mask) 16316ea975eSRob Clark { 16416ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) & ~mask); 16516ea975eSRob Clark } 16616ea975eSRob Clark 16716ea975eSRob Clark /* the register to read/clear irqstatus differs between v1 and v2 of the IP */ 16816ea975eSRob Clark static inline u32 tilcdc_irqstatus_reg(struct drm_device *dev) 16916ea975eSRob Clark { 17016ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private; 17116ea975eSRob Clark return (priv->rev == 2) ? LCDC_MASKED_STAT_REG : LCDC_STAT_REG; 17216ea975eSRob Clark } 17316ea975eSRob Clark 17416ea975eSRob Clark static inline u32 tilcdc_read_irqstatus(struct drm_device *dev) 17516ea975eSRob Clark { 17616ea975eSRob Clark return tilcdc_read(dev, tilcdc_irqstatus_reg(dev)); 17716ea975eSRob Clark } 17816ea975eSRob Clark 17916ea975eSRob Clark static inline void tilcdc_clear_irqstatus(struct drm_device *dev, u32 mask) 18016ea975eSRob Clark { 18116ea975eSRob Clark tilcdc_write(dev, tilcdc_irqstatus_reg(dev), mask); 18216ea975eSRob Clark } 18316ea975eSRob Clark 18416ea975eSRob Clark #endif /* __TILCDC_REGS_H__ */ 185