i2c update to 2.6.0 for 2.4.7

i2c update to 2.6.0 for 2.4.7

Post by J . A . Magallo » Thu, 26 Jul 2001 09:50:09



Hi.

This patch updates i2c support in kernel to 2.6.0. I have corrected original patch
to use slab.h instead of malloc.h, a couple #endif's, and Comfigure.help references
to other docs in <file:...> format.

It was done on 2.4.6-ac5, but should apply on 2.4.7. Only problem is those
document references in <file:.......> format, that are not suitable for plain 2.4.7.

BTW, is there any chance to include lm_sensors also in mainstream kernel ?

TIA

--- linux-old/Documentation/i2c/writing-clients Mon Jul 23 01:39:46 CEST 2001
+++ linux/Documentation/i2c/writing-clients     Mon Jul 23 01:39:46 CEST 2001
@@ -34,5 +34,5 @@
     /* command        */  &foo_command,   /* May be NULL */
     /* inc_use        */  &foo_inc_use,   /* May be NULL */
-    /* dec_use        */  &foo_dev_use    /* May be NULL */
+    /* dec_use        */  &foo_dec_use    /* May be NULL */
   }

--- linux-old/drivers/i2c/i2c-algo-bit.c        Mon Jul 23 01:39:47 CEST 2001
+++ linux/drivers/i2c/i2c-algo-bit.c    Mon Jul 23 01:39:47 CEST 2001
@@ -22,5 +22,5 @@
    Frodo Looijaard <fro...@dds.nl> */

-/* $Id: i2c-algo-bit.c,v 1.27 2000/07/09 15:16:16 frodo Exp $ */
+/* $Id: i2c-algo-bit.c,v 1.29 2001/04/03 02:44:02 mds Exp $ */

 #include <linux/kernel.h>
--- linux-old/drivers/i2c/i2c-algo-pcf.c        Mon Jul 23 01:39:48 CEST 2001
+++ linux/drivers/i2c/i2c-algo-pcf.c    Mon Jul 23 01:39:48 CEST 2001
@@ -1,3 +1,2 @@
-
 /* ------------------------------------------------------------------------- */
 /* i2c-algo-pcf.c i2c driver algorithms for PCF8584 adapters                */
@@ -25,5 +24,7 @@
    <mbai...@littlefeet-inc.com> */

-/* $Id: i2c-algo-pcf.c,v 1.25 2000/11/10 13:43:32 frodo Exp $ */
+/* Partially rewriten by Oleg I. Vdovikin <vdovi...@jscc.ru> to handle multiple
+   messages, proper stop/repstart signaling during receive,
+   added detect code */

 #include <linux/kernel.h>
@@ -50,24 +51,7 @@
 #define DEF_TIMEOUT 16

-/* debugging - slow down transfer to have a look at the data ..        */
-/* I use this with two leds&resistors, each one connected to sda,scl       */
-/* respectively. This makes sure that the algorithm works. Some chips   */
-/* might not like this, as they have an internal timeout of some mils  */
-/*
-#define SLO_IO      jif=jiffies;while(jiffies<=jif+i2c_table[minor].veryslow)\
-                        if (need_resched) schedule();
-*/
-
-
-/* ----- global variables ---------------------------------------------        */
-
-#ifdef SLO_IO
-       int jif;
-#endif
-
 /* module parameters:
  */
-static int i2c_debug=1;
-static int pcf_test=0; /* see if the line-setting functions work       */
+static int i2c_debug=0;
 static int pcf_scan=0; /* have a look at what's hanging 'round         */

@@ -81,5 +65,4 @@
 #define i2c_inb(adap) adap->getpcf(adap->data, 0)

-
 /* --- other auxiliary functions --------------------------------------        */

@@ -112,14 +95,13 @@
 #ifndef STUB_I2C
        while (timeout-- && !(status & I2C_PCF_BB)) {
-               udelay(1000); /* How much is this? */
+               udelay(100); /* wait for 100 us */
                status = get_pcf(adap, 1);
        }
 #endif
-       if (timeout<=0)
+       if (timeout <= 0) {
                printk("Timeout waiting for Bus Busy\n");
-       /*
-       set_pcf(adap, 1, I2C_PCF_STOP);
-       */
-       return(timeout<=0);
+       }
+      
+       return (timeout<=0);
 }

@@ -148,5 +130,4 @@
 }

