From 6b9849376307e91084fc6c871e96d3d209386035 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 13 Jul 2021 10:16:38 +0200 Subject: i2cdump: Add range support with mode i (I2C block) Implementing range support for I2C block read (mode i) isn't particularly difficult so let's just do that. Signed-off-by: Jean Delvare Reviewed-by: Wolfram Sang Tested-by: Wolfram Sang --- tools/i2cdump.8 | 6 +++--- tools/i2cdump.c | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/i2cdump.8 b/tools/i2cdump.8 index e039751..95a9861 100644 --- a/tools/i2cdump.8 +++ b/tools/i2cdump.8 @@ -1,4 +1,4 @@ -.TH I2CDUMP 8 "October 2017" +.TH I2CDUMP 8 "June 2021" .SH NAME i2cdump \- examine I2C registers @@ -32,8 +32,8 @@ kernel driver in question. It can also cause i2cdump to return invalid results. So use at your own risk and only if you know what you're doing. .TP .B -r first-last -Limit the range of registers being accessed. This option is only available -with modes \fBb\fP, \fBw\fP, \fBc\fP and \fBW\fP. For mode \fBW\fP, +Limit the range of registers being accessed. This option is not available +with mode \fBs\fP. For mode \fBW\fP, \fBfirst\fR must be even and \fBlast\fR must be odd. .TP .B -y diff --git a/tools/i2cdump.c b/tools/i2cdump.c index 7b291ea..4637089 100644 --- a/tools/i2cdump.c +++ b/tools/i2cdump.c @@ -2,7 +2,7 @@ i2cdump.c - a user-space program to dump I2C registers Copyright (C) 2002-2003 Frodo Looijaard , and Mark D. Studebaker - Copyright (C) 2004-2012 Jean Delvare + Copyright (C) 2004-2021 Jean Delvare 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 @@ -251,6 +251,7 @@ int main(int argc, char *argv[]) switch (size) { case I2C_SMBUS_BYTE: case I2C_SMBUS_BYTE_DATA: + case I2C_SMBUS_I2C_BLOCK_DATA: break; case I2C_SMBUS_WORD_DATA: if (!even || (!(first%2) && last%2)) @@ -341,8 +342,9 @@ int main(int argc, char *argv[]) /* Remember returned block length for a nicer display later */ s_length = res; + last = res - 1; } else { - for (res = 0; res < 256; res += i) { + for (res = first; res <= last; res += i) { i = i2c_smbus_read_i2c_block_data(file, res, 32, cblock + res); if (i <= 0) { @@ -356,9 +358,7 @@ int main(int argc, char *argv[]) "return code %d\n", res); exit(1); } - if (res >= 256) - res = 256; - for (i = 0; i < res; i++) + for (i = first; i <= last; i++) block[i] = cblock[i]; } -- cgit v1.2.1