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

Revision 3316, 13.5 KB (checked in by frodo, 15 years ago)

First part of Kyösti Mälkki's patches

* All i2c_bus_handle stuff has been removed
* i2c_probe is made somewhat more efficient and readable

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