Shashank Sharma | dbe9e61 | 2016-10-14 19:56:49 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * |
| 24 | */ |
| 25 | #include <drm/drm_edid.h> |
| 26 | #include <drm/drm_atomic_helper.h> |
| 27 | #include <drm/drm_dp_dual_mode_helper.h> |
| 28 | #include "intel_drv.h" |
| 29 | |
Jani Nikula | 1dc16aa | 2016-10-18 14:21:51 +0300 | [diff] [blame^] | 30 | static enum drm_lspcon_mode lspcon_get_current_mode(struct intel_lspcon *lspcon) |
Shashank Sharma | dbe9e61 | 2016-10-14 19:56:49 +0530 | [diff] [blame] | 31 | { |
| 32 | enum drm_lspcon_mode current_mode = DRM_LSPCON_MODE_INVALID; |
| 33 | struct i2c_adapter *adapter = &lspcon->aux->ddc; |
| 34 | |
| 35 | if (drm_lspcon_get_mode(adapter, ¤t_mode)) |
| 36 | DRM_ERROR("Error reading LSPCON mode\n"); |
| 37 | else |
| 38 | DRM_DEBUG_KMS("Current LSPCON mode %s\n", |
| 39 | current_mode == DRM_LSPCON_MODE_PCON ? "PCON" : "LS"); |
| 40 | return current_mode; |
| 41 | } |
| 42 | |
| 43 | static int lspcon_change_mode(struct intel_lspcon *lspcon, |
| 44 | enum drm_lspcon_mode mode, bool force) |
| 45 | { |
| 46 | int err; |
| 47 | enum drm_lspcon_mode current_mode; |
| 48 | struct i2c_adapter *adapter = &lspcon->aux->ddc; |
| 49 | |
| 50 | err = drm_lspcon_get_mode(adapter, ¤t_mode); |
| 51 | if (err) { |
| 52 | DRM_ERROR("Error reading LSPCON mode\n"); |
| 53 | return err; |
| 54 | } |
| 55 | |
| 56 | if (current_mode == mode) { |
| 57 | DRM_DEBUG_KMS("Current mode = desired LSPCON mode\n"); |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | err = drm_lspcon_set_mode(adapter, mode); |
| 62 | if (err < 0) { |
| 63 | DRM_ERROR("LSPCON mode change failed\n"); |
| 64 | return err; |
| 65 | } |
| 66 | |
| 67 | lspcon->mode = mode; |
| 68 | DRM_DEBUG_KMS("LSPCON mode changed done\n"); |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | static bool lspcon_probe(struct intel_lspcon *lspcon) |
| 73 | { |
| 74 | enum drm_dp_dual_mode_type adaptor_type; |
| 75 | struct i2c_adapter *adapter = &lspcon->aux->ddc; |
| 76 | |
| 77 | /* Lets probe the adaptor and check its type */ |
| 78 | adaptor_type = drm_dp_dual_mode_detect(adapter); |
| 79 | if (adaptor_type != DRM_DP_DUAL_MODE_LSPCON) { |
| 80 | DRM_DEBUG_KMS("No LSPCON detected, found %s\n", |
| 81 | drm_dp_get_dual_mode_type_name(adaptor_type)); |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | /* Yay ... got a LSPCON device */ |
| 86 | DRM_DEBUG_KMS("LSPCON detected\n"); |
| 87 | lspcon->mode = lspcon_get_current_mode(lspcon); |
| 88 | lspcon->active = true; |
| 89 | return true; |
| 90 | } |
| 91 | |
Shashank Sharma | 910530c | 2016-10-14 19:56:52 +0530 | [diff] [blame] | 92 | void lspcon_resume(struct intel_lspcon *lspcon) |
| 93 | { |
| 94 | if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON, true)) |
| 95 | DRM_ERROR("LSPCON resume failed\n"); |
| 96 | else |
| 97 | DRM_DEBUG_KMS("LSPCON resume success\n"); |
| 98 | } |
| 99 | |
Shashank Sharma | dbe9e61 | 2016-10-14 19:56:49 +0530 | [diff] [blame] | 100 | bool lspcon_init(struct intel_digital_port *intel_dig_port) |
| 101 | { |
| 102 | struct intel_dp *dp = &intel_dig_port->dp; |
| 103 | struct intel_lspcon *lspcon = &intel_dig_port->lspcon; |
| 104 | struct drm_device *dev = intel_dig_port->base.base.dev; |
| 105 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 106 | |
| 107 | if (!IS_GEN9(dev_priv)) { |
| 108 | DRM_ERROR("LSPCON is supported on GEN9 only\n"); |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | lspcon->active = false; |
| 113 | lspcon->mode = DRM_LSPCON_MODE_INVALID; |
| 114 | lspcon->aux = &dp->aux; |
| 115 | |
| 116 | if (!lspcon_probe(lspcon)) { |
| 117 | DRM_ERROR("Failed to probe lspcon\n"); |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * In the SW state machine, lets Put LSPCON in PCON mode only. |
| 123 | * In this way, it will work with both HDMI 1.4 sinks as well as HDMI |
| 124 | * 2.0 sinks. |
| 125 | */ |
| 126 | if (lspcon->active && lspcon->mode != DRM_LSPCON_MODE_PCON) { |
| 127 | if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON, |
| 128 | true) < 0) { |
| 129 | DRM_ERROR("LSPCON mode change to PCON failed\n"); |
| 130 | return false; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | DRM_DEBUG_KMS("Success: LSPCON init\n"); |
| 135 | return true; |
| 136 | } |