ts7250.c 4.7 KB

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