Re: Raspberrypi3: AUX Uart driver

2020-01-15 Thread Niteesh
Thank you, it works now :)
I have tested in on a real rpi3 and on rpi2 using QEMU, it works on both of
them.
Shall I send it as two patches, because the first one adds the facility to
pass
user define functions to calculate baud divisor and the 2nd is the driver
patch?

On Wed, Jan 15, 2020 at 1:25 PM Christian Mauderer <
christian.maude...@embedded-brains.de> wrote:

> On 15/01/2020 06:27, Niteesh wrote:
> > I commented out all FDT queries and everything works using ns16550
> driver.
> > How do I load FDT blob using uboot, I tried using the default
> > bootloader, but
> > it doesn't work. I tried the following command but they don't work
> > fatload mmc 0 0x20 kernel7.img
> > fatload mmc 0 0x1000 bcm2710-rpi-3-b.dtb
> > fdt addr 0x1000
> > fdt boardsetup
> > go 0x200080
>
> Instead of "go 0x200080" try it with bootm with the syntax for linux:
>
> https://www.denx.de/wiki/view/DULG/UBootCmdGroupExec#Section_5.9.4.2.
>
> With the commands you used it should be a
>
>bootm 0x20 - 0x1000
>
> Best regards
>
> Christian
>
> >
> > On Tue, Jan 14, 2020 at 9:40 PM Niteesh  > > wrote:
> >
> > I am finished with code, I tested it in QEMU emulator raspi2but it
> > doesn't work
> > when testing on real rpi3. I don't know if the problem is with
> > loading the FDT
> > or with my code?
> > How do I send the code, so that you can take a look at it?
> >
> > On Tue, Jan 14, 2020 at 8:04 PM Niteesh  > > wrote:
> >
> > On Tue, Jan 14, 2020 at 1:57 PM Christian Mauderer
> >  > > wrote:
> >
> > On 13/01/2020 19:04, Niteesh wrote:
> > > The ns16550_context already has a field named
> > baud_divisor, so if the
> > > user passes
> > > value for it, then we can skip the GetBaudDivisor function
> > and use that
> > > value instead.
> > >
> > > Is this approach okay?
> >
> > Is the driver still able to handle different baud rates with
> > this? Does
> > the ioctl call for setting the baudrate work?
> >
> > I didn't think about this, it won't work if we are using this
> > method. ns16550_set_attributes
> > calls ns16550_GetBaudDivisor, then I think we will have to stick
> > with the old method.
> >
> >
> >
> > Best regards
> >
> > Christian
> >
> > >
> > > On Mon, Jan 13, 2020 at 3:46 PM Niteesh  > 
> > > >>
> wrote:
> > >
> > > On Mon, Jan 13, 2020 at 1:38 PM Christian Mauderer
> > >  > 
> > >  > >> wrote:
> > >
> > > On 12/01/2020 21:26, Niteesh wrote:
> > > > On Sun, Jan 12, 2020 at 11:42 PM Christian
> Mauderer
> > > mailto:l...@c-mauderer.de>
> > >
> > > >  >   >  > > >
> > > > Hello Niteesh,
> > > >
> > > > On 12/01/2020 16:06, Niteesh wrote:
> > > > > The only issue, I faced while using this
> > driver is the
> > > baud divisor is
> > > > > calculated
> > > > > by CLOCK_FREQ/(BAUD_RATE * 16)
> > (*ns16550-context.c:68)*
> > > > > but it should BAUD_DIV = (CLOCK_FREQ/(8 *
> > BAUD_RATE)) -
> > > 1, for Rpi3.
> > > > > For testing, I assigned the baud divisor
> > to 270 (115200
> > > bits/s) in
> > > > > ns16550-context.c,
> > > > > and everything works fine.
> > > >
> > > > Sounds great. In NS16550_GetBaudDivisor
> > there is already a
> > > case where
> > > > the baudDivisor is calculated differently
> > (depending on
> > > > ctx->has_precision_clock_synthesizer and
> > > > ctx->has_fractional_divider_register). If
> > none of the two
> > > cases are ok
> > > > for the controller you could just add
> > another one.
> > > >
> >  

Re: Raspberrypi3: AUX Uart driver

