From patchwork Tue Jun 29 11:58:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raphael Gallais-Pou X-Patchwork-Id: 12349833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32E46C11F66 for ; Tue, 29 Jun 2021 13:02:37 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E14D061DBF for ; Tue, 29 Jun 2021 13:02:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E14D061DBF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6590F6E890; Tue, 29 Jun 2021 13:02:36 +0000 (UTC) X-Greylist: delayed 3844 seconds by postgrey-1.36 at gabe; Tue, 29 Jun 2021 13:02:34 UTC Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id B4C866E890 for ; Tue, 29 Jun 2021 13:02:34 +0000 (UTC) Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15TBmjl9008436; Tue, 29 Jun 2021 13:58:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=selector1; bh=906FZGpYwh0Yc5aE+vSBBWEeesUdzLB4RDvgOuUwap4=; b=ExqnUGWDdYRkGex/9BjsbC9mY6ZrU3C9CsoY+JwwqczJ4kY+SRiOAtFC8sfWJMvzoirJ 6Cf7JA/hwdWSvgpaD5tc9SFajv+yp76sTjjuxeb3dcGj/DtcuCL3BVM8VO9qdJ6W8z2P pmRQYQarIJcKH1v4p1hMRkPdj5KQkoS2zUJQ2XiXpc8BuWlNjGKvRv+4uzhSVs9RwtfB zhqjudGxA5xvg0/1ihRXvEQb9ppnDN4U0LHsRcGGqN0Bl3d2ASCKYj1V/rn4KeYNznbe Gc7JZ3epg50Hab5J97V+mazRQ4Z7ee/z3HbE7rXfmMKRiSeBloVYja0o8QKqg0tXWShx 2A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 39fueajw5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 29 Jun 2021 13:58:20 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id F192D100034; Tue, 29 Jun 2021 13:58:19 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id CAAB52291A3; Tue, 29 Jun 2021 13:58:19 +0200 (CEST) Received: from SFHDAG2NODE3.st.com (10.75.127.6) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 29 Jun 2021 13:58:19 +0200 Received: from SFHDAG2NODE3.st.com ([fe80::31b3:13bf:2dbe:f64c]) by SFHDAG2NODE3.st.com ([fe80::31b3:13bf:2dbe:f64c%20]) with mapi id 15.00.1497.015; Tue, 29 Jun 2021 13:58:19 +0200 From: Raphael GALLAIS-POU - foss To: Yannick FERTRE - foss , Philippe CORNU - foss , Benjamin Gaignard , David Airlie , "Daniel Vetter" , Maxime Coquelin , Alexandre TORGUE - foss , "dri-devel@lists.freedesktop.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: [PATCH] drm/stm: ltdc: improve pm_runtime to stop clocks Thread-Topic: [PATCH] drm/stm: ltdc: improve pm_runtime to stop clocks Thread-Index: AQHXbN4NPtwAtoP5gkmmR0xGN01wUg== Date: Tue, 29 Jun 2021 11:58:19 +0000 Message-ID: <20210629115709.16145-1-raphael.gallais-pou@foss.st.com> Accept-Language: fr-FR, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.75.127.44] MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-06-29_06:2021-06-28, 2021-06-29 signatures=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: Yannick FERTRE , Marek Vasut , Raphael GALLAIS-POU , Philippe CORNU , Raphael GALLAIS-POU - foss Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Bugzilla ticket: https://intbugzilla.st.com/show_bug.cgi?id=60620 Gerrit patch: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/208093/ In the LTDC driver, pm_runtime_get_sync was wrongly used and caused the LTDC pixel clock to be systematically enabled in the clock summary. After one simple use of the LTDC by activating and deactivating, the clock summary results as below: ~# cat /sys/kernel/debug/clk/clk_summary | grep ltdc ltdc_px 1 1 0 29700000 0 0 50000 N ltdc 0 0 0 133250000 0 0 50000 N By doing so, pm_runtime_get_sync only increments the clock counter when the driver was in not active, displaying the right information when the LTDC is not in use, resulting of the below clock summary after deactivation of the LTDC. ~# cat /sys/kernel/debug/clk/clk_summary | grep ltdc ltdc_px 0 0 0 29700000 0 0 50000 N ltdc 0 0 0 133250000 0 0 50000 N The clocks are activated either by the crtc_set_nofb function or by the crtc_atomic_enable function. A check of pm_runtime activity must be done before set clocks on. This check must also be done for others functions which access registers. Signed-off-by: Raphael Gallais-Pou Tested-by: Yannick Fertre --- drivers/gpu/drm/stm/ltdc.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index 08b71248044d..bf9d18023698 100644 --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -425,10 +425,17 @@ static void ltdc_crtc_atomic_enable(struct drm_crtc *crtc, { struct ltdc_device *ldev = crtc_to_ltdc(crtc); struct drm_device *ddev = crtc->dev; + int ret; DRM_DEBUG_DRIVER("\n"); - pm_runtime_get_sync(ddev->dev); + if (!pm_runtime_active(ddev->dev)) { + ret = pm_runtime_get_sync(ddev->dev); + if (ret) { + DRM_ERROR("Failed to set mode, cannot get sync\n"); + return; + } + } /* Sets the background color value */ reg_write(ldev->regs, LTDC_BCCR, BCCR_BCBLACK); @@ -783,6 +790,7 @@ static void ltdc_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *newstate = drm_atomic_get_new_plane_state(state, plane); struct drm_framebuffer *fb = newstate->fb; + struct drm_device *ddev = plane->dev; u32 lofs = plane->index * LAY_OFS; u32 x0 = newstate->crtc_x; u32 x1 = newstate->crtc_x + newstate->crtc_w - 1; @@ -792,6 +800,11 @@ static void ltdc_plane_atomic_update(struct drm_plane *plane, u32 val, pitch_in_bytes, line_length, paddr, ahbp, avbp, bpcr; enum ltdc_pix_fmt pf; + if (!pm_runtime_active(ddev->dev)) { + DRM_DEBUG_DRIVER("crtc not activated"); + return; + } + if (!newstate->crtc || !fb) { DRM_DEBUG_DRIVER("fb or crtc NULL"); return; @@ -897,8 +910,14 @@ static void ltdc_plane_atomic_disable(struct drm_plane *plane, struct drm_plane_state *oldstate = drm_atomic_get_old_plane_state(state, plane); struct ltdc_device *ldev = plane_to_ltdc(plane); + struct drm_device *ddev = plane->dev; u32 lofs = plane->index * LAY_OFS; + if (!pm_runtime_active(ddev->dev)) { + DRM_DEBUG_DRIVER("crtc already deactivated"); + return; + } + /* disable layer */ reg_clear(ldev->regs, LTDC_L1CR + lofs, LXCR_LEN);