All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Linux I2C <linux-i2c@vger.kernel.org>
Cc: Wolfram Sang <wsa@kernel.org>
Subject: [PATCH v2 2/3] decode-vaio: Add support for the at24 driver
Date: Mon, 31 Aug 2020 10:08:12 +0200	[thread overview]
Message-ID: <20200831100812.7b189093@endymion> (raw)
In-Reply-To: <20200831100256.077ce253@endymion>

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

Signed-off-by: Jean Delvare <jdelvare@suse.de>
---
 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.

--- i2c-tools.orig/eeprom/decode-vaio	2020-08-31 09:55:34.195144542 +0200
+++ i2c-tools/eeprom/decode-vaio	2020-08-31 10:00:21.945292972 +0200
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# Copyright (C) 2002-2008  Jean Delvare <jdelvare@suse.de>
+# Copyright (C) 2002-2020  Jean Delvare <jdelvare@suse.de>
 #
 #    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");
 }

-- 
Jean Delvare
SUSE L3 Support

  reply	other threads:[~2020-08-31  8:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31  8:02 [PATCH v2 1/3] There are several eeprom drivers Jean Delvare
2020-08-31  8:08 ` Jean Delvare [this message]
2020-08-31  8:09 ` [PATCH v2 3/3] decode-vaio: Scan more i2c buses Jean Delvare
2020-08-31  9:48   ` Wolfram Sang
2020-08-31 13:04     ` Jean Delvare
2020-08-31 13:25       ` Wolfram Sang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200831100812.7b189093@endymion \
    --to=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.