Skip to contentSkip to conversation

xen/arm: drivers: scif: Remove dead code

PATCH Superseded Dirk Behme 3 participants 14 messages Jun 21, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Dirk Behme

author
#0 lore raw

PATCH 1/3 xen/arm: drivers: scif: Remove dead code

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
 xen/drivers/char/scif-uart.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +6 -17
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
     scif_writew(uart, SCIF_SCSMR, val);
 
     ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input) */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
     /* Setup trigger level for TX/RX FIFOs */
     scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);
Signature · 7 lines
2.8.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#1 lore raw

PATCH 2/3 xen/arm: drivers: scif: Remove unused variables

The two struct members baud and clock_hz are in the end read only variables nowhere used for anything useful. Removing them makes the code much simpler without changing any functionality.

---
 xen/drivers/char/scif-uart.c    | 13 +------------
 xen/include/asm-arm/scif-uart.h |  1 -
 2 files changed, 1 insertion(+), 13 deletions(-)
xen/drivers/char/scif-uart.c +1 -12
index ca88c0f..bc157fe 100644
@@ -41,7 +41,7 @@
 #define scif_writew(uart, off, val)    writew((val), (uart)->regs + (off))
 
 static struct scif_uart {
-    unsigned int baud, clock_hz, data_bits, parity, stop_bits;
+    unsigned int data_bits, parity, stop_bits;
     unsigned int irq;
     char __iomem *regs;
     struct irqaction irqaction;
@@ -87,7 +87,6 @@ static void scif_uart_interrupt(int irq, void *data, struct cpu_user_regs *regs)
 static void __init scif_uart_init_preirq(struct serial_port *port)
 {
     struct scif_uart *uart = port->uart;
-    unsigned int divisor;
     uint16_t val;
 
     /*
@@ -142,14 +141,6 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
     }
     scif_writew(uart, SCIF_SCSMR, val);
 
-    ASSERT( uart->clock_hz > 0 );
-    ASSERT( uart->baud == BAUD_AUTO );
-
-    /* Read current Baud rate */
-    divisor = scif_readw(uart, SCIF_DL);
-    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-    uart->baud = uart->clock_hz / (divisor << 4);
-
     /* Setup trigger level for TX/RX FIFOs */
     scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);
 
@@ -292,8 +283,6 @@ static int __init scif_uart_init(struct dt_device_node *dev,
 
     uart = &scif_com;
 
-    uart->clock_hz  = SCIF_CLK_FREQ;
-    uart->baud      = BAUD_AUTO;
     uart->data_bits = 8;
     uart->parity    = PARITY_NONE;
     uart->stop_bits = 1;
xen/include/asm-arm/scif-uart.h +0 -1
index 7a9f639..d030b26 100644
@@ -22,7 +22,6 @@
 #define __ASM_ARM_SCIF_UART_H
 
 #define SCIF_FIFO_MAX_SIZE    16
-#define SCIF_CLK_FREQ         14745600
 
 /* Register offsets */
 #define SCIF_SCSMR     (0x00)    /* Serial mode register           */
Signature · 7 lines
2.8.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#2 lore raw

Re: [PATCH 2/3] xen/arm: drivers: scif: Remove unused variables

Hello Dirk,

Quoted 3 lines · Dirk Behme

The two struct members baud and clock_hz are in the end read only variables nowhere used for anything useful. Removing them makes the code much simpler without changing any functionality.

From my understanding, this patch is removing code you just added on the previous patch. I would prefer if you squash this patch into #1.

Regards,

Quoted 65 lines
---
  xen/drivers/char/scif-uart.c    | 13 +------------
  xen/include/asm-arm/scif-uart.h |  1 -
  2 files changed, 1 insertion(+), 13 deletions(-)
xen/drivers/char/scif-uart.c +1 -12
index ca88c0f..bc157fe 100644
@@ -41,7 +41,7 @@
  #define scif_writew(uart, off, val)    writew((val), (uart)->regs + (off))
 
  static struct scif_uart {
-    unsigned int baud, clock_hz, data_bits, parity, stop_bits;
+    unsigned int data_bits, parity, stop_bits;
      unsigned int irq;
      char __iomem *regs;
      struct irqaction irqaction;
@@ -87,7 +87,6 @@ static void scif_uart_interrupt(int irq, void *data, struct cpu_user_regs *regs)
  static void __init scif_uart_init_preirq(struct serial_port *port)
  {
      struct scif_uart *uart = port->uart;
-    unsigned int divisor;
      uint16_t val;
 
      /*
@@ -142,14 +141,6 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
      }
      scif_writew(uart, SCIF_SCSMR, val);
 
-    ASSERT( uart->clock_hz > 0 );
-    ASSERT( uart->baud == BAUD_AUTO );
-
-    /* Read current Baud rate */
-    divisor = scif_readw(uart, SCIF_DL);
-    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-    uart->baud = uart->clock_hz / (divisor << 4);
-
      /* Setup trigger level for TX/RX FIFOs */
      scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);
 
@@ -292,8 +283,6 @@ static int __init scif_uart_init(struct dt_device_node *dev,
 
      uart = &scif_com;
 
-    uart->clock_hz  = SCIF_CLK_FREQ;
-    uart->baud      = BAUD_AUTO;
      uart->data_bits = 8;
      uart->parity    = PARITY_NONE;
      uart->stop_bits = 1;
xen/include/asm-arm/scif-uart.h +0 -1
index 7a9f639..d030b26 100644
@@ -22,7 +22,6 @@
  #define __ASM_ARM_SCIF_UART_H
 
  #define SCIF_FIFO_MAX_SIZE    16
-#define SCIF_CLK_FREQ         14745600
 
  /* Register offsets */
  #define SCIF_SCSMR     (0x00)    /* Serial mode register           */
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#3 lore raw

PATCH 3/3 xen/arm: drivers: scif: Add clock auto detection

In reply to Dirk Behme

Besides the 14MHz external clock, the SCIF might be clocked by an internal 66MHz clock. Detect this clock based on the SCIF_DL register being 0 (internal clock) or != 0 (external clock).

---
 xen/drivers/char/scif-uart.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
xen/drivers/char/scif-uart.c +13 -2
index bc157fe..678f46b 100644
@@ -107,8 +107,19 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
     scif_readw(uart, SCIF_SCLSR);
     scif_writew(uart, SCIF_SCLSR, 0);
 
-    /* Select Baud rate generator output as a clock source */
-    scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);
+    /*
+     * Select Baud rate generator output as a clock source
+     * The clock source can be an internal or external clock.
+     * Depending on this the DL register is either 0 or contains
+     * the divisor. I.e. we can use this to detect the clock
+     * source and based on this can configure the CKE[1:0] bits
+     * of the SCSCR register.
+     */
+    if ( scif_readw(uart, SCIF_DL) )
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10); /* External clk */
+    else
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE00); /* Internal clk */
+
 
     /* Setup protocol format and Baud rate, select Asynchronous mode */
     val = 0;
Signature · 7 lines
2.8.0


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

Re: [PATCH 3/3] xen/arm: drivers: scif: Add clock auto detection

Hello Dirk,

Quoted 3 lines · Dirk Behme

Besides the 14MHz external clock, the SCIF might be clocked by an internal 66MHz clock. Detect this clock based on the SCIF_DL register being 0 (internal clock) or != 0 (external clock).

Do you have a public link to the specification?

Quoted 17 lines
---
  xen/drivers/char/scif-uart.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
xen/drivers/char/scif-uart.c +2 -2
index bc157fe..678f46b 100644
@@ -107,8 +107,19 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
      scif_readw(uart, SCIF_SCLSR);
      scif_writew(uart, SCIF_SCLSR, 0);
 
-    /* Select Baud rate generator output as a clock source */
-    scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);
+    /*
+     * Select Baud rate generator output as a clock source

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 121

Quoted 10 lines
xen/drivers/char/scif-uart.c +10 -0
+     * The clock source can be an internal or external clock.
+     * Depending on this the DL register is either 0 or contains
+     * the divisor. I.e. we can use this to detect the clock
+     * source and based on this can configure the CKE[1:0] bits
+     * of the SCSCR register.
+     */
+    if ( scif_readw(uart, SCIF_DL) )
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10); /* External clk */
+    else
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE00); /* Internal clk */

