All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers
@ 2015-04-08 13:28 Pramod Gurav
  2015-04-08 13:28 ` [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed Pramod Gurav
  2015-04-08 23:31 ` [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Stephen Boyd
  0 siblings, 2 replies; 6+ messages in thread
From: Pramod Gurav @ 2015-04-08 13:28 UTC (permalink / raw)
  To: linux-arm-msm, linux-serial, linux-kernel
  Cc: gregkh, bryanh, sboyd, jslaby, Pramod Gurav

The bit masks for RFR_LEVEL1 and STALE_TIMEOUT_MSB values in MR1 and
IPR registers respectively are different for UART and UART_DM hardware
cores. We have been using UART core mask values for these. Add the same
for UART_DM core.

There is no bit setting as UART_IPR_RXSTALE_LAST for UART_DM core so do
it only for UART core.

Signed-off-by: Pramod Gurav <gpramod@codeaurora.org>

---
Changes since last version:
 - Added new macro fo UART_DM_MR1_AUTO_RFR_LEVEL1 instead of modifying existing.
 - Added a new macro for IPR register as it is also different in UART_DM
 - Changed subject line
 - Removed change log from message 

 drivers/tty/serial/msm_serial.c | 19 +++++++++++++++----
 drivers/tty/serial/msm_serial.h |  2 ++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index b73889c..4c1e9ea 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -432,8 +432,13 @@ static int msm_set_baud_rate(struct uart_port *port, unsigned int baud)
 	/* RX stale watermark */
 	rxstale = entry->rxstale;
 	watermark = UART_IPR_STALE_LSB & rxstale;
-	watermark |= UART_IPR_RXSTALE_LAST;
-	watermark |= UART_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
+	if (msm_port->is_uartdm)
+		watermark |= UART_DM_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
+	else {
+		watermark |= UART_IPR_RXSTALE_LAST;
+		watermark |= UART_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
+	}
+
 	msm_write(port, watermark, UART_IPR);
 
 	/* set RX watermark */
@@ -496,9 +501,15 @@ static int msm_startup(struct uart_port *port)
 
 	/* set automatic RFR level */
 	data = msm_read(port, UART_MR1);
-	data &= ~UART_MR1_AUTO_RFR_LEVEL1;
+	if (msm_port->is_uartdm) {
+		data &= ~UART_DM_MR1_AUTO_RFR_LEVEL1;
+		data |= UART_DM_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
+	} else {
+		data &= ~UART_MR1_AUTO_RFR_LEVEL1;
+		data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
+	}
+
 	data &= ~UART_MR1_AUTO_RFR_LEVEL0;
-	data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
 	data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level;
 	msm_write(port, data, UART_MR1);
 	return 0;
diff --git a/drivers/tty/serial/msm_serial.h b/drivers/tty/serial/msm_serial.h
index 3e1c713..caf5363 100644
--- a/drivers/tty/serial/msm_serial.h
+++ b/drivers/tty/serial/msm_serial.h
@@ -20,6 +20,7 @@
 
 #define UART_MR1_AUTO_RFR_LEVEL0	0x3F
 #define UART_MR1_AUTO_RFR_LEVEL1	0x3FF00
+#define UART_DM_MR1_AUTO_RFR_LEVEL1	0xFFFFFF00
 #define UART_MR1_RX_RDY_CTL    		(1 << 7)
 #define UART_MR1_CTS_CTL       		(1 << 6)
 
@@ -78,6 +79,7 @@
 #define UART_IPR_RXSTALE_LAST		0x20
 #define UART_IPR_STALE_LSB		0x1F
 #define UART_IPR_STALE_TIMEOUT_MSB	0x3FF80
+#define UART_DM_IPR_STALE_TIMEOUT_MSB	0xFFFFFF80
 
 #define UART_IPR	0x0018
 #define UART_TFWR	0x001C
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed
  2015-04-08 13:28 [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Pramod Gurav
@ 2015-04-08 13:28 ` Pramod Gurav
  2015-04-08 23:51   ` Stephen Boyd
  2015-04-08 23:31 ` [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Stephen Boyd
  1 sibling, 1 reply; 6+ messages in thread
From: Pramod Gurav @ 2015-04-08 13:28 UTC (permalink / raw)
  To: linux-arm-msm, linux-serial, linux-kernel
  Cc: gregkh, bryanh, sboyd, jslaby, Pramod Gurav

Disable the pclk when tty port is closed by user space.

Signed-off-by: Pramod Gurav <gpramod@codeaurora.org>
---
 drivers/tty/serial/msm_serial.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
index 4c1e9ea..f38565c 100644
--- a/drivers/tty/serial/msm_serial.c
+++ b/drivers/tty/serial/msm_serial.c
@@ -523,6 +523,7 @@ static void msm_shutdown(struct uart_port *port)
 	msm_write(port, 0, UART_IMR); /* disable interrupts */
 
 	clk_disable_unprepare(msm_port->clk);
+	clk_disable_unprepare(msm_port->pclk);
 
 	free_irq(port->irq, port);
 }
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers
  2015-04-08 13:28 [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Pramod Gurav
  2015-04-08 13:28 ` [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed Pramod Gurav
@ 2015-04-08 23:31 ` Stephen Boyd
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2015-04-08 23:31 UTC (permalink / raw)
  To: Pramod Gurav, linux-arm-msm, linux-serial, linux-kernel
  Cc: gregkh, bryanh, jslaby

On 04/08/15 06:28, Pramod Gurav wrote:
> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> index b73889c..4c1e9ea 100644
> --- a/drivers/tty/serial/msm_serial.c
> +++ b/drivers/tty/serial/msm_serial.c
> @@ -432,8 +432,13 @@ static int msm_set_baud_rate(struct uart_port *port, unsigned int baud)
>  	/* RX stale watermark */
>  	rxstale = entry->rxstale;
>  	watermark = UART_IPR_STALE_LSB & rxstale;
> -	watermark |= UART_IPR_RXSTALE_LAST;
> -	watermark |= UART_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
> +	if (msm_port->is_uartdm)
> +		watermark |= UART_DM_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
> +	else {
> +		watermark |= UART_IPR_RXSTALE_LAST;
> +		watermark |= UART_IPR_STALE_TIMEOUT_MSB & (rxstale << 2);
> +	}
> +
>  	msm_write(port, watermark, UART_IPR);
>  

This could be written like so:

if (msm_port->is_uartdm) {
	mask = UART_DM_IPR_STALE_TIMEOUT_MSB;
} else {
	watermark |= UART_IPR_RXSTALE_LAST;
	mask = UART_IPR_STALE_TIMEOUT_MSB;
}

watermark |= mask & (rxstale << 2);

so that we don't duplicate the rfr_level << 2 part.

>  	/* set RX watermark */
> @@ -496,9 +501,15 @@ static int msm_startup(struct uart_port *port)
>  
>  	/* set automatic RFR level */
>  	data = msm_read(port, UART_MR1);
> -	data &= ~UART_MR1_AUTO_RFR_LEVEL1;
> +	if (msm_port->is_uartdm) {
> +		data &= ~UART_DM_MR1_AUTO_RFR_LEVEL1;
> +		data |= UART_DM_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
> +	} else {
> +		data &= ~UART_MR1_AUTO_RFR_LEVEL1;
> +		data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
> +	}
> +
>  	data &= ~UART_MR1_AUTO_RFR_LEVEL0;
> -	data |= UART_MR1_AUTO_RFR_LEVEL1 & (rfr_level << 2);
>  	data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level;
>  	msm_write(port, data, UART_MR1);
>  	return 0;

This could be written like so:

if (msm_port->is_uartdm)
	mask = UART_DM_MR1_AUTO_RFR_LEVEL1;
else
	mask = UART_MR1_AUTO_RFR_LEVE1;

data &= ~mask;
data &= ~UART_MR1_AUTO_RFR_LEVEL0;
data |= mask & (rfr_level << 2);
data |= UART_MR1_AUTO_RFR_LEVEL0 & rfr_level;

so that we don't duplicate the rfr_level << 2 part.

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed
  2015-04-08 13:28 ` [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed Pramod Gurav
@ 2015-04-08 23:51   ` Stephen Boyd
  2015-04-09  5:36     ` Pramod Gurav
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2015-04-08 23:51 UTC (permalink / raw)
  To: Pramod Gurav, linux-arm-msm, linux-serial, linux-kernel
  Cc: gregkh, bryanh, jslaby

On 04/08/15 06:28, Pramod Gurav wrote:
> Disable the pclk when tty port is closed by user space.
>
> Signed-off-by: Pramod Gurav <gpramod@codeaurora.org>
> ---
>  drivers/tty/serial/msm_serial.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
> index 4c1e9ea..f38565c 100644
> --- a/drivers/tty/serial/msm_serial.c
> +++ b/drivers/tty/serial/msm_serial.c
> @@ -523,6 +523,7 @@ static void msm_shutdown(struct uart_port *port)
>  	msm_write(port, 0, UART_IMR); /* disable interrupts */
>  
>  	clk_disable_unprepare(msm_port->clk);
> +	clk_disable_unprepare(msm_port->pclk);
>  
>  	free_irq(port->irq, port);
>  }

It's not clear to me at all when this clock is enabled and when it's
disabled during the lifetime of this driver. For example, why do we have
a .pm op to turn clocks on and off? Shouldn't they already be on? Can
you please explain when the clocks are turned on and off and what
userspace actions cause that to happen? Looking at drivers like
amba-pl010.c I don't see any .pm op, just a
clk_prepare_enable/clk_disable_unprepare pair in the startup and
shutdown ops.

Minus my confusion of why our clocking is complicated, it looks correct
to me to do this, so

Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed
  2015-04-08 23:51   ` Stephen Boyd
@ 2015-04-09  5:36     ` Pramod Gurav
  2015-04-09 14:04       ` Stephen Boyd
  0 siblings, 1 reply; 6+ messages in thread
From: Pramod Gurav @ 2015-04-09  5:36 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Pramod Gurav, linux-arm-msm, linux-serial, linux-kernel, gregkh,
	bryanh, jslaby


On Thu, April 9, 2015 5:21 am, Stephen Boyd wrote:
> On 04/08/15 06:28, Pramod Gurav wrote:
>> Disable the pclk when tty port is closed by user space.
>>
>> Signed-off-by: Pramod Gurav <gpramod@codeaurora.org>
>> ---
>>  drivers/tty/serial/msm_serial.c | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/drivers/tty/serial/msm_serial.c
>> b/drivers/tty/serial/msm_serial.c
>> index 4c1e9ea..f38565c 100644
>> --- a/drivers/tty/serial/msm_serial.c
>> +++ b/drivers/tty/serial/msm_serial.c
>> @@ -523,6 +523,7 @@ static void msm_shutdown(struct uart_port *port)
>>  	msm_write(port, 0, UART_IMR); /* disable interrupts */
>>
>>  	clk_disable_unprepare(msm_port->clk);
>> +	clk_disable_unprepare(msm_port->pclk);
>>
>>  	free_irq(port->irq, port);
>>  }
>
> It's not clear to me at all when this clock is enabled and when it's
> disabled during the lifetime of this driver. For example, why do we have
> a .pm op to turn clocks on and off? Shouldn't they already be on? Can
> you please explain when the clocks are turned on and off and what
> userspace actions cause that to happen? Looking at drivers like
> amba-pl010.c I don't see any .pm op, just a
> clk_prepare_enable/clk_disable_unprepare pair in the startup and
> shutdown ops.


When a userspce opens a serial port the uart_startup (in serial_core)
function is executed which changes the uart_pm state to UART_PM_STATE_ON.
So when this port is release/closed by the application
uart_close(serial_core) changes the uart_pm state to UART_PM_STATE_OFF if
its not console. But it is not done in uart_shutdown function.

So ideally clk_prepare_enable/clk_disable_unprepare must be called in .pm
only. So, we can get rid of these operations from msm_startup function as
these will be called anyway using .pm ops.

About .pm in uart_ops, there are few drivers which have it for an example,
atmel_serial, sh-sci etc. That is where they do
clk_prepare_enable/clk_disable_unprepare. And moreover when there is
suspend across system these function will handled through .pm.


>
> Minus my confusion of why our clocking is complicated, it looks correct
> to me to do this, so
>
> Reviewed-by: Stephen Boyd <sboyd@codeaurora.org>

>
> --
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
>

Pramod

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

* Re: [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed
  2015-04-09  5:36     ` Pramod Gurav
@ 2015-04-09 14:04       ` Stephen Boyd
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Boyd @ 2015-04-09 14:04 UTC (permalink / raw)
  To: Pramod Gurav
  Cc: linux-arm-msm, linux-serial, linux-kernel, gregkh, bryanh, jslaby

On 04/09, Pramod Gurav wrote:
> 
> On Thu, April 9, 2015 5:21 am, Stephen Boyd wrote:
> >
> > It's not clear to me at all when this clock is enabled and when it's
> > disabled during the lifetime of this driver. For example, why do we have
> > a .pm op to turn clocks on and off? Shouldn't they already be on? Can
> > you please explain when the clocks are turned on and off and what
> > userspace actions cause that to happen? Looking at drivers like
> > amba-pl010.c I don't see any .pm op, just a
> > clk_prepare_enable/clk_disable_unprepare pair in the startup and
> > shutdown ops.
> 
> 
> When a userspce opens a serial port the uart_startup (in serial_core)
> function is executed which changes the uart_pm state to UART_PM_STATE_ON.
> So when this port is release/closed by the application
> uart_close(serial_core) changes the uart_pm state to UART_PM_STATE_OFF if
> its not console. But it is not done in uart_shutdown function.
> 
> So ideally clk_prepare_enable/clk_disable_unprepare must be called in .pm
> only. So, we can get rid of these operations from msm_startup function as
> these will be called anyway using .pm ops.
> 
> About .pm in uart_ops, there are few drivers which have it for an example,
> atmel_serial, sh-sci etc. That is where they do
> clk_prepare_enable/clk_disable_unprepare. And moreover when there is
> suspend across system these function will handled through .pm.

Ok. If the .pm op is called at the right time then it seems to be
possible to drop the clock operations from startup/shutdown. Do
other drivers hook the .pm op to do runtime PM as well? Because
it would be nice to move this driver to use runtime PM sometime
in the future as well. 

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project

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

end of thread, other threads:[~2015-04-09 14:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-08 13:28 [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Pramod Gurav
2015-04-08 13:28 ` [PATCH v2 2/2] tty: serial: msm: Disable pclk when port is closed Pramod Gurav
2015-04-08 23:51   ` Stephen Boyd
2015-04-09  5:36     ` Pramod Gurav
2015-04-09 14:04       ` Stephen Boyd
2015-04-08 23:31 ` [PATCH v2 1/2] tty: serial: msm: Add mask value for UART_DM registers Stephen Boyd

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.