rk312x mipi:improve CodingStype of mipi driver code
[firefly-linux-kernel-4.4.55.git] / drivers / video / rockchip / transmitter / rk32_mipi_dsi.h
1 /*
2 drivers/video/rockchip/transmitter/rk32_mipi_dsi.h
3 */
4
5 #ifndef RK32_MIPI_DSI_H
6 #define RK32_MIPI_DSI_H
7
8 #ifdef CONFIG_RK_3288_DSI_UBOOT
9 #include <asm/arch/rkplat.h>
10 #define RK_GRF_VIRT                     RKIO_GRF_PHYS
11 #define RK3288_CRU_PHYS                 RKIO_CRU_PHYS
12
13 #define RK3288_GRF_SOC_CON6             GRF_SOC_CON6
14 #define RK3288_GRF_SOC_CON14            GRF_SOC_CON14
15 #else
16 #include <linux/rockchip/grf.h>
17 #endif
18 #define MIPI_DSI_PHY_OFFSET             0x0C00
19 #define MIPI_DSI_PHY_SIZE               0x34c
20
21 #define MIPI_DSI_HOST_OFFSET    0x1000
22
23 /* function bits definition    register addr | bits | offest */
24 #define REG_ADDR(a)                     ((a) << 16)
25 #define REG_BITS(a)                     ((a) << 8)
26 #define BITS_OFFSET(a)          (a)
27 #define DSI_HOST_BITS(addr, bits, bit_offset)  (REG_ADDR((addr)+MIPI_DSI_HOST_OFFSET) \
28                 | REG_BITS(bits) | BITS_OFFSET(bit_offset))
29 #define DSI_DPHY_BITS(addr, bits, bit_offset)  (REG_ADDR((addr)+MIPI_DSI_PHY_OFFSET) \
30                 | REG_BITS(bits) | BITS_OFFSET(bit_offset))
31
32 /* DWC_DSI_VERSION_0x3133302A */
33 #define VERSION                                         DSI_HOST_BITS(0x000, 32, 0)
34 #define shutdownz                                       DSI_HOST_BITS(0x004, 1, 0)
35 #define TO_CLK_DIVISION                         DSI_HOST_BITS(0x008, 8, 8)
36 #define TX_ESC_CLK_DIVISION             DSI_HOST_BITS(0x008, 8, 0)
37 #define dpi_vcid                                        DSI_HOST_BITS(0x00c, 2, 0)
38 #define en18_loosely                            DSI_HOST_BITS(0x010, 1, 8)
39 #define dpi_color_coding                        DSI_HOST_BITS(0x010, 4, 0)      /* need modify in code */
40 #define colorm_active_low                       DSI_HOST_BITS(0x014, 1, 4)
41 #define shutd_active_low                        DSI_HOST_BITS(0x014, 1, 3)
42 #define hsync_active_low                        DSI_HOST_BITS(0x014, 1, 2)
43 #define vsync_active_low                        DSI_HOST_BITS(0x014, 1, 1)
44 #define dataen_active_low                       DSI_HOST_BITS(0x014, 1, 0)
45 #define outvact_lpcmd_time              DSI_HOST_BITS(0x018, 8, 16)     /* attence */
46 #define invact_lpcmd_time                       DSI_HOST_BITS(0x018, 8, 0)
47 /* #define dbi_vcid                                     DSI_HOST_BITS(0x01c, 2, 0) */
48 #define crc_rx_en                                       DSI_HOST_BITS(0x02c, 1, 4)
49 #define ecc_rx_en                                       DSI_HOST_BITS(0x02c, 1, 3)
50 #define bta_en                                          DSI_HOST_BITS(0x02c, 1, 2)
51 #define eotp_rx_en                                      DSI_HOST_BITS(0x02c, 1, 1)
52 #define eotp_tx_en                                      DSI_HOST_BITS(0x02c, 1, 0)
53 #define gen_vid_rx                                      DSI_HOST_BITS(0x030, 2, 0)
54 #define cmd_video_mode                          DSI_HOST_BITS(0x034, 1, 0)
55 #define vpg_orientation             DSI_HOST_BITS(0x038, 1, 24)
56 #define vpg_mode                    DSI_HOST_BITS(0x038, 1, 20)
57 #define vpg_en                      DSI_HOST_BITS(0x038, 1, 16)
58 #define lp_cmd_en                                       DSI_HOST_BITS(0x038, 1, 15)
59 #define frame_bta_ack_en                        DSI_HOST_BITS(0x038, 1, 14)
60 #define lp_hfp_en                                       DSI_HOST_BITS(0x038, 1, 13)
61 #define lp_hbp_en                                       DSI_HOST_BITS(0x038, 1, 12)
62 #define lp_vact_en                                      DSI_HOST_BITS(0x038, 1, 11)
63 #define lp_vfp_en                                       DSI_HOST_BITS(0x038, 1, 10)
64 #define lp_vbp_en                                       DSI_HOST_BITS(0x038, 1, 9)
65 #define lp_vsa_en                                       DSI_HOST_BITS(0x038, 1, 8)
66 #define vid_mode_type                           DSI_HOST_BITS(0x038, 2, 0)
67 #define vid_pkt_size                            DSI_HOST_BITS(0x03c, 14, 0)
68 #define num_chunks                                      DSI_HOST_BITS(0x040, 13, 0)
69 #define null_pkt_size                           DSI_HOST_BITS(0x044, 13, 0)
70 #define vid_hsa_time                            DSI_HOST_BITS(0x048, 12, 0)
71 #define vid_hbp_time                            DSI_HOST_BITS(0x04c, 12, 0)
72 #define vid_hline_time                          DSI_HOST_BITS(0x050, 15, 0)
73 #define vid_vsa_lines                           DSI_HOST_BITS(0x054, 10, 0)
74 #define vid_vbp_lines                           DSI_HOST_BITS(0x058, 10, 0)
75 #define vid_vfp_lines                           DSI_HOST_BITS(0x05c, 10, 0)
76 #define vid_active_lines                        DSI_HOST_BITS(0x060, 14, 0)
77 #define max_rd_pkt_size                         DSI_HOST_BITS(0x068, 1, 24)
78 #define dcs_lw_tx                                       DSI_HOST_BITS(0x068, 1, 19)
79 #define dcs_sr_0p_tx                            DSI_HOST_BITS(0x068, 1, 18)
80 #define dcs_sw_1p_tx                            DSI_HOST_BITS(0x068, 1, 17)
81 #define dcs_sw_0p_tx                            DSI_HOST_BITS(0x068, 1, 16)
82 #define gen_lw_tx                                       DSI_HOST_BITS(0x068, 1, 14)
83 #define gen_sr_2p_tx                            DSI_HOST_BITS(0x068, 1, 13)
84 #define gen_sr_1p_tx                            DSI_HOST_BITS(0x068, 1, 12)
85 #define gen_sr_0p_tx                            DSI_HOST_BITS(0x068, 1, 11)
86 #define gen_sw_2p_tx                            DSI_HOST_BITS(0x068, 1, 10)
87 #define gen_sw_1p_tx                            DSI_HOST_BITS(0x068, 1, 9)
88 #define gen_sw_0p_tx                            DSI_HOST_BITS(0x068, 1, 8)
89 #define ack_rqst_en                             DSI_HOST_BITS(0x068, 1, 1)
90 #define tear_fx_en                                      DSI_HOST_BITS(0x068, 1, 0)
91 #define GEN_HDR                                         DSI_HOST_BITS(0x06c, 32, 0)
92 #define GEN_PLD_DATA                            DSI_HOST_BITS(0x070, 32, 0)
93 #define gen_rd_cmd_busy                         DSI_HOST_BITS(0x074, 1, 6)
94 #define gen_pld_r_full                          DSI_HOST_BITS(0x074, 1, 5)
95 #define gen_pld_r_empty                         DSI_HOST_BITS(0x074, 1, 4)
96 #define gen_pld_w_full                          DSI_HOST_BITS(0x074, 1, 3)      /* 800byte    write GEN_PLD_DATA */
97 #define gen_pld_w_empty                         DSI_HOST_BITS(0x074, 1, 2)
98 #define gen_cmd_full                            DSI_HOST_BITS(0x074, 1, 1)      /* 20   write GEN_HDR */
99 #define gen_cmd_empty                           DSI_HOST_BITS(0x074, 1, 0)
100 #define hstx_to_cnt                             DSI_HOST_BITS(0x078, 16, 16)
101 #define lprx_to_cnt                             DSI_HOST_BITS(0x078, 16, 0)
102 #define hs_rd_to_cnt                            DSI_HOST_BITS(0x07c, 16, 0)
103 #define lp_rd_to_cnt                            DSI_HOST_BITS(0x080, 16, 0)
104 #define presp_to_mode                           DSI_HOST_BITS(0x084, 1, 24)
105 #define hs_wr_to_cnt                            DSI_HOST_BITS(0x084, 16, 0)
106 #define lp_wr_to_cnt                            DSI_HOST_BITS(0x088, 16, 0)
107 #define bta_to_cnt                                      DSI_HOST_BITS(0x08c, 16, 0)
108 /*
109 #define send_3d_cfg                             DSI_HOST_BITS(0x090, 1, 16)
110 #define right_first                             DSI_HOST_BITS(0x090, 1, 5)
111 #define second_vsync                            DSI_HOST_BITS(0x090, 1, 4)
112 #define format_3d                                       DSI_HOST_BITS(0x090, 2, 2)
113 #define mode_3d                                         DSI_HOST_BITS(0x090, 2, 0)
114 */
115 #define auto_clklane_ctrl                       DSI_HOST_BITS(0x094, 1, 1)
116 #define phy_txrequestclkhs                      DSI_HOST_BITS(0x094, 1, 0)
117 #define phy_hs2lp_time_clk_lane                 DSI_HOST_BITS(0x098, 10, 16)
118 #define phy_hs2hs_time_clk_lane                 DSI_HOST_BITS(0x098, 10, 0)
119 #define phy_hs2lp_time                          DSI_HOST_BITS(0x09c, 8, 24)
120 #define phy_lp2hs_time                          DSI_HOST_BITS(0x09c, 8, 16)
121 #define max_rd_time                             DSI_HOST_BITS(0x09c, 15, 0)
122 /* new Dependency: DSI_HOST_FPGA = 0. Otherwise, this bit is reserved. */
123 #define phy_forcepll                            DSI_HOST_BITS(0x0a0, 1, 3)
124 #define phy_enableclk                           DSI_HOST_BITS(0x0a0, 1, 2)
125 #define phy_rstz                                DSI_HOST_BITS(0x0a0, 1, 1)
126 #define phy_shutdownz                           DSI_HOST_BITS(0x0a0, 1, 0)
127 #define phy_stop_wait_time                      DSI_HOST_BITS(0x0a4, 8, 8)
128 #define n_lanes                                 DSI_HOST_BITS(0x0a4, 2, 0)
129 #define phy_txexitulpslan                       DSI_HOST_BITS(0x0a8, 1, 3)
130 #define phy_txrequlpslan                        DSI_HOST_BITS(0x0a8, 1, 2)
131 #define phy_txexitulpsclk                       DSI_HOST_BITS(0x0a8, 1, 1)
132 #define phy_txrequlpsclk                        DSI_HOST_BITS(0x0a8, 1, 0)
133 #define phy_tx_triggers                         DSI_HOST_BITS(0x0ac, 4, 0)
134
135 #define phystopstateclklane                     DSI_HOST_BITS(0x0b0, 1, 2)
136 #define phylock                                 DSI_HOST_BITS(0x0b0, 1, 0)
137 #define phy_testclk                             DSI_HOST_BITS(0x0b4, 1, 1)
138 #define phy_testclr                             DSI_HOST_BITS(0x0b4, 1, 0)
139 #define phy_testen                              DSI_HOST_BITS(0x0b8, 1, 16)
140 #define phy_testdout                            DSI_HOST_BITS(0x0b8, 8, 8)
141 #define phy_testdin                             DSI_HOST_BITS(0x0b8, 8, 0)
142
143 #define PHY_TEST_CTRL1                          DSI_HOST_BITS(0x0b8, 17, 0)
144 #define PHY_TEST_CTRL0                          DSI_HOST_BITS(0x0b4, 2, 0)
145
146 #define INT_ST0                                         DSI_HOST_BITS(0x0bc, 21, 0)
147 #define INT_ST1                                         DSI_HOST_BITS(0x0c0, 18, 0)
148 #define INT_MKS0                                        DSI_HOST_BITS(0x0c4, 21, 0)
149 #define INT_MKS1                                        DSI_HOST_BITS(0x0c8, 18, 0)
150 #define INT_FORCE0                                      DSI_HOST_BITS(0x0d8, 21, 0)
151 #define INT_FORCE1                                      DSI_HOST_BITS(0x0dc, 18, 0)
152
153 #define code_hs_rx_clock                0x34
154 #define code_hs_rx_lane0                0x44
155 #define code_hs_rx_lane1                0x54
156 #define code_hs_rx_lane2                0x84
157 #define code_hs_rx_lane3                0x94
158
159 #define code_pll_input_div_rat          0x17
160 #define code_pll_loop_div_rat           0x18
161 #define code_pll_input_loop_div_rat     0x19
162
163 #define code_hstxdatalanerequsetstatetime       0x70
164 #define code_hstxdatalanepreparestatetime       0x71
165 #define code_hstxdatalanehszerostatetime        0x72
166
167 /* rk312x MIPI DSI DPHY REGISTERS */
168 #define DPHY_REGISTER0                          DSI_DPHY_BITS(0x00, 32, 0)
169 #define DPHY_REGISTER1                          DSI_DPHY_BITS(0x04, 32, 0)
170 #define DPHY_REGISTER3                          DSI_DPHY_BITS(0x0c, 32, 0)
171 #define DPHY_REGISTER4                          DSI_DPHY_BITS(0x10, 32, 0)
172 #define DPHY_REGISTER20                         DSI_DPHY_BITS(0X80, 32, 0)
173
174 #define lane_en_ck                              DSI_DPHY_BITS(0x00, 1, 6)
175 #define lane_en_3                               DSI_DPHY_BITS(0x00, 1, 5)
176 #define lane_en_2                               DSI_DPHY_BITS(0x00, 1, 4)
177 #define lane_en_1                               DSI_DPHY_BITS(0x00, 1, 3)
178 #define lane_en_0                               DSI_DPHY_BITS(0x00, 1, 2)
179 #define reg0_phy                                DSI_DPHY_BITS(0x00, 8, 0)
180
181 #define reg_da_ppfc                             DSI_DPHY_BITS(0x04, 1, 4)
182 #define reg_da_syncrst                          DSI_DPHY_BITS(0x04, 1, 2)
183 #define reg_da_ldopd                            DSI_DPHY_BITS(0x04, 1, 1)
184 #define reg_da_pllpd                            DSI_DPHY_BITS(0x04, 1, 0)
185 #define reg1_phy                                DSI_DPHY_BITS(0x04, 8, 0)
186 #define reg5_phy                                DSI_DPHY_BITS(0x14, 3, 0)
187 #define reg5_3_phy                              DSI_DPHY_BITS(0x14, 1, 3)
188 #define reg5_7_phy                              DSI_DPHY_BITS(0x14, 1, 7)
189 #define reg8_phy                                DSI_DPHY_BITS(0x20, 4, 0)
190
191 #define reg_fbdiv_8                             DSI_DPHY_BITS(0x0c, 1, 5)
192 #define reg_prediv                              DSI_DPHY_BITS(0x0c, 5, 0)
193 #define reg_fbdiv                               DSI_DPHY_BITS(0x10, 8, 0)
194 #define reg9_phy                                DSI_DPHY_BITS(0x24, 8, 0)
195 #define reg10_phy                               DSI_DPHY_BITS(0X40, 8, 0)
196 #define reg10_4_6_phy                           DSI_DPHY_BITS(0X40, 3, 4)
197 #define regb_phy                                DSI_DPHY_BITS(0X2c, 4, 0)
198
199 #define reg_dig_rstn                            DSI_DPHY_BITS(0X80, 1, 0)
200 #define reg20_phy                               DSI_DPHY_BITS(0X80, 8, 0)
201
202 #define DPHY_CLOCK_OFFSET                       REG_ADDR(0X0100)
203 #define DPHY_LANE0_OFFSET                       REG_ADDR(0X0180)
204 #define DPHY_LANE1_OFFSET                       REG_ADDR(0X0200)
205 #define DPHY_LANE2_OFFSET                       REG_ADDR(0X0280)
206 #define DPHY_LANE3_OFFSET                       REG_ADDR(0X0300)
207
208 #define reg_ths_settle                          DSI_DPHY_BITS(0x0000, 4, 0)
209 #define reg_hs_tlpx                             DSI_DPHY_BITS(0x0014, 6, 0)
210 #define reg_hs_ths_prepare                      DSI_DPHY_BITS(0x0018, 7, 0)
211 #define reg_hs_the_zero                         DSI_DPHY_BITS(0x001c, 6, 0)
212 #define reg_hs_ths_trail                        DSI_DPHY_BITS(0x0020, 7, 0)
213 #define reg_hs_ths_exit                         DSI_DPHY_BITS(0x0024, 5, 0)
214 #define reg_hs_tclk_post                        DSI_DPHY_BITS(0x0028, 4, 0)
215 #define reserved                                DSI_DPHY_BITS(0x002c, 1, 0)
216 #define reg_hs_twakup_h                         DSI_DPHY_BITS(0x0030, 2, 0)
217 #define reg_hs_twakup_l                         DSI_DPHY_BITS(0x0034, 8, 0)
218 #define reg_hs_tclk_pre                         DSI_DPHY_BITS(0x0038, 4, 0)
219 #define reg_hs_tta_go                           DSI_DPHY_BITS(0x0040, 6, 0)
220 #define reg_hs_tta_sure                         DSI_DPHY_BITS(0x0044, 6, 0)
221 #define reg_hs_tta_wait                         DSI_DPHY_BITS(0x0048, 6, 0)
222 /* end of rk312x MIPI DSI DPHY REGISTERS */
223
224 /* global operation timing parameter */
225 struct gotp_m {
226         /* time uint is ns */
227         u32 min;
228         u32 value;
229         u32 max;
230 };
231
232 /*
233  * default time unit is ns
234  * Unit Interval, equal to the duration of any HS state on the Clock Lane
235 */
236 struct gotp {
237         u32 CLK_MISS;           /* min:no    max:60 */
238         u32 CLK_POST;           /* min:60 ns + 52*UI    max:no */
239         u32 CLK_PRE;            /* min:8*UI    max:no */
240         u32 CLK_PREPARE;        /* min:38    max:95 */
241         u32 CLK_SETTLE;         /* min:95    max:300 */
242         u32 CLK_TERM_EN;        /* min:Time for Dn to reach VTERM-EN    max:38 */
243         u32 CLK_TRAIL;          /* min:60    max:no */
244         u32 CLK_ZERO;           /* min:300 - CLK_PREPARE    max:no */
245         u32 D_TERM_EN;          /* min:Time for Dn to reach VTERM-EN    max:35 ns + 4*UI */
246         u32 EOT;                /* min:no    max:105 ns + n*12*UI */
247         u32 HS_EXIT;            /* min:100    max:no */
248         u32 HS_PREPARE;         /* min:40 ns + 4*UI     max:85 ns + 6*UI */
249         u32 HS_ZERO;            /* min:145 ns + 10*UI - HS_PREPARE    max:no */
250         u32 HS_SETTLE;          /* min:85 ns + 6*UI     max:145 ns + 10*UI */
251         u32 HS_SKIP;            /* min:40    max:55 ns + 4*UI */
252         u32 HS_TRAIL;           /* min: max( n*8*UI, 60 ns + n*4*UI )    max:no */
253         u32 NIT;                /* min:100us    max:no */
254         u32 LPX;                /* min:50    max:no */
255         u32 TA_GET;             /* min:5*TLPX */
256         u32 TA_GO;              /* min:4*TLPX */
257         u32 TA_SURE;            /* min:TLPX    max:2*TLPX */
258         u32 WAKEUP;             /* min:1ms    max:no */
259 };
260
261 struct dsi_phy {
262         u32 UI;
263         u32 ref_clk;            /* input_clk */
264         u32 ddr_clk;            /* data bit clk */
265         u32 txbyte_clk;         /* 1/8 of ddr_clk */
266         u32 sys_clk;
267         u32 pclk;
268         u32 txclkesc;
269
270         u32 Tddr_clk;           /* ps */
271         u32 Ttxbyte_clk;        /* ps */
272         u32 Tsys_clk;           /* ps */
273         u32 Tpclk;              /* ps */
274         u32 Ttxclkesc;          /* ps */
275
276         struct clk      *refclk;
277         unsigned long iobase;
278         void __iomem *membase;
279         u16 prediv;
280         u16 fbdiv;
281         u8 flag;
282         struct gotp gotp;
283
284 };
285
286 struct dsi_host {
287         u8 flag;
288         u8 lane;
289         u8 format;
290         u8 video_mode;
291         u32 clk;
292         u32 irq;
293         unsigned long iobase;
294         void __iomem *membase;
295 };
296
297 struct dsi {
298         u8 dsi_id;
299         u8 lcdc_id;
300         u8 vid;
301         struct dsi_phy phy;
302         struct dsi_host host;
303         struct mipi_dsi_ops ops;
304         struct mipi_dsi_screen screen;
305 #ifdef CONFIG_MIPI_DSI_LINUX
306         struct clk      *dsi_pclk; /* for mipi phy */
307         struct clk      *dsi_host_pclk; /* for mipi host */
308         struct clk      *h2p_hclk;
309         struct clk      *dsi_pd;
310 #endif
311     struct dentry *debugfs_dir;
312         struct platform_device *pdev;
313 };
314
315 int rk_mipi_get_dsi_clk(void);
316 int rk_mipi_get_dsi_num(void);
317 int rk_mipi_get_dsi_lane(void);
318 static int rk32_mipi_power_down_DDR(void);
319 static int rk32_mipi_power_up_DDR(void);
320 static void rk32_init_phy_mode(int lcdc_id);
321
322
323 #endif /* end of RK32_MIPI_DSI_H */