Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <debug_uart.h> |
| 8 | #include <linux/io.h> |
| 9 | #include <linux/serial_reg.h> |
| 10 | |
| 11 | #include "../soc-info.h" |
| 12 | #include "debug-uart.h" |
| 13 | |
| 14 | #define UNIPHIER_UART_TX 0x00 |
| 15 | #define UNIPHIER_UART_LCR_MCR 0x10 |
| 16 | #define UNIPHIER_UART_LSR 0x14 |
| 17 | #define UNIPHIER_UART_LDR 0x24 |
| 18 | |
| 19 | static void _debug_uart_putc(int c) |
| 20 | { |
| 21 | void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE; |
| 22 | |
| 23 | while (!(readl(base + UNIPHIER_UART_LSR) & UART_LSR_THRE)) |
| 24 | ; |
| 25 | |
| 26 | writel(c, base + UNIPHIER_UART_TX); |
| 27 | } |
| 28 | |
| 29 | void _debug_uart_init(void) |
| 30 | { |
| 31 | void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE; |
| 32 | unsigned int divisor; |
| 33 | |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 34 | switch (uniphier_get_soc_id()) { |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 35 | #if defined(CONFIG_ARCH_UNIPHIER_LD4) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 36 | case UNIPHIER_LD4_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 37 | divisor = uniphier_ld4_debug_uart_init(); |
| 38 | break; |
| 39 | #endif |
| 40 | #if defined(CONFIG_ARCH_UNIPHIER_PRO4) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 41 | case UNIPHIER_PRO4_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 42 | divisor = uniphier_pro4_debug_uart_init(); |
| 43 | break; |
| 44 | #endif |
| 45 | #if defined(CONFIG_ARCH_UNIPHIER_SLD8) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 46 | case UNIPHIER_SLD8_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 47 | divisor = uniphier_sld8_debug_uart_init(); |
| 48 | break; |
| 49 | #endif |
| 50 | #if defined(CONFIG_ARCH_UNIPHIER_PRO5) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 51 | case UNIPHIER_PRO5_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 52 | divisor = uniphier_pro5_debug_uart_init(); |
| 53 | break; |
| 54 | #endif |
| 55 | #if defined(CONFIG_ARCH_UNIPHIER_PXS2) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 56 | case UNIPHIER_PXS2_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 57 | divisor = uniphier_pxs2_debug_uart_init(); |
| 58 | break; |
| 59 | #endif |
| 60 | #if defined(CONFIG_ARCH_UNIPHIER_LD6B) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 61 | case UNIPHIER_LD6B_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 62 | divisor = uniphier_ld6b_debug_uart_init(); |
| 63 | break; |
| 64 | #endif |
| 65 | #if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 66 | case UNIPHIER_LD11_ID: |
| 67 | case UNIPHIER_LD20_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 68 | divisor = uniphier_ld20_debug_uart_init(); |
| 69 | break; |
| 70 | #endif |
| 71 | default: |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | writel(UART_LCR_WLEN8 << 8, base + UNIPHIER_UART_LCR_MCR); |
| 76 | |
| 77 | writel(divisor, base + UNIPHIER_UART_LDR); |
| 78 | } |
| 79 | DEBUG_UART_FUNCS |