h1910.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * NAND_NCE: bit 0 - don't care
  54. * NAND_CLE: bit 1 - address bit 2
  55. * NAND_ALE: bit 2 - address bit 3
  56. */
  57. static void h1910_hwcontrol(struct mtd_info *mtd, int cmd,
  58. unsigned int ctrl)
  59. {
  60. struct nand_chip *chip = mtd->priv;
  61. if (cmd != NAND_CMD_NONE)
  62. writeb(cmd, chip->IO_ADDR_W | ((ctrl & 0x6) << 1));
  63. }
  64. /*
  65. * read device ready pin
  66. */
  67. #if 0
  68. static int h1910_device_ready(struct mtd_info *mtd)
  69. {
  70. return (GPLR(55) & GPIO_bit(55));
  71. }
  72. #endif
  73. /*
  74. * Main initialization routine
  75. */
  76. static int __init h1910_init(void)
  77. {
  78. struct nand_chip *this;
  79. const char *part_type = 0;
  80. int mtd_parts_nb = 0;
  81. struct mtd_partition *mtd_parts = 0;
  82. void __iomem *nandaddr;
  83. if (!machine_is_h1900())
  84. return -ENODEV;
  85. nandaddr = ioremap(0x08000000, 0x1000);
  86. if (!nandaddr) {
  87. printk("Failed to ioremap nand flash.\n");
  88. return -ENOMEM;
  89. }
  90. /* Allocate memory for MTD device structure and private data */
  91. h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  92. if (!h1910_nand_mtd) {
  93. printk("Unable to allocate h1910 NAND MTD device structure.\n");
  94. iounmap((void *)nandaddr);
  95. return -ENOMEM;
  96. }
  97. /* Get pointer to private data */
  98. this = (struct nand_chip *)(&h1910_nand_mtd[1]);
  99. /* Initialize structures */
  100. memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
  101. memset(this, 0, sizeof(struct nand_chip));
  102. /* Link the private data with the MTD structure */
  103. h1910_nand_mtd->priv = this;
  104. h1910_nand_mtd->owner = THIS_MODULE;
  105. /*
  106. * Enable VPEN
  107. */
  108. GPSR(37) = GPIO_bit(37);
  109. /* insert callbacks */
  110. this->IO_ADDR_R = nandaddr;
  111. this->IO_ADDR_W = nandaddr;
  112. this->cmd_ctrl = h1910_hwcontrol;
  113. this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
  114. /* 15 us command delay time */
  115. this->chip_delay = 50;
  116. this->ecc.mode = NAND_ECC_SOFT;
  117. this->options = NAND_NO_AUTOINCR;
  118. /* Scan to find existence of the device */
  119. if (nand_scan(h1910_nand_mtd, 1)) {
  120. printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
  121. kfree(h1910_nand_mtd);
  122. iounmap((void *)nandaddr);
  123. return -ENXIO;
  124. }
  125. #ifdef CONFIG_MTD_CMDLINE_PARTS
  126. mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
  127. if (mtd_parts_nb > 0)
  128. part_type = "command line";
  129. else
  130. mtd_parts_nb = 0;
  131. #endif
  132. if (mtd_parts_nb == 0) {
  133. mtd_parts = partition_info;
  134. mtd_parts_nb = NUM_PARTITIONS;
  135. part_type = "static";
  136. }
  137. /* Register the partitions */
  138. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  139. add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
  140. /* Return happy */
  141. return 0;
  142. }
  143. module_init(h1910_init);
  144. /*
  145. * Clean up routine
  146. */
  147. static void __exit h1910_cleanup(void)
  148. {
  149. struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
  150. /* Release resources, unregister device */
  151. nand_release(h1910_nand_mtd);
  152. /* Release io resource */
  153. iounmap((void *)this->IO_ADDR_W);
  154. /* Free the MTD device structure */
  155. kfree(h1910_nand_mtd);
  156. }
  157. module_exit(h1910_cleanup);
  158. MODULE_LICENSE("GPL");
  159. MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
  160. MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");