1235348Smarius/*- 2235348Smarius * Copyright (c) 2012 Marius Strobl <marius@FreeBSD.org> 3235348Smarius * All rights reserved. 4235348Smarius * 5235348Smarius * Redistribution and use in source and binary forms, with or without 6235348Smarius * modification, are permitted provided that the following conditions 7235348Smarius * are met: 8235348Smarius * 1. Redistributions of source code must retain the above copyright 9235348Smarius * notice, this list of conditions and the following disclaimer. 10235348Smarius * 2. Redistributions in binary form must reproduce the above copyright 11235348Smarius * notice, this list of conditions and the following disclaimer in the 12235348Smarius * documentation and/or other materials provided with the distribution. 13235348Smarius * 14235348Smarius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15235348Smarius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16235348Smarius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17235348Smarius * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18235348Smarius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19235348Smarius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20235348Smarius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21235348Smarius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22235348Smarius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23235348Smarius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24235348Smarius * SUCH DAMAGE. 25235348Smarius */ 26235348Smarius 27235348Smarius/* 28235348Smarius * Ethernut 5 board support 29235348Smarius */ 30235348Smarius 31235348Smarius#include <sys/cdefs.h> 32235348Smarius__FBSDID("$FreeBSD: releng/10.3/sys/arm/at91/board_sam9260ek.c 266097 2014-05-14 23:51:07Z ian $"); 33235348Smarius 34235348Smarius#include <sys/param.h> 35235348Smarius#include <sys/systm.h> 36238189Simp#include <machine/board.h> 37235348Smarius#include <arm/at91/at91_pioreg.h> 38235348Smarius#include <arm/at91/at91_piovar.h> 39235348Smarius#include <arm/at91/at91board.h> 40235348Smarius#include <arm/at91/at91sam9260reg.h> 41266097Sian#include <arm/at91/at91_smc.h> 42266097Sian#include <arm/at91/at91_gpio.h> 43266097Sian#include <dev/nand/nfc_at91.h> 44235348Smarius 45266097Sianstatic struct at91_smc_init nand_smc = { 46266097Sian .ncs_rd_setup = 0, 47266097Sian .nrd_setup = 1, 48266097Sian .ncs_wr_setup = 0, 49266097Sian .nwe_setup = 1, 50266097Sian 51266097Sian .ncs_rd_pulse = 3, 52266097Sian .nrd_pulse = 3, 53266097Sian .ncs_wr_pulse = 3, 54266097Sian .nwe_pulse = 3, 55266097Sian 56266097Sian .nrd_cycle = 5, 57266097Sian .nwe_cycle = 5, 58266097Sian 59266097Sian .mode = SMC_MODE_READ | SMC_MODE_WRITE | SMC_MODE_EXNW_DISABLED, 60266097Sian .tdf_cycles = 2, 61266097Sian}; 62266097Sian 63266097Sianstatic struct at91_nand_params nand_param = { 64266097Sian .ale = 1u << 21, 65266097Sian .cle = 1u << 22, 66266097Sian .width = 8, 67266097Sian .rnb_pin = AT91_PIN_PC13, 68266097Sian .nce_pin = AT91_PIN_PC14, 69266097Sian .cs = 3, 70266097Sian}; 71266097Sian 72266097Sianstatic void 73266097Sianbi_dbgu(void) 74235348Smarius{ 75235348Smarius 76235348Smarius /* 77235348Smarius * DBGU 78235348Smarius */ 79235348Smarius /* DRXD */ 80235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB14, 0); 81235348Smarius /* DTXD */ 82235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB15, 1); 83266097Sian} 84235348Smarius 85266097Sianstatic void 86266097Sianbi_emac(void) 87266097Sian{ 88266097Sian 89235348Smarius /* 90235348Smarius * EMAC 91235348Smarius */ 92235348Smarius /* ETX0 */ 93235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA12, 0); 94235348Smarius /* ETX1 */ 95235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA13, 0); 96235348Smarius /* ERX0 */ 97235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA14, 0); 98235348Smarius /* ERX1 */ 99235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA15, 0); 100235348Smarius /* ETXEN */ 101235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA16, 0); 102235348Smarius /* ERXDV */ 103235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA17, 0); 104235348Smarius /* ERXER */ 105235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA18, 0); 106235348Smarius /* ETXCK */ 107235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA19, 0); 108235348Smarius /* EMDC */ 109235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA20, 0); 110235348Smarius /* EMDIO */ 111235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA21, 0); 112238821Simp /* Not RMII */ 113238821Simp /* ETX2 */ 114238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA10, 0); 115238821Simp /* ETX3 */ 116238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA11, 0); 117238821Simp /* ETXER */ 118238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA22, 0); 119238821Simp /* ERX2 */ 120238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA25, 0); 121238821Simp /* ERX3 */ 122238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA26, 0); 123238821Simp /* ERXCK */ 124238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA27, 0); 125238821Simp /* ECRS */ 126238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA28, 0); 127238821Simp /* ECOL */ 128238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA29, 0); 129266097Sian} 130235348Smarius 131266097Sianstatic void 132266097Sianbi_mmc(void) 133266097Sian{ 134238821Simp 135235348Smarius /* 136238821Simp * MMC, wired to socket B. 137235348Smarius */ 138238821Simp /* MCDB0 */ 139238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA0, 1); 140238821Simp /* MCCDB */ 141238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA1, 1); 142238821Simp /* MCDB3 */ 143238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA3, 1); 144238821Simp /* MCDB2 */ 145238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA4, 1); 146238821Simp /* MCDB1 */ 147238821Simp at91_pio_use_periph_b(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA5, 1); 148235348Smarius /* MCCK */ 149235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA8, 1); 150235348Smarius 151235348Smarius /* 152238821Simp * SPI0 and MMC are wired together, since we don't support sharing 153238821Simp * don't support the dataflash. But if you did, you'd have to 154238821Simp * use CS0 and CS1. 155235348Smarius */ 156266097Sian} 157235348Smarius 158266097Sianstatic void 159266097Sianbi_iic(void) 160266097Sian{ 161238821Simp 162238821Simp /* 163238821Simp * TWI. Only one child on the iic bus, which we take care of 164238821Simp * via hints. 165238821Simp */ 166235348Smarius /* TWD */ 167235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA23, 1); 168235348Smarius /* TWCK */ 169235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOA_BASE, AT91C_PIO_PA24, 1); 170266097Sian} 171235348Smarius 172266097Sianstatic void 173266097Sianbi_usart0(void) 174266097Sian{ 175266097Sian 176235348Smarius /* 177235348Smarius * USART0 178235348Smarius */ 179235348Smarius /* TXD0 */ 180235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB4, 1); 181235348Smarius /* RXD0 */ 182235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB5, 0); 183235348Smarius /* DSR0 */ 184235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB22, 0); 185235348Smarius /* DCD0 */ 186235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB23, 0); 187235348Smarius /* DTR0 */ 188235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB24, 1); 189235348Smarius /* RI0 */ 190235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB25, 0); 191235348Smarius /* RTS0 */ 192235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB26, 1); 193235348Smarius /* CTS0 */ 194235348Smarius at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB27, 0); 195266097Sian} 196235348Smarius 197266097Sianstatic void 198266097Sianbi_usart1(void) 199266097Sian{ 200235348Smarius /* 201238821Simp * USART1 202235348Smarius */ 203238821Simp /* RTS1 */ 204238821Simp at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB28, 1); 205238821Simp /* CTS1 */ 206238821Simp at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB29, 0); 207238821Simp /* TXD1 */ 208238821Simp at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB6, 1); 209238821Simp /* RXD1 */ 210238821Simp at91_pio_use_periph_a(AT91SAM9260_PIOB_BASE, AT91C_PIO_PB7, 0); 211266097Sian} 212235348Smarius 213266097Sianstatic void 214266097Sianbi_nand(void) 215266097Sian{ 216266097Sian /* Samsung 256MB SLC Flash */ 217266097Sian 218266097Sian /* Setup Static Memory Controller */ 219266097Sian at91_smc_setup(0, 3, &nand_smc); 220266097Sian at91_enable_nand(&nand_param); 221266097Sian 222266097Sian /* 223266097Sian * This assumes 224266097Sian * - RNB is on pin PC13 225266097Sian * - CE is on pin PC14 226266097Sian * 227266097Sian * Nothing actually uses RNB right now. 228266097Sian * 229266097Sian * For CE, this currently asserts it during board setup and leaves it 230266097Sian * that way forever. 231266097Sian * 232266097Sian * All this can go away when the gpio pin-renumbering happens... 233266097Sian */ 234266097Sian at91_pio_use_gpio(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC13 | AT91C_PIO_PC14); 235266097Sian at91_pio_gpio_input(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC13); /* RNB */ 236266097Sian at91_pio_gpio_output(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC14, 0); /* nCS */ 237266097Sian at91_pio_gpio_clear(AT91SAM9260_PIOC_BASE, AT91C_PIO_PC14); /* Assert nCS */ 238266097Sian} 239266097Sian 240266097SianBOARD_INIT long 241266097Sianboard_init(void) 242266097Sian{ 243266097Sian bi_dbgu(); 244266097Sian bi_emac(); 245266097Sian bi_mmc(); 246266097Sian 247266097Sian /* 248266097Sian * SPI1 is wired to a audio CODEC that we don't support, so 249266097Sian * give it a pass. 250266097Sian */ 251266097Sian 252266097Sian bi_iic(); 253266097Sian bi_usart0(); 254266097Sian bi_usart1(); 255238821Simp /* USART2 - USART5 aren't wired up, except via PIO pins, ignore them. */ 256238821Simp 257266097Sian bi_nand(); 258266097Sian 259235348Smarius return (at91_ramsize()); 260235348Smarius} 261238189Simp 262238443SimpARM_BOARD(AT91SAM9260EK, "Atmel SMA9260-EK") 263