PageRenderTime 21ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/mtd/nand/h1910.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2
C | 183 lines | 98 code | 27 blank | 58 comment | 9 complexity | 4b52cc95f3957a14d923f0197fe02608 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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. const char *part_type = 0;
  76. int mtd_parts_nb = 0;
  77. struct mtd_partition *mtd_parts = 0;
  78. void __iomem *nandaddr;
  79. if (!machine_is_h1900())
  80. return -ENODEV;
  81. nandaddr = ioremap(0x08000000, 0x1000);
  82. if (!nandaddr) {
  83. printk("Failed to ioremap nand flash.\n");
  84. return -ENOMEM;
  85. }
  86. /* Allocate memory for MTD device structure and private data */
  87. h1910_nand_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  88. if (!h1910_nand_mtd) {
  89. printk("Unable to allocate h1910 NAND MTD device structure.\n");
  90. iounmap((void *)nandaddr);
  91. return -ENOMEM;
  92. }
  93. /* Get pointer to private data */
  94. this = (struct nand_chip *)(&h1910_nand_mtd[1]);
  95. /* Initialize structures */
  96. memset(h1910_nand_mtd, 0, sizeof(struct mtd_info));
  97. memset(this, 0, sizeof(struct nand_chip));
  98. /* Link the private data with the MTD structure */
  99. h1910_nand_mtd->priv = this;
  100. h1910_nand_mtd->owner = THIS_MODULE;
  101. /*
  102. * Enable VPEN
  103. */
  104. GPSR(37) = GPIO_bit(37);
  105. /* insert callbacks */
  106. this->IO_ADDR_R = nandaddr;
  107. this->IO_ADDR_W = nandaddr;
  108. this->cmd_ctrl = h1910_hwcontrol;
  109. this->dev_ready = NULL; /* unknown whether that was correct or not so we will just do it like this */
  110. /* 15 us command delay time */
  111. this->chip_delay = 50;
  112. this->ecc.mode = NAND_ECC_SOFT;
  113. this->options = NAND_NO_AUTOINCR;
  114. /* Scan to find existence of the device */
  115. if (nand_scan(h1910_nand_mtd, 1)) {
  116. printk(KERN_NOTICE "No NAND device - returning -ENXIO\n");
  117. kfree(h1910_nand_mtd);
  118. iounmap((void *)nandaddr);
  119. return -ENXIO;
  120. }
  121. #ifdef CONFIG_MTD_CMDLINE_PARTS
  122. mtd_parts_nb = parse_cmdline_partitions(h1910_nand_mtd, &mtd_parts, "h1910-nand");
  123. if (mtd_parts_nb > 0)
  124. part_type = "command line";
  125. else
  126. mtd_parts_nb = 0;
  127. #endif
  128. if (mtd_parts_nb == 0) {
  129. mtd_parts = partition_info;
  130. mtd_parts_nb = NUM_PARTITIONS;
  131. part_type = "static";
  132. }
  133. /* Register the partitions */
  134. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  135. mtd_device_register(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
  136. /* Return happy */
  137. return 0;
  138. }
  139. module_init(h1910_init);
  140. /*
  141. * Clean up routine
  142. */
  143. static void __exit h1910_cleanup(void)
  144. {
  145. struct nand_chip *this = (struct nand_chip *)&h1910_nand_mtd[1];
  146. /* Release resources, unregister device */
  147. nand_release(h1910_nand_mtd);
  148. /* Release io resource */
  149. iounmap((void *)this->IO_ADDR_W);
  150. /* Free the MTD device structure */
  151. kfree(h1910_nand_mtd);
  152. }
  153. module_exit(h1910_cleanup);
  154. MODULE_LICENSE("GPL");
  155. MODULE_AUTHOR("Joshua Wise <joshua at joshuawise dot com>");
  156. MODULE_DESCRIPTION("NAND flash driver for iPAQ h1910");