sc3nand.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * (C) Copyright 2007
  3. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #if defined(CONFIG_CMD_NAND)
  25. #include <nand.h>
  26. #include <asm/processor.h>
  27. #define readb(addr) *(volatile u_char *)(addr)
  28. #define readl(addr) *(volatile u_long *)(addr)
  29. #define writeb(d,addr) *(volatile u_char *)(addr) = (d)
  30. #define SC3_NAND_ALE 29 /* GPIO PIN 3 */
  31. #define SC3_NAND_CLE 30 /* GPIO PIN 2 */
  32. #define SC3_NAND_CE 27 /* GPIO PIN 5 */
  33. static void *sc3_io_base;
  34. static void *sc3_control_base = (void *)0xEF600700;
  35. static void sc3_nand_hwcontrol(struct mtd_info *mtd, int cmd)
  36. {
  37. switch (cmd) {
  38. case NAND_CTL_SETCLE:
  39. set_bit (SC3_NAND_CLE, sc3_control_base);
  40. break;
  41. case NAND_CTL_CLRCLE:
  42. clear_bit (SC3_NAND_CLE, sc3_control_base);
  43. break;
  44. case NAND_CTL_SETALE:
  45. set_bit (SC3_NAND_ALE, sc3_control_base);
  46. break;
  47. case NAND_CTL_CLRALE:
  48. clear_bit (SC3_NAND_ALE, sc3_control_base);
  49. break;
  50. case NAND_CTL_SETNCE:
  51. set_bit (SC3_NAND_CE, sc3_control_base);
  52. break;
  53. case NAND_CTL_CLRNCE:
  54. clear_bit (SC3_NAND_CE, sc3_control_base);
  55. break;
  56. }
  57. }
  58. static int sc3_nand_dev_ready(struct mtd_info *mtd)
  59. {
  60. if (!(readl(sc3_control_base + 0x1C) & 0x4000))
  61. return 0;
  62. return 1;
  63. }
  64. static void sc3_select_chip(struct mtd_info *mtd, int chip)
  65. {
  66. clear_bit (SC3_NAND_CE, sc3_control_base);
  67. }
  68. int board_nand_init(struct nand_chip *nand)
  69. {
  70. nand->eccmode = NAND_ECC_SOFT;
  71. sc3_io_base = (void *) CFG_NAND_BASE;
  72. /* Set address of NAND IO lines (Using Linear Data Access Region) */
  73. nand->IO_ADDR_R = (void __iomem *) sc3_io_base;
  74. nand->IO_ADDR_W = (void __iomem *) sc3_io_base;
  75. /* Reference hardware control function */
  76. nand->hwcontrol = sc3_nand_hwcontrol;
  77. nand->dev_ready = sc3_nand_dev_ready;
  78. nand->select_chip = sc3_select_chip;
  79. return 0;
  80. }
  81. #endif