Why would we need to select the baud rate generator if the baud has been configured by the firmware?

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 122

Quoted 1 line
xen/drivers/char/scif-uart.c +1 -0
+

Please drop this newline.

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port)

Quoted 4 lines
xen/drivers/char/scif-uart.c +0 -0
      /* Setup protocol format and Baud rate, select Asynchronous mode */
      val = 0;
 

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#5 lore raw

Re: [PATCH 3/3] xen/arm: drivers: scif: Add clock auto detection

Hi Julien,

Quoted 8 lines · Julien Grall

Hello Dirk,

Quoted 3 lines · Dirk Behme

Besides the 14MHz external clock, the SCIF might be clocked by an internal 66MHz clock. Detect this clock based on the SCIF_DL register being 0 (internal clock) or != 0 (external clock).

Do you have a public link to the specification?

I have to check this ;)

Quoted 23 lines
Quoted 23 lines
---
  xen/drivers/char/scif-uart.c | 15 +++++++++++++--
  1 file changed, 13 insertions(+), 2 deletions(-)
xen/drivers/char/scif-uart.c +7 -2
index bc157fe..678f46b 100644
@@ -107,8 +107,19 @@ static void __init scif_uart_init_preirq(struct
 serial_port *port)
      scif_readw(uart, SCIF_SCLSR);
      scif_writew(uart, SCIF_SCLSR, 0);
 
