123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "ops.h"
- #include "io.h"
- #include "stdio.h"
- #define UART_DLL 0
- #define UART_DLM 1
- #define UART_FCR 2
- #define UART_FCR_CLEAR_RCVR 0x02
- #define UART_FCR_CLEAR_XMIT 0x04
- #define UART_LCR 3
- #define UART_MCR 4
- #define UART_MCR_RTS 0x02
- #define UART_MCR_DTR 0x01
- #define UART_LCR_DLAB 0x80
- #define UART_LCR_WLEN8 0x03
- static int virtex_ns16550_console_init(void *devp)
- {
- unsigned char *reg_base;
- u32 reg_shift, reg_offset, clk, spd;
- u16 divisor;
- int n;
- if (dt_get_virtual_reg(devp, (void **)®_base, 1) < 1)
- return -1;
- n = getprop(devp, "reg-offset", ®_offset, sizeof(reg_offset));
- if (n == sizeof(reg_offset))
- reg_base += reg_offset;
- n = getprop(devp, "reg-shift", ®_shift, sizeof(reg_shift));
- if (n != sizeof(reg_shift))
- reg_shift = 0;
- n = getprop(devp, "current-speed", (void *)&spd, sizeof(spd));
- if (n != sizeof(spd))
- spd = 9600;
-
- n = getprop(devp, "clock-frequency", (void *)&clk, sizeof(clk));
- if (n != sizeof(clk))
- return -1;
- divisor = clk / (16 * spd);
-
- out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_DLAB);
-
- out_8(reg_base + (UART_DLL << reg_shift), divisor & 0xFF);
- out_8(reg_base + (UART_DLM << reg_shift), divisor >> 8);
-
- out_8(reg_base + (UART_LCR << reg_shift), UART_LCR_WLEN8);
-
- out_8(reg_base + (UART_MCR << reg_shift), UART_MCR_RTS | UART_MCR_DTR);
-
- out_8(reg_base + (UART_FCR << reg_shift),
- UART_FCR_CLEAR_XMIT | UART_FCR_CLEAR_RCVR);
- return 0;
- }
- int platform_specific_init(void)
- {
- void *devp;
- char devtype[MAX_PROP_LEN];
- char path[MAX_PATH_LEN];
- devp = finddevice("/chosen");
- if (devp == NULL)
- return -1;
- if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
- devp = finddevice(path);
- if (devp == NULL)
- return -1;
- if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
- && !strcmp(devtype, "serial")
- && (dt_is_compatible(devp, "ns16550")))
- virtex_ns16550_console_init(devp);
- }
- return 0;
- }
|