+static int read_probe_eeprom(unsigned int addr, struct probe_eeprom *eeprom)
+{
+ GString *path = g_string_sized_new(64);
+ char eeprom_buf[EEPROM_SIZE];
+ ssize_t rd;
+ int fd;
+
+ probe_eeprom_path(addr, path);
+ fd = g_open(path->str, O_RDONLY);
+ g_string_free(path, TRUE);
+ if (fd < 0)
+ return -1;
+
+ rd = read(fd, eeprom_buf, EEPROM_SIZE);
+ close(fd);
+ if (rd != EEPROM_SIZE)
+ return -1;
+
+ eeprom->type = RB32(eeprom_buf + EEPROM_OFF_TYPE);
+ eeprom->rev = RB32(eeprom_buf + EEPROM_OFF_REV);
+ eeprom->shunt = RB32(eeprom_buf + EEPROM_OFF_SHUNT);
+ eeprom->pwr_sw = R8(eeprom_buf + EEPROM_OFF_PWR_SW);
+ /* Don't care about the serial number and tag for now. */
+
+ /* Check if we have some sensible values. */
+ if (eeprom->rev != 'B')
+ /* 'B' is the only supported revision with EEPROM for now. */
+ return -1;
+
+ if (eeprom->type != EEPROM_PROBE_TYPE_USB &&
+ eeprom->type != EEPROM_PROBE_TYPE_JACK &&
+ eeprom->type != EEPROM_PROBE_TYPE_HE10)
+ return -1;
+
+ return 0;
+}
+
+/* Some i2c slave addresses on revision B probes differ from revision A. */
+static int revB_addr_to_num(unsigned int addr)
+{
+ switch (addr) {
+ case 0x44: return 5;
+ case 0x45: return 6;
+ case 0x42: return 3;
+ case 0x43: return 4;
+ default: return addr - 0x3f;
+ }
+}
+