Lines Matching +full:sync +full:- +full:dual +full:- +full:dsi
1 // SPDX-License-Identifier: GPL-2.0-only
29 #include "dsi.h"
30 #include "mipi-phy.h"
81 /* for ganged-mode support */
102 static struct tegra_dsi_state *tegra_dsi_get_state(struct tegra_dsi *dsi) in tegra_dsi_get_state() argument
104 return to_dsi_state(dsi->output.connector.state); in tegra_dsi_get_state()
107 static inline u32 tegra_dsi_readl(struct tegra_dsi *dsi, unsigned int offset) in tegra_dsi_readl() argument
109 u32 value = readl(dsi->regs + (offset << 2)); in tegra_dsi_readl()
111 trace_dsi_readl(dsi->dev, offset, value); in tegra_dsi_readl()
116 static inline void tegra_dsi_writel(struct tegra_dsi *dsi, u32 value, in tegra_dsi_writel() argument
119 trace_dsi_writel(dsi->dev, offset, value); in tegra_dsi_writel()
120 writel(value, dsi->regs + (offset << 2)); in tegra_dsi_writel()
201 struct drm_info_node *node = s->private; in tegra_dsi_show_regs()
202 struct tegra_dsi *dsi = node->info_ent->data; in tegra_dsi_show_regs() local
203 struct drm_crtc *crtc = dsi->output.encoder.crtc; in tegra_dsi_show_regs()
204 struct drm_device *drm = node->minor->dev; in tegra_dsi_show_regs()
210 if (!crtc || !crtc->state->active) { in tegra_dsi_show_regs()
211 err = -EBUSY; in tegra_dsi_show_regs()
218 seq_printf(s, "%-32s %#05x %08x\n", tegra_dsi_regs[i].name, in tegra_dsi_show_regs()
219 offset, tegra_dsi_readl(dsi, offset)); in tegra_dsi_show_regs()
235 struct drm_minor *minor = connector->dev->primary; in tegra_dsi_late_register()
236 struct dentry *root = connector->debugfs_entry; in tegra_dsi_late_register()
237 struct tegra_dsi *dsi = to_dsi(output); in tegra_dsi_late_register() local
239 dsi->debugfs_files = kmemdup(debugfs_files, sizeof(debugfs_files), in tegra_dsi_late_register()
241 if (!dsi->debugfs_files) in tegra_dsi_late_register()
242 return -ENOMEM; in tegra_dsi_late_register()
245 dsi->debugfs_files[i].data = dsi; in tegra_dsi_late_register()
247 drm_debugfs_create_files(dsi->debugfs_files, count, root, minor); in tegra_dsi_late_register()
256 struct tegra_dsi *dsi = to_dsi(output); in tegra_dsi_early_unregister() local
258 drm_debugfs_remove_files(dsi->debugfs_files, count, in tegra_dsi_early_unregister()
259 connector->debugfs_entry, in tegra_dsi_early_unregister()
260 connector->dev->primary); in tegra_dsi_early_unregister()
261 kfree(dsi->debugfs_files); in tegra_dsi_early_unregister()
262 dsi->debugfs_files = NULL; in tegra_dsi_early_unregister()
276 * non-burst mode with sync pulses
314 * non-burst mode with sync events
358 static void tegra_dsi_set_phy_timing(struct tegra_dsi *dsi, in tegra_dsi_set_phy_timing() argument
364 value = DSI_TIMING_FIELD(timing->hsexit, period, 1) << 24 | in tegra_dsi_set_phy_timing()
365 DSI_TIMING_FIELD(timing->hstrail, period, 0) << 16 | in tegra_dsi_set_phy_timing()
366 DSI_TIMING_FIELD(timing->hszero, period, 3) << 8 | in tegra_dsi_set_phy_timing()
367 DSI_TIMING_FIELD(timing->hsprepare, period, 1); in tegra_dsi_set_phy_timing()
368 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_0); in tegra_dsi_set_phy_timing()
370 value = DSI_TIMING_FIELD(timing->clktrail, period, 1) << 24 | in tegra_dsi_set_phy_timing()
371 DSI_TIMING_FIELD(timing->clkpost, period, 1) << 16 | in tegra_dsi_set_phy_timing()
372 DSI_TIMING_FIELD(timing->clkzero, period, 1) << 8 | in tegra_dsi_set_phy_timing()
373 DSI_TIMING_FIELD(timing->lpx, period, 1); in tegra_dsi_set_phy_timing()
374 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_1); in tegra_dsi_set_phy_timing()
376 value = DSI_TIMING_FIELD(timing->clkprepare, period, 1) << 16 | in tegra_dsi_set_phy_timing()
377 DSI_TIMING_FIELD(timing->clkpre, period, 1) << 8 | in tegra_dsi_set_phy_timing()
379 tegra_dsi_writel(dsi, value, DSI_PHY_TIMING_2); in tegra_dsi_set_phy_timing()
381 value = DSI_TIMING_FIELD(timing->taget, period, 1) << 16 | in tegra_dsi_set_phy_timing()
382 DSI_TIMING_FIELD(timing->tasure, period, 1) << 8 | in tegra_dsi_set_phy_timing()
383 DSI_TIMING_FIELD(timing->tago, period, 1); in tegra_dsi_set_phy_timing()
384 tegra_dsi_writel(dsi, value, DSI_BTA_TIMING); in tegra_dsi_set_phy_timing()
386 if (dsi->slave) in tegra_dsi_set_phy_timing()
387 tegra_dsi_set_phy_timing(dsi->slave, period, timing); in tegra_dsi_set_phy_timing()
411 return -EINVAL; in tegra_dsi_get_muldiv()
438 return -EINVAL; in tegra_dsi_get_format()
444 static void tegra_dsi_ganged_enable(struct tegra_dsi *dsi, unsigned int start, in tegra_dsi_ganged_enable() argument
449 tegra_dsi_writel(dsi, start, DSI_GANGED_MODE_START); in tegra_dsi_ganged_enable()
450 tegra_dsi_writel(dsi, size << 16 | size, DSI_GANGED_MODE_SIZE); in tegra_dsi_ganged_enable()
453 tegra_dsi_writel(dsi, value, DSI_GANGED_MODE_CONTROL); in tegra_dsi_ganged_enable()
456 static void tegra_dsi_enable(struct tegra_dsi *dsi) in tegra_dsi_enable() argument
460 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); in tegra_dsi_enable()
462 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); in tegra_dsi_enable()
464 if (dsi->slave) in tegra_dsi_enable()
465 tegra_dsi_enable(dsi->slave); in tegra_dsi_enable()
468 static unsigned int tegra_dsi_get_lanes(struct tegra_dsi *dsi) in tegra_dsi_get_lanes() argument
470 if (dsi->master) in tegra_dsi_get_lanes()
471 return dsi->master->lanes + dsi->lanes; in tegra_dsi_get_lanes()
473 if (dsi->slave) in tegra_dsi_get_lanes()
474 return dsi->lanes + dsi->slave->lanes; in tegra_dsi_get_lanes()
476 return dsi->lanes; in tegra_dsi_get_lanes()
479 static void tegra_dsi_configure(struct tegra_dsi *dsi, unsigned int pipe, in tegra_dsi_configure() argument
488 if (dsi->master) in tegra_dsi_configure()
489 state = tegra_dsi_get_state(dsi->master); in tegra_dsi_configure()
491 state = tegra_dsi_get_state(dsi); in tegra_dsi_configure()
493 mul = state->mul; in tegra_dsi_configure()
494 div = state->div; in tegra_dsi_configure()
496 if (dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) { in tegra_dsi_configure()
497 DRM_DEBUG_KMS("Non-burst video mode with sync pulses\n"); in tegra_dsi_configure()
499 } else if (dsi->flags & MIPI_DSI_MODE_VIDEO) { in tegra_dsi_configure()
500 DRM_DEBUG_KMS("Non-burst video mode with sync events\n"); in tegra_dsi_configure()
508 DSI_CONTROL_FORMAT(state->format) | in tegra_dsi_configure()
509 DSI_CONTROL_LANES(dsi->lanes - 1) | in tegra_dsi_configure()
511 tegra_dsi_writel(dsi, value, DSI_CONTROL); in tegra_dsi_configure()
513 tegra_dsi_writel(dsi, dsi->video_fifo_depth, DSI_MAX_THRESHOLD); in tegra_dsi_configure()
516 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); in tegra_dsi_configure()
518 value = tegra_dsi_readl(dsi, DSI_CONTROL); in tegra_dsi_configure()
520 if (dsi->flags & MIPI_DSI_CLOCK_NON_CONTINUOUS) in tegra_dsi_configure()
526 if (dsi->flags & MIPI_DSI_MODE_VIDEO) in tegra_dsi_configure()
533 tegra_dsi_writel(dsi, value, DSI_CONTROL); in tegra_dsi_configure()
536 tegra_dsi_writel(dsi, pkt_seq[i], DSI_PKT_SEQ_0_LO + i); in tegra_dsi_configure()
538 if (dsi->flags & MIPI_DSI_MODE_VIDEO) { in tegra_dsi_configure()
540 hact = mode->hdisplay * mul / div; in tegra_dsi_configure()
542 /* horizontal sync width */ in tegra_dsi_configure()
543 hsw = (mode->hsync_end - mode->hsync_start) * mul / div; in tegra_dsi_configure()
546 hbp = (mode->htotal - mode->hsync_end) * mul / div; in tegra_dsi_configure()
548 if ((dsi->flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE) == 0) in tegra_dsi_configure()
552 hfp = (mode->hsync_start - mode->hdisplay) * mul / div; in tegra_dsi_configure()
555 hsw -= 10; in tegra_dsi_configure()
556 hbp -= 14; in tegra_dsi_configure()
557 hfp -= 8; in tegra_dsi_configure()
559 tegra_dsi_writel(dsi, hsw << 16 | 0, DSI_PKT_LEN_0_1); in tegra_dsi_configure()
560 tegra_dsi_writel(dsi, hact << 16 | hbp, DSI_PKT_LEN_2_3); in tegra_dsi_configure()
561 tegra_dsi_writel(dsi, hfp, DSI_PKT_LEN_4_5); in tegra_dsi_configure()
562 tegra_dsi_writel(dsi, 0x0f0f << 16, DSI_PKT_LEN_6_7); in tegra_dsi_configure()
564 /* set SOL delay (for non-burst mode only) */ in tegra_dsi_configure()
565 tegra_dsi_writel(dsi, 8 * mul / div, DSI_SOL_DELAY); in tegra_dsi_configure()
571 if (dsi->master || dsi->slave) { in tegra_dsi_configure()
573 * For ganged mode, assume symmetric left-right mode. in tegra_dsi_configure()
575 bytes = 1 + (mode->hdisplay / 2) * mul / div; in tegra_dsi_configure()
578 bytes = 1 + mode->hdisplay * mul / div; in tegra_dsi_configure()
581 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_0_1); in tegra_dsi_configure()
582 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_2_3); in tegra_dsi_configure()
583 tegra_dsi_writel(dsi, bytes << 16, DSI_PKT_LEN_4_5); in tegra_dsi_configure()
584 tegra_dsi_writel(dsi, 0, DSI_PKT_LEN_6_7); in tegra_dsi_configure()
588 tegra_dsi_writel(dsi, value, DSI_DCS_CMDS); in tegra_dsi_configure()
591 if (dsi->master || dsi->slave) { in tegra_dsi_configure()
593 unsigned int lanes = state->lanes; in tegra_dsi_configure()
601 bclk = DIV_ROUND_UP(mode->htotal * mul, div * lanes); in tegra_dsi_configure()
603 value = bclk - bclk_ganged + delay + 20; in tegra_dsi_configure()
605 /* TODO: revisit for non-ganged mode */ in tegra_dsi_configure()
609 tegra_dsi_writel(dsi, value, DSI_SOL_DELAY); in tegra_dsi_configure()
612 if (dsi->slave) { in tegra_dsi_configure()
613 tegra_dsi_configure(dsi->slave, pipe, mode); in tegra_dsi_configure()
616 * TODO: Support modes other than symmetrical left-right in tegra_dsi_configure()
619 tegra_dsi_ganged_enable(dsi, 0, mode->hdisplay / 2); in tegra_dsi_configure()
620 tegra_dsi_ganged_enable(dsi->slave, mode->hdisplay / 2, in tegra_dsi_configure()
621 mode->hdisplay / 2); in tegra_dsi_configure()
625 static int tegra_dsi_wait_idle(struct tegra_dsi *dsi, unsigned long timeout) in tegra_dsi_wait_idle() argument
632 value = tegra_dsi_readl(dsi, DSI_STATUS); in tegra_dsi_wait_idle()
639 return -ETIMEDOUT; in tegra_dsi_wait_idle()
642 static void tegra_dsi_video_disable(struct tegra_dsi *dsi) in tegra_dsi_video_disable() argument
646 value = tegra_dsi_readl(dsi, DSI_CONTROL); in tegra_dsi_video_disable()
648 tegra_dsi_writel(dsi, value, DSI_CONTROL); in tegra_dsi_video_disable()
650 if (dsi->slave) in tegra_dsi_video_disable()
651 tegra_dsi_video_disable(dsi->slave); in tegra_dsi_video_disable()
654 static void tegra_dsi_ganged_disable(struct tegra_dsi *dsi) in tegra_dsi_ganged_disable() argument
656 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_START); in tegra_dsi_ganged_disable()
657 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_SIZE); in tegra_dsi_ganged_disable()
658 tegra_dsi_writel(dsi, 0, DSI_GANGED_MODE_CONTROL); in tegra_dsi_ganged_disable()
661 static int tegra_dsi_pad_enable(struct tegra_dsi *dsi) in tegra_dsi_pad_enable() argument
666 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_0); in tegra_dsi_pad_enable()
671 static int tegra_dsi_pad_calibrate(struct tegra_dsi *dsi) in tegra_dsi_pad_calibrate() argument
680 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_0); in tegra_dsi_pad_calibrate()
681 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_1); in tegra_dsi_pad_calibrate()
682 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_2); in tegra_dsi_pad_calibrate()
683 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_3); in tegra_dsi_pad_calibrate()
684 tegra_dsi_writel(dsi, 0, DSI_PAD_CONTROL_4); in tegra_dsi_pad_calibrate()
687 tegra_dsi_pad_enable(dsi); in tegra_dsi_pad_calibrate()
692 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_2); in tegra_dsi_pad_calibrate()
696 tegra_dsi_writel(dsi, value, DSI_PAD_CONTROL_3); in tegra_dsi_pad_calibrate()
698 err = tegra_mipi_start_calibration(dsi->mipi); in tegra_dsi_pad_calibrate()
702 return tegra_mipi_finish_calibration(dsi->mipi); in tegra_dsi_pad_calibrate()
705 static void tegra_dsi_set_timeout(struct tegra_dsi *dsi, unsigned long bclk, in tegra_dsi_set_timeout() argument
711 /* one frame high-speed transmission timeout */ in tegra_dsi_set_timeout()
714 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_0); in tegra_dsi_set_timeout()
719 tegra_dsi_writel(dsi, value, DSI_TIMEOUT_1); in tegra_dsi_set_timeout()
722 tegra_dsi_writel(dsi, value, DSI_TO_TALLY); in tegra_dsi_set_timeout()
724 if (dsi->slave) in tegra_dsi_set_timeout()
725 tegra_dsi_set_timeout(dsi->slave, bclk, vrefresh); in tegra_dsi_set_timeout()
728 static void tegra_dsi_disable(struct tegra_dsi *dsi) in tegra_dsi_disable() argument
732 if (dsi->slave) { in tegra_dsi_disable()
733 tegra_dsi_ganged_disable(dsi->slave); in tegra_dsi_disable()
734 tegra_dsi_ganged_disable(dsi); in tegra_dsi_disable()
737 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); in tegra_dsi_disable()
739 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); in tegra_dsi_disable()
741 if (dsi->slave) in tegra_dsi_disable()
742 tegra_dsi_disable(dsi->slave); in tegra_dsi_disable()
747 static void tegra_dsi_soft_reset(struct tegra_dsi *dsi) in tegra_dsi_soft_reset() argument
751 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); in tegra_dsi_soft_reset()
753 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); in tegra_dsi_soft_reset()
757 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); in tegra_dsi_soft_reset()
759 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); in tegra_dsi_soft_reset()
763 value = tegra_dsi_readl(dsi, DSI_TRIGGER); in tegra_dsi_soft_reset()
765 tegra_dsi_writel(dsi, 0, DSI_TRIGGER); in tegra_dsi_soft_reset()
767 if (dsi->slave) in tegra_dsi_soft_reset()
768 tegra_dsi_soft_reset(dsi->slave); in tegra_dsi_soft_reset()
778 if (connector->state) { in tegra_dsi_connector_reset()
779 __drm_atomic_helper_connector_destroy_state(connector->state); in tegra_dsi_connector_reset()
780 kfree(connector->state); in tegra_dsi_connector_reset()
783 __drm_atomic_helper_connector_reset(connector, &state->base); in tegra_dsi_connector_reset()
789 struct tegra_dsi_state *state = to_dsi_state(connector->state); in tegra_dsi_connector_duplicate_state()
797 ©->base); in tegra_dsi_connector_duplicate_state()
799 return ©->base; in tegra_dsi_connector_duplicate_state()
825 static void tegra_dsi_unprepare(struct tegra_dsi *dsi) in tegra_dsi_unprepare() argument
829 if (dsi->slave) in tegra_dsi_unprepare()
830 tegra_dsi_unprepare(dsi->slave); in tegra_dsi_unprepare()
832 err = tegra_mipi_disable(dsi->mipi); in tegra_dsi_unprepare()
834 dev_err(dsi->dev, "failed to disable MIPI calibration: %d\n", in tegra_dsi_unprepare()
837 err = host1x_client_suspend(&dsi->client); in tegra_dsi_unprepare()
839 dev_err(dsi->dev, "failed to suspend: %d\n", err); in tegra_dsi_unprepare()
845 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_dsi_encoder_disable()
846 struct tegra_dsi *dsi = to_dsi(output); in tegra_dsi_encoder_disable() local
850 if (output->panel) in tegra_dsi_encoder_disable()
851 drm_panel_disable(output->panel); in tegra_dsi_encoder_disable()
853 tegra_dsi_video_disable(dsi); in tegra_dsi_encoder_disable()
867 err = tegra_dsi_wait_idle(dsi, 100); in tegra_dsi_encoder_disable()
869 dev_dbg(dsi->dev, "failed to idle DSI: %d\n", err); in tegra_dsi_encoder_disable()
871 tegra_dsi_soft_reset(dsi); in tegra_dsi_encoder_disable()
873 if (output->panel) in tegra_dsi_encoder_disable()
874 drm_panel_unprepare(output->panel); in tegra_dsi_encoder_disable()
876 tegra_dsi_disable(dsi); in tegra_dsi_encoder_disable()
878 tegra_dsi_unprepare(dsi); in tegra_dsi_encoder_disable()
881 static int tegra_dsi_prepare(struct tegra_dsi *dsi) in tegra_dsi_prepare() argument
885 err = host1x_client_resume(&dsi->client); in tegra_dsi_prepare()
887 dev_err(dsi->dev, "failed to resume: %d\n", err); in tegra_dsi_prepare()
891 err = tegra_mipi_enable(dsi->mipi); in tegra_dsi_prepare()
893 dev_err(dsi->dev, "failed to enable MIPI calibration: %d\n", in tegra_dsi_prepare()
896 err = tegra_dsi_pad_calibrate(dsi); in tegra_dsi_prepare()
898 dev_err(dsi->dev, "MIPI calibration failed: %d\n", err); in tegra_dsi_prepare()
900 if (dsi->slave) in tegra_dsi_prepare()
901 tegra_dsi_prepare(dsi->slave); in tegra_dsi_prepare()
908 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in tegra_dsi_encoder_enable()
910 struct tegra_dc *dc = to_tegra_dc(encoder->crtc); in tegra_dsi_encoder_enable()
911 struct tegra_dsi *dsi = to_dsi(output); in tegra_dsi_encoder_enable() local
916 err = tegra_dsi_prepare(dsi); in tegra_dsi_encoder_enable()
918 dev_err(dsi->dev, "failed to prepare: %d\n", err); in tegra_dsi_encoder_enable()
922 state = tegra_dsi_get_state(dsi); in tegra_dsi_encoder_enable()
924 tegra_dsi_set_timeout(dsi, state->bclk, state->vrefresh); in tegra_dsi_encoder_enable()
927 * The D-PHY timing fields are expressed in byte-clock cycles, so in tegra_dsi_encoder_enable()
930 tegra_dsi_set_phy_timing(dsi, state->period * 8, &state->timing); in tegra_dsi_encoder_enable()
932 if (output->panel) in tegra_dsi_encoder_enable()
933 drm_panel_prepare(output->panel); in tegra_dsi_encoder_enable()
935 tegra_dsi_configure(dsi, dc->pipe, mode); in tegra_dsi_encoder_enable()
944 /* enable DSI controller */ in tegra_dsi_encoder_enable()
945 tegra_dsi_enable(dsi); in tegra_dsi_encoder_enable()
947 if (output->panel) in tegra_dsi_encoder_enable()
948 drm_panel_enable(output->panel); in tegra_dsi_encoder_enable()
958 struct tegra_dc *dc = to_tegra_dc(conn_state->crtc); in tegra_dsi_encoder_atomic_check()
959 struct tegra_dsi *dsi = to_dsi(output); in tegra_dsi_encoder_atomic_check() local
964 state->pclk = crtc_state->mode.clock * 1000; in tegra_dsi_encoder_atomic_check()
966 err = tegra_dsi_get_muldiv(dsi->format, &state->mul, &state->div); in tegra_dsi_encoder_atomic_check()
970 state->lanes = tegra_dsi_get_lanes(dsi); in tegra_dsi_encoder_atomic_check()
972 err = tegra_dsi_get_format(dsi->format, &state->format); in tegra_dsi_encoder_atomic_check()
976 state->vrefresh = drm_mode_vrefresh(&crtc_state->mode); in tegra_dsi_encoder_atomic_check()
979 state->bclk = (state->pclk * state->mul) / (state->div * state->lanes); in tegra_dsi_encoder_atomic_check()
981 DRM_DEBUG_KMS("mul: %u, div: %u, lanes: %u\n", state->mul, state->div, in tegra_dsi_encoder_atomic_check()
982 state->lanes); in tegra_dsi_encoder_atomic_check()
983 DRM_DEBUG_KMS("format: %u, vrefresh: %u\n", state->format, in tegra_dsi_encoder_atomic_check()
984 state->vrefresh); in tegra_dsi_encoder_atomic_check()
985 DRM_DEBUG_KMS("bclk: %lu\n", state->bclk); in tegra_dsi_encoder_atomic_check()
990 plld = DIV_ROUND_UP(state->bclk * 8, USEC_PER_SEC) * USEC_PER_SEC; in tegra_dsi_encoder_atomic_check()
991 state->period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, plld); in tegra_dsi_encoder_atomic_check()
993 err = mipi_dphy_timing_get_default(&state->timing, state->period); in tegra_dsi_encoder_atomic_check()
997 err = mipi_dphy_timing_validate(&state->timing, state->period); in tegra_dsi_encoder_atomic_check()
999 dev_err(dsi->dev, "failed to validate D-PHY timing: %d\n", err); in tegra_dsi_encoder_atomic_check()
1020 scdiv = ((8 * state->mul) / (state->div * state->lanes)) - 2; in tegra_dsi_encoder_atomic_check()
1022 err = tegra_dc_state_setup_clock(dc, crtc_state, dsi->clk_parent, in tegra_dsi_encoder_atomic_check()
1025 dev_err(output->dev, "failed to setup CRTC state: %d\n", err); in tegra_dsi_encoder_atomic_check()
1040 struct drm_device *drm = dev_get_drvdata(client->host); in tegra_dsi_init()
1041 struct tegra_dsi *dsi = host1x_client_to_dsi(client); in tegra_dsi_init() local
1045 if (!dsi->master) { in tegra_dsi_init()
1046 dsi->output.dev = client->dev; in tegra_dsi_init()
1048 drm_connector_init(drm, &dsi->output.connector, in tegra_dsi_init()
1051 drm_connector_helper_add(&dsi->output.connector, in tegra_dsi_init()
1053 dsi->output.connector.dpms = DRM_MODE_DPMS_OFF; in tegra_dsi_init()
1055 drm_simple_encoder_init(drm, &dsi->output.encoder, in tegra_dsi_init()
1057 drm_encoder_helper_add(&dsi->output.encoder, in tegra_dsi_init()
1060 drm_connector_attach_encoder(&dsi->output.connector, in tegra_dsi_init()
1061 &dsi->output.encoder); in tegra_dsi_init()
1062 drm_connector_register(&dsi->output.connector); in tegra_dsi_init()
1064 err = tegra_output_init(drm, &dsi->output); in tegra_dsi_init()
1066 dev_err(dsi->dev, "failed to initialize output: %d\n", in tegra_dsi_init()
1069 dsi->output.encoder.possible_crtcs = 0x3; in tegra_dsi_init()
1077 struct tegra_dsi *dsi = host1x_client_to_dsi(client); in tegra_dsi_exit() local
1079 tegra_output_exit(&dsi->output); in tegra_dsi_exit()
1086 struct tegra_dsi *dsi = host1x_client_to_dsi(client); in tegra_dsi_runtime_suspend() local
1087 struct device *dev = client->dev; in tegra_dsi_runtime_suspend()
1090 if (dsi->rst) { in tegra_dsi_runtime_suspend()
1091 err = reset_control_assert(dsi->rst); in tegra_dsi_runtime_suspend()
1100 clk_disable_unprepare(dsi->clk_lp); in tegra_dsi_runtime_suspend()
1101 clk_disable_unprepare(dsi->clk); in tegra_dsi_runtime_suspend()
1103 regulator_disable(dsi->vdd); in tegra_dsi_runtime_suspend()
1111 struct tegra_dsi *dsi = host1x_client_to_dsi(client); in tegra_dsi_runtime_resume() local
1112 struct device *dev = client->dev; in tegra_dsi_runtime_resume()
1121 err = regulator_enable(dsi->vdd); in tegra_dsi_runtime_resume()
1127 err = clk_prepare_enable(dsi->clk); in tegra_dsi_runtime_resume()
1129 dev_err(dev, "cannot enable DSI clock: %d\n", err); in tegra_dsi_runtime_resume()
1133 err = clk_prepare_enable(dsi->clk_lp); in tegra_dsi_runtime_resume()
1135 dev_err(dev, "cannot enable low-power clock: %d\n", err); in tegra_dsi_runtime_resume()
1141 if (dsi->rst) { in tegra_dsi_runtime_resume()
1142 err = reset_control_deassert(dsi->rst); in tegra_dsi_runtime_resume()
1152 clk_disable_unprepare(dsi->clk_lp); in tegra_dsi_runtime_resume()
1154 clk_disable_unprepare(dsi->clk); in tegra_dsi_runtime_resume()
1156 regulator_disable(dsi->vdd); in tegra_dsi_runtime_resume()
1169 static int tegra_dsi_setup_clocks(struct tegra_dsi *dsi) in tegra_dsi_setup_clocks() argument
1174 parent = clk_get_parent(dsi->clk); in tegra_dsi_setup_clocks()
1176 return -EINVAL; in tegra_dsi_setup_clocks()
1178 err = clk_set_parent(parent, dsi->clk_parent); in tegra_dsi_setup_clocks()
1187 "SoT Sync Error",
1188 "EoT Sync Error",
1190 "Low-Power Transmit Sync Error",
1194 "ECC Error, single-bit",
1195 "ECC Error, multi-bit",
1197 "DSI Data Type Not Recognized",
1198 "DSI VC ID Invalid",
1201 "DSI Protocol Violation",
1204 static ssize_t tegra_dsi_read_response(struct tegra_dsi *dsi, in tegra_dsi_read_response() argument
1208 u8 *rx = msg->rx_buf; in tegra_dsi_read_response()
1215 value = tegra_dsi_readl(dsi, DSI_RD_DATA); in tegra_dsi_read_response()
1220 dev_dbg(dsi->dev, "Acknowledge and error report: %04x\n", in tegra_dsi_read_response()
1224 dev_dbg(dsi->dev, " %2u: %s\n", i, in tegra_dsi_read_response()
1248 dev_err(dsi->dev, "unhandled response type: %02x\n", in tegra_dsi_read_response()
1250 return -EPROTO; in tegra_dsi_read_response()
1253 size = min(size, msg->rx_len); in tegra_dsi_read_response()
1255 if (msg->rx_buf && size > 0) { in tegra_dsi_read_response()
1256 for (i = 0, j = 0; i < count - 1; i++, j += 4) { in tegra_dsi_read_response()
1257 u8 *rx = msg->rx_buf + j; in tegra_dsi_read_response()
1259 value = tegra_dsi_readl(dsi, DSI_RD_DATA); in tegra_dsi_read_response()
1261 for (k = 0; k < 4 && (j + k) < msg->rx_len; k++) in tegra_dsi_read_response()
1269 static int tegra_dsi_transmit(struct tegra_dsi *dsi, unsigned long timeout) in tegra_dsi_transmit() argument
1271 tegra_dsi_writel(dsi, DSI_TRIGGER_HOST, DSI_TRIGGER); in tegra_dsi_transmit()
1276 u32 value = tegra_dsi_readl(dsi, DSI_TRIGGER); in tegra_dsi_transmit()
1284 return -ETIMEDOUT; in tegra_dsi_transmit()
1287 static int tegra_dsi_wait_for_response(struct tegra_dsi *dsi, in tegra_dsi_wait_for_response() argument
1293 u32 value = tegra_dsi_readl(dsi, DSI_STATUS); in tegra_dsi_wait_for_response()
1303 return -ETIMEDOUT; in tegra_dsi_wait_for_response()
1306 static void tegra_dsi_writesl(struct tegra_dsi *dsi, unsigned long offset, in tegra_dsi_writesl() argument
1319 tegra_dsi_writel(dsi, value, DSI_WR_DATA); in tegra_dsi_writesl()
1326 struct tegra_dsi *dsi = host_to_tegra(host); in tegra_dsi_host_transfer() local
1340 if (packet.size > dsi->video_fifo_depth * 4) in tegra_dsi_host_transfer()
1341 return -ENOSPC; in tegra_dsi_host_transfer()
1344 value = tegra_dsi_readl(dsi, DSI_STATUS); in tegra_dsi_host_transfer()
1347 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); in tegra_dsi_host_transfer()
1351 value = tegra_dsi_readl(dsi, DSI_POWER_CONTROL); in tegra_dsi_host_transfer()
1353 tegra_dsi_writel(dsi, value, DSI_POWER_CONTROL); in tegra_dsi_host_transfer()
1360 if ((msg->flags & MIPI_DSI_MSG_USE_LPM) == 0) in tegra_dsi_host_transfer()
1367 if (packet.size > dsi->host_fifo_depth * 4) in tegra_dsi_host_transfer()
1370 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); in tegra_dsi_host_transfer()
1376 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) || in tegra_dsi_host_transfer()
1377 (msg->rx_buf && msg->rx_len > 0)) { in tegra_dsi_host_transfer()
1378 value = tegra_dsi_readl(dsi, DSI_HOST_CONTROL); in tegra_dsi_host_transfer()
1380 tegra_dsi_writel(dsi, value, DSI_HOST_CONTROL); in tegra_dsi_host_transfer()
1384 tegra_dsi_writel(dsi, value, DSI_CONTROL); in tegra_dsi_host_transfer()
1388 tegra_dsi_writel(dsi, value, DSI_WR_DATA); in tegra_dsi_host_transfer()
1392 tegra_dsi_writesl(dsi, DSI_WR_DATA, packet.payload, in tegra_dsi_host_transfer()
1395 err = tegra_dsi_transmit(dsi, 250); in tegra_dsi_host_transfer()
1399 if ((msg->flags & MIPI_DSI_MSG_REQ_ACK) || in tegra_dsi_host_transfer()
1400 (msg->rx_buf && msg->rx_len > 0)) { in tegra_dsi_host_transfer()
1401 err = tegra_dsi_wait_for_response(dsi, 250); in tegra_dsi_host_transfer()
1407 value = tegra_dsi_readl(dsi, DSI_RD_DATA); in tegra_dsi_host_transfer()
1411 dev_dbg(dsi->dev, "ACK\n"); in tegra_dsi_host_transfer()
1417 dev_dbg(dsi->dev, "ESCAPE\n"); in tegra_dsi_host_transfer()
1422 dev_err(dsi->dev, "unknown status: %08x\n", value); in tegra_dsi_host_transfer()
1427 err = tegra_dsi_read_response(dsi, msg, count); in tegra_dsi_host_transfer()
1429 dev_err(dsi->dev, in tegra_dsi_host_transfer()
1442 * For write commands, we have transmitted the 4-byte header in tegra_dsi_host_transfer()
1443 * plus the variable-length payload. in tegra_dsi_host_transfer()
1451 static int tegra_dsi_ganged_setup(struct tegra_dsi *dsi) in tegra_dsi_ganged_setup() argument
1456 /* make sure both DSI controllers share the same PLL */ in tegra_dsi_ganged_setup()
1457 parent = clk_get_parent(dsi->slave->clk); in tegra_dsi_ganged_setup()
1459 return -EINVAL; in tegra_dsi_ganged_setup()
1461 err = clk_set_parent(parent, dsi->clk_parent); in tegra_dsi_ganged_setup()
1471 struct tegra_dsi *dsi = host_to_tegra(host); in tegra_dsi_host_attach() local
1473 dsi->flags = device->mode_flags; in tegra_dsi_host_attach()
1474 dsi->format = device->format; in tegra_dsi_host_attach()
1475 dsi->lanes = device->lanes; in tegra_dsi_host_attach()
1477 if (dsi->slave) { in tegra_dsi_host_attach()
1480 dev_dbg(dsi->dev, "attaching dual-channel device %s\n", in tegra_dsi_host_attach()
1481 dev_name(&device->dev)); in tegra_dsi_host_attach()
1483 err = tegra_dsi_ganged_setup(dsi); in tegra_dsi_host_attach()
1485 dev_err(dsi->dev, "failed to set up ganged mode: %d\n", in tegra_dsi_host_attach()
1495 if (!dsi->master) { in tegra_dsi_host_attach()
1496 struct tegra_output *output = &dsi->output; in tegra_dsi_host_attach()
1498 output->panel = of_drm_find_panel(device->dev.of_node); in tegra_dsi_host_attach()
1499 if (IS_ERR(output->panel)) in tegra_dsi_host_attach()
1500 output->panel = NULL; in tegra_dsi_host_attach()
1502 if (output->panel && output->connector.dev) in tegra_dsi_host_attach()
1503 drm_helper_hpd_irq_event(output->connector.dev); in tegra_dsi_host_attach()
1512 struct tegra_dsi *dsi = host_to_tegra(host); in tegra_dsi_host_detach() local
1513 struct tegra_output *output = &dsi->output; in tegra_dsi_host_detach()
1515 if (output->panel && &device->dev == output->panel->dev) { in tegra_dsi_host_detach()
1516 output->panel = NULL; in tegra_dsi_host_detach()
1518 if (output->connector.dev) in tegra_dsi_host_detach()
1519 drm_helper_hpd_irq_event(output->connector.dev); in tegra_dsi_host_detach()
1531 static int tegra_dsi_ganged_probe(struct tegra_dsi *dsi) in tegra_dsi_ganged_probe() argument
1535 np = of_parse_phandle(dsi->dev->of_node, "nvidia,ganged-mode", 0); in tegra_dsi_ganged_probe()
1540 return -EPROBE_DEFER; in tegra_dsi_ganged_probe()
1542 dsi->slave = platform_get_drvdata(gangster); in tegra_dsi_ganged_probe()
1544 if (!dsi->slave) { in tegra_dsi_ganged_probe()
1545 put_device(&gangster->dev); in tegra_dsi_ganged_probe()
1546 return -EPROBE_DEFER; in tegra_dsi_ganged_probe()
1549 dsi->slave->master = dsi; in tegra_dsi_ganged_probe()
1557 struct tegra_dsi *dsi; in tegra_dsi_probe() local
1560 dsi = devm_kzalloc(&pdev->dev, sizeof(*dsi), GFP_KERNEL); in tegra_dsi_probe()
1561 if (!dsi) in tegra_dsi_probe()
1562 return -ENOMEM; in tegra_dsi_probe()
1564 dsi->output.dev = dsi->dev = &pdev->dev; in tegra_dsi_probe()
1565 dsi->video_fifo_depth = 1920; in tegra_dsi_probe()
1566 dsi->host_fifo_depth = 64; in tegra_dsi_probe()
1568 err = tegra_dsi_ganged_probe(dsi); in tegra_dsi_probe()
1572 err = tegra_output_probe(&dsi->output); in tegra_dsi_probe()
1576 dsi->output.connector.polled = DRM_CONNECTOR_POLL_HPD; in tegra_dsi_probe()
1579 * Assume these values by default. When a DSI peripheral driver in tegra_dsi_probe()
1580 * attaches to the DSI host, the parameters will be taken from in tegra_dsi_probe()
1583 dsi->flags = MIPI_DSI_MODE_VIDEO; in tegra_dsi_probe()
1584 dsi->format = MIPI_DSI_FMT_RGB888; in tegra_dsi_probe()
1585 dsi->lanes = 4; in tegra_dsi_probe()
1587 if (!pdev->dev.pm_domain) { in tegra_dsi_probe()
1588 dsi->rst = devm_reset_control_get(&pdev->dev, "dsi"); in tegra_dsi_probe()
1589 if (IS_ERR(dsi->rst)) { in tegra_dsi_probe()
1590 err = PTR_ERR(dsi->rst); in tegra_dsi_probe()
1595 dsi->clk = devm_clk_get(&pdev->dev, NULL); in tegra_dsi_probe()
1596 if (IS_ERR(dsi->clk)) { in tegra_dsi_probe()
1597 err = dev_err_probe(&pdev->dev, PTR_ERR(dsi->clk), in tegra_dsi_probe()
1598 "cannot get DSI clock\n"); in tegra_dsi_probe()
1602 dsi->clk_lp = devm_clk_get(&pdev->dev, "lp"); in tegra_dsi_probe()
1603 if (IS_ERR(dsi->clk_lp)) { in tegra_dsi_probe()
1604 err = dev_err_probe(&pdev->dev, PTR_ERR(dsi->clk_lp), in tegra_dsi_probe()
1605 "cannot get low-power clock\n"); in tegra_dsi_probe()
1609 dsi->clk_parent = devm_clk_get(&pdev->dev, "parent"); in tegra_dsi_probe()
1610 if (IS_ERR(dsi->clk_parent)) { in tegra_dsi_probe()
1611 err = dev_err_probe(&pdev->dev, PTR_ERR(dsi->clk_parent), in tegra_dsi_probe()
1616 dsi->vdd = devm_regulator_get(&pdev->dev, "avdd-dsi-csi"); in tegra_dsi_probe()
1617 if (IS_ERR(dsi->vdd)) { in tegra_dsi_probe()
1618 err = dev_err_probe(&pdev->dev, PTR_ERR(dsi->vdd), in tegra_dsi_probe()
1623 err = tegra_dsi_setup_clocks(dsi); in tegra_dsi_probe()
1625 dev_err(&pdev->dev, "cannot setup clocks\n"); in tegra_dsi_probe()
1629 dsi->regs = devm_platform_ioremap_resource(pdev, 0); in tegra_dsi_probe()
1630 if (IS_ERR(dsi->regs)) { in tegra_dsi_probe()
1631 err = PTR_ERR(dsi->regs); in tegra_dsi_probe()
1635 dsi->mipi = tegra_mipi_request(&pdev->dev, pdev->dev.of_node); in tegra_dsi_probe()
1636 if (IS_ERR(dsi->mipi)) { in tegra_dsi_probe()
1637 err = PTR_ERR(dsi->mipi); in tegra_dsi_probe()
1641 dsi->host.ops = &tegra_dsi_host_ops; in tegra_dsi_probe()
1642 dsi->host.dev = &pdev->dev; in tegra_dsi_probe()
1644 err = mipi_dsi_host_register(&dsi->host); in tegra_dsi_probe()
1646 dev_err(&pdev->dev, "failed to register DSI host: %d\n", err); in tegra_dsi_probe()
1650 platform_set_drvdata(pdev, dsi); in tegra_dsi_probe()
1651 pm_runtime_enable(&pdev->dev); in tegra_dsi_probe()
1653 INIT_LIST_HEAD(&dsi->client.list); in tegra_dsi_probe()
1654 dsi->client.ops = &dsi_client_ops; in tegra_dsi_probe()
1655 dsi->client.dev = &pdev->dev; in tegra_dsi_probe()
1657 err = host1x_client_register(&dsi->client); in tegra_dsi_probe()
1659 dev_err(&pdev->dev, "failed to register host1x client: %d\n", in tegra_dsi_probe()
1667 pm_runtime_disable(&pdev->dev); in tegra_dsi_probe()
1668 mipi_dsi_host_unregister(&dsi->host); in tegra_dsi_probe()
1670 tegra_mipi_free(dsi->mipi); in tegra_dsi_probe()
1672 tegra_output_remove(&dsi->output); in tegra_dsi_probe()
1678 struct tegra_dsi *dsi = platform_get_drvdata(pdev); in tegra_dsi_remove() local
1680 pm_runtime_disable(&pdev->dev); in tegra_dsi_remove()
1682 host1x_client_unregister(&dsi->client); in tegra_dsi_remove()
1684 tegra_output_remove(&dsi->output); in tegra_dsi_remove()
1686 mipi_dsi_host_unregister(&dsi->host); in tegra_dsi_remove()
1687 tegra_mipi_free(dsi->mipi); in tegra_dsi_remove()
1691 { .compatible = "nvidia,tegra210-dsi", },
1692 { .compatible = "nvidia,tegra132-dsi", },
1693 { .compatible = "nvidia,tegra124-dsi", },
1694 { .compatible = "nvidia,tegra114-dsi", },
1701 .name = "tegra-dsi",