h1910.c 4.4 KB

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