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.h49
1 files changed, 33 insertions, 16 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 02fc617782ef..4bae0b72ed3c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -34,8 +34,10 @@
34#include <linux/device.h> /* for struct device */ 34#include <linux/device.h> /* for struct device */
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#include <linux/of.h> /* for struct device_node */
37 38
38extern struct bus_type i2c_bus_type; 39extern struct bus_type i2c_bus_type;
40extern struct device_type i2c_adapter_type;
39 41
40/* --- General options ------------------------------------------------ */ 42/* --- General options ------------------------------------------------ */
41 43
@@ -53,6 +55,7 @@ struct i2c_board_info;
53 * on a bus (or read from them). Apart from two basic transfer functions to 55 * on a bus (or read from them). Apart from two basic transfer functions to
54 * transmit one message at a time, a more complex version can be used to 56 * transmit one message at a time, a more complex version can be used to
55 * transmit an arbitrary number of messages without interruption. 57 * transmit an arbitrary number of messages without interruption.
58 * @count must be be less than 64k since msg.len is u16.
56 */ 59 */
57extern int i2c_master_send(struct i2c_client *client, const char *buf, 60extern int i2c_master_send(struct i2c_client *client, const char *buf,
58 int count); 61 int count);
@@ -106,6 +109,7 @@ extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client *client,
106 * @shutdown: Callback for device shutdown 109 * @shutdown: Callback for device shutdown
107 * @suspend: Callback for device suspend 110 * @suspend: Callback for device suspend
108 * @resume: Callback for device resume 111 * @resume: Callback for device resume
112 * @alert: Alert callback, for example for the SMBus alert protocol
109 * @command: Callback for bus-wide signaling (optional) 113 * @command: Callback for bus-wide signaling (optional)
110 * @driver: Device driver model driver 114 * @driver: Device driver model driver
111 * @id_table: List of I2C devices supported by this driver 115 * @id_table: List of I2C devices supported by this driver
@@ -152,6 +156,13 @@ struct i2c_driver {
152 int (*suspend)(struct i2c_client *, pm_message_t mesg); 156 int (*suspend)(struct i2c_client *, pm_message_t mesg);
153 int (*resume)(struct i2c_client *); 157 int (*resume)(struct i2c_client *);
154 158
159 /* Alert callback, for example for the SMBus alert protocol.
160 * The format and meaning of the data value depends on the protocol.
161 * For the SMBus alert protocol, there is a single bit of data passed
162 * as the alert response's low bit ("event flag").
163 */
164 void (*alert)(struct i2c_client *, unsigned int data);
165
155 /* a ioctl like command that can be used to perform specific functions 166 /* a ioctl like command that can be used to perform specific functions
156 * with the device. 167 * with the device.
157 */ 168 */
@@ -224,6 +235,7 @@ static inline void i2c_set_clientdata(struct i2c_client *dev, void *data)
224 * @addr: stored in i2c_client.addr 235 * @addr: stored in i2c_client.addr
225 * @platform_data: stored in i2c_client.dev.platform_data 236 * @platform_data: stored in i2c_client.dev.platform_data
226 * @archdata: copied into i2c_client.dev.archdata 237 * @archdata: copied into i2c_client.dev.archdata
238 * @of_node: pointer to OpenFirmware device node
227 * @irq: stored in i2c_client.irq 239 * @irq: stored in i2c_client.irq
228 * 240 *
229 * I2C doesn't actually support hardware probing, although controllers and 241 * I2C doesn't actually support hardware probing, although controllers and
@@ -243,6 +255,9 @@ struct i2c_board_info {
243 unsigned short addr; 255 unsigned short addr;
244 void *platform_data; 256 void *platform_data;
245 struct dev_archdata *archdata; 257 struct dev_archdata *archdata;
258#ifdef CONFIG_OF
259 struct device_node *of_node;
260#endif
246 int irq; 261 int irq;
247}; 262};
248 263
@@ -270,12 +285,18 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
270 285
271/* If you don't know the exact address of an I2C device, use this variant 286/* If you don't know the exact address of an I2C device, use this variant
272 * instead, which can probe for device presence in a list of possible 287 * instead, which can probe for device presence in a list of possible
273 * addresses. 288 * addresses. The "probe" callback function is optional. If it is provided,
289 * it must return 1 on successful probe, 0 otherwise. If it is not provided,
290 * a default probing method is used.
274 */ 291 */
275extern struct i2c_client * 292extern struct i2c_client *
276i2c_new_probed_device(struct i2c_adapter *adap, 293i2c_new_probed_device(struct i2c_adapter *adap,
277 struct i2c_board_info *info, 294 struct i2c_board_info *info,
278 unsigned short const *addr_list); 295 unsigned short const *addr_list,
296 int (*probe)(struct i2c_adapter *, unsigned short addr));
297
298/* Common custom probe functions */
299extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr);
279 300
280/* For devices that use several addresses, use i2c_new_dummy() to make 301/* For devices that use several addresses, use i2c_new_dummy() to make
281 * client handles for the extra addresses. 302 * client handles for the extra addresses.
@@ -347,6 +368,9 @@ struct i2c_adapter {
347 int nr; 368 int nr;
348 char name[48]; 369 char name[48];
349 struct completion dev_released; 370 struct completion dev_released;
371
372 struct mutex userspace_clients_lock;
373 struct list_head userspace_clients;
350}; 374};
351#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) 375#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
352 376
@@ -360,23 +384,16 @@ static inline void i2c_set_adapdata(struct i2c_adapter *dev, void *data)
360 dev_set_drvdata(&dev->dev, data); 384 dev_set_drvdata(&dev->dev, data);
361} 385}
362 386
363/** 387static inline int i2c_parent_is_i2c_adapter(const struct i2c_adapter *adapter)
364 * i2c_lock_adapter - Prevent access to an I2C bus segment
365 * @adapter: Target I2C bus segment
366 */
367static inline void i2c_lock_adapter(struct i2c_adapter *adapter)
368{ 388{
369 rt_mutex_lock(&adapter->bus_lock); 389 return adapter->dev.parent != NULL
390 && adapter->dev.parent->bus == &i2c_bus_type
391 && adapter->dev.parent->type == &i2c_adapter_type;
370} 392}
371 393
372/** 394/* Adapter locking functions, exported for shared pin cases */
373 * i2c_unlock_adapter - Reauthorize access to an I2C bus segment 395void i2c_lock_adapter(struct i2c_adapter *);
374 * @adapter: Target I2C bus segment 396void i2c_unlock_adapter(struct i2c_adapter *);
375 */
376static inline void i2c_unlock_adapter(struct i2c_adapter *adapter)
377{
378 rt_mutex_unlock(&adapter->bus_lock);
379}
380 397
381/*flags for the client struct: */ 398/*flags for the client struct: */
382#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ 399#define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */