From patchwork Thu Jun 13 13:49:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Erwan Le Ray X-Patchwork-Id: 166669 Delivered-To: patch@linaro.org Received: by 2002:ac9:2a84:0:0:0:0:0 with SMTP id p4csp797052oca; Thu, 13 Jun 2019 08:11:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzJeB9no83zjvj9a0pUXhMnR9xPy+T6SW58PgLDR9VzJcaXLEuLB6w+vc4O8A0SH1uTDWOI X-Received: by 2002:a65:6241:: with SMTP id q1mr469397pgv.24.1560438691250; Thu, 13 Jun 2019 08:11:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560438691; cv=none; d=google.com; s=arc-20160816; b=dP3FEU0vqyMiaVUMelZA1YE26ErAW9KaugYvs57DegX/obcQIRNRpU002VvOCDU/tw lkVA8F1LhYCLrjklbBWu7dgynqLqvEey+ZXtjSdReE7Y71DR2ifUHa1dNyFalx5ZNnHx 4WTAmqAgKxEuj2qfSuA6molhUBbXvuWb9DK1g/dnyY77HlhVieWqyoWqAoh4QgQdZPjV NK4Gt+ATykiQLAcu0Z5Is+sPAxRZTQPuF0fRMJ38Ye5kKFn21veA4ztYF8SyJx60+OyS mME+nd2UWxWGrgR9PE6Qk4H2IzX4j/z9pUz3SruTmTpAPL2/LQrUN9Eec0y7VDzRKfFH smeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=hllslad0ZWm7rs4WEeAUG4PuD0rX/7NjtO8beDQ9F3E=; b=qgHmm7F/lXZHjmU2Uwy6jyBYxGu+i5w3W+NgS2vw0iHZ06z7XQM1l2EqEdoM5ZmpPL QsnzeO+89Gy4WlwGStIYjRCUAwY19AeJBPY6+X1ffJJzFMJozsmT+DwohYnLTpzcARmn q4kAwzi24iFG/KrEyU5FGVx2I3qK54Unpd5gEpILXZ7T4QnNHMn/llthRbnsDCVaC4Fb 5tMf1bDSOKxlKyeI9ReJFR29Hj6qwlvHXYMhjHQA95l3A6XwVRYZhLulC7O7jn0fPFr/ dKNGGO/6NbUhFzHTgqOSsP3/zYCwN82XLKiGHRFVMJDPyxSNRWJc+Z3FNLu6+/SR20CN SwnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=fYhEwkIE; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10si3594086pfd.226.2019.06.13.08.11.31; Thu, 13 Jun 2019 08:11:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@st.com header.s=STMicroelectronics header.b=fYhEwkIE; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732430AbfFMPLa (ORCPT + 1 other); Thu, 13 Jun 2019 11:11:30 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:61405 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732295AbfFMNug (ORCPT ); Thu, 13 Jun 2019 09:50:36 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5DDkNre026654; Thu, 13 Jun 2019 15:50:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=hllslad0ZWm7rs4WEeAUG4PuD0rX/7NjtO8beDQ9F3E=; b=fYhEwkIEGFECFS7WVam7esMnqdrz2I2VUQOSNaXI3cmIxqL6OPGlOgpWHl0Q6xwlv3NJ 7nCkm0nLiQwCmbnhmIaTjmHihFkaN7f41PfIm153YWEm6UPdZ1z6wMALnOOhGmPB67tb MOLGhmdgm460oLT7lYmiV6GE+sBu2jni6DkLmosOrrFao6hhmlNWF9IxkDf5kNLX090B ICm/u69nUisJbZU+5Gdk7V8pvvrM+Q+u0Wp95VJKpeJp2RgRgrKXo8YQPqTWzDltuHtm yJHE+6th1ZjQLb4T+cUSaThEI9aHm206rFdgJSmngBpgkgXJvLriAGrTY1N5cn5kNTge Fg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2t2k3cb6e8-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 13 Jun 2019 15:50:21 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8188441; Thu, 13 Jun 2019 13:50:18 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id CD94C2BDD; Thu, 13 Jun 2019 13:50:17 +0000 (GMT) Received: from SAFEX1HUBCAS22.st.com (10.75.90.93) by SAFEX1HUBCAS21.st.com (10.75.90.44) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 13 Jun 2019 15:50:17 +0200 Received: from localhost (10.201.23.31) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 13 Jun 2019 15:50:16 +0200 From: Erwan Le Ray To: Greg Kroah-Hartman , Jiri Slaby , Maxime Coquelin , "Alexandre Torgue" , Rob Herring , "Mark Rutland" CC: , , , , , Erwan Le Ray , "Fabrice Gasnier" , Bich Hemon Subject: [PATCH v3 04/10] serial: stm32: add pm_runtime support Date: Thu, 13 Jun 2019 15:49:54 +0200 Message-ID: <1560433800-12255-5-git-send-email-erwan.leray@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1560433800-12255-1-git-send-email-erwan.leray@st.com> References: <1560433800-12255-1-git-send-email-erwan.leray@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.31] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-13_08:, , signatures=0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Use pm_runtime for clock management. Signed-off-by: Bich Hemon Signed-off-by: Erwan Le Ray -- 1.9.1 diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index a8f20ba..41898c4 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -810,13 +810,13 @@ static void stm32_pm(struct uart_port *port, unsigned int state, switch (state) { case UART_PM_STATE_ON: - clk_prepare_enable(stm32port->clk); + pm_runtime_get_sync(port->dev); break; case UART_PM_STATE_OFF: spin_lock_irqsave(&port->lock, flags); stm32_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); spin_unlock_irqrestore(&port->lock, flags); - clk_disable_unprepare(stm32port->clk); + pm_runtime_put_sync(port->dev); break; } } @@ -1111,6 +1111,11 @@ static int stm32_serial_probe(struct platform_device *pdev) platform_set_drvdata(pdev, &stm32port->port); + pm_runtime_get_noresume(&pdev->dev); + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + pm_runtime_put_sync(&pdev->dev); + return 0; err_wirq: @@ -1132,6 +1137,9 @@ static int stm32_serial_remove(struct platform_device *pdev) struct uart_port *port = platform_get_drvdata(pdev); struct stm32_port *stm32_port = to_stm32_port(port); struct stm32_usart_offsets *ofs = &stm32_port->info->ofs; + int err; + + pm_runtime_get_sync(&pdev->dev); stm32_clr_bits(port, ofs->cr3, USART_CR3_DMAR); @@ -1160,7 +1168,12 @@ static int stm32_serial_remove(struct platform_device *pdev) clk_disable_unprepare(stm32_port->clk); - return uart_remove_one_port(&stm32_usart_driver, port); + err = uart_remove_one_port(&stm32_usart_driver, port); + + pm_runtime_disable(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + + return err; } @@ -1317,7 +1330,29 @@ static int stm32_serial_resume(struct device *dev) } #endif /* CONFIG_PM_SLEEP */ +static int __maybe_unused stm32_serial_runtime_suspend(struct device *dev) +{ + struct uart_port *port = dev_get_drvdata(dev); + struct stm32_port *stm32port = container_of(port, + struct stm32_port, port); + + clk_disable_unprepare(stm32port->clk); + + return 0; +} + +static int __maybe_unused stm32_serial_runtime_resume(struct device *dev) +{ + struct uart_port *port = dev_get_drvdata(dev); + struct stm32_port *stm32port = container_of(port, + struct stm32_port, port); + + return clk_prepare_enable(stm32port->clk); +} + static const struct dev_pm_ops stm32_serial_pm_ops = { + SET_RUNTIME_PM_OPS(stm32_serial_runtime_suspend, + stm32_serial_runtime_resume, NULL) SET_SYSTEM_SLEEP_PM_OPS(stm32_serial_suspend, stm32_serial_resume) };