aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/i2c.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r--include/linux/i2c.h72
1 files changed, 23 insertions, 49 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index ad2580596033..f4784c0fe975 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -47,6 +47,7 @@ struct i2c_driver;
47union i2c_smbus_data; 47union i2c_smbus_data;
48struct i2c_board_info; 48struct i2c_board_info;
49 49
50#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
50/* 51/*
51 * The master routines are the ones normally used to transmit data to devices 52 * The master routines are the ones normally used to transmit data to devices
52 * on a bus (or read from them). Apart from two basic transfer functions to 53 * on a bus (or read from them). Apart from two basic transfer functions to
@@ -93,6 +94,7 @@ extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client,
93extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client, 94extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
94 u8 command, u8 length, 95 u8 command, u8 length,
95 const u8 *values); 96 const u8 *values);
97#endif /* I2C */
96 98
97/** 99/**
98 * struct i2c_driver - represent an I2C device driver 100 * struct i2c_driver - represent an I2C device driver
@@ -100,9 +102,8 @@ extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
100 * @class: What kind of i2c device we instantiate (for detect) 102 * @class: What kind of i2c device we instantiate (for detect)
101 * @attach_adapter: Callback for bus addition (for legacy drivers) 103 * @attach_adapter: Callback for bus addition (for legacy drivers)
102 * @detach_adapter: Callback for bus removal (for legacy drivers) 104 * @detach_adapter: Callback for bus removal (for legacy drivers)
103 * @detach_client: Callback for device removal (for legacy drivers) 105 * @probe: Callback for device binding
104 * @probe: Callback for device binding (new-style drivers) 106 * @remove: Callback for device unbinding
105 * @remove: Callback for device unbinding (new-style drivers)
106 * @shutdown: Callback for device shutdown 107 * @shutdown: Callback for device shutdown
107 * @suspend: Callback for device suspend 108 * @suspend: Callback for device suspend
108 * @resume: Callback for device resume 109 * @resume: Callback for device resume
@@ -137,26 +138,14 @@ struct i2c_driver {
137 int id; 138 int id;
138 unsigned int class; 139 unsigned int class;
139 140
140 /* Notifies the driver that a new bus has appeared. This routine 141 /* Notifies the driver that a new bus has appeared or is about to be
141 * can be used by the driver to test if the bus meets its conditions 142 * removed. You should avoid using this if you can, it will probably
142 * & seek for the presence of the chip(s) it supports. If found, it 143 * be removed in a near future.
143 * registers the client(s) that are on the bus to the i2c admin. via
144 * i2c_attach_client. (LEGACY I2C DRIVERS ONLY)
145 */ 144 */
146 int (*attach_adapter)(struct i2c_adapter *); 145 int (*attach_adapter)(struct i2c_adapter *);
147 int (*detach_adapter)(struct i2c_adapter *); 146 int (*detach_adapter)(struct i2c_adapter *);
148 147
149 /* tells the driver that a client is about to be deleted & gives it 148 /* Standard driver model interfaces */
150 * the chance to remove its private data. Also, if the client struct
151 * has been dynamically allocated by the driver in the function above,
152 * it must be freed here. (LEGACY I2C DRIVERS ONLY)
153 */
154 int (*detach_client)(struct i2c_client *) __deprecated;
155
156 /* Standard driver model interfaces, for "new style" i2c drivers.
157 * With the driver model, device enumeration is NEVER done by drivers;
158 * it's done by infrastructure. (NEW STYLE DRIVERS ONLY)
159 */
160 int (*probe)(struct i2c_client *, const struct i2c_device_id *); 149 int (*probe)(struct i2c_client *, const struct i2c_device_id *);
161 int (*remove)(struct i2c_client *); 150 int (*remove)(struct i2c_client *);
162 151
@@ -191,9 +180,8 @@ struct i2c_driver {
191 * @driver: device's driver, hence pointer to access routines 180 * @driver: device's driver, hence pointer to access routines
192 * @dev: Driver model device node for the slave. 181 * @dev: Driver model device node for the slave.
193 * @irq: indicates the IRQ generated by this device (if any) 182 * @irq: indicates the IRQ generated by this device (if any)
194 * @list: list of active/busy clients (DEPRECATED) 183 * @detected: member of an i2c_driver.clients list or i2c-core's
195 * @detected: member of an i2c_driver.clients list 184 * userspace_devices list
196 * @released: used to synchronize client releases & detaches and references
197 * 185 *
198 * An i2c_client identifies a single device (i.e. chip) connected to an 186 * An i2c_client identifies a single device (i.e. chip) connected to an
199 * i2c bus. The behaviour exposed to Linux is defined by the driver 187 * i2c bus. The behaviour exposed to Linux is defined by the driver
@@ -209,9 +197,7 @@ struct i2c_client {
209 struct i2c_driver *driver; /* and our access routines */ 197 struct i2c_driver *driver; /* and our access routines */
210 struct device dev; /* the device structure */ 198 struct device dev; /* the device structure */
211 int irq; /* irq issued by device */ 199 int irq; /* irq issued by device */
212 struct list_head list; /* DEPRECATED */
213 struct list_head detected; 200 struct list_head detected;
214 struct completion released;
215}; 201};
216#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 202#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
217 203
@@ -248,11 +234,10 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
248 * that, such as chip type, configuration, associated IRQ, and so on. 234 * that, such as chip type, configuration, associated IRQ, and so on.
249 * 235 *
250 * i2c_board_info is used to build tables of information listing I2C devices 236 * i2c_board_info is used to build tables of information listing I2C devices
251 * that are present. This information is used to grow the driver model tree 237 * that are present. This information is used to grow the driver model tree.
252 * for "new style" I2C drivers. For mainboards this is done statically using 238 * For mainboards this is done statically using i2c_register_board_info();
253 * i2c_register_board_info(); bus numbers identify adapters that aren't 239 * bus numbers identify adapters that aren't yet available. For add-on boards,
254 * yet available. For add-on boards, i2c_new_device() does this dynamically 240 * i2c_new_device() does this dynamically with the adapter already known.
255 * with the adapter already known.
256 */ 241 */
257struct i2c_board_info { 242struct i2c_board_info {
258 char type[I2C_NAME_SIZE]; 243 char type[I2C_NAME_SIZE];
@@ -277,6 +262,7 @@ struct i2c_board_info {
277 .type = dev_type, .addr = (dev_addr) 262 .type = dev_type, .addr = (dev_addr)
278 263
279 264
265#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
280/* Add-on boards should register/unregister their devices; e.g. a board 266/* Add-on boards should register/unregister their devices; e.g. a board
281 * with integrated I2C, a config eeprom, sensors, and a codec that's 267 * with integrated I2C, a config eeprom, sensors, and a codec that's
282 * used in conjunction with the primary hardware. 268 * used in conjunction with the primary hardware.
@@ -300,6 +286,7 @@ extern struct i2c_client *
300i2c_new_dummy(struct i2c_adapter *adap, u16 address); 286i2c_new_dummy(struct i2c_adapter *adap, u16 address);
301 287
302extern void i2c_unregister_device(struct i2c_client *); 288extern void i2c_unregister_device(struct i2c_client *);
289#endif /* I2C */
303 290
304/* Mainboard arch_initcall() code should register all its I2C devices. 291/* Mainboard arch_initcall() code should register all its I2C devices.
305 * This is done at arch_initcall time, before declaring any i2c adapters. 292 * This is done at arch_initcall time, before declaring any i2c adapters.
@@ -316,7 +303,7 @@ i2c_register_board_info(int busnum, struct i2c_board_info const *info,
316{ 303{
317 return 0; 304 return 0;
318} 305}
319#endif 306#endif /* I2C_BOARDINFO */
320 307
321/* 308/*
322 * The following structs are for those who like to implement new bus drivers: 309 * The following structs are for those who like to implement new bus drivers:
@@ -352,21 +339,15 @@ struct i2c_adapter {
352 const struct i2c_algorithm *algo; /* the algorithm to access the bus */ 339 const struct i2c_algorithm *algo; /* the algorithm to access the bus */
353 void *algo_data; 340 void *algo_data;
354 341
355 /* --- administration stuff. */
356 int (*client_register)(struct i2c_client *) __deprecated;
357 int (*client_unregister)(struct i2c_client *) __deprecated;
358
359 /* data fields that are valid for all devices */ 342 /* data fields that are valid for all devices */
360 u8 level; /* nesting level for lockdep */ 343 u8 level; /* nesting level for lockdep */
361 struct mutex bus_lock; 344 struct mutex bus_lock;
362 struct mutex clist_lock;
363 345
364 int timeout; /* in jiffies */ 346 int timeout; /* in jiffies */
365 int retries; 347 int retries;
366 struct device dev; /* the adapter device */ 348 struct device dev; /* the adapter device */
367 349
368 int nr; 350 int nr;
369 struct list_head clients; /* DEPRECATED */
370 char name[48]; 351 char name[48];
371 struct completion dev_released; 352 struct completion dev_released;
372}; 353};
@@ -412,11 +393,16 @@ struct i2c_client_address_data {
412/* The numbers to use to set I2C bus address */ 393/* The numbers to use to set I2C bus address */
413#define ANY_I2C_BUS 0xffff 394#define ANY_I2C_BUS 0xffff
414 395
396/* Construct an I2C_CLIENT_END-terminated array of i2c addresses */
397#define I2C_ADDRS(addr, addrs...) \
398 ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END })
399
415 400
416/* ----- functions exported by i2c.o */ 401/* ----- functions exported by i2c.o */
417 402
418/* administration... 403/* administration...
419 */ 404 */
405#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
420extern int i2c_add_adapter(struct i2c_adapter *); 406extern int i2c_add_adapter(struct i2c_adapter *);
421extern int i2c_del_adapter(struct i2c_adapter *); 407extern int i2c_del_adapter(struct i2c_adapter *);
422extern int i2c_add_numbered_adapter(struct i2c_adapter *); 408extern int i2c_add_numbered_adapter(struct i2c_adapter *);
@@ -429,11 +415,6 @@ static inline int i2c_add_driver(struct i2c_driver *driver)
429 return i2c_register_driver(THIS_MODULE, driver); 415 return i2c_register_driver(THIS_MODULE, driver);
430} 416}
431 417
432/* These are deprecated, your driver should use the standard .probe()
433 * and .remove() methods instead. */
434extern int __deprecated i2c_attach_client(struct i2c_client *);
435extern int __deprecated i2c_detach_client(struct i2c_client *);
436
437extern struct i2c_client *i2c_use_client(struct i2c_client *client); 418extern struct i2c_client *i2c_use_client(struct i2c_client *client);
438extern void i2c_release_client(struct i2c_client *client); 419extern void i2c_release_client(struct i2c_client *client);
439 420
@@ -442,14 +423,6 @@ extern void i2c_release_client(struct i2c_client *client);
442extern void i2c_clients_command(struct i2c_adapter *adap, 423extern void i2c_clients_command(struct i2c_adapter *adap,
443 unsigned int cmd, void *arg); 424 unsigned int cmd, void *arg);
444 425
445/* Detect function. It iterates over all possible addresses itself.
446 * It will only call found_proc if some client is connected at the
447 * specific address (unless a 'force' matched);
448 */
449extern int i2c_probe(struct i2c_adapter *adapter,
450 const struct i2c_client_address_data *address_data,
451 int (*found_proc) (struct i2c_adapter *, int, int));
452
453extern struct i2c_adapter *i2c_get_adapter(int id); 426extern struct i2c_adapter *i2c_get_adapter(int id);
454extern void i2c_put_adapter(struct i2c_adapter *adap); 427extern void i2c_put_adapter(struct i2c_adapter *adap);
455 428
@@ -471,6 +444,7 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
471{ 444{
472 return adap->nr; 445 return adap->nr;
473} 446}
447#endif /* I2C */
474#endif /* __KERNEL__ */ 448#endif /* __KERNEL__ */
475 449
476/** 450/**