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 #include <asm/clock.h>
20 #define MMR_UART(n) _PASTE_UART(n, UART, REVID)
21 #define UART_BASE MMR_UART(CONFIG_UART_CONSOLE)
23 struct bfin_mmr_serial {
40 #define uart_lsr_t uint32_t
41 #define _lsr_read(p) bfin_read(&p->status)
42 #define _lsr_write(p, v) bfin_write(&p->status, v)
44 __attribute__((always_inline))
45 static inline void serial_early_do_mach_portmux(char port, int mux_mask,
46 int mux_func, int port_pin)
50 bfin_write_PORTD_MUX((bfin_read_PORTD_MUX() &
51 ~mux_mask) | mux_func);
52 bfin_write_PORTD_FER_SET(port_pin);
55 bfin_write_PORTG_MUX((bfin_read_PORTG_MUX() &
56 ~mux_mask) | mux_func);
57 bfin_write_PORTG_FER_SET(port_pin);
62 __attribute__((always_inline))
63 static inline void serial_early_do_portmux(void)
65 #if defined(__ADSPBF60x__)
66 switch (CONFIG_UART_CONSOLE) {
68 serial_early_do_mach_portmux('D', PORT_x_MUX_7_MASK,
69 PORT_x_MUX_7_FUNC_2, PD7); /* TX: D; mux 7; func 2; PD7 */
70 serial_early_do_mach_portmux('D', PORT_x_MUX_8_MASK,
71 PORT_x_MUX_8_FUNC_2, PD8); /* RX: D; mux 8; func 2; PD8 */
74 serial_early_do_mach_portmux('G', PORT_x_MUX_15_MASK,
75 PORT_x_MUX_15_FUNC_1, PG15); /* TX: G; mux 15; func 1; PG15 */
76 serial_early_do_mach_portmux('G', PORT_x_MUX_14_MASK,
77 PORT_x_MUX_14_FUNC_1, PG14); /* RX: G; mux 14; func 1; PG14 */
81 # if (P_UART(RX) & P_DEFINED) || (P_UART(TX) & P_DEFINED)
82 # error "missing portmux logic for UART"
88 __attribute__((always_inline))
89 static inline int uart_init(uint32_t uart_base)
91 /* always enable UART to 8-bit mode */
92 bfin_write(&pUART->control, UEN | UMOD_UART | WLS_8);
99 __attribute__((always_inline))
100 static inline int serial_early_init(uint32_t uart_base)
102 /* handle portmux crap on different Blackfins */
105 return uart_init(uart_base);
108 __attribute__((always_inline))
109 static inline int serial_early_uninit(uint32_t uart_base)
111 /* disable the UART by clearing UEN */
112 bfin_write(&pUART->control, 0);
117 __attribute__((always_inline))
118 static inline void serial_set_divisor(uint32_t uart_base, uint16_t divisor)
120 /* Program the divisor to get the baud rate we want */
121 bfin_write(&pUART->clock, divisor);
125 __attribute__((always_inline))
126 static inline void serial_early_set_baud(uint32_t uart_base, uint32_t baud)
128 uint16_t divisor = early_division(early_get_uart_clk(), baud * 16);
130 /* Program the divisor to get the baud rate we want */
131 serial_set_divisor(uart_base, divisor);
134 __attribute__((always_inline))
135 static inline void serial_early_put_div(uint32_t divisor)
137 uint32_t uart_base = UART_BASE;
138 bfin_write(&pUART->clock, divisor);
141 __attribute__((always_inline))
142 static inline uint32_t serial_early_get_div(void)
144 uint32_t uart_base = UART_BASE;
145 return bfin_read(&pUART->clock);