From patchwork Tue Aug 2 15:43:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nagabhushana.netagunte@ti.com X-Patchwork-Id: 107957 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 15A69B71C0 for ; Wed, 3 Aug 2011 01:44:57 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 549892827B; Tue, 2 Aug 2011 17:44:23 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ue-BRJOC7BGg; Tue, 2 Aug 2011 17:44:23 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E966C2829F; Tue, 2 Aug 2011 17:43:38 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C538228287 for ; Tue, 2 Aug 2011 17:43:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id irQHaGnJTQ-f for ; Tue, 2 Aug 2011 17:43:28 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from bear.ext.ti.com (bear.ext.ti.com [192.94.94.41]) by theia.denx.de (Postfix) with ESMTPS id AC03128276 for ; Tue, 2 Aug 2011 17:43:19 +0200 (CEST) Received: from dbdp20.itg.ti.com ([172.24.170.38]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id p72FhFxu018152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 2 Aug 2011 10:43:17 -0500 Received: from dbde71.ent.ti.com (localhost [127.0.0.1]) by dbdp20.itg.ti.com (8.13.8/8.13.8) with ESMTP id p72FhFW9023521 for ; Tue, 2 Aug 2011 21:13:15 +0530 (IST) Received: from dbdp31.itg.ti.com (172.24.170.98) by DBDE71.ent.ti.com (172.24.170.149) with Microsoft SMTP Server id 8.3.106.1; Tue, 2 Aug 2011 21:13:15 +0530 Received: from psplinux051.india.ti.com (psplinux051.india.ti.com [172.24.162.244]) by dbdp31.itg.ti.com (8.13.8/8.13.8) with ESMTP id p72FhCjS006509; Tue, 2 Aug 2011 21:13:14 +0530 (IST) Received: from psplinux051.india.ti.com (localhost [127.0.0.1]) by psplinux051.india.ti.com (8.13.1/8.13.1) with ESMTP id p72FhCtP016488; Tue, 2 Aug 2011 21:13:12 +0530 Received: (from x0144960@localhost) by psplinux051.india.ti.com (8.13.1/8.13.1/Submit) id p72FhCMd016485; Tue, 2 Aug 2011 21:13:12 +0530 From: To: Date: Tue, 2 Aug 2011 21:13:05 +0530 Message-ID: <1312299792-16415-6-git-send-email-nagabhushana.netagunte@ti.com> X-Mailer: git-send-email 1.6.2.4 In-Reply-To: <1312299792-16415-1-git-send-email-nagabhushana.netagunte@ti.com> References: <1312299792-16415-1-git-send-email-nagabhushana.netagunte@ti.com> MIME-Version: 1.0 Cc: Nagabhushana Netagunte , Prakash PM , sudhakar.raj@ti.com, manjunath.hadli@ti.com Subject: [U-Boot] [PATCH 05/12] da850: add support to read mac address from spi flash X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Nagabhushana Netagunte add misc_int_r function to read the mac address from SPI flash if env variable ethaddr is not set. Signed-off-by: Prakash PM Signed-off-by: Nagabhushana Netagunte --- board/davinci/da8xxevm/da850evm.c | 66 +++++++++++++++++++++++++++++++++++++ include/configs/da850evm.h | 1 + 2 files changed, 67 insertions(+), 0 deletions(-) diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c index d3d965c..ffded78 100644 --- a/board/davinci/da8xxevm/da850evm.c +++ b/board/davinci/da8xxevm/da850evm.c @@ -25,10 +25,13 @@ #include #include #include +#include +#include #include #include #include #include +#include #include DECLARE_GLOBAL_DATA_PTR; @@ -384,4 +387,67 @@ int board_eth_init(bd_t *bis) return 0; } + #endif /* CONFIG_DRIVER_TI_EMAC */ + +#define CFG_MAC_ADDR_SPI_BUS 0 +#define CFG_MAC_ADDR_SPI_CS 0 +#define CFG_MAC_ADDR_SPI_MAX_HZ CONFIG_SF_DEFAULT_SPEED +#define CFG_MAC_ADDR_SPI_MODE SPI_MODE_3 + +#define CFG_MAC_ADDR_OFFSET (flash->size - SZ_64K) + +static int get_mac_addr_spi(u8 *addr) +{ + int ret; + struct spi_flash *flash; + + flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS, + CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE); + if (!flash) { + printf(" Error - unable to probe SPI flash.\n"); + ret = -1; + goto err_probe; + } + + ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr); + if (ret) { + printf("Error - unable to read MAC address from SPI flash.\n"); + goto err_read; + } + +err_read: + /* cannot call free currently since the free function calls free() for + * spi_flash structure though it is not directly allocated through + * malloc() + */ +err_probe: + return ret; +} + +int misc_init_r(void) +{ + uint8_t addr[10]; + uchar enetaddr[6]; + int ret; + + printf("ARM Clock : %d Hz\n", clk_get(DAVINCI_ARM_CLKID)); + + if (!eth_getenv_enetaddr("ethaddr", enetaddr)) { + /* Set Ethernet MAC address from EEPROM */ + ret = get_mac_addr_spi(addr); + if (ret != 0) + return -EINVAL; + + if (is_multicast_ether_addr(addr) || is_zero_ether_addr(addr)) { + printf("Invalid MAC address read.\n"); + return -EINVAL; + } + sprintf((char *)enetaddr, "%02x:%02x:%02x:%02x:%02x:%02x", + addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); + + eth_setenv_enetaddr("ethaddr", enetaddr); + } + + return 0; +} diff --git a/include/configs/da850evm.h b/include/configs/da850evm.h index de22ffa..ede428b 100644 --- a/include/configs/da850evm.h +++ b/include/configs/da850evm.h @@ -161,6 +161,7 @@ /* * U-Boot general configuration */ +#define CONFIG_MISC_INIT_R #define CONFIG_BOOTFILE "uImage" /* Boot file name */ #define CONFIG_SYS_PROMPT "U-Boot > " /* Command Prompt */ #define CONFIG_SYS_CBSIZE 1024 /* Console I/O Buffer Size */