root/lm-sensors/trunk/prog/eeprom/decode-vaio.pl @ 1309

Revision 1309, 3.5 KB (checked in by mds, 13 years ago)

new Sony Vaio eeprom decoder from

Jean Delvare <delvare@…>

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl -w
2#
3# Copyright 2002 Jean Delvare <khali@linux-fr.org>
4#
5#    This program is free software; you can redistribute it and/or modify
6#    it under the terms of the GNU General Public License as published by
7#    the Free Software Foundation; either version 2 of the License, or
8#    (at your option) any later version.
9#
10#    This program is distributed in the hope that it will be useful,
11#    but WITHOUT ANY WARRANTY; without even the implied warranty of
12#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13#    GNU General Public License for more details.
14#
15#    You should have received a copy of the GNU General Public License
16#    along with this program; if not, write to the Free Software
17#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18#
19# Version 0.1  2002-02-06  Jean Delvare <khali@linux-fr.org>
20#
21# EEPROM data decoding for Sony Vaio laptops.
22#
23# Two assumptions: lm_sensors-2.x installed,
24# and Perl is at /usr/bin/perl
25#
26# Please note that this is a guess-only work.  I don't expect much help from
27# Sony, so if someone can provide information, please contact me.  I used my
28# PCG-GR214EP as a base, but I can't promise that this script will work with
29# other models.  Any feedback appreciated anyway.
30#
31
32use strict;
33
34sub print_item
35{
36        my ($label,$value) = @_;
37       
38        printf("\%20s : \%s\n",$label,$value);
39}
40
41sub decode_char
42{
43        my ($bus,$addr,$base,$offset,$length) = @_;
44       
45        my $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/data$base-".($base+15);
46        open(FH,$filename) || die "Can't open $filename";
47        my $line=<FH>;
48        close(FH);
49       
50        my @bytes=split(/[ \n]/,$line);
51        @bytes=@bytes[$offset..$offset+$length-1];
52        my $string='';
53        my $item;
54        while(defined($item=shift(@bytes)))
55        {
56                $string.=chr($item);
57        }
58       
59        return($string);
60}
61
62sub decode_string
63{
64        my ($bus,$addr,$base,$offset,$length) = @_;
65
66        my $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/data$base-".($base+15);
67        open(FH,$filename) || die "Can't open $filename";
68        my $line=<FH>;
69        close(FH);
70
71        my @bytes=split(/[ \n]/,$line);
72        @bytes=@bytes[$offset..$offset+$length-1];
73        my $string='';
74        my $item;
75        while(defined($item=shift(@bytes)) && ($item!=0))
76        {
77                $string.=chr($item);
78        }
79       
80        return($string);
81}
82
83sub decode_string32
84{
85        my ($bus,$addr,$base) = @_;
86
87        my $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/data$base-".($base+15);
88        open(FH,$filename) || die "Can't open $filename";
89        my $line=<FH>;
90        close(FH);
91        $filename="/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/data".($base+16).'-'.($base+31);
92        open(FH,$filename) || die "Can't open $filename";
93        $line.=<FH>;
94        close(FH);
95
96        my @bytes=split(/[ \n]/,$line);
97        my $string='';
98        my $item;
99        while(defined($item=shift(@bytes)) && ($item!=0))
100        {
101                $string.=chr($item);
102        }
103       
104        return($string);
105}
106
107sub vaio_decode
108{
109        my ($bus,$addr) = @_;
110       
111        print_item('Model name',decode_string32($bus,$addr,128).' ['.decode_char($bus,$addr,160,10,4).']');
112        print_item('Revision',decode_string($bus,$addr,160,0,10));
113        print_item('Serial number',decode_string32($bus,$addr,192));
114        print_item('Timestamp',decode_string32($bus,$addr,224));
115}
116
117print("Sony Vaio EEPROM Decoder\n");
118print("Written by Jean Delvare.  Copyright 2002.\n");
119print("Version 0.1\n\n");
120
121if ( -r '/proc/sys/dev/sensors/eeprom-i2c-0-57')
122{
123        vaio_decode('0','57');
124}
125else
126{
127        print("Vaio eeprom not found.  Please make sure that the eeprom module is loaded.\n");
128        print("If you believe this is an error, please contact me <khali\@linux-fr.org>\n");
129        print("so that we may see how to fix the problem.\n");
130}
131
132print("\n");
Note: See TracBrowser for help on using the browser.