nand_plat.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Genericish driver for memory mapped NAND devices
  3. *
  4. * Copyright (c) 2006-2009 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. /* Your board must implement the following macros:
  8. * NAND_PLAT_WRITE_CMD(chip, cmd)
  9. * NAND_PLAT_WRITE_ADR(chip, cmd)
  10. * NAND_PLAT_INIT()
  11. *
  12. * It may also implement the following:
  13. * NAND_PLAT_DEV_READY(chip)
  14. */
  15. #include <common.h>
  16. #include <asm/io.h>
  17. #ifdef NAND_PLAT_GPIO_DEV_READY
  18. # include <asm/gpio.h>
  19. # define NAND_PLAT_DEV_READY(chip) gpio_get_value(NAND_PLAT_GPIO_DEV_READY)
  20. #endif
  21. #include <nand.h>
  22. static void plat_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  23. {
  24. struct nand_chip *this = mtd_to_nand(mtd);
  25. if (cmd == NAND_CMD_NONE)
  26. return;
  27. if (ctrl & NAND_CLE)
  28. NAND_PLAT_WRITE_CMD(this, cmd);
  29. else
  30. NAND_PLAT_WRITE_ADR(this, cmd);
  31. }
  32. #ifdef NAND_PLAT_DEV_READY
  33. static int plat_dev_ready(struct mtd_info *mtd)
  34. {
  35. return NAND_PLAT_DEV_READY((struct nand_chip *)mtd_to_nand(mtd));
  36. }
  37. #else
  38. # define plat_dev_ready NULL
  39. #endif
  40. int board_nand_init(struct nand_chip *nand)
  41. {
  42. #ifdef NAND_PLAT_GPIO_DEV_READY
  43. gpio_request(NAND_PLAT_GPIO_DEV_READY, "nand-plat");
  44. gpio_direction_input(NAND_PLAT_GPIO_DEV_READY);
  45. #endif
  46. #ifdef NAND_PLAT_INIT
  47. NAND_PLAT_INIT();
  48. #endif
  49. nand->cmd_ctrl = plat_cmd_ctrl;
  50. nand->dev_ready = plat_dev_ready;
  51. nand->ecc.mode = NAND_ECC_SOFT;
  52. return 0;
  53. }