Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ------------------------------------------------------------------------- */ |
| 2 | /* */ |
| 3 | /* i2c.h - definitions for the i2c-bus interface */ |
| 4 | /* */ |
| 5 | /* ------------------------------------------------------------------------- */ |
| 6 | /* Copyright (C) 1995-2000 Simon G. Vogl |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program; if not, write to the Free Software |
| 20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 21 | /* ------------------------------------------------------------------------- */ |
| 22 | |
| 23 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and |
| 24 | Frodo Looijaard <frodol@dds.nl> */ |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #ifndef _LINUX_I2C_H |
| 27 | #define _LINUX_I2C_H |
| 28 | |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/i2c-id.h> |
| 32 | #include <linux/device.h> /* for struct device */ |
| 33 | #include <asm/semaphore.h> |
| 34 | |
Jean Delvare | efde723 | 2005-07-20 23:03:50 +0200 | [diff] [blame] | 35 | /* --- For i2c-isa ---------------------------------------------------- */ |
| 36 | |
| 37 | extern void i2c_adapter_dev_release(struct device *dev); |
| 38 | extern struct device_driver i2c_adapter_driver; |
| 39 | extern struct class i2c_adapter_class; |
| 40 | extern struct bus_type i2c_bus_type; |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | /* --- General options ------------------------------------------------ */ |
| 43 | |
| 44 | struct i2c_msg; |
| 45 | struct i2c_algorithm; |
| 46 | struct i2c_adapter; |
| 47 | struct i2c_client; |
| 48 | struct i2c_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | union i2c_smbus_data; |
| 50 | |
| 51 | /* |
| 52 | * The master routines are the ones normally used to transmit data to devices |
| 53 | * 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 |
| 55 | * transmit an arbitrary number of messages without interruption. |
| 56 | */ |
| 57 | extern int i2c_master_send(struct i2c_client *,const char* ,int); |
| 58 | extern int i2c_master_recv(struct i2c_client *,char* ,int); |
| 59 | |
| 60 | /* Transfer num messages. |
| 61 | */ |
| 62 | extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num); |
| 63 | |
| 64 | /* |
| 65 | * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor. |
| 66 | * This is not tested/implemented yet and will change in the future. |
| 67 | */ |
| 68 | extern int i2c_slave_send(struct i2c_client *,char*,int); |
| 69 | extern int i2c_slave_recv(struct i2c_client *,char*,int); |
| 70 | |
| 71 | |
| 72 | |
| 73 | /* This is the very generalized SMBus access routine. You probably do not |
| 74 | want to use this, though; one of the functions below may be much easier, |
| 75 | and probably just as fast. |
| 76 | Note that we use i2c_adapter here, because you do not need a specific |
| 77 | smbus adapter to call this function. */ |
| 78 | extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr, |
| 79 | unsigned short flags, |
| 80 | char read_write, u8 command, int size, |
| 81 | union i2c_smbus_data * data); |
| 82 | |
| 83 | /* Now follow the 'nice' access routines. These also document the calling |
| 84 | conventions of smbus_access. */ |
| 85 | |
| 86 | extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value); |
| 87 | extern s32 i2c_smbus_read_byte(struct i2c_client * client); |
| 88 | extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value); |
| 89 | extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command); |
| 90 | extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, |
| 91 | u8 command, u8 value); |
| 92 | extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command); |
| 93 | extern s32 i2c_smbus_write_word_data(struct i2c_client * client, |
| 94 | u8 command, u16 value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | extern s32 i2c_smbus_write_block_data(struct i2c_client * client, |
| 96 | u8 command, u8 length, |
| 97 | u8 *values); |
Jean Delvare | 31ec5bc | 2005-10-08 00:04:13 +0200 | [diff] [blame^] | 98 | /* Returns the number of read bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client, |
| 100 | u8 command, u8 *values); |
| 101 | |
| 102 | /* |
| 103 | * A driver is capable of handling one or more physical devices present on |
| 104 | * I2C adapters. This information is used to inform the driver of adapter |
| 105 | * events. |
| 106 | */ |
| 107 | |
| 108 | struct i2c_driver { |
| 109 | struct module *owner; |
| 110 | char name[32]; |
| 111 | int id; |
| 112 | unsigned int class; |
| 113 | unsigned int flags; /* div., see below */ |
| 114 | |
| 115 | /* Notifies the driver that a new bus has appeared. This routine |
| 116 | * can be used by the driver to test if the bus meets its conditions |
| 117 | * & seek for the presence of the chip(s) it supports. If found, it |
| 118 | * registers the client(s) that are on the bus to the i2c admin. via |
| 119 | * i2c_attach_client. |
| 120 | */ |
| 121 | int (*attach_adapter)(struct i2c_adapter *); |
| 122 | int (*detach_adapter)(struct i2c_adapter *); |
| 123 | |
| 124 | /* tells the driver that a client is about to be deleted & gives it |
| 125 | * the chance to remove its private data. Also, if the client struct |
| 126 | * has been dynamically allocated by the driver in the function above, |
| 127 | * it must be freed here. |
| 128 | */ |
| 129 | int (*detach_client)(struct i2c_client *); |
| 130 | |
| 131 | /* a ioctl like command that can be used to perform specific functions |
| 132 | * with the device. |
| 133 | */ |
| 134 | int (*command)(struct i2c_client *client,unsigned int cmd, void *arg); |
| 135 | |
| 136 | struct device_driver driver; |
| 137 | struct list_head list; |
| 138 | }; |
| 139 | #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) |
| 140 | |
| 141 | #define I2C_NAME_SIZE 50 |
| 142 | |
| 143 | /* |
| 144 | * i2c_client identifies a single device (i.e. chip) that is connected to an |
| 145 | * i2c bus. The behaviour is defined by the routines of the driver. This |
| 146 | * function is mainly used for lookup & other admin. functions. |
| 147 | */ |
| 148 | struct i2c_client { |
| 149 | unsigned int flags; /* div., see below */ |
Jean Delvare | 5071860 | 2005-07-20 00:02:32 +0200 | [diff] [blame] | 150 | unsigned short addr; /* chip address - NOTE: 7bit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /* addresses are stored in the */ |
Jean Delvare | 5071860 | 2005-07-20 00:02:32 +0200 | [diff] [blame] | 152 | /* _LOWER_ 7 bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct i2c_adapter *adapter; /* the adapter we sit on */ |
| 154 | struct i2c_driver *driver; /* and our access routines */ |
| 155 | int usage_count; /* How many accesses currently */ |
| 156 | /* to the client */ |
| 157 | struct device dev; /* the device structure */ |
| 158 | struct list_head list; |
| 159 | char name[I2C_NAME_SIZE]; |
| 160 | struct completion released; |
| 161 | }; |
| 162 | #define to_i2c_client(d) container_of(d, struct i2c_client, dev) |
| 163 | |
bgardner@wabtec.com | a61fc68 | 2005-07-27 12:43:03 -0500 | [diff] [blame] | 164 | static inline struct i2c_client *kobj_to_i2c_client(struct kobject *kobj) |
| 165 | { |
| 166 | return to_i2c_client(container_of(kobj, struct device, kobj)); |
| 167 | } |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | static inline void *i2c_get_clientdata (struct i2c_client *dev) |
| 170 | { |
| 171 | return dev_get_drvdata (&dev->dev); |
| 172 | } |
| 173 | |
| 174 | static inline void i2c_set_clientdata (struct i2c_client *dev, void *data) |
| 175 | { |
| 176 | dev_set_drvdata (&dev->dev, data); |
| 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
| 180 | * The following structs are for those who like to implement new bus drivers: |
| 181 | * i2c_algorithm is the interface to a class of hardware solutions which can |
| 182 | * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584 |
| 183 | * to name two of the most common. |
| 184 | */ |
| 185 | struct i2c_algorithm { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* If an adapter algorithm can't do I2C-level access, set master_xfer |
| 187 | to NULL. If an adapter algorithm can do SMBus access, set |
| 188 | smbus_xfer. If set to NULL, the SMBus protocol is simulated |
| 189 | using common I2C messages */ |
| 190 | int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg *msgs, |
| 191 | int num); |
| 192 | int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, |
| 193 | unsigned short flags, char read_write, |
| 194 | u8 command, int size, union i2c_smbus_data * data); |
| 195 | |
| 196 | /* --- these optional/future use for some adapter types.*/ |
| 197 | int (*slave_send)(struct i2c_adapter *,char*,int); |
| 198 | int (*slave_recv)(struct i2c_adapter *,char*,int); |
| 199 | |
| 200 | /* --- ioctl like call to set div. parameters. */ |
| 201 | int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long); |
| 202 | |
| 203 | /* To determine what the adapter supports */ |
| 204 | u32 (*functionality) (struct i2c_adapter *); |
| 205 | }; |
| 206 | |
| 207 | /* |
| 208 | * i2c_adapter is the structure used to identify a physical i2c bus along |
| 209 | * with the access algorithms necessary to access it. |
| 210 | */ |
| 211 | struct i2c_adapter { |
| 212 | struct module *owner; |
Jean Delvare | 020789e | 2005-08-13 13:04:32 +0200 | [diff] [blame] | 213 | unsigned int id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | unsigned int class; |
| 215 | struct i2c_algorithm *algo;/* the algorithm to access the bus */ |
| 216 | void *algo_data; |
| 217 | |
| 218 | /* --- administration stuff. */ |
| 219 | int (*client_register)(struct i2c_client *); |
| 220 | int (*client_unregister)(struct i2c_client *); |
| 221 | |
| 222 | /* data fields that are valid for all devices */ |
| 223 | struct semaphore bus_lock; |
| 224 | struct semaphore clist_lock; |
| 225 | |
| 226 | int timeout; |
| 227 | int retries; |
| 228 | struct device dev; /* the adapter device */ |
| 229 | struct class_device class_dev; /* the class device */ |
| 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | int nr; |
| 232 | struct list_head clients; |
| 233 | struct list_head list; |
| 234 | char name[I2C_NAME_SIZE]; |
| 235 | struct completion dev_released; |
| 236 | struct completion class_dev_released; |
| 237 | }; |
| 238 | #define dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) |
| 239 | #define class_dev_to_i2c_adapter(d) container_of(d, struct i2c_adapter, class_dev) |
| 240 | |
| 241 | static inline void *i2c_get_adapdata (struct i2c_adapter *dev) |
| 242 | { |
| 243 | return dev_get_drvdata (&dev->dev); |
| 244 | } |
| 245 | |
| 246 | static inline void i2c_set_adapdata (struct i2c_adapter *dev, void *data) |
| 247 | { |
| 248 | dev_set_drvdata (&dev->dev, data); |
| 249 | } |
| 250 | |
| 251 | /*flags for the driver struct: */ |
| 252 | #define I2C_DF_NOTIFY 0x01 /* notify on bus (de/a)ttaches */ |
| 253 | #if 0 |
| 254 | /* this flag is gone -- there is a (optional) driver->detach_adapter |
| 255 | * callback now which can be used instead */ |
| 256 | # define I2C_DF_DUMMY 0x02 |
| 257 | #endif |
| 258 | |
| 259 | /*flags for the client struct: */ |
| 260 | #define I2C_CLIENT_ALLOW_USE 0x01 /* Client allows access */ |
| 261 | #define I2C_CLIENT_ALLOW_MULTIPLE_USE 0x02 /* Allow multiple access-locks */ |
| 262 | /* on an i2c_client */ |
| 263 | #define I2C_CLIENT_PEC 0x04 /* Use Packet Error Checking */ |
| 264 | #define I2C_CLIENT_TEN 0x10 /* we have a ten bit chip address */ |
| 265 | /* Must equal I2C_M_TEN below */ |
| 266 | |
| 267 | /* i2c adapter classes (bitmask) */ |
| 268 | #define I2C_CLASS_HWMON (1<<0) /* lm_sensors, ... */ |
| 269 | #define I2C_CLASS_TV_ANALOG (1<<1) /* bttv + friends */ |
| 270 | #define I2C_CLASS_TV_DIGITAL (1<<2) /* dvb cards */ |
| 271 | #define I2C_CLASS_DDC (1<<3) /* i2c-matroxfb ? */ |
| 272 | #define I2C_CLASS_CAM_ANALOG (1<<4) /* camera with analog CCD */ |
| 273 | #define I2C_CLASS_CAM_DIGITAL (1<<5) /* most webcams */ |
| 274 | #define I2C_CLASS_SOUND (1<<6) /* sound devices */ |
| 275 | #define I2C_CLASS_ALL (UINT_MAX) /* all of the above */ |
| 276 | |
| 277 | /* i2c_client_address_data is the struct for holding default client |
| 278 | * addresses for a driver and for the parameters supplied on the |
| 279 | * command line |
| 280 | */ |
| 281 | struct i2c_client_address_data { |
| 282 | unsigned short *normal_i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | unsigned short *probe; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | unsigned short *ignore; |
Jean Delvare | 9fc6adf | 2005-07-31 21:20:43 +0200 | [diff] [blame] | 285 | unsigned short **forces; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | /* Internal numbers to terminate lists */ |
| 289 | #define I2C_CLIENT_END 0xfffeU |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* The numbers to use to set I2C bus address */ |
| 292 | #define ANY_I2C_BUS 0xffff |
| 293 | #define ANY_I2C_ISA_BUS 9191 |
| 294 | |
| 295 | |
| 296 | /* ----- functions exported by i2c.o */ |
| 297 | |
| 298 | /* administration... |
| 299 | */ |
| 300 | extern int i2c_add_adapter(struct i2c_adapter *); |
| 301 | extern int i2c_del_adapter(struct i2c_adapter *); |
| 302 | |
| 303 | extern int i2c_add_driver(struct i2c_driver *); |
| 304 | extern int i2c_del_driver(struct i2c_driver *); |
| 305 | |
| 306 | extern int i2c_attach_client(struct i2c_client *); |
| 307 | extern int i2c_detach_client(struct i2c_client *); |
| 308 | |
| 309 | /* New function: This is to get an i2c_client-struct for controlling the |
| 310 | client either by using i2c_control-function or having the |
| 311 | client-module export functions that can be used with the i2c_client |
| 312 | -struct. */ |
| 313 | extern struct i2c_client *i2c_get_client(int driver_id, int adapter_id, |
| 314 | struct i2c_client *prev); |
| 315 | |
| 316 | /* Should be used with new function |
| 317 | extern struct i2c_client *i2c_get_client(int,int,struct i2c_client *); |
| 318 | to make sure that client-struct is valid and that it is okay to access |
| 319 | the i2c-client. |
| 320 | returns -EACCES if client doesn't allow use (default) |
| 321 | returns -EBUSY if client doesn't allow multiple use (default) and |
| 322 | usage_count >0 */ |
| 323 | extern int i2c_use_client(struct i2c_client *); |
| 324 | extern int i2c_release_client(struct i2c_client *); |
| 325 | |
| 326 | /* call the i2c_client->command() of all attached clients with |
| 327 | * the given arguments */ |
| 328 | extern void i2c_clients_command(struct i2c_adapter *adap, |
| 329 | unsigned int cmd, void *arg); |
| 330 | |
| 331 | /* returns -EBUSY if address has been taken, 0 if not. Note that the only |
| 332 | other place at which this is called is within i2c_attach_client; so |
| 333 | you can cheat by simply not registering. Not recommended, of course! */ |
| 334 | extern int i2c_check_addr (struct i2c_adapter *adapter, int addr); |
| 335 | |
| 336 | /* Detect function. It iterates over all possible addresses itself. |
| 337 | * It will only call found_proc if some client is connected at the |
| 338 | * specific address (unless a 'force' matched); |
| 339 | */ |
| 340 | extern int i2c_probe(struct i2c_adapter *adapter, |
| 341 | struct i2c_client_address_data *address_data, |
| 342 | int (*found_proc) (struct i2c_adapter *, int, int)); |
| 343 | |
| 344 | /* An ioctl like call to set div. parameters of the adapter. |
| 345 | */ |
| 346 | extern int i2c_control(struct i2c_client *,unsigned int, unsigned long); |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | extern struct i2c_adapter* i2c_get_adapter(int id); |
| 349 | extern void i2c_put_adapter(struct i2c_adapter *adap); |
| 350 | |
| 351 | |
| 352 | /* Return the functionality mask */ |
| 353 | static inline u32 i2c_get_functionality(struct i2c_adapter *adap) |
| 354 | { |
| 355 | return adap->algo->functionality(adap); |
| 356 | } |
| 357 | |
| 358 | /* Return 1 if adapter supports everything we need, 0 if not. */ |
| 359 | static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func) |
| 360 | { |
| 361 | return (func & i2c_get_functionality(adap)) == func; |
| 362 | } |
| 363 | |
Jean Delvare | cdcb192 | 2005-07-28 23:09:40 +0200 | [diff] [blame] | 364 | /* Return id number for a specific adapter */ |
| 365 | static inline int i2c_adapter_id(struct i2c_adapter *adap) |
| 366 | { |
| 367 | return adap->nr; |
| 368 | } |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* |
| 371 | * I2C Message - used for pure i2c transaction, also from /dev interface |
| 372 | */ |
| 373 | struct i2c_msg { |
| 374 | __u16 addr; /* slave address */ |
| 375 | __u16 flags; |
| 376 | #define I2C_M_TEN 0x10 /* we have a ten bit chip address */ |
| 377 | #define I2C_M_RD 0x01 |
| 378 | #define I2C_M_NOSTART 0x4000 |
| 379 | #define I2C_M_REV_DIR_ADDR 0x2000 |
| 380 | #define I2C_M_IGNORE_NAK 0x1000 |
| 381 | #define I2C_M_NO_RD_ACK 0x0800 |
| 382 | __u16 len; /* msg length */ |
| 383 | __u8 *buf; /* pointer to msg data */ |
| 384 | }; |
| 385 | |
| 386 | /* To determine what functionality is present */ |
| 387 | |
| 388 | #define I2C_FUNC_I2C 0x00000001 |
| 389 | #define I2C_FUNC_10BIT_ADDR 0x00000002 |
| 390 | #define I2C_FUNC_PROTOCOL_MANGLING 0x00000004 /* I2C_M_{REV_DIR_ADDR,NOSTART,..} */ |
| 391 | #define I2C_FUNC_SMBUS_HWPEC_CALC 0x00000008 /* SMBus 2.0 */ |
| 392 | #define I2C_FUNC_SMBUS_READ_WORD_DATA_PEC 0x00000800 /* SMBus 2.0 */ |
| 393 | #define I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC 0x00001000 /* SMBus 2.0 */ |
| 394 | #define I2C_FUNC_SMBUS_PROC_CALL_PEC 0x00002000 /* SMBus 2.0 */ |
| 395 | #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL_PEC 0x00004000 /* SMBus 2.0 */ |
| 396 | #define I2C_FUNC_SMBUS_BLOCK_PROC_CALL 0x00008000 /* SMBus 2.0 */ |
| 397 | #define I2C_FUNC_SMBUS_QUICK 0x00010000 |
| 398 | #define I2C_FUNC_SMBUS_READ_BYTE 0x00020000 |
| 399 | #define I2C_FUNC_SMBUS_WRITE_BYTE 0x00040000 |
| 400 | #define I2C_FUNC_SMBUS_READ_BYTE_DATA 0x00080000 |
| 401 | #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA 0x00100000 |
| 402 | #define I2C_FUNC_SMBUS_READ_WORD_DATA 0x00200000 |
| 403 | #define I2C_FUNC_SMBUS_WRITE_WORD_DATA 0x00400000 |
| 404 | #define I2C_FUNC_SMBUS_PROC_CALL 0x00800000 |
| 405 | #define I2C_FUNC_SMBUS_READ_BLOCK_DATA 0x01000000 |
| 406 | #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA 0x02000000 |
| 407 | #define I2C_FUNC_SMBUS_READ_I2C_BLOCK 0x04000000 /* I2C-like block xfer */ |
| 408 | #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 0x08000000 /* w/ 1-byte reg. addr. */ |
| 409 | #define I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 0x10000000 /* I2C-like block xfer */ |
| 410 | #define I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2 0x20000000 /* w/ 2-byte reg. addr. */ |
| 411 | #define I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC 0x40000000 /* SMBus 2.0 */ |
| 412 | #define I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC 0x80000000 /* SMBus 2.0 */ |
| 413 | |
| 414 | #define I2C_FUNC_SMBUS_BYTE (I2C_FUNC_SMBUS_READ_BYTE | \ |
| 415 | I2C_FUNC_SMBUS_WRITE_BYTE) |
| 416 | #define I2C_FUNC_SMBUS_BYTE_DATA (I2C_FUNC_SMBUS_READ_BYTE_DATA | \ |
| 417 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA) |
| 418 | #define I2C_FUNC_SMBUS_WORD_DATA (I2C_FUNC_SMBUS_READ_WORD_DATA | \ |
| 419 | I2C_FUNC_SMBUS_WRITE_WORD_DATA) |
| 420 | #define I2C_FUNC_SMBUS_BLOCK_DATA (I2C_FUNC_SMBUS_READ_BLOCK_DATA | \ |
| 421 | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA) |
| 422 | #define I2C_FUNC_SMBUS_I2C_BLOCK (I2C_FUNC_SMBUS_READ_I2C_BLOCK | \ |
| 423 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK) |
| 424 | #define I2C_FUNC_SMBUS_I2C_BLOCK_2 (I2C_FUNC_SMBUS_READ_I2C_BLOCK_2 | \ |
| 425 | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK_2) |
| 426 | #define I2C_FUNC_SMBUS_BLOCK_DATA_PEC (I2C_FUNC_SMBUS_READ_BLOCK_DATA_PEC | \ |
| 427 | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC) |
| 428 | #define I2C_FUNC_SMBUS_WORD_DATA_PEC (I2C_FUNC_SMBUS_READ_WORD_DATA_PEC | \ |
| 429 | I2C_FUNC_SMBUS_WRITE_WORD_DATA_PEC) |
| 430 | |
| 431 | #define I2C_FUNC_SMBUS_READ_BYTE_PEC I2C_FUNC_SMBUS_READ_BYTE_DATA |
| 432 | #define I2C_FUNC_SMBUS_WRITE_BYTE_PEC I2C_FUNC_SMBUS_WRITE_BYTE_DATA |
| 433 | #define I2C_FUNC_SMBUS_READ_BYTE_DATA_PEC I2C_FUNC_SMBUS_READ_WORD_DATA |
| 434 | #define I2C_FUNC_SMBUS_WRITE_BYTE_DATA_PEC I2C_FUNC_SMBUS_WRITE_WORD_DATA |
| 435 | #define I2C_FUNC_SMBUS_BYTE_PEC I2C_FUNC_SMBUS_BYTE_DATA |
| 436 | #define I2C_FUNC_SMBUS_BYTE_DATA_PEC I2C_FUNC_SMBUS_WORD_DATA |
| 437 | |
| 438 | #define I2C_FUNC_SMBUS_EMUL (I2C_FUNC_SMBUS_QUICK | \ |
| 439 | I2C_FUNC_SMBUS_BYTE | \ |
| 440 | I2C_FUNC_SMBUS_BYTE_DATA | \ |
| 441 | I2C_FUNC_SMBUS_WORD_DATA | \ |
| 442 | I2C_FUNC_SMBUS_PROC_CALL | \ |
| 443 | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA | \ |
| 444 | I2C_FUNC_SMBUS_WRITE_BLOCK_DATA_PEC | \ |
| 445 | I2C_FUNC_SMBUS_I2C_BLOCK) |
| 446 | |
| 447 | /* |
| 448 | * Data for SMBus Messages |
| 449 | */ |
| 450 | #define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */ |
| 451 | #define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */ |
| 452 | union i2c_smbus_data { |
| 453 | __u8 byte; |
| 454 | __u16 word; |
Hideki Iwamoto | 332bf92 | 2005-09-25 16:56:43 +0200 | [diff] [blame] | 455 | __u8 block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* and one more for PEC */ |
| 457 | }; |
| 458 | |
| 459 | /* smbus_access read or write markers */ |
| 460 | #define I2C_SMBUS_READ 1 |
| 461 | #define I2C_SMBUS_WRITE 0 |
| 462 | |
| 463 | /* SMBus transaction types (size parameter in the above functions) |
| 464 | Note: these no longer correspond to the (arbitrary) PIIX4 internal codes! */ |
| 465 | #define I2C_SMBUS_QUICK 0 |
| 466 | #define I2C_SMBUS_BYTE 1 |
| 467 | #define I2C_SMBUS_BYTE_DATA 2 |
| 468 | #define I2C_SMBUS_WORD_DATA 3 |
| 469 | #define I2C_SMBUS_PROC_CALL 4 |
| 470 | #define I2C_SMBUS_BLOCK_DATA 5 |
| 471 | #define I2C_SMBUS_I2C_BLOCK_DATA 6 |
| 472 | #define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */ |
| 473 | #define I2C_SMBUS_BLOCK_DATA_PEC 8 /* SMBus 2.0 */ |
| 474 | #define I2C_SMBUS_PROC_CALL_PEC 9 /* SMBus 2.0 */ |
| 475 | #define I2C_SMBUS_BLOCK_PROC_CALL_PEC 10 /* SMBus 2.0 */ |
| 476 | #define I2C_SMBUS_WORD_DATA_PEC 11 /* SMBus 2.0 */ |
| 477 | |
| 478 | |
| 479 | /* ----- commands for the ioctl like i2c_command call: |
| 480 | * note that additional calls are defined in the algorithm and hw |
| 481 | * dependent layers - these can be listed here, or see the |
| 482 | * corresponding header files. |
| 483 | */ |
| 484 | /* -> bit-adapter specific ioctls */ |
| 485 | #define I2C_RETRIES 0x0701 /* number of times a device address */ |
| 486 | /* should be polled when not */ |
| 487 | /* acknowledging */ |
| 488 | #define I2C_TIMEOUT 0x0702 /* set timeout - call with int */ |
| 489 | |
| 490 | |
| 491 | /* this is for i2c-dev.c */ |
| 492 | #define I2C_SLAVE 0x0703 /* Change slave address */ |
| 493 | /* Attn.: Slave address is 7 or 10 bits */ |
| 494 | #define I2C_SLAVE_FORCE 0x0706 /* Change slave address */ |
| 495 | /* Attn.: Slave address is 7 or 10 bits */ |
| 496 | /* This changes the address, even if it */ |
| 497 | /* is already taken! */ |
| 498 | #define I2C_TENBIT 0x0704 /* 0 for 7 bit addrs, != 0 for 10 bit */ |
| 499 | |
| 500 | #define I2C_FUNCS 0x0705 /* Get the adapter functionality */ |
| 501 | #define I2C_RDWR 0x0707 /* Combined R/W transfer (one stop only)*/ |
| 502 | #define I2C_PEC 0x0708 /* != 0 for SMBus PEC */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | #define I2C_SMBUS 0x0720 /* SMBus-level access */ |
| 505 | |
| 506 | /* ... algo-bit.c recognizes */ |
| 507 | #define I2C_UDELAY 0x0705 /* set delay in microsecs between each */ |
| 508 | /* written byte (except address) */ |
| 509 | #define I2C_MDELAY 0x0706 /* millisec delay between written bytes */ |
| 510 | |
| 511 | /* ----- I2C-DEV: char device interface stuff ------------------------- */ |
| 512 | |
| 513 | #define I2C_MAJOR 89 /* Device major number */ |
| 514 | |
| 515 | /* These defines are used for probing i2c client addresses */ |
| 516 | /* The length of the option lists */ |
| 517 | #define I2C_CLIENT_MAX_OPTS 48 |
| 518 | |
| 519 | /* Default fill of many variables */ |
| 520 | #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 521 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 522 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 523 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 524 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 525 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 526 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 527 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 528 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 529 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 530 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 531 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 532 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 533 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 534 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ |
| 535 | I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END} |
| 536 | |
| 537 | /* I2C_CLIENT_MODULE_PARM creates a module parameter, and puts it in the |
| 538 | module header */ |
| 539 | |
| 540 | #define I2C_CLIENT_MODULE_PARM(var,desc) \ |
| 541 | static unsigned short var[I2C_CLIENT_MAX_OPTS] = I2C_CLIENT_DEFAULTS; \ |
| 542 | static unsigned int var##_num; \ |
| 543 | module_param_array(var, short, &var##_num, 0); \ |
| 544 | MODULE_PARM_DESC(var,desc) |
| 545 | |
Jean Delvare | f4b5026 | 2005-07-31 21:49:03 +0200 | [diff] [blame] | 546 | #define I2C_CLIENT_MODULE_PARM_FORCE(name) \ |
| 547 | I2C_CLIENT_MODULE_PARM(force_##name, \ |
| 548 | "List of adapter,address pairs which are " \ |
| 549 | "unquestionably assumed to contain a `" \ |
| 550 | # name "' chip") |
| 551 | |
| 552 | |
| 553 | #define I2C_CLIENT_INSMOD_COMMON \ |
| 554 | I2C_CLIENT_MODULE_PARM(probe, "List of adapter,address pairs to scan " \ |
| 555 | "additionally"); \ |
| 556 | I2C_CLIENT_MODULE_PARM(ignore, "List of adapter,address pairs not to " \ |
| 557 | "scan"); \ |
| 558 | static struct i2c_client_address_data addr_data = { \ |
| 559 | .normal_i2c = normal_i2c, \ |
| 560 | .probe = probe, \ |
| 561 | .ignore = ignore, \ |
| 562 | .forces = forces, \ |
| 563 | } |
| 564 | |
| 565 | /* These are the ones you want to use in your own drivers. Pick the one |
| 566 | which matches the number of devices the driver differenciates between. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | #define I2C_CLIENT_INSMOD \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | I2C_CLIENT_MODULE_PARM(force, \ |
| 569 | "List of adapter,address pairs to boldly assume " \ |
| 570 | "to be present"); \ |
Jean Delvare | f4b5026 | 2005-07-31 21:49:03 +0200 | [diff] [blame] | 571 | static unsigned short *forces[] = { \ |
Jean Delvare | 9fc6adf | 2005-07-31 21:20:43 +0200 | [diff] [blame] | 572 | force, \ |
| 573 | NULL \ |
| 574 | }; \ |
Jean Delvare | f4b5026 | 2005-07-31 21:49:03 +0200 | [diff] [blame] | 575 | I2C_CLIENT_INSMOD_COMMON |
| 576 | |
| 577 | #define I2C_CLIENT_INSMOD_1(chip1) \ |
| 578 | enum chips { any_chip, chip1 }; \ |
| 579 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 580 | "boldly assume to be present"); \ |
| 581 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 582 | static unsigned short *forces[] = { force, force_##chip1, NULL }; \ |
| 583 | I2C_CLIENT_INSMOD_COMMON |
| 584 | |
| 585 | #define I2C_CLIENT_INSMOD_2(chip1, chip2) \ |
| 586 | enum chips { any_chip, chip1, chip2 }; \ |
| 587 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 588 | "boldly assume to be present"); \ |
| 589 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 590 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 591 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 592 | force_##chip2, NULL }; \ |
| 593 | I2C_CLIENT_INSMOD_COMMON |
| 594 | |
| 595 | #define I2C_CLIENT_INSMOD_3(chip1, chip2, chip3) \ |
| 596 | enum chips { any_chip, chip1, chip2, chip3 }; \ |
| 597 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 598 | "boldly assume to be present"); \ |
| 599 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 600 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 601 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 602 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 603 | force_##chip2, force_##chip3, \ |
| 604 | NULL }; \ |
| 605 | I2C_CLIENT_INSMOD_COMMON |
| 606 | |
| 607 | #define I2C_CLIENT_INSMOD_4(chip1, chip2, chip3, chip4) \ |
| 608 | enum chips { any_chip, chip1, chip2, chip3, chip4 }; \ |
| 609 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 610 | "boldly assume to be present"); \ |
| 611 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 612 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 613 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 614 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ |
| 615 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 616 | force_##chip2, force_##chip3, \ |
| 617 | force_##chip4, NULL}; \ |
| 618 | I2C_CLIENT_INSMOD_COMMON |
| 619 | |
| 620 | #define I2C_CLIENT_INSMOD_5(chip1, chip2, chip3, chip4, chip5) \ |
| 621 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5 }; \ |
| 622 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 623 | "boldly assume to be present"); \ |
| 624 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 625 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 626 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 627 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ |
| 628 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ |
| 629 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 630 | force_##chip2, force_##chip3, \ |
| 631 | force_##chip4, force_##chip5, \ |
| 632 | NULL }; \ |
| 633 | I2C_CLIENT_INSMOD_COMMON |
| 634 | |
| 635 | #define I2C_CLIENT_INSMOD_6(chip1, chip2, chip3, chip4, chip5, chip6) \ |
| 636 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6 }; \ |
| 637 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 638 | "boldly assume to be present"); \ |
| 639 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 640 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 641 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 642 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ |
| 643 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ |
| 644 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ |
| 645 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 646 | force_##chip2, force_##chip3, \ |
| 647 | force_##chip4, force_##chip5, \ |
| 648 | force_##chip6, NULL }; \ |
| 649 | I2C_CLIENT_INSMOD_COMMON |
| 650 | |
| 651 | #define I2C_CLIENT_INSMOD_7(chip1, chip2, chip3, chip4, chip5, chip6, chip7) \ |
| 652 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ |
| 653 | chip7 }; \ |
| 654 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 655 | "boldly assume to be present"); \ |
| 656 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 657 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 658 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 659 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ |
| 660 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ |
| 661 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ |
| 662 | I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ |
| 663 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 664 | force_##chip2, force_##chip3, \ |
| 665 | force_##chip4, force_##chip5, \ |
| 666 | force_##chip6, force_##chip7, \ |
| 667 | NULL }; \ |
| 668 | I2C_CLIENT_INSMOD_COMMON |
| 669 | |
| 670 | #define I2C_CLIENT_INSMOD_8(chip1, chip2, chip3, chip4, chip5, chip6, chip7, chip8) \ |
| 671 | enum chips { any_chip, chip1, chip2, chip3, chip4, chip5, chip6, \ |
| 672 | chip7, chip8 }; \ |
| 673 | I2C_CLIENT_MODULE_PARM(force, "List of adapter,address pairs to " \ |
| 674 | "boldly assume to be present"); \ |
| 675 | I2C_CLIENT_MODULE_PARM_FORCE(chip1); \ |
| 676 | I2C_CLIENT_MODULE_PARM_FORCE(chip2); \ |
| 677 | I2C_CLIENT_MODULE_PARM_FORCE(chip3); \ |
| 678 | I2C_CLIENT_MODULE_PARM_FORCE(chip4); \ |
| 679 | I2C_CLIENT_MODULE_PARM_FORCE(chip5); \ |
| 680 | I2C_CLIENT_MODULE_PARM_FORCE(chip6); \ |
| 681 | I2C_CLIENT_MODULE_PARM_FORCE(chip7); \ |
| 682 | I2C_CLIENT_MODULE_PARM_FORCE(chip8); \ |
| 683 | static unsigned short *forces[] = { force, force_##chip1, \ |
| 684 | force_##chip2, force_##chip3, \ |
| 685 | force_##chip4, force_##chip5, \ |
| 686 | force_##chip6, force_##chip7, \ |
| 687 | force_##chip8, NULL }; \ |
| 688 | I2C_CLIENT_INSMOD_COMMON |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | #endif /* _LINUX_I2C_H */ |