nand.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * (C) Copyright 2008
  3. * Gary Jennejohn, DENX Software Engineering GmbH, garyj@denx.de
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <config.h>
  25. #if defined(CONFIG_CMD_NAND)
  26. #include <asm/gpio.h>
  27. #include <asm/io.h>
  28. #include <nand.h>
  29. /*
  30. * hardware specific access to control-lines
  31. */
  32. static void quad100hd_hwcontrol(struct mtd_info *mtd,
  33. int cmd, unsigned int ctrl)
  34. {
  35. struct nand_chip *this = mtd->priv;
  36. if (ctrl & NAND_CTRL_CHANGE) {
  37. gpio_write_bit(CONFIG_SYS_NAND_CLE, !!(ctrl & NAND_CLE));
  38. gpio_write_bit(CONFIG_SYS_NAND_ALE, !!(ctrl & NAND_ALE));
  39. gpio_write_bit(CONFIG_SYS_NAND_CE, !(ctrl & NAND_NCE));
  40. }
  41. if (cmd != NAND_CMD_NONE)
  42. writeb(cmd, this->IO_ADDR_W);
  43. }
  44. static int quad100hd_nand_ready(struct mtd_info *mtd)
  45. {
  46. return gpio_read_in_bit(CONFIG_SYS_NAND_RDY);
  47. }
  48. /*
  49. * Main initialization routine
  50. */
  51. int board_nand_init(struct nand_chip *nand)
  52. {
  53. /* Set address of hardware control function */
  54. nand->cmd_ctrl = quad100hd_hwcontrol;
  55. nand->dev_ready = quad100hd_nand_ready;
  56. nand->ecc.mode = NAND_ECC_SOFT;
  57. /* 15 us command delay time */
  58. nand->chip_delay = 20;
  59. /* Return happy */
  60. return 0;
  61. }
  62. #endif /* CONFIG_CMD_NAND */