Philip Blundell (philb@gnu.org)
Wed, 04 Nov 1998 19:36:19 +0100
I forget who was asking for it, but...
Here's the IIC driver I wrote to run over a parallel port. It's a pretty
trivial piece of code as you can see. :-)
p.
/*
* I2C driver for 4-wire parallel port
*/
#include <linux/parport.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#define I2C_DELAY 10
/* software I2C functions */
static void i2c_setlines(struct i2c_bus *bus,int ctrl,int data)
{
struct parport *p = bus->data;
parport_write_data(p, (ctrl?1:0) | (data?2:0));
udelay(I2C_DELAY);
}
static int i2c_getdataline(struct i2c_bus *bus)
{
struct parport *p = bus->data;
return ((parport_read_status(p) & 0x80) >> 7) ^ 1;
}
static struct i2c_bus p4w_i2c_bus_template =
{
"p4w",
I2C_BUSID_P4W,
NULL,
SPIN_LOCK_UNLOCKED,
NULL,
NULL,
i2c_setlines,
i2c_getdataline,
NULL,
NULL,
};
#define MAX_BUS 8
static int nr_bus = 0;
static struct i2c_bus *bus[MAX_BUS];
int init_module(void)
{
struct parport *p = parport_enumerate();
while (p)
{
struct i2c_bus *b = kmalloc(sizeof(struct i2c_bus), GFP_KERNEL);
*b = p4w_i2c_bus_template;
b->data = p;
i2c_register_bus(b);
bus[nr_bus++] = b;
if (nr_bus == MAX_BUS) break;
p = p->next;
}
return 0;
}
void cleanup_module(void)
{
int i;
for (i = 0; i < nr_bus; i++)
i2c_unregister_bus(bus[i]);
}
-- To unsubscribe, send mail to: linux-parport-request@torque.net --
-- with the single word "unsubscribe" in the body of the message. --
This archive was generated by hypermail 2.0b3 on Wed 30 Dec 1998 - 10:18:44 EST