autcpu12.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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),
  117. GFP_KERNEL);
  118. if (!autcpu12_mtd) {
  119. printk ("Unable to allocate AUTCPU12 NAND MTD device structure.\n");
  120. err = -ENOMEM;
  121. goto out;
  122. }
  123. /* map physical adress */
  124. autcpu12_fio_base = ioremap(autcpu12_fio_pbase,SZ_1K);
  125. if(!autcpu12_fio_base){
  126. printk("Ioremap autcpu12 SmartMedia Card failed\n");
  127. err = -EIO;
  128. goto out_mtd;
  129. }
  130. /* Get pointer to private data */
  131. this = (struct nand_chip *) (&autcpu12_mtd[1]);
  132. /* Initialize structures */
  133. memset((char *) autcpu12_mtd, 0, sizeof(struct mtd_info));
  134. memset((char *) this, 0, sizeof(struct nand_chip));
  135. /* Link the private data with the MTD structure */
  136. autcpu12_mtd->priv = this;
  137. /* Set address of NAND IO lines */
  138. this->IO_ADDR_R = autcpu12_fio_base;
  139. this->IO_ADDR_W = autcpu12_fio_base;
  140. this->hwcontrol = autcpu12_hwcontrol;
  141. this->dev_ready = autcpu12_device_ready;
  142. /* 20 us command delay time */
  143. this->chip_delay = 20;
  144. this->eccmode = NAND_ECC_SOFT;
  145. /* Enable the following for a flash based bad block table */
  146. /*
  147. this->options = NAND_USE_FLASH_BBT;
  148. */
  149. this->options = NAND_USE_FLASH_BBT;
  150. /* Scan to find existance of the device */
  151. if (nand_scan (autcpu12_mtd, 1)) {
  152. err = -ENXIO;
  153. goto out_ior;
  154. }
  155. /* Register the partitions */
  156. switch(autcpu12_mtd->size){
  157. case SZ_16M: add_mtd_partitions(autcpu12_mtd, partition_info16k, NUM_PARTITIONS16K); break;
  158. case SZ_32M: add_mtd_partitions(autcpu12_mtd, partition_info32k, NUM_PARTITIONS32K); break;
  159. case SZ_64M: add_mtd_partitions(autcpu12_mtd, partition_info64k, NUM_PARTITIONS64K); break;
  160. case SZ_128M: add_mtd_partitions(autcpu12_mtd, partition_info128k, NUM_PARTITIONS128K); break;
  161. default: {
  162. printk ("Unsupported SmartMedia device\n");
  163. err = -ENXIO;
  164. goto out_ior;
  165. }
  166. }
  167. goto out;
  168. out_ior:
  169. iounmap((void *)autcpu12_fio_base);
  170. out_mtd:
  171. kfree (autcpu12_mtd);
  172. out:
  173. return err;
  174. }
  175. module_init(autcpu12_init);
  176. /*
  177. * Clean up routine
  178. */
  179. #ifdef MODULE
  180. static void __exit autcpu12_cleanup (void)
  181. {
  182. /* Release resources, unregister device */
  183. nand_release (autcpu12_mtd);
  184. /* unmap physical adress */
  185. iounmap((void *)autcpu12_fio_base);
  186. /* Free the MTD device structure */
  187. kfree (autcpu12_mtd);
  188. }
  189. module_exit(autcpu12_cleanup);
  190. #endif
  191. MODULE_LICENSE("GPL");
  192. MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
  193. MODULE_DESCRIPTION("Glue layer for SmartMediaCard on autronix autcpu12");