Initial commit with upstream sources
[platform/core/security/tef-optee_os.git] / core / arch / arm / plat-stm / asc.S
1 /*
2  * Copyright (c) 2014, STMicroelectronics International N.V.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #include <platform_config.h>
28 #include <asm.S>
29 #include <kernel/unwind.h>
30
31 #define ASC_BAUDRATE    0x00
32 #define ASC_TXBUFFER    0x04
33 #define ASC_RXBUFFER    0x08
34 #define ASC_CONTROL     0x0c
35 #define ASC_INTENABLE   0x10
36 #define ASC_STATUS      0x14
37 #define ASC_GUARDTIME   0x18
38 #define ASC_TIMEOUT     0x1c
39 #define ASC_TXRESET     0x20
40 #define ASC_RXRESET     0x24
41 #define ASC_RETRIES     0x28
42
43 .section .text.asc
44
45
46 /*
47  * void __asc_flush(vaddr_t base)
48  *
49  *    Clobbers r0-r3
50  */
51 FUNC __asc_flush , :
52 UNWIND( .fnstart)
53
54     ADD r3, r0, #ASC_STATUS
55
56 flush_wait:
57     LDR r1, [r3]
58     ANDS r1, r1, #0x02   /* AND TX FIFO EMPTY flag */
59     BEQ flush_wait          /* ANDS should have set Z bit if zero */
60
61     LDR r0, =0
62     BX lr
63 UNWIND( .fnend)
64 END_FUNC __asc_flush
65
66 /*
67  * int __asc_xmit_char(char p, vaddr_t base) - Transmit a single character.
68  *
69  *    R0 is the 1-byte character to be transmited
70  *    R1 is the base address of the uart
71  *    Clobbers r0-r3
72  */
73 FUNC __asc_xmit_char , :
74 UNWIND( .fnstart)
75
76     ADD r2, r1, #ASC_TXBUFFER
77     ADD r3, r1, #ASC_STATUS
78
79     /* Output byte */
80
81     /* Spin until TX FIFO ready */
82 __asc_char_crwait:
83     LDR r1, [r3]
84     ANDS r1, r1, #0x04         /* AND TX FIFO HALF EMPTY flag */
85     BEQ __asc_char_crwait      /* ANDS should have set Z bit if zero */
86
87     MOVS r1, r0
88     LDR r0, =0xFF
89     AND r1, r1, r0
90     BEQ __asc_char_exit
91     CMP r1, #0xa               /* r1 == \n (line feed) ? */
92     BNE __asc_char_notlf
93
94     /* Transmit character extra carriage return for each line feed */
95     LDR r1, =0x0d
96     STR r1, [r2]
97
98     LDR r1, =0x0a              /* replace line feed */
99
100 __asc_char_notlf:
101     /* Transmit character */
102     STR r1, [r2]
103
104 __asc_char_exit:
105     LDR r0, =0
106     BX lr
107 UNWIND( .fnend)
108 END_FUNC __asc_xmit_char