2 * serial.h - common serial defines for early debug and serial driver.
3 * any functions defined here must be always_inline since
4 * initcode cannot have function calls.
6 * Copyright (c) 2004-2011 Analog Devices Inc.
8 * Licensed under the GPL-2 or later.
11 #ifndef __BFIN_CPU_SERIAL4_H__
12 #define __BFIN_CPU_SERIAL4_H__
14 #include <asm/mach-common/bits/uart4.h>
18 #define MMR_UART(n) _PASTE_UART(n, UART, REVID)
19 #define UART_BASE MMR_UART(CONFIG_UART_CONSOLE)
21 struct bfin_mmr_serial {
38 #define uart_lsr_t uint32_t
39 #define _lsr_read(p) bfin_read(&p->status)
40 #define _lsr_write(p, v) bfin_write(&p->status, v)
42 __attribute__((always_inline))
43 static inline void serial_early_do_mach_portmux(char port, int mux_mask,
44 int mux_func, int port_pin)
48 bfin_write_PORTD_MUX((bfin_read_PORTD_MUX() &
49 ~mux_mask) | mux_func);
50 bfin_write_PORTD_FER_SET(port_pin);
53 bfin_write_PORTG_MUX((bfin_read_PORTG_MUX() &
54 ~mux_mask) | mux_func);
55 bfin_write_PORTG_FER_SET(port_pin);
60 __attribute__((always_inline))
61 static inline void serial_early_do_portmux(void)
63 #if defined(__ADSPBF60x__)
64 switch (CONFIG_UART_CONSOLE) {
66 serial_early_do_mach_portmux('D', PORT_x_MUX_7_MASK,
67 PORT_x_MUX_7_FUNC_2, PD7); /* TX: D; mux 7; func 2; PD7 */
68 serial_early_do_mach_portmux('D', PORT_x_MUX_8_MASK,
69 PORT_x_MUX_8_FUNC_2, PD8); /* RX: D; mux 8; func 2; PD8 */
72 serial_early_do_mach_portmux('G', PORT_x_MUX_15_MASK,
73 PORT_x_MUX_15_FUNC_1, PG15); /* TX: G; mux 15; func 1; PG15 */
74 serial_early_do_mach_portmux('G', PORT_x_MUX_14_MASK,
75 PORT_x_MUX_14_FUNC_1, PG14); /* RX: G; mux 14; func 1; PG14 */
79 # if (P_UART(RX) & P_DEFINED) || (P_UART(TX) & P_DEFINED)
80 # error "missing portmux logic for UART"
86 __attribute__((always_inline))
87 static inline uint32_t uart_sclk(void)
89 #if defined(BFIN_IN_INITCODE) || defined(CONFIG_DEBUG_EARLY_SERIAL)
90 /* We cannot use get_sclk() early on as it uses caches in
93 return CONFIG_CLKIN_HZ * CONFIG_VCO_MULT / CONFIG_SCLK_DIV /
100 __attribute__((always_inline))
101 static inline int uart_init(uint32_t uart_base)
103 /* always enable UART to 8-bit mode */
104 bfin_write(&pUART->control, UEN | UMOD_UART | WLS_8);
111 __attribute__((always_inline))
112 static inline int serial_early_init(uint32_t uart_base)
114 /* handle portmux crap on different Blackfins */
117 return uart_init(uart_base);
120 __attribute__((always_inline))
121 static inline int serial_early_uninit(uint32_t uart_base)
123 /* disable the UART by clearing UEN */
124 bfin_write(&pUART->control, 0);
129 __attribute__((always_inline))
130 static inline int serial_early_enabled(uint32_t uart_base)
132 return bfin_read(&pUART->control) & UEN;
135 __attribute__((always_inline))
136 static inline void serial_early_set_baud(uint32_t uart_base, uint32_t baud)
138 uint32_t divisor = uart_sclk() / (baud * 16);
140 /* Program the divisor to get the baud rate we want */
141 bfin_write(&pUART->clock, divisor);
145 __attribute__((always_inline))
146 static inline void serial_early_put_div(uint32_t divisor)
148 uint32_t uart_base = UART_BASE;
149 bfin_write(&pUART->clock, divisor);
152 __attribute__((always_inline))
153 static inline uint32_t serial_early_get_div(void)
155 uint32_t uart_base = UART_BASE;
156 return bfin_read(&pUART->clock);