Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4237972pxj; Tue, 25 May 2021 03:32:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxagOaCJmeZzMcGTbgAIhVwx0O6/ndIRdjw7X7DvtRQ7BkYqFtD48aRx9bLt+8EAugInKVo X-Received: by 2002:a05:6402:42cd:: with SMTP id i13mr30671698edc.34.1621938724902; Tue, 25 May 2021 03:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621938724; cv=none; d=google.com; s=arc-20160816; b=aYX8wrzLNJyCP2jOTaJwJF5W9M7eEe1wyxO8dfJZcodX0DIQJwt+TG8bU0nEpzx8o2 RmfXWIPR9U35UOvHRXIqVDWyx4CpuRvyl8/i/9B7g6jQB4U/+YZf2yGHf1C7kElYkAE9 zYaXE/Yuh6KUih/eCEERlJRVVsEw3MBEucLpQzHvCpKt6MTnVhUu+J+yzCefTPsQcThg ffiq37wbfjaQvB0GLi21ZZaOa3N/qn0HR2Q5V6pvuNaUaKJ/ySAho/HmrhLjZK5u71AF ncq8u2/gvPuf3EB2U6i+Z15JC70j7QdjyNxS22U8yaIkMnDutmNp4faB7Is/enPtVU3T sFPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=WMExxbKpb723D6YVDVSHvvRRkWLWmEdwafytxkU3Fmc=; b=OBcVS6HMADb3bDdV47dObTKkMAB/inUY6DCUaiDONMNSr17aWdn09s1EeeioCdrmGJ ut5sC5Ca0hKT4bCeMsccGnZO06KaENd6w23pmJYQpcSDKcuBZf11Zmsr1+yLc0Uv9IN9 4C06H965z1oZvKkvNTgJ1sTjDp0IN6KVWrh5dU0rKgVYQorlPF+hKbxR7TfPJRjgcIch x5A8Ii77wsRM1DMtZaDGCRw20u/0SIK+C4/R6WRtwLqZVhHAKAryNPeh2lzgvzZ+O5Wx gwp3UN/0uEPhScpDuuHI6E1LOrf+zsIiJgThe+FzYGTbA48wGCBx04kW/EolDSot8jYl df0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=aoek5ABh; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=U6BkRoNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l7si14743568edv.147.2021.05.25.03.31.39; Tue, 25 May 2021 03:32:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=aoek5ABh; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=U6BkRoNL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232430AbhEYJMx (ORCPT + 99 others); Tue, 25 May 2021 05:12:53 -0400 Received: from wnew2-smtp.messagingengine.com ([64.147.123.27]:55485 "EHLO wnew2-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232364AbhEYJMn (ORCPT ); Tue, 25 May 2021 05:12:43 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.west.internal (Postfix) with ESMTP id 1E685E2C; Tue, 25 May 2021 05:11:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 25 May 2021 05:11:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=WMExxbKpb723D 6YVDVSHvvRRkWLWmEdwafytxkU3Fmc=; b=aoek5ABh1q7SanV3Owr+OAYGp9dh5 XGK0744ecAByekZHKUN0LHI107HYQTxiBK8R1mveLV1xALhGJCre70QF5ry3N21J 3STD8nQdbpEPoVe/oqeh7338ItnWBzYOAy1vfIs5w9CiqWimBrOKnC+PtQIf1duD Q6p35q/c+YhDzu1ug/fYSgXEnUohtFNjv4PrTGfzCzDHu/rKx97ss+IMoCcRwQW7 ePa1tdBIMCpf/Lcr2CVKmfwQ2pbqTe3iHMoYXvzSQPfbupyTdXqrxazTDAAf7qbI Xo2pMYNSTNvITWTZoX9hHkNJ7ZdFY3nNKJceJ7jlocklz2gK1w1mIyakg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=WMExxbKpb723D6YVDVSHvvRRkWLWmEdwafytxkU3Fmc=; b=U6BkRoNL XX/lshApFctlXIiwHgyA5n4R2AIkG2bAtA6KOrNcsN4erAGug0a0F5n8F//e+Eat ZKtcS/VA56OH7xbhRTzcm0ebuWtbiO7e35AsQVdHDdMOa7MgnGf4U1PHe7vV6Ujz ayLGcjy+FRW8jQnhHKX0NI+Y9+Af5MOemQkpAWzR2dBo5kXfs+NhbkW3cr8NQ/vk hXCwBCMEc6Kqfo9wRhX+wn43wzNFmmXIxeH8yEuxIYB9J8Q0NP4SjiL0XcUUsIzS dXqEWxKSUa/ftvg0sWrdXJRvGzzLxp326d9GkJi8+8//5VzvUa04iHR28hQ+omUY P7O359z58PBsGQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdekuddgudefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeforgigihhm vgcutfhiphgrrhguuceomhgrgihimhgvsegtvghrnhhordhtvggthheqnecuggftrfgrth htvghrnhepvdekleevfeffkeejhfffueelteelfeduieefheduudfggffhhfffheevveeh hedvnecukfhppeeltddrkeelrdeikedrjeeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhgrgihimhgvsegtvghrnhhordhtvggthh X-ME-Proxy: Received: from localhost (lfbn-tou-1-1502-76.w90-89.abo.wanadoo.fr [90.89.68.76]) by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 May 2021 05:11:11 -0400 (EDT) From: Maxime Ripard To: dri-devel@lists.freedesktop.org, Daniel Vetter , David Airlie , Maarten Lankhorst , Thomas Zimmermann , Maxime Ripard Cc: Daniel Vetter , Boris Brezillon , linux-kernel@vger.kernel.org, Eric Anholt , Emma Anholt , Dave Stevenson , Phil Elwell , Tim Gover , Dom Cobley , Maxime Ripard Subject: [PATCH 2/3] drm/vc4: hdmi: Move the HSM clock enable to runtime_pm Date: Tue, 25 May 2021 11:10:58 +0200 Message-Id: <20210525091059.234116-3-maxime@cerno.tech> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210525091059.234116-1-maxime@cerno.tech> References: <20210525091059.234116-1-maxime@cerno.tech> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to access the HDMI controller, we need to make sure the HSM clock is enabled. If we were to access it with the clock disabled, the CPU would completely hang, resulting in an hard crash. Since we have different code path that would require it, let's move that clock enable / disable to runtime_pm that will take care of the reference counting for us. Fixes: 4f6e3d66ac52 ("drm/vc4: Add runtime PM support to the HDMI encoder driver") Signed-off-by: Maxime Ripard --- drivers/gpu/drm/vc4/vc4_hdmi.c | 41 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index f9de8632a28b..867009a471e1 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -632,7 +632,6 @@ static void vc4_hdmi_encoder_post_crtc_powerdown(struct drm_encoder *encoder, HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE); clk_disable_unprepare(vc4_hdmi->pixel_bvb_clock); - clk_disable_unprepare(vc4_hdmi->hsm_clock); clk_disable_unprepare(vc4_hdmi->pixel_clock); ret = pm_runtime_put(&vc4_hdmi->pdev->dev); @@ -943,13 +942,6 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, return; } - ret = clk_prepare_enable(vc4_hdmi->hsm_clock); - if (ret) { - DRM_ERROR("Failed to turn on HSM clock: %d\n", ret); - clk_disable_unprepare(vc4_hdmi->pixel_clock); - return; - } - vc4_hdmi_cec_update_clk_div(vc4_hdmi); if (pixel_rate > 297000000) @@ -962,7 +954,6 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, ret = clk_set_min_rate(vc4_hdmi->pixel_bvb_clock, bvb_rate); if (ret) { DRM_ERROR("Failed to set pixel bvb clock rate: %d\n", ret); - clk_disable_unprepare(vc4_hdmi->hsm_clock); clk_disable_unprepare(vc4_hdmi->pixel_clock); return; } @@ -970,7 +961,6 @@ static void vc4_hdmi_encoder_pre_crtc_configure(struct drm_encoder *encoder, ret = clk_prepare_enable(vc4_hdmi->pixel_bvb_clock); if (ret) { DRM_ERROR("Failed to turn on pixel bvb clock: %d\n", ret); - clk_disable_unprepare(vc4_hdmi->hsm_clock); clk_disable_unprepare(vc4_hdmi->pixel_clock); return; } @@ -2097,6 +2087,29 @@ static int vc5_hdmi_init_resources(struct vc4_hdmi *vc4_hdmi) return 0; } +#ifdef CONFIG_PM +static int vc4_hdmi_runtime_suspend(struct device *dev) +{ + struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev); + + clk_disable_unprepare(vc4_hdmi->hsm_clock); + + return 0; +} + +static int vc4_hdmi_runtime_resume(struct device *dev) +{ + struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev); + int ret; + + ret = clk_prepare_enable(vc4_hdmi->hsm_clock); + if (ret) + return ret; + + return 0; +} +#endif + static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data) { const struct vc4_hdmi_variant *variant = of_device_get_match_data(dev); @@ -2353,11 +2366,19 @@ static const struct of_device_id vc4_hdmi_dt_match[] = { {} }; + +static const struct dev_pm_ops vc4_hdmi_pm_ops = { + SET_RUNTIME_PM_OPS(vc4_hdmi_runtime_suspend, + vc4_hdmi_runtime_resume, + NULL) +}; + struct platform_driver vc4_hdmi_driver = { .probe = vc4_hdmi_dev_probe, .remove = vc4_hdmi_dev_remove, .driver = { .name = "vc4_hdmi", .of_match_table = vc4_hdmi_dt_match, + .pm = &vc4_hdmi_pm_ops, }, }; -- 2.31.1