Chinaunix首页 | 论坛 | 博客
  • 博客访问: 241157
  • 博文数量: 76
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 440
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-20 14:21
文章分类

全部博文(76)

文章存档

2015年(76)

我的朋友

分类: 其他平台

2015-05-11 11:31:56


点击(此处)折叠或打开

  1. #include <common.h>

  2. #define MEMCCMD    0x7e001004    //32-bit DRAM controller command register
  3. #define P1REFRESH    0x7e001010    //32-bit DRAM controller refresh period register
  4. #define P1CASLAT    0x7e001014    //32-bit DRAM controller CAS latency register
  5. #define MEM_SYS_CFG    0x7e00f120    //Configure memory subsystem
  6. #define P1MEMCFG    0x7e00100c    //32-bit DRAM controller memory configuration register
  7. #define P1T_DQSS    0x7e001018    //32-bit DRAM controller t_DQSS register
  8. #define P1T_MRD        0x7e00101c    //32-bit DRAM controller t_MRD register
  9. #define P1T_RAS        0x7e001020    //32-bit DRAM controller t_RAS register
  10. #define P1T_RC        0x7e001024    //32-bit DRAM controller t_RC register
  11. #define P1T_RCD        0x7e001028    //32-bit DRAM controller t_RCD register
  12. #define P1T_RFC        0x7e00102c    //32-bit DRAM controller t_RFC register
  13. #define P1T_RP        0x7e001030    //32-bit DRAM controller t_RP register
  14. #define P1T_RRD        0x7e001034    //32-bit DRAM controller t_RRD register
  15. #define P1T_WR        0x7e001038    //32-bit DRAM controller t_WR register
  16. #define P1T_WTR        0x7e00103c    //32-bit DRAM controller t_WTR register
  17. #define P1T_XP        0x7e001040    //32-bit DRAM controller t_XP register
  18. #define P1T_XSR        0x7e001044    //32-bit DRAM controller t_XSR register
  19. #define P1T_ESR        0x7e001048    //32-bit DRAM controller t_ESR register
  20. #define P1MEMCFG2    0X7e00104c    //32-bit DRAM controller configuration register
  21. #define P1_chip_0_cfg    0x7e001200    //32-bit DRAM controller chip_<n>_cfg register

  22. #define P1MEMSTAT    0x7e001000    //32-bit DRAM controller status register
  23. #define P1MEMCCMD    0x7e001004    //32-bit DRAM controller command register
  24. #define P1DIRECTCMD    0x7e001008    //32-bit DRAM controller direct command register

  25.     
  26. #define HCLK    133000000    

  27. #define nstoclk(ns)    (ns/( 1000000000/HCLK)+1)    //convert nanosecond to clock cycle count

  28. //initialize sdram ,according to "5.4 SDRAM INITIALIZATION SEQUENCE" in the s3c6410 manual
  29. int ddr_init( void )
  30. {
  31.     // tell dramc to configure, 0x4 is configure command                
  32.     set_val( MEMCCMD, 0x4 );

  33.     // set refresh period    
  34.     set_val( P1REFRESH, nstoclk(7800) );

  35.     // set timing para, according to "AC Timming Parameters & Specifications" in the K4X51163PC manual
  36.     set_val( P1CASLAT, ( 3 << 1 ) );
  37.     set_val( P1T_DQSS, 0x1 );    // 0.75 - 1.25
  38.     set_val( P1T_MRD, 0x2 );
  39.     set_val( P1T_RAS, nstoclk(45) );
  40.     set_val( P1T_RC, nstoclk(68) );        

  41.     u32 trcd = nstoclk( 23 );
  42.     set_val( P1T_RCD, trcd | (( trcd - 3 ) << 3 ) );
  43.     u32 trfc = nstoclk( 80 );
  44.     set_val( P1T_RFC, trfc | ( ( trfc-3 ) << 5 ) );
  45.     u32 trp = nstoclk( 23 );
  46.     set_val( P1T_RP, trp | ( ( trp - 3 ) << 3 ) );
  47.     set_val( P1T_RRD, nstoclk(15) );
  48.     set_val( P1T_WR, nstoclk(15) );
  49.     set_val( P1T_WTR, 0x7 );
  50.     set_val( P1T_XP, 0x2 );
  51.     set_val( P1T_XSR, nstoclk(120) );
  52.     set_val( P1T_ESR, nstoclk(120) );
  53.     
  54.     // set mem cfg
  55.     set_nbit( P1MEMCFG, 0, 3, 0x2 ); /* 10 column address */

  56.     /* set_nbit: 把从第bit位开始的一共len位消零,然后把这几位设为val */
  57.     
  58.     set_nbit( P1MEMCFG, 3, 3, 0x2 ); /* 13 row address */
  59.     set_zero( P1MEMCFG, 6 );         /* A10/AP */
  60.     set_nbit( P1MEMCFG, 15, 3, 0x2 ); /* Burst 4 */
  61.     
  62.     set_nbit( P1MEMCFG2, 0, 4, 0x5 );
  63.     set_2bit( P1MEMCFG2, 6, 0x1 );        /* 32 bit */
  64.     set_nbit( P1MEMCFG2, 8, 3, 0x3 );    /* Mobile DDR SDRAM */
  65.     set_2bit( P1MEMCFG2, 11, 0x1 );

  66.     set_one( P1_chip_0_cfg, 16 );        /* Bank-Row-Column organization */

  67.     // memory init
  68.     set_val( P1DIRECTCMD, 0xc0000 ); // NOP
  69.     set_val( P1DIRECTCMD, 0x000 );    // precharge
  70.     set_val( P1DIRECTCMD, 0x40000 );// auto refresh
  71.     set_val( P1DIRECTCMD, 0x40000 );// auto refresh
  72.     set_val( P1DIRECTCMD, 0xa0000 ); // EMRS
  73.     set_val( P1DIRECTCMD, 0x80032 ); // MRS

  74.     set_val( MEM_SYS_CFG, 0x0 );
  75.                     
  76.     // set dramc to "go" status    
  77.     set_val( P1MEMCCMD, 0x000 );

  78.     // wait ready
  79.     while( !(( read_val( P1MEMSTAT ) & 0x3 ) == 0x1));
  80. }


阅读(1357) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~