All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] drm: DP++ adaptor support (v2)
@ 2016-05-02 19:08 ville.syrjala
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
                   ` (4 more replies)
  0 siblings, 5 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-02 19:08 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Here's a respin of my DP++ adaptor support series [1]. Pardon for taking
forever with this. Presumably we want to get this into stable to fix the
regression from HDMI 12bpc support.

I've tried to account for a bunch of Paulo's review comments

I also tried to make the helper a bit easier to use by having the caller
pass the adaptor type to the helper functions, and so the need for most
adaptor type checks in driver code is eliminated. I still left some
checks in i915, but those are there just to do the type 1 DVI vs. none
detectio, and to suppress the debug output when no adaptor is detected.

I also redid the detection logic a bit to ease future LSPCON enabling.

I had to rebase a bunch of stuff due to VBT shuffling. I also noticed
that my BSW still wasn't detecting type 1 DVI adaptors, which I managed
to "fix" by having the VBT check also accept HDMI type dvo_ports as DP++
ports, which sucks a bit but should hopefully be robust enough.

I felt that things changed a bit too much in the end for me to hang
on to the r-bs unfortunately, so I didn't actually pick them up. So
if people aren't too fed up with this, I'd appreciate them having a
a second look.

Series available here:
git://github.com/vsyrjala/linux.git dp_dual_mode_3

[1] https://lists.freedesktop.org/archives/dri-devel/2016-February/101494.html

Ville Syrjälä (4):
  drm: Add helper for DP++ adaptors
  drm/i915: Respect DP++ adaptor TMDS clock limit
  drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
  drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT

 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/i915_drv.h           |   1 +
 drivers/gpu/drm/i915/intel_bios.c         |  36 +++
 drivers/gpu/drm/i915/intel_ddi.c          |  12 +
 drivers/gpu/drm/i915/intel_drv.h          |   6 +
 drivers/gpu/drm/i915/intel_hdmi.c         | 100 ++++++++-
 drivers/gpu/drm/i915/intel_vbt_defs.h     |  13 ++
 include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
 9 files changed, 600 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

-- 
2.7.4

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v2 1/4] drm: Add helper for DP++ adaptors
  2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
@ 2016-05-02 19:08 ` ville.syrjala
  2016-05-03  7:46     ` Jani Nikula
                     ` (2 more replies)
  2016-05-02 19:08 ` [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit ville.syrjala
                   ` (3 subsequent siblings)
  4 siblings, 3 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-02 19:08 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a helper which aids in the identification of DP dual mode
(aka. DP++) adaptors. There are several types of adaptors
specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI

Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
may go as high as 300MHz and they provide a register informing the
source device what the actual limit is. Supposedly also type 1 adaptors
may optionally implement this register. This TMDS clock limit is the
main reason why we need to identify these adaptors.

Type 1 adaptors provide access to their internal registers and the sink
DDC bus through I2C. Type 2 adaptors provide this access both via I2C
and I2C-over-AUX. A type 2 source device may choose to implement either
of these methods. If a source device implements the I2C-over-AUX
method, then the driver will obviously need specific support for such
adaptors since the port is driven like an HDMI port, but DDC
communication happes over the AUX channel.

This helper should be enough to identify the adaptor type (some
type 1 DVI adaptors may be a slight exception) and the maximum TMDS
clock limit. Another feature that may be available is control over
the TMDS output buffers on the adaptor, possibly allowing for some
power saving when the TMDS link is down.

Other user controllable features that may be available in the adaptors
are downstream i2c bus speed control when using i2c-over-aux, and
some control over the CEC pin. I chose not to provide any helper
functions for those since I have no use for them in i915 at this time.
The rest of the registers in the adaptor are mostly just information,
eg. IEEE OUI, hardware and firmware revision, etc.

v2: Pass adaptor type to helper functions to ease driver implementation
    Fix a bunch of typoes (Paulo)
    Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
    the type (Paulo)
    Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
    Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
    ease future LSPCON enabling
    Remove the unused DP_DUAL_MODE_LAST_RESERVED define

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
 include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
 3 files changed, 440 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 1a26b4eb1ce0..29f2ee9b9534 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
-		drm_kms_helper_common.o
+		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
 
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
new file mode 100644
index 000000000000..949c0fbeb542
--- /dev/null
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -0,0 +1,356 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dp_dual_mode_helper.h>
+#include <drm/drmP.h>
+
+/**
+ * DOC: DP dual mode (aka. DP++) adaptor helpers
+ *
+ * Helper functions to deal with DP dual mode adaptors.
+ *
+ * Type 1:
+ * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
+ *
+ * Type 2:
+ * Adaptor registers and sink DDC bus can be accessed either via I2C or
+ * I2C-over-AUX. Source devices may choose to implement either of these
+ * access methods.
+ */
+
+#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
+
+/**
+ * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
+ * adapter: I2C adapter for the DDC bus
+ * offset: register offset
+ * buffer: buffer for return data
+ * size: sizo of the buffer
+ *
+ * Reads @size bytes from the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size)
+{
+	struct i2c_msg msgs[] = {
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = 0,
+			.len = 1,
+			.buf = &offset,
+		},
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = I2C_M_RD,
+			.len = size,
+			.buf = buffer,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret < 0)
+		return ret;
+	if (ret != ARRAY_SIZE(msgs))
+		return -EPROTO;
+
+	return 0;
+}
+
+/**
+ * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
+ * adapter: I2C adapter for the DDC bus
+ * offset: register offset
+ * buffer: buffer for write data
+ * size: sizo of the buffer
+ *
+ * Writes @size bytes to the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size)
+{
+	struct i2c_msg msg = {
+		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+		.flags = 0,
+		.len = 1 + size,
+		.buf = NULL,
+	};
+	void *data;
+	int ret;
+
+	data = kmalloc(msg.len, GFP_TEMPORARY);
+	if (!data)
+		return -ENOMEM;
+
+	msg.buf = data;
+
+	memcpy(data, &offset, 1);
+	memcpy(data + 1, buffer, size);
+
+	ret = i2c_transfer(adapter, &msg, 1);
+
+	kfree(data);
+
+	if (ret < 0)
+		return ret;
+	if (ret != 1)
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_write);
+
+static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
+{
+	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
+		"DP-HDMI ADAPTOR\x04";
+
+	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
+		      sizeof(dp_dual_mode_hdmi_id)) == 0;
+}
+
+static bool is_type2_adaptor(uint8_t adaptor_id)
+{
+	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
+			      DP_DUAL_MODE_REV_TYPE2);
+}
+
+/**
+ * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
+ * adapter: I2C adapter for the DDC bus
+ *
+ * Attempt to identify the type of the DP dual mode adaptor used.
+ *
+ * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
+ * certain whether we're dealing with a native HDMI port or
+ * a type 1 DVI dual mode adaptor. The driver will have to use
+ * some other hardware/driver specific mechanism to make that
+ * distinction.
+ *
+ * Returns:
+ * The type of the DP dual mode adaptor used
+ */
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
+{
+	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
+	uint8_t adaptor_id = 0x00;
+	ssize_t ret;
+
+	/*
+	 * Let's see if the adaptor is there the by reading the
+	 * HDMI ID registers.
+	 *
+	 * Note that type 1 DVI adaptors are not required to implemnt
+	 * any registers, and that presents a problem for detection.
+	 * If the i2c transfer is nacked, we may or may not be dealing
+	 * with a type 1 DVI adaptor. Some other mechanism of detecting
+	 * the presence of the adaptor is required. One way would be
+	 * to check the state of the CONFIG1 pin, Another method would
+	 * simply require the driver to know whether the port is a DP++
+	 * port or a native HDMI port. Both of these methods are entirely
+	 * hardware/driver specific so we can't deal with them here.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
+				    hdmi_id, sizeof(hdmi_id));
+	if (ret)
+		return DRM_DP_DUAL_MODE_UNKNOWN;
+
+	/*
+	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
+	 * the offset but ignore it, and instead they just always return
+	 * data from the start of the HDMI ID buffer. So for a broken
+	 * type 1 HDMI adaptor a single byte read will always give us
+	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
+	 * (assuming it implements any registers). Fortunately neither
+	 * of those values will match the type 2 signature of the
+	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
+	 * the type 2 adaptor detection safely even in the presence
+	 * of broken type 1 adaptors.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
+				    &adaptor_id, sizeof(adaptor_id));
+	if (ret == 0) {
+		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
+			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
+		else if (is_type2_adaptor(adaptor_id))
+			return DRM_DP_DUAL_MODE_TYPE2_DVI;
+	}
+
+	if (is_hdmi_adaptor(hdmi_id))
+		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
+	else
+		return DRM_DP_DUAL_MODE_TYPE1_DVI;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_detect);
+
+/**
+ * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
+ * type: DP dual mode adaptor type
+ * adapter: I2C adapter for the DDC bus
+ *
+ * Determine the max TMDS clock the adaptor supports based on the
+ * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
+ * register (on type2 adaptors). As some type 1 adaptors have
+ * problems with registers (see comments in drm_dp_dual_mode_detect())
+ * we don't read the register on those, instead we simply assume
+ * a 165 MHz limit based on the specification.
+ *
+ * Returns:
+ * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
+ */
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter)
+{
+	uint8_t max_tmds_clock;
+	ssize_t ret;
+
+	/* native HDMI so no limit */
+	if (type == DRM_DP_DUAL_MODE_NONE)
+		return 0;
+
+	/*
+	 * Type 1 adaptors are limited to 165MHz
+	 * Type 2 adaptors can tells us their limit
+	 */
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 165000;
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
+				    &max_tmds_clock, sizeof(max_tmds_clock));
+	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
+		return 165000;
+
+	return max_tmds_clock * 5000 / 2;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
+
+/**
+ * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
+ * type: DP dual mode adaptor type
+ * adapter: I2C adapter for the DDC bus
+ * enabled: current state of the TMDS output buffers
+ *
+ * Get the state of the TMDS output buffers in the adaptor. For
+ * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
+ * register. As some type 1 adaptors have problems with registers
+ * (see comments in drm_dp_dual_mode_detect()) we don't read the
+ * register on those, instead we simply assume that the buffers
+ * are always enabled.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter,
+				     bool *enabled)
+{
+	uint8_t tmds_oen;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
+		*enabled = true;
+		return 0;
+	}
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
+				    &tmds_oen, sizeof(tmds_oen));
+	if (ret)
+		return ret;
+
+	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
+
+/**
+ * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
+ * type: DP dual mode adaptor type
+ * adapter: I2C adapter for the DDC bus
+ * enable: enable (as opposed to disable) the TMDS output buffers
+ *
+ * Set the state of the TMDS output buffers in the adaptor. For
+ * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
+ * some type 1 adaptors have problems with registers (see comments
+ * in drm_dp_dual_mode_detect()) we avoid touching the register,
+ * making this function a no-op on type 1 adaptors.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable)
+{
+	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 0;
+
+	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
+				     &tmds_oen, sizeof(tmds_oen));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
+
+/**
+ * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
+ * type: DP dual mode adaptor type
+ *
+ * Returns:
+ * String representation of the DP dual mode adaptor type
+ */
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
+{
+	switch (type) {
+	case DRM_DP_DUAL_MODE_NONE:
+		return "none";
+	case DRM_DP_DUAL_MODE_TYPE1_DVI:
+		return "type 1 DVI";
+	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
+		return "type 1 HDMI";
+	case DRM_DP_DUAL_MODE_TYPE2_DVI:
+		return "type 2 DVI";
+	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
+		return "type 2 HDMI";
+	default:
+		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
+		return "unknown";
+	}
+}
+EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
new file mode 100644
index 000000000000..b4603b9fc03d
--- /dev/null
+++ b/include/drm/drm_dp_dual_mode_helper.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DP_DUAL_MODE_HELPER_H
+#define DRM_DP_DUAL_MODE_HELPER_H
+
+#include <linux/types.h>
+
+/*
+ * Optional for type 1 DVI adaptors
+ * Mandatory for type 1 HDMI and type 2 adators
+ */
+#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
+#define  DP_DUAL_MODE_HDMI_ID_LEN 16
+/*
+ * Optional for type 1 adaptors
+ * Mandatory for type 2 adators
+ */
+#define DP_DUAL_MODE_ADAPTOR_ID 0x10
+#define  DP_DUAL_MODE_REV_MASK 0x07
+#define  DP_DUAL_MODE_REV_TYPE2 0x00
+#define  DP_DUAL_MODE_TYPE_MASK 0xf0
+#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
+#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
+#define  DP_DUAL_IEEE_OUI_LEN 3
+#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
+#define  DP_DUAL_DEVICE_ID_LEN 6
+#define DP_DUAL_MODE_HARDWARE_REV 0x1a
+#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
+#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
+#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
+#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
+#define DP_DUAL_MODE_TMDS_OEN 0x20
+#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
+#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
+#define  DP_DUAL_MODE_CEC_ENABLE 0x01
+#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
+
+struct i2c_adapter;
+
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size);
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size);
+
+enum drm_dp_dual_mode_type {
+	DRM_DP_DUAL_MODE_NONE,
+	DRM_DP_DUAL_MODE_UNKNOWN,
+	DRM_DP_DUAL_MODE_TYPE1_DVI,
+	DRM_DP_DUAL_MODE_TYPE1_HDMI,
+	DRM_DP_DUAL_MODE_TYPE2_DVI,
+	DRM_DP_DUAL_MODE_TYPE2_HDMI,
+};
+
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter);
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool *enabled);
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable);
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
+
+#endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit
  2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
@ 2016-05-02 19:08 ` ville.syrjala
  2016-05-04 10:08   ` Sharma, Shashank
  2016-05-02 19:08 ` [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed ville.syrjala
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 36+ messages in thread
From: ville.syrjala @ 2016-05-02 19:08 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx, stable, Paulo Zanoni, Shashank Sharma, Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Try to detect the max TMDS clock limit for the DP++ adaptor (if any)
and take it into account when checking the port clock.

Note that as with the sink (HDMI vs. DVI) TMDS clock limit we'll ignore
the adaptor TMDS clock limit in the modeset path, in case users are
already "overclocking" their TMDS links. One subtle change here is that
we'll have to respect the adaptor TMDS clock limit when we decide whether
to do 12bpc or 8bpc, otherwise we might end up picking 12bpc and
accidentally driving the TMDS link out of spec even when the user chose
a mode that fits wihting the limits at 8bpc. This means you can't
"overclock" your DP++ dongle at 12bpc anymore, but you can continue to
do so at 8bpc.

Note that for simplicity we'll use the I2C access method for all dual
mode adaptors including type 2. Otherwise we'd have to start mixing
DP AUX and HDMI together. In the future we may need to do that if we
come across any board designs that don't hook up the DDC pins to the
DP++ connectors. Such boards would obviously only work with type 2
dual mode adaptors, and not type 1.

v2: Store adaptor type under indel_hdmi->dp_dual_mode
    Deal with DRM_DP_DUAL_MODE_UNKNOWN
    Pass adaptor type to drm_dp_dual_mode_max_tmds_clock(),
    and use it for type1 adaptors as well

Cc: stable@vger.kernel.org
Reported-by: Tore Anderson <tore@fud.no>
Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/intel_drv.h  |  5 ++++
 drivers/gpu/drm/i915/intel_hdmi.c | 58 +++++++++++++++++++++++++++++++++------
 2 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index 21dee3f89e84..e94d18fb2ff1 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -33,6 +33,7 @@
 #include <drm/drm_crtc.h>
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_fb_helper.h>
+#include <drm/drm_dp_dual_mode_helper.h>
 #include <drm/drm_dp_mst_helper.h>
 #include <drm/drm_rect.h>
 #include <drm/drm_atomic.h>
@@ -753,6 +754,10 @@ struct cxsr_latency {
 struct intel_hdmi {
 	i915_reg_t hdmi_reg;
 	int ddc_bus;
+	struct {
+		enum drm_dp_dual_mode_type type;
+		int max_tmds_clock;
+	} dp_dual_mode;
 	bool limited_color_range;
 	bool color_range_auto;
 	bool has_hdmi_sink;
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index e1012d612024..31ca11134294 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1167,27 +1167,42 @@ static void pch_post_disable_hdmi(struct intel_encoder *encoder)
 	intel_disable_hdmi(encoder);
 }
 
-static int hdmi_port_clock_limit(struct intel_hdmi *hdmi, bool respect_dvi_limit)
+static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
 {
-	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
-
-	if ((respect_dvi_limit && !hdmi->has_hdmi_sink) || IS_G4X(dev))
+	if (IS_G4X(dev_priv))
 		return 165000;
-	else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
+	else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
 		return 300000;
 	else
 		return 225000;
 }
 
+static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
+				 bool respect_downstream_limits)
+{
+	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
+	int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
+
+	if (respect_downstream_limits) {
+		if (hdmi->dp_dual_mode.max_tmds_clock)
+			max_tmds_clock = min(max_tmds_clock,
+					     hdmi->dp_dual_mode.max_tmds_clock);
+		if (!hdmi->has_hdmi_sink)
+			max_tmds_clock = min(max_tmds_clock, 165000);
+	}
+
+	return max_tmds_clock;
+}
+
 static enum drm_mode_status
 hdmi_port_clock_valid(struct intel_hdmi *hdmi,
-		      int clock, bool respect_dvi_limit)
+		      int clock, bool respect_downstream_limits)
 {
 	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
 
 	if (clock < 25000)
 		return MODE_CLOCK_LOW;
-	if (clock > hdmi_port_clock_limit(hdmi, respect_dvi_limit))
+	if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
 		return MODE_CLOCK_HIGH;
 
 	/* BXT DPLL can't generate 223-240 MHz */
@@ -1311,7 +1326,7 @@ bool intel_hdmi_compute_config(struct intel_encoder *encoder,
 	 * within limits.
 	 */
 	if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
-	    hdmi_port_clock_valid(intel_hdmi, clock_12bpc, false) == MODE_OK &&
+	    hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
 	    hdmi_12bpc_possible(pipe_config)) {
 		DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
 		desired_bpp = 12*3;
@@ -1353,10 +1368,35 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
 	intel_hdmi->has_audio = false;
 	intel_hdmi->rgb_quant_range_selectable = false;
 
+	intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
+	intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
+
 	kfree(to_intel_connector(connector)->detect_edid);
 	to_intel_connector(connector)->detect_edid = NULL;
 }
 
+static void
+intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
+{
+	struct drm_i915_private *dev_priv = to_i915(connector->dev);
+	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
+	struct i2c_adapter *adapter =
+		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
+	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
+
+	if (type == DRM_DP_DUAL_MODE_NONE ||
+	    type == DRM_DP_DUAL_MODE_UNKNOWN)
+		return;
+
+	hdmi->dp_dual_mode.type = type;
+	hdmi->dp_dual_mode.max_tmds_clock =
+		drm_dp_dual_mode_max_tmds_clock(type, adapter);
+
+	DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
+		      drm_dp_get_dual_mode_type_name(type),
+		      hdmi->dp_dual_mode.max_tmds_clock);
+}
+
 static bool
 intel_hdmi_set_edid(struct drm_connector *connector, bool force)
 {
@@ -1372,6 +1412,8 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
 				    intel_gmbus_get_adapter(dev_priv,
 				    intel_hdmi->ddc_bus));
 
+		intel_hdmi_dp_dual_mode_detect(connector);
+
 		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
 	}
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
  2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
  2016-05-02 19:08 ` [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit ville.syrjala
@ 2016-05-02 19:08 ` ville.syrjala
  2016-05-04 10:13   ` Sharma, Shashank
  2016-05-02 19:08 ` [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT ville.syrjala
  2016-05-09 12:12 ` [PATCH v2 0/4] drm: DP++ adaptor support (v2) Ville Syrjälä
  4 siblings, 1 reply; 36+ messages in thread
From: ville.syrjala @ 2016-05-02 19:08 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

To save a bit of power, let's try to turn off the TMDS output buffers
in DP++ adaptors when we're not driving the port.

v2: Let's not forget DDI, toss in a debug message while at it
v3: Just do the TMDS output control based on adaptor type. With the
    helper getting passed the type, we wouldn't actually have to
    check at all in the driver, but the check eliminates the debug
    output more honest

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
 drivers/gpu/drm/i915/intel_drv.h  |  1 +
 drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
index 422ec81ef59b..a3600704e6d4 100644
--- a/drivers/gpu/drm/i915/intel_ddi.c
+++ b/drivers/gpu/drm/i915/intel_ddi.c
@@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
 	enum port port = intel_ddi_get_encoder_port(intel_encoder);
 	int type = intel_encoder->type;
 
+	if (type == INTEL_OUTPUT_HDMI) {
+		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
+
+		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
+	}
+
 	intel_prepare_ddi_buffer(intel_encoder);
 
 	if (type == INTEL_OUTPUT_EDP) {
@@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
 					DPLL_CTRL2_DDI_CLK_OFF(port)));
 	else if (INTEL_INFO(dev)->gen < 9)
 		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
+
+	if (type == INTEL_OUTPUT_HDMI) {
+		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
+
+		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
+	}
 }
 
 static void intel_enable_ddi(struct intel_encoder *intel_encoder)
diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index e94d18fb2ff1..dbcb80c70e2e 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
 struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
 bool intel_hdmi_compute_config(struct intel_encoder *encoder,
 			       struct intel_crtc_state *pipe_config);
+void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
 
 
 /* intel_lvds.c */
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index 31ca11134294..c4d93e6b4bed 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
 	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
 }
 
+void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
+{
+	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
+	struct i2c_adapter *adapter =
+		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
+
+	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return;
+
+	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
+		      enable ? "Enabling" : "Disabling");
+
+	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
+					 adapter, enable);
+}
+
 static void intel_hdmi_prepare(struct intel_encoder *encoder)
 {
 	struct drm_device *dev = encoder->base.dev;
@@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
 	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
 	u32 hdmi_val;
 
+	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
+
 	hdmi_val = SDVO_ENCODING_HDMI;
 	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
 		hdmi_val |= HDMI_COLOR_RANGE_16_235;
@@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
 	}
 
 	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
+
+	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
 }
 
 static void g4x_disable_hdmi(struct intel_encoder *encoder)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
  2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
                   ` (2 preceding siblings ...)
  2016-05-02 19:08 ` [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed ville.syrjala
@ 2016-05-02 19:08 ` ville.syrjala
  2016-05-04 10:24     ` Sharma, Shashank
  2016-05-04 11:45   ` [PATCH v3 " ville.syrjala
  2016-05-09 12:12 ` [PATCH v2 0/4] drm: DP++ adaptor support (v2) Ville Syrjälä
  4 siblings, 2 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-02 19:08 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

DP dual mode type 1 DVI adaptors aren't required to implement any
registers, so it's a bit hard to detect them. The best way would
be to check the state of the CONFIG1 pin, but we have no way to
do that. So as a last resort, check the VBT to see if the HDMI
port is in fact a dual mode capable DP port.

v2: Deal with VBT code reorganization
    Deal with DRM_DP_DUAL_MODE_UNKNOWN
    Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
    Accept both DP and HDMI dvo_port in VBT as my BSW
    at least declare its DP port as HDMI :(

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Reported-by: Tore Anderson <tore@fud.no>
Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h       |  1 +
 drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
 drivers/gpu/drm/i915/intel_vbt_defs.h | 13 +++++++++++++
 4 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ff6aaf0c4e1e..abe43922a08f 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
 bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
 bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
 bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
+bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
 bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
 bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
 				     enum port port);
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index 81518116e00d..8b68c4882fba 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
 	return false;
 }
 
+bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
+{
+	static const struct {
+		u16 dp, hdmi;
+	} port_mapping[] = {
+		/*
+		 * Buggy VBTs may declare DP ports as having
+		 * HDMI type dvo_port :( So let's check both.
+		 */
+		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
+		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
+		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
+		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
+	};
+	int i;
+
+	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
+		return false;
+
+	if (!dev_priv->vbt.child_dev_num)
+		return false;
+
+	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
+		const union child_device_config *p_child =
+			&dev_priv->vbt.child_dev[i];
+
+		if ((p_child->common.dvo_port == port_mapping[port].dp ||
+		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
+		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
+		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
+			return true;
+	}
+
+	return false;
+}
+
 /**
  * intel_bios_is_dsi_present - is DSI present in VBT
  * @dev_priv:	i915 device instance
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index c4d93e6b4bed..6b52c6accf6a 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
 }
 
 static void
-intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
+intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
 {
 	struct drm_i915_private *dev_priv = to_i915(connector->dev);
 	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
+	enum port port = hdmi_to_dig_port(hdmi)->port;
 	struct i2c_adapter *adapter =
 		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
 	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
 
-	if (type == DRM_DP_DUAL_MODE_NONE ||
-	    type == DRM_DP_DUAL_MODE_UNKNOWN)
+	/*
+	 * Type 1 DVI adaptors are not required to implement any
+	 * registers, so we can't always detect their presence.
+	 * Ideally we should be able to check the state of the
+	 * CONFIG1 pin, but no such luck on our hardware.
+	 *
+	 * The only method left to us is to check the VBT to see
+	 * if the port is a dual mode capable DP port. But let's
+	 * only do that when we sucesfully read the EDID, to avoid
+	 * confusing log messages about DP dual mode adaptors when
+	 * there's nothing connected to the port.
+	 */
+	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
+		if (has_edid &&
+		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
+			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
+			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
+		} else {
+			type = DRM_DP_DUAL_MODE_NONE;
+		}
+	}
+
+	if (type == DRM_DP_DUAL_MODE_NONE)
 		return;
 
 	hdmi->dp_dual_mode.type = type;
@@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
 				    intel_gmbus_get_adapter(dev_priv,
 				    intel_hdmi->ddc_bus));
 
-		intel_hdmi_dp_dual_mode_detect(connector);
+		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
 
 		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
 	}
diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
index a4a42f254c35..b1019e01e51d 100644
--- a/drivers/gpu/drm/i915/intel_vbt_defs.h
+++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
@@ -746,6 +746,7 @@ struct bdb_psr {
 #define	 DEVICE_TYPE_INT_TV	0x1009
 #define	 DEVICE_TYPE_HDMI	0x60D2
 #define	 DEVICE_TYPE_DP		0x68C6
+#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
 #define	 DEVICE_TYPE_eDP	0x78C6
 
 #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
@@ -780,6 +781,18 @@ struct bdb_psr {
 	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
 	 DEVICE_TYPE_ANALOG_OUTPUT)
 
+#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
+	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
+	 DEVICE_TYPE_NOT_HDMI_OUTPUT | \
+	 DEVICE_TYPE_MIPI_OUTPUT | \
+	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
+	 DEVICE_TYPE_LVDS_SINGALING | \
+	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
+	 DEVICE_TYPE_VIDEO_SIGNALING | \
+	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
+	 DEVICE_TYPE_DIGITAL_OUTPUT | \
+	 DEVICE_TYPE_ANALOG_OUTPUT)
+
 /* define the DVO port for HDMI output type */
 #define		DVO_B		1
 #define		DVO_C		2
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [Intel-gfx] [PATCH v2 1/4] drm: Add helper for DP++ adaptors
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
@ 2016-05-03  7:46     ` Jani Nikula
  2016-05-03 14:55   ` [PATCH v3 " ville.syrjala
  2016-05-03 16:33     ` Sharma, Shashank
  2 siblings, 0 replies; 36+ messages in thread
From: Jani Nikula @ 2016-05-03  7:46 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: Paulo Zanoni, Daniel Vetter, intel-gfx, Tore Anderson, stable

On Mon, 02 May 2016, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
>
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1 adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
>
> Type 1 adaptors provide access to their internal registers and the sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
>
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
>
> Other user controllable features that may be available in the adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
>
> v2: Pass adaptor type to helper functions to ease driver implementation
>     Fix a bunch of typoes (Paulo)
>     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
>     the type (Paulo)
>     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>     ease future LSPCON enabling
>     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/Makefile                  |   2 +-
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
>  include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
>  3 files changed, 440 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>  
>  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
>  		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>  
>  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..949c0fbeb542
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,356 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: DP dual mode (aka. DP++) adaptor helpers
> + *
> + * Helper functions to deal with DP dual mode adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> + * I2C-over-AUX. Source devices may choose to implement either of these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for return data
> + * size: sizo of the buffer

The parameters need to be prefixed with @ in kernel-doc. Same across the
patch series.

BR,
Jani.


> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for write data
> + * size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method would
> +	 * simply require the driver to know whether the port is a DP++
> +	 * port or a native HDMI port. Both of these methods are entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> +	 * the offset but ignore it, and instead they just always return
> +	 * data from the start of the HDMI ID buffer. So for a broken
> +	 * type 1 HDMI adaptor a single byte read will always give us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id, sizeof(adaptor_id));
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +		else if (is_type2_adaptor(adaptor_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock, sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> +		return 165000;
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
> +		return ret;
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> + * type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..b4603b9fc03d
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adators
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adators
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size);
> +
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> +
> +#endif

-- 
Jani Nikula, Intel Open Source Technology Center

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Intel-gfx] [PATCH v2 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-03  7:46     ` Jani Nikula
  0 siblings, 0 replies; 36+ messages in thread
From: Jani Nikula @ 2016-05-03  7:46 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: Daniel Vetter, intel-gfx, Tore Anderson, Paulo Zanoni, stable

On Mon, 02 May 2016, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
>
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1 adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
>
> Type 1 adaptors provide access to their internal registers and the sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
>
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
>
> Other user controllable features that may be available in the adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
>
> v2: Pass adaptor type to helper functions to ease driver implementation
>     Fix a bunch of typoes (Paulo)
>     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
>     the type (Paulo)
>     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>     ease future LSPCON enabling
>     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/Makefile                  |   2 +-
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
>  include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
>  3 files changed, 440 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>  
>  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
>  		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>  
>  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..949c0fbeb542
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,356 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: DP dual mode (aka. DP++) adaptor helpers
> + *
> + * Helper functions to deal with DP dual mode adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> + * I2C-over-AUX. Source devices may choose to implement either of these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for return data
> + * size: sizo of the buffer

The parameters need to be prefixed with @ in kernel-doc. Same across the
patch series.

BR,
Jani.


> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for write data
> + * size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method would
> +	 * simply require the driver to know whether the port is a DP++
> +	 * port or a native HDMI port. Both of these methods are entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> +	 * the offset but ignore it, and instead they just always return
> +	 * data from the start of the HDMI ID buffer. So for a broken
> +	 * type 1 HDMI adaptor a single byte read will always give us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id, sizeof(adaptor_id));
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +		else if (is_type2_adaptor(adaptor_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock, sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> +		return 165000;
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
> +		return ret;
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> + * type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..b4603b9fc03d
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adators
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adators
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size);
> +
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> +
> +#endif

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Intel-gfx] [PATCH v2 1/4] drm: Add helper for DP++ adaptors
  2016-05-03  7:46     ` Jani Nikula
@ 2016-05-03 13:38       ` Ville Syrjälä
  -1 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-03 13:38 UTC (permalink / raw)
  To: Jani Nikula
  Cc: dri-devel, Paulo Zanoni, Daniel Vetter, intel-gfx, Tore Anderson, stable

