/*
 * Copyright (c) 2020-2022, NVIDIA CORPORATION.  All rights reserved.
 *
 * NVIDIA CORPORATION and its licensors retain all intellectual property
 * and proprietary rights in and to this software, related documentation
 * and any modifications thereto.  Any use, reproduction, disclosure or
 * distribution of this software and related documentation without an express
 * license agreement from NVIDIA CORPORATION is strictly prohibited.
 */

#ifndef I2C__I2C_CONFIG_H
#define I2C__I2C_CONFIG_H
#define FSP__I2C__I2C_CONFIG_H                          1

/* Compiler headers */
#include <stdint.h>

/* Early FSP headers */

/* Hardware headers */

/* Late FSP headers */

/* Module-specific FSP headers */

/** @file i2c-config.h */

/*
 * Compile-time check for FSP header files
 *   Each FSP header file contains a signature unique to that file, and the
 *   FSP project.  The CT_ASSERT macro (contained in misc/ct-assert.h) can
 *   check for this signature.  If it does not exist, then the build will
 *   abort.
 *
 *   This is a trap for projects which have their own include files of the
 *   same names, but different contents.  This trap ensures that only the
 *   files from the FSP project, are built into the FSP source code.
 */

/**
 * @defgroup I2C_SUPPORTED_CLKS Clock rate macros
 * @brief Defines for clock rates corresponding to i2c modes
 * @{
 */
/** Standard Mode */
#define I2C_CLK_RATE_SM                 100000U
/** Fast Mode */
#define I2C_CLK_RATE_FM                 400000U
/** Fast Mode + */
#define I2C_CLK_RATE_FMPLUS             1000000U
/** High Speed Mode */
#define I2C_CLK_RATE_HS                 3400000U
/** @} */

// IWYU pragma: no_forward_declare i2c_xfer_msg
struct i2c_handle;
struct i2c_xfer_msg;
struct i2c_config_data;

#ifdef I2C_ASYNC_XFER
/**
 * Define callback function type for transfer completion.
 */
typedef void (*i2c_async_callback)(void *i2c_client_data,
                error_t xfer_ret);
#endif
/**
 * @struct i2c_config_data
 * @brief I2C controller and bus configuration data.
 *
 * @{
 */
struct i2c_config_data
{
/**
 * Controller clock rate in Hz. <br>
 *  Valid range - <100000, 4294967295>
 */
    uint32_t ctrl_clk_rate;
/**
 * Bus clock rate in Hz. <br>
 *  Standard Mode  - 100000 <br>
 *  Fast Mode      - 400000 <br>
 *  Fast Mode Plus - 1000000
 */
    uint32_t bus_clk_rate;
#ifdef CUSTOM_TIMING_PARAMS
/**
 * Interface timing prod setting parameter in us. <br>
 *  Valid ranges: <br>
 *  Standard Mode  - <4, 4294967295> <br>
 *  Fast Mode      - <0, 4294967295> <br>
 *  Fast Mode Plus - <0, 4294967295>
 */
    uint32_t thigh;
/**
 * Interface timing prod setting parameter in us. <br>
 *  Valid Ranges: <br>
 *  Standard Mode  - <4, 4294967295> <br>
 *  Fast Mode      - <0, 4294967295> <br>
 *  Fast Mode Plus - <0, 4294967295>
 */
    uint32_t tlow;
#endif
/**
 * High speed master code. <br>
 *  Valid range - <0, 4294967295>
 */
    uint32_t hs_master_code;
};
/** @} */

/**
 * @struct i2c_handle
 * @brief Contains all relevant data for an i2c controller.
 *
 * @{
 */
struct i2c_handle
{
/** ID of the controller. */
    uint32_t ctrl_id;
/** Function pointers for HW operations */
    struct i2c_hw_ops *hw_ops;
/** Configuration data specific to the HW */
    struct i2c_tegra_handle *hi2c_tegra;
/** State variable for pre-init sequence */
    bool pre_init_done;
/**
 * State of controller <br>
 *  Enabled - True <br>
 *  Disabled - False
 */
    bool enabled;
};
/** @} */

/**
 * @struct i2c_xfer_msg
 * @brief I2C transfer message structure contains the message information -
 * slave address, transfer flags, message data buffer and message length.
 *
 * @{
 */
struct i2c_xfer_msg
{
/** Slave address. It can be 7-bit or 10-bit address. */
    uint16_t dev_addr;
/**
 * Transfer flags. Multiple transfer flags can be combined with OR
 * operation. Check - SW Defined I2C Transfer flags section.
 */
    uint16_t xfer_flags;
/**
 * Length of the message. <br>
 * Valid range - <1, 512>
 */
    uint16_t buf_len;
/** Pointer to read message buffer. */
    uint8_t *prbuf;
/** Pointer to write message buffer. */
    const uint8_t *pwbuf;
};
/** @} */

#endif        /* FSP_I2C_I2C_CONFIG_H */
