1 // SPDX-License-Identifier: GPL-2.0-only
3 * DesignWare MIPI DSI Host Controller v1.02 driver
5 * Copyright (c) 2016 Linaro Limited.
6 * Copyright (c) 2014-2016 Hisilicon Limited.
9 * Xinliang Liu <z.liuxinliang@hisilicon.com>
10 * Xinliang Liu <xinliang.liu@linaro.org>
11 * Xinwei Kong <kong.kongxinwei@hisilicon.com>
14 #include <linux/clk.h>
15 #include <linux/component.h>
16 #include <linux/delay.h>
17 #include <linux/module.h>
18 #include <linux/platform_device.h>
20 #include <drm/drm_atomic_helper.h>
21 #include <drm/drm_device.h>
22 #include <drm/drm_encoder_slave.h>
23 #include <drm/drm_mipi_dsi.h>
24 #include <drm/drm_of.h>
25 #include <drm/drm_print.h>
26 #include <drm/drm_probe_helper.h>
28 #include "dw_dsi_reg.h"
30 #define MAX_TX_ESC_CLK 10
31 #define ROUND(x, y) ((x) / (y) + \
32 ((x) % (y) * 10 / (y) >= 5 ? 1 : 0))
33 #define PHY_REF_CLK_RATE 19200000
34 #define PHY_REF_CLK_PERIOD_PS (1000000000 / (PHY_REF_CLK_RATE / 1000))
36 #define encoder_to_dsi(encoder) \
37 container_of(encoder, struct dw_dsi, encoder)
38 #define host_to_dsi(host) \
39 container_of(host, struct dw_dsi, host)
41 struct mipi_phy_params {
48 u32 data_t_hs_prepare;
70 u32 clk_to_data_delay;
71 u32 data_to_clk_delay;
72 u32 lane_byte_clk_kHz;
82 struct drm_encoder encoder;
83 struct drm_bridge *bridge;
84 struct mipi_dsi_host host;
85 struct drm_display_mode cur_mode;
86 struct dsi_hw_ctx *ctx;
87 struct mipi_phy_params phy;
90 enum mipi_dsi_pixel_format format;
91 unsigned long mode_flags;
97 struct dsi_hw_ctx ctx;
100 struct dsi_phy_range {
107 static const struct dsi_phy_range dphy_range_info[] = {
108 { 46875, 62500, 1, 7 },
109 { 62500, 93750, 0, 7 },
110 { 93750, 125000, 1, 6 },
111 { 125000, 187500, 0, 6 },
112 { 187500, 250000, 1, 5 },
113 { 250000, 375000, 0, 5 },
114 { 375000, 500000, 1, 4 },
115 { 500000, 750000, 0, 4 },
116 { 750000, 1000000, 1, 0 },
117 { 1000000, 1500000, 0, 0 }
120 static u32 dsi_calc_phy_rate(u32 req_kHz, struct mipi_phy_params *phy)
122 u32 ref_clk_ps = PHY_REF_CLK_PERIOD_PS;
123 u32 tmp_kHz = req_kHz;
135 * Find a rate >= req_kHz.
140 for (i = 0; i < ARRAY_SIZE(dphy_range_info); i++)
141 if (f_kHz >= dphy_range_info[i].min_range_kHz &&
142 f_kHz <= dphy_range_info[i].max_range_kHz)
145 if (i == ARRAY_SIZE(dphy_range_info)) {
146 DRM_ERROR("%dkHz out of range\n", f_kHz);
150 phy->pll_vco_750M = dphy_range_info[i].pll_vco_750M;
151 phy->hstx_ckg_sel = dphy_range_info[i].hstx_ckg_sel;
153 if (phy->hstx_ckg_sel <= 7 &&
154 phy->hstx_ckg_sel >= 4)
155 q_pll = 0x10 >> (7 - phy->hstx_ckg_sel);
157 temp = f_kHz * (u64)q_pll * (u64)ref_clk_ps;
158 m_n_int = temp / (u64)1000000000;
159 m_n = (temp % (u64)1000000000) / (u64)100000000;
161 if (m_n_int % 2 == 0) {
164 m_pll = (m_n_int + 1) * n_pll;
165 } else if (m_n * 6 >= 30) {
167 m_pll = m_n_int * n_pll + 2;
170 m_pll = m_n_int * n_pll;
175 m_pll = (m_n_int + 1) * n_pll;
176 } else if (m_n * 6 >= 30) {
178 m_pll = (m_n_int + 1) * n_pll;
179 } else if (m_n * 6 >= 10) {
181 m_pll = m_n_int * n_pll + 1;
184 m_pll = m_n_int * n_pll;
190 phy->pll_pre_div1p = 1;
192 phy->pll_fbd_p = n_pll;
193 phy->pll_pre_div1p = 0;
196 if (phy->pll_fbd_2p <= 7 && phy->pll_fbd_2p >= 4)
197 r_pll = 0x10 >> (7 - phy->pll_fbd_2p);
202 phy->pll_fbd_div1f = 0;
203 phy->pll_fbd_div5f = 1;
204 } else if (m_pll >= 2 * 2 * r_pll && m_pll <= 2 * 4 * r_pll) {
205 phy->pll_pre_p = m_pll / (2 * r_pll);
207 phy->pll_fbd_div1f = 1;
208 phy->pll_fbd_div5f = 0;
209 } else if (m_pll >= 2 * 5 * r_pll && m_pll <= 2 * 150 * r_pll) {
210 if (((m_pll / (2 * r_pll)) % 2) == 0) {
212 (m_pll / (2 * r_pll)) / 2 - 1;
214 (m_pll / (2 * r_pll)) % 2 + 2;
217 (m_pll / (2 * r_pll)) / 2;
219 (m_pll / (2 * r_pll)) % 2;
221 phy->pll_fbd_div1f = 0;
222 phy->pll_fbd_div5f = 0;
226 phy->pll_fbd_div1f = 0;
227 phy->pll_fbd_div5f = 1;
230 f_kHz = (u64)1000000000 * (u64)m_pll /
231 ((u64)ref_clk_ps * (u64)n_pll * (u64)q_pll);
233 if (f_kHz >= req_kHz)
243 static void dsi_get_phy_params(u32 phy_req_kHz,
244 struct mipi_phy_params *phy)
246 u32 ref_clk_ps = PHY_REF_CLK_PERIOD_PS;
250 memset(phy, 0, sizeof(*phy));
252 phy_rate_kHz = dsi_calc_phy_rate(phy_req_kHz, phy);
256 ui = 1000000 / phy_rate_kHz;
258 phy->clk_t_lpx = ROUND(50, 8 * ui);
259 phy->clk_t_hs_prepare = ROUND(133, 16 * ui) - 1;
261 phy->clk_t_hs_zero = ROUND(262, 8 * ui);
262 phy->clk_t_hs_trial = 2 * (ROUND(60, 8 * ui) - 1);
263 phy->clk_t_wakeup = ROUND(1000000, (ref_clk_ps / 1000) - 1);
264 if (phy->clk_t_wakeup > 0xff)
265 phy->clk_t_wakeup = 0xff;
266 phy->data_t_wakeup = phy->clk_t_wakeup;
267 phy->data_t_lpx = phy->clk_t_lpx;
268 phy->data_t_hs_prepare = ROUND(125 + 10 * ui, 16 * ui) - 1;
269 phy->data_t_hs_zero = ROUND(105 + 6 * ui, 8 * ui);
270 phy->data_t_hs_trial = 2 * (ROUND(60 + 4 * ui, 8 * ui) - 1);
271 phy->data_t_ta_go = 3;
272 phy->data_t_ta_get = 4;
275 phy->clklp2hs_time = ROUND(407, 8 * ui) + 12;
276 phy->clkhs2lp_time = ROUND(105 + 12 * ui, 8 * ui);
277 phy->lp2hs_time = ROUND(240 + 12 * ui, 8 * ui) + 1;
278 phy->hs2lp_time = phy->clkhs2lp_time;
279 phy->clk_to_data_delay = 1 + phy->clklp2hs_time;
280 phy->data_to_clk_delay = ROUND(60 + 52 * ui, 8 * ui) +
283 phy->lane_byte_clk_kHz = phy_rate_kHz / 8;
285 DIV_ROUND_UP(phy->lane_byte_clk_kHz, MAX_TX_ESC_CLK);
288 static u32 dsi_get_dpi_color_coding(enum mipi_dsi_pixel_format format)
293 * TODO: only support RGB888 now, to support more
296 case MIPI_DSI_FMT_RGB888:
308 * dsi phy reg write function
310 static void dsi_phy_tst_set(void __iomem *base, u32 reg, u32 val)
312 u32 reg_write = 0x10000 + reg;
317 writel(reg_write, base + PHY_TST_CTRL1);
318 writel(0x02, base + PHY_TST_CTRL0);
319 writel(0x00, base + PHY_TST_CTRL0);
324 writel(val, base + PHY_TST_CTRL1);
325 writel(0x02, base + PHY_TST_CTRL0);
326 writel(0x00, base + PHY_TST_CTRL0);
329 static void dsi_set_phy_timer(void __iomem *base,
330 struct mipi_phy_params *phy,
336 * Set lane value and phy stop wait time.
338 val = (lanes - 1) | (PHY_STOP_WAIT_TIME << 8);
339 writel(val, base + PHY_IF_CFG);
342 * Set phy clk division.
344 val = readl(base + CLKMGR_CFG) | phy->clk_division;
345 writel(val, base + CLKMGR_CFG);
348 * Set lp and hs switching params.
350 dw_update_bits(base + PHY_TMR_CFG, 24, MASK(8), phy->hs2lp_time);
351 dw_update_bits(base + PHY_TMR_CFG, 16, MASK(8), phy->lp2hs_time);
352 dw_update_bits(base + PHY_TMR_LPCLK_CFG, 16, MASK(10),
354 dw_update_bits(base + PHY_TMR_LPCLK_CFG, 0, MASK(10),
356 dw_update_bits(base + CLK_DATA_TMR_CFG, 8, MASK(8),
357 phy->data_to_clk_delay);
358 dw_update_bits(base + CLK_DATA_TMR_CFG, 0, MASK(8),
359 phy->clk_to_data_delay);
362 static void dsi_set_mipi_phy(void __iomem *base,
363 struct mipi_phy_params *phy,
370 /* phy timer setting */
371 dsi_set_phy_timer(base, phy, lanes);
374 * Reset to clean up phy tst params.
376 writel(0, base + PHY_RSTZ);
377 writel(0, base + PHY_TST_CTRL0);
378 writel(1, base + PHY_TST_CTRL0);
379 writel(0, base + PHY_TST_CTRL0);
382 * Clock lane timing control setting: TLPX, THS-PREPARE,
383 * THS-ZERO, THS-TRAIL, TWAKEUP.
385 dsi_phy_tst_set(base, CLK_TLPX, phy->clk_t_lpx);
386 dsi_phy_tst_set(base, CLK_THS_PREPARE, phy->clk_t_hs_prepare);
387 dsi_phy_tst_set(base, CLK_THS_ZERO, phy->clk_t_hs_zero);
388 dsi_phy_tst_set(base, CLK_THS_TRAIL, phy->clk_t_hs_trial);
389 dsi_phy_tst_set(base, CLK_TWAKEUP, phy->clk_t_wakeup);
392 * Data lane timing control setting: TLPX, THS-PREPARE,
393 * THS-ZERO, THS-TRAIL, TTA-GO, TTA-GET, TWAKEUP.
395 for (i = 0; i < lanes; i++) {
396 dsi_phy_tst_set(base, DATA_TLPX(i), phy->data_t_lpx);
397 dsi_phy_tst_set(base, DATA_THS_PREPARE(i),
398 phy->data_t_hs_prepare);
399 dsi_phy_tst_set(base, DATA_THS_ZERO(i), phy->data_t_hs_zero);
400 dsi_phy_tst_set(base, DATA_THS_TRAIL(i), phy->data_t_hs_trial);
401 dsi_phy_tst_set(base, DATA_TTA_GO(i), phy->data_t_ta_go);
402 dsi_phy_tst_set(base, DATA_TTA_GET(i), phy->data_t_ta_get);
403 dsi_phy_tst_set(base, DATA_TWAKEUP(i), phy->data_t_wakeup);
407 * physical configuration: I, pll I, pll II, pll III,
410 dsi_phy_tst_set(base, PHY_CFG_I, phy->hstx_ckg_sel);
411 val = (phy->pll_fbd_div5f << 5) + (phy->pll_fbd_div1f << 4) +
412 (phy->pll_fbd_2p << 1) + phy->pll_enbwt;
413 dsi_phy_tst_set(base, PHY_CFG_PLL_I, val);
414 dsi_phy_tst_set(base, PHY_CFG_PLL_II, phy->pll_fbd_p);
415 dsi_phy_tst_set(base, PHY_CFG_PLL_III, phy->pll_fbd_s);
416 val = (phy->pll_pre_div1p << 7) + phy->pll_pre_p;
417 dsi_phy_tst_set(base, PHY_CFG_PLL_IV, val);
418 val = (5 << 5) + (phy->pll_vco_750M << 4) + (phy->pll_lpf_rs << 2) +
420 dsi_phy_tst_set(base, PHY_CFG_PLL_V, val);
422 writel(PHY_ENABLECLK, base + PHY_RSTZ);
424 writel(PHY_ENABLECLK | PHY_UNSHUTDOWNZ, base + PHY_RSTZ);
426 writel(PHY_ENABLECLK | PHY_UNRSTZ | PHY_UNSHUTDOWNZ, base + PHY_RSTZ);
427 usleep_range(1000, 1500);
430 * wait for phy's clock ready
433 while (delay_count) {
434 val = readl(base + PHY_STATUS);
435 if ((BIT(0) | BIT(2)) & val)
443 DRM_INFO("phylock and phystopstateclklane is not ready.\n");
446 static void dsi_set_mode_timing(void __iomem *base,
447 u32 lane_byte_clk_kHz,
448 struct drm_display_mode *mode,
449 enum mipi_dsi_pixel_format format)
451 u32 hfp, hbp, hsw, vfp, vbp, vsw;
460 val = dsi_get_dpi_color_coding(format);
461 writel(val, base + DPI_COLOR_CODING);
463 val = (mode->flags & DRM_MODE_FLAG_NHSYNC ? 1 : 0) << 2;
464 val |= (mode->flags & DRM_MODE_FLAG_NVSYNC ? 1 : 0) << 1;
465 writel(val, base + DPI_CFG_POL);
468 * The DSI IP accepts vertical timing using lines as normal,
469 * but horizontal timing is a mixture of pixel-clocks for the
470 * active region and byte-lane clocks for the blanking-related
471 * timings. hfp is specified as the total hline_time in byte-
472 * lane clocks minus hsa, hbp and active.
474 pixel_clk_kHz = mode->clock;
477 hfp = mode->hsync_start - mode->hdisplay;
478 hbp = mode->htotal - mode->hsync_end;
479 hsw = mode->hsync_end - mode->hsync_start;
480 vfp = mode->vsync_start - mode->vdisplay;
481 vbp = mode->vtotal - mode->vsync_end;
482 vsw = mode->vsync_end - mode->vsync_start;
484 DRM_DEBUG_DRIVER("vsw exceeded 15\n");
488 hsa_time = (hsw * lane_byte_clk_kHz) / pixel_clk_kHz;
489 hbp_time = (hbp * lane_byte_clk_kHz) / pixel_clk_kHz;
490 tmp = (u64)htot * (u64)lane_byte_clk_kHz;
491 hline_time = DIV_ROUND_UP(tmp, pixel_clk_kHz);
493 /* all specified in byte-lane clocks */
494 writel(hsa_time, base + VID_HSA_TIME);
495 writel(hbp_time, base + VID_HBP_TIME);
496 writel(hline_time, base + VID_HLINE_TIME);
498 writel(vsw, base + VID_VSA_LINES);
499 writel(vbp, base + VID_VBP_LINES);
500 writel(vfp, base + VID_VFP_LINES);
501 writel(mode->vdisplay, base + VID_VACTIVE_LINES);
502 writel(mode->hdisplay, base + VID_PKT_SIZE);
504 DRM_DEBUG_DRIVER("htot=%d, hfp=%d, hbp=%d, hsw=%d\n",
505 htot, hfp, hbp, hsw);
506 DRM_DEBUG_DRIVER("vtol=%d, vfp=%d, vbp=%d, vsw=%d\n",
507 vtot, vfp, vbp, vsw);
508 DRM_DEBUG_DRIVER("hsa_time=%d, hbp_time=%d, hline_time=%d\n",
509 hsa_time, hbp_time, hline_time);
512 static void dsi_set_video_mode(void __iomem *base, unsigned long flags)
515 u32 mode_mask = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
516 MIPI_DSI_MODE_VIDEO_SYNC_PULSE;
517 u32 non_burst_sync_pulse = MIPI_DSI_MODE_VIDEO |
518 MIPI_DSI_MODE_VIDEO_SYNC_PULSE;
519 u32 non_burst_sync_event = MIPI_DSI_MODE_VIDEO;
522 * choose video mode type
524 if ((flags & mode_mask) == non_burst_sync_pulse)
525 val = DSI_NON_BURST_SYNC_PULSES;
526 else if ((flags & mode_mask) == non_burst_sync_event)
527 val = DSI_NON_BURST_SYNC_EVENTS;
529 val = DSI_BURST_SYNC_PULSES_1;
530 writel(val, base + VID_MODE_CFG);
532 writel(PHY_TXREQUESTCLKHS, base + LPCLK_CTRL);
533 writel(DSI_VIDEO_MODE, base + MODE_CFG);
536 static void dsi_mipi_init(struct dw_dsi *dsi)
538 struct dsi_hw_ctx *ctx = dsi->ctx;
539 struct mipi_phy_params *phy = &dsi->phy;
540 struct drm_display_mode *mode = &dsi->cur_mode;
541 u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format);
542 void __iomem *base = ctx->base;
548 dphy_req_kHz = mode->clock * bpp / dsi->lanes;
549 dsi_get_phy_params(dphy_req_kHz, phy);
552 writel(RESET, base + PWR_UP);
554 /* set dsi phy params */
555 dsi_set_mipi_phy(base, phy, dsi->lanes);
557 /* set dsi mode timing */
558 dsi_set_mode_timing(base, phy->lane_byte_clk_kHz, mode, dsi->format);
560 /* set dsi video mode */
561 dsi_set_video_mode(base, dsi->mode_flags);
564 writel(POWERUP, base + PWR_UP);
566 DRM_DEBUG_DRIVER("lanes=%d, pixel_clk=%d kHz, bytes_freq=%d kHz\n",
567 dsi->lanes, mode->clock, phy->lane_byte_clk_kHz);
570 static void dsi_encoder_disable(struct drm_encoder *encoder)
572 struct dw_dsi *dsi = encoder_to_dsi(encoder);
573 struct dsi_hw_ctx *ctx = dsi->ctx;
574 void __iomem *base = ctx->base;
579 writel(0, base + PWR_UP);
580 writel(0, base + LPCLK_CTRL);
581 writel(0, base + PHY_RSTZ);
582 clk_disable_unprepare(ctx->pclk);
587 static void dsi_encoder_enable(struct drm_encoder *encoder)
589 struct dw_dsi *dsi = encoder_to_dsi(encoder);
590 struct dsi_hw_ctx *ctx = dsi->ctx;
596 ret = clk_prepare_enable(ctx->pclk);
598 DRM_ERROR("fail to enable pclk: %d\n", ret);
607 static enum drm_mode_status dsi_encoder_phy_mode_valid(
608 struct drm_encoder *encoder,
609 const struct drm_display_mode *mode)
611 struct dw_dsi *dsi = encoder_to_dsi(encoder);
612 struct mipi_phy_params phy;
613 u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format);
614 u32 req_kHz, act_kHz, lane_byte_clk_kHz;
616 /* Calculate the lane byte clk using the adjusted mode clk */
617 memset(&phy, 0, sizeof(phy));
618 req_kHz = mode->clock * bpp / dsi->lanes;
619 act_kHz = dsi_calc_phy_rate(req_kHz, &phy);
620 lane_byte_clk_kHz = act_kHz / 8;
622 DRM_DEBUG_DRIVER("Checking mode %ix%i-%i@%i clock: %i...",
623 mode->hdisplay, mode->vdisplay, bpp,
624 drm_mode_vrefresh(mode), mode->clock);
627 * Make sure the adjusted mode clock and the lane byte clk
628 * have a common denominator base frequency
630 if (mode->clock/dsi->lanes == lane_byte_clk_kHz/3) {
631 DRM_DEBUG_DRIVER("OK!\n");
635 DRM_DEBUG_DRIVER("BAD!\n");
639 static enum drm_mode_status dsi_encoder_mode_valid(struct drm_encoder *encoder,
640 const struct drm_display_mode *mode)
643 const struct drm_crtc_helper_funcs *crtc_funcs = NULL;
644 struct drm_crtc *crtc = NULL;
645 struct drm_display_mode adj_mode;
646 enum drm_mode_status ret;
649 * The crtc might adjust the mode, so go through the
650 * possible crtcs (technically just one) and call
651 * mode_fixup to figure out the adjusted mode before we
654 drm_for_each_crtc(crtc, encoder->dev) {
656 * reset adj_mode to the mode value each time,
657 * so we don't adjust the mode twice
659 drm_mode_copy(&adj_mode, mode);
661 crtc_funcs = crtc->helper_private;
662 if (crtc_funcs && crtc_funcs->mode_fixup)
663 if (!crtc_funcs->mode_fixup(crtc, mode, &adj_mode))
666 ret = dsi_encoder_phy_mode_valid(encoder, &adj_mode);
673 static void dsi_encoder_mode_set(struct drm_encoder *encoder,
674 struct drm_display_mode *mode,
675 struct drm_display_mode *adj_mode)
677 struct dw_dsi *dsi = encoder_to_dsi(encoder);
679 drm_mode_copy(&dsi->cur_mode, adj_mode);
682 static int dsi_encoder_atomic_check(struct drm_encoder *encoder,
683 struct drm_crtc_state *crtc_state,
684 struct drm_connector_state *conn_state)
690 static const struct drm_encoder_helper_funcs dw_encoder_helper_funcs = {
691 .atomic_check = dsi_encoder_atomic_check,
692 .mode_valid = dsi_encoder_mode_valid,
693 .mode_set = dsi_encoder_mode_set,
694 .enable = dsi_encoder_enable,
695 .disable = dsi_encoder_disable
698 static const struct drm_encoder_funcs dw_encoder_funcs = {
699 .destroy = drm_encoder_cleanup,
702 static int dw_drm_encoder_init(struct device *dev,
703 struct drm_device *drm_dev,
704 struct drm_encoder *encoder)
707 u32 crtc_mask = drm_of_find_possible_crtcs(drm_dev, dev->of_node);
710 DRM_ERROR("failed to find crtc mask\n");
714 encoder->possible_crtcs = crtc_mask;
715 ret = drm_encoder_init(drm_dev, encoder, &dw_encoder_funcs,
716 DRM_MODE_ENCODER_DSI, NULL);
718 DRM_ERROR("failed to init dsi encoder\n");
722 drm_encoder_helper_add(encoder, &dw_encoder_helper_funcs);
727 static int dsi_host_attach(struct mipi_dsi_host *host,
728 struct mipi_dsi_device *mdsi)
730 struct dw_dsi *dsi = host_to_dsi(host);
732 if (mdsi->lanes < 1 || mdsi->lanes > 4) {
733 DRM_ERROR("dsi device params invalid\n");
737 dsi->lanes = mdsi->lanes;
738 dsi->format = mdsi->format;
739 dsi->mode_flags = mdsi->mode_flags;
744 static int dsi_host_detach(struct mipi_dsi_host *host,
745 struct mipi_dsi_device *mdsi)
751 static const struct mipi_dsi_host_ops dsi_host_ops = {
752 .attach = dsi_host_attach,
753 .detach = dsi_host_detach,
756 static int dsi_host_init(struct device *dev, struct dw_dsi *dsi)
758 struct mipi_dsi_host *host = &dsi->host;
762 host->ops = &dsi_host_ops;
763 ret = mipi_dsi_host_register(host);
765 DRM_ERROR("failed to register dsi host\n");
772 static int dsi_bridge_init(struct drm_device *dev, struct dw_dsi *dsi)
774 struct drm_encoder *encoder = &dsi->encoder;
775 struct drm_bridge *bridge = dsi->bridge;
778 /* associate the bridge to dsi encoder */
779 ret = drm_bridge_attach(encoder, bridge, NULL);
781 DRM_ERROR("failed to attach external bridge\n");
788 static int dsi_bind(struct device *dev, struct device *master, void *data)
790 struct dsi_data *ddata = dev_get_drvdata(dev);
791 struct dw_dsi *dsi = &ddata->dsi;
792 struct drm_device *drm_dev = data;
795 ret = dw_drm_encoder_init(dev, drm_dev, &dsi->encoder);
799 ret = dsi_host_init(dev, dsi);
803 ret = dsi_bridge_init(drm_dev, dsi);
810 static void dsi_unbind(struct device *dev, struct device *master, void *data)
815 static const struct component_ops dsi_ops = {
817 .unbind = dsi_unbind,
820 static int dsi_parse_dt(struct platform_device *pdev, struct dw_dsi *dsi)
822 struct dsi_hw_ctx *ctx = dsi->ctx;
823 struct device_node *np = pdev->dev.of_node;
824 struct resource *res;
828 * Get the endpoint node. In our case, dsi has one output port1
829 * to which the external HDMI bridge is connected.
831 ret = drm_of_find_panel_or_bridge(np, 1, 0, NULL, &dsi->bridge);
835 ctx->pclk = devm_clk_get(&pdev->dev, "pclk");
836 if (IS_ERR(ctx->pclk)) {
837 DRM_ERROR("failed to get pclk clock\n");
838 return PTR_ERR(ctx->pclk);
841 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
842 ctx->base = devm_ioremap_resource(&pdev->dev, res);
843 if (IS_ERR(ctx->base)) {
844 DRM_ERROR("failed to remap dsi io region\n");
845 return PTR_ERR(ctx->base);
851 static int dsi_probe(struct platform_device *pdev)
853 struct dsi_data *data;
855 struct dsi_hw_ctx *ctx;
858 data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
860 DRM_ERROR("failed to allocate dsi data.\n");
867 ret = dsi_parse_dt(pdev, dsi);
871 platform_set_drvdata(pdev, data);
873 return component_add(&pdev->dev, &dsi_ops);
876 static int dsi_remove(struct platform_device *pdev)
878 component_del(&pdev->dev, &dsi_ops);
883 static const struct of_device_id dsi_of_match[] = {
884 {.compatible = "hisilicon,hi6220-dsi"},
887 MODULE_DEVICE_TABLE(of, dsi_of_match);
889 static struct platform_driver dsi_driver = {
891 .remove = dsi_remove,
894 .of_match_table = dsi_of_match,
898 module_platform_driver(dsi_driver);
900 MODULE_AUTHOR("Xinliang Liu <xinliang.liu@linaro.org>");
901 MODULE_AUTHOR("Xinliang Liu <z.liuxinliang@hisilicon.com>");
902 MODULE_AUTHOR("Xinwei Kong <kong.kongxinwei@hisilicon.com>");
903 MODULE_DESCRIPTION("DesignWare MIPI DSI Host Controller v1.02 driver");
904 MODULE_LICENSE("GPL v2");