2020-01-15 Thread Christian Mauderer
On 15/01/2020 12:13, Niteesh wrote:
> Thank you, it works now :)
> I have tested in on a real rpi3 and on rpi2 using QEMU, it works on both
> of them.
> Shall I send it as two patches, because the first one adds the facility
> to pass
> user define functions to calculate baud divisor and the 2nd is the
> driver patch?

Yes that sounds like two patches.

> 
> On Wed, Jan 15, 2020 at 1:25 PM Christian Mauderer
>  > wrote:
> 
> On 15/01/2020 06:27, Niteesh wrote:
> > I commented out all FDT queries and everything works using ns16550
> driver.
> > How do I load FDT blob using uboot, I tried using the default
> > bootloader, but
> > it doesn't work. I tried the following command but they don't work
> > fatload mmc 0 0x20 kernel7.img
> > fatload mmc 0 0x1000 bcm2710-rpi-3-b.dtb
> > fdt addr 0x1000
> > fdt boardsetup
> > go 0x200080
> 
> Instead of "go 0x200080" try it with bootm with the syntax for linux:
> 
> https://www.denx.de/wiki/view/DULG/UBootCmdGroupExec#Section_5.9.4.2.
> 
> With the commands you used it should be a
> 
>    bootm 0x20 - 0x1000
> 
> Best regards
> 
> Christian
> 
> >
> > On Tue, Jan 14, 2020 at 9:40 PM Niteesh  
> > >> wrote:
> >
> >     I am finished with code, I tested it in QEMU emulator raspi2but it
> >     doesn't work
> >     when testing on real rpi3. I don't know if the problem is with
> >     loading the FDT
> >     or with my code?
> >     How do I send the code, so that you can take a look at it?
> >
> >     On Tue, Jan 14, 2020 at 8:04 PM Niteesh  
> >     >> wrote:
> >
> >         On Tue, Jan 14, 2020 at 1:57 PM Christian Mauderer
> >          
> >          >> wrote:
> >
> >             On 13/01/2020 19:04, Niteesh wrote:
> >             > The ns16550_context already has a field named
> >             baud_divisor, so if the
> >             > user passes
> >             > value for it, then we can skip the GetBaudDivisor
> function
> >             and use that
> >             > value instead.
> >             >
> >             > Is this approach okay?
> >
> >             Is the driver still able to handle different baud
> rates with
> >             this? Does
> >             the ioctl call for setting the baudrate work?
> >
> >         I didn't think about this, it won't work if we are using this
> >         method. ns16550_set_attributes
> >         calls ns16550_GetBaudDivisor, then I think we will have to
> stick
> >         with the old method.
> >
> >              
> >
> >             Best regards
> >
> >             Christian
> >
> >             >
> >             > On Mon, Jan 13, 2020 at 3:46 PM Niteesh
> mailto:gsnb...@gmail.com>
> >             >
> >             > 
>  >             >
> >             >     On Mon, Jan 13, 2020 at 1:38 PM Christian Mauderer
> >             >      
> >              >
> >             >      
> >               >             >
> >             >         On 12/01/2020 21:26, Niteesh wrote:
> >             >         > On Sun, Jan 12, 2020 at 11:42 PM Christian
> Mauderer
> >             >            >
> >             
> >>
> >             >         >  
> >              >  
> >               wrote:
> >             >         >
> >             >         >     Hello Niteesh,
> >             >         >
> >             >         >     On 12/01/2020 16:06, Niteesh wrote:
> >             >         >

[PATCH] libchip/ns16550: Allow user calculate baud divisor