-    /* Select Baud rate generator output as a clock source */
-    scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);
+    /*
+     * Select Baud rate generator output as a clock source
+     * The clock source can be an internal or external clock.
+     * Depending on this the DL register is either 0 or contains
+     * the divisor. I.e. we can use this to detect the clock
+     * source and based on this can configure the CKE[1:0] bits
+     * of the SCSCR register.
Quoted 8 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 121

Quoted 5 lines
xen/drivers/char/scif-uart.c +5 -0
+     */
+    if ( scif_readw(uart, SCIF_DL) )
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10); /* External clk */
+    else
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE00); /* Internal clk */

Why would we need to select the baud rate generator if the baud has been configured by the firmware?

Just to get the correct understanding: The proposal is to just remove the code which (wrongly) overwrites the correct settings done by the firmware?

I.e. instead of doing the same thing the firmware is already doing, again (the if .. else ), the proposal is simply dropping the

- /* Select Baud rate generator output as a clock source */
- scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);

?

Best regards

Dirk

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH 3/3] xen/arm: drivers: scif: Add clock auto detection

Quoted 32 lines · Dirk Behme
Quoted 18 lines
Quoted 18 lines
xen/drivers/char/scif-uart.c +7 -2
index bc157fe..678f46b 100644
@@ -107,8 +107,19 @@ static void __init scif_uart_init_preirq(struct
 serial_port *port)
      scif_readw(uart, SCIF_SCLSR);
      scif_writew(uart, SCIF_SCLSR, 0);
 
-    /* Select Baud rate generator output as a clock source */
-    scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);
+    /*
+     * Select Baud rate generator output as a clock source
+     * The clock source can be an internal or external clock.
+     * Depending on this the DL register is either 0 or contains
+     * the divisor. I.e. we can use this to detect the clock
+     * source and based on this can configure the CKE[1:0] bits
+     * of the SCSCR register.
Quoted 8 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 121

Quoted 5 lines
xen/drivers/char/scif-uart.c +5 -0
+     */
+    if ( scif_readw(uart, SCIF_DL) )
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10); /* External clk */
+    else
+        scif_writew(uart, SCIF_SCSCR, SCSCR_CKE00); /* Internal clk */

Why would we need to select the baud rate generator if the baud has been configured by the firmware?

Just to get the correct understanding: The proposal is to just remove the code which (wrongly) overwrites the correct settings done by the firmware?

Quoted 8 lines

I.e. instead of doing the same thing the firmware is already doing, again (the if .. else ), the proposal is simply dropping the

- /* Select Baud rate generator output as a clock source */
- scif_writew(uart, SCIF_SCSCR, SCSCR_CKE10);

?

