微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > MCU和DSP > S5PV210之Nand flash驱动编写

S5PV210之Nand flash驱动编写

时间:12-10 来源:互联网 点击:
  •         dev_dbg(&pdev->dev, "get clk failed\n");  
  •         ret = -ENODEV;  
  •         goto err_iounmap;  
  •     }  
  •   
  •     clk_enable(s5p_nand_clk);  
  •       
  •     s5p_nand_regs->nfconf = (3<<12)|(5<<8)|(3<<4)|(1<<1);  
  •     s5p_nand_regs->nfcont |= 3;  
  •   
  •     //分配驱动相关结构体  
  •     nand_chip = (struct nand_chip *)kzalloc(sizeof(struct nand_chip), GFP_KERNEL);  
  •     if(nand_chip == NULL){  
  •         dev_err(&pdev->dev, "failed to allocate nand_chip structure\n");  
  •         ret = -ENOMEM;  
  •         goto err_clk_put;  
  •     }  
  •   
  •     s5p_mtd_info = (struct mtd_info *)kzalloc(sizeof(struct mtd_info), GFP_KERNEL);  
  •     if(s5p_mtd_info == NULL){  
  •         dev_err(&pdev->dev, "failed to allocate mtd_info structure\n");  
  •         ret = -ENOMEM;  
  •         goto err_free_chip;  
  •     }  
  •   
  •     //设置驱动相关结构体  
  •     nand_chip->select_chip = s5p_nand_select_chip;  
  •     nand_chip->cmd_ctrl    = s5p_nand_cmd_ctrl;  
  •     nand_chip->IO_ADDR_R   = &s5p_nand_regs->nfdata;  
  •     nand_chip->IO_ADDR_W   = &s5p_nand_regs->nfdata;  
  •     nand_chip->dev_ready   = s5p_nand_ready;  
  •     nand_chip->ecc.mode       = NAND_ECC_SOFT;  
  •       
  •     s5p_mtd_info->priv = nand_chip;  
  •     s5p_mtd_info->owner = THIS_MODULE;  
  •   
  •     //扫描Nand flash 设备  
  •     if(nand_scan(s5p_mtd_info, 1)){  
  •         dev_dbg(&pdev->dev, "nand scan error\n");  
  •         goto err_free_info;  
  •     }  
  •   
  •     //添加分区信息  
  •     ret = mtd_device_parse_register(s5p_mtd_info, NULL, NULL, s5p_nand_partions, ARRAY_SIZE(s5p_nand_partions));  
  •     if(!ret)  
  •         return 0;  
  •   
  • err_free_info:  
  •     kfree(s5p_mtd_info);  
  • err_free_chip:  
  •     kfree(nand_chip);  
  • err_clk_put:  
  •     clk_disable(s5p_nand_clk);  
  •     clk_put(s5p_nand_clk);  
  • err_iounmap:  
  •     //if(s5p_nand_ecc == NULL)  
  •     //  iounmap(s5p_nand_ecc);  
  •     if(s5p_nand_regs == NULL)  
  •         iounmap(s5p_nand_regs);  
  • err_exit:  
  •     return ret;  
  • }  
  •   
  • static int s5p_nand_remove(struct platform_device *pdev){  
  •     nand_release(s5p_mtd_info);  
  •     kfree(s5p_mtd_info);  
  •     kfree(nan

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top