Moving EEPROM_TYPE to an enum in i2c.h and rewrite of get_eeprom_type()
authorNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 11 Mar 2013 16:26:05 +0000 (17:26 +0100)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 8 Nov 2022 16:03:04 +0000 (17:03 +0100)
drivers/eeprom.c
include/drivers/i2c.h

index e55ebc8..c3fccc8 100644 (file)
 #define EEPROM_ID_BIG_I2C_SIZE  16*1024
 #define EEPROM_ID_BIG_PAGE_SIZE 64
 
-#define EEPROM_TYPE_SMALL  EEPROM_ID_SMALL_ADDR
-#define EEPROM_TYPE_BIG    EEPROM_ID_BIG_ADDR
-#define EEPROM_TYPE_NONE   0xFF   /* Impossible eeprom address */
-
 
 /* Detect the eeprom size */
 int eeprom_detect(void)
@@ -78,16 +74,15 @@ int eeprom_detect(void)
 
 int get_eeprom_type(void)
 {
-       static int eeprom_type = 0; /* Will in fact store the eeprom address */
+       static int eeprom_type = -1;
 
-       if (eeprom_type == EEPROM_TYPE_NONE)
-               return -1; /* No need to check again */
+       if (eeprom_type >= 0) {
+               return eeprom_type; /* No need to check again */
+       }
 
+       eeprom_type = eeprom_detect();
        if (eeprom_type <= 0) {
-               eeprom_type = eeprom_detect();
-               if (eeprom_type <= 0) {
-                       return -EBADFD;
-               }
+               return -1;
        }
        return eeprom_type;
 }
index 8b8965e..a498303 100644 (file)
@@ -71,6 +71,12 @@ enum i2c_state_machine_states {
        I2C_DATA_NACK = 0x58,
 };
 
+enum i2c_eeprom_type {
+       EEPROM_TYPE_NONE = 0,
+       EEPROM_TYPE_SMALL,
+       EEPROM_TYPE_BIG,
+};
+
 
 /***************************************************************************** */
 /*                I2C Init                                                     */