spia.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * drivers/mtd/nand/spia.c
  3. *
  4. * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
  5. *
  6. *
  7. * 10-29-2001 TG change to support hardwarespecific access
  8. * to controllines (due to change in nand.c)
  9. * page_cache added
  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. * SPIA board which utilizes the Toshiba TC58V64AFT part. This is
  18. * a 64Mibit (8MiB x 8 bits) NAND flash device.
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/mtd/mtd.h>
  25. #include <linux/mtd/nand.h>
  26. #include <linux/mtd/partitions.h>
  27. #include <asm/io.h>
  28. /*
  29. * MTD structure for SPIA board
  30. */
  31. static struct mtd_info *spia_mtd = NULL;
  32. /*
  33. * Values specific to the SPIA board (used with EP7212 processor)
  34. */
  35. #define SPIA_IO_BASE 0xd0000000 /* Start of EP7212 IO address space */
  36. #define SPIA_FIO_BASE 0xf0000000 /* Address where flash is mapped */
  37. #define SPIA_PEDR 0x0080 /*
  38. * IO offset to Port E data register
  39. * where the CLE, ALE and NCE pins
  40. * are wired to.
  41. */
  42. #define SPIA_PEDDR 0x00c0 /*
  43. * IO offset to Port E data direction
  44. * register so we can control the IO
  45. * lines.
  46. */
  47. /*
  48. * Module stuff
  49. */
  50. static int spia_io_base = SPIA_IO_BASE;
  51. static int spia_fio_base = SPIA_FIO_BASE;
  52. static int spia_pedr = SPIA_PEDR;
  53. static int spia_peddr = SPIA_PEDDR;
  54. module_param(spia_io_base, int, 0);
  55. module_param(spia_fio_base, int, 0);
  56. module_param(spia_pedr, int, 0);
  57. module_param(spia_peddr, int, 0);
  58. /*
  59. * Define partitions for flash device
  60. */
  61. static const struct mtd_partition partition_info[] = {
  62. {
  63. .name = "SPIA flash partition 1",
  64. .offset = 0,
  65. .size = 2 * 1024 * 1024},
  66. {
  67. .name = "SPIA flash partition 2",
  68. .offset = 2 * 1024 * 1024,
  69. .size = 6 * 1024 * 1024}
  70. };
  71. #define NUM_PARTITIONS 2
  72. /*
  73. * hardware specific access to control-lines
  74. *
  75. * ctrl:
  76. * NAND_CNE: bit 0 -> bit 2
  77. * NAND_CLE: bit 1 -> bit 0
  78. * NAND_ALE: bit 2 -> bit 1
  79. */
  80. static void spia_hwcontrol(struct mtd_info *mtd, int cmd)
  81. {
  82. struct nand_chip *chip = mtd->priv;
  83. if (ctrl & NAND_CTRL_CHANGE) {
  84. void __iomem *addr = spia_io_base + spia_pedr;
  85. unsigned char bits;
  86. bits = (ctrl & NAND_CNE) << 2;
  87. bits |= (ctrl & NAND_CLE | NAND_ALE) >> 1;
  88. writeb((readb(addr) & ~0x7) | bits, addr);
  89. }
  90. if (cmd != NAND_CMD_NONE)
  91. writeb(cmd, chip->IO_ADDR_W);
  92. }
  93. /*
  94. * Main initialization routine
  95. */
  96. static int __init spia_init(void)
  97. {
  98. struct nand_chip *this;
  99. /* Allocate memory for MTD device structure and private data */
  100. spia_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  101. if (!spia_mtd) {
  102. printk("Unable to allocate SPIA NAND MTD device structure.\n");
  103. return -ENOMEM;
  104. }
  105. /* Get pointer to private data */
  106. this = (struct nand_chip *)(&spia_mtd[1]);
  107. /* Initialize structures */
  108. memset(spia_mtd, 0, sizeof(struct mtd_info));
  109. memset(this, 0, sizeof(struct nand_chip));
  110. /* Link the private data with the MTD structure */
  111. spia_mtd->priv = this;
  112. spia_mtd->owner = THIS_MODULE;
  113. /*
  114. * Set GPIO Port E control register so that the pins are configured
  115. * to be outputs for controlling the NAND flash.
  116. */
  117. (*(volatile unsigned char *)(spia_io_base + spia_peddr)) = 0x07;
  118. /* Set address of NAND IO lines */
  119. this->IO_ADDR_R = (void __iomem *)spia_fio_base;
  120. this->IO_ADDR_W = (void __iomem *)spia_fio_base;
  121. /* Set address of hardware control function */
  122. this->cmd_ctrl = spia_hwcontrol;
  123. /* 15 us command delay time */
  124. this->chip_delay = 15;
  125. /* Scan to find existence of the device */
  126. if (nand_scan(spia_mtd, 1)) {
  127. kfree(spia_mtd);
  128. return -ENXIO;
  129. }
  130. /* Register the partitions */
  131. mtd_device_register(spia_mtd, partition_info, NUM_PARTITIONS);
  132. /* Return happy */
  133. return 0;
  134. }
  135. module_init(spia_init);
  136. /*
  137. * Clean up routine
  138. */
  139. static void __exit spia_cleanup(void)
  140. {
  141. /* Release resources, unregister device */
  142. nand_release(spia_mtd);
  143. /* Free the MTD device structure */
  144. kfree(spia_mtd);
  145. }
  146. module_exit(spia_cleanup);
  147. MODULE_LICENSE("GPL");
  148. MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com");
  149. MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board");