linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management
@ 2019-07-19  2:59 Changqi Hu
  2019-07-19 11:16 ` Matthias Brugger
  2019-07-25  9:47 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 3+ messages in thread
From: Changqi Hu @ 2019-07-19  2:59 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Matthias Brugger
  Cc: Peter Shih, Changqi Hu, Gustavo A. R. Silva, linux-kernel,
	srv_heupstream, linux-mediatek, linux-serial, Yingjoe Chen,
	Eddie Huang, linux-arm-kernel

modify mtk uart runtime interface, add uart clock use count.
merge patch v1 and patch v2 together.

Signed-off-by: Changqi Hu <changqi.hu@mediatek.com>
---
 drivers/tty/serial/8250/8250_mtk.c | 50 ++++++++++++++++++++++++--------------
 1 file changed, 32 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index f470ded..a07c8ae 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -31,6 +31,7 @@
 #define MTK_UART_RXTRI_AD	0x14	/* RX Trigger address */
 #define MTK_UART_FRACDIV_L	0x15	/* Fractional divider LSB address */
 #define MTK_UART_FRACDIV_M	0x16	/* Fractional divider MSB address */
+#define MTK_UART_DEBUG0	0x18
 #define MTK_UART_IER_XOFFI	0x20	/* Enable XOFF character interrupt */
 #define MTK_UART_IER_RTSI	0x40	/* Enable RTS Modem status interrupt */
 #define MTK_UART_IER_CTSI	0x80	/* Enable CTS Modem status interrupt */
@@ -386,9 +387,18 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 static int __maybe_unused mtk8250_runtime_suspend(struct device *dev)
 {
 	struct mtk8250_data *data = dev_get_drvdata(dev);
+	struct uart_8250_port *up = serial8250_get_port(data->line);
 
-	clk_disable_unprepare(data->uart_clk);
-	clk_disable_unprepare(data->bus_clk);
+	/* wait until UART in idle status */
+	while
+		(serial_in(up, MTK_UART_DEBUG0));
+
+	if (data->clk_count == 0U) {
+		dev_dbg(dev, "%s clock count is 0\n", __func__);
+	} else {
+		clk_disable_unprepare(data->bus_clk);
+		data->clk_count--;
+	}
 
 	return 0;
 }
@@ -398,16 +408,16 @@ static int __maybe_unused mtk8250_runtime_resume(struct device *dev)
 	struct mtk8250_data *data = dev_get_drvdata(dev);
 	int err;
 
-	err = clk_prepare_enable(data->uart_clk);
-	if (err) {
-		dev_warn(dev, "Can't enable clock\n");
-		return err;
-	}
-
-	err = clk_prepare_enable(data->bus_clk);
-	if (err) {
-		dev_warn(dev, "Can't enable bus clock\n");
-		return err;
+	if (data->clk_count > 0U) {
+		dev_dbg(dev, "%s clock count is %d\n", __func__,
+			data->clk_count);
+	} else {
+		err = clk_prepare_enable(data->bus_clk);
+		if (err) {
+			dev_warn(dev, "Can't enable bus clock\n");
+			return err;
+		}
+		data->clk_count++;
 	}
 
 	return 0;
@@ -417,12 +427,14 @@ static int __maybe_unused mtk8250_runtime_resume(struct device *dev)
 mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
 {
 	if (!state)
-		pm_runtime_get_sync(port->dev);
+		if (!mtk8250_runtime_resume(port->dev))
+			pm_runtime_get_sync(port->dev);
 
 	serial8250_do_pm(port, state, old);
 
 	if (state)
-		pm_runtime_put_sync_suspend(port->dev);
+		if (!pm_runtime_put_sync_suspend(port->dev))
+			mtk8250_runtime_suspend(port->dev);
 }
 
 #ifdef CONFIG_SERIAL_8250_DMA
@@ -499,6 +511,8 @@ static int mtk8250_probe(struct platform_device *pdev)
 	if (!data)
 		return -ENOMEM;
 
+	data->clk_count = 0;
+
 	if (pdev->dev.of_node) {
 		err = mtk8250_probe_of(pdev, &uart.port, data);
 		if (err)
@@ -531,6 +545,7 @@ static int mtk8250_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, data);
 
+	pm_runtime_enable(&pdev->dev);
 	err = mtk8250_runtime_resume(&pdev->dev);
 	if (err)
 		return err;
@@ -539,9 +554,6 @@ static int mtk8250_probe(struct platform_device *pdev)
 	if (data->line < 0)
 		return data->line;
 
-	pm_runtime_set_active(&pdev->dev);
-	pm_runtime_enable(&pdev->dev);
-
 	return 0;
 }
 
@@ -552,11 +564,13 @@ static int mtk8250_remove(struct platform_device *pdev)
 	pm_runtime_get_sync(&pdev->dev);
 
 	serial8250_unregister_port(data->line);
-	mtk8250_runtime_suspend(&pdev->dev);
 
 	pm_runtime_disable(&pdev->dev);
 	pm_runtime_put_noidle(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		mtk8250_runtime_suspend(&pdev->dev);
+
 	return 0;
 }
 
-- 
1.8.1.1.dirty


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management
  2019-07-19  2:59 [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management Changqi Hu
@ 2019-07-19 11:16 ` Matthias Brugger
  2019-07-25  9:47 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Matthias Brugger @ 2019-07-19 11:16 UTC (permalink / raw)
  To: Changqi Hu, Greg Kroah-Hartman, Jiri Slaby
  Cc: Peter Shih, srv_heupstream, Gustavo A. R. Silva, linux-kernel,
	linux-mediatek, linux-serial, Yingjoe Chen, Eddie Huang,
	linux-arm-kernel



On 19/07/2019 04:59, Changqi Hu wrote:
> modify mtk uart runtime interface, add uart clock use count.
> merge patch v1 and patch v2 together.
> 

Please try to explain better why we need this.

> Signed-off-by: Changqi Hu <changqi.hu@mediatek.com>
> ---

Changelog from one version to another (like that you merged v1 and v2) should go
here, as we don't want that to be part of the commit message once the patch is
applied.

Regards,
Matthias

>  drivers/tty/serial/8250/8250_mtk.c | 50 ++++++++++++++++++++++++--------------
>  1 file changed, 32 insertions(+), 18 deletions(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
> index f470ded..a07c8ae 100644
> --- a/drivers/tty/serial/8250/8250_mtk.c
> +++ b/drivers/tty/serial/8250/8250_mtk.c
> @@ -31,6 +31,7 @@
>  #define MTK_UART_RXTRI_AD	0x14	/* RX Trigger address */
>  #define MTK_UART_FRACDIV_L	0x15	/* Fractional divider LSB address */
>  #define MTK_UART_FRACDIV_M	0x16	/* Fractional divider MSB address */
> +#define MTK_UART_DEBUG0	0x18
>  #define MTK_UART_IER_XOFFI	0x20	/* Enable XOFF character interrupt */
>  #define MTK_UART_IER_RTSI	0x40	/* Enable RTS Modem status interrupt */
>  #define MTK_UART_IER_CTSI	0x80	/* Enable CTS Modem status interrupt */
> @@ -386,9 +387,18 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
>  static int __maybe_unused mtk8250_runtime_suspend(struct device *dev)
>  {
>  	struct mtk8250_data *data = dev_get_drvdata(dev);
> +	struct uart_8250_port *up = serial8250_get_port(data->line);
>  
> -	clk_disable_unprepare(data->uart_clk);
> -	clk_disable_unprepare(data->bus_clk);
> +	/* wait until UART in idle status */
> +	while
> +		(serial_in(up, MTK_UART_DEBUG0));
> +
> +	if (data->clk_count == 0U) {
> +		dev_dbg(dev, "%s clock count is 0\n", __func__);
> +	} else {
> +		clk_disable_unprepare(data->bus_clk);
> +		data->clk_count--;
> +	}
>  
>  	return 0;
>  }
> @@ -398,16 +408,16 @@ static int __maybe_unused mtk8250_runtime_resume(struct device *dev)
>  	struct mtk8250_data *data = dev_get_drvdata(dev);
>  	int err;
>  
> -	err = clk_prepare_enable(data->uart_clk);
> -	if (err) {
> -		dev_warn(dev, "Can't enable clock\n");
> -		return err;
> -	}
> -
> -	err = clk_prepare_enable(data->bus_clk);
> -	if (err) {
> -		dev_warn(dev, "Can't enable bus clock\n");
> -		return err;
> +	if (data->clk_count > 0U) {
> +		dev_dbg(dev, "%s clock count is %d\n", __func__,
> +			data->clk_count);
> +	} else {
> +		err = clk_prepare_enable(data->bus_clk);
> +		if (err) {
> +			dev_warn(dev, "Can't enable bus clock\n");
> +			return err;
> +		}
> +		data->clk_count++;
>  	}
>  
>  	return 0;
> @@ -417,12 +427,14 @@ static int __maybe_unused mtk8250_runtime_resume(struct device *dev)
>  mtk8250_do_pm(struct uart_port *port, unsigned int state, unsigned int old)
>  {
>  	if (!state)
> -		pm_runtime_get_sync(port->dev);
> +		if (!mtk8250_runtime_resume(port->dev))
> +			pm_runtime_get_sync(port->dev);
>  
>  	serial8250_do_pm(port, state, old);
>  
>  	if (state)
> -		pm_runtime_put_sync_suspend(port->dev);
> +		if (!pm_runtime_put_sync_suspend(port->dev))
> +			mtk8250_runtime_suspend(port->dev);
>  }
>  
>  #ifdef CONFIG_SERIAL_8250_DMA
> @@ -499,6 +511,8 @@ static int mtk8250_probe(struct platform_device *pdev)
>  	if (!data)
>  		return -ENOMEM;
>  
> +	data->clk_count = 0;
> +
>  	if (pdev->dev.of_node) {
>  		err = mtk8250_probe_of(pdev, &uart.port, data);
>  		if (err)
> @@ -531,6 +545,7 @@ static int mtk8250_probe(struct platform_device *pdev)
>  
>  	platform_set_drvdata(pdev, data);
>  
> +	pm_runtime_enable(&pdev->dev);
>  	err = mtk8250_runtime_resume(&pdev->dev);
>  	if (err)
>  		return err;
> @@ -539,9 +554,6 @@ static int mtk8250_probe(struct platform_device *pdev)
>  	if (data->line < 0)
>  		return data->line;
>  
> -	pm_runtime_set_active(&pdev->dev);
> -	pm_runtime_enable(&pdev->dev);
> -
>  	return 0;
>  }
>  
> @@ -552,11 +564,13 @@ static int mtk8250_remove(struct platform_device *pdev)
>  	pm_runtime_get_sync(&pdev->dev);
>  
>  	serial8250_unregister_port(data->line);
> -	mtk8250_runtime_suspend(&pdev->dev);
>  
>  	pm_runtime_disable(&pdev->dev);
>  	pm_runtime_put_noidle(&pdev->dev);
>  
> +	if (!pm_runtime_status_suspended(&pdev->dev))
> +		mtk8250_runtime_suspend(&pdev->dev);
> +
>  	return 0;
>  }
>  
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management
  2019-07-19  2:59 [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management Changqi Hu
  2019-07-19 11:16 ` Matthias Brugger
@ 2019-07-25  9:47 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2019-07-25  9:47 UTC (permalink / raw)
  To: Changqi Hu
  Cc: Peter Shih, srv_heupstream, Gustavo A. R. Silva, linux-kernel,
	linux-mediatek, linux-serial, Jiri Slaby, Matthias Brugger,
	Yingjoe Chen, Eddie Huang, linux-arm-kernel

On Fri, Jul 19, 2019 at 10:59:42AM +0800, Changqi Hu wrote:
> modify mtk uart runtime interface, add uart clock use count.
> merge patch v1 and patch v2 together.
> 
> Signed-off-by: Changqi Hu <changqi.hu@mediatek.com>
> ---
>  drivers/tty/serial/8250/8250_mtk.c | 50 ++++++++++++++++++++++++--------------
>  1 file changed, 32 insertions(+), 18 deletions(-)

Always describe what changed from the previous versions in the area
below the --- line.

Also, your changelog needs a lot more work.  Please read the section
entitled "The canonical patch format" in the kernel file,
Documentation/SubmittingPatches for a description of how to do this.

thanks,

greg k-h's patch email bot

thanks,

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-25  9:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-19  2:59 [PATCH v3] serial: 8250-mtk: modify mtk uart power and clock management Changqi Hu
2019-07-19 11:16 ` Matthias Brugger
2019-07-25  9:47 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).