mirror of
https://git.codelinaro.org/clo/qsdk/oss/boot/u-boot-2016.git
synced 2026-02-11 06:12:58 +01:00
1. Added Ethernet and switch init calls. 2. Added GMAC config info to Devicetree. 3. Enabled Network components in config file. Change-Id: I1704b01ca9f991934045a2d23f52d1af0f490aab Signed-off-by: Aditya Kumar Patra S <apatr@codeaurora.org>
119 lines
3.2 KiB
C
119 lines
3.2 KiB
C
/*
|
|
* Copyright (c) 2016 The Linux Foundation. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
* only version 2 as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <asm/errno.h>
|
|
#include <nand.h>
|
|
#include <part.h>
|
|
#include <mmc.h>
|
|
#include <asm/arch-qcom-common/smem.h>
|
|
#include "qca_common.h"
|
|
|
|
#ifdef CONFIG_QCA_MMC
|
|
extern qca_mmc mmc_host;
|
|
#endif
|
|
|
|
/*
|
|
* Gets the ethernet address from the ART partition table and return the value
|
|
*/
|
|
int get_eth_mac_address(uchar *enetaddr, uint no_of_macs)
|
|
{
|
|
s32 ret = 0 ;
|
|
u32 start_blocks;
|
|
u32 size_blocks;
|
|
u32 length = (6 * no_of_macs);
|
|
u32 flash_type;
|
|
loff_t art_offset;
|
|
qca_smem_flash_info_t *sfi = &qca_smem_flash_info;
|
|
#ifdef CONFIG_QCA_MMC
|
|
block_dev_desc_t *blk_dev;
|
|
disk_partition_t disk_info;
|
|
struct mmc *mmc;
|
|
char mmc_blks[512];
|
|
#endif
|
|
if (sfi->flash_type != SMEM_BOOT_MMC_FLASH) {
|
|
if (qca_smem_flash_info.flash_type == SMEM_BOOT_SPI_FLASH)
|
|
flash_type = CONFIG_SPI_FLASH_INFO_IDX;
|
|
else if (qca_smem_flash_info.flash_type == SMEM_BOOT_NAND_FLASH)
|
|
flash_type = CONFIG_NAND_FLASH_INFO_IDX;
|
|
else {
|
|
printf("Unknown flash type\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = smem_getpart("0:ART", &start_blocks, &size_blocks);
|
|
if (ret < 0) {
|
|
printf("No ART partition found\n");
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
* ART partition 0th position will contain Mac address.
|
|
*/
|
|
art_offset =
|
|
((loff_t) qca_smem_flash_info.flash_block_size * start_blocks);
|
|
|
|
ret = nand_read(&nand_info[flash_type],
|
|
art_offset, &length, enetaddr);
|
|
if (ret < 0)
|
|
printf("ART partition read failed..\n");
|
|
#ifdef CONFIG_QCA_MMC
|
|
} else {
|
|
blk_dev = mmc_get_dev(mmc_host.dev_num);
|
|
ret = get_partition_info_efi_by_name(blk_dev, "0:ART", &disk_info);
|
|
/*
|
|
* ART partition 0th position will contain MAC address.
|
|
* Read 1 block.
|
|
*/
|
|
if (ret == 0) {
|
|
mmc = mmc_host.mmc;
|
|
ret = mmc->block_dev.block_read
|
|
(mmc_host.dev_num, disk_info.start,
|
|
1, mmc_blks);
|
|
memcpy(enetaddr, mmc_blks, length);
|
|
}
|
|
if (ret < 0)
|
|
printf("ART partition read failed..\n");
|
|
#endif
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void set_ethmac_addr(void)
|
|
{
|
|
int i, ret;
|
|
uchar enetaddr[CONFIG_IPQ_NO_MACS * 6];
|
|
uchar *mac_addr;
|
|
char ethaddr[16] = "ethaddr";
|
|
char mac[64];
|
|
/* Get the MAC address from ART partition */
|
|
ret = get_eth_mac_address(enetaddr, CONFIG_IPQ_NO_MACS);
|
|
for (i = 0; (ret >= 0) && (i < CONFIG_IPQ_NO_MACS); i++) {
|
|
mac_addr = &enetaddr[i * 6];
|
|
if (!is_valid_ethaddr(mac_addr)) {
|
|
printf("eth%d MAC Address from ART is not valid\n", i);
|
|
} else {
|
|
/*
|
|
* U-Boot uses these to patch the 'local-mac-address'
|
|
* dts entry for the ethernet entries, which in turn
|
|
* will be picked up by the HLOS driver
|
|
*/
|
|
sprintf(mac, "%x:%x:%x:%x:%x:%x",
|
|
mac_addr[0], mac_addr[1],
|
|
mac_addr[2], mac_addr[3],
|
|
mac_addr[4], mac_addr[5]);
|
|
setenv(ethaddr, mac);
|
|
}
|
|
sprintf(ethaddr, "eth%daddr", (i + 1));
|
|
}
|
|
}
|