On Tue, May 03, 2016 at 10:46:26AM +0300, Jani Nikula wrote:
> On Mon, 02 May 2016, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> >
> > Add a helper which aids in the identification of DP dual mode
> > (aka. DP++) adaptors. There are several types of adaptors
> > specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> >
> > Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> > may go as high as 300MHz and they provide a register informing the
> > source device what the actual limit is. Supposedly also type 1 adaptors
> > may optionally implement this register. This TMDS clock limit is the
> > main reason why we need to identify these adaptors.
> >
> > Type 1 adaptors provide access to their internal registers and the sink
> > DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> > and I2C-over-AUX. A type 2 source device may choose to implement either
> > of these methods. If a source device implements the I2C-over-AUX
> > method, then the driver will obviously need specific support for such
> > adaptors since the port is driven like an HDMI port, but DDC
> > communication happes over the AUX channel.
> >
> > This helper should be enough to identify the adaptor type (some
> > type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> > clock limit. Another feature that may be available is control over
> > the TMDS output buffers on the adaptor, possibly allowing for some
> > power saving when the TMDS link is down.
> >
> > Other user controllable features that may be available in the adaptors
> > are downstream i2c bus speed control when using i2c-over-aux, and
> > some control over the CEC pin. I chose not to provide any helper
> > functions for those since I have no use for them in i915 at this time.
> > The rest of the registers in the adaptor are mostly just information,
> > eg. IEEE OUI, hardware and firmware revision, etc.
> >
> > v2: Pass adaptor type to helper functions to ease driver implementation
> >     Fix a bunch of typoes (Paulo)
> >     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
> >     the type (Paulo)
> >     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
> >     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
> >     ease future LSPCON enabling
> >     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/Makefile                  |   2 +-
> >  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
> >  include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
> >  3 files changed, 440 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
> >  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> >
> > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> > index 1a26b4eb1ce0..29f2ee9b9534 100644
> > --- a/drivers/gpu/drm/Makefile
> > +++ b/drivers/gpu/drm/Makefile
> > @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
> >  
> >  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
> >  		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> > -		drm_kms_helper_common.o
> > +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
> >  
> >  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> >  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> > diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > new file mode 100644
> > index 000000000000..949c0fbeb542
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > @@ -0,0 +1,356 @@
> > +/*
> > + * Copyright � 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include <linux/errno.h>
> > +#include <linux/export.h>
> > +#include <linux/i2c.h>
> > +#include <linux/slab.h>
> > +#include <linux/string.h>
> > +#include <drm/drm_dp_dual_mode_helper.h>
> > +#include <drm/drmP.h>
> > +
> > +/**
> > + * DOC: DP dual mode (aka. DP++) adaptor helpers
> > + *
> > + * Helper functions to deal with DP dual mode adaptors.
> > + *
> > + * Type 1:
> > + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> > + *
> > + * Type 2:
> > + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> > + * I2C-over-AUX. Source devices may choose to implement either of these
> > + * access methods.
> > + */
> > +
> > +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for return data
> > + * size: sizo of the buffer
> 
> The parameters need to be prefixed with @ in kernel-doc. Same across the
> patch series.

Hmm. I guess kernel-doc is just too complicated for me. I never get
the magic formatting right. v3 coming up...

> 
> BR,
> Jani.
> 
> 
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for write data
> > + * size: sizo of the buffer
> > + *
> > + * Writes @size bytes to the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msg = {
> > +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +		.flags = 0,
> > +		.len = 1 + size,
> > +		.buf = NULL,
> > +	};
> > +	void *data;
> > +	int ret;
> > +
> > +	data = kmalloc(msg.len, GFP_TEMPORARY);
> > +	if (!data)
> > +		return -ENOMEM;
> > +
> > +	msg.buf = data;
> > +
> > +	memcpy(data, &offset, 1);
> > +	memcpy(data + 1, buffer, size);
> > +
> > +	ret = i2c_transfer(adapter, &msg, 1);
> > +
> > +	kfree(data);
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != 1)
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> > +
> > +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> > +{
> > +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> > +		"DP-HDMI ADAPTOR\x04";
> > +
> > +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> > +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> > +}
> > +
> > +static bool is_type2_adaptor(uint8_t adaptor_id)
> > +{
> > +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> > +			      DP_DUAL_MODE_REV_TYPE2);
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Attempt to identify the type of the DP dual mode adaptor used.
> > + *
> > + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> > + * certain whether we're dealing with a native HDMI port or
> > + * a type 1 DVI dual mode adaptor. The driver will have to use
> > + * some other hardware/driver specific mechanism to make that
> > + * distinction.
> > + *
> > + * Returns:
> > + * The type of the DP dual mode adaptor used
> > + */
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> > +{
> > +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> > +	uint8_t adaptor_id = 0x00;
> > +	ssize_t ret;
> > +
> > +	/*
> > +	 * Let's see if the adaptor is there the by reading the
> > +	 * HDMI ID registers.
> > +	 *
> > +	 * Note that type 1 DVI adaptors are not required to implemnt
> > +	 * any registers, and that presents a problem for detection.
> > +	 * If the i2c transfer is nacked, we may or may not be dealing
> > +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> > +	 * the presence of the adaptor is required. One way would be
> > +	 * to check the state of the CONFIG1 pin, Another method would
> > +	 * simply require the driver to know whether the port is a DP++
> > +	 * port or a native HDMI port. Both of these methods are entirely
> > +	 * hardware/driver specific so we can't deal with them here.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> > +				    hdmi_id, sizeof(hdmi_id));
> > +	if (ret)
> > +		return DRM_DP_DUAL_MODE_UNKNOWN;
> > +
> > +	/*
> > +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> > +	 * the offset but ignore it, and instead they just always return
> > +	 * data from the start of the HDMI ID buffer. So for a broken
> > +	 * type 1 HDMI adaptor a single byte read will always give us
> > +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> > +	 * (assuming it implements any registers). Fortunately neither
> > +	 * of those values will match the type 2 signature of the
> > +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> > +	 * the type 2 adaptor detection safely even in the presence
> > +	 * of broken type 1 adaptors.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> > +				    &adaptor_id, sizeof(adaptor_id));
> > +	if (ret == 0) {
> > +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> > +		else if (is_type2_adaptor(adaptor_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> > +	}
> > +
> > +	if (is_hdmi_adaptor(hdmi_id))
> > +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> > +	else
> > +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> > +
> > +/**
> > + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Determine the max TMDS clock the adaptor supports based on the
> > + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> > + * register (on type2 adaptors). As some type 1 adaptors have
> > + * problems with registers (see comments in drm_dp_dual_mode_detect())
> > + * we don't read the register on those, instead we simply assume
> > + * a 165 MHz limit based on the specification.
> > + *
> > + * Returns:
> > + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> > + */
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter)
> > +{
> > +	uint8_t max_tmds_clock;
> > +	ssize_t ret;
> > +
> > +	/* native HDMI so no limit */
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> > +		return 0;
> > +
> > +	/*
> > +	 * Type 1 adaptors are limited to 165MHz
> > +	 * Type 2 adaptors can tells us their limit
> > +	 */
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 165000;
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> > +				    &max_tmds_clock, sizeof(max_tmds_clock));
> > +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> > +		return 165000;
> > +
> > +	return max_tmds_clock * 5000 / 2;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> > +
> > +/**
> > + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enabled: current state of the TMDS output buffers
> > + *
> > + * Get the state of the TMDS output buffers in the adaptor. For
> > + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> > + * register. As some type 1 adaptors have problems with registers
> > + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> > + * register on those, instead we simply assume that the buffers
> > + * are always enabled.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter,
> > +				     bool *enabled)
> > +{
> > +	uint8_t tmds_oen;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> > +		*enabled = true;
> > +		return 0;
> > +	}
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				    &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> > +		return ret;
> > +
> > +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> > +
> > +/**
> > + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enable: enable (as opposed to disable) the TMDS output buffers
> > + *
> > + * Set the state of the TMDS output buffers in the adaptor. For
> > + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> > + * some type 1 adaptors have problems with registers (see comments
> > + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> > + * making this function a no-op on type 1 adaptors.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable)
> > +{
> > +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 0;
> > +
> > +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				     &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> > +		return ret;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> > +
> > +/**
> > + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> > + * type: DP dual mode adaptor type
> > + *
> > + * Returns:
> > + * String representation of the DP dual mode adaptor type
> > + */
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> > +{
> > +	switch (type) {
> > +	case DRM_DP_DUAL_MODE_NONE:
> > +		return "none";
> > +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> > +		return "type 1 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> > +		return "type 1 HDMI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> > +		return "type 2 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> > +		return "type 2 HDMI";
> > +	default:
> > +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> > +		return "unknown";
> > +	}
> > +}
> > +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> > diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> > new file mode 100644
> > index 000000000000..b4603b9fc03d
> > --- /dev/null
> > +++ b/include/drm/drm_dp_dual_mode_helper.h
> > @@ -0,0 +1,83 @@
> > +/*
> > + * Copyright � 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> > +#define DRM_DP_DUAL_MODE_HELPER_H
> > +
> > +#include <linux/types.h>
> > +
> > +/*
> > + * Optional for type 1 DVI adaptors
> > + * Mandatory for type 1 HDMI and type 2 adators
> > + */
> > +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> > +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> > +/*
> > + * Optional for type 1 adaptors
> > + * Mandatory for type 2 adators
> > + */
> > +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> > +#define  DP_DUAL_MODE_REV_MASK 0x07
> > +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> > +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> > +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> > +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> > +#define  DP_DUAL_IEEE_OUI_LEN 3
> > +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> > +#define  DP_DUAL_DEVICE_ID_LEN 6
> > +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> > +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> > +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> > +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> > +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> > +#define DP_DUAL_MODE_TMDS_OEN 0x20
> > +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> > +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> > +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> > +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> > +
> > +struct i2c_adapter;
> > +
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size);
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size);
> > +
> > +enum drm_dp_dual_mode_type {
> > +	DRM_DP_DUAL_MODE_NONE,
> > +	DRM_DP_DUAL_MODE_UNKNOWN,
> > +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> > +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> > +};
> > +
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool *enabled);
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable);
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> > +
> > +#endif
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center

-- 
Ville Syrj�l�
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [Intel-gfx] [PATCH v2 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-03 13:38       ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-03 13:38 UTC (permalink / raw)
  To: Jani Nikula
  Cc: dri-devel, Paulo Zanoni, Daniel Vetter, intel-gfx, Tore Anderson, stable

On Tue, May 03, 2016 at 10:46:26AM +0300, Jani Nikula wrote:
> On Mon, 02 May 2016, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Add a helper which aids in the identification of DP dual mode
> > (aka. DP++) adaptors. There are several types of adaptors
> > specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> >
> > Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> > may go as high as 300MHz and they provide a register informing the
> > source device what the actual limit is. Supposedly also type 1 adaptors
> > may optionally implement this register. This TMDS clock limit is the
> > main reason why we need to identify these adaptors.
> >
> > Type 1 adaptors provide access to their internal registers and the sink
> > DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> > and I2C-over-AUX. A type 2 source device may choose to implement either
> > of these methods. If a source device implements the I2C-over-AUX
> > method, then the driver will obviously need specific support for such
> > adaptors since the port is driven like an HDMI port, but DDC
> > communication happes over the AUX channel.
> >
> > This helper should be enough to identify the adaptor type (some
> > type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> > clock limit. Another feature that may be available is control over
> > the TMDS output buffers on the adaptor, possibly allowing for some
> > power saving when the TMDS link is down.
> >
> > Other user controllable features that may be available in the adaptors
> > are downstream i2c bus speed control when using i2c-over-aux, and
> > some control over the CEC pin. I chose not to provide any helper
> > functions for those since I have no use for them in i915 at this time.
> > The rest of the registers in the adaptor are mostly just information,
> > eg. IEEE OUI, hardware and firmware revision, etc.
> >
> > v2: Pass adaptor type to helper functions to ease driver implementation
> >     Fix a bunch of typoes (Paulo)
> >     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
> >     the type (Paulo)
> >     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
> >     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
> >     ease future LSPCON enabling
> >     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/Makefile                  |   2 +-
> >  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
> >  include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
> >  3 files changed, 440 insertions(+), 1 deletion(-)
> >  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
> >  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> >
> > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> > index 1a26b4eb1ce0..29f2ee9b9534 100644
> > --- a/drivers/gpu/drm/Makefile
> > +++ b/drivers/gpu/drm/Makefile
> > @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
> >  
> >  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
> >  		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> > -		drm_kms_helper_common.o
> > +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
> >  
> >  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> >  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> > diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > new file mode 100644
> > index 000000000000..949c0fbeb542
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > @@ -0,0 +1,356 @@
> > +/*
> > + * Copyright © 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include <linux/errno.h>
> > +#include <linux/export.h>
> > +#include <linux/i2c.h>
> > +#include <linux/slab.h>
> > +#include <linux/string.h>
> > +#include <drm/drm_dp_dual_mode_helper.h>
> > +#include <drm/drmP.h>
> > +
> > +/**
> > + * DOC: DP dual mode (aka. DP++) adaptor helpers
> > + *
> > + * Helper functions to deal with DP dual mode adaptors.
> > + *
> > + * Type 1:
> > + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> > + *
> > + * Type 2:
> > + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> > + * I2C-over-AUX. Source devices may choose to implement either of these
> > + * access methods.
> > + */
> > +
> > +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for return data
> > + * size: sizo of the buffer
> 
> The parameters need to be prefixed with @ in kernel-doc. Same across the
> patch series.

Hmm. I guess kernel-doc is just too complicated for me. I never get
the magic formatting right. v3 coming up...

> 
> BR,
> Jani.
> 
> 
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for write data
> > + * size: sizo of the buffer
> > + *
> > + * Writes @size bytes to the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msg = {
> > +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +		.flags = 0,
> > +		.len = 1 + size,
> > +		.buf = NULL,
> > +	};
> > +	void *data;
> > +	int ret;
> > +
> > +	data = kmalloc(msg.len, GFP_TEMPORARY);
> > +	if (!data)
> > +		return -ENOMEM;
> > +
> > +	msg.buf = data;
> > +
> > +	memcpy(data, &offset, 1);
> > +	memcpy(data + 1, buffer, size);
> > +
> > +	ret = i2c_transfer(adapter, &msg, 1);
> > +
> > +	kfree(data);
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != 1)
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> > +
> > +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> > +{
> > +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> > +		"DP-HDMI ADAPTOR\x04";
> > +
> > +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> > +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> > +}
> > +
> > +static bool is_type2_adaptor(uint8_t adaptor_id)
> > +{
> > +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> > +			      DP_DUAL_MODE_REV_TYPE2);
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Attempt to identify the type of the DP dual mode adaptor used.
> > + *
> > + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> > + * certain whether we're dealing with a native HDMI port or
> > + * a type 1 DVI dual mode adaptor. The driver will have to use
> > + * some other hardware/driver specific mechanism to make that
> > + * distinction.
> > + *
> > + * Returns:
> > + * The type of the DP dual mode adaptor used
> > + */
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> > +{
> > +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> > +	uint8_t adaptor_id = 0x00;
> > +	ssize_t ret;
> > +
> > +	/*
> > +	 * Let's see if the adaptor is there the by reading the
> > +	 * HDMI ID registers.
> > +	 *
> > +	 * Note that type 1 DVI adaptors are not required to implemnt
> > +	 * any registers, and that presents a problem for detection.
> > +	 * If the i2c transfer is nacked, we may or may not be dealing
> > +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> > +	 * the presence of the adaptor is required. One way would be
> > +	 * to check the state of the CONFIG1 pin, Another method would
> > +	 * simply require the driver to know whether the port is a DP++
> > +	 * port or a native HDMI port. Both of these methods are entirely
> > +	 * hardware/driver specific so we can't deal with them here.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> > +				    hdmi_id, sizeof(hdmi_id));
> > +	if (ret)
> > +		return DRM_DP_DUAL_MODE_UNKNOWN;
> > +
> > +	/*
> > +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> > +	 * the offset but ignore it, and instead they just always return
> > +	 * data from the start of the HDMI ID buffer. So for a broken
> > +	 * type 1 HDMI adaptor a single byte read will always give us
> > +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> > +	 * (assuming it implements any registers). Fortunately neither
> > +	 * of those values will match the type 2 signature of the
> > +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> > +	 * the type 2 adaptor detection safely even in the presence
> > +	 * of broken type 1 adaptors.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> > +				    &adaptor_id, sizeof(adaptor_id));
> > +	if (ret == 0) {
> > +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> > +		else if (is_type2_adaptor(adaptor_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> > +	}
> > +
> > +	if (is_hdmi_adaptor(hdmi_id))
> > +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> > +	else
> > +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> > +
> > +/**
> > + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Determine the max TMDS clock the adaptor supports based on the
> > + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> > + * register (on type2 adaptors). As some type 1 adaptors have
> > + * problems with registers (see comments in drm_dp_dual_mode_detect())
> > + * we don't read the register on those, instead we simply assume
> > + * a 165 MHz limit based on the specification.
> > + *
> > + * Returns:
> > + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> > + */
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter)
> > +{
> > +	uint8_t max_tmds_clock;
> > +	ssize_t ret;
> > +
> > +	/* native HDMI so no limit */
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> > +		return 0;
> > +
> > +	/*
> > +	 * Type 1 adaptors are limited to 165MHz
> > +	 * Type 2 adaptors can tells us their limit
> > +	 */
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 165000;
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> > +				    &max_tmds_clock, sizeof(max_tmds_clock));
> > +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> > +		return 165000;
> > +
> > +	return max_tmds_clock * 5000 / 2;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> > +
> > +/**
> > + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enabled: current state of the TMDS output buffers
> > + *
> > + * Get the state of the TMDS output buffers in the adaptor. For
> > + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> > + * register. As some type 1 adaptors have problems with registers
> > + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> > + * register on those, instead we simply assume that the buffers
> > + * are always enabled.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter,
> > +				     bool *enabled)
> > +{
> > +	uint8_t tmds_oen;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> > +		*enabled = true;
> > +		return 0;
> > +	}
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				    &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> > +		return ret;
> > +
> > +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> > +
> > +/**
> > + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enable: enable (as opposed to disable) the TMDS output buffers
> > + *
> > + * Set the state of the TMDS output buffers in the adaptor. For
> > + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> > + * some type 1 adaptors have problems with registers (see comments
> > + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> > + * making this function a no-op on type 1 adaptors.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable)
> > +{
> > +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 0;
> > +
> > +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				     &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> > +		return ret;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> > +
> > +/**
> > + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> > + * type: DP dual mode adaptor type
> > + *
> > + * Returns:
> > + * String representation of the DP dual mode adaptor type
> > + */
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> > +{
> > +	switch (type) {
> > +	case DRM_DP_DUAL_MODE_NONE:
> > +		return "none";
> > +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> > +		return "type 1 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> > +		return "type 1 HDMI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> > +		return "type 2 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> > +		return "type 2 HDMI";
> > +	default:
> > +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> > +		return "unknown";
> > +	}
> > +}
> > +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> > diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> > new file mode 100644
> > index 000000000000..b4603b9fc03d
> > --- /dev/null
> > +++ b/include/drm/drm_dp_dual_mode_helper.h
> > @@ -0,0 +1,83 @@
> > +/*
> > + * Copyright © 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> > +#define DRM_DP_DUAL_MODE_HELPER_H
> > +
> > +#include <linux/types.h>
> > +
> > +/*
> > + * Optional for type 1 DVI adaptors
> > + * Mandatory for type 1 HDMI and type 2 adators
> > + */
> > +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> > +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> > +/*
> > + * Optional for type 1 adaptors
> > + * Mandatory for type 2 adators
> > + */
> > +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> > +#define  DP_DUAL_MODE_REV_MASK 0x07
> > +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> > +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> > +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> > +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> > +#define  DP_DUAL_IEEE_OUI_LEN 3
> > +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> > +#define  DP_DUAL_DEVICE_ID_LEN 6
> > +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> > +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> > +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> > +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> > +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> > +#define DP_DUAL_MODE_TMDS_OEN 0x20
> > +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> > +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> > +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> > +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> > +
> > +struct i2c_adapter;
> > +
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size);
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size);
> > +
> > +enum drm_dp_dual_mode_type {
> > +	DRM_DP_DUAL_MODE_NONE,
> > +	DRM_DP_DUAL_MODE_UNKNOWN,
> > +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> > +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> > +};
> > +
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool *enabled);
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable);
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> > +
> > +#endif
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center

-- 
Ville Syrjälä
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v3 1/4] drm: Add helper for DP++ adaptors
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
  2016-05-03  7:46     ` Jani Nikula
@ 2016-05-03 14:55   ` ville.syrjala
  2016-05-03 17:56       ` ville.syrjala
  2016-05-03 16:33     ` Sharma, Shashank
  2 siblings, 1 reply; 36+ messages in thread
From: ville.syrjala @ 2016-05-03 14:55 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a helper which aids in the identification of DP dual mode
(aka. DP++) adaptors. There are several types of adaptors
specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI

Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
may go as high as 300MHz and they provide a register informing the
source device what the actual limit is. Supposedly also type 1 adaptors
may optionally implement this register. This TMDS clock limit is the
main reason why we need to identify these adaptors.

Type 1 adaptors provide access to their internal registers and the sink
DDC bus through I2C. Type 2 adaptors provide this access both via I2C
and I2C-over-AUX. A type 2 source device may choose to implement either
of these methods. If a source device implements the I2C-over-AUX
method, then the driver will obviously need specific support for such
adaptors since the port is driven like an HDMI port, but DDC
communication happes over the AUX channel.

This helper should be enough to identify the adaptor type (some
type 1 DVI adaptors may be a slight exception) and the maximum TMDS
clock limit. Another feature that may be available is control over
the TMDS output buffers on the adaptor, possibly allowing for some
power saving when the TMDS link is down.

Other user controllable features that may be available in the adaptors
are downstream i2c bus speed control when using i2c-over-aux, and
some control over the CEC pin. I chose not to provide any helper
functions for those since I have no use for them in i915 at this time.
The rest of the registers in the adaptor are mostly just information,
eg. IEEE OUI, hardware and firmware revision, etc.

v2: Pass adaptor type to helper functions to ease driver implementation
    Fix a bunch of typoes (Paulo)
    Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
    the type (Paulo)
    Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
    Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
    ease future LSPCON enabling
    Remove the unused DP_DUAL_MODE_LAST_RESERVED define
v3: Fix kernel doc function argument descriptions (Jani)
    s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
    Add kernel doc for enum drm_dp_dual_mode_type
    Actually build the docs
    Fix more typoes

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 Documentation/DocBook/gpu.tmpl            |   6 +
 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
 include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
 4 files changed, 455 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 1464fb2f3c46..c248124357df 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_dp_helper.c
     </sect2>
     <sect2>
