This patch adds below I2C APIs.
- peripheral_i2c_read_register_byte()
- peripheral_i2c_write_register_byte()
- peripheral_i2c_read_register_word()
- peripheral_i2c_write_register_word()
igned-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
Change-Id: Ic0e96b4225b6596556b670487c905e6c77c4039c
int peripheral_gdbus_i2c_close(peripheral_i2c_h i2c);
int peripheral_gdbus_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
int peripheral_gdbus_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
+int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out);
#endif /* __PERIPHERAL_GDBUS_I2C_H__ */
int peripheral_i2c_close(peripheral_i2c_h i2c);
/**
- * @brief Reads data from the i2c device.
+ * @brief Reads data from the i2c slave device.
* @since_tizen 4.0
*
* @param[in] i2c The handle to the i2c device
int peripheral_i2c_read(peripheral_i2c_h i2c, uint8_t *data, int length);
/**
- * @brief Write data to the i2c device.
+ * @brief Write data to the i2c slave device.
* @since_tizen 4.0
*
* @param[in] i2c The handle to the i2c device
int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
/**
- * @brief Reads single byte data from the i2c device.
+ * @brief Reads single byte data from the i2c slave device.
* @since_tizen 4.0
*
* @param[in] i2c The handle to the i2c device
* @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
*/
int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data);
+
/**
- * @brief Write single byte data to the i2c device.
+ * @brief Write single byte data to the i2c slave device.
* @since_tizen 4.0
*
* @param[in] i2c The handle to the i2c device
*/
int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data);
+/**
+ * @brief Reads byte data from the register of i2c slave device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in] address The register address of the i2c slave device to read
+ * @param[out] data The byte output of slave device(register value)
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
+int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data);
+
+/**
+ * @brief Write byte data to the register of i2c slave device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in] address The register address of the i2c slave device to write
+ * @param[in] data The byte value to write
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
+int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data);
+
+/**
+ * @brief Reads word data from the register of i2c slave device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in] address The register address of the i2c slave device to read
+ * @param[out] data The word output(2 bytes) of slave device(register value)
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
+int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data);
+
+/**
+ * @brief Write byte data to the register of i2c slave device.
+ * @since_tizen 4.0
+ *
+ * @param[in] i2c The handle to the i2c device
+ * @param[in] address The register address of the i2c slave device to write
+ * @param[in] data The word(2 bytes) value to write
+ *
+ * @return 0 on success, otherwise a negative error value
+ * @retval #PERIPHERAL_ERROR_NONE Successful
+ * @retval #PERIPHERAL_ERROR_IO_ERROR I/O operation failed
+ * @retval #PERIPHERAL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #PERIPHERAL_ERROR_UNKNOWN Unknown internal error
+ */
+int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data);
+
/**
* @}
*/
return ret;
}
+
+int peripheral_gdbus_i2c_smbus_ioctl(peripheral_i2c_h i2c, uint8_t read_write, uint8_t command, uint32_t size, uint16_t data_in, uint16_t *data_out)
+{
+ GError *error = NULL;
+ peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+ if (i2c_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+ if (peripheral_io_gdbus_i2c_call_smbus_ioctl_sync(
+ i2c_proxy,
+ i2c->handle,
+ read_write,
+ command,
+ size,
+ data_in,
+ data_out,
+ &ret,
+ NULL,
+ &error) == FALSE) {
+ _E("Error in %s() : %s\n", __func__, error->message);
+ g_error_free(error);
+ return PERIPHERAL_ERROR_UNKNOWN;
+ }
+
+ return ret;
+}
#include "peripheral_common.h"
#include "peripheral_internal.h"
+/* i2c_smbus_xfer read or write markers */
+#define I2C_SMBUS_READ 1
+#define I2C_SMBUS_WRITE 0
+
+/* SMBus transaction types */
+#define I2C_SMBUS_QUICK 0
+#define I2C_SMBUS_BYTE 1
+#define I2C_SMBUS_BYTE_DATA 2
+#define I2C_SMBUS_WORD_DATA 3
+
int peripheral_i2c_open(int bus, int address, peripheral_i2c_h *i2c)
{
peripheral_i2c_h handle;
if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
ret = peripheral_gdbus_i2c_read(i2c, data, length);
- /*
- _D("I2C read data : ");
- for (int i = 0 ; i < length ; i++)
- _D("[%02x]", data[i]);
- */
+
return ret;
}
int peripheral_i2c_read_byte(peripheral_i2c_h i2c, uint8_t *data)
{
int ret = PERIPHERAL_ERROR_NONE;
+ uint16_t w_data, dummy = 0;
if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- ret = peripheral_gdbus_i2c_read(i2c, data, 0x1);
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, 0x0, I2C_SMBUS_BYTE, dummy, &w_data);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to read, ret : %d", ret);
+
+ *data = (uint8_t)w_data;
return ret;
}
int peripheral_i2c_write_byte(peripheral_i2c_h i2c, uint8_t data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+ uint16_t dummy = 0;
+
if (i2c == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
- return peripheral_gdbus_i2c_write(i2c, &data, 0x1);
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, dummy, I2C_SMBUS_BYTE, (uint16_t)data, &dummy);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Failed to read, ret : %d", ret);
+
+ return ret;
+}
+
+int peripheral_i2c_read_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t *data)
+{
+ int ret;
+ uint16_t w_data, dummy = 0;
+
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_BYTE_DATA, dummy, &w_data);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Smbus transaction failed, ret : %d", ret);
+
+ *data = (uint8_t)w_data;
+
+ return ret;
+}
+
+int peripheral_i2c_write_register_byte(peripheral_i2c_h i2c, uint8_t address, uint8_t data)
+{
+ int ret;
+ uint16_t dummy = 0;
+
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_BYTE_DATA, (uint16_t)data, &dummy);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Smbus transaction failed, ret : %d", ret);
+
+ return ret;
+}
+
+int peripheral_i2c_read_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t *data)
+{
+ int ret;
+ uint16_t dummy = 0, data_out;
+
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_READ, address, I2C_SMBUS_WORD_DATA, dummy, &data_out);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Smbus transaction failed, ret : %d", ret);
+
+ *data = data_out;
+
+ return ret;
+}
+
+int peripheral_i2c_write_register_word(peripheral_i2c_h i2c, uint8_t address, uint16_t data)
+{
+ int ret;
+ uint16_t dummy = 0;
+
+ ret = peripheral_gdbus_i2c_smbus_ioctl(i2c, I2C_SMBUS_WRITE, address, I2C_SMBUS_WORD_DATA, data, &dummy);
+ if (ret < PERIPHERAL_ERROR_NONE)
+ _E("Smbus transaction failed, ret : %d", ret);
+
+ return ret;
}
</arg>
<arg type="i" name="result" direction="out"/>
</method>
+ <method name="SmbusIoctl">
+ <arg type="u" name="handle" direction="in"/>
+ <arg type="y" name="read_write" direction="in"/>
+ <arg type="y" name="command" direction="in"/>
+ <arg type="u" name="size" direction="in"/>
+ <arg type="q" name="data_in" direction="in"/>
+ <arg type="q" name="data_out" direction="out"/>
+ <arg type="i" name="result" direction="out"/>
+ </method>
</interface>
<interface name="org.tizen.peripheral_io.pwm">
<method name="Open">