From patchwork Tue Aug 20 01:16:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 11102487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5DEAF14DE for ; Tue, 20 Aug 2019 01:18:29 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4764F2339E for ; Tue, 20 Aug 2019 01:18:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4764F2339E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B6BAB6E57A; Tue, 20 Aug 2019 01:18:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B2B36E56D for ; Tue, 20 Aug 2019 01:17:54 +0000 (UTC) Received: from pendragon.bb.dnainternet.fi (dfj612yhrgyx302h3jwwy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:ce28:277f:58d7:3ca4]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 63C24F85; Tue, 20 Aug 2019 03:17:48 +0200 (CEST) From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 24/50] drm/omap: hdmi: Allocate EDID in the .read_edid() operation Date: Tue, 20 Aug 2019 04:16:55 +0300 Message-Id: <20190820011721.30136-25-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190820011721.30136-1-laurent.pinchart@ideasonboard.com> References: <20190820011721.30136-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1566263868; bh=kAVHkju+JOdb5H8lOEzpikT0Rc2Aq1332/5bg+KklDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j4Jb0vwlMV6gixaPsVzXuIqfICtbXPsK3OLfbVD5jmd4WJtLaQw5ryM0S686NZayb DNrY5OytZVxKoAGlhJttx6cXNGqF2PnHMP9vlsGL6SHLwz3THHFVxZZNTtzr9zw8jn r7vfaQiRUzVf/h9t5N/yKLZyMwSnOl+O/L8DIHwY= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Ripard , Tomi Valkeinen , Sean Paul , Sebastian Reichel Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Bring the omapdss-specific .read_edid() operation in sync with the drm_bridge .get_edid() operation to ease code reuse. Signed-off-by: Laurent Pinchart Reviewed-by: Tomi Valkeinen --- Changes since v1: - Keep MAX_EDID macro --- drivers/gpu/drm/omapdrm/dss/hdmi4.c | 36 ++++++++++++++++-------- drivers/gpu/drm/omapdrm/dss/hdmi5.c | 24 ++++++++++++---- drivers/gpu/drm/omapdrm/dss/omapdss.h | 2 +- drivers/gpu/drm/omapdrm/omap_connector.c | 12 ++------ 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi4.c b/drivers/gpu/drm/omapdrm/dss/hdmi4.c index dd4a14fe7e59..e15fa3862922 100644 --- a/drivers/gpu/drm/omapdrm/dss/hdmi4.c +++ b/drivers/gpu/drm/omapdrm/dss/hdmi4.c @@ -405,31 +405,45 @@ static void hdmi_disconnect(struct omap_dss_device *src, omapdss_device_disconnect(dst, dst->next); } -static int hdmi_read_edid(struct omap_dss_device *dssdev, - u8 *edid, int len) +#define MAX_EDID 512 + +static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev) { struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); bool need_enable; + u8 *edid; int r; + edid = kzalloc(MAX_EDID, GFP_KERNEL); + if (!edid) + return NULL; + need_enable = hdmi->core_enabled == false; if (need_enable) { r = hdmi4_core_enable(&hdmi->core); - if (r) - return r; + if (r) { + kfree(edid); + return NULL; + } + } + + r = read_edid(hdmi, edid, MAX_EDID); + if (r < 0) { + kfree(edid); + edid = NULL; + } else { + unsigned int cec_addr; + + 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); } - r = read_edid(hdmi, edid, len); - if (r >= 256) - hdmi4_cec_set_phys_addr(&hdmi->core, - cec_get_edid_phys_addr(edid, r, NULL)); - else - hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID); if (need_enable) hdmi4_core_disable(&hdmi->core); - return r; + return (struct edid *)edid; } static void hdmi_lost_hotplug(struct omap_dss_device *dssdev) diff --git a/drivers/gpu/drm/omapdrm/dss/hdmi5.c b/drivers/gpu/drm/omapdrm/dss/hdmi5.c index 8e3790dd8b98..99720dfc5769 100644 --- a/drivers/gpu/drm/omapdrm/dss/hdmi5.c +++ b/drivers/gpu/drm/omapdrm/dss/hdmi5.c @@ -410,27 +410,39 @@ static void hdmi_disconnect(struct omap_dss_device *src, omapdss_device_disconnect(dst, dst->next); } -static int hdmi_read_edid(struct omap_dss_device *dssdev, - u8 *edid, int len) +#define MAX_EDID 512 + +static struct edid *hdmi_read_edid(struct omap_dss_device *dssdev) { struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev); bool need_enable; + u8 *edid; int r; + edid = kzalloc(MAX_EDID, GFP_KERNEL); + if (!edid) + return NULL; + need_enable = hdmi->core_enabled == false; if (need_enable) { r = hdmi_core_enable(hdmi); - if (r) - return r; + if (r) { + kfree(edid); + return NULL; + } } - r = read_edid(hdmi, edid, len); + r = read_edid(hdmi, edid, MAX_EDID); + if (r < 0) { + kfree(edid); + edid = NULL; + } if (need_enable) hdmi_core_disable(hdmi); - return r; + return (struct edid *)edid; } static int hdmi_set_infoframe(struct omap_dss_device *dssdev, diff --git a/drivers/gpu/drm/omapdrm/dss/omapdss.h b/drivers/gpu/drm/omapdrm/dss/omapdss.h index 82e9bfa5530a..269e143d57be 100644 --- a/drivers/gpu/drm/omapdrm/dss/omapdss.h +++ b/drivers/gpu/drm/omapdrm/dss/omapdss.h @@ -367,7 +367,7 @@ struct omap_dss_device_ops { void *cb_data); void (*unregister_hpd_cb)(struct omap_dss_device *dssdev); - int (*read_edid)(struct omap_dss_device *dssdev, u8 *buf, int len); + struct edid *(*read_edid)(struct omap_dss_device *dssdev); int (*get_modes)(struct omap_dss_device *dssdev, struct drm_connector *connector); diff --git a/drivers/gpu/drm/omapdrm/omap_connector.c b/drivers/gpu/drm/omapdrm/omap_connector.c index a24cec4b0bb9..c636ae228130 100644 --- a/drivers/gpu/drm/omapdrm/omap_connector.c +++ b/drivers/gpu/drm/omapdrm/omap_connector.c @@ -153,25 +153,19 @@ static void omap_connector_destroy(struct drm_connector *connector) kfree(omap_connector); } -#define MAX_EDID 512 - static int omap_connector_get_modes_edid(struct drm_connector *connector, struct omap_dss_device *dssdev) { enum drm_connector_status status; - void *edid; + struct edid *edid; int n; status = omap_connector_detect(connector, false); if (status != connector_status_connected) goto no_edid; - edid = kzalloc(MAX_EDID, GFP_KERNEL); - if (!edid) - goto no_edid; - - if (dssdev->ops->read_edid(dssdev, edid, MAX_EDID) <= 0 || - !drm_edid_is_valid(edid)) { + edid = dssdev->ops->read_edid(dssdev); + if (!edid || !drm_edid_is_valid(edid)) { kfree(edid); goto no_edid; }