/*------------------------------------------------------------------------------------------*\
 *   
 *   Copyright (C) 2006 AVM GmbH <fritzbox_info@avm.de>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation version 2 of the License.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
\*------------------------------------------------------------------------------------------*/
#include <stdarg.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#if !defined(CONFIG_NETCHIP_ADM69961)
#define CONFIG_NETCHIP_ADM69961
#endif
#include <linux/avm_event.h>
#include <asm/mips-boards/ohio.h>
#include <asm/mips-boards/prom.h>
#include <asm/mach-ohio/hw_gpio.h>

#include "cpmac_if.h"
#include "cpmac_const.h"
#include "cpmac_types.h"
#include "cpmac_debug.h"
#include "cpphy_const.h"
#include "cpphy_types.h"
#include "cpphy_main.h"

MODULE_AUTHOR("Maintainer: AVM GmbH");
MODULE_DESCRIPTION("Ethernet driver for FRITZ!Box (external phy on high cpmac)");
MODULE_LICENSE("\n(C) Copyright 2005, AVM GmbH\n");

/*----------------------------------------------------------------------------------*\
  Zugriff auf cpphy_global aus anderen Modulen ueber phy_handle
\*----------------------------------------------------------------------------------*/
static cpphy_global_t cpphy_global;

/*----------------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------------*/
static int __init cpphy_entry_probe (void)
{
  cpmac_err_t ret = CPMAC_ERR_NOERR;
  union _chip_version *chip_version = (union _chip_version *)&OHIO_CVR;
  char  *hwrev;

  DEB_INFO("cpphy_entry_probe, init\n");

  /* detect sangam / ohio */
  cpphy_global.is_ohio = (chip_version->Bits.Id == OHIO_CHIP_ID);
#if defined(HIGH_PHY)
  cpphy_global.high_phy = 1;
#endif
#if defined(SWITCH)
  cpphy_global.cpmac_switch = 1;
#endif
  cpphy_global.is_vdsl = 0;

    /*--------------------------------------------------------------------------------------*\
    \*--------------------------------------------------------------------------------------*/
    hwrev = prom_getenv("HWRevision");
    /*--- printk("HWRevision=\"%s\"\n", hwrev); ---*/
    if(hwrev) {
        char buff[20];
        char *p;

        strcpy(buff, hwrev);
        strcat(buff, " ");
        /*----------------------------------------------------------------------------------*\
         * aus "94.0.0.1 "  -->   "94 " erzeugen
        \*----------------------------------------------------------------------------------*/
        p = strchr(buff, '.');
        if(p) {
            *p++ = ' ';
            *p++ = '\0';
        }

        /*--- AVM_CPMAC_SWITCH_HWREV_LIST wird automatisch in init_cpmac erzeugt ---*/
        if(!strstr(AVM_CPMAC_SWITCH_HWREV_LIST, buff)) {
#if defined(CONFIG_AVM_CPPHY_LOW_SWITCH)
            DEB_INFO("cpphy_entry_probe, built-in, ohio: %u, high: %u, switch: %u vdsl: %u\n",
                cpphy_global.is_ohio,
                cpphy_global.high_phy,
                cpphy_global.cpmac_switch,
				cpphy_global.is_vdsl);
#else
            DEB_INFO("cpphy_entry_probe, module, ohio: %u, high: %u, switch: %u vdsl: %u\n",
                cpphy_global.is_ohio,
                cpphy_global.high_phy,
                cpphy_global.cpmac_switch,
				cpphy_global.is_vdsl);
#endif
            ret = cpphy_main_register (&cpphy_global);
        }
    }



#if 0
#if defined(CONFIG_AVM_CPPHY_HIGH)
  /* build in driver */
  start_module = prom_getcmdline();
  if (strstr(start_module, "cpphy_high")) { 
    DEB_INFO("cpphy_entry_probe, built-in, ohio: %u, high: %u, switch: %u\n",
        cpphy_global.is_ohio,
        cpphy_global.high_phy,
        cpphy_global.cpmac_switch);
    ret = cpphy_main_register (&cpphy_global);
  } else {
    DEB_INFO("cpphy_entry_probe, built-in, not starting, %p\n",
        start_module);
    ret = CPMAC_ERR_NOERR;
  }
#else
  ret = cpphy_main_register (&cpphy_global);
#endif
#endif

  /* weiter geht es per cb hier: cpphy_if_init() */
  return (ret == CPMAC_ERR_NOERR) ? 0 : -ENODEV;
}

/*----------------------------------------------------------------------------------*\
\*----------------------------------------------------------------------------------*/
static void cpphy_entry_exit (void)
{
  DEB_INFO("cpphy_entry_exit, init\n");
  cpmac_if_release (cpphy_global.cpmac_priv);
}


module_init(cpphy_entry_probe);
module_exit(cpphy_entry_exit);

