nand.c 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2010-2023 CS GROUP France
  4. * Florent TRINH THAI (florent.trinh-thai@csgroup.eu)
  5. * Stephane FRANJOU (stephane.franjou@csgroup.eu)
  6. */
  7. #include <config.h>
  8. #include <nand.h>
  9. #include <linux/bitops.h>
  10. #include <linux/mtd/rawnand.h>
  11. #include <asm/io.h>
  12. #define BIT_CLE BIT(6)
  13. #define BIT_ALE BIT(5)
  14. static u32 nand_mask(unsigned int ctrl)
  15. {
  16. return ((ctrl & NAND_CLE) ? BIT_CLE : 0) |
  17. ((ctrl & NAND_ALE) ? BIT_ALE : 0);
  18. }
  19. static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
  20. {
  21. immap_t __iomem *immr = (immap_t *)CONFIG_SYS_IMMR;
  22. struct nand_chip *chip = mtd_to_nand(mtdinfo);
  23. if (ctrl & NAND_CTRL_CHANGE)
  24. clrsetbits_be32(&immr->qepio.ioport[2].pdat,
  25. BIT_CLE | BIT_ALE, nand_mask(ctrl));
  26. if (cmd != NAND_CMD_NONE)
  27. out_8(chip->IO_ADDR_W, cmd);
  28. }
  29. int board_nand_init(struct nand_chip *nand)
  30. {
  31. nand->chip_delay = 60;
  32. nand->ecc.mode = NAND_ECC_SOFT;
  33. nand->cmd_ctrl = nand_hwcontrol;
  34. return 0;
  35. }