/*******************************************************************************
* DISCLAIMER
* This software is supplied by Renesas Electronics Corporation and is only
* intended for use with Renesas products. No other uses are authorized. This
* software is owned by Renesas Electronics Corporation and is protected under
* all applicable laws, including copyright laws.
* THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
* THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
* LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
* TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
* ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
* FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
* ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
* BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* Renesas reserves the right, without notice, to make changes to this software
* and to discontinue the availability of this software. By using this software,
* you agree to the additional terms and conditions found by accessing the
* following link:
* http://www.renesas.com/disclaimer
* Copyright 2018-2023 Renesas Electronics Corporation All rights reserved.
*******************************************************************************/



/*******************************************************************************
 * DESCRIPTION   : IP's control function
 ******************************************************************************/
/******************************************************************************
 * @file          ip_control.c
 * - Version      : 0.08
 * @brief         Initial setting controller.
 * .
 *****************************************************************************/
/******************************************************************************
 * History : DD.MM.YYYY Version  Description
 *         : 30.11.2021 0.01     First Release
 *         : 18.01.2022 0.02     Changed log output
 *                               Supported Generic Timer
 *         : 22.03.2022 0.03     Removed unnecessary header file inclusions
 *                               Removed unnecessary functions
 *         : 10.05.2022 0.04     Added function return value judgment
 *         : 16.06.2022 0.05     Change log output
 *         : 02.08.2022 0.06     Added SWDT and GIC
 *         : 31.10.2022 0.07     License notation change.
 *         : 04.09.2023 0.08     Add C4 power domain setting.
 *         : 13.10.2023 0.09     Moved C4 power domain setting to ICUMX IPL.
 *****************************************************************************/
#include <scif.h>
#include <ip_control.h>
#include <emmc_boot.h>
#include <emmc_def.h>
#include <timer.h>
#include <log.h>
#include "gic.h"
#include "swdt.h"
#if (1 == (MEASURE_TIME))
	#include <scmt.h>
	#include <scmt_checkpoint.h>
#else
  #define scmt_wait_ticks(x)
  #define store_time_checkpoint(x,y)
#endif

void ip_init(void)
{
    scif_init();
    generic_timer_init();

#if (RCAR_LSI == RCAR_S4)
    Interrupt_Config();
    Interrupt_Enable(INTC_SPI_SWDT);
    swdt_init();
#endif /* RCAR_LSI == RCAR_S4 */
#ifndef MOBIS_PRK3
    emmc_initialize();
    store_time_checkpoint("emmc_initialize", 0);
#endif
}
/* End of function ip_init(void) */

void ip_release(void)
{
#if (BL2_LOAD_ENABLE == BL2_DISABLE)
    EMMC_ERROR_CODE result = EMMC_ERR;

    result = emmc_terminate();
    if(EMMC_SUCCESS != result)
    {
        ERROR("ip_release error (emmc_terminate).\n");
        panic;
    }
#endif

#if (RCAR_LSI == RCAR_S4)
    swdt_release();
    Interrupt_Disable(INTC_SPI_SWDT);
#endif /* RCAR_LSI == RCAR_S4 */
}
/* End of function ip_release(void) */
