nandflash.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * arch/cris/arch-v32/drivers/nandflash.c
  3. *
  4. * Copyright (c) 2004
  5. *
  6. * Derived from drivers/mtd/nand/spia.c
  7. * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
  8. *
  9. * $Id: nandflash.c,v 1.3 2005/06/01 10:57:12 starvik Exp $
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. *
  15. */
  16. #include <linux/slab.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/mtd/mtd.h>
  20. #include <linux/mtd/nand.h>
  21. #include <linux/mtd/partitions.h>
  22. #include <asm/arch/memmap.h>
  23. #include <asm/arch/hwregs/reg_map.h>
  24. #include <asm/arch/hwregs/reg_rdwr.h>
  25. #include <asm/arch/hwregs/gio_defs.h>
  26. #include <asm/arch/hwregs/bif_core_defs.h>
  27. #include <asm/io.h>
  28. #define CE_BIT 4
  29. #define CLE_BIT 5
  30. #define ALE_BIT 6
  31. #define BY_BIT 7
  32. static struct mtd_info *crisv32_mtd = NULL;
  33. /*
  34. * hardware specific access to control-lines
  35. */
  36. static void crisv32_hwcontrol(struct mtd_info *mtd, int cmd)
  37. {
  38. unsigned long flags;
  39. reg_gio_rw_pa_dout dout = REG_RD(gio, regi_gio, rw_pa_dout);
  40. local_irq_save(flags);
  41. switch(cmd){
  42. case NAND_CTL_SETCLE:
  43. dout.data |= (1<<CLE_BIT);
  44. break;
  45. case NAND_CTL_CLRCLE:
  46. dout.data &= ~(1<<CLE_BIT);
  47. break;
  48. case NAND_CTL_SETALE:
  49. dout.data |= (1<<ALE_BIT);
  50. break;
  51. case NAND_CTL_CLRALE:
  52. dout.data &= ~(1<<ALE_BIT);
  53. break;
  54. case NAND_CTL_SETNCE:
  55. dout.data |= (1<<CE_BIT);
  56. break;
  57. case NAND_CTL_CLRNCE:
  58. dout.data &= ~(1<<CE_BIT);
  59. break;
  60. }
  61. REG_WR(gio, regi_gio, rw_pa_dout, dout);
  62. local_irq_restore(flags);
  63. }
  64. /*
  65. * read device ready pin
  66. */
  67. int crisv32_device_ready(struct mtd_info *mtd)
  68. {
  69. reg_gio_r_pa_din din = REG_RD(gio, regi_gio, r_pa_din);
  70. return ((din.data & (1 << BY_BIT)) >> BY_BIT);
  71. }
  72. /*
  73. * Main initialization routine
  74. */
  75. struct mtd_info* __init crisv32_nand_flash_probe (void)
  76. {
  77. void __iomem *read_cs;
  78. void __iomem *write_cs;
  79. reg_bif_core_rw_grp3_cfg bif_cfg = REG_RD(bif_core, regi_bif_core, rw_grp3_cfg);
  80. reg_gio_rw_pa_oe pa_oe = REG_RD(gio, regi_gio, rw_pa_oe);
  81. struct nand_chip *this;
  82. int err = 0;
  83. /* Allocate memory for MTD device structure and private data */
  84. crisv32_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
  85. GFP_KERNEL);
  86. if (!crisv32_mtd) {
  87. printk ("Unable to allocate CRISv32 NAND MTD device structure.\n");
  88. err = -ENOMEM;
  89. return NULL;
  90. }
  91. read_cs = ioremap(MEM_CSP0_START | MEM_NON_CACHEABLE, 8192);
  92. write_cs = ioremap(MEM_CSP1_START | MEM_NON_CACHEABLE, 8192);
  93. if (!read_cs || !write_cs) {
  94. printk("CRISv32 NAND ioremap failed\n");
  95. err = -EIO;
  96. goto out_mtd;
  97. }
  98. /* Get pointer to private data */
  99. this = (struct nand_chip *) (&crisv32_mtd[1]);
  100. pa_oe.oe |= 1 << CE_BIT;
  101. pa_oe.oe |= 1 << ALE_BIT;
  102. pa_oe.oe |= 1 << CLE_BIT;
  103. pa_oe.oe &= ~ (1 << BY_BIT);
  104. REG_WR(gio, regi_gio, rw_pa_oe, pa_oe);
  105. bif_cfg.gated_csp0 = regk_bif_core_rd;
  106. bif_cfg.gated_csp1 = regk_bif_core_wr;
  107. REG_WR(bif_core, regi_bif_core, rw_grp3_cfg, bif_cfg);
  108. /* Initialize structures */
  109. memset((char *) crisv32_mtd, 0, sizeof(struct mtd_info));
  110. memset((char *) this, 0, sizeof(struct nand_chip));
  111. /* Link the private data with the MTD structure */
  112. crisv32_mtd->priv = this;
  113. /* Set address of NAND IO lines */
  114. this->IO_ADDR_R = read_cs;
  115. this->IO_ADDR_W = write_cs;
  116. this->hwcontrol = crisv32_hwcontrol;
  117. this->dev_ready = crisv32_device_ready;
  118. /* 20 us command delay time */
  119. this->chip_delay = 20;
  120. this->eccmode = NAND_ECC_SOFT;
  121. /* Enable the following for a flash based bad block table */
  122. this->options = NAND_USE_FLASH_BBT;
  123. /* Scan to find existance of the device */
  124. if (nand_scan (crisv32_mtd, 1)) {
  125. err = -ENXIO;
  126. goto out_ior;
  127. }
  128. return crisv32_mtd;
  129. out_ior:
  130. iounmap((void *)read_cs);
  131. iounmap((void *)write_cs);
  132. out_mtd:
  133. kfree (crisv32_mtd);
  134. return NULL;
  135. }