Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Based on modifications by Alan Lu / Artila |
| 4 | * Author : Timo Tuunainen / Sysart |
| 5 | Kimmo Leppala / Sysart |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
Jens Scharsig | dab7cb8 | 2010-01-23 12:03:45 +0100 | [diff] [blame] | 27 | #include <asm/io.h> |
| 28 | #include <netdev.h> |
| 29 | #if defined(CONFIG_DRIVER_ETHER) |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 30 | #include <at91rm9200_net.h> |
| 31 | #include <dm9161.h> |
Jens Scharsig | dab7cb8 | 2010-01-23 12:03:45 +0100 | [diff] [blame] | 32 | #endif |
| 33 | |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 34 | #include "m501sk.h" |
| 35 | #include "net.h" |
| 36 | |
| 37 | #ifdef CONFIG_M501SK |
| 38 | |
| 39 | void m501sk_gpio_init(void) |
| 40 | { |
| 41 | AT91C_BASE_PIOD->PIO_PER = 1 << (M501SK_DEBUG_LED1 - 96) | |
| 42 | 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) | |
| 43 | 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96); |
| 44 | |
| 45 | AT91C_BASE_PIOD->PIO_OER = 1 << (M501SK_DEBUG_LED1 - 96) | |
| 46 | 1 << (M501SK_DEBUG_LED2 - 96) | 1 << (M501SK_DEBUG_LED3 - 96) | |
| 47 | 1 << (M501SK_DEBUG_LED4 - 96) | 1 << (M501SK_READY_LED - 96); |
| 48 | |
| 49 | AT91C_BASE_PIOD->PIO_SODR = 1 << (M501SK_READY_LED - 96); |
| 50 | AT91C_BASE_PIOD->PIO_CODR = 1 << (M501SK_DEBUG_LED3 - 96); |
| 51 | AT91C_BASE_PIOB->PIO_PER = 1 << (M501SK_BUZZER - 32); |
| 52 | AT91C_BASE_PIOB->PIO_OER = 1 << (M501SK_BUZZER - 32); |
| 53 | AT91C_BASE_PIOC->PIO_PDR = (1 << 7) | (1 << 8); |
| 54 | |
| 55 | /* Power OFF all USART's LEDs */ |
| 56 | AT91C_BASE_PIOA->PIO_PER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 | |
| 57 | AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \ |
| 58 | AT91C_PA23_TXD2; |
| 59 | |
| 60 | AT91C_BASE_PIOA->PIO_OER = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 | |
| 61 | AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \ |
| 62 | AT91C_PA23_TXD2; |
| 63 | |
| 64 | AT91C_BASE_PIOA->PIO_SODR = AT91C_PA5_TXD3 | AT91C_PA6_RXD3 | |
| 65 | AT91C_PA17_TXD0 | AT91C_PA18_RXD0 | AT91C_PA22_RXD2 | \ |
| 66 | AT91C_PA23_TXD2; |
| 67 | |
| 68 | AT91C_BASE_PIOB->PIO_PER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1; |
| 69 | AT91C_BASE_PIOB->PIO_OER = AT91C_PB20_RXD1 | AT91C_PB21_TXD1; |
| 70 | AT91C_BASE_PIOB->PIO_SODR = AT91C_PB20_RXD1 | AT91C_PB21_TXD1; |
| 71 | } |
| 72 | |
| 73 | uchar m501sk_gpio_set(M501SK_PIO io) |
| 74 | { |
| 75 | uchar status = 0xff; |
| 76 | switch (io) { |
| 77 | case M501SK_DEBUG_LED1: |
| 78 | case M501SK_DEBUG_LED2: |
| 79 | case M501SK_DEBUG_LED3: |
| 80 | case M501SK_DEBUG_LED4: |
| 81 | case M501SK_READY_LED: |
| 82 | AT91C_BASE_PIOD->PIO_SODR = 1 << (io - 96); |
| 83 | status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96)); |
| 84 | break; |
| 85 | case M501SK_BUZZER: |
| 86 | AT91C_BASE_PIOB->PIO_SODR = 1 << (io - 32); |
| 87 | status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32)); |
| 88 | break; |
| 89 | } |
| 90 | return status; |
| 91 | } |
| 92 | |
| 93 | uchar m501sk_gpio_clear(M501SK_PIO io) |
| 94 | { |
| 95 | uchar status = 0xff; |
| 96 | switch (io) { |
| 97 | case M501SK_DEBUG_LED1: |
| 98 | case M501SK_DEBUG_LED2: |
| 99 | case M501SK_DEBUG_LED3: |
| 100 | case M501SK_DEBUG_LED4: |
| 101 | case M501SK_READY_LED: |
| 102 | AT91C_BASE_PIOD->PIO_CODR = 1 << (io - 96); |
| 103 | status = AT91C_BASE_PIOD->PIO_ODSR & (1 << (io - 96)); |
| 104 | break; |
| 105 | case M501SK_BUZZER: |
| 106 | AT91C_BASE_PIOB->PIO_CODR = 1 << (io - 32); |
| 107 | status = AT91C_BASE_PIOB->PIO_ODSR & (1 << (io - 32)); |
| 108 | break; |
| 109 | } |
| 110 | return status; |
| 111 | } |
| 112 | |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 113 | /* |
| 114 | * Miscelaneous platform dependent initialisations |
| 115 | */ |
| 116 | DECLARE_GLOBAL_DATA_PTR; |
| 117 | |
| 118 | int board_init(void) |
| 119 | { |
| 120 | /* Enable Ctrlc */ |
| 121 | console_init_f(); |
| 122 | |
| 123 | /* Correct IRDA resistor problem */ |
| 124 | /* Set PA23_TXD in Output */ |
| 125 | ((AT91PS_PIO)AT91C_BASE_PIOA)->PIO_OER = AT91C_PA23_TXD2; |
| 126 | |
| 127 | /* memory and cpu-speed are setup before relocation */ |
| 128 | /* so we do _nothing_ here */ |
| 129 | gd->bd->bi_arch_number = MACH_TYPE_M501; |
| 130 | /* adress of boot parameters */ |
| 131 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 132 | m501sk_gpio_init(); |
| 133 | |
| 134 | /* Do interrupt init here, because flash needs timers */ |
Jean-Christophe PLAGNIOL-VILLARD | 8c9fc00 | 2009-05-15 23:47:02 +0200 | [diff] [blame] | 135 | timer_init(); |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 136 | flash_init(); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | int dram_init(void) |
| 142 | { |
| 143 | int i = 0; |
| 144 | gd->bd->bi_dram[0].start = PHYS_SDRAM; |
| 145 | gd->bd->bi_dram[0].size = PHYS_SDRAM_SIZE; |
| 146 | |
| 147 | for (i = 0; i < 500; i++) { |
| 148 | m501sk_gpio_clear(M501SK_DEBUG_LED3); |
| 149 | m501sk_gpio_clear(M501SK_BUZZER); |
| 150 | udelay(250); |
| 151 | m501sk_gpio_set(M501SK_DEBUG_LED3); |
| 152 | m501sk_gpio_set(M501SK_BUZZER); |
| 153 | udelay(80); |
| 154 | } |
| 155 | m501sk_gpio_clear(M501SK_BUZZER); |
| 156 | m501sk_gpio_clear(M501SK_DEBUG_LED3); |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | int board_late_init(void) |
| 162 | { |
| 163 | #if defined(CONFIG_CMD_NET) |
| 164 | eth_init(gd->bd); |
| 165 | eth_halt(); |
| 166 | #endif |
| 167 | |
| 168 | /* Protect U-Boot, kernel & ramdisk memory addresses */ |
| 169 | run_command("protect on 10000000 1041ffff", 0); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | #ifdef CONFIG_DRIVER_ETHER |
| 174 | #if defined(CONFIG_CMD_NET) |
| 175 | /* |
| 176 | * Name: |
| 177 | * at91rm9200_GetPhyInterface |
| 178 | * Description: |
| 179 | * Initialise the interface functions to the PHY |
| 180 | * Arguments: |
| 181 | * None |
| 182 | * Return value: |
| 183 | * None |
| 184 | */ |
| 185 | void at91rm9200_GetPhyInterface(AT91PS_PhyOps p_phyops) |
| 186 | { |
| 187 | p_phyops->Init = dm9161_InitPhy; |
| 188 | p_phyops->IsPhyConnected = dm9161_IsPhyConnected; |
| 189 | p_phyops->GetLinkSpeed = dm9161_GetLinkSpeed; |
| 190 | p_phyops->AutoNegotiate = dm9161_AutoNegotiate; |
| 191 | } |
| 192 | #endif /* CONFIG_CMD_NET */ |
| 193 | #endif /* CONFIG_DRIVER_ETHER */ |
Jens Scharsig | dab7cb8 | 2010-01-23 12:03:45 +0100 | [diff] [blame] | 194 | |
| 195 | #ifdef CONFIG_DRIVER_AT91EMAC |
| 196 | int board_eth_init(bd_t *bis) |
| 197 | { |
| 198 | int rc = 0; |
| 199 | rc = at91emac_register(bis, 0); |
| 200 | return rc; |
| 201 | } |
| 202 | #endif |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 203 | #endif /* CONFIG_M501SK */ |