⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctrl_regs.c

📁 uboot200903最新版本的通用uboot
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright 2008 Freescale Semiconductor, Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * Version 2 as published by the Free Software Foundation. *//* * Generic driver for Freescale DDR/DDR2/DDR3 memory controller. * Based on code from spd_sdram.c * Author: James Yang [at freescale.com] */#include <common.h>#include <asm/fsl_ddr_sdram.h>#include "ddr.h"extern unsigned int picos_to_mclk(unsigned int picos);/* * Determine Rtt value. * * This should likely be either board or controller specific. * * Rtt(nominal): *	0 = Rtt disabled *	1 = 75 ohm *	2 = 150 ohm *	3 = 50 ohm * * FIXME: Apparently 8641 needs a value of 2 * FIXME: Old code seys if 667 MHz or higher, use 3 on 8572 * * FIXME: There was some effort down this line earlier: * *	unsigned int i; *	for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL/2; i++) { *		if (popts->dimmslot[i].num_valid_cs *		    && (popts->cs_local_opts[2*i].odt_rd_cfg *			|| popts->cs_local_opts[2*i].odt_wr_cfg)) { *			rtt = 2; *			break; *		} *	} */static inline int fsl_ddr_get_rtt(void){	int rtt;#if defined(CONFIG_FSL_DDR1)	rtt = 0;#elif defined(CONFIG_FSL_DDR2)	rtt = 3;#else#error "Need Rtt value for DDR3"#endif	return rtt;}/* Chip Select Configuration (CSn_CONFIG) */static void set_csn_config(int i, fsl_ddr_cfg_regs_t *ddr,			       const memctl_options_t *popts,			       const dimm_params_t *dimm_params){	unsigned int cs_n_en = 0; /* Chip Select enable */	unsigned int intlv_en = 0; /* Memory controller interleave enable */	unsigned int intlv_ctl = 0; /* Interleaving control */	unsigned int ap_n_en = 0; /* Chip select n auto-precharge enable */	unsigned int odt_rd_cfg = 0; /* ODT for reads configuration */	unsigned int odt_wr_cfg = 0; /* ODT for writes configuration */	unsigned int ba_bits_cs_n = 0; /* Num of bank bits for SDRAM on CSn */	unsigned int row_bits_cs_n = 0; /* Num of row bits for SDRAM on CSn */	unsigned int col_bits_cs_n = 0; /* Num of ocl bits for SDRAM on CSn */	/* Compute CS_CONFIG only for existing ranks of each DIMM.  */	if ((((i&1) == 0)	    && (dimm_params[i/2].n_ranks == 1))	    || (dimm_params[i/2].n_ranks == 2)) {		unsigned int n_banks_per_sdram_device;		cs_n_en = 1;		if (i == 0) {			/* These fields only available in CS0_CONFIG */			intlv_en = popts->memctl_interleaving;			intlv_ctl = popts->memctl_interleaving_mode;		}		ap_n_en = popts->cs_local_opts[i].auto_precharge;		odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg;		odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg;		n_banks_per_sdram_device			= dimm_params[i/2].n_banks_per_sdram_device;		ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2;		row_bits_cs_n = dimm_params[i/2].n_row_addr - 12;		col_bits_cs_n = dimm_params[i/2].n_col_addr - 8;	}	ddr->cs[i].config = (0		| ((cs_n_en & 0x1) << 31)		| ((intlv_en & 0x3) << 29)		| ((intlv_ctl & 0xf) << 24)		| ((ap_n_en & 0x1) << 23)		/* XXX: some implementation only have 1 bit starting at left */		| ((odt_rd_cfg & 0x7) << 20)		/* XXX: Some implementation only have 1 bit starting at left */		| ((odt_wr_cfg & 0x7) << 16)		| ((ba_bits_cs_n & 0x3) << 14)		| ((row_bits_cs_n & 0x7) << 8)		| ((col_bits_cs_n & 0x7) << 0)		);	debug("FSLDDR: cs[%d]_config = 0x%08x\n", i,ddr->cs[i].config);}/* Chip Select Configuration 2 (CSn_CONFIG_2) *//* FIXME: 8572 */static void set_csn_config_2(int i, fsl_ddr_cfg_regs_t *ddr){	unsigned int pasr_cfg = 0;	/* Partial array self refresh config */	ddr->cs[i].config_2 = ((pasr_cfg & 7) << 24);	debug("FSLDDR: cs[%d]_config_2 = 0x%08x\n", i, ddr->cs[i].config_2);}/* -3E = 667 CL5, -25 = CL6 800, -25E = CL5 800 */#if defined(CONFIG_FSL_DDR2)/* * DDR SDRAM Timing Configuration 0 (TIMING_CFG_0) * * Avoid writing for DDR I.  The new PQ38 DDR controller * dreams up non-zero default values to be backwards compatible. */static void set_timing_cfg_0(fsl_ddr_cfg_regs_t *ddr){	unsigned char trwt_mclk = 0;   /* Read-to-write turnaround */	unsigned char twrt_mclk = 0;   /* Write-to-read turnaround */	/* 7.5 ns on -3E; 0 means WL - CL + BL/2 + 1 */	unsigned char trrt_mclk = 0;   /* Read-to-read turnaround */	unsigned char twwt_mclk = 0;   /* Write-to-write turnaround */	/* Active powerdown exit timing (tXARD and tXARDS). */	unsigned char act_pd_exit_mclk;	/* Precharge powerdown exit timing (tXP). */	unsigned char pre_pd_exit_mclk;	/* Precharge powerdown exit timing (tAXPD). */	unsigned char taxpd_mclk;	/* Mode register set cycle time (tMRD). */	unsigned char tmrd_mclk;	/* (tXARD and tXARDS). Empirical? */	act_pd_exit_mclk = 2;	/* XXX:  tXARD = 2, tXARDS = 7 - AL. * Empirical? */	pre_pd_exit_mclk = 6;	/* FIXME:  tXP = 2 on Micron 667 MHz DIMM */	taxpd_mclk = 8;	tmrd_mclk = 2;	ddr->timing_cfg_0 = (0		| ((trwt_mclk & 0x3) << 30)	/* RWT */		| ((twrt_mclk & 0x3) << 28)	/* WRT */		| ((trrt_mclk & 0x3) << 26)	/* RRT */		| ((twwt_mclk & 0x3) << 24)	/* WWT */		| ((act_pd_exit_mclk & 0x7) << 20)  /* ACT_PD_EXIT */		| ((pre_pd_exit_mclk & 0xF) << 16)  /* PRE_PD_EXIT */		| ((taxpd_mclk & 0xf) << 8)	/* ODT_PD_EXIT */		| ((tmrd_mclk & 0xf) << 0)	/* MRS_CYC */		);	debug("FSLDDR: timing_cfg_0 = 0x%08x\n", ddr->timing_cfg_0);}#endif	/* defined(CONFIG_FSL_DDR2) *//* DDR SDRAM Timing Configuration 3 (TIMING_CFG_3) */static void set_timing_cfg_3(fsl_ddr_cfg_regs_t *ddr,			       const common_timing_params_t *common_dimm){	/* Extended Activate to precharge interval (tRAS) */	unsigned int ext_acttopre = 0;	unsigned int ext_refrec; /* Extended refresh recovery time (tRFC) */	unsigned int ext_caslat = 0; /* Extended MCAS latency from READ cmd */	unsigned int cntl_adj = 0; /* Control Adjust */	/* If the tRAS > 19 MCLK, we use the ext mode */	if (picos_to_mclk(common_dimm->tRAS_ps) > 0x13)		ext_acttopre = 1;	ext_refrec = (picos_to_mclk(common_dimm->tRFC_ps) - 8) >> 4;	ddr->timing_cfg_3 = (0		| ((ext_acttopre & 0x1) << 24)		| ((ext_refrec & 0xF) << 16)		| ((ext_caslat & 0x1) << 12)		| ((cntl_adj & 0x7) << 0)		);	debug("FSLDDR: timing_cfg_3 = 0x%08x\n", ddr->timing_cfg_3);}/* DDR SDRAM Timing Configuration 1 (TIMING_CFG_1) */static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr,			       const common_timing_params_t *common_dimm,			       unsigned int cas_latency){	/* Precharge-to-activate interval (tRP) */	unsigned char pretoact_mclk;	/* Activate to precharge interval (tRAS) */	unsigned char acttopre_mclk;	/*  Activate to read/write interval (tRCD) */	unsigned char acttorw_mclk;	/* CASLAT */	unsigned char caslat_ctrl;	/*  Refresh recovery time (tRFC) ; trfc_low */	unsigned char refrec_ctrl;	/* Last data to precharge minimum interval (tWR) */	unsigned char wrrec_mclk;	/* Activate-to-activate interval (tRRD) */	unsigned char acttoact_mclk;	/* Last write data pair to read command issue interval (tWTR) */	unsigned char wrtord_mclk;	pretoact_mclk = picos_to_mclk(common_dimm->tRP_ps);	acttopre_mclk = picos_to_mclk(common_dimm->tRAS_ps);	acttorw_mclk = picos_to_mclk(common_dimm->tRCD_ps);	/*	 * Translate CAS Latency to a DDR controller field value:	 *	 *      CAS Lat DDR I   DDR II  Ctrl	 *      Clocks  SPD Bit SPD Bit Value	 *      ------- ------- ------- -----	 *      1.0     0               0001	 *      1.5     1               0010	 *      2.0     2       2       0011	 *      2.5     3               0100	 *      3.0     4       3       0101	 *      3.5     5               0110	 *      4.0             4       0111	 *      4.5                     1000	 *      5.0             5       1001	 */#if defined(CONFIG_FSL_DDR1)	caslat_ctrl = (cas_latency + 1) & 0x07;#elif defined(CONFIG_FSL_DDR2)	caslat_ctrl = 2 * cas_latency - 1;#else#error "Need CAS Latency help for DDR3 in fsl_ddr_sdram.c"#endif	refrec_ctrl = picos_to_mclk(common_dimm->tRFC_ps) - 8;	wrrec_mclk = picos_to_mclk(common_dimm->tWR_ps);	acttoact_mclk = picos_to_mclk(common_dimm->tRRD_ps);	wrtord_mclk = picos_to_mclk(common_dimm->tWTR_ps);	ddr->timing_cfg_1 = (0		| ((pretoact_mclk & 0x0F) << 28)		| ((acttopre_mclk & 0x0F) << 24)		| ((acttorw_mclk & 0xF) << 20)		| ((caslat_ctrl & 0xF) << 16)		| ((refrec_ctrl & 0xF) << 12)		| ((wrrec_mclk & 0x0F) << 8)		| ((acttoact_mclk & 0x07) << 4)		| ((wrtord_mclk & 0x07) << 0)		);	debug("FSLDDR: timing_cfg_1 = 0x%08x\n", ddr->timing_cfg_1);}/* DDR SDRAM Timing Configuration 2 (TIMING_CFG_2) */static void set_timing_cfg_2(fsl_ddr_cfg_regs_t *ddr,			       const memctl_options_t *popts,			       const common_timing_params_t *common_dimm,			       unsigned int cas_latency,			       unsigned int additive_latency){	/* Additive latency */	unsigned char add_lat_mclk;	/* CAS-to-preamble override */	unsigned short cpo;	/* Write latency */	unsigned char wr_lat;	/*  Read to precharge (tRTP) */	unsigned char rd_to_pre;	/* Write command to write data strobe timing adjustment */	unsigned char wr_data_delay;	/* Minimum CKE pulse width (tCKE) */	unsigned char cke_pls;	/* Window for four activates (tFAW) */	unsigned short four_act;	/* FIXME add check that this must be less than acttorw_mclk */	add_lat_mclk = additive_latency;	cpo = popts->cpo_override;#if defined(CONFIG_FSL_DDR1)	/*	 * This is a lie.  It should really be 1, but if it is	 * set to 1, bits overlap into the old controller's	 * otherwise unused ACSM field.  If we leave it 0, then	 * the HW will magically treat it as 1 for DDR 1.  Oh Yea.	 */	wr_lat = 0;#elif defined(CONFIG_FSL_DDR2)	wr_lat = cas_latency + additive_latency - 1;#else#error "Fix WR_LAT for DDR3"#endif	rd_to_pre = picos_to_mclk(common_dimm->tRTP_ps);	wr_data_delay = popts->write_data_delay;	cke_pls = picos_to_mclk(popts->tCKE_clock_pulse_width_ps);	four_act = picos_to_mclk(popts->tFAW_window_four_activates_ps);	ddr->timing_cfg_2 = (0		| ((add_lat_mclk & 0xf) << 28)		| ((cpo & 0x1f) << 23)		| ((wr_lat & 0xf) << 19)		| ((rd_to_pre & 0x7) << 13)		| ((wr_data_delay & 0x7) << 10)		| ((cke_pls & 0x7) << 6)		| ((four_act & 0x3f) << 0)		);	debug("FSLDDR: timing_cfg_2 = 0x%08x\n", ddr->timing_cfg_2);}/* DDR SDRAM control configuration (DDR_SDRAM_CFG) */static void set_ddr_sdram_cfg(fsl_ddr_cfg_regs_t *ddr,			       const memctl_options_t *popts,			       const common_timing_params_t *common_dimm){	unsigned int mem_en;		/* DDR SDRAM interface logic enable */	unsigned int sren;		/* Self refresh enable (during sleep) */	unsigned int ecc_en;		/* ECC enable. */	unsigned int rd_en;		/* Registered DIMM enable */	unsigned int sdram_type;	/* Type of SDRAM */	unsigned int dyn_pwr;		/* Dynamic power management mode */	unsigned int dbw;		/* DRAM dta bus width */	unsigned int eight_be = 0;	/* 8-beat burst enable, DDR2 is zero */	unsigned int ncap = 0;		/* Non-concurrent auto-precharge */	unsigned int threeT_en;		/* Enable 3T timing */	unsigned int twoT_en;		/* Enable 2T timing */	unsigned int ba_intlv_ctl;	/* Bank (CS) interleaving control */	unsigned int x32_en = 0;	/* x32 enable */	unsigned int pchb8 = 0;		/* precharge bit 8 enable */	unsigned int hse;		/* Global half strength override */	unsigned int mem_halt = 0;	/* memory controller halt */	unsigned int bi = 0;		/* Bypass initialization */	mem_en = 1;	sren = popts->self_refresh_in_sleep;	if (common_dimm->all_DIMMs_ECC_capable) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -