at91_smc.c revision 330897
1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2014 M. Warner Losh. All rights reserved. 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: stable/11/sys/arm/at91/at91_smc.c 330897 2018-03-14 03:19:51Z eadler $"); 30 31#include <sys/types.h> 32 33#include <arm/at91/at91reg.h> 34#include <arm/at91/at91_smc.h> 35#include <arm/at91/at91sam9260reg.h> 36 37/* 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. 43 */ 44static inline uint32_t 45RD4HW(uint32_t devbase, uint32_t regoff) 46{ 47 48 return *(volatile uint32_t *)(AT91_BASE + devbase + regoff); 49} 50 51 52static inline void 53WR4HW(uint32_t devbase, uint32_t regoff, uint32_t val) 54{ 55 56 *(volatile uint32_t *)(AT91_BASE + devbase + regoff) = val; 57} 58 59 60void 61at91_smc_setup(int id, int cs, const struct at91_smc_init *smc) 62{ 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); 65 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)); 77} 78 79void 80at91_ebi_enable(int bank) 81{ 82 83 WR4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA, (1 << bank) | 84 RD4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA)); 85} 86 87void 88at91_ebi_disable(int bank) 89{ 90 91 WR4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA, ~(1 << bank) & 92 RD4HW(AT91SAM9260_MATRIX_BASE, AT91SAM9260_EBICSA)); 93} 94