interface: move interface header files to top level include folder.
[platform/core/api/peripheral-io.git] / include / interface / i2c.h
1 /*
2  * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __I2C_H__
18 #define __I2C_H__
19
20 #include <stdint.h>
21
22 #define SYSFS_I2C_DIR "/dev/i2c"
23 #define I2C_BUFFER_MAX 64
24
25 #define I2C_SLAVE       0x0703  /* Use this slave address */
26 #define I2C_SMBUS       0x0720  /* SMBus transfer */
27
28 /* i2c_smbus_xfer read or write markers */
29 #define I2C_SMBUS_READ  1
30 #define I2C_SMBUS_WRITE 0
31
32 /* SMBus transaction types */
33 #define I2C_SMBUS_QUICK             0
34 #define I2C_SMBUS_BYTE              1
35 #define I2C_SMBUS_BYTE_DATA         2
36 #define I2C_SMBUS_WORD_DATA         3
37
38 /*
39  * Data for SMBus Messages
40  */
41 #define I2C_SMBUS_BLOCK_MAX     32      /* As specified in SMBus standard */
42
43 union i2c_smbus_data {
44         uint8_t byte;
45         uint16_t word;
46         uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
47                                /* and one more for user-space compatibility */
48 };
49
50 /* This is the structure as used in the I2C_SMBUS ioctl call */
51 struct i2c_smbus_ioctl_data {
52         uint8_t read_write;
53         uint8_t command;
54         uint32_t size;
55         union i2c_smbus_data *data;
56 };
57
58 int i2c_open(int bus, int *fd);
59 int i2c_close(int fd);
60 int i2c_set_address(int fd, int address);
61 int i2c_read(int fd, unsigned char *data, int length);
62 int i2c_write(int fd, const unsigned char *data, int length);
63 int i2c_smbus_ioctl(int fd, struct i2c_smbus_ioctl_data *data);
64
65 #endif/* __I2C_H__ */