From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Jason Morgan" Date: Tue, 02 Apr 2013 13:07:50 +0000 Subject: [lm-sensors] i2c-tools 'raw' i2c unsupported Message-Id: <20130402130750.164070@gmx.com> MIME-Version: 1 Content-Type: multipart/mixed; boundary="===============8588452095159277838==" List-Id: To: lm-sensors@vger.kernel.org --===============8588452095159277838== Content-Type: multipart/alternative; boundary="========GMXBoundary164071364908070625525" --========GMXBoundary164071364908070625525 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Hi, I notice that the lm-sensors i2c-tools don't support 'raw' I2C device file access, instead they rely on the driver supporting the smbus interface. I am working on an embedded system that does not have smbus, so I created a some patches for lm-sensors tools that add a 'r' access method. The changes support i2c-get, i2c-put and i2c-dump. These changes allow the i2c-tools to be used without smbus support in the kernel device driver for the I2C inteface. Would the developers be interested in adding my patch to the distribution? diff from r6127 regards, Jason ---- Index: tools/i2cbusses.c =================================================================== --- tools/i2cbusses.c (revision 6127) +++ tools/i2cbusses.c (working copy) @@ -415,3 +415,50 @@ return 0; } + +int i2c_read_raw_again(int file, unsigned char *buffer, unsigned int count) +{ + unsigned char *ptr = buffer; + int res=0; + + res = read(file, ptr, count); + if(res<0)fprintf(stderr, "Aborting - read data failed (%d) : %s\n",errno,strerror(errno)); + + return res; +} + +int i2c_read_raw(int file, unsigned char *buffer, int daddress, unsigned int count) +{ + int res; + buffer[0] = (unsigned char)(daddress>>8); + buffer[1] = (unsigned char)daddress & 0xFF; + + res = write(file, buffer, 2); + if (res < 0)fprintf(stderr, "Warning - write addr failed %d : %s\n",errno,strerror(errno)); + + return i2c_read_raw_again(file,buffer,count); +} + +int i2c_write_raw(int file, unsigned char *buffer, int daddress, unsigned int count) +{ + unsigned char *ptr; + int res; + unsigned int n; + + ptr = malloc(count+10); + if(ptr==NULL) + { + fprintf(stderr, "Memory allocation error\n"); + return -1; + } + ptr[0] = (unsigned char)(daddress>>8); + ptr[1] = (unsigned char)daddress & 0xFF; + memcpy(ptr+2,buffer,count); + for(n=0;n= 0) { old_bank = res; @@ -331,7 +349,7 @@ if (size != I2C_SMBUS_WORD_DATA || even) { /* do the block transaction */ if (size == I2C_SMBUS_BLOCK_DATA - || size == I2C_SMBUS_I2C_BLOCK_DATA) { + || size == I2C_SMBUS_I2C_BLOCK_DATA || size == I2C_RAW) { unsigned char cblock[288]; if (size == I2C_SMBUS_BLOCK_DATA) { @@ -340,6 +358,9 @@ /* Remember returned block length for a nicer display later */ s_length = res; + } else if(size == I2C_RAW) { + res = i2c_read_raw(file, cblock, (bank*256), 256); + s_length = res; } else { for (res = 0; res < 256; res += i) { i = i2c_smbus_read_i2c_block_data(file, @@ -359,7 +380,7 @@ res = 256; for (i = 0; i < res; i++) block[i] = cblock[i]; - if (size != I2C_SMBUS_BLOCK_DATA) + if (size != I2C_SMBUS_BLOCK_DATA && size != I2C_RAW) for (i = res; i < 256; i++) block[i] = -1; } @@ -372,12 +393,14 @@ exit(1); } } - + printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f" " 0123456789abcdef\n"); for (i = 0; i < 256; i+=16) { if (size == I2C_SMBUS_BLOCK_DATA && i >= s_length) break; + if (size == I2C_RAW && i >= s_length) + break; if (i/16 < first/16) continue; if (i/16 > last/16) @@ -400,8 +423,7 @@ block[i+j] = res = i2c_smbus_read_byte_data(file, i+j); } else if (size == I2C_SMBUS_WORD_DATA) { - res = i2c_smbus_read_word_data(file, - i+j); + res = i2c_smbus_read_word_data(file, i+j); if (res < 0) { block[i+j] = res; block[i+j+1] = res; @@ -415,7 +437,7 @@ } else res = block[i+j]; - if (size == I2C_SMBUS_BLOCK_DATA + if ((size == I2C_SMBUS_BLOCK_DATA || size == I2C_RAW) && i+j >= s_length) { printf(" "); } else if (res < 0) { @@ -433,7 +455,7 @@ printf(" "); for (j = 0; j < 16; j++) { - if (size == I2C_SMBUS_BLOCK_DATA + if ((size == I2C_SMBUS_BLOCK_DATA || size == I2C_RAW) && i+j >= s_length) break; /* Skip unwanted registers */ @@ -483,7 +505,7 @@ printf("\n"); } } - if (bank && size != I2C_SMBUS_BLOCK_DATA) { + if (bank && size != I2C_SMBUS_BLOCK_DATA && size != I2C_RAW) { i2c_smbus_write_byte_data(file, bankreg, old_bank); } exit(0); Index: tools/i2cget.c =================================================================== --- tools/i2cget.c (revision 6127) +++ tools/i2cget.c (working copy) @@ -38,6 +38,8 @@ static void help(void) __attribute__ ((noreturn)); +#define I2C_RAW -1 + static void help(void) { fprintf(stderr, @@ -45,6 +47,7 @@ " I2CBUS is an integer or an I2C bus name\n" " ADDRESS is an integer (0x03 - 0x77)\n" " MODE is one of:\n" + " r (read byte using raw i2c device)\n" " b (read byte data, default)\n" " w (read word data)\n" " c (write byte/read byte)\n" @@ -52,6 +55,7 @@ exit(1); } + static int check_funcs(int file, int size, int daddress, int pec) { unsigned long funcs; @@ -62,8 +66,15 @@ "functionality matrix: %s\n", strerror(errno)); return -1; } - + switch (size) { + case I2C_RAW: + //If raw i2c is specified, use that instead of SMBus + if (!(funcs & I2C_FUNC_I2C)){ + fprintf(stderr, MISSING_FUNC_FMT, "Raw I2C"); + return -1; + } + break; case I2C_SMBUS_BYTE: if (!(funcs & I2C_FUNC_SMBUS_READ_BYTE)) { fprintf(stderr, MISSING_FUNC_FMT, "SMBus receive byte"); @@ -135,8 +146,8 @@ fprintf(stderr, ", using %s.\n", size == I2C_SMBUS_BYTE ? (daddress < 0 ? "read byte" : "write byte/read byte") : - size == I2C_SMBUS_BYTE_DATA ? "read byte data" : - "read word data"); + (size == I2C_SMBUS_BYTE_DATA || size == I2C_RAW) ? + "read byte data" : "read word data"); if (pec) fprintf(stderr, "PEC checking enabled.\n"); @@ -159,6 +170,7 @@ int pec = 0; int flags = 0; int force = 0, yes = 0, version = 0; + unsigned char buffer[10]; /* handle (optional) flags first */ while (1+flags < argc && argv[1+flags][0] == '-') { @@ -208,6 +220,7 @@ case 'b': size = I2C_SMBUS_BYTE_DATA; break; case 'w': size = I2C_SMBUS_WORD_DATA; break; case 'c': size = I2C_SMBUS_BYTE; break; + case 'r': size = I2C_RAW; break; default: fprintf(stderr, "Error: Invalid mode!\n"); help(); @@ -232,11 +245,14 @@ } switch (size) { + case I2C_RAW: + res = i2c_read_raw(file,buffer,daddress,1); + break; case I2C_SMBUS_BYTE: if (daddress >= 0) { res = i2c_smbus_write_byte(file, daddress); if (res < 0) - fprintf(stderr, "Warning - write failed\n"); + fprintf(stderr, "Warning - write addr failed\n"); } res = i2c_smbus_read_byte(file); break; @@ -253,7 +269,13 @@ exit(2); } - printf("0x%0*x\n", size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); - + switch(size){ + case I2C_RAW: + printf("0x%04x = %02hhx\n", daddress, buffer[0]); + break; + default: + printf("0x%0*x\n", size == I2C_SMBUS_WORD_DATA ? 4 : 2, res); + } + exit(0); } Index: tools/i2cset.c =================================================================== --- tools/i2cset.c (revision 6127) +++ tools/i2cset.c (working copy) @@ -35,6 +35,8 @@ static void help(void) __attribute__ ((noreturn)); +#define I2C_RAW -1 + static void help(void) { fprintf(stderr, @@ -42,6 +44,7 @@ " I2CBUS is an integer or an I2C bus name\n" " ADDRESS is an integer (0x03 - 0x77)\n" " MODE is one of:\n" + " r (write byte using raw i2c device)\n" " c (byte, no value)\n" " b (byte data, default)\n" " w (word data)\n" @@ -63,6 +66,13 @@ } switch (size) { + case I2C_RAW: + //If raw i2c is specified, use that instead of SMBus + if (!(funcs & I2C_FUNC_I2C)){ + fprintf(stderr, MISSING_FUNC_FMT, "Raw I2C"); + return -1; + } + break; case I2C_SMBUS_BYTE: if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) { fprintf(stderr, MISSING_FUNC_FMT, "SMBus send byte"); @@ -140,7 +150,7 @@ } else fprintf(stderr, "data 0x%02x%s, mode %s.\n", value, vmask ? " (masked)" : "", - size == I2C_SMBUS_BYTE_DATA ? "byte" : "word"); + (size == I2C_SMBUS_BYTE_DATA || size == I2C_RAW) ? "byte" : "word"); if (pec) fprintf(stderr, "PEC checking enabled.\n"); @@ -235,6 +245,7 @@ case 'w': size = I2C_SMBUS_WORD_DATA; break; case 's': size = I2C_SMBUS_BLOCK_DATA; break; case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break; + case 'r': size = I2C_RAW; break; default: fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]); help(); @@ -263,6 +274,7 @@ /* read values from command line */ switch (size) { + case I2C_RAW: case I2C_SMBUS_BYTE_DATA: case I2C_SMBUS_WORD_DATA: value = strtol(argv[flags+4], &end, 0); @@ -303,7 +315,7 @@ fprintf(stderr, "Error: Data value mask invalid!\n"); help(); } - if (((size == I2C_SMBUS_BYTE || size == I2C_SMBUS_BYTE_DATA) + if (((size == I2C_SMBUS_BYTE || size == I2C_SMBUS_BYTE_DATA || size == I2C_RAW) && vmask > 0xff) || vmask > 0xffff) { fprintf(stderr, "Error: Data value mask out of range!\n"); help(); @@ -320,10 +332,15 @@ value, vmask, block, len, pec)) exit(0); + //Get the old value if (vmask) { int oldvalue; switch (size) { + case I2C_RAW: + res = i2c_read_raw(file,block,daddress,1); + oldvalue = (unsigned int)block[0]; + break; case I2C_SMBUS_BYTE: oldvalue = i2c_smbus_read_byte(file); break; @@ -366,7 +383,12 @@ exit(1); } + //Do the write switch (size) { + case I2C_RAW: + block[0] = value; + res = i2c_write_raw(file,block,daddress,1); + break; case I2C_SMBUS_BYTE: res = i2c_smbus_write_byte(file, daddress); break; @@ -403,7 +425,11 @@ exit(0); } + //Verify the write switch (size) { + case I2C_RAW: + i2c_read_raw(file,block,daddress,1); + res = (unsigned int)block[0]; case I2C_SMBUS_BYTE: res = i2c_smbus_read_byte(file); value = daddress; --========GMXBoundary164071364908070625525 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hi,

I notice that the lm-sensors i2c-tools don't support 'raw' I2C devic= e file access, instead they rely on the driver supporting the smbus interfa= ce.  I am working on an embedded system that does not have smbus, so I= created a some patches for lm-sensors tools that add a 'r' access method. =   The changes support i2c-get, i2c-put and i2c-dump.

These = changes allow the i2c-tools to be used without smbus support in the kernel = device driver for the I2C inteface.

Would the developers be inte= rested in adding my patch to the distribution?

diff from r6127
regards,
Jason

----
Index: tools/i2cbusses.c=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- tools/i2= cbusses.c    (revision 6127)
+++ tools/i2cbusses.c = ;   (working copy)
@@ -415,3 +415,50 @@
 
&nb= sp;    return 0;
 }
+
+int i2c_read_raw_= again(int file, unsigned char *buffer, unsigned int count)
+{
+&n= bsp;   unsigned char *ptr =3D buffer;
+    in= t res=3D0;
+
+    res =3D read(file, ptr, count);<= br />+    if(res<0)fprintf(stderr, "Aborting - read data = failed (%d) : %s\n",errno,strerror(errno));
+
+   = return res;
+}
+
+int i2c_read_raw(int file, unsigned char = *buffer, int daddress, unsigned int count)
+{
+   = int res;
+    buffer[0] =3D (unsigned char)(daddress&g= t;>8);
+    buffer[1] =3D (unsigned char)daddress &a= mp; 0xFF;
+
+    res =3D write(file, buffer, 2);+    if (res < 0)fprintf(stderr, "Warning - write add= r failed %d : %s\n",errno,strerror(errno));
+   
+=     return i2c_read_raw_again(file,buffer,count);
+}+
+int i2c_write_raw(int file, unsigned char *buffer, int daddress,= unsigned int count)
+{
+    unsigned char *ptr;+    int res;
+    unsigned int n;+   
+    ptr =3D malloc(count+10);<= br />+    if(ptr=3D=3DNULL)
+    {
= +        fprintf(stderr, "Memory allocation e= rror\n");
+        return -1;
+&nbs= p;   }
+    ptr[0] =3D (unsigned char)(daddre= ss>>8);
+    ptr[1] =3D (unsigned char)daddress &= amp; 0xFF;
+    memcpy(ptr+2,buffer,count);
+ = ;   for(n=3D0;n<count+2;n++)fprintf(stderr,"%hhx ",*(ptr+n));<= br />+    fprintf(stderr,"\n");
+    res= =3D write(file,ptr,count+2);
+    if(res<0)fprintf(= stderr, "Warning: write data failed (%d) : %s\n",errno,strerror(errno));+   
+    free(ptr);
+ &nbs= p;  return res;
+}
Index: tools/i2cbusses.h
=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- tools/i2cbusses.h =    (revision 6127)
+++ tools/i2cbusses.h    (= working copy)
@@ -38,7 +38,9 @@
 int parse_i2c_address(const= char *address_arg);
 int open_i2c_dev(int i2cbus, char *filename= , size_t size, int quiet);
 int set_slave_addr(int file, int addr= ess, int force);
-
+int i2c_read_raw(int file, unsigned char *buf= fer, int daddress, unsigned int count);
+int i2c_write_raw(int file, u= nsigned char *buffer, int daddress, unsigned int count);
+int i2c_read= _raw_again(int file, unsigned char *buffer, unsigned int count);
 = ;#define MISSING_FUNC_FMT    "Error: Adapter does not have %= s capability\n"
 
 #endif
Index: tools/i2cdump.c=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- tools/i2= cdump.c    (revision 6127)
+++ tools/i2cdump.c &nb= sp;  (working copy)
@@ -33,6 +33,9 @@
 #include "util.h= "
 #include "../version.h"
 
+
+#define I2C_R= AW -1
+
 static void help(void)
 {
 &nbs= p;   fprintf(stderr,
@@ -46,6 +49,7 @@
  &nbs= p;      "    s (SMBus block)\n"
&nb= sp;        "    i (I2C block)\= n"
         "    c (= consecutive byte)\n"
+        " &nb= sp;  r (i2c raw device)"
       &nb= sp; "    Append p for SMBus PEC\n");
 }
 = ;
@@ -61,6 +65,14 @@
     }
 
=      switch(size) {
+    case I2C_R= AW:
+        //If raw i2c is specified, = use that instead of SMBus
+        if (!= (funcs & I2C_FUNC_I2C)){
+        &n= bsp;   fprintf(stderr, MISSING_FUNC_FMT, "Raw I2C");
+ =            return -1;
+ &= nbsp;      }
+       = ; break;
+   
     case I2C_SM= BUS_BYTE:
         if (!(funcs &= ; I2C_FUNC_SMBUS_READ_BYTE)) {
       &n= bsp;     fprintf(stderr, MISSING_FUNC_FMT, "SMBus receive by= te");
@@ -184,8 +196,10 @@
     } else if (!s= trncmp(argv[flags+3], "c", 1)) {
       =   size =3D I2C_SMBUS_BYTE;
       &= nbsp; pec =3D argv[flags+3][1] =3D=3D 'p';
-    } else = if (!strcmp(argv[flags+3], "i"))
+    } else if (!strcm= p(argv[flags+3], "i")) {
         s= ize =3D I2C_SMBUS_I2C_BLOCK_DATA;
+    } else if (!strc= mp(argv[flags+3], "r"))
+        size = =3D I2C_RAW;
     else {
   &n= bsp;     fprintf(stderr, "Error: Invalid mode!\n");
&nb= sp;        help();
@@ -248,6 +262,7 @@ 
         /* Check mode c= onstraints */
         switch (size= ) {
+        case I2C_RAW:
 &n= bsp;       case I2C_SMBUS_BYTE:
  &= nbsp;      case I2C_SMBUS_BYTE_DATA:
  &= nbsp;          break;
@@ -285,6 +30= 0,7 @@
             = size =3D=3D I2C_SMBUS_BLOCK_DATA ? "smbus block" :
   &= nbsp;         size =3D=3D I2C_SMBUS_I2C_BLOCK= _DATA ? "i2c block" :
         &nbs= p;   size =3D=3D I2C_SMBUS_BYTE ? "byte consecutive read" :
= +            size =3D=3D I2C_R= AW ? "raw I2C consecutive read" :
       = ;      size =3D=3D I2C_SMBUS_BYTE_DATA ? "byte" : "word= ");
         if (pec)
 &n= bsp;           fprintf(stderr, "PEC= checking enabled.\n");
@@ -292,7 +308,9 @@
   &nb= sp;         fprintf(stderr, "Only probing eve= n register "
           &= nbsp;     "addresses.\n");
     &nb= sp;   if (bank) {
-        &nb= sp;   if (size =3D=3D I2C_SMBUS_BLOCK_DATA)
+  &nb= sp;         if (size =3D=3D I2C_RAW)
+&n= bsp;               f= printf(stderr, "With bank offset 0x%04x\n",(bank*256));
+  &= nbsp;         else if (size =3D=3D I2C_SMBUS_= BLOCK_DATA)
           &n= bsp;     fprintf(stderr, "Using command 0x%02x.\n",
&nb= sp;              &nb= sp;     bank);
       &nb= sp;     else
@@ -314,7 +332,7 @@
   = ;  }
 
     /* See Winbond w83781d = data sheet for bank details */
-    if (bank &&= size !=3D I2C_SMBUS_BLOCK_DATA) {
+    if (bank &&= amp; size !=3D I2C_SMBUS_BLOCK_DATA && size !=3D I2C_RAW) {
&n= bsp;        res =3D i2c_smbus_read_byte_data(= file, bankreg);
         if (res &g= t;=3D 0) {
           &nb= sp; old_bank =3D res;
@@ -331,7 +349,7 @@
    = ; if (size !=3D I2C_SMBUS_WORD_DATA || even) {
    = ;     /* do the block transaction */
   =       if (size =3D=3D I2C_SMBUS_BLOCK_DATA
- =         || size =3D=3D I2C_SMBUS_I2C_BLOCK_DA= TA) {
+         || size =3D=3D I2C_= SMBUS_I2C_BLOCK_DATA || size =3D=3D I2C_RAW) {
    = ;         unsigned char cblock[288];
&nb= sp;
             if = (size =3D=3D I2C_SMBUS_BLOCK_DATA) {
@@ -340,6 +358,9 @@
 &n= bsp;               /= * Remember returned block length for a nicer
     =                displ= ay later */
           &n= bsp;     s_length =3D res;
+     &n= bsp;      } else if(size =3D=3D I2C_RAW) {
+ =                res = =3D i2c_read_raw(file, cblock, (bank*256), 256);
+    &= nbsp;           s_length =3D res;             } else {=
              =    for (res =3D 0; res < 256; res +=3D i) {
  &= nbsp;               =    i =3D i2c_smbus_read_i2c_block_data(file,
@@ -359,7 +380,= 7 @@
             &n= bsp;   res =3D 256;
       &nb= sp;     for (i =3D 0; i < res; i++)
  &nbs= p;              block[i] = =3D cblock[i];
-          &nbs= p; if (size !=3D I2C_SMBUS_BLOCK_DATA)
+      = ;      if (size !=3D I2C_SMBUS_BLOCK_DATA && si= ze !=3D I2C_RAW)
          &nb= sp;      for (i =3D res; i < 256; i++)
 &n= bsp;               &= nbsp;   block[i] =3D -1;
      &nbs= p;  }
@@ -372,12 +393,14 @@
      &= nbsp;          exit(1);
  = ;           }
  &nbs= p;      }
-
+      &= nbsp;
         printf("  =    0  1  2  3  4  5  6  7 = ; 8  9  a  b  c  d  e  f"
 &nb= sp;              "&n= bsp;   0123456789abcdef\n");
      =    for (i =3D 0; i < 256; i+=3D16) {
   &n= bsp;         if (size =3D=3D I2C_SMBUS_BLOCK_= DATA && i >=3D s_length)
      &nb= sp;          break;
+  &n= bsp;         if (size =3D=3D I2C_RAW &&am= p; i >=3D s_length)
+         &n= bsp;      break;
      &n= bsp;      if (i/16 < first/16)
  &nbs= p;              continue;=
             if (i/= 16 > last/16)
@@ -400,8 +423,7 @@
     &nb= sp;               bl= ock[i+j] =3D res =3D
          = ;             i2c_smbus_read_b= yte_data(file, i+j);
          = ;       } else if (size =3D=3D I2C_SMBUS_WORD_DATA= ) {
-             &n= bsp;      res =3D i2c_smbus_read_word_data(file,
-=                =                = ;        i+j);
+     = ;               res = =3D i2c_smbus_read_word_data(file, i+j);
     &nbs= p;               if = (res < 0) {
           = ;              block[i+j]= =3D res;
           &nbs= p;             block[i+j+1] = =3D res;
@@ -415,7 +437,7 @@
       = ;          } else
   = ;               &nbs= p;  res =3D block[i+j];
 
-     &nb= sp;          if (size =3D=3D I2C_SMBUS_B= LOCK_DATA
+            &n= bsp;   if ((size =3D=3D I2C_SMBUS_BLOCK_DATA || size =3D=3D I2C_R= AW)
             &nb= sp;    && i+j >=3D s_length) {
  &= nbsp;               =    printf("   ");
      &= nbsp;          } else if (res < 0) {<= br />@@ -433,7 +455,7 @@
         &= nbsp;   printf("   ");
 
  &nb= sp;          for (j =3D 0; j < 16; j+= +) {
-             &= nbsp;  if (size =3D=3D I2C_SMBUS_BLOCK_DATA
+    &= nbsp;           if ((size =3D=3D I2= C_SMBUS_BLOCK_DATA || size =3D=3D I2C_RAW)
     &n= bsp;            && i+j= >=3D s_length)
          &= nbsp;          break;
  &= nbsp;              /* Ski= p unwanted registers */
@@ -483,7 +505,7 @@
   &nb= sp;         printf("\n");
  &n= bsp;      }
     }
- = ;   if (bank && size !=3D I2C_SMBUS_BLOCK_DATA) {
+&= nbsp;   if (bank && size !=3D I2C_SMBUS_BLOCK_DATA &&= amp; size !=3D I2C_RAW) {
         = i2c_smbus_write_byte_data(file, bankreg, old_bank);
   =   }
     exit(0);
Index: tools/i2cget.c<= br />=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- tools/i2= cget.c    (revision 6127)
+++ tools/i2cget.c  = ;  (working copy)
@@ -38,6 +38,8 @@
 
 static= void help(void) __attribute__ ((noreturn));
 
+#define I2C_= RAW -1
+
 static void help(void)
 {
 &nb= sp;   fprintf(stderr,
@@ -45,6 +47,7 @@
  &nb= sp;      "  I2CBUS is an integer or an I2C bus nam= e\n"
         "  ADDRESS is an= integer (0x03 - 0x77)\n"
         = "  MODE is one of:\n"
+        "&nb= sp;   r (read byte using raw i2c device)\n"
  &nbs= p;      "    b (read byte data, default)= \n"
         "    w = (read word data)\n"
         " = ;   c (write byte/read byte)\n"
@@ -52,6 +55,7 @@
 = ;    exit(1);
 }
 
+
 sta= tic int check_funcs(int file, int size, int daddress, int pec)
 {=
     unsigned long funcs;
@@ -62,8 +66,15 @@=
             "funct= ionality matrix: %s\n", strerror(errno));
     &nb= sp;   return -1;
     }
-
+&nb= sp;  
     switch (size) {
+ &= nbsp;  case I2C_RAW:
+        //If = raw i2c is specified, use that instead of SMBus
+    &n= bsp;   if (!(funcs & I2C_FUNC_I2C)){
+   =         fprintf(stderr, MISSING_FUNC_FMT, "R= aw I2C");
+            re= turn -1;
+        }
+  &n= bsp;     break;
     case I2C_SMBUS= _BYTE:
         if (!(funcs & I= 2C_FUNC_SMBUS_READ_BYTE)) {
        = ;     fprintf(stderr, MISSING_FUNC_FMT, "SMBus receive byte"= );
@@ -135,8 +146,8 @@
     fprintf(stderr, "= , using %s.\n",
         size =3D= =3D I2C_SMBUS_BYTE ? (daddress < 0 ?
      = ;   "read byte" : "write byte/read byte") :
-  &nb= sp;     size =3D=3D I2C_SMBUS_BYTE_DATA ? "read byte data" :=
-        "read word data");
+ = ;       (size =3D=3D I2C_SMBUS_BYTE_DATA || size = =3D=3D I2C_RAW) ?
+        "read byte da= ta" : "read word data");
     if (pec)
 =         fprintf(stderr, "PEC checking enabled= .\n");
 
@@ -159,6 +170,7 @@
     i= nt pec =3D 0;
     int flags =3D 0;
 &nb= sp;   int force =3D 0, yes =3D 0, version =3D 0;
+ &nbs= p;  unsigned char buffer[10];
 
    = ; /* handle (optional) flags first */
     while (= 1+flags < argc && argv[1+flags][0] =3D=3D '-') {
@@ -208,6 = +220,7 @@
         case 'b': size = =3D I2C_SMBUS_BYTE_DATA; break;
       &= nbsp; case 'w': size =3D I2C_SMBUS_WORD_DATA; break;
   = ;      case 'c': size =3D I2C_SMBUS_BYTE; break;
+=         case 'r': size =3D I2C_RAW; break;         default:
  &n= bsp;          fprintf(stderr, "Error: In= valid mode!\n");
          &nb= sp;  help();
@@ -232,11 +245,14 @@
     = }
 
     switch (size) {
+ &nb= sp;  case I2C_RAW:
+        res =3D= i2c_read_raw(file,buffer,daddress,1);
+      = ;  break;
     case I2C_SMBUS_BYTE:
&nbs= p;        if (daddress >=3D 0) {
&nbs= p;            res =3D i2c_smbu= s_write_byte(file, daddress);
       &nb= sp;     if (res < 0)
-      = ;          fprintf(stderr, "Warning - wr= ite failed\n");
+          &nb= sp;     fprintf(stderr, "Warning - write addr failed\n");         }
   &nb= sp;     res =3D i2c_smbus_read_byte(file);
  =        break;
@@ -253,7 +269,13 @@
 = ;        exit(2);
   &nbs= p; }
 
-    printf("0x%0*x\n", size =3D=3D I2= C_SMBUS_WORD_DATA ? 4 : 2, res);
-
+    switch(siz= e){
+    case I2C_RAW:
+     &= nbsp;  printf("0x%04x =3D %02hhx\n", daddress, buffer[0]);
+ = ;       break;
+    default:+        printf("0x%0*x\n", size =3D=3D I= 2C_SMBUS_WORD_DATA ? 4 : 2, res);
+    }
+ &n= bsp; 
     exit(0);
 }
Index: = tools/i2cset.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D--- tools/i2cset.c    (revision 6127)
+++ tools/i2cs= et.c    (working copy)
@@ -35,6 +35,8 @@
  static void help(void) __attribute__ ((noreturn));
 
+#define I2C_RAW -1
+
 static void help(void)
 {=
     fprintf(stderr,
@@ -42,6 +44,7 @@
=          "  I2CBUS is an integer or= an I2C bus name\n"
         " = ; ADDRESS is an integer (0x03 - 0x77)\n"
     &nbs= p;   "  MODE is one of:\n"
+     &n= bsp;  "    r (write byte using raw i2c device)\n"
=          "    c (byte, no= value)\n"
         "  &n= bsp; b (byte data, default)\n"
       &n= bsp; "    w (word data)\n"
@@ -63,6 +66,13 @@
&nbs= p;    }
 
     switch (si= ze) {
+    case I2C_RAW:
+     = ;   //If raw i2c is specified, use that instead of SMBus
+&n= bsp;       if (!(funcs & I2C_FUNC_I2C)){
= +            fprintf(stderr, M= ISSING_FUNC_FMT, "Raw I2C");
+        &n= bsp;   return -1;
+        }+        break;
   &n= bsp; case I2C_SMBUS_BYTE:
         = if (!(funcs & I2C_FUNC_SMBUS_WRITE_BYTE)) {
   &nbs= p;         fprintf(stderr, MISSING_FUNC_FMT, = "SMBus send byte");
@@ -140,7 +150,7 @@
     = } else
         fprintf(stderr, "da= ta 0x%02x%s, mode %s.\n", value,
       =       vmask ? " (masked)" : "",
-   = ;         size =3D=3D I2C_SMBUS_BYTE_DATA ? "= byte" : "word");
+          &n= bsp; (size =3D=3D I2C_SMBUS_BYTE_DATA || size =3D=3D I2C_RAW) ? "byte" : "w= ord");
     if (pec)
    =     fprintf(stderr, "PEC checking enabled.\n");
 =
@@ -235,6 +245,7 @@
         = case 'w': size =3D I2C_SMBUS_WORD_DATA; break;
    = ;     case 's': size =3D I2C_SMBUS_BLOCK_DATA; break;
&= nbsp;        case 'i': size =3D I2C_SMBUS_I2C= _BLOCK_DATA; break;
+        case 'r': s= ize =3D I2C_RAW; break;
         de= fault:
             = fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]);
 &n= bsp;           help();
@@ -263= ,6 +274,7 @@
 
     /* read values from = command line */
     switch (size) {
+ &= nbsp;  case I2C_RAW:
     case I2C_SMBUS_BYTE= _DATA:
     case I2C_SMBUS_WORD_DATA:
 &= nbsp;       value =3D strtol(argv[flags+4], &e= nd, 0);
@@ -303,7 +315,7 @@
       =       fprintf(stderr, "Error: Data value mask invalid!\= n");
             he= lp();
         }
-  =       if (((size =3D=3D I2C_SMBUS_BYTE || size =3D=3D I= 2C_SMBUS_BYTE_DATA)
+        if (((size = =3D=3D I2C_SMBUS_BYTE || size =3D=3D I2C_SMBUS_BYTE_DATA || size =3D=3D I2C= _RAW)
            &n= bsp; && vmask > 0xff) || vmask > 0xffff) {
  &= nbsp;          fprintf(stderr, "Error: D= ata value mask out of range!\n");
       = ;      help();
@@ -320,10 +332,15 @@
 &n= bsp;              &n= bsp; value, vmask, block, len, pec))
      &n= bsp;  exit(0);
 
+    //Get the old valu= e
     if (vmask) {
     =     int oldvalue;
 
     =     switch (size) {
+      &nb= sp; case I2C_RAW:
+          &= nbsp; res =3D i2c_read_raw(file,block,daddress,1);
+   =         oldvalue =3D (unsigned int)block[0];=
+        break;
   =       case I2C_SMBUS_BYTE:
    = ;         oldvalue =3D i2c_smbus_read_byte(fi= le);
             br= eak;
@@ -366,7 +383,12 @@
       &n= bsp; exit(1);
     }
 
+  = ;  //Do the write
     switch (size) {
+=     case I2C_RAW:
+       = ; block[0] =3D value;
+        res =3D i= 2c_write_raw(file,block,daddress,1);
+      &= nbsp; break;
     case I2C_SMBUS_BYTE:
 =         res =3D i2c_smbus_write_byte(file, da= ddress);
         break;
@@ -4= 03,7 +425,11 @@
         exit(0);     }
 
+    //Verif= y the write
     switch (size) {
+  = ;  case I2C_RAW:
+        i2c_read_= raw(file,block,daddress,1);
+        res= =3D (unsigned int)block[0];
     case I2C_SMBUS_B= YTE:
         res =3D i2c_smbus_rea= d_byte(file);
         value =3D da= ddress;
=C2=A0
--========GMXBoundary164071364908070625525-- --===============8588452095159277838== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ lm-sensors mailing list lm-sensors@lm-sensors.org http://lists.lm-sensors.org/mailman/listinfo/lm-sensors --===============8588452095159277838==--