treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / i915 / display / intel_dsi.c
bloba2a937109a5ad113e18b8363c1dc5d9807114716
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright © 2018 Intel Corporation
4 */
6 #include <drm/drm_mipi_dsi.h>
7 #include "intel_dsi.h"
9 int intel_dsi_bitrate(const struct intel_dsi *intel_dsi)
11 int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
13 if (WARN_ON(bpp < 0))
14 bpp = 16;
16 return intel_dsi->pclk * bpp / intel_dsi->lane_count;
19 int intel_dsi_tlpx_ns(const struct intel_dsi *intel_dsi)
21 switch (intel_dsi->escape_clk_div) {
22 default:
23 case 0:
24 return 50;
25 case 1:
26 return 100;
27 case 2:
28 return 200;
32 int intel_dsi_get_modes(struct drm_connector *connector)
34 struct intel_connector *intel_connector = to_intel_connector(connector);
35 struct drm_display_mode *mode;
37 DRM_DEBUG_KMS("\n");
39 if (!intel_connector->panel.fixed_mode) {
40 DRM_DEBUG_KMS("no fixed mode\n");
41 return 0;
44 mode = drm_mode_duplicate(connector->dev,
45 intel_connector->panel.fixed_mode);
46 if (!mode) {
47 DRM_DEBUG_KMS("drm_mode_duplicate failed\n");
48 return 0;
51 drm_mode_probed_add(connector, mode);
52 return 1;
55 enum drm_mode_status intel_dsi_mode_valid(struct drm_connector *connector,
56 struct drm_display_mode *mode)
58 struct drm_i915_private *dev_priv = to_i915(connector->dev);
59 struct intel_connector *intel_connector = to_intel_connector(connector);
60 const struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
61 int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
63 DRM_DEBUG_KMS("\n");
65 if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
66 return MODE_NO_DBLESCAN;
68 if (fixed_mode) {
69 if (mode->hdisplay > fixed_mode->hdisplay)
70 return MODE_PANEL;
71 if (mode->vdisplay > fixed_mode->vdisplay)
72 return MODE_PANEL;
73 if (fixed_mode->clock > max_dotclk)
74 return MODE_CLOCK_HIGH;
77 return intel_mode_valid_max_plane_size(dev_priv, mode);
80 struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
81 const struct mipi_dsi_host_ops *funcs,
82 enum port port)
84 struct intel_dsi_host *host;
85 struct mipi_dsi_device *device;
87 host = kzalloc(sizeof(*host), GFP_KERNEL);
88 if (!host)
89 return NULL;
91 host->base.ops = funcs;
92 host->intel_dsi = intel_dsi;
93 host->port = port;
96 * We should call mipi_dsi_host_register(&host->base) here, but we don't
97 * have a host->dev, and we don't have OF stuff either. So just use the
98 * dsi framework as a library and hope for the best. Create the dsi
99 * devices by ourselves here too. Need to be careful though, because we
100 * don't initialize any of the driver model devices here.
102 device = kzalloc(sizeof(*device), GFP_KERNEL);
103 if (!device) {
104 kfree(host);
105 return NULL;
108 device->host = &host->base;
109 host->device = device;
111 return host;
114 enum drm_panel_orientation
115 intel_dsi_get_panel_orientation(struct intel_connector *connector)
117 struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
118 enum drm_panel_orientation orientation;
120 orientation = dev_priv->vbt.dsi.orientation;
121 if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
122 return orientation;
124 orientation = dev_priv->vbt.orientation;
125 if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
126 return orientation;
128 return DRM_MODE_PANEL_ORIENTATION_NORMAL;