uartlite driver MicroBlaze compatability
RFC 1/1 uartlite driver MicroBlaze compatability
Hi Peter,
The attached patch gets your uartlite driver going on MicroBlaze.
All readb/writeb ops are converted to ioread32/iowrite32.
On MicroBlaze readb/writeb are picking up the MSB, instead of LSB, and thus reading all zeros instead of the 8-bit control/status/FIFO registers that you intended.
Can you please confirm if this works on PPC?
I note that Grant's recent bootloader driver uses in_be32/out_be32 - would you prefer that instead of ioread32/iowrite32?
Thanks,
John
Convert readb/writeb ops into ioread32/iowrite32.
This gets the driver working with MicroBlaze (2.6.20).
drivers/serial/uartlite.c +15 -15
@@ -61,7 +61,7 @@/* stats */ if (stat &ULITE_STATUS_RXVALID ) { port->icount.rx++; - ch =readb (port->membase +ULITE_RX ); + ch =ioread32 (port->membase +ULITE_RX );if (stat &ULITE_STATUS_PARITY ) port->icount.parity++;
@@ -106,7 +106,7 @@return 0 ;if (port->x_char) { -writeb (port->x_char, port->membase +ULITE_TX ); +iowrite32 (port->x_char, port->membase +ULITE_TX ); port->x_char =0 ; port->icount.tx++;return 1 ;
@@ -115,7 +115,7 @@if (uart_circ_empty (xmit) ||uart_tx_stopped (port))return 0 ; -writeb (xmit->buf[xmit->tail], port->membase +ULITE_TX ); +iowrite32 (xmit->buf[xmit->tail], port->membase +ULITE_TX ); xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); port->icount.tx++;
@@ -132,7 +132,7 @@int busy;do { -int stat =readb (port->membase +ULITE_STATUS ); +int stat =ioread32 (port->membase +ULITE_STATUS ); busy =ulite_receive (port, stat); busy |=ulite_transmit (port, stat); }while (busy);
@@ -148,7 +148,7 @@unsigned int ret;spin_lock_irqsave (&port->lock, flags); - ret =readb (port->membase +ULITE_STATUS ); + ret =ioread32 (port->membase +ULITE_STATUS );spin_unlock_irqrestore (&port->lock, flags);return ret &ULITE_STATUS_TXEMPTY ?TIOCSER_TEMT :0 ;
@@ -171,7 +171,7 @@static void ulite_start_tx (struct uart_port *port) { -ulite_transmit (port,readb (port->membase +ULITE_STATUS )); +ulite_transmit (port,ioread32 (port->membase +ULITE_STATUS )); }static void ulite_stop_rx (struct uart_port *port)
@@ -200,17 +200,17 @@if (ret)return ret; -writeb (ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX , +iowrite32 (ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX , port->membase +ULITE_CONTROL ); -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +iowrite32 (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL );return 0 ; }static void ulite_shutdown (struct uart_port *port) { -writeb (0 , port->membase +ULITE_CONTROL ); -readb (port->membase +ULITE_CONTROL );/* dummy */ +iowrite32 (0 , port->membase +ULITE_CONTROL ); +ioread32 (port->membase +ULITE_CONTROL );/* dummy */ free_irq (port->irq, port); }
@@ -314,7 +314,7 @@/* wait up to 10ms for the character(s) to be sent */ for (i =0 ; i <10000 ; i++) { -if (readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_TXEMPTY ) +if (ioread32 (port->membase +ULITE_STATUS ) &ULITE_STATUS_TXEMPTY )break ;udelay (1 ); }
@@ -323,7 +323,7 @@static void ulite_console_putchar (struct uart_port *port,int ch) {ulite_console_wait_tx (port); -writeb (ch, port->membase +ULITE_TX ); +iowrite32 (ch, port->membase +ULITE_TX ); } static void ulite_console_write(struct console *co, const char *s,
@@ -340,8 +340,8 @@spin_lock_irqsave (&port->lock, flags);/* save and disable interrupt */ - ier =readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_IE ; -writeb (0 , port->membase +ULITE_CONTROL ); + ier =ioread32 (port->membase +ULITE_STATUS ) &ULITE_STATUS_IE ; +iowrite32 (0 , port->membase +ULITE_CONTROL );uart_console_write (port, s, count, ulite_console_putchar);
@@ -349,7 +349,7 @@/* restore interrupt state */ if (ier) -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +iowrite32 (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL );if (locked)spin_unlock_irqrestore (&port->lock, flags);
Quoted 11 lines · John Williams
Hi Peter,
The attached patch gets your uartlite driver going on MicroBlaze.
All readb/writeb ops are converted to ioread32/iowrite32.
On MicroBlaze readb/writeb are picking up the MSB, instead of LSB, and thus reading all zeros instead of the 8-bit control/status/FIFO registers that you intended.
Can you please confirm if this works on PPC?
Yes, I've confirmed this does work on PPC; but I don't think it's quite the correct fix.
ioread/write32 is mapped to in/out_le32, yet the bootloader driver must use in/out_be32. This is because the uartlite driver follows the lead of 8250 and requires an offset of 3 from the base address in order to find the relevant byte wise address. In fact, I believe the driver should work as-is on microblaze if the offset-by-3 is not used when registering it to the platform bus.
However, the uartlite is *not* an 8250. The 8250 turns up all over the place and it's registers are defined as 8 bit wide. The offset-by-3 stuff is part of the plat_serial8250_port structure which is also used to specify .regshift (increment between registers). Whereas the UARTLITE is defined as a 32 bit device and it doesn't show up in anywhere near as many designs. Registers are always 4 bytes wide and are always located at multiples of 4 bytes off the base address.
The biggest problem with keeping the 3 byte offset and using ioread/write32 on it makes every register access straddle a 32-bit boundary. This means 2 bus transactions for every register access. Absolutely not what we want.
The problem with keeping the byte-wise access as it is now is that it means the platform bus binding needs to explicitly know what the host access width is and add the 3 byte offset accordingly (rather than using the base address as specified in xparameters unmodified and using the in/out_be32 macro take care of reading it correctly & efficiently).
(There are also annoyances that will come up when we move to arch/powerpc and hook it up to the of_platform_bus)
Quoted 3 lines
I note that Grant's recent bootloader driver uses in_be32/out_be32 - would you prefer that instead of ioread32/iowrite32?
I certainly think so. The device is documented as using 32 bit BE registers; so the driver should access them as 32bit BE registers IMHO. Or at least, if there is a good reason to continue the bytewise access, then the driver should contain the smarts to translate from documented base address to the appropriate offset.
So; starting with your patch and modifying it, I've attached I think the change should be. It should work for microblaze, but I've only tested w/ ppc. Unfortunately the (void*) casts are ugly; there might be a way around that, but it's due to the type used for the (struct uart_port)->membase variable.
Cheers,
g.
Signature · 4 lines
Grant Likely, B.Sc. P.Eng. Secret Lab Technologies Ltd. [email protected] (403) 399-0195
From cafac17d995fb2ced7102e8fbaad1f9bf3306b8b Mon Sep 17 00:00:00 2001
From: Grant Likely <[email protected]>
Date: Mon, 30 Apr 2007 23:53:03 -0600
Subject: [PATCH] [PPC] Fix UARTLITE register access for little-endian (microblaze) architectures
--- arch/ppc/syslib/virtex_devices.c | 2 +- drivers/serial/uartlite.c | 32 ++++++++++++++++---------------- 2 files changed, 17 insertions(+), 17 deletions(-)
arch/ppc/syslib/virtex_devices.c +1 -1
@@ -31,7 +31,7 @@ .num_resources = 2, \ .resource = (struct resource[]) { \ { \ - .start = XPAR_UARTLITE_##num##_BASEADDR + 3, \ + .start = XPAR_UARTLITE_##num##_BASEADDR, \ .end = XPAR_UARTLITE_##num##_HIGHADDR, \ .flags = IORESOURCE_MEM, \ }, \
drivers/serial/uartlite.c +16 -16
@@ -61,7 +61,7 @@ static int ulite_receive(struct uart_port *port, int stat)/* stats */ if (stat &ULITE_STATUS_RXVALID ) { port->icount.rx++; - ch =readb (port->membase +ULITE_RX ); + ch =in_be32 ((void *)port->membase +ULITE_RX );if (stat &ULITE_STATUS_PARITY ) port->icount.parity++;
@@ -106,7 +106,7 @@ static int ulite_transmit(struct uart_port *port, int stat)return 0 ;if (port->x_char) { -writeb (port->x_char, port->membase +ULITE_TX ); +out_be32 ((void *)port->membase +ULITE_TX , port->x_char); port->x_char =0 ; port->icount.tx++;return 1 ;
@@ -115,7 +115,7 @@ static int ulite_transmit(struct uart_port *port, int stat)if (uart_circ_empty (xmit) ||uart_tx_stopped (port))return 0 ; -writeb (xmit->buf[xmit->tail], port->membase +ULITE_TX ); +out_be32 ((void *)port->membase +ULITE_TX , xmit->buf[xmit->tail]); xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); port->icount.tx++;
@@ -132,7 +132,7 @@ static irqreturn_t ulite_isr(int irq, void *dev_id)int busy;do { -int stat =readb (port->membase +ULITE_STATUS ); +int stat =in_be32 ((void *)port->membase +ULITE_STATUS ); busy =ulite_receive (port, stat); busy |=ulite_transmit (port, stat); }while (busy);
@@ -148,7 +148,7 @@ static unsigned int ulite_tx_empty(struct uart_port *port)unsigned int ret;spin_lock_irqsave (&port->lock, flags); - ret =readb (port->membase +ULITE_STATUS ); + ret =in_be32 ((void *)port->membase +ULITE_STATUS );spin_unlock_irqrestore (&port->lock, flags);return ret &ULITE_STATUS_TXEMPTY ?TIOCSER_TEMT :0 ;
@@ -171,7 +171,7 @@ static void ulite_stop_tx(struct uart_port *port)static void ulite_start_tx (struct uart_port *port) { -ulite_transmit (port,readb (port->membase +ULITE_STATUS )); +ulite_transmit (port,in_be32 ((void *)port->membase +ULITE_STATUS )); }static void ulite_stop_rx (struct uart_port *port)
@@ -200,17 +200,17 @@ static int ulite_startup(struct uart_port *port)if (ret)return ret; -writeb (ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX , - port->membase +ULITE_CONTROL ); -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +out_be32 ((void *)port->membase +ULITE_CONTROL , +ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX ); +out_be32 ((void *)port->membase +ULITE_CONTROL ,ULITE_CONTROL_IE );return 0 ; }static void ulite_shutdown (struct uart_port *port) { -writeb (0 , port->membase +ULITE_CONTROL ); -readb (port->membase +ULITE_CONTROL );/* dummy */ +out_be32 ((void *)port->membase +ULITE_CONTROL ,0 ); +in_be32 ((void *)port->membase +ULITE_CONTROL );/* dummy */ free_irq (port->irq, port); }
@@ -314,7 +314,7 @@ static void ulite_console_wait_tx(struct uart_port *port)/* wait up to 10ms for the character(s) to be sent */ for (i =0 ; i <10000 ; i++) { -if (readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_TXEMPTY ) +if (in_be32 ((void *)port->membase +ULITE_STATUS ) &ULITE_STATUS_TXEMPTY )break ;udelay (1 ); }
@@ -323,7 +323,7 @@ static void ulite_console_wait_tx(struct uart_port *port)static void ulite_console_putchar (struct uart_port *port,int ch) {ulite_console_wait_tx (port); -writeb (ch, port->membase +ULITE_TX ); +out_be32 ((void *)port->membase +ULITE_TX , ch); } static void ulite_console_write(struct console *co, const char *s,
@@ -340,8 +340,8 @@ static void ulite_console_write(struct console *co, const char *s,spin_lock_irqsave (&port->lock, flags);/* save and disable interrupt */ - ier =readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_IE ; -writeb (0 , port->membase +ULITE_CONTROL ); + ier =in_be32 ((void *)port->membase +ULITE_STATUS ) &ULITE_STATUS_IE ; +out_be32 ((void *)port->membase +ULITE_CONTROL ,0 );uart_console_write (port, s, count, ulite_console_putchar);
@@ -349,7 +349,7 @@ static void ulite_console_write(struct console *co, const char *s,/* restore interrupt state */ if (ier) -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +out_be32 ((void *)port->membase +ULITE_CONTROL ,ULITE_CONTROL_IE );if (locked)spin_unlock_irqrestore (&port->lock, flags);
Signature · 1 line
1.5.1
John Williams
Acked-byQuoted 13 lines · Grant Likely
Quoted 7 lines · John Williams
All readb/writeb ops are converted to ioread32/iowrite32.
On MicroBlaze readb/writeb are picking up the MSB, instead of LSB, and thus reading all zeros instead of the 8-bit control/status/FIFO registers that you intended.
Can you please confirm if this works on PPC?
Yes, I've confirmed this does work on PPC; but I don't think it's quite the correct fix.
Quoted 6 lines
ioread/write32 is mapped to in/out_le32, yet the bootloader driver must use in/out_be32. This is because the uartlite driver follows the lead of 8250 and requires an offset of 3 from the base address in order to find the relevant byte wise address. In fact, I believe the driver should work as-is on microblaze if the offset-by-3 is not used when registering it to the platform bus.
ugh. I missed the off-by-3 stuff in the PPC platform setup. Smells bad!
Quoted 8 lines
However, the uartlite is *not* an 8250. The 8250 turns up all over the place and it's registers are defined as 8 bit wide. The offset-by-3 stuff is part of the
plat_serial8250_portstructure which is also used to specify .regshift (increment between registers). Whereas the UARTLITE is defined as a 32 bit device and it doesn't show up in anywhere near as many designs. Registers are always 4 bytes wide and are always located at multiples of 4 bytes off the base address.
Agreed.
Quoted 5 lines
So; starting with your patch and modifying it, I've attached I think the change should be. It should work for microblaze, but I've only tested w/ ppc. Unfortunately the (void*) casts are ugly; there might be a way around that, but it's due to the type used for the (struct uart_port)->membase variable.
Looks good - boot tested on MicroBlaze 2.6.20
John
Quoted 8 lines · John Williams
Quoted 7 lines · Grant Likely
However, the uartlite is *not* an 8250. The 8250 turns up all over the place and it's registers are defined as 8 bit wide. The offset-by-3 stuff is part of the
plat_serial8250_portstructure which is also used to specify .regshift (increment between registers). Whereas the UARTLITE is defined as a 32 bit device and it doesn't show up in anywhere near as many designs. Registers are always 4 bytes wide and are always located at multiples of 4 bytes off the base
Hmm, I think I was smoking something last night. Address used for 8 bit access should not be affected by CPU endianess. After David's comments, I reread the uartlite documentation. The current design is definately for 32bit OPB bus connections, but it looks like there is a posibility for xilinx to add a 16 or 8 bit attachment. Since the uartlite design explicitly supports 8, 16 and 32 bit access, sticking with 8 bit io may be the safest. However, I still think the application of the 3 byte offset should be done in the driver, and not in the platform bus registration.
I've reworked the patch with the following changes
- remove 3 byte offset from platform bus registration.
- added ulite_in/ulite_out macros to make changing bus attachment details simpler if xilinx changes the uartlite design.
- stick with 8 bit IO.
Tested on PPC. John, can you please test on microblaze?
Cheers,
g.
Signature · 4 lines
Grant Likely, B.Sc. P.Eng. Secret Lab Technologies Ltd. [email protected] (403) 399-0195
From fd14939b570511cd57dc5d3efa1145976706c6ad Mon Sep 17 00:00:00 2001
From: Grant Likely <[email protected]>
Date: Mon, 30 Apr 2007 23:53:03 -0600
Subject: [PATCH] [POWERPC] Fix UARTLITE driver to add a 3 byte offset when accessing registers
Also, replace direct calls to readb/writeb with ulite_in/ulite_out macros so any future register access changes are simpler to apply.
--- arch/ppc/syslib/virtex_devices.c | 2 +- drivers/serial/uartlite.c | 35 +++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 17 deletions(-)
arch/ppc/syslib/virtex_devices.c +1 -1
@@ -31,7 +31,7 @@ .num_resources = 2, \ .resource = (struct resource[]) { \ { \ - .start = XPAR_UARTLITE_##num##_BASEADDR + 3, \ + .start = XPAR_UARTLITE_##num##_BASEADDR, \ .end = XPAR_UARTLITE_##num##_HIGHADDR, \ .flags = IORESOURCE_MEM, \ }, \
drivers/serial/uartlite.c +19 -16
@@ -48,6 +48,9 @@static struct uart_port ports[ULITE_NR_UARTS ]; +#define ulite_in (p,r) in_8(p->membase + (r) + 3) +#define ulite_out (p,r,v) out_8(p->membase + (r) + 3, v) +static int ulite_receive (struct uart_port *port,int stat) {struct tty_struct *tty = port->info->tty;
@@ -61,7 +64,7 @@ static int ulite_receive(struct uart_port *port, int stat)/* stats */ if (stat &ULITE_STATUS_RXVALID ) { port->icount.rx++; - ch =readb (port->membase +ULITE_RX ); + ch =ulite_in (port,ULITE_RX );if (stat &ULITE_STATUS_PARITY ) port->icount.parity++;
@@ -106,7 +109,7 @@ static int ulite_transmit(struct uart_port *port, int stat)return 0 ;if (port->x_char) { -writeb (port->x_char, port->membase +ULITE_TX ); +ulite_out (port,ULITE_TX , port->x_char); port->x_char =0 ; port->icount.tx++;return 1 ;
@@ -115,7 +118,7 @@ static int ulite_transmit(struct uart_port *port, int stat)if (uart_circ_empty (xmit) ||uart_tx_stopped (port))return 0 ; -writeb (xmit->buf[xmit->tail], port->membase +ULITE_TX ); +ulite_out (port,ULITE_TX , xmit->buf[xmit->tail]); xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); port->icount.tx++;
@@ -132,7 +135,7 @@ static irqreturn_t ulite_isr(int irq, void *dev_id)int busy;do { -int stat =readb (port->membase +ULITE_STATUS ); +int stat =ulite_in (port,ULITE_STATUS ); busy =ulite_receive (port, stat); busy |=ulite_transmit (port, stat); }while (busy);
@@ -148,7 +151,7 @@ static unsigned int ulite_tx_empty(struct uart_port *port)unsigned int ret;spin_lock_irqsave (&port->lock, flags); - ret =readb (port->membase +ULITE_STATUS ); + ret =ulite_in (port,ULITE_STATUS );spin_unlock_irqrestore (&port->lock, flags);return ret &ULITE_STATUS_TXEMPTY ?TIOCSER_TEMT :0 ;
@@ -171,7 +174,7 @@ static void ulite_stop_tx(struct uart_port *port)static void ulite_start_tx (struct uart_port *port) { -ulite_transmit (port,readb (port->membase +ULITE_STATUS )); +ulite_transmit (port,ulite_in (port,ULITE_STATUS )); }static void ulite_stop_rx (struct uart_port *port)
@@ -200,17 +203,17 @@ static int ulite_startup(struct uart_port *port)if (ret)return ret; -writeb (ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX , - port->membase +ULITE_CONTROL ); -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +ulite_out (port,ULITE_CONTROL , +ULITE_CONTROL_RST_RX |ULITE_CONTROL_RST_TX ); +ulite_out (port,ULITE_CONTROL ,ULITE_CONTROL_IE );return 0 ; }static void ulite_shutdown (struct uart_port *port) { -writeb (0 , port->membase +ULITE_CONTROL ); -readb (port->membase +ULITE_CONTROL );/* dummy */ +ulite_out (port,ULITE_CONTROL ,0 ); +ulite_in (port,ULITE_CONTROL );/* dummy */ free_irq (port->irq, port); }
@@ -314,7 +317,7 @@ static void ulite_console_wait_tx(struct uart_port *port)/* wait up to 10ms for the character(s) to be sent */ for (i =0 ; i <10000 ; i++) { -if (readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_TXEMPTY ) +if (ulite_in (port,ULITE_STATUS ) &ULITE_STATUS_TXEMPTY )break ;udelay (1 ); }
@@ -323,7 +326,7 @@ static void ulite_console_wait_tx(struct uart_port *port)static void ulite_console_putchar (struct uart_port *port,int ch) {ulite_console_wait_tx (port); -writeb (ch, port->membase +ULITE_TX ); +ulite_out (port,ULITE_TX , ch); } static void ulite_console_write(struct console *co, const char *s,
@@ -340,8 +343,8 @@ static void ulite_console_write(struct console *co, const char *s,spin_lock_irqsave (&port->lock, flags);/* save and disable interrupt */ - ier =readb (port->membase +ULITE_STATUS ) &ULITE_STATUS_IE ; -writeb (0 , port->membase +ULITE_CONTROL ); + ier =ulite_in (port,ULITE_STATUS ) &ULITE_STATUS_IE ; +ulite_out (port,ULITE_CONTROL ,0 );uart_console_write (port, s, count, ulite_console_putchar);
@@ -349,7 +352,7 @@ static void ulite_console_write(struct console *co, const char *s,/* restore interrupt state */ if (ier) -writeb (ULITE_CONTROL_IE , port->membase +ULITE_CONTROL ); +ulite_out (port,ULITE_CONTROL ,ULITE_CONTROL_IE );if (locked)spin_unlock_irqrestore (&port->lock, flags);
Signature · 1 line
1.5.1
John Williams
Acked-byQuoted 11 lines · Grant Likely
Quoted 8 lines · John Williams
Quoted 7 lines · Grant Likely
However, the uartlite is *not* an 8250. The 8250 turns up all over the place and it's registers are defined as 8 bit wide. The offset-by-3 stuff is part of the
plat_serial8250_portstructure which is also used to specify .regshift (increment between registers). Whereas the UARTLITE is defined as a 32 bit device and it doesn't show up in anywhere near as many designs. Registers are always 4 bytes wide and are always located at multiples of 4 bytes off the base
Quoted 7 lines
Hmm, I think I was smoking something last night. Address used for 8 bit access should not be affected by CPU endianess. After David's comments, I reread the uartlite documentation. The current design is definately for 32bit OPB bus connections, but it looks like there is a posibility for xilinx to add a 16 or 8 bit attachment. Since the uartlite design explicitly supports 8, 16 and 32 bit access, sticking with 8 bit io may be the safest.
To be honest I don't think that will ever happen - just because the OPB bus data width is parameterisable, doesn't mean that it actually *works* or has been tested on anything other than 32-bits wide. I've certainly never heard of anyone doing so, on either MicroBlaze or PPC.
but, I won't fight over it :)
Either way, it will still require a code change if/when someone does a 16/8 bit wide OPB bus. Whether they change the IO access operation, or a hardcoded constant, it's still not perfect.
Of course the real solution here is to create an OPB bus driver, with a 'width' field that you can pull out of XPAR, and so on... Use that instead of platform bus, and all this rubbish can be dealt with cleanly.
Quoted 3 lines
However, I still think the
application of the 3 byte offset should be done in the driver, and not in the platform bus registration.
If it has to be done, I agree the driver is the place to put it.
Quoted 5 lines
I've reworked the patch with the following changes
- remove 3 byte offset from platform bus registration.
- added ulite_in/ulite_out macros to make changing bus attachment details simpler if xilinx changes the uartlite design.
- stick with 8 bit IO.
It works fine, however perhaps a comment explaining the +3 offset might be appreciated by those who follow.
Quoted 1 line
Tested on PPC. John, can you please test on microblaze?
John
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"JW" == John Williams <[email protected]> writes:
Hi,
JW> The attached patch gets your uartlite driver going on MicroBlaze.
Nice!
JW> All readb/writeb ops are converted to ioread32/iowrite32.
JW> On MicroBlaze readb/writeb are picking up the MSB, instead of LSB, JW> and thus reading all zeros instead of the 8-bit
JW> control/status/FIFO registers that you intended.
I take it that the microblaze is big endian? Then you just need to add 3 to the base address and everything should work without your patch.
JW> Can you please confirm if this works on PPC?
It won't as ioread/write does big/little endian byte swapping. Isn't that done on microblaze?
Signature · 1 line
Bye, Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"GL" == Grant Likely <[email protected]> writes:
Hi,
Quoted 1 line
Quoted 1 line
Can you please confirm if this works on PPC?
GL> Yes, I've confirmed this does work on PPC; but I don't think it's GL> quite the correct fix.
GL> ioread/write32 is mapped to in/out_le32, yet the bootloader driver GL> must use in/out_be32. This is because the uartlite driver follows GL> the lead of 8250 and requires an offset of 3 from the base address GL> in order to find the relevant byte wise address. In fact, I GL> believe the driver should work as-is on microblaze if the GL> offset-by-3 is not used when registering it to the platform bus.
Not used? Isn't the microblaze big endian as well?
GL> However, the uartlite is *not* an 8250. The 8250 turns up all GL> over the place and it's registers are defined as 8 bit wide. The GL> offset-by-3 stuff is part of the plat_serial8250_port structure GL> which is also used to specify .regshift (increment between GL> registers). Whereas the UARTLITE is defined as a 32 bit device GL> and it doesn't show up in anywhere near as many designs. GL> Registers are always 4 bytes wide and are always located at GL> multiples of 4 bytes off the base address.
Well, yes and no - The registers physically contains 8 bit of information, but are commonly located on the 32bit opb bus.
GL> The biggest problem with keeping the 3 byte offset and using GL> ioread/write32 on it makes every register access straddle a 32-bit GL> boundary. This means 2 bus transactions for every register GL> access. Absolutely not what we want.
Exactly.
GL> The problem with keeping the byte-wise access as it is now is that GL> it means the platform bus binding needs to explicitly know what GL> the host access width is and add the 3 byte offset accordingly GL> (rather than using the base address as specified in xparameters GL> unmodified and using the in/out_be32 macro take care of reading it GL> correctly & efficiently).
I don't think that's a big problem. Other reasons for using 8bit I/O are:
- No endianness problems (besides setting the proper base address). "There's no read/write register in native endianness" interface in the kernel. readl is always little endian, and _be32 would be wrong/not available on all archs. The uartlite interface is nice and simple - Who knows if someone would add a FPGA with a bunch of uartlite's to an ARM/MIPS/whatever design?
- No bus width problems. We have designs which needed extra uarts late in the design, and have implemented uartlite compatible firmware in a SP3e FPGA connected over a 16bit bus (EMC). The uartlite driver works nicely with that as it is. With 32bit access you would double the bus transactions.
- It matches 8250.c
GL> (There are also annoyances that will come up when we move to GL> arch/powerpc and hook it up to the of_platform_bus)
Ohh, like what?
Quoted 2 lines
Quoted 2 lines
I note that Grant's recent bootloader driver uses in_be32/out_be32
- would you prefer that instead of ioread32/iowrite32?
GL> I certainly think so. The device is documented as using 32 bit BE GL> registers; so the driver should access them as 32bit BE registers GL> IMHO. Or at least, if there is a good reason to continue the GL> bytewise access, then the driver should contain the smarts to GL> translate from documented base address to the appropriate offset.
How should it be able to do that? Using some magic #ifdef to know if it's compiled for a big endian arch and do a +3? That seems ugly to me.
In other words - I disagree.
Signature · 1 line
Bye, Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"GL" == Grant Likely <[email protected]> writes:
Hi,
GL> Hmm, I think I was smoking something last night.
;)
GL> Address used for 8 bit access should not be affected by CPU GL> endianess. After David's comments, I reread the uartlite GL> documentation. The current design is definately for 32bit OPB bus GL> connections, but it looks like there is a posibility for xilinx to GL> add a 16 or 8 bit attachment. Since the uartlite design GL> explicitly supports 8, 16 and 32 bit access, sticking with 8 bit GL> io may be the safest. However, I still think the application of GL> the 3 byte offset should be done in the driver, and not in the GL> platform bus registration.
That would effectively make the driver big endian only. What if Xilinx would come out with a FPGA with a ARM core in it?
GL> I've reworked the patch with the following changes - remove 3 byte GL> offset from platform bus registration. - added ulite_in/ulite_out GL> macros to make changing bus attachment details simpler if xilinx GL> changes the uartlite design. - stick with 8 bit IO.
Russell didn't like those accessor macros back when it was submitted last year:
http://thread.gmane.org/gmane.linux.serial/1237/focus=1251
Signature · 1 line
Bye, Peter Korsgaard
Quoted 18 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"GL" == Grant Likely <[email protected]> writes:
Hi,
GL> Hmm, I think I was smoking something last night.
;)
GL> Address used for 8 bit access should not be affected by CPU GL> endianess. After David's comments, I reread the uartlite GL> documentation. The current design is definately for 32bit OPB bus GL> connections, but it looks like there is a posibility for xilinx to GL> add a 16 or 8 bit attachment. Since the uartlite design GL> explicitly supports 8, 16 and 32 bit access, sticking with 8 bit GL> io may be the safest. However, I still think the application of GL> the 3 byte offset should be done in the driver, and not in the GL> platform bus registration.
Quoted 2 lines
That would effectively make the driver big endian only. What if Xilinx would come out with a FPGA with a ARM core in it?
It shouldn't. When doing byte-wise access, byte 3 is *always* byte 3; regardless of the endianess of the processor. It's the endianess of the device that determines where the individual bytes show up. The opb_uartlite documentation defines the registers as big endian, therefore if you do a bytewise access to address 0x3, you'll always get the least significant byte of the first register.
Since the 3 byte offset does not change between little endian and big endian processors then I think the knowledge of the offset should be kept in the driver, not the device registration.
Quoted 10 lines
GL> I've reworked the patch with the following changes - remove 3 byte GL> offset from platform bus registration. - added ulite_in/ulite_out GL> macros to make changing bus attachment details simpler if xilinx GL> changes the uartlite design. - stick with 8 bit IO.
Russell didn't like those accessor macros back when it was submitted last year:
Quoted 1 line
+static inline void serial_out(struct
uart_port*port, int offset, int
Russell> Since there's no additional complication here, do you need separate Russell> serial_in/serial_out inline functions?
As I think the driver should know about the 3 byte offset; the accessor macro makes sense again. Plus if Xilinx ever adds a uartlite varient w/ bytewise or halfword wise registers it becomes much easier to taylor in the future.
Cheers,
g.
Signature · 4 lines
Grant Likely, B.Sc. P.Eng. Secret Lab Technologies Ltd. [email protected] (403) 399-0195
Hi Peter,
Quoted 4 lines · Peter Korsgaard
JW> The attached patch gets your uartlite driver going on MicroBlaze.
Nice!
Quoted 8 lines
JW> All readb/writeb ops are converted to ioread32/iowrite32.
JW> On MicroBlaze readb/writeb are picking up the MSB, instead of LSB, JW> and thus reading all zeros instead of the 8-bit
JW> control/status/FIFO registers that you intended.I take it that the microblaze is big endian? Then you just need to add 3 to the base address and everything should work without your patch.
I struggle to see adding 3 to the base address in the platform driver as a clean solution. The base address of the peripheral is 0x10240000, or whatever, not 0x10240003.
I understand the reasoning for it, but from the platform's perspective it seems wrong.
If you read the opb_uartlite datasheet, it says that bits 0-26 of the FIFO, CTRL and STATUS regs are "reserved". It doesn't say, this is an 8-bit peripheral that is mapped onto a 32bit bus with a stride of 4.
If you also read page 6 , under address map, it says
BASE_ADDRESS+0 : read from receive FIFO
BASE_ADDRESS+4 : write to transmit FIFO
and so on.
It is a 32-bit peripheral, it just so happens the 24 of those bits are currently "reserved".
Grant's recanting may have been triggered by the figure on page 4 of the datasheet, which is generic Xilnx IP Core datasheet material explaining the endian interpretation for different data widths.
Quoted 4 lines
JW> Can you please confirm if this works on PPC?
It won't as ioread/write does big/little endian byte swapping. Isn't that done on microblaze?
Not presently, but I will fix that.
I think that's Grant's approach of using in/out_be32, and the real base address (ie not +3) is the only logically correct solution.
Regards,
John
Quoted 4 lines · John Williams
I think that's Grant's approach of using in/out_be32, and the real base address (ie not +3) is the only logically correct solution.
Trying to track how every permutation maps in every possible
scenario is more than my brain can handle.
What I do know is that throwing an arbitrary +3 offset in is
incredibly confusing.
While I pointed out that the Xilinx docs sugguest implimentations
with regshifts of 0,1 &2 - and I beleive
I have seen xilinx example code that sugest they may have somehow
implimented UartLite on occasion
with less than 32bit registers. The stock GreenHills Integrity
default UartLite driver presumes a regshift of 0.
But I have never seen an 8 or 16 bit Uartlite.
However before either my driver or Peters showed up there was one
posted to this list that used dcr.
My suggestion would be to handle "port IO" inside
serial_in()serial_out() functions like the 8250 driver (and about 1/3 of the
other serial drivers) do.
While in a perfect world we should be able to compile the UartLite
driver without change for an x86
if somehow that can be created, atleast with all the io moved to two
functions, adjusting for different regshifts,
endians, .... requires a very limited number of localized changes.
I would be happy to submit a patch to do that
but I can not test it because I can not get Peter's driver to work
with my hardware.
Signature · 8 lines
Dave Lynch DLA Systems Software Development: Embedded Linux 717.627.3770 [email protected] http://www.dlasys.net fax: 1.253.369.9244 Cell: 1.717.587.7774 Over 25 years' experience in platforms, languages, and technologies too numerous to list. "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." Albert Einstein