More Makefile cleanups, otherwise mainly noticeable are the netfilter fix
[davej-history.git] / include / linux / i2c-dev.h
blob39ed2adfa56e30f08ac8ac6727c72094525eaaff
1 /*
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.7 2000/02/15 17:57:27 frodo Exp $ */
24 #ifndef I2C_DEV_H
25 #define I2C_DEV_H
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 {
36 char read_write;
37 __u8 command;
38 int size;
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 int nmsgs; /* number of i2c_msgs */
48 #ifndef __KERNEL__
50 #include <sys/ioctl.h>
52 extern 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;
59 args.size = size;
60 args.data = data;
61 return ioctl(file,I2C_SMBUS,&args);
65 extern inline __s32 i2c_smbus_write_quick(int file, __u8 value)
67 return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL);
70 extern 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))
74 return -1;
75 else
76 return 0x0FF & data.byte;
79 extern inline __s32 i2c_smbus_write_byte(int file, __u8 value)
81 return i2c_smbus_access(file,I2C_SMBUS_WRITE,value,
82 I2C_SMBUS_BYTE,NULL);
85 extern 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))
90 return -1;
91 else
92 return 0x0FF & data.byte;
95 extern inline __s32 i2c_smbus_write_byte_data(int file, __u8 command,
96 __u8 value)
98 union i2c_smbus_data data;
99 data.byte = value;
100 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
101 I2C_SMBUS_BYTE_DATA, &data);
104 extern 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))
109 return -1;
110 else
111 return 0x0FFFF & data.word;
114 extern inline __s32 i2c_smbus_write_word_data(int file, __u8 command,
115 __u16 value)
117 union i2c_smbus_data data;
118 data.word = value;
119 return i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
120 I2C_SMBUS_WORD_DATA, &data);
123 extern inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value)
125 union i2c_smbus_data data;
126 data.word = value;
127 if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command,
128 I2C_SMBUS_PROC_CALL,&data))
129 return -1;
130 else
131 return 0x0FFFF & data.word;
135 /* Returns the number of read bytes */
136 extern inline __s32 i2c_smbus_read_block_data(int file, __u8 command,
137 __u8 *values)
139 union i2c_smbus_data data;
140 int i;
141 if (i2c_smbus_access(file,I2C_SMBUS_READ,command,
142 I2C_SMBUS_BLOCK_DATA,&data))
143 return -1;
144 else {
145 for (i = 1; i <= data.block[0]; i++)
146 values[i-1] = data.block[i];
147 return data.block[0];
151 extern inline __s32 i2c_smbus_write_block_data(int file, __u8 command,
152 __u8 length, __u8 *values)
154 union i2c_smbus_data data;
155 int i;
156 if (length > 32)
157 length = 32;
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 #endif /* ndef __KERNEL__ */
167 #endif