| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: obio_com.c,v 1.5 2014/04/09 21:02:31 hans Exp $ */ | | 1 | /* $NetBSD: obio_com.c,v 1.6 2016/07/07 15:20:58 kiyohara Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Based on arch/arm/omap/omap_com.c | | 4 | * Based on arch/arm/omap/omap_com.c |
5 | * | | 5 | * |
6 | * Copyright 2003 Wasabi Systems, Inc. | | 6 | * Copyright 2003 Wasabi Systems, Inc. |
7 | * OMAP support Copyright (c) 2007 Microsoft | | 7 | * OMAP support Copyright (c) 2007 Microsoft |
8 | * All rights reserved. | | 8 | * All rights reserved. |
9 | * | | 9 | * |
10 | * Written by Steve C. Woodford for Wasabi Systems, Inc. | | 10 | * Written by Steve C. Woodford for Wasabi Systems, Inc. |
11 | * | | 11 | * |
12 | * Redistribution and use in source and binary forms, with or without | | 12 | * Redistribution and use in source and binary forms, with or without |
13 | * modification, are permitted provided that the following conditions | | 13 | * modification, are permitted provided that the following conditions |
14 | * are met: | | 14 | * are met: |
| @@ -29,94 +29,117 @@ | | | @@ -29,94 +29,117 @@ |
29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
30 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 30 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
31 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC | | 31 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
32 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 32 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | * POSSIBILITY OF SUCH DAMAGE. | | 38 | * POSSIBILITY OF SUCH DAMAGE. |
39 | */ | | 39 | */ |
40 | | | 40 | |
41 | #include <sys/cdefs.h> | | 41 | #include <sys/cdefs.h> |
42 | __KERNEL_RCSID(0, "$NetBSD: obio_com.c,v 1.5 2014/04/09 21:02:31 hans Exp $"); | | 42 | __KERNEL_RCSID(0, "$NetBSD: obio_com.c,v 1.6 2016/07/07 15:20:58 kiyohara Exp $"); |
43 | | | 43 | |
44 | #include "opt_omap.h" | | 44 | #include "opt_omap.h" |
45 | #include "opt_com.h" | | 45 | #include "opt_com.h" |
46 | | | 46 | |
47 | #include <sys/param.h> | | 47 | #include <sys/param.h> |
48 | #include <sys/systm.h> | | 48 | #include <sys/systm.h> |
49 | #include <sys/device.h> | | 49 | #include <sys/device.h> |
50 | #include <sys/termios.h> | | 50 | #include <sys/termios.h> |
51 | | | 51 | |
52 | #include <machine/intr.h> | | 52 | #include <machine/intr.h> |
53 | #include <sys/bus.h> | | 53 | #include <sys/bus.h> |
54 | | | 54 | |
55 | #include <dev/ic/comreg.h> | | 55 | #include <dev/ic/comreg.h> |
56 | #include <dev/ic/comvar.h> | | 56 | #include <dev/ic/comvar.h> |
57 | | | 57 | |
58 | #include <arm/omap/omap2_obiovar.h> | | 58 | #include <arm/omap/omap2_obiovar.h> |
59 | #include <arm/omap/omap2_reg.h> | | 59 | #include <arm/omap/omap2_reg.h> |
60 | #include <arm/omap/omap_com.h> | | 60 | #include <arm/omap/omap_com.h> |
61 | | | 61 | |
| | | 62 | #include <arm/omap/omap2_prcm.h> |
| | | 63 | #include <arm/omap/am335x_prcm.h> |
| | | 64 | |
62 | #include "locators.h" | | 65 | #include "locators.h" |
63 | | | 66 | |
64 | static int obiouart_match(device_t, cfdata_t, void *); | | 67 | static int obiouart_match(device_t, cfdata_t, void *); |
65 | static void obiouart_attach(device_t, device_t, void *); | | 68 | static void obiouart_attach(device_t, device_t, void *); |
66 | static int uart_enable(struct obio_attach_args *); | | 69 | #if defined(TI_AM335X) |
| | | 70 | static int uart_enable_am335x(struct obio_attach_args *); |
| | | 71 | #else |
| | | 72 | static int uart_enable_omap(struct obio_attach_args *); |
| | | 73 | #endif |
| | | 74 | static int uart_enable(struct obio_attach_args *, bus_space_handle_t); |
67 | static void obiouart_callout(void *); | | 75 | static void obiouart_callout(void *); |
68 | | | 76 | |
| | | 77 | #if defined(TI_AM335X) |
| | | 78 | struct am335x_com { |
| | | 79 | bus_addr_t as_base_addr; |
| | | 80 | int as_intr; |
| | | 81 | struct omap_module as_module; |
| | | 82 | }; |
| | | 83 | |
| | | 84 | static const struct am335x_com am335x_com[] = { |
| | | 85 | { 0x44e09000, 72, { AM335X_PRCM_CM_WKUP, 0xb4 } }, |
| | | 86 | { 0x48022000, 73, { AM335X_PRCM_CM_PER, 0x6c } }, |
| | | 87 | { 0x48024000, 74, { AM335X_PRCM_CM_PER, 0x70 } }, |
| | | 88 | { 0x481a6000, 44, { AM335X_PRCM_CM_PER, 0x74 } }, |
| | | 89 | { 0x481a8000, 45, { AM335X_PRCM_CM_PER, 0x78 } }, |
| | | 90 | { 0x481aa000, 46, { AM335X_PRCM_CM_PER, 0x38 } }, |
| | | 91 | }; |
| | | 92 | #endif |
| | | 93 | |
69 | struct com_obio_softc { | | 94 | struct com_obio_softc { |
70 | struct com_softc sc_sc; | | 95 | struct com_softc sc_sc; |
71 | struct callout sc_callout; | | 96 | struct callout sc_callout; |
72 | }; | | 97 | }; |
73 | | | 98 | |
74 | CFATTACH_DECL_NEW(obiouart, sizeof(struct com_obio_softc), | | 99 | CFATTACH_DECL_NEW(obiouart, sizeof(struct com_obio_softc), |
75 | obiouart_match, obiouart_attach, NULL, NULL); | | 100 | obiouart_match, obiouart_attach, NULL, NULL); |
76 | | | 101 | |
77 | static int | | 102 | static int |
78 | obiouart_match(device_t parent, cfdata_t cf, void *aux) | | 103 | obiouart_match(device_t parent, cfdata_t cf, void *aux) |
79 | { | | 104 | { |
80 | struct obio_attach_args *obio = aux; | | 105 | struct obio_attach_args *obio = aux; |
81 | bus_space_handle_t bh; | | 106 | bus_space_handle_t bh; |
82 | int rv; | | 107 | int rv; |
83 | | | 108 | |
84 | if (obio->obio_addr == OBIOCF_ADDR_DEFAULT) | | 109 | if (obio->obio_addr == OBIOCF_ADDR_DEFAULT) |
85 | panic("obiouart must have addr specified in config."); | | 110 | panic("obiouart must have addr specified in config."); |
86 | | | 111 | |
87 | #if 0 | | 112 | #if 0 |
88 | /* | | 113 | /* |
89 | * XXX this should be ifdefed on a board-dependent switch | | 114 | * XXX this should be ifdefed on a board-dependent switch |
90 | * We don't know what is the irq for com0 on the sdp2430 | | 115 | * We don't know what is the irq for com0 on the sdp2430 |
91 | */ | | 116 | */ |
92 | if (obio->obio_intr == OBIOCF_INTR_DEFAULT) | | 117 | if (obio->obio_intr == OBIOCF_INTR_DEFAULT) |
93 | panic("obiouart must have intr specified in config."); | | 118 | panic("obiouart must have intr specified in config."); |
94 | #endif | | 119 | #endif |
95 | | | 120 | |
96 | if (obio->obio_size == OBIOCF_SIZE_DEFAULT) | | 121 | if (obio->obio_size == OBIOCF_SIZE_DEFAULT) |
97 | obio->obio_size = OMAP_COM_SIZE; | | 122 | obio->obio_size = OMAP_COM_SIZE; |
98 | | | 123 | |
99 | if (com_is_console(obio->obio_iot, obio->obio_addr, NULL)) | | 124 | if (com_is_console(obio->obio_iot, obio->obio_addr, NULL)) |
100 | return 1; | | 125 | return 1; |
101 | | | 126 | |
102 | if (uart_enable(obio) != 0) | | | |
103 | return 1; | | | |
104 | | | | |
105 | if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size, | | 127 | if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size, |
106 | 0, &bh)) | | 128 | 0, &bh) != 0) |
107 | return 1; | | 129 | return 0; |
108 | | | 130 | rv = 0; |
109 | rv = comprobe1(obio->obio_iot, bh); | | 131 | if (uart_enable(obio, bh) == 0) |
| | | 132 | rv = comprobe1(obio->obio_iot, bh); |
110 | | | 133 | |
111 | bus_space_unmap(obio->obio_iot, bh, obio->obio_size); | | 134 | bus_space_unmap(obio->obio_iot, bh, obio->obio_size); |
112 | | | 135 | |
113 | return rv; | | 136 | return rv; |
114 | } | | 137 | } |
115 | | | 138 | |
116 | static void | | 139 | static void |
117 | obiouart_attach(device_t parent, device_t self, void *aux) | | 140 | obiouart_attach(device_t parent, device_t self, void *aux) |
118 | { | | 141 | { |
119 | struct com_obio_softc *osc = device_private(self); | | 142 | struct com_obio_softc *osc = device_private(self); |
120 | struct com_softc *sc = &osc->sc_sc; | | 143 | struct com_softc *sc = &osc->sc_sc; |
121 | struct obio_attach_args *obio = aux; | | 144 | struct obio_attach_args *obio = aux; |
122 | bus_space_tag_t iot; | | 145 | bus_space_tag_t iot; |
| @@ -151,28 +174,49 @@ obiouart_attach(device_t parent, device_ | | | @@ -151,28 +174,49 @@ obiouart_attach(device_t parent, device_ |
151 | | | 174 | |
152 | static void | | 175 | static void |
153 | obiouart_callout(void *arg) | | 176 | obiouart_callout(void *arg) |
154 | { | | 177 | { |
155 | struct com_obio_softc * const osc = arg; | | 178 | struct com_obio_softc * const osc = arg; |
156 | int s; | | 179 | int s; |
157 | s = splserial(); | | 180 | s = splserial(); |
158 | comintr(arg); | | 181 | comintr(arg); |
159 | splx(s); | | 182 | splx(s); |
160 | callout_schedule(&osc->sc_callout, 1); | | 183 | callout_schedule(&osc->sc_callout, 1); |
161 | } | | 184 | } |
162 | | | 185 | |
163 | | | 186 | |
| | | 187 | #if defined(TI_AM335X) |
| | | 188 | |
164 | static int | | 189 | static int |
165 | uart_enable(struct obio_attach_args *obio) | | 190 | uart_enable_am335x(struct obio_attach_args *obio) |
| | | 191 | { |
| | | 192 | int i; |
| | | 193 | |
| | | 194 | /* XXX Not really AM335X-specific. */ |
| | | 195 | for (i = 0; i < __arraycount(am335x_com); i++) |
| | | 196 | if ((obio->obio_addr == am335x_com[i].as_base_addr) && |
| | | 197 | (obio->obio_intr == am335x_com[i].as_intr)) { |
| | | 198 | prcm_module_enable(&am335x_com[i].as_module); |
| | | 199 | break; |
| | | 200 | } |
| | | 201 | KASSERT(i < __arraycount(am335x_com)); |
| | | 202 | |
| | | 203 | return 0; |
| | | 204 | } |
| | | 205 | |
| | | 206 | #else |
| | | 207 | |
| | | 208 | static int |
| | | 209 | uart_enable_omap(struct obio_attach_args *obio) |
166 | { | | 210 | { |
167 | bus_space_handle_t ioh; | | 211 | bus_space_handle_t ioh; |
168 | uint32_t r; | | 212 | uint32_t r; |
169 | #if 0 | | 213 | #if 0 |
170 | uint32_t clksel2; | | 214 | uint32_t clksel2; |
171 | #endif | | 215 | #endif |
172 | uint32_t fclken1; | | 216 | uint32_t fclken1; |
173 | uint32_t iclken1; | | 217 | uint32_t iclken1; |
174 | int err __diagused; | | 218 | int err __diagused; |
175 | int n=-1; | | 219 | int n=-1; |
176 | | | 220 | |
177 | KASSERT(obio != NULL); | | 221 | KASSERT(obio != NULL); |
178 | | | 222 | |
| @@ -212,13 +256,43 @@ printf("%s: UART#%d\n", __func__, n); | | | @@ -212,13 +256,43 @@ printf("%s: UART#%d\n", __func__, n); |
212 | r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE); | | 256 | r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE); |
213 | r |= fclken1; | | 257 | r |= fclken1; |
214 | bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE, r); | | 258 | bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_FCLKEN1_CORE, r); |
215 | | | 259 | |
216 | r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE); | | 260 | r = bus_space_read_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE); |
217 | r |= iclken1; | | 261 | r |= iclken1; |
218 | bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE, r); | | 262 | bus_space_write_4(obio->obio_iot, ioh, OMAP2_CM_ICLKEN1_CORE, r); |
219 | | | 263 | |
220 | err: | | 264 | err: |
221 | // bus_space_unmap(obio->obio_iot, ioh, OMAP2_CM_SIZE); | | 265 | // bus_space_unmap(obio->obio_iot, ioh, OMAP2_CM_SIZE); |
222 | | | 266 | |
223 | return 0; | | 267 | return 0; |
224 | } | | 268 | } |
| | | 269 | |
| | | 270 | #endif |
| | | 271 | |
| | | 272 | static int |
| | | 273 | uart_enable(struct obio_attach_args *obio, bus_space_handle_t bh) |
| | | 274 | { |
| | | 275 | uint32_t v; |
| | | 276 | |
| | | 277 | #if defined(TI_AM335X) |
| | | 278 | if (uart_enable_am335x(obio) != 0) |
| | | 279 | return -1; |
| | | 280 | #else |
| | | 281 | if (uart_enable_omap(obio) != 0) |
| | | 282 | return -1; |
| | | 283 | #endif |
| | | 284 | |
| | | 285 | v = bus_space_read_4(obio->obio_iot, bh, OMAP_COM_SYSC); |
| | | 286 | v |= OMAP_COM_SYSC_SOFT_RESET; |
| | | 287 | bus_space_write_4(obio->obio_iot, bh, OMAP_COM_SYSC, v); |
| | | 288 | v = bus_space_read_4(obio->obio_iot, bh, OMAP_COM_SYSS); |
| | | 289 | while (!(v & OMAP_COM_SYSS_RESET_DONE)) |
| | | 290 | v = bus_space_read_4(obio->obio_iot, bh, OMAP_COM_SYSS); |
| | | 291 | |
| | | 292 | /* Disable smart idle */ |
| | | 293 | v = bus_space_read_4(obio->obio_iot, bh, OMAP_COM_SYSC); |
| | | 294 | v |= OMAP_COM_SYSC_NO_IDLE; |
| | | 295 | bus_space_write_4(obio->obio_iot, bh, OMAP_COM_SYSC, v); |
| | | 296 | |
| | | 297 | return 0; |
| | | 298 | } |