OMAP: DISPC: Fix to disable also interface clocks. 2nd.
[linux-ginger.git] / arch / ppc / boot / common / ns16550.c
blobfc5b7204194802db616c2271208eaadc79fc219f
1 /*
2 * COM1 NS16550 support
3 */
5 #include <linux/types.h>
6 #include <linux/serial.h>
7 #include <linux/serial_reg.h>
8 #include <asm/serial.h>
10 #if defined(CONFIG_XILINX_VIRTEX)
11 #include <platforms/4xx/xparameters/xparameters.h>
12 #endif
13 #include "nonstdio.h"
14 #include "serial.h"
16 #define SERIAL_BAUD 9600
18 extern unsigned long ISA_io;
20 static struct serial_state rs_table[RS_TABLE_SIZE] = {
21 SERIAL_PORT_DFNS /* Defined in <asm/serial.h> */
24 static int shift;
26 unsigned long serial_init(int chan, void *ignored)
28 unsigned long com_port, base_baud;
29 unsigned char lcr, dlm;
31 /* We need to find out which type io we're expecting. If it's
32 * 'SERIAL_IO_PORT', we get an offset from the isa_io_base.
33 * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */
34 switch (rs_table[chan].io_type) {
35 case SERIAL_IO_PORT:
36 com_port = rs_table[chan].port;
37 break;
38 case SERIAL_IO_MEM:
39 com_port = (unsigned long)rs_table[chan].iomem_base;
40 break;
41 default:
42 /* We can't deal with it. */
43 return -1;
46 /* How far apart the registers are. */
47 shift = rs_table[chan].iomem_reg_shift;
48 /* Base baud.. */
49 base_baud = rs_table[chan].baud_base;
51 /* save the LCR */
52 lcr = inb(com_port + (UART_LCR << shift));
53 /* Access baud rate */
54 outb(com_port + (UART_LCR << shift), 0x80);
55 dlm = inb(com_port + (UART_DLM << shift));
57 * Test if serial port is unconfigured.
58 * We assume that no-one uses less than 110 baud or
59 * less than 7 bits per character these days.
60 * -- paulus.
63 if ((dlm <= 4) && (lcr & 2))
64 /* port is configured, put the old LCR back */
65 outb(com_port + (UART_LCR << shift), lcr);
66 else {
67 /* Input clock. */
68 outb(com_port + (UART_DLL << shift),
69 (base_baud / SERIAL_BAUD) & 0xFF);
70 outb(com_port + (UART_DLM << shift),
71 (base_baud / SERIAL_BAUD) >> 8);
72 /* 8 data, 1 stop, no parity */
73 outb(com_port + (UART_LCR << shift), 0x03);
74 /* RTS/DTR */
75 outb(com_port + (UART_MCR << shift), 0x03);
77 /* Clear & enable FIFOs */
78 outb(com_port + (UART_FCR << shift), 0x07);
80 return (com_port);
83 void
84 serial_putc(unsigned long com_port, unsigned char c)
86 while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0)
88 outb(com_port, c);
91 unsigned char
92 serial_getc(unsigned long com_port)
94 while ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0)
96 return inb(com_port);
99 int
100 serial_tstc(unsigned long com_port)
102 return ((inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0);