2020-01-15 Thread G S Niteesh
This patch will allow the user to pass a function to calculate
the baud divisor.
This is will allow for more flexibility, since for some BSP's
like raspberrypi, the calculate of baud divisor is different
from what is in the current driver.
---
 bsps/include/libchip/ns16550.h   | 11 ---
 bsps/shared/dev/serial/ns16550-context.c |  6 --
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/bsps/include/libchip/ns16550.h b/bsps/include/libchip/ns16550.h
index f053c8767f9..ab7992fd30b 100644
--- a/bsps/include/libchip/ns16550.h
+++ b/bsps/include/libchip/ns16550.h
@@ -1,6 +1,6 @@
 /**
  *  @file
- *  
+ *
  */
 
 /*
@@ -60,7 +60,11 @@ typedef uint8_t (*ns16550_get_reg)(uintptr_t port, uint8_t 
reg);
 
 typedef void (*ns16550_set_reg)(uintptr_t port, uint8_t reg, uint8_t value);
 
-typedef struct {
+typedef struct ns16550_context ns16550_context;
+
+typedef uint32_t (*ns16550_calculate_baud_divisor)(ns16550_context *ctx, 
uint32_t baud);
+
+struct ns16550_context{
   rtems_termios_device_context base;
   ns16550_get_reg get_reg;
   ns16550_set_reg set_reg;
@@ -70,6 +74,7 @@ typedef struct {
   uint32_t initial_baud;
   bool has_fractional_divider_register;
   bool has_precision_clock_synthesizer;
+  ns16550_calculate_baud_divisor calculate_baud_divisor;
   uint8_t modem_control;
   uint8_t line_control;
   uint32_t baud_divisor;
@@ -78,7 +83,7 @@ typedef struct {
   size_t out_current;
   const char *out_buf;
   rtems_termios_tty *tty;
-} ns16550_context;
+};
 
 extern const rtems_termios_device_handler ns16550_handler_interrupt;
 extern const rtems_termios_device_handler ns16550_handler_polled;
diff --git a/bsps/shared/dev/serial/ns16550-context.c 
b/bsps/shared/dev/serial/ns16550-context.c
index ce55b8309cc..70e73fc8c93 100644
--- a/bsps/shared/dev/serial/ns16550-context.c
+++ b/bsps/shared/dev/serial/ns16550-context.c
@@ -1,6 +1,6 @@
 /**
  *  @file
- *  
+ *
  *  This file contains the TTY driver for the National Semiconductor NS16550.
  *
  *  This part is widely cloned and second sourced.  It is found in a number
@@ -112,6 +112,8 @@ static uint32_t NS16550_GetBaudDivisor(ns16550_context 
*ctx, uint32_t baud)
   NS16550_FRACTIONAL_DIVIDER,
   fractionalDivider
 );
+  } else if (ctx->calculate_baud_divisor != NULL) {
+baudDivisor = ctx->calculate_baud_divisor(ctx, baud);
   }
 
   return baudDivisor;
@@ -165,7 +167,7 @@ bool ns16550_probe(rtems_termios_device_context *base)
 
   ctx->modem_control = SP_MODEM_IRQ;
 
-  pNS16550 = ctx->port;
+  pNS16550 = ctx->port;
   setReg   = ctx->set_reg;
   getReg   = ctx->get_reg;
 
-- 
2.17.1

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] bsp/raspberrypi: AUX uart driver

2020-01-15 Thread G S Niteesh
This patch adds the driver for aux driver present in Raspberry
Pi 3 and above, this uart is currently used as the primary uart.
The AUX uart is similar to ns16550, it uses the libchip/ns16550
driver.
---
 bsps/arm/raspberrypi/console/console-config.c | 113 --
 bsps/arm/raspberrypi/include/bsp/usart.h  |   1 +
 2 files changed, 107 insertions(+), 7 deletions(-)

diff --git a/bsps/arm/raspberrypi/console/console-config.c 
b/bsps/arm/raspberrypi/console/console-config.c
index 48c4c6a3ec7..6ff018fb8ef 100644
--- a/bsps/arm/raspberrypi/console/console-config.c
+++ b/bsps/arm/raspberrypi/console/console-config.c
@@ -24,6 +24,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -34,35 +35,103 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
-
+/**
+ * UART0 - PL011
+ * UART1 - AUX UART
+ */
 #define UART0 "/dev/ttyS0"
+#define UART1 "/dev/ttyS1"
 #define FBCONS"/dev/fbcons"
 
 arm_pl011_context pl011_context;
+ns16550_context aux_context;
 
 rpi_fb_context fb_context;
 
-static void output_char_serial(char c)
+static void output_char_pl011(char c)
 {
   arm_pl011_write_polled(&pl011_context.base, c);
 }
 
+static void output_char_aux(char c)
+{
+  ns16550_polled_putchar(&aux_context.base, c);
+}
+
 void output_char_fb(char c)
 {
   fbcons_write_polled(&fb_context.base, c);
 }
 
