15 #include <linux/module.h>
16 #include <linux/sched.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
20 #include <linux/string.h>
27 #include <asm/delay.h>
37 static const char i2c_name[] =
"i2c";
39 #define CLOCK_LOW_TIME 8
40 #define CLOCK_HIGH_TIME 8
41 #define START_CONDITION_HOLD_TIME 8
42 #define STOP_CONDITION_HOLD_TIME 8
43 #define ENABLE_OUTPUT 0x01
44 #define ENABLE_INPUT 0x00
45 #define I2C_CLOCK_HIGH 1
46 #define I2C_CLOCK_LOW 0
47 #define I2C_DATA_HIGH 1
48 #define I2C_DATA_LOW 0
50 #ifdef CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C
52 #ifndef CONFIG_ETRAX_I2C_DATA_PORT
53 #define CONFIG_ETRAX_I2C_DATA_PORT 0
55 #ifndef CONFIG_ETRAX_I2C_CLK_PORT
56 #define CONFIG_ETRAX_I2C_CLK_PORT 1
59 #define SDABIT CONFIG_ETRAX_I2C_DATA_PORT
60 #define SCLBIT CONFIG_ETRAX_I2C_CLK_PORT
66 #define i2c_dir_out() \
67 REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, SDABIT, 1)
68 #define i2c_dir_in() \
69 REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, SDABIT, 0)
74 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, SCLBIT, x)
76 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, SDABIT, x)
80 #define i2c_getbit() (((*R_PORT_PB_READ & (1 << SDABIT))) >> SDABIT)
85 #define i2c_enable() *R_PORT_PB_I2C = (port_pb_i2c_shadow |= IO_MASK(R_PORT_PB_I2C, i2c_en))
86 #define i2c_disable() *R_PORT_PB_I2C = (port_pb_i2c_shadow &= ~IO_MASK(R_PORT_PB_I2C, i2c_en))
90 #define i2c_dir_out() \
91 *R_PORT_PB_I2C = (port_pb_i2c_shadow &= ~IO_MASK(R_PORT_PB_I2C, i2c_oe_)); \
92 REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, 0, 1);
93 #define i2c_dir_in() \
94 *R_PORT_PB_I2C = (port_pb_i2c_shadow |= IO_MASK(R_PORT_PB_I2C, i2c_oe_)); \
95 REG_SHADOW_SET(R_PORT_PB_DIR, port_pb_dir_shadow, 0, 0);
100 *R_PORT_PB_I2C = (port_pb_i2c_shadow = (port_pb_i2c_shadow & \
101 ~IO_MASK(R_PORT_PB_I2C, i2c_clk)) | IO_FIELD(R_PORT_PB_I2C, i2c_clk, (x))); \
102 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, 1, x);
104 #define i2c_data(x) \
105 *R_PORT_PB_I2C = (port_pb_i2c_shadow = (port_pb_i2c_shadow & \
106 ~IO_MASK(R_PORT_PB_I2C, i2c_d)) | IO_FIELD(R_PORT_PB_I2C, i2c_d, (x))); \
107 REG_SHADOW_SET(R_PORT_PB_DATA, port_pb_data_shadow, 0, x);
111 #define i2c_getbit() (*R_PORT_PB_READ & 0x1)
116 #define i2c_delay(usecs) udelay(usecs)
184 for (i = 0; i < 8; i++) {
212 unsigned char aBitByte = 0;
227 for (i = 1; i < 8; i++) {
418 unsigned char theValue)
423 spin_lock(&i2c_lock);
470 }
while(error && cntr--);
474 spin_unlock(&i2c_lock);
493 spin_lock(&i2c_lock);
557 }
while(error && cntr--);
559 spin_unlock(&i2c_lock);
579 static long i2c_ioctl(
struct file *
file,
unsigned int cmd,
unsigned long arg)
616 .unlocked_ioctl = i2c_ioctl,
618 .release = i2c_release,
626 static int first = 1;
635 #ifndef CONFIG_ETRAX_I2C_USES_PB_NOT_PB_I2C
642 IO_STATE(R_PORT_PB_I2C, i2c_en, on) |
656 CONFIG_ETRAX_I2C_DATA_PORT,
657 CONFIG_ETRAX_I2C_DATA_PORT))) {
662 CONFIG_ETRAX_I2C_CLK_PORT,
663 CONFIG_ETRAX_I2C_CLK_PORT))) {
666 CONFIG_ETRAX_I2C_DATA_PORT,
667 CONFIG_ETRAX_I2C_DATA_PORT);
683 res = register_chrdev(
I2C_MAJOR, i2c_name, &i2c_fops);
689 printk(
KERN_INFO "I2C driver v2.2, (c) 1999-2004 Axis Communications AB\n");