edb7312.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * Overview:
  14. * This is a device driver for the NAND flash device found on the
  15. * CLEP7312 board which utilizes the Toshiba TC58V64AFT part. This is
  16. * a 64Mibit (8MiB x 8 bits) NAND flash device.
  17. */
  18. #include <linux/slab.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/mtd/nand.h>
  23. #include <linux/mtd/partitions.h>
  24. #include <asm/io.h>
  25. #include <mach/hardware.h> /* for CLPS7111_VIRT_BASE */
  26. #include <asm/sizes.h>
  27. #include <asm/hardware/clps7111.h>
  28. /*
  29. * MTD structure for EDB7312 board
  30. */
  31. static struct mtd_info *ep7312_mtd = NULL;
  32. /*
  33. * Values specific to the EDB7312 board (used with EP7312 processor)
  34. */
  35. #define EP7312_FIO_PBASE 0x10000000 /* Phys address of flash */
  36. #define EP7312_PXDR 0x0001 /*
  37. * IO offset to Port B data register
  38. * where the CLE, ALE and NCE pins
  39. * are wired to.
  40. */
  41. #define EP7312_PXDDR 0x0041 /*
  42. * IO offset to Port B data direction
  43. * register so we can control the IO
  44. * lines.
  45. */
  46. /*
  47. * Module stuff
  48. */
  49. static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE;
  50. static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR;
  51. static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR;
  52. /*
  53. * Define static partitions for flash device
  54. */
  55. static struct mtd_partition partition_info[] = {
  56. {.name = "EP7312 Nand Flash",
  57. .offset = 0,
  58. .size = 8 * 1024 * 1024}
  59. };
  60. #define NUM_PARTITIONS 1
  61. /*
  62. * hardware specific access to control-lines
  63. *
  64. * NAND_NCE: bit 0 -> bit 6 (bit 7 = 1)
  65. * NAND_CLE: bit 1 -> bit 4
  66. * NAND_ALE: bit 2 -> bit 5
  67. */
  68. static void ep7312_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  69. {
  70. struct nand_chip *chip = mtd->priv;
  71. if (ctrl & NAND_CTRL_CHANGE) {
  72. unsigned char bits = 0x80;
  73. bits |= (ctrl & (NAND_CLE | NAND_ALE)) << 3;
  74. bits |= (ctrl & NAND_NCE) ? 0x00 : 0x40;
  75. clps_writeb((clps_readb(ep7312_pxdr) & 0xF0) | bits,
  76. ep7312_pxdr);
  77. }
  78. if (cmd != NAND_CMD_NONE)
  79. writeb(cmd, chip->IO_ADDR_W);
  80. }
  81. /*
  82. * read device ready pin
  83. */
  84. static int ep7312_device_ready(struct mtd_info *mtd)
  85. {
  86. return 1;
  87. }
  88. const char *part_probes[] = { "cmdlinepart", NULL };
  89. /*
  90. * Main initialization routine
  91. */
  92. static int __init ep7312_init(void)
  93. {
  94. struct nand_chip *this;
  95. const char *part_type = 0;
  96. int mtd_parts_nb = 0;
  97. struct mtd_partition *mtd_parts = 0;
  98. void __iomem *ep7312_fio_base;
  99. /* Allocate memory for MTD device structure and private data */
  100. ep7312_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  101. if (!ep7312_mtd) {
  102. printk("Unable to allocate EDB7312 NAND MTD device structure.\n");
  103. return -ENOMEM;
  104. }
  105. /* map physical address */
  106. ep7312_fio_base = ioremap(ep7312_fio_pbase, SZ_1K);
  107. if (!ep7312_fio_base) {
  108. printk("ioremap EDB7312 NAND flash failed\n");
  109. kfree(ep7312_mtd);
  110. return -EIO;
  111. }
  112. /* Get pointer to private data */
  113. this = (struct nand_chip *)(&ep7312_mtd[1]);
  114. /* Initialize structures */
  115. memset(ep7312_mtd, 0, sizeof(struct mtd_info));
  116. memset(this, 0, sizeof(struct nand_chip));
  117. /* Link the private data with the MTD structure */
  118. ep7312_mtd->priv = this;
  119. ep7312_mtd->owner = THIS_MODULE;
  120. /*
  121. * Set GPIO Port B control register so that the pins are configured
  122. * to be outputs for controlling the NAND flash.
  123. */
  124. clps_writeb(0xf0, ep7312_pxddr);
  125. /* insert callbacks */
  126. this->IO_ADDR_R = ep7312_fio_base;
  127. this->IO_ADDR_W = ep7312_fio_base;
  128. this->cmd_ctrl = ep7312_hwcontrol;
  129. this->dev_ready = ep7312_device_ready;
  130. /* 15 us command delay time */
  131. this->chip_delay = 15;
  132. /* Scan to find existence of the device */
  133. if (nand_scan(ep7312_mtd, 1)) {
  134. iounmap((void *)ep7312_fio_base);
  135. kfree(ep7312_mtd);
  136. return -ENXIO;
  137. }
  138. ep7312_mtd->name = "edb7312-nand";
  139. mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
  140. if (mtd_parts_nb > 0)
  141. part_type = "command line";
  142. else
  143. mtd_parts_nb = 0;
  144. if (mtd_parts_nb == 0) {
  145. mtd_parts = partition_info;
  146. mtd_parts_nb = NUM_PARTITIONS;
  147. part_type = "static";
  148. }
  149. /* Register the partitions */
  150. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  151. mtd_device_register(ep7312_mtd, mtd_parts, mtd_parts_nb);
  152. /* Return happy */
  153. return 0;
  154. }
  155. module_init(ep7312_init);
  156. /*
  157. * Clean up routine
  158. */
  159. static void __exit ep7312_cleanup(void)
  160. {
  161. struct nand_chip *this = (struct nand_chip *)&ep7312_mtd[1];
  162. /* Release resources, unregister device */
  163. nand_release(ap7312_mtd);
  164. /* Release io resource */
  165. iounmap(this->IO_ADDR_R);
  166. /* Free the MTD device structure */
  167. kfree(ep7312_mtd);
  168. }
  169. module_exit(ep7312_cleanup);
  170. MODULE_LICENSE("GPL");
  171. MODULE_AUTHOR("Marius Groeger <mag@sysgo.de>");
  172. MODULE_DESCRIPTION("MTD map driver for Cogent EDB7312 board");