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) + sizeof(struct nand_chip), GFP_KERNEL);
  113. if (!ep7312_mtd) {
  114. printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
  115. return -ENOMEM;
  116. }
  117. /* map physical adress */
  118. ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
  119. if (!ep7312_fio_base) {
  120. printk("ioremap EDB7312 NAND flash failed\n");
  121. kfree(ep7312_mtd);
  122. return -EIO;
  123. }
  124. /* Get pointer to private data */
  125. this = (struct nand_chip *)(&ep7312_mtd[1]);
  126. /* Initialize structures */
  127. memset(ep7312_mtd, 0, sizeof(struct mtd_info));
  128. memset(this, 0, sizeof(struct nand_chip));
  129. /* Link the private data with the MTD structure */
  130. ep7312_mtd->priv = this;
  131. ep7312_mtd->owner = THIS_MODULE;
  132. /*
  133. * Set GPIO Port B control register so that the pins are configured
  134. * to be outputs for controlling the NAND flash.
  135. */
  136. clps_writeb(0xf0, ep7312_pxddr);
  137. /* insert callbacks */
  138. this->IO_ADDR_R = ep7312_fio_base;
  139. this->IO_ADDR_W = ep7312_fio_base;
  140. this->hwcontrol = ep7312_hwcontrol;
  141. this->dev_ready = ep7312_device_ready;
  142. /* 15 us command delay time */
  143. this->chip_delay = 15;
  144. /* Scan to find existence of the device */
  145. if (nand_scan(ep7312_mtd, 1)) {
  146. iounmap((void *)ep7312_fio_base);
  147. kfree(ep7312_mtd);
  148. return -ENXIO;
  149. }
  150. #ifdef CONFIG_MTD_PARTITIONS
  151. ep7312_mtd->name = "edb7312-nand";
  152. mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
  153. if (mtd_parts_nb > 0)
  154. part_type = "command line";
  155. else
  156. mtd_parts_nb = 0;
  157. #endif
  158. if (mtd_parts_nb == 0) {
  159. mtd_parts = partition_info;
  160. mtd_parts_nb = NUM_PARTITIONS;
  161. part_type = "static";
  162. }
  163. /* Register the partitions */
  164. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  165. add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
  166. /* Return happy */
  167. return 0;
  168. }
  169. module_init(ep7312_init);
  170. /*
  171. * Clean up routine
  172. */
  173. static void __exit ep7312_cleanup(void)
  174. {
  175. struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
  176. /* Release resources, unregister device */
  177. nand_release(ap7312_mtd);
  178. /* Free internal data buffer */
  179. kfree(this->data_buf);
  180. /* Free the MTD device structure */
  181. kfree(ep7312_mtd);
  182. }
  183. module_exit(ep7312_cleanup);
  184. MODULE_LICENSE("GPL");
  185. MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
  186. MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");