Skip to contentSkip to conversation

There are several eeprom drivers

PATCH In review Jean Delvare 2 participants 6 messages Aug 31, 2020 I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/3 There are several eeprom drivers

There used to be only 1 eeprom driver (named "eeprom") but now there are 3 and the legacy "eeprom" driver is not the preferred option. So list all 3 drivers in our documentation to prevent confusion.

---
 README           |    3 ++-
 eeprom/Module.mk |    4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

No changes since v1.

README +2 -1
@@ -20,7 +20,8 @@ The various tools included in this packa
 
 * eeprom
   Perl scripts for decoding different types of EEPROMs (SPD, EDID...) These
-  scripts rely on the "eeprom" kernel driver. They are installed by default.
+  scripts rely on the eeprom kernel drivers ("at24" and "ee1004", "eeprom" on
+  older kernels). They are installed by default.
 
 * eeprog, eepromer
   Tools for writing to EEPROMs. These tools rely on the "i2c-dev" kernel
eeprom/Module.mk +2 -2
@@ -1,6 +1,6 @@
-# EEPROM decoding scripts for the Linux eeprom driver
+# EEPROM decoding scripts for the Linux eeprom drivers
 #
-# Copyright (C) 2007-2013  Jean Delvare <[email protected]>
+# Copyright (C) 2007-2020  Jean Delvare <[email protected]>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#1 lore raw

PATCH v2 2/3 decode-vaio: Add support for the at24 driver

We have just added support for the VAIO EEPROM to the at24 kernel driver, so let this script handle it.

---
 eeprom/decode-vaio |   41 +++++++++++++++++++++++++++++++++++++----
 1 file changed, 37 insertions(+), 4 deletions(-)

Changes since v1:
* Move the increase of scanned i2c buses to a separate patch (suggested by Wolfram, thanks).
* Explicitly skip devices that aren't driven by either at24 or eeprom.
* Fix the failure error message when no VAIO EEPROM is found to mention the at24 driver.

eeprom/decode-vaio +37 -4
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# Copyright (C) 2002-2008  Jean Delvare <[email protected]>
+# Copyright (C) 2002-2020  Jean Delvare <[email protected]>
 #
 #    This program is free software; you can redistribute it and/or modify
 #    it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
 #
 # EEPROM data decoding for Sony Vaio laptops.
 #
-# The eeprom driver must be loaded. For kernels older than 2.6.0, the
+# The at24 or eeprom driver must be loaded. For kernels older than 2.6.0, the
 # eeprom driver can be found in the lm-sensors package.
 #
 # Please note that this is a guess-only work.  Sony support refused to help
@@ -53,11 +53,39 @@
 
 use strict;
 use Fcntl qw(:DEFAULT :seek);
+use File::Basename;
 use vars qw($sysfs $found);
 
-use constant VERSION	=> "1.6";
+use constant VERSION	=> "1.7";
 use constant ONLYROOT	=> "Readable only by root";
 