+      <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
+!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
+!Iinclude/drm/drm_dp_dual_mode_helper.h
+!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
+    </sect2>
+    <sect2>
       <title>Display Port MST Helper Functions Reference</title>
 !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
 !Iinclude/drm/drm_dp_mst_helper.h
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 1a26b4eb1ce0..29f2ee9b9534 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
-		drm_kms_helper_common.o
+		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
 
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
new file mode 100644
index 000000000000..af68c4cdf817
--- /dev/null
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -0,0 +1,356 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dp_dual_mode_helper.h>
+#include <drm/drmP.h>
+
+/**
+ * DOC: dp dual mode helpers
+ *
+ * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
+ *
+ * Type 1:
+ * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
+ *
+ * Type 2:
+ * Adaptor registers and sink DDC bus can be accessed either via I2C or
+ * I2C-over-AUX. Source devices may choose to implement either of these
+ * access methods.
+ */
+
+#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
+
+/**
+ * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for return data
+ * @size: sizo of the buffer
+ *
+ * Reads @size bytes from the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size)
+{
+	struct i2c_msg msgs[] = {
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = 0,
+			.len = 1,
+			.buf = &offset,
+		},
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = I2C_M_RD,
+			.len = size,
+			.buf = buffer,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret < 0)
+		return ret;
+	if (ret != ARRAY_SIZE(msgs))
+		return -EPROTO;
+
+	return 0;
+}
+
+/**
+ * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for write data
+ * @size: sizo of the buffer
+ *
+ * Writes @size bytes to the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size)
+{
+	struct i2c_msg msg = {
+		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+		.flags = 0,
+		.len = 1 + size,
+		.buf = NULL,
+	};
+	void *data;
+	int ret;
+
+	data = kmalloc(msg.len, GFP_TEMPORARY);
+	if (!data)
+		return -ENOMEM;
+
+	msg.buf = data;
+
+	memcpy(data, &offset, 1);
+	memcpy(data + 1, buffer, size);
+
+	ret = i2c_transfer(adapter, &msg, 1);
+
+	kfree(data);
+
+	if (ret < 0)
+		return ret;
+	if (ret != 1)
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_write);
+
+static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
+{
+	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
+		"DP-HDMI ADAPTOR\x04";
+
+	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
+		      sizeof(dp_dual_mode_hdmi_id)) == 0;
+}
+
+static bool is_type2_adaptor(uint8_t adaptor_id)
+{
+	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
+			      DP_DUAL_MODE_REV_TYPE2);
+}
+
+/**
+ * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Attempt to identify the type of the DP dual mode adaptor used.
+ *
+ * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
+ * certain whether we're dealing with a native HDMI port or
+ * a type 1 DVI dual mode adaptor. The driver will have to use
+ * some other hardware/driver specific mechanism to make that
+ * distinction.
+ *
+ * Returns:
+ * The type of the DP dual mode adaptor used
+ */
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
+{
+	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
+	uint8_t adaptor_id = 0x00;
+	ssize_t ret;
+
+	/*
+	 * Let's see if the adaptor is there the by reading the
+	 * HDMI ID registers.
+	 *
+	 * Note that type 1 DVI adaptors are not required to implemnt
+	 * any registers, and that presents a problem for detection.
+	 * If the i2c transfer is nacked, we may or may not be dealing
+	 * with a type 1 DVI adaptor. Some other mechanism of detecting
+	 * the presence of the adaptor is required. One way would be
+	 * to check the state of the CONFIG1 pin, Another method would
+	 * simply require the driver to know whether the port is a DP++
+	 * port or a native HDMI port. Both of these methods are entirely
+	 * hardware/driver specific so we can't deal with them here.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
+				    hdmi_id, sizeof(hdmi_id));
+	if (ret)
+		return DRM_DP_DUAL_MODE_UNKNOWN;
+
+	/*
+	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
+	 * the offset but ignore it, and instead they just always return
+	 * data from the start of the HDMI ID buffer. So for a broken
+	 * type 1 HDMI adaptor a single byte read will always give us
+	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
+	 * (assuming it implements any registers). Fortunately neither
+	 * of those values will match the type 2 signature of the
+	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
+	 * the type 2 adaptor detection safely even in the presence
+	 * of broken type 1 adaptors.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
+				    &adaptor_id, sizeof(adaptor_id));
+	if (ret == 0) {
+		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
+			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
+		else if (is_type2_adaptor(adaptor_id))
+			return DRM_DP_DUAL_MODE_TYPE2_DVI;
+	}
+
+	if (is_hdmi_adaptor(hdmi_id))
+		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
+	else
+		return DRM_DP_DUAL_MODE_TYPE1_DVI;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_detect);
+
+/**
+ * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Determine the max TMDS clock the adaptor supports based on the
+ * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
+ * register (on type2 adaptors). As some type 1 adaptors have
+ * problems with registers (see comments in drm_dp_dual_mode_detect())
+ * we don't read the register on those, instead we simply assume
+ * a 165 MHz limit based on the specification.
+ *
+ * Returns:
+ * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
+ */
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter)
+{
+	uint8_t max_tmds_clock;
+	ssize_t ret;
+
+	/* native HDMI so no limit */
+	if (type == DRM_DP_DUAL_MODE_NONE)
+		return 0;
+
+	/*
+	 * Type 1 adaptors are limited to 165MHz
+	 * Type 2 adaptors can tells us their limit
+	 */
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 165000;
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
+				    &max_tmds_clock, sizeof(max_tmds_clock));
+	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
+		return 165000;
+
+	return max_tmds_clock * 5000 / 2;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
+
+/**
+ * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enabled: current state of the TMDS output buffers
+ *
+ * Get the state of the TMDS output buffers in the adaptor. For
+ * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
+ * register. As some type 1 adaptors have problems with registers
+ * (see comments in drm_dp_dual_mode_detect()) we don't read the
+ * register on those, instead we simply assume that the buffers
+ * are always enabled.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter,
+				     bool *enabled)
+{
+	uint8_t tmds_oen;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
+		*enabled = true;
+		return 0;
+	}
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
+				    &tmds_oen, sizeof(tmds_oen));
+	if (ret)
+		return ret;
+
+	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
+
+/**
+ * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enable: enable (as opposed to disable) the TMDS output buffers
+ *
+ * Set the state of the TMDS output buffers in the adaptor. For
+ * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
+ * some type 1 adaptors have problems with registers (see comments
+ * in drm_dp_dual_mode_detect()) we avoid touching the register,
+ * making this function a no-op on type 1 adaptors.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable)
+{
+	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 0;
+
+	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
+				     &tmds_oen, sizeof(tmds_oen));
+	if (ret)
+		return ret;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
+
+/**
+ * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
+ * @type: DP dual mode adaptor type
+ *
+ * Returns:
+ * String representation of the DP dual mode adaptor type
+ */
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
+{
+	switch (type) {
+	case DRM_DP_DUAL_MODE_NONE:
+		return "none";
+	case DRM_DP_DUAL_MODE_TYPE1_DVI:
+		return "type 1 DVI";
+	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
+		return "type 1 HDMI";
+	case DRM_DP_DUAL_MODE_TYPE2_DVI:
+		return "type 2 DVI";
+	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
+		return "type 2 HDMI";
+	default:
+		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
+		return "unknown";
+	}
+}
+EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
new file mode 100644
index 000000000000..e8a9dfd0e055
--- /dev/null
+++ b/include/drm/drm_dp_dual_mode_helper.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DP_DUAL_MODE_HELPER_H
+#define DRM_DP_DUAL_MODE_HELPER_H
+
+#include <linux/types.h>
+
+/*
+ * Optional for type 1 DVI adaptors
+ * Mandatory for type 1 HDMI and type 2 adaptors
+ */
+#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
+#define  DP_DUAL_MODE_HDMI_ID_LEN 16
+/*
+ * Optional for type 1 adaptors
+ * Mandatory for type 2 adaptors
+ */
+#define DP_DUAL_MODE_ADAPTOR_ID 0x10
+#define  DP_DUAL_MODE_REV_MASK 0x07
+#define  DP_DUAL_MODE_REV_TYPE2 0x00
+#define  DP_DUAL_MODE_TYPE_MASK 0xf0
+#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
+#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
+#define  DP_DUAL_IEEE_OUI_LEN 3
+#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
+#define  DP_DUAL_DEVICE_ID_LEN 6
+#define DP_DUAL_MODE_HARDWARE_REV 0x1a
+#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
+#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
+#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
+#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
+#define DP_DUAL_MODE_TMDS_OEN 0x20
+#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
+#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
+#define  DP_DUAL_MODE_CEC_ENABLE 0x01
+#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
+
+struct i2c_adapter;
+
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size);
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size);
+
+/**
+ * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
+ */
+enum drm_dp_dual_mode_type {
+	DRM_DP_DUAL_MODE_NONE,
+	DRM_DP_DUAL_MODE_UNKNOWN,
+	DRM_DP_DUAL_MODE_TYPE1_DVI,
+	DRM_DP_DUAL_MODE_TYPE1_HDMI,
+	DRM_DP_DUAL_MODE_TYPE2_DVI,
+	DRM_DP_DUAL_MODE_TYPE2_HDMI,
+};
+
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter);
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool *enabled);
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable);
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
+
+#endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 1/4] drm: Add helper for DP++ adaptors
  2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
