autcpu12.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. bits = clps_readb(AUTCPU12_SMC_PORT_OFFSET) & ~0x30;
  97. bits |= (ctrl & NAND_CLE) << 4;
  98. bits |= (ctrl & NAND_ALE) << 2;
  99. clps_writeb(bits, AUTCPU12_SMC_PORT_OFFSET);
  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. return clps_readb(AUTCPU12_SMC_PORT_OFFSET) & AUTCPU12_SMC_RDY;
  112. }
  113. /*
  114. * Main initialization routine
  115. */
  116. static int __init autcpu12_init(void)
  117. {
  118. struct nand_chip *this;
  119. int err = 0;
  120. /* Allocate memory for MTD device structure and private data */
  121. autcpu12_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip),
  122. GFP_KERNEL);
  123. if (!autcpu12_mtd) {
  124. printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
  125. err = -ENOMEM;
  126. goto out;
  127. }
  128. /* map physical address */
  129. autcpu12_fio_base = ioremap(AUTCPU12_PHYS_SMC, SZ_1K);
  130. if (!autcpu12_fio_base) {
  131. printk("Ioremap autcpu12 SmartMedia Card failed\n");
  132. err = -EIO;
  133. goto out_mtd;
  134. }
  135. /* Get pointer to private data */
  136. this = (struct nand_chip *)(&autcpu12_mtd[1]);
  137. /* Initialize structures */
  138. memset(autcpu12_mtd, 0, sizeof(struct mtd_info));
  139. memset(this, 0, sizeof(struct nand_chip));
  140. /* Link the private data with the MTD structure */
  141. autcpu12_mtd->priv = this;
  142. autcpu12_mtd->owner = THIS_MODULE;
  143. /* Set address of NAND IO lines */
  144. this->IO_ADDR_R = autcpu12_fio_base;
  145. this->IO_ADDR_W = autcpu12_fio_base;
  146. this->cmd_ctrl = autcpu12_hwcontrol;
  147. this->dev_ready = autcpu12_device_ready;
  148. /* 20 us command delay time */
  149. this->chip_delay = 20;
  150. this->ecc.mode = NAND_ECC_SOFT;
  151. /* Enable the following for a flash based bad block table */
  152. /*
  153. this->bbt_options = NAND_BBT_USE_FLASH;
  154. */
  155. this->bbt_options = NAND_BBT_USE_FLASH;
  156. /* Scan to find existence of the device */
  157. if (nand_scan(autcpu12_mtd, 1)) {
  158. err = -ENXIO;
  159. goto out_ior;
  160. }
  161. /* Register the partitions */
  162. switch (autcpu12_mtd->size) {
  163. case SZ_16M:
  164. mtd_device_register(autcpu12_mtd, partition_info16k,
  165. NUM_PARTITIONS16K);
  166. break;
  167. case SZ_32M:
  168. mtd_device_register(autcpu12_mtd, partition_info32k,
  169. NUM_PARTITIONS32K);
  170. break;
  171. case SZ_64M:
  172. mtd_device_register(autcpu12_mtd, partition_info64k,
  173. NUM_PARTITIONS64K);
  174. break;
  175. case SZ_128M:
  176. mtd_device_register(autcpu12_mtd, partition_info128k,
  177. NUM_PARTITIONS128K);
  178. break;
  179. default:
  180. printk("Unsupported SmartMedia device\n");
  181. err = -ENXIO;
  182. goto out_ior;
  183. }
  184. goto out;
  185. out_ior:
  186. iounmap(autcpu12_fio_base);
  187. out_mtd:
  188. kfree(autcpu12_mtd);
  189. out:
  190. return err;
  191. }
  192. module_init(autcpu12_init);
  193. /*
  194. * Clean up routine
  195. */
  196. static void __exit autcpu12_cleanup(void)
  197. {
  198. /* Release resources, unregister device */
  199. nand_release(autcpu12_mtd);
  200. /* unmap physical address */
  201. iounmap(autcpu12_fio_base);
  202. /* Free the MTD device structure */
  203. kfree(autcpu12_mtd);
  204. }
  205. module_exit(autcpu12_cleanup);
  206. MODULE_LICENSE("GPL");
  207. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  208. MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");