| 1 | /* ------------------------------------------------------------------------- */ |
|---|
| 2 | /* */ |
|---|
| 3 | /* i2c.h - definitions for the \iic-bus interface */ |
|---|
| 4 | /* */ |
|---|
| 5 | /* ------------------------------------------------------------------------- */ |
|---|
| 6 | /* Copyright (C) 1995 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 | #ifndef _I2C_H |
|---|
| 23 | #define _I2C_H |
|---|
| 24 | |
|---|
| 25 | #ifdef __KERNEL__ |
|---|
| 26 | |
|---|
| 27 | /* define spinlock to use spinlocks for sync., else use semaphores*/ |
|---|
| 28 | /*#define I2C_SPINLOCK*/ |
|---|
| 29 | |
|---|
| 30 | #ifdef I2C_SPINLOCK |
|---|
| 31 | #include <asm/spinlock.h> /* for spinlock_t */ |
|---|
| 32 | #else |
|---|
| 33 | #include <asm/page.h> /* Needed for 2.2 kernels */ |
|---|
| 34 | #include <asm/semaphore.h> |
|---|
| 35 | #endif |
|---|
| 36 | /* --- General options ------------------------------------------------ */ |
|---|
| 37 | |
|---|
| 38 | #define I2C_ALGO_MAX 4 /* control memory consumption */ |
|---|
| 39 | #define I2C_ADAP_MAX 16 |
|---|
| 40 | #define I2C_DRIVER_MAX 16 |
|---|
| 41 | #define I2C_CLIENT_MAX 32 |
|---|
| 42 | |
|---|
| 43 | struct i2c_msg; |
|---|
| 44 | struct i2c_algorithm; |
|---|
| 45 | struct i2c_adapter; |
|---|
| 46 | struct i2c_client; |
|---|
| 47 | struct i2c_driver; |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | /* |
|---|
| 51 | * 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 transmit |
|---|
| 53 | * one message at a time, a more complex version can be used to transmit an arbitrary |
|---|
| 54 | * number of messages without interruption. |
|---|
| 55 | */ |
|---|
| 56 | extern int i2c_master_send(struct i2c_client *,const char* ,int); |
|---|
| 57 | extern int i2c_master_recv(struct i2c_client *,char* ,int); |
|---|
| 58 | |
|---|
| 59 | /* Transfer num messages. |
|---|
| 60 | */ |
|---|
| 61 | extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],int num); |
|---|
| 62 | |
|---|
| 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 | /* |
|---|
| 74 | * I2C Message - could be used in the current interface to |
|---|
| 75 | */ |
|---|
| 76 | struct i2c_msg { |
|---|
| 77 | unsigned char addr; /* slave address */ |
|---|
| 78 | unsigned short flags; |
|---|
| 79 | #define I2C_M_TEN 0x10 /* we have a ten bit chip address */ |
|---|
| 80 | #define I2C_M_TEN0 0x10 /* herein lie the first 2 bits */ |
|---|
| 81 | #define I2C_M_TEN1 0x12 |
|---|
| 82 | #define I2C_M_TEN2 0x14 |
|---|
| 83 | #define I2C_M_TEN3 0x16 |
|---|
| 84 | #define I2C_M_TENMASK 0x06 |
|---|
| 85 | #define I2C_M_RD 0x01 |
|---|
| 86 | short len; /* msg length */ |
|---|
| 87 | char *buf; /* pointer to msg data */ |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | /* |
|---|
| 91 | * A driver is capable of handling one or more physical devices present on |
|---|
| 92 | * I2C adapters. This information is used to inform the driver of adapter |
|---|
| 93 | * events. |
|---|
| 94 | */ |
|---|
| 95 | |
|---|
| 96 | struct i2c_driver { |
|---|
| 97 | char name[32]; |
|---|
| 98 | int id; |
|---|
| 99 | unsigned int flags; /* div., see below */ |
|---|
| 100 | |
|---|
| 101 | /* notifies the driver that a new bus has appeared. This routine |
|---|
| 102 | * can be used by the driver to test if the bus meets its conditions |
|---|
| 103 | * & seek for the presence of the chip(s) it supports. If found, it |
|---|
| 104 | * registers the client(s) that are on the bus to the i2c admin. via |
|---|
| 105 | * i2c_attach_client |
|---|
| 106 | */ |
|---|
| 107 | int (*attach_adapter)(struct i2c_adapter *); |
|---|
| 108 | |
|---|
| 109 | /* tells the driver that a client is about to be deleted & gives it |
|---|
| 110 | * the chance to remove its private data. Also, if the client struct |
|---|
| 111 | * has been dynamically allocated by the driver in the function above, |
|---|
| 112 | * it must be freed here. |
|---|
| 113 | */ |
|---|
| 114 | int (*detach_client)(struct i2c_client *); |
|---|
| 115 | |
|---|
| 116 | /* a ioctl like command that can be used to perform specific functions |
|---|
| 117 | * with the device. |
|---|
| 118 | */ |
|---|
| 119 | int (*command)(struct i2c_client *client,unsigned int cmd, void *arg); |
|---|
| 120 | |
|---|
| 121 | /* These two are mainly used for bookkeeping & dynamic unloading of |
|---|
| 122 | * kernel modules. inc_use tells the driver that a client is being |
|---|
| 123 | * used by another module & that it should increase its ref. counter. |
|---|
| 124 | * dec_use is the inverse operation. |
|---|
| 125 | * NB: Make sure you have no circular dependencies, or else you get a |
|---|
| 126 | * deadlock when trying to unload the modules. |
|---|
| 127 | */ |
|---|
| 128 | void (*inc_use)(struct i2c_client *client); |
|---|
| 129 | void (*dec_use)(struct i2c_client *client); |
|---|
| 130 | }; |
|---|
| 131 | |
|---|
| 132 | /* |
|---|
| 133 | * i2c_client identifies a single device (i.e. chip) that is connected to an |
|---|
| 134 | * i2c bus. The behaviour is defined by the routines of the driver. This |
|---|
| 135 | * function is mainly used for lookup & other admin. functions. |
|---|
| 136 | */ |
|---|
| 137 | struct i2c_client { |
|---|
| 138 | char name[32]; |
|---|
| 139 | int id; |
|---|
| 140 | unsigned int flags; /* div., see below */ |
|---|
| 141 | unsigned char addr; /* chip address - NOTE: 7bit */ |
|---|
| 142 | /* addresses are stored in the */ |
|---|
| 143 | /* _LOWER_ 7 bits of this char */ |
|---|
| 144 | /* 10 bit addresses use the full*/ |
|---|
| 145 | /* 8 bits & the flags like in */ |
|---|
| 146 | /* i2c_msg */ |
|---|
| 147 | struct i2c_adapter *adapter; /* the adapter we sit on */ |
|---|
| 148 | struct i2c_driver *driver; /* and our access routines */ |
|---|
| 149 | void *data; /* for the clients */ |
|---|
| 150 | }; |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | /* |
|---|
| 154 | * The following structs are for those who like to implement new bus drivers: |
|---|
| 155 | * i2c_algorithm is the interface to a class of hardware solutions which can |
|---|
| 156 | * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584 |
|---|
| 157 | * to name two of the most common. |
|---|
| 158 | */ |
|---|
| 159 | struct i2c_algorithm { |
|---|
| 160 | char name[32]; /* textual description */ |
|---|
| 161 | unsigned int id; |
|---|
| 162 | /* |
|---|
| 163 | int (*master_send)(struct i2c_client *,const char*,int); |
|---|
| 164 | int (*master_recv)(struct i2c_client *,char*,int); |
|---|
| 165 | int (*master_comb)(struct i2c_client *,char*,const char*,int,int,int); |
|---|
| 166 | */ |
|---|
| 167 | int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg msgs[], int num); |
|---|
| 168 | |
|---|
| 169 | /* --- these optional/future use for some adapter types.*/ |
|---|
| 170 | int (*slave_send)(struct i2c_adapter *,char*,int); |
|---|
| 171 | int (*slave_recv)(struct i2c_adapter *,char*,int); |
|---|
| 172 | |
|---|
| 173 | /* --- ioctl like call to set div. parameters. */ |
|---|
| 174 | int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long); |
|---|
| 175 | |
|---|
| 176 | /* --- administration stuff. */ |
|---|
| 177 | int (*client_register)(struct i2c_client *); |
|---|
| 178 | int (*client_unregister)(struct i2c_client *); |
|---|
| 179 | }; |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | /* |
|---|
| 183 | * i2c_adapter is the structure used to identify a physical i2c bus along |
|---|
| 184 | * with the access algorithms necessary to access it. |
|---|
| 185 | */ |
|---|
| 186 | struct i2c_adapter { |
|---|
| 187 | char name[32]; /* some useful name to identify the adapter */ |
|---|
| 188 | unsigned int id;/* == is algo->id | hwdep.struct->id, */ |
|---|
| 189 | /* for registered values see below */ |
|---|
| 190 | struct i2c_algorithm *algo;/* the algorithm to access the bus */ |
|---|
| 191 | |
|---|
| 192 | void *data; /* private data for the adapter */ |
|---|
| 193 | /* some data fields that are used by all types */ |
|---|
| 194 | /* these data fields are readonly to the public */ |
|---|
| 195 | /* and can be set via the i2c_ioctl call */ |
|---|
| 196 | |
|---|
| 197 | /* data fields that are valid for all devices */ |
|---|
| 198 | #ifdef I2C_SPINLOCK |
|---|
| 199 | spinlock_t lock;/* used to access the adapter exclusively */ |
|---|
| 200 | unsigned long lockflags; |
|---|
| 201 | #else |
|---|
| 202 | struct semaphore lock; |
|---|
| 203 | #endif |
|---|
| 204 | unsigned int flags;/* flags specifying div. data */ |
|---|
| 205 | |
|---|
| 206 | struct i2c_client *clients[I2C_CLIENT_MAX]; |
|---|
| 207 | int client_count; |
|---|
| 208 | |
|---|
| 209 | int timeout; |
|---|
| 210 | int retries; |
|---|
| 211 | }; |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | /*flags for the driver struct: |
|---|
| 215 | */ |
|---|
| 216 | #define DF_NOTIFY 0x01 /* notify on bus (de/a)ttaches */ |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | /* ----- functions exported by i2c.o */ |
|---|
| 220 | |
|---|
| 221 | /* administration... |
|---|
| 222 | */ |
|---|
| 223 | extern int i2c_add_algorithm(struct i2c_algorithm *); |
|---|
| 224 | extern int i2c_del_algorithm(struct i2c_algorithm *); |
|---|
| 225 | |
|---|
| 226 | extern int i2c_add_adapter(struct i2c_adapter *); |
|---|
| 227 | extern int i2c_del_adapter(struct i2c_adapter *); |
|---|
| 228 | |
|---|
| 229 | extern int i2c_add_driver(struct i2c_driver *); |
|---|
| 230 | extern int i2c_del_driver(struct i2c_driver *); |
|---|
| 231 | |
|---|
| 232 | extern int i2c_attach_client(struct i2c_client *); |
|---|
| 233 | extern int i2c_detach_client(struct i2c_client *); |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | /* |
|---|
| 237 | * A utility function used in the attach-phase of drivers. Returns at the first address |
|---|
| 238 | * that acks in the given range. |
|---|
| 239 | */ |
|---|
| 240 | extern int i2c_probe(struct i2c_client *client, int low_addr, int hi_addr); |
|---|
| 241 | |
|---|
| 242 | /* An ioctl like call to set div. parameters of the adapter. |
|---|
| 243 | */ |
|---|
| 244 | extern int i2c_control(struct i2c_client *,unsigned int, unsigned long); |
|---|
| 245 | |
|---|
| 246 | /* This call returns a unique low identifier for each registered adapter, |
|---|
| 247 | * or -1 if the adapter was not regisitered. |
|---|
| 248 | */ |
|---|
| 249 | extern int i2c_adapter_id(struct i2c_adapter *adap); |
|---|
| 250 | |
|---|
| 251 | #endif /* __KERNEL__ */ |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | /* ----- commands for the ioctl like i2c_command call: |
|---|
| 255 | * note that additional calls are defined in the algorithm and hw |
|---|
| 256 | * dependent layers - these can be listed here, or see the |
|---|
| 257 | * corresponding header files. |
|---|
| 258 | */ |
|---|
| 259 | /* -> bit-adapter specific ioctls */ |
|---|
| 260 | #define I2C_RETRIES 0x0701 /* number times a device adress should */ |
|---|
| 261 | /* be polled when not acknowledging */ |
|---|
| 262 | #define I2C_TIMEOUT 0x0702 /* set timeout - call with int */ |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | /* this is for i2c-dev.c */ |
|---|
| 266 | #define I2C_SLAVE 0x0703 /* Change slave address */ |
|---|
| 267 | /* Attn.: Slave address is 7 bits long, */ |
|---|
| 268 | /* these are to be passed as the */ |
|---|
| 269 | /* lowest 7 bits in the arg. */ |
|---|
| 270 | /* for 10-bit addresses pass lower 8bits*/ |
|---|
| 271 | #define I2C_TENBIT 0x0704 /* with 0-3 as arg to this call */ |
|---|
| 272 | /* a value <0 resets to 7 bits */ |
|---|
| 273 | /* ... algo-bit.c recognizes */ |
|---|
| 274 | #define I2C_UDELAY 0x0705 /* set delay in microsecs between each */ |
|---|
| 275 | /* written byte (except address) */ |
|---|
| 276 | #define I2C_MDELAY 0x0706 /* millisec delay between written bytes */ |
|---|
| 277 | |
|---|
| 278 | #if 0 |
|---|
| 279 | #define I2C_ADDR 0x0707 /* Change adapter's \iic address */ |
|---|
| 280 | /* ...not supported by all adap's */ |
|---|
| 281 | |
|---|
| 282 | #define I2C_RESET 0x07fd /* reset adapter */ |
|---|
| 283 | #define I2C_CLEAR 0x07fe /* when lost, use to clear stale info */ |
|---|
| 284 | #define I2C_V_SLOW 0x07ff /* set jiffies delay call with int */ |
|---|
| 285 | |
|---|
| 286 | #define I2C_INTR 0x0708 /* Pass interrupt number - 2be impl. */ |
|---|
| 287 | |
|---|
| 288 | #endif |
|---|
| 289 | |
|---|
| 290 | /* |
|---|
| 291 | * ---- Driver types ----------------------------------------------------- |
|---|
| 292 | */ |
|---|
| 293 | |
|---|
| 294 | #define I2C_DRIVERID_MSP3400 1 |
|---|
| 295 | #define I2C_DRIVERID_TUNER 2 |
|---|
| 296 | #define I2C_DRIVERID_VIDEOTEXT 3 |
|---|
| 297 | #define I2C_DRIVERID_GL518SM 4 /* hardware monitor cpu temp. */ |
|---|
| 298 | #define I2C_DRIVERID_TEA6420 5 /* audio matrix switch */ |
|---|
| 299 | #define I2C_DRIVERID_TEA6415 6 /* video matrix switch */ |
|---|
| 300 | #define I2C_DRIVERID_TDA9840 7 /* stereo sound processor */ |
|---|
| 301 | #define I2C_DRIVERID_SAA7111 8 /* video input processor */ |
|---|
| 302 | #define I2C_DRIVERID_BT848 9 /* video input processor */ |
|---|
| 303 | |
|---|
| 304 | #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */ |
|---|
| 305 | #define I2C_DRIVERID_EXP1 0xF1 |
|---|
| 306 | #define I2C_DRIVERID_EXP2 0xF2 |
|---|
| 307 | #define I2C_DRIVERID_EXP3 0xF3 |
|---|
| 308 | |
|---|
| 309 | /* |
|---|
| 310 | * ---- Adapter types ---------------------------------------------------- |
|---|
| 311 | * |
|---|
| 312 | * First, we distinguish between several algorithms to access the hardware |
|---|
| 313 | * interface types, as a PCF 8584 needs other care than a bit adapter. |
|---|
| 314 | */ |
|---|
| 315 | |
|---|
| 316 | #define ALGO_NONE 0x000000 |
|---|
| 317 | #define ALGO_BIT 0x010000 /* bit style adapters */ |
|---|
| 318 | #define ALGO_PCF 0x020000 /* PCF 8584 style adapters */ |
|---|
| 319 | |
|---|
| 320 | #define ALGO_EXP 0x800000 /* experimental */ |
|---|
| 321 | |
|---|
| 322 | #define ALGO_MASK 0xff0000 /* Mask for algorithms */ |
|---|
| 323 | #define ALGO_SHIFT 0x10 /* right shift to get index values */ |
|---|
| 324 | |
|---|
| 325 | #define I2C_HW_ADAPS 0x10000 /* number of different hw implements per*/ |
|---|
| 326 | /* algorithm layer module */ |
|---|
| 327 | #define I2C_HW_MASK 0xffff /* space for indiv. hw implmentations */ |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | /* hw specific modules that are defined per algorithm layer |
|---|
| 331 | */ |
|---|
| 332 | |
|---|
| 333 | /* --- Bit algorithm adapters */ |
|---|
| 334 | #define HW_B_LP 0x00 /* Parallel port Philips style adapter */ |
|---|
| 335 | #define HW_B_LPC 0x01 /* Parallel port, over control reg. */ |
|---|
| 336 | #define HW_B_SER 0x02 /* Serial line interface */ |
|---|
| 337 | #define HW_B_ELV 0x03 /* ELV Card */ |
|---|
| 338 | #define HW_B_VELLE 0x04 /* Vellemann K8000 */ |
|---|
| 339 | #define HW_B_BT848 0x05 /* BT848 video boards */ |
|---|
| 340 | #define HW_B_WNV 0x06 /* Winnov Videums */ |
|---|
| 341 | #define HW_B_VIA 0x07 /* Via vt82c586b */ |
|---|
| 342 | |
|---|
| 343 | /* --- PCF 8584 based algorithms */ |
|---|
| 344 | #define HW_P_LP 0x00 /* Parallel port interface */ |
|---|
| 345 | #define HW_P_ISA 0x01 /* generic ISA Bus inteface card */ |
|---|
| 346 | #define HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */ |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | |
|---|
| 350 | |
|---|
| 351 | /* ----- I2C-DEV: char device interface stuff ------------------------- */ |
|---|
| 352 | |
|---|
| 353 | #define I2C_MAJOR 89 /* Device major number */ |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | # if LINUX_VERSION_CODE < 0x020100 |
|---|
| 357 | /* Hack to make this thing compile under 2.0.xx kernels |
|---|
| 358 | */ |
|---|
| 359 | |
|---|
| 360 | # ifdef MODULE |
|---|
| 361 | # define MODULE_AUTHOR(noone) |
|---|
| 362 | # define MODULE_DESCRIPTION(none) |
|---|
| 363 | # define MODULE_PARM(no,param) |
|---|
| 364 | # define MODULE_PARM_DESC(no,description) |
|---|
| 365 | # define EXPORT_SYMBOL(noexport) |
|---|
| 366 | # define EXPORT_NO_SYMBOLS |
|---|
| 367 | # endif |
|---|
| 368 | |
|---|
| 369 | # ifndef NULL |
|---|
| 370 | # define NULL ( (void *) 0 ) |
|---|
| 371 | # endif |
|---|
| 372 | #endif |
|---|
| 373 | |
|---|
| 374 | # ifndef ENODEV |
|---|
| 375 | # include <asm/errno.h> |
|---|
| 376 | # endif |
|---|
| 377 | #endif |
|---|