| 1 |
2 |
drasko |
/*
|
| 2 |
|
|
* OMAP UART Generic driver implementation.
|
| 3 |
|
|
*
|
| 4 |
|
|
* Copyright (C) 2007 Bahadir Balban
|
| 5 |
|
|
*
|
| 6 |
|
|
* The particular intention of this code is that it has been carefully written
|
| 7 |
|
|
* as decoupled from os-specific code and in a verbose way such that it clearly
|
| 8 |
|
|
* demonstrates how the device operates, reducing the amount of time to be spent
|
| 9 |
|
|
* for understanding the operational model and implementing a driver from
|
| 10 |
|
|
* scratch. This is the very first to be such a driver so far, hopefully it will
|
| 11 |
|
|
* turn out to be useful.
|
| 12 |
|
|
*/
|
| 13 |
|
|
|
| 14 |
|
|
#ifndef __OMAP_UART_H__
|
| 15 |
|
|
#define __OMAP_UART_H__
|
| 16 |
|
|
|
| 17 |
|
|
#include <l4/config.h> /* To get PLATFORM */
|
| 18 |
|
|
#include <l4lib/types.h>
|
| 19 |
|
|
|
| 20 |
|
|
#if defined(VARIANT_USERSPACE)
|
| 21 |
|
|
/* FIXME: Take this value in agreement from kernel, or from kernel only */
|
| 22 |
|
|
#include <l4/macros.h>
|
| 23 |
|
|
#include INC_ARCH(io.h)
|
| 24 |
|
|
#define OMAP_UART_BASE USERSPACE_CONSOLE_VBASE
|
| 25 |
|
|
#endif
|
| 26 |
|
|
|
| 27 |
|
|
#if defined(VARIANT_BAREMETAL)
|
| 28 |
|
|
#if defined(CONFIG_PLATFORM_BEAGLE)
|
| 29 |
|
|
#define OMAP_UART_BASE 0x49020000
|
| 30 |
|
|
#endif
|
| 31 |
|
|
#endif
|
| 32 |
|
|
|
| 33 |
|
|
/* Register offsets */
|
| 34 |
|
|
#define OMAP_UART_DLL 0x00
|
| 35 |
|
|
#define OMAP_UART_THR 0x00
|
| 36 |
|
|
#define OMAP_UART_RHR 0x00
|
| 37 |
|
|
#define OMAP_UART_DLH 0x04
|
| 38 |
|
|
#define OMAP_UART_IER 0x04
|
| 39 |
|
|
#define OMAP_UART_FCR 0x08
|
| 40 |
|
|
#define OMAP_UART_MCR 0x10
|
| 41 |
|
|
#define OMAP_UART_LSR 0x14
|
| 42 |
|
|
#define OMAP_UART_MDR1 0x20
|
| 43 |
|
|
#define OMAP_UART_LCR 0x0C
|
| 44 |
|
|
|
| 45 |
|
|
/* Modes supported by OMAP UART/IRDA/CIR IP */
|
| 46 |
|
|
#define OMAP_UART_MODE_UART16X 0x0
|
| 47 |
|
|
#define OMAP_UART_MODE_SIR 0x1
|
| 48 |
|
|
#define OMAP_UART_MODE_UART16X_AUTO_BAUD 0x2
|
| 49 |
|
|
#define OMAP_UART_MODE_UART13X 0x3
|
| 50 |
|
|
#define OMAP_UART_MODE_MIR 0x4
|
| 51 |
|
|
#define OMAP_UART_MODE_FIR 0x5
|
| 52 |
|
|
#define OMAP_UART_MODE_CIR 0x6
|
| 53 |
|
|
#define OMAP_UART_MODE_DEFAULT 0x7 /* Disable */
|
| 54 |
|
|
|
| 55 |
|
|
/* Number of data bits for UART */
|
| 56 |
|
|
#define OMAP_UART_DATA_BITS_5 0x0
|
| 57 |
|
|
#define OMAP_UART_DATA_BITS_6 0x1
|
| 58 |
|
|
#define OMAP_UART_DATA_BITS_7 0x2
|
| 59 |
|
|
#define OMAP_UART_DATA_BITS_8 0x3
|
| 60 |
|
|
|
| 61 |
|
|
/* Stop bits to be used for UART data */
|
| 62 |
|
|
#define OMAP_UART_STOP_BITS_1 0x0
|
| 63 |
|
|
#define OMAP_UART_STOP_BITS_1_5 0x1
|
| 64 |
|
|
|
| 65 |
|
|
/* Banked Register modes- ConfigA, ConfigB, Operational */
|
| 66 |
|
|
#define OMAP_UART_BANKED_MODE_OPERATIONAL 0x00
|
| 67 |
|
|
#define OMAP_UART_BANKED_MODE_CONFIG_A 0x80
|
| 68 |
|
|
#define OMAP_UART_BANKED_MODE_CONFIG_B 0xBF
|
| 69 |
|
|
|
| 70 |
|
|
void uart_tx_char(unsigned long uart_base, char c);
|
| 71 |
|
|
char uart_rx_char(unsigned long uart_base);
|
| 72 |
|
|
void uart_set_baudrate(unsigned long uart_base, u32 baudrate);
|
| 73 |
|
|
void uart_init(unsigned long uart_base);
|
| 74 |
|
|
|
| 75 |
|
|
|
| 76 |
|
|
#define OMAP_UART_FIFO_ENABLE (1 << 0)
|
| 77 |
|
|
#define OMAP_UART_RX_FIFO_CLR (1 << 1)
|
| 78 |
|
|
#define OMAP_UART_TX_FIFO_CLR (1 << 2)
|
| 79 |
|
|
static inline void uart_enable_fifo(unsigned long uart_base)
|
| 80 |
|
|
{
|
| 81 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_FCR);
|
| 82 |
|
|
reg |= (OMAP_UART_FIFO_ENABLE | OMAP_UART_RX_FIFO_CLR |
|
| 83 |
|
|
OMAP_UART_TX_FIFO_CLR);
|
| 84 |
|
|
write(reg, uart_base + OMAP_UART_FCR);
|
| 85 |
|
|
}
|
| 86 |
|
|
|
| 87 |
|
|
static inline void uart_disable_fifo(unsigned long uart_base)
|
| 88 |
|
|
{
|
| 89 |
|
|
volatile u32 reg= read(uart_base + OMAP_UART_FCR);
|
| 90 |
|
|
reg &= (~OMAP_UART_FIFO_ENABLE | OMAP_UART_RX_FIFO_CLR |
|
| 91 |
|
|
OMAP_UART_TX_FIFO_CLR);
|
| 92 |
|
|
write(reg, uart_base + OMAP_UART_FCR);
|
| 93 |
|
|
}
|
| 94 |
|
|
|
| 95 |
|
|
#define OMAP_UART_TX_ENABLE (1 << 0)
|
| 96 |
|
|
static inline void uart_enable_tx(unsigned long uart_base)
|
| 97 |
|
|
{
|
| 98 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
|
| 99 |
|
|
reg |= OMAP_UART_TX_ENABLE;
|
| 100 |
|
|
write(reg, uart_base + OMAP_UART_MCR);
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
static inline void uart_disable_tx(unsigned long uart_base)
|
| 104 |
|
|
{
|
| 105 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
|
| 106 |
|
|
reg &= ~OMAP_UART_TX_ENABLE;
|
| 107 |
|
|
write(reg, uart_base + OMAP_UART_MCR);
|
| 108 |
|
|
|
| 109 |
|
|
}
|
| 110 |
|
|
|
| 111 |
|
|
#define OMAP_UART_RX_ENABLE (1 << 1)
|
| 112 |
|
|
static inline void uart_enable_rx(unsigned long uart_base)
|
| 113 |
|
|
{
|
| 114 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
|
| 115 |
|
|
reg |= OMAP_UART_RX_ENABLE;
|
| 116 |
|
|
write(reg, uart_base + OMAP_UART_MCR);
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
|
|
static inline void uart_disable_rx(unsigned long uart_base)
|
| 120 |
|
|
{
|
| 121 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_MCR);
|
| 122 |
|
|
reg &= ~OMAP_UART_RX_ENABLE;
|
| 123 |
|
|
write(reg, uart_base + OMAP_UART_MCR);
|
| 124 |
|
|
}
|
| 125 |
|
|
|
| 126 |
|
|
#define OMAP_UART_STOP_BITS_MASK (1 << 2)
|
| 127 |
|
|
static inline void uart_set_stop_bits(unsigned long uart_base, int bits)
|
| 128 |
|
|
{
|
| 129 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 130 |
|
|
reg &= ~OMAP_UART_STOP_BITS_MASK;
|
| 131 |
|
|
reg |= (bits << 2);
|
| 132 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 133 |
|
|
}
|
| 134 |
|
|
|
| 135 |
|
|
#define OMAP_UART_DATA_BITS_MASK (0x3)
|
| 136 |
|
|
static inline void uart_set_data_bits(unsigned long uart_base, int bits)
|
| 137 |
|
|
{
|
| 138 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 139 |
|
|
reg &= ~OMAP_UART_DATA_BITS_MASK;
|
| 140 |
|
|
reg |= bits;
|
| 141 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
#define OMAP_UART_PARITY_ENABLE (1 << 3)
|
| 145 |
|
|
static inline void uart_enable_parity(unsigned long uart_base)
|
| 146 |
|
|
{
|
| 147 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 148 |
|
|
reg |= OMAP_UART_PARITY_ENABLE;
|
| 149 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 150 |
|
|
}
|
| 151 |
|
|
|
| 152 |
|
|
static inline void uart_disable_parity(unsigned long uart_base)
|
| 153 |
|
|
{
|
| 154 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 155 |
|
|
reg &= ~OMAP_UART_PARITY_ENABLE;
|
| 156 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 157 |
|
|
}
|
| 158 |
|
|
|
| 159 |
|
|
#define OMAP_UART_PARITY_EVEN (1 << 4)
|
| 160 |
|
|
static inline void uart_set_even_parity(unsigned long uart_base)
|
| 161 |
|
|
{
|
| 162 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 163 |
|
|
reg |= OMAP_UART_PARITY_EVEN;
|
| 164 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
static inline void uart_set_odd_parity(unsigned long uart_base)
|
| 168 |
|
|
{
|
| 169 |
|
|
volatile u32 reg = read(uart_base + OMAP_UART_LCR);
|
| 170 |
|
|
reg &= ~OMAP_UART_PARITY_EVEN;
|
| 171 |
|
|
write(reg, uart_base + OMAP_UART_LCR);
|
| 172 |
|
|
}
|
| 173 |
|
|
|
| 174 |
|
|
static inline void uart_select_mode(unsigned long uart_base, int mode)
|
| 175 |
|
|
{
|
| 176 |
|
|
write(mode, uart_base + OMAP_UART_MDR1);
|
| 177 |
|
|
}
|
| 178 |
|
|
|
| 179 |
|
|
#define OMAP_UART_INTR_EN 1
|
| 180 |
|
|
static inline void uart_enable_interrupt(unsigned long uart_base)
|
| 181 |
|
|
{
|
| 182 |
|
|
write(OMAP_UART_INTR_EN, uart_base + OMAP_UART_IER);
|
| 183 |
|
|
}
|
| 184 |
|
|
|
| 185 |
|
|
static inline void uart_disable_interrupt(unsigned long uart_base)
|
| 186 |
|
|
{
|
| 187 |
|
|
write((~OMAP_UART_INTR_EN), uart_base + OMAP_UART_IER);
|
| 188 |
|
|
}
|
| 189 |
|
|
|
| 190 |
|
|
static inline void uart_set_link_control(unsigned long uart_base, int mode)
|
| 191 |
|
|
{
|
| 192 |
|
|
write(mode, uart_base + OMAP_UART_LCR);
|
| 193 |
|
|
}
|
| 194 |
|
|
|
| 195 |
|
|
#endif /* __OMAP_UART_H__ */
|