/*-----------------------------------------------------------------------------------
!
!                              COPYRIGHT 2015 BY
!                            MegaChips Corporation
!
!------------------------------------------------------------------------------------
! These coded instructions, statements, and computer programs include
! intellectual property and know-how belonging to MegaChips
! Corporaiton ("MCC") and its partner companies.
! Therefore, do not use these specifications for any purpose other than
! the purpose
! expressly agreed to by MCCs customer and MCC.  Also, do not duplicate,
! copy,
! or reproduce these specifications, nor reveal these specifications to
! any third party
! without MCCs prior written consent.
!
*/

/*-----------------------------------------------------------------------------------
  FILE        : ctl_reg.h
  DESCRIPTION : CTL Register
  Revision    : $Rev: 4 $
  Author      : $Author: shirait $
  Date        : $Date: 2015-09-09 15:19:58 +0900 (豌ｴ, 09 9 2015) $
-----------------------------------------------------------------------------------*/
#ifndef ___CTL_REG_H_INCLUDED___
#define ___CTL_REG_H_INCLUDED___

#include <stdint.h>


/*
	公開レジスタ関連
*/
typedef struct _tagLts3Reg {

	uint32_t latency_time;
	uint32_t lim_area;
	uint32_t cup_version;
	uint32_t cup_version_h;
	uint32_t lts3_version;
	uint32_t  sel_sec;
	uint32_t  sel_t1_key;
	uint32_t  sel_key;
	uint32_t  selclk;
	uint32_t reserve6[7];

} LTS3Reg;


/*
	Security IP関連
*/
typedef struct _TagSipReg {

	uint32_t sip_int;
	uint32_t t2_ckey[4];
	uint32_t t2_iv[4];
	uint32_t set_tx_sec;
	uint32_t t1_key[4];
	uint32_t cv_en;
	uint32_t pm;
	uint32_t temper_en;
	uint32_t set_sec;
	uint32_t sec_rdy;
	uint32_t  sel_sec;
	uint32_t  t1_ukey[4];

} SipReg;


/*
	Local関連
*/
typedef struct _TagLocalReg {

	// 00A0h
	uint32_t fifo_clr;

	// 00A4h
	uint32_t ip_resb;

	// 00A8h
	uint32_t sl_cyc;

	// 00ACh
	uint32_t awake_cyc;

	// 00B0h
	uint32_t standby2_cyc;

	// 00B4h
	uint32_t standby2;

	// 00B8h
	uint16_t step;
	uint8_t  nclk;
	uint8_t  multf;

	// 00BCh
	uint32_t  otp_test_blk;

	// 00C0h
	uint32_t lazy;


	// 00C4h
	uint32_t reserve8[3];

} LocalReg;





/*
	eMMC関連
*/
typedef struct _TagMMC {
	uint32_t ctl_int60;
	uint32_t ctl_ack60;
	uint32_t ctl_int63;
	uint32_t ctl_ack63;
	uint32_t reserve5[4];
	uint32_t busy;
	uint32_t busy_ack;
	uint32_t block_count;
	uint32_t rw;
	uint32_t stop;
	uint32_t sec_req;
	uint32_t sec_ack;
	uint32_t cv_int[4];
	uint32_t aes_sk[4];
	uint32_t aes_iv[4];
	uint32_t cc_error;
	uint32_t error;
	uint32_t lts3_error;
	uint32_t lts3_error_detail;
	uint32_t state9_now;
	uint32_t cv[4];
	uint32_t reserve17[4];
}MMCReg;


/*
	L1関連
*/
typedef struct _TagL1Reg {
	uint32_t rsa_d[64];  // Read不可
	uint8_t soc_oaep_label[32];
	uint32_t soc_cv_fix[4];
	uint32_t t2_oaep_label[8];
	uint32_t t2_cv_fix[4];
	uint32_t fw_sk[4];
	uint32_t fw_sk_cut;
	uint32_t reserve2[3];
} L1Reg;


/*
	TEST関連
*/
typedef struct _TagTestReg {
	uint32_t enc_data[4];
	uint32_t tout_data;
	uint32_t tout_done;
}TestReg;


/*
	CTLモジュールのレジスタ
*/
typedef struct _TagCtlReg {
	LTS3Reg  LTS3R;
	SipReg   SIPR;
	LocalReg LOCALR;
	MMCReg   MMCR;
	L1Reg    L1R;
	TestReg  TESTR;
}CtlReg;

#define CTL_REG_BASE (0x4000C000u)
#define CTLR (*(volatile CtlReg*)(CTL_REG_BASE))

#define RSA_D_SIZE (256)
#define CTLR_L1_FWSEED_CUT  (0x00000001u)
#define CTLR_LOCAL_RESET_MASK     (0x00000007u)
#define CTLR_LOCAL_SHA_RESET_MASK (0x00000002u)
#define CLTR_LOCALR_FIFO_CLERA    (0x00000001u)

#define INT_DISABLE   (0x00000000u)
#define BUSY_ENABLE   (0x00000001u)
#define BUSY_DISABLE  (0x00000000u)
#define MMC_REQ       (0x00000001u)
#define KEY_ACK       (0x00000001u)

#endif // ___CTL_REG_H_INCLUDED___
