2 i2c-dev.h - i2c-bus driver, char device interface
4 Copyright (C) 1995-97 Simon G. Vogl
5 Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* $Id: i2c-dev.h,v 1.9 2001/08/15 03:04:58 mds Exp $ */
28 #include <linux/types.h>
29 #include <linux/i2c.h>
31 /* Some IOCTL commands are defined in <linux/i2c.h> */
32 /* Note: 10-bit addresses are NOT supported! */
34 /* This is the structure as used in the I2C_SMBUS ioctl call */
35 struct i2c_smbus_ioctl_data {
39 union i2c_smbus_data *data;
42 /* This is the structure as used in the I2C_RDWR ioctl call */
43 struct i2c_rdwr_ioctl_data {
44 struct i2c_msg *msgs; /* pointers to i2c_msgs */
45 __u32 nmsgs; /* number of i2c_msgs */
50 #include <sys/ioctl.h>
52 static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command,
53 int size, union i2c_smbus_data *data)
55 struct i2c_smbus_ioctl_data args;
57 args.read_write = read_write;
58 args.command = command;
61 return ioctl(file,I2C_SMBUS,&args);
65 static inline __s32 i2c_smbus_write_quick(int file, __u8 value)
67 return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
70 static inline __s32 i2c_smbus_read_byte(int file)
72 union i2c_smbus_data data;
73 if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data))
76 return 0x0FF & data.byte;
79 static inline __s32 i2c_smbus_write_byte(int file, __u8 value)
81 return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
85 static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command)
87 union i2c_smbus_data data;
88 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
89 I2C_SMBUS_BYTE_DATA,&data))
92 return 0x0FF & data.byte;
95 static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
98 union i2c_smbus_data data;
100 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
101 I2C_SMBUS_BYTE_DATA, &data);
104 static inline __s32 i2c_smbus_read_word_data(int file, __u8 command)
106 union i2c_smbus_data data;
107 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
108 I2C_SMBUS_WORD_DATA,&data))
111 return 0x0FFFF & data.word;
114 static inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
117 union i2c_smbus_data data;
119 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
120 I2C_SMBUS_WORD_DATA, &data);
123 static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
125 union i2c_smbus_data data;
127 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
128 I2C_SMBUS_PROC_CALL,&data))
131 return 0x0FFFF & data.word;
135 /* Returns the number of read bytes */
136 static inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
139 union i2c_smbus_data data;
141 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
142 I2C_SMBUS_BLOCK_DATA,&data))
145 for (i = 1; i <= data.block[0]; i++)
146 values[i-1] = data.block[i];
147 return data.block[0];
151 static inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
152 __u8 length, __u8 *values)
154 union i2c_smbus_data data;
158 for (i = 1; i <= length; i++)
159 data.block[i] = values[i-1];
160 data.block[0] = length;
161 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
162 I2C_SMBUS_BLOCK_DATA, &data);
165 static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command,
166 __u8 length, __u8 *values)
168 union i2c_smbus_data data;
172 for (i = 1; i <= length; i++)
173 data.block[i] = values[i-1];
174 data.block[0] = length;
175 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
176 I2C_SMBUS_I2C_BLOCK_DATA, &data);
179 #endif /* ndef __KERNEL__ */