/*
 *               Copyright (C) 2005, BroadOn Communications Corp.
 *
 *  These coded instructions, statements, and computer programs contain
 *  unpublished  proprietary information of BroadOn Communications Corp.,
 *  and  are protected by Federal copyright law. They may not be disclosed
 *  to  third  parties or copied or duplicated in any form, in whole or in
 *  part, without the prior written consent of BroadOn Communications Corp.
 *
 */

// #include "iop_utils.h"
#include "iop.h"
#include "ioslibc.h"
#include "sys.h"


void setupAccess()
{

    u32 reg;
    u32 major, minor;

    /* Enable access for SRON */

    reg = busRd32((u32)(ACR_REGS_BASE+ACRSRNPROT_OFFSET+AHB_TRUSTED_OFFSET)); 
    reg = reg | (ACRSRNPROT_AESEN_MASK | ACRSRNPROT_SHAEN_MASK |
          ACRSRNPROT_FLAEN_MASK);

    getChipId(&major, &minor);
    if (major == 0) {
        reg = reg | ACRSRNPROT_IOPDBGEN_MASK;
    }
    busWrt32((u32)(ACR_REGS_BASE+ACRSRNPROT_OFFSET+AHB_TRUSTED_OFFSET), reg);
    busPrintf("Enable SRN access: Reg 0x%x <- 0x%x", 
        (ACR_REGS_BASE+ACRSRNPROT_OFFSET+AHB_TRUSTED_OFFSET), reg);

#ifdef DDR_ENABLE
    /* After reset wait for 256 cycles before programming AHMPROTF */
    // busDelay(256);
    reg = (busRd32(AHM_BASE+AHMSECSPL+AHB_TRUSTED_OFFSET) & 
           ~AHMSECSPL_REG_FINE_EN_SPL_MASK);
    busPrintf("%s: Disable AHM Fine Grain Access (Napa): Reg 0x%x <- 0x%x", 
        __FILE__, (AHM_BASE+AHMSECSPL+AHB_TRUSTED_OFFSET), reg);
    busWrt32((u32)(AHM_BASE+AHMSECSPL+AHB_TRUSTED_OFFSET), reg);

    reg = (busRd32(AHM_BASE+AHMSECDDR+AHB_TRUSTED_OFFSET) & 
           ~AHMSECDDR_REG_FINE_EN_DDR_MASK);
    busPrintf("%s: Disable AHM Fine Grain Access (DDR): Reg 0x%x <- 0x%x", 
        __FILE__, (AHM_BASE+AHMSECDDR+AHB_TRUSTED_OFFSET), reg);
    busWrt32((u32)(AHM_BASE+AHMSECDDR+AHB_TRUSTED_OFFSET), reg);
#endif

}

