Lines Matching +full:slave +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0+
8 * Rockchip version from rockchip/dw-mipi-dsi.c with phy & bridge APIs.
193 #define N_LANES(n) (((n) - 1) & 0x3)
265 struct dw_mipi_dsi *master; /* dual-dsi master ptr */
266 struct dw_mipi_dsi *slave; /* dual-dsi slave ptr */ member
272 * Check if either a link to a master or slave is present
276 return dsi->slave || dsi->master; in dw_mipi_is_dual_mode()
283 static void dw_mipi_dsi_wait_for_two_frames(const struct drm_display_mode *mode) in dw_mipi_dsi_wait_for_two_frames() argument
287 refresh = drm_mode_vrefresh(mode); in dw_mipi_dsi_wait_for_two_frames()
304 writel(val, dsi->base + reg); in dsi_write()
309 return readl(dsi->base + reg); in dsi_read()
316 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_attach()
320 if (device->lanes > dsi->plat_data->max_data_lanes) { in dw_mipi_dsi_host_attach()
321 dev_err(dsi->dev, "the number of data lanes(%u) is too many\n", in dw_mipi_dsi_host_attach()
322 device->lanes); in dw_mipi_dsi_host_attach()
323 return -EINVAL; in dw_mipi_dsi_host_attach()
326 dsi->lanes = device->lanes; in dw_mipi_dsi_host_attach()
327 dsi->channel = device->channel; in dw_mipi_dsi_host_attach()
328 dsi->format = device->format; in dw_mipi_dsi_host_attach()
329 dsi->mode_flags = device->mode_flags; in dw_mipi_dsi_host_attach()
331 bridge = devm_drm_of_get_bridge(dsi->dev, dsi->dev->of_node, 1, 0); in dw_mipi_dsi_host_attach()
335 dsi->panel_bridge = bridge; in dw_mipi_dsi_host_attach()
337 drm_bridge_add(&dsi->bridge); in dw_mipi_dsi_host_attach()
339 if (pdata->host_ops && pdata->host_ops->attach) { in dw_mipi_dsi_host_attach()
340 ret = pdata->host_ops->attach(pdata->priv_data, device); in dw_mipi_dsi_host_attach()
352 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_host_detach()
355 if (pdata->host_ops && pdata->host_ops->detach) { in dw_mipi_dsi_host_detach()
356 ret = pdata->host_ops->detach(pdata->priv_data, device); in dw_mipi_dsi_host_detach()
361 drm_of_panel_bridge_remove(host->dev->of_node, 1, 0); in dw_mipi_dsi_host_detach()
363 drm_bridge_remove(&dsi->bridge); in dw_mipi_dsi_host_detach()
371 bool lpm = msg->flags & MIPI_DSI_MSG_USE_LPM; in dw_mipi_message_config()
383 if (msg->flags & MIPI_DSI_MSG_REQ_ACK) in dw_mipi_message_config()
403 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
407 dev_err(dsi->dev, "failed to get available command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
414 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_gen_pkt_hdr_write()
418 dev_err(dsi->dev, "failed to write command FIFO\n"); in dw_mipi_dsi_gen_pkt_hdr_write()
428 const u8 *tx_buf = packet->payload; in dw_mipi_dsi_write()
429 int len = packet->payload_length, pld_data_bytes = sizeof(u32), ret; in dw_mipi_dsi_write()
443 len -= pld_data_bytes; in dw_mipi_dsi_write()
446 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_write()
450 dev_err(dsi->dev, in dw_mipi_dsi_write()
457 memcpy(&word, packet->header, sizeof(packet->header)); in dw_mipi_dsi_write()
464 int i, j, ret, len = msg->rx_len; in dw_mipi_dsi_read()
465 u8 *buf = msg->rx_buf; in dw_mipi_dsi_read()
469 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
473 dev_err(dsi->dev, "Timeout during read operation\n"); in dw_mipi_dsi_read()
479 ret = readl_poll_timeout(dsi->base + DSI_CMD_PKT_STATUS, in dw_mipi_dsi_read()
483 dev_err(dsi->dev, "Read payload FIFO is empty\n"); in dw_mipi_dsi_read()
504 dev_err(dsi->dev, "failed to create packet: %d\n", ret); in dw_mipi_dsi_host_transfer()
509 if (dsi->slave) in dw_mipi_dsi_host_transfer()
510 dw_mipi_message_config(dsi->slave, msg); in dw_mipi_dsi_host_transfer()
515 if (dsi->slave) { in dw_mipi_dsi_host_transfer()
516 ret = dw_mipi_dsi_write(dsi->slave, &packet); in dw_mipi_dsi_host_transfer()
521 if (msg->rx_buf && msg->rx_len) { in dw_mipi_dsi_host_transfer()
525 nb_bytes = msg->rx_len; in dw_mipi_dsi_host_transfer()
545 * enabling low power is panel-dependent, we should use the in dw_mipi_dsi_video_mode_config()
550 if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_BURST) in dw_mipi_dsi_video_mode_config()
552 else if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) in dw_mipi_dsi_video_mode_config()
558 if (dsi->vpg_defs.vpg) { in dw_mipi_dsi_video_mode_config()
560 val |= dsi->vpg_defs.vpg_horizontal ? in dw_mipi_dsi_video_mode_config()
562 val |= dsi->vpg_defs.vpg_ber_pattern ? VID_MODE_VPG_MODE : 0; in dw_mipi_dsi_video_mode_config()
584 if (dsi->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) in dw_mipi_dsi_set_mode()
599 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_init()
608 if (phy_ops->get_esc_clk_rate) { in dw_mipi_dsi_init()
609 ret = phy_ops->get_esc_clk_rate(dsi->plat_data->priv_data, in dw_mipi_dsi_init()
622 esc_clk_division = (dsi->lane_mbps >> 3) / esc_rate + 1; in dw_mipi_dsi_init()
636 const struct drm_display_mode *mode) in dw_mipi_dsi_dpi_config() argument
640 switch (dsi->format) { in dw_mipi_dsi_dpi_config()
655 if (mode->flags & DRM_MODE_FLAG_NVSYNC) in dw_mipi_dsi_dpi_config()
657 if (mode->flags & DRM_MODE_FLAG_NHSYNC) in dw_mipi_dsi_dpi_config()
660 dsi_write(dsi, DSI_DPI_VCID, DPI_VCID(dsi->channel)); in dw_mipi_dsi_dpi_config()
671 const struct drm_display_mode *mode) in dw_mipi_dsi_video_packet_config() argument
675 * only burst mode is supported here. For non-burst video modes, in dw_mipi_dsi_video_packet_config()
678 * non-burst video modes, see dw_mipi_dsi_video_mode_config()... in dw_mipi_dsi_video_packet_config()
683 VID_PKT_SIZE(mode->hdisplay / 2) : in dw_mipi_dsi_video_packet_config()
684 VID_PKT_SIZE(mode->hdisplay)); in dw_mipi_dsi_video_packet_config()
697 * the Bus-Turn-Around Timeout Counter should be computed in dw_mipi_dsi_command_mode_config()
706 const struct drm_display_mode *mode, in dw_mipi_dsi_get_hcomponent_lbcc() argument
711 lbcc = hcomponent * dsi->lane_mbps * MSEC_PER_SEC / 8; in dw_mipi_dsi_get_hcomponent_lbcc()
713 frac = lbcc % mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
714 lbcc = lbcc / mode->clock; in dw_mipi_dsi_get_hcomponent_lbcc()
722 const struct drm_display_mode *mode) in dw_mipi_dsi_line_timer_config() argument
726 htotal = mode->htotal; in dw_mipi_dsi_line_timer_config()
727 hsa = mode->hsync_end - mode->hsync_start; in dw_mipi_dsi_line_timer_config()
728 hbp = mode->htotal - mode->hsync_end; in dw_mipi_dsi_line_timer_config()
734 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, htotal); in dw_mipi_dsi_line_timer_config()
737 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hsa); in dw_mipi_dsi_line_timer_config()
740 lbcc = dw_mipi_dsi_get_hcomponent_lbcc(dsi, mode, hbp); in dw_mipi_dsi_line_timer_config()
745 const struct drm_display_mode *mode) in dw_mipi_dsi_vertical_timing_config() argument
749 vactive = mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
750 vsa = mode->vsync_end - mode->vsync_start; in dw_mipi_dsi_vertical_timing_config()
751 vfp = mode->vsync_start - mode->vdisplay; in dw_mipi_dsi_vertical_timing_config()
752 vbp = mode->vtotal - mode->vsync_end; in dw_mipi_dsi_vertical_timing_config()
762 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_dphy_timing_config()
767 ret = phy_ops->get_timing(dsi->plat_data->priv_data, in dw_mipi_dsi_dphy_timing_config()
768 dsi->lane_mbps, &timing); in dw_mipi_dsi_dphy_timing_config()
770 DRM_DEV_ERROR(dsi->dev, "Retrieving phy timings failed\n"); in dw_mipi_dsi_dphy_timing_config()
775 * blankings and to the automatic clock lane control mode... in dw_mipi_dsi_dphy_timing_config()
807 N_LANES(dsi->lanes)); in dw_mipi_dsi_dphy_interface_config()
828 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, val, in dw_mipi_dsi_dphy_enable()
833 ret = readl_poll_timeout(dsi->base + DSI_PHY_STATUS, in dw_mipi_dsi_dphy_enable()
852 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_bridge_post_atomic_disable()
855 * Switch to command mode before panel-bridge post_disable & in dw_mipi_dsi_bridge_post_atomic_disable()
857 * Note: panel-bridge disable & panel disable has been called in dw_mipi_dsi_bridge_post_atomic_disable()
863 * TODO Only way found to call panel-bridge post_disable & in dw_mipi_dsi_bridge_post_atomic_disable()
868 if (dsi->panel_bridge->funcs->post_disable) in dw_mipi_dsi_bridge_post_atomic_disable()
869 dsi->panel_bridge->funcs->post_disable(dsi->panel_bridge); in dw_mipi_dsi_bridge_post_atomic_disable()
871 if (phy_ops->power_off) in dw_mipi_dsi_bridge_post_atomic_disable()
872 phy_ops->power_off(dsi->plat_data->priv_data); in dw_mipi_dsi_bridge_post_atomic_disable()
874 if (dsi->slave) { in dw_mipi_dsi_bridge_post_atomic_disable()
875 dw_mipi_dsi_disable(dsi->slave); in dw_mipi_dsi_bridge_post_atomic_disable()
876 clk_disable_unprepare(dsi->slave->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
877 pm_runtime_put(dsi->slave->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
881 clk_disable_unprepare(dsi->pclk); in dw_mipi_dsi_bridge_post_atomic_disable()
882 pm_runtime_put(dsi->dev); in dw_mipi_dsi_bridge_post_atomic_disable()
887 /* this instance is the slave, so add the master's lanes */ in dw_mipi_dsi_get_lanes()
888 if (dsi->master) in dw_mipi_dsi_get_lanes()
889 return dsi->master->lanes + dsi->lanes; in dw_mipi_dsi_get_lanes()
891 /* this instance is the master, so add the slave's lanes */ in dw_mipi_dsi_get_lanes()
892 if (dsi->slave) in dw_mipi_dsi_get_lanes()
893 return dsi->lanes + dsi->slave->lanes; in dw_mipi_dsi_get_lanes()
895 /* single-dsi, so no other instance to consider */ in dw_mipi_dsi_get_lanes()
896 return dsi->lanes; in dw_mipi_dsi_get_lanes()
902 const struct dw_mipi_dsi_phy_ops *phy_ops = dsi->plat_data->phy_ops; in dw_mipi_dsi_mode_set()
903 void *priv_data = dsi->plat_data->priv_data; in dw_mipi_dsi_mode_set()
907 clk_prepare_enable(dsi->pclk); in dw_mipi_dsi_mode_set()
909 ret = phy_ops->get_lane_mbps(priv_data, adjusted_mode, dsi->mode_flags, in dw_mipi_dsi_mode_set()
910 lanes, dsi->format, &dsi->lane_mbps); in dw_mipi_dsi_mode_set()
914 pm_runtime_get_sync(dsi->dev); in dw_mipi_dsi_mode_set()
930 ret = phy_ops->init(priv_data); in dw_mipi_dsi_mode_set()
938 /* Switch to cmd mode for panel-bridge pre_enable & panel prepare */ in dw_mipi_dsi_mode_set()
941 if (phy_ops->power_on) in dw_mipi_dsi_mode_set()
942 phy_ops->power_on(dsi->plat_data->priv_data); in dw_mipi_dsi_mode_set()
946 const struct drm_display_mode *mode, in dw_mipi_dsi_bridge_mode_set() argument
952 if (dsi->slave) in dw_mipi_dsi_bridge_mode_set()
953 dw_mipi_dsi_mode_set(dsi->slave, adjusted_mode); in dw_mipi_dsi_bridge_mode_set()
961 /* Switch to video mode for panel-bridge enable & panel enable */ in dw_mipi_dsi_bridge_atomic_enable()
963 if (dsi->slave) in dw_mipi_dsi_bridge_atomic_enable()
964 dw_mipi_dsi_set_mode(dsi->slave, MIPI_DSI_MODE_VIDEO); in dw_mipi_dsi_bridge_atomic_enable()
970 const struct drm_display_mode *mode) in dw_mipi_dsi_bridge_mode_valid() argument
973 const struct dw_mipi_dsi_plat_data *pdata = dsi->plat_data; in dw_mipi_dsi_bridge_mode_valid()
976 if (pdata->mode_valid) in dw_mipi_dsi_bridge_mode_valid()
977 mode_status = pdata->mode_valid(pdata->priv_data, mode, in dw_mipi_dsi_bridge_mode_valid()
978 dsi->mode_flags, in dw_mipi_dsi_bridge_mode_valid()
980 dsi->format); in dw_mipi_dsi_bridge_mode_valid()
990 if (!bridge->encoder) { in dw_mipi_dsi_bridge_attach()
992 return -ENODEV; in dw_mipi_dsi_bridge_attach()
996 bridge->encoder->encoder_type = DRM_MODE_ENCODER_DSI; in dw_mipi_dsi_bridge_attach()
998 /* Attach the panel-bridge to the dsi bridge */ in dw_mipi_dsi_bridge_attach()
999 return drm_bridge_attach(bridge->encoder, dsi->panel_bridge, bridge, in dw_mipi_dsi_bridge_attach()
1023 return -ENODEV; in dw_mipi_dsi_debugfs_write()
1025 dsi = vpg->dsi; in dw_mipi_dsi_debugfs_write()
1027 *vpg->reg = (bool)val; in dw_mipi_dsi_debugfs_write()
1031 if (*vpg->reg) in dw_mipi_dsi_debugfs_write()
1032 mode_cfg |= vpg->mask; in dw_mipi_dsi_debugfs_write()
1034 mode_cfg &= ~vpg->mask; in dw_mipi_dsi_debugfs_write()
1046 return -ENODEV; in dw_mipi_dsi_debugfs_show()
1048 *val = *vpg->reg; in dw_mipi_dsi_debugfs_show()
1066 dsi->debugfs_vpg = kmemdup(debugfs, sizeof(debugfs), GFP_KERNEL); in debugfs_create_files()
1067 if (!dsi->debugfs_vpg) in debugfs_create_files()
1071 debugfs_create_file(dsi->debugfs_vpg[i].name, 0644, in debugfs_create_files()
1072 dsi->debugfs, &dsi->debugfs_vpg[i], in debugfs_create_files()
1078 dsi->debugfs = debugfs_create_dir(dev_name(dsi->dev), NULL); in dw_mipi_dsi_debugfs_init()
1079 if (IS_ERR(dsi->debugfs)) { in dw_mipi_dsi_debugfs_init()
1080 dev_err(dsi->dev, "failed to create debugfs root\n"); in dw_mipi_dsi_debugfs_init()
1089 debugfs_remove_recursive(dsi->debugfs); in dw_mipi_dsi_debugfs_remove()
1090 kfree(dsi->debugfs_vpg); in dw_mipi_dsi_debugfs_remove()
1104 struct device *dev = &pdev->dev; in __dw_mipi_dsi_probe()
1111 return ERR_PTR(-ENOMEM); in __dw_mipi_dsi_probe()
1113 dsi->dev = dev; in __dw_mipi_dsi_probe()
1114 dsi->plat_data = plat_data; in __dw_mipi_dsi_probe()
1116 if (!plat_data->phy_ops->init || !plat_data->phy_ops->get_lane_mbps || in __dw_mipi_dsi_probe()
1117 !plat_data->phy_ops->get_timing) { in __dw_mipi_dsi_probe()
1119 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1122 if (!plat_data->base) { in __dw_mipi_dsi_probe()
1123 dsi->base = devm_platform_ioremap_resource(pdev, 0); in __dw_mipi_dsi_probe()
1124 if (IS_ERR(dsi->base)) in __dw_mipi_dsi_probe()
1125 return ERR_PTR(-ENODEV); in __dw_mipi_dsi_probe()
1128 dsi->base = plat_data->base; in __dw_mipi_dsi_probe()
1131 dsi->pclk = devm_clk_get(dev, "pclk"); in __dw_mipi_dsi_probe()
1132 if (IS_ERR(dsi->pclk)) { in __dw_mipi_dsi_probe()
1133 ret = PTR_ERR(dsi->pclk); in __dw_mipi_dsi_probe()
1146 if (ret != -EPROBE_DEFER) in __dw_mipi_dsi_probe()
1153 ret = clk_prepare_enable(dsi->pclk); in __dw_mipi_dsi_probe()
1163 clk_disable_unprepare(dsi->pclk); in __dw_mipi_dsi_probe()
1169 dsi->dsi_host.ops = &dw_mipi_dsi_host_ops; in __dw_mipi_dsi_probe()
1170 dsi->dsi_host.dev = dev; in __dw_mipi_dsi_probe()
1171 ret = mipi_dsi_host_register(&dsi->dsi_host); in __dw_mipi_dsi_probe()
1179 dsi->bridge.driver_private = dsi; in __dw_mipi_dsi_probe()
1180 dsi->bridge.funcs = &dw_mipi_dsi_bridge_funcs; in __dw_mipi_dsi_probe()
1182 dsi->bridge.of_node = pdev->dev.of_node; in __dw_mipi_dsi_probe()
1190 mipi_dsi_host_unregister(&dsi->dsi_host); in __dw_mipi_dsi_remove()
1192 pm_runtime_disable(dsi->dev); in __dw_mipi_dsi_remove()
1196 void dw_mipi_dsi_set_slave(struct dw_mipi_dsi *dsi, struct dw_mipi_dsi *slave) in dw_mipi_dsi_set_slave() argument
1199 dsi->slave = slave; in dw_mipi_dsi_set_slave()
1200 dsi->slave->master = dsi; in dw_mipi_dsi_set_slave()
1203 dsi->slave->lanes = dsi->lanes; in dw_mipi_dsi_set_slave()
1204 dsi->slave->channel = dsi->channel; in dw_mipi_dsi_set_slave()
1205 dsi->slave->format = dsi->format; in dw_mipi_dsi_set_slave()
1206 dsi->slave->mode_flags = dsi->mode_flags; in dw_mipi_dsi_set_slave()
1232 return drm_bridge_attach(encoder, &dsi->bridge, NULL, 0); in dw_mipi_dsi_bind()
1241 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
1245 MODULE_ALIAS("platform:dw-mipi-dsi");