From patchwork Thu Sep 8 08:12:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 12969749 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 1566FECAAD5 for ; Thu, 8 Sep 2022 08:13:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AFE3310E999; Thu, 8 Sep 2022 08:13:14 +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 7682C10E999 for ; Thu, 8 Sep 2022 08:13:11 +0000 (UTC) Received: by mail-pj1-x102a.google.com with SMTP id q15-20020a17090a304f00b002002ac83485so1627599pjl.0 for ; Thu, 08 Sep 2022 01:13:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=O1vPzp++Y+rg877+GNK8AXhim+X8pwwIT0iX2ZyyZGc=; b=aU+cB1J4gIcX9czY5UabCbYzMhsgnCE6P3ZxLkl4oSTxzOqBFcrV2pRr1ffiSzzg3l IHX9G44qeKLQ/5IltNvL0aay91DB+3ApLtFPI4BmiGuGODuMQEXCZ3lZsS9p3yf9WnRz f+81tttNHHZ+kIoOjkUd0vEXPpMkSPGalXvbM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=O1vPzp++Y+rg877+GNK8AXhim+X8pwwIT0iX2ZyyZGc=; b=XojbTd7xeJV8bcbTOIPa/eTnO9x2g0rtELIfpZA/dZD6OsxcILu4J7qt/uYIdOqGiU rzQZosBrAowIE1LDYN2/qbq+QUX8gFWFRjmJNFuGO/0rMd/cqqtPRMvc6AA5mZ5IoPle QtdBzZ7Y7dvcWWx6ZQsuT6G5nsfkAKC2Fm2+xed+SpCvOe532/KFGa7WFl/9PtsHoSyF 20JLdKs5tV3lDiMfxl5RSCzgJiaS484S/dWZa+ZvCUMuD9+cddX7no0o/7n/3DAOAJ7L 0Ka6YMl5ASf5kSJNa2Aloc4Y3ZlyRJ1AIIvkLJ0K1fnBASx6KUd9GIqPgfuVBYqxWeqa VjIw== X-Gm-Message-State: ACgBeo3sVmmC6IpxCxm4Y5EoLLFHW3RAdfh2G0Qo17omQZ1Mky++lD80 8aAPk1Aecy1R/AtJKHkldRI/tw== X-Google-Smtp-Source: AA6agR7NC8MzGBXfOam39plBc4fj/sNv5PauFaLxGrH8rC2K1EiGjJ6oljoacaKFQeeyTHBzyd58Jw== X-Received: by 2002:a17:902:ec88:b0:175:d8f:44b with SMTP id x8-20020a170902ec8800b001750d8f044bmr7849588plg.84.1662624791085; Thu, 08 Sep 2022 01:13:11 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:5237:c185:9b01:8955]) by smtp.gmail.com with ESMTPSA id z22-20020aa79496000000b0052d4cb47339sm14159702pfk.151.2022.09.08.01.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 01:13:10 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Subject: [PATCH 1/2] drm/bridge: it6505: Adapt runtime power management framework Date: Thu, 8 Sep 2022 16:12:57 +0800 Message-Id: <20220908081259.503236-2-treapking@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220908081259.503236-1-treapking@chromium.org> References: <20220908081259.503236-1-treapking@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: Allen Chen , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Pin-yen Lin , Hermes Wu , Hsin-Yi Wang , AngeloGioacchino Del Regno Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use pm_runtime_(get|put)_sync to control the bridge power, and add SET_SYSTEM_SLEEP_PM_OPS with pm_runtime_force_(suspend|resume) to it6505 driver. Without SET_SYSTEM_SLEEP_PM_OPS, the bridge will be powered on unnecessarily when no external display is connected. Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver") Signed-off-by: Pin-yen Lin --- drivers/gpu/drm/bridge/ite-it6505.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 2bb957cffd94..9d37660545fb 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -421,6 +421,7 @@ struct it6505 { struct notifier_block event_nb; struct extcon_dev *extcon; struct work_struct extcon_wq; + int extcon_state; enum drm_connector_status connector_status; enum link_train_status link_state; struct work_struct link_works; @@ -2685,31 +2686,34 @@ static void it6505_extcon_work(struct work_struct *work) { struct it6505 *it6505 = container_of(work, struct it6505, extcon_wq); struct device *dev = &it6505->client->dev; - int state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP); - unsigned int pwroffretry = 0; + int state; if (it6505->enable_drv_hold) return; mutex_lock(&it6505->extcon_lock); + state = extcon_get_state(it6505->extcon, EXTCON_DISP_DP); DRM_DEV_DEBUG_DRIVER(dev, "EXTCON_DISP_DP = 0x%02x", state); + + if (state == it6505->extcon_state) + goto unlock; + if (state > 0) { DRM_DEV_DEBUG_DRIVER(dev, "start to power on"); msleep(100); - it6505_poweron(it6505); + pm_runtime_get_sync(dev); } else { DRM_DEV_DEBUG_DRIVER(dev, "start to power off"); - while (it6505_poweroff(it6505) && pwroffretry++ < 5) { - DRM_DEV_DEBUG_DRIVER(dev, "power off fail %d times", - pwroffretry); - } + pm_runtime_put_sync(dev); drm_helper_hpd_irq_event(it6505->bridge.dev); memset(it6505->dpcd, 0, sizeof(it6505->dpcd)); DRM_DEV_DEBUG_DRIVER(dev, "power off it6505 success!"); } + it6505->extcon_state = state; +unlock: mutex_unlock(&it6505->extcon_lock); } @@ -3032,8 +3036,10 @@ static __maybe_unused int it6505_bridge_suspend(struct device *dev) return it6505_poweroff(it6505); } -static SIMPLE_DEV_PM_OPS(it6505_bridge_pm_ops, it6505_bridge_suspend, - it6505_bridge_resume); +static const struct dev_pm_ops it6505_bridge_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume) + SET_RUNTIME_PM_OPS(it6505_bridge_suspend, it6505_bridge_resume, NULL) +}; static int it6505_init_pdata(struct it6505 *it6505) { @@ -3315,6 +3321,7 @@ static int it6505_i2c_probe(struct i2c_client *client, DRM_DEV_DEBUG_DRIVER(dev, "it6505 device name: %s", dev_name(dev)); debugfs_init(it6505); + pm_runtime_enable(dev); it6505->bridge.funcs = &it6505_bridge_funcs; it6505->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; From patchwork Thu Sep 8 08:12:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pin-yen Lin X-Patchwork-Id: 12969750 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 099C0C38145 for ; Thu, 8 Sep 2022 08:13:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A073E10E99D; Thu, 8 Sep 2022 08:13:19 +0000 (UTC) Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by gabe.freedesktop.org (Postfix) with ESMTPS id 05CB910E99D for ; Thu, 8 Sep 2022 08:13:17 +0000 (UTC) Received: by mail-pg1-x536.google.com with SMTP id s206so16013744pgs.3 for ; Thu, 08 Sep 2022 01:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=jD1WgCeSA8uWA865ybZkInzC4AA4C89F3a1ntZPiE8k=; b=gRx+CxMIiN6H9pj7fPVTKTaBOZuCbadXfe/izl78J7zwh9G/F/ZZfhDRPAR4KUqpIT tzTV7y+tG4VbrnkuhCTSDnVuChYd1LK08RhOcWwdzZIjw2AGCjLp9xz3DJj7dl2RNmhS laBZg/+nT7AZB8IzBfjPX3AwryZn3ulbsNQ5g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=jD1WgCeSA8uWA865ybZkInzC4AA4C89F3a1ntZPiE8k=; b=gHpgkUZ5ZwpcTfZGExIuJ6+ofj+a7v/JMa+tPW7Qc+I9jQcgn2jeFdQ5Fz3YKxw6mw 5R5iidEHWLCyXAXmk4x9viNfuQXBdIc7wqKxCebIpyvL4dUluB59wYIGILp3aaYWdt0f gJKd3zV2Zvu6d5AeuUH7chmzSvzH17Q0Jz8g2T4FRCSQtyNF2Yx9fx4kZNLKIqEbeyXb Fo9F5LapTEZ4ZXMCtXCX874gpB+ENDF/QMeR8E248rqGsMC4OJiTnmmTfrDi6TkHQk6m p2QHfcsbO8ULTYjD2F3RMDCYVWl4FoFYPGmr90gBkrg3Mp6C/CYUPh2XrUAywxqAtM2c E99A== X-Gm-Message-State: ACgBeo0zojFWqNXqMEmW7IgNqBmf1yZ82PPxRQJPyp0/ATZTrrTkNz6G Vqjx7R0EmtEnIKPnwy6cdXd9BA== X-Google-Smtp-Source: AA6agR5pAxhOg42yEVQWiNBTst6BWefRDET/Dw+fjQjsfFbYbib4gMXfhh2kApJRsESI7zxngjveLQ== X-Received: by 2002:a63:6683:0:b0:42b:1d69:a0ff with SMTP id a125-20020a636683000000b0042b1d69a0ffmr6965140pgc.475.1662624796587; Thu, 08 Sep 2022 01:13:16 -0700 (PDT) Received: from treapking.tpe.corp.google.com ([2401:fa00:1:10:5237:c185:9b01:8955]) by smtp.gmail.com with ESMTPSA id z22-20020aa79496000000b0052d4cb47339sm14159702pfk.151.2022.09.08.01.13.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 01:13:16 -0700 (PDT) From: Pin-yen Lin To: Andrzej Hajda , Neil Armstrong , Robert Foss , Laurent Pinchart , Jonas Karlman , Jernej Skrabec , David Airlie , Daniel Vetter Subject: [PATCH 2/2] drm/bridge: it6505: Add pre_enable/post_disable callback Date: Thu, 8 Sep 2022 16:12:58 +0800 Message-Id: <20220908081259.503236-3-treapking@chromium.org> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog In-Reply-To: <20220908081259.503236-1-treapking@chromium.org> References: <20220908081259.503236-1-treapking@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: Allen Chen , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Pin-yen Lin , Hermes Wu , Hsin-Yi Wang , AngeloGioacchino Del Regno Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add atomic_pre_enable and atomic_post_disable callback to make sure the bridge is not powered off until atomic_post_disable is called. This prevents a power leakage when it6505 is powered off, but the upstream DRM bridge is still sending display signals. Fixes: b5c84a9edcd4 ("drm/bridge: add it6505 driver") Signed-off-by: Pin-yen Lin --- drivers/gpu/drm/bridge/ite-it6505.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/gpu/drm/bridge/ite-it6505.c b/drivers/gpu/drm/bridge/ite-it6505.c index 9d37660545fb..f5eea138ace4 100644 --- a/drivers/gpu/drm/bridge/ite-it6505.c +++ b/drivers/gpu/drm/bridge/ite-it6505.c @@ -2984,6 +2984,28 @@ static void it6505_bridge_atomic_disable(struct drm_bridge *bridge, } } +static void it6505_bridge_atomic_pre_enable(struct drm_bridge *bridge, + struct drm_bridge_state *old_state) +{ + struct it6505 *it6505 = bridge_to_it6505(bridge); + struct device *dev = &it6505->client->dev; + + DRM_DEV_DEBUG_DRIVER(dev, "start"); + + pm_runtime_get_sync(dev); +} + +static void it6505_bridge_atomic_post_disable(struct drm_bridge *bridge, + struct drm_bridge_state *old_state) +{ + struct it6505 *it6505 = bridge_to_it6505(bridge); + struct device *dev = &it6505->client->dev; + + DRM_DEV_DEBUG_DRIVER(dev, "start"); + + pm_runtime_put_sync(dev); +} + static enum drm_connector_status it6505_bridge_detect(struct drm_bridge *bridge) { @@ -3018,6 +3040,8 @@ static const struct drm_bridge_funcs it6505_bridge_funcs = { .mode_valid = it6505_bridge_mode_valid, .atomic_enable = it6505_bridge_atomic_enable, .atomic_disable = it6505_bridge_atomic_disable, + .atomic_pre_enable = it6505_bridge_atomic_pre_enable, + .atomic_post_disable = it6505_bridge_atomic_post_disable, .detect = it6505_bridge_detect, .get_edid = it6505_bridge_get_edid, };