2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2014 M. Warner Losh. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
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
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/types.h>
33 #include <arm/at91/at91reg.h>
34 #include <arm/at91/at91_smc.h>
35 #include <arm/at91/at91sam9260reg.h>
38 * RD4HW()/WR4HW() read and write at91 hardware register space directly. They
39 * serve the same purpose as the RD4()/WR4() idiom you see in many drivers,
40 * except that those translate to bus_space calls, but in this code we need to
41 * access some devices before bus_space is ready to use. Of course for this to
42 * work the appropriate static device mappings need to be made in machdep.c.
44 static inline uint32_t
45 RD4HW(uint32_t devbase, uint32_t regoff)
48 return *(volatile uint32_t *)(AT91_BASE + devbase + regoff);
53 WR4HW(uint32_t devbase, uint32_t regoff, uint32_t val)
56 *(volatile uint32_t *)(AT91_BASE + devbase + regoff) = val;
61 at91_smc_setup(int id, int cs, const struct at91_smc_init *smc)
63 // Need a generic way to get this address for all SoCs... Assume 9260 for now...
64 uint32_t base = AT91SAM9260_SMC_BASE + SMC_CS_OFF(cs);
66 WR4HW(base, SMC_SETUP, SMC_SETUP_NCS_RD_SETUP(smc->ncs_rd_setup) |
67 SMC_SETUP_NRD_SETUP(smc->nrd_setup) |
68 SMC_SETUP_NCS_WR_SETUP(smc->ncs_wr_setup) |
69 SMC_SETUP_NWE_SETUP(smc->nwe_setup));
70 WR4HW(base, SMC_PULSE, SMC_PULSE_NCS_RD_PULSE(smc->ncs_rd_pulse) |
71 SMC_PULSE_NRD_PULSE(smc->nrd_pulse) |
72 SMC_PULSE_NCS_WR_PULSE(smc->ncs_wr_pulse) |
73 SMC_PULSE_NWE_PULSE(smc->nwe_pulse));
74 WR4HW(base, SMC_CYCLE, SMC_CYCLE_NRD_CYCLE(smc->nrd_cycle) |
75 SMC_CYCLE_NWE_CYCLE(smc->nwe_cycle));
76 WR4HW(base, SMC_MODE, smc->mode | SMC_MODE_TDF_CYCLES(smc->tdf_cycles));
80 at91_ebi_enable(int bank)
83 WR4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA, (1 << bank) |
84 RD4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA));
88 at91_ebi_disable(int bank)
91 WR4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA, ~(1 << bank) &
92 RD4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA));