Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Oct 2013 17:25:24 +0200
From:      Steven Lawrance <stl@koffein.net>
To:        freebsd-arm <freebsd-arm@freebsd.org>
Subject:   pl011 UART driver (as used on Raspberry Pi) baud rate divisor
Message-ID:  <1382282023-sup-4600@luwak.koffein.net>

index | next in thread | raw e-mail

[-- Attachment #1 --]
Hi all,

attached is a small patch to calculate the baud rate divisor for the
pl011 UART.  The existing code used hardcoded values which work for a
UARTCLK frequency of 3Mhz and a baud rate of 115200.  If my
calculations are correct, the same values should still end up being
set on the RPI but this patch allows it to work on an i.MX233 with a
fixed 24MHz clock frequency and it obeys the values in the FDT.

Is someone able to test it on the Raspberry Pi?

cheers,

-- 
Steven Lawrance
stl@koffein.net

[-- Attachment #2 --]
Index: sys/dev/uart/uart_dev_pl011.c
===================================================================
--- sys/dev/uart/uart_dev_pl011.c	(revision 256779)
+++ sys/dev/uart/uart_dev_pl011.c	(arbetskopia)
@@ -147,9 +147,6 @@
 		break;
 	}
 
-	/* TODO: Calculate divisors */
-	baud = (0x1 << 16) | 0x28;
-
 	if (stopbits == 2)
 		line |= LCR_H_STP2;
 	else
@@ -164,8 +161,11 @@
 	line &=  ~LCR_H_FEN;
 	ctrl |= (CR_RXE | CR_TXE | CR_UARTEN);
 
-	__uart_setreg(bas, UART_IBRD, ((uint32_t)(baud >> 16)) & IBRD_BDIVINT);
-	__uart_setreg(bas, UART_FBRD, (uint32_t)(baud) & FBRD_BDIVFRAC);
+	if (bas->rclk != 0 && baudrate != 0) {
+		baud = bas->rclk * 4 / baudrate;
+		__uart_setreg(bas, UART_IBRD, ((uint32_t)(baud >> 6)) & IBRD_BDIVINT);
+		__uart_setreg(bas, UART_FBRD, (uint32_t)(baud & 0x3F) & FBRD_BDIVFRAC);
+	}
 
 	/* Add config. to line before reenabling UART */
 	__uart_setreg(bas, UART_LCR_H, (__uart_getreg(bas, UART_LCR_H) &
home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1382282023-sup-4600>