diff mbox

[V2] serial: imx: enable the clocks only when the uart is used

Message ID 1370311173-15019-1-git-send-email-b32955@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Huang Shijie June 4, 2013, 1:59 a.m. UTC
Current code opens the clocks when the uart driver is probed.
This will wastes some power if several uarts are enabled, but not really
used.

So close these clocks for uart, and enable the clocks only when
the uart is used.

Signed-off-by: Huang Shijie <b32955@freescale.com>
---
v1 --> v2:
	check the return value of clk_prepare_enable().
---
 drivers/tty/serial/imx.c |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

Comments

Shawn Guo June 8, 2013, 6:01 a.m. UTC | #1
On Tue, Jun 04, 2013 at 09:59:33AM +0800, Huang Shijie wrote:
> Current code opens the clocks when the uart driver is probed.
> This will wastes some power if several uarts are enabled, but not really
> used.
> 
> So close these clocks for uart, and enable the clocks only when
> the uart is used.
> 
> Signed-off-by: Huang Shijie <b32955@freescale.com>

Running linux-next 20130607, I just found that the serial console stops
working due to this patch.  I think the clocks need to be enabled for
console as well.

Shawn

> ---
> v1 --> v2:
> 	check the return value of clk_prepare_enable().
> ---
>  drivers/tty/serial/imx.c |   17 ++++++++++++++---
>  1 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
> index 72bc1db..7cc4810 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -699,6 +699,14 @@ static int imx_startup(struct uart_port *port)
>  	int retval;
>  	unsigned long flags, temp;
>  
> +	retval = clk_prepare_enable(sport->clk_per);
> +	if (retval)
> +		goto error_out1;
> +
> +	retval = clk_prepare_enable(sport->clk_ipg);
> +	if (retval)
> +		goto error_out1;
> +
>  	imx_setup_ufcr(sport, 0);
>  
>  	/* disable the DREN bit (Data Ready interrupt enable) before
> @@ -884,6 +892,9 @@ static void imx_shutdown(struct uart_port *port)
>  
>  	writel(temp, sport->port.membase + UCR1);
>  	spin_unlock_irqrestore(&sport->port.lock, flags);
> +
> +	clk_disable_unprepare(sport->clk_per);
> +	clk_disable_unprepare(sport->clk_ipg);
>  }
>  
>  static void
> @@ -1557,6 +1568,9 @@ static int serial_imx_probe(struct platform_device *pdev)
>  		goto deinit;
>  	platform_set_drvdata(pdev, sport);
>  
> +	clk_disable_unprepare(sport->clk_per);
> +	clk_disable_unprepare(sport->clk_ipg);
> +
>  	return 0;
>  deinit:
>  	if (pdata && pdata->exit)
> @@ -1578,9 +1592,6 @@ static int serial_imx_remove(struct platform_device *pdev)
>  
>  	uart_remove_one_port(&imx_reg, &sport->port);
>  
> -	clk_disable_unprepare(sport->clk_per);
> -	clk_disable_unprepare(sport->clk_ipg);
> -
>  	if (pdata && pdata->exit)
>  		pdata->exit(pdev);
>  
> -- 
> 1.7.1
> 
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Huang Shijie June 8, 2013, 6:22 a.m. UTC | #2
? 2013?06?08? 14:01, Shawn Guo ??:
> Running linux-next 20130607, I just found that the serial console stops
> working due to this patch.  I think the clocks need to be enabled for
> console as well.
could you tell me the board?
i tested on imx6q-sabreauto boards, the console is ok.

thanks
Huang Shijie
Shawn Guo June 8, 2013, 6:23 a.m. UTC | #3
On Sat, Jun 08, 2013 at 02:22:39PM +0800, Huang Shijie wrote:
> ? 2013?06?08? 14:01, Shawn Guo ??:
> >Running linux-next 20130607, I just found that the serial console stops
> >working due to this patch.  I think the clocks need to be enabled for
> >console as well.
> could you tell me the board?
> i tested on imx6q-sabreauto boards, the console is ok.

imx6q-sabresd

Shawn
Russell King - ARM Linux June 8, 2013, 8:15 a.m. UTC | #4
On Sat, Jun 08, 2013 at 02:22:39PM +0800, Huang Shijie wrote:
> ? 2013?06?08? 14:01, Shawn Guo ??:
>> Running linux-next 20130607, I just found that the serial console stops
>> working due to this patch.  I think the clocks need to be enabled for
>> console as well.
> could you tell me the board?
> i tested on imx6q-sabreauto boards, the console is ok.

Take a look at amba-pl011.c to see how to deal with the console and clk API
correctly in serial drivers.
Alexander Shiyan June 8, 2013, 11:56 a.m. UTC | #5
> On Sat, Jun 08, 2013 at 02:22:39PM +0800, Huang Shijie wrote:
> > ? 2013?06?08? 14:01, Shawn Guo ??:
> > >Running linux-next 20130607, I just found that the serial console stops
> > >working due to this patch.  I think the clocks need to be enabled for
> > >console as well.
> > could you tell me the board?
> > i tested on imx6q-sabreauto boards, the console is ok.
> 
> imx6q-sabresd

I confirm that console not work correct after this patch on the i.MX27 PCM038 board.

---
diff mbox

Patch

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 72bc1db..7cc4810 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -699,6 +699,14 @@  static int imx_startup(struct uart_port *port)
 	int retval;
 	unsigned long flags, temp;
 
+	retval = clk_prepare_enable(sport->clk_per);
+	if (retval)
+		goto error_out1;
+
+	retval = clk_prepare_enable(sport->clk_ipg);
+	if (retval)
+		goto error_out1;
+
 	imx_setup_ufcr(sport, 0);
 
 	/* disable the DREN bit (Data Ready interrupt enable) before
@@ -884,6 +892,9 @@  static void imx_shutdown(struct uart_port *port)
 
 	writel(temp, sport->port.membase + UCR1);
 	spin_unlock_irqrestore(&sport->port.lock, flags);
+
+	clk_disable_unprepare(sport->clk_per);
+	clk_disable_unprepare(sport->clk_ipg);
 }
 
 static void
@@ -1557,6 +1568,9 @@  static int serial_imx_probe(struct platform_device *pdev)
 		goto deinit;
 	platform_set_drvdata(pdev, sport);
 
+	clk_disable_unprepare(sport->clk_per);
+	clk_disable_unprepare(sport->clk_ipg);
+
 	return 0;
 deinit:
 	if (pdata && pdata->exit)
@@ -1578,9 +1592,6 @@  static int serial_imx_remove(struct platform_device *pdev)
 
 	uart_remove_one_port(&imx_reg, &sport->port);
 
-	clk_disable_unprepare(sport->clk_per);
-	clk_disable_unprepare(sport->clk_ipg);
-
 	if (pdata && pdata->exit)
 		pdata->exit(pdev);