From d0123ecca679bc8132b19ad88a84648b7743f8f9 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Fri, 13 Nov 2015 02:50:40 +0100 Subject: [PATCH] New, common file for board related, common functions --- u-boot/board/ar7240/ap121/Makefile | 2 +- u-boot/board/ar7240/common/common.c | 124 ++++++++++++++++++++++++++++ u-boot/board/ar7240/db12x/Makefile | 2 +- 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 u-boot/board/ar7240/common/common.c diff --git a/u-boot/board/ar7240/ap121/Makefile b/u-boot/board/ar7240/ap121/Makefile index 768e929..f93b1d3 100644 --- a/u-boot/board/ar7240/ap121/Makefile +++ b/u-boot/board/ar7240/ap121/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/config.mk LIB = lib$(BOARD).a -OBJS = $(BOARD).o ../common/ar7240_flash.o ../common/ar7240_s26_phy.o +OBJS = $(BOARD).o ../common/ar7240_flash.o ../common/ar7240_s26_phy.o ../common/common.o SOBJS = ../common/lowlevel_init.o ifeq ($(BOARD), ap121) diff --git a/u-boot/board/ar7240/common/common.c b/u-boot/board/ar7240/common/common.c new file mode 100644 index 0000000..326f012 --- /dev/null +++ b/u-boot/board/ar7240/common/common.c @@ -0,0 +1,124 @@ +#include +#include +#include +#include +#include +#include + +#define ALIGN_SIZE "8" + +DECLARE_GLOBAL_DATA_PTR; + +static u32 mac_is_not_valid = 1; + +/* + * Prints available information about the board + */ +void print_board_info(void) +{ + u32 ahb_clk, cpu_clk, ddr_clk, spi_clk, ref_clk; + bd_t *bd = gd->bd; + char soc_buffer[24]; + + /* Board name */ +#ifdef BOARD_CUSTOM_STRING + printf("%" ALIGN_SIZE "s %s\n", "BOARD:", BOARD_CUSTOM_STRING); +#endif + + /* SOC name, version and revision */ + qca_soc_name_rev(soc_buffer); + printf("%" ALIGN_SIZE "s %s\n", "SOC:", soc_buffer); + + /* RAM size and type */ + printf("%" ALIGN_SIZE "s ", "RAM:"); + print_size(bd->bi_memsize, ""); + + switch (qca_mem_type()) { + case QCA_RST_BOOTSTRAP_MEM_TYPE_SDR_VAL: + puts(" SDR\n"); + break; + case QCA_RST_BOOTSTRAP_MEM_TYPE_DDR1_VAL: + puts(" DDR1\n"); + break; + case QCA_RST_BOOTSTRAP_MEM_TYPE_DDR2_VAL: + puts(" DDR2\n"); + break; + default: + puts("\n"); + break; + } + + /* FLASH size and type */ + printf("%" ALIGN_SIZE "s ", "FLASH:"); + flash_print_name(); + puts("\n"); + + /* MAC address */ + printf("%" ALIGN_SIZE "s %02X:%02X:%02X:%02X:%02X:%02X", "MAC:", + bd->bi_enetaddr[0],bd->bi_enetaddr[1], bd->bi_enetaddr[2], + bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); + + if (mac_is_not_valid) { + puts(" (fixed)\n"); + } else { + puts("\n"); + } + + /* System clocks */ + printf("%" ALIGN_SIZE "s CPU/RAM/AHB/SPI/REF\n", "CLOCKS:"); + + qca_sys_clocks(&cpu_clk, &ddr_clk, &ahb_clk, &spi_clk, &ref_clk); + cpu_clk = cpu_clk / 1000000; + ddr_clk = ddr_clk / 1000000; + ahb_clk = ahb_clk / 1000000; + spi_clk = spi_clk / 1000000; + ref_clk = ref_clk / 1000000; + + printf("%" ALIGN_SIZE "s %d/%d/%d/%3d/%3d MHz\n", + " ", cpu_clk, ddr_clk, ahb_clk, spi_clk, ref_clk); + + puts("\n"); +} + +/* + * Reads MAC address if available or uses fixed one + */ +void macaddr_init(u8 *mac_addr) +{ + u8 buffer[6]; + u8 fixed_mac[6] = {0x00, 0x03, 0x7F, 0x09, 0x0B, 0xAD}; + +#if defined(OFFSET_MAC_ADDRESS) + memcpy(buffer, (void *)(CFG_FLASH_BASE + + OFFSET_MAC_DATA_BLOCK + OFFSET_MAC_ADDRESS), 6); + + /* + * Check first LSBit (I/G bit) and second LSBit (U/L bit) in MSByte of vendor part + * both of them should be 0: + * I/G bit == 0 -> Individual MAC address (unicast address) + * U/L bit == 0 -> Burned-In-Address (BIA) MAC address + */ + if (CHECK_BIT((buffer[0] & 0xFF), 0) != 0 || + CHECK_BIT((buffer[0] & 0xFF), 1) != 0) { + memcpy(buffer, fixed_mac, 6); + } else { + mac_is_not_valid = 0; + } +#else + memcpy(buffer, fixed_mac, 6); +#endif + + memcpy(mac_addr, buffer, 6); +} + +/* + * Returns main CPU clock in Hz + */ +u32 main_cpu_clk(void) +{ + u32 cpu_clk; + + qca_sys_clocks(&cpu_clk, NULL, NULL, NULL, NULL); + + return cpu_clk; +} diff --git a/u-boot/board/ar7240/db12x/Makefile b/u-boot/board/ar7240/db12x/Makefile index dbf98a4..f655de9 100644 --- a/u-boot/board/ar7240/db12x/Makefile +++ b/u-boot/board/ar7240/db12x/Makefile @@ -2,7 +2,7 @@ include $(TOPDIR)/config.mk LIB = lib$(BOARD).a -OBJS = $(BOARD).o ../common/ar7240_pci.o ../common/ar7240_flash.o +OBJS = $(BOARD).o ../common/ar7240_pci.o ../common/ar7240_flash.o ../common/common.o ifeq ($(ETH_CONFIG), _s17) OBJS += ../common/athrs17_phy.o -- 2.25.1