spia.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. * $Id: spia.c,v 1.25 2005/11/07 11:14:31 gleixner Exp $
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. *
  17. * Overview:
  18. * This is a device driver for the NAND flash device found on the
  19. * SPIA board which utilizes the Toshiba TC58V64AFT part. This is
  20. * a 64Mibit (8MiB x 8 bits) NAND flash device.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/module.h>
  26. #include <linux/mtd/mtd.h>
  27. #include <linux/mtd/nand.h>
  28. #include <linux/mtd/partitions.h>
  29. #include <asm/io.h>
  30. /*
  31. * MTD structure for SPIA board
  32. */
  33. static struct mtd_info *spia_mtd = NULL;
  34. /*
  35. * Values specific to the SPIA board (used with EP7212 processor)
  36. */
  37. #define SPIA_IO_BASE 0xd0000000 /* Start of EP7212 IO address space */
  38. #define SPIA_FIO_BASE 0xf0000000 /* Address where flash is mapped */
  39. #define SPIA_PEDR 0x0080 /*
  40. * IO offset to Port E data register
  41. * where the CLE, ALE and NCE pins
  42. * are wired to.
  43. */
  44. #define SPIA_PEDDR 0x00c0 /*
  45. * IO offset to Port E data direction
  46. * register so we can control the IO
  47. * lines.
  48. */
  49. /*
  50. * Module stuff
  51. */
  52. static int spia_io_base = SPIA_IO_BASE;
  53. static int spia_fio_base = SPIA_FIO_BASE;
  54. static int spia_pedr = SPIA_PEDR;
  55. static int spia_peddr = SPIA_PEDDR;
  56. module_param(spia_io_base, int, 0);
  57. module_param(spia_fio_base, int, 0);
  58. module_param(spia_pedr, int, 0);
  59. module_param(spia_peddr, int, 0);
  60. /*
  61. * Define partitions for flash device
  62. */
  63. static const struct mtd_partition partition_info[] = {
  64. {
  65. .name = "SPIA flash partition 1",
  66. .offset = 0,
  67. .size = 2*1024*1024
  68. },
  69. {
  70. .name = "SPIA flash partition 2",
  71. .offset = 2*1024*1024,
  72. .size = 6*1024*1024
  73. }
  74. };
  75. #define NUM_PARTITIONS 2
  76. /*
  77. * hardware specific access to control-lines
  78. */
  79. static void spia_hwcontrol(struct mtd_info *mtd, int cmd){
  80. switch(cmd){
  81. case NAND_CTL_SETCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x01; break;
  82. case NAND_CTL_CLRCLE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x01; break;
  83. case NAND_CTL_SETALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x02; break;
  84. case NAND_CTL_CLRALE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x02; break;
  85. case NAND_CTL_SETNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) &= ~0x04; break;
  86. case NAND_CTL_CLRNCE: (*(volatile unsigned char *) (spia_io_base + spia_pedr)) |= 0x04; break;
  87. }
  88. }
  89. /*
  90. * Main initialization routine
  91. */
  92. int __init spia_init (void)
  93. {
  94. struct nand_chip *this;
  95. /* Allocate memory for MTD device structure and private data */
  96. spia_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip),
  97. GFP_KERNEL);
  98. if (!spia_mtd) {
  99. printk ("Unable to allocate SPIA NAND MTD device structure.\n");
  100. return -ENOMEM;
  101. }
  102. /* Get pointer to private data */
  103. this = (struct nand_chip *) (&spia_mtd[1]);
  104. /* Initialize structures */
  105. memset((char *) spia_mtd, 0, sizeof(struct mtd_info));
  106. memset((char *) this, 0, sizeof(struct nand_chip));
  107. /* Link the private data with the MTD structure */
  108. spia_mtd->priv = this;
  109. /*
  110. * Set GPIO Port E control register so that the pins are configured
  111. * to be outputs for controlling the NAND flash.
  112. */
  113. (*(volatile unsigned char *) (spia_io_base + spia_peddr)) = 0x07;
  114. /* Set address of NAND IO lines */
  115. this->IO_ADDR_R = (void __iomem *) spia_fio_base;
  116. this->IO_ADDR_W = (void __iomem *) spia_fio_base;
  117. /* Set address of hardware control function */
  118. this->hwcontrol = spia_hwcontrol;
  119. /* 15 us command delay time */
  120. this->chip_delay = 15;
  121. /* Scan to find existence of the device */
  122. if (nand_scan (spia_mtd, 1)) {
  123. kfree (spia_mtd);
  124. return -ENXIO;
  125. }
  126. /* Register the partitions */
  127. add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS);
  128. /* Return happy */
  129. return 0;
  130. }
  131. module_init(spia_init);
  132. /*
  133. * Clean up routine
  134. */
  135. #ifdef MODULE
  136. static void __exit spia_cleanup (void)
  137. {
  138. /* Release resources, unregister device */
  139. nand_release (spia_mtd);
  140. /* Free the MTD device structure */
  141. kfree (spia_mtd);
  142. }
  143. module_exit(spia_cleanup);
  144. #endif
  145. MODULE_LICENSE("GPL");
  146. MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com");
  147. MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on SPIA board");