spl_id_nand.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <linux/mtd/nand.h>
  29. #include <asm/io.h>
  30. #include <asm/arch/sys_proto.h>
  31. #include <asm/arch/mem.h>
  32. static struct gpmc *gpmc_config = (struct gpmc *)GPMC_BASE;
  33. /* nand_command: Send a flash command to the flash chip */
  34. static void nand_command(u8 command)
  35. {
  36. writeb(command, &gpmc_config->cs[0].nand_cmd);
  37. if (command == NAND_CMD_RESET) {
  38. unsigned char ret_val;
  39. writeb(NAND_CMD_STATUS, &gpmc_config->cs[0].nand_cmd);
  40. do {
  41. /* Wait until ready */
  42. ret_val = readl(&gpmc_config->cs[0].nand_dat);
  43. } while ((ret_val & NAND_STATUS_READY) != NAND_STATUS_READY);
  44. }
  45. }
  46. /*
  47. * Many boards will want to know the results of the NAND_CMD_READID command
  48. * in order to decide what to do about DDR initialization. This function
  49. * allows us to do that very early and to pass those results back to the
  50. * board so it can make whatever decisions need to be made.
  51. */
  52. void identify_nand_chip(int *mfr, int *id)
  53. {
  54. /* Make sure that we have setup GPMC for NAND correctly. */
  55. writel(M_NAND_GPMC_CONFIG1, &gpmc_config->cs[0].config1);
  56. writel(M_NAND_GPMC_CONFIG2, &gpmc_config->cs[0].config2);
  57. writel(M_NAND_GPMC_CONFIG3, &gpmc_config->cs[0].config3);
  58. writel(M_NAND_GPMC_CONFIG4, &gpmc_config->cs[0].config4);
  59. writel(M_NAND_GPMC_CONFIG5, &gpmc_config->cs[0].config5);
  60. writel(M_NAND_GPMC_CONFIG6, &gpmc_config->cs[0].config6);
  61. /*
  62. * Enable the config. The CS size goes in bits 11:8. We set
  63. * bit 6 to enable the CS and the base address goes into bits 5:0.
  64. */
  65. writel((GPMC_SIZE_128M << 8) | (GPMC_CS_ENABLE << 6) |
  66. ((NAND_BASE >> 24) & GPMC_BASEADDR_MASK),
  67. &gpmc_config->cs[0].config7);
  68. sdelay(2000);
  69. /* Issue a RESET and then READID */
  70. nand_command(NAND_CMD_RESET);
  71. nand_command(NAND_CMD_READID);
  72. /* Set the address to read to 0x0 */
  73. writeb(0x0, &gpmc_config->cs[0].nand_adr);
  74. /* Read off the manufacturer and device id. */
  75. *mfr = readb(&gpmc_config->cs[0].nand_dat);
  76. *id = readb(&gpmc_config->cs[0].nand_dat);
  77. }