[haiku-commits] haiku: hrev44127 - src/system/kernel/arch/arm headers/private/kernel/arch/arm src/system/boot/platform/raspberrypi_arm headers/private/kernel/arch/arm/board/raspberry_pi

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Mon, 7 May 2012 05:55:25 +0200 (CEST)

hrev44127 adds 1 changeset to branch 'master'
old head: c76127fadeb72c8e8791a3e0c5c9486270d53504
new head: b74906293b1e8749c46ce0972693a06e45053908

----------------------------------------------------------------------------

b749062: pl011 uart: Add port_init code
  
  * Add code to initilize the uart port
  * Fix uart clock

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44127
Commit:      b74906293b1e8749c46ce0972693a06e45053908
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b749062
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Mon May  7 03:53:56 2012 UTC

----------------------------------------------------------------------------

4 files changed, 37 insertions(+), 9 deletions(-)
.../arch/arm/board/raspberry_pi/board_config.h     |    4 +--
headers/private/kernel/arch/arm/uart_pl011.h       |   11 ++++++
.../boot/platform/raspberrypi_arm/serial.cpp       |    3 +-
src/system/kernel/arch/arm/uart_pl011.cpp          |   28 ++++++++++++----

----------------------------------------------------------------------------

diff --git a/headers/private/kernel/arch/arm/board/raspberry_pi/board_config.h 
b/headers/private/kernel/arch/arm/board/raspberry_pi/board_config.h
index 626dadf..5393754 100644
--- a/headers/private/kernel/arch/arm/board/raspberry_pi/board_config.h
+++ b/headers/private/kernel/arch/arm/board/raspberry_pi/board_config.h
@@ -24,8 +24,8 @@
 
 #define BOARD_UART_DEBUG BOARD_UART2_BASE
 
-#define BOARD_UART_CLOCK 125000000
-       /* 125Mhz, strange */
+#define BOARD_UART_CLOCK 3000000
+       /* 3Mhz */
 
 
 #endif /* _BOARD_RASPBERRY_PI_BOARD_CONFIG_H */
diff --git a/headers/private/kernel/arch/arm/uart_pl011.h 
b/headers/private/kernel/arch/arm/uart_pl011.h
index b09b373..5510dbc 100644
--- a/headers/private/kernel/arch/arm/uart_pl011.h
+++ b/headers/private/kernel/arch/arm/uart_pl011.h
@@ -72,6 +72,17 @@
 #define PL011_CR_SIREN 0x0002 // SIR enable
 #define PL011_CR_UARTEN 0x0001 // UART enable
 
+#define PL011_LCRH_SPS         0x80
+#define PL01x_LCRH_WLEN_8      0x60
+#define PL01x_LCRH_WLEN_7      0x40
+#define PL01x_LCRH_WLEN_6      0x20
+#define PL01x_LCRH_WLEN_5      0x00
+#define PL01x_LCRH_FEN         0x10
+#define PL01x_LCRH_STP2                0x08
+#define PL01x_LCRH_EPS         0x04
+#define PL01x_LCRH_PEN         0x02
+#define PL01x_LCRH_BRK         0x01
+
 // TODO: Other PL01x registers + values?
 
 
diff --git a/src/system/boot/platform/raspberrypi_arm/serial.cpp 
b/src/system/boot/platform/raspberrypi_arm/serial.cpp
index 243dc64..4c2e77f 100644
--- a/src/system/boot/platform/raspberrypi_arm/serial.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/serial.cpp
@@ -89,7 +89,8 @@ serial_init(void)
        }
 
        gUARTInfo->init_early();
-       gUARTInfo->init(gUARTInfo->base);
+       gUARTInfo->init_port(gUARTInfo->base, 9600);
+       //gUARTInfo->init(gUARTInfo->base);
 
        serial_enable();
 
diff --git a/src/system/kernel/arch/arm/uart_pl011.cpp 
b/src/system/kernel/arch/arm/uart_pl011.cpp
index 52b2af1..d57a21f 100644
--- a/src/system/kernel/arch/arm/uart_pl011.cpp
+++ b/src/system/kernel/arch/arm/uart_pl011.cpp
@@ -31,6 +31,28 @@ read_pl011(addr_t base, uint reg)
 void
 uart_pl011_init_port(addr_t base, uint baud)
 {
+       uint16 clockDiv
+               = (baud > BOARD_UART_CLOCK / 16) ? 8 : 4;
+       uint16 baudDivisor = BOARD_UART_CLOCK * clockDiv / baud;
+               // TODO: Round to closest baud divisor
+       uint16 lcr = PL01x_LCRH_WLEN_8;
+
+       // Disable everything
+       unsigned char originalCR
+               = read_pl011(base, PL011_CR);
+       write_pl011(base, PL011_CR, 0);
+
+       // Set baud divisor
+       write_pl011(base, PL011_FBRD, baudDivisor & 0x3f);
+       write_pl011(base, PL011_IBRD, baudDivisor >> 6);
+
+       // Set LCR
+       write_pl011(base, PL011_LCRH, lcr);
+
+       // Disable auto RTS / CTS in original CR
+       originalCR &= ~(PL011_CR_CTSEN | PL011_CR_RTSEN);
+
+       write_pl011(base, PL011_CR, originalCR);
 }
 
 
@@ -60,12 +82,6 @@ uart_pl011_init(addr_t base)
 
        while (read_pl011(base, PL01x_FR) & PL01x_FR_BUSY);
                // Wait for xmit
-
-       // Write baud divider
-       #if 0
-       write_pl011(base, PL011_FBRD, div & 0x3F);
-       write_pl011(base, PL011_IBRD, div >> 6);
-       #endif
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev44127 - src/system/kernel/arch/arm headers/private/kernel/arch/arm src/system/boot/platform/raspberrypi_arm headers/private/kernel/arch/arm/board/raspberry_pi - kallisti5