h1910.c 4.0 KB

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