From patchwork Mon Jul 24 14:54:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowki X-Patchwork-Id: 9859649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5EE1560349 for ; Mon, 24 Jul 2017 14:55:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5090D283ED for ; Mon, 24 Jul 2017 14:55:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 457ED28419; Mon, 24 Jul 2017 14:55:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0F238283ED for ; Mon, 24 Jul 2017 14:55:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E0FFF6E2DD; Mon, 24 Jul 2017 14:55:07 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id CEB4D6E2CD; Mon, 24 Jul 2017 14:55:05 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jul 2017 07:55:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,407,1496127600"; d="scan'208";a="114849382" Received: from linux.intel.com ([10.54.29.200]) by orsmga002.jf.intel.com with ESMTP; 24 Jul 2017 07:55:01 -0700 Received: from workstation.fi.intel.com (workstation.fi.intel.com [10.237.68.144]) by linux.intel.com (Postfix) with ESMTP id 911DA580130; Mon, 24 Jul 2017 07:55:01 -0700 (PDT) From: Paul Kocialkowski To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org Date: Mon, 24 Jul 2017 17:54:46 +0300 Message-Id: <20170724145447.23449-1-paul.kocialkowski@linux.intel.com> X-Mailer: git-send-email 2.13.2 Cc: David Airlie , Daniel Vetter Subject: [Intel-gfx] [PATCH 1/2] drm/edid: Add helper to detect whether EDID changed X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This adds a common drm helper to detect whether the EDID changed from the last known cached one. This is useful help detect that a monitor was changed during a suspend/resume cycle. When that happens (a monitor is replaced by another one during suspend), no hotplug event will be triggered so the change will not be caught at resume time. Detecting that the EDID changed allows detecting it. Signed-off-by: Paul Kocialkowski Acked-by: Harry Wentland --- drivers/gpu/drm/drm_edid.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/drm/drm_edid.h | 3 +++ 2 files changed, 48 insertions(+) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 6bb6337be920..f6ce8bc2907a 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -5036,3 +5036,48 @@ static void drm_get_displayid(struct drm_connector *connector, } return; } + +/** + * drm_check_edid_changed - Check whether the EDID changed since the last update + * @connector: connector we're probing + * @adapter: I2C adapter to use for DDC + * + * Check whether the EDID changed since the last time it was updated in the + * drm blob cache. + * + * Return: A boolean indicating whether a change happened or not. + */ +bool drm_check_edid_changed(struct drm_connector *connector, + struct i2c_adapter *adapter) +{ + struct drm_property_blob *edid_blob; + struct edid *edid_stored; + struct edid *edid_read; + int ret = 0; + + if (!connector->edid_blob_ptr) + return false; + + edid_blob = drm_property_blob_get(connector->edid_blob_ptr); + if (!edid_blob) + return false; + + if (!edid_blob->data || edid_blob->length != sizeof(struct edid)) + goto out; + + edid_stored = (struct edid *) edid_blob->data; + + edid_read = drm_get_edid(connector, adapter); + if (!edid_read) + goto out; + + ret = memcmp(edid_stored, edid_read, sizeof(struct edid)); + + kfree(edid_read); + +out: + drm_property_blob_put(edid_blob); + + return ret != 0; +} +EXPORT_SYMBOL_GPL(drm_check_edid_changed); diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 1e1908a6b1d6..593a97b269c3 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -485,4 +485,7 @@ void drm_edid_get_monitor_name(struct edid *edid, char *name, struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, int hsize, int vsize, int fresh, bool rb); +bool drm_check_edid_changed(struct drm_connector *connector, + struct i2c_adapter *adapter); + #endif /* __DRM_EDID_H__ */