1*caab277bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
216ea975eSRob Clark /*
316ea975eSRob Clark * Copyright (C) 2012 Texas Instruments
416ea975eSRob Clark * Author: Rob Clark <robdclark@gmail.com>
516ea975eSRob Clark */
616ea975eSRob Clark
716ea975eSRob Clark #ifndef __TILCDC_REGS_H__
816ea975eSRob Clark #define __TILCDC_REGS_H__
916ea975eSRob Clark
1016ea975eSRob Clark /* LCDC register definitions, based on da8xx-fb */
1116ea975eSRob Clark
1216ea975eSRob Clark #include <linux/bitops.h>
1316ea975eSRob Clark
1416ea975eSRob Clark #include "tilcdc_drv.h"
1516ea975eSRob Clark
1616ea975eSRob Clark /* LCDC Status Register */
1716ea975eSRob Clark #define LCDC_END_OF_FRAME1 BIT(9)
1816ea975eSRob Clark #define LCDC_END_OF_FRAME0 BIT(8)
1916ea975eSRob Clark #define LCDC_PL_LOAD_DONE BIT(6)
2016ea975eSRob Clark #define LCDC_FIFO_UNDERFLOW BIT(5)
2116ea975eSRob Clark #define LCDC_SYNC_LOST BIT(2)
2216ea975eSRob Clark #define LCDC_FRAME_DONE BIT(0)
2316ea975eSRob Clark
2416ea975eSRob Clark /* LCDC DMA Control Register */
2516ea975eSRob Clark #define LCDC_DMA_BURST_SIZE(x) ((x) << 4)
260f92e898SJyri Sarha #define LCDC_DMA_BURST_SIZE_MASK ((0x7) << 4)
2716ea975eSRob Clark #define LCDC_DMA_BURST_1 0x0
2816ea975eSRob Clark #define LCDC_DMA_BURST_2 0x1
2916ea975eSRob Clark #define LCDC_DMA_BURST_4 0x2
3016ea975eSRob Clark #define LCDC_DMA_BURST_8 0x3
3116ea975eSRob Clark #define LCDC_DMA_BURST_16 0x4
320f92e898SJyri Sarha #define LCDC_DMA_FIFO_THRESHOLD(x) ((x) << 8)
330f92e898SJyri Sarha #define LCDC_DMA_FIFO_THRESHOLD_MASK ((0x3) << 8)
3416ea975eSRob Clark #define LCDC_V1_END_OF_FRAME_INT_ENA BIT(2)
3516ea975eSRob Clark #define LCDC_V2_END_OF_FRAME0_INT_ENA BIT(8)
3616ea975eSRob Clark #define LCDC_V2_END_OF_FRAME1_INT_ENA BIT(9)
3716ea975eSRob Clark #define LCDC_DUAL_FRAME_BUFFER_ENABLE BIT(0)
3816ea975eSRob Clark
3916ea975eSRob Clark /* LCDC Control Register */
4016ea975eSRob Clark #define LCDC_CLK_DIVISOR(x) ((x) << 8)
410f92e898SJyri Sarha #define LCDC_CLK_DIVISOR_MASK ((0xFF) << 8)
4216ea975eSRob Clark #define LCDC_RASTER_MODE 0x01
4316ea975eSRob Clark
4416ea975eSRob Clark /* LCDC Raster Control Register */
4516ea975eSRob Clark #define LCDC_PALETTE_LOAD_MODE(x) ((x) << 20)
460f92e898SJyri Sarha #define LCDC_PALETTE_LOAD_MODE_MASK ((0x3) << 20)
4716ea975eSRob Clark #define PALETTE_AND_DATA 0x00
4816ea975eSRob Clark #define PALETTE_ONLY 0x01
4916ea975eSRob Clark #define DATA_ONLY 0x02
5016ea975eSRob Clark
5116ea975eSRob Clark #define LCDC_MONO_8BIT_MODE BIT(9)
5216ea975eSRob Clark #define LCDC_RASTER_ORDER BIT(8)
5316ea975eSRob Clark #define LCDC_TFT_MODE BIT(7)
5416ea975eSRob Clark #define LCDC_V1_UNDERFLOW_INT_ENA BIT(6)
5516ea975eSRob Clark #define LCDC_V2_UNDERFLOW_INT_ENA BIT(5)
5616ea975eSRob Clark #define LCDC_V1_PL_INT_ENA BIT(4)
5716ea975eSRob Clark #define LCDC_V2_PL_INT_ENA BIT(6)
58cba8844aSJyri Sarha #define LCDC_V1_SYNC_LOST_INT_ENA BIT(5)
593672583fSJyri Sarha #define LCDC_V1_FRAME_DONE_INT_ENA BIT(3)
6016ea975eSRob Clark #define LCDC_MONOCHROME_MODE BIT(1)
6116ea975eSRob Clark #define LCDC_RASTER_ENABLE BIT(0)
6216ea975eSRob Clark #define LCDC_TFT_ALT_ENABLE BIT(23)
6316ea975eSRob Clark #define LCDC_STN_565_ENABLE BIT(24)
6416ea975eSRob Clark #define LCDC_V2_DMA_CLK_EN BIT(2)
6516ea975eSRob Clark #define LCDC_V2_LIDD_CLK_EN BIT(1)
6616ea975eSRob Clark #define LCDC_V2_CORE_CLK_EN BIT(0)
6716ea975eSRob Clark #define LCDC_V2_LPP_B10 26
6816ea975eSRob Clark #define LCDC_V2_TFT_24BPP_MODE BIT(25)
6916ea975eSRob Clark #define LCDC_V2_TFT_24BPP_UNPACK BIT(26)
7016ea975eSRob Clark
7116ea975eSRob Clark /* LCDC Raster Timing 2 Register */
7216ea975eSRob Clark #define LCDC_AC_BIAS_TRANSITIONS_PER_INT(x) ((x) << 16)
730f92e898SJyri Sarha #define LCDC_AC_BIAS_TRANSITIONS_PER_INT_MASK ((0xF) << 16)
7416ea975eSRob Clark #define LCDC_AC_BIAS_FREQUENCY(x) ((x) << 8)
750f92e898SJyri Sarha #define LCDC_AC_BIAS_FREQUENCY_MASK ((0xFF) << 8)
7616ea975eSRob Clark #define LCDC_SYNC_CTRL BIT(25)
7716ea975eSRob Clark #define LCDC_SYNC_EDGE BIT(24)
7816ea975eSRob Clark #define LCDC_INVERT_PIXEL_CLOCK BIT(22)
7916ea975eSRob Clark #define LCDC_INVERT_HSYNC BIT(21)
8016ea975eSRob Clark #define LCDC_INVERT_VSYNC BIT(20)
816bf02c66SDarren Etheridge #define LCDC_LPP_B10 BIT(26)
8216ea975eSRob Clark
8316ea975eSRob Clark /* LCDC Block */
8416ea975eSRob Clark #define LCDC_PID_REG 0x0
8516ea975eSRob Clark #define LCDC_CTRL_REG 0x4
8616ea975eSRob Clark #define LCDC_STAT_REG 0x8
8716ea975eSRob Clark #define LCDC_RASTER_CTRL_REG 0x28
8816ea975eSRob Clark #define LCDC_RASTER_TIMING_0_REG 0x2c
8916ea975eSRob Clark #define LCDC_RASTER_TIMING_1_REG 0x30
9016ea975eSRob Clark #define LCDC_RASTER_TIMING_2_REG 0x34
9116ea975eSRob Clark #define LCDC_DMA_CTRL_REG 0x40
9216ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_0_REG 0x44
9316ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_0_REG 0x48
9416ea975eSRob Clark #define LCDC_DMA_FB_BASE_ADDR_1_REG 0x4c
9516ea975eSRob Clark #define LCDC_DMA_FB_CEILING_ADDR_1_REG 0x50
9616ea975eSRob Clark
9716ea975eSRob Clark /* Interrupt Registers available only in Version 2 */
9816ea975eSRob Clark #define LCDC_RAW_STAT_REG 0x58
9916ea975eSRob Clark #define LCDC_MASKED_STAT_REG 0x5c
10016ea975eSRob Clark #define LCDC_INT_ENABLE_SET_REG 0x60
10116ea975eSRob Clark #define LCDC_INT_ENABLE_CLR_REG 0x64
10216ea975eSRob Clark #define LCDC_END_OF_INT_IND_REG 0x68
10316ea975eSRob Clark
10416ea975eSRob Clark /* Clock registers available only on Version 2 */
10516ea975eSRob Clark #define LCDC_CLK_ENABLE_REG 0x6c
10616ea975eSRob Clark #define LCDC_CLK_RESET_REG 0x70
10716ea975eSRob Clark #define LCDC_CLK_MAIN_RESET BIT(3)
10816ea975eSRob Clark
10916ea975eSRob Clark
11016ea975eSRob Clark /*
11116ea975eSRob Clark * Helpers:
11216ea975eSRob Clark */
11316ea975eSRob Clark
tilcdc_write(struct drm_device * dev,u32 reg,u32 data)11416ea975eSRob Clark static inline void tilcdc_write(struct drm_device *dev, u32 reg, u32 data)
11516ea975eSRob Clark {
11616ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private;
11716ea975eSRob Clark iowrite32(data, priv->mmio + reg);
11816ea975eSRob Clark }
11916ea975eSRob Clark
tilcdc_write64(struct drm_device * dev,u32 reg,u64 data)1207eb9f069SJyri Sarha static inline void tilcdc_write64(struct drm_device *dev, u32 reg, u64 data)
1217eb9f069SJyri Sarha {
1227eb9f069SJyri Sarha struct tilcdc_drm_private *priv = dev->dev_private;
1237eb9f069SJyri Sarha volatile void __iomem *addr = priv->mmio + reg;
1247eb9f069SJyri Sarha
1254e5ca2d9SLogan Gunthorpe #if defined(iowrite64) && !defined(iowrite64_is_nonatomic)
1267eb9f069SJyri Sarha iowrite64(data, addr);
1277eb9f069SJyri Sarha #else
1287eb9f069SJyri Sarha __iowmb();
1297eb9f069SJyri Sarha /* This compiles to strd (=64-bit write) on ARM7 */
1307eb9f069SJyri Sarha *(volatile u64 __force *)addr = __cpu_to_le64(data);
1317eb9f069SJyri Sarha #endif
1327eb9f069SJyri Sarha }
1337eb9f069SJyri Sarha
tilcdc_read(struct drm_device * dev,u32 reg)13416ea975eSRob Clark static inline u32 tilcdc_read(struct drm_device *dev, u32 reg)
13516ea975eSRob Clark {
13616ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private;
13716ea975eSRob Clark return ioread32(priv->mmio + reg);
13816ea975eSRob Clark }
13916ea975eSRob Clark
tilcdc_write_mask(struct drm_device * dev,u32 reg,u32 val,u32 mask)1400f92e898SJyri Sarha static inline void tilcdc_write_mask(struct drm_device *dev, u32 reg,
1410f92e898SJyri Sarha u32 val, u32 mask)
1420f92e898SJyri Sarha {
1430f92e898SJyri Sarha tilcdc_write(dev, reg, (tilcdc_read(dev, reg) & ~mask) | (val & mask));
1440f92e898SJyri Sarha }
1450f92e898SJyri Sarha
tilcdc_set(struct drm_device * dev,u32 reg,u32 mask)14616ea975eSRob Clark static inline void tilcdc_set(struct drm_device *dev, u32 reg, u32 mask)
14716ea975eSRob Clark {
14816ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) | mask);
14916ea975eSRob Clark }
15016ea975eSRob Clark
tilcdc_clear(struct drm_device * dev,u32 reg,u32 mask)15116ea975eSRob Clark static inline void tilcdc_clear(struct drm_device *dev, u32 reg, u32 mask)
15216ea975eSRob Clark {
15316ea975eSRob Clark tilcdc_write(dev, reg, tilcdc_read(dev, reg) & ~mask);
15416ea975eSRob Clark }
15516ea975eSRob Clark
15616ea975eSRob Clark /* the register to read/clear irqstatus differs between v1 and v2 of the IP */
tilcdc_irqstatus_reg(struct drm_device * dev)15716ea975eSRob Clark static inline u32 tilcdc_irqstatus_reg(struct drm_device *dev)
15816ea975eSRob Clark {
15916ea975eSRob Clark struct tilcdc_drm_private *priv = dev->dev_private;
16016ea975eSRob Clark return (priv->rev == 2) ? LCDC_MASKED_STAT_REG : LCDC_STAT_REG;
16116ea975eSRob Clark }
16216ea975eSRob Clark
tilcdc_read_irqstatus(struct drm_device * dev)16316ea975eSRob Clark static inline u32 tilcdc_read_irqstatus(struct drm_device *dev)
16416ea975eSRob Clark {
16516ea975eSRob Clark return tilcdc_read(dev, tilcdc_irqstatus_reg(dev));
16616ea975eSRob Clark }
16716ea975eSRob Clark
tilcdc_clear_irqstatus(struct drm_device * dev,u32 mask)16816ea975eSRob Clark static inline void tilcdc_clear_irqstatus(struct drm_device *dev, u32 mask)
16916ea975eSRob Clark {
17016ea975eSRob Clark tilcdc_write(dev, tilcdc_irqstatus_reg(dev), mask);
17116ea975eSRob Clark }
17216ea975eSRob Clark
17316ea975eSRob Clark #endif /* __TILCDC_REGS_H__ */
174