edb7312.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * drivers/mtd/nand/edb7312.c
  3. *
  4. * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
  5. *
  6. * Derived from drivers/mtd/nand/autcpu12.c
  7. * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
  8. *
  9. * $Id: edb7312.c,v 1.12 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. * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is
  18. * a 64Mibit (8MiB x 8 bits) NAND flash device.
  19. */
  20. #include <linux/slab.h>
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/nand.h>
  25. #include <linux/mtd/partitions.h>
  26. #include <asm/io.h>
  27. #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
  28. #include <asm/sizes.h>
  29. #include <asm/hardware/clps7111.h>
  30. /*
  31. * MTD structure for EDB7312 board
  32. */
  33. static struct mtd_info *ep7312_mtd = NULL;
  34. /*
  35. * Values specific to the EDB7312 board (used with EP7312 processor)
  36. */
  37. #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
  38. #define EP7312_PXDR 0x0001 /*
  39. * IO offset to Port B data register
  40. * where the CLE, ALE and NCE pins
  41. * are wired to.
  42. */
  43. #define EP7312_PXDDR 0x0041 /*
  44. * IO offset to Port B data direction
  45. * register so we can control the IO
  46. * lines.
  47. */
  48. /*
  49. * Module stuff
  50. */
  51. static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE;
  52. static void __iomem * ep7312_pxdr = (void __iomem *) EP7312_PXDR;
  53. static void __iomem * ep7312_pxddr = (void __iomem *) EP7312_PXDDR;
  54. #ifdef CONFIG_MTD_PARTITIONS
  55. /*
  56. * Define static partitions for flash device
  57. */
  58. static struct mtd_partition partition_info[] = {
  59. { .name = "EP7312 Nand Flash",
  60. .offset = 0,
  61. .size = 8*1024*1024 }
  62. };
  63. #define NUM_PARTITIONS 1
  64. #endif
  65. /*
  66. * hardware specific access to control-lines
  67. */
  68. static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd)
  69. {
  70. switch(cmd) {
  71. case NAND_CTL_SETCLE:
  72. clps_writeb(clps_readb(ep7312_pxdr) | 0x10, ep7312_pxdr);
  73. break;
  74. case NAND_CTL_CLRCLE:
  75. clps_writeb(clps_readb(ep7312_pxdr) & ~0x10, ep7312_pxdr);
  76. break;
  77. case NAND_CTL_SETALE:
  78. clps_writeb(clps_readb(ep7312_pxdr) | 0x20, ep7312_pxdr);
  79. break;
  80. case NAND_CTL_CLRALE:
  81. clps_writeb(clps_readb(ep7312_pxdr) & ~0x20, ep7312_pxdr);
  82. break;
  83. case NAND_CTL_SETNCE:
  84. clps_writeb((clps_readb(ep7312_pxdr) | 0x80) & ~0x40, ep7312_pxdr);
  85. break;
  86. case NAND_CTL_CLRNCE:
  87. clps_writeb((clps_readb(ep7312_pxdr) | 0x80) | 0x40, ep7312_pxdr);
  88. break;
  89. }
  90. }
  91. /*
  92. * read device ready pin
  93. */
  94. static int ep7312_device_ready(struct mtd_info *mtd)
  95. {
  96. return 1;
  97. }
  98. #ifdef CONFIG_MTD_PARTITIONS
  99. const char *part_probes[] = { "cmdlinepart", NULL };
  100. #endif
  101. /*
  102. * Main initialization routine
  103. */
  104. static int __init ep7312_init (void)
  105. {
  106. struct nand_chip *this;
  107. const char *part_type = 0;
  108. int mtd_parts_nb = 0;
  109. struct mtd_partition *mtd_parts = 0;
  110. void __iomem * ep7312_fio_base;
  111. /* Allocate memory for MTD device structure and private data */
  112. ep7312_mtd = kmalloc(sizeof(struct mtd_info) +
  113. sizeof(struct nand_chip),
  114. GFP_KERNEL);
  115. if (!ep7312_mtd) {
  116. printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
  117. return -ENOMEM;
  118. }
  119. /* map physical adress */
  120. ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
  121. if(!ep7312_fio_base) {
  122. printk("ioremap EDB7312 NAND flash failed\n");
  123. kfree(ep7312_mtd);
  124. return -EIO;
  125. }
  126. /* Get pointer to private data */
  127. this = (struct nand_chip *) (&ep7312_mtd[1]);
  128. /* Initialize structures */
  129. memset((char *) ep7312_mtd, 0, sizeof(struct mtd_info));
  130. memset((char *) this, 0, sizeof(struct nand_chip));
  131. /* Link the private data with the MTD structure */
  132. ep7312_mtd->priv = this;
  133. /*
  134. * Set GPIO Port B control register so that the pins are configured
  135. * to be outputs for controlling the NAND flash.
  136. */
  137. clps_writeb(0xf0, ep7312_pxddr);
  138. /* insert callbacks */
  139. this->IO_ADDR_R = ep7312_fio_base;
  140. this->IO_ADDR_W = ep7312_fio_base;
  141. this->hwcontrol = ep7312_hwcontrol;
  142. this->dev_ready = ep7312_device_ready;
  143. /* 15 us command delay time */
  144. this->chip_delay = 15;
  145. /* Scan to find existence of the device */
  146. if (nand_scan (ep7312_mtd, 1)) {
  147. iounmap((void *)ep7312_fio_base);
  148. kfree (ep7312_mtd);
  149. return -ENXIO;
  150. }
  151. #ifdef CONFIG_MTD_PARTITIONS
  152. ep7312_mtd->name = "edb7312-nand";
  153. mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes,
  154. &mtd_parts, 0);
  155. if (mtd_parts_nb > 0)
  156. part_type = "command line";
  157. else
  158. mtd_parts_nb = 0;
  159. #endif
  160. if (mtd_parts_nb == 0) {
  161. mtd_parts = partition_info;
  162. mtd_parts_nb = NUM_PARTITIONS;
  163. part_type = "static";
  164. }
  165. /* Register the partitions */
  166. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  167. add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
  168. /* Return happy */
  169. return 0;
  170. }
  171. module_init(ep7312_init);
  172. /*
  173. * Clean up routine
  174. */
  175. static void __exit ep7312_cleanup (void)
  176. {
  177. struct nand_chip *this = (struct nand_chip *) &ep7312_mtd[1];
  178. /* Release resources, unregister device */
  179. nand_release (ap7312_mtd);
  180. /* Free internal data buffer */
  181. kfree (this->data_buf);
  182. /* Free the MTD device structure */
  183. kfree (ep7312_mtd);
  184. }
  185. module_exit(ep7312_cleanup);
  186. MODULE_LICENSE("GPL");
  187. MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
  188. MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");