autcpu12.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 int autcpu12_io_base = CS89712_VIRT_BASE;
  44. static int autcpu12_fio_pbase = AUTCPU12_PHYS_SMC;
  45. static int autcpu12_fio_ctrl = AUTCPU12_SMC_SELECT_OFFSET;
  46. static int autcpu12_pedr = AUTCPU12_SMC_PORT_OFFSET;
  47. static void __iomem *autcpu12_fio_base;
  48. /*
  49. * Define partitions for flash devices
  50. */
  51. static struct mtd_partition partition_info16k[] = {
  52. { .name = "AUTCPU12 flash partition 1",
  53. .offset = 0,
  54. .size = 8 * SZ_1M },
  55. { .name = "AUTCPU12 flash partition 2",
  56. .offset = 8 * SZ_1M,
  57. .size = 8 * SZ_1M },
  58. };
  59. static struct mtd_partition partition_info32k[] = {
  60. { .name = "AUTCPU12 flash partition 1",
  61. .offset = 0,
  62. .size = 8 * SZ_1M },
  63. { .name = "AUTCPU12 flash partition 2",
  64. .offset = 8 * SZ_1M,
  65. .size = 24 * SZ_1M },
  66. };
  67. static struct mtd_partition partition_info64k[] = {
  68. { .name = "AUTCPU12 flash partition 1",
  69. .offset = 0,
  70. .size = 16 * SZ_1M },
  71. { .name = "AUTCPU12 flash partition 2",
  72. .offset = 16 * SZ_1M,
  73. .size = 48 * SZ_1M },
  74. };
  75. static struct mtd_partition partition_info128k[] = {
  76. { .name = "AUTCPU12 flash partition 1",
  77. .offset = 0,
  78. .size = 16 * SZ_1M },
  79. { .name = "AUTCPU12 flash partition 2",
  80. .offset = 16 * SZ_1M,
  81. .size = 112 * SZ_1M },
  82. };
  83. #define NUM_PARTITIONS16K 2
  84. #define NUM_PARTITIONS32K 2
  85. #define NUM_PARTITIONS64K 2
  86. #define NUM_PARTITIONS128K 2
  87. /*
  88. * hardware specific access to control-lines
  89. */
  90. static void autcpu12_hwcontrol(struct mtd_info *mtd, int cmd)
  91. {
  92. switch (cmd) {
  93. case NAND_CTL_SETCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_CLE; break;
  94. case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_CLE; break;
  95. case NAND_CTL_SETALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) |= AUTCPU12_SMC_ALE; break;
  96. case NAND_CTL_CLRALE: (*(volatile unsigned char *) (autcpu12_io_base + autcpu12_pedr)) &= ~AUTCPU12_SMC_ALE; break;
  97. case NAND_CTL_SETNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x01; break;
  98. case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (autcpu12_fio_base + autcpu12_fio_ctrl)) = 0x00; break;
  99. }
  100. }
  101. /*
  102. * read device ready pin
  103. */
  104. int autcpu12_device_ready(struct mtd_info *mtd)
  105. {
  106. return ((*(volatile unsigned char *)(autcpu12_io_base + autcpu12_pedr)) & AUTCPU12_SMC_RDY) ? 1 : 0;
  107. }
  108. /*
  109. * Main initialization routine
  110. */
  111. int __init autcpu12_init(void)
  112. {
  113. struct nand_chip *this;
  114. int err = 0;
  115. /* Allocate memory for MTD device structure and private data */
  116. autcpu12_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  117. if (!autcpu12_mtd) {
  118. printk("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
  119. err = -ENOMEM;
  120. goto out;
  121. }
  122. /* map physical adress */
  123. autcpu12_fio_base = ioremap(autcpu12_fio_pbase, SZ_1K);
  124. if (!autcpu12_fio_base) {
  125. printk("Ioremap autcpu12 SmartMedia Card failed\n");
  126. err = -EIO;
  127. goto out_mtd;
  128. }
  129. /* Get pointer to private data */
  130. this = (struct nand_chip *)(&autcpu12_mtd[1]);
  131. /* Initialize structures */
  132. memset(autcpu12_mtd, 0, sizeof(struct mtd_info));
  133. memset(this, 0, sizeof(struct nand_chip));
  134. /* Link the private data with the MTD structure */
  135. autcpu12_mtd->priv = this;
  136. /* Set address of NAND IO lines */
  137. this->IO_ADDR_R = autcpu12_fio_base;
  138. this->IO_ADDR_W = autcpu12_fio_base;
  139. this->hwcontrol = autcpu12_hwcontrol;
  140. this->dev_ready = autcpu12_device_ready;
  141. /* 20 us command delay time */
  142. this->chip_delay = 20;
  143. this->eccmode = NAND_ECC_SOFT;
  144. /* Enable the following for a flash based bad block table */
  145. /*
  146. this->options = NAND_USE_FLASH_BBT;
  147. */
  148. this->options = NAND_USE_FLASH_BBT;
  149. /* Scan to find existance of the device */
  150. if (nand_scan(autcpu12_mtd, 1)) {
  151. err = -ENXIO;
  152. goto out_ior;
  153. }
  154. /* Register the partitions */
  155. switch (autcpu12_mtd->size) {
  156. case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
  157. case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
  158. case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
  159. case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
  160. default:
  161. printk("Unsupported SmartMedia device\n");
  162. err = -ENXIO;
  163. goto out_ior;
  164. }
  165. goto out;
  166. out_ior:
  167. iounmap((void *)autcpu12_fio_base);
  168. out_mtd:
  169. kfree(autcpu12_mtd);
  170. out:
  171. return err;
  172. }
  173. module_init(autcpu12_init);
  174. /*
  175. * Clean up routine
  176. */
  177. #ifdef MODULE
  178. static void __exit autcpu12_cleanup(void)
  179. {
  180. /* Release resources, unregister device */
  181. nand_release(autcpu12_mtd);
  182. /* unmap physical adress */
  183. iounmap((void *)autcpu12_fio_base);
  184. /* Free the MTD device structure */
  185. kfree(autcpu12_mtd);
  186. }
  187. module_exit(autcpu12_cleanup);
  188. #endif
  189. MODULE_LICENSE("GPL");
  190. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  191. MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");