#!/usr/bin/perl
use strict;
use warnings;
use FindBin qw($Bin);
use lib "$Bin/../../PerlLib";
use BRCM::GenConfig;

# $p will allow us to GET values from the PROFILE
# $c will allow us to SET (and GET and DRIVER_SETUP) on the config
# file as we transform it from a template to the final config

# arguments
# * profile file
# * config  file
my $p    = new BRCM::GenConfig(shift);
my $chip = $p->get('BRCM_CHIP');
my $c    = new BRCM::GenConfig( shift, Chip => $chip, Profile => $p );

if ( $p->get("BRCM_ETH_PWRSAVE") ) {
    $c->set( "CONFIG_BCM_ETH_PWRSAVE", "y" );
    if ( $chip =~ /^(63268|6318|6838|6848|63138|63148|63381|4908)$/ ) {
        $c->set( "CONFIG_BCM_ETH_HWAPD_PWRSAVE", "y" );
    }
}

if ( $p->get("BRCM_ENERGY_EFFICIENT_ETHERNET") ) {
    $c->set( "CONFIG_BCM_ENERGY_EFFICIENT_ETHERNET", "y" );
}

if ( $p->get("BRCM_ETH_DEEP_GREEN_MODE") ) {
    $c->set( "CONFIG_BCM_ETH_DEEP_GREEN_MODE", "y" );
}

if ( $p->get("BRCM_HOSTMIPS_PWRSAVE") ) {
    $c->set( "CONFIG_BCM_HOSTMIPS_PWRSAVE", "y" );
    if ( $chip =~ /^(6362|6328|6318)$/ ) {
        $c->set( "CONFIG_BCM_HOSTMIPS_PWRSAVE_TIMERS", "y" );
    }
}
$c->set( "CONFIG_BCM_DDR_SELF_REFRESH_PWRSAVE", $p->get("BRCM_DDR_SELF_REFRESH_PWRSAVE") );
$c->set( "CONFIG_BCM_AVS_PWRSAVE",              $p->get("BRCM_AVS_PWRSAVE") );

if ( $chip =~ /^(63268)$/ ) {
    $c->set( "CONFIG_BCM_1V2REG_AUTO_SHUTDOWN",   $p->get("BRCM_1V2REG_AUTO_SHUTDOWN") );
    $c->set( "CONFIG_BCM_1V2REG_ALWAYS_SHUTDOWN", $p->get("BRCM_1V2REG_ALWAYS_SHUTDOWN") );
    $c->set( "CONFIG_BCM_1V2REG_NEVER_SHUTDOWN",  $p->get("BRCM_1V2REG_NEVER_SHUTDOWN") );
}

if ( $p->get("BUILD_BMU") ) {
    $c->set( "CONFIG_BCM_BMU", "y" );
}

if ( $p->get("BRCM_CPUIDLE_CLK_DIVIDER") ) {
    $c->set( "CONFIG_BCM_CPUIDLE_CLK_DIVIDER", "y" );
}

if ( $p->get("BRCM_UBUS4_DCM") ) { # chips with UBUS4_DCM feature
	$c->set( "CONFIG_BCM_UBUS4_DCM", "y" );
}

if ( $p->get("BRCM_XRDP_AUTOGATE") ) {
    $c->set( "CONFIG_BCM_XRDP_AUTOGATE", "y" );
}

$c->set('CONFIG_BCM_CPUOFF', 'm') if $p->get('BRCM_CPUOFF');

$c->write();

