/*
 * Copyright (c) 2018 Renesas Electronics Corporation. All rights reserved.
 */


#include "reg_rcargen3.h"
#include "common.h"
#include "scifdrv0.h"
#include "scifdrv3.h"
#include "init_scif.h"
#include "hscifdrv0.h"


void InitScif(void)
{
	uint32_t product;
	uint32_t modemr0;
	uint32_t modemr1;

	product = *((volatile uint32_t*)PRR) & PRR_PRODUCT_MASK;
	switch (product) {
	case PRR_PRODUCT_S4:
		modemr0 = *((volatile uint32_t*)RST_MODEMR0) & MODEMR0_MD31_GEN4;	/* bit31 */
		modemr1 = *((volatile uint32_t*)RST_MODEMR1) & MODEMR1_MD32_GEN4;	/* bit0  */
		switch (modemr0 | modemr1) {
		case MODEMR_SCIF_115200_GEN4:	/* 0x00000000 */
			InitScif3_SCIFCLK();
			break;
		case MODEMR_SCIF_921600_GEN4:	/* 0x80000000 */
		case MODEMR_SCIF_1843200_GEN4:	/* 0x00000001 */
		case MODEMR_SCIF_3000000_GEN4:	/* 0x80000001 */
			InitHscif0_SCIFCLK();
			break;
		default:
			break;
		}
	case PRR_PRODUCT_V4H:
	case PRR_PRODUCT_V4M:
		modemr0 = *((volatile uint32_t*)RST_MODEMR0) & MODEMR0_MD31_GEN4;	/* bit31 */
		modemr1 = *((volatile uint32_t*)RST_MODEMR1) & MODEMR1_MD32_GEN4;	/* bit0  */
		switch (modemr0 | modemr1) {
		case MODEMR_SCIF_115200_GEN4:	/* 0x00000000 */
			InitScif0_SCIFCLK();
			break;
		case MODEMR_SCIF_921600_GEN4:	/* 0x80000000 */
		case MODEMR_SCIF_1843200_GEN4:	/* 0x00000001 */
		case MODEMR_SCIF_3000000_GEN4:	/* 0x80000001 */
			InitHscif0_SCIFCLK();
			break;
		default:
			break;
		}
	default:
		break;
	}
}
