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