19026e0d1SMaxime Ripard /* 29026e0d1SMaxime Ripard * Copyright (C) 2015 Free Electrons 39026e0d1SMaxime Ripard * Copyright (C) 2015 NextThing Co 49026e0d1SMaxime Ripard * 59026e0d1SMaxime Ripard * Boris Brezillon <boris.brezillon@free-electrons.com> 69026e0d1SMaxime Ripard * Maxime Ripard <maxime.ripard@free-electrons.com> 79026e0d1SMaxime Ripard * 89026e0d1SMaxime Ripard * This program is free software; you can redistribute it and/or 99026e0d1SMaxime Ripard * modify it under the terms of the GNU General Public License as 109026e0d1SMaxime Ripard * published by the Free Software Foundation; either version 2 of 119026e0d1SMaxime Ripard * the License, or (at your option) any later version. 129026e0d1SMaxime Ripard */ 139026e0d1SMaxime Ripard 149026e0d1SMaxime Ripard #ifndef __SUN4I_TCON_H__ 159026e0d1SMaxime Ripard #define __SUN4I_TCON_H__ 169026e0d1SMaxime Ripard 179026e0d1SMaxime Ripard #include <drm/drm_crtc.h> 189026e0d1SMaxime Ripard 199026e0d1SMaxime Ripard #include <linux/kernel.h> 2080a58240SChen-Yu Tsai #include <linux/list.h> 219026e0d1SMaxime Ripard #include <linux/reset.h> 229026e0d1SMaxime Ripard 239026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_REG 0x0 249026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_TCON_ENABLE BIT(31) 259026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_MASK BIT(0) 269026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON1 (1 << 0) 279026e0d1SMaxime Ripard #define SUN4I_TCON_GCTL_IOMAP_TCON0 (0 << 0) 289026e0d1SMaxime Ripard 299026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_REG 0x4 309026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe) BIT(31 - (pipe)) 31*a493ceaeSMaxime Ripard #define SUN4I_TCON_GINT0_TCON0_TRI_FINISH_ENABLE BIT(27) 32*a493ceaeSMaxime Ripard #define SUN4I_TCON_GINT0_TCON0_TRI_COUNTER_ENABLE BIT(26) 339026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe)) 34*a493ceaeSMaxime Ripard #define SUN4I_TCON_GINT0_TCON0_TRI_FINISH_INT BIT(11) 35*a493ceaeSMaxime Ripard #define SUN4I_TCON_GINT0_TCON0_TRI_COUNTER_INT BIT(10) 369026e0d1SMaxime Ripard 379026e0d1SMaxime Ripard #define SUN4I_TCON_GINT1_REG 0x8 389026e0d1SMaxime Ripard #define SUN4I_TCON_FRM_CTL_REG 0x10 399026e0d1SMaxime Ripard 409026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_REG 0x40 419026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31) 429026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY_MASK GENMASK(8, 4) 439026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK) 4427e18de7SChen-Yu Tsai #define SUN4I_TCON0_CTL_SRC_SEL_MASK GENMASK(2, 0) 459026e0d1SMaxime Ripard 469026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_REG 0x44 479026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_GATE_BIT (31) 489026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_SHIFT (0) 499026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_WIDTH (7) 509026e0d1SMaxime Ripard 519026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_REG 0x48 529026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 539026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_Y(height) (((height) - 1) & 0xfff) 549026e0d1SMaxime Ripard 559026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_REG 0x4c 569026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 579026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 589026e0d1SMaxime Ripard 599026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_REG 0x50 60a88cbbd4SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_TOTAL(total) (((total) & 0x1fff) << 16) 619026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 629026e0d1SMaxime Ripard 639026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_REG 0x54 649026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_H_SYNC(width) ((((width) - 1) & 0x7ff) << 16) 659026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_V_SYNC(height) (((height) - 1) & 0x7ff) 669026e0d1SMaxime Ripard 679026e0d1SMaxime Ripard #define SUN4I_TCON0_HV_IF_REG 0x58 689026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_IF_REG 0x60 699026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_WR_REG 0x64 709026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RD0_REG 0x68 719026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RDA_REG 0x6c 729026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL0_REG 0x70 739026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL1_REG 0x74 749026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL2_REG 0x78 759026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL3_REG 0x7c 769026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL4_REG 0x80 77a0c1214eSMaxime Ripard 789026e0d1SMaxime Ripard #define SUN4I_TCON0_LVDS_IF_REG 0x84 79a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_EN BIT(31) 80a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_MASK BIT(26) 81a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_18BITS (1 << 26) 82a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_24BITS (0 << 26) 83a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_SEL_MASK BIT(20) 84a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_SEL_TCON0 (1 << 20) 85a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_MASK BIT(4) 86a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_NORMAL (1 << 4) 87a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_INV (0 << 4) 88a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_MASK GENMASK(3, 0) 89a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_NORMAL (0xf) 90a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_INV (0) 91a0c1214eSMaxime Ripard 929026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_REG 0x88 939026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28) 949026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25) 959026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24) 969026e0d1SMaxime Ripard 979026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_REG 0x8c 989026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25) 999026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24) 1009026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0) 1019026e0d1SMaxime Ripard 1029026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_REG 0x90 1039026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31) 1049026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20) 1059026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4) 1069026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK) 10727e18de7SChen-Yu Tsai #define SUN4I_TCON1_CTL_SRC_SEL_MASK GENMASK(1, 0) 1089026e0d1SMaxime Ripard 1099026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_REG 0x94 1109026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 1119026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff) 1129026e0d1SMaxime Ripard 1139026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_REG 0x98 1149026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16) 1159026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff) 1169026e0d1SMaxime Ripard 1179026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_REG 0x9c 1189026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16) 1199026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff) 1209026e0d1SMaxime Ripard 1219026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_REG 0xa0 1229026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 1239026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1249026e0d1SMaxime Ripard 1259026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_REG 0xa4 1269026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16) 1279026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1289026e0d1SMaxime Ripard 1299026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_REG 0xa8 1309026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16) 1319026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff) 1329026e0d1SMaxime Ripard 1339026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_POL_REG 0xf0 1349026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_TRI_REG 0xf4 1359026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_CTL_REG 0x100 1369026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RR_REG 0x110 1379026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RG_REG 0x114 1389026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RB_REG 0x118 1399026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c 1409026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GR_REG 0x120 1419026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GG_REG 0x124 1429026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GB_REG 0x128 1439026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c 1449026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BR_REG 0x130 1459026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BG_REG 0x134 1469026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BB_REG 0x138 1479026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c 1489026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_R_REG 0x140 1499026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_G_REG 0x144 1509026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_B_REG 0x148 1519026e0d1SMaxime Ripard #define SUN4I_TCON_MUX_CTRL_REG 0x200 152a0c1214eSMaxime Ripard 153a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_ANA0_REG 0x220 154a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_MB BIT(31) 155a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_LDO BIT(30) 156a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_DRVC BIT(24) 157a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_DRVD(x) (((x) & 0xf) << 20) 158a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_C(x) (((x) & 3) << 17) 159a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_V(x) (((x) & 3) << 8) 160a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_PD(x) (((x) & 3) << 4) 161a0c1214eSMaxime Ripard 1629026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_CTL_REG 0x300 1639026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG0_REG 0x304 1649026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END0_REG 0x308 1659026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA0_REG 0x30c 1669026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG1_REG 0x310 1679026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END1_REG 0x314 1689026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA1_REG 0x318 1699026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG2_REG 0x31c 1709026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END2_REG 0x320 1719026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA2_REG 0x324 1729026e0d1SMaxime Ripard #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400 1739026e0d1SMaxime Ripard 1749026e0d1SMaxime Ripard #define SUN4I_TCON_MAX_CHANNELS 2 1759026e0d1SMaxime Ripard 176ad537fb2SChen-Yu Tsai struct sun4i_tcon; 177ad537fb2SChen-Yu Tsai 17891ea2f29SChen-Yu Tsai struct sun4i_tcon_quirks { 17934d698f6SJernej Skrabec bool has_channel_0; /* a83t does not have channel 0 on second TCON */ 18091ea2f29SChen-Yu Tsai bool has_channel_1; /* a33 does not have channel 1 */ 181a0c1214eSMaxime Ripard bool has_lvds_alt; /* Does the LVDS clock have a parent other than the TCON clock? */ 18227e18de7SChen-Yu Tsai bool needs_de_be_mux; /* sun6i needs mux to select backend */ 1836664e9dcSChen-Yu Tsai bool needs_edp_reset; /* a80 edp reset needed for tcon0 access */ 184e742a17cSMaxime Ripard bool supports_lvds; /* Does the TCON support an LVDS output? */ 185ad537fb2SChen-Yu Tsai 186ad537fb2SChen-Yu Tsai /* callback to handle tcon muxing options */ 187abcb8766SMaxime Ripard int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *); 18891ea2f29SChen-Yu Tsai }; 18991ea2f29SChen-Yu Tsai 1909026e0d1SMaxime Ripard struct sun4i_tcon { 191ae558110SMaxime Ripard struct device *dev; 1929026e0d1SMaxime Ripard struct drm_device *drm; 1939026e0d1SMaxime Ripard struct regmap *regs; 1949026e0d1SMaxime Ripard 1959026e0d1SMaxime Ripard /* Main bus clock */ 1969026e0d1SMaxime Ripard struct clk *clk; 1979026e0d1SMaxime Ripard 1989026e0d1SMaxime Ripard /* Clocks for the TCON channels */ 1999026e0d1SMaxime Ripard struct clk *sclk0; 2009026e0d1SMaxime Ripard struct clk *sclk1; 2019026e0d1SMaxime Ripard 202a0c1214eSMaxime Ripard /* Possible mux for the LVDS clock */ 203a0c1214eSMaxime Ripard struct clk *lvds_pll; 204a0c1214eSMaxime Ripard 2059026e0d1SMaxime Ripard /* Pixel clock */ 2069026e0d1SMaxime Ripard struct clk *dclk; 207ec08d596SMaxime Ripard u8 dclk_max_div; 208ec08d596SMaxime Ripard u8 dclk_min_div; 2099026e0d1SMaxime Ripard 2109026e0d1SMaxime Ripard /* Reset control */ 2119026e0d1SMaxime Ripard struct reset_control *lcd_rst; 212a0c1214eSMaxime Ripard struct reset_control *lvds_rst; 2139026e0d1SMaxime Ripard 21429e57fabSMaxime Ripard struct drm_panel *panel; 2158e924047SMaxime Ripard 21691ea2f29SChen-Yu Tsai /* Platform adjustments */ 21791ea2f29SChen-Yu Tsai const struct sun4i_tcon_quirks *quirks; 21846cce6daSChen-Yu Tsai 21946cce6daSChen-Yu Tsai /* Associated crtc */ 22046cce6daSChen-Yu Tsai struct sun4i_crtc *crtc; 22180a58240SChen-Yu Tsai 222d281c862SChen-Yu Tsai int id; 223d281c862SChen-Yu Tsai 22480a58240SChen-Yu Tsai /* TCON list management */ 22580a58240SChen-Yu Tsai struct list_head list; 2269026e0d1SMaxime Ripard }; 2279026e0d1SMaxime Ripard 228894f5a9fSMaxime Ripard struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node); 229a8444c7eSMaxime Ripard struct drm_panel *sun4i_tcon_find_panel(struct device_node *node); 230a8444c7eSMaxime Ripard 2319026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable); 2325b8f0910SMaxime Ripard void sun4i_tcon_mode_set(struct sun4i_tcon *tcon, 2335b8f0910SMaxime Ripard const struct drm_encoder *encoder, 2345b8f0910SMaxime Ripard const struct drm_display_mode *mode); 23545e88f99SMaxime Ripard void sun4i_tcon_set_status(struct sun4i_tcon *crtc, 23645e88f99SMaxime Ripard const struct drm_encoder *encoder, bool enable); 2379026e0d1SMaxime Ripard 238ff71c2cfSChen-Yu Tsai extern const struct of_device_id sun4i_tcon_of_table[]; 239ff71c2cfSChen-Yu Tsai 2409026e0d1SMaxime Ripard #endif /* __SUN4I_TCON_H__ */ 241