/*
 * Copyright 2004 Freescale Semiconductor, Inc. All Rights Reserved.
 */

/* 
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 * 
 * http://www.opensource.org/licenses/gpl-license.html 
 * http://www.gnu.org/copyleft/gpl.html
 */

#ifndef MXC_I2C_H

#define MXC_I2C_H

/*!
 * @defgroup MXCI2C Inter-IC (I2C) Driver
 */

/*!
 * @file mxc_i2c.h
 * 
 * @brief This file contains the I2C chip level configuration details. 
 * 
 * It also contains the API function that other drivers can use to read/write
 * to the I2C device registers.
 * 
 * @ingroup MXCI2C
 */

/*!
 * This defines the number of I2C modules in the MXC platform
 */
#define I2C_NR                  3 
/*!
 * This defines the string used to identify MXC I2C Bus drivers
 */
#define MXC_ADAPTER_NAME        "MXC I2C Adapter"

/* I2C1 configuration */
/*!
 * This define specifies the frequency divider value to be written into
 * the I2C \b IFDR register.
 */
#define I2C1_FRQ_DIV            0x17

/* I2C2 configuration */
#define I2C2_FRQ_DIV            0x17
/* I2C3 configuration */
#define I2C3_FRQ_DIV            0x17

/*!
 * Function used to read the register of the i2c slave device. This function
 * is a kernel level API that can be called by other device drivers.
 *
 * @param   bus_id       the MXC I2C bus that the slave device is connected to
 *                       (0 based)
 * @param   addr         slave address of the device we wish to read data from
 * @param   *reg         register in the device we wish to access
 * @param   reg_len      number of bytes in the register address
 * @param   *buf         data buffer 
 * @param   num          number of data bytes to transfer
 *
 * @return  Function returns the number of messages transferred to/from the 
 *          device or a negative number on failure
 */
int mxc_i2c_read(int bus_id, unsigned int addr, char *reg, int reg_len, 
                 char *buf, int num);

/*!
 * Function used to write to the register of the i2c slave device. This function
 * is a kernel level API that can be called by other device drivers.
 *
 * @param   bus_id       the MXC I2C bus that the slave device is connected to
 *                       (0 based) 
 * @param   addr         slave address of the device we wish to write data to
 * @param   *reg         register in the device we wish to access
 * @param   reg_len      number of bytes in the register address
 * @param   *buf         data buffer 
 * @param   num          number of data bytes to transfer
 *
 * @return  Function returns the number of messages transferred to/from the 
 *          device or a negative number on failure
 */
int mxc_i2c_write(int bus_id, unsigned int addr, char *reg, int reg_len, 
                  char *buf, int num);

#endif /* MXC_I2C_H */
