aboutsummaryrefslogtreecommitdiff
path: root/arch/cris/arch-v10/drivers/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/cris/arch-v10/drivers/i2c.c')
-rw-r--r--arch/cris/arch-v10/drivers/i2c.c128
1 files changed, 24 insertions, 104 deletions
diff --git a/arch/cris/arch-v10/drivers/i2c.c b/arch/cris/arch-v10/drivers/i2c.c
index b38267d60d3..b3d1f9ed1b9 100644
--- a/arch/cris/arch-v10/drivers/i2c.c
+++ b/arch/cris/arch-v10/drivers/i2c.c
@@ -6,105 +6,26 @@
*! kernel modules (i2c_writereg/readreg) and from userspace using
*! ioctl()'s
*!
-*! Nov 30 1998 Torbjorn Eliasson Initial version.
-*! Bjorn Wesen Elinux kernel version.
-*! Jan 14 2000 Johan Adolfsson Fixed PB shadow register stuff -
-*! don't use PB_I2C if DS1302 uses same bits,
-*! use PB.
-*! $Log: i2c.c,v $
-*! Revision 1.13 2005/03/07 13:13:07 starvik
-*! Added spinlocks to protect states etc
-*!
-*! Revision 1.12 2005/01/05 06:11:22 starvik
-*! No need to do local_irq_disable after local_irq_save.
-*!
-*! Revision 1.11 2004/12/13 12:21:52 starvik
-*! Added I/O and DMA allocators from Linux 2.4
-*!
-*! Revision 1.9 2004/08/24 06:49:14 starvik
-*! Whitespace cleanup
-*!
-*! Revision 1.8 2004/06/08 08:48:26 starvik
-*! Removed unused code
-*!
-*! Revision 1.7 2004/05/28 09:26:59 starvik
-*! Modified I2C initialization to work in 2.6.
-*!
-*! Revision 1.6 2004/05/14 07:58:03 starvik
-*! Merge of changes from 2.4
-*!
-*! Revision 1.4 2002/12/11 13:13:57 starvik
-*! Added arch/ to v10 specific includes
-*! Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer)
-*!
-*! Revision 1.3 2002/11/20 11:56:11 starvik
-*! Merge of Linux 2.5.48
-*!
-*! Revision 1.2 2002/11/18 13:16:06 starvik
-*! Linux 2.5 port of latest 2.4 drivers
-*!
-*! 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
-*! Never set direction to out in i2c_inbyte
-*! Removed incorrect clock togling at end of i2c_inbyte
-*!
-*! Revision 1.8 2002/08/13 06:31:53 starvik
-*! Made SDA and SCL line configurable
-*! Modified i2c_inbyte to work with PCF8563
-*!
-*! Revision 1.7 2001/04/04 13:11:36 markusl
-*! Updated according to review remarks
-*!
-*! Revision 1.6 2001/03/19 12:43:00 markusl
-*! Made some symbols unstatic (used by the eeprom driver)
-*!
-*! Revision 1.5 2001/02/27 13:52:48 bjornw
-*! malloc.h -> slab.h
-*!
-*! Revision 1.4 2001/02/15 07:17:40 starvik
-*! Corrected usage if port_pb_i2c_shadow
-*!
-*! Revision 1.3 2001/01/26 17:55:13 bjornw
-*! * Made I2C_USES_PB_NOT_PB_I2C a CONFIG option instead of assigning it
-*! magically. Config.in needs to set it for the options that need it, like
-*! Dallas 1302 support. Actually, it should be default since it screws up
-*! the PB bits even if you don't use I2C..
-*! * Include linux/config.h to get the above
-*!
-*! Revision 1.2 2001/01/18 15:49:30 bjornw
-*! 2.4 port of I2C including some cleanups (untested of course)
-*!
-*! Revision 1.1 2001/01/18 15:35:25 bjornw
-*! Verbatim copy of the Etrax i2c driver, 2.0 elinux version
-*!
-*!
-*! ---------------------------------------------------------------------------
-*!
-*! (C) Copyright 1999-2002 Axis Communications AB, LUND, SWEDEN
+*! (C) Copyright 1999-2007 Axis Communications AB, LUND, SWEDEN
*!
*!***************************************************************************/
-/* $Id: i2c.c,v 1.13 2005/03/07 13:13:07 starvik Exp $ */
/****************** INCLUDE FILES SECTION ***********************************/
#include <linux/module.h>
#include <linux/sched.h>
-#include <linux/slab.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/string.h>
#include <linux/init.h>
-#include <linux/config.h>
#include <asm/etraxi2c.h>
-#include <asm/system.h>
-#include <asm/arch/svinto.h>
+#include <arch/svinto.h>
#include <asm/io.h>
#include <asm/delay.h>
-#include <asm/arch/io_interface_mux.h>
+#include <arch/io_interface_mux.h>
#include "i2c.h"
@@ -137,8 +58,8 @@ static const char i2c_name[] = "i2c";
#define SDABIT CONFIG_ETRAX_I2C_DATA_PORT
#define SCLBIT CONFIG_ETRAX_I2C_CLK_PORT
-#define i2c_enable()
-#define i2c_disable()
+#define i2c_enable()
+#define i2c_disable()
/* enable or disable output-enable, to select output or input on the i2c bus */
@@ -168,7 +89,7 @@ static const char i2c_name[] = "i2c";
#define i2c_dir_out() \
*R_PORT_PB_I2C = (port_pb_i2c_shadow &= ~IO_MASK(R_PORT_PB_I2C, i2c_oe_)); \
- REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, 0, 1);
+ REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, 0, 1);
#define i2c_dir_in() \
*R_PORT_PB_I2C = (port_pb_i2c_shadow |= IO_MASK(R_PORT_PB_I2C, i2c_oe_)); \
REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, 0, 0);
@@ -266,7 +187,7 @@ i2c_outbyte(unsigned char x)
} else {
i2c_data(I2C_DATA_LOW);
}
-
+
i2c_delay(CLOCK_LOW_TIME/2);
i2c_clk(I2C_CLOCK_HIGH);
i2c_delay(CLOCK_HIGH_TIME);
@@ -493,7 +414,7 @@ i2c_sendnack(void)
*#
*#--------------------------------------------------------------------------*/
int
-i2c_writereg(unsigned char theSlave, unsigned char theReg,
+i2c_writereg(unsigned char theSlave, unsigned char theReg,
unsigned char theValue)
{
int error, cntr = 3;
@@ -545,7 +466,7 @@ i2c_writereg(unsigned char theSlave, unsigned char theReg,
* enable interrupt again
*/
local_irq_restore(flags);
-
+
} while(error && cntr--);
i2c_delay(CLOCK_LOW_TIME);
@@ -581,7 +502,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
* generate start condition
*/
i2c_start();
-
+
/*
* send slave address
*/
@@ -623,7 +544,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
* last received byte needs to be nacked
* instead of acked
*/
- i2c_sendack();
+ i2c_sendnack();
/*
* end sequence
*/
@@ -632,7 +553,7 @@ i2c_readreg(unsigned char theSlave, unsigned char theReg)
* enable interrupt again
*/
local_irq_restore(flags);
-
+
} while(error && cntr--);
spin_unlock(&i2c_lock);
@@ -655,9 +576,7 @@ i2c_release(struct inode *inode, struct file *filp)
/* Main device API. ioctl's to write or read to/from i2c registers.
*/
-static int
-i2c_ioctl(struct inode *inode, struct file *file,
- unsigned int cmd, unsigned long arg)
+static long i2c_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
if(_IOC_TYPE(cmd) != ETRAXI2C_IOCTYPE) {
return -EINVAL;
@@ -666,7 +585,7 @@ i2c_ioctl(struct inode *inode, struct file *file,
switch (_IOC_NR(cmd)) {
case I2C_WRITEREG:
/* write to an i2c slave */
- D(printk("i2cw %d %d %d\n",
+ D(printk(KERN_DEBUG "i2cw %d %d %d\n",
I2C_ARGSLAVE(arg),
I2C_ARGREG(arg),
I2C_ARGVALUE(arg)));
@@ -678,26 +597,26 @@ i2c_ioctl(struct inode *inode, struct file *file,
{
unsigned char val;
/* read from an i2c slave */
- D(printk("i2cr %d %d ",
+ D(printk(KERN_DEBUG "i2cr %d %d ",
I2C_ARGSLAVE(arg),
I2C_ARGREG(arg)));
val = i2c_readreg(I2C_ARGSLAVE(arg), I2C_ARGREG(arg));
- D(printk("= %d\n", val));
+ D(printk(KERN_DEBUG "= %d\n", val));
return val;
- }
+ }
default:
return -EINVAL;
}
-
return 0;
}
-static struct file_operations i2c_fops = {
- .owner = THIS_MODULE,
- .ioctl = i2c_ioctl,
- .open = i2c_open,
- .release = i2c_release,
+static const struct file_operations i2c_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = i2c_ioctl,
+ .open = i2c_open,
+ .release = i2c_release,
+ .llseek = noop_llseek,
};
int __init
@@ -709,6 +628,7 @@ i2c_init(void)
if (!first) {
return res;
}
+ first = 0;
/* Setup and enable the Port B I2C interface */