]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/at91/board_sam9260ek.c
Properly support the GPIO_PIN_PRESET_{LOW,HIGH} options when configuring
[FreeBSD/FreeBSD.git] / sys / arm / at91 / board_sam9260ek.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2012 Marius Strobl <marius@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 /*
30  * Ethernut 5 board support
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <machine/board.h>
39 #include <arm/at91/at91_pioreg.h>
40 #include <arm/at91/at91_piovar.h>
41 #include <arm/at91/at91board.h>
42 #include <arm/at91/at91sam9260reg.h>
43 #include <arm/at91/at91_smc.h>
44 #include <arm/at91/at91_gpio.h>
45 #include <dev/nand/nfc_at91.h>
46
47 static struct at91_smc_init nand_smc = {
48         .ncs_rd_setup           = 0,
49         .nrd_setup              = 1,
50         .ncs_wr_setup           = 0,
51         .nwe_setup              = 1,
52
53         .ncs_rd_pulse           = 3,
54         .nrd_pulse              = 3,
55         .ncs_wr_pulse           = 3,
56         .nwe_pulse              = 3,
57
58         .nrd_cycle              = 5,
59         .nwe_cycle              = 5,
60
61         .mode                   = SMC_MODE_READ | SMC_MODE_WRITE | SMC_MODE_EXNW_DISABLED,
62         .tdf_cycles             = 2,
63 };
64
65 static struct at91_nand_params nand_param = {
66         .ale                    = 1u << 21,
67         .cle                    = 1u << 22,
68         .width                  = 8,
69         .rnb_pin                = AT91_PIN_PC13,
70         .nce_pin                = AT91_PIN_PC14,
71         .cs                     = 3,
72 };
73
74 static void
75 bi_dbgu(void)
76 {
77
78         /*
79          * DBGU
80          */
81         /* DRXD */
82         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB14, 0);
83         /* DTXD */
84         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB15, 1);
85 }
86
87 static void
88 bi_emac(void)
89 {
90
91         /*
92          * EMAC
93          */
94         /* ETX0 */
95         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA12, 0);
96         /* ETX1 */
97         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA13, 0);
98         /* ERX0 */
99         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA14, 0);
100         /* ERX1 */
101         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA15, 0);
102         /* ETXEN */
103         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA16, 0);
104         /* ERXDV */
105         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA17, 0);
106         /* ERXER */
107         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA18, 0);
108         /* ETXCK */
109         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA19, 0);
110         /* EMDC */
111         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA20, 0);
112         /* EMDIO */
113         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA21, 0);
114         /* Not RMII */
115         /* ETX2 */
116         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA10, 0);
117         /* ETX3 */
118         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA11, 0);
119         /* ETXER */
120         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA22, 0);
121         /* ERX2 */
122         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA25, 0);
123         /* ERX3 */
124         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA26, 0);
125         /* ERXCK */
126         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA27, 0);
127         /* ECRS */
128         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA28, 0);
129         /* ECOL */
130         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA29, 0);
131 }
132
133 static void
134 bi_mmc(void)
135 {
136
137         /*
138          * MMC, wired to socket B.
139          */
140         /* MCDB0 */
141         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA0, 1);
142         /* MCCDB */
143         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA1, 1);
144         /* MCDB3 */
145         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA3, 1);
146         /* MCDB2 */
147         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA4, 1);
148         /* MCDB1 */
149         at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA5, 1);
150         /* MCCK */
151         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA8, 1);
152
153         /*
154          * SPI0 and MMC are wired together, since we don't support sharing
155          * don't support the dataflash.  But if you did, you'd have to
156          * use CS0 and CS1.
157          */
158 }
159
160 static void
161 bi_iic(void)
162 {
163
164         /*
165          * TWI.  Only one child on the iic bus, which we take care of
166          * via hints.
167          */
168         /* TWD */
169         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA23, 1);
170         /* TWCK */
171         at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA24, 1);
172 }
173
174 static void
175 bi_usart0(void)
176 {
177
178         /*
179          * USART0
180          */
181         /* TXD0 */
182         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB4, 1);
183         /* RXD0 */
184         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB5, 0);
185         /* DSR0 */
186         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB22, 0);
187         /* DCD0 */
188         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB23, 0);
189         /* DTR0 */
190         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB24, 1);
191         /* RI0 */
192         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB25, 0);
193         /* RTS0 */
194         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB26, 1);
195         /* CTS0 */
196         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB27, 0);
197 }
198
199 static void
200 bi_usart1(void)
201 {
202         /*
203          * USART1
204          */
205         /* RTS1 */
206         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB28, 1);
207         /* CTS1 */
208         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB29, 0);
209         /* TXD1 */
210         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB6, 1);
211         /* RXD1 */
212         at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB7, 0);
213 }
214
215 static void
216 bi_nand(void)
217 {
218         /* Samsung 256MB SLC Flash */
219
220         /* Setup Static Memory Controller */
221         at91_smc_setup(0, 3, &nand_smc);
222         at91_enable_nand(&nand_param);
223
224         /*
225          * This assumes
226          *  - RNB is on pin PC13
227          *  - CE is on pin PC14
228          *
229          * Nothing actually uses RNB right now.
230          *
231          * For CE, this currently asserts it during board setup and leaves it
232          * that way forever.
233          *
234          * All this can go away when the gpio pin-renumbering happens...
235          */
236         at91_pio_use_gpio(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC13 | AT91C_PIO_PC14);
237         at91_pio_gpio_input(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC13);     /* RNB */
238         at91_pio_gpio_output(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC14, 0); /* nCS */
239         at91_pio_gpio_clear(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC14);     /* Assert nCS */
240 }
241
242 BOARD_INIT long
243 board_init(void)
244 {
245         bi_dbgu();
246         bi_emac();
247         bi_mmc();
248
249         /*
250          * SPI1 is wired to a audio CODEC that we don't support, so
251          * give it a pass.
252          */
253
254         bi_iic();
255         bi_usart0();
256         bi_usart1();
257         /* USART2 - USART5 aren't wired up, except via PIO pins, ignore them. */
258
259         bi_nand();
260
261         return (at91_ramsize());
262 }
263
264 ARM_BOARD(AT91SAM9260EK, "Atmel SMA9260-EK")