diff options
Diffstat (limited to 'firmware/target/arm/s5l8700/uart-s5l8700.c')
-rw-r--r-- | firmware/target/arm/s5l8700/uart-s5l8700.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/uart-s5l8700.c b/firmware/target/arm/s5l8700/uart-s5l8700.c new file mode 100644 index 0000000000..80207e94df --- /dev/null +++ b/firmware/target/arm/s5l8700/uart-s5l8700.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2014 by Cástor Muñoz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | #include <stdint.h> | ||
22 | #include <stdbool.h> | ||
23 | |||
24 | #include "config.h" | ||
25 | #include "system.h" | ||
26 | |||
27 | #include "s5l8700.h" | ||
28 | #include "uc870x.h" | ||
29 | |||
30 | |||
31 | /* | ||
32 | * XXX: This code is based on datasheets and NEVER TESTED !!! | ||
33 | */ | ||
34 | |||
35 | |||
36 | /* | ||
37 | * s5l8700 UC870X HW: 1 UARTC, 2 ports | ||
38 | */ | ||
39 | static struct uartc_port *uartc_port_l[UARTC_N_PORTS]; | ||
40 | const struct uartc s5l8700_uartc = | ||
41 | { | ||
42 | .id = 0, | ||
43 | .baddr = UARTC_BASE_ADDR, | ||
44 | .port_off = UARTC_PORT_OFFSET, | ||
45 | .n_ports = UARTC_N_PORTS, | ||
46 | .port_l = uartc_port_l, | ||
47 | }; | ||
48 | |||
49 | static int intmsk_uart[S5L8700_N_PORTS] = { INTMSK_UART0, INTMSK_UART1 }; | ||
50 | |||
51 | /* | ||
52 | * Device level functions specific to S5L8700 | ||
53 | */ | ||
54 | void uart_target_enable_gpio(int uart_id, int port_id) | ||
55 | { | ||
56 | (void) uart_id; | ||
57 | switch (port_id) { | ||
58 | /* configure UARTx Tx/Rx GPIO ports */ | ||
59 | case 0: | ||
60 | PCON0 = (PCON0 & 0x0fff) | 0xa000; | ||
61 | break; | ||
62 | case 1: | ||
63 | PCON6 = (PCON6 & 0xfff00fff) | 0x00044000; | ||
64 | break; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | void uart_target_disable_gpio(int uart_id, int port_id) | ||
69 | { | ||
70 | (void) uart_id; | ||
71 | switch (port_id) { | ||
72 | /* configure default reset values */ | ||
73 | case 0: | ||
74 | PCON0 = (PCON0 & 0x0fff) | 0x0000; | ||
75 | break; | ||
76 | case 1: | ||
77 | PCON6 = (PCON6 & 0xfff00fff) | 0x00000000; | ||
78 | break; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | void uart_target_enable_irq(int uart_id, int port_id) | ||
83 | { | ||
84 | (void) uart_id; | ||
85 | INTMSK |= intmsk_uart[port_id]; | ||
86 | } | ||
87 | |||
88 | void uart_target_disable_irq(int uart_id, int port_id) | ||
89 | { | ||
90 | (void) uart_id; | ||
91 | INTMSK &= ~intmsk_uart[port_id]; | ||
92 | } | ||
93 | |||
94 | void uart_target_clear_irq(int uart_id, int port_id) | ||
95 | { | ||
96 | (void) uart_id; | ||
97 | SRCPND |= intmsk_uart[port_id]; | ||
98 | } | ||
99 | |||
100 | void uart_target_enable_clocks(int uart_id) | ||
101 | { | ||
102 | (void) uart_id; | ||
103 | PWRCON &= ~(1 << CLOCKGATE_UARTC); | ||
104 | } | ||
105 | |||
106 | void uart_target_disable_clocks(int uart_id) | ||
107 | { | ||
108 | (void) uart_id; | ||
109 | PWRCON |= (1 << CLOCKGATE_UARTC); | ||
110 | } | ||
111 | |||
112 | /* | ||
113 | * ISRs | ||
114 | */ | ||
115 | void ICODE_ATTR INT_UART0(void) | ||
116 | { | ||
117 | uartc_callback(&s5l8700_uartc, 0); | ||
118 | } | ||
119 | |||
120 | void ICODE_ATTR INT_UART1(void) | ||
121 | { | ||
122 | uartc_callback(&s5l8700_uartc, 1); | ||
123 | } | ||
124 | |||
125 | /* Main init */ | ||
126 | void uart_init(void) | ||
127 | { | ||
128 | uartc_open(&s5l8700_uartc); | ||
129 | } | ||