@ 2016-05-03 16:33     ` Sharma, Shashank
  2016-05-03 14:55   ` [PATCH v3 " ville.syrjala
  2016-05-03 16:33     ` Sharma, Shashank
  2 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-03 16:33 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter



On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
>
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1 adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
>
> Type 1 adaptors provide access to their internal registers and the sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
>
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
>
> Other user controllable features that may be available in the adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
>
> v2: Pass adaptor type to helper functions to ease driver implementation
>      Fix a bunch of typoes (Paulo)
>      Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
>      the type (Paulo)
>      Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>      Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>      ease future LSPCON enabling
>      Remove the unused DP_DUAL_MODE_LAST_RESERVED define
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/Makefile                  |   2 +-
>   drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
>   include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
>   3 files changed, 440 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>   create mode 100644 include/drm/drm_dp_dual_mode_helper.h
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>
>   drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
>   		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>
>   drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>   drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..949c0fbeb542
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,356 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: DP dual mode (aka. DP++) adaptor helpers
> + *
> + * Helper functions to deal with DP dual mode adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> + * I2C-over-AUX. Source devices may choose to implement either of these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for return data
> + * size: sizo of the buffer
> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for write data
> + * size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method would
> +	 * simply require the driver to know whether the port is a DP++
> +	 * port or a native HDMI port. Both of these methods are entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> +	 * the offset but ignore it, and instead they just always return
> +	 * data from the start of the HDMI ID buffer. So for a broken
> +	 * type 1 HDMI adaptor a single byte read will always give us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id, sizeof(adaptor_id));
can we read all 16 bytes in a single read, and then split the characters 
into dongle_signature and adaptor_id ?
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +		else if (is_type2_adaptor(adaptor_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
	can we save one if, or its too late for me to work :) ?
		is_type2_adaptor() {
			is_hdmi_adaptor()
				return type2_hdmi;
			else
				return type2_dvi
		}
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock, sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> +		return 165000;
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
debug message here might help in failure cases.
> +		return ret;
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
debug message here might help in failure cases.
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> + * type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
do we need a warning here, or a DRM_ERROR should work ?
I am afraid we will show a back-trace for all non-compliant adapters.
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..b4603b9fc03d
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adators
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adators
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size);
> +
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
what does dual mode none indicate (considering we have an unknown case 
below) ?
Regards
Shashank
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> +
> +#endif
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-03 16:33     ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-03 16:33 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: Daniel Vetter, intel-gfx, Tore Anderson, Paulo Zanoni, stable



On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
>
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1 adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
>
> Type 1 adaptors provide access to their internal registers and the sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
>
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
>
> Other user controllable features that may be available in the adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
>
> v2: Pass adaptor type to helper functions to ease driver implementation
>      Fix a bunch of typoes (Paulo)
>      Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
>      the type (Paulo)
>      Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>      Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>      ease future LSPCON enabling
>      Remove the unused DP_DUAL_MODE_LAST_RESERVED define
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/Makefile                  |   2 +-
>   drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
>   include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
>   3 files changed, 440 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>   create mode 100644 include/drm/drm_dp_dual_mode_helper.h
>
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>
>   drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
>   		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>
>   drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>   drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..949c0fbeb542
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,356 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: DP dual mode (aka. DP++) adaptor helpers
> + *
> + * Helper functions to deal with DP dual mode adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> + * I2C-over-AUX. Source devices may choose to implement either of these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for return data
> + * size: sizo of the buffer
> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> + * adapter: I2C adapter for the DDC bus
> + * offset: register offset
> + * buffer: buffer for write data
> + * size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method would
> +	 * simply require the driver to know whether the port is a DP++
> +	 * port or a native HDMI port. Both of these methods are entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> +	 * the offset but ignore it, and instead they just always return
> +	 * data from the start of the HDMI ID buffer. So for a broken
> +	 * type 1 HDMI adaptor a single byte read will always give us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id, sizeof(adaptor_id));
can we read all 16 bytes in a single read, and then split the characters 
into dongle_signature and adaptor_id ?
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +		else if (is_type2_adaptor(adaptor_id))
> +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
	can we save one if, or its too late for me to work :) ?
		is_type2_adaptor() {
			is_hdmi_adaptor()
				return type2_hdmi;
			else
				return type2_dvi
		}
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock, sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> +		return 165000;
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
debug message here might help in failure cases.
> +		return ret;
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> + * type: DP dual mode adaptor type
> + * adapter: I2C adapter for the DDC bus
> + * enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret)
debug message here might help in failure cases.
> +		return ret;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> + * type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
do we need a warning here, or a DRM_ERROR should work ?
I am afraid we will show a back-trace for all non-compliant adapters.
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..b4603b9fc03d
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,83 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adators
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adators
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size);
> +
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
what does dual mode none indicate (considering we have an unknown case 
below) ?
Regards
Shashank
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> +
> +#endif
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 1/4] drm: Add helper for DP++ adaptors
  2016-05-03 16:33     ` Sharma, Shashank
@ 2016-05-03 17:38       ` Ville Syrjälä
  -1 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-03 17:38 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

On Tue, May 03, 2016 at 10:03:30PM +0530, Sharma, Shashank wrote:
> 
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> >
> > Add a helper which aids in the identification of DP dual mode
> > (aka. DP++) adaptors. There are several types of adaptors
> > specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> >
> > Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> > may go as high as 300MHz and they provide a register informing the
> > source device what the actual limit is. Supposedly also type 1 adaptors
> > may optionally implement this register. This TMDS clock limit is the
> > main reason why we need to identify these adaptors.
> >
> > Type 1 adaptors provide access to their internal registers and the sink
> > DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> > and I2C-over-AUX. A type 2 source device may choose to implement either
> > of these methods. If a source device implements the I2C-over-AUX
> > method, then the driver will obviously need specific support for such
> > adaptors since the port is driven like an HDMI port, but DDC
> > communication happes over the AUX channel.
> >
> > This helper should be enough to identify the adaptor type (some
> > type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> > clock limit. Another feature that may be available is control over
> > the TMDS output buffers on the adaptor, possibly allowing for some
> > power saving when the TMDS link is down.
> >
> > Other user controllable features that may be available in the adaptors
> > are downstream i2c bus speed control when using i2c-over-aux, and
> > some control over the CEC pin. I chose not to provide any helper
> > functions for those since I have no use for them in i915 at this time.
> > The rest of the registers in the adaptor are mostly just information,
> > eg. IEEE OUI, hardware and firmware revision, etc.
> >
> > v2: Pass adaptor type to helper functions to ease driver implementation
> >      Fix a bunch of typoes (Paulo)
> >      Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
> >      the type (Paulo)
> >      Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
> >      Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
> >      ease future LSPCON enabling
> >      Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/Makefile                  |   2 +-
> >   drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
> >   include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
> >   3 files changed, 440 insertions(+), 1 deletion(-)
> >   create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
> >   create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> >
> > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> > index 1a26b4eb1ce0..29f2ee9b9534 100644
> > --- a/drivers/gpu/drm/Makefile
> > +++ b/drivers/gpu/drm/Makefile
> > @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
> >
> >   drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
> >   		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> > -		drm_kms_helper_common.o
> > +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
> >
> >   drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> >   drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> > diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > new file mode 100644
> > index 000000000000..949c0fbeb542
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > @@ -0,0 +1,356 @@
> > +/*
> > + * Copyright � 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include <linux/errno.h>
> > +#include <linux/export.h>
> > +#include <linux/i2c.h>
> > +#include <linux/slab.h>
> > +#include <linux/string.h>
> > +#include <drm/drm_dp_dual_mode_helper.h>
> > +#include <drm/drmP.h>
> > +
> > +/**
> > + * DOC: DP dual mode (aka. DP++) adaptor helpers
> > + *
> > + * Helper functions to deal with DP dual mode adaptors.
> > + *
> > + * Type 1:
> > + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> > + *
> > + * Type 2:
> > + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> > + * I2C-over-AUX. Source devices may choose to implement either of these
> > + * access methods.
> > + */
> > +
> > +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for return data
> > + * size: sizo of the buffer
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for write data
> > + * size: sizo of the buffer
> > + *
> > + * Writes @size bytes to the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msg = {
> > +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +		.flags = 0,
> > +		.len = 1 + size,
> > +		.buf = NULL,
> > +	};
> > +	void *data;
> > +	int ret;
> > +
> > +	data = kmalloc(msg.len, GFP_TEMPORARY);
> > +	if (!data)
> > +		return -ENOMEM;
> > +
> > +	msg.buf = data;
> > +
> > +	memcpy(data, &offset, 1);
> > +	memcpy(data + 1, buffer, size);
> > +
> > +	ret = i2c_transfer(adapter, &msg, 1);
> > +
> > +	kfree(data);
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != 1)
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> > +
> > +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> > +{
> > +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> > +		"DP-HDMI ADAPTOR\x04";
> > +
> > +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> > +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> > +}
> > +
> > +static bool is_type2_adaptor(uint8_t adaptor_id)
> > +{
> > +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> > +			      DP_DUAL_MODE_REV_TYPE2);
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Attempt to identify the type of the DP dual mode adaptor used.
> > + *
> > + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> > + * certain whether we're dealing with a native HDMI port or
> > + * a type 1 DVI dual mode adaptor. The driver will have to use
> > + * some other hardware/driver specific mechanism to make that
> > + * distinction.
> > + *
> > + * Returns:
> > + * The type of the DP dual mode adaptor used
> > + */
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> > +{
> > +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> > +	uint8_t adaptor_id = 0x00;
> > +	ssize_t ret;
> > +
> > +	/*
> > +	 * Let's see if the adaptor is there the by reading the
> > +	 * HDMI ID registers.
> > +	 *
> > +	 * Note that type 1 DVI adaptors are not required to implemnt
> > +	 * any registers, and that presents a problem for detection.
> > +	 * If the i2c transfer is nacked, we may or may not be dealing
> > +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> > +	 * the presence of the adaptor is required. One way would be
> > +	 * to check the state of the CONFIG1 pin, Another method would
> > +	 * simply require the driver to know whether the port is a DP++
> > +	 * port or a native HDMI port. Both of these methods are entirely
> > +	 * hardware/driver specific so we can't deal with them here.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> > +				    hdmi_id, sizeof(hdmi_id));
> > +	if (ret)
> > +		return DRM_DP_DUAL_MODE_UNKNOWN;
> > +
> > +	/*
> > +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> > +	 * the offset but ignore it, and instead they just always return
> > +	 * data from the start of the HDMI ID buffer. So for a broken
> > +	 * type 1 HDMI adaptor a single byte read will always give us
> > +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> > +	 * (assuming it implements any registers). Fortunately neither
> > +	 * of those values will match the type 2 signature of the
> > +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> > +	 * the type 2 adaptor detection safely even in the presence
> > +	 * of broken type 1 adaptors.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> > +				    &adaptor_id, sizeof(adaptor_id));
> can we read all 16 bytes in a single read, and then split the characters 
> into dongle_signature and adaptor_id ?

I think Paulo suggested the same thing more or less. Hmm. Let me think.
I'm not sure we want to do that because IIRC the spec says that type 1
HDMI adaptors aren't required to support any registers beyond the HDMI
ID, so I'm not sure some of them might not return an error if we try to
read more than that, and that could then cause the HDMI ID read fail as
well even if it's indeed present. I don't think any of the adaptors I
tested behaved that way, but I don't have that many of them here.

It's a bit of a shame the i2c subsystem doesn't report the number of 
bytes succesfully transferred. It just returns the number of messages
succesfully transferred. And if a message is only partially
transferred, I think we'd just get a negative error code back.

> > +	if (ret == 0) {
> > +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> > +		else if (is_type2_adaptor(adaptor_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> 	can we save one if, or its too late for me to work :) ?
> 		is_type2_adaptor() {
> 			is_hdmi_adaptor()
> 				return type2_hdmi;
> 			else
> 				return type2_dvi
> 		}

I wanted to avoid nesting too deeply here. But the line ended up quite
long anyway, so I guess the extra indent wouldn't really look any
worse than this.

> > +	}
> > +
> > +	if (is_hdmi_adaptor(hdmi_id))
> > +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> > +	else
> > +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> > +
> > +/**
> > + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Determine the max TMDS clock the adaptor supports based on the
> > + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> > + * register (on type2 adaptors). As some type 1 adaptors have
> > + * problems with registers (see comments in drm_dp_dual_mode_detect())
> > + * we don't read the register on those, instead we simply assume
> > + * a 165 MHz limit based on the specification.
> > + *
> > + * Returns:
> > + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> > + */
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter)
> > +{
> > +	uint8_t max_tmds_clock;
> > +	ssize_t ret;
> > +
> > +	/* native HDMI so no limit */
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> > +		return 0;
> > +
> > +	/*
> > +	 * Type 1 adaptors are limited to 165MHz
> > +	 * Type 2 adaptors can tells us their limit
> > +	 */
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 165000;
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> > +				    &max_tmds_clock, sizeof(max_tmds_clock));
> > +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> > +		return 165000;
> > +
> > +	return max_tmds_clock * 5000 / 2;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> > +
> > +/**
> > + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enabled: current state of the TMDS output buffers
> > + *
> > + * Get the state of the TMDS output buffers in the adaptor. For
> > + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> > + * register. As some type 1 adaptors have problems with registers
> > + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> > + * register on those, instead we simply assume that the buffers
> > + * are always enabled.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter,
> > +				     bool *enabled)
> > +{
> > +	uint8_t tmds_oen;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> > +		*enabled = true;
> > +		return 0;
> > +	}
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				    &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> debug message here might help in failure cases.

Sure, I can add it.

> > +		return ret;
> > +
> > +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> > +
> > +/**
> > + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enable: enable (as opposed to disable) the TMDS output buffers
> > + *
> > + * Set the state of the TMDS output buffers in the adaptor. For
> > + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> > + * some type 1 adaptors have problems with registers (see comments
> > + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> > + * making this function a no-op on type 1 adaptors.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable)
> > +{
> > +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 0;
> > +
> > +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				     &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> debug message here might help in failure cases.

can do.

> > +		return ret;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> > +
> > +/**
> > + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> > + * type: DP dual mode adaptor type
> > + *
> > + * Returns:
> > + * String representation of the DP dual mode adaptor type
> > + */
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> > +{
> > +	switch (type) {
> > +	case DRM_DP_DUAL_MODE_NONE:
> > +		return "none";
> > +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> > +		return "type 1 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> > +		return "type 1 HDMI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> > +		return "type 2 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> > +		return "type 2 HDMI";
> > +	default:
> > +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> do we need a warning here, or a DRM_ERROR should work ?
> I am afraid we will show a back-trace for all non-compliant adapters.

If someone passes in an invalid type, that's a bug in the caller. So
this should never happen.

> > +		return "unknown";
> > +	}
> > +}
> > +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> > diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> > new file mode 100644
> > index 000000000000..b4603b9fc03d
> > --- /dev/null
> > +++ b/include/drm/drm_dp_dual_mode_helper.h
> > @@ -0,0 +1,83 @@
> > +/*
> > + * Copyright � 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> > +#define DRM_DP_DUAL_MODE_HELPER_H
> > +
> > +#include <linux/types.h>
> > +
> > +/*
> > + * Optional for type 1 DVI adaptors
> > + * Mandatory for type 1 HDMI and type 2 adators
> > + */
> > +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> > +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> > +/*
> > + * Optional for type 1 adaptors
> > + * Mandatory for type 2 adators
> > + */
> > +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> > +#define  DP_DUAL_MODE_REV_MASK 0x07
> > +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> > +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> > +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> > +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> > +#define  DP_DUAL_IEEE_OUI_LEN 3
> > +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> > +#define  DP_DUAL_DEVICE_ID_LEN 6
> > +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> > +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> > +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> > +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> > +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> > +#define DP_DUAL_MODE_TMDS_OEN 0x20
> > +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> > +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> > +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> > +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> > +
> > +struct i2c_adapter;
> > +
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size);
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size);
> > +
> > +enum drm_dp_dual_mode_type {
> > +	DRM_DP_DUAL_MODE_NONE,
> what does dual mode none indicate (considering we have an unknown case 
> below) ?

It mean we know that there is no dual mode adaptor, meaning we're
dealing with a native HDMI port. Originally I had just the NONE, but
Paulo requested that we make the UNKNOWN case more explicit so I split
it into two. It's always the driver's responsibility to refine the
detection result to NONE or TYPE1_DVI if drm_dp_dual_mode_detect()
returns UNKNOWN.

> Regards
> Shashank
> > +	DRM_DP_DUAL_MODE_UNKNOWN,
> > +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> > +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> > +};
> > +
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool *enabled);
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable);
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> > +
> > +#endif
> >

-- 
Ville Syrj�l�
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-03 17:38       ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-03 17:38 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: Paulo Zanoni, Daniel Vetter, intel-gfx, Tore Anderson, stable, dri-devel

On Tue, May 03, 2016 at 10:03:30PM +0530, Sharma, Shashank wrote:
> 
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Add a helper which aids in the identification of DP dual mode
> > (aka. DP++) adaptors. There are several types of adaptors
> > specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> >
> > Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> > may go as high as 300MHz and they provide a register informing the
> > source device what the actual limit is. Supposedly also type 1 adaptors
> > may optionally implement this register. This TMDS clock limit is the
> > main reason why we need to identify these adaptors.
> >
> > Type 1 adaptors provide access to their internal registers and the sink
> > DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> > and I2C-over-AUX. A type 2 source device may choose to implement either
> > of these methods. If a source device implements the I2C-over-AUX
> > method, then the driver will obviously need specific support for such
> > adaptors since the port is driven like an HDMI port, but DDC
> > communication happes over the AUX channel.
> >
> > This helper should be enough to identify the adaptor type (some
> > type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> > clock limit. Another feature that may be available is control over
> > the TMDS output buffers on the adaptor, possibly allowing for some
> > power saving when the TMDS link is down.
> >
> > Other user controllable features that may be available in the adaptors
> > are downstream i2c bus speed control when using i2c-over-aux, and
> > some control over the CEC pin. I chose not to provide any helper
> > functions for those since I have no use for them in i915 at this time.
> > The rest of the registers in the adaptor are mostly just information,
> > eg. IEEE OUI, hardware and firmware revision, etc.
> >
> > v2: Pass adaptor type to helper functions to ease driver implementation
> >      Fix a bunch of typoes (Paulo)
> >      Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
> >      the type (Paulo)
> >      Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
> >      Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
> >      ease future LSPCON enabling
> >      Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/Makefile                  |   2 +-
> >   drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
> >   include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
> >   3 files changed, 440 insertions(+), 1 deletion(-)
> >   create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
> >   create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> >
> > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> > index 1a26b4eb1ce0..29f2ee9b9534 100644
> > --- a/drivers/gpu/drm/Makefile
> > +++ b/drivers/gpu/drm/Makefile
> > @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
> >
> >   drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
> >   		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> > -		drm_kms_helper_common.o
> > +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
> >
> >   drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
> >   drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> > diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > new file mode 100644
> > index 000000000000..949c0fbeb542
> > --- /dev/null
> > +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> > @@ -0,0 +1,356 @@
> > +/*
> > + * Copyright © 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include <linux/errno.h>
> > +#include <linux/export.h>
> > +#include <linux/i2c.h>
> > +#include <linux/slab.h>
> > +#include <linux/string.h>
> > +#include <drm/drm_dp_dual_mode_helper.h>
> > +#include <drm/drmP.h>
> > +
> > +/**
> > + * DOC: DP dual mode (aka. DP++) adaptor helpers
> > + *
> > + * Helper functions to deal with DP dual mode adaptors.
> > + *
> > + * Type 1:
> > + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> > + *
> > + * Type 2:
> > + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> > + * I2C-over-AUX. Source devices may choose to implement either of these
> > + * access methods.
> > + */
> > +
> > +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for return data
> > + * size: sizo of the buffer
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> > + * adapter: I2C adapter for the DDC bus
> > + * offset: register offset
> > + * buffer: buffer for write data
> > + * size: sizo of the buffer
> > + *
> > + * Writes @size bytes to the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msg = {
> > +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +		.flags = 0,
> > +		.len = 1 + size,
> > +		.buf = NULL,
> > +	};
> > +	void *data;
> > +	int ret;
> > +
> > +	data = kmalloc(msg.len, GFP_TEMPORARY);
> > +	if (!data)
> > +		return -ENOMEM;
> > +
> > +	msg.buf = data;
> > +
> > +	memcpy(data, &offset, 1);
> > +	memcpy(data + 1, buffer, size);
> > +
> > +	ret = i2c_transfer(adapter, &msg, 1);
> > +
> > +	kfree(data);
> > +
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != 1)
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> > +
> > +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> > +{
> > +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> > +		"DP-HDMI ADAPTOR\x04";
> > +
> > +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> > +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> > +}
> > +
> > +static bool is_type2_adaptor(uint8_t adaptor_id)
> > +{
> > +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> > +			      DP_DUAL_MODE_REV_TYPE2);
> > +}
> > +
> > +/**
> > + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Attempt to identify the type of the DP dual mode adaptor used.
> > + *
> > + * Note that when the answer is @DRM_DP_DUAL_MODE_NONE it's not
> > + * certain whether we're dealing with a native HDMI port or
> > + * a type 1 DVI dual mode adaptor. The driver will have to use
> > + * some other hardware/driver specific mechanism to make that
> > + * distinction.
> > + *
> > + * Returns:
> > + * The type of the DP dual mode adaptor used
> > + */
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> > +{
> > +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> > +	uint8_t adaptor_id = 0x00;
> > +	ssize_t ret;
> > +
> > +	/*
> > +	 * Let's see if the adaptor is there the by reading the
> > +	 * HDMI ID registers.
> > +	 *
> > +	 * Note that type 1 DVI adaptors are not required to implemnt
> > +	 * any registers, and that presents a problem for detection.
> > +	 * If the i2c transfer is nacked, we may or may not be dealing
> > +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> > +	 * the presence of the adaptor is required. One way would be
> > +	 * to check the state of the CONFIG1 pin, Another method would
> > +	 * simply require the driver to know whether the port is a DP++
> > +	 * port or a native HDMI port. Both of these methods are entirely
> > +	 * hardware/driver specific so we can't deal with them here.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> > +				    hdmi_id, sizeof(hdmi_id));
> > +	if (ret)
> > +		return DRM_DP_DUAL_MODE_UNKNOWN;
> > +
> > +	/*
> > +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> > +	 * the offset but ignore it, and instead they just always return
> > +	 * data from the start of the HDMI ID buffer. So for a broken
> > +	 * type 1 HDMI adaptor a single byte read will always give us
> > +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> > +	 * (assuming it implements any registers). Fortunately neither
> > +	 * of those values will match the type 2 signature of the
> > +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> > +	 * the type 2 adaptor detection safely even in the presence
> > +	 * of broken type 1 adaptors.
> > +	 */
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> > +				    &adaptor_id, sizeof(adaptor_id));
> can we read all 16 bytes in a single read, and then split the characters 
> into dongle_signature and adaptor_id ?

I think Paulo suggested the same thing more or less. Hmm. Let me think.
I'm not sure we want to do that because IIRC the spec says that type 1
HDMI adaptors aren't required to support any registers beyond the HDMI
ID, so I'm not sure some of them might not return an error if we try to
read more than that, and that could then cause the HDMI ID read fail as
well even if it's indeed present. I don't think any of the adaptors I
tested behaved that way, but I don't have that many of them here.

It's a bit of a shame the i2c subsystem doesn't report the number of 
bytes succesfully transferred. It just returns the number of messages
succesfully transferred. And if a message is only partially
transferred, I think we'd just get a negative error code back.

> > +	if (ret == 0) {
> > +		if (is_type2_adaptor(adaptor_id) && is_hdmi_adaptor(hdmi_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> > +		else if (is_type2_adaptor(adaptor_id))
> > +			return DRM_DP_DUAL_MODE_TYPE2_DVI;
> 	can we save one if, or its too late for me to work :) ?
> 		is_type2_adaptor() {
> 			is_hdmi_adaptor()
> 				return type2_hdmi;
> 			else
> 				return type2_dvi
> 		}

I wanted to avoid nesting too deeply here. But the line ended up quite
long anyway, so I guess the extra indent wouldn't really look any
worse than this.

> > +	}
> > +
> > +	if (is_hdmi_adaptor(hdmi_id))
> > +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> > +	else
> > +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> > +
> > +/**
> > + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + *
> > + * Determine the max TMDS clock the adaptor supports based on the
> > + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> > + * register (on type2 adaptors). As some type 1 adaptors have
> > + * problems with registers (see comments in drm_dp_dual_mode_detect())
> > + * we don't read the register on those, instead we simply assume
> > + * a 165 MHz limit based on the specification.
> > + *
> > + * Returns:
> > + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> > + */
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter)
> > +{
> > +	uint8_t max_tmds_clock;
> > +	ssize_t ret;
> > +
> > +	/* native HDMI so no limit */
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> > +		return 0;
> > +
> > +	/*
> > +	 * Type 1 adaptors are limited to 165MHz
> > +	 * Type 2 adaptors can tells us their limit
> > +	 */
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 165000;
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> > +				    &max_tmds_clock, sizeof(max_tmds_clock));
> > +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> > +		return 165000;
> > +
> > +	return max_tmds_clock * 5000 / 2;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> > +
> > +/**
> > + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enabled: current state of the TMDS output buffers
> > + *
> > + * Get the state of the TMDS output buffers in the adaptor. For
> > + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> > + * register. As some type 1 adaptors have problems with registers
> > + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> > + * register on those, instead we simply assume that the buffers
> > + * are always enabled.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter,
> > +				     bool *enabled)
> > +{
> > +	uint8_t tmds_oen;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> > +		*enabled = true;
> > +		return 0;
> > +	}
> > +
> > +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				    &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> debug message here might help in failure cases.

Sure, I can add it.

> > +		return ret;
> > +
> > +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> > +
> > +/**
> > + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> > + * type: DP dual mode adaptor type
> > + * adapter: I2C adapter for the DDC bus
> > + * enable: enable (as opposed to disable) the TMDS output buffers
> > + *
> > + * Set the state of the TMDS output buffers in the adaptor. For
> > + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> > + * some type 1 adaptors have problems with registers (see comments
> > + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> > + * making this function a no-op on type 1 adaptors.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable)
> > +{
> > +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> > +	ssize_t ret;
> > +
> > +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return 0;
> > +
> > +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> > +				     &tmds_oen, sizeof(tmds_oen));
> > +	if (ret)
> debug message here might help in failure cases.

can do.

> > +		return ret;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> > +
> > +/**
> > + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> > + * type: DP dual mode adaptor type
> > + *
> > + * Returns:
> > + * String representation of the DP dual mode adaptor type
> > + */
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> > +{
> > +	switch (type) {
> > +	case DRM_DP_DUAL_MODE_NONE:
> > +		return "none";
> > +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> > +		return "type 1 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> > +		return "type 1 HDMI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> > +		return "type 2 DVI";
> > +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> > +		return "type 2 HDMI";
> > +	default:
> > +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> do we need a warning here, or a DRM_ERROR should work ?
> I am afraid we will show a back-trace for all non-compliant adapters.

If someone passes in an invalid type, that's a bug in the caller. So
this should never happen.

> > +		return "unknown";
> > +	}
> > +}
> > +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> > diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> > new file mode 100644
> > index 000000000000..b4603b9fc03d
> > --- /dev/null
> > +++ b/include/drm/drm_dp_dual_mode_helper.h
> > @@ -0,0 +1,83 @@
> > +/*
> > + * Copyright © 2016 Intel Corporation
> > + *
> > + * Permission is hereby granted, free of charge, to any person obtaining a
> > + * copy of this software and associated documentation files (the "Software"),
> > + * to deal in the Software without restriction, including without limitation
> > + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> > +#define DRM_DP_DUAL_MODE_HELPER_H
> > +
> > +#include <linux/types.h>
> > +
> > +/*
> > + * Optional for type 1 DVI adaptors
> > + * Mandatory for type 1 HDMI and type 2 adators
> > + */
> > +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> > +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> > +/*
> > + * Optional for type 1 adaptors
> > + * Mandatory for type 2 adators
> > + */
> > +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> > +#define  DP_DUAL_MODE_REV_MASK 0x07
> > +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> > +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> > +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> > +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> > +#define  DP_DUAL_IEEE_OUI_LEN 3
> > +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> > +#define  DP_DUAL_DEVICE_ID_LEN 6
> > +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> > +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> > +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> > +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> > +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> > +#define DP_DUAL_MODE_TMDS_OEN 0x20
> > +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> > +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> > +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> > +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> > +
> > +struct i2c_adapter;
> > +
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size);
> > +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> > +			       u8 offset, const void *buffer, size_t size);
> > +
> > +enum drm_dp_dual_mode_type {
> > +	DRM_DP_DUAL_MODE_NONE,
> what does dual mode none indicate (considering we have an unknown case 
> below) ?

It mean we know that there is no dual mode adaptor, meaning we're
dealing with a native HDMI port. Originally I had just the NONE, but
Paulo requested that we make the UNKNOWN case more explicit so I split
it into two. It's always the driver's responsibility to refine the
detection result to NONE or TYPE1_DVI if drm_dp_dual_mode_detect()
returns UNKNOWN.

> Regards
> Shashank
> > +	DRM_DP_DUAL_MODE_UNKNOWN,
> > +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> > +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> > +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> > +};
> > +
> > +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> > +				    struct i2c_adapter *adapter);
> > +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool *enabled);
> > +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> > +				     struct i2c_adapter *adapter, bool enable);
> > +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> > +
> > +#endif
> >

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v4 1/4] drm: Add helper for DP++ adaptors
  2016-05-03 14:55   ` [PATCH v3 " ville.syrjala
@ 2016-05-03 17:56       ` ville.syrjala
  0 siblings, 0 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-03 17:56 UTC (permalink / raw)
  To: intel-gfx
  Cc: stable, Tore Anderson, Paulo Zanoni, Shashank Sharma, Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a helper which aids in the identification of DP dual mode
(aka. DP++) adaptors. There are several types of adaptors
specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI

Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
may go as high as 300MHz and they provide a register informing the
source device what the actual limit is. Supposedly also type 1 adaptors
may optionally implement this register. This TMDS clock limit is the
main reason why we need to identify these adaptors.

Type 1 adaptors provide access to their internal registers and the sink
DDC bus through I2C. Type 2 adaptors provide this access both via I2C
and I2C-over-AUX. A type 2 source device may choose to implement either
of these methods. If a source device implements the I2C-over-AUX
method, then the driver will obviously need specific support for such
adaptors since the port is driven like an HDMI port, but DDC
communication happes over the AUX channel.

This helper should be enough to identify the adaptor type (some
type 1 DVI adaptors may be a slight exception) and the maximum TMDS
clock limit. Another feature that may be available is control over
the TMDS output buffers on the adaptor, possibly allowing for some
power saving when the TMDS link is down.

Other user controllable features that may be available in the adaptors
are downstream i2c bus speed control when using i2c-over-aux, and
some control over the CEC pin. I chose not to provide any helper
functions for those since I have no use for them in i915 at this time.
The rest of the registers in the adaptor are mostly just information,
eg. IEEE OUI, hardware and firmware revision, etc.

v2: Pass adaptor type to helper functions to ease driver implementation
    Fix a bunch of typoes (Paulo)
    Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
    the type (Paulo)
    Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
    Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
    ease future LSPCON enabling
    Remove the unused DP_DUAL_MODE_LAST_RESERVED define
v3: Fix kernel doc function argument descriptions (Jani)
    s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
    Add kernel doc for enum drm_dp_dual_mode_type
    Actually build the docs
    Fix more typoes
v4: Adjust code indentation of type2 adaptor detection (Shashank)
    Add debug messages for failurs cases (Shashank)

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 Documentation/DocBook/gpu.tmpl            |   6 +
 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 365 ++++++++++++++++++++++++++++++
 include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
 4 files changed, 464 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 1464fb2f3c46..c248124357df 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_dp_helper.c
     </sect2>
     <sect2>
+      <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
+!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
+!Iinclude/drm/drm_dp_dual_mode_helper.h
+!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
+    </sect2>
+    <sect2>
       <title>Display Port MST Helper Functions Reference</title>
 !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
 !Iinclude/drm/drm_dp_mst_helper.h
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 1a26b4eb1ce0..29f2ee9b9534 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
-		drm_kms_helper_common.o
+		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
 
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
new file mode 100644
index 000000000000..6842178474ba
--- /dev/null
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -0,0 +1,365 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dp_dual_mode_helper.h>
+#include <drm/drmP.h>
+
+/**
+ * DOC: dp dual mode helpers
+ *
+ * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
+ *
+ * Type 1:
+ * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
+ *
+ * Type 2:
+ * Adaptor registers and sink DDC bus can be accessed either via I2C or
+ * I2C-over-AUX. Source devices may choose to implement either of these
+ * access methods.
+ */
+
+#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
+
+/**
+ * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for return data
+ * @size: sizo of the buffer
+ *
+ * Reads @size bytes from the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size)
+{
+	struct i2c_msg msgs[] = {
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = 0,
+			.len = 1,
+			.buf = &offset,
+		},
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = I2C_M_RD,
+			.len = size,
+			.buf = buffer,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret < 0)
+		return ret;
+	if (ret != ARRAY_SIZE(msgs))
+		return -EPROTO;
+
+	return 0;
+}
+
+/**
+ * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for write data
+ * @size: sizo of the buffer
+ *
+ * Writes @size bytes to the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size)
+{
+	struct i2c_msg msg = {
+		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+		.flags = 0,
+		.len = 1 + size,
+		.buf = NULL,
+	};
+	void *data;
+	int ret;
+
+	data = kmalloc(msg.len, GFP_TEMPORARY);
+	if (!data)
+		return -ENOMEM;
+
+	msg.buf = data;
+
+	memcpy(data, &offset, 1);
+	memcpy(data + 1, buffer, size);
+
+	ret = i2c_transfer(adapter, &msg, 1);
+
+	kfree(data);
+
+	if (ret < 0)
+		return ret;
+	if (ret != 1)
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_write);
+
+static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
+{
+	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
+		"DP-HDMI ADAPTOR\x04";
+
+	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
+		      sizeof(dp_dual_mode_hdmi_id)) == 0;
+}
+
+static bool is_type2_adaptor(uint8_t adaptor_id)
+{
+	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
+			      DP_DUAL_MODE_REV_TYPE2);
+}
+
+/**
+ * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Attempt to identify the type of the DP dual mode adaptor used.
+ *
+ * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
+ * certain whether we're dealing with a native HDMI port or
+ * a type 1 DVI dual mode adaptor. The driver will have to use
+ * some other hardware/driver specific mechanism to make that
+ * distinction.
+ *
+ * Returns:
+ * The type of the DP dual mode adaptor used
+ */
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
+{
+	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
+	uint8_t adaptor_id = 0x00;
+	ssize_t ret;
+
+	/*
+	 * Let's see if the adaptor is there the by reading the
+	 * HDMI ID registers.
+	 *
+	 * Note that type 1 DVI adaptors are not required to implemnt
+	 * any registers, and that presents a problem for detection.
+	 * If the i2c transfer is nacked, we may or may not be dealing
+	 * with a type 1 DVI adaptor. Some other mechanism of detecting
+	 * the presence of the adaptor is required. One way would be
+	 * to check the state of the CONFIG1 pin, Another method would
+	 * simply require the driver to know whether the port is a DP++
+	 * port or a native HDMI port. Both of these methods are entirely
+	 * hardware/driver specific so we can't deal with them here.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
+				    hdmi_id, sizeof(hdmi_id));
+	if (ret)
+		return DRM_DP_DUAL_MODE_UNKNOWN;
+
+	/*
+	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
+	 * the offset but ignore it, and instead they just always return
+	 * data from the start of the HDMI ID buffer. So for a broken
+	 * type 1 HDMI adaptor a single byte read will always give us
+	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
+	 * (assuming it implements any registers). Fortunately neither
+	 * of those values will match the type 2 signature of the
+	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
+	 * the type 2 adaptor detection safely even in the presence
+	 * of broken type 1 adaptors.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
+				    &adaptor_id, sizeof(adaptor_id));
+	if (ret == 0) {
+		if (is_type2_adaptor(adaptor_id)) {
+			if (is_hdmi_adaptor(hdmi_id))
+				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
+			else
+				return DRM_DP_DUAL_MODE_TYPE2_DVI;
+		}
+	}
+
+	if (is_hdmi_adaptor(hdmi_id))
+		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
+	else
+		return DRM_DP_DUAL_MODE_TYPE1_DVI;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_detect);
+
+/**
+ * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Determine the max TMDS clock the adaptor supports based on the
+ * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
+ * register (on type2 adaptors). As some type 1 adaptors have
+ * problems with registers (see comments in drm_dp_dual_mode_detect())
+ * we don't read the register on those, instead we simply assume
+ * a 165 MHz limit based on the specification.
+ *
+ * Returns:
+ * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
+ */
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter)
+{
+	uint8_t max_tmds_clock;
+	ssize_t ret;
+
+	/* native HDMI so no limit */
+	if (type == DRM_DP_DUAL_MODE_NONE)
+		return 0;
+
+	/*
+	 * Type 1 adaptors are limited to 165MHz
+	 * Type 2 adaptors can tells us their limit
+	 */
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 165000;
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
+				    &max_tmds_clock, sizeof(max_tmds_clock));
+	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff) {
+		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
+		return 165000;
+	}
+
+	return max_tmds_clock * 5000 / 2;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
+
+/**
+ * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enabled: current state of the TMDS output buffers
+ *
+ * Get the state of the TMDS output buffers in the adaptor. For
+ * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
+ * register. As some type 1 adaptors have problems with registers
+ * (see comments in drm_dp_dual_mode_detect()) we don't read the
+ * register on those, instead we simply assume that the buffers
+ * are always enabled.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter,
+				     bool *enabled)
+{
+	uint8_t tmds_oen;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
+		*enabled = true;
+		return 0;
+	}
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
+				    &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to query state of TMDS output buffers\n");
+		return ret;
+	}
+
+	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
+
+/**
+ * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enable: enable (as opposed to disable) the TMDS output buffers
+ *
+ * Set the state of the TMDS output buffers in the adaptor. For
+ * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
+ * some type 1 adaptors have problems with registers (see comments
+ * in drm_dp_dual_mode_detect()) we avoid touching the register,
+ * making this function a no-op on type 1 adaptors.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable)
+{
+	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 0;
+
+	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
+				     &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
+			      enable ? "enable" : "disable");
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
+
+/**
+ * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
+ * @type: DP dual mode adaptor type
+ *
+ * Returns:
+ * String representation of the DP dual mode adaptor type
+ */
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
+{
+	switch (type) {
+	case DRM_DP_DUAL_MODE_NONE:
+		return "none";
+	case DRM_DP_DUAL_MODE_TYPE1_DVI:
+		return "type 1 DVI";
+	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
+		return "type 1 HDMI";
+	case DRM_DP_DUAL_MODE_TYPE2_DVI:
+		return "type 2 DVI";
+	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
+		return "type 2 HDMI";
+	default:
+		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
+		return "unknown";
+	}
+}
+EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
new file mode 100644
index 000000000000..e8a9dfd0e055
--- /dev/null
+++ b/include/drm/drm_dp_dual_mode_helper.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DP_DUAL_MODE_HELPER_H
+#define DRM_DP_DUAL_MODE_HELPER_H
+
+#include <linux/types.h>
+
+/*
+ * Optional for type 1 DVI adaptors
+ * Mandatory for type 1 HDMI and type 2 adaptors
+ */
+#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
+#define  DP_DUAL_MODE_HDMI_ID_LEN 16
+/*
+ * Optional for type 1 adaptors
+ * Mandatory for type 2 adaptors
+ */
+#define DP_DUAL_MODE_ADAPTOR_ID 0x10
+#define  DP_DUAL_MODE_REV_MASK 0x07
+#define  DP_DUAL_MODE_REV_TYPE2 0x00
+#define  DP_DUAL_MODE_TYPE_MASK 0xf0
+#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
+#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
+#define  DP_DUAL_IEEE_OUI_LEN 3
+#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
+#define  DP_DUAL_DEVICE_ID_LEN 6
+#define DP_DUAL_MODE_HARDWARE_REV 0x1a
+#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
+#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
+#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
+#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
+#define DP_DUAL_MODE_TMDS_OEN 0x20
+#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
+#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
+#define  DP_DUAL_MODE_CEC_ENABLE 0x01
+#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
+
+struct i2c_adapter;
+
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size);
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size);
+
+/**
+ * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
+ */
+enum drm_dp_dual_mode_type {
+	DRM_DP_DUAL_MODE_NONE,
+	DRM_DP_DUAL_MODE_UNKNOWN,
+	DRM_DP_DUAL_MODE_TYPE1_DVI,
+	DRM_DP_DUAL_MODE_TYPE1_HDMI,
+	DRM_DP_DUAL_MODE_TYPE2_DVI,
+	DRM_DP_DUAL_MODE_TYPE2_HDMI,
+};
+
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter);
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool *enabled);
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable);
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
+
+#endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* [PATCH v4 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-03 17:56       ` ville.syrjala
  0 siblings, 0 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-03 17:56 UTC (permalink / raw)
  To: intel-gfx; +Cc: Daniel Vetter, Tore Anderson, Paulo Zanoni, stable

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a helper which aids in the identification of DP dual mode
(aka. DP++) adaptors. There are several types of adaptors
specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI

Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
may go as high as 300MHz and they provide a register informing the
source device what the actual limit is. Supposedly also type 1 adaptors
may optionally implement this register. This TMDS clock limit is the
main reason why we need to identify these adaptors.

Type 1 adaptors provide access to their internal registers and the sink
DDC bus through I2C. Type 2 adaptors provide this access both via I2C
and I2C-over-AUX. A type 2 source device may choose to implement either
of these methods. If a source device implements the I2C-over-AUX
method, then the driver will obviously need specific support for such
adaptors since the port is driven like an HDMI port, but DDC
communication happes over the AUX channel.

This helper should be enough to identify the adaptor type (some
type 1 DVI adaptors may be a slight exception) and the maximum TMDS
clock limit. Another feature that may be available is control over
the TMDS output buffers on the adaptor, possibly allowing for some
power saving when the TMDS link is down.

Other user controllable features that may be available in the adaptors
are downstream i2c bus speed control when using i2c-over-aux, and
some control over the CEC pin. I chose not to provide any helper
functions for those since I have no use for them in i915 at this time.
The rest of the registers in the adaptor are mostly just information,
eg. IEEE OUI, hardware and firmware revision, etc.

v2: Pass adaptor type to helper functions to ease driver implementation
    Fix a bunch of typoes (Paulo)
    Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
    the type (Paulo)
    Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
    Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
    ease future LSPCON enabling
    Remove the unused DP_DUAL_MODE_LAST_RESERVED define
v3: Fix kernel doc function argument descriptions (Jani)
    s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
    Add kernel doc for enum drm_dp_dual_mode_type
    Actually build the docs
    Fix more typoes
v4: Adjust code indentation of type2 adaptor detection (Shashank)
    Add debug messages for failurs cases (Shashank)

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 Documentation/DocBook/gpu.tmpl            |   6 +
 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 365 ++++++++++++++++++++++++++++++
 include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
 4 files changed, 464 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 1464fb2f3c46..c248124357df 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_dp_helper.c
     </sect2>
     <sect2>
+      <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
+!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
+!Iinclude/drm/drm_dp_dual_mode_helper.h
+!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
+    </sect2>
+    <sect2>
       <title>Display Port MST Helper Functions Reference</title>
 !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
 !Iinclude/drm/drm_dp_mst_helper.h
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 1a26b4eb1ce0..29f2ee9b9534 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
-		drm_kms_helper_common.o
+		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
 
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
new file mode 100644
index 000000000000..6842178474ba
--- /dev/null
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -0,0 +1,365 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dp_dual_mode_helper.h>
+#include <drm/drmP.h>
+
+/**
+ * DOC: dp dual mode helpers
+ *
+ * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
+ *
+ * Type 1:
+ * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
+ *
+ * Type 2:
+ * Adaptor registers and sink DDC bus can be accessed either via I2C or
+ * I2C-over-AUX. Source devices may choose to implement either of these
+ * access methods.
+ */
+
+#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
+
+/**
+ * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for return data
+ * @size: sizo of the buffer
+ *
+ * Reads @size bytes from the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size)
+{
+	struct i2c_msg msgs[] = {
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = 0,
+			.len = 1,
+			.buf = &offset,
+		},
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = I2C_M_RD,
+			.len = size,
+			.buf = buffer,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret < 0)
+		return ret;
+	if (ret != ARRAY_SIZE(msgs))
+		return -EPROTO;
+
+	return 0;
+}
+
+/**
+ * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for write data
+ * @size: sizo of the buffer
+ *
+ * Writes @size bytes to the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size)
+{
+	struct i2c_msg msg = {
+		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+		.flags = 0,
+		.len = 1 + size,
+		.buf = NULL,
+	};
+	void *data;
+	int ret;
+
+	data = kmalloc(msg.len, GFP_TEMPORARY);
+	if (!data)
+		return -ENOMEM;
+
+	msg.buf = data;
+
+	memcpy(data, &offset, 1);
+	memcpy(data + 1, buffer, size);
+
+	ret = i2c_transfer(adapter, &msg, 1);
+
+	kfree(data);
+
+	if (ret < 0)
+		return ret;
+	if (ret != 1)
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_write);
+
+static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
+{
+	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
+		"DP-HDMI ADAPTOR\x04";
+
+	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
+		      sizeof(dp_dual_mode_hdmi_id)) == 0;
+}
+
+static bool is_type2_adaptor(uint8_t adaptor_id)
+{
+	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
+			      DP_DUAL_MODE_REV_TYPE2);
+}
+
+/**
+ * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Attempt to identify the type of the DP dual mode adaptor used.
+ *
+ * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
+ * certain whether we're dealing with a native HDMI port or
+ * a type 1 DVI dual mode adaptor. The driver will have to use
+ * some other hardware/driver specific mechanism to make that
+ * distinction.
+ *
+ * Returns:
+ * The type of the DP dual mode adaptor used
+ */
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
+{
+	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
+	uint8_t adaptor_id = 0x00;
+	ssize_t ret;
+
+	/*
+	 * Let's see if the adaptor is there the by reading the
+	 * HDMI ID registers.
+	 *
+	 * Note that type 1 DVI adaptors are not required to implemnt
+	 * any registers, and that presents a problem for detection.
+	 * If the i2c transfer is nacked, we may or may not be dealing
+	 * with a type 1 DVI adaptor. Some other mechanism of detecting
+	 * the presence of the adaptor is required. One way would be
+	 * to check the state of the CONFIG1 pin, Another method would
+	 * simply require the driver to know whether the port is a DP++
+	 * port or a native HDMI port. Both of these methods are entirely
+	 * hardware/driver specific so we can't deal with them here.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
+				    hdmi_id, sizeof(hdmi_id));
+	if (ret)
+		return DRM_DP_DUAL_MODE_UNKNOWN;
+
+	/*
+	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
+	 * the offset but ignore it, and instead they just always return
+	 * data from the start of the HDMI ID buffer. So for a broken
+	 * type 1 HDMI adaptor a single byte read will always give us
+	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
+	 * (assuming it implements any registers). Fortunately neither
+	 * of those values will match the type 2 signature of the
+	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
+	 * the type 2 adaptor detection safely even in the presence
+	 * of broken type 1 adaptors.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
+				    &adaptor_id, sizeof(adaptor_id));
+	if (ret == 0) {
+		if (is_type2_adaptor(adaptor_id)) {
+			if (is_hdmi_adaptor(hdmi_id))
+				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
+			else
+				return DRM_DP_DUAL_MODE_TYPE2_DVI;
+		}
+	}
+
+	if (is_hdmi_adaptor(hdmi_id))
+		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
+	else
+		return DRM_DP_DUAL_MODE_TYPE1_DVI;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_detect);
+
+/**
+ * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Determine the max TMDS clock the adaptor supports based on the
+ * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
+ * register (on type2 adaptors). As some type 1 adaptors have
+ * problems with registers (see comments in drm_dp_dual_mode_detect())
+ * we don't read the register on those, instead we simply assume
+ * a 165 MHz limit based on the specification.
+ *
+ * Returns:
+ * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
+ */
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter)
+{
+	uint8_t max_tmds_clock;
+	ssize_t ret;
+
+	/* native HDMI so no limit */
+	if (type == DRM_DP_DUAL_MODE_NONE)
+		return 0;
+
+	/*
+	 * Type 1 adaptors are limited to 165MHz
+	 * Type 2 adaptors can tells us their limit
+	 */
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 165000;
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
+				    &max_tmds_clock, sizeof(max_tmds_clock));
+	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff) {
+		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
+		return 165000;
+	}
+
+	return max_tmds_clock * 5000 / 2;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
+
+/**
+ * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enabled: current state of the TMDS output buffers
+ *
+ * Get the state of the TMDS output buffers in the adaptor. For
+ * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
+ * register. As some type 1 adaptors have problems with registers
+ * (see comments in drm_dp_dual_mode_detect()) we don't read the
+ * register on those, instead we simply assume that the buffers
+ * are always enabled.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter,
+				     bool *enabled)
+{
+	uint8_t tmds_oen;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
+		*enabled = true;
+		return 0;
+	}
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
+				    &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to query state of TMDS output buffers\n");
+		return ret;
+	}
+
+	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
+
+/**
+ * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enable: enable (as opposed to disable) the TMDS output buffers
+ *
+ * Set the state of the TMDS output buffers in the adaptor. For
+ * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
+ * some type 1 adaptors have problems with registers (see comments
+ * in drm_dp_dual_mode_detect()) we avoid touching the register,
+ * making this function a no-op on type 1 adaptors.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable)
+{
+	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 0;
+
+	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
+				     &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
+			      enable ? "enable" : "disable");
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
+
+/**
+ * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
+ * @type: DP dual mode adaptor type
+ *
+ * Returns:
+ * String representation of the DP dual mode adaptor type
+ */
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
+{
+	switch (type) {
+	case DRM_DP_DUAL_MODE_NONE:
+		return "none";
+	case DRM_DP_DUAL_MODE_TYPE1_DVI:
+		return "type 1 DVI";
+	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
+		return "type 1 HDMI";
+	case DRM_DP_DUAL_MODE_TYPE2_DVI:
+		return "type 2 DVI";
+	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
+		return "type 2 HDMI";
+	default:
+		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
+		return "unknown";
+	}
+}
+EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
new file mode 100644
index 000000000000..e8a9dfd0e055
--- /dev/null
+++ b/include/drm/drm_dp_dual_mode_helper.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DP_DUAL_MODE_HELPER_H
+#define DRM_DP_DUAL_MODE_HELPER_H
+
+#include <linux/types.h>
+
+/*
+ * Optional for type 1 DVI adaptors
+ * Mandatory for type 1 HDMI and type 2 adaptors
+ */
+#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
+#define  DP_DUAL_MODE_HDMI_ID_LEN 16
+/*
+ * Optional for type 1 adaptors
+ * Mandatory for type 2 adaptors
+ */
+#define DP_DUAL_MODE_ADAPTOR_ID 0x10
+#define  DP_DUAL_MODE_REV_MASK 0x07
+#define  DP_DUAL_MODE_REV_TYPE2 0x00
+#define  DP_DUAL_MODE_TYPE_MASK 0xf0
+#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
+#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
+#define  DP_DUAL_IEEE_OUI_LEN 3
+#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
+#define  DP_DUAL_DEVICE_ID_LEN 6
+#define DP_DUAL_MODE_HARDWARE_REV 0x1a
+#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
+#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
+#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
+#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
+#define DP_DUAL_MODE_TMDS_OEN 0x20
+#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
+#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
+#define  DP_DUAL_MODE_CEC_ENABLE 0x01
+#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
+
+struct i2c_adapter;
+
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size);
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size);
+
+/**
+ * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
+ */
+enum drm_dp_dual_mode_type {
+	DRM_DP_DUAL_MODE_NONE,
+	DRM_DP_DUAL_MODE_UNKNOWN,
+	DRM_DP_DUAL_MODE_TYPE1_DVI,
+	DRM_DP_DUAL_MODE_TYPE1_HDMI,
+	DRM_DP_DUAL_MODE_TYPE2_DVI,
+	DRM_DP_DUAL_MODE_TYPE2_HDMI,
+};
+
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter);
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool *enabled);
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable);
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
+
+#endif
-- 
2.7.4

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 1/4] drm: Add helper for DP++ adaptors
  2016-05-03 17:56       ` ville.syrjala
  (?)
@ 2016-05-04  6:26       ` Sharma, Shashank
  -1 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04  6:26 UTC (permalink / raw)
  To: ville.syrjala, intel-gfx
  Cc: stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

