aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/i915/intel_lspcon.c
diff options
context:
space:
mode:
authorShashank Sharma <shashank.sharma@intel.com>2016-10-14 10:26:49 -0400
committerJani Nikula <jani.nikula@intel.com>2016-10-18 05:42:47 -0400
commitdbe9e61b8e4306df24b3e8370a62f7954a81ff5d (patch)
treeb96f4920d1a72d74fe2abd73bb314b5b896c6188 /drivers/gpu/drm/i915/intel_lspcon.c
parent056996b95686324fdc00e72f8cea01be2356ef62 (diff)
drm/i915: Add lspcon support for I915 driver
This patch adds a new file, to accommodate lspcon support for I915 driver. These functions probe, detect, initialize and configure an on-board lspcon device during the driver init time. Also, this patch adds a small structure for lspcon device, which will provide the runtime status of the device. V2: addressed ville's review comments - Clean the leftover macros from previous patch set V3: Rebase V4: addressed ville's review comments - make internal functions static - remove lspcon_detect_identifier, make it inline with lspcon_probe - remove is_lspcon_active function - remove force check while setting a lspcon mode V5: Rebase V6: Pass dev_priv to IS_GEN9 check Signed-off-by: Shashank Sharma <shashank.sharma@intel.com> Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com> Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Acked-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Link: http://patchwork.freedesktop.org/patch/msgid/1476455212-27893-3-git-send-email-shashank.sharma@intel.com
Diffstat (limited to 'drivers/gpu/drm/i915/intel_lspcon.c')
-rw-r--r--drivers/gpu/drm/i915/intel_lspcon.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/drivers/gpu/drm/i915/intel_lspcon.c b/drivers/gpu/drm/i915/intel_lspcon.c
new file mode 100644
index 000000000000..628ae6fbdcb1
--- /dev/null
+++ b/drivers/gpu/drm/i915/intel_lspcon.c
@@ -0,0 +1,128 @@
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
30enum drm_lspcon_mode lspcon_get_current_mode(struct intel_lspcon *lspcon)
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, &current_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
43static 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, &current_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
72static 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
92bool lspcon_init(struct intel_digital_port *intel_dig_port)
93{
94 struct intel_dp *dp = &intel_dig_port->dp;
95 struct intel_lspcon *lspcon = &intel_dig_port->lspcon;
96 struct drm_device *dev = intel_dig_port->base.base.dev;
97 struct drm_i915_private *dev_priv = to_i915(dev);
98
99 if (!IS_GEN9(dev_priv)) {
100 DRM_ERROR("LSPCON is supported on GEN9 only\n");
101 return false;
102 }
103
104 lspcon->active = false;
105 lspcon->mode = DRM_LSPCON_MODE_INVALID;
106 lspcon->aux = &dp->aux;
107
108 if (!lspcon_probe(lspcon)) {
109 DRM_ERROR("Failed to probe lspcon\n");
110 return false;
111 }
112
113 /*
114 * In the SW state machine, lets Put LSPCON in PCON mode only.
115 * In this way, it will work with both HDMI 1.4 sinks as well as HDMI
116 * 2.0 sinks.
117 */
118 if (lspcon->active && lspcon->mode != DRM_LSPCON_MODE_PCON) {
119 if (lspcon_change_mode(lspcon, DRM_LSPCON_MODE_PCON,
120 true) < 0) {
121 DRM_ERROR("LSPCON mode change to PCON failed\n");
122 return false;
123 }
124 }
125
126 DRM_DEBUG_KMS("Success: LSPCON init\n");
127 return true;
128}