nandflash.c 3.9 KB

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