New, common file for board related, common functions
authorPiotr Dymacz <pepe2k@gmail.com>
Fri, 13 Nov 2015 01:50:40 +0000 (02:50 +0100)
committerPiotr Dymacz <pepe2k@gmail.com>
Fri, 13 Nov 2015 01:50:40 +0000 (02:50 +0100)
u-boot/board/ar7240/ap121/Makefile
u-boot/board/ar7240/common/common.c [new file with mode: 0644]
u-boot/board/ar7240/db12x/Makefile

index 768e92937f3802ab2a07db55fa24c21fd7eda8df..f93b1d34089cce14c4593a7a8c24348702a700f9 100644 (file)
@@ -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 (file)
index 0000000..326f012
--- /dev/null
@@ -0,0 +1,124 @@
+#include <config.h>
+#include <common.h>
+#include <command.h>
+#include <asm/mipsregs.h>
+#include <asm/addrspace.h>
+#include <soc/qca_soc_common.h>
+
+#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;
+}
index dbf98a480d122d1e0da28b7d480361c346087320..f655de902213b9b1cbc1f0d4a616f4f49f91c009 100644 (file)
@@ -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