Thanks for addressing my review comments.
Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
On 5/3/2016 11:26 PM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
>
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1 adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
>
> Type 1 adaptors provide access to their internal registers and the sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
>
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
>
> Other user controllable features that may be available in the adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
>
> v2: Pass adaptor type to helper functions to ease driver implementation
>      Fix a bunch of typoes (Paulo)
>      Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
>      the type (Paulo)
>      Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>      Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>      ease future LSPCON enabling
>      Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> v3: Fix kernel doc function argument descriptions (Jani)
>      s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
>      Add kernel doc for enum drm_dp_dual_mode_type
>      Actually build the docs
>      Fix more typoes
> v4: Adjust code indentation of type2 adaptor detection (Shashank)
>      Add debug messages for failurs cases (Shashank)
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   Documentation/DocBook/gpu.tmpl            |   6 +
>   drivers/gpu/drm/Makefile                  |   2 +-
>   drivers/gpu/drm/drm_dp_dual_mode_helper.c | 365 ++++++++++++++++++++++++++++++
>   include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
>   4 files changed, 464 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>   create mode 100644 include/drm/drm_dp_dual_mode_helper.h
>
> diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
> index 1464fb2f3c46..c248124357df 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
>   !Edrivers/gpu/drm/drm_dp_helper.c
>       </sect2>
>       <sect2>
> +      <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
> +!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
> +!Iinclude/drm/drm_dp_dual_mode_helper.h
> +!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
> +    </sect2>
> +    <sect2>
>         <title>Display Port MST Helper Functions Reference</title>
>   !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
>   !Iinclude/drm/drm_dp_mst_helper.h
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>
>   drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
>   		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>
>   drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>   drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..6842178474ba
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,365 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: dp dual mode helpers
> + *
> + * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C or
> + * I2C-over-AUX. Source devices may choose to implement either of these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for return data
> + * @size: sizo of the buffer
> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for write data
> + * @size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method would
> +	 * simply require the driver to know whether the port is a DP++
> +	 * port or a native HDMI port. Both of these methods are entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
> +	 * the offset but ignore it, and instead they just always return
> +	 * data from the start of the HDMI ID buffer. So for a broken
> +	 * type 1 HDMI adaptor a single byte read will always give us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id, sizeof(adaptor_id));
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id)) {
> +			if (is_hdmi_adaptor(hdmi_id))
> +				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +			else
> +				return DRM_DP_DUAL_MODE_TYPE2_DVI;
> +		}
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock, sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff) {
> +		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
> +		return 165000;
> +	}
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to query state of TMDS output buffers\n");
> +		return ret;
> +	}
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
> +			      enable ? "enable" : "disable");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
> + * @type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..e8a9dfd0e055
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,92 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adaptors
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adaptors
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t size);
> +
> +/**
> + * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
> + */
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
> +				     struct i2c_adapter *adapter, bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
> +
> +#endif
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit
  2016-05-02 19:08 ` [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit ville.syrjala
@ 2016-05-04 10:08   ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 10:08 UTC (permalink / raw)
  To: ville.syrjala, dri-devel; +Cc: intel-gfx, stable, Paulo Zanoni, Daniel Vetter

Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Try to detect the max TMDS clock limit for the DP++ adaptor (if any)
> and take it into account when checking the port clock.
>
> Note that as with the sink (HDMI vs. DVI) TMDS clock limit we'll ignore
> the adaptor TMDS clock limit in the modeset path, in case users are
> already "overclocking" their TMDS links. One subtle change here is that
> we'll have to respect the adaptor TMDS clock limit when we decide whether
> to do 12bpc or 8bpc, otherwise we might end up picking 12bpc and
> accidentally driving the TMDS link out of spec even when the user chose
> a mode that fits wihting the limits at 8bpc. This means you can't
> "overclock" your DP++ dongle at 12bpc anymore, but you can continue to
> do so at 8bpc.
>
> Note that for simplicity we'll use the I2C access method for all dual
> mode adaptors including type 2. Otherwise we'd have to start mixing
> DP AUX and HDMI together. In the future we may need to do that if we
> come across any board designs that don't hook up the DDC pins to the
> DP++ connectors. Such boards would obviously only work with type 2
> dual mode adaptors, and not type 1.
>
> v2: Store adaptor type under indel_hdmi->dp_dual_mode
>      Deal with DRM_DP_DUAL_MODE_UNKNOWN
>      Pass adaptor type to drm_dp_dual_mode_max_tmds_clock(),
>      and use it for type1 adaptors as well
>
> Cc: stable@vger.kernel.org
> Reported-by: Tore Anderson <tore@fud.no>
> Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/intel_drv.h  |  5 ++++
>   drivers/gpu/drm/i915/intel_hdmi.c | 58 +++++++++++++++++++++++++++++++++------
>   2 files changed, 55 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index 21dee3f89e84..e94d18fb2ff1 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -33,6 +33,7 @@
>   #include <drm/drm_crtc.h>
>   #include <drm/drm_crtc_helper.h>
>   #include <drm/drm_fb_helper.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
>   #include <drm/drm_dp_mst_helper.h>
>   #include <drm/drm_rect.h>
>   #include <drm/drm_atomic.h>
> @@ -753,6 +754,10 @@ struct cxsr_latency {
>   struct intel_hdmi {
>   	i915_reg_t hdmi_reg;
>   	int ddc_bus;
> +	struct {
> +		enum drm_dp_dual_mode_type type;
> +		int max_tmds_clock;
> +	} dp_dual_mode;
>   	bool limited_color_range;
>   	bool color_range_auto;
>   	bool has_hdmi_sink;
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index e1012d612024..31ca11134294 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -1167,27 +1167,42 @@ static void pch_post_disable_hdmi(struct intel_encoder *encoder)
>   	intel_disable_hdmi(encoder);
>   }
>
> -static int hdmi_port_clock_limit(struct intel_hdmi *hdmi, bool respect_dvi_limit)
> +static int intel_hdmi_source_max_tmds_clock(struct drm_i915_private *dev_priv)
>   {
> -	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
> -
> -	if ((respect_dvi_limit && !hdmi->has_hdmi_sink) || IS_G4X(dev))
> +	if (IS_G4X(dev_priv))
>   		return 165000;
> -	else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
> +	else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8)
>   		return 300000;
>   	else
>   		return 225000;
>   }
>
> +static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
> +				 bool respect_downstream_limits)
> +{
> +	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
> +	int max_tmds_clock = intel_hdmi_source_max_tmds_clock(to_i915(dev));
> +
> +	if (respect_downstream_limits) {
> +		if (hdmi->dp_dual_mode.max_tmds_clock)
> +			max_tmds_clock = min(max_tmds_clock,
> +					     hdmi->dp_dual_mode.max_tmds_clock);
> +		if (!hdmi->has_hdmi_sink)
> +			max_tmds_clock = min(max_tmds_clock, 165000);
> +	}
> +
> +	return max_tmds_clock;
> +}
> +
>   static enum drm_mode_status
>   hdmi_port_clock_valid(struct intel_hdmi *hdmi,
> -		      int clock, bool respect_dvi_limit)
> +		      int clock, bool respect_downstream_limits)
>   {
>   	struct drm_device *dev = intel_hdmi_to_dev(hdmi);
>
>   	if (clock < 25000)
>   		return MODE_CLOCK_LOW;
> -	if (clock > hdmi_port_clock_limit(hdmi, respect_dvi_limit))
> +	if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits))
>   		return MODE_CLOCK_HIGH;
>
>   	/* BXT DPLL can't generate 223-240 MHz */
> @@ -1311,7 +1326,7 @@ bool intel_hdmi_compute_config(struct intel_encoder *encoder,
>   	 * within limits.
>   	 */
>   	if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
> -	    hdmi_port_clock_valid(intel_hdmi, clock_12bpc, false) == MODE_OK &&
> +	    hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true) == MODE_OK &&
>   	    hdmi_12bpc_possible(pipe_config)) {
>   		DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
>   		desired_bpp = 12*3;
> @@ -1353,10 +1368,35 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
>   	intel_hdmi->has_audio = false;
>   	intel_hdmi->rgb_quant_range_selectable = false;
>
> +	intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
> +	intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
> +
>   	kfree(to_intel_connector(connector)->detect_edid);
>   	to_intel_connector(connector)->detect_edid = NULL;
>   }
>
> +static void
> +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> +{
> +	struct drm_i915_private *dev_priv = to_i915(connector->dev);
> +	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> +	struct i2c_adapter *adapter =
> +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> +	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
> +
> +	if (type == DRM_DP_DUAL_MODE_NONE ||
> +	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> +		return;
> +
> +	hdmi->dp_dual_mode.type = type;
> +	hdmi->dp_dual_mode.max_tmds_clock =
> +		drm_dp_dual_mode_max_tmds_clock(type, adapter);
> +
> +	DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
> +		      drm_dp_get_dual_mode_type_name(type),
> +		      hdmi->dp_dual_mode.max_tmds_clock);
> +}
> +
>   static bool
>   intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   {
> @@ -1372,6 +1412,8 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   				    intel_gmbus_get_adapter(dev_priv,
>   				    intel_hdmi->ddc_bus));
>
> +		intel_hdmi_dp_dual_mode_detect(connector);
> +
>   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>   	}
>
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
  2016-05-02 19:08 ` [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed ville.syrjala
@ 2016-05-04 10:13   ` Sharma, Shashank
  2016-05-04 11:49       ` Ville Syrjälä
  0 siblings, 1 reply; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 10:13 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter


On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> To save a bit of power, let's try to turn off the TMDS output buffers
> in DP++ adaptors when we're not driving the port.
>
> v2: Let's not forget DDI, toss in a debug message while at it
> v3: Just do the TMDS output control based on adaptor type. With the
>      helper getting passed the type, we wouldn't actually have to
>      check at all in the driver, but the check eliminates the debug
>      output more honest
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
>   drivers/gpu/drm/i915/intel_drv.h  |  1 +
>   drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
>   3 files changed, 33 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
> index 422ec81ef59b..a3600704e6d4 100644
> --- a/drivers/gpu/drm/i915/intel_ddi.c
> +++ b/drivers/gpu/drm/i915/intel_ddi.c
> @@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
>   	enum port port = intel_ddi_get_encoder_port(intel_encoder);
>   	int type = intel_encoder->type;
>
> +	if (type == INTEL_OUTPUT_HDMI) {
how to handle type2 active adapters here, which can show type = DP ?
> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> +
> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> +	}
> +
>   	intel_prepare_ddi_buffer(intel_encoder);
>
>   	if (type == INTEL_OUTPUT_EDP) {
> @@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
>   					DPLL_CTRL2_DDI_CLK_OFF(port)));
>   	else if (INTEL_INFO(dev)->gen < 9)
>   		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
> +
> +	if (type == INTEL_OUTPUT_HDMI) {
Same as above.

Regards
Shashank
> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> +
> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
> +	}
>   }
>
>   static void intel_enable_ddi(struct intel_encoder *intel_encoder)
> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> index e94d18fb2ff1..dbcb80c70e2e 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
>   struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
>   bool intel_hdmi_compute_config(struct intel_encoder *encoder,
>   			       struct intel_crtc_state *pipe_config);
> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
>
>
>   /* intel_lvds.c */
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index 31ca11134294..c4d93e6b4bed 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
>   	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
>   }
>
> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
> +{
> +	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
> +	struct i2c_adapter *adapter =
> +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> +
> +	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return;
> +
> +	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
> +		      enable ? "Enabling" : "Disabling");
> +
> +	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
> +					 adapter, enable);
> +}
> +
>   static void intel_hdmi_prepare(struct intel_encoder *encoder)
>   {
>   	struct drm_device *dev = encoder->base.dev;
> @@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
>   	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
>   	u32 hdmi_val;
>
> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> +
>   	hdmi_val = SDVO_ENCODING_HDMI;
>   	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
>   		hdmi_val |= HDMI_COLOR_RANGE_16_235;
> @@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
>   	}
>
>   	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
> +
> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
>   }
>
>   static void g4x_disable_hdmi(struct intel_encoder *encoder)
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
  2016-05-02 19:08 ` [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT ville.syrjala
@ 2016-05-04 10:24     ` Sharma, Shashank
  2016-05-04 11:45   ` [PATCH v3 " ville.syrjala
  1 sibling, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 10:24 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter



On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> DP dual mode type 1 DVI adaptors aren't required to implement any
> registers, so it's a bit hard to detect them. The best way would
> be to check the state of the CONFIG1 pin, but we have no way to
> do that. So as a last resort, check the VBT to see if the HDMI
> port is in fact a dual mode capable DP port.
>
> v2: Deal with VBT code reorganization
>      Deal with DRM_DP_DUAL_MODE_UNKNOWN
>      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
>      Accept both DP and HDMI dvo_port in VBT as my BSW
>      at least declare its DP port as HDMI :(
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Reported-by: Tore Anderson <tore@fud.no>
> Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/i915_drv.h       |  1 +
>   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
>   drivers/gpu/drm/i915/intel_vbt_defs.h | 13 +++++++++++++
>   4 files changed, 76 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index ff6aaf0c4e1e..abe43922a08f 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
>   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
>   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
>   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
>   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
>   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
>   				     enum port port);
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 81518116e00d..8b68c4882fba 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
>   	return false;
>   }
>
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> +{
> +	static const struct {
> +		u16 dp, hdmi;
> +	} port_mapping[] = {
> +		/*
> +		 * Buggy VBTs may declare DP ports as having
> +		 * HDMI type dvo_port :( So let's check both.
> +		 */
> +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> +	};
> +	int i;
> +
> +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> +		return false;
> +
> +	if (!dev_priv->vbt.child_dev_num)
> +		return false;
> +
> +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> +		const union child_device_config *p_child =
> +			&dev_priv->vbt.child_dev[i];
> +
> +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   /**
>    * intel_bios_is_dsi_present - is DSI present in VBT
>    * @dev_priv:	i915 device instance
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index c4d93e6b4bed..6b52c6accf6a 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
>   }
>
>   static void
> -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
>   {
>   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
>   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> +	enum port port = hdmi_to_dig_port(hdmi)->port;
>   	struct i2c_adapter *adapter =
>   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
>
> -	if (type == DRM_DP_DUAL_MODE_NONE ||
> -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> +	/*
> +	 * Type 1 DVI adaptors are not required to implement any
> +	 * registers, so we can't always detect their presence.
> +	 * Ideally we should be able to check the state of the
> +	 * CONFIG1 pin, but no such luck on our hardware.
> +	 *
> +	 * The only method left to us is to check the VBT to see
> +	 * if the port is a dual mode capable DP port. But let's
> +	 * only do that when we sucesfully read the EDID, to avoid
> +	 * confusing log messages about DP dual mode adaptors when
> +	 * there's nothing connected to the port.
> +	 */
> +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> +		if (has_edid &&
> +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> +		} else {
> +			type = DRM_DP_DUAL_MODE_NONE;
> +		}
> +	}
> +
> +	if (type == DRM_DP_DUAL_MODE_NONE)
>   		return;
>
>   	hdmi->dp_dual_mode.type = type;
> @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   				    intel_gmbus_get_adapter(dev_priv,
>   				    intel_hdmi->ddc_bus));
>
> -		intel_hdmi_dp_dual_mode_detect(connector);
> +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
>
>   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>   	}
> diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> index a4a42f254c35..b1019e01e51d 100644
> --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> @@ -746,6 +746,7 @@ struct bdb_psr {
>   #define	 DEVICE_TYPE_INT_TV	0x1009
>   #define	 DEVICE_TYPE_HDMI	0x60D2
>   #define	 DEVICE_TYPE_DP		0x68C6
> +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
>   #define	 DEVICE_TYPE_eDP	0x78C6
>
>   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> @@ -780,6 +781,18 @@ struct bdb_psr {
>   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
>   	 DEVICE_TYPE_ANALOG_OUTPUT)
>
> +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> +	 DEVICE_TYPE_NOT_HDMI_OUTPUT | \
Why do we need this one ? Shouldn't the others cover all the cases ?
Is there a special case in your mind ?

Regards
Shashank
> +	 DEVICE_TYPE_MIPI_OUTPUT | \
> +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> +	 DEVICE_TYPE_LVDS_SINGALING | \
> +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> +	 DEVICE_TYPE_ANALOG_OUTPUT)
> +
>   /* define the DVO port for HDMI output type */
>   #define		DVO_B		1
>   #define		DVO_C		2
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
@ 2016-05-04 10:24     ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 10:24 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: Daniel Vetter, intel-gfx, Tore Anderson, Paulo Zanoni, stable



On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> DP dual mode type 1 DVI adaptors aren't required to implement any
> registers, so it's a bit hard to detect them. The best way would
> be to check the state of the CONFIG1 pin, but we have no way to
> do that. So as a last resort, check the VBT to see if the HDMI
> port is in fact a dual mode capable DP port.
>
> v2: Deal with VBT code reorganization
>      Deal with DRM_DP_DUAL_MODE_UNKNOWN
>      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
>      Accept both DP and HDMI dvo_port in VBT as my BSW
>      at least declare its DP port as HDMI :(
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Reported-by: Tore Anderson <tore@fud.no>
> Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/i915_drv.h       |  1 +
>   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
>   drivers/gpu/drm/i915/intel_vbt_defs.h | 13 +++++++++++++
>   4 files changed, 76 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index ff6aaf0c4e1e..abe43922a08f 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
>   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
>   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
>   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
>   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
>   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
>   				     enum port port);
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 81518116e00d..8b68c4882fba 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
>   	return false;
>   }
>
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> +{
> +	static const struct {
> +		u16 dp, hdmi;
> +	} port_mapping[] = {
> +		/*
> +		 * Buggy VBTs may declare DP ports as having
> +		 * HDMI type dvo_port :( So let's check both.
> +		 */
> +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> +	};
> +	int i;
> +
> +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> +		return false;
> +
> +	if (!dev_priv->vbt.child_dev_num)
> +		return false;
> +
> +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> +		const union child_device_config *p_child =
> +			&dev_priv->vbt.child_dev[i];
> +
> +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   /**
>    * intel_bios_is_dsi_present - is DSI present in VBT
>    * @dev_priv:	i915 device instance
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index c4d93e6b4bed..6b52c6accf6a 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
>   }
>
>   static void
> -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
>   {
>   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
>   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> +	enum port port = hdmi_to_dig_port(hdmi)->port;
>   	struct i2c_adapter *adapter =
>   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
>
> -	if (type == DRM_DP_DUAL_MODE_NONE ||
> -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> +	/*
> +	 * Type 1 DVI adaptors are not required to implement any
> +	 * registers, so we can't always detect their presence.
> +	 * Ideally we should be able to check the state of the
> +	 * CONFIG1 pin, but no such luck on our hardware.
> +	 *
> +	 * The only method left to us is to check the VBT to see
> +	 * if the port is a dual mode capable DP port. But let's
> +	 * only do that when we sucesfully read the EDID, to avoid
> +	 * confusing log messages about DP dual mode adaptors when
> +	 * there's nothing connected to the port.
> +	 */
> +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> +		if (has_edid &&
> +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> +		} else {
> +			type = DRM_DP_DUAL_MODE_NONE;
> +		}
> +	}
> +
> +	if (type == DRM_DP_DUAL_MODE_NONE)
>   		return;
>
>   	hdmi->dp_dual_mode.type = type;
> @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   				    intel_gmbus_get_adapter(dev_priv,
>   				    intel_hdmi->ddc_bus));
>
> -		intel_hdmi_dp_dual_mode_detect(connector);
> +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
>
>   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>   	}
> diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> index a4a42f254c35..b1019e01e51d 100644
> --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> @@ -746,6 +746,7 @@ struct bdb_psr {
>   #define	 DEVICE_TYPE_INT_TV	0x1009
>   #define	 DEVICE_TYPE_HDMI	0x60D2
>   #define	 DEVICE_TYPE_DP		0x68C6
> +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
>   #define	 DEVICE_TYPE_eDP	0x78C6
>
>   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> @@ -780,6 +781,18 @@ struct bdb_psr {
>   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
>   	 DEVICE_TYPE_ANALOG_OUTPUT)
>
> +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> +	 DEVICE_TYPE_NOT_HDMI_OUTPUT | \
Why do we need this one ? Shouldn't the others cover all the cases ?
Is there a special case in your mind ?

Regards
Shashank
> +	 DEVICE_TYPE_MIPI_OUTPUT | \
> +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> +	 DEVICE_TYPE_LVDS_SINGALING | \
> +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> +	 DEVICE_TYPE_ANALOG_OUTPUT)
> +
>   /* define the DVO port for HDMI output type */
>   #define		DVO_B		1
>   #define		DVO_C		2
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
  2016-05-04 10:24     ` Sharma, Shashank
