static int switch_init(int argc, char *argv[]){ int rv; rv = rtk_switch_init(); if(rv){ printf("switch init error!"); return 1; } return 0; }
int rtl8367_switch_init_post(void) { rtk_api_ret_t retVal; rtk_portmask_t portmask; rtk_port_mac_ability_t mac_cfg; printf(" Reset and init RTL8367 external switch..."); /* soft reset switch */ rtl8367b_setAsicReg(RTL8367B_REG_CHIP_RESET, 1); /* wait 1s for switch ready */ mdelay(1000); /* main switch init */ retVal = rtk_switch_init(); if (retVal != RT_ERR_OK) { printf("FAILED! (code: %d)\n", retVal); return retVal; } /* create default ports isolation */ partition_bridge_default(); /* configure ExtIf to RGMII, fixed gigabit mode w/o autoneg */ mac_cfg.forcemode = MAC_FORCE; mac_cfg.speed = SPD_1000M; mac_cfg.duplex = FULL_DUPLEX; mac_cfg.link = PORT_LINKUP; mac_cfg.nway = DISABLED; mac_cfg.rxpause = ENABLED; mac_cfg.txpause = ENABLED; rtk_port_macForceLinkExt_set(EXT_PORT_1, MODE_EXT_RGMII, &mac_cfg); /* disable iNIC_mii port link */ mac_cfg.link = PORT_LINKDOWN; rtk_port_macForceLinkExt_set(EXT_PORT_2, MODE_EXT_RGMII, &mac_cfg); /* configure ExtIf RGMII delays */ rtk_port_rgmiiDelayExt_set(EXT_PORT_1, RTL8367_RGMII_DELAY_TX, RTL8367_RGMII_DELAY_RX); rtk_port_rgmiiDelayExt_set(EXT_PORT_2, RTL8367_RGMII_DELAY_TX, RTL8367_RGMII_DELAY_RX); /* configure PHY leds */ portmask.bits[0] = 0x1F; rtk_led_enable_set(LED_GROUP_0, portmask); rtk_led_enable_set(LED_GROUP_1, portmask); rtk_led_operation_set(LED_OP_PARALLEL); rtk_led_groupConfig_set(LED_GROUP_0, LED_CONFIG_SPD10010ACT); // group 0 - green LED rtk_led_groupConfig_set(LED_GROUP_1, LED_CONFIG_SPD1000ACT); // group 1 - yellow LED printf("SUCCESS!\n"); return RT_ERR_OK; }
int rtl8367_switch_init_pre(void) { u32 data; rtk_api_ret_t retVal; data = le32_to_cpu(*(volatile u32 *)(RALINK_REG_GPIOMODE)); /* Configure I2C pin as GPIO mode or I2C mode */ if (SMI_SCK == 2 || SMI_SDA == 1) data |= RALINK_GPIOMODE_I2C; else data &= ~RALINK_GPIOMODE_I2C; /* Configure MDC/MDIO pin as GPIO mode or MDIO mode */ if (SMI_SCK == 23 || SMI_SDA == 22) data |= RALINK_GPIOMODE_MDIO; else data &= ~RALINK_GPIOMODE_MDIO; *((volatile uint32_t *)(RALINK_REG_GPIOMODE)) = cpu_to_le32(data); smi_init(SMI_SCK, SMI_SDA); printf("\n Init RTL8367 external switch..."); /* wait min 200ms after power-on-reset */ mdelay(200); test_smi_signal_and_wait(); /* main switch init */ retVal = rtk_switch_init(); if (retVal != RT_ERR_OK) { printf("FAILED! (code: %d)\n", retVal); return retVal; } /* power down all ports (prevent spoofing) */ rtl8367_port_power(RTL8367_PORT_WAN, 0); rtl8367_port_power(RTL8367_PORT_LAN4, 0); rtl8367_port_power(RTL8367_PORT_LAN3, 0); rtl8367_port_power(RTL8367_PORT_LAN2, 0); rtl8367_port_power(RTL8367_PORT_LAN1, 0); printf("SUCCESS!\n"); return RT_ERR_OK; }
/* * board_final_init() * * Do any final initialization, such as adding commands to the * user interface. * * If you don't want a user interface, put the startup code here. * This routine is called just before CFE starts its user interface. * * Input parameters: * nothing * * Return value: * nothing */ void board_final_init(void) { char *addr, *mask, *wait_time; char buf[512], *cur = buf; #ifdef CFG_ROMBOOT char *laddr = NULL; #endif #if !CFG_SIM char *boot_cfg = NULL; char *go_cmd = "go;"; #endif int commit = 0; uint32 ncdl; #if CFG_WL && CFG_WLU && CFG_SIM char *ssid; #endif ui_init_bcm947xxcmds(); /* Force commit of embedded NVRAM */ commit = restore_defaults; /* Set the SDRAM NCDL value into NVRAM if not already done */ if ((getintvar(NULL, "sdram_ncdl") == 0) && ((ncdl = si_memc_get_ncdl(sih)) != 0)) { sprintf(buf, "0x%x", ncdl); nvram_set("sdram_ncdl", buf); commit = 1; } /* Set the bootloader version string if not already done */ sprintf(buf, "CFE %s", EPI_VERSION_STR); if (strcmp(nvram_safe_get("pmon_ver"), buf) != 0) { nvram_set("pmon_ver", buf); commit = 1; } /* Set the size of the nvram area if not already done */ sprintf(buf, "%d", MAX_NVRAM_SPACE); if (strcmp(nvram_safe_get("nvram_space"), buf) != 0) { nvram_set("nvram_space", buf); commit = 1; } #ifdef RTL8365MB int ret = -1, retry = 0; rtk_port_mac_ability_t pa; GPIO_INIT(); for(retry = 0; ret && retry < 10; ++retry) { ret = rtk_switch_init(); if(ret) cfe_usleep(10000); else break; } printf("rtl8354mb initialized(%d)(retry %d) %s\n", ret, retry, ret?"failed":""); ret = rtk_port_phyEnableAll_set(1); if(ret) printf("rtk port_phyEnableAll Failed!(%d)\n", ret); else printf("rtk port_phyEnableAll ok\n"); /* configure & set GMAC ports */ pa.forcemode = MAC_FORCE; pa.speed = SPD_1000M; pa.duplex = FULL_DUPLEX; pa.link = 1; pa.nway = 0; pa.rxpause = 0; pa.txpause = 0; ret = rtk_port_macForceLinkExt_set(EXT_PORT0, MODE_EXT_RGMII, &pa); if(ret) printf("rtk port_macForceLink_set ext_Port0 Failed!(%d)\n", ret); else printf("rtk port_macForceLink_set ext_Port0 ok\n"); /* asic chk */ rtk_uint32 retVal, retVal2; rtk_uint32 data, data2; if((retVal = rtl8367c_getAsicReg(0x1311, &data)) != RT_ERR_OK || (retVal2 = rtl8367c_getAsicReg(0x1305, &data2)) != RT_ERR_OK) { printf("get failed(%d)(%d). (%x)(supposed to be 0x1016)\n", retVal, retVal2, data); } else { /* get ok, then chk reg*/ printf("get ok, chk 0x1311:%x(0x1016), 0x1305:%x(b4~b7:0x1)\n", data, data2); if(data != 0x1016){ printf("\n!! rtl reg 0x1311 error: (%d)(get %x)\n", retVal, data); } if((data2 & 0xf0) != 0x10) { printf("\n!! rtl reg 0x1305 error: (%d)(get %x)\n", retVal, data2); } } /* reset tx/rx delay */ retVal = rtk_port_rgmiiDelayExt_set(EXT_PORT0, 1, 4); if (retVal != RT_ERR_OK) printf("\n!! rtl set delay failed (%d)\n", retVal); #endif #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH #if !CFG_SIM /* Commit NVRAM only if in FLASH */ if ( #ifdef BCMNVRAMW !nvram_inotp() && #endif commit) { printf("Committing NVRAM..."); nvram_commit(); printf("done\n"); if (restore_defaults) { #ifdef BCM_DEVINFO /* devinfo nvram hash table sync */ devinfo_nvram_sync(); #endif printf("Waiting for wps button release..."); reset_release_wait(); printf("done\n"); } } /* Reboot after restoring defaults */ if (restore_defaults) si_watchdog(sih, 1); #endif /* !CFG_SIM */ #else if (commit) printf("Flash not configured, not commiting NVRAM...\n"); #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */ /* * Read the wait_time NVRAM variable and set the tftp max retries. * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec. */ if ((wait_time = nvram_get("wait_time")) != NULL) { tftp_max_retries = atoi(wait_time); if (tftp_max_retries > MAX_WAIT_TIME) tftp_max_retries = MAX_WAIT_TIME; else if (tftp_max_retries < MIN_WAIT_TIME) tftp_max_retries = MIN_WAIT_TIME; } #ifdef CFG_ROMBOOT else if (board_bootdev_rom(sih)) { tftp_max_retries = 10; } #endif /* Configure network */ if (cfe_finddev("eth0")) { int res; if ((addr = nvram_get("lan_ipaddr")) && (mask = nvram_get("lan_netmask"))) sprintf(buf, "ifconfig eth0 -addr=%s -mask=%s", addr, mask); else sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); #ifdef CFG_ROMBOOT /* Try indefinite netboot only while booting from ROM * and we are sure that we dont have valid nvram in FLASH */ while (board_bootdev_rom(sih) && !addr) { char ch; cur = buf; /* Check if something typed at console */ if (console_status()) { console_read(&ch, 1); /* Check for Ctrl-C */ if (ch == 3) { if (laddr) MFREE(osh, laddr, MAX_SCRIPT_FSIZE); xprintf("Stopped auto netboot!!!\n"); return; } } if (!res) { char *bserver, *bfile, *load_ptr; if (!laddr) laddr = MALLOC(osh, MAX_SCRIPT_FSIZE); if (!laddr) { load_ptr = (char *) 0x00008000; xprintf("Failed malloc for boot_script, Using :0x%x\n", (unsigned int)laddr); } else { load_ptr = laddr; } bserver = (bserver = env_getenv("BOOT_SERVER")) ? bserver:"192.168.1.1"; if ((bfile = env_getenv("BOOT_FILE"))) { int len; if (((len = strlen(bfile)) > 5) && !strncmp((bfile + len - 5), "cfesh", 5)) { cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, bfile); } if (((len = strlen(bfile)) > 3)) { if (!strncmp((bfile + len - 3), "elf", 3)) { cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, bfile); } if (!strncmp((bfile + len - 3), "raw", 3)) { cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, bfile); } } } else { /* Make last effort */ cur += sprintf(cur, "batch -raw -tftp -addr=0x%x -max=0x%x %s:%s;", (unsigned int)load_ptr, MAX_SCRIPT_FSIZE, bserver, "cfe_script.cfesh"); cur += sprintf(cur, "boot -elf -tftp -max=0x5000000 %s:%s;", bserver, "boot_file.elf"); cur += sprintf(cur, "boot -raw -z -tftp -addr=0x00008000" " -max=0x5000000 %s:%s;", bserver, "boot_file.raw"); } ui_docommand(buf); cfe_sleep(3*CFE_HZ); } sprintf(buf, "ifconfig eth0 -auto"); res = ui_docommand(buf); } #endif /* CFG_ROMBOOT */ } #if CFG_WL && CFG_WLU && CFG_SIM if ((ssid = nvram_get("wl0_ssid"))) { sprintf(buf, "wl join %s", ssid); ui_docommand(buf); } #endif #if !CFG_SIM /* Try to run boot_config command if configured. * make sure to leave space for "go" command. */ if ((boot_cfg = nvram_get("boot_config"))) { if (strlen(boot_cfg) < (sizeof(buf) - sizeof(go_cmd))) cur += sprintf(cur, "%s;", boot_cfg); else printf("boot_config too long, skipping to autoboot\n"); } /* Boot image */ cur += sprintf(cur, go_cmd); #endif /* !CFG_SIM */ /* Startup */ if (cur > buf) env_setenv("STARTUP", buf, ENV_FLG_NORMAL); }
int rtl8367r_switch_init_pre() { rtk_api_ret_t retVal; unsigned long gpiomode; set_mdc_to_gpio_mode(); smi_reset(); // after reset, switch need to delay 1 ms // if not, SMI may send out unknown data udelay(1000); smi_init(); test_smi_signal_and_wait(); retVal = rtk_switch_init(); printf("rtk_switch_init(): return %d\n", retVal); if (retVal != RT_ERR_OK) return retVal; // // RALINK uses RGMII to connect switch IC directly // we need to set the MDIO mode here // rtk_port_mac_ability_t mac_cfg; mac_cfg.forcemode = MAC_FORCE; mac_cfg.speed = SPD_1000M; mac_cfg.duplex = FULL_DUPLEX; mac_cfg.link = PORT_LINKUP; mac_cfg.nway = DISABLED; mac_cfg.txpause = ENABLED; mac_cfg.rxpause = ENABLED; retVal = rtk_port_macForceLinkExt_set (1, MODE_EXT_RGMII,&mac_cfg); printf("rtk_port_macForceLinkExt_set(): return %d\n", retVal); int input_txDelay = 1; int input_rxDelay = 2; printf("input_txDelay:%d, input_rxDelay:%d\n", input_txDelay, input_rxDelay); retVal = rtk_port_rgmiiDelayExt_set(1, input_txDelay, input_rxDelay); printf("rtk_port_rgmiiDelayExt_set(): return %d\n", retVal); // power down all LAN ports // this is to force DHCP IP address new when PC cable connects to LAN port rtk_port_phy_data_t pData; rtk_port_phyReg_get(1, PHY_CONTROL_REG, &pData); printf("** rtk_port_phyReg_get = %x\n", pData); pData |= CONTROL_REG_PORT_POWER_BIT; rtk_port_phyReg_set(1, PHY_CONTROL_REG, pData); rtk_port_phyReg_get(2, PHY_CONTROL_REG, &pData); printf("** rtk_port_phyReg_get = %x\n", pData); pData |= CONTROL_REG_PORT_POWER_BIT; rtk_port_phyReg_set(2, PHY_CONTROL_REG, pData); rtk_port_phyReg_get(3, PHY_CONTROL_REG, &pData); printf("** rtk_port_phyReg_get = %x\n", pData); pData |= CONTROL_REG_PORT_POWER_BIT; rtk_port_phyReg_set(3, PHY_CONTROL_REG, pData); rtk_port_phyReg_get(4, PHY_CONTROL_REG, &pData); printf("** rtk_port_phyReg_get = %x\n", pData); pData |= CONTROL_REG_PORT_POWER_BIT; rtk_port_phyReg_set(4, PHY_CONTROL_REG, pData); /* { int i; for (i=0; i<8; i++) { rtk_port_phy_data_t pData; rtk_port_phyReg_get(i, 1, &pData); printf("** %d rtk_port_phyReg_get = %x\n", i, pData); } } */ /* { // read EXT MAC status // seems not works rtk_uint32 data; rtk_api_ret_t retVal; if((retVal = rtl8367b_getAsicReg(0x1305, &data)) != RT_ERR_OK) { printf("error = %d\n", retVal); } printf("data = %x\n", data); if((retVal = rtl8367b_getAsicReg(0x1311, &data)) != RT_ERR_OK) { printf("error = %d\n", retVal); } printf("data = %x\n", data); //data 1305 = c010 //data 1311 = 1076 } */ rtl8367r_switch_inited = 1; return RT_ERR_OK; }