Linux Audio

Check our new training course

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