• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) Rockchip Electronics Co.Ltd
4  * Author:
5  *      Guochun Huang <hero.huang@rock-chips.com>
6  */
7 
8 #include <linux/clk.h>
9 #include <linux/component.h>
10 #include <linux/gpio.h>
11 #include <linux/iopoll.h>
12 #include <linux/math64.h>
13 #include <linux/module.h>
14 #include <linux/of_device.h>
15 #include <linux/of_gpio.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/regmap.h>
18 #include <linux/reset.h>
19 #include <linux/mfd/syscon.h>
20 #include <linux/phy/phy.h>
21 
22 #include <drm/drm_atomic_helper.h>
23 #include <drm/drm_crtc.h>
24 #include <drm/drm_crtc_helper.h>
25 #include <drm/drm_dsc.h>
26 #include <drm/drm_mipi_dsi.h>
27 #include <drm/drm_of.h>
28 #include <drm/drm_panel.h>
29 #include <video/mipi_display.h>
30 #include <video/videomode.h>
31 #include <asm/unaligned.h>
32 #include <uapi/linux/videodev2.h>
33 #include <drm/drm_panel.h>
34 #include <drm/drm_connector.h>
35 #include <drm/drm_probe_helper.h>
36 #include <drm/drm_simple_kms_helper.h>
37 
38 #include "rockchip_drm_drv.h"
39 #include "rockchip_drm_vop.h"
40 
41 #define UPDATE(v, h, l) (((v) << (l)) & GENMASK((h), (l)))
42 
43 #define DSI2_PWR_UP 0x000c
44 #define RESET 0
45 #define POWER_UP BIT(0)
46 #define CMD_TX_MODE(x) UPDATE((x), 24, 24)
47 #define DSI2_SOFT_RESET 0x0010
48 #define SYS_RSTN BIT(2)
49 #define PHY_RSTN BIT(1)
50 #define IPI_RSTN BIT(0)
51 #define INT_ST_MAIN 0x0014
52 #define DSI2_MODE_CTRL 0x0018
53 #define DSI2_MODE_STATUS 0x001c
54 #define DSI2_CORE_STATUS 0x0020
55 #define PRI_RD_DATA_AVAIL BIT(26)
56 #define PRI_FIFOS_NOT_EMPTY BIT(25)
57 #define PRI_BUSY BIT(24)
58 #define CRI_RD_DATA_AVAIL BIT(18)
59 #define CRT_FIFOS_NOT_EMPTY BIT(17)
60 #define CRI_BUSY BIT(16)
61 #define IPI_FIFOS_NOT_EMPTY BIT(9)
62 #define IPI_BUSY BIT(8)
63 #define CORE_FIFOS_NOT_EMPTY BIT(1)
64 #define CORE_BUSY BIT(0)
65 #define MANUAL_MODE_CFG 0x0024
66 #define MANUAL_MODE_EN BIT(0)
67 #define DSI2_TIMEOUT_HSTX_CFG 0x0048
68 #define TO_HSTX(x) UPDATE((x), 15, 0)
69 #define DSI2_TIMEOUT_HSTXRDY_CFG 0x004c
70 #define TO_HSTXRDY(x) UPDATE((x), 15, 0)
71 #define DSI2_TIMEOUT_LPRX_CFG 0x0050
72 #define TO_LPRXRDY(x) UPDATE((x), 15, 0)
73 #define DSI2_TIMEOUT_LPTXRDY_CFG 0x0054
74 #define TO_LPTXRDY(x) UPDATE((x), 15, 0)
75 #define DSI2_TIMEOUT_LPTXTRIG_CFG 0x0058
76 #define TO_LPTXTRIG(x) UPDATE((x), 15, 0)
77 #define DSI2_TIMEOUT_LPTXULPS_CFG 0x005c
78 #define TO_LPTXULPS(x) UPDATE((x), 15, 0)
79 #define DSI2_TIMEOUT_BTA_CFG 0x60
80 #define TO_BTA(x) UPDATE((x), 15, 0)
81 
82 #define DSI2_PHY_MODE_CFG 0x0100
83 #define PPI_WIDTH(x) UPDATE((x), 9, 8)
84 #define PHY_LANES(x) UPDATE((x)-1, 5, 4)
85 #define PHY_TYPE(x) UPDATE((x), 0, 0)
86 #define DSI2_PHY_CLK_CFG 0X0104
87 #define PHY_LPTX_CLK_DIV(x) UPDATE((x), 12, 8)
88 #define CLK_TYPE_MASK BIT(0)
89 #define NON_CONTINUOUS_CLK BIT(0)
90 #define CONTIUOUS_CLK 0
91 #define DSI2_PHY_LP2HS_MAN_CFG 0x010c
92 #define PHY_LP2HS_TIME(x) UPDATE((x), 28, 0)
93 #define DSI2_PHY_HS2LP_MAN_CFG 0x0114
94 #define PHY_HS2LP_TIME(x) UPDATE((x), 28, 0)
95 #define DSI2_PHY_MAX_RD_T_MAN_CFG 0x011c
96 #define PHY_MAX_RD_TIME(x) UPDATE((x), 26, 0)
97 #define DSI2_PHY_ESC_CMD_T_MAN_CFG 0x0124
98 #define PHY_ESC_CMD_TIME(x) UPDATE((x), 28, 0)
99 #define DSI2_PHY_ESC_BYTE_T_MAN_CFG 0x012c
100 #define PHY_ESC_BYTE_TIME(x) UPDATE((x), 28, 0)
101 
102 #define DSI2_PHY_IPI_RATIO_MAN_CFG 0x0134
103 #define PHY_IPI_RATIO(x) UPDATE((x), 21, 0)
104 #define DSI2_PHY_SYS_RATIO_MAN_CFG 0x013C
105 #define PHY_SYS_RATIO(x) UPDATE((x), 16, 0)
106 
107 #define DSI2_DSI_GENERAL_CFG 0x0200
108 #define BTA_EN BIT(1)
109 #define EOTP_TX_EN BIT(0)
110 #define DSI2_DSI_VCID_CFG 0x0204
111 #define TX_VCID(x) UPDATE((x), 1, 0)
112 #define DSI2_DSI_SCRAMBLING_CFG 0x0208
113 #define SCRAMBLING_SEED(x) UPDATE((x), 31, 16)
114 #define SCRAMBLING_EN BIT(0)
115 #define DSI2_DSI_VID_TX_CFG 0x020c
116 #define LPDT_DISPLAY_CMD_EN BIT(20)
117 #define BLK_VFP_HS_EN BIT(14)
118 #define BLK_VBP_HS_EN BIT(13)
119 #define BLK_VSA_HS_EN BIT(12)
120 #define BLK_HFP_HS_EN BIT(6)
121 #define BLK_HBP_HS_EN BIT(5)
122 #define BLK_HSA_HS_EN BIT(4)
123 #define VID_MODE_TYPE(x) UPDATE((x), 1, 0)
124 #define DSI2_CRI_TX_HDR 0x02c0
125 #define CMD_TX_MODE(x) UPDATE((x), 24, 24)
126 #define DSI2_CRI_TX_PLD 0x02c4
127 #define DSI2_CRI_RX_HDR 0x02c8
128 #define DSI2_CRI_RX_PLD 0x02cc
129 
130 #define DSI2_IPI_COLOR_MAN_CFG 0x0300
131 #define IPI_DEPTH(x) UPDATE((x), 7, 4)
132 #define IPI_DEPTH_5_6_5_BITS 0x02
133 #define IPI_DEPTH_6_BITS 0x03
134 #define IPI_DEPTH_8_BITS 0x05
135 #define IPI_DEPTH_10_BITS 0x06
136 #define IPI_FORMAT(x) UPDATE((x), 3, 0)
137 #define IPI_FORMAT_RGB 0x0
138 #define IPI_FORMAT_DSC 0x0b
139 #define DSI2_IPI_VID_HSA_MAN_CFG 0x0304
140 #define VID_HSA_TIME(x) UPDATE((x), 29, 0)
141 #define DSI2_IPI_VID_HBP_MAN_CFG 0x030c
142 #define VID_HBP_TIME(x) UPDATE((x), 29, 0)
143 #define DSI2_IPI_VID_HACT_MAN_CFG 0x0314
144 #define VID_HACT_TIME(x) UPDATE((x), 29, 0)
145 #define DSI2_IPI_VID_HLINE_MAN_CFG 0x031c
146 #define VID_HLINE_TIME(x) UPDATE((x), 29, 0)
147 #define DSI2_IPI_VID_VSA_MAN_CFG 0x0324
148 #define VID_VSA_LINES(x) UPDATE((x), 9, 0)
149 #define DSI2_IPI_VID_VBP_MAN_CFG 0X032C
150 #define VID_VBP_LINES(x) UPDATE((x), 9, 0)
151 #define DSI2_IPI_VID_VACT_MAN_CFG 0X0334
152 #define VID_VACT_LINES(x) UPDATE((x), 13, 0)
153 #define DSI2_IPI_VID_VFP_MAN_CFG 0X033C
154 #define VID_VFP_LINES(x) UPDATE((x), 9, 0)
155 #define DSI2_IPI_PIX_PKT_CFG 0x0344
156 #define MAX_PIX_PKT(x) UPDATE((x), 15, 0)
157 
158 #define DSI2_INT_ST_PHY 0x0400
159 #define DSI2_INT_MASK_PHY 0x0404
160 #define DSI2_INT_ST_TO 0x0410
161 #define DSI2_INT_MASK_TO 0x0414
162 #define DSI2_INT_ST_ACK 0x0420
163 #define DSI2_INT_MASK_ACK 0x0424
164 #define DSI2_INT_ST_IPI 0x0430
165 #define DSI2_INT_MASK_IPI 0x0434
166 #define DSI2_INT_ST_FIFO 0x0440
167 #define DSI2_INT_MASK_FIFO 0x0444
168 #define DSI2_INT_ST_PRI 0x0450
169 #define DSI2_INT_MASK_PRI 0x0454
170 #define DSI2_INT_ST_CRI 0x0460
171 #define DSI2_INT_MASK_CRI 0x0464
172 #define DSI2_INT_FORCE_CRI 0x0468
173 #define DSI2_MAX_REGISGER DSI2_INT_FORCE_CRI
174 
175 #define MODE_STATUS_TIMEOUT_US 10000
176 #define CMD_PKT_STATUS_TIMEOUT_US 20000
177 #define PSEC_PER_SEC 1000000000000LL
178 
179 #define GRF_REG_FIELD(reg, lsb, msb) (((reg) << 16) | ((lsb) << 8) | (msb))
180 
181 enum vid_mode_type {
182     VID_MODE_TYPE_NON_BURST_SYNC_PULSES,
183     VID_MODE_TYPE_NON_BURST_SYNC_EVENTS,
184     VID_MODE_TYPE_BURST,
185 };
186 
187 enum mode_ctrl {
188     IDLE_MODE,
189     AUTOCALC_MODE,
190     COMMAND_MODE,
191     VIDEO_MODE,
192     DATA_STREAM_MODE,
193     VIDE_TEST_MODE,
194     DATA_STREAM_TEST_MODE,
195 };
196 
197 enum grf_reg_fields {
198     TXREQCLKHS_EN,
199     GATING_EN,
200     IPI_SHUTDN,
201     IPI_COLORM,
202     IPI_COLOR_DEPTH,
203     IPI_FORMAT,
204     MAX_FIELDS,
205 };
206 
207 enum phy_type {
208     DPHY,
209     CPHY,
210 };
211 
212 enum ppi_width {
213     PPI_WIDTH_8_BITS,
214     PPI_WIDTH_16_BITS,
215     PPI_WIDTH_32_BITS,
216 };
217 
218 struct cmd_header {
219     u8 cmd_type;
220     u8 delay;
221     u8 payload_length;
222 };
223 
224 struct dw_mipi_dsi2_plat_data {
225     const u32 *dsi0_grf_reg_fields;
226     const u32 *dsi1_grf_reg_fields;
227     unsigned long long dphy_max_bit_rate_per_lane;
228     unsigned long long cphy_max_symbol_rate_per_lane;
229 };
230 
231 struct dw_mipi_dsi2 {
232     struct drm_encoder encoder;
233     struct drm_connector connector;
234     struct drm_bridge *bridge;
235     struct mipi_dsi_host host;
236     struct drm_panel *panel;
237     struct drm_display_mode mode;
238     struct device *dev;
239     struct device_node *client;
240     struct regmap *grf;
241     struct clk *pclk;
242     struct clk *sys_clk;
243     bool phy_enabled;
244     struct phy *dcphy;
245     union phy_configure_opts phy_opts;
246 
247     bool c_option;
248     bool scrambling_en;
249     unsigned int slice_width;
250     unsigned int slice_height;
251     bool dsc_enable;
252     u8 version_major;
253     u8 version_minor;
254 
255     struct drm_dsc_picture_parameter_set *pps;
256     struct regmap *regmap;
257     struct reset_control *apb_rst;
258     int irq;
259     int id;
260 
261     /* dual-channel */
262     struct dw_mipi_dsi2 *master;
263     struct dw_mipi_dsi2 *slave;
264     bool data_swap;
265 
266     unsigned int lane_hs_rate; /* Mbps or Msps per lane */
267     u32 channel;
268     u32 lanes;
269     u32 format;
270     unsigned long mode_flags;
271 
272     const struct dw_mipi_dsi2_plat_data *pdata;
273     struct rockchip_drm_sub_dev sub_dev;
274 
275     struct gpio_desc *te_gpio;
276 };
277 
host_to_dsi2(struct mipi_dsi_host * host)278 static inline struct dw_mipi_dsi2 *host_to_dsi2(struct mipi_dsi_host *host)
279 {
280     return container_of(host, struct dw_mipi_dsi2, host);
281 }
282 
con_to_dsi2(struct drm_connector * con)283 static inline struct dw_mipi_dsi2 *con_to_dsi2(struct drm_connector *con)
284 {
285     return container_of(con, struct dw_mipi_dsi2, connector);
286 }
287 
encoder_to_dsi2(struct drm_encoder * encoder)288 static inline struct dw_mipi_dsi2 *encoder_to_dsi2(struct drm_encoder *encoder)
289 {
290     return container_of(encoder, struct dw_mipi_dsi2, encoder);
291 }
292 
grf_field_write(struct dw_mipi_dsi2 * dsi2,enum grf_reg_fields index,unsigned int val)293 static void grf_field_write(struct dw_mipi_dsi2 *dsi2, enum grf_reg_fields index, unsigned int val)
294 {
295     const u32 field = dsi2->id ? dsi2->pdata->dsi1_grf_reg_fields[index] : dsi2->pdata->dsi0_grf_reg_fields[index];
296     u16 reg;
297     u8 msb, lsb;
298 
299     if (!field) {
300         return;
301     }
302 
303     reg = (field >> 0x10) & 0xffff;
304     lsb = (field >> 0x8) & 0xff;
305     msb = (field >> 0x0) & 0xff;
306 
307     regmap_write(dsi2->grf, reg, (val << lsb) | (GENMASK(msb, lsb) << 0x10));
308 }
309 
cri_fifos_wait_avail(struct dw_mipi_dsi2 * dsi2)310 static int cri_fifos_wait_avail(struct dw_mipi_dsi2 *dsi2)
311 {
312     u32 sts, mask;
313     int ret;
314 
315     mask = CRI_BUSY | CRT_FIFOS_NOT_EMPTY;
316     ret = regmap_read_poll_timeout(dsi2->regmap, DSI2_CORE_STATUS, sts, !(sts & mask), 0, CMD_PKT_STATUS_TIMEOUT_US);
317     if (ret < 0) {
318         DRM_DEV_ERROR(dsi2->dev, "command interface is busy\n");
319         return ret;
320     }
321 
322     return 0;
323 }
324 
dw_mipi_dsi2_irq_enable(struct dw_mipi_dsi2 * dsi2,bool enable)325 static void dw_mipi_dsi2_irq_enable(struct dw_mipi_dsi2 *dsi2, bool enable)
326 {
327     if (enable) {
328         regmap_write(dsi2->regmap, DSI2_INT_MASK_PHY, 0x1);
329         regmap_write(dsi2->regmap, DSI2_INT_MASK_TO, 0xf);
330         regmap_write(dsi2->regmap, DSI2_INT_MASK_ACK, 0x1);
331         regmap_write(dsi2->regmap, DSI2_INT_MASK_IPI, 0x1);
332         regmap_write(dsi2->regmap, DSI2_INT_MASK_FIFO, 0x1);
333         regmap_write(dsi2->regmap, DSI2_INT_MASK_PRI, 0x1);
334         regmap_write(dsi2->regmap, DSI2_INT_MASK_CRI, 0x1);
335     } else {
336         regmap_write(dsi2->regmap, DSI2_INT_MASK_PHY, 0x0);
337         regmap_write(dsi2->regmap, DSI2_INT_MASK_TO, 0x0);
338         regmap_write(dsi2->regmap, DSI2_INT_MASK_ACK, 0x0);
339         regmap_write(dsi2->regmap, DSI2_INT_MASK_IPI, 0x0);
340         regmap_write(dsi2->regmap, DSI2_INT_MASK_FIFO, 0x0);
341         regmap_write(dsi2->regmap, DSI2_INT_MASK_PRI, 0x0);
342         regmap_write(dsi2->regmap, DSI2_INT_MASK_CRI, 0x0);
343     };
344 }
345 
mipi_dcphy_power_on(struct dw_mipi_dsi2 * dsi2)346 static void mipi_dcphy_power_on(struct dw_mipi_dsi2 *dsi2)
347 {
348     if (dsi2->phy_enabled) {
349         return;
350     }
351 
352     if (dsi2->dcphy) {
353         phy_power_on(dsi2->dcphy);
354     }
355 
356     dsi2->phy_enabled = true;
357 }
358 
mipi_dcphy_power_off(struct dw_mipi_dsi2 * dsi2)359 static void mipi_dcphy_power_off(struct dw_mipi_dsi2 *dsi2)
360 {
361     if (!dsi2->phy_enabled) {
362         return;
363     }
364 
365     if (dsi2->dcphy) {
366         phy_power_off(dsi2->dcphy);
367     }
368 
369     dsi2->phy_enabled = false;
370 }
371 
dw_mipi_dsi2_set_vid_mode(struct dw_mipi_dsi2 * dsi2)372 static void dw_mipi_dsi2_set_vid_mode(struct dw_mipi_dsi2 *dsi2)
373 {
374     u32 val = 0, mode;
375     int ret;
376 
377     if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) {
378         val |= VID_MODE_TYPE_BURST;
379     } else if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) {
380         val |= VID_MODE_TYPE_NON_BURST_SYNC_PULSES;
381     } else {
382         val |= VID_MODE_TYPE_NON_BURST_SYNC_EVENTS;
383     }
384 
385     regmap_write(dsi2->regmap, DSI2_DSI_VID_TX_CFG, val);
386 
387     regmap_write(dsi2->regmap, DSI2_MODE_CTRL, VIDEO_MODE);
388     ret = regmap_read_poll_timeout(dsi2->regmap, DSI2_MODE_STATUS, mode, mode & VIDEO_MODE, 0x3e8,
389                                    MODE_STATUS_TIMEOUT_US);
390     if (ret < 0) {
391         dev_err(dsi2->dev, "failed to enter video mode\n");
392     }
393 }
394 
dw_mipi_dsi2_set_data_stream_mode(struct dw_mipi_dsi2 * dsi2)395 static void dw_mipi_dsi2_set_data_stream_mode(struct dw_mipi_dsi2 *dsi2)
396 {
397     u32 mode;
398     int ret;
399 
400     regmap_write(dsi2->regmap, DSI2_MODE_CTRL, DATA_STREAM_MODE);
401     ret = regmap_read_poll_timeout(dsi2->regmap, DSI2_MODE_STATUS, mode, mode & DATA_STREAM_MODE, 0x3e8,
402                                    MODE_STATUS_TIMEOUT_US);
403     if (ret < 0) {
404         dev_err(dsi2->dev, "failed to enter data stream mode\n");
405     }
406 }
407 
dw_mipi_dsi2_set_cmd_mode(struct dw_mipi_dsi2 * dsi2)408 static void dw_mipi_dsi2_set_cmd_mode(struct dw_mipi_dsi2 *dsi2)
409 {
410     u32 mode;
411     int ret;
412 
413     regmap_write(dsi2->regmap, DSI2_MODE_CTRL, COMMAND_MODE);
414     ret = regmap_read_poll_timeout(dsi2->regmap, DSI2_MODE_STATUS, mode, mode & COMMAND_MODE, 0x3e8,
415                                    MODE_STATUS_TIMEOUT_US);
416     if (ret < 0) {
417         dev_err(dsi2->dev, "failed to enter data stream mode\n");
418     }
419 }
420 
dw_mipi_dsi2_disable(struct dw_mipi_dsi2 * dsi2)421 static void dw_mipi_dsi2_disable(struct dw_mipi_dsi2 *dsi2)
422 {
423     regmap_write(dsi2->regmap, DSI2_IPI_PIX_PKT_CFG, 0);
424     dw_mipi_dsi2_set_cmd_mode(dsi2);
425 
426     if (dsi2->slave) {
427         dw_mipi_dsi2_disable(dsi2->slave);
428     }
429 }
430 
dw_mipi_dsi2_post_disable(struct dw_mipi_dsi2 * dsi2)431 static void dw_mipi_dsi2_post_disable(struct dw_mipi_dsi2 *dsi2)
432 {
433     dw_mipi_dsi2_irq_enable(dsi2, 0);
434     regmap_write(dsi2->regmap, DSI2_PWR_UP, RESET);
435     mipi_dcphy_power_off(dsi2);
436     pm_runtime_put(dsi2->dev);
437 
438     if (dsi2->slave) {
439         dw_mipi_dsi2_post_disable(dsi2->slave);
440     }
441 }
442 
dw_mipi_dsi2_encoder_disable(struct drm_encoder * encoder)443 static void dw_mipi_dsi2_encoder_disable(struct drm_encoder *encoder)
444 {
445     struct dw_mipi_dsi2 *dsi2 = encoder_to_dsi2(encoder);
446 
447     if (dsi2->panel) {
448         drm_panel_disable(dsi2->panel);
449     }
450 
451     if (!(dsi2->mode_flags & MIPI_DSI_MODE_VIDEO)) {
452         vop2_standby(encoder->crtc, 1);
453     }
454 
455     dw_mipi_dsi2_disable(dsi2);
456 
457     if (!(dsi2->mode_flags & MIPI_DSI_MODE_VIDEO)) {
458         vop2_standby(encoder->crtc, 0);
459     }
460 
461     if (dsi2->panel) {
462         drm_panel_unprepare(dsi2->panel);
463     }
464 
465     dw_mipi_dsi2_post_disable(dsi2);
466 }
467 
dw_mipi_dsi2_set_lane_rate(struct dw_mipi_dsi2 * dsi2)468 static void dw_mipi_dsi2_set_lane_rate(struct dw_mipi_dsi2 *dsi2)
469 {
470     struct device *dev = dsi2->dev;
471     const struct drm_display_mode *mode = &dsi2->mode;
472     unsigned long max_lane_rate;
473     unsigned long lane_rate, hs_clk_rate, target_pclk;
474     unsigned int value;
475     int bpp, lanes;
476     u64 tmp;
477 
478     max_lane_rate =
479         (dsi2->c_option) ? dsi2->pdata->cphy_max_symbol_rate_per_lane : dsi2->pdata->dphy_max_bit_rate_per_lane;
480 
481     lanes = (dsi2->slave || dsi2->master) ? dsi2->lanes * 0x2 : dsi2->lanes;
482     bpp = mipi_dsi_pixel_format_to_bpp(dsi2->format);
483     if (bpp < 0) {
484         bpp = 0x18;
485     }
486 
487     /* optional override of the desired bandwidth */
488     if (!of_property_read_u32(dev->of_node, "rockchip,lane-rate", &value)) {
489         lane_rate = value * USEC_PER_SEC;
490     } else {
491         tmp = (u64)mode->clock * 0x3e8 * bpp;
492         do_div(tmp, lanes);
493 
494         /*
495          * Multiple bits are encoded into each symbol epoch,
496          * the data rate is ~2.28x the symbol rate.
497          */
498         if (dsi2->c_option) {
499             tmp = DIV_ROUND_CLOSEST_ULL(tmp * 0x64, 0xe4);
500         }
501 
502         /* take 1 / 0.9, since Mbps must big than bandwidth of RGB */
503         tmp *= 0xa;
504         do_div(tmp, 0x9);
505 
506         if (tmp > max_lane_rate) {
507             lane_rate = max_lane_rate;
508         } else {
509             lane_rate = tmp;
510         }
511     }
512 
513     target_pclk = DIV_ROUND_CLOSEST_ULL(lane_rate * lanes, bpp);
514     phy_mipi_dphy_get_default_config(target_pclk, bpp, lanes, &dsi2->phy_opts.mipi_dphy);
515 
516     if (dsi2->dcphy) {
517         if (!dsi2->c_option) {
518             phy_set_mode(dsi2->dcphy, PHY_MODE_MIPI_DPHY);
519         }
520     }
521 
522     phy_configure(dsi2->dcphy, &dsi2->phy_opts);
523     hs_clk_rate = dsi2->phy_opts.mipi_dphy.hs_clk_rate;
524     dsi2->lane_hs_rate = DIV_ROUND_UP(hs_clk_rate, USEC_PER_SEC);
525 }
526 
dw_mipi_dsi2_host_softrst(struct dw_mipi_dsi2 * dsi2)527 static void dw_mipi_dsi2_host_softrst(struct dw_mipi_dsi2 *dsi2)
528 {
529     if (dsi2->apb_rst) {
530         reset_control_assert(dsi2->apb_rst);
531         usleep_range(0xa, 0x14);
532         reset_control_deassert(dsi2->apb_rst);
533     }
534 
535     regmap_write(dsi2->regmap, DSI2_SOFT_RESET, 0x0);
536     udelay(0x64);
537     regmap_write(dsi2->regmap, DSI2_SOFT_RESET, SYS_RSTN | PHY_RSTN | IPI_RSTN);
538 }
539 
dw_mipi_dsi2_phy_mode_cfg(struct dw_mipi_dsi2 * dsi2)540 static void dw_mipi_dsi2_phy_mode_cfg(struct dw_mipi_dsi2 *dsi2)
541 {
542     u32 val = 0;
543 
544     /* PPI width is fixed to 16 bits in DCPHY */
545     val |= PPI_WIDTH(PPI_WIDTH_16_BITS) | PHY_LANES(dsi2->lanes);
546     val |= PHY_TYPE(dsi2->c_option ? CPHY : DPHY);
547     regmap_write(dsi2->regmap, DSI2_PHY_MODE_CFG, val);
548 }
549 
dw_mipi_dsi2_phy_clk_mode_cfg(struct dw_mipi_dsi2 * dsi2)550 static void dw_mipi_dsi2_phy_clk_mode_cfg(struct dw_mipi_dsi2 *dsi2)
551 {
552     u32 sys_clk, esc_clk_div;
553     u32 val = 0;
554 
555     /*
556      * clk_type should be NON_CONTINUOUS_CLK before
557      * initial deskew calibration be sent.
558      */
559     val |= NON_CONTINUOUS_CLK;
560 
561     /* The Escape clock ranges from 1MHz to 20MHz. */
562     sys_clk = clk_get_rate(dsi2->sys_clk) / USEC_PER_SEC;
563     esc_clk_div = DIV_ROUND_UP(sys_clk, 0xa * 0x2);
564     val |= PHY_LPTX_CLK_DIV(esc_clk_div);
565 
566     regmap_write(dsi2->regmap, DSI2_PHY_CLK_CFG, val);
567 }
568 
dw_mipi_dsi2_phy_ratio_cfg(struct dw_mipi_dsi2 * dsi2)569 static void dw_mipi_dsi2_phy_ratio_cfg(struct dw_mipi_dsi2 *dsi2)
570 {
571     struct drm_display_mode *mode = &dsi2->mode;
572     u32 sys_clk = clk_get_rate(dsi2->sys_clk) / MSEC_PER_SEC;
573     u64 pixel_clk, ipi_clk, phy_hsclk;
574     u64 tmp;
575 
576     /*
577      * in DPHY mode, the phy_hstx_clk is exactly 1/16 the Lane high-speed
578      * data rate; In CPHY mode, the phy_hstx_clk is exactly 1/7 the trio
579      * high speed symbol rate.
580      */
581     if (dsi2->c_option) {
582         phy_hsclk = DIV_ROUND_CLOSEST_ULL(dsi2->lane_hs_rate * MSEC_PER_SEC, 0x7);
583     } else {
584         phy_hsclk = DIV_ROUND_CLOSEST_ULL(dsi2->lane_hs_rate * MSEC_PER_SEC, 0x10);
585     }
586 
587     /* IPI_RATIO_MAN_CFG = PHY_HSTX_CLK / IPI_CLK */
588     pixel_clk = mode->clock;
589     ipi_clk = pixel_clk / 0x4;
590 
591     tmp = DIV_ROUND_CLOSEST_ULL(phy_hsclk << 0x10, ipi_clk);
592     regmap_write(dsi2->regmap, DSI2_PHY_IPI_RATIO_MAN_CFG, PHY_IPI_RATIO(tmp));
593 
594     /*
595      * SYS_RATIO_MAN_CFG = MIPI_DCPHY_HSCLK_Freq / MIPI_DCPHY_HSCLK_Freq
596      */
597     tmp = DIV_ROUND_CLOSEST_ULL(phy_hsclk << 0x10, sys_clk);
598     regmap_write(dsi2->regmap, DSI2_PHY_SYS_RATIO_MAN_CFG, PHY_SYS_RATIO(tmp));
599 }
600 
dw_mipi_dsi2_lp2hs_or_hs2lp_cfg(struct dw_mipi_dsi2 * dsi2)601 static void dw_mipi_dsi2_lp2hs_or_hs2lp_cfg(struct dw_mipi_dsi2 *dsi2)
602 {
603     struct phy_configure_opts_mipi_dphy *cfg = &dsi2->phy_opts.mipi_dphy;
604     unsigned long long tmp, ui;
605     unsigned long long hstx_clk;
606 
607     hstx_clk = DIV_ROUND_CLOSEST_ULL(dsi2->lane_hs_rate * USEC_PER_SEC, 0x10);
608 
609     ui = ALIGN(PSEC_PER_SEC, hstx_clk);
610     do_div(ui, hstx_clk);
611 
612     /* PHY_LP2HS_TIME = (TLPX + THS-PREPARE + THS-ZERO) / Tphy_hstx_clk */
613     tmp = cfg->lpx + cfg->hs_prepare + cfg->hs_zero;
614     tmp = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, ui);
615     regmap_write(dsi2->regmap, DSI2_PHY_LP2HS_MAN_CFG, PHY_LP2HS_TIME(tmp));
616 
617     /* PHY_HS2LP_TIME = (THS-TRAIL + THS-EXIT) / Tphy_hstx_clk */
618     tmp = cfg->hs_trail + cfg->hs_exit;
619     tmp = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, ui);
620     regmap_write(dsi2->regmap, DSI2_PHY_HS2LP_MAN_CFG, PHY_HS2LP_TIME(tmp));
621 }
622 
dw_mipi_dsi2_phy_init(struct dw_mipi_dsi2 * dsi2)623 static void dw_mipi_dsi2_phy_init(struct dw_mipi_dsi2 *dsi2)
624 {
625     dw_mipi_dsi2_phy_mode_cfg(dsi2);
626     dw_mipi_dsi2_phy_clk_mode_cfg(dsi2);
627     dw_mipi_dsi2_phy_ratio_cfg(dsi2);
628     dw_mipi_dsi2_lp2hs_or_hs2lp_cfg(dsi2);
629 
630     /* phy configuration 8 - 10 */
631 }
632 
dw_mipi_dsi2_tx_option_set(struct dw_mipi_dsi2 * dsi2)633 static void dw_mipi_dsi2_tx_option_set(struct dw_mipi_dsi2 *dsi2)
634 {
635     u32 val;
636 
637     val = BTA_EN | EOTP_TX_EN;
638 
639     if (dsi2->mode_flags & MIPI_DSI_MODE_EOT_PACKET) {
640         val &= ~EOTP_TX_EN;
641     }
642 
643     regmap_write(dsi2->regmap, DSI2_DSI_GENERAL_CFG, val);
644     regmap_write(dsi2->regmap, DSI2_DSI_VCID_CFG, TX_VCID(dsi2->channel));
645 
646     if (dsi2->scrambling_en) {
647         regmap_write(dsi2->regmap, DSI2_DSI_SCRAMBLING_CFG, SCRAMBLING_EN);
648     }
649 
650     val = 0;
651     if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO_HFP) {
652         val |= BLK_HFP_HS_EN;
653     }
654 
655     if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO_HBP) {
656         val |= BLK_HBP_HS_EN;
657     }
658 
659     if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO_HSA) {
660         val |= BLK_HSA_HS_EN;
661     }
662 
663     regmap_write(dsi2->regmap, DSI2_DSI_VID_TX_CFG, val);
664 
665     /* configure the maximum return packet size that periphera can send */
666 }
667 
dw_mipi_dsi2_ipi_color_coding_cfg(struct dw_mipi_dsi2 * dsi2)668 static void dw_mipi_dsi2_ipi_color_coding_cfg(struct dw_mipi_dsi2 *dsi2)
669 {
670     u32 val, color_depth;
671 
672     switch (dsi2->format) {
673         case MIPI_DSI_FMT_RGB666:
674         case MIPI_DSI_FMT_RGB666_PACKED:
675             color_depth = IPI_DEPTH_6_BITS;
676             break;
677         case MIPI_DSI_FMT_RGB565:
678             color_depth = IPI_DEPTH_5_6_5_BITS;
679             break;
680         case MIPI_DSI_FMT_RGB888:
681         default:
682             color_depth = IPI_DEPTH_8_BITS;
683             break;
684     }
685 
686     val = IPI_DEPTH(color_depth) | IPI_FORMAT(dsi2->dsc_enable ? IPI_FORMAT_DSC : IPI_FORMAT_RGB);
687     regmap_write(dsi2->regmap, DSI2_IPI_COLOR_MAN_CFG, val);
688     grf_field_write(dsi2, IPI_COLOR_DEPTH, color_depth);
689 
690     if (dsi2->dsc_enable) {
691         grf_field_write(dsi2, IPI_FORMAT, IPI_FORMAT_DSC);
692     }
693 }
694 
dw_mipi_dsi2_ipi_set(struct dw_mipi_dsi2 * dsi2)695 static void dw_mipi_dsi2_ipi_set(struct dw_mipi_dsi2 *dsi2)
696 {
697     struct drm_display_mode *mode = &dsi2->mode;
698     u32 hline, hsa, hbp, hact;
699     u64 hline_time, hsa_time, hbp_time, hact_time, tmp;
700     u32 vact, vsa, vfp, vbp;
701     u32 pixel_clk, phy_hs_clk;
702     u16 val;
703 
704     if (dsi2->slave || dsi2->master) {
705         val = mode->hdisplay / 0x2;
706     } else {
707         val = mode->hdisplay;
708     }
709 
710     regmap_write(dsi2->regmap, DSI2_IPI_PIX_PKT_CFG, MAX_PIX_PKT(val));
711 
712     dw_mipi_dsi2_ipi_color_coding_cfg(dsi2);
713 
714     /*
715      * if the controller is intended to operate in data stream mode,
716      * no more steps are required.
717      */
718     if (!(dsi2->mode_flags & MIPI_DSI_MODE_VIDEO)) {
719         return;
720     }
721 
722     vact = mode->vdisplay;
723     vsa = mode->vsync_end - mode->vsync_start;
724     vfp = mode->vsync_start - mode->vdisplay;
725     vbp = mode->vtotal - mode->vsync_end;
726     hact = mode->hdisplay;
727     hsa = mode->hsync_end - mode->hsync_start;
728     hbp = mode->htotal - mode->hsync_end;
729     hline = mode->htotal;
730 
731     pixel_clk = mode->clock / 0x3e8;
732 
733     if (dsi2->c_option) {
734         phy_hs_clk = DIV_ROUND_CLOSEST_ULL(dsi2->lane_hs_rate, 0x7);
735     } else {
736         phy_hs_clk = DIV_ROUND_CLOSEST_ULL(dsi2->lane_hs_rate, 0x10);
737     }
738 
739     tmp = hsa * phy_hs_clk;
740     hsa_time = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, pixel_clk);
741     regmap_write(dsi2->regmap, DSI2_IPI_VID_HSA_MAN_CFG, VID_HSA_TIME(hsa_time));
742 
743     tmp = hbp * phy_hs_clk;
744     hbp_time = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, pixel_clk);
745     regmap_write(dsi2->regmap, DSI2_IPI_VID_HBP_MAN_CFG, VID_HBP_TIME(hbp_time));
746 
747     tmp = hact * phy_hs_clk;
748     hact_time = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, pixel_clk);
749     regmap_write(dsi2->regmap, DSI2_IPI_VID_HACT_MAN_CFG, VID_HACT_TIME(hact_time));
750 
751     tmp = hline * phy_hs_clk;
752     hline_time = DIV_ROUND_CLOSEST_ULL(tmp << 0x10, pixel_clk);
753     regmap_write(dsi2->regmap, DSI2_IPI_VID_HLINE_MAN_CFG, VID_HLINE_TIME(hline_time));
754 
755     regmap_write(dsi2->regmap, DSI2_IPI_VID_VSA_MAN_CFG, VID_VSA_LINES(vsa));
756     regmap_write(dsi2->regmap, DSI2_IPI_VID_VBP_MAN_CFG, VID_VBP_LINES(vbp));
757     regmap_write(dsi2->regmap, DSI2_IPI_VID_VACT_MAN_CFG, VID_VACT_LINES(vact));
758     regmap_write(dsi2->regmap, DSI2_IPI_VID_VFP_MAN_CFG, VID_VFP_LINES(vfp));
759 }
760 
dw_mipi_dsi2_work_mode(struct dw_mipi_dsi2 * dsi2,u32 mode)761 static void dw_mipi_dsi2_work_mode(struct dw_mipi_dsi2 *dsi2, u32 mode)
762 {
763     /*
764      * select controller work in Manual mode
765      * Manual: MANUAL_MODE_EN
766      * Automatic: 0
767      */
768     regmap_write(dsi2->regmap, MANUAL_MODE_CFG, mode);
769 }
770 
dw_mipi_dsi2_pre_enable(struct dw_mipi_dsi2 * dsi2)771 static void dw_mipi_dsi2_pre_enable(struct dw_mipi_dsi2 *dsi2)
772 {
773     pm_runtime_get_sync(dsi2->dev);
774 
775     dw_mipi_dsi2_host_softrst(dsi2);
776     regmap_write(dsi2->regmap, DSI2_PWR_UP, RESET);
777 
778     /* there may be some timeout registers may be configured if desired */
779 
780     dw_mipi_dsi2_work_mode(dsi2, MANUAL_MODE_EN);
781     dw_mipi_dsi2_phy_init(dsi2);
782     dw_mipi_dsi2_tx_option_set(dsi2);
783     dw_mipi_dsi2_irq_enable(dsi2, 1);
784     mipi_dcphy_power_on(dsi2);
785 
786     /*
787      * initial deskew calibration is send after phy_power_on,
788      * then we can configure clk_type.
789      */
790     if (!(dsi2->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS)) {
791         regmap_update_bits(dsi2->regmap, DSI2_PHY_CLK_CFG, CLK_TYPE_MASK, CONTIUOUS_CLK);
792     }
793 
794     regmap_write(dsi2->regmap, DSI2_PWR_UP, POWER_UP);
795     dw_mipi_dsi2_set_cmd_mode(dsi2);
796 
797     if (dsi2->slave) {
798         dw_mipi_dsi2_pre_enable(dsi2->slave);
799     }
800 }
801 
dw_mipi_dsi2_enable(struct dw_mipi_dsi2 * dsi2)802 static void dw_mipi_dsi2_enable(struct dw_mipi_dsi2 *dsi2)
803 {
804     dw_mipi_dsi2_ipi_set(dsi2);
805 
806     if (dsi2->mode_flags & MIPI_DSI_MODE_VIDEO) {
807         dw_mipi_dsi2_set_vid_mode(dsi2);
808     } else {
809         dw_mipi_dsi2_set_data_stream_mode(dsi2);
810     }
811 
812     if (dsi2->slave) {
813         dw_mipi_dsi2_enable(dsi2->slave);
814     }
815 }
816 
dw_mipi_dsi2_encoder_enable(struct drm_encoder * encoder)817 static void dw_mipi_dsi2_encoder_enable(struct drm_encoder *encoder)
818 {
819     struct dw_mipi_dsi2 *dsi2 = encoder_to_dsi2(encoder);
820 
821     if (dsi2->dcphy) {
822         dw_mipi_dsi2_set_lane_rate(dsi2);
823     }
824 
825     if (dsi2->slave && dsi2->slave->dcphy) {
826         dw_mipi_dsi2_set_lane_rate(dsi2->slave);
827     }
828 
829     dw_mipi_dsi2_pre_enable(dsi2);
830 
831     if (dsi2->panel) {
832         drm_panel_prepare(dsi2->panel);
833     }
834 
835     dw_mipi_dsi2_enable(dsi2);
836 
837     if (dsi2->panel) {
838         drm_panel_enable(dsi2->panel);
839     }
840 
841     DRM_DEV_INFO(dsi2->dev, "final DSI-Link bandwidth: %u x %d %s\n", dsi2->lane_hs_rate,
842                  dsi2->slave ? dsi2->lanes * 0x2 : dsi2->lanes, dsi2->c_option ? "Msps" : "Mbps");
843 }
844 
dw_mipi_dsi2_encoder_atomic_check(struct drm_encoder * encoder,struct drm_crtc_state * crtc_state,struct drm_connector_state * conn_state)845 static int dw_mipi_dsi2_encoder_atomic_check(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state,
846                                              struct drm_connector_state *conn_state)
847 {
848     struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state);
849     struct dw_mipi_dsi2 *dsi2 = encoder_to_dsi2(encoder);
850     struct drm_connector *connector = conn_state->connector;
851     struct drm_display_info *info = &connector->display_info;
852 
853     switch (dsi2->format) {
854         case MIPI_DSI_FMT_RGB888:
855             s->output_mode = ROCKCHIP_OUT_MODE_P888;
856             break;
857         case MIPI_DSI_FMT_RGB666:
858             s->output_mode = ROCKCHIP_OUT_MODE_P666;
859             break;
860         case MIPI_DSI_FMT_RGB565:
861             s->output_mode = ROCKCHIP_OUT_MODE_P565;
862             break;
863         default:
864             WARN_ON(1);
865             return -EINVAL;
866     }
867 
868     if (info->num_bus_formats) {
869         s->bus_format = info->bus_formats[0];
870     } else {
871         s->bus_format = MEDIA_BUS_FMT_RGB888_1X24;
872     }
873 
874     s->output_type = DRM_MODE_CONNECTOR_DSI;
875     s->output_if = dsi2->id ? VOP_OUTPUT_IF_MIPI1 : VOP_OUTPUT_IF_MIPI0;
876     s->bus_flags = info->bus_flags;
877 
878     s->tv_state = &conn_state->tv;
879     s->color_space = V4L2_COLORSPACE_DEFAULT;
880 
881     if (!(dsi2->mode_flags & MIPI_DSI_MODE_VIDEO)) {
882         s->output_flags |= ROCKCHIP_OUTPUT_MIPI_DS_MODE;
883         s->hold_mode = true;
884     }
885 
886     if (dsi2->slave) {
887         s->output_flags |= ROCKCHIP_OUTPUT_DUAL_CHANNEL_LEFT_RIGHT_MODE;
888         if (dsi2->data_swap) {
889             s->output_flags |= ROCKCHIP_OUTPUT_DATA_SWAP;
890         }
891 
892         s->output_if |= VOP_OUTPUT_IF_MIPI1;
893     }
894 
895     if (dsi2->dsc_enable) {
896         s->dsc_enable = 1;
897         s->dsc_sink_cap.version_major = dsi2->version_major;
898         s->dsc_sink_cap.version_minor = dsi2->version_minor;
899         s->dsc_sink_cap.slice_width = dsi2->slice_width;
900         s->dsc_sink_cap.slice_height = dsi2->slice_height;
901         /* only can support rgb888 panel now */
902         s->dsc_sink_cap.target_bits_per_pixel_x16 = 0x8 << 0x4;
903         s->dsc_sink_cap.native_420 = 0;
904 
905         memcpy(&s->pps, dsi2->pps, sizeof(struct drm_dsc_picture_parameter_set));
906     }
907 
908     return 0;
909 }
910 
dw_mipi_dsi2_encoder_atomic_mode_set(struct drm_encoder * encoder,struct drm_crtc_state * crtc_state,struct drm_connector_state * connector_state)911 static void dw_mipi_dsi2_encoder_atomic_mode_set(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state,
912                                                  struct drm_connector_state *connector_state)
913 {
914     struct dw_mipi_dsi2 *dsi2 = encoder_to_dsi2(encoder);
915 
916     drm_mode_copy(&dsi2->mode, &crtc_state->adjusted_mode);
917     if (dsi2->slave) {
918         drm_mode_copy(&dsi2->slave->mode, &crtc_state->adjusted_mode);
919     }
920 }
921 
dw_mipi_dsi2_loader_protect(struct dw_mipi_dsi2 * dsi2,bool on)922 static void dw_mipi_dsi2_loader_protect(struct dw_mipi_dsi2 *dsi2, bool on)
923 {
924     if (on) {
925         pm_runtime_get_sync(dsi2->dev);
926         phy_init(dsi2->dcphy);
927         dsi2->phy_enabled = true;
928         if (dsi2->dcphy) {
929             dsi2->dcphy->power_count++;
930         }
931     } else {
932         pm_runtime_put(dsi2->dev);
933         phy_exit(dsi2->dcphy);
934         dsi2->phy_enabled = false;
935         if (dsi2->dcphy) {
936             dsi2->dcphy->power_count--;
937         }
938     }
939 
940     if (dsi2->slave) {
941         dw_mipi_dsi2_loader_protect(dsi2->slave, on);
942     }
943 }
944 
dw_mipi_dsi2_encoder_loader_protect(struct drm_encoder * encoder,bool on)945 static void dw_mipi_dsi2_encoder_loader_protect(struct drm_encoder *encoder, bool on)
946 {
947     struct dw_mipi_dsi2 *dsi2 = encoder_to_dsi2(encoder);
948 
949     if (dsi2->panel) {
950         panel_simple_loader_protect(dsi2->panel);
951     }
952 
953     dw_mipi_dsi2_loader_protect(dsi2, on);
954 }
955 
956 static const struct drm_encoder_helper_funcs dw_mipi_dsi2_encoder_helper_funcs = {
957     .enable = dw_mipi_dsi2_encoder_enable,
958     .disable = dw_mipi_dsi2_encoder_disable,
959     .atomic_check = dw_mipi_dsi2_encoder_atomic_check,
960     .atomic_mode_set = dw_mipi_dsi2_encoder_atomic_mode_set,
961 };
962 
dw_mipi_dsi2_connector_get_modes(struct drm_connector * connector)963 static int dw_mipi_dsi2_connector_get_modes(struct drm_connector *connector)
964 {
965     struct dw_mipi_dsi2 *dsi2 = con_to_dsi2(connector);
966 
967     return drm_panel_get_modes(dsi2->panel, connector);
968 }
969 
dw_mipi_dsi2_connector_mode_valid(struct drm_connector * connector,struct drm_display_mode * mode)970 static int dw_mipi_dsi2_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode)
971 {
972     struct videomode vm;
973 
974     drm_display_mode_to_videomode(mode, &vm);
975 
976     /*
977      * the minimum region size (HSA,HBP,HACT,HFP) is 4 pixels
978      * which is the ip known issues and limitations.
979      */
980     if (!(vm.hsync_len < 0x4 || vm.hback_porch < 0x4 || vm.hfront_porch < 0x4 || vm.hactive < 0x4)) {
981         return MODE_OK;
982     }
983 
984     if (vm.hsync_len < 0x4) {
985         vm.hsync_len = 0x4;
986     }
987 
988     if (vm.hback_porch < 0x4) {
989         vm.hback_porch = 0x4;
990     }
991 
992     if (vm.hfront_porch < 0x4) {
993         vm.hfront_porch = 0x4;
994     }
995 
996     if (vm.hactive < 0x4) {
997         vm.hactive = 0x4;
998     }
999 
1000     drm_display_mode_from_videomode(&vm, mode);
1001 
1002     return MODE_OK;
1003 }
1004 
1005 static struct drm_connector_helper_funcs dw_mipi_dsi2_connector_helper_funcs = {
1006     .get_modes = dw_mipi_dsi2_connector_get_modes,
1007     .mode_valid = dw_mipi_dsi2_connector_mode_valid,
1008 };
1009 
dw_mipi_dsi2_drm_connector_destroy(struct drm_connector * connector)1010 static void dw_mipi_dsi2_drm_connector_destroy(struct drm_connector *connector)
1011 {
1012     drm_connector_unregister(connector);
1013     drm_connector_cleanup(connector);
1014 }
1015 
1016 static const struct drm_connector_funcs dw_mipi_dsi2_atomic_connector_funcs = {
1017     .fill_modes = drm_helper_probe_single_connector_modes,
1018     .destroy = dw_mipi_dsi2_drm_connector_destroy,
1019     .reset = drm_atomic_helper_connector_reset,
1020     .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
1021     .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
1022 };
1023 
dw_mipi_dsi2_dual_channel_probe(struct dw_mipi_dsi2 * dsi2)1024 static int dw_mipi_dsi2_dual_channel_probe(struct dw_mipi_dsi2 *dsi2)
1025 {
1026     struct device_node *np;
1027     struct platform_device *secondary;
1028 
1029     np = of_parse_phandle(dsi2->dev->of_node, "rockchip,dual-channel", 0);
1030     if (np) {
1031         dsi2->data_swap = of_property_read_bool(dsi2->dev->of_node, "rockchip,data-swap");
1032         secondary = of_find_device_by_node(np);
1033         dsi2->slave = platform_get_drvdata(secondary);
1034         of_node_put(np);
1035 
1036         if (!dsi2->slave) {
1037             return -EPROBE_DEFER;
1038         }
1039 
1040         dsi2->slave->master = dsi2;
1041         dsi2->lanes /= 0x2;
1042 
1043         dsi2->slave->lanes = dsi2->lanes;
1044         dsi2->slave->channel = dsi2->channel;
1045         dsi2->slave->format = dsi2->format;
1046         dsi2->slave->mode_flags = dsi2->mode_flags;
1047     }
1048 
1049     return 0;
1050 }
1051 
dw_mipi_dsi2_te_irq_handler(int irq,void * dev_id)1052 static irqreturn_t dw_mipi_dsi2_te_irq_handler(int irq, void *dev_id)
1053 {
1054     struct dw_mipi_dsi2 *dsi2 = (struct dw_mipi_dsi2 *)dev_id;
1055     struct drm_encoder *encoder = &dsi2->encoder;
1056 
1057     rockchip_drm_te_handle(encoder->crtc);
1058 
1059     return IRQ_HANDLED;
1060 }
1061 
dw_mipi_dsi2_get_dsc_params_from_sink(struct dw_mipi_dsi2 * dsi2,struct drm_panel * panel,struct drm_bridge * bridge)1062 static int dw_mipi_dsi2_get_dsc_params_from_sink(struct dw_mipi_dsi2 *dsi2, struct drm_panel *panel,
1063                                                  struct drm_bridge *bridge)
1064 {
1065     struct drm_dsc_picture_parameter_set *pps = NULL;
1066     struct device_node *np = NULL;
1067     struct cmd_header *header;
1068     const void *data;
1069     char *d;
1070     uint8_t *dsc_packed_pps;
1071     int len;
1072 
1073     if (!panel && !bridge) {
1074         return -ENODEV;
1075     }
1076 
1077     if (panel) {
1078         np = panel->dev->of_node;
1079     } else {
1080         np = bridge->of_node;
1081     }
1082 
1083     dsi2->c_option = of_property_read_bool(np, "phy-c-option");
1084     dsi2->scrambling_en = of_property_read_bool(np, "scrambling-enable");
1085     dsi2->dsc_enable = of_property_read_bool(np, "compressed-data");
1086 
1087     if (dsi2->slave) {
1088         dsi2->slave->c_option = dsi2->c_option;
1089         dsi2->slave->scrambling_en = dsi2->scrambling_en;
1090         dsi2->slave->dsc_enable = dsi2->dsc_enable;
1091     }
1092 
1093     of_property_read_u32(np, "slice-width", &dsi2->slice_width);
1094     of_property_read_u32(np, "slice-height", &dsi2->slice_height);
1095     of_property_read_u8(np, "version-major", &dsi2->version_major);
1096     of_property_read_u8(np, "version-minor", &dsi2->version_minor);
1097 
1098     data = of_get_property(np, "panel-init-sequence", &len);
1099     if (!data) {
1100         return -EINVAL;
1101     }
1102 
1103     d = devm_kmemdup(dsi2->dev, data, len, GFP_KERNEL);
1104     if (!d) {
1105         return -ENOMEM;
1106     }
1107 
1108     while (len > sizeof(*header)) {
1109         header = (struct cmd_header *)d;
1110         d += sizeof(*header);
1111         len -= sizeof(*header);
1112 
1113         if (header->payload_length > len) {
1114             return -EINVAL;
1115         }
1116 
1117         if (header->cmd_type == MIPI_DSI_PICTURE_PARAMETER_SET) {
1118             dsc_packed_pps = devm_kmemdup(dsi2->dev, d, header->payload_length, GFP_KERNEL);
1119             if (!dsc_packed_pps) {
1120                 return -ENOMEM;
1121             }
1122 
1123             pps = (struct drm_dsc_picture_parameter_set *)dsc_packed_pps;
1124             break;
1125         }
1126 
1127         d += header->payload_length;
1128         len -= header->payload_length;
1129     }
1130 
1131     dsi2->pps = pps;
1132 
1133     return 0;
1134 }
1135 
dw_mipi_dsi2_bind(struct device * dev,struct device * master,void * data)1136 static int dw_mipi_dsi2_bind(struct device *dev, struct device *master, void *data)
1137 {
1138     struct dw_mipi_dsi2 *dsi2 = dev_get_drvdata(dev);
1139     struct drm_device *drm_dev = data;
1140     struct drm_encoder *encoder = &dsi2->encoder;
1141     struct drm_connector *connector = &dsi2->connector;
1142     struct device_node *of_node = dsi2->dev->of_node;
1143     int ret;
1144 
1145     ret = dw_mipi_dsi2_dual_channel_probe(dsi2);
1146     if (ret) {
1147         return ret;
1148     }
1149 
1150     if (dsi2->master) {
1151         return 0;
1152     }
1153 
1154     ret = drm_of_find_panel_or_bridge(dev->of_node, 1, -1, &dsi2->panel, &dsi2->bridge);
1155     if (ret) {
1156         DRM_DEV_ERROR(dev, "Failed to find panel or bridge: %d\n", ret);
1157         return ret;
1158     }
1159 
1160     dw_mipi_dsi2_get_dsc_params_from_sink(dsi2, dsi2->panel, dsi2->bridge);
1161     encoder->possible_crtcs = rockchip_drm_of_find_possible_crtcs(drm_dev, of_node);
1162 
1163     ret = drm_simple_encoder_init(drm_dev, encoder, DRM_MODE_ENCODER_DSI);
1164     if (ret) {
1165         DRM_ERROR("Failed to initialize encoder with drm\n");
1166         return ret;
1167     }
1168 
1169     drm_encoder_helper_add(encoder, &dw_mipi_dsi2_encoder_helper_funcs);
1170 
1171     if (dsi2->panel) {
1172         ret = drm_connector_init(drm_dev, connector, &dw_mipi_dsi2_atomic_connector_funcs, DRM_MODE_CONNECTOR_DSI);
1173         if (ret) {
1174             DRM_DEV_ERROR(dev, "Failed to initialize connector\n");
1175             goto encoder_cleanup;
1176         }
1177 
1178         drm_connector_helper_add(connector, &dw_mipi_dsi2_connector_helper_funcs);
1179         drm_connector_attach_encoder(connector, encoder);
1180         if (ret < 0) {
1181             DRM_DEV_ERROR(dev, "Failed to attach encoder: %d\n", ret);
1182             goto connector_cleanup;
1183         }
1184 
1185         dsi2->sub_dev.connector = &dsi2->connector;
1186         dsi2->sub_dev.of_node = dev->of_node;
1187         dsi2->sub_dev.loader_protect = dw_mipi_dsi2_encoder_loader_protect;
1188         rockchip_drm_register_sub_dev(&dsi2->sub_dev);
1189     } else {
1190         dsi2->bridge->driver_private = &dsi2->host;
1191         dsi2->bridge->encoder = encoder;
1192 
1193         ret = drm_bridge_attach(encoder, dsi2->bridge, NULL, 0);
1194         if (ret) {
1195             DRM_DEV_ERROR(dev, "Failed to attach bridge: %d\n", ret);
1196             goto encoder_cleanup;
1197         }
1198     }
1199 
1200     pm_runtime_enable(dsi2->dev);
1201     if (dsi2->slave) {
1202         pm_runtime_enable(dsi2->slave->dev);
1203     }
1204 
1205     return 0;
1206 
1207 connector_cleanup:
1208     connector->funcs->destroy(connector);
1209 encoder_cleanup:
1210     encoder->funcs->destroy(encoder);
1211 
1212     return ret;
1213 }
1214 
dw_mipi_dsi2_unbind(struct device * dev,struct device * master,void * data)1215 static void dw_mipi_dsi2_unbind(struct device *dev, struct device *master, void *data)
1216 {
1217     struct dw_mipi_dsi2 *dsi2 = dev_get_drvdata(dev);
1218 
1219     if (dsi2->sub_dev.connector) {
1220         rockchip_drm_unregister_sub_dev(&dsi2->sub_dev);
1221     }
1222 
1223     pm_runtime_disable(dsi2->dev);
1224     if (dsi2->slave) {
1225         pm_runtime_disable(dsi2->slave->dev);
1226     }
1227 
1228     dsi2->connector.funcs->destroy(&dsi2->connector);
1229     dsi2->encoder.funcs->destroy(&dsi2->encoder);
1230 }
1231 
1232 static const struct component_ops dw_mipi_dsi2_ops = {
1233     .bind = dw_mipi_dsi2_bind,
1234     .unbind = dw_mipi_dsi2_unbind,
1235 };
1236 
1237 struct dsi2_irq_data {
1238     u32 offeset;
1239     char *irq_src;
1240 };
1241 
1242 static const struct dsi2_irq_data dw_mipi_dsi2_irq_data[] = {
1243     {DSI2_INT_ST_PHY, "int_st_phy"}, {DSI2_INT_ST_TO, "int_st_to"},     {DSI2_INT_ST_ACK, "int_st_ack"},
1244     {DSI2_INT_ST_IPI, "int_st_ipi"}, {DSI2_INT_ST_FIFO, "int_st_fifo"}, {DSI2_INT_ST_PRI, "int_st_pri"},
1245     {DSI2_INT_ST_CRI, "int_st_cri"},
1246 };
1247 
dw_mipi_dsi2_irq_handler(int irq,void * dev_id)1248 static irqreturn_t dw_mipi_dsi2_irq_handler(int irq, void *dev_id)
1249 {
1250     struct dw_mipi_dsi2 *dsi2 = dev_id;
1251     u32 int_st;
1252     unsigned int i;
1253 
1254     regmap_read(dsi2->regmap, INT_ST_MAIN, &int_st);
1255 
1256     for (i = 0; i < ARRAY_SIZE(dw_mipi_dsi2_irq_data); i++) {
1257         if (int_st & BIT(i)) {
1258             DRM_DEV_DEBUG(dsi2->dev, "%s\n", dw_mipi_dsi2_irq_data[i].irq_src);
1259         }
1260     }
1261 
1262     return IRQ_HANDLED;
1263 }
1264 
1265 static const struct regmap_config dw_mipi_dsi2_regmap_config = {
1266     .name = "host",
1267     .reg_bits = 32,
1268     .val_bits = 32,
1269     .reg_stride = 4,
1270     .fast_io = true,
1271     .max_register = DSI2_MAX_REGISGER,
1272 };
1273 
dw_mipi_dsi2_host_attach(struct mipi_dsi_host * host,struct mipi_dsi_device * device)1274 static int dw_mipi_dsi2_host_attach(struct mipi_dsi_host *host, struct mipi_dsi_device *device)
1275 {
1276     struct dw_mipi_dsi2 *dsi2 = host_to_dsi2(host);
1277 
1278     if (dsi2->master) {
1279         return 0x0;
1280     }
1281 
1282     if (device->lanes < 0x1 || device->lanes > 0x8) {
1283         return -EINVAL;
1284     }
1285 
1286     dsi2->client = device->dev.of_node;
1287     dsi2->lanes = device->lanes;
1288     dsi2->channel = device->channel;
1289     dsi2->format = device->format;
1290     dsi2->mode_flags = device->mode_flags;
1291 
1292     return 0x0;
1293 }
1294 
dw_mipi_dsi2_host_detach(struct mipi_dsi_host * host,struct mipi_dsi_device * device)1295 static int dw_mipi_dsi2_host_detach(struct mipi_dsi_host *host, struct mipi_dsi_device *device)
1296 {
1297     return 0x0;
1298 }
1299 
dw_mipi_dsi2_read_from_fifo(struct dw_mipi_dsi2 * dsi2,const struct mipi_dsi_msg * msg)1300 static int dw_mipi_dsi2_read_from_fifo(struct dw_mipi_dsi2 *dsi2, const struct mipi_dsi_msg *msg)
1301 {
1302     u8 *payload = msg->rx_buf;
1303     u8 data_type;
1304     u16 wc;
1305     int i, j, ret, len = msg->rx_len;
1306     unsigned int vrefresh = drm_mode_vrefresh(&dsi2->mode);
1307     u32 val;
1308 
1309     ret = regmap_read_poll_timeout(dsi2->regmap, DSI2_CORE_STATUS, val, val & CRI_RD_DATA_AVAIL, 0,
1310                                    DIV_ROUND_UP(0xf4240, vrefresh));
1311     if (ret) {
1312         DRM_DEV_ERROR(dsi2->dev, "CRI has no available read data\n");
1313         return ret;
1314     }
1315 
1316     regmap_read(dsi2->regmap, DSI2_CRI_RX_HDR, &val);
1317     data_type = val & 0x3f;
1318 
1319     if (mipi_dsi_packet_format_is_short(data_type)) {
1320         for (i = 0; i < len && i < 0x2; i++) {
1321             payload[i] = (val >> (0x8 * (i + 1))) & 0xff;
1322         }
1323 
1324         return 0;
1325     }
1326 
1327     wc = (val >> 0x8) & 0xffff;
1328     /* Receive payload */
1329     for (i = 0; i < len && i < wc; i += 0x4) {
1330         regmap_read(dsi2->regmap, DSI2_CRI_RX_PLD, &val);
1331         for (j = 0; j < 0x4 && j + i < len && j + i < wc; j++) {
1332             payload[i + j] = val >> (0x8 * j);
1333         }
1334     }
1335 
1336     return 0;
1337 }
1338 
dw_mipi_dsi2_transfer(struct dw_mipi_dsi2 * dsi2,const struct mipi_dsi_msg * msg)1339 static ssize_t dw_mipi_dsi2_transfer(struct dw_mipi_dsi2 *dsi2, const struct mipi_dsi_msg *msg)
1340 {
1341     struct mipi_dsi_packet packet;
1342     int ret;
1343     u32 val;
1344     u32 mode;
1345 
1346     regmap_update_bits(dsi2->regmap, DSI2_DSI_VID_TX_CFG, LPDT_DISPLAY_CMD_EN,
1347                        msg->flags & MIPI_DSI_MSG_USE_LPM ? LPDT_DISPLAY_CMD_EN : 0);
1348 
1349     /* create a packet to the DSI protocol */
1350     ret = mipi_dsi_create_packet(&packet, msg);
1351     if (ret) {
1352         DRM_DEV_ERROR(dsi2->dev, "failed to create packet: %d\n", ret);
1353         return ret;
1354     }
1355 
1356     ret = cri_fifos_wait_avail(dsi2);
1357     if (ret) {
1358         return ret;
1359     }
1360 
1361     /* Send payload */
1362     while (DIV_ROUND_UP(packet.payload_length, 0x4)) {
1363         /* check cri interface is not busy */
1364         if (packet.payload_length < 0x4) {
1365             /* send residu payload */
1366             val = 0;
1367             memcpy(&val, packet.payload, packet.payload_length);
1368             regmap_write(dsi2->regmap, DSI2_CRI_TX_PLD, val);
1369             packet.payload_length = 0;
1370         } else {
1371             val = get_unaligned_le32(packet.payload);
1372             regmap_write(dsi2->regmap, DSI2_CRI_TX_PLD, val);
1373             packet.payload += 0x4;
1374             packet.payload_length -= 0x4;
1375         }
1376     }
1377 
1378     /* Send packet header */
1379     mode = CMD_TX_MODE(msg->flags & MIPI_DSI_MSG_USE_LPM ? 1 : 0);
1380     val = get_unaligned_le32(packet.header);
1381 
1382     regmap_write(dsi2->regmap, DSI2_CRI_TX_HDR, mode | val);
1383 
1384     ret = cri_fifos_wait_avail(dsi2);
1385     if (ret) {
1386         return ret;
1387     }
1388 
1389     if (msg->rx_len) {
1390         ret = dw_mipi_dsi2_read_from_fifo(dsi2, msg);
1391         if (ret < 0) {
1392             return ret;
1393         }
1394     }
1395 
1396     if (dsi2->slave) {
1397         dw_mipi_dsi2_transfer(dsi2->slave, msg);
1398     }
1399 
1400     return msg->tx_len;
1401 }
1402 
dw_mipi_dsi2_host_transfer(struct mipi_dsi_host * host,const struct mipi_dsi_msg * msg)1403 static ssize_t dw_mipi_dsi2_host_transfer(struct mipi_dsi_host *host, const struct mipi_dsi_msg *msg)
1404 {
1405     struct dw_mipi_dsi2 *dsi2 = host_to_dsi2(host);
1406 
1407     return dw_mipi_dsi2_transfer(dsi2, msg);
1408 }
1409 
1410 static const struct mipi_dsi_host_ops dw_mipi_dsi2_host_ops = {
1411     .attach = dw_mipi_dsi2_host_attach,
1412     .detach = dw_mipi_dsi2_host_detach,
1413     .transfer = dw_mipi_dsi2_host_transfer,
1414 };
1415 
dw_mipi_dsi2_probe(struct platform_device * pdev)1416 static int dw_mipi_dsi2_probe(struct platform_device *pdev)
1417 {
1418     struct device *dev = &pdev->dev;
1419     struct dw_mipi_dsi2 *dsi2;
1420     struct resource *res;
1421     void __iomem *regs;
1422     int id;
1423     int ret;
1424 
1425     dsi2 = devm_kzalloc(dev, sizeof(*dsi2), GFP_KERNEL);
1426     if (!dsi2) {
1427         return -ENOMEM;
1428     }
1429 
1430     id = of_alias_get_id(dev->of_node, "dsi");
1431     if (id < 0) {
1432         id = 0;
1433     }
1434 
1435     dsi2->dev = dev;
1436     dsi2->id = id;
1437     dsi2->pdata = of_device_get_match_data(dev);
1438     platform_set_drvdata(pdev, dsi2);
1439 
1440     res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1441     regs = devm_ioremap_resource(dev, res);
1442     if (IS_ERR(regs)) {
1443         return PTR_ERR(regs);
1444     }
1445 
1446     dsi2->irq = platform_get_irq(pdev, 0);
1447     if (dsi2->irq < 0) {
1448         return dsi2->irq;
1449     }
1450 
1451     dsi2->pclk = devm_clk_get(dev, "pclk");
1452     if (IS_ERR(dsi2->pclk)) {
1453         ret = PTR_ERR(dsi2->pclk);
1454         DRM_DEV_ERROR(dev, "Unable to get pclk: %d\n", ret);
1455         return ret;
1456     }
1457 
1458     dsi2->sys_clk = devm_clk_get(dev, "sys_clk");
1459     if (IS_ERR(dsi2->sys_clk)) {
1460         ret = PTR_ERR(dsi2->sys_clk);
1461         DRM_DEV_ERROR(dev, "Unable to get sys_clk: %d\n", ret);
1462         return ret;
1463     }
1464 
1465     dsi2->regmap = devm_regmap_init_mmio(dev, regs, &dw_mipi_dsi2_regmap_config);
1466     if (IS_ERR(dsi2->regmap)) {
1467         ret = PTR_ERR(dsi2->regmap);
1468         DRM_DEV_ERROR(dev, "failed to init register map: %d\n", ret);
1469         return ret;
1470     }
1471 
1472     dsi2->grf = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,grf");
1473     if (IS_ERR(dsi2->grf)) {
1474         ret = PTR_ERR(dsi2->grf);
1475         DRM_DEV_ERROR(dsi2->dev, "Unable to get grf: %d\n", ret);
1476         return ret;
1477     }
1478 
1479     dsi2->apb_rst = devm_reset_control_get(dev, "apb");
1480     if (IS_ERR(dsi2->apb_rst)) {
1481         ret = PTR_ERR(dsi2->apb_rst);
1482         DRM_DEV_ERROR(dev, "Unable to get reset control: %d\n", ret);
1483         return ret;
1484     }
1485 
1486     dsi2->dcphy = devm_phy_optional_get(dev, "dcphy");
1487     if (IS_ERR(dsi2->dcphy)) {
1488         ret = PTR_ERR(dsi2->dcphy);
1489         DRM_DEV_ERROR(dev, "failed to get mipi dcphy: %d\n", ret);
1490         return ret;
1491     }
1492 
1493     dsi2->te_gpio = devm_gpiod_get_optional(dsi2->dev, "te", GPIOD_IN);
1494     if (IS_ERR(dsi2->te_gpio)) {
1495         dsi2->te_gpio = NULL;
1496     }
1497 
1498     if (dsi2->te_gpio) {
1499         ret = devm_request_threaded_irq(dsi2->dev, gpiod_to_irq(dsi2->te_gpio), NULL, dw_mipi_dsi2_te_irq_handler,
1500                                         IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "PANEL-TE", dsi2);
1501         if (ret) {
1502             dev_err(dsi2->dev, "failed to request TE IRQ: %d\n", ret);
1503             return ret;
1504         }
1505     }
1506 
1507     ret = devm_request_irq(dev, dsi2->irq, dw_mipi_dsi2_irq_handler, IRQF_SHARED, dev_name(dev), dsi2);
1508     if (ret) {
1509         DRM_DEV_ERROR(dev, "failed to request irq: %d\n", ret);
1510         return ret;
1511     }
1512 
1513     dsi2->host.ops = &dw_mipi_dsi2_host_ops;
1514     dsi2->host.dev = dev;
1515     ret = mipi_dsi_host_register(&dsi2->host);
1516     if (ret) {
1517         DRM_DEV_ERROR(dev, "Failed to register MIPI host: %d\n", ret);
1518         return ret;
1519     }
1520 
1521     return component_add(&pdev->dev, &dw_mipi_dsi2_ops);
1522 }
1523 
dw_mipi_dsi2_remove(struct platform_device * pdev)1524 static int dw_mipi_dsi2_remove(struct platform_device *pdev)
1525 {
1526     return 0;
1527 }
1528 
dw_mipi_dsi2_runtime_suspend(struct device * dev)1529 static __maybe_unused int dw_mipi_dsi2_runtime_suspend(struct device *dev)
1530 {
1531     struct dw_mipi_dsi2 *dsi2 = dev_get_drvdata(dev);
1532 
1533     clk_disable_unprepare(dsi2->pclk);
1534     clk_disable_unprepare(dsi2->sys_clk);
1535 
1536     return 0;
1537 }
1538 
dw_mipi_dsi2_runtime_resume(struct device * dev)1539 static __maybe_unused int dw_mipi_dsi2_runtime_resume(struct device *dev)
1540 {
1541     struct dw_mipi_dsi2 *dsi2 = dev_get_drvdata(dev);
1542 
1543     clk_prepare_enable(dsi2->pclk);
1544     clk_prepare_enable(dsi2->sys_clk);
1545 
1546     return 0;
1547 }
1548 
1549 static const struct dev_pm_ops dw_mipi_dsi2_rockchip_pm_ops = {
1550     SET_RUNTIME_PM_OPS(dw_mipi_dsi2_runtime_suspend, dw_mipi_dsi2_runtime_resume, NULL)};
1551 
1552 static const u32 rk3588_dsi0_grf_reg_fields[MAX_FIELDS] = {
1553     [TXREQCLKHS_EN] = GRF_REG_FIELD(0x0000, 11, 11), [GATING_EN] = GRF_REG_FIELD(0x0000, 10, 10),
1554     [IPI_SHUTDN] = GRF_REG_FIELD(0x0000, 9, 9),      [IPI_COLORM] = GRF_REG_FIELD(0x0000, 8, 8),
1555     [IPI_COLOR_DEPTH] = GRF_REG_FIELD(0x0000, 4, 7), [IPI_FORMAT] = GRF_REG_FIELD(0x0000, 0, 3),
1556 };
1557 
1558 static const u32 rk3588_dsi1_grf_reg_fields[MAX_FIELDS] = {
1559     [TXREQCLKHS_EN] = GRF_REG_FIELD(0x0004, 11, 11), [GATING_EN] = GRF_REG_FIELD(0x0004, 10, 10),
1560     [IPI_SHUTDN] = GRF_REG_FIELD(0x0004, 9, 9),      [IPI_COLORM] = GRF_REG_FIELD(0x0004, 8, 8),
1561     [IPI_COLOR_DEPTH] = GRF_REG_FIELD(0x0004, 4, 7), [IPI_FORMAT] = GRF_REG_FIELD(0x0004, 0, 3),
1562 };
1563 
1564 static const struct dw_mipi_dsi2_plat_data rk3588_mipi_dsi2_plat_data = {
1565     .dsi0_grf_reg_fields = rk3588_dsi0_grf_reg_fields,
1566     .dsi1_grf_reg_fields = rk3588_dsi1_grf_reg_fields,
1567     .dphy_max_bit_rate_per_lane = 4500000000ULL,
1568     .cphy_max_symbol_rate_per_lane = 2000000000ULL,
1569 };
1570 
1571 static const struct of_device_id dw_mipi_dsi2_dt_ids[] = {
1572     {
1573         .compatible = "rockchip,rk3588-mipi-dsi2",
1574         .data = &rk3588_mipi_dsi2_plat_data,
1575     },
1576     {}
1577 };
1578 
1579 MODULE_DEVICE_TABLE(of, dw_mipi_dsi2_dt_ids);
1580 
1581 struct platform_driver dw_mipi_dsi2_rockchip_driver = {
1582     .probe = dw_mipi_dsi2_probe,
1583     .remove = dw_mipi_dsi2_remove,
1584     .driver =
1585         {
1586             .of_match_table = dw_mipi_dsi2_dt_ids,
1587             .pm = &dw_mipi_dsi2_rockchip_pm_ops,
1588             .name = "dw-mipi-dsi2",
1589         },
1590 };
1591