@ 2016-05-04 11:29       ` Ville Syrjälä
  -1 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-04 11:29 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

On Wed, May 04, 2016 at 03:54:41PM +0530, Sharma, Shashank wrote:
> 
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> >
> > DP dual mode type 1 DVI adaptors aren't required to implement any
> > registers, so it's a bit hard to detect them. The best way would
> > be to check the state of the CONFIG1 pin, but we have no way to
> > do that. So as a last resort, check the VBT to see if the HDMI
> > port is in fact a dual mode capable DP port.
> >
> > v2: Deal with VBT code reorganization
> >      Deal with DRM_DP_DUAL_MODE_UNKNOWN
> >      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
> >      Accept both DP and HDMI dvo_port in VBT as my BSW
> >      at least declare its DP port as HDMI :(
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Reported-by: Tore Anderson <tore@fud.no>
> > Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/i915/i915_drv.h       |  1 +
> >   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
> >   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
> >   drivers/gpu/drm/i915/intel_vbt_defs.h | 13 +++++++++++++
> >   4 files changed, 76 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> > index ff6aaf0c4e1e..abe43922a08f 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
> >   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
> >   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
> >   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> > +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
> >   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
> >   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
> >   				     enum port port);
> > diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> > index 81518116e00d..8b68c4882fba 100644
> > --- a/drivers/gpu/drm/i915/intel_bios.c
> > +++ b/drivers/gpu/drm/i915/intel_bios.c
> > @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
> >   	return false;
> >   }
> >
> > +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> > +{
> > +	static const struct {
> > +		u16 dp, hdmi;
> > +	} port_mapping[] = {
> > +		/*
> > +		 * Buggy VBTs may declare DP ports as having
> > +		 * HDMI type dvo_port :( So let's check both.
> > +		 */
> > +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> > +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> > +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> > +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> > +	};
> > +	int i;
> > +
> > +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> > +		return false;
> > +
> > +	if (!dev_priv->vbt.child_dev_num)
> > +		return false;
> > +
> > +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> > +		const union child_device_config *p_child =
> > +			&dev_priv->vbt.child_dev[i];
> > +
> > +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> > +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> > +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> > +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> > +			return true;
> > +	}
> > +
> > +	return false;
> > +}
> > +
> >   /**
> >    * intel_bios_is_dsi_present - is DSI present in VBT
> >    * @dev_priv:	i915 device instance
> > diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> > index c4d93e6b4bed..6b52c6accf6a 100644
> > --- a/drivers/gpu/drm/i915/intel_hdmi.c
> > +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> > @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
> >   }
> >
> >   static void
> > -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> > +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
> >   {
> >   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
> >   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> > +	enum port port = hdmi_to_dig_port(hdmi)->port;
> >   	struct i2c_adapter *adapter =
> >   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> >   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
> >
> > -	if (type == DRM_DP_DUAL_MODE_NONE ||
> > -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> > +	/*
> > +	 * Type 1 DVI adaptors are not required to implement any
> > +	 * registers, so we can't always detect their presence.
> > +	 * Ideally we should be able to check the state of the
> > +	 * CONFIG1 pin, but no such luck on our hardware.
> > +	 *
> > +	 * The only method left to us is to check the VBT to see
> > +	 * if the port is a dual mode capable DP port. But let's
> > +	 * only do that when we sucesfully read the EDID, to avoid
> > +	 * confusing log messages about DP dual mode adaptors when
> > +	 * there's nothing connected to the port.
> > +	 */
> > +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> > +		if (has_edid &&
> > +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> > +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> > +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +		} else {
> > +			type = DRM_DP_DUAL_MODE_NONE;
> > +		}
> > +	}
> > +
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> >   		return;
> >
> >   	hdmi->dp_dual_mode.type = type;
> > @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
> >   				    intel_gmbus_get_adapter(dev_priv,
> >   				    intel_hdmi->ddc_bus));
> >
> > -		intel_hdmi_dp_dual_mode_detect(connector);
> > +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
> >
> >   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
> >   	}
> > diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> > index a4a42f254c35..b1019e01e51d 100644
> > --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> > +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> > @@ -746,6 +746,7 @@ struct bdb_psr {
> >   #define	 DEVICE_TYPE_INT_TV	0x1009
> >   #define	 DEVICE_TYPE_HDMI	0x60D2
> >   #define	 DEVICE_TYPE_DP		0x68C6
> > +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
> >   #define	 DEVICE_TYPE_eDP	0x78C6
> >
> >   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> > @@ -780,6 +781,18 @@ struct bdb_psr {
> >   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> >   	 DEVICE_TYPE_ANALOG_OUTPUT)
> >
> > +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> > +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> > +	 DEVICE_TYPE_NOT_HDMI_OUTPUT | \
> Why do we need this one ? Shouldn't the others cover all the cases ?
> Is there a special case in your mind ?

Doh. That bit shouldn't be here. It's the only bit I was ignoring in
the previous version, and definitely we should ignore it still. I'll
send out a v3. Good catch there.

> 
> Regards
> Shashank
> > +	 DEVICE_TYPE_MIPI_OUTPUT | \
> > +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> > +	 DEVICE_TYPE_LVDS_SINGALING | \
> > +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> > +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> > +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> > +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> > +	 DEVICE_TYPE_ANALOG_OUTPUT)
> > +
> >   /* define the DVO port for HDMI output type */
> >   #define		DVO_B		1
> >   #define		DVO_C		2
> >

-- 
Ville Syrj�l�
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
@ 2016-05-04 11:29       ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-04 11:29 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

On Wed, May 04, 2016 at 03:54:41PM +0530, Sharma, Shashank wrote:
> 
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > DP dual mode type 1 DVI adaptors aren't required to implement any
> > registers, so it's a bit hard to detect them. The best way would
> > be to check the state of the CONFIG1 pin, but we have no way to
> > do that. So as a last resort, check the VBT to see if the HDMI
> > port is in fact a dual mode capable DP port.
> >
> > v2: Deal with VBT code reorganization
> >      Deal with DRM_DP_DUAL_MODE_UNKNOWN
> >      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
> >      Accept both DP and HDMI dvo_port in VBT as my BSW
> >      at least declare its DP port as HDMI :(
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Reported-by: Tore Anderson <tore@fud.no>
> > Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/i915/i915_drv.h       |  1 +
> >   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
> >   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
> >   drivers/gpu/drm/i915/intel_vbt_defs.h | 13 +++++++++++++
> >   4 files changed, 76 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> > index ff6aaf0c4e1e..abe43922a08f 100644
> > --- a/drivers/gpu/drm/i915/i915_drv.h
> > +++ b/drivers/gpu/drm/i915/i915_drv.h
> > @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
> >   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
> >   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
> >   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> > +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
> >   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
> >   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
> >   				     enum port port);
> > diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> > index 81518116e00d..8b68c4882fba 100644
> > --- a/drivers/gpu/drm/i915/intel_bios.c
> > +++ b/drivers/gpu/drm/i915/intel_bios.c
> > @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
> >   	return false;
> >   }
> >
> > +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> > +{
> > +	static const struct {
> > +		u16 dp, hdmi;
> > +	} port_mapping[] = {
> > +		/*
> > +		 * Buggy VBTs may declare DP ports as having
> > +		 * HDMI type dvo_port :( So let's check both.
> > +		 */
> > +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> > +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> > +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> > +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> > +	};
> > +	int i;
> > +
> > +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> > +		return false;
> > +
> > +	if (!dev_priv->vbt.child_dev_num)
> > +		return false;
> > +
> > +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> > +		const union child_device_config *p_child =
> > +			&dev_priv->vbt.child_dev[i];
> > +
> > +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> > +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> > +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> > +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> > +			return true;
> > +	}
> > +
> > +	return false;
> > +}
> > +
> >   /**
> >    * intel_bios_is_dsi_present - is DSI present in VBT
> >    * @dev_priv:	i915 device instance
> > diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> > index c4d93e6b4bed..6b52c6accf6a 100644
> > --- a/drivers/gpu/drm/i915/intel_hdmi.c
> > +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> > @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
> >   }
> >
> >   static void
> > -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> > +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
> >   {
> >   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
> >   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> > +	enum port port = hdmi_to_dig_port(hdmi)->port;
> >   	struct i2c_adapter *adapter =
> >   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> >   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
> >
> > -	if (type == DRM_DP_DUAL_MODE_NONE ||
> > -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> > +	/*
> > +	 * Type 1 DVI adaptors are not required to implement any
> > +	 * registers, so we can't always detect their presence.
> > +	 * Ideally we should be able to check the state of the
> > +	 * CONFIG1 pin, but no such luck on our hardware.
> > +	 *
> > +	 * The only method left to us is to check the VBT to see
> > +	 * if the port is a dual mode capable DP port. But let's
> > +	 * only do that when we sucesfully read the EDID, to avoid
> > +	 * confusing log messages about DP dual mode adaptors when
> > +	 * there's nothing connected to the port.
> > +	 */
> > +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> > +		if (has_edid &&
> > +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> > +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> > +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> > +		} else {
> > +			type = DRM_DP_DUAL_MODE_NONE;
> > +		}
> > +	}
> > +
> > +	if (type == DRM_DP_DUAL_MODE_NONE)
> >   		return;
> >
> >   	hdmi->dp_dual_mode.type = type;
> > @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
> >   				    intel_gmbus_get_adapter(dev_priv,
> >   				    intel_hdmi->ddc_bus));
> >
> > -		intel_hdmi_dp_dual_mode_detect(connector);
> > +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
> >
> >   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
> >   	}
> > diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> > index a4a42f254c35..b1019e01e51d 100644
> > --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> > +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> > @@ -746,6 +746,7 @@ struct bdb_psr {
> >   #define	 DEVICE_TYPE_INT_TV	0x1009
> >   #define	 DEVICE_TYPE_HDMI	0x60D2
> >   #define	 DEVICE_TYPE_DP		0x68C6
> > +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
> >   #define	 DEVICE_TYPE_eDP	0x78C6
> >
> >   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> > @@ -780,6 +781,18 @@ struct bdb_psr {
> >   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> >   	 DEVICE_TYPE_ANALOG_OUTPUT)
> >
> > +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> > +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> > +	 DEVICE_TYPE_NOT_HDMI_OUTPUT | \
> Why do we need this one ? Shouldn't the others cover all the cases ?
> Is there a special case in your mind ?

Doh. That bit shouldn't be here. It's the only bit I was ignoring in
the previous version, and definitely we should ignore it still. I'll
send out a v3. Good catch there.

> 
> Regards
> Shashank
> > +	 DEVICE_TYPE_MIPI_OUTPUT | \
> > +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> > +	 DEVICE_TYPE_LVDS_SINGALING | \
> > +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> > +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> > +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> > +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> > +	 DEVICE_TYPE_ANALOG_OUTPUT)
> > +
> >   /* define the DVO port for HDMI output type */
> >   #define		DVO_B		1
> >   #define		DVO_C		2
> >

-- 
Ville Syrjälä
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v3 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
  2016-05-02 19:08 ` [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT ville.syrjala
  2016-05-04 10:24     ` Sharma, Shashank
@ 2016-05-04 11:45   ` ville.syrjala
  2016-05-04 13:50       ` Sharma, Shashank
  1 sibling, 1 reply; 36+ messages in thread
From: ville.syrjala @ 2016-05-04 11:45 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

DP dual mode type 1 DVI adaptors aren't required to implement any
registers, so it's a bit hard to detect them. The best way would
be to check the state of the CONFIG1 pin, but we have no way to
do that. So as a last resort, check the VBT to see if the HDMI
port is in fact a dual mode capable DP port.

v2: Deal with VBT code reorganization
    Deal with DRM_DP_DUAL_MODE_UNKNOWN
    Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
    Accept both DP and HDMI dvo_port in VBT as my BSW
    at least declare its DP port as HDMI :(
v3: Ignore DEVICE_TYPE_NOT_HDMI_OUTPUT (Shashanl)

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Reported-by: Tore Anderson <tore@fud.no>
Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h       |  1 +
 drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
 drivers/gpu/drm/i915/intel_vbt_defs.h | 12 ++++++++++++
 4 files changed, 75 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index ff6aaf0c4e1e..abe43922a08f 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
 bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
 bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
 bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
+bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
 bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
 bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
 				     enum port port);
diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
index 81518116e00d..8b68c4882fba 100644
--- a/drivers/gpu/drm/i915/intel_bios.c
+++ b/drivers/gpu/drm/i915/intel_bios.c
@@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
 	return false;
 }
 
+bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
+{
+	static const struct {
+		u16 dp, hdmi;
+	} port_mapping[] = {
+		/*
+		 * Buggy VBTs may declare DP ports as having
+		 * HDMI type dvo_port :( So let's check both.
+		 */
+		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
+		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
+		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
+		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
+	};
+	int i;
+
+	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
+		return false;
+
+	if (!dev_priv->vbt.child_dev_num)
+		return false;
+
+	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
+		const union child_device_config *p_child =
+			&dev_priv->vbt.child_dev[i];
+
+		if ((p_child->common.dvo_port == port_mapping[port].dp ||
+		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
+		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
+		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
+			return true;
+	}
+
+	return false;
+}
+
 /**
  * intel_bios_is_dsi_present - is DSI present in VBT
  * @dev_priv:	i915 device instance
diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
index c4d93e6b4bed..6b52c6accf6a 100644
--- a/drivers/gpu/drm/i915/intel_hdmi.c
+++ b/drivers/gpu/drm/i915/intel_hdmi.c
@@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
 }
 
 static void
-intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
+intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
 {
 	struct drm_i915_private *dev_priv = to_i915(connector->dev);
 	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
+	enum port port = hdmi_to_dig_port(hdmi)->port;
 	struct i2c_adapter *adapter =
 		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
 	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
 
-	if (type == DRM_DP_DUAL_MODE_NONE ||
-	    type == DRM_DP_DUAL_MODE_UNKNOWN)
+	/*
+	 * Type 1 DVI adaptors are not required to implement any
+	 * registers, so we can't always detect their presence.
+	 * Ideally we should be able to check the state of the
+	 * CONFIG1 pin, but no such luck on our hardware.
+	 *
+	 * The only method left to us is to check the VBT to see
+	 * if the port is a dual mode capable DP port. But let's
+	 * only do that when we sucesfully read the EDID, to avoid
+	 * confusing log messages about DP dual mode adaptors when
+	 * there's nothing connected to the port.
+	 */
+	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
+		if (has_edid &&
+		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
+			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
+			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
+		} else {
+			type = DRM_DP_DUAL_MODE_NONE;
+		}
+	}
+
+	if (type == DRM_DP_DUAL_MODE_NONE)
 		return;
 
 	hdmi->dp_dual_mode.type = type;
@@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
 				    intel_gmbus_get_adapter(dev_priv,
 				    intel_hdmi->ddc_bus));
 
-		intel_hdmi_dp_dual_mode_detect(connector);
+		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
 
 		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
 	}
diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
index a4a42f254c35..4f9799f025a9 100644
--- a/drivers/gpu/drm/i915/intel_vbt_defs.h
+++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
@@ -746,6 +746,7 @@ struct bdb_psr {
 #define	 DEVICE_TYPE_INT_TV	0x1009
 #define	 DEVICE_TYPE_HDMI	0x60D2
 #define	 DEVICE_TYPE_DP		0x68C6
+#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
 #define	 DEVICE_TYPE_eDP	0x78C6
 
 #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
@@ -780,6 +781,17 @@ struct bdb_psr {
 	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
 	 DEVICE_TYPE_ANALOG_OUTPUT)
 
+#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
+	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
+	 DEVICE_TYPE_MIPI_OUTPUT | \
+	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
+	 DEVICE_TYPE_LVDS_SINGALING | \
+	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
+	 DEVICE_TYPE_VIDEO_SIGNALING | \
+	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
+	 DEVICE_TYPE_DIGITAL_OUTPUT | \
+	 DEVICE_TYPE_ANALOG_OUTPUT)
+
 /* define the DVO port for HDMI output type */
 #define		DVO_B		1
 #define		DVO_C		2
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
  2016-05-04 10:13   ` Sharma, Shashank
@ 2016-05-04 11:49       ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-04 11:49 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

On Wed, May 04, 2016 at 03:43:30PM +0530, Sharma, Shashank wrote:
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> >
> > To save a bit of power, let's try to turn off the TMDS output buffers
> > in DP++ adaptors when we're not driving the port.
> >
> > v2: Let's not forget DDI, toss in a debug message while at it
> > v3: Just do the TMDS output control based on adaptor type. With the
> >      helper getting passed the type, we wouldn't actually have to
> >      check at all in the driver, but the check eliminates the debug
> >      output more honest
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrj�l� <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
> >   drivers/gpu/drm/i915/intel_drv.h  |  1 +
> >   drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
> >   3 files changed, 33 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
> > index 422ec81ef59b..a3600704e6d4 100644
> > --- a/drivers/gpu/drm/i915/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/intel_ddi.c
> > @@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
> >   	enum port port = intel_ddi_get_encoder_port(intel_encoder);
> >   	int type = intel_encoder->type;
> >
> > +	if (type == INTEL_OUTPUT_HDMI) {
> how to handle type2 active adapters here, which can show type = DP ?

The dual mode concept shouldn't apply to active adapters. Those, as you
say, appear as DP and so will be handled as if they were native DP sinks
more or less.

Or are you aware of active DP dongles that also implement the dual mode
standatd? Apart from LSPCON of course. Actually I'm not sure how LSPCON
will handle this. If we drive it in PCON mode, would it still respect
the dual mode register settings, including the TMDS OE# state?

> > +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> > +
> > +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> > +	}
> > +
> >   	intel_prepare_ddi_buffer(intel_encoder);
> >
> >   	if (type == INTEL_OUTPUT_EDP) {
> > @@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
> >   					DPLL_CTRL2_DDI_CLK_OFF(port)));
> >   	else if (INTEL_INFO(dev)->gen < 9)
> >   		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
> > +
> > +	if (type == INTEL_OUTPUT_HDMI) {
> Same as above.
> 
> Regards
> Shashank
> > +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> > +
> > +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
> > +	}
> >   }
> >
> >   static void intel_enable_ddi(struct intel_encoder *intel_encoder)
> > diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> > index e94d18fb2ff1..dbcb80c70e2e 100644
> > --- a/drivers/gpu/drm/i915/intel_drv.h
> > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > @@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
> >   struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
> >   bool intel_hdmi_compute_config(struct intel_encoder *encoder,
> >   			       struct intel_crtc_state *pipe_config);
> > +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
> >
> >
> >   /* intel_lvds.c */
> > diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> > index 31ca11134294..c4d93e6b4bed 100644
> > --- a/drivers/gpu/drm/i915/intel_hdmi.c
> > +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> > @@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
> >   	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
> >   }
> >
> > +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
> > +{
> > +	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
> > +	struct i2c_adapter *adapter =
> > +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> > +
> > +	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return;
> > +
> > +	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
> > +		      enable ? "Enabling" : "Disabling");
> > +
> > +	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
> > +					 adapter, enable);
> > +}
> > +
> >   static void intel_hdmi_prepare(struct intel_encoder *encoder)
> >   {
> >   	struct drm_device *dev = encoder->base.dev;
> > @@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
> >   	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
> >   	u32 hdmi_val;
> >
> > +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> > +
> >   	hdmi_val = SDVO_ENCODING_HDMI;
> >   	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
> >   		hdmi_val |= HDMI_COLOR_RANGE_16_235;
> > @@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
> >   	}
> >
> >   	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
> > +
> > +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
> >   }
> >
> >   static void g4x_disable_hdmi(struct intel_encoder *encoder)
> >

-- 
Ville Syrj�l�
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
@ 2016-05-04 11:49       ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-04 11:49 UTC (permalink / raw)
  To: Sharma, Shashank
  Cc: Paulo Zanoni, Daniel Vetter, intel-gfx, Tore Anderson, stable, dri-devel

On Wed, May 04, 2016 at 03:43:30PM +0530, Sharma, Shashank wrote:
> 
> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > To save a bit of power, let's try to turn off the TMDS output buffers
> > in DP++ adaptors when we're not driving the port.
> >
> > v2: Let's not forget DDI, toss in a debug message while at it
> > v3: Just do the TMDS output control based on adaptor type. With the
> >      helper getting passed the type, we wouldn't actually have to
> >      check at all in the driver, but the check eliminates the debug
> >      output more honest
> >
> > Cc: stable@vger.kernel.org
> > Cc: Tore Anderson <tore@fud.no>
> > Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> > Cc: Shashank Sharma <shashank.sharma@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >   drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
> >   drivers/gpu/drm/i915/intel_drv.h  |  1 +
> >   drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
> >   3 files changed, 33 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
> > index 422ec81ef59b..a3600704e6d4 100644
> > --- a/drivers/gpu/drm/i915/intel_ddi.c
> > +++ b/drivers/gpu/drm/i915/intel_ddi.c
> > @@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
> >   	enum port port = intel_ddi_get_encoder_port(intel_encoder);
> >   	int type = intel_encoder->type;
> >
> > +	if (type == INTEL_OUTPUT_HDMI) {
> how to handle type2 active adapters here, which can show type = DP ?

The dual mode concept shouldn't apply to active adapters. Those, as you
say, appear as DP and so will be handled as if they were native DP sinks
more or less.

Or are you aware of active DP dongles that also implement the dual mode
standatd? Apart from LSPCON of course. Actually I'm not sure how LSPCON
will handle this. If we drive it in PCON mode, would it still respect
the dual mode register settings, including the TMDS OE# state?

> > +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> > +
> > +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> > +	}
> > +
> >   	intel_prepare_ddi_buffer(intel_encoder);
> >
> >   	if (type == INTEL_OUTPUT_EDP) {
> > @@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
> >   					DPLL_CTRL2_DDI_CLK_OFF(port)));
> >   	else if (INTEL_INFO(dev)->gen < 9)
> >   		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
> > +
> > +	if (type == INTEL_OUTPUT_HDMI) {
> Same as above.
> 
> Regards
> Shashank
> > +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
> > +
> > +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
> > +	}
> >   }
> >
> >   static void intel_enable_ddi(struct intel_encoder *intel_encoder)
> > diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
> > index e94d18fb2ff1..dbcb80c70e2e 100644
> > --- a/drivers/gpu/drm/i915/intel_drv.h
> > +++ b/drivers/gpu/drm/i915/intel_drv.h
> > @@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
> >   struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
> >   bool intel_hdmi_compute_config(struct intel_encoder *encoder,
> >   			       struct intel_crtc_state *pipe_config);
> > +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
> >
> >
> >   /* intel_lvds.c */
> > diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> > index 31ca11134294..c4d93e6b4bed 100644
> > --- a/drivers/gpu/drm/i915/intel_hdmi.c
> > +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> > @@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
> >   	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
> >   }
> >
> > +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
> > +{
> > +	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
> > +	struct i2c_adapter *adapter =
> > +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
> > +
> > +	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> > +		return;
> > +
> > +	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
> > +		      enable ? "Enabling" : "Disabling");
> > +
> > +	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
> > +					 adapter, enable);
> > +}
> > +
> >   static void intel_hdmi_prepare(struct intel_encoder *encoder)
> >   {
> >   	struct drm_device *dev = encoder->base.dev;
> > @@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
> >   	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
> >   	u32 hdmi_val;
> >
> > +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
> > +
> >   	hdmi_val = SDVO_ENCODING_HDMI;
> >   	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
> >   		hdmi_val |= HDMI_COLOR_RANGE_16_235;
> > @@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
> >   	}
> >
> >   	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
> > +
> > +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
> >   }
> >
> >   static void g4x_disable_hdmi(struct intel_encoder *encoder)
> >

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
  2016-05-04 11:49       ` Ville Syrjälä
@ 2016-05-04 13:48         ` Sharma, Shashank
  -1 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 13:48 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter



On 5/4/2016 5:19 PM, Ville Syrj�l� wrote:
> On Wed, May 04, 2016 at 03:43:30PM +0530, Sharma, Shashank wrote:
>>
>> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
>>> From: Ville Syrj�l� <ville.syrjala@linux.intel.com>
>>>
>>> To save a bit of power, let's try to turn off the TMDS output buffers
>>> in DP++ adaptors when we're not driving the port.
>>>
>>> v2: Let's not forget DDI, toss in a debug message while at it
>>> v3: Just do the TMDS output control based on adaptor type. With the
>>>       helper getting passed the type, we wouldn't actually have to
>>>       check at all in the driver, but the check eliminates the debug
>>>       output more honest
>>>
>>> Cc: stable@vger.kernel.org
>>> Cc: Tore Anderson <tore@fud.no>
>>> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
>>> Cc: Shashank Sharma <shashank.sharma@intel.com>
>>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>>> Signed-off-by: Ville Syrj�l� <ville.syrjala@linux.intel.com>
>>> ---
>>>    drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
>>>    drivers/gpu/drm/i915/intel_drv.h  |  1 +
>>>    drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
>>>    3 files changed, 33 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
>>> index 422ec81ef59b..a3600704e6d4 100644
>>> --- a/drivers/gpu/drm/i915/intel_ddi.c
>>> +++ b/drivers/gpu/drm/i915/intel_ddi.c
>>> @@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
>>>    	enum port port = intel_ddi_get_encoder_port(intel_encoder);
>>>    	int type = intel_encoder->type;
>>>
>>> +	if (type == INTEL_OUTPUT_HDMI) {
>> how to handle type2 active adapters here, which can show type = DP ?
>
> The dual mode concept shouldn't apply to active adapters. Those, as you
> say, appear as DP and so will be handled as if they were native DP sinks
> more or less.
>
> Or are you aware of active DP dongles that also implement the dual mode
> standatd? Apart from LSPCON of course. Actually I'm not sure how LSPCON
> will handle this. If we drive it in PCON mode, would it still respect
> the dual mode register settings, including the TMDS OE# state?
>
I cross checked LSPCON specs, it respects TMDS_OE (0x80, 0x20) register 
only in LS mode (like stype 2 adapter), by putting it in low power 
state. So I guess you are right, we have to handle LSPCON separately, 
based on if it's in LS mode or PCON mode.  May be while re-basing LSPCON 
layer on top of this new series, I can think of this.

Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
>>> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
>>> +
>>> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
>>> +	}
>>> +
>>>    	intel_prepare_ddi_buffer(intel_encoder);
>>>
>>>    	if (type == INTEL_OUTPUT_EDP) {
>>> @@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
>>>    					DPLL_CTRL2_DDI_CLK_OFF(port)));
>>>    	else if (INTEL_INFO(dev)->gen < 9)
>>>    		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
>>> +
>>> +	if (type == INTEL_OUTPUT_HDMI) {
>> Same as above.
>>
>> Regards
>> Shashank
>>> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
>>> +
>>> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
>>> +	}
>>>    }
>>>
>>>    static void intel_enable_ddi(struct intel_encoder *intel_encoder)
>>> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
>>> index e94d18fb2ff1..dbcb80c70e2e 100644
>>> --- a/drivers/gpu/drm/i915/intel_drv.h
>>> +++ b/drivers/gpu/drm/i915/intel_drv.h
>>> @@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
>>>    struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
>>>    bool intel_hdmi_compute_config(struct intel_encoder *encoder,
>>>    			       struct intel_crtc_state *pipe_config);
>>> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
>>>
>>>
>>>    /* intel_lvds.c */
>>> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
>>> index 31ca11134294..c4d93e6b4bed 100644
>>> --- a/drivers/gpu/drm/i915/intel_hdmi.c
>>> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
>>> @@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
>>>    	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
>>>    }
>>>
>>> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
>>> +{
>>> +	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
>>> +	struct i2c_adapter *adapter =
>>> +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>>> +
>>> +	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
>>> +		return;
>>> +
>>> +	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
>>> +		      enable ? "Enabling" : "Disabling");
>>> +
>>> +	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
>>> +					 adapter, enable);
>>> +}
>>> +
>>>    static void intel_hdmi_prepare(struct intel_encoder *encoder)
>>>    {
>>>    	struct drm_device *dev = encoder->base.dev;
>>> @@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
>>>    	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
>>>    	u32 hdmi_val;
>>>
>>> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
>>> +
>>>    	hdmi_val = SDVO_ENCODING_HDMI;
>>>    	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
>>>    		hdmi_val |= HDMI_COLOR_RANGE_16_235;
>>> @@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
>>>    	}
>>>
>>>    	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
>>> +
>>> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
>>>    }
>>>
>>>    static void g4x_disable_hdmi(struct intel_encoder *encoder)
>>>
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
@ 2016-05-04 13:48         ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 13:48 UTC (permalink / raw)
  To: Ville Syrjälä
  Cc: dri-devel, intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter



On 5/4/2016 5:19 PM, Ville Syrjälä wrote:
> On Wed, May 04, 2016 at 03:43:30PM +0530, Sharma, Shashank wrote:
>>
>> On 5/3/2016 12:38 AM, ville.syrjala@linux.intel.com wrote:
>>> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>>
>>> To save a bit of power, let's try to turn off the TMDS output buffers
>>> in DP++ adaptors when we're not driving the port.
>>>
>>> v2: Let's not forget DDI, toss in a debug message while at it
>>> v3: Just do the TMDS output control based on adaptor type. With the
>>>       helper getting passed the type, we wouldn't actually have to
>>>       check at all in the driver, but the check eliminates the debug
>>>       output more honest
>>>
>>> Cc: stable@vger.kernel.org
>>> Cc: Tore Anderson <tore@fud.no>
>>> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
>>> Cc: Shashank Sharma <shashank.sharma@intel.com>
>>> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
>>> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
>>> ---
>>>    drivers/gpu/drm/i915/intel_ddi.c  | 12 ++++++++++++
>>>    drivers/gpu/drm/i915/intel_drv.h  |  1 +
>>>    drivers/gpu/drm/i915/intel_hdmi.c | 20 ++++++++++++++++++++
>>>    3 files changed, 33 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/i915/intel_ddi.c b/drivers/gpu/drm/i915/intel_ddi.c
>>> index 422ec81ef59b..a3600704e6d4 100644
>>> --- a/drivers/gpu/drm/i915/intel_ddi.c
>>> +++ b/drivers/gpu/drm/i915/intel_ddi.c
>>> @@ -1601,6 +1601,12 @@ static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
>>>    	enum port port = intel_ddi_get_encoder_port(intel_encoder);
>>>    	int type = intel_encoder->type;
>>>
>>> +	if (type == INTEL_OUTPUT_HDMI) {
>> how to handle type2 active adapters here, which can show type = DP ?
>
> The dual mode concept shouldn't apply to active adapters. Those, as you
> say, appear as DP and so will be handled as if they were native DP sinks
> more or less.
>
> Or are you aware of active DP dongles that also implement the dual mode
> standatd? Apart from LSPCON of course. Actually I'm not sure how LSPCON
> will handle this. If we drive it in PCON mode, would it still respect
> the dual mode register settings, including the TMDS OE# state?
>
I cross checked LSPCON specs, it respects TMDS_OE (0x80, 0x20) register 
only in LS mode (like stype 2 adapter), by putting it in low power 
state. So I guess you are right, we have to handle LSPCON separately, 
based on if it's in LS mode or PCON mode.  May be while re-basing LSPCON 
layer on top of this new series, I can think of this.

Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
>>> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
>>> +
>>> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
>>> +	}
>>> +
>>>    	intel_prepare_ddi_buffer(intel_encoder);
>>>
>>>    	if (type == INTEL_OUTPUT_EDP) {
>>> @@ -1667,6 +1673,12 @@ static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
>>>    					DPLL_CTRL2_DDI_CLK_OFF(port)));
>>>    	else if (INTEL_INFO(dev)->gen < 9)
>>>    		I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
>>> +
>>> +	if (type == INTEL_OUTPUT_HDMI) {
>> Same as above.
>>
>> Regards
>> Shashank
>>> +		struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
>>> +
>>> +		intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
>>> +	}
>>>    }
>>>
>>>    static void intel_enable_ddi(struct intel_encoder *intel_encoder)
>>> diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
>>> index e94d18fb2ff1..dbcb80c70e2e 100644
>>> --- a/drivers/gpu/drm/i915/intel_drv.h
>>> +++ b/drivers/gpu/drm/i915/intel_drv.h
>>> @@ -1419,6 +1419,7 @@ void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
>>>    struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
>>>    bool intel_hdmi_compute_config(struct intel_encoder *encoder,
>>>    			       struct intel_crtc_state *pipe_config);
>>> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable);
>>>
>>>
>>>    /* intel_lvds.c */
>>> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
>>> index 31ca11134294..c4d93e6b4bed 100644
>>> --- a/drivers/gpu/drm/i915/intel_hdmi.c
>>> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
>>> @@ -836,6 +836,22 @@ static void hsw_set_infoframes(struct drm_encoder *encoder,
>>>    	intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
>>>    }
>>>
>>> +void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
>>> +{
>>> +	struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
>>> +	struct i2c_adapter *adapter =
>>> +		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>>> +
>>> +	if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
>>> +		return;
>>> +
>>> +	DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
>>> +		      enable ? "Enabling" : "Disabling");
>>> +
>>> +	drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
>>> +					 adapter, enable);
>>> +}
>>> +
>>>    static void intel_hdmi_prepare(struct intel_encoder *encoder)
>>>    {
>>>    	struct drm_device *dev = encoder->base.dev;
>>> @@ -845,6 +861,8 @@ static void intel_hdmi_prepare(struct intel_encoder *encoder)
>>>    	const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
>>>    	u32 hdmi_val;
>>>
>>> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
>>> +
>>>    	hdmi_val = SDVO_ENCODING_HDMI;
>>>    	if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
>>>    		hdmi_val |= HDMI_COLOR_RANGE_16_235;
>>> @@ -1142,6 +1160,8 @@ static void intel_disable_hdmi(struct intel_encoder *encoder)
>>>    	}
>>>
>>>    	intel_hdmi->set_infoframes(&encoder->base, false, NULL);
>>> +
>>> +	intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
>>>    }
>>>
>>>    static void g4x_disable_hdmi(struct intel_encoder *encoder)
>>>
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
  2016-05-04 11:45   ` [PATCH v3 " ville.syrjala
@ 2016-05-04 13:50       ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 13:50 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Daniel Vetter

Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
On 5/4/2016 5:15 PM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> DP dual mode type 1 DVI adaptors aren't required to implement any
> registers, so it's a bit hard to detect them. The best way would
> be to check the state of the CONFIG1 pin, but we have no way to
> do that. So as a last resort, check the VBT to see if the HDMI
> port is in fact a dual mode capable DP port.
>
> v2: Deal with VBT code reorganization
>      Deal with DRM_DP_DUAL_MODE_UNKNOWN
>      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
>      Accept both DP and HDMI dvo_port in VBT as my BSW
>      at least declare its DP port as HDMI :(
> v3: Ignore DEVICE_TYPE_NOT_HDMI_OUTPUT (Shashanl)
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Reported-by: Tore Anderson <tore@fud.no>
> Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/i915_drv.h       |  1 +
>   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
>   drivers/gpu/drm/i915/intel_vbt_defs.h | 12 ++++++++++++
>   4 files changed, 75 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index ff6aaf0c4e1e..abe43922a08f 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
>   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
>   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
>   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
>   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
>   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
>   				     enum port port);
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 81518116e00d..8b68c4882fba 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
>   	return false;
>   }
>
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> +{
> +	static const struct {
> +		u16 dp, hdmi;
> +	} port_mapping[] = {
> +		/*
> +		 * Buggy VBTs may declare DP ports as having
> +		 * HDMI type dvo_port :( So let's check both.
> +		 */
> +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> +	};
> +	int i;
> +
> +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> +		return false;
> +
> +	if (!dev_priv->vbt.child_dev_num)
> +		return false;
> +
> +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> +		const union child_device_config *p_child =
> +			&dev_priv->vbt.child_dev[i];
> +
> +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   /**
>    * intel_bios_is_dsi_present - is DSI present in VBT
>    * @dev_priv:	i915 device instance
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index c4d93e6b4bed..6b52c6accf6a 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
>   }
>
>   static void
> -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
>   {
>   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
>   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> +	enum port port = hdmi_to_dig_port(hdmi)->port;
>   	struct i2c_adapter *adapter =
>   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
>
> -	if (type == DRM_DP_DUAL_MODE_NONE ||
> -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> +	/*
> +	 * Type 1 DVI adaptors are not required to implement any
> +	 * registers, so we can't always detect their presence.
> +	 * Ideally we should be able to check the state of the
> +	 * CONFIG1 pin, but no such luck on our hardware.
> +	 *
> +	 * The only method left to us is to check the VBT to see
> +	 * if the port is a dual mode capable DP port. But let's
> +	 * only do that when we sucesfully read the EDID, to avoid
> +	 * confusing log messages about DP dual mode adaptors when
> +	 * there's nothing connected to the port.
> +	 */
> +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> +		if (has_edid &&
> +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> +		} else {
> +			type = DRM_DP_DUAL_MODE_NONE;
> +		}
> +	}
> +
> +	if (type == DRM_DP_DUAL_MODE_NONE)
>   		return;
>
>   	hdmi->dp_dual_mode.type = type;
> @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   				    intel_gmbus_get_adapter(dev_priv,
>   				    intel_hdmi->ddc_bus));
>
> -		intel_hdmi_dp_dual_mode_detect(connector);
> +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
>
>   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>   	}
> diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> index a4a42f254c35..4f9799f025a9 100644
> --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> @@ -746,6 +746,7 @@ struct bdb_psr {
>   #define	 DEVICE_TYPE_INT_TV	0x1009
>   #define	 DEVICE_TYPE_HDMI	0x60D2
>   #define	 DEVICE_TYPE_DP		0x68C6
> +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
>   #define	 DEVICE_TYPE_eDP	0x78C6
>
>   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> @@ -780,6 +781,17 @@ struct bdb_psr {
>   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
>   	 DEVICE_TYPE_ANALOG_OUTPUT)
>
> +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> +	 DEVICE_TYPE_MIPI_OUTPUT | \
> +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> +	 DEVICE_TYPE_LVDS_SINGALING | \
> +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> +	 DEVICE_TYPE_ANALOG_OUTPUT)
> +
>   /* define the DVO port for HDMI output type */
>   #define		DVO_B		1
>   #define		DVO_C		2
>

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v3 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT
@ 2016-05-04 13:50       ` Sharma, Shashank
  0 siblings, 0 replies; 36+ messages in thread
