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

Revision 3070, 6.3 KB (checked in by khali, 9 years ago)

One more model reported to work (VGN-S4M/S).

  • 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 (C) 2002-2005 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# Version 0.2  2002-02-16  Jean Delvare <khali@linux-fr.org>
21#  Fixed to work with the new, simplified /proc interface names of the eeprom
22#    driver (lm_sensors 2.6.3 and greater).
23#  Shifted data display by 4 columns left.
24# Version 0.3  2002-02-17  Jean Delvare <khali@linux-fr.org>
25#  Added UUID field at 0x10 (added decode_uuid).
26#  Merged decode_string and decode_string32.
27#  Added unknown field at 0x20.
28#  Moved header and footer to BEGIN and END, respectively.
29#  Reformated history to match those of the other decode scripts.
30#  Deleted decode_char (made useless by decode_string).
31#  Reordered field display, changed some labels.
32#  Added old /proc interface check.
33# Version 1.0  2002-11-15  Jean Delvare <khali@linux-fr.org>
34#  Gave the label "OEM Data" to the field at 0x20.
35#  Gave the label "Timestamp" to the field at 0xE0.
36#  Renamed "Model Number" to "Model Name".
37#  Added some documentation.
38# Version 1.1  2004-01-17  Jean Delvare <khali@linux-fr.org>
39#  Added support for Linux 2.5/2.6 (i.e. sysfs).
40# Version 1.2  2004-11-28  Jean Delvare <khali@linux-fr.org>
41#  Support bus number 0 to 4 instead of only 0.
42# Version 1.3  2005-01-18  Jean Delvare <khali@linux-fr.org>
43#  Revision might be a Service Tag.
44#
45# EEPROM data decoding for Sony Vaio laptops.
46#
47# Two assumptions: lm_sensors-2.6.3 or greater installed,
48# and Perl is at /usr/bin/perl
49#
50# Please note that this is a guess-only work.  Sony support refused to help
51# me, so if someone can provide information, please contact me.
52# My knowledge is summarized on this page:
53# http://khali.linux-fr.org/vaio/eeprom.html
54#
55# It seems that if present, the EEPROM is always at 0x57.
56#
57# Models tested so far:
58#   PCG-F403     : No EEPROM
59#   PCG-F707     : No EEPROM
60#   PCG-GR114EK  : OK
61#   PCG-GR114SK  : OK
62#   PCG-GR214EP  : OK
63#   PCG-GRX316G  : OK
64#   PCG-GRX570   : OK
65#   PCG-GRX600K  : OK
66#   PCG-U1       : OK
67#   PCG-Z600LEK  : No EEPROM
68#   PCG-Z600NE   : No EEPROM
69#   VGN-S260     : OK
70#   VGN-S4M/S    : OK
71# Any feedback appreciated anyway.
72#
73# Thanks to Werner Heuser, Carsten Blume, Christian Gennerat, Joe Wreschnig,
74# Xavier Roche, Sebastien Lefevre, Lars Heer, Steve Dobson, Kent Hunt and
75# others for their precious help.
76
77
78use strict;
79use Fcntl qw(:DEFAULT :seek);
80use vars qw($sysfs $found);
81
82sub print_item
83{
84        my ($label,$value) = @_;
85       
86        printf("\%16s : \%s\n",$label,$value);
87}
88
89# Abstract reads so that other functions don't have to care wether
90# we need to use procfs or sysfs
91sub read_eeprom_bytes
92{
93        my ($bus, $addr, $offset, $length) = @_;
94        my $filename;
95       
96        if ($sysfs)
97        {
98                $filename = "/sys/bus/i2c/devices/$bus-00$addr/eeprom";
99                sysopen(FH, $filename, O_RDONLY)
100                        or die "Can't open $filename";
101                sysseek(FH, $offset, SEEK_SET)
102                        or die "Can't seek in $filename";
103
104                my ($r, $bytes);
105                $bytes = '';
106                $offset = 0;
107                while($length)
108                {
109                        $r = sysread(FH, $bytes, $length, $offset);
110                        die "Can't read $filename"
111                                unless defined($r);
112                        die "Unexpected EOF in $filename"
113                                unless $r;
114                        $offset += $r;
115                        $length -= $r;
116                }
117                close(FH);
118               
119                return $bytes;
120        }
121        else
122        {
123                my $base = $offset & 0xf0;
124                $offset -= $base;
125                my $values = '';
126                my $remains = $length + $offset;
127               
128                # Get all lines in a single string
129                while ($remains > 0)
130                {
131                        $filename = "/proc/sys/dev/sensors/eeprom-i2c-$bus-$addr/"
132                                  . sprintf('%02x', $base);
133                        open(FH, $filename)
134                                or die "Can't open $filename";
135                        $values .= <FH>;
136                        close(FH);
137                        $remains -= 16;
138                        $base += 16;
139                }
140               
141                # Store the useful part in an array
142                my @bytes = split(/[ \n]/, $values);
143                @bytes = @bytes[$offset..$offset+$length-1];
144
145                # Back to a binary string
146                return pack('C*', @bytes);
147        }
148}
149
150sub decode_string
151{
152        my ($bus, $addr, $offset, $length) = @_;
153
154        my $string = read_eeprom_bytes($bus, $addr, $offset, $length);
155        $string =~ s/\x00.*$//;
156       
157        return($string);
158}
159
160sub decode_uuid
161{
162        my ($bus,$addr,$base) = @_;
163
164        my @bytes = unpack('C16', read_eeprom_bytes($bus, $addr, $base, 16));
165        my $string='';
166
167        for(my $i=0;$i<16;$i++)
168        {
169                $string.=sprintf('%02x',shift(@bytes));
170                if(($i==3)||($i==5)||($i==7)||($i==9))
171                {
172                        $string.='-';
173                }
174        }
175
176        return($string);
177}
178
179sub vaio_decode
180{
181        my ($bus,$addr) = @_;
182       
183        print_item('Machine Name', decode_string($bus, $addr, 128, 32));
184        print_item('Serial Number', decode_string($bus, $addr, 192, 32));
185        print_item('UUID', decode_uuid($bus, $addr, 16));
186        my $revision = decode_string($bus, $addr, 160, 10);
187        print_item(length($revision) > 2 ? 'Service Tag' : 'Revision',
188                   $revision);
189        print_item('Model Name', 'PCG-'.decode_string($bus, $addr, 170, 4));
190        print_item('OEM Data', decode_string($bus, $addr, 32, 16));
191        print_item('Timestamp', decode_string($bus, $addr, 224, 32));
192}
193
194BEGIN
195{
196        print("Sony Vaio EEPROM Decoder\n");
197        print("Copyright (C) 2002-2005  Jean Delvare\n");
198        print("Version 1.3\n\n");
199}
200
201END
202{
203        print("\n");
204}
205
206for (my $i = 0, $found=0; $i <= 4 && !$found; $i++)
207{
208        if (-r "/sys/bus/i2c/devices/$i-0057/eeprom")
209        {
210                $sysfs = 1;
211                vaio_decode($i, '57');
212                $found++;
213        }
214        elsif (-r "/proc/sys/dev/sensors/eeprom-i2c-$i-57")
215        {
216                if (-r "/proc/sys/dev/sensors/eeprom-i2c-$i-57/data0-15")
217                {
218                        print("Deprecated old interface found.  Please upgrade to lm_sensors 2.6.3 or greater.");
219                        exit;
220                }
221                else
222                {
223                        $sysfs = 0;
224                        vaio_decode($i, '57');
225                        $found++;
226                }
227        }
228}
229
230if (!$found)
231{
232        print("Vaio EEPROM not found.  Please make sure that the eeprom module is loaded.\n");
233        print("If you believe this is an error, please contact me <khali\@linux-fr.org>\n");
234        print("so that we may see how to fix the problem.\n");
235}
Note: See TracBrowser for help on using the browser.