Chinaunix首页 | 论坛 | 博客
  • 博客访问: 393905
  • 博文数量: 138
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1620
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-10 16:55
个人简介

当你比别人优秀一点点,别人会嫉妒你。当你比别人优秀很多,别人会羡慕你。

文章分类

全部博文(138)

文章存档

2016年(2)

2015年(2)

2014年(15)

2013年(119)

我的朋友

分类: LINUX

2013-05-02 06:53:32


点击(此处)折叠或打开

  1. #include <common.h>
  2.  
  3. #if (CONFIG_COMMANDS & CFG_CMD_NAND) && !defined(CFG_NAND_LEGACY)
  4. #include <s3c2410.h>
  5. #include <nand.h>
  6.  
  7. DECLARE_GLOBAL_DATA_PTR;
  8.  
  9. #define S3C2410_NFSTAT_READY (1<<0)
  10. #define S3C2410_NFCONF_nFCE (1<<11)
  11.  
  12. #define S3C2440_NFSTAT_READY (1<<0)
  13. #define S3C2440_NFCONT_nFCE (1<<1)




  14. static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
  15. {
  16.     S3C2410_NAND * const s3c2410nand = S3C2410_GetBase_NAND();
  17.  
  18.     if (chip == -1) {
  19.         s3c2410nand->NFCONF |= S3C2410_NFCONF_nFCE;
  20.     } else {
  21.         s3c2410nand->NFCONF &= ~S3C2410_NFCONF_nFCE;
  22.     }
  23. }




  24. static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd)
  25. {
  26.     S3C2410_NAND * const s3c2410nand = S3C2410_GetBase_NAND();
  27.     struct nand_chip *chip = mtd->priv;
  28.  
  29.     switch (cmd) {
  30.     case NAND_CTL_SETNCE:
  31.     case NAND_CTL_CLRNCE:
  32.         printf("%s: called for NCE\n", __FUNCTION__);
  33.         break;
  34.  
  35.     case NAND_CTL_SETCLE:
  36.         chip->IO_ADDR_W = (void *)&s3c2410nand->NFCMD;
  37.         break;
  38.  
  39.     case NAND_CTL_SETALE:
  40.         chip->IO_ADDR_W = (void *)&s3c2410nand->NFADDR;
  41.         break;
  42.  
  43.         
  44.        
  45.     default:
  46.         chip->IO_ADDR_W = (void *)&s3c2410nand->NFDATA;
  47.         break;
  48.     }
  49. }




  50. static int s3c2410_nand_devready(struct mtd_info *mtd)
  51. {
  52.     S3C2410_NAND * const s3c2410nand = S3C2410_GetBase_NAND();
  53.  
  54.     return (s3c2410nand->NFSTAT & S3C2410_NFSTAT_READY);
  55. }
  56.  
  57.  
  58.  
  59. static void s3c2440_nand_select_chip(struct mtd_info *mtd, int chip)
  60. {
  61.     S3C2440_NAND * const s3c2440nand = S3C2440_GetBase_NAND();
  62.  
  63.     if (chip == -1) {
  64.         s3c2440nand->NFCONT |= S3C2440_NFCONT_nFCE;
  65.     } else {
  66.         s3c2440nand->NFCONT &= ~S3C2440_NFCONT_nFCE;
  67.     }
  68. }
  69.  
  70.  
  71. static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd)
  72. {
  73.     S3C2440_NAND * const s3c2440nand = S3C2440_GetBase_NAND();
  74.     struct nand_chip *chip = mtd->priv;
  75.  
  76.     switch (cmd) {
  77.     case NAND_CTL_SETNCE:
  78.     case NAND_CTL_CLRNCE:
  79.         printf("%s: called for NCE\n", __FUNCTION__);
  80.         break;
  81.  
  82.     case NAND_CTL_SETCLE:
  83.         chip->IO_ADDR_W = (void *)&s3c2440nand->NFCMD;
  84.         break;
  85.  
  86.     case NAND_CTL_SETALE:
  87.         chip->IO_ADDR_W = (void *)&s3c2440nand->NFADDR;
  88.         break;
  89.  
  90.        
  91.        
  92.     default:
  93.         chip->IO_ADDR_W = (void *)&s3c2440nand->NFDATA;
  94.         break;
  95.     }
  96. }
  97.  
  98.  
  99. static int s3c2440_nand_devready(struct mtd_info *mtd)
  100. {
  101.     S3C2440_NAND * const s3c2440nand = S3C2440_GetBase_NAND();
  102.  
  103.     return (s3c2440nand->NFSTAT & S3C2440_NFSTAT_READY);
  104. }
  105.  
  106.  
  107. static void s3c24x0_nand_inithw(void)
  108. {
  109.     S3C2410_NAND * const s3c2410nand = S3C2410_GetBase_NAND();
  110.     S3C2440_NAND * const s3c2440nand = S3C2440_GetBase_NAND();
  111.  
  112. #define TACLS 0
  113. #define TWRPH0 4
  114. #define TWRPH1 2
  115.  
  116.     if (gd->bd->bi_arch_number == MACH_TYPE_SMDK2410)
  117.     {
  118.        
  119.         s3c2410nand->NFCONF = (1<<15)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);
  120.     }
  121.     else
  122.     {
  123.        
  124.         s3c2440nand->NFCONF = (TACLS<<12)|(TWRPH0<<8)|(TWRPH1<<4);
  125.        
  126.         s3c2440nand->NFCONT = (1<<4)|(0<<1)|(1<<0);
  127.     }
  128. }
  129.  
  130.  
  131. void board_nand_init(struct nand_chip *chip)
  132. {
  133.     S3C2410_NAND * const s3c2410nand = S3C2410_GetBase_NAND();
  134.     S3C2440_NAND * const s3c2440nand = S3C2440_GetBase_NAND();
  135.  
  136.     s3c24x0_nand_inithw();
  137.  
  138.     if (gd->bd->bi_arch_number == MACH_TYPE_SMDK2410) {
  139.         chip->IO_ADDR_R = (void *)&s3c2410nand->NFDATA;
  140.         chip->IO_ADDR_W = (void *)&s3c2410nand->NFDATA;
  141.         chip->hwcontrol = s3c2410_nand_hwcontrol;
  142.         chip->dev_ready = s3c2410_nand_devready;
  143.         chip->select_chip = s3c2410_nand_select_chip;
  144.         chip->options = 0;
  145.     } else {
  146.         chip->IO_ADDR_R = (void *)&s3c2440nand->NFDATA;
  147.         chip->IO_ADDR_W = (void *)&s3c2440nand->NFDATA;
  148.         chip->hwcontrol = s3c2440_nand_hwcontrol;
  149.         chip->dev_ready = s3c2440_nand_devready;
  150.         chip->select_chip = s3c2440_nand_select_chip;
  151.         chip->options = 0;
  152.     }
  153.  
  154.     chip->eccmode = NAND_ECC_SOFT;
  155. }
  156.  
  157. #endif


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