toto.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. #include <linux/slab.h>
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include <linux/delay.h>
  22. #include <linux/mtd/mtd.h>
  23. #include <linux/mtd/nand.h>
  24. #include <linux/mtd/partitions.h>
  25. #include <asm/io.h>
  26. #include <asm/arch/hardware.h>
  27. #include <asm/sizes.h>
  28. #include <asm/arch/toto.h>
  29. #include <asm/arch-omap1510/hardware.h>
  30. #include <asm/arch/gpio.h>
  31. #define CONFIG_NAND_WORKAROUND 1
  32. /*
  33. * MTD structure for TOTO board
  34. */
  35. static struct mtd_info *toto_mtd = NULL;
  36. static unsigned long toto_io_base = OMAP_FLASH_1_BASE;
  37. /*
  38. * Define partitions for flash devices
  39. */
  40. static struct mtd_partition partition_info64M[] = {
  41. { .name = "toto kernel partition 1",
  42. .offset = 0,
  43. .size = 2 * SZ_1M },
  44. { .name = "toto file sys partition 2",
  45. .offset = 2 * SZ_1M,
  46. .size = 14 * SZ_1M },
  47. { .name = "toto user partition 3",
  48. .offset = 16 * SZ_1M,
  49. .size = 16 * SZ_1M },
  50. { .name = "toto devboard extra partition 4",
  51. .offset = 32 * SZ_1M,
  52. .size = 32 * SZ_1M },
  53. };
  54. static struct mtd_partition partition_info32M[] = {
  55. { .name = "toto kernel partition 1",
  56. .offset = 0,
  57. .size = 2 * SZ_1M },
  58. { .name = "toto file sys partition 2",
  59. .offset = 2 * SZ_1M,
  60. .size = 14 * SZ_1M },
  61. { .name = "toto user partition 3",
  62. .offset = 16 * SZ_1M,
  63. .size = 16 * SZ_1M },
  64. };
  65. #define NUM_PARTITIONS32M 3
  66. #define NUM_PARTITIONS64M 4
  67. /*
  68. * hardware specific access to control-lines
  69. *
  70. * ctrl:
  71. * NAND_NCE: bit 0 -> bit 14 (0x4000)
  72. * NAND_CLE: bit 1 -> bit 12 (0x1000)
  73. * NAND_ALE: bit 2 -> bit 1 (0x0002)
  74. */
  75. static void toto_hwcontrol(struct mtd_info *mtd, int cmd,
  76. unsigned int ctrl)
  77. {
  78. struct nand_chip *chip = mtd->priv;
  79. if (ctrl & NAND_CTRL_CHANGE) {
  80. unsigned long bits;
  81. /* hopefully enough time for tc make proceding write to clear */
  82. udelay(1);
  83. bits = (~ctrl & NAND_NCE) << 14;
  84. bits |= (ctrl & NAND_CLE) << 12;
  85. bits |= (ctrl & NAND_ALE) >> 1;
  86. #warning Wild guess as gpiosetout() is nowhere defined in the kernel source - tglx
  87. gpiosetout(0x5002, bits);
  88. #ifdef CONFIG_NAND_WORKAROUND
  89. /* "some" dev boards busted, blue wired to rts2 :( */
  90. rts2setout(2, (ctrl & NAND_CLE) << 1);
  91. #endif
  92. /* allow time to ensure gpio state to over take memory write */
  93. udelay(1);
  94. }
  95. if (cmd != NAND_CMD_NONE)
  96. writeb(cmd, chip->IO_ADDR_W);
  97. }
  98. /*
  99. * Main initialization routine
  100. */
  101. static int __init toto_init(void)
  102. {
  103. struct nand_chip *this;
  104. int err = 0;
  105. /* Allocate memory for MTD device structure and private data */
  106. toto_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  107. if (!toto_mtd) {
  108. printk(KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n");
  109. err = -ENOMEM;
  110. goto out;
  111. }
  112. /* Get pointer to private data */
  113. this = (struct nand_chip *)(&toto_mtd[1]);
  114. /* Initialize structures */
  115. memset(toto_mtd, 0, sizeof(struct mtd_info));
  116. memset(this, 0, sizeof(struct nand_chip));
  117. /* Link the private data with the MTD structure */
  118. toto_mtd->priv = this;
  119. toto_mtd->owner = THIS_MODULE;
  120. /* Set address of NAND IO lines */
  121. this->IO_ADDR_R = toto_io_base;
  122. this->IO_ADDR_W = toto_io_base;
  123. this->cmd_ctrl = toto_hwcontrol;
  124. this->dev_ready = NULL;
  125. /* 25 us command delay time */
  126. this->chip_delay = 30;
  127. this->ecc.mode = NAND_ECC_SOFT;
  128. /* Scan to find existance of the device */
  129. if (nand_scan(toto_mtd, 1)) {
  130. err = -ENXIO;
  131. goto out_mtd;
  132. }
  133. /* Register the partitions */
  134. switch (toto_mtd->size) {
  135. case SZ_64M:
  136. add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M);
  137. break;
  138. case SZ_32M:
  139. add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M);
  140. break;
  141. default:{
  142. printk(KERN_WARNING "Unsupported Nand device\n");
  143. err = -ENXIO;
  144. goto out_buf;
  145. }
  146. }
  147. gpioreserve(NAND_MASK); /* claim our gpios */
  148. archflashwp(0, 0); /* open up flash for writing */
  149. goto out;
  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");