⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2c.h

📁 I2C总线LINUX驱动程序
💻 H
📖 第 1 页 / 共 2 页
字号:
/* ------------------------------------------------------------------------- *//* 									     *//* i2c.h - definitions for the i2c-bus interface			     *//* 									     *//* ------------------------------------------------------------------------- *//*   Copyright (C) 1995-2000 Simon G. Vogl    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.		     *//* ------------------------------------------------------------------------- *//* With some changes from Ky鰏ti M鋖kki <kmalkki@cc.hut.fi> and   Frodo Looijaard <frodol@dds.nl> *//* $Id: i2c.h,v 1.101 2006/02/15 01:40:46 phil Exp $ */#ifndef _LINUX_I2C_H#define _LINUX_I2C_H#define I2C_DATE "20060214"#define I2C_VERSION "2.10.0"/* You can set this to 0 if you patch i2c into your kernel tree   and have no i2c module that have been compiled using a   Linux-2.4-compatible i2c.h header file left.    As a result, you'll get a different code (can't really   say whether it's any better, but it's different). */#define I2C_LINUX_2_4_BINARY_COMPATIBILITY 1#include <linux/module.h>#include <linux/types.h>#include <linux/errno.h>#include <linux/sched.h>#include <asm/semaphore.h>#include "i2c-id.h"/* --- General options ------------------------------------------------	*/#define I2C_ADAP_MAX	16		/* control memory consumption	*/#define I2C_DRIVER_MAX	16#define I2C_CLIENT_MAX	32struct i2c_msg;struct i2c_algorithm;struct i2c_adapter;struct i2c_client;struct i2c_driver;struct i2c_client_address_data;union i2c_smbus_data;/* * The master routines are the ones normally used to transmit data to devices * on a bus (or read from them). Apart from two basic transfer functions to  * transmit one message at a time, a more complex version can be used to  * transmit an arbitrary number of messages without interruption. */extern int i2c_master_send(struct i2c_client *,const char* ,int);extern int i2c_master_recv(struct i2c_client *,char* ,int);/* Transfer num messages. */extern int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],int num);/* * Some adapter types (i.e. PCF 8584 based ones) may support slave behaviuor.  * This is not tested/implemented yet and will change in the future. */extern int i2c_slave_send(struct i2c_client *,char*,int);extern int i2c_slave_recv(struct i2c_client *,char*,int);/* This is the very generalized SMBus access routine. You probably do not   want to use this, though; one of the functions below may be much easier,   and probably just as fast.    Note that we use i2c_adapter here, because you do not need a specific   smbus adapter to call this function. */extern s32 i2c_smbus_xfer (struct i2c_adapter * adapter, u16 addr,                            unsigned short flags,                           char read_write, u8 command, int size,                           union i2c_smbus_data * data);/* Now follow the 'nice' access routines. These also document the calling   conventions of smbus_access. */extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value);extern s32 i2c_smbus_read_byte(struct i2c_client * client);extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value);extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command);extern s32 i2c_smbus_write_byte_data(struct i2c_client * client,                                     u8 command, u8 value);extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command);extern s32 i2c_smbus_write_word_data(struct i2c_client * client,                                     u8 command, u16 value);extern s32 i2c_smbus_process_call(struct i2c_client * client,                                  u8 command, u16 value);/* Returns the number of read bytes */extern s32 i2c_smbus_read_block_data(struct i2c_client * client,                                     u8 command, u8 *values);extern s32 i2c_smbus_write_block_data(struct i2c_client * client,                                      u8 command, u8 length,                                      u8 *values);/* Returns the number of read bytes */extern s32 i2c_smbus_read_i2c_block_data(struct i2c_client * client,                                         u8 command, u8 *values);extern s32 i2c_smbus_write_i2c_block_data(struct i2c_client * client,                                          u8 command, u8 length,                                          u8 *values);/* * A driver is capable of handling one or more physical devices present on * I2C adapters. This information is used to inform the driver of adapter * events. */struct i2c_driver {	char name[32];	int id;	unsigned int flags;		/* div., see below		*/	/* Notifies the driver that a new bus has appeared. This routine	 * can be used by the driver to test if the bus meets its conditions	 * & seek for the presence of the chip(s) it supports. If found, it 	 * registers the client(s) that are on the bus to the i2c admin. via	 * i2c_attach_client.	 */	int (*attach_adapter)(struct i2c_adapter *);	/* tells the driver that a client is about to be deleted & gives it 	 * the chance to remove its private data. Also, if the client struct	 * has been dynamically allocated by the driver in the function above,	 * it must be freed here.	 */	int (*detach_client)(struct i2c_client *);		/* a ioctl like command that can be used to perform specific functions	 * with the device.	 */	int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);		/* These two are used for bookkeeping & dynamic unloading of 	 * kernel modules. inc_use tells the driver that a client is being  	 * used by another module & that it should increase its ref. counter.	 * dec_use is the inverse operation.	 * NB: Make sure you have no circular dependencies, or else you get a 	 * deadlock when trying to unload the modules.	 * You should use the i2c_{inc,dec}_use_client functions instead of	 * calling this function directly.	 * Note that most clients won't need to implement these, only those	 * which have users inside the kernel (as opposed to only in	 * user-space through i2c-proc).	 */	void (*inc_use)(struct i2c_client *client);	void (*dec_use)(struct i2c_client *client);};/* * i2c_client identifies a single device (i.e. chip) that is connected to an  * i2c bus. The behaviour is defined by the routines of the driver. This * function is mainly used for lookup & other admin. functions. */struct i2c_client {	char name[32];	int id;	unsigned int flags;		/* div., see below		*/	unsigned int addr;		/* chip address - NOTE: 7bit 	*/					/* addresses are stored in the	*/					/* _LOWER_ 7 bits of this char	*/	/* addr: unsigned int to make lm_sensors i2c-isa adapter work	  more cleanly. It does not take any more memory space, due to	  alignment considerations */	struct i2c_adapter *adapter;	/* the adapter we sit on	*/	struct i2c_driver *driver;	/* and our access routines	*/	void *data;			/* for the clients		*/	int usage_count;		/* How many accesses currently  */					/* to the client		*/};/* * The following structs are for those who like to implement new bus drivers: * i2c_algorithm is the interface to a class of hardware solutions which can * be addressed using the same bus algorithms - i.e. bit-banging or the PCF8584 * to name two of the most common. */struct i2c_algorithm {	char name[32];				/* textual description 	*/	unsigned int id;	/* If an adapter algorithm can't do I2C-level access, set master_xfer	   to NULL. If an adapter algorithm can do SMBus access, set 	   smbus_xfer. If set to NULL, the SMBus protocol is simulated	   using common I2C messages */	int (*master_xfer)(struct i2c_adapter *adap,struct i2c_msg msgs[], 	                   int num);	int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr, 	                   unsigned short flags, char read_write,	                   u8 command, int size, union i2c_smbus_data * data);	/* --- these optional/future use for some adapter types.*/	int (*slave_send)(struct i2c_adapter *,char*,int);	int (*slave_recv)(struct i2c_adapter *,char*,int);	/* --- ioctl like call to set div. parameters. */	int (*algo_control)(struct i2c_adapter *, unsigned int, unsigned long);	/* To determine what the adapter supports */	u32 (*functionality) (struct i2c_adapter *);};/* * i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */struct i2c_adapter {	char name[32];	/* some useful name to identify the adapter	*/	unsigned int id;/* == is algo->id | hwdep.struct->id, 		*/			/* for registered values see below		*/	struct i2c_algorithm *algo;/* the algorithm to access the bus	*/	void *algo_data;	/* --- These may be NULL, but should increase the module use count */	void (*inc_use)(struct i2c_adapter *);	void (*dec_use)(struct i2c_adapter *);	/* --- administration stuff. */	int (*client_register)(struct i2c_client *);	int (*client_unregister)(struct i2c_client *);	void *data;	/* private data for the adapter			*/			/* some data fields that are used by all types	*/			/* these data fields are readonly to the public	*/			/* and can be set via the i2c_ioctl call	*/			/* data fields that are valid for all devices	*/	struct semaphore bus;#if !I2C_LINUX_2_4_BINARY_COMPATIBILITY	struct semaphore list;  #endif	unsigned int flags;/* flags specifying div. data		*/	struct i2c_client *clients[I2C_CLIENT_MAX];#if I2C_LINUX_2_4_BINARY_COMPATIBILITY	int client_count; /* not used anywhere */#endif	int timeout;	int retries;#ifdef CONFIG_PROC_FS 	/* No need to set this when you initialize the adapter          */	int inode;#endif /* def CONFIG_PROC_FS */};/*flags for the driver struct: */#define I2C_DF_NOTIFY	0x01		/* notify on bus (de/a)ttaches 	*/#define I2C_DF_DUMMY	0x02		/* do not connect any clients *//*flags for the client struct: */#define I2C_CLIENT_ALLOW_USE		0x01	/* Client allows access */#define I2C_CLIENT_ALLOW_MULTIPLE_USE 	0x02  	/* Allow multiple access-locks */						/* on an i2c_client */#define I2C_CLIENT_PEC  0x04			/* Use Packet Error Checking */#define I2C_CLIENT_TEN	0x10			/* we have a ten bit chip address	*/						/* Must equal I2C_M_TEN below *//* i2c_client_address_data is the struct for holding default client * addresses for a driver and for the parameters supplied on the * command line */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -