autcpu12.c 5.8 KB

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