i2c: replace gdbus with direct implementation
[platform/core/api/peripheral-io.git] / include / interface / peripheral_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 __PERIPHERAL_INTERFACE_I2C_H__
18 #define __PERIPHERAL_INTERFACE_I2C_H__
19
20 #include "peripheral_interface_common.h"
21
22 #define I2C_BUFFER_MAX 64
23
24 #define I2C_SLAVE       0x0703  /* Use this slave address */
25 #define I2C_SMBUS       0x0720  /* SMBus transfer */
26
27 /* i2c_smbus_xfer read or write markers */
28 #define I2C_SMBUS_READ  1
29 #define I2C_SMBUS_WRITE 0
30
31 /* SMBus transaction types */
32 #define I2C_SMBUS_QUICK             0
33 #define I2C_SMBUS_BYTE              1
34 #define I2C_SMBUS_BYTE_DATA         2
35 #define I2C_SMBUS_WORD_DATA         3
36
37 /*
38  * Data for SMBus Messages
39  */
40 #define I2C_SMBUS_BLOCK_MAX     32      /* As specified in SMBus standard */
41
42 union i2c_smbus_data {
43         uint8_t byte;
44         uint16_t word;
45         uint8_t block[I2C_SMBUS_BLOCK_MAX + 2]; /* block[0] is used for length */
46                                /* and one more for user-space compatibility */
47 };
48
49 /* This is the structure as used in the I2C_SMBUS ioctl call */
50 struct i2c_smbus_ioctl_data {
51         uint8_t read_write;
52         uint8_t command;
53         uint32_t size;
54         union i2c_smbus_data *data;
55 };
56
57 void peripheral_interface_i2c_close(peripheral_i2c_h i2c);
58 int peripheral_interface_i2c_read(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
59 int peripheral_interface_i2c_write(peripheral_i2c_h i2c, uint8_t *data, uint32_t length);
60 int peripheral_interface_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t *data_out);
61 int peripheral_interface_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t reg, uint8_t data_in);
62 int peripheral_interface_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t *data_out);
63 int peripheral_interface_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t reg, uint16_t data_in);
64
65 #endif /* __PERIPHERAL_INTERFACE_I2C_H__ */