Add preliminary support for ADM5120 big-endian targets (Zyxel P-335WT for instance...
[openwrt.git] / target / linux / generic-2.6 / image / lzma-loader / src / uart16550.c
1 /*
2 * Copyright (C) 2001 MontaVista Software Inc.
3 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 *
10 */
11
12
13 #include "uart16550.h"
14
15 /* === CONFIG === */
16
17 #define BASE 0xb8058000
18 #define MAX_BAUD 1152000
19 #define REG_OFFSET 4
20
21 /* === END OF CONFIG === */
22
23 /* register offset */
24 #define OFS_RCV_BUFFER (0*REG_OFFSET)
25 #define OFS_TRANS_HOLD (0*REG_OFFSET)
26 #define OFS_SEND_BUFFER (0*REG_OFFSET)
27 #define OFS_INTR_ENABLE (1*REG_OFFSET)
28 #define OFS_INTR_ID (2*REG_OFFSET)
29 #define OFS_DATA_FORMAT (3*REG_OFFSET)
30 #define OFS_LINE_CONTROL (3*REG_OFFSET)
31 #define OFS_MODEM_CONTROL (4*REG_OFFSET)
32 #define OFS_RS232_OUTPUT (4*REG_OFFSET)
33 #define OFS_LINE_STATUS (5*REG_OFFSET)
34 #define OFS_MODEM_STATUS (6*REG_OFFSET)
35 #define OFS_RS232_INPUT (6*REG_OFFSET)
36 #define OFS_SCRATCH_PAD (7*REG_OFFSET)
37
38 #define OFS_DIVISOR_LSB (0*REG_OFFSET)
39 #define OFS_DIVISOR_MSB (1*REG_OFFSET)
40
41
42 /* memory-mapped read/write of the port */
43 #define UART16550_READ(y) (*((volatile uint32*)(BASE + y)))
44 #define UART16550_WRITE(y, z) ((*((volatile uint32*)(BASE + y))) = z)
45
46 #define DEBUG_LED (*(unsigned short*)0xb7ffffc0)
47 #define OutputLED(x) (DEBUG_LED = x)
48
49 void Uart16550Init(uint32 baud, uint8 data, uint8 parity, uint8 stop)
50 {
51 /* disable interrupts */
52 UART16550_WRITE(OFS_INTR_ENABLE, 0);
53
54 /* set up buad rate */
55 {
56 uint32 divisor;
57
58 /* set DIAB bit */
59 UART16550_WRITE(OFS_LINE_CONTROL, 0x80);
60
61 /* set divisor */
62 divisor = MAX_BAUD / baud;
63 UART16550_WRITE(OFS_DIVISOR_LSB, divisor & 0xff);
64 UART16550_WRITE(OFS_DIVISOR_MSB, (divisor & 0xff00)>>8);
65
66 /* clear DIAB bit */
67 UART16550_WRITE(OFS_LINE_CONTROL, 0x0);
68 }
69
70 /* set data format */
71 UART16550_WRITE(OFS_DATA_FORMAT, data | parity | stop);
72 }
73
74 uint8 Uart16550GetPoll()
75 {
76 while((UART16550_READ(OFS_LINE_STATUS) & 0x1) == 0);
77 return UART16550_READ(OFS_RCV_BUFFER);
78 }
79
80
81 void Uart16550Put(uint8 byte)
82 {
83 while ((UART16550_READ(OFS_LINE_STATUS) &0x20) == 0);
84 UART16550_WRITE(OFS_SEND_BUFFER, byte);
85 }
86
This page took 0.046021 seconds and 5 git commands to generate.