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)) 319026e0d1SMaxime Ripard #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe)) 329026e0d1SMaxime Ripard 339026e0d1SMaxime Ripard #define SUN4I_TCON_GINT1_REG 0x8 349026e0d1SMaxime Ripard #define SUN4I_TCON_FRM_CTL_REG 0x10 359026e0d1SMaxime Ripard 369026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_REG 0x40 379026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31) 389026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY_MASK GENMASK(8, 4) 399026e0d1SMaxime Ripard #define SUN4I_TCON0_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK) 4027e18de7SChen-Yu Tsai #define SUN4I_TCON0_CTL_SRC_SEL_MASK GENMASK(2, 0) 419026e0d1SMaxime Ripard 429026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_REG 0x44 439026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_GATE_BIT (31) 449026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_SHIFT (0) 459026e0d1SMaxime Ripard #define SUN4I_TCON0_DCLK_DIV_WIDTH (7) 469026e0d1SMaxime Ripard 479026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_REG 0x48 489026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 499026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC0_Y(height) (((height) - 1) & 0xfff) 509026e0d1SMaxime Ripard 519026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_REG 0x4c 529026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 539026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 549026e0d1SMaxime Ripard 559026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_REG 0x50 56a88cbbd4SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_TOTAL(total) (((total) & 0x1fff) << 16) 579026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 589026e0d1SMaxime Ripard 599026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_REG 0x54 609026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_H_SYNC(width) ((((width) - 1) & 0x7ff) << 16) 619026e0d1SMaxime Ripard #define SUN4I_TCON0_BASIC3_V_SYNC(height) (((height) - 1) & 0x7ff) 629026e0d1SMaxime Ripard 639026e0d1SMaxime Ripard #define SUN4I_TCON0_HV_IF_REG 0x58 649026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_IF_REG 0x60 659026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_WR_REG 0x64 669026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RD0_REG 0x68 679026e0d1SMaxime Ripard #define SUN4I_TCON0_CPU_RDA_REG 0x6c 689026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL0_REG 0x70 699026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL1_REG 0x74 709026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL2_REG 0x78 719026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL3_REG 0x7c 729026e0d1SMaxime Ripard #define SUN4I_TCON0_TTL4_REG 0x80 73a0c1214eSMaxime Ripard 749026e0d1SMaxime Ripard #define SUN4I_TCON0_LVDS_IF_REG 0x84 75a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_EN BIT(31) 76a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_MASK BIT(26) 77a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_18BITS (1 << 26) 78a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_BITWIDTH_24BITS (0 << 26) 79a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_SEL_MASK BIT(20) 80a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_SEL_TCON0 (1 << 20) 81a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_MASK BIT(4) 82a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_NORMAL (1 << 4) 83a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_CLK_POL_INV (0 << 4) 84a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_MASK GENMASK(3, 0) 85a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_NORMAL (0xf) 86a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_IF_DATA_POL_INV (0) 87a0c1214eSMaxime Ripard 889026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_REG 0x88 899026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28) 909026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25) 919026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24) 929026e0d1SMaxime Ripard 939026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_REG 0x8c 949026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25) 959026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24) 969026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0) 979026e0d1SMaxime Ripard 989026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_REG 0x90 999026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31) 1009026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20) 1019026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4) 1029026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK) 10327e18de7SChen-Yu Tsai #define SUN4I_TCON1_CTL_SRC_SEL_MASK GENMASK(1, 0) 1049026e0d1SMaxime Ripard 1059026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_REG 0x94 1069026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 1079026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff) 1089026e0d1SMaxime Ripard 1099026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_REG 0x98 1109026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16) 1119026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff) 1129026e0d1SMaxime Ripard 1139026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_REG 0x9c 1149026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16) 1159026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff) 1169026e0d1SMaxime Ripard 1179026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_REG 0xa0 1189026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 1199026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1209026e0d1SMaxime Ripard 1219026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_REG 0xa4 1229026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16) 1239026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1249026e0d1SMaxime Ripard 1259026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_REG 0xa8 1269026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16) 1279026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff) 1289026e0d1SMaxime Ripard 1299026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_POL_REG 0xf0 1309026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_TRI_REG 0xf4 1319026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_CTL_REG 0x100 1329026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RR_REG 0x110 1339026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RG_REG 0x114 1349026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RB_REG 0x118 1359026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c 1369026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GR_REG 0x120 1379026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GG_REG 0x124 1389026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GB_REG 0x128 1399026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c 1409026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BR_REG 0x130 1419026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BG_REG 0x134 1429026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BB_REG 0x138 1439026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c 1449026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_R_REG 0x140 1459026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_G_REG 0x144 1469026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_B_REG 0x148 1479026e0d1SMaxime Ripard #define SUN4I_TCON_MUX_CTRL_REG 0x200 148a0c1214eSMaxime Ripard 149a0c1214eSMaxime Ripard #define SUN4I_TCON0_LVDS_ANA0_REG 0x220 150a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_MB BIT(31) 151a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_LDO BIT(30) 152a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_DRVC BIT(24) 153a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_EN_DRVD(x) (((x) & 0xf) << 20) 154a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_C(x) (((x) & 3) << 17) 155a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_V(x) (((x) & 3) << 8) 156a0c1214eSMaxime Ripard #define SUN6I_TCON0_LVDS_ANA0_PD(x) (((x) & 3) << 4) 157a0c1214eSMaxime Ripard 1589026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_CTL_REG 0x300 1599026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG0_REG 0x304 1609026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END0_REG 0x308 1619026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA0_REG 0x30c 1629026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG1_REG 0x310 1639026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END1_REG 0x314 1649026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA1_REG 0x318 1659026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG2_REG 0x31c 1669026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END2_REG 0x320 1679026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA2_REG 0x324 1689026e0d1SMaxime Ripard #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400 1699026e0d1SMaxime Ripard 1709026e0d1SMaxime Ripard #define SUN4I_TCON_MAX_CHANNELS 2 1719026e0d1SMaxime Ripard 172ad537fb2SChen-Yu Tsai struct sun4i_tcon; 173ad537fb2SChen-Yu Tsai 17491ea2f29SChen-Yu Tsai struct sun4i_tcon_quirks { 17534d698f6SJernej Skrabec bool has_channel_0; /* a83t does not have channel 0 on second TCON */ 17691ea2f29SChen-Yu Tsai bool has_channel_1; /* a33 does not have channel 1 */ 177a0c1214eSMaxime Ripard bool has_lvds_alt; /* Does the LVDS clock have a parent other than the TCON clock? */ 17827e18de7SChen-Yu Tsai bool needs_de_be_mux; /* sun6i needs mux to select backend */ 179*6664e9dcSChen-Yu Tsai bool needs_edp_reset; /* a80 edp reset needed for tcon0 access */ 180ad537fb2SChen-Yu Tsai 181ad537fb2SChen-Yu Tsai /* callback to handle tcon muxing options */ 182abcb8766SMaxime Ripard int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *); 18391ea2f29SChen-Yu Tsai }; 18491ea2f29SChen-Yu Tsai 1859026e0d1SMaxime Ripard struct sun4i_tcon { 186ae558110SMaxime Ripard struct device *dev; 1879026e0d1SMaxime Ripard struct drm_device *drm; 1889026e0d1SMaxime Ripard struct regmap *regs; 1899026e0d1SMaxime Ripard 1909026e0d1SMaxime Ripard /* Main bus clock */ 1919026e0d1SMaxime Ripard struct clk *clk; 1929026e0d1SMaxime Ripard 1939026e0d1SMaxime Ripard /* Clocks for the TCON channels */ 1949026e0d1SMaxime Ripard struct clk *sclk0; 1959026e0d1SMaxime Ripard struct clk *sclk1; 1969026e0d1SMaxime Ripard 197a0c1214eSMaxime Ripard /* Possible mux for the LVDS clock */ 198a0c1214eSMaxime Ripard struct clk *lvds_pll; 199a0c1214eSMaxime Ripard 2009026e0d1SMaxime Ripard /* Pixel clock */ 2019026e0d1SMaxime Ripard struct clk *dclk; 202ec08d596SMaxime Ripard u8 dclk_max_div; 203ec08d596SMaxime Ripard u8 dclk_min_div; 2049026e0d1SMaxime Ripard 2059026e0d1SMaxime Ripard /* Reset control */ 2069026e0d1SMaxime Ripard struct reset_control *lcd_rst; 207a0c1214eSMaxime Ripard struct reset_control *lvds_rst; 2089026e0d1SMaxime Ripard 20929e57fabSMaxime Ripard struct drm_panel *panel; 2108e924047SMaxime Ripard 21191ea2f29SChen-Yu Tsai /* Platform adjustments */ 21291ea2f29SChen-Yu Tsai const struct sun4i_tcon_quirks *quirks; 21346cce6daSChen-Yu Tsai 21446cce6daSChen-Yu Tsai /* Associated crtc */ 21546cce6daSChen-Yu Tsai struct sun4i_crtc *crtc; 21680a58240SChen-Yu Tsai 217d281c862SChen-Yu Tsai int id; 218d281c862SChen-Yu Tsai 21980a58240SChen-Yu Tsai /* TCON list management */ 22080a58240SChen-Yu Tsai struct list_head list; 2219026e0d1SMaxime Ripard }; 2229026e0d1SMaxime Ripard 223894f5a9fSMaxime Ripard struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node); 224a8444c7eSMaxime Ripard struct drm_panel *sun4i_tcon_find_panel(struct device_node *node); 225a8444c7eSMaxime Ripard 2269026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable); 2275b8f0910SMaxime Ripard void sun4i_tcon_mode_set(struct sun4i_tcon *tcon, 2285b8f0910SMaxime Ripard const struct drm_encoder *encoder, 2295b8f0910SMaxime Ripard const struct drm_display_mode *mode); 23045e88f99SMaxime Ripard void sun4i_tcon_set_status(struct sun4i_tcon *crtc, 23145e88f99SMaxime Ripard const struct drm_encoder *encoder, bool enable); 2329026e0d1SMaxime Ripard 233ff71c2cfSChen-Yu Tsai extern const struct of_device_id sun4i_tcon_of_table[]; 234ff71c2cfSChen-Yu Tsai 2359026e0d1SMaxime Ripard #endif /* __SUN4I_TCON_H__ */ 236