]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: phytec: common: Move API v2 init to new function
authorDaniel Schultz <d.schultz@phytec.de>
Wed, 22 May 2024 06:18:24 +0000 (23:18 -0700)
committerTom Rini <trini@konsulko.com>
Fri, 7 Jun 2024 20:01:53 +0000 (14:01 -0600)
Move the entire initialization code for API v2 into a dedicated
function. This rework will allow to easily integrate the API v3
as next step during init.

Signed-off-by: Daniel Schultz <d.schultz@phytec.de>
Tested-by: Wadim Egorov <w.egorov@phytec.de>
board/phytec/common/phytec_som_detection.c

index f0e35d8d2ecfee9d2592fa7e42c0ff7f713f20f7..ab2d5a7b72673992ded49a2835d2dd3d7f04d2f7 100644 (file)
@@ -72,11 +72,29 @@ int phytec_eeprom_read(u8 *data, int bus_num, int addr, int size, int offset)
        return ret;
 }
 
+int phytec_eeprom_data_init_v2(struct phytec_eeprom_data *data)
+{
+       unsigned int crc;
+
+       if (!data)
+               return -1;
+
+       crc = crc8(0, (const unsigned char *)&data->payload, PHYTEC_API2_DATA_LEN);
+       debug("%s: crc: %x\n", __func__, crc);
+
+       if (crc) {
+               pr_err("%s: CRC mismatch. EEPROM data is not usable.\n",
+                      __func__);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
                            int bus_num, int addr)
 {
        int ret, i;
-       unsigned int crc;
        u8 *ptr;
 
        if (!data)
@@ -104,20 +122,10 @@ int phytec_eeprom_data_init(struct phytec_eeprom_data *data,
                goto err;
        }
 
-       /* We are done here for early revisions */
-       if (data->payload.api_rev <= PHYTEC_API_REV1) {
-               data->valid = true;
-               return 0;
-       }
-
-       crc = crc8(0, (const unsigned char *)&data->payload, PHYTEC_API2_DATA_LEN);
-       debug("%s: crc: %x\n", __func__, crc);
-
-       if (crc) {
-               pr_err("%s: CRC mismatch. EEPROM data is not usable.\n",
-                      __func__);
-               ret = -EINVAL;
-               goto err;
+       if (data->payload.api_rev >= PHYTEC_API_REV2) {
+               ret = phytec_eeprom_data_init_v2(data);
+               if (ret)
+                       goto err;
        }
 
        data->valid = true;