Hi all,

This is a proposal for a new option to i2cdump, which would let the
user specify a register range to be probed (instead of the default 0x00
to 0xff). This improvement was suggested to me by Hendrik Sattler.

Index: tools/i2cdump.c
===================================================================
--- tools/i2cdump.c     (révision 5106)
+++ tools/i2cdump.c     (copie de travail)
@@ -61,12 +61,15 @@
        int pec = 0, even = 0;
        int flags = 0;
        int force = 0, yes = 0, version = 0;
+       const char *range = NULL;
+       int first = 0x00, last = 0xff;
 
        /* handle (optional) flags first */
        while (1+flags < argc && argv[1+flags][0] == '-') {
                switch (argv[1+flags][1]) {
                case 'V': version = 1; break;
                case 'f': force = 1; break;
+               case 'r': range = argv[1+(++flags)]; break;
                case 'y': yes = 1; break;
                default:
                        fprintf(stderr, "Warning: Unsupported flag "
@@ -179,6 +182,39 @@
                }
        }
 
+       /* Parse optional range string */
+       if (range) {
+               char *dash;
+
+               first = strtol(range, &dash, 0);
+               if (dash == range || *dash != '-'
+                || first < 0 || first > 0xff) {
+                       fprintf(stderr, "Error: Invalid range parameter!\n");
+                       exit(1);
+               }
+               last = strtol(++dash, &end, 0);
+               if (end == dash || *end != '\0'
+                || last < first || last > 0xff) {
+                       fprintf(stderr, "Error: Invalid range parameter!\n");
+                       exit(1);
+               }
+
+               /* Check mode constraints */
+               switch (size) {
+               case I2C_SMBUS_BYTE:
+               case I2C_SMBUS_BYTE_DATA:
+                       break;
+               case I2C_SMBUS_WORD_DATA:
+                       if (!even || (!(first%2) && last%2))
+                               break;
+                       /* Fall through */
+               default:
+                       fprintf(stderr,
+                               "Error: Range parameter not compatible with 
selected mode!\n");
+                       exit(1);
+               }
+       }
+
        file = open_i2c_dev(i2cbus, filename, 0);
        if (file < 0) {
                exit(1);
@@ -273,6 +309,11 @@
                                fprintf(stderr, "Probing bank %d using bank "
                                        "register 0x%02x.\n", bank, bankreg);
                }
+               if (range) {
+                       fprintf(stderr,
+                               "Probe range limited to 0x%02x-0x%02x.\n",
+                               first, last);
+               }
 
                fprintf(stderr, "Continue? [Y/n] ");
                fflush(stderr);
@@ -334,7 +375,7 @@
                }
 
                if (size == I2C_SMBUS_BYTE) {
-                       res = i2c_smbus_write_byte(file, 0);
+                       res = i2c_smbus_write_byte(file, first);
                        if(res != 0) {
                                fprintf(stderr, "Error: Write start address "
                                        "failed, return code %d\n", res);
@@ -347,9 +388,24 @@
                for (i = 0; i < 256; i+=16) {
                        if (size == I2C_SMBUS_BLOCK_DATA && i >= s_length)
                                break;
+                       if (i/16 < first/16)
+                               continue;
+                       if (i/16 > last/16)
+                               break;
+
                        printf("%02x: ", i);
                        for (j = 0; j < 16; j++) {
                                fflush(stdout);
+                               /* Skip unwanted registers */
+                               if (i+j < first || i+j > last) {
+                                       printf("   ");
+                                       if (size == I2C_SMBUS_WORD_DATA) {
+                                               printf("   ");
+                                               j++;
+                                       }
+                                       continue;
+                               }
+
                                if (size == I2C_SMBUS_BYTE_DATA) {
                                        block[i+j] = res =
                                          i2c_smbus_read_byte_data(file, i+j);
@@ -390,6 +446,11 @@
                                if (size == I2C_SMBUS_BLOCK_DATA
                                 && i+j >= s_length)
                                        break;
+                               /* Skip unwanted registers */
+                               if (i+j < first || i+j > last) {
+                                       printf(" ");
+                                       continue;
+                               }
 
                                res = block[i+j];
                                if (res < 0)
@@ -410,8 +471,19 @@
        } else {
                printf("     0,8  1,9  2,a  3,b  4,c  5,d  6,e  7,f\n");
                for (i = 0; i < 256; i+=8) {
+                       if (i/8 < first/8)
+                               continue;
+                       if (i/8 > last/8)
+                               break;
+
                        printf("%02x: ", i);
                        for (j = 0; j < 8; j++) {
+                               /* Skip unwanted registers */
+                               if (i+j < first || i+j > last) {
+                                       printf("     ");
+                                       continue;
+                               }
+
                                res = i2c_smbus_read_word_data(file, i+j);
                                if (res < 0)
                                        printf("XXXX ");
Index: tools/i2cdump.8
===================================================================
--- tools/i2cdump.8     (révision 5140)
+++ tools/i2cdump.8     (copie de travail)
@@ -5,6 +5,7 @@
 .SH SYNOPSIS
 .B i2cdump
 .RB [ -f ]
+.RB [ "-r first-last" ]
 .RB [ -y ]
 .I i2cbus
 .I address
@@ -30,6 +31,11 @@
 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,
+\fBfirst\fR must be even and \fBlast\fR must be odd.
+.TP
 .B -y
 Disable interactive mode. By default, i2cdump will wait for a confirmation
 from the user before messing with the I2C bus. When this flag is used, it

Hendrik, with this patch applied (on top of i2c-tools 3.0.0 or SVN),
you should be able to dump the registers of your 0Z99x chip with:

i2cdump -r 0x00-0x14 0 0x5c w

Please give it a try and let me know how it goes.

-- 
Jean Delvare

_______________________________________________
i2c mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/i2c

Reply via email to