- Kai Germaschewski: ymfpci cleanups and resource leak fixes
[davej-history.git] / include / linux / i2c-old.h
blobcc9d9c148661b837028748fd12597fb20f751e83
1 #ifndef I2C_H
2 #define I2C_H
4 /*
5 * linux i2c interface. Works a little bit like the scsi subsystem.
6 * There are:
8 * i2c the basic control module (like scsi_mod)
9 * bus driver a driver with a i2c bus (hostadapter driver)
10 * chip driver a driver for a chip connected
11 * to a i2c bus (cdrom/hd driver)
13 * A device will be attached to one bus and one chip driver. Every chip
14 * driver gets a unique ID.
16 * A chip driver can provide a ioctl-like callback for the
17 * communication with other parts of the kernel (not every i2c chip is
18 * useful without other devices, a TV card tuner for example).
20 * "i2c internal" parts of the structs: only the i2c module is allowed to
21 * write to them, for others they are read-only.
25 #include <linux/version.h>
27 #define I2C_BUS_MAX 4 /* max # of bus drivers */
28 #define I2C_DRIVER_MAX 8 /* max # of chip drivers */
29 #define I2C_DEVICE_MAX 8 /* max # if devices per bus/driver */
31 struct i2c_bus;
32 struct i2c_driver;
33 struct i2c_device;
35 #define I2C_DRIVERID_MSP3400 1
36 #define I2C_DRIVERID_TUNER 2
37 #define I2C_DRIVERID_VIDEOTEXT 3
38 #define I2C_DRIVERID_VIDEODECODER 4
39 #define I2C_DRIVERID_VIDEOENCODER 5
41 #define I2C_BUSID_BT848 1 /* I2C bus on a BT848 */
42 #define I2C_BUSID_PARPORT 2 /* Bit banging on a parallel port */
43 #define I2C_BUSID_BUZ 3
44 #define I2C_BUSID_ZORAN 4
45 #define I2C_BUSID_CYBER2000 5
48 * struct for a driver for a i2c chip (tuner, soundprocessor,
49 * videotext, ... ).
51 * a driver will register within the i2c module. The i2c module will
52 * callback the driver (i2c_attach) for every device it finds on a i2c
53 * bus at the specified address. If the driver decides to "accept"
54 * the, device, it must return a struct i2c_device, and NULL
55 * otherwise.
57 * i2c_detach = i2c_attach ** -1
59 * i2c_command will be used to pass commands to the driver in a
60 * ioctl-line manner.
64 struct i2c_driver
66 char name[32]; /* some useful label */
67 int id; /* device type ID */
68 unsigned char addr_l, addr_h; /* address range of the chip */
70 int (*attach)(struct i2c_device *device);
71 int (*detach)(struct i2c_device *device);
72 int (*command)(struct i2c_device *device,unsigned int cmd, void *arg);
74 /* i2c internal */
75 struct i2c_device *devices[I2C_DEVICE_MAX];
76 int devcount;
81 * this holds the informations about a i2c bus available in the system.
83 * a chip with a i2c bus interface (like bt848) registers the bus within
84 * the i2c module. This struct provides functions to access the i2c bus.
86 * One must hold the spinlock to access the i2c bus (XXX: is the irqsave
87 * required? Maybe better use a semaphore?).
88 * [-AC-] having a spinlock_irqsave is only needed if we have drivers wishing
89 * to bang their i2c bus from an interrupt.
91 * attach/detach_inform is a callback to inform the bus driver about
92 * attached chip drivers.
96 /* needed: unsigned long flags */
98 #if LINUX_VERSION_CODE >= 0x020100
99 # if 0
100 # define LOCK_FLAGS unsigned long flags;
101 # define LOCK_I2C_BUS(bus) spin_lock_irqsave(&(bus->bus_lock),flags);
102 # define UNLOCK_I2C_BUS(bus) spin_unlock_irqrestore(&(bus->bus_lock),flags);
103 # else
104 # define LOCK_FLAGS
105 # define LOCK_I2C_BUS(bus) spin_lock(&(bus->bus_lock));
106 # define UNLOCK_I2C_BUS(bus) spin_unlock(&(bus->bus_lock));
107 # endif
108 #else
109 # define LOCK_FLAGS unsigned long flags;
110 # define LOCK_I2C_BUS(bus) { save_flags(flags); cli(); }
111 # define UNLOCK_I2C_BUS(bus) { restore_flags(flags); }
112 #endif
114 struct i2c_bus
116 char name[32]; /* some useful label */
117 int id;
118 void *data; /* free for use by the bus driver */
120 #if LINUX_VERSION_CODE >= 0x020100
121 spinlock_t bus_lock;
122 #endif
124 /* attach/detach inform callbacks */
125 void (*attach_inform)(struct i2c_bus *bus, int id);
126 void (*detach_inform)(struct i2c_bus *bus, int id);
128 /* Software I2C */
129 void (*i2c_setlines)(struct i2c_bus *bus, int ctrl, int data);
130 int (*i2c_getdataline)(struct i2c_bus *bus);
132 /* Hardware I2C */
133 int (*i2c_read)(struct i2c_bus *bus, unsigned char addr);
134 int (*i2c_write)(struct i2c_bus *bus, unsigned char addr,
135 unsigned char b1, unsigned char b2, int both);
137 /* internal data for i2c module */
138 struct i2c_device *devices[I2C_DEVICE_MAX];
139 int devcount;
144 * This holds per-device data for a i2c device
147 struct i2c_device
149 char name[32]; /* some useful label */
150 void *data; /* free for use by the chip driver */
151 unsigned char addr; /* chip addr */
153 /* i2c internal */
154 struct i2c_bus *bus;
155 struct i2c_driver *driver;
159 /* ------------------------------------------------------------------- */
160 /* i2c module functions */
162 /* register/unregister a i2c bus */
163 int i2c_register_bus(struct i2c_bus *bus);
164 int i2c_unregister_bus(struct i2c_bus *bus);
166 /* register/unregister a chip driver */
167 int i2c_register_driver(struct i2c_driver *driver);
168 int i2c_unregister_driver(struct i2c_driver *driver);
170 /* send a command to a chip using the ioctl-like callback interface */
171 int i2c_control_device(struct i2c_bus *bus, int id,
172 unsigned int cmd, void *arg);
174 /* i2c bus access functions */
175 void i2c_start(struct i2c_bus *bus);
176 void i2c_stop(struct i2c_bus *bus);
177 void i2c_one(struct i2c_bus *bus);
178 void i2c_zero(struct i2c_bus *bus);
179 int i2c_ack(struct i2c_bus *bus);
181 int i2c_sendbyte(struct i2c_bus *bus,unsigned char data,int wait_for_ack);
182 unsigned char i2c_readbyte(struct i2c_bus *bus,int last);
184 /* i2c (maybe) hardware functions */
185 int i2c_read(struct i2c_bus *bus, unsigned char addr);
186 int i2c_write(struct i2c_bus *bus, unsigned char addr,
187 unsigned char b1, unsigned char b2, int both);
189 int i2c_init(void);
190 #endif /* I2C_H */