+static uint8_t raspberrypi_get_reg(uintptr_t port, uint8_t index)
+{
+  volatile uint32_t *val = (volatile uint32_t *)port + index;
+  return (uint8_t) *val;
+}
+
+static void raspberrypi_set_reg(uintptr_t port, uint8_t index, uint8_t val)
+{
+  volatile uint32_t *reg = (volatile uint32_t *)port + index;
+  *reg = val;
+}
+
 static void init_ctx_arm_pl011(
   const void *fdt,
   int node
 )
 {
   arm_pl011_context *ctx = &pl011_context;
-  rtems_termios_device_context_initialize(&ctx->base, "UART");
+  rtems_termios_device_context_initialize(&ctx->base, "UART 0");
   ctx->regs = raspberrypi_get_reg_of_node(fdt, node);
 }
 
+static uint32_t calculate_baud_divisor(
+  ns16550_context *ctx,
+  uint32_t baud
+)
+{
+  uint32_t baudDivisor = (ctx->clock / (8 * baud)) - 1;
+  return baudDivisor;
+}
+
+static void init_ctx_aux(
+  const void *fdt,
+  int node
+)
+{
+  const char *status;
+  int len;
+  ns16550_context *ctx = &aux_context;
+  rtems_termios_device_context_initialize(&ctx->base, "UART 1");
+
+  status = fdt_getprop(fdt, node, "status", &len);
+  if (status == NULL){
+return ;
+  }
+
+  if ( strcmp(status, "disabled") == 0 ) {
+return ;
+  }
+
+  ctx->port = (uintptr_t) raspberrypi_get_reg_of_node(fdt, node);
+  ctx->initial_baud = AUX_DEFAULT_BAUD;
+  ctx->clock = BCM2835_CLOCK_FREQ;
+  ctx->calculate_baud_divisor = calculate_baud_divisor;
+  ctx->get_reg = raspberrypi_get_reg;
+  ctx->set_reg = raspberrypi_set_reg;
+
+  rtems_gpio_bsp_select_specific_io(0, 14, RPI_ALT_FUNC_5, NULL);
+  rtems_gpio_bsp_select_specific_io(0, 15, RPI_ALT_FUNC_5, NULL);
+  rtems_gpio_bsp_set_resistor_mode(0, 14, NO_PULL_RESISTOR);
+  rtems_gpio_bsp_set_resistor_mode(0, 15, NO_PULL_RESISTOR);
+
+  BCM2835_REG(AUX_ENABLES) |= 0x1;
+  ns16550_probe(&ctx->base);
+}
+
 static void register_fb( void )
 {
   if (fbcons_probe(&fb_context.base) == true) {
@@ -87,16 +156,27 @@ static void console_select( void )
 link(FBCONS, CONSOLE_DEVICE_NAME);
 return ;
   }
+} else if ( strncmp( opt, UART1, sizeof(UART1) - 1 ) == 0) {
+  BSP_output_char = output_char_aux;
+  link(UART1, CONSOLE_DEVICE_NAME);
+} else if ( strncmp( opt, UART0, sizeof(UART0) - 1 ) == 0) {
+  BSP_output_char = output_char_pl011;
+  link(UART0, CONSOLE_DEVICE_NAME);
 }
   }