From: Sharma, Shashank @ 2016-05-04 13:50 UTC (permalink / raw)
  To: ville.syrjala, dri-devel
  Cc: Daniel Vetter, intel-gfx, Tore Anderson, Paulo Zanoni, stable

Reviewed-by: Shashank Sharma <shashank.sharma@intel.com>

Regards
Shashank
On 5/4/2016 5:15 PM, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> DP dual mode type 1 DVI adaptors aren't required to implement any
> registers, so it's a bit hard to detect them. The best way would
> be to check the state of the CONFIG1 pin, but we have no way to
> do that. So as a last resort, check the VBT to see if the HDMI
> port is in fact a dual mode capable DP port.
>
> v2: Deal with VBT code reorganization
>      Deal with DRM_DP_DUAL_MODE_UNKNOWN
>      Reduce DEVICE_TYPE_DP_DUAL_MODE_BITS a bit
>      Accept both DP and HDMI dvo_port in VBT as my BSW
>      at least declare its DP port as HDMI :(
> v3: Ignore DEVICE_TYPE_NOT_HDMI_OUTPUT (Shashanl)
>
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Reported-by: Tore Anderson <tore@fud.no>
> Fixes: 7a0baa623446 ("Revert "drm/i915: Disable 12bpc hdmi for now"")
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>   drivers/gpu/drm/i915/i915_drv.h       |  1 +
>   drivers/gpu/drm/i915/intel_bios.c     | 36 +++++++++++++++++++++++++++++++++++
>   drivers/gpu/drm/i915/intel_hdmi.c     | 30 +++++++++++++++++++++++++----
>   drivers/gpu/drm/i915/intel_vbt_defs.h | 12 ++++++++++++
>   4 files changed, 75 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index ff6aaf0c4e1e..abe43922a08f 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -3489,6 +3489,7 @@ bool intel_bios_is_valid_vbt(const void *buf, size_t size);
>   bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv);
>   bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin);
>   bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port);
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port);
>   bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv, enum port *port);
>   bool intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
>   				     enum port port);
> diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c
> index 81518116e00d..8b68c4882fba 100644
> --- a/drivers/gpu/drm/i915/intel_bios.c
> +++ b/drivers/gpu/drm/i915/intel_bios.c
> @@ -1597,6 +1597,42 @@ bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
>   	return false;
>   }
>
> +bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv, enum port port)
> +{
> +	static const struct {
> +		u16 dp, hdmi;
> +	} port_mapping[] = {
> +		/*
> +		 * Buggy VBTs may declare DP ports as having
> +		 * HDMI type dvo_port :( So let's check both.
> +		 */
> +		[PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
> +		[PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
> +		[PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
> +		[PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
> +	};
> +	int i;
> +
> +	if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
> +		return false;
> +
> +	if (!dev_priv->vbt.child_dev_num)
> +		return false;
> +
> +	for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
> +		const union child_device_config *p_child =
> +			&dev_priv->vbt.child_dev[i];
> +
> +		if ((p_child->common.dvo_port == port_mapping[port].dp ||
> +		     p_child->common.dvo_port == port_mapping[port].hdmi) &&
> +		    (p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) ==
> +		    (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
> +			return true;
> +	}
> +
> +	return false;
> +}
> +
>   /**
>    * intel_bios_is_dsi_present - is DSI present in VBT
>    * @dev_priv:	i915 device instance
> diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c
> index c4d93e6b4bed..6b52c6accf6a 100644
> --- a/drivers/gpu/drm/i915/intel_hdmi.c
> +++ b/drivers/gpu/drm/i915/intel_hdmi.c
> @@ -1396,16 +1396,38 @@ intel_hdmi_unset_edid(struct drm_connector *connector)
>   }
>
>   static void
> -intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector)
> +intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
>   {
>   	struct drm_i915_private *dev_priv = to_i915(connector->dev);
>   	struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
> +	enum port port = hdmi_to_dig_port(hdmi)->port;
>   	struct i2c_adapter *adapter =
>   		intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
>   	enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
>
> -	if (type == DRM_DP_DUAL_MODE_NONE ||
> -	    type == DRM_DP_DUAL_MODE_UNKNOWN)
> +	/*
> +	 * Type 1 DVI adaptors are not required to implement any
> +	 * registers, so we can't always detect their presence.
> +	 * Ideally we should be able to check the state of the
> +	 * CONFIG1 pin, but no such luck on our hardware.
> +	 *
> +	 * The only method left to us is to check the VBT to see
> +	 * if the port is a dual mode capable DP port. But let's
> +	 * only do that when we sucesfully read the EDID, to avoid
> +	 * confusing log messages about DP dual mode adaptors when
> +	 * there's nothing connected to the port.
> +	 */
> +	if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
> +		if (has_edid &&
> +		    intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
> +			DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
> +			type = DRM_DP_DUAL_MODE_TYPE1_DVI;
> +		} else {
> +			type = DRM_DP_DUAL_MODE_NONE;
> +		}
> +	}
> +
> +	if (type == DRM_DP_DUAL_MODE_NONE)
>   		return;
>
>   	hdmi->dp_dual_mode.type = type;
> @@ -1432,7 +1454,7 @@ intel_hdmi_set_edid(struct drm_connector *connector, bool force)
>   				    intel_gmbus_get_adapter(dev_priv,
>   				    intel_hdmi->ddc_bus));
>
> -		intel_hdmi_dp_dual_mode_detect(connector);
> +		intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
>
>   		intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
>   	}
> diff --git a/drivers/gpu/drm/i915/intel_vbt_defs.h b/drivers/gpu/drm/i915/intel_vbt_defs.h
> index a4a42f254c35..4f9799f025a9 100644
> --- a/drivers/gpu/drm/i915/intel_vbt_defs.h
> +++ b/drivers/gpu/drm/i915/intel_vbt_defs.h
> @@ -746,6 +746,7 @@ struct bdb_psr {
>   #define	 DEVICE_TYPE_INT_TV	0x1009
>   #define	 DEVICE_TYPE_HDMI	0x60D2
>   #define	 DEVICE_TYPE_DP		0x68C6
> +#define	 DEVICE_TYPE_DP_DUAL_MODE	0x60D6
>   #define	 DEVICE_TYPE_eDP	0x78C6
>
>   #define  DEVICE_TYPE_CLASS_EXTENSION	(1 << 15)
> @@ -780,6 +781,17 @@ struct bdb_psr {
>   	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
>   	 DEVICE_TYPE_ANALOG_OUTPUT)
>
> +#define DEVICE_TYPE_DP_DUAL_MODE_BITS \
> +	(DEVICE_TYPE_INTERNAL_CONNECTOR | \
> +	 DEVICE_TYPE_MIPI_OUTPUT | \
> +	 DEVICE_TYPE_COMPOSITE_OUTPUT | \
> +	 DEVICE_TYPE_LVDS_SINGALING | \
> +	 DEVICE_TYPE_TMDS_DVI_SIGNALING | \
> +	 DEVICE_TYPE_VIDEO_SIGNALING | \
> +	 DEVICE_TYPE_DISPLAYPORT_OUTPUT | \
> +	 DEVICE_TYPE_DIGITAL_OUTPUT | \
> +	 DEVICE_TYPE_ANALOG_OUTPUT)
> +
>   /* define the DVO port for HDMI output type */
>   #define		DVO_B		1
>   #define		DVO_C		2
>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 1/4] drm: Add helper for DP++ adaptors
  2016-05-03 17:56       ` ville.syrjala
@ 2016-05-06 12:37         ` Zanoni, Paulo R
  -1 siblings, 0 replies; 36+ messages in thread
From: Zanoni, Paulo R @ 2016-05-06 12:37 UTC (permalink / raw)
  To: ville.syrjala, intel-gfx; +Cc: tore, Sharma, Shashank, stable, daniel.vetter

Em Ter, 2016-05-03 às 20:56 +0300, ville.syrjala@linux.intel.com
escreveu:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> 
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2
> adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1
> adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
> 
> Type 1 adaptors provide access to their internal registers and the
> sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement
> either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
> 
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
> 
> Other user controllable features that may be available in the
> adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this
> time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
> 
> v2: Pass adaptor type to helper functions to ease driver
> implementation
>     Fix a bunch of typoes (Paulo)
>     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet)
> know
>     the type (Paulo)
>     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>     ease future LSPCON enabling
>     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> v3: Fix kernel doc function argument descriptions (Jani)
>     s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
>     Add kernel doc for enum drm_dp_dual_mode_type
>     Actually build the docs
>     Fix more typoes
> v4: Adjust code indentation of type2 adaptor detection (Shashank)
>     Add debug messages for failurs cases (Shashank)
> 
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  Documentation/DocBook/gpu.tmpl            |   6 +
>  drivers/gpu/drm/Makefile                  |   2 +-
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 365
> ++++++++++++++++++++++++++++++
>  include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
>  4 files changed, 464 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> 
> diff --git a/Documentation/DocBook/gpu.tmpl
> b/Documentation/DocBook/gpu.tmpl
> index 1464fb2f3c46..c248124357df 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
>  !Edrivers/gpu/drm/drm_dp_helper.c
>      </sect2>
>      <sect2>
> +      <title>Display Port Dual Mode Adaptor Helper Functions
> Reference</title>
> +!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
> +!Iinclude/drm/drm_dp_dual_mode_helper.h
> +!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
> +    </sect2>
> +    <sect2>
>        <title>Display Port MST Helper Functions Reference</title>
>  !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
>  !Iinclude/drm/drm_dp_mst_helper.h
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>  
>  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o
> drm_probe_helper.o \
>  		drm_plane_helper.o drm_dp_mst_topology.o
> drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>  
>  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..6842178474ba
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,365 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person
> obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without
> limitation
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom
> the
> + * Software is furnished to do so, subject to the following
> conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
> EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: dp dual mode helpers
> + *
> + * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed
> via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C
> or
> + * I2C-over-AUX. Source devices may choose to implement either of
> these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor
> register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for return data
> + * @size: sizo of the buffer
> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
EXPORT_SYMBOL(drm_dp_dual_mode_read);

(or make it static and remove from the .h file)

> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor
> register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for write data
> + * @size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t
> size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char
> hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char
> dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct
> i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to
> implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be
> dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of
> detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method
> would
> +	 * simply require the driver to know whether the port is a
> DP++
> +	 * port or a native HDMI port. Both of these methods are
> entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and
> ack
> +	 * the offset but ignore it, and instead they just always
> return
> +	 * data from the start of the HDMI ID buffer. So for a
> broken
> +	 * type 1 HDMI adaptor a single byte read will always give
> us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately
> neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter,
> DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id,
> sizeof(adaptor_id));
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id)) {
> +			if (is_hdmi_adaptor(hdmi_id))
> +				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +			else
> +				return DRM_DP_DUAL_MODE_TYPE2_DVI;
> +		}
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode
> adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in
> drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in
> kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter,
> DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock,
> sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> {
> +		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
> +		return 165000;
> +	}
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS
> output buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to query state of TMDS output
> buffers\n");
> +		return ret;
> +	}
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output
> buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
> +			      enable ? "enable" : "disable");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode
> adaptor type as a string
> + * @type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum
> drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h
> b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..e8a9dfd0e055
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,92 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person
> obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without
> limitation
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom
> the
> + * Software is furnished to do so, subject to the following
> conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
> EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adaptors
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adaptors
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t
> size);
> +
> +/**
> + * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI
> adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
> + */
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct
> i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum
> drm_dp_dual_mode_type type);
> +
> +#endif

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-06 12:37         ` Zanoni, Paulo R
  0 siblings, 0 replies; 36+ messages in thread
From: Zanoni, Paulo R @ 2016-05-06 12:37 UTC (permalink / raw)
  To: ville.syrjala, intel-gfx; +Cc: daniel.vetter, tore, stable

Em Ter, 2016-05-03 às 20:56 +0300, ville.syrjala@linux.intel.com
escreveu:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Add a helper which aids in the identification of DP dual mode
> (aka. DP++) adaptors. There are several types of adaptors
> specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI
> 
> Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2
> adaptors
> may go as high as 300MHz and they provide a register informing the
> source device what the actual limit is. Supposedly also type 1
> adaptors
> may optionally implement this register. This TMDS clock limit is the
> main reason why we need to identify these adaptors.
> 
> Type 1 adaptors provide access to their internal registers and the
> sink
> DDC bus through I2C. Type 2 adaptors provide this access both via I2C
> and I2C-over-AUX. A type 2 source device may choose to implement
> either
> of these methods. If a source device implements the I2C-over-AUX
> method, then the driver will obviously need specific support for such
> adaptors since the port is driven like an HDMI port, but DDC
> communication happes over the AUX channel.
> 
> This helper should be enough to identify the adaptor type (some
> type 1 DVI adaptors may be a slight exception) and the maximum TMDS
> clock limit. Another feature that may be available is control over
> the TMDS output buffers on the adaptor, possibly allowing for some
> power saving when the TMDS link is down.
> 
> Other user controllable features that may be available in the
> adaptors
> are downstream i2c bus speed control when using i2c-over-aux, and
> some control over the CEC pin. I chose not to provide any helper
> functions for those since I have no use for them in i915 at this
> time.
> The rest of the registers in the adaptor are mostly just information,
> eg. IEEE OUI, hardware and firmware revision, etc.
> 
> v2: Pass adaptor type to helper functions to ease driver
> implementation
>     Fix a bunch of typoes (Paulo)
>     Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet)
> know
>     the type (Paulo)
>     Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
>     Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
>     ease future LSPCON enabling
>     Remove the unused DP_DUAL_MODE_LAST_RESERVED define
> v3: Fix kernel doc function argument descriptions (Jani)
>     s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
>     Add kernel doc for enum drm_dp_dual_mode_type
>     Actually build the docs
>     Fix more typoes
> v4: Adjust code indentation of type2 adaptor detection (Shashank)
>     Add debug messages for failurs cases (Shashank)
> 
> Cc: stable@vger.kernel.org
> Cc: Tore Anderson <tore@fud.no>
> Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
> Cc: Shashank Sharma <shashank.sharma@intel.com>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  Documentation/DocBook/gpu.tmpl            |   6 +
>  drivers/gpu/drm/Makefile                  |   2 +-
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 365
> ++++++++++++++++++++++++++++++
>  include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
>  4 files changed, 464 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> 
> diff --git a/Documentation/DocBook/gpu.tmpl
> b/Documentation/DocBook/gpu.tmpl
> index 1464fb2f3c46..c248124357df 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
>  !Edrivers/gpu/drm/drm_dp_helper.c
>      </sect2>
>      <sect2>
> +      <title>Display Port Dual Mode Adaptor Helper Functions
> Reference</title>
> +!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
> +!Iinclude/drm/drm_dp_dual_mode_helper.h
> +!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
> +    </sect2>
> +    <sect2>
>        <title>Display Port MST Helper Functions Reference</title>
>  !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
>  !Iinclude/drm/drm_dp_mst_helper.h
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index 1a26b4eb1ce0..29f2ee9b9534 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
>  
>  drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o
> drm_probe_helper.o \
>  		drm_plane_helper.o drm_dp_mst_topology.o
> drm_atomic_helper.o \
> -		drm_kms_helper_common.o
> +		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
>  
>  drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
>  drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
> diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> new file mode 100644
> index 000000000000..6842178474ba
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
> @@ -0,0 +1,365 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person
> obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without
> limitation
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom
> the
> + * Software is furnished to do so, subject to the following
> conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
> EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/i2c.h>
> +#include <linux/slab.h>
> +#include <linux/string.h>
> +#include <drm/drm_dp_dual_mode_helper.h>
> +#include <drm/drmP.h>
> +
> +/**
> + * DOC: dp dual mode helpers
> + *
> + * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
> + *
> + * Type 1:
> + * Adaptor registers (if any) and the sink DDC bus may be accessed
> via I2C.
> + *
> + * Type 2:
> + * Adaptor registers and sink DDC bus can be accessed either via I2C
> or
> + * I2C-over-AUX. Source devices may choose to implement either of
> these
> + * access methods.
> + */
> +
> +#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
> +
> +/**
> + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor
> register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for return data
> + * @size: sizo of the buffer
> + *
> + * Reads @size bytes from the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size)
> +{
> +	struct i2c_msg msgs[] = {
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = 0,
> +			.len = 1,
> +			.buf = &offset,
> +		},
> +		{
> +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +			.flags = I2C_M_RD,
> +			.len = size,
> +			.buf = buffer,
> +		},
> +	};
> +	int ret;
> +
> +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> +	if (ret < 0)
> +		return ret;
> +	if (ret != ARRAY_SIZE(msgs))
> +		return -EPROTO;
> +
> +	return 0;
> +}
EXPORT_SYMBOL(drm_dp_dual_mode_read);

(or make it static and remove from the .h file)

> +
> +/**
> + * drm_dp_dual_mode_write - Write to the DP dual mode adaptor
> register(s)
> + * @adapter: I2C adapter for the DDC bus
> + * @offset: register offset
> + * @buffer: buffer for write data
> + * @size: sizo of the buffer
> + *
> + * Writes @size bytes to the DP dual mode adaptor registers
> + * starting at @offset.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t
> size)
> +{
> +	struct i2c_msg msg = {
> +		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> +		.flags = 0,
> +		.len = 1 + size,
> +		.buf = NULL,
> +	};
> +	void *data;
> +	int ret;
> +
> +	data = kmalloc(msg.len, GFP_TEMPORARY);
> +	if (!data)
> +		return -ENOMEM;
> +
> +	msg.buf = data;
> +
> +	memcpy(data, &offset, 1);
> +	memcpy(data + 1, buffer, size);
> +
> +	ret = i2c_transfer(adapter, &msg, 1);
> +
> +	kfree(data);
> +
> +	if (ret < 0)
> +		return ret;
> +	if (ret != 1)
> +		return -EPROTO;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_write);
> +
> +static bool is_hdmi_adaptor(const char
> hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
> +{
> +	static const char
> dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
> +		"DP-HDMI ADAPTOR\x04";
> +
> +	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
> +		      sizeof(dp_dual_mode_hdmi_id)) == 0;
> +}
> +
> +static bool is_type2_adaptor(uint8_t adaptor_id)
> +{
> +	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
> +			      DP_DUAL_MODE_REV_TYPE2);
> +}
> +
> +/**
> + * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Attempt to identify the type of the DP dual mode adaptor used.
> + *
> + * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
> + * certain whether we're dealing with a native HDMI port or
> + * a type 1 DVI dual mode adaptor. The driver will have to use
> + * some other hardware/driver specific mechanism to make that
> + * distinction.
> + *
> + * Returns:
> + * The type of the DP dual mode adaptor used
> + */
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct
> i2c_adapter *adapter)
> +{
> +	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
> +	uint8_t adaptor_id = 0x00;
> +	ssize_t ret;
> +
> +	/*
> +	 * Let's see if the adaptor is there the by reading the
> +	 * HDMI ID registers.
> +	 *
> +	 * Note that type 1 DVI adaptors are not required to
> implemnt
> +	 * any registers, and that presents a problem for detection.
> +	 * If the i2c transfer is nacked, we may or may not be
> dealing
> +	 * with a type 1 DVI adaptor. Some other mechanism of
> detecting
> +	 * the presence of the adaptor is required. One way would be
> +	 * to check the state of the CONFIG1 pin, Another method
> would
> +	 * simply require the driver to know whether the port is a
> DP++
> +	 * port or a native HDMI port. Both of these methods are
> entirely
> +	 * hardware/driver specific so we can't deal with them here.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
> +				    hdmi_id, sizeof(hdmi_id));
> +	if (ret)
> +		return DRM_DP_DUAL_MODE_UNKNOWN;
> +
> +	/*
> +	 * Sigh. Some (maybe all?) type 1 adaptors are broken and
> ack
> +	 * the offset but ignore it, and instead they just always
> return
> +	 * data from the start of the HDMI ID buffer. So for a
> broken
> +	 * type 1 HDMI adaptor a single byte read will always give
> us
> +	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
> +	 * (assuming it implements any registers). Fortunately
> neither
> +	 * of those values will match the type 2 signature of the
> +	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
> +	 * the type 2 adaptor detection safely even in the presence
> +	 * of broken type 1 adaptors.
> +	 */
> +	ret = drm_dp_dual_mode_read(adapter,
> DP_DUAL_MODE_ADAPTOR_ID,
> +				    &adaptor_id,
> sizeof(adaptor_id));
> +	if (ret == 0) {
> +		if (is_type2_adaptor(adaptor_id)) {
> +			if (is_hdmi_adaptor(hdmi_id))
> +				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
> +			else
> +				return DRM_DP_DUAL_MODE_TYPE2_DVI;
> +		}
> +	}
> +
> +	if (is_hdmi_adaptor(hdmi_id))
> +		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
> +	else
> +		return DRM_DP_DUAL_MODE_TYPE1_DVI;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_detect);
> +
> +/**
> + * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode
> adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + *
> + * Determine the max TMDS clock the adaptor supports based on the
> + * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
> + * register (on type2 adaptors). As some type 1 adaptors have
> + * problems with registers (see comments in
> drm_dp_dual_mode_detect())
> + * we don't read the register on those, instead we simply assume
> + * a 165 MHz limit based on the specification.
> + *
> + * Returns:
> + * Maximum supported TMDS clock rate for the DP dual mode adaptor in
> kHz.
> + */
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter)
> +{
> +	uint8_t max_tmds_clock;
> +	ssize_t ret;
> +
> +	/* native HDMI so no limit */
> +	if (type == DRM_DP_DUAL_MODE_NONE)
> +		return 0;
> +
> +	/*
> +	 * Type 1 adaptors are limited to 165MHz
> +	 * Type 2 adaptors can tells us their limit
> +	 */
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 165000;
> +
> +	ret = drm_dp_dual_mode_read(adapter,
> DP_DUAL_MODE_MAX_TMDS_CLOCK,
> +				    &max_tmds_clock,
> sizeof(max_tmds_clock));
> +	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff)
> {
> +		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
> +		return 165000;
> +	}
> +
> +	return max_tmds_clock * 5000 / 2;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
> +
> +/**
> + * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS
> output buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enabled: current state of the TMDS output buffers
> + *
> + * Get the state of the TMDS output buffers in the adaptor. For
> + * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
> + * register. As some type 1 adaptors have problems with registers
> + * (see comments in drm_dp_dual_mode_detect()) we don't read the
> + * register on those, instead we simply assume that the buffers
> + * are always enabled.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> +				     bool *enabled)
> +{
> +	uint8_t tmds_oen;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
> +		*enabled = true;
> +		return 0;
> +	}
> +
> +	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				    &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to query state of TMDS output
> buffers\n");
> +		return ret;
> +	}
> +
> +	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
> +
> +/**
> + * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output
> buffers in the DP dual mode adaptor
> + * @type: DP dual mode adaptor type
> + * @adapter: I2C adapter for the DDC bus
> + * @enable: enable (as opposed to disable) the TMDS output buffers
> + *
> + * Set the state of the TMDS output buffers in the adaptor. For
> + * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
> + * some type 1 adaptors have problems with registers (see comments
> + * in drm_dp_dual_mode_detect()) we avoid touching the register,
> + * making this function a no-op on type 1 adaptors.
> + *
> + * Returns:
> + * 0 on success, negative error code on failure
> + */
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool enable)
> +{
> +	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
> +	ssize_t ret;
> +
> +	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
> +		return 0;
> +
> +	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
> +				     &tmds_oen, sizeof(tmds_oen));
> +	if (ret) {
> +		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
> +			      enable ? "enable" : "disable");
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
> +
> +/**
> + * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode
> adaptor type as a string
> + * @type: DP dual mode adaptor type
> + *
> + * Returns:
> + * String representation of the DP dual mode adaptor type
> + */
> +const char *drm_dp_get_dual_mode_type_name(enum
> drm_dp_dual_mode_type type)
> +{
> +	switch (type) {
> +	case DRM_DP_DUAL_MODE_NONE:
> +		return "none";
> +	case DRM_DP_DUAL_MODE_TYPE1_DVI:
> +		return "type 1 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
> +		return "type 1 HDMI";
> +	case DRM_DP_DUAL_MODE_TYPE2_DVI:
> +		return "type 2 DVI";
> +	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
> +		return "type 2 HDMI";
> +	default:
> +		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
> +		return "unknown";
> +	}
> +}
> +EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
> diff --git a/include/drm/drm_dp_dual_mode_helper.h
> b/include/drm/drm_dp_dual_mode_helper.h
> new file mode 100644
> index 000000000000..e8a9dfd0e055
> --- /dev/null
> +++ b/include/drm/drm_dp_dual_mode_helper.h
> @@ -0,0 +1,92 @@
> +/*
> + * Copyright © 2016 Intel Corporation
> + *
> + * Permission is hereby granted, free of charge, to any person
> obtaining a
> + * copy of this software and associated documentation files (the
> "Software"),
> + * to deal in the Software without restriction, including without
> limitation
> + * the rights to use, copy, modify, merge, publish, distribute,
> sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom
> the
> + * Software is furnished to do so, subject to the following
> conditions:
> + *
> + * The above copyright notice and this permission notice shall be
> included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO
> EVENT SHALL
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> DAMAGES OR
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> OTHERWISE,
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
> USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef DRM_DP_DUAL_MODE_HELPER_H
> +#define DRM_DP_DUAL_MODE_HELPER_H
> +
> +#include <linux/types.h>
> +
> +/*
> + * Optional for type 1 DVI adaptors
> + * Mandatory for type 1 HDMI and type 2 adaptors
> + */
> +#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
> +#define  DP_DUAL_MODE_HDMI_ID_LEN 16
> +/*
> + * Optional for type 1 adaptors
> + * Mandatory for type 2 adaptors
> + */
> +#define DP_DUAL_MODE_ADAPTOR_ID 0x10
> +#define  DP_DUAL_MODE_REV_MASK 0x07
> +#define  DP_DUAL_MODE_REV_TYPE2 0x00
> +#define  DP_DUAL_MODE_TYPE_MASK 0xf0
> +#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
> +#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
> +#define  DP_DUAL_IEEE_OUI_LEN 3
> +#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
> +#define  DP_DUAL_DEVICE_ID_LEN 6
> +#define DP_DUAL_MODE_HARDWARE_REV 0x1a
> +#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
> +#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
> +#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
> +#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
> +#define DP_DUAL_MODE_TMDS_OEN 0x20
> +#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
> +#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
> +#define  DP_DUAL_MODE_CEC_ENABLE 0x01
> +#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
> +
> +struct i2c_adapter;
> +
> +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> +			      u8 offset, void *buffer, size_t size);
> +ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
> +			       u8 offset, const void *buffer, size_t
> size);
> +
> +/**
> + * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
> + * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI
> adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
> + * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
> + */
> +enum drm_dp_dual_mode_type {
> +	DRM_DP_DUAL_MODE_NONE,
> +	DRM_DP_DUAL_MODE_UNKNOWN,
> +	DRM_DP_DUAL_MODE_TYPE1_DVI,
> +	DRM_DP_DUAL_MODE_TYPE1_HDMI,
> +	DRM_DP_DUAL_MODE_TYPE2_DVI,
> +	DRM_DP_DUAL_MODE_TYPE2_HDMI,
> +};
> +
> +enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct
> i2c_adapter *adapter);
> +int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
> +				    struct i2c_adapter *adapter);
> +int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool *enabled);
> +int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type
> type,
> +				     struct i2c_adapter *adapter,
> bool enable);
> +const char *drm_dp_get_dual_mode_type_name(enum
> drm_dp_dual_mode_type type);
> +
> +#endif
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 1/4] drm: Add helper for DP++ adaptors
  2016-05-06 12:37         ` Zanoni, Paulo R
