h1910.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * drivers/mtd/nand/h1910.c
  3. *
  4. * Copyright (C) 2003 Joshua Wise (joshua@joshuawise.com)
  5. *
  6. * Derived from drivers/mtd/nand/edb7312.c
  7. * Copyright (C) 2002 Marius Gröger (mag@sysgo.de)
  8. * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
  9. *
  10. * $Id: h1910.c,v 1.6 2005/11/07 11:14:30 gleixner Exp $
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. *
  16. * Overview:
  17. * This is a device driver for the NAND flash device found on the
  18. * iPAQ h1910 board which utilizes the Samsung K9F2808 part. This is
  19. * a 128Mibit (16MiB x 8 bits) NAND flash device.
  20. */
  21. #include <linux/slab.h>
  22. #include <linux/init.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. #include <asm/arch/hardware.h> /* for CLPS7111_VIRT_BASE */
  29. #include <asm/sizes.h>
  30. #include <asm/arch/h1900-gpio.h>
  31. #include <asm/arch/ipaq.h>
  32. /*
  33. * MTD structure for EDB7312 board
  34. */
  35. static struct mtd_info *h1910_nand_mtd = NULL;
  36. /*
  37. * Module stuff
  38. */
  39. #ifdef CONFIG_MTD_PARTITIONS
  40. /*
  41. * Define static partitions for flash device
  42. */
  43. static struct mtd_partition partition_info[] = {
  44. { name: "h1910 NAND Flash",
  45. offset: 0,
  46. size: 16*1024*1024 }
  47. };
  48. #define NUM_PARTITIONS 1
  49. #endif
  50. /*
  51. * hardware specific access to control-lines
  52. */
  53. static void h1910_hwcontrol(struct mtd_info *mtd, int cmd)
  54. {
  55. struct nand_chip* this = (struct nand_chip *) (mtd->priv);
  56. switch(cmd) {
  57. case NAND_CTL_SETCLE:
  58. this->IO_ADDR_R |= (1 << 2);
  59. this->IO_ADDR_W |= (1 << 2);
  60. break;
  61. case NAND_CTL_CLRCLE:
  62. this->IO_ADDR_R &= ~(1 << 2);
  63. this->IO_ADDR_W &= ~(1 << 2);
  64. break;
  65. case NAND_CTL_SETALE:
  66. this->IO_ADDR_R |= (1 << 3);
  67. this->IO_ADDR_W |= (1 << 3);
  68. break;
  69. case NAND_CTL_CLRALE:
  70. this->IO_ADDR_R &= ~(1 << 3);
  71. this->IO_ADDR_W &= ~(1 << 3);
  72. break;
  73. case NAND_CTL_SETNCE:
  74. break;
  75. case NAND_CTL_CLRNCE:
  76. break;
  77. }
  78. }
  79. /*
  80. * read device ready pin
  81. */
  82. #if 0
  83. static int h1910_device_ready(struct mtd_info *mtd)
  84. {
  85. return (GPLR(55) & GPIO_bit(55));
  86. }
  87. #endif
  88. /*
  89. * Main initialization routine
  90. */
  91. static int __init h1910_init (void)
  92. {
  93. struct nand_chip *this;
  94. const char *part_type = 0;
  95. int mtd_parts_nb = 0;
  96. struct mtd_partition *mtd_parts = 0;
  97. void __iomem *nandaddr;
  98. if (!machine_is_h1900())
  99. return -ENODEV;
  100. nandaddr = ioremap(0x08000000, 0x1000);
  101. if (!nandaddr) {
  102. printk("Failed to ioremap nand flash.\n");
  103. return -ENOMEM;
  104. }
  105. /* Allocate memory for MTD device structure and private data */
  106. h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) +
  107. sizeof(struct nand_chip),
  108. GFP_KERNEL);
  109. if (!h1910_nand_mtd) {
  110. printk("Unable to allocate h1910 NAND MTD device structure.\n");
  111. iounmap ((void *) nandaddr);
  112. return -ENOMEM;
  113. }
  114. /* Get pointer to private data */
  115. this = (struct nand_chip *) (&h1910_nand_mtd[1]);
  116. /* Initialize structures */
  117. memset((char *) h1910_nand_mtd, 0, sizeof(struct mtd_info));
  118. memset((char *) this, 0, sizeof(struct nand_chip));
  119. /* Link the private data with the MTD structure */
  120. h1910_nand_mtd->priv = this;
  121. /*
  122. * Enable VPEN
  123. */
  124. GPSR(37) = GPIO_bit(37);
  125. /* insert callbacks */
  126. this->IO_ADDR_R = nandaddr;
  127. this->IO_ADDR_W = nandaddr;
  128. this->hwcontrol = h1910_hwcontrol;
  129. this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
  130. /* 15 us command delay time */
  131. this->chip_delay = 50;
  132. this->eccmode = NAND_ECC_SOFT;
  133. this->options = NAND_NO_AUTOINCR;
  134. /* Scan to find existence of the device */
  135. if (nand_scan (h1910_nand_mtd, 1)) {
  136. printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
  137. kfree (h1910_nand_mtd);
  138. iounmap ((void *) nandaddr);
  139. return -ENXIO;
  140. }
  141. #ifdef CONFIG_MTD_CMDLINE_PARTS
  142. mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts,
  143. "h1910-nand");
  144. if (mtd_parts_nb > 0)
  145. part_type = "command line";
  146. else
  147. mtd_parts_nb = 0;
  148. #endif
  149. if (mtd_parts_nb == 0)
  150. {
  151. mtd_parts = partition_info;
  152. mtd_parts_nb = NUM_PARTITIONS;
  153. part_type = "static";
  154. }
  155. /* Register the partitions */
  156. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  157. add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
  158. /* Return happy */
  159. return 0;
  160. }
  161. module_init(h1910_init);
  162. /*
  163. * Clean up routine
  164. */
  165. static void __exit h1910_cleanup (void)
  166. {
  167. struct nand_chip *this = (struct nand_chip *) &h1910_nand_mtd[1];
  168. /* Release resources, unregister device */
  169. nand_release (h1910_nand_mtd);
  170. /* Release io resource */
  171. iounmap ((void *) this->IO_ADDR_W);
  172. /* Free the MTD device structure */
  173. kfree (h1910_nand_mtd);
  174. }
  175. module_exit(h1910_cleanup);
  176. MODULE_LICENSE("GPL");
  177. MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
  178. MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");