diff options
author | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2008-03-19 14:04:25 +0000 |
---|---|---|
committer | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2008-03-19 14:04:25 +0000 |
commit | c6809f3a748f86e9d8abbcc61f46d306c526b55e (patch) | |
tree | 16ab75df764eb59fe101c17ed73e5597577e60c6 /stub | |
parent | 2f6b3aefe321a21dd06d4784ea4dee290f9dfba1 (diff) | |
download | i2c-tools-c6809f3a748f86e9d8abbcc61f46d306c526b55e.tar.gz |
Add support for word register access mode.
git-svn-id: http://lm-sensors.org/svn/i2c-tools/trunk@5149 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'stub')
-rwxr-xr-x | stub/i2c-stub-from-dump | 69 | ||||
-rw-r--r-- | stub/i2c-stub-from-dump.8 | 11 |
2 files changed, 52 insertions, 28 deletions
diff --git a/stub/i2c-stub-from-dump b/stub/i2c-stub-from-dump index 1d76b43..0a6f8ff 100755 --- a/stub/i2c-stub-from-dump +++ b/stub/i2c-stub-from-dump @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> +# Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org> # # 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 @@ -22,7 +22,7 @@ # a device you do not have access to, but of which you have a dump. use strict; -use vars qw($bus_nr $addr $count); +use vars qw($bus_nr $addr $bytes $words); # Kernel version detection code by Mark M. Hoffman, # copied from sensors-detect. @@ -66,6 +66,42 @@ sub get_i2c_stub_bus_number return $nr; } +sub process_dump +{ + my $dump = shift; + + open(DUMP, $dump) || die "Can't open $dump: $!\n"; + OUTER_LOOP: + while (<DUMP>) { + if (m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/) { + # Byte dump + my $offset = hex($1); + my @values = split(/ /, $2); + shift(@values); + for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) { + last OUTER_LOOP if system("i2cset", "-y", + $bus_nr, $addr, + sprintf("0x\%02x", $offset+$i), + "0x$val", "b"); + $bytes++; + } + } elsif (m/^([0-9a-f][08]):(( [0-9a-f]{4}){8})/) { + # Word dump + my $offset = hex($1); + my @values = split(/ /, $2); + shift(@values); + for (my $i = 0; $i < 8 && (my $val = shift(@values)); $i++) { + last OUTER_LOOP if system("i2cset", "-y", + $bus_nr, $addr, + sprintf("0x\%02x", $offset+$i), + "0x$val", "w"); + $words++; + } + } + } + close(DUMP); +} + if ($>) { print "You must be root to use this script\n"; exit 1; @@ -95,33 +131,22 @@ if (kernel_version_at_least(2, 6, 19)) { sleep(1); # udev may take some time to create the device node $bus_nr = get_i2c_stub_bus_number(); +$bytes = $words = 0; # We don't want to see the output of 256 i2cset open(SAVEOUT, ">&STDOUT"); open(STDOUT, ">/dev/null"); +process_dump($ARGV[1]); +close(STDOUT); -$count = 0; -open(DUMP, $ARGV[1]) || die "Can't open $ARGV[1]: $!\n"; -OUTER_LOOP: -while (<DUMP>) { - next unless m/^([0-9a-f]0):(( [0-9a-f]{2}){16})/; - my $offset = hex($1); - my @values = split(/ /, $2); - shift(@values); - for (my $i = 0; $i < 16 && (my $val = shift(@values)); $i++) { - last OUTER_LOOP if system("i2cset", "-y", - $bus_nr, $addr, - sprintf("0x\%02x", $offset+$i), - sprintf("0x\%02x", hex($val)), "b"); - $count++; - } +if ($bytes) { + printf SAVEOUT "$bytes byte values written to \%d-\%04x\n", + $bus_nr, oct($addr); } -close(DUMP); -close(STDOUT); -if ($count) { - printf SAVEOUT "$count byte values written to \%d-\%04x\n", +if ($words) { + printf SAVEOUT "$words word values written to \%d-\%04x\n", $bus_nr, oct($addr); } -exit($count == 0); +exit($bytes + $words == 0); diff --git a/stub/i2c-stub-from-dump.8 b/stub/i2c-stub-from-dump.8 index fc63f62..b26af75 100644 --- a/stub/i2c-stub-from-dump.8 +++ b/stub/i2c-stub-from-dump.8 @@ -1,4 +1,4 @@ -.TH I2C-STUB-FROM-DUMP 8 "November 2007" +.TH I2C-STUB-FROM-DUMP 8 "March 2008" .SH NAME i2c-stub-from-dump \- feed i2c-stub with a dump file @@ -26,7 +26,9 @@ chip in question lives at address 0x4c on I2C bus 0, you would run: i2cdump -y 0 0x4c b > chip.dump Adjust the bus number and chip address for your case. i2cdetect can help -you find out their values. +you find out their values. If the device uses word (16-bit) register +access instead of the traditional byte (8-bit) access, use mode \fBw\fR +instead of \fBb\fR. Copy the dump file to system B. @@ -40,14 +42,11 @@ Again, adjust the address as needed. .SH LIMITATIONS There are some limitations to the kind of devices that can be handled: -.IP \(bu "\w'\(bu'u+1n" -Device must only use byte register access. i2c-stub supports word -access but i2c-stub-from-dump doesn't (yet). .IP \(bu Device must not have banks (as most Winbond devices do). .SH SEE ALSO - i2cdump(8), i2cdetect(8), i2cset(8) +i2cdump(8), i2cdetect(8), i2cset(8) .SH AUTHOR Jean Delvare |