0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __SUN4I_TCON_H__
0011 #define __SUN4I_TCON_H__
0012
0013 #include <drm/drm_crtc.h>
0014
0015 #include <linux/kernel.h>
0016 #include <linux/list.h>
0017 #include <linux/mod_devicetable.h>
0018 #include <linux/reset.h>
0019
0020 #define SUN4I_TCON_GCTL_REG 0x0
0021 #define SUN4I_TCON_GCTL_TCON_ENABLE BIT(31)
0022 #define SUN4I_TCON_GCTL_IOMAP_MASK BIT(0)
0023 #define SUN4I_TCON_GCTL_IOMAP_TCON1 (1 << 0)
0024 #define SUN4I_TCON_GCTL_IOMAP_TCON0 (0 << 0)
0025
0026 #define SUN4I_TCON_GINT0_REG 0x4
0027 #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe) BIT(31 - (pipe))
0028 #define SUN4I_TCON_GINT0_TCON0_TRI_FINISH_ENABLE BIT(27)
0029 #define SUN4I_TCON_GINT0_TCON0_TRI_COUNTER_ENABLE BIT(26)
0030 #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe))
0031 #define SUN4I_TCON_GINT0_TCON0_TRI_FINISH_INT BIT(11)
0032 #define SUN4I_TCON_GINT0_TCON0_TRI_COUNTER_INT BIT(10)
0033
0034 #define SUN4I_TCON_GINT1_REG 0x8
0035
0036 #define SUN4I_TCON_FRM_CTL_REG 0x10
0037 #define SUN4I_TCON0_FRM_CTL_EN BIT(31)
0038 #define SUN4I_TCON0_FRM_CTL_MODE_R BIT(6)
0039 #define SUN4I_TCON0_FRM_CTL_MODE_G BIT(5)
0040 #define SUN4I_TCON0_FRM_CTL_MODE_B BIT(4)
0041
0042 #define SUN4I_TCON0_FRM_SEED_PR_REG 0x14
0043 #define SUN4I_TCON0_FRM_SEED_PG_REG 0x18
0044 #define SUN4I_TCON0_FRM_SEED_PB_REG 0x1c
0045 #define SUN4I_TCON0_FRM_SEED_LR_REG 0x20
0046 #define SUN4I_TCON0_FRM_SEED_LG_REG 0x24
0047 #define SUN4I_TCON0_FRM_SEED_LB_REG 0x28
0048 #define SUN4I_TCON0_FRM_TBL0_REG 0x2c
0049 #define SUN4I_TCON0_FRM_TBL1_REG 0x30
0050 #define SUN4I_TCON0_FRM_TBL2_REG 0x34
0051 #define SUN4I_TCON0_FRM_TBL3_REG 0x38
0052
0053 #define SUN4I_TCON0_CTL_REG 0x40
0054 #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31)
0055 #define SUN4I_TCON0_CTL_IF_MASK GENMASK(25, 24)
0056 #define SUN4I_TCON0_CTL_IF_8080 (1 << 24)
0057 #define SUN4I_TCON0_CTL_CLK_DELAY_MASK GENMASK(8, 4)
0058 #define SUN4I_TCON0_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK)
0059 #define SUN4I_TCON0_CTL_SRC_SEL_MASK GENMASK(2, 0)
0060
0061 #define SUN4I_TCON0_DCLK_REG 0x44
0062 #define SUN4I_TCON0_DCLK_GATE_BIT (31)
0063 #define SUN4I_TCON0_DCLK_DIV_SHIFT (0)
0064 #define SUN4I_TCON0_DCLK_DIV_WIDTH (7)
0065
0066 #define SUN4I_TCON0_BASIC0_REG 0x48
0067 #define SUN4I_TCON0_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16)
0068 #define SUN4I_TCON0_BASIC0_Y(height) (((height) - 1) & 0xfff)
0069
0070 #define SUN4I_TCON0_BASIC1_REG 0x4c
0071 #define SUN4I_TCON0_BASIC1_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16)
0072 #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp) (((bp) - 1) & 0xfff)
0073
0074 #define SUN4I_TCON0_BASIC2_REG 0x50
0075 #define SUN4I_TCON0_BASIC2_V_TOTAL(total) (((total) & 0x1fff) << 16)
0076 #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp) (((bp) - 1) & 0xfff)
0077
0078 #define SUN4I_TCON0_BASIC3_REG 0x54
0079 #define SUN4I_TCON0_BASIC3_H_SYNC(width) ((((width) - 1) & 0x7ff) << 16)
0080 #define SUN4I_TCON0_BASIC3_V_SYNC(height) (((height) - 1) & 0x7ff)
0081
0082 #define SUN4I_TCON0_HV_IF_REG 0x58
0083
0084 #define SUN4I_TCON0_CPU_IF_REG 0x60
0085 #define SUN4I_TCON0_CPU_IF_MODE_MASK GENMASK(31, 28)
0086 #define SUN4I_TCON0_CPU_IF_MODE_DSI (1 << 28)
0087 #define SUN4I_TCON0_CPU_IF_TRI_FIFO_FLUSH BIT(16)
0088 #define SUN4I_TCON0_CPU_IF_TRI_FIFO_EN BIT(2)
0089 #define SUN4I_TCON0_CPU_IF_TRI_EN BIT(0)
0090
0091 #define SUN4I_TCON0_CPU_WR_REG 0x64
0092 #define SUN4I_TCON0_CPU_RD0_REG 0x68
0093 #define SUN4I_TCON0_CPU_RDA_REG 0x6c
0094 #define SUN4I_TCON0_TTL0_REG 0x70
0095 #define SUN4I_TCON0_TTL1_REG 0x74
0096 #define SUN4I_TCON0_TTL2_REG 0x78
0097 #define SUN4I_TCON0_TTL3_REG 0x7c
0098 #define SUN4I_TCON0_TTL4_REG 0x80
0099
0100 #define SUN4I_TCON0_LVDS_IF_REG 0x84
0101 #define SUN4I_TCON0_LVDS_IF_EN BIT(31)
0102 #define SUN4I_TCON0_LVDS_IF_BITWIDTH_MASK BIT(26)
0103 #define SUN4I_TCON0_LVDS_IF_BITWIDTH_18BITS (1 << 26)
0104 #define SUN4I_TCON0_LVDS_IF_BITWIDTH_24BITS (0 << 26)
0105 #define SUN4I_TCON0_LVDS_IF_CLK_SEL_MASK BIT(20)
0106 #define SUN4I_TCON0_LVDS_IF_CLK_SEL_TCON0 (1 << 20)
0107 #define SUN4I_TCON0_LVDS_IF_CLK_POL_MASK BIT(4)
0108 #define SUN4I_TCON0_LVDS_IF_CLK_POL_NORMAL (1 << 4)
0109 #define SUN4I_TCON0_LVDS_IF_CLK_POL_INV (0 << 4)
0110 #define SUN4I_TCON0_LVDS_IF_DATA_POL_MASK GENMASK(3, 0)
0111 #define SUN4I_TCON0_LVDS_IF_DATA_POL_NORMAL (0xf)
0112 #define SUN4I_TCON0_LVDS_IF_DATA_POL_INV (0)
0113
0114 #define SUN4I_TCON0_IO_POL_REG 0x88
0115 #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28)
0116 #define SUN4I_TCON0_IO_POL_DE_NEGATIVE BIT(27)
0117 #define SUN4I_TCON0_IO_POL_DCLK_DRIVE_NEGEDGE BIT(26)
0118 #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25)
0119 #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24)
0120
0121 #define SUN4I_TCON0_IO_TRI_REG 0x8c
0122 #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25)
0123 #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24)
0124 #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0)
0125
0126 #define SUN4I_TCON1_CTL_REG 0x90
0127 #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31)
0128 #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20)
0129 #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4)
0130 #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK)
0131 #define SUN4I_TCON1_CTL_SRC_SEL_MASK GENMASK(1, 0)
0132
0133 #define SUN4I_TCON1_BASIC0_REG 0x94
0134 #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16)
0135 #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff)
0136
0137 #define SUN4I_TCON1_BASIC1_REG 0x98
0138 #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16)
0139 #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff)
0140
0141 #define SUN4I_TCON1_BASIC2_REG 0x9c
0142 #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16)
0143 #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff)
0144
0145 #define SUN4I_TCON1_BASIC3_REG 0xa0
0146 #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16)
0147 #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff)
0148
0149 #define SUN4I_TCON1_BASIC4_REG 0xa4
0150 #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16)
0151 #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff)
0152
0153 #define SUN4I_TCON1_BASIC5_REG 0xa8
0154 #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16)
0155 #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff)
0156
0157 #define SUN4I_TCON1_IO_POL_REG 0xf0
0158
0159 #define SUN4I_TCON1_IO_POL_UNKNOWN BIT(26)
0160 #define SUN4I_TCON1_IO_POL_HSYNC_POSITIVE BIT(25)
0161 #define SUN4I_TCON1_IO_POL_VSYNC_POSITIVE BIT(24)
0162
0163 #define SUN4I_TCON1_IO_TRI_REG 0xf4
0164
0165 #define SUN4I_TCON_ECC_FIFO_REG 0xf8
0166 #define SUN4I_TCON_ECC_FIFO_EN BIT(3)
0167
0168 #define SUN4I_TCON_CEU_CTL_REG 0x100
0169 #define SUN4I_TCON_CEU_MUL_RR_REG 0x110
0170 #define SUN4I_TCON_CEU_MUL_RG_REG 0x114
0171 #define SUN4I_TCON_CEU_MUL_RB_REG 0x118
0172 #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c
0173 #define SUN4I_TCON_CEU_MUL_GR_REG 0x120
0174 #define SUN4I_TCON_CEU_MUL_GG_REG 0x124
0175 #define SUN4I_TCON_CEU_MUL_GB_REG 0x128
0176 #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c
0177 #define SUN4I_TCON_CEU_MUL_BR_REG 0x130
0178 #define SUN4I_TCON_CEU_MUL_BG_REG 0x134
0179 #define SUN4I_TCON_CEU_MUL_BB_REG 0x138
0180 #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c
0181 #define SUN4I_TCON_CEU_RANGE_R_REG 0x140
0182 #define SUN4I_TCON_CEU_RANGE_G_REG 0x144
0183 #define SUN4I_TCON_CEU_RANGE_B_REG 0x148
0184
0185 #define SUN4I_TCON0_CPU_TRI0_REG 0x160
0186 #define SUN4I_TCON0_CPU_TRI0_BLOCK_SPACE(space) ((((space) - 1) & 0xfff) << 16)
0187 #define SUN4I_TCON0_CPU_TRI0_BLOCK_SIZE(size) (((size) - 1) & 0xfff)
0188
0189 #define SUN4I_TCON0_CPU_TRI1_REG 0x164
0190 #define SUN4I_TCON0_CPU_TRI1_BLOCK_NUM(num) (((num) - 1) & 0xffff)
0191
0192 #define SUN4I_TCON0_CPU_TRI2_REG 0x168
0193 #define SUN4I_TCON0_CPU_TRI2_START_DELAY(delay) (((delay) & 0xffff) << 16)
0194 #define SUN4I_TCON0_CPU_TRI2_TRANS_START_SET(set) ((set) & 0xfff)
0195
0196 #define SUN4I_TCON_SAFE_PERIOD_REG 0x1f0
0197 #define SUN4I_TCON_SAFE_PERIOD_NUM(num) (((num) & 0xfff) << 16)
0198 #define SUN4I_TCON_SAFE_PERIOD_MODE(mode) ((mode) & 0x3)
0199
0200 #define SUN4I_TCON_MUX_CTRL_REG 0x200
0201
0202 #define SUN4I_TCON0_LVDS_ANA0_REG 0x220
0203 #define SUN4I_TCON0_LVDS_ANA0_DCHS BIT(16)
0204 #define SUN4I_TCON0_LVDS_ANA0_PD (BIT(20) | BIT(21))
0205 #define SUN4I_TCON0_LVDS_ANA0_EN_MB BIT(22)
0206 #define SUN4I_TCON0_LVDS_ANA0_REG_C (BIT(24) | BIT(25))
0207 #define SUN4I_TCON0_LVDS_ANA0_REG_V (BIT(26) | BIT(27))
0208 #define SUN4I_TCON0_LVDS_ANA0_CK_EN (BIT(29) | BIT(28))
0209
0210 #define SUN6I_TCON0_LVDS_ANA0_EN_MB BIT(31)
0211 #define SUN6I_TCON0_LVDS_ANA0_EN_LDO BIT(30)
0212 #define SUN6I_TCON0_LVDS_ANA0_EN_DRVC BIT(24)
0213 #define SUN6I_TCON0_LVDS_ANA0_EN_DRVD(x) (((x) & 0xf) << 20)
0214 #define SUN6I_TCON0_LVDS_ANA0_C(x) (((x) & 3) << 17)
0215 #define SUN6I_TCON0_LVDS_ANA0_V(x) (((x) & 3) << 8)
0216 #define SUN6I_TCON0_LVDS_ANA0_PD(x) (((x) & 3) << 4)
0217
0218 #define SUN4I_TCON0_LVDS_ANA1_REG 0x224
0219 #define SUN4I_TCON0_LVDS_ANA1_INIT (0x1f << 26 | 0x1f << 10)
0220 #define SUN4I_TCON0_LVDS_ANA1_UPDATE (0x1f << 16 | 0x1f << 00)
0221
0222 #define SUN4I_TCON1_FILL_CTL_REG 0x300
0223 #define SUN4I_TCON1_FILL_BEG0_REG 0x304
0224 #define SUN4I_TCON1_FILL_END0_REG 0x308
0225 #define SUN4I_TCON1_FILL_DATA0_REG 0x30c
0226 #define SUN4I_TCON1_FILL_BEG1_REG 0x310
0227 #define SUN4I_TCON1_FILL_END1_REG 0x314
0228 #define SUN4I_TCON1_FILL_DATA1_REG 0x318
0229 #define SUN4I_TCON1_FILL_BEG2_REG 0x31c
0230 #define SUN4I_TCON1_FILL_END2_REG 0x320
0231 #define SUN4I_TCON1_FILL_DATA2_REG 0x324
0232 #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400
0233
0234 #define SUN4I_TCON_MAX_CHANNELS 2
0235
0236 struct sun4i_tcon;
0237
0238 struct sun4i_tcon_quirks {
0239 bool has_channel_0;
0240 bool has_channel_1;
0241 bool has_lvds_alt;
0242 bool needs_de_be_mux;
0243 bool needs_edp_reset;
0244 bool supports_lvds;
0245 bool polarity_in_ch0;
0246 u8 dclk_min_div;
0247
0248
0249 int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *);
0250
0251 void (*setup_lvds_phy)(struct sun4i_tcon *tcon,
0252 const struct drm_encoder *encoder);
0253 };
0254
0255 struct sun4i_tcon {
0256 struct device *dev;
0257 struct drm_device *drm;
0258 struct regmap *regs;
0259
0260
0261 struct clk *clk;
0262
0263
0264 struct clk *sclk0;
0265 struct clk *sclk1;
0266
0267
0268 struct clk *lvds_pll;
0269
0270
0271 struct clk *dclk;
0272 u8 dclk_max_div;
0273 u8 dclk_min_div;
0274
0275
0276 struct reset_control *lcd_rst;
0277 struct reset_control *lvds_rst;
0278
0279
0280 const struct sun4i_tcon_quirks *quirks;
0281
0282
0283 struct sun4i_crtc *crtc;
0284
0285 int id;
0286
0287
0288 struct list_head list;
0289 };
0290
0291 struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);
0292 struct drm_panel *sun4i_tcon_find_panel(struct device_node *node);
0293
0294 void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable);
0295 void sun4i_tcon_mode_set(struct sun4i_tcon *tcon,
0296 const struct drm_encoder *encoder,
0297 const struct drm_display_mode *mode);
0298 void sun4i_tcon_set_status(struct sun4i_tcon *crtc,
0299 const struct drm_encoder *encoder, bool enable);
0300
0301 extern const struct of_device_id sun4i_tcon_of_table[];
0302
0303 #endif