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.
16 #include <linux/media-bus-format.h>
196 #define N_LANES(n) (((n) - 1) & 0x3)
229 #define VPG_DEFS(name, dsi) \ argument
230 ((void __force *)&((*dsi).vpg_defs.name))
232 #define REGISTER(name, mask, dsi) \ argument
233 { #name, VPG_DEFS(name, dsi), mask, dsi }
239 struct dw_mipi_dsi *dsi; member
268 struct dw_mipi_dsi *master; /* dual-dsi master ptr */
269 struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */
278 static inline bool dw_mipi_is_dual_mode(struct dw_mipi_dsi *dsi) in dw_mipi_is_dual_mode() argument
280 return dsi->slave || dsi->master; in dw_mipi_is_dual_mode()
306 static inline void dsi_write(struct dw_mipi_dsi *dsi, u32 reg, u32 val) in dsi_write() argument
308 writel(val, dsi->base + reg); in dsi_write()
311 static inline u32 dsi_read(struct dw_mipi_dsi *dsi, u32 reg) in dsi_read() argument
313 return readl(dsi->base + reg); in dsi_read()
319 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_attach() local
320 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_attach()
324 if (device->lanes > dsi->plat_data->max_data_lanes) { in dw_mipi_dsi_host_attach()
325 dev_err(dsi->dev, "the number of data lanes(%u) is too many\n", in dw_mipi_dsi_host_attach()
326 device->lanes); in dw_mipi_dsi_host_attach()
327 return -EINVAL; in dw_mipi_dsi_host_attach()
330 dsi->lanes = device->lanes; in dw_mipi_dsi_host_attach()
331 dsi->channel = device->channel; in dw_mipi_dsi_host_attach()
332 dsi->format = device->format; in dw_mipi_dsi_host_attach()
333 dsi->mode_flags = device->mode_flags; in dw_mipi_dsi_host_attach()
335 bridge = devm_drm_of_get_bridge(dsi->dev, dsi->dev->of_node, 1, 0); in dw_mipi_dsi_host_attach()
339 bridge->pre_enable_prev_first = true; in dw_mipi_dsi_host_attach()
340 dsi->panel_bridge = bridge; in dw_mipi_dsi_host_attach()
342 drm_bridge_add(&dsi->bridge); in dw_mipi_dsi_host_attach()
344 if (pdata->host_ops && pdata->host_ops->attach) { in dw_mipi_dsi_host_attach()
345 ret = pdata->host_ops->attach(pdata->priv_data, device); in dw_mipi_dsi_host_attach()
356 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_detach() local
357 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_detach()
360 if (pdata->host_ops && pdata->host_ops->detach) { in dw_mipi_dsi_host_detach()
361 ret = pdata->host_ops->detach(pdata->priv_data, device); in dw_mipi_dsi_host_detach()
366 drm_of_panel_bridge_remove(host->dev->of_node, 1, 0); in dw_mipi_dsi_host_detach()
368 drm_bridge_remove(&dsi->bridge); in dw_mipi_dsi_host_detach()
373 static void dw_mipi_message_config(struct dw_mipi_dsi *dsi, in dw_mipi_message_config() argument
376 bool lpm = msg->flags & MIPI_DSI_MSG_USE_LPM; in dw_mipi_message_config()
385 dsi_write(dsi, DSI_DPI_LP_CMD_TIM, OUTVACT_LPCMD_TIME(16) in dw_mipi_message_config()
388 if (msg->flags & MIPI_DSI_MSG_REQ_ACK) in dw_mipi_message_config()
393 dsi_write(dsi, DSI_CMD_MODE_CFG, val); in dw_mipi_message_config()
395 val = dsi_read(dsi, DSI_VID_MODE_CFG); in dw_mipi_message_config()
400 dsi_write(dsi, DSI_VID_MODE_CFG, val); in dw_mipi_message_config()
403 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
408 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
412 dev_err(dsi->dev, "failed to get available command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
416 dsi_write(dsi, DSI_GEN_HDR, hdr_val); in dw_mipi_dsi_gen_pkt_hdr_write()
419 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
423 dev_err(dsi->dev, "failed to write command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
430 static int dw_mipi_dsi_write(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_write() argument
433 const u8 *tx_buf = packet->payload; in dw_mipi_dsi_write()
434 int len = packet->payload_length, pld_data_bytes = sizeof(u32), ret; in dw_mipi_dsi_write()
442 dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); in dw_mipi_dsi_write()
446 dsi_write(dsi, DSI_GEN_PLD_DATA, le32_to_cpu(word)); in dw_mipi_dsi_write()
448 len -= pld_data_bytes; in dw_mipi_dsi_write()
451 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_write()
455 dev_err(dsi->dev, in dw_mipi_dsi_write()
462 memcpy(&word, packet->header, sizeof(packet->header)); in dw_mipi_dsi_write()
463 return dw_mipi_dsi_gen_pkt_hdr_write(dsi, le32_to_cpu(word)); in dw_mipi_dsi_write()
466 static int dw_mipi_dsi_read(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_read() argument
469 int i, j, ret, len = msg->rx_len; in dw_mipi_dsi_read()
470 u8 *buf = msg->rx_buf; in dw_mipi_dsi_read()
474 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
478 dev_err(dsi->dev, "Timeout during read operation\n"); in dw_mipi_dsi_read()
484 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
488 dev_err(dsi->dev, "Read payload FIFO is empty\n"); in dw_mipi_dsi_read()
492 val = dsi_read(dsi, DSI_GEN_PLD_DATA); in dw_mipi_dsi_read()
503 struct dw_mipi_dsi *dsi = host_to_dsi(host); in dw_mipi_dsi_host_transfer() local
509 dev_err(dsi->dev, "failed to create packet: %d\n", ret); in dw_mipi_dsi_host_transfer()
513 dw_mipi_message_config(dsi, msg); in dw_mipi_dsi_host_transfer()
514 if (dsi->slave) in dw_mipi_dsi_host_transfer()
515 dw_mipi_message_config(dsi->slave, msg); in dw_mipi_dsi_host_transfer()
517 ret = dw_mipi_dsi_write(dsi, &packet); in dw_mipi_dsi_host_transfer()
520 if (dsi->slave) { in dw_mipi_dsi_host_transfer()
521 ret = dw_mipi_dsi_write(dsi->slave, &packet); in dw_mipi_dsi_host_transfer()
526 if (msg->rx_buf && msg->rx_len) { in dw_mipi_dsi_host_transfer()
527 ret = dw_mipi_dsi_read(dsi, msg); in dw_mipi_dsi_host_transfer()
530 nb_bytes = msg->rx_len; in dw_mipi_dsi_host_transfer()
552 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_get_input_bus_fmts() local
553 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_bridge_atomic_get_input_bus_fmts()
556 if (pdata->get_input_bus_fmts) in dw_mipi_dsi_bridge_atomic_get_input_bus_fmts()
557 return pdata->get_input_bus_fmts(pdata->priv_data, in dw_mipi_dsi_bridge_atomic_get_input_bus_fmts()
577 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_check() local
578 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_bridge_atomic_check()
581 bridge_state->input_bus_cfg.flags = in dw_mipi_dsi_bridge_atomic_check()
584 if (pdata->mode_fixup) { in dw_mipi_dsi_bridge_atomic_check()
585 ret = pdata->mode_fixup(pdata->priv_data, &crtc_state->mode, in dw_mipi_dsi_bridge_atomic_check()
586 &crtc_state->adjusted_mode); in dw_mipi_dsi_bridge_atomic_check()
589 DRM_MODE_ARG(&crtc_state->mode)); in dw_mipi_dsi_bridge_atomic_check()
590 return -EINVAL; in dw_mipi_dsi_bridge_atomic_check()
597 static void dw_mipi_dsi_video_mode_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_video_mode_config() argument
603 * enabling low power is panel-dependent, we should use the in dw_mipi_dsi_video_mode_config()
608 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in dw_mipi_dsi_video_mode_config()
610 else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in dw_mipi_dsi_video_mode_config()
616 if (dsi->vpg_defs.vpg) { in dw_mipi_dsi_video_mode_config()
618 val |= dsi->vpg_defs.vpg_horizontal ? in dw_mipi_dsi_video_mode_config()
620 val |= dsi->vpg_defs.vpg_ber_pattern ? VID_MODE_VPG_MODE : 0; in dw_mipi_dsi_video_mode_config()
624 dsi_write(dsi, DSI_VID_MODE_CFG, val); in dw_mipi_dsi_video_mode_config()
627 static void dw_mipi_dsi_set_mode(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_set_mode() argument
632 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_set_mode()
635 dsi_write(dsi, DSI_MODE_CFG, ENABLE_VIDEO_MODE); in dw_mipi_dsi_set_mode()
636 dw_mipi_dsi_video_mode_config(dsi); in dw_mipi_dsi_set_mode()
638 dsi_write(dsi, DSI_MODE_CFG, ENABLE_CMD_MODE); in dw_mipi_dsi_set_mode()
642 if (dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) in dw_mipi_dsi_set_mode()
644 dsi_write(dsi, DSI_LPCLK_CTRL, val); in dw_mipi_dsi_set_mode()
646 dsi_write(dsi, DSI_PWR_UP, POWERUP); in dw_mipi_dsi_set_mode()
649 static void dw_mipi_dsi_disable(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_disable() argument
651 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_disable()
652 dsi_write(dsi, DSI_PHY_RSTZ, PHY_RSTZ); in dw_mipi_dsi_disable()
655 static void dw_mipi_dsi_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_init() argument
657 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_init()
666 if (phy_ops->get_esc_clk_rate) { in dw_mipi_dsi_init()
667 ret = phy_ops->get_esc_clk_rate(dsi->plat_data->priv_data, in dw_mipi_dsi_init()
680 esc_clk_division = (dsi->lane_mbps >> 3) / esc_rate + 1; in dw_mipi_dsi_init()
682 dsi_write(dsi, DSI_PWR_UP, RESET); in dw_mipi_dsi_init()
689 dsi_write(dsi, DSI_CLKMGR_CFG, TO_CLK_DIVISION(0) | in dw_mipi_dsi_init()
693 static void dw_mipi_dsi_dpi_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_dpi_config() argument
698 switch (dsi->format) { in dw_mipi_dsi_dpi_config()
713 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in dw_mipi_dsi_dpi_config()
715 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in dw_mipi_dsi_dpi_config()
718 dsi_write(dsi, DSI_DPI_VCID, DPI_VCID(dsi->channel)); in dw_mipi_dsi_dpi_config()
719 dsi_write(dsi, DSI_DPI_COLOR_CODING, color); in dw_mipi_dsi_dpi_config()
720 dsi_write(dsi, DSI_DPI_CFG_POL, val); in dw_mipi_dsi_dpi_config()
723 static void dw_mipi_dsi_packet_handler_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_packet_handler_config() argument
727 if (dsi->mode_flags & MIPI_DSI_MODE_NO_EOT_PACKET) in dw_mipi_dsi_packet_handler_config()
730 dsi_write(dsi, DSI_PCKHDL_CFG, val); in dw_mipi_dsi_packet_handler_config()
733 static void dw_mipi_dsi_video_packet_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_video_packet_config() argument
738 * only burst mode is supported here. For non-burst video modes, in dw_mipi_dsi_video_packet_config()
741 * non-burst video modes, see dw_mipi_dsi_video_mode_config()... in dw_mipi_dsi_video_packet_config()
744 dsi_write(dsi, DSI_VID_PKT_SIZE, in dw_mipi_dsi_video_packet_config()
745 dw_mipi_is_dual_mode(dsi) ? in dw_mipi_dsi_video_packet_config()
746 VID_PKT_SIZE(mode->hdisplay / 2) : in dw_mipi_dsi_video_packet_config()
747 VID_PKT_SIZE(mode->hdisplay)); in dw_mipi_dsi_video_packet_config()
750 static void dw_mipi_dsi_command_mode_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_command_mode_config() argument
757 dsi_write(dsi, DSI_TO_CNT_CFG, HSTX_TO_CNT(0) | LPRX_TO_CNT(0)); in dw_mipi_dsi_command_mode_config()
760 * the Bus-Turn-Around Timeout Counter should be computed in dw_mipi_dsi_command_mode_config()
763 dsi_write(dsi, DSI_BTA_TO_CNT, 0xd00); in dw_mipi_dsi_command_mode_config()
764 dsi_write(dsi, DSI_MODE_CFG, ENABLE_CMD_MODE); in dw_mipi_dsi_command_mode_config()
769 static inline u32 dw_mipi_dsi_get_minimum_lbcc(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_get_minimum_lbcc() argument
771 return minimum_lbccs[dsi->lanes - 1]; in dw_mipi_dsi_get_minimum_lbcc()
775 static u32 dw_mipi_dsi_get_hcomponent_lbcc(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_get_hcomponent_lbcc() argument
782 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) { in dw_mipi_dsi_get_hcomponent_lbcc()
783 /* lbcc based on lane_mbps */ in dw_mipi_dsi_get_hcomponent_lbcc()
784 lbcc = hcomponent * dsi->lane_mbps * MSEC_PER_SEC / 8; in dw_mipi_dsi_get_hcomponent_lbcc()
786 /* lbcc based on pixel clock rate */ in dw_mipi_dsi_get_hcomponent_lbcc()
787 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); in dw_mipi_dsi_get_hcomponent_lbcc()
789 dev_err(dsi->dev, "failed to get bpp\n"); in dw_mipi_dsi_get_hcomponent_lbcc()
793 lbcc = div_u64((u64)hcomponent * mode->clock * bpp, dsi->lanes * 8); in dw_mipi_dsi_get_hcomponent_lbcc()
796 frac = lbcc % mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
797 lbcc = lbcc / mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
801 minimum_lbcc = dw_mipi_dsi_get_minimum_lbcc(dsi); in dw_mipi_dsi_get_hcomponent_lbcc()
809 static void dw_mipi_dsi_line_timer_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_line_timer_config() argument
814 htotal = mode->htotal; in dw_mipi_dsi_line_timer_config()
815 hsa = mode->hsync_end - mode->hsync_start; in dw_mipi_dsi_line_timer_config()
816 hbp = mode->htotal - mode->hsync_end; in dw_mipi_dsi_line_timer_config()
822 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, htotal); in dw_mipi_dsi_line_timer_config()
823 dsi_write(dsi, DSI_VID_HLINE_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
825 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hsa); in dw_mipi_dsi_line_timer_config()
826 dsi_write(dsi, DSI_VID_HSA_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
828 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hbp); in dw_mipi_dsi_line_timer_config()
829 dsi_write(dsi, DSI_VID_HBP_TIME, lbcc); in dw_mipi_dsi_line_timer_config()
832 static void dw_mipi_dsi_vertical_timing_config(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_vertical_timing_config() argument
837 vactive = mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
838 vsa = mode->vsync_end - mode->vsync_start; in dw_mipi_dsi_vertical_timing_config()
839 vfp = mode->vsync_start - mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
840 vbp = mode->vtotal - mode->vsync_end; in dw_mipi_dsi_vertical_timing_config()
842 dsi_write(dsi, DSI_VID_VACTIVE_LINES, vactive); in dw_mipi_dsi_vertical_timing_config()
843 dsi_write(dsi, DSI_VID_VSA_LINES, vsa); in dw_mipi_dsi_vertical_timing_config()
844 dsi_write(dsi, DSI_VID_VFP_LINES, vfp); in dw_mipi_dsi_vertical_timing_config()
845 dsi_write(dsi, DSI_VID_VBP_LINES, vbp); in dw_mipi_dsi_vertical_timing_config()
848 static void dw_mipi_dsi_dphy_timing_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_timing_config() argument
850 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_dphy_timing_config()
855 ret = phy_ops->get_timing(dsi->plat_data->priv_data, in dw_mipi_dsi_dphy_timing_config()
856 dsi->lane_mbps, &timing); in dw_mipi_dsi_dphy_timing_config()
858 DRM_DEV_ERROR(dsi->dev, "Retrieving phy timings failed\n"); in dw_mipi_dsi_dphy_timing_config()
868 hw_version = dsi_read(dsi, DSI_VERSION) & VERSION; in dw_mipi_dsi_dphy_timing_config()
871 dsi_write(dsi, DSI_PHY_TMR_CFG, in dw_mipi_dsi_dphy_timing_config()
874 dsi_write(dsi, DSI_PHY_TMR_RD_CFG, MAX_RD_TIME_V131(10000)); in dw_mipi_dsi_dphy_timing_config()
876 dsi_write(dsi, DSI_PHY_TMR_CFG, in dw_mipi_dsi_dphy_timing_config()
882 dsi_write(dsi, DSI_PHY_TMR_LPCLK_CFG, in dw_mipi_dsi_dphy_timing_config()
887 static void dw_mipi_dsi_dphy_interface_config(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_interface_config() argument
891 * stop wait time should be the maximum between host dsi in dw_mipi_dsi_dphy_interface_config()
894 dsi_write(dsi, DSI_PHY_IF_CFG, PHY_STOP_WAIT_TIME(0x20) | in dw_mipi_dsi_dphy_interface_config()
895 N_LANES(dsi->lanes)); in dw_mipi_dsi_dphy_interface_config()
898 static void dw_mipi_dsi_dphy_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_init() argument
901 dsi_write(dsi, DSI_PHY_RSTZ, PHY_DISFORCEPLL | PHY_DISABLECLK in dw_mipi_dsi_dphy_init()
903 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_UNTESTCLR); in dw_mipi_dsi_dphy_init()
904 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_TESTCLR); in dw_mipi_dsi_dphy_init()
905 dsi_write(dsi, DSI_PHY_TST_CTRL0, PHY_UNTESTCLR); in dw_mipi_dsi_dphy_init()
908 static void dw_mipi_dsi_dphy_enable(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_dphy_enable() argument
913 dsi_write(dsi, DSI_PHY_RSTZ, PHY_ENFORCEPLL | PHY_ENABLECLK | in dw_mipi_dsi_dphy_enable()
916 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, val, in dw_mipi_dsi_dphy_enable()
921 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, in dw_mipi_dsi_dphy_enable()
928 static void dw_mipi_dsi_clear_err(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_clear_err() argument
930 dsi_read(dsi, DSI_INT_ST0); in dw_mipi_dsi_clear_err()
931 dsi_read(dsi, DSI_INT_ST1); in dw_mipi_dsi_clear_err()
932 dsi_write(dsi, DSI_INT_MSK0, 0); in dw_mipi_dsi_clear_err()
933 dsi_write(dsi, DSI_INT_MSK1, 0); in dw_mipi_dsi_clear_err()
939 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_post_atomic_disable() local
940 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_bridge_post_atomic_disable()
943 * Switch to command mode before panel-bridge post_disable & in dw_mipi_dsi_bridge_post_atomic_disable()
945 * Note: panel-bridge disable & panel disable has been called in dw_mipi_dsi_bridge_post_atomic_disable()
948 dw_mipi_dsi_set_mode(dsi, 0); in dw_mipi_dsi_bridge_post_atomic_disable()
950 if (phy_ops->power_off) in dw_mipi_dsi_bridge_post_atomic_disable()
951 phy_ops->power_off(dsi->plat_data->priv_data); in dw_mipi_dsi_bridge_post_atomic_disable()
953 if (dsi->slave) { in dw_mipi_dsi_bridge_post_atomic_disable()
954 dw_mipi_dsi_disable(dsi->slave); in dw_mipi_dsi_bridge_post_atomic_disable()
955 clk_disable_unprepare(dsi->slave->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
956 pm_runtime_put(dsi->slave->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
958 dw_mipi_dsi_disable(dsi); in dw_mipi_dsi_bridge_post_atomic_disable()
960 clk_disable_unprepare(dsi->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
961 pm_runtime_put(dsi->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
964 static unsigned int dw_mipi_dsi_get_lanes(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_get_lanes() argument
967 if (dsi->master) in dw_mipi_dsi_get_lanes()
968 return dsi->master->lanes + dsi->lanes; in dw_mipi_dsi_get_lanes()
971 if (dsi->slave) in dw_mipi_dsi_get_lanes()
972 return dsi->lanes + dsi->slave->lanes; in dw_mipi_dsi_get_lanes()
974 /* single-dsi, so no other instance to consider */ in dw_mipi_dsi_get_lanes()
975 return dsi->lanes; in dw_mipi_dsi_get_lanes()
978 static void dw_mipi_dsi_mode_set(struct dw_mipi_dsi *dsi, in dw_mipi_dsi_mode_set() argument
981 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_mode_set()
982 void *priv_data = dsi->plat_data->priv_data; in dw_mipi_dsi_mode_set()
984 u32 lanes = dw_mipi_dsi_get_lanes(dsi); in dw_mipi_dsi_mode_set()
986 clk_prepare_enable(dsi->pclk); in dw_mipi_dsi_mode_set()
988 ret = phy_ops->get_lane_mbps(priv_data, adjusted_mode, dsi->mode_flags, in dw_mipi_dsi_mode_set()
989 lanes, dsi->format, &dsi->lane_mbps); in dw_mipi_dsi_mode_set()
993 pm_runtime_get_sync(dsi->dev); in dw_mipi_dsi_mode_set()
994 dw_mipi_dsi_init(dsi); in dw_mipi_dsi_mode_set()
995 dw_mipi_dsi_dpi_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
996 dw_mipi_dsi_packet_handler_config(dsi); in dw_mipi_dsi_mode_set()
997 dw_mipi_dsi_video_mode_config(dsi); in dw_mipi_dsi_mode_set()
998 dw_mipi_dsi_video_packet_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
999 dw_mipi_dsi_command_mode_config(dsi); in dw_mipi_dsi_mode_set()
1000 dw_mipi_dsi_line_timer_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
1001 dw_mipi_dsi_vertical_timing_config(dsi, adjusted_mode); in dw_mipi_dsi_mode_set()
1003 dw_mipi_dsi_dphy_init(dsi); in dw_mipi_dsi_mode_set()
1004 dw_mipi_dsi_dphy_timing_config(dsi); in dw_mipi_dsi_mode_set()
1005 dw_mipi_dsi_dphy_interface_config(dsi); in dw_mipi_dsi_mode_set()
1007 dw_mipi_dsi_clear_err(dsi); in dw_mipi_dsi_mode_set()
1009 ret = phy_ops->init(priv_data); in dw_mipi_dsi_mode_set()
1013 dw_mipi_dsi_dphy_enable(dsi); in dw_mipi_dsi_mode_set()
1017 /* Switch to cmd mode for panel-bridge pre_enable & panel prepare */ in dw_mipi_dsi_mode_set()
1018 dw_mipi_dsi_set_mode(dsi, 0); in dw_mipi_dsi_mode_set()
1020 if (phy_ops->power_on) in dw_mipi_dsi_mode_set()
1021 phy_ops->power_on(dsi->plat_data->priv_data); in dw_mipi_dsi_mode_set()
1027 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_pre_enable() local
1029 /* Power up the dsi ctl into a command mode */ in dw_mipi_dsi_bridge_atomic_pre_enable()
1030 dw_mipi_dsi_mode_set(dsi, &dsi->mode); in dw_mipi_dsi_bridge_atomic_pre_enable()
1031 if (dsi->slave) in dw_mipi_dsi_bridge_atomic_pre_enable()
1032 dw_mipi_dsi_mode_set(dsi->slave, &dsi->mode); in dw_mipi_dsi_bridge_atomic_pre_enable()
1039 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_mode_set() local
1042 drm_mode_copy(&dsi->mode, adjusted_mode); in dw_mipi_dsi_bridge_mode_set()
1048 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_atomic_enable() local
1050 /* Switch to video mode for panel-bridge enable & panel enable */ in dw_mipi_dsi_bridge_atomic_enable()
1051 dw_mipi_dsi_set_mode(dsi, MIPI_DSI_MODE_VIDEO); in dw_mipi_dsi_bridge_atomic_enable()
1052 if (dsi->slave) in dw_mipi_dsi_bridge_atomic_enable()
1053 dw_mipi_dsi_set_mode(dsi->slave, MIPI_DSI_MODE_VIDEO); in dw_mipi_dsi_bridge_atomic_enable()
1061 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_mode_valid() local
1062 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_bridge_mode_valid()
1065 if (pdata->mode_valid) in dw_mipi_dsi_bridge_mode_valid()
1066 mode_status = pdata->mode_valid(pdata->priv_data, mode, in dw_mipi_dsi_bridge_mode_valid()
1067 dsi->mode_flags, in dw_mipi_dsi_bridge_mode_valid()
1068 dw_mipi_dsi_get_lanes(dsi), in dw_mipi_dsi_bridge_mode_valid()
1069 dsi->format); in dw_mipi_dsi_bridge_mode_valid()
1077 struct dw_mipi_dsi *dsi = bridge_to_dsi(bridge); in dw_mipi_dsi_bridge_attach() local
1080 bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI; in dw_mipi_dsi_bridge_attach()
1082 /* Attach the panel-bridge to the dsi bridge */ in dw_mipi_dsi_bridge_attach()
1083 return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge, in dw_mipi_dsi_bridge_attach()
1106 struct dw_mipi_dsi *dsi; in dw_mipi_dsi_debugfs_write() local
1110 return -ENODEV; in dw_mipi_dsi_debugfs_write()
1112 dsi = vpg->dsi; in dw_mipi_dsi_debugfs_write()
1114 *vpg->reg = (bool)val; in dw_mipi_dsi_debugfs_write()
1116 mode_cfg = dsi_read(dsi, DSI_VID_MODE_CFG); in dw_mipi_dsi_debugfs_write()
1118 if (*vpg->reg) in dw_mipi_dsi_debugfs_write()
1119 mode_cfg |= vpg->mask; in dw_mipi_dsi_debugfs_write()
1121 mode_cfg &= ~vpg->mask; in dw_mipi_dsi_debugfs_write()
1123 dsi_write(dsi, DSI_VID_MODE_CFG, mode_cfg); in dw_mipi_dsi_debugfs_write()
1133 return -ENODEV; in dw_mipi_dsi_debugfs_show()
1135 *val = *vpg->reg; in dw_mipi_dsi_debugfs_show()
1145 struct dw_mipi_dsi *dsi = data; in debugfs_create_files() local
1147 REGISTER(vpg, VID_MODE_VPG_ENABLE, dsi), in debugfs_create_files()
1148 REGISTER(vpg_horizontal, VID_MODE_VPG_HORIZONTAL, dsi), in debugfs_create_files()
1149 REGISTER(vpg_ber_pattern, VID_MODE_VPG_MODE, dsi), in debugfs_create_files()
1153 dsi->debugfs_vpg = kmemdup(debugfs, sizeof(debugfs), GFP_KERNEL); in debugfs_create_files()
1154 if (!dsi->debugfs_vpg) in debugfs_create_files()
1158 debugfs_create_file(dsi->debugfs_vpg[i].name, 0644, in debugfs_create_files()
1159 dsi->debugfs, &dsi->debugfs_vpg[i], in debugfs_create_files()
1163 static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_debugfs_init() argument
1165 dsi->debugfs = debugfs_create_dir(dev_name(dsi->dev), NULL); in dw_mipi_dsi_debugfs_init()
1166 if (IS_ERR(dsi->debugfs)) { in dw_mipi_dsi_debugfs_init()
1167 dev_err(dsi->dev, "failed to create debugfs root\n"); in dw_mipi_dsi_debugfs_init()
1171 debugfs_create_files(dsi); in dw_mipi_dsi_debugfs_init()
1174 static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_debugfs_remove() argument
1176 debugfs_remove_recursive(dsi->debugfs); in dw_mipi_dsi_debugfs_remove()
1177 kfree(dsi->debugfs_vpg); in dw_mipi_dsi_debugfs_remove()
1182 static void dw_mipi_dsi_debugfs_init(struct dw_mipi_dsi *dsi) { } in dw_mipi_dsi_debugfs_init() argument
1183 static void dw_mipi_dsi_debugfs_remove(struct dw_mipi_dsi *dsi) { } in dw_mipi_dsi_debugfs_remove() argument
1191 struct device *dev = &pdev->dev; in __dw_mipi_dsi_probe()
1193 struct dw_mipi_dsi *dsi; in __dw_mipi_dsi_probe() local
1196 dsi = devm_kzalloc(dev, sizeof(*dsi), GFP_KERNEL); in __dw_mipi_dsi_probe()
1197 if (!dsi) in __dw_mipi_dsi_probe()
1198 return ERR_PTR(-ENOMEM); in __dw_mipi_dsi_probe()
1200 dsi->dev = dev; in __dw_mipi_dsi_probe()
1201 dsi->plat_data = plat_data; in __dw_mipi_dsi_probe()
1203 if (!plat_data->phy_ops->init || !plat_data->phy_ops->get_lane_mbps || in __dw_mipi_dsi_probe()
1204 !plat_data->phy_ops->get_timing) { in __dw_mipi_dsi_probe()
1206 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1209 if (!plat_data->base) { in __dw_mipi_dsi_probe()
1210 dsi->base = devm_platform_ioremap_resource(pdev, 0); in __dw_mipi_dsi_probe()
1211 if (IS_ERR(dsi->base)) in __dw_mipi_dsi_probe()
1212 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1215 dsi->base = plat_data->base; in __dw_mipi_dsi_probe()
1218 dsi->pclk = devm_clk_get(dev, "pclk"); in __dw_mipi_dsi_probe()
1219 if (IS_ERR(dsi->pclk)) { in __dw_mipi_dsi_probe()
1220 ret = PTR_ERR(dsi->pclk); in __dw_mipi_dsi_probe()
1233 if (ret != -EPROBE_DEFER) in __dw_mipi_dsi_probe()
1240 ret = clk_prepare_enable(dsi->pclk); in __dw_mipi_dsi_probe()
1250 clk_disable_unprepare(dsi->pclk); in __dw_mipi_dsi_probe()
1253 dw_mipi_dsi_debugfs_init(dsi); in __dw_mipi_dsi_probe()
1256 dsi->dsi_host.ops = &dw_mipi_dsi_host_ops; in __dw_mipi_dsi_probe()
1257 dsi->dsi_host.dev = dev; in __dw_mipi_dsi_probe()
1258 ret = mipi_dsi_host_register(&dsi->dsi_host); in __dw_mipi_dsi_probe()
1262 dw_mipi_dsi_debugfs_remove(dsi); in __dw_mipi_dsi_probe()
1266 dsi->bridge.driver_private = dsi; in __dw_mipi_dsi_probe()
1267 dsi->bridge.funcs = &dw_mipi_dsi_bridge_funcs; in __dw_mipi_dsi_probe()
1268 dsi->bridge.of_node = pdev->dev.of_node; in __dw_mipi_dsi_probe()
1270 return dsi; in __dw_mipi_dsi_probe()
1273 static void __dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) in __dw_mipi_dsi_remove() argument
1275 mipi_dsi_host_unregister(&dsi->dsi_host); in __dw_mipi_dsi_remove()
1277 pm_runtime_disable(dsi->dev); in __dw_mipi_dsi_remove()
1278 dw_mipi_dsi_debugfs_remove(dsi); in __dw_mipi_dsi_remove()
1281 void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave) in dw_mipi_dsi_set_slave() argument
1284 dsi->slave = slave; in dw_mipi_dsi_set_slave()
1285 dsi->slave->master = dsi; in dw_mipi_dsi_set_slave()
1288 dsi->slave->lanes = dsi->lanes; in dw_mipi_dsi_set_slave()
1289 dsi->slave->channel = dsi->channel; in dw_mipi_dsi_set_slave()
1290 dsi->slave->format = dsi->format; in dw_mipi_dsi_set_slave()
1291 dsi->slave->mode_flags = dsi->mode_flags; in dw_mipi_dsi_set_slave()
1295 struct drm_bridge *dw_mipi_dsi_get_bridge(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_get_bridge() argument
1297 return &dsi->bridge; in dw_mipi_dsi_get_bridge()
1302 * Probe/remove API, used from platforms based on the DRM bridge API.
1312 void dw_mipi_dsi_remove(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_remove() argument
1314 __dw_mipi_dsi_remove(dsi); in dw_mipi_dsi_remove()
1319 * Bind/unbind API, used from platforms based on the component framework.
1321 int dw_mipi_dsi_bind(struct dw_mipi_dsi *dsi, struct drm_encoder *encoder) in dw_mipi_dsi_bind() argument
1323 return drm_bridge_attach(encoder, &dsi->bridge, NULL, 0); in dw_mipi_dsi_bind()
1327 void dw_mipi_dsi_unbind(struct dw_mipi_dsi *dsi) in dw_mipi_dsi_unbind() argument
1332 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
1334 MODULE_DESCRIPTION("DW MIPI DSI host controller driver");
1336 MODULE_ALIAS("platform:dw-mipi-dsi");