Lines Matching +full:dsi +full:- +full:based

1 // SPDX-License-Identifier: GPL-2.0+
7 * This generic Synopsys DesignWare MIPI DSI host driver is based on the
8 * Rockchip version from rockchip/dw-mipi-dsi.c with phy & bridge APIs.
193 #define N_LANES(n) (((n) - 1) & 0x3)
226 #define VPG_DEFS(name, dsi) \ argument
227 ((void __force *)&((*dsi).vpg_defs.name))
229 #define REGISTER(name, mask, dsi) \ argument
230 { #name, VPG_DEFS(name, dsi), mask, dsi }
236 struct dw_mipi_dsi *dsi; member
265 struct dw_mipi_dsi *master; /* dual-dsi master ptr */
266 struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */
275 static inline bool dw_mipi_is_dual_mode(struct dw_mipi_dsi *dsi) in dw_mipi_is_dual_mode() argument
277 return dsi->slave || dsi->master; in dw_mipi_is_dual_mode()
303 static inline void dsi_write(struct dw_mipi_dsi *dsi, u32 reg, u32 val) in dsi_write() argument
305 writel(val, dsi->base + reg); in dsi_write()
308 static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg) in dsi_read() argument
310 return readl(dsi->base + reg); in dsi_read()
316 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_attach() local
317 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_attach()
321 if (device->lanes > dsi->plat_data->max_data_lanes) { in dw_mipi_dsi_host_attach()
322 dev_err(dsi->dev, "the number of data lanes(%u) is too many\n", in dw_mipi_dsi_host_attach()
323 device->lanes); in dw_mipi_dsi_host_attach()
324 return -EINVAL; in dw_mipi_dsi_host_attach()
327 dsi->lanes = device->lanes; in dw_mipi_dsi_host_attach()
328 dsi->channel = device->channel; in dw_mipi_dsi_host_attach()
329 dsi->format = device->format; in dw_mipi_dsi_host_attach()
330 dsi->mode_flags = device->mode_flags; in dw_mipi_dsi_host_attach()
332 bridge = devm_drm_of_get_bridge(dsi->dev, dsi->dev->of_node, 1, 0); in dw_mipi_dsi_host_attach()
336 bridge->pre_enable_prev_first = true; in dw_mipi_dsi_host_attach()
337 dsi->panel_bridge = bridge; in dw_mipi_dsi_host_attach()
339 drm_bridge_add(&dsi->bridge); in dw_mipi_dsi_host_attach()
341 if (pdata->host_ops && pdata->host_ops->attach) { in dw_mipi_dsi_host_attach()
342 ret = pdata->host_ops->attach(pdata->priv_data, device); in dw_mipi_dsi_host_attach()
353 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_detach() local
354 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_detach()
357 if (pdata->host_ops && pdata->host_ops->detach) { in dw_mipi_dsi_host_detach()
358 ret = pdata->host_ops->detach(pdata->priv_data, device); in dw_mipi_dsi_host_detach()
363 drm_of_panel_bridge_remove(host->dev->of_node, 1, 0); in dw_mipi_dsi_host_detach()
365 drm_bridge_remove(&dsi->bridge); in dw_mipi_dsi_host_detach()
370 static void dw_mipi_message_config(struct dw_mipi_dsi *dsi, in dw_mipi_message_config() argument
373 bool lpm = msg->flags & MIPI_DSI_MSG_USE_LPM; in dw_mipi_message_config()
382 dsi_write(dsi, DSI_DPI_LP_CMD_TIM, OUTVACT_LPCMD_TIME(16) in dw_mipi_message_config()
385 if (msg->flags & MIPI_DSI_MSG_REQ_ACK) in dw_mipi_message_config()
390 dsi_write(dsi, DSI_CMD_MODE_CFG, val); in dw_mipi_message_config()
392 val = dsi_read(dsi, DSI_VID_MODE_CFG); in dw_mipi_message_config()
397 dsi_write(dsi, DSI_VID_MODE_CFG, val); in dw_mipi_message_config()
400 static int dw_mipi_dsi_gen_pkt_hdr_write(struct dw_mipi_dsi *dsi, u32 hdr_val) in dw_mipi_dsi_gen_pkt_hdr_write() argument
405 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
409 dev_err(dsi->dev, "failed to get available command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
413 dsi_write(dsi, DSI_GEN_HDR, hdr_val); in dw_mipi_dsi_gen_pkt_hdr_write()
416 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
420 dev_err(dsi->dev, "failed to write command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
427 static int dw_mipi_dsi_write(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_write() argument
430 const u8 *tx_buf = packet->payload; in dw_mipi_dsi_write()
431 int len = packet->payload_length, pld_data_bytes = sizeof(u32), ret; in dw_mipi_dsi_write()
439 dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); in dw_mipi_dsi_write()
443 dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); in dw_mipi_dsi_write()
445 len -= pld_data_bytes; in dw_mipi_dsi_write()
448 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_write()
452 dev_err(dsi->dev, in dw_mipi_dsi_write()
459 memcpy(&word, packet->header, sizeof(packet->header)); in dw_mipi_dsi_write()
460 return dw_mipi_dsi_gen_pkt_hdr_write(dsi, le32_to_cpu(word)); in dw_mipi_dsi_write()
463 static int dw_mipi_dsi_read(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_read() argument
466 int i, j, ret, len = msg->rx_len; in dw_mipi_dsi_read()
467 u8 *buf = msg->rx_buf; in dw_mipi_dsi_read()
471 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
475 dev_err(dsi->dev, "Timeout during read operation\n"); in dw_mipi_dsi_read()
481 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
485 dev_err(dsi->dev, "Read payload FIFO is empty\n"); in dw_mipi_dsi_read()
489 val = dsi_read(dsi, DSI_GEN_PLD_DATA); in dw_mipi_dsi_read()
500 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_transfer() local
506 dev_err(dsi->dev, "failed to create packet: %d\n", ret); in dw_mipi_dsi_host_transfer()
510 dw_mipi_message_config(dsi, msg); in dw_mipi_dsi_host_transfer()
511 if (dsi->slave) in dw_mipi_dsi_host_transfer()
512 dw_mipi_message_config(dsi->slave, msg); in dw_mipi_dsi_host_transfer()
514 ret = dw_mipi_dsi_write(dsi, &packet); in dw_mipi_dsi_host_transfer()
517 if (dsi->slave) { in dw_mipi_dsi_host_transfer()
518 ret = dw_mipi_dsi_write(dsi->slave, &packet); in dw_mipi_dsi_host_transfer()
523 if (msg->rx_buf && msg->rx_len) { in dw_mipi_dsi_host_transfer()
524 ret = dw_mipi_dsi_read(dsi, msg); in dw_mipi_dsi_host_transfer()
527 nb_bytes = msg->rx_len; in dw_mipi_dsi_host_transfer()
541 static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_video_mode_config() argument
547 * enabling low power is panel-dependent, we should use the in dw_mipi_dsi_video_mode_config()
552 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in dw_mipi_dsi_video_mode_config()
554 else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in dw_mipi_dsi_video_mode_config()
560 if (dsi->vpg_defs.vpg) { in dw_mipi_dsi_video_mode_config()
562 val |= dsi->vpg_defs.vpg_horizontal ? in dw_mipi_dsi_video_mode_config()
564 val |= dsi->vpg_defs.vpg_ber_pattern ? VID_MODE_VPG_MODE : 0; in dw_mipi_dsi_video_mode_config()
568 dsi_write(dsi, DSI_VID_MODE_CFG, val); in dw_mipi_dsi_video_mode_config()
571 static void dw_mipi_dsi_set_mode(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_set_mode() argument
576 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_set_mode()
579 dsi_write(dsi, DSI_MODE_CFG, ENABLE_VIDEO_MODE); in dw_mipi_dsi_set_mode()
580 dw_mipi_dsi_video_mode_config(dsi); in dw_mipi_dsi_set_mode()
582 dsi_write(dsi, DSI_MODE_CFG, ENABLE_CMD_MODE); in dw_mipi_dsi_set_mode()
586 if (dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) in dw_mipi_dsi_set_mode()
588 dsi_write(dsi, DSI_LPCLK_CTRL, val); in dw_mipi_dsi_set_mode()
590 dsi_write(dsi, DSI_PWR_UP, POWERUP); in dw_mipi_dsi_set_mode()
593 static void dw_mipi_dsi_disable(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_disable() argument
595 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_disable()
596 dsi_write(dsi, DSI_PHY_RSTZ, PHY_RSTZ); in dw_mipi_dsi_disable()
599 static void dw_mipi_dsi_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_init() argument
601 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_init()
610 if (phy_ops->get_esc_clk_rate) { in dw_mipi_dsi_init()
611 ret = phy_ops->get_esc_clk_rate(dsi->plat_data->priv_data, in dw_mipi_dsi_init()
624 esc_clk_division = (dsi->lane_mbps >> 3) / esc_rate + 1; in dw_mipi_dsi_init()
626 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_init()
633 dsi_write(dsi, DSI_CLKMGR_CFG, TO_CLK_DIVISION(10) | in dw_mipi_dsi_init()
637 static void dw_mipi_dsi_dpi_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_dpi_config() argument
642 switch (dsi->format) { in dw_mipi_dsi_dpi_config()
657 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in dw_mipi_dsi_dpi_config()
659 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in dw_mipi_dsi_dpi_config()
662 dsi_write(dsi, DSI_DPI_VCID, DPI_VCID(dsi->channel)); in dw_mipi_dsi_dpi_config()
663 dsi_write(dsi, DSI_DPI_COLOR_CODING, color); in dw_mipi_dsi_dpi_config()
664 dsi_write(dsi, DSI_DPI_CFG_POL, val); in dw_mipi_dsi_dpi_config()
667 static void dw_mipi_dsi_packet_handler_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_packet_handler_config() argument
669 dsi_write(dsi, DSI_PCKHDL_CFG, CRC_RX_EN | ECC_RX_EN | BTA_EN); in dw_mipi_dsi_packet_handler_config()
672 static void dw_mipi_dsi_video_packet_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_video_packet_config() argument
677 * only burst mode is supported here. For non-burst video modes, in dw_mipi_dsi_video_packet_config()
680 * non-burst video modes, see dw_mipi_dsi_video_mode_config()... in dw_mipi_dsi_video_packet_config()
683 dsi_write(dsi, DSI_VID_PKT_SIZE, in dw_mipi_dsi_video_packet_config()
684 dw_mipi_is_dual_mode(dsi) ? in dw_mipi_dsi_video_packet_config()
685 VID_PKT_SIZE(mode->hdisplay / 2) : in dw_mipi_dsi_video_packet_config()
686 VID_PKT_SIZE(mode->hdisplay)); in dw_mipi_dsi_video_packet_config()
689 static void dw_mipi_dsi_command_mode_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_command_mode_config() argument
696 dsi_write(dsi, DSI_TO_CNT_CFG, HSTX_TO_CNT(1000) | LPRX_TO_CNT(1000)); in dw_mipi_dsi_command_mode_config()
699 * the Bus-Turn-Around Timeout Counter should be computed in dw_mipi_dsi_command_mode_config()
702 dsi_write(dsi, DSI_BTA_TO_CNT, 0xd00); in dw_mipi_dsi_command_mode_config()
703 dsi_write(dsi, DSI_MODE_CFG, ENABLE_CMD_MODE); in dw_mipi_dsi_command_mode_config()
707 static u32 dw_mipi_dsi_get_hcomponent_lbcc(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_get_hcomponent_lbcc() argument
713 lbcc = hcomponent * dsi->lane_mbps * MSEC_PER_SEC / 8; in dw_mipi_dsi_get_hcomponent_lbcc()
715 frac = lbcc % mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
716 lbcc = lbcc / mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
723 static void dw_mipi_dsi_line_timer_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_line_timer_config() argument
728 htotal = mode->htotal; in dw_mipi_dsi_line_timer_config()
729 hsa = mode->hsync_end - mode->hsync_start; in dw_mipi_dsi_line_timer_config()
730 hbp = mode->htotal - mode->hsync_end; in dw_mipi_dsi_line_timer_config()
736 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, htotal); in dw_mipi_dsi_line_timer_config()
737 dsi_write(dsi, DSI_VID_HLINE_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
739 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hsa); in dw_mipi_dsi_line_timer_config()
740 dsi_write(dsi, DSI_VID_HSA_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
742 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hbp); in dw_mipi_dsi_line_timer_config()
743 dsi_write(dsi, DSI_VID_HBP_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
746 static void dw_mipi_dsi_vertical_timing_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_vertical_timing_config() argument
751 vactive = mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
752 vsa = mode->vsync_end - mode->vsync_start; in dw_mipi_dsi_vertical_timing_config()
753 vfp = mode->vsync_start - mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
754 vbp = mode->vtotal - mode->vsync_end; in dw_mipi_dsi_vertical_timing_config()
756 dsi_write(dsi, DSI_VID_VACTIVE_LINES, vactive); in dw_mipi_dsi_vertical_timing_config()
757 dsi_write(dsi, DSI_VID_VSA_LINES, vsa); in dw_mipi_dsi_vertical_timing_config()
758 dsi_write(dsi, DSI_VID_VFP_LINES, vfp); in dw_mipi_dsi_vertical_timing_config()
759 dsi_write(dsi, DSI_VID_VBP_LINES, vbp); in dw_mipi_dsi_vertical_timing_config()
762 static void dw_mipi_dsi_dphy_timing_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_timing_config() argument
764 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_dphy_timing_config()
769 ret = phy_ops->get_timing(dsi->plat_data->priv_data, in dw_mipi_dsi_dphy_timing_config()
770 dsi->lane_mbps, &timing); in dw_mipi_dsi_dphy_timing_config()
772 DRM_DEV_ERROR(dsi->dev, "Retrieving phy timings failed\n"); in dw_mipi_dsi_dphy_timing_config()
782 hw_version = dsi_read(dsi, DSI_VERSION) & VERSION; in dw_mipi_dsi_dphy_timing_config()
785 dsi_write(dsi, DSI_PHY_TMR_CFG, in dw_mipi_dsi_dphy_timing_config()
788 dsi_write(dsi, DSI_PHY_TMR_RD_CFG, MAX_RD_TIME_V131(10000)); in dw_mipi_dsi_dphy_timing_config()
790 dsi_write(dsi, DSI_PHY_TMR_CFG, in dw_mipi_dsi_dphy_timing_config()
796 dsi_write(dsi, DSI_PHY_TMR_LPCLK_CFG, in dw_mipi_dsi_dphy_timing_config()
801 static void dw_mipi_dsi_dphy_interface_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_interface_config() argument
805 * stop wait time should be the maximum between host dsi in dw_mipi_dsi_dphy_interface_config()
808 dsi_write(dsi, DSI_PHY_IF_CFG, PHY_STOP_WAIT_TIME(0x20) | in dw_mipi_dsi_dphy_interface_config()
809 N_LANES(dsi->lanes)); in dw_mipi_dsi_dphy_interface_config()
812 static void dw_mipi_dsi_dphy_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_init() argument
815 dsi_write(dsi, DSI_PHY_RSTZ, PHY_DISFORCEPLL | PHY_DISABLECLK in dw_mipi_dsi_dphy_init()
817 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_UNTESTCLR); in dw_mipi_dsi_dphy_init()
818 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_TESTCLR); in dw_mipi_dsi_dphy_init()
819 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_UNTESTCLR); in dw_mipi_dsi_dphy_init()
822 static void dw_mipi_dsi_dphy_enable(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_enable() argument
827 dsi_write(dsi, DSI_PHY_RSTZ, PHY_ENFORCEPLL | PHY_ENABLECLK | in dw_mipi_dsi_dphy_enable()
830 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, val, in dw_mipi_dsi_dphy_enable()
835 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, in dw_mipi_dsi_dphy_enable()
842 static void dw_mipi_dsi_clear_err(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_clear_err() argument
844 dsi_read(dsi, DSI_INT_ST0); in dw_mipi_dsi_clear_err()
845 dsi_read(dsi, DSI_INT_ST1); in dw_mipi_dsi_clear_err()
846 dsi_write(dsi, DSI_INT_MSK0, 0); in dw_mipi_dsi_clear_err()
847 dsi_write(dsi, DSI_INT_MSK1, 0); in dw_mipi_dsi_clear_err()
853 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_post_atomic_disable() local
854 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_bridge_post_atomic_disable()
857 * Switch to command mode before panel-bridge post_disable & in dw_mipi_dsi_bridge_post_atomic_disable()
859 * Note: panel-bridge disable & panel disable has been called in dw_mipi_dsi_bridge_post_atomic_disable()
862 dw_mipi_dsi_set_mode(dsi, 0); in dw_mipi_dsi_bridge_post_atomic_disable()
864 if (phy_ops->power_off) in dw_mipi_dsi_bridge_post_atomic_disable()
865 phy_ops->power_off(dsi->plat_data->priv_data); in dw_mipi_dsi_bridge_post_atomic_disable()
867 if (dsi->slave) { in dw_mipi_dsi_bridge_post_atomic_disable()
868 dw_mipi_dsi_disable(dsi->slave); in dw_mipi_dsi_bridge_post_atomic_disable()
869 clk_disable_unprepare(dsi->slave->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
870 pm_runtime_put(dsi->slave->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
872 dw_mipi_dsi_disable(dsi); in dw_mipi_dsi_bridge_post_atomic_disable()
874 clk_disable_unprepare(dsi->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
875 pm_runtime_put(dsi->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
878 static unsigned int dw_mipi_dsi_get_lanes(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_get_lanes() argument
881 if (dsi->master) in dw_mipi_dsi_get_lanes()
882 return dsi->master->lanes + dsi->lanes; in dw_mipi_dsi_get_lanes()
885 if (dsi->slave) in dw_mipi_dsi_get_lanes()
886 return dsi->lanes + dsi->slave->lanes; in dw_mipi_dsi_get_lanes()
888 /* single-dsi, so no other instance to consider */ in dw_mipi_dsi_get_lanes()
889 return dsi->lanes; in dw_mipi_dsi_get_lanes()
892 static void dw_mipi_dsi_mode_set(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_mode_set() argument
895 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_mode_set()
896 void *priv_data = dsi->plat_data->priv_data; in dw_mipi_dsi_mode_set()
898 u32 lanes = dw_mipi_dsi_get_lanes(dsi); in dw_mipi_dsi_mode_set()
900 clk_prepare_enable(dsi->pclk); in dw_mipi_dsi_mode_set()
902 ret = phy_ops->get_lane_mbps(priv_data, adjusted_mode, dsi->mode_flags, in dw_mipi_dsi_mode_set()
903 lanes, dsi->format, &dsi->lane_mbps); in dw_mipi_dsi_mode_set()
907 pm_runtime_get_sync(dsi->dev); in dw_mipi_dsi_mode_set()
908 dw_mipi_dsi_init(dsi); in dw_mipi_dsi_mode_set()
909 dw_mipi_dsi_dpi_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
910 dw_mipi_dsi_packet_handler_config(dsi); in dw_mipi_dsi_mode_set()
911 dw_mipi_dsi_video_mode_config(dsi); in dw_mipi_dsi_mode_set()
912 dw_mipi_dsi_video_packet_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
913 dw_mipi_dsi_command_mode_config(dsi); in dw_mipi_dsi_mode_set()
914 dw_mipi_dsi_line_timer_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
915 dw_mipi_dsi_vertical_timing_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
917 dw_mipi_dsi_dphy_init(dsi); in dw_mipi_dsi_mode_set()
918 dw_mipi_dsi_dphy_timing_config(dsi); in dw_mipi_dsi_mode_set()
919 dw_mipi_dsi_dphy_interface_config(dsi); in dw_mipi_dsi_mode_set()
921 dw_mipi_dsi_clear_err(dsi); in dw_mipi_dsi_mode_set()
923 ret = phy_ops->init(priv_data); in dw_mipi_dsi_mode_set()
927 dw_mipi_dsi_dphy_enable(dsi); in dw_mipi_dsi_mode_set()
931 /* Switch to cmd mode for panel-bridge pre_enable & panel prepare */ in dw_mipi_dsi_mode_set()
932 dw_mipi_dsi_set_mode(dsi, 0); in dw_mipi_dsi_mode_set()
934 if (phy_ops->power_on) in dw_mipi_dsi_mode_set()
935 phy_ops->power_on(dsi->plat_data->priv_data); in dw_mipi_dsi_mode_set()
941 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_pre_enable() local
943 /* Power up the dsi ctl into a command mode */ in dw_mipi_dsi_bridge_atomic_pre_enable()
944 dw_mipi_dsi_mode_set(dsi, &dsi->mode); in dw_mipi_dsi_bridge_atomic_pre_enable()
945 if (dsi->slave) in dw_mipi_dsi_bridge_atomic_pre_enable()
946 dw_mipi_dsi_mode_set(dsi->slave, &dsi->mode); in dw_mipi_dsi_bridge_atomic_pre_enable()
953 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_mode_set() local
956 drm_mode_copy(&dsi->mode, adjusted_mode); in dw_mipi_dsi_bridge_mode_set()
962 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_enable() local
964 /* Switch to video mode for panel-bridge enable & panel enable */ in dw_mipi_dsi_bridge_atomic_enable()
965 dw_mipi_dsi_set_mode(dsi, MIPI_DSI_MODE_VIDEO); in dw_mipi_dsi_bridge_atomic_enable()
966 if (dsi->slave) in dw_mipi_dsi_bridge_atomic_enable()
967 dw_mipi_dsi_set_mode(dsi->slave, MIPI_DSI_MODE_VIDEO); in dw_mipi_dsi_bridge_atomic_enable()
975 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_mode_valid() local
976 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_bridge_mode_valid()
979 if (pdata->mode_valid) in dw_mipi_dsi_bridge_mode_valid()
980 mode_status = pdata->mode_valid(pdata->priv_data, mode, in dw_mipi_dsi_bridge_mode_valid()
981 dsi->mode_flags, in dw_mipi_dsi_bridge_mode_valid()
982 dw_mipi_dsi_get_lanes(dsi), in dw_mipi_dsi_bridge_mode_valid()
983 dsi->format); in dw_mipi_dsi_bridge_mode_valid()
991 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_attach() local
993 if (!bridge->encoder) { in dw_mipi_dsi_bridge_attach()
995 return -ENODEV; in dw_mipi_dsi_bridge_attach()
999 bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI; in dw_mipi_dsi_bridge_attach()
1001 /* Attach the panel-bridge to the dsi bridge */ in dw_mipi_dsi_bridge_attach()
1002 return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge, in dw_mipi_dsi_bridge_attach()
1023 struct dw_mipi_dsi *dsi; in dw_mipi_dsi_debugfs_write() local
1027 return -ENODEV; in dw_mipi_dsi_debugfs_write()
1029 dsi = vpg->dsi; in dw_mipi_dsi_debugfs_write()
1031 *vpg->reg = (bool)val; in dw_mipi_dsi_debugfs_write()
1033 mode_cfg = dsi_read(dsi, DSI_VID_MODE_CFG); in dw_mipi_dsi_debugfs_write()
1035 if (*vpg->reg) in dw_mipi_dsi_debugfs_write()
1036 mode_cfg |= vpg->mask; in dw_mipi_dsi_debugfs_write()
1038 mode_cfg &= ~vpg->mask; in dw_mipi_dsi_debugfs_write()
1040 dsi_write(dsi, DSI_VID_MODE_CFG, mode_cfg); in dw_mipi_dsi_debugfs_write()
1050 return -ENODEV; in dw_mipi_dsi_debugfs_show()
1052 *val = *vpg->reg; in dw_mipi_dsi_debugfs_show()
1062 struct dw_mipi_dsi *dsi = data; in debugfs_create_files() local
1064 REGISTER(vpg, VID_MODE_VPG_ENABLE, dsi), in debugfs_create_files()
1065 REGISTER(vpg_horizontal, VID_MODE_VPG_HORIZONTAL, dsi), in debugfs_create_files()
1066 REGISTER(vpg_ber_pattern, VID_MODE_VPG_MODE, dsi), in debugfs_create_files()
1070 dsi->debugfs_vpg = kmemdup(debugfs, sizeof(debugfs), GFP_KERNEL); in debugfs_create_files()
1071 if (!dsi->debugfs_vpg) in debugfs_create_files()
1075 debugfs_create_file(dsi->debugfs_vpg[i].name, 0644, in debugfs_create_files()
1076 dsi->debugfs, &dsi->debugfs_vpg[i], in debugfs_create_files()
1080 static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_debugfs_init() argument
1082 dsi->debugfs = debugfs_create_dir(dev_name(dsi->dev), NULL); in dw_mipi_dsi_debugfs_init()
1083 if (IS_ERR(dsi->debugfs)) { in dw_mipi_dsi_debugfs_init()
1084 dev_err(dsi->dev, "failed to create debugfs root\n"); in dw_mipi_dsi_debugfs_init()
1088 debugfs_create_files(dsi); in dw_mipi_dsi_debugfs_init()
1091 static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_debugfs_remove() argument
1093 debugfs_remove_recursive(dsi->debugfs); in dw_mipi_dsi_debugfs_remove()
1094 kfree(dsi->debugfs_vpg); in dw_mipi_dsi_debugfs_remove()
1099 static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) { } in dw_mipi_dsi_debugfs_init() argument
1100 static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) { } in dw_mipi_dsi_debugfs_remove() argument
1108 struct device *dev = &pdev->dev; in __dw_mipi_dsi_probe()
1110 struct dw_mipi_dsi *dsi; in __dw_mipi_dsi_probe() local
1113 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); in __dw_mipi_dsi_probe()
1114 if (!dsi) in __dw_mipi_dsi_probe()
1115 return ERR_PTR(-ENOMEM); in __dw_mipi_dsi_probe()
1117 dsi->dev = dev; in __dw_mipi_dsi_probe()
1118 dsi->plat_data = plat_data; in __dw_mipi_dsi_probe()
1120 if (!plat_data->phy_ops->init || !plat_data->phy_ops->get_lane_mbps || in __dw_mipi_dsi_probe()
1121 !plat_data->phy_ops->get_timing) { in __dw_mipi_dsi_probe()
1123 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1126 if (!plat_data->base) { in __dw_mipi_dsi_probe()
1127 dsi->base = devm_platform_ioremap_resource(pdev, 0); in __dw_mipi_dsi_probe()
1128 if (IS_ERR(dsi->base)) in __dw_mipi_dsi_probe()
1129 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1132 dsi->base = plat_data->base; in __dw_mipi_dsi_probe()
1135 dsi->pclk = devm_clk_get(dev, "pclk"); in __dw_mipi_dsi_probe()
1136 if (IS_ERR(dsi->pclk)) { in __dw_mipi_dsi_probe()
1137 ret = PTR_ERR(dsi->pclk); in __dw_mipi_dsi_probe()
1150 if (ret != -EPROBE_DEFER) in __dw_mipi_dsi_probe()
1157 ret = clk_prepare_enable(dsi->pclk); in __dw_mipi_dsi_probe()
1167 clk_disable_unprepare(dsi->pclk); in __dw_mipi_dsi_probe()
1170 dw_mipi_dsi_debugfs_init(dsi); in __dw_mipi_dsi_probe()
1173 dsi->dsi_host.ops = &dw_mipi_dsi_host_ops; in __dw_mipi_dsi_probe()
1174 dsi->dsi_host.dev = dev; in __dw_mipi_dsi_probe()
1175 ret = mipi_dsi_host_register(&dsi->dsi_host); in __dw_mipi_dsi_probe()
1179 dw_mipi_dsi_debugfs_remove(dsi); in __dw_mipi_dsi_probe()
1183 dsi->bridge.driver_private = dsi; in __dw_mipi_dsi_probe()
1184 dsi->bridge.funcs = &dw_mipi_dsi_bridge_funcs; in __dw_mipi_dsi_probe()
1186 dsi->bridge.of_node = pdev->dev.of_node; in __dw_mipi_dsi_probe()
1189 return dsi; in __dw_mipi_dsi_probe()
1192 static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) in __dw_mipi_dsi_remove() argument
1194 mipi_dsi_host_unregister(&dsi->dsi_host); in __dw_mipi_dsi_remove()
1196 pm_runtime_disable(dsi->dev); in __dw_mipi_dsi_remove()
1197 dw_mipi_dsi_debugfs_remove(dsi); in __dw_mipi_dsi_remove()
1200 void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave) in dw_mipi_dsi_set_slave() argument
1203 dsi->slave = slave; in dw_mipi_dsi_set_slave()
1204 dsi->slave->master = dsi; in dw_mipi_dsi_set_slave()
1207 dsi->slave->lanes = dsi->lanes; in dw_mipi_dsi_set_slave()
1208 dsi->slave->channel = dsi->channel; in dw_mipi_dsi_set_slave()
1209 dsi->slave->format = dsi->format; in dw_mipi_dsi_set_slave()
1210 dsi->slave->mode_flags = dsi->mode_flags; in dw_mipi_dsi_set_slave()
1215 * Probe/remove API, used from platforms based on the DRM bridge API.
1225 void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_remove() argument
1227 __dw_mipi_dsi_remove(dsi); in dw_mipi_dsi_remove()
1232 * Bind/unbind API, used from platforms based on the component framework.
1234 int dw_mipi_dsi_bind(struct dw_mipi_dsi *dsi, struct drm_encoder *encoder) in dw_mipi_dsi_bind() argument
1236 return drm_bridge_attach(encoder, &dsi->bridge, NULL, 0); in dw_mipi_dsi_bind()
1240 void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_unbind() argument
1245 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
1247 MODULE_DESCRIPTION("DW MIPI DSI host controller driver");
1249 MODULE_ALIAS("platform:dw-mipi-dsi");