speed.c
来自「U-boot源码 ARM7启动代码」· C语言 代码 · 共 926 行 · 第 1/2 页
C
926 行
/* Determine FB divisors values */ if ((fpga_clocking_reg & FPGA_REG16_FB1_DIV_MASK) == FPGA_REG16_FB1_DIV_LOW) { if ((fpga_clocking_reg & FPGA_REG16_FB2_DIV_MASK) == FPGA_REG16_FB2_DIV_LOW) fb_div_selection = FPGA_FB_DIV_6; else fb_div_selection = FPGA_FB_DIV_12; } else { if ((fpga_clocking_reg & FPGA_REG16_FB2_DIV_MASK) == FPGA_REG16_FB2_DIV_LOW) fb_div_selection = FPGA_FB_DIV_10; else fb_div_selection = FPGA_FB_DIV_20; } /* Determine VCO divisors values */ vco_div_reg_value = fpga_clocking_reg & FPGA_REG16_VCO_DIV_MASK; switch(vco_div_reg_value) { case FPGA_REG16_VCO_DIV_4: vco_div_selection = FPGA_VCO_DIV_4; break; case FPGA_REG16_VCO_DIV_6: vco_div_selection = FPGA_VCO_DIV_6; break; case FPGA_REG16_VCO_DIV_8: vco_div_selection = FPGA_VCO_DIV_8; break; case FPGA_REG16_VCO_DIV_10: default: vco_div_selection = FPGA_VCO_DIV_10; break; } if (master_clock_selection == FPGA_REG16_MASTER_CLK_EXT) { switch(master_clock_per) { case PERIOD_25_00MHZ: if (fb_div_selection == FPGA_FB_DIV_12) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_75_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_50_00MHZ; } break; case PERIOD_33_33MHZ: if (fb_div_selection == FPGA_FB_DIV_6) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_50_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_33_33MHZ; } if (fb_div_selection == FPGA_FB_DIV_10) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_83_33MHZ; if (vco_div_selection == FPGA_VCO_DIV_10) sys_per = PERIOD_33_33MHZ; } if (fb_div_selection == FPGA_FB_DIV_12) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_100_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_66_66MHZ; if (vco_div_selection == FPGA_VCO_DIV_8) sys_per = PERIOD_50_00MHZ; } break; case PERIOD_50_00MHZ: if (fb_div_selection == FPGA_FB_DIV_6) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_75_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_50_00MHZ; } if (fb_div_selection == FPGA_FB_DIV_10) { if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_83_33MHZ; if (vco_div_selection == FPGA_VCO_DIV_10) sys_per = PERIOD_50_00MHZ; } if (fb_div_selection == FPGA_FB_DIV_12) { if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_100_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_8) sys_per = PERIOD_75_00MHZ; } break; case PERIOD_66_66MHZ: if (fb_div_selection == FPGA_FB_DIV_6) { if (vco_div_selection == FPGA_VCO_DIV_4) sys_per = PERIOD_100_00MHZ; if (vco_div_selection == FPGA_VCO_DIV_6) sys_per = PERIOD_66_66MHZ; if (vco_div_selection == FPGA_VCO_DIV_8) sys_per = PERIOD_50_00MHZ; } if (fb_div_selection == FPGA_FB_DIV_10) { if (vco_div_selection == FPGA_VCO_DIV_8) sys_per = PERIOD_83_33MHZ; if (vco_div_selection == FPGA_VCO_DIV_10) sys_per = PERIOD_66_66MHZ; } if (fb_div_selection == FPGA_FB_DIV_12) { if (vco_div_selection == FPGA_VCO_DIV_8) sys_per = PERIOD_100_00MHZ; } break; default: break; } if (sys_per == 0) { /* Other combinations are not supported */ DEBUGF ("%s[%d] *** sys period compute failed ***\n", __FUNCTION__,__LINE__); hang(); } } else { /* calcul system clock without cheking */ /* if engineering option clock no check is selected */ /* sys_per = master_clock_per * vco_div_selection / fb_div_selection */ sys_per = (master_clock_per/fb_div_selection) * vco_div_selection; } return(sys_per);}/*-------------------------------------------------------------------------+| determine_pci_clock_per.+-------------------------------------------------------------------------*/unsigned long determine_pci_clock_per(void){ unsigned long pci_clock_selection, pci_period; /*-------------------------------------------------------------------------+ | Read FPGA reg 6 to get PCI 0 FPGA reg information +-------------------------------------------------------------------------*/ pci_clock_selection = in16(FPGA_REG16); /* was reg6 averifier */ pci_clock_selection = pci_clock_selection & FPGA_REG16_PCI0_CLK_MASK; switch (pci_clock_selection) { case FPGA_REG16_PCI0_CLK_133_33: pci_period = PERIOD_133_33MHZ; break; case FPGA_REG16_PCI0_CLK_100: pci_period = PERIOD_100_00MHZ; break; case FPGA_REG16_PCI0_CLK_66_66: pci_period = PERIOD_66_66MHZ; break; default: pci_period = PERIOD_33_33MHZ;; break; } return(pci_period);}#endifulong get_OPB_freq (void){ sys_info_t sys_info; get_sys_info (&sys_info); return sys_info.freqOPB;}#elif defined(CONFIG_XILINX_ML300)extern void get_sys_info (sys_info_t * sysInfo);extern ulong get_PCI_freq (void);#elif defined(CONFIG_AP1000)void get_sys_info (sys_info_t * sysInfo) { sysInfo->freqProcessor = 240 * 1000 * 1000; sysInfo->freqPLB = 80 * 1000 * 1000; sysInfo->freqPCI = 33 * 1000 * 1000;}#elif defined(CONFIG_405)void get_sys_info (sys_info_t * sysInfo) { sysInfo->freqVCOMhz=3125000; sysInfo->freqProcessor=12*1000*1000; sysInfo->freqPLB=50*1000*1000; sysInfo->freqPCI=66*1000*1000;}#elif defined(CONFIG_405EP)void get_sys_info (PPC405_SYS_INFO * sysInfo){ unsigned long pllmr0; unsigned long pllmr1; unsigned long sysClkPeriodPs = ONE_BILLION / (CONFIG_SYS_CLK_FREQ / 1000); unsigned long m; unsigned long pllmr0_ccdv; /* * Read PLL Mode registers */ pllmr0 = mfdcr (cpc0_pllmr0); pllmr1 = mfdcr (cpc0_pllmr1); /* * Determine forward divider A */ sysInfo->pllFwdDiv = 8 - ((pllmr1 & PLLMR1_FWDVA_MASK) >> 16); /* * Determine forward divider B (should be equal to A) */ sysInfo->pllFwdDivB = 8 - ((pllmr1 & PLLMR1_FWDVB_MASK) >> 12); /* * Determine FBK_DIV. */ sysInfo->pllFbkDiv = ((pllmr1 & PLLMR1_FBMUL_MASK) >> 20); if (sysInfo->pllFbkDiv == 0) { sysInfo->pllFbkDiv = 16; } /* * Determine PLB_DIV. */ sysInfo->pllPlbDiv = ((pllmr0 & PLLMR0_CPU_TO_PLB_MASK) >> 16) + 1; /* * Determine PCI_DIV. */ sysInfo->pllPciDiv = (pllmr0 & PLLMR0_PCI_TO_PLB_MASK) + 1; /* * Determine EXTBUS_DIV. */ sysInfo->pllExtBusDiv = ((pllmr0 & PLLMR0_EXB_TO_PLB_MASK) >> 8) + 2; /* * Determine OPB_DIV. */ sysInfo->pllOpbDiv = ((pllmr0 & PLLMR0_OPB_TO_PLB_MASK) >> 12) + 1; /* * Determine the M factor */ m = sysInfo->pllFbkDiv * sysInfo->pllFwdDivB; /* * Determine VCO clock frequency */ sysInfo->freqVCOHz = (1000000000000LL * (unsigned long long)m) / (unsigned long long)sysClkPeriodPs; /* * Determine CPU clock frequency */ pllmr0_ccdv = ((pllmr0 & PLLMR0_CPU_DIV_MASK) >> 20) + 1; if (pllmr1 & PLLMR1_SSCS_MASK) { /* * This is true if FWDVA == FWDVB: * sysInfo->freqProcessor = (CONFIG_SYS_CLK_FREQ * sysInfo->pllFbkDiv) * / pllmr0_ccdv; */ sysInfo->freqProcessor = (CONFIG_SYS_CLK_FREQ * sysInfo->pllFbkDiv * sysInfo->pllFwdDivB) / sysInfo->pllFwdDiv / pllmr0_ccdv; } else { sysInfo->freqProcessor = CONFIG_SYS_CLK_FREQ / pllmr0_ccdv; } /* * Determine PLB clock frequency */ sysInfo->freqPLB = sysInfo->freqProcessor / sysInfo->pllPlbDiv;}/******************************************** * get_OPB_freq * return OPB bus freq in Hz *********************************************/ulong get_OPB_freq (void){ ulong val = 0; PPC405_SYS_INFO sys_info; get_sys_info (&sys_info); val = sys_info.freqPLB / sys_info.pllOpbDiv; return val;}/******************************************** * get_PCI_freq * return PCI bus freq in Hz *********************************************/ulong get_PCI_freq (void){ ulong val; PPC405_SYS_INFO sys_info; get_sys_info (&sys_info); val = sys_info.freqPLB / sys_info.pllPciDiv; return val;}#elif defined(CONFIG_405EZ)void get_sys_info (PPC405_SYS_INFO * sysInfo){ unsigned long cpr_plld; unsigned long cpr_pllc; unsigned long cpr_primad; unsigned long sysClkPeriodPs = ONE_BILLION / (CONFIG_SYS_CLK_FREQ/1000); unsigned long primad_cpudv; unsigned long m; /* * Read PLL Mode registers */ mfcpr(cprplld, cpr_plld); mfcpr(cprpllc, cpr_pllc); /* * Determine forward divider A */ sysInfo->pllFwdDiv = ((cpr_plld & PLLD_FWDVA_MASK) >> 16); /* * Determine forward divider B */ sysInfo->pllFwdDivB = ((cpr_plld & PLLD_FWDVB_MASK) >> 8); if (sysInfo->pllFwdDivB == 0) sysInfo->pllFwdDivB = 8; /* * Determine FBK_DIV. */ sysInfo->pllFbkDiv = ((cpr_plld & PLLD_FBDV_MASK) >> 24); if (sysInfo->pllFbkDiv == 0) sysInfo->pllFbkDiv = 256; /* * Read CPR_PRIMAD register */ mfcpr(cprprimad, cpr_primad); /* * Determine PLB_DIV. */ sysInfo->pllPlbDiv = ((cpr_primad & PRIMAD_PLBDV_MASK) >> 16); if (sysInfo->pllPlbDiv == 0) sysInfo->pllPlbDiv = 16; /* * Determine EXTBUS_DIV. */ sysInfo->pllExtBusDiv = (cpr_primad & PRIMAD_EBCDV_MASK); if (sysInfo->pllExtBusDiv == 0) sysInfo->pllExtBusDiv = 16; /* * Determine OPB_DIV. */ sysInfo->pllOpbDiv = ((cpr_primad & PRIMAD_OPBDV_MASK) >> 8); if (sysInfo->pllOpbDiv == 0) sysInfo->pllOpbDiv = 16; /* * Determine the M factor */ if (cpr_pllc & PLLC_SRC_MASK) m = sysInfo->pllFbkDiv * sysInfo->pllFwdDivB; else m = sysInfo->pllFbkDiv * sysInfo->pllFwdDiv; /* * Determine VCO clock frequency */ sysInfo->freqVCOHz = (1000000000000LL * (unsigned long long)m) / (unsigned long long)sysClkPeriodPs; /* * Determine CPU clock frequency */ primad_cpudv = ((cpr_primad & PRIMAD_CPUDV_MASK) >> 24); if (primad_cpudv == 0) primad_cpudv = 16; sysInfo->freqProcessor = (CONFIG_SYS_CLK_FREQ * m) / sysInfo->pllFwdDiv / primad_cpudv; /* * Determine PLB clock frequency */ sysInfo->freqPLB = (CONFIG_SYS_CLK_FREQ * m) / sysInfo->pllFwdDiv / sysInfo->pllPlbDiv;}/******************************************** * get_OPB_freq * return OPB bus freq in Hz *********************************************/ulong get_OPB_freq (void){ ulong val = 0; PPC405_SYS_INFO sys_info; get_sys_info (&sys_info); val = (CONFIG_SYS_CLK_FREQ * sys_info.pllFbkDiv) / sys_info.pllOpbDiv; return val;}#endifint get_clocks (void){#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \ defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \ defined(CONFIG_440) || defined(CONFIG_405) sys_info_t sys_info; get_sys_info (&sys_info); gd->cpu_clk = sys_info.freqProcessor; gd->bus_clk = sys_info.freqPLB;#endif /* defined(CONFIG_405GP) || defined(CONFIG_405CR) */#ifdef CONFIG_IOP480 gd->cpu_clk = 66000000; gd->bus_clk = 66000000;#endif return (0);}/******************************************** * get_bus_freq * return PLB bus freq in Hz *********************************************/ulong get_bus_freq (ulong dummy){ ulong val;#if defined(CONFIG_405GP) || defined(CONFIG_405CR) || \ defined(CONFIG_405EP) || defined(CONFIG_405EZ) || \ defined(CONFIG_440) || defined(CONFIG_405) sys_info_t sys_info; get_sys_info (&sys_info); val = sys_info.freqPLB;#elif defined(CONFIG_IOP480) val = 66;#else# error get_bus_freq() not implemented#endif return val;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?