patch-2.4.22 linux-2.4.22/arch/cris/drivers/i2c.c
Next file: linux-2.4.22/arch/cris/drivers/i2c.h
Previous file: linux-2.4.22/arch/cris/drivers/gpio.c
Back to the patch index
Back to the overall index
- Lines: 151
- Date:
2003-08-25 04:44:39.000000000 -0700
- Orig file:
linux-2.4.21/arch/cris/drivers/i2c.c
- Orig date:
2003-06-13 07:51:29.000000000 -0700
diff -urN linux-2.4.21/arch/cris/drivers/i2c.c linux-2.4.22/arch/cris/drivers/i2c.c
@@ -11,7 +11,26 @@
*! Jan 14 2000 Johan Adolfsson Fixed PB shadow register stuff -
*! don't use PB_I2C if DS1302 uses same bits,
*! use PB.
+*| June 23 2003 Pieter Grimmerink Added 'i2c_sendnack'. i2c_readreg now
+*| generates nack on last received byte,
+*| instead of ack.
+*| i2c_getack changed data level while clock
+*| was high, causing DS75 to see a stop condition
+*|
*! $Log: i2c.c,v $
+*! Revision 1.12 2003/06/23 14:43:47 oskarp
+*! * i2c_sendnack is added.
+*! - i2c_readreg now generates nack on last received byte, instead of ack.
+*! i2c_getack changed data level while clock was high, causing DS75 to
+*! see a stop condition.
+*!
+*! Revision 1.11 2003/05/23 09:37:23 oskarp
+*! * Made i2c_init() visible.
+*! - e.g. pcf856.c uses i2c_init().
+*!
+*! Revision 1.10 2003/04/01 14:12:06 starvik
+*! Added loglevel for lots of printks
+*!
*! Revision 1.9 2002/10/31 15:32:26 starvik
*! Update Port B register and shadow even when running with hardware support
*! to avoid glitches when reading bits
@@ -53,7 +72,7 @@
*! (C) Copyright 1999-2002 Axis Communications AB, LUND, SWEDEN
*!
*!***************************************************************************/
-/* $Id: i2c.c,v 1.9 2002/10/31 15:32:26 starvik Exp $ */
+/* $Id: i2c.c,v 1.12 2003/06/23 14:43:47 oskarp Exp $ */
/****************** INCLUDE FILES SECTION ***********************************/
#include <linux/module.h>
@@ -133,7 +152,7 @@
#define i2c_getbit() (((*R_PORT_PB_READ & (1 << SDABIT))) >> SDABIT)
-#else
+#else /* !CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C */
/* enable or disable the i2c interface */
#define i2c_enable() *R_PORT_PB_I2C = (port_pb_i2c_shadow |= IO_MASK(R_PORT_PB_I2C, i2c_en))
@@ -163,7 +182,8 @@
/* read a bit from the i2c interface */
#define i2c_getbit() (*R_PORT_PB_READ & 0x1)
-#endif
+
+#endif /* CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C */
/* use the kernels delay routine */
@@ -299,6 +319,12 @@
}
i2c_clk(I2C_CLOCK_HIGH);
i2c_delay(CLOCK_HIGH_TIME);
+
+ /*
+ * we leave the clock low, getbyte is usually followed
+ * by sendack/nack, they assume the clock to be low
+ */
+ i2c_clk(I2C_CLOCK_LOW);
return aBitByte;
}
@@ -360,6 +386,13 @@
i2c_delay(CLOCK_HIGH_TIME/2);
}
+ /*
+ * our clock is high now, make sure data is low
+ * before we enable our output. If we keep data high
+ * and enable output, we would generate a stop condition.
+ */
+ i2c_data(I2C_DATA_LOW);
+
/*
* end clock pulse
*/
@@ -417,6 +450,37 @@
/*#---------------------------------------------------------------------------
*#
+*# FUNCTION NAME: i2c_sendnack
+*#
+*# DESCRIPTION : Sends NACK on received data
+*#
+*#--------------------------------------------------------------------------*/
+void
+i2c_sendnack(void)
+{
+ /*
+ * enable output
+ */
+ i2c_delay(CLOCK_LOW_TIME);
+ i2c_dir_out();
+ /*
+ * set data high
+ */
+ i2c_data(I2C_DATA_HIGH);
+ /*
+ * generate clock pulse
+ */
+ i2c_delay(CLOCK_HIGH_TIME/6);
+ i2c_clk(I2C_CLOCK_HIGH);
+ i2c_delay(CLOCK_HIGH_TIME);
+ i2c_clk(I2C_CLOCK_LOW);
+ i2c_delay(CLOCK_LOW_TIME);
+
+ i2c_dir_in();
+}
+
+/*#---------------------------------------------------------------------------
+*#
*# FUNCTION NAME: i2c_writereg
*#
*# DESCRIPTION : Writes a value to an I2C device
@@ -546,9 +610,10 @@
*/
b = i2c_inbyte();
/*
- * send Ack
+ * last received byte needs to be nacked
+ * instead of acked
*/
- i2c_sendack();
+ i2c_sendnack();
/*
* end sequence
*/
@@ -623,7 +688,7 @@
release: i2c_release,
};
-static int __init
+int __init
i2c_init(void)
{
int res;
@@ -653,7 +718,7 @@
return res;
}
- printk("I2C driver v2.2, (c) 1999-2001 Axis Communications AB\n");
+ printk(KERN_INFO "I2C driver v2.2, (c) 1999-2001 Axis Communications AB\n");
return 0;
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)