]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/at91/at91rm9200_devices.c
Upgrade Unbound to 1.6.7. More to follow.
[FreeBSD/FreeBSD.git] / sys / arm / at91 / at91rm9200_devices.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2012 M. Warner Losh.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/bus.h>
34 #include <sys/kernel.h>
35 #include <sys/malloc.h>
36 #include <sys/module.h>
37
38 #define _ARM32_BUS_DMA_PRIVATE
39 #include <machine/bus.h>
40
41 #include <arm/at91/at91var.h>
42 #include <arm/at91/at91board.h>
43 #include <arm/at91/at91rm92reg.h>
44 #include <arm/at91/at91rm9200var.h>
45 #include <arm/at91/at91_pioreg.h>
46 #include <arm/at91/at91_piovar.h>
47
48 /*
49  * The AT91RM9200 uses the same silicon for both the BGA and PQFP
50  * packages.  There's no documented way to detect this at runtime,
51  * so we require the board code to register what type of SoC is on the
52  * board in question.  The pinouts are not quite compatible, and we
53  * use this information to cope with the slight differences.
54  */
55 void
56 at91rm9200_set_subtype(enum at91_soc_subtype st)
57 {
58
59         switch (st) {
60         case AT91_ST_RM9200_BGA:
61         case AT91_ST_RM9200_PQFP:
62                 soc_info.subtype = st;
63                 break;
64         default:
65                 panic("Bad SoC subtype %d for at91rm9200_set_subtype.", st);
66                 break;
67         }
68 }
69
70 void
71 at91rm9200_config_uart(unsigned devid, unsigned unit, unsigned pinmask)
72 {
73
74         /*
75          * Since the USART supports RS-485 multidrop mode, it allows the
76          * TX pins to float.  However, for RS-232 operations, we don't want
77          * these pins to float.  Instead, they should be pulled up to avoid
78          * mismatches.  Linux does something similar when it configures the
79          * TX lines.  This implies that we also allow the RX lines to float
80          * rather than be in the state they are left in by the boot loader.
81          * Since they are input pins, I think that this is the right thing
82          * to do.
83          */
84
85         /*
86          * Current boards supported don't need the extras, but they should be
87          * implemented.  But that should wait until the new pin api goes in.
88          */
89         switch (devid) {
90         case AT91_ID_DBGU:
91                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA30, 0); /* DRXD */
92                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA31, 1); /* DTXD */
93                 break;
94
95         case AT91RM9200_ID_USART0:
96                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA17, 1); /* TXD0 */
97                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA18, 0); /* RXD0 */
98                 /* CTS PA20 */
99                 /* RTS -- errata #39 PA21 */
100                 break;
101
102         case AT91RM9200_ID_USART1:
103                 at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PIO_PB20, 1); /* TXD1 */
104                 at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PIO_PB21, 0); /* RXD1 */
105                 /* RI - PB18 */
106                 /* DTR - PB19 */
107                 /* DCD - PB23 */
108                 /* CTS - PB24 */
109                 /* DSR - PB25 */
110                 /* RTS - PB26 */
111                 break;
112
113         case AT91RM9200_ID_USART2:
114                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA22, 0); /* RXD2 */
115                 at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA23, 1); /* TXD2 */
116                 /* CTS - PA30 B periph */
117                 /* RTS - PA31 B periph */
118                 break;
119
120         case AT91RM9200_ID_USART3:
121                 at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PIO_PA5, 1); /* TXD3 */
122                 at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PIO_PA6, 0); /* RXD3 */
123                 /* CTS - PB0 B periph */
124                 /* RTS - PB1 B periph */
125                 break;
126
127         default:
128                 break;
129         }
130 }
131
132 void
133 at91rm9200_config_mci(int has_4wire)
134 {
135         /* XXX TODO chip changed GPIO, other slots, etc */
136         at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA27,  0); /* MCCK */
137         at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA28, 1);  /* MCCDA */
138         at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA29, 1);  /* MCDA0 */
139         if (has_4wire) {
140                 at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB3, 1); /* MCDA1 */
141                 at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB4, 1); /* MCDA2 */
142                 at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB5, 1); /* MCDA3 */
143         }
144 }