]> rtime.felk.cvut.cz Git - l4.git/blob - kernel/fiasco/src/lib/uart/arm/uart_omap35x.cc
update
[l4.git] / kernel / fiasco / src / lib / uart / arm / uart_omap35x.cc
1 #include "uart_omap35x.h"
2
3 namespace L4
4 {
5   enum {
6     DLL_REG  = 0x00,
7     RHR_REG  = 0x00,
8     THR_REG  = 0x00,
9     IER_REG  = 0x04,
10     DLH_REG  = 0x04,
11     LCD_REG  = 0x08,
12     LSR_REG  = 0x14,
13     SSR_REG  = 0x44,
14     SYSC_REG = 0x54,
15     SYSS_REG = 0x58,
16
17     LCD_REG_CHAR_LENGTH_5BIT       = 0 << 0,
18     LCD_REG_CHAR_LENGTH_6BIT       = 1 << 0,
19     LCD_REG_CHAR_LENGTH_7BIT       = 2 << 0,
20     LCD_REG_CHAR_LENGTH_8BIT       = 3 << 0,
21     LCD_REG_CHAR_NB_STOP_2         = 1 << 2,
22     LCD_REG_CHAR_PARITY_EN         = 1 << 3,
23     LCD_REG_CHAR_PARITY_TYPE1_EVEN = 1 << 4,
24
25     LSR_REG_RX_FIFO_E_AVAIL        = 1 << 0,
26     LSR_REG_TX_FIFO_E_EMPTY        = 1 << 5,
27
28     SSR_REG_TX_FIFO_FULL           = 1 << 0,
29
30     SYSC_REG_SOFTRESET             = 1 << 1,
31
32     SYSC_REG_RESETDONE             = 1 << 0,
33   };
34
35
36   unsigned long Uart_omap35x::rd(unsigned long reg) const
37   {
38     volatile unsigned long *r = (unsigned long*)(_base + reg);
39     return *r;
40   }
41
42   void Uart_omap35x::wr(unsigned long reg, unsigned long val) const
43   {
44     volatile unsigned long *r = (unsigned long*)(_base + reg);
45     *r = val;
46   }
47
48   bool Uart_omap35x::startup(unsigned long base)
49   {
50     _base = base;
51
52     // Reset UART
53     //wr(SYSC_REG, rd(SYSC_REG) | SYSC_REG_SOFTRESET);
54     //while (!(rd(SYSS_REG) & SYSC_REG_RESETDONE))
55     //  ;
56
57     return true;
58   }
59
60   void Uart_omap35x::shutdown()
61   {
62   }
63
64   bool Uart_omap35x::enable_rx_irq(bool enable)
65   {
66     wr(IER_REG, enable ? 1 : 0);
67     return true;
68   }
69   bool Uart_omap35x::enable_tx_irq(bool /*enable*/) { return false; }
70   bool Uart_omap35x::change_mode(Transfer_mode, Baud_rate r)
71   {
72     if (r != 115200)
73       return false;
74
75     return true;
76   }
77
78   int Uart_omap35x::get_char(bool blocking) const
79   {
80     while (!char_avail())
81       if (!blocking)
82         return -1;
83
84     return rd(RHR_REG);
85   }
86
87   int Uart_omap35x::char_avail() const
88   {
89     return rd(LSR_REG) & LSR_REG_RX_FIFO_E_AVAIL;
90   }
91
92   void Uart_omap35x::out_char(char c) const
93   {
94     wr(THR_REG, c);
95     while (!(rd(LSR_REG) & LSR_REG_TX_FIFO_E_EMPTY))
96       ;
97   }
98
99   int Uart_omap35x::write(char const *s, unsigned long count) const
100   {
101     unsigned long c = count;
102     while (c)
103       {
104         if (*s == 10)
105           out_char(13);
106         out_char(*s++);
107         --c;
108       }
109     return count;
110   }
111
112 };
113