nand.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <config.h>
  11. #include <common.h>
  12. #include <asm/io.h>
  13. #include <asm/immap.h>
  14. #if defined(CONFIG_CMD_NAND)
  15. #include <nand.h>
  16. #include <linux/mtd/mtd.h>
  17. #define SET_CLE 0x10
  18. #define SET_ALE 0x08
  19. static void nand_hwcontrol(struct mtd_info *mtdinfo, int cmd, unsigned int ctrl)
  20. {
  21. struct nand_chip *this = mtd_to_nand(mtdinfo);
  22. volatile u16 *nCE = (u16 *) CONFIG_SYS_LATCH_ADDR;
  23. if (ctrl & NAND_CTRL_CHANGE) {
  24. ulong IO_ADDR_W = (ulong) this->IO_ADDR_W;
  25. IO_ADDR_W &= ~(SET_ALE | SET_CLE);
  26. if (ctrl & NAND_NCE)
  27. *nCE &= 0xFFFB;
  28. else
  29. *nCE |= 0x0004;
  30. if (ctrl & NAND_CLE)
  31. IO_ADDR_W |= SET_CLE;
  32. if (ctrl & NAND_ALE)
  33. IO_ADDR_W |= SET_ALE;
  34. this->IO_ADDR_W = (void *)IO_ADDR_W;
  35. }
  36. if (cmd != NAND_CMD_NONE)
  37. writeb(cmd, this->IO_ADDR_W);
  38. }
  39. int board_nand_init(struct nand_chip *nand)
  40. {
  41. gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  42. fbcs_t *fbcs = (fbcs_t *) MMAP_FBCS;
  43. clrbits_be32(&fbcs->csmr2, FBCS_CSMR_WP);
  44. /*
  45. * set up pin configuration - enabled 2nd output buffer's signals
  46. * (nand_ngpio - nCE USB1/2_PWR_EN, LATCH_GPIOs, LCD_VEEEN, etc)
  47. * to use nCE signal
  48. */
  49. clrbits_8(&gpio->par_timer, GPIO_PAR_TIN3_TIN3);
  50. setbits_8(&gpio->pddr_timer, 0x08);
  51. setbits_8(&gpio->ppd_timer, 0x08);
  52. out_8(&gpio->pclrr_timer, 0);
  53. out_8(&gpio->podr_timer, 0);
  54. nand->chip_delay = 60;
  55. nand->ecc.mode = NAND_ECC_SOFT;
  56. nand->cmd_ctrl = nand_hwcontrol;
  57. return 0;
  58. }
  59. #endif