Yes. However I don't have any spec in hand so I am not sure if it is correct.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#7 lore raw
In reply to Dirk Behme

Hi, Dirk.

Quoted 16 lines · Dirk Behme

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
 xen/drivers/char/scif-uart.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +0 -0
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
     scif_writew(uart, SCIF_SCSMR, val);
 

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 154

Quoted 10 lines
xen/drivers/char/scif-uart.c +0 -9
     ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input) */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);

This part of code might be used for people who are not satisfied with default baudrate which has been set in U-Boot.
If we remove this we will take away the opportunity to just change uart->baud from BAUD_AUTO to desired one.

Quoted 20 lines
xen/drivers/char/scif-uart.c +6 -9
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
     /* Setup trigger level for TX/RX FIFOs */
     scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);
--

2.8.0

Signature · 8 lines
Oleksandr Tyshchenko | Embedded Dev
GlobalLogic
www.globallogic.com

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#8 lore raw
Quoted 1 line · Oleksandr Tyshchenko

Hi, Dirk.

Hello Oleksandr,

Quoted 17 lines · Dirk Behme
Quoted 16 lines

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
  xen/drivers/char/scif-uart.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +0 -0
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct serial_port *port)
      scif_writew(uart, SCIF_SCSMR, val);
 
Quoted 13 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 154

Quoted 10 lines
xen/drivers/char/scif-uart.c +0 -9
      ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input) */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);

This part of code might be used for people who are not satisfied with default baudrate which has been set in U-Boot.

Can you elaborate? If the baud rate is different, it will not be possible to get output from U-boot.

Quoted 2 lines

If we remove this we will take away the opportunity to just change uart->baud from BAUD_AUTO to desired one.

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

I would rather avoid to keep dead code (or not accessible without hacking Xen). For what is worth, we recently removed a similar code from the PL011 driver as this should be correctly configured by the firmware.

Quoted 15 lines
Quoted 15 lines
xen/drivers/char/scif-uart.c +6 -8
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
Quoted 5 lines
Quoted 5 lines
xen/drivers/char/scif-uart.c +0 -1
      /* Setup trigger level for TX/RX FIFOs */
      scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);
--

2.8.0

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#9 lore raw
Quoted 8 lines · Julien Grall
Quoted 2 lines · Oleksandr Tyshchenko

Hi, Dirk.

Hello Oleksandr,

Hello Julien.

Quoted 42 lines
Quoted 22 lines
Quoted 18 lines · Dirk Behme

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
  xen/drivers/char/scif-uart.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +0 -0
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct
 serial_port *port)
      scif_writew(uart, SCIF_SCSMR, val);
 
Quoted 15 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 154

Quoted 11 lines
xen/drivers/char/scif-uart.c +0 -9
      ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input)
 */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);

This part of code might be used for people who are not satisfied with default baudrate which has been set in U-Boot.

Can you elaborate? If the baud rate is different, it will not be possible to get output from U-boot.

Quoted 7 lines
Quoted 2 lines

If we remove this we will take away the opportunity to just change uart->baud from BAUD_AUTO to desired one.

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

No.

This driver has been initially written for Renesas Lager board based on R-Car H2 SoC which
has SCIF compatible UART. And the current code is valid for it. I have tested both auto and
variable (38400, 115200) baudrates.
But, I am afraid that current code won't be suitable for all of the boards which have the same UART IP. It depends at least from clock source
(external/internal) and clock frequency.

Quoted 30 lines

I would rather avoid to keep dead code (or not accessible without hacking Xen). For what is worth, we recently removed a similar code from the PL011 driver as this should be correctly configured by the firmware.

Quoted 15 lines
Quoted 15 lines
xen/drivers/char/scif-uart.c +6 -8
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
Quoted 5 lines
Quoted 5 lines
      /* Setup trigger level for TX/RX FIFOs */
      scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);

--
2.8.0

Regards,

--
Julien Grall

Signature · 8 lines
Oleksandr Tyshchenko | Embedded Dev
GlobalLogic
www.globallogic.com

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
author
#10 lore raw

Hello Oleksandr,

