Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: MIT
0002 /*
0003  * Copyright © 2018 Intel Corporation
0004  */
0005 
0006 #include <drm/drm_mipi_dsi.h>
0007 
0008 #include "i915_drv.h"
0009 #include "intel_dsi.h"
0010 #include "intel_panel.h"
0011 
0012 int intel_dsi_bitrate(const struct intel_dsi *intel_dsi)
0013 {
0014     int bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
0015 
0016     if (WARN_ON(bpp < 0))
0017         bpp = 16;
0018 
0019     return intel_dsi->pclk * bpp / intel_dsi->lane_count;
0020 }
0021 
0022 int intel_dsi_tlpx_ns(const struct intel_dsi *intel_dsi)
0023 {
0024     switch (intel_dsi->escape_clk_div) {
0025     default:
0026     case 0:
0027         return 50;
0028     case 1:
0029         return 100;
0030     case 2:
0031         return 200;
0032     }
0033 }
0034 
0035 int intel_dsi_get_modes(struct drm_connector *connector)
0036 {
0037     return intel_panel_get_modes(to_intel_connector(connector));
0038 }
0039 
0040 enum drm_mode_status intel_dsi_mode_valid(struct drm_connector *connector,
0041                       struct drm_display_mode *mode)
0042 {
0043     struct drm_i915_private *dev_priv = to_i915(connector->dev);
0044     struct intel_connector *intel_connector = to_intel_connector(connector);
0045     const struct drm_display_mode *fixed_mode =
0046         intel_panel_fixed_mode(intel_connector, mode);
0047     int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
0048     enum drm_mode_status status;
0049 
0050     drm_dbg_kms(&dev_priv->drm, "\n");
0051 
0052     if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
0053         return MODE_NO_DBLESCAN;
0054 
0055     status = intel_panel_mode_valid(intel_connector, mode);
0056     if (status != MODE_OK)
0057         return status;
0058 
0059     if (fixed_mode->clock > max_dotclk)
0060         return MODE_CLOCK_HIGH;
0061 
0062     return intel_mode_valid_max_plane_size(dev_priv, mode, false);
0063 }
0064 
0065 struct intel_dsi_host *intel_dsi_host_init(struct intel_dsi *intel_dsi,
0066                        const struct mipi_dsi_host_ops *funcs,
0067                        enum port port)
0068 {
0069     struct intel_dsi_host *host;
0070     struct mipi_dsi_device *device;
0071 
0072     host = kzalloc(sizeof(*host), GFP_KERNEL);
0073     if (!host)
0074         return NULL;
0075 
0076     host->base.ops = funcs;
0077     host->intel_dsi = intel_dsi;
0078     host->port = port;
0079 
0080     /*
0081      * We should call mipi_dsi_host_register(&host->base) here, but we don't
0082      * have a host->dev, and we don't have OF stuff either. So just use the
0083      * dsi framework as a library and hope for the best. Create the dsi
0084      * devices by ourselves here too. Need to be careful though, because we
0085      * don't initialize any of the driver model devices here.
0086      */
0087     device = kzalloc(sizeof(*device), GFP_KERNEL);
0088     if (!device) {
0089         kfree(host);
0090         return NULL;
0091     }
0092 
0093     device->host = &host->base;
0094     host->device = device;
0095 
0096     return host;
0097 }
0098 
0099 enum drm_panel_orientation
0100 intel_dsi_get_panel_orientation(struct intel_connector *connector)
0101 {
0102     struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
0103     enum drm_panel_orientation orientation;
0104 
0105     orientation = connector->panel.vbt.dsi.orientation;
0106     if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
0107         return orientation;
0108 
0109     orientation = dev_priv->vbt.orientation;
0110     if (orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
0111         return orientation;
0112 
0113     return DRM_MODE_PANEL_ORIENTATION_NORMAL;
0114 }