ts7250.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * drivers/mtd/nand/ts7250.c
  3. *
  4. * Copyright (C) 2004 Technologic Systems (support@embeddedARM.com)
  5. *
  6. * Derived from drivers/mtd/nand/edb7312.c
  7. * Copyright (C) 2004 Marius Gröger (mag@sysgo.de)
  8. *
  9. * Derived from drivers/mtd/nand/autcpu12.c
  10. * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
  11. *
  12. * $Id: ts7250.c,v 1.4 2004/12/30 22:02:07 joff Exp $
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License version 2 as
  16. * published by the Free Software Foundation.
  17. *
  18. * Overview:
  19. * This is a device driver for the NAND flash device found on the
  20. * TS-7250 board which utilizes a Samsung 32 Mbyte part.
  21. */
  22. #include <linux/slab.h>
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/mtd/mtd.h>
  26. #include <linux/mtd/nand.h>
  27. #include <linux/mtd/partitions.h>
  28. #include <asm/io.h>
  29. #include <asm/arch/hardware.h>
  30. #include <asm/sizes.h>
  31. #include <asm/mach-types.h>
  32. /*
  33. * MTD structure for TS7250 board
  34. */
  35. static struct mtd_info *ts7250_mtd = NULL;
  36. #ifdef CONFIG_MTD_PARTITIONS
  37. static const char *part_probes[] = { "cmdlinepart", NULL };
  38. #define NUM_PARTITIONS 3
  39. /*
  40. * Define static partitions for flash device
  41. */
  42. static struct mtd_partition partition_info32[] = {
  43. {
  44. .name = "TS-BOOTROM",
  45. .offset = 0x00000000,
  46. .size = 0x00004000,
  47. }, {
  48. .name = "Linux",
  49. .offset = 0x00004000,
  50. .size = 0x01d00000,
  51. }, {
  52. .name = "RedBoot",
  53. .offset = 0x01d04000,
  54. .size = 0x002fc000,
  55. },
  56. };
  57. /*
  58. * Define static partitions for flash device
  59. */
  60. static struct mtd_partition partition_info128[] = {
  61. {
  62. .name = "TS-BOOTROM",
  63. .offset = 0x00000000,
  64. .size = 0x00004000,
  65. }, {
  66. .name = "Linux",
  67. .offset = 0x00004000,
  68. .size = 0x07d00000,
  69. }, {
  70. .name = "RedBoot",
  71. .offset = 0x07d04000,
  72. .size = 0x002fc000,
  73. },
  74. };
  75. #endif
  76. /*
  77. * hardware specific access to control-lines
  78. *
  79. * ctrl:
  80. * NAND_NCE: bit 0 -> bit 2
  81. * NAND_CLE: bit 1 -> bit 1
  82. * NAND_ALE: bit 2 -> bit 0
  83. */
  84. static void ts7250_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  85. {
  86. struct nand_chip *chip = mtd->priv;
  87. if (ctrl & NAND_CTRL_CHANGE) {
  88. unsigned long addr = TS72XX_NAND_CONTROL_VIRT_BASE;
  89. unsigned char bits;
  90. bits = (ctrl & NAND_NCE) << 2;
  91. bits |= ctrl & NAND_CLE;
  92. bits |= (ctrl & NAND_ALE) >> 2;
  93. __raw_writeb((__raw_readb(addr) & ~0x7) | bits, addr);
  94. }
  95. if (cmd != NAND_CMD_NONE)
  96. writeb(cmd, chip->IO_ADDR_W);
  97. }
  98. /*
  99. * read device ready pin
  100. */
  101. static int ts7250_device_ready(struct mtd_info *mtd)
  102. {
  103. return __raw_readb(TS72XX_NAND_BUSY_VIRT_BASE) & 0x20;
  104. }
  105. /*
  106. * Main initialization routine
  107. */
  108. static int __init ts7250_init(void)
  109. {
  110. struct nand_chip *this;
  111. const char *part_type = 0;
  112. int mtd_parts_nb = 0;
  113. struct mtd_partition *mtd_parts = 0;
  114. if (!machine_is_ts72xx() || board_is_ts7200())
  115. return -ENXIO;
  116. /* Allocate memory for MTD device structure and private data */
  117. ts7250_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
  118. if (!ts7250_mtd) {
  119. printk("Unable to allocate TS7250 NAND MTD device structure.\n");
  120. return -ENOMEM;
  121. }
  122. /* Get pointer to private data */
  123. this = (struct nand_chip *)(&ts7250_mtd[1]);
  124. /* Initialize structures */
  125. memset(ts7250_mtd, 0, sizeof(struct mtd_info));
  126. memset(this, 0, sizeof(struct nand_chip));
  127. /* Link the private data with the MTD structure */
  128. ts7250_mtd->priv = this;
  129. ts7250_mtd->owner = THIS_MODULE;
  130. /* insert callbacks */
  131. this->IO_ADDR_R = (void *)TS72XX_NAND_DATA_VIRT_BASE;
  132. this->IO_ADDR_W = (void *)TS72XX_NAND_DATA_VIRT_BASE;
  133. this->cmd_ctrl = ts7250_hwcontrol;
  134. this->dev_ready = ts7250_device_ready;
  135. this->chip_delay = 15;
  136. this->ecc.mode = NAND_ECC_SOFT;
  137. printk("Searching for NAND flash...\n");
  138. /* Scan to find existence of the device */
  139. if (nand_scan(ts7250_mtd, 1)) {
  140. kfree(ts7250_mtd);
  141. return -ENXIO;
  142. }
  143. #ifdef CONFIG_MTD_PARTITIONS
  144. ts7250_mtd->name = "ts7250-nand";
  145. mtd_parts_nb = parse_mtd_partitions(ts7250_mtd, part_probes, &mtd_parts, 0);
  146. if (mtd_parts_nb > 0)
  147. part_type = "command line";
  148. else
  149. mtd_parts_nb = 0;
  150. #endif
  151. if (mtd_parts_nb == 0) {
  152. mtd_parts = partition_info32;
  153. if (ts7250_mtd->size >= (128 * 0x100000))
  154. mtd_parts = partition_info128;
  155. mtd_parts_nb = NUM_PARTITIONS;
  156. part_type = "static";
  157. }
  158. /* Register the partitions */
  159. printk(KERN_NOTICE "Using %s partition definition\n", part_type);
  160. add_mtd_partitions(ts7250_mtd, mtd_parts, mtd_parts_nb);
  161. /* Return happy */
  162. return 0;
  163. }
  164. module_init(ts7250_init);
  165. /*
  166. * Clean up routine
  167. */
  168. static void __exit ts7250_cleanup(void)
  169. {
  170. /* Unregister the device */
  171. del_mtd_device(ts7250_mtd);
  172. /* Free the MTD device structure */
  173. kfree(ts7250_mtd);
  174. }
  175. module_exit(ts7250_cleanup);
  176. MODULE_LICENSE("GPL");
  177. MODULE_AUTHOR("Jesse Off <joff@embeddedARM.com>");
  178. MODULE_DESCRIPTION("MTD map driver for Technologic Systems TS-7250 board");