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 3fa53ff..23bfe55 100644 (file)
@@ -290,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) {
@@ -321,36 +321,6 @@ static void process_vpd(struct vpd_cache *vpd)
                eth_env_set_enetaddr("ethaddr", vpd->mac1);
 }
 
-static int read_vpd(void)
-{
-       struct vpd_cache vpd;
-       int res;
-       static const int size = CONFIG_SYS_VPD_EEPROM_SIZE;
-       u8 *data;
-       unsigned int current_i2c_bus = i2c_get_bus_num();
-
-       res = i2c_set_bus_num(CONFIG_SYS_VPD_EEPROM_I2C_BUS);
-       if (res < 0)
-               return res;
-
-       data = malloc(size);
-       if (!data)
-               return -ENOMEM;
-
-       res = i2c_read(CONFIG_SYS_VPD_EEPROM_I2C_ADDR, 0,
-                      CONFIG_SYS_VPD_EEPROM_I2C_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;
-}
-
 int board_init(void)
 {
        gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
@@ -383,8 +353,14 @@ int misc_init_r(void)
 int board_late_init(void)
 {
        int res;
+       struct vpd_cache vpd;
 
-       read_vpd();
+       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)