[U-Boot] [PATCH 07/17] LEON3: serial baud rate register support multiple buses with different frequency.

2010-05-18 Thread Daniel Hellstrom
Signed-off-by: Daniel Hellstrom dan...@gaisler.com
---
 arch/sparc/cpu/leon3/serial.c |   17 ++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/arch/sparc/cpu/leon3/serial.c b/arch/sparc/cpu/leon3/serial.c
index 8964310..1f17ede 100644
--- a/arch/sparc/cpu/leon3/serial.c
+++ b/arch/sparc/cpu/leon3/serial.c
@@ -47,11 +47,18 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 
 ambapp_dev_apbuart *leon3_apbuart = NULL;
+unsigned int apbuart_freq = CONFIG_SYS_CLK_FREQ;
+
+unsigned int apbuart_calc_scaler(unsigned int apbuart_freq, unsigned int baud)
+{
+   return apbuart_freq*10)/(baud*8))-5)/10);
+}
 
 int serial_init(void)
 {
ambapp_apbdev apbdev;
unsigned int tmp;
+   unsigned int freq;
 
/* find UART */
if (ambapp_apb_find(ambapp_plb, VENDOR_GAISLER, GAISLER_APBUART,
@@ -65,7 +72,13 @@ int serial_init(void)
 *
 * Receiver  transmitter enable
 */
+#ifdef CONFIG_SYS_GRLIB_APBUART_SCALER
leon3_apbuart-scaler = CONFIG_SYS_GRLIB_APBUART_SCALER;
+#else
+   /* APBUART Frequency is equal to bus frequency */
+   freq = ambapp_bus_freq(ambapp_plb, apbdev.ahb_bus_index);
+   leon3_apbuart-scaler = apbuart_calc_scaler(freq, 
CONFIG_BAUDRATE);
+#endif
 
/* Let bit 11 be unchanged (debug bit for GRMON) */
tmp = READ_WORD(leon3_apbuart-ctrl);
@@ -136,9 +149,7 @@ void serial_setbrg(void)
/* update baud rate settings, read it from gd-baudrate */
unsigned int scaler;
if (leon3_apbuart  (gd-baudrate  0)) {
-   scaler =
-   (((CONFIG_SYS_CLK_FREQ * 10) / (gd-baudrate * 8)) -
-5) / 10;
+   scaler = apbuart_calc_scaler(apbuart_freq, gd-baudrate);
leon3_apbuart-scaler = scaler;
}
return;
-- 
1.5.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 07/17] LEON3: serial baud rate register support multiple buses with different frequency.

2010-01-28 Thread Daniel Hellstrom
Signed-off-by: Daniel Hellstrom dan...@gaisler.com
---
 cpu/leon3/serial.c |   17 ++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cpu/leon3/serial.c b/cpu/leon3/serial.c
index 8964310..1f17ede 100644
--- a/cpu/leon3/serial.c
+++ b/cpu/leon3/serial.c
@@ -47,11 +47,18 @@ DECLARE_GLOBAL_DATA_PTR;
 #endif
 
 ambapp_dev_apbuart *leon3_apbuart = NULL;
+unsigned int apbuart_freq = CONFIG_SYS_CLK_FREQ;
+
+unsigned int apbuart_calc_scaler(unsigned int apbuart_freq, unsigned int baud)
+{
+   return apbuart_freq*10)/(baud*8))-5)/10);
+}
 
 int serial_init(void)
 {
ambapp_apbdev apbdev;
unsigned int tmp;
+   unsigned int freq;
 
/* find UART */
if (ambapp_apb_find(ambapp_plb, VENDOR_GAISLER, GAISLER_APBUART,
@@ -65,7 +72,13 @@ int serial_init(void)
 *
 * Receiver  transmitter enable
 */
+#ifdef CONFIG_SYS_GRLIB_APBUART_SCALER
leon3_apbuart-scaler = CONFIG_SYS_GRLIB_APBUART_SCALER;
+#else
+   /* APBUART Frequency is equal to bus frequency */
+   freq = ambapp_bus_freq(ambapp_plb, apbdev.ahb_bus_index);
+   leon3_apbuart-scaler = apbuart_calc_scaler(freq, 
CONFIG_BAUDRATE);
+#endif
 
/* Let bit 11 be unchanged (debug bit for GRMON) */
tmp = READ_WORD(leon3_apbuart-ctrl);
@@ -136,9 +149,7 @@ void serial_setbrg(void)
/* update baud rate settings, read it from gd-baudrate */
unsigned int scaler;
if (leon3_apbuart  (gd-baudrate  0)) {
-   scaler =
-   (((CONFIG_SYS_CLK_FREQ * 10) / (gd-baudrate * 8)) -
-5) / 10;
+   scaler = apbuart_calc_scaler(apbuart_freq, gd-baudrate);
leon3_apbuart-scaler = scaler;
}
return;
-- 
1.5.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot