Konstantin Porotchkin | ee4fa95 | 2018-10-08 16:50:54 +0300 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 Marvell International Ltd. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * https://spdx.org/licenses |
| 6 | */ |
| 7 | |
| 8 | #include <asm_macros.S> |
| 9 | #include <a3700_console.h> |
| 10 | |
| 11 | .globl console_core_init |
| 12 | .globl console_core_putc |
| 13 | .globl console_core_getc |
| 14 | .globl console_core_flush |
| 15 | |
| 16 | /* ----------------------------------------------- |
| 17 | * int console_core_init(unsigned long base_addr, |
| 18 | * unsigned int uart_clk, unsigned int baud_rate) |
| 19 | * Function to initialize the console without a |
| 20 | * C Runtime to print debug information. This |
| 21 | * function will be accessed by console_init and |
| 22 | * crash reporting. |
| 23 | * In: x0 - console base address |
| 24 | * w1 - Uart clock in Hz |
| 25 | * w2 - Baud rate |
| 26 | * Out: return 1 on success |
| 27 | * Clobber list : x1, x2, x3 |
| 28 | * ----------------------------------------------- |
| 29 | */ |
| 30 | func console_core_init |
| 31 | /* Check the input base address */ |
| 32 | cbz x0, init_fail |
| 33 | /* Check baud rate and uart clock for sanity */ |
| 34 | cbz w1, init_fail |
| 35 | cbz w2, init_fail |
| 36 | |
| 37 | /* Program the baudrate */ |
| 38 | /* Divisor = Uart clock / (16 * baudrate) */ |
| 39 | lsl w2, w2, #4 |
| 40 | udiv w2, w1, w2 |
| 41 | and w2, w2, #0x3ff |
| 42 | |
| 43 | ldr w3, [x0, #UART_BAUD_REG] |
| 44 | bic w3, w3, 0x3ff |
| 45 | orr w3, w3, w2 |
| 46 | str w3, [x0, #UART_BAUD_REG]/* set baud rate divisor */ |
| 47 | |
| 48 | /* Set UART to default 16X scheme */ |
| 49 | mov w3, #0 |
| 50 | str w3, [x0, #UART_POSSR_REG] |
| 51 | |
| 52 | /* |
| 53 | * Wait for the TX FIFO to be empty. If wait for 20ms, the TX FIFO is |
| 54 | * still not empty, TX FIFO will reset by all means. |
| 55 | */ |
| 56 | mov w1, #20 /* max time out 20ms */ |
| 57 | 2: |
| 58 | /* Check whether TX FIFO is empty */ |
| 59 | ldr w3, [x0, #UART_STATUS_REG] |
| 60 | and w3, w3, #UARTLSR_TXFIFOEMPTY |
| 61 | cmp w3, #0 |
| 62 | b.ne 4f |
| 63 | |
| 64 | /* Delay */ |
| 65 | mov w2, #30000 |
| 66 | 3: |
| 67 | sub w2, w2, #1 |
| 68 | cmp w2, #0 |
| 69 | b.ne 3b |
| 70 | |
| 71 | /* Check whether 10ms is waited */ |
| 72 | sub w1, w1, #1 |
| 73 | cmp w1, #0 |
| 74 | b.ne 2b |
| 75 | |
| 76 | 4: |
| 77 | /* Reset FIFO */ |
| 78 | mov w3, #UART_CTRL_RXFIFO_RESET |
| 79 | orr w3, w3, #UART_CTRL_TXFIFO_RESET |
| 80 | str w3, [x0, #UART_CTRL_REG] |
| 81 | |
| 82 | /* Delay */ |
| 83 | mov w2, #2000 |
| 84 | 1: |
| 85 | sub w2, w2, #1 |
| 86 | cmp w2, #0 |
| 87 | b.ne 1b |
| 88 | |
| 89 | /* No Parity, 1 Stop */ |
| 90 | mov w3, #0 |
| 91 | str w3, [x0, #UART_CTRL_REG] |
| 92 | |
| 93 | mov w0, #1 |
| 94 | ret |
| 95 | init_fail: |
| 96 | mov w0, #0 |
| 97 | ret |
| 98 | endfunc console_core_init |
| 99 | |
| 100 | /* -------------------------------------------------------- |
| 101 | * int console_core_putc(int c, unsigned int base_addr) |
| 102 | * Function to output a character over the console. It |
| 103 | * returns the character printed on success or -1 on error. |
| 104 | * In : w0 - character to be printed |
| 105 | * x1 - console base address |
| 106 | * Out : return -1 on error else return character. |
| 107 | * Clobber list : x2 |
| 108 | * -------------------------------------------------------- |
| 109 | */ |
| 110 | func console_core_putc |
| 111 | /* Check the input parameter */ |
| 112 | cbz x1, putc_error |
| 113 | |
| 114 | /* Prepend '\r' to '\n' */ |
| 115 | cmp w0, #0xA |
| 116 | b.ne 2f |
| 117 | /* Check if the transmit FIFO is full */ |
| 118 | 1: ldr w2, [x1, #UART_STATUS_REG] |
| 119 | and w2, w2, #UARTLSR_TXFIFOFULL |
| 120 | cmp w2, #UARTLSR_TXFIFOFULL |
| 121 | b.eq 1b |
| 122 | mov w2, #0xD /* '\r' */ |
| 123 | str w2, [x1, #UART_TX_REG] |
| 124 | |
| 125 | /* Check if the transmit FIFO is full */ |
| 126 | 2: ldr w2, [x1, #UART_STATUS_REG] |
| 127 | and w2, w2, #UARTLSR_TXFIFOFULL |
| 128 | cmp w2, #UARTLSR_TXFIFOFULL |
| 129 | b.eq 2b |
| 130 | str w0, [x1, #UART_TX_REG] |
| 131 | ret |
| 132 | putc_error: |
| 133 | mov w0, #-1 |
| 134 | ret |
| 135 | endfunc console_core_putc |
| 136 | |
| 137 | /* --------------------------------------------- |
| 138 | * int console_core_getc(void) |
| 139 | * Function to get a character from the console. |
| 140 | * It returns the character grabbed on success |
| 141 | * or -1 on error. |
| 142 | * In : w0 - console base address |
| 143 | * Out : return -1 on error else return character. |
| 144 | * Clobber list : x0, x1 |
| 145 | * --------------------------------------------- |
| 146 | */ |
| 147 | func console_core_getc |
| 148 | /* Check if the receive FIFO is empty */ |
| 149 | ret |
| 150 | getc_error: |
| 151 | mov w0, #-1 |
| 152 | ret |
| 153 | endfunc console_core_getc |
| 154 | |
| 155 | /* --------------------------------------------- |
| 156 | * int console_core_flush(uintptr_t base_addr) |
| 157 | * Function to force a write of all buffered |
| 158 | * data that hasn't been output. |
| 159 | * In : x0 - console base address |
| 160 | * Out : return -1 on error else return 0. |
| 161 | * Clobber list : x0, x1 |
| 162 | * --------------------------------------------- |
| 163 | */ |
| 164 | func console_core_flush |
| 165 | /* Placeholder */ |
| 166 | mov w0, #0 |
| 167 | ret |
| 168 | endfunc console_core_flush |