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 | |
Masahiro Yamada | 3cac7f7 | 2019-06-29 02:38:06 +0900 | [diff] [blame] | 11 | #include "../sg-regs.h" |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 12 | #include "../soc-info.h" |
| 13 | #include "debug-uart.h" |
| 14 | |
| 15 | #define UNIPHIER_UART_TX 0x00 |
| 16 | #define UNIPHIER_UART_LCR_MCR 0x10 |
| 17 | #define UNIPHIER_UART_LSR 0x14 |
| 18 | #define UNIPHIER_UART_LDR 0x24 |
| 19 | |
| 20 | static void _debug_uart_putc(int c) |
| 21 | { |
| 22 | void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE; |
| 23 | |
| 24 | while (!(readl(base + UNIPHIER_UART_LSR) & UART_LSR_THRE)) |
| 25 | ; |
| 26 | |
| 27 | writel(c, base + UNIPHIER_UART_TX); |
| 28 | } |
| 29 | |
Masahiro Yamada | 3cac7f7 | 2019-06-29 02:38:06 +0900 | [diff] [blame] | 30 | #ifdef CONFIG_SPL_BUILD |
| 31 | void sg_set_pinsel(unsigned int pin, unsigned int muxval, |
| 32 | unsigned int mux_bits, unsigned int reg_stride) |
| 33 | { |
| 34 | unsigned int shift = pin * mux_bits % 32; |
Masahiro Yamada | 76b3124 | 2019-07-10 20:07:40 +0900 | [diff] [blame] | 35 | void __iomem *reg = sg_base + SG_PINCTRL_BASE + |
| 36 | pin * mux_bits / 32 * reg_stride; |
Masahiro Yamada | 3cac7f7 | 2019-06-29 02:38:06 +0900 | [diff] [blame] | 37 | u32 mask = (1U << mux_bits) - 1; |
| 38 | u32 tmp; |
| 39 | |
| 40 | tmp = readl(reg); |
| 41 | tmp &= ~(mask << shift); |
| 42 | tmp |= (mask & muxval) << shift; |
| 43 | writel(tmp, reg); |
| 44 | } |
| 45 | |
| 46 | void sg_set_iectrl(unsigned int pin) |
| 47 | { |
| 48 | unsigned int bit = pin % 32; |
Masahiro Yamada | 76b3124 | 2019-07-10 20:07:40 +0900 | [diff] [blame] | 49 | void __iomem *reg = sg_base + SG_IECTRL + pin / 32 * 4; |
Masahiro Yamada | 3cac7f7 | 2019-06-29 02:38:06 +0900 | [diff] [blame] | 50 | u32 tmp; |
| 51 | |
| 52 | tmp = readl(reg); |
| 53 | tmp |= 1 << bit; |
| 54 | writel(tmp, reg); |
| 55 | } |
| 56 | #endif |
| 57 | |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 58 | void _debug_uart_init(void) |
| 59 | { |
Masahiro Yamada | 1950f12 | 2019-06-29 02:38:05 +0900 | [diff] [blame] | 60 | #ifdef CONFIG_SPL_BUILD |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 61 | void __iomem *base = (void __iomem *)CONFIG_DEBUG_UART_BASE; |
| 62 | unsigned int divisor; |
| 63 | |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 64 | switch (uniphier_get_soc_id()) { |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 65 | #if defined(CONFIG_ARCH_UNIPHIER_LD4) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 66 | case UNIPHIER_LD4_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 67 | divisor = uniphier_ld4_debug_uart_init(); |
| 68 | break; |
| 69 | #endif |
| 70 | #if defined(CONFIG_ARCH_UNIPHIER_PRO4) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 71 | case UNIPHIER_PRO4_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 72 | divisor = uniphier_pro4_debug_uart_init(); |
| 73 | break; |
| 74 | #endif |
| 75 | #if defined(CONFIG_ARCH_UNIPHIER_SLD8) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 76 | case UNIPHIER_SLD8_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 77 | divisor = uniphier_sld8_debug_uart_init(); |
| 78 | break; |
| 79 | #endif |
| 80 | #if defined(CONFIG_ARCH_UNIPHIER_PRO5) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 81 | case UNIPHIER_PRO5_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 82 | divisor = uniphier_pro5_debug_uart_init(); |
| 83 | break; |
| 84 | #endif |
| 85 | #if defined(CONFIG_ARCH_UNIPHIER_PXS2) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 86 | case UNIPHIER_PXS2_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 87 | divisor = uniphier_pxs2_debug_uart_init(); |
| 88 | break; |
| 89 | #endif |
| 90 | #if defined(CONFIG_ARCH_UNIPHIER_LD6B) |
Masahiro Yamada | 3164905 | 2017-01-21 18:05:26 +0900 | [diff] [blame] | 91 | case UNIPHIER_LD6B_ID: |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 92 | divisor = uniphier_ld6b_debug_uart_init(); |
| 93 | break; |
| 94 | #endif |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 95 | default: |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | writel(UART_LCR_WLEN8 << 8, base + UNIPHIER_UART_LCR_MCR); |
| 100 | |
| 101 | writel(divisor, base + UNIPHIER_UART_LDR); |
Masahiro Yamada | 1950f12 | 2019-06-29 02:38:05 +0900 | [diff] [blame] | 102 | #endif |
Masahiro Yamada | 52f0c51 | 2016-03-18 16:41:52 +0900 | [diff] [blame] | 103 | } |
| 104 | DEBUG_UART_FUNCS |