edb7312.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. * NAND_NCE: bit 0 -> bit 7
  69. * NAND_CLE: bit 1 -> bit 4
  70. * NAND_ALE: bit 2 -> bit 5
  71. */
  72. static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  73. {
  74. struct nand_chip *chip = mtd->priv;
  75. if (ctrl & NAND_CTRL_CHANGE) {
  76. unsigned char bits;
  77. bits = (ctrl & (NAND_CLE | NAND_ALE)) << 3;
  78. bits = (ctrl & NAND_NCE) << 7;
  79. clps_writeb((clps_readb(ep7312_pxdr) & 0xB0) | 0x10,
  80. ep7312_pxdr);
  81. }
  82. if (cmd != NAND_CMD_NONE)
  83. writeb(cmd, chip->IO_ADDR_W);
  84. }
  85. /*
  86. * read device ready pin
  87. */
  88. static int ep7312_device_ready(struct mtd_info *mtd)
  89. {
  90. return 1;
  91. }
  92. #ifdef CONFIG_MTD_PARTITIONS
  93. const char *part_probes[] = { "cmdlinepart", NULL };
  94. #endif
  95. /*
  96. * Main initialization routine
  97. */
  98. static int __init ep7312_init(void)
  99. {
  100. struct nand_chip *this;
  101. const char *part_type = 0;
  102. int mtd_parts_nb = 0;
  103. struct mtd_partition *mtd_parts = 0;
  104. void __iomem *ep7312_fio_base;
  105. /* Allocate memory for MTD device structure and private data */
  106. ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  107. if (!ep7312_mtd) {
  108. printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
  109. return -ENOMEM;
  110. }
  111. /* map physical adress */
  112. ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
  113. if (!ep7312_fio_base) {
  114. printk("ioremap EDB7312 NAND flash failed\n");
  115. kfree(ep7312_mtd);
  116. return -EIO;
  117. }
  118. /* Get pointer to private data */
  119. this = (struct nand_chip *)(&ep7312_mtd[1]);
  120. /* Initialize structures */
  121. memset(ep7312_mtd, 0, sizeof(struct mtd_info));
  122. memset(this, 0, sizeof(struct nand_chip));
  123. /* Link the private data with the MTD structure */
  124. ep7312_mtd->priv = this;
  125. ep7312_mtd->owner = THIS_MODULE;
  126. /*
  127. * Set GPIO Port B control register so that the pins are configured
  128. * to be outputs for controlling the NAND flash.
  129. */
  130. clps_writeb(0xf0, ep7312_pxddr);
  131. /* insert callbacks */
  132. this->IO_ADDR_R = ep7312_fio_base;
  133. this->IO_ADDR_W = ep7312_fio_base;
  134. this->cmd_ctrl = ep7312_hwcontrol;
  135. this->dev_ready = ep7312_device_ready;
  136. /* 15 us command delay time */
  137. this->chip_delay = 15;
  138. /* Scan to find existence of the device */
  139. if (nand_scan(ep7312_mtd, 1)) {
  140. iounmap((void *)ep7312_fio_base);
  141. kfree(ep7312_mtd);
  142. return -ENXIO;
  143. }
  144. #ifdef CONFIG_MTD_PARTITIONS
  145. ep7312_mtd->name = "edb7312-nand";
  146. mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
  147. if (mtd_parts_nb > 0)
  148. part_type = "command line";
  149. else
  150. mtd_parts_nb = 0;
  151. #endif
  152. if (mtd_parts_nb == 0) {
  153. mtd_parts = partition_info;
  154. mtd_parts_nb = NUM_PARTITIONS;
  155. part_type = "static";
  156. }
  157. /* Register the partitions */
  158. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  159. add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb);
  160. /* Return happy */
  161. return 0;
  162. }
  163. module_init(ep7312_init);
  164. /*
  165. * Clean up routine
  166. */
  167. static void __exit ep7312_cleanup(void)
  168. {
  169. struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
  170. /* Release resources, unregister device */
  171. nand_release(ap7312_mtd);
  172. /* Release io resource */
  173. iounmap(this->IO_ADDR_R);
  174. /* Free the MTD device structure */
  175. kfree(ep7312_mtd);
  176. }
  177. module_exit(ep7312_cleanup);
  178. MODULE_LICENSE("GPL");
  179. MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
  180. MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");