@@ -82,6 +82,7 @@ INCLUDE FILES: drivers/uart.h
82
82
#define REG_MDC 0x04 /* Modem control reg. */
83
83
#define REG_LSR 0x05 /* Line status reg. */
84
84
#define REG_MSR 0x06 /* Modem status reg. */
85
+ #define REG_DLF 0x30 /* Divisor Latch Fraction. */
85
86
86
87
/* equates for interrupt enable register */
87
88
@@ -203,6 +204,7 @@ INCLUDE FILES: drivers/uart.h
203
204
#define MDC (n ) (uart[n].port + REG_MDC * UART_REG_ADDR_INTERVAL)
204
205
#define LSR (n ) (uart[n].port + REG_LSR * UART_REG_ADDR_INTERVAL)
205
206
#define MSR (n ) (uart[n].port + REG_MSR * UART_REG_ADDR_INTERVAL)
207
+ #define DLF (n ) (uart[n].port + REG_DLF * UART_REG_ADDR_INTERVAL)
206
208
207
209
#define IIRC (n ) uart[n].iirCache
208
210
@@ -247,7 +249,7 @@ void uart_init(int which, /* UART channel to initialize */
247
249
)
248
250
{
249
251
unsigned int oldLevel ; /* old interrupt lock level */
250
- uint32_t divisor ; /* baud rate divisor */
252
+ uint32_t divisor , fdivisor , tmp ; /* baud rate divisors */
251
253
uint8_t mdc = 0 ;
252
254
253
255
uart [which ].port = init_info -> regs ;
@@ -257,13 +259,22 @@ void uart_init(int which, /* UART channel to initialize */
257
259
258
260
oldLevel = interrupt_lock ();
259
261
262
+ /* The formula for calculating these baud rate divisors is:
263
+ * baud rate = (Fbase) / (16 * (divisor+(fdivisor/16))
264
+ */
265
+
260
266
/* calculate baud rate divisor */
261
267
divisor = (init_info -> sys_clk_freq / init_info -> baud_rate ) >> 4 ;
268
+ /* Calculate baud rate fractional divisor from the remainder.
269
+ * The result is rounded to the nearest whole number */
270
+ tmp = init_info -> baud_rate >> 4 ;
271
+ fdivisor = (((init_info -> sys_clk_freq >> 4 ) % init_info -> baud_rate ) + (tmp >> 1 )) / tmp ;
262
272
263
273
/* set the DLAB to access the baud rate divisor registers */
264
274
OUTBYTE (LCR (which ), LCR_DLAB );
265
275
OUTBYTE (BRDL (which ), (unsigned char )(divisor & 0xff ));
266
276
OUTBYTE (BRDH (which ), (unsigned char )((divisor >> 8 ) & 0xff ));
277
+ OUTBYTE (DLF (which ), (unsigned char )(fdivisor & 0xf ));
267
278
268
279
/* specify the format of the asynchronous data communication exchange */
269
280
OUTBYTE (LCR (which ), init_info -> async_format );
0 commit comments