esd405ep_nand.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * (C) Copyright 2007
  3. * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #if defined(CONFIG_CMD_NAND)
  9. #include <asm/io.h>
  10. #include <nand.h>
  11. /*
  12. * hardware specific access to control-lines
  13. */
  14. static void esd405ep_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  15. {
  16. struct nand_chip *this = mtd_to_nand(mtd);
  17. if (ctrl & NAND_CTRL_CHANGE) {
  18. if ( ctrl & NAND_CLE )
  19. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CLE);
  20. else
  21. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CLE);
  22. if ( ctrl & NAND_ALE )
  23. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_ALE);
  24. else
  25. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_ALE);
  26. if ( ctrl & NAND_NCE )
  27. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~CONFIG_SYS_NAND_CE);
  28. else
  29. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CE);
  30. }
  31. if (cmd != NAND_CMD_NONE)
  32. writeb(cmd, this->IO_ADDR_W);
  33. }
  34. /*
  35. * read device ready pin
  36. */
  37. static int esd405ep_nand_device_ready(struct mtd_info *mtdinfo)
  38. {
  39. if (in_be32((void *)GPIO0_IR) & CONFIG_SYS_NAND_RDY)
  40. return 1;
  41. return 0;
  42. }
  43. int board_nand_init(struct nand_chip *nand)
  44. {
  45. /*
  46. * Set NAND-FLASH GPIO signals to defaults
  47. */
  48. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) & ~(CONFIG_SYS_NAND_CLE | CONFIG_SYS_NAND_ALE));
  49. out_be32((void *)GPIO0_OR, in_be32((void *)GPIO0_OR) | CONFIG_SYS_NAND_CE);
  50. /*
  51. * Initialize nand_chip structure
  52. */
  53. nand->cmd_ctrl = esd405ep_nand_hwcontrol;
  54. nand->dev_ready = esd405ep_nand_device_ready;
  55. nand->ecc.mode = NAND_ECC_SOFT;
  56. nand->chip_delay = NAND_BIG_DELAY_US;
  57. nand->options = NAND_SAMSUNG_LP_OPTIONS;
  58. return 0;
  59. }
  60. #endif