-
 /*
  * This should perform the 'PCF8584 initialization sequence' as described
@@ -157,109 +138,62 @@
  * to synchronize the BB-bit (in multimaster systems). How long is
  * this? I assume 1 second is always long enough.
+ *
+ * vdovikin: added detect code for PCF8584
  */
 static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
 {
+       unsigned char temp;
+
+       DEB3(printk("i2c-algo-pcf.o: PCF state 0x%02x\n", get_pcf(adap, 1)));

-       /* S1=0x80: S0 selected, serial interface off                   */
+       /* S1=0x80: S0 selected, serial interface off */
        set_pcf(adap, 1, I2C_PCF_PIN);
+       /* check to see S1 now used as R/W ctrl -
+          PCF8584 does that when ESO is zero */
+       /* PCF also resets PIN bit */
+       if ((temp = get_pcf(adap, 1)) != (0)) {
+               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S0 (0x%02x).\n", temp));
+               return -ENXIO; /* definetly not PCF8584 */
+       }

        /* load own address in S0, effective address is (own << 1)        */
        i2c_outb(adap, get_own(adap));
+       /* check it's realy writen */
+       if ((temp = i2c_inb(adap)) != get_own(adap)) {
+               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
+               return -ENXIO;
+       }

        /* S1=0xA0, next byte in S2                                     */
        set_pcf(adap, 1, I2C_PCF_PIN | I2C_PCF_ES1);
+       /* check to see S2 now selected */
+       if ((temp = get_pcf(adap, 1)) != I2C_PCF_ES1) {
+               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S2 (0x%02x).\n", temp));
+               return -ENXIO;
+       }

        /* load clock register S2                                       */
        i2c_outb(adap, get_clock(adap));
+       /* check it's realy writen, the only 5 lowest bits does matter */
+       if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
+               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
+               return -ENXIO;
+       }

        /* Enable serial interface, idle, S0 selected                   */
        set_pcf(adap, 1, I2C_PCF_IDLE);

