diff options
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r-- | include/linux/i2c.h | 123 |
1 files changed, 103 insertions, 20 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 9428092017e3..cae7d618030c 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h | |||
@@ -35,11 +35,6 @@ | |||
35 | #include <linux/sched.h> /* for completion */ | 35 | #include <linux/sched.h> /* for completion */ |
36 | #include <linux/mutex.h> | 36 | #include <linux/mutex.h> |
37 | 37 | ||
38 | /* --- For i2c-isa ---------------------------------------------------- */ | ||
39 | |||
40 | extern void i2c_adapter_dev_release(struct device *dev); | ||
41 | extern struct device_driver i2c_adapter_driver; | ||
42 | extern struct class i2c_adapter_class; | ||
43 | extern struct bus_type i2c_bus_type; | 38 | extern struct bus_type i2c_bus_type; |
44 | 39 | ||
45 | /* --- General options ------------------------------------------------ */ | 40 | /* --- General options ------------------------------------------------ */ |
@@ -87,6 +82,9 @@ extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, | |||
87 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); | 82 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); |
88 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, | 83 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, |
89 | u8 command, u16 value); | 84 | u8 command, u16 value); |
85 | /* Returns the number of read bytes */ | ||
86 | extern s32 i2c_smbus_read_block_data(struct i2c_client *client, | ||
87 | u8 command, u8 *values); | ||
90 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, | 88 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
91 | u8 command, u8 length, | 89 | u8 command, u8 length, |
92 | const u8 *values); | 90 | const u8 *values); |
@@ -114,7 +112,7 @@ struct i2c_driver { | |||
114 | * can be used by the driver to test if the bus meets its conditions | 112 | * can be used by the driver to test if the bus meets its conditions |
115 | * & seek for the presence of the chip(s) it supports. If found, it | 113 | * & seek for the presence of the chip(s) it supports. If found, it |
116 | * registers the client(s) that are on the bus to the i2c admin. via | 114 | * registers the client(s) that are on the bus to the i2c admin. via |
117 | * i2c_attach_client. | 115 | * i2c_attach_client. (LEGACY I2C DRIVERS ONLY) |
118 | */ | 116 | */ |
119 | int (*attach_adapter)(struct i2c_adapter *); | 117 | int (*attach_adapter)(struct i2c_adapter *); |
120 | int (*detach_adapter)(struct i2c_adapter *); | 118 | int (*detach_adapter)(struct i2c_adapter *); |
@@ -122,10 +120,17 @@ struct i2c_driver { | |||
122 | /* tells the driver that a client is about to be deleted & gives it | 120 | /* tells the driver that a client is about to be deleted & gives it |
123 | * the chance to remove its private data. Also, if the client struct | 121 | * the chance to remove its private data. Also, if the client struct |
124 | * has been dynamically allocated by the driver in the function above, | 122 | * has been dynamically allocated by the driver in the function above, |
125 | * it must be freed here. | 123 | * it must be freed here. (LEGACY I2C DRIVERS ONLY) |
126 | */ | 124 | */ |
127 | int (*detach_client)(struct i2c_client *); | 125 | int (*detach_client)(struct i2c_client *); |
128 | 126 | ||
127 | /* Standard driver model interfaces, for "new style" i2c drivers. | ||
128 | * With the driver model, device enumeration is NEVER done by drivers; | ||
129 | * it's done by infrastructure. (NEW STYLE DRIVERS ONLY) | ||
130 | */ | ||
131 | int (*probe)(struct i2c_client *); | ||
132 | int (*remove)(struct i2c_client *); | ||
133 | |||
129 | /* driver model interfaces that don't relate to enumeration */ | 134 | /* driver model interfaces that don't relate to enumeration */ |
130 | void (*shutdown)(struct i2c_client *); | 135 | void (*shutdown)(struct i2c_client *); |
131 | int (*suspend)(struct i2c_client *, pm_message_t mesg); | 136 | int (*suspend)(struct i2c_client *, pm_message_t mesg); |
@@ -141,25 +146,34 @@ struct i2c_driver { | |||
141 | }; | 146 | }; |
142 | #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) | 147 | #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) |
143 | 148 | ||
144 | #define I2C_NAME_SIZE 50 | 149 | #define I2C_NAME_SIZE 20 |
145 | 150 | ||
146 | /* | 151 | /** |
147 | * i2c_client identifies a single device (i.e. chip) that is connected to an | 152 | * struct i2c_client - represent an I2C slave device |
148 | * i2c bus. The behaviour is defined by the routines of the driver. This | 153 | * @addr: Address used on the I2C bus connected to the parent adapter. |
149 | * function is mainly used for lookup & other admin. functions. | 154 | * @name: Indicates the type of the device, usually a chip name that's |
155 | * generic enough to hide second-sourcing and compatible revisions. | ||
156 | * @dev: Driver model device node for the slave. | ||
157 | * @driver_name: Identifies new-style driver used with this device; also | ||
158 | * used as the module name for hotplug/coldplug modprobe support. | ||
159 | * | ||
160 | * An i2c_client identifies a single device (i.e. chip) connected to an | ||
161 | * i2c bus. The behaviour is defined by the routines of the driver. | ||
150 | */ | 162 | */ |
151 | struct i2c_client { | 163 | struct i2c_client { |
152 | unsigned int flags; /* div., see below */ | 164 | unsigned short flags; /* div., see below */ |
153 | unsigned short addr; /* chip address - NOTE: 7bit */ | 165 | unsigned short addr; /* chip address - NOTE: 7bit */ |
154 | /* addresses are stored in the */ | 166 | /* addresses are stored in the */ |
155 | /* _LOWER_ 7 bits */ | 167 | /* _LOWER_ 7 bits */ |
168 | char name[I2C_NAME_SIZE]; | ||
156 | struct i2c_adapter *adapter; /* the adapter we sit on */ | 169 | struct i2c_adapter *adapter; /* the adapter we sit on */ |
157 | struct i2c_driver *driver; /* and our access routines */ | 170 | struct i2c_driver *driver; /* and our access routines */ |
158 | int usage_count; /* How many accesses currently */ | 171 | int usage_count; /* How many accesses currently */ |
159 | /* to the client */ | 172 | /* to the client */ |
160 | struct device dev; /* the device structure */ | 173 | struct device dev; /* the device structure */ |
174 | int irq; /* irq issued by device (or -1) */ | ||
175 | char driver_name[KOBJ_NAME_LEN]; | ||
161 | struct list_head list; | 176 | struct list_head list; |
162 | char name[I2C_NAME_SIZE]; | ||
163 | struct completion released; | 177 | struct completion released; |
164 | }; | 178 | }; |
165 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) | 179 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) |
@@ -179,6 +193,76 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data) | |||
179 | dev_set_drvdata (&dev->dev, data); | 193 | dev_set_drvdata (&dev->dev, data); |
180 | } | 194 | } |
181 | 195 | ||
196 | /** | ||
197 | * struct i2c_board_info - template for device creation | ||
198 | * @driver_name: identifies the driver to be bound to the device | ||
199 | * @type: optional chip type information, to initialize i2c_client.name | ||
200 | * @flags: to initialize i2c_client.flags | ||
201 | * @addr: stored in i2c_client.addr | ||
202 | * @platform_data: stored in i2c_client.dev.platform_data | ||
203 | * @irq: stored in i2c_client.irq | ||
204 | |||
205 | * I2C doesn't actually support hardware probing, although controllers and | ||
206 | * devices may be able to use I2C_SMBUS_QUICK to tell whether or not there's | ||
207 | * a device at a given address. Drivers commonly need more information than | ||
208 | * that, such as chip type, configuration, associated IRQ, and so on. | ||
209 | * | ||
210 | * i2c_board_info is used to build tables of information listing I2C devices | ||
211 | * that are present. This information is used to grow the driver model tree | ||
212 | * for "new style" I2C drivers. For mainboards this is done statically using | ||
213 | * i2c_register_board_info(), where @bus_num represents an adapter that isn't | ||
214 | * yet available. For add-on boards, i2c_new_device() does this dynamically | ||
215 | * with the adapter already known. | ||
216 | */ | ||
217 | struct i2c_board_info { | ||
218 | char driver_name[KOBJ_NAME_LEN]; | ||
219 | char type[I2C_NAME_SIZE]; | ||
220 | unsigned short flags; | ||
221 | unsigned short addr; | ||
222 | void *platform_data; | ||
223 | int irq; | ||
224 | }; | ||
225 | |||
226 | /** | ||
227 | * I2C_BOARD_INFO - macro used to list an i2c device and its driver | ||
228 | * @driver: identifies the driver to use with the device | ||
229 | * @dev_addr: the device's address on the bus. | ||
230 | * | ||
231 | * This macro initializes essential fields of a struct i2c_board_info, | ||
232 | * declaring what has been provided on a particular board. Optional | ||
233 | * fields (such as the chip type, its associated irq, or device-specific | ||
234 | * platform_data) are provided using conventional syntax. | ||
235 | */ | ||
236 | #define I2C_BOARD_INFO(driver,dev_addr) \ | ||
237 | .driver_name = (driver), .addr = (dev_addr) | ||
238 | |||
239 | |||
240 | /* Add-on boards should register/unregister their devices; e.g. a board | ||
241 | * with integrated I2C, a config eeprom, sensors, and a codec that's | ||
242 | * used in conjunction with the primary hardware. | ||
243 | */ | ||
244 | extern struct i2c_client * | ||
245 | i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info); | ||
246 | |||
247 | /* If you don't know the exact address of an I2C device, use this variant | ||
248 | * instead, which can probe for device presence in a list of possible | ||
249 | * addresses. | ||
250 | */ | ||
251 | extern struct i2c_client * | ||
252 | i2c_new_probed_device(struct i2c_adapter *adap, | ||
253 | struct i2c_board_info *info, | ||
254 | unsigned short const *addr_list); | ||
255 | |||
256 | extern void i2c_unregister_device(struct i2c_client *); | ||
257 | |||
258 | /* Mainboard arch_initcall() code should register all its I2C devices. | ||
259 | * This is done at arch_initcall time, before declaring any i2c adapters. | ||
260 | * Modules for add-on boards must use other calls. | ||
261 | */ | ||
262 | extern int | ||
263 | i2c_register_board_info(int busnum, struct i2c_board_info const *info, unsigned n); | ||
264 | |||
265 | |||
182 | /* | 266 | /* |
183 | * The following structs are for those who like to implement new bus drivers: | 267 | * The following structs are for those who like to implement new bus drivers: |
184 | * i2c_algorithm is the interface to a class of hardware solutions which can | 268 | * i2c_algorithm is the interface to a class of hardware solutions which can |
@@ -228,17 +312,14 @@ struct i2c_adapter { | |||
228 | int timeout; | 312 | int timeout; |
229 | int retries; | 313 | int retries; |
230 | struct device dev; /* the adapter device */ | 314 | struct device dev; /* the adapter device */ |
231 | struct class_device class_dev; /* the class device */ | ||
232 | 315 | ||
233 | int nr; | 316 | int nr; |
234 | struct list_head clients; | 317 | struct list_head clients; |
235 | struct list_head list; | 318 | struct list_head list; |
236 | char name[I2C_NAME_SIZE]; | 319 | char name[48]; |
237 | struct completion dev_released; | 320 | struct completion dev_released; |
238 | struct completion class_dev_released; | ||
239 | }; | 321 | }; |
240 | #define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) | 322 | #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) |
241 | #define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev) | ||
242 | 323 | ||
243 | static inline void *i2c_get_adapdata (struct i2c_adapter *dev) | 324 | static inline void *i2c_get_adapdata (struct i2c_adapter *dev) |
244 | { | 325 | { |
@@ -290,9 +371,10 @@ struct i2c_client_address_data { | |||
290 | */ | 371 | */ |
291 | extern int i2c_add_adapter(struct i2c_adapter *); | 372 | extern int i2c_add_adapter(struct i2c_adapter *); |
292 | extern int i2c_del_adapter(struct i2c_adapter *); | 373 | extern int i2c_del_adapter(struct i2c_adapter *); |
374 | extern int i2c_add_numbered_adapter(struct i2c_adapter *); | ||
293 | 375 | ||
294 | extern int i2c_register_driver(struct module *, struct i2c_driver *); | 376 | extern int i2c_register_driver(struct module *, struct i2c_driver *); |
295 | extern int i2c_del_driver(struct i2c_driver *); | 377 | extern void i2c_del_driver(struct i2c_driver *); |
296 | 378 | ||
297 | static inline int i2c_add_driver(struct i2c_driver *driver) | 379 | static inline int i2c_add_driver(struct i2c_driver *driver) |
298 | { | 380 | { |
@@ -365,6 +447,7 @@ struct i2c_msg { | |||
365 | #define I2C_M_REV_DIR_ADDR 0x2000 | 447 | #define I2C_M_REV_DIR_ADDR 0x2000 |
366 | #define I2C_M_IGNORE_NAK 0x1000 | 448 | #define I2C_M_IGNORE_NAK 0x1000 |
367 | #define I2C_M_NO_RD_ACK 0x0800 | 449 | #define I2C_M_NO_RD_ACK 0x0800 |
450 | #define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */ | ||
368 | __u16 len; /* msg length */ | 451 | __u16 len; /* msg length */ |
369 | __u8 *buf; /* pointer to msg data */ | 452 | __u8 *buf; /* pointer to msg data */ |
370 | }; | 453 | }; |