Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 1 | /* |
| 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. |
| 5 | * |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 6 | * Copyright (c) 2004-2011 Analog Devices Inc. |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the GPL-2 or later. |
| 9 | */ |
| 10 | |
| 11 | #ifndef __BFIN_CPU_SERIAL_H__ |
| 12 | #define __BFIN_CPU_SERIAL_H__ |
| 13 | |
| 14 | #include <asm/blackfin.h> |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 15 | #include <asm/portmux.h> |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 16 | |
Mike Frysinger | 7633903 | 2008-10-11 21:52:17 -0400 | [diff] [blame] | 17 | #ifndef CONFIG_UART_CONSOLE |
| 18 | # define CONFIG_UART_CONSOLE 0 |
| 19 | #endif |
| 20 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 21 | #ifdef CONFIG_DEBUG_EARLY_SERIAL |
| 22 | # define BFIN_DEBUG_EARLY_SERIAL 1 |
| 23 | #else |
| 24 | # define BFIN_DEBUG_EARLY_SERIAL 0 |
| 25 | #endif |
| 26 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 27 | #if defined(__ADSPBF60x__) |
| 28 | # define BFIN_UART_HW_VER 4 |
| 29 | #elif defined(__ADSPBF50x__) || defined(__ADSPBF54x__) |
Mike Frysinger | cca0741 | 2010-12-17 15:25:09 -0500 | [diff] [blame] | 30 | # define BFIN_UART_HW_VER 2 |
| 31 | #else |
| 32 | # define BFIN_UART_HW_VER 1 |
| 33 | #endif |
| 34 | |
Mike Frysinger | baaa4f9 | 2010-12-17 16:23:59 -0500 | [diff] [blame] | 35 | #define __PASTE_UART(num, pfx, sfx) pfx##num##_##sfx |
| 36 | #define _PASTE_UART(num, pfx, sfx) __PASTE_UART(num, pfx, sfx) |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 37 | #define _P_UART(n, pin) _PASTE_UART(n, P_UART, pin) |
| 38 | #define P_UART(pin) _P_UART(CONFIG_UART_CONSOLE, pin) |
Mike Frysinger | baaa4f9 | 2010-12-17 16:23:59 -0500 | [diff] [blame] | 39 | |
Mike Frysinger | 635f330 | 2011-04-29 23:23:28 -0400 | [diff] [blame] | 40 | #define pUART ((volatile struct bfin_mmr_serial *)uart_base) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 41 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 42 | #ifndef __ASSEMBLY__ |
| 43 | __attribute__((always_inline)) |
| 44 | static inline void serial_do_portmux(void); |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 45 | #endif |
| 46 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 47 | #if BFIN_UART_HW_VER < 4 |
| 48 | # include "serial1.h" |
| 49 | #else |
| 50 | # include "serial4.h" |
| 51 | #endif |
| 52 | |
| 53 | #ifndef __ASSEMBLY__ |
| 54 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 55 | __attribute__((always_inline)) |
| 56 | static inline void serial_do_portmux(void) |
| 57 | { |
Mike Frysinger | a409fdd | 2010-06-02 06:00:27 -0400 | [diff] [blame] | 58 | if (!BFIN_DEBUG_EARLY_SERIAL) { |
Mike Frysinger | baaa4f9 | 2010-12-17 16:23:59 -0500 | [diff] [blame] | 59 | const unsigned short pins[] = { P_UART(RX), P_UART(TX), 0, }; |
Mike Frysinger | a409fdd | 2010-06-02 06:00:27 -0400 | [diff] [blame] | 60 | peripheral_request_list(pins, "bfin-uart"); |
| 61 | return; |
| 62 | } |
| 63 | |
Sonic Zhang | a12c51f | 2012-08-16 11:16:02 +0800 | [diff] [blame] | 64 | serial_early_do_portmux(); |
Mike Frysinger | f790ef6 | 2008-12-10 12:33:54 -0500 | [diff] [blame] | 65 | } |
| 66 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 67 | #ifndef BFIN_IN_INITCODE |
| 68 | __attribute__((always_inline)) |
| 69 | static inline void serial_early_puts(const char *s) |
| 70 | { |
| 71 | if (BFIN_DEBUG_EARLY_SERIAL) { |
| 72 | serial_puts("Early: "); |
| 73 | serial_puts(s); |
| 74 | } |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | #else |
| 79 | |
| 80 | .macro serial_early_init |
Sonic Zhang | 50aadcc | 2013-03-13 19:06:16 +0800 | [diff] [blame^] | 81 | #if defined(CONFIG_DEBUG_EARLY_SERIAL) && !defined(CONFIG_UART_MEM) |
| 82 | call __serial_early_init; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 83 | #endif |
| 84 | .endm |
| 85 | |
| 86 | .macro serial_early_set_baud |
Sonic Zhang | 50aadcc | 2013-03-13 19:06:16 +0800 | [diff] [blame^] | 87 | #if defined(CONFIG_DEBUG_EARLY_SERIAL) && !defined(CONFIG_UART_MEM) |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 88 | R0.L = LO(CONFIG_BAUDRATE); |
| 89 | R0.H = HI(CONFIG_BAUDRATE); |
Sonic Zhang | 50aadcc | 2013-03-13 19:06:16 +0800 | [diff] [blame^] | 90 | call __serial_early_set_baud; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 91 | #endif |
| 92 | .endm |
| 93 | |
Sonic Zhang | ab80b65 | 2012-11-30 17:39:32 +0800 | [diff] [blame] | 94 | #if CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_BYPASS |
| 95 | #define update_serial_early_string_addr \ |
| 96 | R1.L = _start; \ |
| 97 | R1.H = _start; \ |
| 98 | R0 = R0 - R1; \ |
| 99 | R1.L = 0; \ |
| 100 | R1.H = 0x2000; \ |
| 101 | R0 = R0 + R1; |
| 102 | #else |
| 103 | #define update_serial_early_string_addr |
| 104 | #endif |
| 105 | |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 106 | /* Since we embed the string right into our .text section, we need |
| 107 | * to find its address. We do this by getting our PC and adding 2 |
| 108 | * bytes (which is the length of the jump instruction). Then we |
| 109 | * pass this address to serial_puts(). |
| 110 | */ |
| 111 | #ifdef CONFIG_DEBUG_EARLY_SERIAL |
| 112 | # define serial_early_puts(str) \ |
Mike Frysinger | e8e35ef | 2011-06-29 16:21:28 -0400 | [diff] [blame] | 113 | .section .rodata; \ |
| 114 | 7: \ |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 115 | .ascii "Early:"; \ |
| 116 | .ascii __FILE__; \ |
| 117 | .ascii ": "; \ |
| 118 | .ascii str; \ |
| 119 | .asciz "\n"; \ |
Mike Frysinger | e8e35ef | 2011-06-29 16:21:28 -0400 | [diff] [blame] | 120 | .previous; \ |
| 121 | R0.L = 7b; \ |
| 122 | R0.H = 7b; \ |
Sonic Zhang | ab80b65 | 2012-11-30 17:39:32 +0800 | [diff] [blame] | 123 | update_serial_early_string_addr \ |
Sonic Zhang | 50aadcc | 2013-03-13 19:06:16 +0800 | [diff] [blame^] | 124 | call _uart_early_puts; |
Mike Frysinger | 9171fc8 | 2008-03-30 15:46:13 -0400 | [diff] [blame] | 125 | #else |
| 126 | # define serial_early_puts(str) |
| 127 | #endif |
| 128 | |
| 129 | #endif |
| 130 | |
| 131 | #endif |