xref: /linux/drivers/gpu/drm/i915/display/intel_dsi.c (revision 201963a82708780faaed55ca15f8261f98d36d56)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2018 Intel Corporation
4  */
5 
6 #include <drm/drm_mipi_dsi.h>
7 
8 #include "i915_drv.h"
9 #include "intel_dsi.h"
10 #include "intel_panel.h"
11 
12 void intel_dsi_wait_panel_power_cycle(struct intel_dsi *intel_dsi)
13 {
14 	ktime_t panel_power_on_time;
15 	s64 panel_power_off_duration;
16 
17 	panel_power_on_time = ktime_get_boottime();
18 	panel_power_off_duration = ktime_ms_delta(panel_power_on_time,
19 						  intel_dsi->panel_power_off_time);
20 
21 	if (panel_power_off_duration < (s64)intel_dsi->panel_pwr_cycle_delay)
22 		msleep(intel_dsi->panel_pwr_cycle_delay - panel_power_off_duration);
23 }
24 
25 int intel_dsi_bitrate(const struct intel_dsi *intel_dsi)
26 {
27 	int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
28 
29 	if (WARN_ON(bpp < 0))
30 		bpp = 16;
31 
32 	return intel_dsi->pclk * bpp / intel_dsi->lane_count;
33 }
34 
35 int intel_dsi_tlpx_ns(const struct intel_dsi *intel_dsi)
36 {
37 	switch (intel_dsi->escape_clk_div) {
38 	default:
39 	case 0:
40 		return 50;
41 	case 1:
42 		return 100;
43 	case 2:
44 		return 200;
45 	}
46 }
47 
48 int intel_dsi_get_modes(struct drm_connector *connector)
49 {
50 	return intel_panel_get_modes(to_intel_connector(connector));
51 }
52 
53 enum drm_mode_status intel_dsi_mode_valid(struct drm_connector *connector,
54 					  struct drm_display_mode *mode)
55 {
56 	struct drm_i915_private *dev_priv = to_i915(connector->dev);
57 	struct intel_connector *intel_connector = to_intel_connector(connector);
58 	const struct drm_display_mode *fixed_mode =
59 		intel_panel_fixed_mode(intel_connector, mode);
60 	int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
61 	enum drm_mode_status status;
62 
63 	drm_dbg_kms(&dev_priv->drm, "\n");
64 
65 	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
66 		return MODE_NO_DBLESCAN;
67 
68 	status = intel_panel_mode_valid(intel_connector, mode);
69 	if (status != MODE_OK)
70 		return status;
71 
72 	if (fixed_mode->clock > max_dotclk)
73 		return MODE_CLOCK_HIGH;
74 
75 	return intel_mode_valid_max_plane_size(dev_priv, mode, false);
76 }
77 
78 struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
79 					   const struct mipi_dsi_host_ops *funcs,
80 					   enum port port)
81 {
82 	struct intel_dsi_host *host;
83 	struct mipi_dsi_device *device;
84 
85 	host = kzalloc(sizeof(*host), GFP_KERNEL);
86 	if (!host)
87 		return NULL;
88 
89 	host->base.ops = funcs;
90 	host->intel_dsi = intel_dsi;
91 	host->port = port;
92 
93 	/*
94 	 * We should call mipi_dsi_host_register(&host->base) here, but we don't
95 	 * have a host->dev, and we don't have OF stuff either. So just use the
96 	 * dsi framework as a library and hope for the best. Create the dsi
97 	 * devices by ourselves here too. Need to be careful though, because we
98 	 * don't initialize any of the driver model devices here.
99 	 */
100 	device = kzalloc(sizeof(*device), GFP_KERNEL);
101 	if (!device) {
102 		kfree(host);
103 		return NULL;
104 	}
105 
106 	device->host = &host->base;
107 	host->device = device;
108 
109 	return host;
110 }
111 
112 enum drm_panel_orientation
113 intel_dsi_get_panel_orientation(struct intel_connector *connector)
114 {
115 	struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
116 	enum drm_panel_orientation orientation;
117 
118 	orientation = connector->panel.vbt.dsi.orientation;
119 	if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
120 		return orientation;
121 
122 	orientation = dev_priv->display.vbt.orientation;
123 	if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
124 		return orientation;
125 
126 	return DRM_MODE_PANEL_ORIENTATION_NORMAL;
127 }
128