aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/i2c.h
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-07-14 16:38:36 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-07-14 16:38:36 -0400
commit4735c98f8447acb1c8977e2b8024640f7bf36dd6 (patch)
tree7f7c65b1feef6a0213caa20218cd6080488cc62b /include/linux/i2c.h
parent8508159e2f3b82bf109f0ec77bcbd8ff3f3a7e17 (diff)
i2c: Add detection capability to new-style drivers
Add a mechanism to let new-style i2c drivers optionally autodetect devices they would support on selected buses and ask i2c-core to instantiate them. This is a replacement for legacy i2c drivers, much cleaner. Where drivers had to implement both a legacy i2c_driver and a new-style i2c_driver so far, this mechanism makes it possible to get rid of the legacy i2c_driver and implement both enumerated and detected device support with just one (new-style) i2c_driver. Here is a quick conversion guide for these drivers, step by step: * Delete the legacy driver definition, registration and removal. Delete the attach_adapter and detach_client methods of the legacy driver. * Change the prototype of the legacy detect function from static int foo_detect(struct i2c_adapter *adapter, int address, int kind); to static int foo_detect(struct i2c_client *client, int kind, struct i2c_board_info *info); * Set the new-style driver detect callback to this new function, and set its address_data to &addr_data (addr_data is generally provided by I2C_CLIENT_INSMOD.) * Add the appropriate class to the new-style driver. This is typically the class the legacy attach_adapter method was checking for. Class checking is now mandatory (done by i2c-core.) See <linux/i2c.h> for the list of available classes. * Remove the i2c_client allocation and freeing from the detect function. A pre-allocated client is now handed to you by i2c-core, and is freed automatically. * Make the detect function fill the type field of the i2c_board_info structure it was passed as a parameter, and return 0, on success. If the detection fails, return -ENODEV. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'include/linux/i2c.h')
-rw-r--r--include/linux/i2c.h36
1 files changed, 31 insertions, 5 deletions
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 50cbab4b62b0..08be0d21864c 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -45,6 +45,7 @@ struct i2c_adapter;
45struct i2c_client; 45struct i2c_client;
46struct i2c_driver; 46struct i2c_driver;
47union i2c_smbus_data; 47union i2c_smbus_data;
48struct i2c_board_info;
48 49
49/* 50/*
50 * The master routines are the ones normally used to transmit data to devices 51 * The master routines are the ones normally used to transmit data to devices
@@ -94,15 +95,33 @@ extern 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);
96 97
97/* 98/**
98 * A driver is capable of handling one or more physical devices present on 99 * struct i2c_driver - represent an I2C device driver
99 * I2C adapters. This information is used to inform the driver of adapter 100 * @class: What kind of i2c device we instantiate (for detect)
100 * events. 101 * @detect: Callback for device detection
102 * @address_data: The I2C addresses to probe, ignore or force (for detect)
103 * @clients: List of detected clients we created (for i2c-core use only)
101 * 104 *
102 * The driver.owner field should be set to the module owner of this driver. 105 * The driver.owner field should be set to the module owner of this driver.
103 * The driver.name field should be set to the name of this driver. 106 * The driver.name field should be set to the name of this driver.
107 *
108 * For automatic device detection, both @detect and @address_data must
109 * be defined. @class should also be set, otherwise only devices forced
110 * with module parameters will be created. The detect function must
111 * fill at least the name field of the i2c_board_info structure it is
112 * handed upon successful detection, and possibly also the flags field.
113 *
114 * If @detect is missing, the driver will still work fine for enumerated
115 * devices. Detected devices simply won't be supported. This is expected
116 * for the many I2C/SMBus devices which can't be detected reliably, and
117 * the ones which can always be enumerated in practice.
118 *
119 * The i2c_client structure which is handed to the @detect callback is
120 * not a real i2c_client. It is initialized just enough so that you can
121 * call i2c_smbus_read_byte_data and friends on it. Don't do anything
122 * else with it. In particular, calling dev_dbg and friends on it is
123 * not allowed.
104 */ 124 */
105
106struct i2c_driver { 125struct i2c_driver {
107 int id; 126 int id;
108 unsigned int class; 127 unsigned int class;
@@ -142,6 +161,11 @@ struct i2c_driver {
142 161
143 struct device_driver driver; 162 struct device_driver driver;
144 const struct i2c_device_id *id_table; 163 const struct i2c_device_id *id_table;
164
165 /* Device detection callback for automatic device creation */
166 int (*detect)(struct i2c_client *, int kind, struct i2c_board_info *);
167 const struct i2c_client_address_data *address_data;
168 struct list_head clients;
145}; 169};
146#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 170#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
147 171
@@ -157,6 +181,7 @@ struct i2c_driver {
157 * @dev: Driver model device node for the slave. 181 * @dev: Driver model device node for the slave.
158 * @irq: indicates the IRQ generated by this device (if any) 182 * @irq: indicates the IRQ generated by this device (if any)
159 * @list: list of active/busy clients (DEPRECATED) 183 * @list: list of active/busy clients (DEPRECATED)
184 * @detected: member of an i2c_driver.clients list
160 * @released: used to synchronize client releases & detaches and references 185 * @released: used to synchronize client releases & detaches and references
161 * 186 *
162 * An i2c_client identifies a single device (i.e. chip) connected to an 187 * An i2c_client identifies a single device (i.e. chip) connected to an
@@ -174,6 +199,7 @@ struct i2c_client {
174 struct device dev; /* the device structure */ 199 struct device dev; /* the device structure */
175 int irq; /* irq issued by device */ 200 int irq; /* irq issued by device */
176 struct list_head list; /* DEPRECATED */ 201 struct list_head list; /* DEPRECATED */
202 struct list_head detected;
177 struct completion released; 203 struct completion released;
178}; 204};
179#define to_i2c_client(d) container_of(d, struct i2c_client, dev) 205#define to_i2c_client(d) container_of(d, struct i2c_client, dev)