root/i2c/trunk/kernel/i2c.h @ 3320

Revision 3320, 13.9 KB (checked in by frodo, 14 years ago)

Yet another MOD_{INC,DEC}_USE_COUNT change

The {inc,dec}_use callbacks are moved from i2c_algorithm to i2c_adapter.
This makes much more sense: look at how they were implemented in
i2c-algo-bit and i2c-algo-pcf (ie. in their version of the adapter drivers!).

Also a few comments added to i2c.h, and removed the commented-out old
single-message i2c routines in i2c_adapter.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* ------------------------------------------------------------------------- */
2/*                                                                           */
3/* i2c.h - definitions for the \iic-bus interface                            */
4/*                                                                           */
5/* ------------------------------------------------------------------------- */
6/*   Copyright (C) 1995-1999 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
26#ifndef I2C_H
27#define I2C_H
28
29#ifdef __KERNEL__
30
31#include <asm/page.h>                   /* for 2.2.xx                   */
32#if LINUX_VERSION_CODE < 0x020019
33#include <linux/sched.h>
34#else
35#include <asm/semaphore.h>
36#endif
37
38/* --- General options ------------------------------------------------ */
39
40#define I2C_ALGO_MAX    4               /* control memory consumption   */
41#define I2C_ADAP_MAX    16
42#define I2C_DRIVER_MAX  16
43#define I2C_CLIENT_MAX  32
44
45struct i2c_msg;
46struct i2c_algorithm;
47struct i2c_adapter;
48struct i2c_client;
49struct i2c_driver;
50
51
52/*
53 * The master routines are the ones normally used to transmit data to devices
54 * on a bus (or read from them). Apart from two basic transfer functions to
55 * transmit one message at a time, a more complex version can be used to
56 * transmit an arbitrary number of messages without interruption.
57 */
58extern int i2c_master_send(struct i2c_client *,const char* ,int);
59extern int i2c_master_recv(struct i2c_client *,char* ,int);
60
61/* Transfer num messages.
62 */
63extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],int num);
64
65/* Two convenience functions: send bytes to/recv from a chip with 
66 * sending one byte of data first, normally a register address.
67 */
68extern int i2c_master_send_subadress(struct i2c_client *client,
69                                     const char *buf ,int count, int subadress);
70extern int i2c_master_recv_subadress(struct i2c_client *client,const char *buf,
71                                     int count, int subadress);
72
73
74/*
75 * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.
76 * This is not tested/implemented yet and will change in the future.
77 */
78extern int i2c_slave_send(struct i2c_client *,char*,int);
79extern int i2c_slave_recv(struct i2c_client *,char*,int);
80
81
82/*
83 * I2C Message - could be used in the current interface to
84 */
85struct i2c_msg {
86        unsigned char addr;     /* slave address                        */
87        unsigned short flags;           
88#define I2C_M_TEN       0x10    /* we have a ten bit chip address       */
89#define I2C_M_TEN0      0x10    /* herein lie the first 2 bits          */
90#define I2C_M_TEN1      0x12
91#define I2C_M_TEN2      0x14
92#define I2C_M_TEN3      0x16
93#define I2C_M_TENMASK   0x06
94#define I2C_M_RD        0x01
95        short len;              /* msg length                           */
96        char *buf;              /* pointer to msg data                  */
97};
98
99/*
100 * A driver is capable of handling one or more physical devices present on
101 * I2C adapters. This information is used to inform the driver of adapter
102 * events.
103 */
104
105struct i2c_driver {
106        char name[32];
107        int id;
108        unsigned int flags;             /* div., see below              */
109
110        /* Notifies the driver that a new bus has appeared. This routine
111         * can be used by the driver to test if the bus meets its conditions
112         * & seek for the presence of the chip(s) it supports. If found, it
113         * registers the client(s) that are on the bus to the i2c admin. via
114         * i2c_attach_client.
115         */
116        int (*attach_adapter)(struct i2c_adapter *);
117
118        /* tells the driver that a client is about to be deleted & gives it
119         * the chance to remove its private data. Also, if the client struct
120         * has been dynamically allocated by the driver in the function above,
121         * it must be freed here.
122         */
123        int (*detach_client)(struct i2c_client *);
124       
125        /* a ioctl like command that can be used to perform specific functions
126         * with the device.
127         */
128        int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
129       
130        /* These two are mainly used for bookkeeping & dynamic unloading of
131         * kernel modules. inc_use tells the driver that a client is being 
132         * used by another module & that it should increase its ref. counter.
133         * dec_use is the inverse operation.
134         * NB: Make sure you have no circular dependencies, or else you get a
135         * deadlock when trying to unload the modules.
136         * You should use the i2c_{inc,dec}_use_client functions instead of
137         * calling this function directly.
138         */
139        void (*inc_use)(struct i2c_client *client);
140        void (*dec_use)(struct i2c_client *client);
141};
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 */
148struct i2c_client {
149        char name[32];
150        int id;
151        unsigned int flags;             /* div., see below              */
152        unsigned char addr;             /* chip address - NOTE: 7bit    */
153                                        /* addresses are stored in the  */
154                                        /* _LOWER_ 7 bits of this char  */
155                                        /* 10 bit addresses use the full*/
156                                        /* 8 bits & the flags like in   */
157                                        /* i2c_msg                      */
158        struct i2c_adapter *adapter;    /* the adapter we sit on        */
159        struct i2c_driver *driver;      /* and our access routines      */
160        void *data;                     /* for the clients              */
161};
162
163
164/*
165 * The following structs are for those who like to implement new bus drivers:
166 * i2c_algorithm is the interface to a class of hardware solutions which can
167 * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584
168 * to name two of the most common.
169 */
170struct i2c_algorithm {
171        char name[32];                          /* textual description  */
172        unsigned int id;       
173        int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg msgs[], 
174                           int num);
175
176        /* --- these optional/future use for some adapter types.*/
177        int (*slave_send)(struct i2c_adapter *,char*,int);
178        int (*slave_recv)(struct i2c_adapter *,char*,int);
179
180        /* --- ioctl like call to set div. parameters. */
181        int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);
182
183        /* --- administration stuff. */
184        int (*client_register)(struct i2c_client *);
185        int (*client_unregister)(struct i2c_client *);
186
187};
188
189
190/*
191 * i2c_adapter is the structure used to identify a physical i2c bus along
192 * with the access algorithms necessary to access it.
193 */
194struct i2c_adapter {
195        char name[32];  /* some useful name to identify the adapter     */
196        unsigned int id;/* == is algo->id | hwdep.struct->id,           */
197                        /* for registered values see below              */
198        struct i2c_algorithm *algo;/* the algorithm to access the bus   */
199
200        /* --- These may be NULL, but should increase the module use count */
201        void (*inc_use)(struct i2c_adapter *);
202        void (*dec_use)(struct i2c_adapter *);
203
204        void *data;     /* private data for the adapter                 */
205                        /* some data fields that are used by all types  */
206                        /* these data fields are readonly to the public */
207                        /* and can be set via the i2c_ioctl call        */
208
209                        /* data fields that are valid for all devices   */
210        struct semaphore lock; 
211        unsigned int flags;/* flags specifying div. data                */
212
213        struct i2c_client *clients[I2C_CLIENT_MAX];
214        int client_count;
215
216        int timeout;
217        int retries;
218};
219
220
221/*flags for the driver struct:
222 */
223#define DF_NOTIFY       0x01            /* notify on bus (de/a)ttaches  */
224
225
226/* ----- functions exported by i2c.o */
227
228/* administration...
229 */
230extern int i2c_add_algorithm(struct i2c_algorithm *);
231extern int i2c_del_algorithm(struct i2c_algorithm *);
232
233extern int i2c_add_adapter(struct i2c_adapter *);
234extern int i2c_del_adapter(struct i2c_adapter *);
235
236extern int i2c_add_driver(struct i2c_driver *);
237extern int i2c_del_driver(struct i2c_driver *);
238
239extern int i2c_attach_client(struct i2c_client *);
240extern int i2c_detach_client(struct i2c_client *);
241
242/* Only call these if you grab a resource that makes unloading the
243   client and the adapter it is on completely impossible. Like when a
244   /proc directory is entered. */
245extern void i2c_inc_use_client(struct i2c_client *);
246extern void i2c_dec_use_client(struct i2c_client *);
247
248
249/*
250 * A utility function used in the attach-phase of drivers. Returns at the
251 * first address that acks in the given range.
252 */
253extern int i2c_probe(struct i2c_client *client, int low_addr, int hi_addr);
254
255/* An ioctl like call to set div. parameters of the adapter.
256 */
257extern int i2c_control(struct i2c_client *,unsigned int, unsigned long);
258
259/* This call returns a unique low identifier for each registered adapter,
260 * or -1 if the adapter was not regisitered.
261 */
262extern int i2c_adapter_id(struct i2c_adapter *adap);
263
264#endif /* __KERNEL__ */
265
266
267/* ----- commands for the ioctl like i2c_command call:
268 * note that additional calls are defined in the algorithm and hw
269 *      dependent layers - these can be listed here, or see the
270 *      corresponding header files.
271 */
272                                /* -> bit-adapter specific ioctls       */
273#define I2C_RETRIES     0x0701  /* number times a device adress should  */
274                                /* be polled when not acknowledging     */
275#define I2C_TIMEOUT     0x0702  /* set timeout - call with int          */
276
277
278/* this is for i2c-dev.c        */
279#define I2C_SLAVE       0x0703  /* Change slave address                 */
280                                /* Attn.: Slave address is 7 bits long, */
281                                /*      these are to be passed as the   */
282                                /*      lowest 7 bits in the arg.       */
283                                /* for 10-bit addresses pass lower 8bits*/
284#define I2C_TENBIT      0x0704  /*      with 0-3 as arg to this call    */
285                                /*      a value <0 resets to 7 bits     */
286
287#define I2C_ACK_TEST    0x0710  /* See if a slave is at a specific adress */
288
289/* ... algo-bit.c recognizes */
290#define I2C_UDELAY      0x0705  /* set delay in microsecs between each  */
291                                /* written byte (except address)        */
292#define I2C_MDELAY      0x0706  /* millisec delay between written bytes */
293
294
295
296
297/*
298 * ---- Driver types -----------------------------------------------------
299 *       device id name + number        function description, i2c address(es)
300 */
301
302#define I2C_DRIVERID_MSP3400     1
303#define I2C_DRIVERID_TUNER       2
304#define I2C_DRIVERID_VIDEOTEXT   3
305#define I2C_DRIVERID_GL518SM     4      /* hardware monitor cpu temp.   */
306#define I2C_DRIVERID_TEA6420     5      /* audio matrix switch          */
307#define I2C_DRIVERID_TEA6415C    6      /* video matrix switch          */
308#define I2C_DRIVERID_TDA9840     7      /* stereo sound processor       */
309#define I2C_DRIVERID_SAA7111A    8      /* video input processor        */
310#define I2C_DRIVERID_SAA5281     9      /* videotext decoder            */
311#define I2C_DRIVERID_SAA7112    10      /* video decoder, image scaler  */
312#define I2C_DRIVERID_SAA7120    11      /* video encoder                */
313#define I2C_DRIVERID_SAA7121    12      /* video encoder                */
314#define I2C_DRIVERID_SAA7185B   13      /* video encoder                */
315#define I2C_DRIVERID_CH7003     14      /* digital pc to tv encoder     */
316#define I2C_DRIVERID_PCF8574A   15      /* i2c expander - 8 bit in/out  */
317#define I2C_DRIVERID_PCF8582C   16      /* eeprom                       */
318#define I2C_DRIVERID_AT24Cxx    17      /* eeprom 1/2/4/8/16 K          */
319
320#define I2C_DRIVERID_EXP0       0xF0    /* experimental use id's        */
321#define I2C_DRIVERID_EXP1       0xF1
322#define I2C_DRIVERID_EXP2       0xF2
323#define I2C_DRIVERID_EXP3       0xF3
324
325                                        /* the 1000-1999 range is used by
326                                           the lm_sensor developers     */
327#define I2C_DRIVERID_I2CDEV     1000
328#define I2C_DRIVERID_I2CPROC    1001
329#define I2C_DRIVERID_LM78       1002
330#define I2C_DRIVERID_LM75       1003
331#define I2C_DRIVERID_GL518      1004
332#define I2C_DRIVERID_EEPROM     1005
333#define I2C_DRIVERID_W83781D    1006
334#define I2C_DRIVERID_LM80       1007
335#define I2C_DRIVERID_ADM1021    1008
336#define I2C_DRIVERID_ADM9240    1009
337#define I2C_DRIVERID_LTC1710    1010
338#define I2C_DRIVERID_BT848      1200
339
340/*
341 * ---- Adapter types ----------------------------------------------------
342 *
343 * First, we distinguish between several algorithms to access the hardware
344 * interface types, as a PCF 8584 needs other care than a bit adapter.
345 */
346
347#define I2C_ALGO_NONE   0x000000
348#define I2C_ALGO_BIT    0x010000        /* bit style adapters           */
349#define I2C_ALGO_PCF    0x020000        /* PCF 8584 style adapters      */
350#define I2C_ALGO_SMBUS  0x040000
351#define I2C_ALGO_ISA    0x050000
352#define I2C_ALGO_SAA7146A 0x060000      /* SAA 7146 video decoder bus   */
353
354
355#define I2C_ALGO_EXP    0x800000        /* experimental                 */
356
357#define I2C_ALGO_MASK   0xff0000        /* Mask for algorithms          */
358#define I2C_ALGO_SHIFT  0x10    /* right shift to get index values      */
359
360#define I2C_HW_ADAPS    0x10000         /* # adapter types              */
361#define I2C_HW_MASK     0xffff         
362
363
364/* hw specific modules that are defined per algorithm layer
365 */
366
367/* --- Bit algorithm adapters                                           */
368#define I2C_HW_B_LP     0x00    /* Parallel port Philips style adapter  */
369#define I2C_HW_B_LPC    0x01    /* Parallel port, over control reg.     */
370#define I2C_HW_B_SER    0x02    /* Serial line interface                */
371#define I2C_HW_B_ELV    0x03    /* ELV Card                             */
372#define I2C_HW_B_VELLE  0x04    /* Vellemann K8000                      */
373#define I2C_HW_B_BT848  0x05    /* BT848 video boards                   */
374#define I2C_HW_B_WNV    0x06    /* Winnov Videums                       */
375#define I2C_HW_B_VIA    0x07    /* Via vt82c586b                        */
376#define I2C_HW_B_HYDRA  0x08    /* Apple Hydra Mac I/O                  */
377
378/* --- PCF 8584 based algorithms                                        */
379#define I2C_HW_P_LP     0x00    /* Parallel port interface              */
380#define I2C_HW_P_ISA    0x01    /* generic ISA Bus inteface card        */
381#define I2C_HW_P_ELEK   0x02    /* Elektor ISA Bus inteface card        */
382
383
384
385
386/* ----- I2C-DEV: char device interface stuff ------------------------- */
387
388#define I2C_MAJOR       89              /* Device major number          */
389
390
391#  if LINUX_VERSION_CODE < 0x020100
392/* Hack to make this thing compile under 2.0.xx kernels
393 */
394
395#  ifdef MODULE
396#    define MODULE_AUTHOR(noone)
397#    define MODULE_DESCRIPTION(none)
398#    define MODULE_PARM(no,param)
399#    define MODULE_PARM_DESC(no,description)
400#    define EXPORT_SYMBOL(noexport)
401#    define EXPORT_NO_SYMBOLS
402#  endif
403
404#  ifndef NULL
405#    define NULL ( (void *) 0 )
406#  endif
407#endif
408
409#  ifndef ENODEV
410#    include <asm/errno.h>
411#  endif
412#endif /* I2C_H */
Note: See TracBrowser for help on using the browser.