toto.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. #define CONFIG_NAND_WORKAROUND 1
  34. /*
  35. * MTD structure for TOTO board
  36. */
  37. static struct mtd_info *toto_mtd = NULL;
  38. static unsigned long toto_io_base = OMAP_FLASH_1_BASE;
  39. /*
  40. * Define partitions for flash devices
  41. */
  42. static struct mtd_partition partition_info64M[] = {
  43. { .name = "toto kernel partition 1",
  44. .offset = 0,
  45. .size = 2 * SZ_1M },
  46. { .name = "toto file sys partition 2",
  47. .offset = 2 * SZ_1M,
  48. .size = 14 * SZ_1M },
  49. { .name = "toto user partition 3",
  50. .offset = 16 * SZ_1M,
  51. .size = 16 * SZ_1M },
  52. { .name = "toto devboard extra partition 4",
  53. .offset = 32 * SZ_1M,
  54. .size = 32 * SZ_1M },
  55. };
  56. static struct mtd_partition partition_info32M[] = {
  57. { .name = "toto kernel partition 1",
  58. .offset = 0,
  59. .size = 2 * SZ_1M },
  60. { .name = "toto file sys partition 2",
  61. .offset = 2 * SZ_1M,
  62. .size = 14 * SZ_1M },
  63. { .name = "toto user partition 3",
  64. .offset = 16 * SZ_1M,
  65. .size = 16 * SZ_1M },
  66. };
  67. #define NUM_PARTITIONS32M 3
  68. #define NUM_PARTITIONS64M 4
  69. /*
  70. * hardware specific access to control-lines
  71. *
  72. * ctrl:
  73. * NAND_NCE: bit 0 -> bit 14 (0x4000)
  74. * NAND_CLE: bit 1 -> bit 12 (0x1000)
  75. * NAND_ALE: bit 2 -> bit 1 (0x0002)
  76. */
  77. static void toto_hwcontrol(struct mtd_info *mtd, int cmd,
  78. unsigned int ctrl)
  79. {
  80. struct nand_chip *chip = mtd->priv;
  81. if (ctrl & NAND_CTRL_CHANGE) {
  82. unsigned long bits;
  83. /* hopefully enough time for tc make proceding write to clear */
  84. udelay(1);
  85. bits = (~ctrl & NAND_NCE) << 14;
  86. bits |= (ctrl & NAND_CLE) << 12;
  87. bits |= (ctrl & NAND_ALE) >> 1;
  88. #warning Wild guess as gpiosetout() is nowhere defined in the kernel source - tglx
  89. gpiosetout(0x5002, bits);
  90. #ifdef CONFIG_NAND_WORKAROUND
  91. /* "some" dev boards busted, blue wired to rts2 :( */
  92. rts2setout(2, (ctrl & NAND_CLE) << 1);
  93. #endif
  94. /* allow time to ensure gpio state to over take memory write */
  95. udelay(1);
  96. }
  97. if (cmd != NAND_CMD_NONE)
  98. writeb(cmd, chip->IO_ADDR_W);
  99. }
  100. /*
  101. * Main initialization routine
  102. */
  103. static 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), GFP_KERNEL);
  109. if (!toto_mtd) {
  110. printk(KERN_WARNING "Unable to allocate toto NAND MTD device structure.\n");
  111. err = -ENOMEM;
  112. goto out;
  113. }
  114. /* Get pointer to private data */
  115. this = (struct nand_chip *)(&toto_mtd[1]);
  116. /* Initialize structures */
  117. memset(toto_mtd, 0, sizeof(struct mtd_info));
  118. memset(this, 0, sizeof(struct nand_chip));
  119. /* Link the private data with the MTD structure */
  120. toto_mtd->priv = this;
  121. toto_mtd->owner = THIS_MODULE;
  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->cmd_ctrl = toto_hwcontrol;
  126. this->dev_ready = NULL;
  127. /* 25 us command delay time */
  128. this->chip_delay = 30;
  129. this->ecc.mode = 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:
  138. add_mtd_partitions(toto_mtd, partition_info64M, NUM_PARTITIONS64M);
  139. break;
  140. case SZ_32M:
  141. add_mtd_partitions(toto_mtd, partition_info32M, NUM_PARTITIONS32M);
  142. break;
  143. default:{
  144. printk(KERN_WARNING "Unsupported Nand device\n");
  145. err = -ENXIO;
  146. goto out_buf;
  147. }
  148. }
  149. gpioreserve(NAND_MASK); /* claim our gpios */
  150. archflashwp(0, 0); /* open up flash for writing */
  151. goto out;
  152. out_mtd:
  153. kfree(toto_mtd);
  154. out:
  155. return err;
  156. }
  157. module_init(toto_init);
  158. /*
  159. * Clean up routine
  160. */
  161. static void __exit toto_cleanup(void)
  162. {
  163. /* Release resources, unregister device */
  164. nand_release(toto_mtd);
  165. /* Free the MTD device structure */
  166. kfree(toto_mtd);
  167. /* stop flash writes */
  168. archflashwp(0, 1);
  169. /* release gpios to system */
  170. gpiorelease(NAND_MASK);
  171. }
  172. module_exit(toto_cleanup);
  173. MODULE_LICENSE("GPL");
  174. MODULE_AUTHOR("Richard Woodruff <r-woodruff2@ti.com>");
  175. MODULE_DESCRIPTION("Glue layer for NAND flash on toto board");