Quoted 61 lines · Oleksandr Tyshchenko
Quoted 8 lines · Julien Grall
Quoted 2 lines · Oleksandr Tyshchenko

Hi, Dirk.

Hello Oleksandr,

Hello Julien.

Quoted 42 lines
Quoted 22 lines
Quoted 18 lines · Dirk Behme

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
  xen/drivers/char/scif-uart.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +0 -0
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct
 serial_port *port)
      scif_writew(uart, SCIF_SCSMR, val);
 
Quoted 15 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 154

Quoted 11 lines
xen/drivers/char/scif-uart.c +0 -9
      ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input)
 */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);

This part of code might be used for people who are not satisfied with default baudrate which has been set in U-Boot.

Can you elaborate? If the baud rate is different, it will not be possible to get output from U-boot.

Quoted 7 lines
Quoted 2 lines

If we remove this we will take away the opportunity to just change uart->baud from BAUD_AUTO to desired one.

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

Quoted 7 lines

No.

This driver has been initially written for Renesas Lager board based on R-Car H2 SoC which
has SCIF compatible UART. And the current code is valid for it. I have tested both auto and
variable (38400, 115200) baudrates.

Could you help me a little to understand this?

The driver has

scif_uart_init()
{
...
struct scif_uart *uart;
...
uart->baud = BAUD_AUTO;
...
}

I checked the code for struct scif_uart but it isn't used anywhere outside this driver. So uart->baud is a driver local variable, which looks to me isn't used anywhere useful.

What have I missed?

Best regards

Dirk

Quoted 32 lines

But, I am afraid that current code won't be suitable for all of the boards which have the same UART IP. It depends at least from clock source
(external/internal) and clock frequency.

Quoted 27 lines

I would rather avoid to keep dead code (or not accessible without hacking Xen). For what is worth, we recently removed a similar code from the PL011 driver as this should be correctly configured by the firmware.

Quoted 15 lines
Quoted 15 lines
xen/drivers/char/scif-uart.c +6 -8
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
Quoted 5 lines
Quoted 5 lines
      /* Setup trigger level for TX/RX FIFOs */
      scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);

--
2.8.0

Regards,

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#11 lore raw
Quoted 103 lines · Dirk Behme

Hello Oleksandr,

Quoted 76 lines · Oleksandr Tyshchenko
Quoted 11 lines · Julien Grall
Quoted 3 lines · Oleksandr Tyshchenko

Hi, Dirk.

Hello Oleksandr,

Hello Julien.

Quoted 49 lines
Quoted 26 lines
Quoted 21 lines · Dirk Behme

In scif_uart_init() uart->baud is set to BAUD_AUTO. So its a basic error
if this is different later. Detect this by an ASSERT, but remove the dead code normally never reached.

---
  xen/drivers/char/scif-uart.c | 23 ++++++-----------------
  1 file changed, 6 insertions(+), 17 deletions(-)
xen/drivers/char/scif-uart.c +0 -0
index 51a2233..ca88c0f 100644
@@ -143,23 +143,12 @@ static void __init scif_uart_init_preirq(struct
 serial_port *port)
      scif_writew(uart, SCIF_SCSMR, val);
 
Quoted 16 lines

xen/drivers/char/scif-uart.c static void __init scif_uart_init_preirq(struct serial_port *port) · line 154

Quoted 11 lines
xen/drivers/char/scif-uart.c +0 -9
      ASSERT( uart->clock_hz > 0 );
