All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	Boris Brezillon <bbrezillon@kernel.org>
Subject: [PATCH v5 27/52] drm/omap: hdmi4: Rework EDID read to isolate data read
Date: Fri, 24 Jan 2020 05:54:20 +0200	[thread overview]
Message-ID: <20200124035445.1830-28-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200124035445.1830-1-laurent.pinchart@ideasonboard.com>

In preparation of adding DRM bridge support to the hdmi4 encoder code,
rework the EDID read to isolate data read.

The hdmi_read_edid() function is the main entry point. It performs all
initialisation steps required prior to reading the EDID (such as
ensuring the device is powered on), as well as corresponding cleanup
steps afterwards. EDID read itself is handled by hdmi_read_edid_data()
that calls the hdmi4_core_ddc_read() function to read individual blocks.

This new code architecture will allow reusing hdmi_read_edid() and
hdmi4_core_ddc_read() for the drm_bridge EDID read implementation, while
swapping out hdmi_read_edid_data() for the DRM drm_do_get_edid()
function.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
Changes since v2:

- Expand commit message
---
 drivers/gpu/drm/omapdrm/dss/hdmi4.c      | 94 +++++++++++++++---------
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.c | 59 +++------------
 drivers/gpu/drm/omapdrm/dss/hdmi4_core.h |  4 +-
 3 files changed, 73 insertions(+), 84 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
index e15fa3862922..37536b9f3114 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c
@@ -272,23 +272,6 @@ static int hdmi_dump_regs(struct seq_file *s, void *p)
 	return 0;
 }
 
-static int read_edid(struct omap_hdmi *hdmi, u8 *buf, int len)
-{
-	int r;
-
-	mutex_lock(&hdmi->lock);
-
-	r = hdmi_runtime_get(hdmi);
-	BUG_ON(r);
-
-	r = hdmi4_read_edid(&hdmi->core,  buf, len);
-
-	hdmi_runtime_put(hdmi);
-	mutex_unlock(&hdmi->lock);
-
-	return r;
-}
-
 static void hdmi_start_audio_stream(struct omap_hdmi *hd)
 {
 	hdmi_wp_audio_enable(&hd->wp, true);
@@ -407,10 +390,8 @@ static void hdmi_disconnect(struct omap_dss_device *src,
 
 #define MAX_EDID	512
 
-static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev)
+static struct edid *hdmi_read_edid_data(struct omap_hdmi *hdmi)
 {
-	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
-	bool need_enable;
 	u8 *edid;
 	int r;
 
@@ -418,32 +399,79 @@ static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev)
 	if (!edid)
 		return NULL;
 
+	r = hdmi4_core_ddc_read(&hdmi->core, edid, 0, EDID_LENGTH);
+	if (r)
+		goto error;
+
+	if (edid[0x7e] > 0) {
+		char checksum = 0;
+		unsigned int i;
+
+		r = hdmi4_core_ddc_read(&hdmi->core, edid + EDID_LENGTH, 1,
+					EDID_LENGTH);
+		if (r)
+			goto error;
+
+		for (i = 0; i < EDID_LENGTH; ++i)
+			checksum += edid[EDID_LENGTH + i];
+
+		if (checksum != 0) {
+			DSSERR("E-EDID checksum failed!!\n");
+			goto error;
+		}
+	}
+
+	return (struct edid *)edid;
+
+error:
+	kfree(edid);
+	return NULL;
+}
+
+static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev)
+{
+	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
+	struct edid *edid = NULL;
+	unsigned int cec_addr;
+	bool need_enable;
+	int r;
+
 	need_enable = hdmi->core_enabled == false;
 
 	if (need_enable) {
 		r = hdmi4_core_enable(&hdmi->core);
-		if (r) {
-			kfree(edid);
+		if (r)
 			return NULL;
-		}
 	}
 
-	r = read_edid(hdmi, edid, MAX_EDID);
-	if (r < 0) {
-		kfree(edid);
-		edid = NULL;
-	} else {
-		unsigned int cec_addr;
+	mutex_lock(&hdmi->lock);
+	r = hdmi_runtime_get(hdmi);
+	BUG_ON(r);
+
+	r = hdmi4_core_ddc_init(&hdmi->core);
+	if (r)
+		goto done;
 
-		cec_addr = r >= 256 ? cec_get_edid_phys_addr(edid, r, NULL)
-			 : CEC_PHYS_ADDR_INVALID;
-		hdmi4_cec_set_phys_addr(&hdmi->core, cec_addr);
+	edid = hdmi_read_edid_data(hdmi);
+
+done:
+	hdmi_runtime_put(hdmi);
+	mutex_unlock(&hdmi->lock);
+
+	if (edid && edid->extensions) {
+		unsigned int len = (edid->extensions + 1) * EDID_LENGTH;
+
+		cec_addr = cec_get_edid_phys_addr((u8 *)edid, len, NULL);
+	} else {
+		cec_addr = CEC_PHYS_ADDR_INVALID;
 	}
 
+	hdmi4_cec_set_phys_addr(&hdmi->core, cec_addr);
+
 	if (need_enable)
 		hdmi4_core_disable(&hdmi->core);
 
-	return (struct edid *)edid;
+	return edid;
 }
 
 static void hdmi_lost_hotplug(struct omap_dss_device *dssdev)
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
index ea5d5c228534..751985a2679a 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.c
@@ -32,7 +32,7 @@ static inline void __iomem *hdmi_av_base(struct hdmi_core_data *core)
 	return core->base + HDMI_CORE_AV;
 }
 
-static int hdmi_core_ddc_init(struct hdmi_core_data *core)
+int hdmi4_core_ddc_init(struct hdmi_core_data *core)
 {
 	void __iomem *base = core->base;
 
@@ -74,13 +74,11 @@ static int hdmi_core_ddc_init(struct hdmi_core_data *core)
 	return 0;
 }
 
-static int hdmi_core_ddc_edid(struct hdmi_core_data *core,
-		u8 *pedid, int ext)
+int hdmi4_core_ddc_read(void *data, u8 *buf, unsigned int block, size_t len)
 {
+	struct hdmi_core_data *core = data;
 	void __iomem *base = core->base;
 	u32 i;
-	char checksum;
-	u32 offset = 0;
 
 	/* HDMI_CORE_DDC_STATUS_IN_PROG */
 	if (hdmi_wait_for_bit_change(base, HDMI_CORE_DDC_STATUS,
@@ -89,24 +87,21 @@ static int hdmi_core_ddc_edid(struct hdmi_core_data *core,
 		return -ETIMEDOUT;
 	}
 
-	if (ext % 2 != 0)
-		offset = 0x80;
-
 	/* Load Segment Address Register */
-	REG_FLD_MOD(base, HDMI_CORE_DDC_SEGM, ext / 2, 7, 0);
+	REG_FLD_MOD(base, HDMI_CORE_DDC_SEGM, block / 2, 7, 0);
 
 	/* Load Slave Address Register */
 	REG_FLD_MOD(base, HDMI_CORE_DDC_ADDR, 0xA0 >> 1, 7, 1);
 
 	/* Load Offset Address Register */
-	REG_FLD_MOD(base, HDMI_CORE_DDC_OFFSET, offset, 7, 0);
+	REG_FLD_MOD(base, HDMI_CORE_DDC_OFFSET, block % 2 ? 0x80 : 0, 7, 0);
 
 	/* Load Byte Count */
-	REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT1, 0x80, 7, 0);
+	REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT1, len, 7, 0);
 	REG_FLD_MOD(base, HDMI_CORE_DDC_COUNT2, 0x0, 1, 0);
 
 	/* Set DDC_CMD */
-	if (ext)
+	if (block)
 		REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x4, 3, 0);
 	else
 		REG_FLD_MOD(base, HDMI_CORE_DDC_CMD, 0x2, 3, 0);
@@ -122,7 +117,7 @@ static int hdmi_core_ddc_edid(struct hdmi_core_data *core,
 		return -EIO;
 	}
 
-	for (i = 0; i < 0x80; ++i) {
+	for (i = 0; i < len; ++i) {
 		int t;
 
 		/* IN_PROG */
@@ -141,48 +136,12 @@ static int hdmi_core_ddc_edid(struct hdmi_core_data *core,
 			udelay(1);
 		}
 
-		pedid[i] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
-	}
-
-	checksum = 0;
-	for (i = 0; i < 0x80; ++i)
-		checksum += pedid[i];
-
-	if (checksum != 0) {
-		DSSERR("E-EDID checksum failed!!\n");
-		return -EIO;
+		buf[i] = REG_GET(base, HDMI_CORE_DDC_DATA, 7, 0);
 	}
 
 	return 0;
 }
 
