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 739026e0d1SMaxime Ripard #define SUN4I_TCON0_LVDS_IF_REG 0x84 749026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_REG 0x88 759026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28) 769026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25) 779026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24) 789026e0d1SMaxime Ripard 799026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_REG 0x8c 809026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25) 819026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24) 829026e0d1SMaxime Ripard #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0) 839026e0d1SMaxime Ripard 849026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_REG 0x90 859026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31) 869026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20) 879026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4) 889026e0d1SMaxime Ripard #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK) 8927e18de7SChen-Yu Tsai #define SUN4I_TCON1_CTL_SRC_SEL_MASK GENMASK(1, 0) 909026e0d1SMaxime Ripard 919026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_REG 0x94 929026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 939026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff) 949026e0d1SMaxime Ripard 959026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_REG 0x98 969026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16) 979026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff) 989026e0d1SMaxime Ripard 999026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_REG 0x9c 1009026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16) 1019026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff) 1029026e0d1SMaxime Ripard 1039026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_REG 0xa0 1049026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 1059026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1069026e0d1SMaxime Ripard 1079026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_REG 0xa4 1089026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16) 1099026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 1109026e0d1SMaxime Ripard 1119026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_REG 0xa8 1129026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16) 1139026e0d1SMaxime Ripard #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff) 1149026e0d1SMaxime Ripard 1159026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_POL_REG 0xf0 1169026e0d1SMaxime Ripard #define SUN4I_TCON1_IO_TRI_REG 0xf4 1179026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_CTL_REG 0x100 1189026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RR_REG 0x110 1199026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RG_REG 0x114 1209026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_RB_REG 0x118 1219026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c 1229026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GR_REG 0x120 1239026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GG_REG 0x124 1249026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_GB_REG 0x128 1259026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c 1269026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BR_REG 0x130 1279026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BG_REG 0x134 1289026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_MUL_BB_REG 0x138 1299026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c 1309026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_R_REG 0x140 1319026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_G_REG 0x144 1329026e0d1SMaxime Ripard #define SUN4I_TCON_CEU_RANGE_B_REG 0x148 1339026e0d1SMaxime Ripard #define SUN4I_TCON_MUX_CTRL_REG 0x200 1349026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_CTL_REG 0x300 1359026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG0_REG 0x304 1369026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END0_REG 0x308 1379026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA0_REG 0x30c 1389026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG1_REG 0x310 1399026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END1_REG 0x314 1409026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA1_REG 0x318 1419026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_BEG2_REG 0x31c 1429026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_END2_REG 0x320 1439026e0d1SMaxime Ripard #define SUN4I_TCON1_FILL_DATA2_REG 0x324 1449026e0d1SMaxime Ripard #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400 1459026e0d1SMaxime Ripard 1469026e0d1SMaxime Ripard #define SUN4I_TCON_MAX_CHANNELS 2 1479026e0d1SMaxime Ripard 148ad537fb2SChen-Yu Tsai struct sun4i_tcon; 149ad537fb2SChen-Yu Tsai 15091ea2f29SChen-Yu Tsai struct sun4i_tcon_quirks { 15191ea2f29SChen-Yu Tsai bool has_channel_1; /* a33 does not have channel 1 */ 15227e18de7SChen-Yu Tsai bool needs_de_be_mux; /* sun6i needs mux to select backend */ 153ad537fb2SChen-Yu Tsai 154ad537fb2SChen-Yu Tsai /* callback to handle tcon muxing options */ 155*abcb8766SMaxime Ripard int (*set_mux)(struct sun4i_tcon *, const struct drm_encoder *); 15691ea2f29SChen-Yu Tsai }; 15791ea2f29SChen-Yu Tsai 1589026e0d1SMaxime Ripard struct sun4i_tcon { 159ae558110SMaxime Ripard struct device *dev; 1609026e0d1SMaxime Ripard struct drm_device *drm; 1619026e0d1SMaxime Ripard struct regmap *regs; 1629026e0d1SMaxime Ripard 1639026e0d1SMaxime Ripard /* Main bus clock */ 1649026e0d1SMaxime Ripard struct clk *clk; 1659026e0d1SMaxime Ripard 1669026e0d1SMaxime Ripard /* Clocks for the TCON channels */ 1679026e0d1SMaxime Ripard struct clk *sclk0; 1689026e0d1SMaxime Ripard struct clk *sclk1; 1699026e0d1SMaxime Ripard 1709026e0d1SMaxime Ripard /* Pixel clock */ 1719026e0d1SMaxime Ripard struct clk *dclk; 1729026e0d1SMaxime Ripard 1739026e0d1SMaxime Ripard /* Reset control */ 1749026e0d1SMaxime Ripard struct reset_control *lcd_rst; 1759026e0d1SMaxime Ripard 17629e57fabSMaxime Ripard struct drm_panel *panel; 1778e924047SMaxime Ripard 17891ea2f29SChen-Yu Tsai /* Platform adjustments */ 17991ea2f29SChen-Yu Tsai const struct sun4i_tcon_quirks *quirks; 18046cce6daSChen-Yu Tsai 18146cce6daSChen-Yu Tsai /* Associated crtc */ 18246cce6daSChen-Yu Tsai struct sun4i_crtc *crtc; 18380a58240SChen-Yu Tsai 184d281c862SChen-Yu Tsai int id; 185d281c862SChen-Yu Tsai 18680a58240SChen-Yu Tsai /* TCON list management */ 18780a58240SChen-Yu Tsai struct list_head list; 1889026e0d1SMaxime Ripard }; 1899026e0d1SMaxime Ripard 190894f5a9fSMaxime Ripard struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node); 191a8444c7eSMaxime Ripard struct drm_panel *sun4i_tcon_find_panel(struct device_node *node); 192a8444c7eSMaxime Ripard 1939026e0d1SMaxime Ripard /* Global Control */ 1949026e0d1SMaxime Ripard void sun4i_tcon_disable(struct sun4i_tcon *tcon); 1959026e0d1SMaxime Ripard void sun4i_tcon_enable(struct sun4i_tcon *tcon); 1969026e0d1SMaxime Ripard 1979026e0d1SMaxime Ripard /* Channel Control */ 1989026e0d1SMaxime Ripard void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel); 1999026e0d1SMaxime Ripard void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel); 2009026e0d1SMaxime Ripard 2019026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable); 2029026e0d1SMaxime Ripard 2039026e0d1SMaxime Ripard /* Mode Related Controls */ 204f8c73f4fSMaxime Ripard void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel, 205f8c73f4fSMaxime Ripard struct drm_encoder *encoder); 2069026e0d1SMaxime Ripard void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, 2079026e0d1SMaxime Ripard struct drm_display_mode *mode); 2089026e0d1SMaxime Ripard void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, 2099026e0d1SMaxime Ripard struct drm_display_mode *mode); 2109026e0d1SMaxime Ripard 2119026e0d1SMaxime Ripard #endif /* __SUN4I_TCON_H__ */ 212