/*
 * Copyright (c) 2014 - 2016 MediaTek Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef __MTK_DAPC_H__
#define __MTK_DAPC_H__

#include <stdint.h>
#include <stdio.h>
#include <tlDapcIndex.h>

/* device apc attribute*/
 typedef enum
 {
     E_L0 = 0,
     E_L1 = 1,
     E_L2 = 2,
     E_L3 = 3,
     E_MAX_APC_ATTR,
     E_APC_ATTR_RESERVRD = 0x7FFFFFFF  /* force enum to use 32 bits */
 } APC_ATTR;

/* domain index */
 typedef enum
 {
     E_DOMAIN_0 = 0,
     E_DOMAIN_1 = 1,
     E_DOMAIN_2 = 2,
     E_DOMAIN_3 = 3,
     E_DOMAIN_4 = 4,
     E_DOMAIN_5 = 5,
     E_DOMAIN_6 = 6,
     E_DOMAIN_7 = 7,
     E_MAX_MAS_DOM,
     E_MAS_DOM_RESERVRD = 0x7FFFFFFF  /* force enum to use 32 bits */
 } E_MAS_DOM;

#define MOD_NO_IN_1_DEVAPC     16
#define MASTER_MAX_INDEX       29
#define DEVAPC_DEVICE_NUMBER   221  /* This number must be bigger than total slave */

#define DEVAPC_AO_BASE         0x1000E000
#define DEVAPC_PD_BASE         0x10207000
#define INFRACFG_AO_base       0x10001000

#define DEVAPC_AO_VA_BUFFER    (devapc_ao_vaddr)

#define DEVAPC_D0_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0000))
#define DEVAPC_D1_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0100))
#define DEVAPC_D2_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0200))
#define DEVAPC_D3_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0300))
#define DEVAPC_D4_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0400))
#define DEVAPC_D5_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0500))
#define DEVAPC_D6_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0600))
#define DEVAPC_D7_APC_0        ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0700))

#define DEVAPC_MAS_SEC         ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0B00))

#define DEVAPC_APC_CON         ((volatile unsigned int *)(DEVAPC_AO_VA_BUFFER + 0x0F00))

/* common function*/
int start_devapc(void);
void set_module_apc(unsigned int module, E_MAS_DOM domain_num, APC_ATTR permission_control);

#endif
