autcpu12.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * drivers/mtd/autcpu12.c
  3. *
  4. * Copyright (c) 2002 Thomas Gleixner <tgxl@linutronix.de>
  5. *
  6. * Derived from drivers/mtd/spia.c
  7. * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Overview:
  14. * This is a device driver for the NAND flash device found on the
  15. * autronix autcpu12 board, which is a SmartMediaCard. It supports
  16. * 16MiB, 32MiB and 64MiB cards.
  17. *
  18. *
  19. * 02-12-2002 TG Cleanup of module params
  20. *
  21. * 02-20-2002 TG adjusted for different rd/wr address support
  22. * added support for read device ready/busy line
  23. * added page_cache
  24. *
  25. * 10-06-2002 TG 128K card support added
  26. */
  27. #include <linux/slab.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/nand.h>
  32. #include <linux/mtd/partitions.h>
  33. #include <asm/io.h>
  34. #include <mach/hardware.h>
  35. #include <asm/sizes.h>
  36. #include <mach/autcpu12.h>
  37. /*
  38. * MTD structure for AUTCPU12 board
  39. */
  40. static struct mtd_info *autcpu12_mtd = NULL;
  41. static void __iomem *autcpu12_fio_base;
  42. /*
  43. * Define partitions for flash devices
  44. */
  45. static struct mtd_partition partition_info16k[] = {
  46. { .name = "AUTCPU12 flash partition 1",
  47. .offset = 0,
  48. .size = 8 * SZ_1M },
  49. { .name = "AUTCPU12 flash partition 2",
  50. .offset = 8 * SZ_1M,
  51. .size = 8 * SZ_1M },
  52. };
  53. static struct mtd_partition partition_info32k[] = {
  54. { .name = "AUTCPU12 flash partition 1",
  55. .offset = 0,
  56. .size = 8 * SZ_1M },
  57. { .name = "AUTCPU12 flash partition 2",
  58. .offset = 8 * SZ_1M,
  59. .size = 24 * SZ_1M },
  60. };
  61. static struct mtd_partition partition_info64k[] = {
  62. { .name = "AUTCPU12 flash partition 1",
  63. .offset = 0,
  64. .size = 16 * SZ_1M },
  65. { .name = "AUTCPU12 flash partition 2",
  66. .offset = 16 * SZ_1M,
  67. .size = 48 * SZ_1M },
  68. };
  69. static struct mtd_partition partition_info128k[] = {
  70. { .name = "AUTCPU12 flash partition 1",
  71. .offset = 0,
  72. .size = 16 * SZ_1M },
  73. { .name = "AUTCPU12 flash partition 2",
  74. .offset = 16 * SZ_1M,
  75. .size = 112 * SZ_1M },
  76. };
  77. #define NUM_PARTITIONS16K 2
  78. #define NUM_PARTITIONS32K 2
  79. #define NUM_PARTITIONS64K 2
  80. #define NUM_PARTITIONS128K 2
  81. /*
  82. * hardware specific access to control-lines
  83. *
  84. * ALE bit 4 autcpu12_pedr
  85. * CLE bit 5 autcpu12_pedr
  86. * NCE bit 0 fio_ctrl
  87. *
  88. */
  89. static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd,
  90. unsigned int ctrl)
  91. {
  92. struct nand_chip *chip = mtd->priv;
  93. if (ctrl & NAND_CTRL_CHANGE) {
  94. void __iomem *addr;
  95. unsigned char bits;
  96. addr = CS89712_VIRT_BASE + AUTCPU12_SMC_PORT_OFFSET;
  97. bits = (ctrl & NAND_CLE) << 4;
  98. bits |= (ctrl & NAND_ALE) << 2;
  99. writeb((readb(addr) & ~0x30) | bits, addr);
  100. addr = autcpu12_fio_base + AUTCPU12_SMC_SELECT_OFFSET;
  101. writeb((readb(addr) & ~0x1) | (ctrl & NAND_NCE), addr);
  102. }
  103. if (cmd != NAND_CMD_NONE)
  104. writeb(cmd, chip->IO_ADDR_W);
  105. }
  106. /*
  107. * read device ready pin
  108. */
  109. int autcpu12_device_ready(struct mtd_info *mtd)
  110. {
  111. void __iomem *addr = CS89712_VIRT_BASE + AUTCPU12_SMC_PORT_OFFSET;
  112. return readb(addr) & AUTCPU12_SMC_RDY;
  113. }
  114. /*
  115. * Main initialization routine
  116. */
  117. static int __init autcpu12_init(void)
  118. {
  119. struct nand_chip *this;
  120. int err = 0;
  121. /* Allocate memory for MTD device structure and private data */
  122. autcpu12_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip),
  123. GFP_KERNEL);
  124. if (!autcpu12_mtd) {
  125. printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
  126. err = -ENOMEM;
  127. goto out;
  128. }
  129. /* map physical address */
  130. autcpu12_fio_base = ioremap(AUTCPU12_PHYS_SMC, SZ_1K);
  131. if (!autcpu12_fio_base) {
  132. printk("Ioremap autcpu12 SmartMedia Card failed\n");
  133. err = -EIO;
  134. goto out_mtd;
  135. }
  136. /* Get pointer to private data */
  137. this = (struct nand_chip *)(&autcpu12_mtd[1]);
  138. /* Initialize structures */
  139. memset(autcpu12_mtd, 0, sizeof(struct mtd_info));
  140. memset(this, 0, sizeof(struct nand_chip));
  141. /* Link the private data with the MTD structure */
  142. autcpu12_mtd->priv = this;
  143. autcpu12_mtd->owner = THIS_MODULE;
  144. /* Set address of NAND IO lines */
  145. this->IO_ADDR_R = autcpu12_fio_base;
  146. this->IO_ADDR_W = autcpu12_fio_base;
  147. this->cmd_ctrl = autcpu12_hwcontrol;
  148. this->dev_ready = autcpu12_device_ready;
  149. /* 20 us command delay time */
  150. this->chip_delay = 20;
  151. this->ecc.mode = NAND_ECC_SOFT;
  152. /* Enable the following for a flash based bad block table */
  153. /*
  154. this->bbt_options = NAND_BBT_USE_FLASH;
  155. */
  156. this->bbt_options = NAND_BBT_USE_FLASH;
  157. /* Scan to find existence of the device */
  158. if (nand_scan(autcpu12_mtd, 1)) {
  159. err = -ENXIO;
  160. goto out_ior;
  161. }
  162. /* Register the partitions */
  163. switch (autcpu12_mtd->size) {
  164. case SZ_16M:
  165. mtd_device_register(autcpu12_mtd, partition_info16k,
  166. NUM_PARTITIONS16K);
  167. break;
  168. case SZ_32M:
  169. mtd_device_register(autcpu12_mtd, partition_info32k,
  170. NUM_PARTITIONS32K);
  171. break;
  172. case SZ_64M:
  173. mtd_device_register(autcpu12_mtd, partition_info64k,
  174. NUM_PARTITIONS64K);
  175. break;
  176. case SZ_128M:
  177. mtd_device_register(autcpu12_mtd, partition_info128k,
  178. NUM_PARTITIONS128K);
  179. break;
  180. default:
  181. printk("Unsupported SmartMedia device\n");
  182. err = -ENXIO;
  183. goto out_ior;
  184. }
  185. goto out;
  186. out_ior:
  187. iounmap(autcpu12_fio_base);
  188. out_mtd:
  189. kfree(autcpu12_mtd);
  190. out:
  191. return err;
  192. }
  193. module_init(autcpu12_init);
  194. /*
  195. * Clean up routine
  196. */
  197. static void __exit autcpu12_cleanup(void)
  198. {
  199. /* Release resources, unregister device */
  200. nand_release(autcpu12_mtd);
  201. /* unmap physical address */
  202. iounmap(autcpu12_fio_base);
  203. /* Free the MTD device structure */
  204. kfree(autcpu12_mtd);
  205. }
  206. module_exit(autcpu12_cleanup);
  207. MODULE_LICENSE("GPL");
  208. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  209. MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");