Merge tag 'u-boot-imx-20190101' of git://www.denx.de/git/u-boot-imx
[platform/kernel/u-boot.git] / board / ge / mx53ppd / mx53ppd.c
index 6a8a29d..23bfe55 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2017 General Electric Company
  *
@@ -5,8 +6,6 @@
  *
  * Copyright (C) 2011 Freescale Semiconductor, Inc.
  * Jason Liu <r64343@freescale.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -20,6 +19,7 @@
 #include <linux/errno.h>
 #include <asm/mach-imx/mxc_i2c.h>
 #include <asm/mach-imx/mx5_video.h>
+#include <environment.h>
 #include <netdev.h>
 #include <i2c.h>
 #include <mmc.h>
 #include <watchdog.h>
 #include "ppd_gpio.h"
 #include <stdlib.h>
+#include "../../ge/common/ge_common.h"
 #include "../../ge/common/vpd_reader.h"
-#include <rtc.h>
 
 #define MX53PPD_LCD_POWER              IMX_GPIO_NR(3, 24)
 
 DECLARE_GLOBAL_DATA_PTR;
 
-/* Index of I2C1, SEGMENT 1 (see CONFIG_SYS_I2C_BUSES). */
-#define VPD_EEPROM_BUS 2
-
-/* Address of 24C08 EEPROM. */
-#define VPD_EEPROM_ADDR                0x50
-#define VPD_EEPROM_ADDR_LEN    1
-
 static u32 mx53_dram_size[2];
 
 phys_size_t get_effective_memsize(void)
@@ -297,10 +290,10 @@ struct vpd_cache {
 /*
  * Extracts MAC and product information from the VPD.
  */
-static int vpd_callback(void *userdata, u8 id, u8 version, u8 type, size_t size,
-                       u8 const *data)
+static int vpd_callback(struct vpd_cache *userdata, u8 id, u8 version,
+                       u8 type, size_t size, u8 const *data)
 {
-       struct vpd_cache *vpd = (struct vpd_cache *)userdata;
+       struct vpd_cache *vpd = userdata;
 
        if (id == VPD_BLOCK_HWID && version == 1 && type != VPD_TYPE_INVALID &&
            size >= 1) {
@@ -328,80 +321,6 @@ static void process_vpd(struct vpd_cache *vpd)
                eth_env_set_enetaddr("ethaddr", vpd->mac1);
 }
 
-static int read_vpd(uint eeprom_bus)
-{
-       struct vpd_cache vpd;
-       int res;
-       int size = 1024;
-       u8 *data;
-       unsigned int current_i2c_bus = i2c_get_bus_num();
-
-       res = i2c_set_bus_num(eeprom_bus);
-       if (res < 0)
-               return res;
-
-       data = malloc(size);
-       if (!data)
-               return -ENOMEM;
-
-       res = i2c_read(VPD_EEPROM_ADDR, 0, VPD_EEPROM_ADDR_LEN, data, size);
-       if (res == 0) {
-               memset(&vpd, 0, sizeof(vpd));
-               vpd_reader(size, data, &vpd, vpd_callback);
-               process_vpd(&vpd);
-       }
-
-       free(data);
-
-       i2c_set_bus_num(current_i2c_bus);
-       return res;
-}
-
-static void check_time(void)
-{
-       int ret, i;
-       struct rtc_time tm;
-       u8 retry = 3;
-
-       unsigned int current_i2c_bus = i2c_get_bus_num();
-
-       ret = i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
-       if (ret < 0)
-               return;
-
-       rtc_init();
-
-       for (i = 0; i < retry; i++) {
-               ret = rtc_get(&tm);
-               if (!ret || ret == -EINVAL)
-                       break;
-       }
-
-       if (ret < 0)
-               env_set("rtc_status", "RTC_ERROR");
-
-       if (tm.tm_year > 2037) {
-               tm.tm_sec  = 0;
-               tm.tm_min  = 0;
-               tm.tm_hour = 0;
-               tm.tm_mday = 1;
-               tm.tm_wday = 2;
-               tm.tm_mon  = 1;
-               tm.tm_year = 2036;
-
-               for (i = 0; i < retry; i++) {
-                       ret = rtc_set(&tm);
-                       if (!ret)
-                               break;
-               }
-
-               if (ret < 0)
-                       env_set("rtc_status", "RTC_ERROR");
-       }
-
-       i2c_set_bus_num(current_i2c_bus);
-}
-
 int board_init(void)
 {
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
@@ -434,8 +353,14 @@ int misc_init_r(void)
 int board_late_init(void)
 {
        int res;
+       struct vpd_cache vpd;
 
-       read_vpd(VPD_EEPROM_BUS);
+       memset(&vpd, 0, sizeof(vpd));
+       res = read_vpd(&vpd, vpd_callback);
+       if (!res)
+               process_vpd(&vpd);
+       else
+               printf("Can't read VPD");
 
        res = clock_1GHz();
        if (res != 0)