1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef __HISOC_UART_H__ 17 #define __HISOC_UART_H__ 18 19 #include "asm/platform.h" 20 #include "los_typedef.h" 21 #include "los_base.h" 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif /* __cplusplus */ 26 #endif /* __cplusplus */ 27 28 #define CONFIG_UART0_BAUDRATE 115200 29 #define CONFIG_UART_CLK_INPUT (24000000) // 24M or 6M 30 31 #define UART0 0 32 #define UART1 1 33 #define UART2 2 34 35 #define UART0_ENABLE 1 36 #define UART1_ENABLE 1 37 #define UART2_ENABLE 1 38 39 #define UART0_DMA_RX_PERI 4 40 #define UART1_DMA_RX_PERI 6 41 #define UART2_DMA_RX_PERI 8 42 43 #define uart_pin_mux_cfg(uart_num) ({ \ 44 if (UART0 == uart_num) {} \ 45 else if (UART1 == uart_num) { \ 46 WRITE_UINT16(0x01, IO_MUX_REG_BASE + 0x07C); \ 47 WRITE_UINT16(0x01, IO_MUX_REG_BASE + 0x084); \ 48 } \ 49 else if (UART2 == uart_num) { \ 50 WRITE_UINT16(0x01, IO_MUX_REG_BASE + 0x088); \ 51 WRITE_UINT16(0x01, IO_MUX_REG_BASE + 0x08C); \ 52 } \ 53 else if (UART3 ==uart_num) { \ 54 WRITE_UINT16(0x02, IO_MUX_REG_BASE + 0x078); \ 55 WRITE_UINT16(0x02, IO_MUX_REG_BASE + 0x080); \ 56 } \ 57 }) 58 #define uart_clk_cfg(uart_num, flag) ({ \ 59 unsigned int tmp = 0; \ 60 tmp = GET_UINT32(CRG_REG_BASE + 0x0198); \ 61 if (flag) \ 62 tmp |= (1<<(uart_num + 24)); \ 63 else \ 64 tmp &= ~(1<<(uart_num + 24)); \ 65 WRITE_UINT32(tmp, CRG_REG_BASE + 0x0198); \ 66 }) 67 #define get_uart_dma_peri(uart_num) ({ \ 68 unsigned int peri_num = -1; \ 69 if (UART0 == uart_num) \ 70 peri_num = UART0_DMA_RX_PERI; \ 71 else if (UART1 == uart_num) \ 72 peri_num = UART1_DMA_RX_PERI; \ 73 else if (UART2 == uart_num) \ 74 peri_num = UART2_DMA_RX_PERI; \ 75 else if (UART3 == uart_num) \ 76 peri_num = UART3_DMA_RX_PERI; \ 77 peri_num; \ 78 }) 79 80 81 #define TTYS0 "/dev/ttyS0" 82 83 #define CONSOLE_UART UART0 84 85 #define CONSOLE_UART_BAUDRATE 115200 86 #define UART_NUM 4 87 #if (CONSOLE_UART == UART0) 88 #define TTY_DEVICE "/dev/uartdev-0" 89 #define UART_REG_BASE UART0_REG_BASE 90 #define NUM_HAL_INTERRUPT_UART NUM_HAL_INTERRUPT_UART0 91 #elif (CONSOLE_UART == UART1) 92 #define TTY_DEVICE "/dev/uartdev-1" 93 #define UART_REG_BASE UART1_REG_BASE 94 #define NUM_HAL_INTERRUPT_UART NUM_HAL_INTERRUPT_UART1 95 #elif (CONSOLE_UART == UART2) 96 #define TTY_DEVICE "/dev/uartdev-2" 97 #define UART_REG_BASE UART2_REG_BASE 98 #define NUM_HAL_INTERRUPT_UART NUM_HAL_INTERRUPT_UART2 99 #endif 100 101 #ifdef LOSCFG_PLATFORM_HISI_AMP 102 #undef TTY_DEVICE 103 #define TTY_DEVICE "/dev/virt-tty" 104 #endif 105 106 typedef struct { 107 UINT32 base; 108 INT32 msec_timeout; 109 int isr_vector; 110 } channel_data_t; 111 112 extern void uart_init(void); 113 extern void uart_interrupt_unmask(void); 114 extern int uart_hwiCreate(void); 115 extern UINT8 uart_getc(void); 116 extern char uart_fputc(char c, void *f); 117 118 extern UINT32 UartPutsReg(UINTPTR base, const CHAR *s, UINT32 len, BOOL isLock); 119 extern VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock); 120 121 #define UART_WITHOUT_LOCK 0 122 #define UART_WITH_LOCK 1 123 124 #ifdef __cplusplus 125 #if __cplusplus 126 } 127 #endif /* __cplusplus */ 128 #endif /* __cplusplus */ 129 130 #endif 131