toto.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * drivers/mtd/nand/toto.c
  3. *
  4. * Copyright (c) 2003 Texas Instruments
  5. *
  6. * Derived from drivers/mtd/autcpu12.c
  7. *
  8. * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. *
  14. * Overview:
  15. * This is a device driver for the NAND flash device found on the
  16. * TI fido board. It supports 32MiB and 64MiB cards
  17. *
  18. * $Id: toto.c,v 1.5 2005/11/07 11:14:31 gleixner Exp $
  19. */
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/delay.h>
  24. #include <linux/mtd/mtd.h>
  25. #include <linux/mtd/nand.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/hardware.h>
  29. #include <asm/sizes.h>
  30. #include <asm/arch/toto.h>
  31. #include <asm/arch-omap1510/hardware.h>
  32. #include <asm/arch/gpio.h>
  33. /*
  34. * MTD structure for TOTO board
  35. */
  36. static struct mtd_info *toto_mtd = NULL;
  37. static unsigned long toto_io_base = OMAP_FLASH_1_BASE;
  38. #define CONFIG_NAND_WORKAROUND 1
  39. #define NAND_NCE 0x4000
  40. #define NAND_CLE 0x1000
  41. #define NAND_ALE 0x0002
  42. #define NAND_MASK (NAND_CLE | NAND_ALE | NAND_NCE)
  43. #define T_NAND_CTL_CLRALE(iob) gpiosetout(NAND_ALE, 0)
  44. #define T_NAND_CTL_SETALE(iob) gpiosetout(NAND_ALE, NAND_ALE)
  45. #ifdef CONFIG_NAND_WORKAROUND /* "some" dev boards busted, blue wired to rts2 :( */
  46. #define T_NAND_CTL_CLRCLE(iob) gpiosetout(NAND_CLE, 0); rts2setout(2, 2)
  47. #define T_NAND_CTL_SETCLE(iob) gpiosetout(NAND_CLE, NAND_CLE); rts2setout(2, 0)
  48. #else
  49. #define T_NAND_CTL_CLRCLE(iob) gpiosetout(NAND_CLE, 0)
  50. #define T_NAND_CTL_SETCLE(iob) gpiosetout(NAND_CLE, NAND_CLE)
  51. #endif
  52. #define T_NAND_CTL_SETNCE(iob) gpiosetout(NAND_NCE, 0)
  53. #define T_NAND_CTL_CLRNCE(iob) gpiosetout(NAND_NCE, NAND_NCE)
  54. /*
  55. * Define partitions for flash devices
  56. */
  57. static struct mtd_partition partition_info64M[] = {
  58. { .name = "toto kernel partition 1",
  59. .offset = 0,
  60. .size = 2 * SZ_1M },
  61. { .name = "toto file sys partition 2",
  62. .offset = 2 * SZ_1M,
  63. .size = 14 * SZ_1M },
  64. { .name = "toto user partition 3",
  65. .offset = 16 * SZ_1M,
  66. .size = 16 * SZ_1M },
  67. { .name = "toto devboard extra partition 4",
  68. .offset = 32 * SZ_1M,
  69. .size = 32 * SZ_1M },
  70. };
  71. static struct mtd_partition partition_info32M[] = {
  72. { .name = "toto kernel partition 1",
  73. .offset = 0,
  74. .size = 2 * SZ_1M },
  75. { .name = "toto file sys partition 2",
  76. .offset = 2 * SZ_1M,
  77. .size = 14 * SZ_1M },
  78. { .name = "toto user partition 3",
  79. .offset = 16 * SZ_1M,
  80. .size = 16 * SZ_1M },
  81. };
  82. #define NUM_PARTITIONS32M 3
  83. #define NUM_PARTITIONS64M 4
  84. /*
  85. * hardware specific access to control-lines
  86. */
  87. static void toto_hwcontrol(struct mtd_info *mtd, int cmd)
  88. {
  89. udelay(1); /* hopefully enough time for tc make proceding write to clear */
  90. switch(cmd){
  91. case NAND_CTL_SETCLE: T_NAND_CTL_SETCLE(cmd); break;
  92. case NAND_CTL_CLRCLE: T_NAND_CTL_CLRCLE(cmd); break;
  93. case NAND_CTL_SETALE: T_NAND_CTL_SETALE(cmd); break;
  94. case NAND_CTL_CLRALE: T_NAND_CTL_CLRALE(cmd); break;
  95. case NAND_CTL_SETNCE: T_NAND_CTL_SETNCE(cmd); break;
  96. case NAND_CTL_CLRNCE: T_NAND_CTL_CLRNCE(cmd); break;
  97. }
  98. udelay(1); /* allow time to ensure gpio state to over take memory write */
  99. }
  100. /*
  101. * Main initialization routine
  102. */
  103. int __init toto_init (void)
  104. {
  105. struct nand_chip *this;
  106. int err = 0;
  107. /* Allocate memory for MTD device structure and private data */
  108. toto_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
  109. GFP_KERNEL);
  110. if (!toto_mtd) {
  111. printk (KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n");
  112. err = -ENOMEM;
  113. goto out;
  114. }
  115. /* Get pointer to private data */
  116. this = (struct nand_chip *) (&toto_mtd[1]);
  117. /* Initialize structures */
  118. memset((char *) toto_mtd, 0, sizeof(struct mtd_info));
  119. memset((char *) this, 0, sizeof(struct nand_chip));
  120. /* Link the private data with the MTD structure */
  121. toto_mtd->priv = this;
  122. /* Set address of NAND IO lines */
  123. this->IO_ADDR_R = toto_io_base;
  124. this->IO_ADDR_W = toto_io_base;
  125. this->hwcontrol = toto_hwcontrol;
  126. this->dev_ready = NULL;
  127. /* 25 us command delay time */
  128. this->chip_delay = 30;
  129. this->eccmode = NAND_ECC_SOFT;
  130. /* Scan to find existance of the device */
  131. if (nand_scan (toto_mtd, 1)) {
  132. err = -ENXIO;
  133. goto out_mtd;
  134. }
  135. /* Register the partitions */
  136. switch(toto_mtd->size){
  137. case SZ_64M: add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M); break;
  138. case SZ_32M: add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M); break;
  139. default: {
  140. printk (KERN_WARNING "Unsupported Nand device\n");
  141. err = -ENXIO;
  142. goto out_buf;
  143. }
  144. }
  145. gpioreserve(NAND_MASK); /* claim our gpios */
  146. archflashwp(0,0); /* open up flash for writing */
  147. goto out;
  148. out_buf:
  149. kfree (this->data_buf);
  150. out_mtd:
  151. kfree (toto_mtd);
  152. out:
  153. return err;
  154. }
  155. module_init(toto_init);
  156. /*
  157. * Clean up routine
  158. */
  159. static void __exit toto_cleanup (void)
  160. {
  161. /* Release resources, unregister device */
  162. nand_release (toto_mtd);
  163. /* Free the MTD device structure */
  164. kfree (toto_mtd);
  165. /* stop flash writes */
  166. archflashwp(0,1);
  167. /* release gpios to system */
  168. gpiorelease(NAND_MASK);
  169. }
  170. module_exit(toto_cleanup);
  171. MODULE_LICENSE("GPL");
  172. MODULE_AUTHOR("Richard Woodruff <r-woodruff2@ti.com>");
  173. MODULE_DESCRIPTION("Glue layer for NAND flash on toto board");