1161370Simp/*- 2161370Simp * Copyright (c) 2006 M. Warner Losh. All rights reserved. 3161370Simp * 4161370Simp * Redistribution and use in source and binary forms, with or without 5161370Simp * modification, are permitted provided that the following conditions 6161370Simp * are met: 7161370Simp * 1. Redistributions of source code must retain the above copyright 8161370Simp * notice, this list of conditions and the following disclaimer. 9161370Simp * 2. Redistributions in binary form must reproduce the above copyright 10161370Simp * notice, this list of conditions and the following disclaimer in the 11161370Simp * documentation and/or other materials provided with the distribution. 12161370Simp * 13161370Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14161370Simp * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15161370Simp * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16161370Simp * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17161370Simp * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18161370Simp * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19161370Simp * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20161370Simp * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21161370Simp * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22161370Simp * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23161370Simp * 24161370Simp * This software is derived from software provide by Kwikbyte who specifically 25161370Simp * disclaimed copyright on the code. 26161370Simp * 27161370Simp * $FreeBSD: releng/10.2/sys/boot/arm/at91/libat91/emac_init.c 238463 2012-07-15 05:35:14Z imp $ 28161370Simp */ 29161370Simp 30161370Simp/****************************************************************************** 31161370Simp * 32161370Simp * Filename: emac.c 33161370Simp * 34161370Simp * Instantiation of routines for MAC/ethernet functions supporting tftp. 35161370Simp * 36161370Simp * Revision information: 37161370Simp * 38161370Simp * 28AUG2004 kb_admin initial creation 39161370Simp * 08JAN2005 kb_admin added tftp download 40161370Simp * also adapted from external sources 41161370Simp * 42161370Simp * BEGIN_KBDD_BLOCK 43161370Simp * No warranty, expressed or implied, is included with this software. It is 44161370Simp * provided "AS IS" and no warranty of any kind including statutory or aspects 45161370Simp * relating to merchantability or fitness for any purpose is provided. All 46161370Simp * intellectual property rights of others is maintained with the respective 47161370Simp * owners. This software is not copyrighted and is intended for reference 48161370Simp * only. 49161370Simp * END_BLOCK 50161370Simp ******************************************************************************/ 51161370Simp 52161370Simp#include "at91rm9200.h" 53161370Simp#include "at91rm9200_lowlevel.h" 54161370Simp#include "emac.h" 55161370Simp#include "lib.h" 56161370Simp 57161370Simp/* ****************************** GLOBALS *************************************/ 58161370Simp 59163533Simpunsigned localMACSet; 60161370Simpunsigned char localMACAddr[6]; 61161370Simpunsigned localMAClow, localMAChigh; 62161370Simp 63161370Simp/* ********************** PRIVATE FUNCTIONS/DATA ******************************/ 64161370Simp 65161370Simp/* 66161370Simp * .KB_C_FN_DEFINITION_START 67161370Simp * void EMAC_SetMACAddress(unsigned low_address, unsigned high_address) 68161370Simp * This global function sets the MAC address. low_address is the first 69161370Simp * four bytes while high_address is the last 2 bytes of the 48-bit value. 70161370Simp * .KB_C_FN_DEFINITION_END 71161370Simp */ 72161370Simpvoid 73161370SimpEMAC_SetMACAddress(unsigned char mac[6]) 74161370Simp{ 75161370Simp AT91PS_PMC pPMC = AT91C_BASE_PMC; 76161370Simp AT91PS_EMAC pEmac = AT91C_BASE_EMAC; 77161370Simp 78161370Simp /* enable the peripheral clock before using EMAC */ 79161370Simp pPMC->PMC_PCER = ((unsigned) 1 << AT91C_ID_EMAC); 80161370Simp 81163533Simp memcpy(localMACAddr, mac, 6); 82172952Simp localMAClow = (mac[3] << 24) | (mac[2] << 16) | (mac[1] << 8) | mac[0]; 83172952Simp localMAChigh = (mac[5] << 8) | mac[4]; 84161370Simp localMACSet = 1; 85161370Simp 86161370Simp AT91C_BASE_PMC->PMC_PCER = 1u << AT91C_ID_EMAC; 87161370Simp AT91C_BASE_PIOA->PIO_ASR = 88238463Simp AT91C_PIO_PA14 | AT91C_PIO_PA12 | AT91C_PIO_PA13 | 89238463Simp AT91C_PIO_PA8 | AT91C_PIO_PA16 | AT91C_PIO_PA9 | 90238463Simp AT91C_PIO_PA10 | AT91C_PIO_PA11 | AT91C_PIO_PA15 | 91238463Simp AT91C_PIO_PA7; 92161370Simp AT91C_BASE_PIOA->PIO_PDR = 93238463Simp AT91C_PIO_PA14 | AT91C_PIO_PA12 | AT91C_PIO_PA13 | 94238463Simp AT91C_PIO_PA8 | AT91C_PIO_PA16 | AT91C_PIO_PA9 | 95238463Simp AT91C_PIO_PA10 | AT91C_PIO_PA11 | AT91C_PIO_PA15 | 96238463Simp AT91C_PIO_PA7; 97165401Simp#if defined(BOOT_KB920X) | defined(BOOT_BWCT) /* Really !RMII */ 98161370Simp AT91C_BASE_PIOB->PIO_BSR = 99238463Simp AT91C_PIO_PB12 | AT91C_PIO_PB13 | AT91C_PIO_PB14 | 100238463Simp AT91C_PIO_PB15 | AT91C_PIO_PB16 | AT91C_PIO_PB17 | 101238463Simp AT91C_PIO_PB18 | AT91C_PIO_PB19; 102161370Simp AT91C_BASE_PIOB->PIO_PDR = 103238463Simp AT91C_PIO_PB12 | AT91C_PIO_PB13 | AT91C_PIO_PB14 | 104238463Simp AT91C_PIO_PB15 | AT91C_PIO_PB16 | AT91C_PIO_PB17 | 105238463Simp AT91C_PIO_PB18 | AT91C_PIO_PB19; 106161370Simp#endif 107161370Simp pEmac->EMAC_CTL = 0; 108161370Simp 109161370Simp pEmac->EMAC_CFG = (pEmac->EMAC_CFG & ~(AT91C_EMAC_CLK)) | 110161370Simp#ifdef BOOT_TSC 111161370Simp AT91C_EMAC_RMII | 112161370Simp#endif 113161370Simp AT91C_EMAC_CLK_HCLK_32 | AT91C_EMAC_CAF; 114161370Simp // the sequence write EMAC_SA1L and write EMAC_SA1H must be respected 115161370Simp pEmac->EMAC_SA1L = localMAClow; 116161370Simp pEmac->EMAC_SA1H = localMAChigh; 117161370Simp} 118