2 * Author: Robin Knight (robin.knight@roadnarrows.com)
4 * Copyright © 2009 RoadNarrows LLC.
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that
9 * (1) The above copyright notice and the following two paragraphs
10 * appear in all copies of the source code and (2) redistributions
11 * including binaries reproduces these notices in the supporting
12 * documentation. Substantial modifications to this software may be
13 * copyrighted by their authors and need not follow the licensing terms
14 * described here, provided that the new terms are clearly indicated in
15 * all files where they apply.
17 * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
18 * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
19 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
20 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
21 * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH DAMAGE.
24 * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
26 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
27 * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
28 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
37 #include <sys/types.h>
38 #include <sys/errno.h>
39 #include <sys/ioctl.h>
41 #include "linux/i2c-dev.h"
43 typedef union i2c_smbus_data_union
45 uint8_t byte; ///< data byte
46 unsigned short word; ///< data short word
47 uint8_t block[I2C_SMBUS_BLOCK_MAX + 2];
48 ///< block[0] is used for length and one more for PEC
51 typedef struct i2c_smbus_ioctl_data_struct
53 uint8_t read_write; ///< operation direction
54 uint8_t command; ///< ioctl command
55 int size; ///< data size
56 i2c_smbus_data_t *data; ///< data
57 } i2c_smbus_ioctl_data_t;
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 extern int i2c_smbus_access(int fd, uint8_t read_write, uint8_t command,
64 int size, i2c_smbus_data_t *data);
66 extern int i2c_smbus_write_quick(int fd, uint8_t value);
68 extern int i2c_smbus_read_byte(int fd);
70 extern int i2c_smbus_write_byte(int fd, uint8_t value);
72 extern int i2c_smbus_read_byte_data(int fd, uint8_t command);
74 extern int i2c_smbus_write_byte_data(int fd, uint8_t command, uint8_t value);
76 extern int i2c_smbus_read_word_data(int fd, uint8_t command);
78 extern int i2c_smbus_write_word_data(int fd, uint8_t command, unsigned short value);
80 extern int i2c_smbus_process_call(int fd, uint8_t command, unsigned short value);
82 extern int i2c_smbus_read_block_data(int fd, uint8_t command, uint8_t *values);
84 extern int i2c_smbus_write_block_data(int fd, uint8_t command, uint8_t length,
85 const uint8_t *values);
86 extern int i2c_smbus_read_i2c_block_data(int fd, uint8_t command,
89 extern int i2c_smbus_write_i2c_block_data(int fd, uint8_t command, uint8_t length,
90 const uint8_t *values);
92 extern int i2c_smbus_block_process_call(int fd, uint8_t command, uint8_t length,