-int hdmi4_read_edid(struct hdmi_core_data *core, u8 *edid, int len)
-{
-	int r, l;
-
-	if (len < 128)
-		return -EINVAL;
-
-	r = hdmi_core_ddc_init(core);
-	if (r)
-		return r;
-
-	r = hdmi_core_ddc_edid(core, edid, 0);
-	if (r)
-		return r;
-
-	l = 128;
-
-	if (len >= 128 * 2 && edid[0x7e] > 0) {
-		r = hdmi_core_ddc_edid(core, edid + 0x80, 1);
-		if (r)
-			return r;
-		l += 128;
-	}
-
-	return l;
-}
-
 static void hdmi_core_init(struct hdmi_core_video_config *video_cfg)
 {
 	DSSDBG("Enter hdmi_core_init\n");
diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
index 11c4b7ba1eee..dc64ae2aa300 100644
--- a/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
+++ b/drivers/gpu/drm/omapdrm/dss/hdmi4_core.h
@@ -249,7 +249,9 @@ struct hdmi_core_packet_enable_repeat {
 	u32	generic_pkt_repeat;
 };
 
-int hdmi4_read_edid(struct hdmi_core_data *core, u8 *edid, int len);
+int hdmi4_core_ddc_init(struct hdmi_core_data *core);
+int hdmi4_core_ddc_read(void *data, u8 *buf, unsigned int block, size_t len);
+
 void hdmi4_configure(struct hdmi_core_data *core, struct hdmi_wp_data *wp,
 		struct hdmi_config *cfg);
 void hdmi4_core_dump(struct hdmi_core_data *core, struct seq_file *s);
-- 
Regards,

Laurent Pinchart

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

  parent reply	other threads:[~2020-01-24  3:56 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-24  3:53 [PATCH v5 00/52] drm/omap: Replace custom display drivers with drm_bridge and drm_panel Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 01/52] video: hdmi: Change return type of hdmi_avi_infoframe_init() to void Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 02/52] drm/connector: Add helper to get a connector type name Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 03/52] drm/edid: Add flag to drm_display_info to identify HDMI sinks Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 04/52] drm/bridge: Add connector-related bridge operations and data Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 05/52] drm/bridge: Add interlace_allowed flag to drm_bridge Laurent Pinchart
2020-01-24  3:53 ` [PATCH v5 06/52] drm/bridge: Extend bridge API to disable connector creation Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 07/52] drm/bridge: dumb-vga-dac: Rename internal symbols to simple-bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 08/52] drm/bridge: dumb-vga-dac: Rename driver " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 09/52] drm/bridge: simple-bridge: Add support for non-VGA bridges Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 10/52] drm/bridge: simple-bridge: Add support for enable GPIO Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 11/52] drm/bridge: simple-bridge: Add support for the TI OPA362 Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 12/52] drm/bridge: Add bridge driver for display connectors Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 13/52] drm/bridge: Add driver for the TI TPD12S015 HDMI level shifter Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 14/52] drm/bridge: panel: Implement bridge connector operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 15/52] drm/bridge: tfp410: Replace manual connector handling with bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 16/52] drm/bridge: tfp410: Allow operation without drm_connector Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 17/52] drm: Add helper to create a connector for a chain of bridges Laurent Pinchart
2020-01-28 11:19   ` Tomi Valkeinen
2020-02-16 15:39     ` Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 18/52] drm/omap: Fix possible object reference leak Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 19/52] drm/omap: dss: Cleanup DSS ports on initialisation failure Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 20/52] drm/omap: Simplify HDMI mode and infoframe configuration Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 21/52] drm/omap: Factor out display type to connector type conversion Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 22/52] drm/omap: Use the drm_panel_bridge API Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 23/52] drm/omap: dss: Fix output next device lookup in DT Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 24/52] drm/omap: Add infrastructure to support drm_bridge local to DSS outputs Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 25/52] drm/omap: dss: Make omap_dss_device_ops optional Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 26/52] drm/omap: hdmi: Allocate EDID in the .read_edid() operation Laurent Pinchart
2020-01-24  3:54 ` Laurent Pinchart [this message]
2020-01-24  3:54 ` [PATCH v5 28/52] drm/omap: hdmi5: Rework EDID read to isolate data read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 29/52] drm/omap: hdmi4: Register a drm_bridge for EDID read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 30/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 31/52] drm/omap: hdmi4: Move mode set, enable and disable operations to bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 32/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 33/52] drm/omap: hdmi4: Implement drm_bridge .hpd_notify() operation Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 34/52] drm/omap: dss: Remove .set_hdmi_mode() and .set_infoframe() operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 35/52] drm/omap: venc: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 36/52] drm/omap: Create connector for bridges Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 37/52] drm/omap: Switch the HDMI and VENC outputs to drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 38/52] drm/omap: Remove HPD, detect and EDID omapdss operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 39/52] drm/omap: hdmi: Remove omap_dss_device operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 40/52] drm/omap: venc: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 41/52] drm/omap: hdmi4: Simplify EDID read Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 42/52] drm/omap: hdmi5: " Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 43/52] drm/omap: dpi: Sort includes alphabetically Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 44/52] drm/omap: dpi: Reorder functions in sections Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 45/52] drm/omap: dpi: Simplify clock setting API Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 46/52] drm/omap: dpi: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 47/52] drm/omap: sdi: Sort includes alphabetically Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 48/52] drm/omap: sdi: Register a drm_bridge Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 49/52] drm/omap: Hardcode omap_connector type to DSI Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 50/52] drm/omap: dss: Remove unused omap_dss_device operations Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 51/52] drm/omap: dss: Inline the omapdss_display_get() function Laurent Pinchart
2020-01-24  3:54 ` [PATCH v5 52/52] drm/omap: dss: Remove unused omapdss_of_find_connected_device() function Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200124035445.1830-28-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=bbrezillon@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sam@ravnborg.org \
    --cc=sebastian.reichel@collabora.com \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.