-    if ( uart->baud != BAUD_AUTO )
-    {
-        /* Setup desired Baud rate */
-        divisor = uart->clock_hz / (uart->baud << 4);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        scif_writew(uart, SCIF_DL, (uint16_t)divisor);
-        /* Selects the frequency divided clock (SC_CLK external input)
 */
-        scif_writew(uart, SCIF_CKS, 0);
-        udelay(1000000 / uart->baud + 1);

This part of code might be used for people who are not satisfied with default baudrate which has been set in U-Boot.

Can you elaborate? If the baud rate is different, it will not be possible to
get output from U-boot.

Quoted 8 lines
Quoted 2 lines

If we remove this we will take away the opportunity to just change uart->baud from BAUD_AUTO to desired one.

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

Quoted 7 lines

No.

This driver has been initially written for Renesas Lager board based on R-Car H2 SoC which
has SCIF compatible UART. And the current code is valid for it. I have tested both auto and
variable (38400, 115200) baudrates.

Could you help me a little to understand this?

The driver has

scif_uart_init()
{
...
struct scif_uart *uart;
...
uart->baud = BAUD_AUTO;
...
}

Quoted 5 lines

I checked the code for struct scif_uart but it isn't used anywhere outside this driver. So uart->baud is a driver local variable, which looks to me isn't used anywhere useful.

What have I missed?

Unfortunately, I don't have recent Xen sources right now to be 100% sure. But, it seems you are right: uart->baud is a driver local variable.

Quoted 40 lines

Best regards

Dirk

Quoted 33 lines

But, I am afraid that current code won't be suitable for all of the boards which have the same UART IP. It depends at least from clock source
(external/internal) and clock frequency.

Quoted 28 lines

I would rather avoid to keep dead code (or not accessible without hacking Xen). For what is worth, we recently removed a similar code from the PL011
driver as this should be correctly configured by the firmware.

Quoted 15 lines
Quoted 15 lines
xen/drivers/char/scif-uart.c +6 -8
-    }
-    else
-    {
-        /* Read current Baud rate */
-        divisor = scif_readw(uart, SCIF_DL);
-        ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
-        uart->baud = uart->clock_hz / (divisor << 4);
-    }
+    ASSERT( uart->baud == BAUD_AUTO );
+
+    /* Read current Baud rate */
+    divisor = scif_readw(uart, SCIF_DL);
+    ASSERT( divisor >= 1 && divisor <= (uint16_t)UINT_MAX );
+    uart->baud = uart->clock_hz / (divisor << 4);
 
Quoted 5 lines
Quoted 5 lines
      /* Setup trigger level for TX/RX FIFOs */
      scif_writew(uart, SCIF_SCFCR, SCFCR_RTRG11 | SCFCR_TTRG11);

--
2.8.0

Regards,

Signature · 8 lines
Oleksandr Tyshchenko | Embedded Dev
GlobalLogic
www.globallogic.com

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#12 lore raw
In reply to Oleksandr Tyshchenko
Quoted 9 lines · Oleksandr Tyshchenko
Quoted 5 lines · Julien Grall
Quoted 2 lines

On Tue, Jun 21, 2016 at 12:15 PM, Dirk Behme <[email protected]> wrote:

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

No.

Quoted 9 lines

This driver has been initially written for Renesas Lager board based on R-Car H2 SoC which
has SCIF compatible UART. And the current code is valid for it. I have tested both auto and
variable (38400, 115200) baudrates.
But, I am afraid that current code won't be suitable for all of the boards which have the same UART IP. It depends at least from clock source
(external/internal) and clock frequency.

In this case, the code should either be fixed by reading the clock frequency from the firmware tables or be dropped.

I would lean towards the later because the user cannot specify the baud rate to Xen.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#13 lore raw
Quoted 28 lines · Julien Grall
Quoted 14 lines · Oleksandr Tyshchenko
Quoted 7 lines · Julien Grall
Quoted 3 lines

On Tue, Jun 21, 2016 at 12:15 PM, Dirk Behme <[email protected]> wrote:

I have some doubt that the current code is valid. The clock frequency is hardcoded (see SCIF_CLK_FREQ), so are you saying that the frequency is always the same across all the platforms?

No.

Quoted 9 lines

This driver has been initially written for Renesas Lager board based on R-Car H2 SoC which
has SCIF compatible UART. And the current code is valid for it. I have tested both auto and
variable (38400, 115200) baudrates.
But, I am afraid that current code won't be suitable for all of the boards which have the same UART IP. It depends at least from clock source
(external/internal) and clock frequency.

Quoted 5 lines

In this case, the code should either be fixed by reading the clock frequency from the firmware tables or be dropped.

I would lean towards the later because the user cannot specify the baud rate to Xen.

Agree.

Quoted 5 lines

Regards,

--
Julien Grall

Signature · 8 lines
Oleksandr Tyshchenko | Embedded Dev
GlobalLogic
www.globallogic.com

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel