From patchwork Wed Jul 6 12:52:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12908096 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 F3689C433EF for ; Wed, 6 Jul 2022 12:53:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1E1BA11AEE5; Wed, 6 Jul 2022 12:53:06 +0000 (UTC) Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by gabe.freedesktop.org (Postfix) with ESMTPS id DC9E311AEF3 for ; Wed, 6 Jul 2022 12:53:04 +0000 (UTC) Received: by mail-pl1-x633.google.com with SMTP id c13so9825375pla.6 for ; Wed, 06 Jul 2022 05:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=dwMB+k9IGlD1nBJyNrEkLFj2csDbu5Qc4SyaeENoXs4=; b=VLocBcR67BH55CFePg7A7u3NRm1n4ardKuomKvCqMEuZ1qS29FEGTPbwhupBegRGGV pEFJtFTMkb/b2XpBQPLTY7Oe7jtGOopiYkTJgulNCbmKKEnHW5FeZDiPqZmAKO0i8WqZ Lm9yqq7WX9rKKbs4KFq6mTwidKV/MGZxvUBHk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=dwMB+k9IGlD1nBJyNrEkLFj2csDbu5Qc4SyaeENoXs4=; b=Nv1LidiELaKNgzGBUIGexqgJbWLIlK2NwOR7JoENG1rM/hNE5uW+3Xg4R0SqXB3Jmp VzGoeWqg2s5j1WAtAwOWzt6MbwOumWadQUUsBTmt4aH9+BgmYV/kxqSIvpQfXKddUV8R +SJcM1e2xbKUWLO4VnT+dNQZIMbxvjPTFRw2Ngy0P8xE5X+1Gr5FoycMMgCfb4h+jq20 JBINaxn2QT0DboEbrk2kr34+ZyrIsnaYvOcI18zhlpmbikK8jL8P0F13roXk2B6pZ2Dl /pC78RYp95+7OHUO+pkfpm8J9DfwFyMqDb9rD3i3e1f2tuz+1C+UdJZc8s4tCeIf/2V0 ktnA== X-Gm-Message-State: AJIora9ZswiyHQhgcCIC41hsRW57NGCRyKPW7XJfGlYavviDMy62cKQd Pa8NmZQ8itHmJvHxMqsG69rwlQ== X-Google-Smtp-Source: AGRyM1vRXlvrOK3qxEFCRY5ntUjBQ+I/TKLHMNestZ/71lmAhunY5e/klvvWxIOHDet94pd164yMmQ== X-Received: by 2002:a17:90a:178b:b0:1ef:7c85:8070 with SMTP id q11-20020a17090a178b00b001ef7c858070mr25348020pja.233.1657111984407; Wed, 06 Jul 2022 05:53:04 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5300:b974:1680:1bd]) by smtp.gmail.com with ESMTPSA id u12-20020a17090341cc00b0016a6cd546d6sm25640127ple.251.2022.07.06.05.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 05:53:04 -0700 (PDT) From: Hsin-Yi Wang To: Robert Foss , Xin Ji Subject: [PATCH v2 1/4] drm/bridge: anx7625: Convert to devm_i2c_new_dummy_device() Date: Wed, 6 Jul 2022 20:52:51 +0800 Message-Id: <20220706125254.2474095-2-hsinyi@chromium.org> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220706125254.2474095-1-hsinyi@chromium.org> References: <20220706125254.2474095-1-hsinyi@chromium.org> MIME-Version: 1.0 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: Jonas Karlman , David Airlie , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Neil Armstrong , linux-kernel@vger.kernel.org, Jernej Skrabec , Laurent Pinchart , Andrzej Hajda , Sam Ravnborg , Maxime Ripard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Simplify the resource management. Signed-off-by: Hsin-Yi Wang Reviewed-by: Xin Ji --- v1->v2: Fix indent. --- drivers/gpu/drm/bridge/analogix/anx7625.c | 96 +++++++---------------- 1 file changed, 27 insertions(+), 69 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index 3710fa9ee0acd..ab346d32d8735 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -2436,82 +2436,44 @@ static const struct drm_bridge_funcs anx7625_bridge_funcs = { static int anx7625_register_i2c_dummy_clients(struct anx7625_data *ctx, struct i2c_client *client) { - int err = 0; + struct device *dev = &ctx->client->dev; - ctx->i2c.tx_p0_client = i2c_new_dummy_device(client->adapter, - TX_P0_ADDR >> 1); + ctx->i2c.tx_p0_client = devm_i2c_new_dummy_device(dev, client->adapter, + TX_P0_ADDR >> 1); if (IS_ERR(ctx->i2c.tx_p0_client)) return PTR_ERR(ctx->i2c.tx_p0_client); - ctx->i2c.tx_p1_client = i2c_new_dummy_device(client->adapter, - TX_P1_ADDR >> 1); - if (IS_ERR(ctx->i2c.tx_p1_client)) { - err = PTR_ERR(ctx->i2c.tx_p1_client); - goto free_tx_p0; - } + ctx->i2c.tx_p1_client = devm_i2c_new_dummy_device(dev, client->adapter, + TX_P1_ADDR >> 1); + if (IS_ERR(ctx->i2c.tx_p1_client)) + return PTR_ERR(ctx->i2c.tx_p1_client); - ctx->i2c.tx_p2_client = i2c_new_dummy_device(client->adapter, - TX_P2_ADDR >> 1); - if (IS_ERR(ctx->i2c.tx_p2_client)) { - err = PTR_ERR(ctx->i2c.tx_p2_client); - goto free_tx_p1; - } + ctx->i2c.tx_p2_client = devm_i2c_new_dummy_device(dev, client->adapter, + TX_P2_ADDR >> 1); + if (IS_ERR(ctx->i2c.tx_p2_client)) + return PTR_ERR(ctx->i2c.tx_p2_client); - ctx->i2c.rx_p0_client = i2c_new_dummy_device(client->adapter, - RX_P0_ADDR >> 1); - if (IS_ERR(ctx->i2c.rx_p0_client)) { - err = PTR_ERR(ctx->i2c.rx_p0_client); - goto free_tx_p2; - } + ctx->i2c.rx_p0_client = devm_i2c_new_dummy_device(dev, client->adapter, + RX_P0_ADDR >> 1); + if (IS_ERR(ctx->i2c.rx_p0_client)) + return PTR_ERR(ctx->i2c.rx_p0_client); - ctx->i2c.rx_p1_client = i2c_new_dummy_device(client->adapter, - RX_P1_ADDR >> 1); - if (IS_ERR(ctx->i2c.rx_p1_client)) { - err = PTR_ERR(ctx->i2c.rx_p1_client); - goto free_rx_p0; - } + ctx->i2c.rx_p1_client = devm_i2c_new_dummy_device(dev, client->adapter, + RX_P1_ADDR >> 1); + if (IS_ERR(ctx->i2c.rx_p1_client)) + return PTR_ERR(ctx->i2c.rx_p1_client); - ctx->i2c.rx_p2_client = i2c_new_dummy_device(client->adapter, - RX_P2_ADDR >> 1); - if (IS_ERR(ctx->i2c.rx_p2_client)) { - err = PTR_ERR(ctx->i2c.rx_p2_client); - goto free_rx_p1; - } + ctx->i2c.rx_p2_client = devm_i2c_new_dummy_device(dev, client->adapter, + RX_P2_ADDR >> 1); + if (IS_ERR(ctx->i2c.rx_p2_client)) + return PTR_ERR(ctx->i2c.rx_p2_client); - ctx->i2c.tcpc_client = i2c_new_dummy_device(client->adapter, - TCPC_INTERFACE_ADDR >> 1); - if (IS_ERR(ctx->i2c.tcpc_client)) { - err = PTR_ERR(ctx->i2c.tcpc_client); - goto free_rx_p2; - } + ctx->i2c.tcpc_client = devm_i2c_new_dummy_device(dev, client->adapter, + TCPC_INTERFACE_ADDR >> 1); + if (IS_ERR(ctx->i2c.tcpc_client)) + return PTR_ERR(ctx->i2c.tcpc_client); return 0; - -free_rx_p2: - i2c_unregister_device(ctx->i2c.rx_p2_client); -free_rx_p1: - i2c_unregister_device(ctx->i2c.rx_p1_client); -free_rx_p0: - i2c_unregister_device(ctx->i2c.rx_p0_client); -free_tx_p2: - i2c_unregister_device(ctx->i2c.tx_p2_client); -free_tx_p1: - i2c_unregister_device(ctx->i2c.tx_p1_client); -free_tx_p0: - i2c_unregister_device(ctx->i2c.tx_p0_client); - - return err; -} - -static void anx7625_unregister_i2c_dummy_clients(struct anx7625_data *ctx) -{ - i2c_unregister_device(ctx->i2c.tx_p0_client); - i2c_unregister_device(ctx->i2c.tx_p1_client); - i2c_unregister_device(ctx->i2c.tx_p2_client); - i2c_unregister_device(ctx->i2c.rx_p0_client); - i2c_unregister_device(ctx->i2c.rx_p1_client); - i2c_unregister_device(ctx->i2c.rx_p2_client); - i2c_unregister_device(ctx->i2c.tcpc_client); } static int __maybe_unused anx7625_runtime_pm_suspend(struct device *dev) @@ -2723,8 +2685,6 @@ static int anx7625_i2c_probe(struct i2c_client *client, if (!platform->pdata.low_power_mode) pm_runtime_put_sync_suspend(&client->dev); - anx7625_unregister_i2c_dummy_clients(platform); - free_wq: if (platform->workqueue) destroy_workqueue(platform->workqueue); @@ -2754,8 +2714,6 @@ static int anx7625_i2c_remove(struct i2c_client *client) if (!platform->pdata.low_power_mode) pm_runtime_put_sync_suspend(&client->dev); - anx7625_unregister_i2c_dummy_clients(platform); - if (platform->pdata.audio_en) anx7625_unregister_audio(platform); From patchwork Wed Jul 6 12:52:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12908097 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 EA71BC433EF for ; Wed, 6 Jul 2022 12:53:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D9B011AEF8; Wed, 6 Jul 2022 12:53:08 +0000 (UTC) Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 723BF11AEEA for ; Wed, 6 Jul 2022 12:53:07 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id z12-20020a17090a7b8c00b001ef84000b8bso9932472pjc.1 for ; Wed, 06 Jul 2022 05:53:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=02sx8dmnjBV/TuA75YAbyzwEMk2jxyWLuGZcJUXA1mA=; b=X9gPzsTtEqyMRnO0Ze3pIsRss45disf2+3R39oFMVTCGIQYT5ISLaMeO4Gh8LRckRx OERTPNsDduJXlF7SJsWM6NOCPOLaRNPDFhuL1h/nJ9YD5qa9n21qbyoY8vZic5K1hDcl VxrOjj8xpT3Tn2zhuDO+XCcn7MNtsKGW5+rZg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=02sx8dmnjBV/TuA75YAbyzwEMk2jxyWLuGZcJUXA1mA=; b=vQJJ/pgo8fsj65GG6WUXadzKg5qQrhKZ+0dJjyi5eEWz4zOnYVDZuhikbKSfQlTr1O fTsXeEHSwcvRo+cffu+azq66iWrcgPHhQZZSEq4fAFiYvFm8eIP7fZ3KFNfLcL0kmdrc Ztrq1Q6+FnabO1vW5tUjsJBv1sKUd9/qnYElMQlWzCU2veINNTnYlnW2dBW5ZI82uTZU LOh7FA0L3UlYSfaqgsHxlqD1YlJKwR3mlr7aX8m0W+xjSV96R1q6x0rDYfLKe2uDBCPs xlpQ8E9BT1KuPWEgVnFqeYCXHUC02i86d6uJFyvHHYypo7V7kRVLpW5WiezB0jFCl2uy 8HBg== X-Gm-Message-State: AJIora/M9SRnbukM0LNQ3gaEQ+Rx0VWbzYKq6/ptChaaDyLdtH21gyf0 w5iLG+epsOEsr/5dq5gqO4uiJg== X-Google-Smtp-Source: AGRyM1tVtIQMvEuRrEN1V6YdOkUQGwBxQrSJYSlc5cAvGJXjazJWEXQKaWJoonujkv303bFau4bonQ== X-Received: by 2002:a17:90a:1a42:b0:1ef:680b:8ecd with SMTP id 2-20020a17090a1a4200b001ef680b8ecdmr30544374pjl.88.1657111986992; Wed, 06 Jul 2022 05:53:06 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5300:b974:1680:1bd]) by smtp.gmail.com with ESMTPSA id u12-20020a17090341cc00b0016a6cd546d6sm25640127ple.251.2022.07.06.05.53.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 05:53:06 -0700 (PDT) From: Hsin-Yi Wang To: Robert Foss , Xin Ji Subject: [PATCH v2 2/4] drm/bridge: anx7625: use pm_runtime_force_suspend(resume) Date: Wed, 6 Jul 2022 20:52:52 +0800 Message-Id: <20220706125254.2474095-3-hsinyi@chromium.org> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220706125254.2474095-1-hsinyi@chromium.org> References: <20220706125254.2474095-1-hsinyi@chromium.org> MIME-Version: 1.0 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: Jonas Karlman , David Airlie , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Neil Armstrong , linux-kernel@vger.kernel.org, Jernej Skrabec , Laurent Pinchart , Andrzej Hajda , Sam Ravnborg , Maxime Ripard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There's no need to check for IRQ or disable it in suspend. Use pm_runtime_force_suspend(resume) to make sure anx7625 is powered off correctly. Make the system suspend/resume and pm runtime suspend/resume more consistent. Signed-off-by: Hsin-Yi Wang Reviewed-by: Xin Ji --- v1->v2: Fix typo. --- drivers/gpu/drm/bridge/analogix/anx7625.c | 33 ++--------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index ab346d32d8735..fcf07a037c2c8 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -2504,38 +2504,9 @@ static int __maybe_unused anx7625_runtime_pm_resume(struct device *dev) return 0; } -static int __maybe_unused anx7625_resume(struct device *dev) -{ - struct anx7625_data *ctx = dev_get_drvdata(dev); - - if (!ctx->pdata.intp_irq) - return 0; - - if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { - enable_irq(ctx->pdata.intp_irq); - anx7625_runtime_pm_resume(dev); - } - - return 0; -} - -static int __maybe_unused anx7625_suspend(struct device *dev) -{ - struct anx7625_data *ctx = dev_get_drvdata(dev); - - if (!ctx->pdata.intp_irq) - return 0; - - if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { - anx7625_runtime_pm_suspend(dev); - disable_irq(ctx->pdata.intp_irq); - } - - return 0; -} - static const struct dev_pm_ops anx7625_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(anx7625_suspend, anx7625_resume) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) SET_RUNTIME_PM_OPS(anx7625_runtime_pm_suspend, anx7625_runtime_pm_resume, NULL) }; From patchwork Wed Jul 6 12:52:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12908098 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 E88C9CCA473 for ; Wed, 6 Jul 2022 12:53:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A7C8811AF03; Wed, 6 Jul 2022 12:53:10 +0000 (UTC) Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1698D11AF02 for ; Wed, 6 Jul 2022 12:53:10 +0000 (UTC) Received: by mail-pl1-x62a.google.com with SMTP id l12so8216954plk.13 for ; Wed, 06 Jul 2022 05:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jts1Y9JMpVL0If8P8yimWr5loe4E0VIqYItcqhdJT04=; b=J5h7sC+wpA1ej0AY7GGFDGcLzlBfbS2jtjQAtEj3EooYLMSkvj+E/iH7Ihp5W/wj/U 5av2KGOQdc8rZFtYkRx2Ww0Ty5D2u9A2G7dZfNfbS7wy/za51jTXhMuKYfj+XqabLgs/ EtJmN4yrr1ag0rJ9mDGzrgjDPQDiRCkguqDAE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jts1Y9JMpVL0If8P8yimWr5loe4E0VIqYItcqhdJT04=; b=jm+QWCPH4AcN9mW9FhB+Axf0f4WscV9yEIoWQV/t4xtgg50xCWDFKZiW+9LjqJKWgy nKdQD7pj2FUxoJTm2VRMQ+L/m4Lhkx+qodIiuybV+CMXKJlyJS9gldScez8lFHnRh5S6 +aDSSE4pnJ+NGBJU2fxJ2uqCruzDMzxlagf3RXBREpI2EYXuWNH8R7ziniEa3lvyuHk4 KziaYqKFBhnDzvVHhnDR4jBzbHkIFmaUYQbjaiHAboJMXTA9a9NJvkwVs8fNVfeYWbCW hyvhO59048NPWcEu784vRu3oRQivA0upeyymLIiaZnv7Wom8DFhazoHyN1Kf6PPVbkhc nvAw== X-Gm-Message-State: AJIora+0xw+pp3pwNGbD7EC9bFEsqKr5tuHTK2NUaSBOVKt65eW6s4Ep S8LYCH0mGVH+gc1X5chFGmfr3O1HuTqfdQ== X-Google-Smtp-Source: AGRyM1t3rkNRA6Pzf7Rhejl5i6Yk/NJFrroHb1CZ1jTGwinOP7wTDoxpkRm6jtCxnL+OTuJWRwSxKw== X-Received: by 2002:a17:903:41d0:b0:16a:55e0:6c3d with SMTP id u16-20020a17090341d000b0016a55e06c3dmr47794830ple.21.1657111989582; Wed, 06 Jul 2022 05:53:09 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5300:b974:1680:1bd]) by smtp.gmail.com with ESMTPSA id u12-20020a17090341cc00b0016a6cd546d6sm25640127ple.251.2022.07.06.05.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 05:53:09 -0700 (PDT) From: Hsin-Yi Wang To: Robert Foss , Xin Ji Subject: [PATCH v2 3/4] drm/bridge: anx7625: Fix NULL pointer crash when using edp-panel Date: Wed, 6 Jul 2022 20:52:53 +0800 Message-Id: <20220706125254.2474095-4-hsinyi@chromium.org> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220706125254.2474095-1-hsinyi@chromium.org> References: <20220706125254.2474095-1-hsinyi@chromium.org> MIME-Version: 1.0 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: Jonas Karlman , David Airlie , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Neil Armstrong , linux-kernel@vger.kernel.org, Jernej Skrabec , Laurent Pinchart , Andrzej Hajda , Sam Ravnborg , Maxime Ripard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Move devm_of_dp_aux_populate_ep_devices() after pm runtime and i2c setup to avoid NULL pointer crash. edp-panel probe (generic_edp_panel_probe) calls pm_runtime_get_sync() to read EDID. At this time, bridge should have pm runtime enabled and i2c clients ready. Fixes: adca62ec370c ("drm/bridge: anx7625: Support reading edid through aux channel") Signed-off-by: Hsin-Yi Wang Reviewed-by: Xin Ji --- drivers/gpu/drm/bridge/analogix/anx7625.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index fcf07a037c2c8..aded20b9e25b1 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -2590,14 +2590,6 @@ static int anx7625_i2c_probe(struct i2c_client *client, platform->aux.dev = dev; platform->aux.transfer = anx7625_aux_transfer; drm_dp_aux_init(&platform->aux); - devm_of_dp_aux_populate_ep_devices(&platform->aux); - - ret = anx7625_parse_dt(dev, pdata); - if (ret) { - if (ret != -EPROBE_DEFER) - DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret); - goto free_wq; - } if (anx7625_register_i2c_dummy_clients(platform, client) != 0) { ret = -ENOMEM; @@ -2613,6 +2605,15 @@ static int anx7625_i2c_probe(struct i2c_client *client, if (ret) goto free_wq; + devm_of_dp_aux_populate_ep_devices(&platform->aux); + + ret = anx7625_parse_dt(dev, pdata); + if (ret) { + if (ret != -EPROBE_DEFER) + DRM_DEV_ERROR(dev, "fail to parse DT : %d\n", ret); + goto free_wq; + } + if (!platform->pdata.low_power_mode) { anx7625_disable_pd_protocol(platform); pm_runtime_get_sync(dev); From patchwork Wed Jul 6 12:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsin-Yi Wang X-Patchwork-Id: 12908099 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 A5CD3C43334 for ; Wed, 6 Jul 2022 12:53:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 67B7611AF06; Wed, 6 Jul 2022 12:53:13 +0000 (UTC) Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9FA8311AEFF for ; Wed, 6 Jul 2022 12:53:12 +0000 (UTC) Received: by mail-pl1-x635.google.com with SMTP id r1so13554176plo.10 for ; Wed, 06 Jul 2022 05:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vpU/47CIGfcMKZ4E2aqoCQ1BOqNCcamkTX7gRfUbreo=; b=N4/8r99A/+2PtNfA6zKC7zYa6daai8aymv0oo3OLKvNL1LFMgLq9MqhuNCRPZ3Orxk 9zvYKc6A5GGxS5wljKrCbsmwjwHl6kAnoYdQMXqFdMF7SXJW4lvoOmGOpHB6cWTmBgbP vttKZCao/XCM9jfG6jGi8vO8rWAAtlO5bajew= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vpU/47CIGfcMKZ4E2aqoCQ1BOqNCcamkTX7gRfUbreo=; b=0Ek8HI6ChJf9MVNrRP4z1EeO60Gikqdq1L55we0USPqhUE0stzRPR8cdKvz5/3HVZd TMOMCZZEbT8+UF5d8Rq3eYI3TBUdfLd4LaLm5oBGr43wmgM9Y+bHyrK375CjLAJYqK4F 1KgzcFnwN7jrkFiVy6Wptr5VsTwCvaEb0oGVQKfna3lT4TtJfBdtkgJK/End3fSfm3lO A1EcG7e4JKDYvepDa/cMJtA1rq52Puu47P/M1BKcWo0a5CBhzuPHiJrtWB2GZj6DvpoX vERbWstGsbGIIlbkreecbH1bUXnmcATLgEwZuLPFYQ2Cqzm9n4XE2s6cyWeQKXl7q/8P 6Jiw== X-Gm-Message-State: AJIora/TwQVvL7Cz0K/5LkWQLHyNRDVkAbfsxoORwk7hK8dXhq4L44OM y18IKIH1r0+cC9yLM4MRUP0zGQ== X-Google-Smtp-Source: AGRyM1vPZy1bE7pCVFrwvF6JhtLpJ3e5q30yrQdoFZdI6S+SjkzAjaWd6jRhqaEDx5rYAAusjkJdSg== X-Received: by 2002:a17:902:d50d:b0:16b:ff69:35 with SMTP id b13-20020a170902d50d00b0016bff690035mr4257876plg.160.1657111992179; Wed, 06 Jul 2022 05:53:12 -0700 (PDT) Received: from hsinyi-z840.tpe.corp.google.com ([2401:fa00:1:10:5300:b974:1680:1bd]) by smtp.gmail.com with ESMTPSA id u12-20020a17090341cc00b0016a6cd546d6sm25640127ple.251.2022.07.06.05.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 05:53:11 -0700 (PDT) From: Hsin-Yi Wang To: Robert Foss , Xin Ji Subject: [PATCH v2 4/4] drm/bridge: anx7625: Add wait_hpd_asserted() callback Date: Wed, 6 Jul 2022 20:52:54 +0800 Message-Id: <20220706125254.2474095-5-hsinyi@chromium.org> X-Mailer: git-send-email 2.37.0.rc0.161.g10f37bed90-goog In-Reply-To: <20220706125254.2474095-1-hsinyi@chromium.org> References: <20220706125254.2474095-1-hsinyi@chromium.org> MIME-Version: 1.0 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: Jonas Karlman , David Airlie , Thomas Zimmermann , dri-devel@lists.freedesktop.org, Neil Armstrong , linux-kernel@vger.kernel.org, Jernej Skrabec , Laurent Pinchart , Andrzej Hajda , Sam Ravnborg , Maxime Ripard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Move hpd polling check into wait_hpd_asserted() callback. For the cases that aux transfer function wasn't used, do hpd polling check after pm runtime resume, which will power on the bridge. Signed-off-by: Hsin-Yi Wang Reviewed-by: Xin Ji --- v1->v2: fix indent. --- drivers/gpu/drm/bridge/analogix/anx7625.c | 33 ++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c index aded20b9e25b1..d1f1d525aeb6d 100644 --- a/drivers/gpu/drm/bridge/analogix/anx7625.c +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c @@ -1443,23 +1443,24 @@ static int anx7625_read_hpd_status_p0(struct anx7625_data *ctx) return anx7625_reg_read(ctx, ctx->i2c.rx_p0_client, SYSTEM_STSTUS); } -static void anx7625_hpd_polling(struct anx7625_data *ctx) +static int _anx7625_hpd_polling(struct anx7625_data *ctx, + unsigned long wait_us) { int ret, val; struct device *dev = &ctx->client->dev; /* Interrupt mode, no need poll HPD status, just return */ if (ctx->pdata.intp_irq) - return; + return 0; ret = readx_poll_timeout(anx7625_read_hpd_status_p0, ctx, val, ((val & HPD_STATUS) || (val < 0)), - 5000, - 5000 * 100); + wait_us / 100, + wait_us); if (ret) { DRM_DEV_ERROR(dev, "no hpd.\n"); - return; + return ret; } DRM_DEV_DEBUG_DRIVER(dev, "system status: 0x%x. HPD raise up.\n", val); @@ -1472,6 +1473,23 @@ static void anx7625_hpd_polling(struct anx7625_data *ctx) if (!ctx->pdata.panel_bridge && ctx->bridge_attached) drm_helper_hpd_irq_event(ctx->bridge.dev); + + return 0; +} + +static int anx7625_wait_hpd_asserted(struct drm_dp_aux *aux, + unsigned long wait_us) +{ + struct anx7625_data *ctx = container_of(aux, struct anx7625_data, aux); + struct device *dev = &ctx->client->dev; + int ret; + + pm_runtime_get_sync(dev); + ret = _anx7625_hpd_polling(ctx, wait_us); + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; } static void anx7625_remove_edid(struct anx7625_data *ctx) @@ -1741,6 +1759,7 @@ static struct edid *anx7625_get_edid(struct anx7625_data *ctx) } pm_runtime_get_sync(dev); + _anx7625_hpd_polling(ctx, 5000 * 100); edid_num = sp_tx_edid_read(ctx, p_edid->edid_raw_data); pm_runtime_put_sync(dev); @@ -2378,6 +2397,7 @@ static void anx7625_bridge_atomic_enable(struct drm_bridge *bridge, ctx->connector = connector; pm_runtime_get_sync(dev); + _anx7625_hpd_polling(ctx, 5000 * 100); anx7625_dp_start(ctx); } @@ -2497,7 +2517,6 @@ static int __maybe_unused anx7625_runtime_pm_resume(struct device *dev) mutex_lock(&ctx->lock); anx7625_power_on_init(ctx); - anx7625_hpd_polling(ctx); mutex_unlock(&ctx->lock); @@ -2589,6 +2608,7 @@ static int anx7625_i2c_probe(struct i2c_client *client, platform->aux.name = "anx7625-aux"; platform->aux.dev = dev; platform->aux.transfer = anx7625_aux_transfer; + platform->aux.wait_hpd_asserted = anx7625_wait_hpd_asserted; drm_dp_aux_init(&platform->aux); if (anx7625_register_i2c_dummy_clients(platform, client) != 0) { @@ -2617,6 +2637,7 @@ static int anx7625_i2c_probe(struct i2c_client *client, if (!platform->pdata.low_power_mode) { anx7625_disable_pd_protocol(platform); pm_runtime_get_sync(dev); + _anx7625_hpd_polling(platform, 5000 * 100); } /* Add work function */