1238415Simp/*- 2238415Simp * Copyright (c) 2012 M. Warner Losh. All Rights Reserved. 3238415Simp * 4238415Simp * Redistribution and use in source and binary forms, with or without 5238415Simp * modification, are permitted provided that the following conditions 6238415Simp * are met: 7238415Simp * 1. Redistributions of source code must retain the above copyright 8238415Simp * notice, this list of conditions and the following disclaimer. 9238415Simp * 2. Redistributions in binary form must reproduce the above copyright 10238415Simp * notice, this list of conditions and the following disclaimer in the 11238415Simp * documentation and/or other materials provided with the distribution. 12238415Simp * 13238415Simp * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14238415Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15238415Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16238415Simp * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 17238415Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18238415Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19238415Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20238415Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21238415Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22238415Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23238415Simp * SUCH DAMAGE. 24238415Simp */ 25238415Simp 26238415Simp#include <sys/cdefs.h> 27238415Simp__FBSDID("$FreeBSD$"); 28238415Simp 29238415Simp#include <sys/param.h> 30238415Simp#include <sys/systm.h> 31238415Simp#include <sys/bus.h> 32238415Simp#include <sys/kernel.h> 33238415Simp#include <sys/malloc.h> 34238415Simp#include <sys/module.h> 35238415Simp 36238415Simp#define _ARM32_BUS_DMA_PRIVATE 37238415Simp#include <machine/bus.h> 38238415Simp 39238415Simp#include <arm/at91/at91var.h> 40238439Simp#include <arm/at91/at91board.h> 41238439Simp#include <arm/at91/at91rm92reg.h> 42238415Simp#include <arm/at91/at91rm9200var.h> 43238439Simp#include <arm/at91/at91_pioreg.h> 44238439Simp#include <arm/at91/at91_piovar.h> 45238415Simp 46238415Simp/* 47238415Simp * The AT91RM9200 uses the same silicon for both the BGA and PQFP 48238415Simp * packages. There's no documented way to detect this at runtime, 49238415Simp * so we require the board code to register what type of SoC is on the 50238415Simp * board in question. The pinouts are not quite compatible, and we 51238415Simp * use this information to cope with the slight differences. 52238415Simp */ 53238415Simpvoid 54238415Simpat91rm9200_set_subtype(enum at91_soc_subtype st) 55238415Simp{ 56238415Simp 57238415Simp switch (st) { 58238415Simp case AT91_ST_RM9200_BGA: 59238415Simp case AT91_ST_RM9200_PQFP: 60238415Simp soc_info.subtype = st; 61238415Simp break; 62238415Simp default: 63238415Simp panic("Bad SoC subtype %d for at91rm9200_set_subtype.", st); 64238415Simp break; 65238415Simp } 66238415Simp} 67238439Simp 68238439Simpvoid 69238439Simpat91rm9200_config_uart(unsigned devid, unsigned unit, unsigned pinmask) 70238439Simp{ 71238439Simp 72238439Simp /* 73238439Simp * Since the USART supports RS-485 multidrop mode, it allows the 74238439Simp * TX pins to float. However, for RS-232 operations, we don't want 75238439Simp * these pins to float. Instead, they should be pulled up to avoid 76238439Simp * mismatches. Linux does something similar when it configures the 77238439Simp * TX lines. This implies that we also allow the RX lines to float 78238439Simp * rather than be in the state they are left in by the boot loader. 79238439Simp * Since they are input pins, I think that this is the right thing 80238439Simp * to do. 81238439Simp */ 82238439Simp 83238465Simp /* 84238465Simp * Current boards supported don't need the extras, but they should be 85238465Simp * implemented. But that should wait until the new pin api goes in. 86238465Simp */ 87238439Simp switch (devid) { 88238439Simp case AT91_ID_DBGU: 89238439Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA30, 0); /* DRXD */ 90238439Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA31, 1); /* DTXD */ 91238439Simp break; 92238439Simp 93238439Simp case AT91RM9200_ID_USART0: 94238439Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA17, 1); /* TXD0 */ 95248902Sian at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA18, 0); /* RXD0 */ 96238439Simp /* CTS PA20 */ 97238439Simp /* RTS -- errata #39 PA21 */ 98238439Simp break; 99238439Simp 100238439Simp case AT91RM9200_ID_USART1: 101238439Simp at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PIO_PB20, 1); /* TXD1 */ 102238439Simp at91_pio_use_periph_a(AT91RM92_PIOB_BASE, AT91C_PIO_PB21, 0); /* RXD1 */ 103238439Simp /* RI - PB18 */ 104238439Simp /* DTR - PB19 */ 105238439Simp /* DCD - PB23 */ 106238439Simp /* CTS - PB24 */ 107238439Simp /* DSR - PB25 */ 108238439Simp /* RTS - PB26 */ 109238439Simp break; 110238439Simp 111238439Simp case AT91RM9200_ID_USART2: 112238439Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA22, 0); /* RXD2 */ 113238439Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA23, 1); /* TXD2 */ 114238439Simp /* CTS - PA30 B periph */ 115238439Simp /* RTS - PA31 B periph */ 116238439Simp break; 117238439Simp 118238439Simp case AT91RM9200_ID_USART3: 119238439Simp at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PIO_PA5, 1); /* TXD3 */ 120238439Simp at91_pio_use_periph_b(AT91RM92_PIOA_BASE, AT91C_PIO_PA6, 0); /* RXD3 */ 121238439Simp /* CTS - PB0 B periph */ 122238439Simp /* RTS - PB1 B periph */ 123238439Simp break; 124238439Simp 125238439Simp default: 126238439Simp break; 127238439Simp } 128238439Simp} 129238465Simp 130238465Simpvoid 131238465Simpat91rm9200_config_mci(int has_4wire) 132238465Simp{ 133238465Simp /* XXX TODO chip changed GPIO, other slots, etc */ 134238465Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA27, 0); /* MCCK */ 135238465Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA28, 1); /* MCCDA */ 136238465Simp at91_pio_use_periph_a(AT91RM92_PIOA_BASE, AT91C_PIO_PA29, 1); /* MCDA0 */ 137238465Simp if (has_4wire) { 138238465Simp at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB3, 1); /* MCDA1 */ 139238465Simp at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB4, 1); /* MCDA2 */ 140238465Simp at91_pio_use_periph_b(AT91RM92_PIOB_BASE, AT91C_PIO_PB5, 1); /* MCDA3 */ 141238465Simp } 142238465Simp} 143