From patchwork Fri Nov 24 15:14:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alvin_=C5=A0ipraga?= X-Patchwork-Id: 13467797 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 559F4C624B4 for ; Fri, 24 Nov 2023 15:24:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A9A6310E804; Fri, 24 Nov 2023 15:24:40 +0000 (UTC) X-Greylist: delayed 600 seconds by postgrey-1.36 at gabe; Fri, 24 Nov 2023 15:24:32 UTC Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [IPv6:2001:41d0:203:375::b6]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EE8110E803 for ; Fri, 24 Nov 2023 15:24:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=key1; t=1700838870; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jIEnx9CoIn2hRvEpRDmHvZNWG76Z/UfEmMl3bO7DffQ=; b=ns4rkLOPocy4Mn0v+u8Rcp2xu2ZFBxhXfYtK1b7SRNd23n9CoTcwPAuNHPZiMezFimpvB4 t4uX+3azkRlUJXTZvB5tHGrmmO+XnvxMerTvxzHeby3mLIKgotqYjjtiDdFgCyNiDz7cu5 CP5QQ7jkYzwfhLXZ2MJf6NeVXt7C+HG5bE/lpCKV/SNg6bzBwINZDT/rm8imsGA4ev+7bb gHvlWwyZxDgke7PYsX3nUcLxEpCgoa3zXs5w/ANydLm60Na9iO+gsRg0hLXnDKluxWoCDl wtfVDvDHzCMxdv0JiTO60URFNkbMZwvcUG1aIe4jWgrc66u+OuufZMoeMh2zjQ== From: =?utf-8?q?Alvin_=C5=A0ipraga?= Date: Fri, 24 Nov 2023 16:14:21 +0100 Subject: [PATCH v2 1/2] drm/bridge: adv7511: rearrange hotplug work code MIME-Version: 1.0 Message-Id: <20231124-adv7511-cec-edid-v2-1-f0e5eeafdfc2@bang-olufsen.dk> References: <20231124-adv7511-cec-edid-v2-0-f0e5eeafdfc2@bang-olufsen.dk> In-Reply-To: <20231124-adv7511-cec-edid-v2-0-f0e5eeafdfc2@bang-olufsen.dk> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Hans Verkuil X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?utf-8?q?Alvin_=C5=A0ipraga?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alvin Šipraga In preparation for calling EDID helpers from the hotplug work, move the hotplug work below the EDID helper section. No functional change. Signed-off-by: Alvin Šipraga --- drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 120 ++++++++++++++------------- 1 file changed, 62 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c index 8be235144f6d..5ffc5904bd59 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c @@ -406,64 +406,6 @@ static void adv7511_power_off(struct adv7511 *adv7511) * Interrupt and hotplug detection */ -static bool adv7511_hpd(struct adv7511 *adv7511) -{ - unsigned int irq0; - int ret; - - ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0); - if (ret < 0) - return false; - - if (irq0 & ADV7511_INT0_HPD) { - regmap_write(adv7511->regmap, ADV7511_REG_INT(0), - ADV7511_INT0_HPD); - return true; - } - - return false; -} - -static void adv7511_hpd_work(struct work_struct *work) -{ - struct adv7511 *adv7511 = container_of(work, struct adv7511, hpd_work); - enum drm_connector_status status; - unsigned int val; - int ret; - - ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val); - if (ret < 0) - status = connector_status_disconnected; - else if (val & ADV7511_STATUS_HPD) - status = connector_status_connected; - else - status = connector_status_disconnected; - - /* - * The bridge resets its registers on unplug. So when we get a plug - * event and we're already supposed to be powered, cycle the bridge to - * restore its state. - */ - if (status == connector_status_connected && - adv7511->connector.status == connector_status_disconnected && - adv7511->powered) { - regcache_mark_dirty(adv7511->regmap); - adv7511_power_on(adv7511); - } - - if (adv7511->connector.status != status) { - adv7511->connector.status = status; - - if (adv7511->connector.dev) { - if (status == connector_status_disconnected) - cec_phys_addr_invalidate(adv7511->cec_adap); - drm_kms_helper_hotplug_event(adv7511->connector.dev); - } else { - drm_bridge_hpd_notify(&adv7511->bridge, status); - } - } -} - static int adv7511_irq_process(struct adv7511 *adv7511, bool process_hpd) { unsigned int irq0, irq1; @@ -600,6 +542,68 @@ static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, return 0; } +/* ----------------------------------------------------------------------------- + * Hotplug handling + */ + +static bool adv7511_hpd(struct adv7511 *adv7511) +{ + unsigned int irq0; + int ret; + + ret = regmap_read(adv7511->regmap, ADV7511_REG_INT(0), &irq0); + if (ret < 0) + return false; + + if (irq0 & ADV7511_INT0_HPD) { + regmap_write(adv7511->regmap, ADV7511_REG_INT(0), + ADV7511_INT0_HPD); + return true; + } + + return false; +} + +static void adv7511_hpd_work(struct work_struct *work) +{ + struct adv7511 *adv7511 = container_of(work, struct adv7511, hpd_work); + enum drm_connector_status status; + unsigned int val; + int ret; + + ret = regmap_read(adv7511->regmap, ADV7511_REG_STATUS, &val); + if (ret < 0) + status = connector_status_disconnected; + else if (val & ADV7511_STATUS_HPD) + status = connector_status_connected; + else + status = connector_status_disconnected; + + /* + * The bridge resets its registers on unplug. So when we get a plug + * event and we're already supposed to be powered, cycle the bridge to + * restore its state. + */ + if (status == connector_status_connected && + adv7511->connector.status == connector_status_disconnected && + adv7511->powered) { + regcache_mark_dirty(adv7511->regmap); + adv7511_power_on(adv7511); + } + + if (adv7511->connector.status != status) { + adv7511->connector.status = status; + + if (adv7511->connector.dev) { + if (status == connector_status_disconnected) + cec_phys_addr_invalidate(adv7511->cec_adap); + drm_kms_helper_hotplug_event(adv7511->connector.dev); + } else { + drm_bridge_hpd_notify(&adv7511->bridge, status); + } + } +} + /* ----------------------------------------------------------------------------- * ADV75xx helpers */ From patchwork Fri Nov 24 15:14:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alvin_=C5=A0ipraga?= X-Patchwork-Id: 13467796 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 83512C61D97 for ; Fri, 24 Nov 2023 15:24:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B033010E803; Fri, 24 Nov 2023 15:24:34 +0000 (UTC) Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) by gabe.freedesktop.org (Postfix) with ESMTPS id 133E910E802 for ; Fri, 24 Nov 2023 15:24:32 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pqrs.dk; s=key1; t=1700838871; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mc7Wf0hW6FowFM4Mm7qR65l0E98I4NpTxHZ7srPzTOc=; b=wkVvMqHUqI8TxuJSHJUgA8mxyczMeeUC99Yz/tNb1r7Myj4sN7l2EK/Q0rfSuOFEf4t5sF vKjL5Rd/Hyds14IHXsQOjg2rNPtIjIUyZPhBJ9JwaDL255ckALplmxOGruk5AlgpkE7Sk1 UfDI3+bJ3d6UyWkGeP1v/MBptd2Y97+UhXIFLeQJ9FPbD37RvZ2e8YCC1pmhtvbvLpFhPj C3vdz1MF3pD9KCx+b+HoUNBtIyPuZNIoaH441+D55iMUYY+85ztWHwgsryXIaij6x0qW32 4CYpSy9dQQLXSQLFjML3kZqphN/AdJjOPToem+Vr38z5+GXi9cKAcWRizHTmDA== From: =?utf-8?q?Alvin_=C5=A0ipraga?= Date: Fri, 24 Nov 2023 16:14:22 +0100 Subject: [PATCH v2 2/2] drm/bridge: adv7511: get edid in hpd_work to update CEC phys address MIME-Version: 1.0 Message-Id: <20231124-adv7511-cec-edid-v2-2-f0e5eeafdfc2@bang-olufsen.dk> References: <20231124-adv7511-cec-edid-v2-0-f0e5eeafdfc2@bang-olufsen.dk> In-Reply-To: <20231124-adv7511-cec-edid-v2-0-f0e5eeafdfc2@bang-olufsen.dk> To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter , Hans Verkuil X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, =?utf-8?q?Alvin_=C5=A0ipraga?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alvin Šipraga The adv7511 driver is solely responsible for setting the physical address of its CEC adapter. To do this, it must read the EDID. However, EDID is only read when either the drm_bridge_funcs :: get_edid or drm_connector_helper_funcs :: get_modes ops are called. Without loss of generality, it cannot be assumed that these ops are called when a sink gets attached. Therefore there exist scenarios in which the CEC physical address will be invalid (f.f.f.f), rendering the CEC adapter inoperable. Address this problem by always fetching the EDID in the HPD work when we detect a connection. The CEC physical address is set in the process. This is done by moving the EDID DRM helper into an internal helper function so that it can be cleanly called from an earlier section of the code. The EDID getter has not changed in practice. Signed-off-by: Alvin Šipraga Reviewed-by: Robert Foss --- drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 74 ++++++++++++++++++---------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c index 5ffc5904bd59..1f1d3a440895 100644 --- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c +++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c @@ -542,6 +542,36 @@ static int adv7511_get_edid_block(void *data, u8 *buf, unsigned int block, return 0; } +static struct edid *__adv7511_get_edid(struct adv7511 *adv7511, + struct drm_connector *connector) +{ + struct edid *edid; + + /* Reading the EDID only works if the device is powered */ + if (!adv7511->powered) { + unsigned int edid_i2c_addr = + (adv7511->i2c_edid->addr << 1); + + __adv7511_power_on(adv7511); + + /* Reset the EDID_I2C_ADDR register as it might be cleared */ + regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, + edid_i2c_addr); + } + + edid = drm_do_get_edid(connector, adv7511_get_edid_block, adv7511); + + if (!adv7511->powered) + __adv7511_power_off(adv7511); + + adv7511_set_config_csc(adv7511, connector, adv7511->rgb, + drm_detect_hdmi_monitor(edid)); + + cec_s_phys_addr_from_edid(adv7511->cec_adap, edid); + + return edid; +} + /* ----------------------------------------------------------------------------- * Hotplug handling */ @@ -595,8 +625,24 @@ static void adv7511_hpd_work(struct work_struct *work) adv7511->connector.status = status; if (adv7511->connector.dev) { - if (status == connector_status_disconnected) + if (status == connector_status_disconnected) { cec_phys_addr_invalidate(adv7511->cec_adap); + } else { + struct edid *edid; + + /* + * Get the updated EDID so that the CEC + * subsystem gets informed of any change in CEC + * address. The helper returns a newly allocated + * edid structure, so free it to prevent + * leakage. + */ + edid = __adv7511_get_edid(adv7511, + &adv7511->connector); + if (edid) + kfree(edid); + } + drm_kms_helper_hotplug_event(adv7511->connector.dev); } else { drm_bridge_hpd_notify(&adv7511->bridge, status); @@ -611,31 +657,7 @@ static void adv7511_hpd_work(struct work_struct *work) static struct edid *adv7511_get_edid(struct adv7511 *adv7511, struct drm_connector *connector) { - struct edid *edid; - - /* Reading the EDID only works if the device is powered */ - if (!adv7511->powered) { - unsigned int edid_i2c_addr = - (adv7511->i2c_edid->addr << 1); - - __adv7511_power_on(adv7511); - - /* Reset the EDID_I2C_ADDR register as it might be cleared */ - regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, - edid_i2c_addr); - } - - edid = drm_do_get_edid(connector, adv7511_get_edid_block, adv7511); - - if (!adv7511->powered) - __adv7511_power_off(adv7511); - - adv7511_set_config_csc(adv7511, connector, adv7511->rgb, - drm_detect_hdmi_monitor(edid)); - - cec_s_phys_addr_from_edid(adv7511->cec_adap, edid); - - return edid; + return __adv7511_get_edid(adv7511, connector); } static int adv7511_get_modes(struct adv7511 *adv7511,