Merge tag 'lsk-v4.4-17.03-android' of git://git.linaro.org/kernel/linux-linaro-stable.git
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / transmitter / rk31xx_lvds.h
1 #ifndef _RK31XX_LVDS_H_
2 #define _RK31XX_LVDS_H_
3
4 #include <linux/rk_screen.h>
5 #include <linux/mfd/syscon.h>
6 #include <linux/regmap.h>
7
8 #define BITS(x, bit)            ((x) << (bit))
9 #define BITS_MASK(x, mask, bit)  BITS((x) & (mask), bit)
10 #define BITS_EN(mask, bit)       BITS(mask, bit + 16)
11
12 /* RK312X_GRF_LVDS_CON0 */
13 #define v_LVDS_DATA_SEL(x)      (BITS_MASK(x, 1, 0) | BITS_EN(1, 0))
14 #define v_LVDS_OUTPUT_FORMAT(x) (BITS_MASK(x, 3, 1) | BITS_EN(3, 1))
15 #define v_LVDS_MSBSEL(x)        (BITS_MASK(x, 1, 3) | BITS_EN(1, 3))
16 #define v_LVDSMODE_EN(x)        (BITS_MASK(x, 1, 6) | BITS_EN(1, 6))
17 #define v_MIPIPHY_TTL_EN(x)     (BITS_MASK(x, 1, 7) | BITS_EN(1, 7))
18 #define v_MIPIPHY_LANE0_EN(x)   (BITS_MASK(x, 1, 8) | BITS_EN(1, 8))
19 #define v_MIPIDPI_FORCEX_EN(x)  (BITS_MASK(x, 1, 9) | BITS_EN(1, 9))
20
21 /* RK3368_GRF_SOC_CON7 0x41c*/
22 /* RK3366_GRF_SOC_CON5 0x414*/
23 #define v_RK3368_LVDS_OUTPUT_FORMAT(x) (BITS_MASK(x, 3, 13) | BITS_EN(3, 13))
24 #define v_RK3368_LVDS_MSBSEL(x)        (BITS_MASK(x, 1, 11) | BITS_EN(1, 11))
25 #define v_RK3368_LVDSMODE_EN(x)        (BITS_MASK(x, 1, 12) | BITS_EN(1, 12))
26 #define v_RK3368_MIPIPHY_TTL_EN(x)     (BITS_MASK(x, 1, 15) | BITS_EN(1, 15))
27 #define v_RK3368_MIPIPHY_LANE0_EN(x)   (BITS_MASK(x, 1, 5) | BITS_EN(1, 5))
28 #define v_RK3368_MIPIDPI_FORCEX_EN(x)  (BITS_MASK(x, 1, 6) | BITS_EN(1, 6))
29 enum {
30         LVDS_DATA_FROM_LCDC = 0,
31         LVDS_DATA_FORM_EBC,
32 };
33
34 enum {
35         LVDS_MSB_D0 = 0,
36         LVDS_MSB_D7,
37 };
38
39 /* RK312X_GRF_SOC_CON1 */
40 #define v_MIPITTL_CLK_EN(x)     (BITS_MASK(x, 1, 7) | BITS_EN(1, 7))
41 #define v_MIPITTL_LANE0_EN(x)   (BITS_MASK(x, 1, 11) | BITS_EN(1, 11))
42 #define v_MIPITTL_LANE1_EN(x)   (BITS_MASK(x, 1, 12) | BITS_EN(1, 12))
43 #define v_MIPITTL_LANE2_EN(x)   (BITS_MASK(x, 1, 13) | BITS_EN(1, 13))
44 #define v_MIPITTL_LANE3_EN(x)   (BITS_MASK(x, 1, 14) | BITS_EN(1, 14))
45
46
47 #define MIPIPHY_REG0            0x0000
48 #define m_LANE_EN_0             BITS(1, 2)
49 #define m_LANE_EN_1             BITS(1, 3)
50 #define m_LANE_EN_2             BITS(1, 4)
51 #define m_LANE_EN_3             BITS(1, 5)
52 #define m_LANE_EN_CLK           BITS(1, 5)
53 #define v_LANE_EN_0(x)          BITS(1, 2)
54 #define v_LANE_EN_1(x)          BITS(1, 3)
55 #define v_LANE_EN_2(x)          BITS(1, 4)
56 #define v_LANE_EN_3(x)          BITS(1, 5)
57 #define v_LANE_EN_CLK(x)        BITS(1, 5)
58
59 #define MIPIPHY_REG1            0x0004
60 #define m_SYNC_RST              BITS(1, 0)
61 #define m_LDO_PWR_DOWN          BITS(1, 1)
62 #define m_PLL_PWR_DOWN          BITS(1, 2)
63 #define v_SYNC_RST(x)           BITS_MASK(x, 1, 0)
64 #define v_LDO_PWR_DOWN(x)       BITS_MASK(x, 1, 1)
65 #define v_PLL_PWR_DOWN(x)       BITS_MASK(x, 1, 2)
66
67 #define MIPIPHY_REG3            0x000c
68 #define m_PREDIV                BITS(0x1f, 0)
69 #define m_FBDIV_MSB             BITS(1, 5)
70 #define v_PREDIV(x)             BITS_MASK(x, 0x1f, 0)
71 #define v_FBDIV_MSB(x)          BITS_MASK(x, 1, 5)
72
73 #define MIPIPHY_REG4            0x0010
74 #define v_FBDIV_LSB(x)          BITS_MASK(x, 0xff, 0)
75
76 #define MIPIPHY_REGE0           0x0380
77 #define m_MSB_SEL               BITS(1, 0)
78 #define m_DIG_INTER_RST         BITS(1, 2)
79 #define m_LVDS_MODE_EN          BITS(1, 5)
80 #define m_TTL_MODE_EN           BITS(1, 6)
81 #define m_MIPI_MODE_EN          BITS(1, 7)
82 #define v_MSB_SEL(x)            BITS_MASK(x, 1, 0)
83 #define v_DIG_INTER_RST(x)      BITS_MASK(x, 1, 2)
84 #define v_LVDS_MODE_EN(x)       BITS_MASK(x, 1, 5)
85 #define v_TTL_MODE_EN(x)        BITS_MASK(x, 1, 6)
86 #define v_MIPI_MODE_EN(x)       BITS_MASK(x, 1, 7)
87
88 #define MIPIPHY_REGE1           0x0384
89 #define m_DIG_INTER_EN          BITS(1, 7)
90 #define v_DIG_INTER_EN(x)       BITS_MASK(x, 1, 7)
91
92 #define MIPIPHY_REGE3           0x038c
93 #define m_MIPI_EN               BITS(1, 0)
94 #define m_LVDS_EN               BITS(1, 1)
95 #define m_TTL_EN                BITS(1, 2)
96 #define v_MIPI_EN(x)            BITS_MASK(x, 1, 0)
97 #define v_LVDS_EN(x)            BITS_MASK(x, 1, 1)
98 #define v_TTL_EN(x)             BITS_MASK(x, 1, 2)
99
100 #define MIPIPHY_REGE4           0x0390
101 #define m_VOCM                  BITS(3, 4)
102 #define m_DIFF_V                BITS(3, 6)
103
104 #define v_VOCM(x)               BITS_MASK(x, 3, 4)
105 #define v_DIFF_V(x)             BITS_MASK(x, 3, 6)
106
107 #define MIPIPHY_REGE8           0x03a0
108
109 #define MIPIPHY_REGEB           0x03ac
110 #define v_PLL_PWR_OFF(x)        BITS_MASK(x, 1, 2)
111 #define v_LANECLK_EN(x)         BITS_MASK(x, 1, 3)
112 #define v_LANE3_EN(x)           BITS_MASK(x, 1, 4)
113 #define v_LANE2_EN(x)           BITS_MASK(x, 1, 5)
114 #define v_LANE1_EN(x)           BITS_MASK(x, 1, 6)
115 #define v_LANE0_EN(x)           BITS_MASK(x, 1, 7)
116
117 #define RK3368_GRF_SOC_CON7_LVDS        0x041c
118 #define RK3368_GRF_SOC_CON15_LVDS       0x043c
119 #define RK3366_GRF_SOC_CON5_LVDS        0x0414
120 #define RK3366_GRF_SOC_CON6_LVDS        0x0418
121 #define v_RK3368_FORCE_JETAG(x) (BITS_MASK(x, 1, 13) | BITS_EN(1, 13))
122
123 enum {
124         LVDS_SOC_RK312X,
125         LVDS_SOC_RK3368,
126         LVDS_SOC_RK3366
127 };
128
129 struct rk_lvds_drvdata  {
130         u8 soc_type;
131         u32 reversed;
132 };
133
134 struct rk_lvds_device {
135         struct rk_lvds_drvdata *data;
136         struct device           *dev;
137         void __iomem            *regbase;
138         void __iomem            *ctrl_reg;
139         struct regmap           *grf_lvds_base;
140         struct clk              *pd;  /*power domain*/
141         struct clk              *pclk;  /*phb clk*/
142         struct clk              *ctrl_pclk;     /* mipi ctrl pclk*/
143         struct clk              *ctrl_hclk;     /* mipi ctrl hclk*/
144         struct rk_screen        screen;
145         bool                    clk_on;
146         bool                    sys_state;
147 #ifdef CONFIG_PINCTRL
148         struct dev_pin_info     *pins;
149 #endif
150 };
151
152 static inline int lvds_writel(struct rk_lvds_device *lvds, u32 offset, u32 val)
153 {
154         writel_relaxed(val, lvds->regbase + offset);
155         return 0;
156 }
157
158 static inline int lvds_msk_reg(struct rk_lvds_device *lvds, u32 offset,
159                                u32 msk, u32 val)
160 {
161         u32 temp;
162
163         temp = readl_relaxed(lvds->regbase + offset) & (0xFF - (msk));
164         writel_relaxed(temp | ((val) & (msk)), lvds->regbase + offset);
165         return 0;
166 }
167
168 static inline u32 lvds_readl(struct rk_lvds_device *lvds, u32 offset)
169 {
170         return readl_relaxed(lvds->regbase + offset);
171 }
172
173 static inline int lvds_grf_writel(struct rk_lvds_device *lvds,
174                                   u32 offset, u32 val)
175 {
176         regmap_write(lvds->grf_lvds_base, offset, val);
177         dsb(sy);
178
179         return 0;
180 }
181
182 static inline int lvds_dsi_writel(struct rk_lvds_device *lvds,
183                                   u32 offset, u32 val)
184 {
185         writel_relaxed(val, lvds->ctrl_reg + offset);
186         dsb(sy);
187
188         return 0;
189 }
190
191 static inline u32 lvds_phy_lockon(struct rk_lvds_device *lvds)
192 {
193         u32 val = 0;
194         if (lvds->data->soc_type == LVDS_SOC_RK312X)
195                 val = readl_relaxed(lvds->ctrl_reg);
196         else
197                 val = readl_relaxed(lvds->ctrl_reg + 0x10);
198         return (val & 0x01);
199 }
200
201 #endif
202