-       DEB2(printk("i2c-algo-pcf.o: irq: Initialized 8584.\n"));
-       return 0;
-}
-
-
-/*
- * Sanity check for the adapter hardware - check the reaction of
- * the bus lines only if it seems to be idle.
- */
-static int test_bus(struct i2c_algo_pcf_data *adap, char *name) {
-#if 0
-       int scl,sda;
-       sda=getsda(adap);
-       if (adap->getscl==NULL) {
-               printk("i2c-algo-pcf.o: Warning: Adapter can't read from clock line - skipping test.\n");
-               return 0;              
-       }
-       scl=getscl(adap);
-       printk("i2c-algo-pcf.o: Adapter: %s scl: %d  sda: %d -- testing...\n",
-       name,getscl(adap),getsda(adap));
-       if (!scl || !sda ) {
-               printk("i2c-algo-pcf.o: %s seems to be busy.\n",adap->name);
-               goto bailout;
-       }
-       sdalo(adap);
-       printk("i2c-algo-pcf.o:1 scl: %d  sda: %d \n",getscl(adap),
-              getsda(adap));
-       if ( 0 != getsda(adap) ) {
-               printk("i2c-algo-pcf.o: %s SDA stuck high!\n",name);
-               sdahi(adap);
-               goto bailout;
-       }
-       if ( 0 == getscl(adap) ) {
-               printk("i2c-algo-pcf.o: %s SCL unexpected low while pulling SDA low!\n",
-                       name);
-               goto bailout;
-       }              
-       sdahi(adap);
-       printk("i2c-algo-pcf.o:2 scl: %d  sda: %d \n",getscl(adap),
-              getsda(adap));
-       if ( 0 == getsda(adap) ) {
-               printk("i2c-algo-pcf.o: %s SDA stuck low!\n",name);
-               sdahi(adap);
-               goto bailout;
-       }
-       if ( 0 == getscl(adap) ) {
-               printk("i2c-algo-pcf.o: %s SCL unexpected low while SDA high!\n",
-                      adap->name);
-       goto bailout;
-       }
-       scllo(adap);
-       printk("i2c-algo-pcf.o:3 scl: %d  sda: %d \n",getscl(adap),
-              getsda(adap));
-       if ( 0 != getscl(adap) ) {
-               printk("i2c-algo-pcf.o: %s SCL stuck high!\n",name);
-               sclhi(adap);
-               goto bailout;
-       }
-       if ( 0 == getsda(adap) ) {
-               printk("i2c-algo-pcf.o: %s SDA unexpected low while pulling SCL low!\n",
-                       name);
-               goto bailout;
-       }
-       sclhi(adap);
-       printk("i2c-algo-pcf.o:4 scl: %d  sda: %d \n",getscl(adap),
-              getsda(adap));
-       if ( 0 == getscl(adap) ) {
-               printk("i2c-algo-pcf.o: %s SCL stuck low!\n",name);
-               sclhi(adap);
-               goto bailout;
-       }
-       if ( 0 == getsda(adap) ) {
-               printk("i2c-algo-pcf.o: %s SDA unexpected low while SCL high!\n",
-                       name);
-               goto bailout;
+       /* check to see PCF is realy idled and we can access status register */
+       if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
+               DEB2(printk("i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
+               return -ENXIO;
        }
-       printk("i2c-algo-pcf.o: %s passed test.\n",name);
+      
+       printk("i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
+
        return 0;
-bailout:
-       sdahi(adap);
-       sclhi(adap);
-       return -ENODEV;
-#endif
-       return (0);
 }

+
 /* ----- Utility functions
  */
@@ -288,6 +222,6 @@

-static int pcf_sendbytes(struct i2c_adapter *i2c_adap,const char *buf,
-                         int count)
+static int pcf_sendbytes(struct i2c_adapter *i2c_adap, const char *buf,
+                         int count, int last)
 {
        struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
@@ -300,5 +234,5 @@
                timeout = wait_for_pin(adap, &status);
                if (timeout) {
-                       i2c_stop(adap);
+                       i2c_stop(adap);
                        printk("i2c-algo-pcf.o: %s i2c_write: "
                               "error - timeout.\n", i2c_adap->name);
@@ -307,5 +241,5 @@
 #ifndef STUB_I2C
                if (status & I2C_PCF_LRB) {
-                       i2c_stop(adap);
+                       i2c_stop(adap);
                        printk("i2c-algo-pcf.o: %s i2c_write: "
                               "error - no ack.\n", i2c_adap->name);
@@ -314,56 +248,57 @@
 #endif
        }
-       i2c_stop(adap);
+       if (last) {
+               i2c_stop(adap);
+       }
+       else {
+               i2c_repstart(adap);
+       }
+
        return (wrcount);
 }

-static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf, int count)
+static int pcf_readbytes(struct i2c_adapter *i2c_adap, char *buf,
+                         int count, int last)
 {
-       int rdcount=0, i, status, timeout, dummy=1;
+       int i, status;
        struct i2c_algo_pcf_data *adap = i2c_adap->algo_data;
-    
-       for (i=0; i<count; ++i) {
-               buf[rdcount] = i2c_inb(adap);
-               if (dummy) {
-                       dummy = 0;
-               } else {
-                       rdcount++;
-               }
-               timeout = wait_for_pin(adap, &status);
-               if (timeout) {
-                       i2c_stop(adap);
-                       printk("i2c-algo-pcf.o: i2c_read: "
-                              "i2c_inb timed out.\n");
+
+       /* increment number of bytes to read by one -- read dummy byte */
+       for (i = 0; i <= count; i++) {
+
+               if (wait_for_pin(adap, &status)) {
+                       i2c_stop(adap);
+                       printk("i2c-algo-pcf.o: pcf_readbytes timed out.\n");
                        return (-1);
                }
+
 #ifndef STUB_I2C
-               if (status & I2C_PCF_LRB) {
-                       i2c_stop(adap);
+               if ((status & I2C_PCF_LRB) && (i != count)) {
+                       i2c_stop(adap);
                        printk("i2c-algo-pcf.o: i2c_read: i2c_inb, No ack.\n");
                        return (-1);
                }
 #endif
-       }
-       set_pcf(adap, 1, I2C_PCF_ESO);
-       buf[rdcount] = i2c_inb(adap);
-       if (dummy) {
-               dummy = 0;
-       } else {
-               rdcount++;
-       }
-       timeout = wait_for_pin(adap, &status);
-       if (timeout) {
-               i2c_stop(adap);
-               printk("i2c-algo-pcf.o: i2c_read: i2c_inb timed out.\n");
-               return (-1);
-       }
-    
- ...

read more »

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by Steven Walte » Thu, 26 Jul 2001 10:10:08



Quote:> BTW, is there any chance to include lm_sensors also in mainstream kernel ?

This is something that I would really like to see.  I've been using the
lm_sensors patch on several kernels on at least two different types of
hardware with no problems whatsoever.

If there's no technical reason to keep it out, I think this would be a
good candidate for integration.
--
-Steven
In a time of universal deceit, telling the truth is a revolutionary act.
                        -- George Orwell
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by Tom Rin » Thu, 26 Jul 2001 11:40:06



Quote:> Hi.

> This patch updates i2c support in kernel to 2.6.0. I have corrected original patch
> to use slab.h instead of malloc.h, a couple #endif's, and Comfigure.help references
> to other docs in <file:...> format.

It appears to be missing new files.  The rpx and 405 bits aren't all there.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by J . A . Magallo » Thu, 26 Jul 2001 19:10:06




>> Hi.

>> This patch updates i2c support in kernel to 2.6.0. I have corrected original patch
>> to use slab.h instead of malloc.h, a couple #endif's, and Comfigure.help references
>> to other docs in <file:...> format.

>It appears to be missing new files.  The rpx and 405 bits aren't all there.

Correct, the original patch generator skips them, both in 2.6.0 and latest cvs.
Why ?
Will redo the patch...

--
J.A. Magallon                           #  Let the source be with you...        

Mandrake Linux release 8.1 (Cooker) for i586
Linux werewolf 2.4.7 #1 SMP Mon Jul 23 01:55:36 CEST 2001 i686
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by AndrĂ© Dahlqvis » Thu, 26 Jul 2001 19:40:06



Quote:> Correct, the original patch generator skips them, both in 2.6.0 and latest cvs.
> Why ?

Did you perhaps forget the  --new-file flag to diff?
--


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by Alan Co » Thu, 26 Jul 2001 22:40:08


Quote:> It was done on 2.4.6-ac5, but should apply on 2.4.7. Only problem is those
> document references in <file:.......> format, that are not suitable for plain 2.4.7.

I sent Linus the <file: > fixes so they should be in 2.4.7

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by J . A . Magallo » Fri, 27 Jul 2001 07:00:10



Quote:>> It was done on 2.4.6-ac5, but should apply on 2.4.7. Only problem is those
>> document references in <file:.......> format, that are not suitable for plain 2.4.7.

>I sent Linus the <file: > fixes so they should be in 2.4.7

In Documentation/Condigure.help in my tree (incrmentally patched without errors
since 2.4.0), the only references
to Documentation/* in <file: > shape are in CONFIG_USB_CATC and CONFIG_NTFS_FS.
The rest are plain Doc/* refs.

--
J.A. Magallon                           #  Let the source be with you...        

Mandrake Linux release 8.1 (Cooker) for i586
Linux werewolf 2.4.7 #1 SMP Mon Jul 23 01:55:36 CEST 2001 i686
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by J . A . Magallo » Fri, 27 Jul 2001 08:30:08





>>> Hi.

>>> This patch updates i2c support in kernel to 2.6.0. I have corrected original patch
>>> to use slab.h instead of malloc.h, a couple #endif's, and Comfigure.help references
>>> to other docs in <file:...> format.

>>It appears to be missing new files.  The rpx and 405 bits aren't all there.

>Correct, the original patch generator skips them, both in 2.6.0 and latest cvs.
>Why ?
>Will redo the patch...

I have been looking at that part, and seems like pretty half-done, even buggy.
Can't you live without it ?

For example, in mkpatch/Config.in:

   if [ "$CONFIG_8xx" = "y" ]; then
<well, there is a 8xx cpu variable in arch/ppc>
...
   if [ "$CONFIG_405" = "y" ]; then
<I found no _405, should not it be _4xx ?>
      dep_tristate 'PPC 405 I2C Algorithm' CONFIG_I2C_PPC405_ALGO $CONFIG_I2C
                               look at this ^^^^^^^^^^^^^^^^^^^^
      if [ "CONFIG_PPC405_I2C_ALGO" != "n" ]; then
     <vs this ^^^^^^^^^^^^^^^^^^^^ >
         dep_tristate '  PPC 405 I2C Adapter' CONFIG_I2C_PPC405_ADAP $CONFIG_I2C
_PPC405_ALGO

I would not trust that part still.

BTW, I sent the patches about slab/malloc to the mantainer time ago, and cvs
still uses malloc.

--
J.A. Magallon                           #  Let the source be with you...        

Mandrake Linux release 8.1 (Cooker) for i586
Linux werewolf 2.4.7 #1 SMP Mon Jul 23 01:55:36 CEST 2001 i686
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

 
 
 

i2c update to 2.6.0 for 2.4.7

Post by Tom Rin » Fri, 27 Jul 2001 08:40:06






> >>> Hi.

> >>> This patch updates i2c support in kernel to 2.6.0. I have corrected original patch
> >>> to use slab.h instead of malloc.h, a couple #endif's, and Comfigure.help references
> >>> to other docs in <file:...> format.

> >>It appears to be missing new files.  The rpx and 405 bits aren't all there.

> >Correct, the original patch generator skips them, both in 2.6.0 and latest cvs.
> >Why ?
> >Will redo the patch...

> I have been looking at that part, and seems like pretty half-done, even buggy.
> Can't you live without it ?

The code actually works well, it just depends on other things which aren't yet
in Linus' tree but should be soon.  There might be typos however.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/