@ 2016-05-06 13:10           ` Ville Syrjälä
  -1 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-06 13:10 UTC (permalink / raw)
  To: Zanoni, Paulo R; +Cc: intel-gfx, tore, Sharma, Shashank, stable, daniel.vetter

On Fri, May 06, 2016 at 12:37:51PM +0000, Zanoni, Paulo R wrote:
> Em Ter, 2016-05-03 �s 20:56 +0300, ville.syrjala@linux.intel.com
> escreveu:
<snip>
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor
> > register(s)
> > + * @adapter: I2C adapter for the DDC bus
> > + * @offset: register offset
> > + * @buffer: buffer for return data
> > + * @size: sizo of the buffer
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			������u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> EXPORT_SYMBOL(drm_dp_dual_mode_read);
> 
> (or make it static and remove from the .h file)

Hmm. My initial idea was that someone might want to use these for debug
and/or accessing some vendor specific register and whatnot. Which is why
I meant to export them (and somehow failed in this case). I guess I
still stand by that reasoning, although right now we have no users
outside this file.

-- 
Ville Syrj�l�
Intel OTC

^ permalink raw reply	[flat|nested] 36+ messages in thread

* Re: [PATCH v4 1/4] drm: Add helper for DP++ adaptors
@ 2016-05-06 13:10           ` Ville Syrjälä
  0 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-06 13:10 UTC (permalink / raw)
  To: Zanoni, Paulo R; +Cc: daniel.vetter, intel-gfx, tore, stable

On Fri, May 06, 2016 at 12:37:51PM +0000, Zanoni, Paulo R wrote:
> Em Ter, 2016-05-03 às 20:56 +0300, ville.syrjala@linux.intel.com
> escreveu:
<snip>
> > +
> > +/**
> > + * drm_dp_dual_mode_read - Read from the DP dual mode adaptor
> > register(s)
> > + * @adapter: I2C adapter for the DDC bus
> > + * @offset: register offset
> > + * @buffer: buffer for return data
> > + * @size: sizo of the buffer
> > + *
> > + * Reads @size bytes from the DP dual mode adaptor registers
> > + * starting at @offset.
> > + *
> > + * Returns:
> > + * 0 on success, negative error code on failure
> > + */
> > +ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
> > +			      u8 offset, void *buffer, size_t size)
> > +{
> > +	struct i2c_msg msgs[] = {
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = 0,
> > +			.len = 1,
> > +			.buf = &offset,
> > +		},
> > +		{
> > +			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
> > +			.flags = I2C_M_RD,
> > +			.len = size,
> > +			.buf = buffer,
> > +		},
> > +	};
> > +	int ret;
> > +
> > +	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
> > +	if (ret < 0)
> > +		return ret;
> > +	if (ret != ARRAY_SIZE(msgs))
> > +		return -EPROTO;
> > +
> > +	return 0;
> > +}
> EXPORT_SYMBOL(drm_dp_dual_mode_read);
> 
> (or make it static and remove from the .h file)

Hmm. My initial idea was that someone might want to use these for debug
and/or accessing some vendor specific register and whatnot. Which is why
I meant to export them (and somehow failed in this case). I guess I
still stand by that reasoning, although right now we have no users
outside this file.

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [PATCH v5 1/4] drm: Add helper for DP++ adaptors
  2016-05-03 17:56       ` ville.syrjala
                         ` (2 preceding siblings ...)
  (?)
@ 2016-05-06 13:46       ` ville.syrjala
  -1 siblings, 0 replies; 36+ messages in thread
From: ville.syrjala @ 2016-05-06 13:46 UTC (permalink / raw)
  To: dri-devel
  Cc: intel-gfx, stable, Tore Anderson, Paulo Zanoni, Shashank Sharma,
	Daniel Vetter

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Add a helper which aids in the identification of DP dual mode
(aka. DP++) adaptors. There are several types of adaptors
specified: type 1 DVI, type 1 HDMI, type 2 DVI, type 2 HDMI

Type 1 adaptors have a max TMDS clock limit of 165MHz, type 2 adaptors
may go as high as 300MHz and they provide a register informing the
source device what the actual limit is. Supposedly also type 1 adaptors
may optionally implement this register. This TMDS clock limit is the
main reason why we need to identify these adaptors.

Type 1 adaptors provide access to their internal registers and the sink
DDC bus through I2C. Type 2 adaptors provide this access both via I2C
and I2C-over-AUX. A type 2 source device may choose to implement either
of these methods. If a source device implements the I2C-over-AUX
method, then the driver will obviously need specific support for such
adaptors since the port is driven like an HDMI port, but DDC
communication happes over the AUX channel.

This helper should be enough to identify the adaptor type (some
type 1 DVI adaptors may be a slight exception) and the maximum TMDS
clock limit. Another feature that may be available is control over
the TMDS output buffers on the adaptor, possibly allowing for some
power saving when the TMDS link is down.

Other user controllable features that may be available in the adaptors
are downstream i2c bus speed control when using i2c-over-aux, and
some control over the CEC pin. I chose not to provide any helper
functions for those since I have no use for them in i915 at this time.
The rest of the registers in the adaptor are mostly just information,
eg. IEEE OUI, hardware and firmware revision, etc.

v2: Pass adaptor type to helper functions to ease driver implementation
    Fix a bunch of typoes (Paulo)
    Add DRM_DP_DUAL_MODE_UNKNOWN for the case where we don't (yet) know
    the type (Paulo)
    Reject 0x00 and 0xff DP_DUAL_MODE_MAX_TMDS_CLOCK values (Paulo)
    Adjust drm_dp_dual_mode_detect() type2 vs. type1 detection to
    ease future LSPCON enabling
    Remove the unused DP_DUAL_MODE_LAST_RESERVED define
v3: Fix kernel doc function argument descriptions (Jani)
    s/NONE/UNKNOWN/ in drm_dp_dual_mode_detect() docs
    Add kernel doc for enum drm_dp_dual_mode_type
    Actually build the docs
    Fix more typoes
v4: Adjust code indentation of type2 adaptor detection (Shashank)
    Add debug messages for failurs cases (Shashank)
v5: EXPORT_SYMBOL(drm_dp_dual_mode_read) (Paulo)

Cc: stable@vger.kernel.org
Cc: Tore Anderson <tore@fud.no>
Cc: Paulo Zanoni <paulo.r.zanoni@intel.com>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Shashank Sharma <shashank.sharma@intel.com> (v4)
---
 Documentation/DocBook/gpu.tmpl            |   6 +
 drivers/gpu/drm/Makefile                  |   2 +-
 drivers/gpu/drm/drm_dp_dual_mode_helper.c | 366 ++++++++++++++++++++++++++++++
 include/drm/drm_dp_dual_mode_helper.h     |  92 ++++++++
 4 files changed, 465 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
 create mode 100644 include/drm/drm_dp_dual_mode_helper.h

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index 1464fb2f3c46..c248124357df 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1623,6 +1623,12 @@ void intel_crt_init(struct drm_device *dev)
 !Edrivers/gpu/drm/drm_dp_helper.c
     </sect2>
     <sect2>
+      <title>Display Port Dual Mode Adaptor Helper Functions Reference</title>
+!Pdrivers/gpu/drm/drm_dp_dual_mode_helper.c dp dual mode helpers
+!Iinclude/drm/drm_dp_dual_mode_helper.h
+!Edrivers/gpu/drm/drm_dp_dual_mode_helper.c
+    </sect2>
+    <sect2>
       <title>Display Port MST Helper Functions Reference</title>
 !Pdrivers/gpu/drm/drm_dp_mst_topology.c dp mst helper
 !Iinclude/drm/drm_dp_mst_helper.h
diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
index 1a26b4eb1ce0..29f2ee9b9534 100644
--- a/drivers/gpu/drm/Makefile
+++ b/drivers/gpu/drm/Makefile
@@ -23,7 +23,7 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o
 
 drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \
 		drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \
-		drm_kms_helper_common.o
+		drm_kms_helper_common.o drm_dp_dual_mode_helper.o
 
 drm_kms_helper-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
diff --git a/drivers/gpu/drm/drm_dp_dual_mode_helper.c b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
new file mode 100644
index 000000000000..a7b2a751f6fe
--- /dev/null
+++ b/drivers/gpu/drm/drm_dp_dual_mode_helper.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <drm/drm_dp_dual_mode_helper.h>
+#include <drm/drmP.h>
+
+/**
+ * DOC: dp dual mode helpers
+ *
+ * Helper functions to deal with DP dual mode (aka. DP++) adaptors.
+ *
+ * Type 1:
+ * Adaptor registers (if any) and the sink DDC bus may be accessed via I2C.
+ *
+ * Type 2:
+ * Adaptor registers and sink DDC bus can be accessed either via I2C or
+ * I2C-over-AUX. Source devices may choose to implement either of these
+ * access methods.
+ */
+
+#define DP_DUAL_MODE_SLAVE_ADDRESS 0x40
+
+/**
+ * drm_dp_dual_mode_read - Read from the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for return data
+ * @size: sizo of the buffer
+ *
+ * Reads @size bytes from the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size)
+{
+	struct i2c_msg msgs[] = {
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = 0,
+			.len = 1,
+			.buf = &offset,
+		},
+		{
+			.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+			.flags = I2C_M_RD,
+			.len = size,
+			.buf = buffer,
+		},
+	};
+	int ret;
+
+	ret = i2c_transfer(adapter, msgs, ARRAY_SIZE(msgs));
+	if (ret < 0)
+		return ret;
+	if (ret != ARRAY_SIZE(msgs))
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_read);
+
+/**
+ * drm_dp_dual_mode_write - Write to the DP dual mode adaptor register(s)
+ * @adapter: I2C adapter for the DDC bus
+ * @offset: register offset
+ * @buffer: buffer for write data
+ * @size: sizo of the buffer
+ *
+ * Writes @size bytes to the DP dual mode adaptor registers
+ * starting at @offset.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size)
+{
+	struct i2c_msg msg = {
+		.addr = DP_DUAL_MODE_SLAVE_ADDRESS,
+		.flags = 0,
+		.len = 1 + size,
+		.buf = NULL,
+	};
+	void *data;
+	int ret;
+
+	data = kmalloc(msg.len, GFP_TEMPORARY);
+	if (!data)
+		return -ENOMEM;
+
+	msg.buf = data;
+
+	memcpy(data, &offset, 1);
+	memcpy(data + 1, buffer, size);
+
+	ret = i2c_transfer(adapter, &msg, 1);
+
+	kfree(data);
+
+	if (ret < 0)
+		return ret;
+	if (ret != 1)
+		return -EPROTO;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_write);
+
+static bool is_hdmi_adaptor(const char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN])
+{
+	static const char dp_dual_mode_hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] =
+		"DP-HDMI ADAPTOR\x04";
+
+	return memcmp(hdmi_id, dp_dual_mode_hdmi_id,
+		      sizeof(dp_dual_mode_hdmi_id)) == 0;
+}
+
+static bool is_type2_adaptor(uint8_t adaptor_id)
+{
+	return adaptor_id == (DP_DUAL_MODE_TYPE_TYPE2 |
+			      DP_DUAL_MODE_REV_TYPE2);
+}
+
+/**
+ * drm_dp_dual_mode_detect - Identify the DP dual mode adaptor
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Attempt to identify the type of the DP dual mode adaptor used.
+ *
+ * Note that when the answer is @DRM_DP_DUAL_MODE_UNKNOWN it's not
+ * certain whether we're dealing with a native HDMI port or
+ * a type 1 DVI dual mode adaptor. The driver will have to use
+ * some other hardware/driver specific mechanism to make that
+ * distinction.
+ *
+ * Returns:
+ * The type of the DP dual mode adaptor used
+ */
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter)
+{
+	char hdmi_id[DP_DUAL_MODE_HDMI_ID_LEN] = {};
+	uint8_t adaptor_id = 0x00;
+	ssize_t ret;
+
+	/*
+	 * Let's see if the adaptor is there the by reading the
+	 * HDMI ID registers.
+	 *
+	 * Note that type 1 DVI adaptors are not required to implemnt
+	 * any registers, and that presents a problem for detection.
+	 * If the i2c transfer is nacked, we may or may not be dealing
+	 * with a type 1 DVI adaptor. Some other mechanism of detecting
+	 * the presence of the adaptor is required. One way would be
+	 * to check the state of the CONFIG1 pin, Another method would
+	 * simply require the driver to know whether the port is a DP++
+	 * port or a native HDMI port. Both of these methods are entirely
+	 * hardware/driver specific so we can't deal with them here.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_HDMI_ID,
+				    hdmi_id, sizeof(hdmi_id));
+	if (ret)
+		return DRM_DP_DUAL_MODE_UNKNOWN;
+
+	/*
+	 * Sigh. Some (maybe all?) type 1 adaptors are broken and ack
+	 * the offset but ignore it, and instead they just always return
+	 * data from the start of the HDMI ID buffer. So for a broken
+	 * type 1 HDMI adaptor a single byte read will always give us
+	 * 0x44, and for a type 1 DVI adaptor it should give 0x00
+	 * (assuming it implements any registers). Fortunately neither
+	 * of those values will match the type 2 signature of the
+	 * DP_DUAL_MODE_ADAPTOR_ID register so we can proceed with
+	 * the type 2 adaptor detection safely even in the presence
+	 * of broken type 1 adaptors.
+	 */
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_ADAPTOR_ID,
+				    &adaptor_id, sizeof(adaptor_id));
+	if (ret == 0) {
+		if (is_type2_adaptor(adaptor_id)) {
+			if (is_hdmi_adaptor(hdmi_id))
+				return DRM_DP_DUAL_MODE_TYPE2_HDMI;
+			else
+				return DRM_DP_DUAL_MODE_TYPE2_DVI;
+		}
+	}
+
+	if (is_hdmi_adaptor(hdmi_id))
+		return DRM_DP_DUAL_MODE_TYPE1_HDMI;
+	else
+		return DRM_DP_DUAL_MODE_TYPE1_DVI;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_detect);
+
+/**
+ * drm_dp_dual_mode_max_tmds_clock - Max TMDS clock for DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ *
+ * Determine the max TMDS clock the adaptor supports based on the
+ * type of the dual mode adaptor and the DP_DUAL_MODE_MAX_TMDS_CLOCK
+ * register (on type2 adaptors). As some type 1 adaptors have
+ * problems with registers (see comments in drm_dp_dual_mode_detect())
+ * we don't read the register on those, instead we simply assume
+ * a 165 MHz limit based on the specification.
+ *
+ * Returns:
+ * Maximum supported TMDS clock rate for the DP dual mode adaptor in kHz.
+ */
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter)
+{
+	uint8_t max_tmds_clock;
+	ssize_t ret;
+
+	/* native HDMI so no limit */
+	if (type == DRM_DP_DUAL_MODE_NONE)
+		return 0;
+
+	/*
+	 * Type 1 adaptors are limited to 165MHz
+	 * Type 2 adaptors can tells us their limit
+	 */
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 165000;
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_MAX_TMDS_CLOCK,
+				    &max_tmds_clock, sizeof(max_tmds_clock));
+	if (ret || max_tmds_clock == 0x00 || max_tmds_clock == 0xff) {
+		DRM_DEBUG_KMS("Failed to query max TMDS clock\n");
+		return 165000;
+	}
+
+	return max_tmds_clock * 5000 / 2;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_max_tmds_clock);
+
+/**
+ * drm_dp_dual_mode_get_tmds_output - Get the state of the TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enabled: current state of the TMDS output buffers
+ *
+ * Get the state of the TMDS output buffers in the adaptor. For
+ * type2 adaptors this is queried from the DP_DUAL_MODE_TMDS_OEN
+ * register. As some type 1 adaptors have problems with registers
+ * (see comments in drm_dp_dual_mode_detect()) we don't read the
+ * register on those, instead we simply assume that the buffers
+ * are always enabled.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter,
+				     bool *enabled)
+{
+	uint8_t tmds_oen;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI) {
+		*enabled = true;
+		return 0;
+	}
+
+	ret = drm_dp_dual_mode_read(adapter, DP_DUAL_MODE_TMDS_OEN,
+				    &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to query state of TMDS output buffers\n");
+		return ret;
+	}
+
+	*enabled = !(tmds_oen & DP_DUAL_MODE_TMDS_DISABLE);
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_get_tmds_output);
+
+/**
+ * drm_dp_dual_mode_set_tmds_output - Enable/disable TMDS output buffers in the DP dual mode adaptor
+ * @type: DP dual mode adaptor type
+ * @adapter: I2C adapter for the DDC bus
+ * @enable: enable (as opposed to disable) the TMDS output buffers
+ *
+ * Set the state of the TMDS output buffers in the adaptor. For
+ * type2 this is set via the DP_DUAL_MODE_TMDS_OEN register. As
+ * some type 1 adaptors have problems with registers (see comments
+ * in drm_dp_dual_mode_detect()) we avoid touching the register,
+ * making this function a no-op on type 1 adaptors.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure
+ */
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable)
+{
+	uint8_t tmds_oen = enable ? 0 : DP_DUAL_MODE_TMDS_DISABLE;
+	ssize_t ret;
+
+	if (type < DRM_DP_DUAL_MODE_TYPE2_DVI)
+		return 0;
+
+	ret = drm_dp_dual_mode_write(adapter, DP_DUAL_MODE_TMDS_OEN,
+				     &tmds_oen, sizeof(tmds_oen));
+	if (ret) {
+		DRM_DEBUG_KMS("Failed to %s TMDS output buffers\n",
+			      enable ? "enable" : "disable");
+		return ret;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_dp_dual_mode_set_tmds_output);
+
+/**
+ * drm_dp_get_dual_mode_type_name - Get the name of the DP dual mode adaptor type as a string
+ * @type: DP dual mode adaptor type
+ *
+ * Returns:
+ * String representation of the DP dual mode adaptor type
+ */
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type)
+{
+	switch (type) {
+	case DRM_DP_DUAL_MODE_NONE:
+		return "none";
+	case DRM_DP_DUAL_MODE_TYPE1_DVI:
+		return "type 1 DVI";
+	case DRM_DP_DUAL_MODE_TYPE1_HDMI:
+		return "type 1 HDMI";
+	case DRM_DP_DUAL_MODE_TYPE2_DVI:
+		return "type 2 DVI";
+	case DRM_DP_DUAL_MODE_TYPE2_HDMI:
+		return "type 2 HDMI";
+	default:
+		WARN_ON(type != DRM_DP_DUAL_MODE_UNKNOWN);
+		return "unknown";
+	}
+}
+EXPORT_SYMBOL(drm_dp_get_dual_mode_type_name);
diff --git a/include/drm/drm_dp_dual_mode_helper.h b/include/drm/drm_dp_dual_mode_helper.h
new file mode 100644
index 000000000000..e8a9dfd0e055
--- /dev/null
+++ b/include/drm/drm_dp_dual_mode_helper.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef DRM_DP_DUAL_MODE_HELPER_H
+#define DRM_DP_DUAL_MODE_HELPER_H
+
+#include <linux/types.h>
+
+/*
+ * Optional for type 1 DVI adaptors
+ * Mandatory for type 1 HDMI and type 2 adaptors
+ */
+#define DP_DUAL_MODE_HDMI_ID 0x00 /* 00-0f */
+#define  DP_DUAL_MODE_HDMI_ID_LEN 16
+/*
+ * Optional for type 1 adaptors
+ * Mandatory for type 2 adaptors
+ */
+#define DP_DUAL_MODE_ADAPTOR_ID 0x10
+#define  DP_DUAL_MODE_REV_MASK 0x07
+#define  DP_DUAL_MODE_REV_TYPE2 0x00
+#define  DP_DUAL_MODE_TYPE_MASK 0xf0
+#define  DP_DUAL_MODE_TYPE_TYPE2 0xa0
+#define DP_DUAL_MODE_IEEE_OUI 0x11 /* 11-13*/
+#define  DP_DUAL_IEEE_OUI_LEN 3
+#define DP_DUAL_DEVICE_ID 0x14 /* 14-19 */
+#define  DP_DUAL_DEVICE_ID_LEN 6
+#define DP_DUAL_MODE_HARDWARE_REV 0x1a
+#define DP_DUAL_MODE_FIRMWARE_MAJOR_REV 0x1b
+#define DP_DUAL_MODE_FIRMWARE_MINOR_REV 0x1c
+#define DP_DUAL_MODE_MAX_TMDS_CLOCK 0x1d
+#define DP_DUAL_MODE_I2C_SPEED_CAP 0x1e
+#define DP_DUAL_MODE_TMDS_OEN 0x20
+#define  DP_DUAL_MODE_TMDS_DISABLE 0x01
+#define DP_DUAL_MODE_HDMI_PIN_CTRL 0x21
+#define  DP_DUAL_MODE_CEC_ENABLE 0x01
+#define DP_DUAL_MODE_I2C_SPEED_CTRL 0x22
+
+struct i2c_adapter;
+
+ssize_t drm_dp_dual_mode_read(struct i2c_adapter *adapter,
+			      u8 offset, void *buffer, size_t size);
+ssize_t drm_dp_dual_mode_write(struct i2c_adapter *adapter,
+			       u8 offset, const void *buffer, size_t size);
+
+/**
+ * enum drm_dp_dual_mode_type - Type of the DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_NONE: No DP dual mode adaptor
+ * @DRM_DP_DUAL_MODE_UNKNOWN: Could be either none or type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_DVI: Type 1 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE1_HDMI: Type 1 HDMI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_DVI: Type 2 DVI adaptor
+ * @DRM_DP_DUAL_MODE_TYPE2_HDMI: Type 2 HDMI adaptor
+ */
+enum drm_dp_dual_mode_type {
+	DRM_DP_DUAL_MODE_NONE,
+	DRM_DP_DUAL_MODE_UNKNOWN,
+	DRM_DP_DUAL_MODE_TYPE1_DVI,
+	DRM_DP_DUAL_MODE_TYPE1_HDMI,
+	DRM_DP_DUAL_MODE_TYPE2_DVI,
+	DRM_DP_DUAL_MODE_TYPE2_HDMI,
+};
+
+enum drm_dp_dual_mode_type drm_dp_dual_mode_detect(struct i2c_adapter *adapter);
+int drm_dp_dual_mode_max_tmds_clock(enum drm_dp_dual_mode_type type,
+				    struct i2c_adapter *adapter);
+int drm_dp_dual_mode_get_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool *enabled);
+int drm_dp_dual_mode_set_tmds_output(enum drm_dp_dual_mode_type type,
+				     struct i2c_adapter *adapter, bool enable);
+const char *drm_dp_get_dual_mode_type_name(enum drm_dp_dual_mode_type type);
+
+#endif
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 36+ messages in thread

* Re: [PATCH v2 0/4] drm: DP++ adaptor support (v2)
  2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
                   ` (3 preceding siblings ...)
  2016-05-02 19:08 ` [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT ville.syrjala
@ 2016-05-09 12:12 ` Ville Syrjälä
  4 siblings, 0 replies; 36+ messages in thread
From: Ville Syrjälä @ 2016-05-09 12:12 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

On Mon, May 02, 2016 at 10:08:21PM +0300, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> Here's a respin of my DP++ adaptor support series [1]. Pardon for taking
> forever with this. Presumably we want to get this into stable to fix the
> regression from HDMI 12bpc support.
> 
> I've tried to account for a bunch of Paulo's review comments
> 
> I also tried to make the helper a bit easier to use by having the caller
> pass the adaptor type to the helper functions, and so the need for most
> adaptor type checks in driver code is eliminated. I still left some
> checks in i915, but those are there just to do the type 1 DVI vs. none
> detectio, and to suppress the debug output when no adaptor is detected.
> 
> I also redid the detection logic a bit to ease future LSPCON enabling.
> 
> I had to rebase a bunch of stuff due to VBT shuffling. I also noticed
> that my BSW still wasn't detecting type 1 DVI adaptors, which I managed
> to "fix" by having the VBT check also accept HDMI type dvo_ports as DP++
> ports, which sucks a bit but should hopefully be robust enough.
> 
> I felt that things changed a bit too much in the end for me to hang
> on to the r-bs unfortunately, so I didn't actually pick them up. So
> if people aren't too fed up with this, I'd appreciate them having a
> a second look.
> 
> Series available here:
> git://github.com/vsyrjala/linux.git dp_dual_mode_3
> 
> [1] https://lists.freedesktop.org/archives/dri-devel/2016-February/101494.html
> 
> Ville Syrjälä (4):
>   drm: Add helper for DP++ adaptors
>   drm/i915: Respect DP++ adaptor TMDS clock limit
>   drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed
>   drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT

Got Dave's ack for merging the helper via drm-intel, so I pushed the
entire series to dinq. Thanks for the reviews everyone.

> 
>  drivers/gpu/drm/Makefile                  |   2 +-
>  drivers/gpu/drm/drm_dp_dual_mode_helper.c | 356 ++++++++++++++++++++++++++++++
>  drivers/gpu/drm/i915/i915_drv.h           |   1 +
>  drivers/gpu/drm/i915/intel_bios.c         |  36 +++
>  drivers/gpu/drm/i915/intel_ddi.c          |  12 +
>  drivers/gpu/drm/i915/intel_drv.h          |   6 +
>  drivers/gpu/drm/i915/intel_hdmi.c         | 100 ++++++++-
>  drivers/gpu/drm/i915/intel_vbt_defs.h     |  13 ++
>  include/drm/drm_dp_dual_mode_helper.h     |  83 +++++++
>  9 files changed, 600 insertions(+), 9 deletions(-)
>  create mode 100644 drivers/gpu/drm/drm_dp_dual_mode_helper.c
>  create mode 100644 include/drm/drm_dp_dual_mode_helper.h
> 
> -- 
> 2.7.4

-- 
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2016-05-09 12:12 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-02 19:08 [PATCH v2 0/4] drm: DP++ adaptor support (v2) ville.syrjala
2016-05-02 19:08 ` [PATCH v2 1/4] drm: Add helper for DP++ adaptors ville.syrjala
2016-05-03  7:46   ` [Intel-gfx] " Jani Nikula
2016-05-03  7:46     ` Jani Nikula
2016-05-03 13:38     ` Ville Syrjälä
2016-05-03 13:38       ` Ville Syrjälä
2016-05-03 14:55   ` [PATCH v3 " ville.syrjala
2016-05-03 17:56     ` [PATCH v4 " ville.syrjala
2016-05-03 17:56       ` ville.syrjala
2016-05-04  6:26       ` Sharma, Shashank
2016-05-06 12:37       ` Zanoni, Paulo R
2016-05-06 12:37         ` Zanoni, Paulo R
2016-05-06 13:10         ` Ville Syrjälä
2016-05-06 13:10           ` Ville Syrjälä
2016-05-06 13:46       ` [PATCH v5 " ville.syrjala
2016-05-03 16:33   ` [PATCH v2 " Sharma, Shashank
2016-05-03 16:33     ` Sharma, Shashank
2016-05-03 17:38     ` Ville Syrjälä
2016-05-03 17:38       ` Ville Syrjälä
2016-05-02 19:08 ` [PATCH v2 2/4] drm/i915: Respect DP++ adaptor TMDS clock limit ville.syrjala
2016-05-04 10:08   ` Sharma, Shashank
2016-05-02 19:08 ` [PATCH v3 3/4] drm/i915: Enable/disable TMDS output buffers in DP++ adaptor as needed ville.syrjala
2016-05-04 10:13   ` Sharma, Shashank
2016-05-04 11:49     ` Ville Syrjälä
2016-05-04 11:49       ` Ville Syrjälä
2016-05-04 13:48       ` Sharma, Shashank
2016-05-04 13:48         ` Sharma, Shashank
2016-05-02 19:08 ` [PATCH v2 4/4] drm/i915: Determine DP++ type 1 DVI adaptor presence based on VBT ville.syrjala
2016-05-04 10:24   ` Sharma, Shashank
2016-05-04 10:24     ` Sharma, Shashank
2016-05-04 11:29     ` Ville Syrjälä
2016-05-04 11:29       ` Ville Syrjälä
2016-05-04 11:45   ` [PATCH v3 " ville.syrjala
2016-05-04 13:50     ` Sharma, Shashank
2016-05-04 13:50       ` Sharma, Shashank
2016-05-09 12:12 ` [PATCH v2 0/4] drm: DP++ adaptor support (v2) Ville Syrjälä

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.