autcpu12.c 6.1 KB

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