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: 12349747 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=-14.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 A9658C11F66 for ; Tue, 29 Jun 2021 12:00:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 68A5961D40 for ; Tue, 29 Jun 2021 12:00:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68A5961D40 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=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=l5aqQfRlPUb8jY6wqgficvT3hHZqTI8NJDfrEec8o00=; b=J84NQ9CbMPu4pO Fh5s97xH64qgNZ1WFU9jtfIcjSPWGnADSpaHJv9w14fZcp6L8Y5+4C7m9Dumn9TPBrTAblJ9FD79+ 6WjTxGn0faug2vV2xVk9RzRpKZClhpSAZjHZwv2m8E0VWG/z9Wkxv4wrICatCoJMX5ax+SzKlitme ohiiVCOfU9lgBo3oytgjiJAVLc/4BK5qMxEMbbkunR6sk4tua5Qj8kf9EOk5AEgQoWuKniRWbSVlg /AQIYP2A2cEwzHPC6Z9SP4n9vd0HnD/GfE7CsbdqiDgA8q1wLgemM7K97yTe20Aj7r/TN7YlmEF/T 8GFGTdiWnSsqck2XzGEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyCO6-00Akg9-2E; Tue, 29 Jun 2021 11:58:46 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lyCO1-00Akdy-Uz for linux-arm-kernel@lists.infradead.org; Tue, 29 Jun 2021 11:58:44 +0000 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" CC: Yannick FERTRE , Philippe CORNU , Marek Vasut , "Raphael GALLAIS-POU - foss" , Raphael GALLAIS-POU 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210629_045842_392783_06C1AED5 X-CRM114-Status: GOOD ( 20.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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);