spl_id_nand.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * (C) Copyright 2011
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * Author :
  6. * Tom Rini <trini@ti.com>
  7. *
  8. * Initial Code from:
  9. * Richard Woodruff <r-woodruff2@ti.com>
  10. * Jian Zhang <jzhang@ti.com>
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <linux/mtd/nand.h>
  16. #include <asm/io.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/arch/mem.h>
  19. static struct gpmc *gpmc_config = (struct gpmc *)GPMC_BASE;
  20. /*
  21. * Many boards will want to know the results of the NAND_CMD_READID command
  22. * in order to decide what to do about DDR initialization. This function
  23. * allows us to do that very early and to pass those results back to the
  24. * board so it can make whatever decisions need to be made.
  25. */
  26. int identify_nand_chip(int *mfr, int *id)
  27. {
  28. int loops = 1000;
  29. /* Make sure that we have setup GPMC for NAND correctly. */
  30. writel(M_NAND_GPMC_CONFIG1, &gpmc_config->cs[0].config1);
  31. writel(M_NAND_GPMC_CONFIG2, &gpmc_config->cs[0].config2);
  32. writel(M_NAND_GPMC_CONFIG3, &gpmc_config->cs[0].config3);
  33. writel(M_NAND_GPMC_CONFIG4, &gpmc_config->cs[0].config4);
  34. writel(M_NAND_GPMC_CONFIG5, &gpmc_config->cs[0].config5);
  35. writel(M_NAND_GPMC_CONFIG6, &gpmc_config->cs[0].config6);
  36. /*
  37. * Enable the config. The CS size goes in bits 11:8. We set
  38. * bit 6 to enable the CS and the base address goes into bits 5:0.
  39. */
  40. writel((GPMC_SIZE_128M << 8) | (GPMC_CS_ENABLE << 6) |
  41. ((NAND_BASE >> 24) & GPMC_BASEADDR_MASK),
  42. &gpmc_config->cs[0].config7);
  43. sdelay(2000);
  44. /* Issue a RESET and then READID */
  45. writeb(NAND_CMD_RESET, &gpmc_config->cs[0].nand_cmd);
  46. writeb(NAND_CMD_STATUS, &gpmc_config->cs[0].nand_cmd);
  47. while ((readl(&gpmc_config->cs[0].nand_dat) & NAND_STATUS_READY)
  48. != NAND_STATUS_READY) {
  49. sdelay(100);
  50. if (--loops == 0)
  51. return 1;
  52. }
  53. writeb(NAND_CMD_READID, &gpmc_config->cs[0].nand_cmd);
  54. /* Set the address to read to 0x0 */
  55. writeb(0x0, &gpmc_config->cs[0].nand_adr);
  56. /* Read off the manufacturer and device id. */
  57. *mfr = readb(&gpmc_config->cs[0].nand_dat);
  58. *id = readb(&gpmc_config->cs[0].nand_dat);
  59. return 0;
  60. }