+# From a sysfs device path and an attribute name, return the attribute
+# value, or undef (stolen from sensors-detect)
+sub sysfs_device_attribute
+{
+	my ($device, $attr) = @_;
+	my $value;
+
+	open(local *FILE, "$device/$attr") or return "";
+	$value = <FILE>;
+	close(FILE);
+	return unless defined $value;
+
+	chomp($value);
+	return $value;
+}
+
+# From a sysfs device path, return the driver name, or undef (stolen from
+# sensors-detect)
+sub sysfs_device_driver
+{
+	my $device = shift;
+
+	my $link = readlink("$device/driver");
+	return unless defined $link;
+	return basename($link);
+}
+
 sub print_item
 {
 	my ($label,$value) = @_;
@@ -213,6 +241,11 @@ for (my $i = 0, $found=0; $i <= 4 && !$f
 {
 	if (-r "/sys/bus/i2c/devices/$i-0057/eeprom")
 	{
+		my $driver = sysfs_device_driver("/sys/bus/i2c/devices/$i-0057");
+		my $name = sysfs_device_attribute("/sys/bus/i2c/devices/$i-0057", "name");
+		next unless ($driver eq "at24" || $driver eq "eeprom");
+		next if ($driver eq "at24" && $name ne "24c02-vaio");
+
 		$sysfs = 1;
 		$found += vaio_decode($i, '57');
 	}
@@ -233,5 +266,5 @@ for (my $i = 0, $found=0; $i <= 4 && !$f
 
 if (!$found)
 {
-	print("Vaio EEPROM not found.  Please make sure that the eeprom module is loaded.\n");
+	print("Vaio EEPROM not found.  Please make sure that the at24 or eeprom module is loaded.\n");
 }
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#2 lore raw

PATCH v2 3/3 decode-vaio: Scan more i2c buses

In reply to Jean Delvare

While the laptop I originally developed decode-vaio on, only had 5 i2c buses, there could be more on other models, and there are definitely more on the system I use to test the script (using i2c-stub) these days. So look for the VAIO EEPROM on up to 32 i2c buses to be on the safe side.

---
 eeprom/decode-vaio |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Changes since v1: New.

eeprom/decode-vaio +1 -1
@@ -237,7 +237,7 @@ END
 	print("\n");
 }
 
-for (my $i = 0, $found=0; $i <= 4 && !$found; $i++)
+for (my $i = 0, $found=0; $i <= 31 && !$found; $i++)
 {
 	if (-r "/sys/bus/i2c/devices/$i-0057/eeprom")
 	{
Signature · 2 lines
Jean Delvare
SUSE L3 Support
#3 lore raw

Re: [PATCH v2 3/3] decode-vaio: Scan more i2c buses

eeprom/decode-vaio END · line 240

Quoted 3 lines
eeprom/decode-vaio +1 -1
-for (my $i = 0, $found=0; $i <= 4 && !$found; $i++)
+for (my $i = 0, $found=0; $i <= 31 && !$found; $i++)

To get rid of the problem entirely, can't we do something like this with shell globs? Pseudo code:

	foreach (/sys/bus/i2c/devices/*-0057/eeprom)
		$found += <found device>

	if (!$found)
		foreach (/proc/sys/dev/sensors/eeprom-i2c-*-57)
		check_old_interface
		$found += <found device>
#4 lore raw

Re: [PATCH v2 3/3] decode-vaio: Scan more i2c buses

Quoted 6 lines · Wolfram Sang

eeprom/decode-vaio END · line 240

Quoted 2 lines
eeprom/decode-vaio +1 -1
-for (my $i = 0, $found=0; $i <= 4 && !$found; $i++)
+for (my $i = 0, $found=0; $i <= 31 && !$found; $i++)  

To get rid of the problem entirely, can't we do something like this with shell globs? Pseudo code:

Quoted 7 lines
	foreach (/sys/bus/i2c/devices/*-0057/eeprom)
		$found += <found device>

	if (!$found)
		foreach (/proc/sys/dev/sensors/eeprom-i2c-*-57)
		check_old_interface
		$found += <found device>

You have hit my perl knowledge limits ;-)

I know that arbitrary limits are bad, but the thing is, I'm not sure if there is any actual user left for that script. I adjusted it for the at24 driver because *if* there are users left then things should keep working. But I wrote all this in 2001, laptops from then are definitely no longer in use, and at this point I have no idea if recent VAIO laptops still have this EEPROM.

So until someone comes to me with a recent VAIO laptop that needs this, I am reluctant to invest more time into this.

Signature · 2 lines
Jean Delvare
SUSE L3 Support
#5 lore raw

Re: [PATCH v2 3/3] decode-vaio: Scan more i2c buses

Quoted 3 lines

So until someone comes to me with a recent VAIO laptop that needs this, I am reluctant to invest more time into this.

Fully agreed!