kirkwood_nand.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * (C) Copyright 2009
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/kirkwood.h>
  27. #include <nand.h>
  28. /* NAND Flash Soc registers */
  29. struct kwnandf_registers {
  30. u32 rd_params; /* 0x10418 */
  31. u32 wr_param; /* 0x1041c */
  32. u8 pad[0x10470 - 0x1041c - 4];
  33. u32 ctrl; /* 0x10470 */
  34. };
  35. static struct kwnandf_registers *nf_reg =
  36. (struct kwnandf_registers *)KW_NANDF_BASE;
  37. /*
  38. * hardware specific access to control-lines/bits
  39. */
  40. #define NAND_ACTCEBOOT_BIT 0x02
  41. static void kw_nand_hwcontrol(struct mtd_info *mtd, int cmd,
  42. unsigned int ctrl)
  43. {
  44. struct nand_chip *nc = mtd->priv;
  45. u32 offs;
  46. if (cmd == NAND_CMD_NONE)
  47. return;
  48. if (ctrl & NAND_CLE)
  49. offs = (1 << 0); /* Commands with A[1:0] == 01 */
  50. else if (ctrl & NAND_ALE)
  51. offs = (1 << 1); /* Addresses with A[1:0] == 10 */
  52. else
  53. return;
  54. writeb(cmd, nc->IO_ADDR_W + offs);
  55. }
  56. void kw_nand_select_chip(struct mtd_info *mtd, int chip)
  57. {
  58. u32 data;
  59. data = readl(&nf_reg->ctrl);
  60. data |= NAND_ACTCEBOOT_BIT;
  61. writel(data, &nf_reg->ctrl);
  62. }
  63. int board_nand_init(struct nand_chip *nand)
  64. {
  65. nand->options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING;
  66. nand->ecc.mode = NAND_ECC_SOFT;
  67. nand->cmd_ctrl = kw_nand_hwcontrol;
  68. nand->chip_delay = 30;
  69. nand->select_chip = kw_nand_select_chip;
  70. return 0;
  71. }