-  BSP_output_char = output_char_serial;
-  link(UART0, CONSOLE_DEVICE_NAME);
+  /**
+   * If no command line option was given, default to AUX uart.
+   */
+  BSP_output_char = output_char_aux;
+  link(UART1, CONSOLE_DEVICE_NAME);
 }
 
 static void uart_probe(void)
 {
   static bool initialized = false;
   const void *fdt;
+  const char *console;
+  int len;
   int node;
 
   if ( initialized ) {
@@ -104,17 +184,29 @@ static void uart_probe(void)
   }
 
   fdt = bsp_fdt_get();
-  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-pl011");
 
+  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-pl011");
   init_ctx_arm_pl011(fdt, node);
 
+  node = fdt_node_offset_by_compatible(fdt, -1, "brcm,bcm2835-aux-uart");
+  init_ctx_aux(fdt, node);
+
+  node = fdt_path_offset(fdt, "/aliases");
+  console = fdt_getprop(fdt, node, "serial0", &len);
+
+  if (strcmp(console, "/soc/serial@7e215040") == 0) {
+BSP_output_char = output_char_aux;
+  }else {
+BSP_output_char = output_char_pl011;
+  }
+
   initialized = true;
 }
 
 static void output_char(char c)
 {
   uart_probe();
-  output_char_serial(c);
+  (*BSP_output_char)(c);
 }
 
 rtems_status_code console_initialize(
@@ -133,6 +225,13 @@ rtems_status_code console_initialize(
 &pl011_context.base
   );
 
+  rtems_termios_device_install(
+UART1,

Link issue on xilinx_zynq_a9_qemu BSP on rtems-libbsd head

2020-01-15 Thread Lou Woods
Hello all,

I just pulled from the master of both rtems 
(362cf319d44e7e64987f12aa36ea030e6298c586) and rtems-libbsd 
(d892051f37c2c4ad7f345f6a817ea3d38e56a431) trees and ran into an couple 
undefined references when linking an application outside of the tree.  The 
application doesn't directly use either symbol and has worked unmodified on 
older trees.  This build issue is not present when using the 5-freebsd-12 
branch of rtems-libbsd on the same application code.  I can move forward with 
the 5-freebsd-12 branch so this isn't a show stopper for me.

$ make
arm-rtems5-gcc --pipe -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard 
-mtune=cortex-a9 -O0 -g -ffunction-sections -fdata-sections -Wall 
-Wmissing-prototypes -Wimplicit-function-declaration -Wstrict-prototypes 
-Wnested-externs -B 
/home/woods/zynq-quickstart-trial/bsp-install/arm-rtems5/xilinx_zynq_a9_qemu/lib/
 -specs bsp_specs -qrtems init.c  -o init.exe -lbsd -lm -ltelnetd
/data/home/woods/zynq-quickstart-trial/tools/bin/../lib/gcc/arm-rtems5/7.5.0/../../../../arm-rtems5/bin/ld:
 
/home/woods/zynq-quickstart-trial/bsp-install/arm-rtems5/xilinx_zynq_a9_qemu/lib/libbsd.a(uipc_mbuf.c.18.o):
 in function `m_unmappedtouio':
/data/home/woods/zynq-quickstart-trial/rtems-libbsd/build/arm-rtems5-xilinx_zynq_a9_qemu-default/../../freebsd/sys/kern/uipc_mbuf.c:1813:
 undefined reference to `PHYS_TO_VM_PAGE'
/data/home/woods/zynq-quickstart-trial/tools/bin/../lib/gcc/arm-rtems5/7.5.0/../../../../arm-rtems5/bin/ld:
 
/data/home/woods/zynq-quickstart-trial/rtems-libbsd/build/arm-rtems5-xilinx_zynq_a9_qemu-default/../../freebsd/sys/kern/uipc_mbuf.c:1814:
 undefined reference to `uiomove_fromphys'
collect2: error: ld returned 1 exit status
make: *** [init.exe] Error 1

RTEMS was configured like this:
../rtems/configure --prefix=${rw}/bsp-install --target=arm-rtems5 \
 --enable-rtemsbsp=xilinx_zynq_a9_qemu --disable-networking

libbsd was configured like this:
$ git clone git://git.rtems.org/rtems-libbsd.git
$ cd ./rtems-libbsd
$ git submodule init
$ git submodule update rtems_waf
$ python3 ./waf configure --rtems-tools=${rw}/tools --rtems=${rw}/bsp-install \
 --prefix=${rw}/bsp-install --rtems-bsps=arm/xilinx_zynq_a9_qemu
$ python3 ./waf
$ python3 ./waf install

Makefile

include $(RTEMS_MAKEFILE_PATH)/Makefile.inc
include $(RTEMS_MAKEFILE_PATH)/make/target.cfg
include $(RTEMS_CUSTOM)

all: init.exe

CFLAGS += -B ${RTEMS_MAKEFILE_PATH}/lib/ -specs bsp_specs -qrtems

init.exe: init.c
$(CC) $(CFLAGS) init.c  -o $@ -lbsd -lm -ltelnetd

 clean:
 init.exe  

If any other information can be useful, please let me know.

Thanks,
Lou Woods
On-Line Applications Research

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel