Procházet zdrojové kódy

board: starfive: Add interface to get data from eeprom

Signed-off-by: Jianlong Huang <jianlong.huang@starfivetech.com>
Jianlong Huang před 1 rokem
rodič
revize
a25a1eb135

+ 1 - 0
arch/riscv/include/asm/arch-jh7110/eeprom.h

@@ -9,5 +9,6 @@
 #define _ASM_RISCV_EEPROM_H
 
 u8 get_pcb_revision_from_eeprom(void);
+int get_data_from_eeprom(int offset, int len, unsigned char *data);
 
 #endif /* _ASM_RISCV_EEPROM_H */

+ 30 - 0
board/starfive/visionfive2/visionfive2-i2c-eeprom.c

@@ -765,8 +765,38 @@ u8 get_pcb_revision_from_eeprom(void)
 {
 	u8 pv = 0xFF;
 
+	if (read_eeprom(eeprom_wp_buff))
+		return pv;
+
 	if (einfo.pcb_revision) {
 		pv = *einfo.pcb_revision;
 	}
 	return pv;
 }
+
+/**
+ * get_data_from_eeprom
+ *
+ * Read data from eeprom, must use int mac_read_from_eeprom(void) first
+ *
+ * offset: offset of eeprom
+ * len: count of data
+ * data: return data
+ *
+ * return the len of valid data
+ */
+int get_data_from_eeprom(int offset, int len, unsigned char *data)
+{
+	int cp_len = -1;
+
+	if (read_eeprom(eeprom_wp_buff))
+		return cp_len;
+
+	if (offset < STARFIVE_EEPROM_HATS_SIZE_MAX) {
+		cp_len = (offset + len > STARFIVE_EEPROM_HATS_SIZE_MAX) ?
+			(offset + len - STARFIVE_EEPROM_HATS_SIZE_MAX) : len;
+		memcpy(data, &eeprom_wp_buff[offset], cp_len);
+	}
+
+	return cp_len;
+}