epxa10db-flash.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Flash memory access on EPXA based devices
  3. *
  4. * (C) 2000 Nicolas Pitre <nico@cam.org>
  5. * Copyright (C) 2001 Altera Corporation
  6. * Copyright (C) 2001 Red Hat, Inc.
  7. *
  8. * $Id: epxa10db-flash.c,v 1.15 2005/11/07 11:14:27 gleixner Exp $
  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 as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. */
  24. #include <linux/config.h>
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/kernel.h>
  28. #include <linux/init.h>
  29. #include <linux/slab.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/map.h>
  32. #include <linux/mtd/partitions.h>
  33. #include <asm/io.h>
  34. #include <asm/hardware.h>
  35. #ifdef CONFIG_EPXA10DB
  36. #define BOARD_NAME "EPXA10DB"
  37. #else
  38. #define BOARD_NAME "EPXA1DB"
  39. #endif
  40. static int nr_parts = 0;
  41. static struct mtd_partition *parts;
  42. static struct mtd_info *mymtd;
  43. static int epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts);
  44. static struct map_info epxa_map = {
  45. .name = "EPXA flash",
  46. .size = FLASH_SIZE,
  47. .bankwidth = 2,
  48. .phys = FLASH_START,
  49. };
  50. static const char *probes[] = { "RedBoot", "afs", NULL };
  51. static int __init epxa_mtd_init(void)
  52. {
  53. int i;
  54. printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START);
  55. epxa_map.virt = ioremap(FLASH_START, FLASH_SIZE);
  56. if (!epxa_map.virt) {
  57. printk("Failed to ioremap %s flash\n",BOARD_NAME);
  58. return -EIO;
  59. }
  60. simple_map_init(&epxa_map);
  61. mymtd = do_map_probe("cfi_probe", &epxa_map);
  62. if (!mymtd) {
  63. iounmap((void *)epxa_map.virt);
  64. return -ENXIO;
  65. }
  66. mymtd->owner = THIS_MODULE;
  67. /* Unlock the flash device. */
  68. if(mymtd->unlock){
  69. for (i=0; i<mymtd->numeraseregions;i++){
  70. int j;
  71. for(j=0;j<mymtd->eraseregions[i].numblocks;j++){
  72. mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize);
  73. }
  74. }
  75. }
  76. #ifdef CONFIG_MTD_PARTITIONS
  77. nr_parts = parse_mtd_partitions(mymtd, probes, &parts, 0);
  78. if (nr_parts > 0) {
  79. add_mtd_partitions(mymtd, parts, nr_parts);
  80. return 0;
  81. }
  82. #endif
  83. /* No recognised partitioning schemes found - use defaults */
  84. nr_parts = epxa_default_partitions(mymtd, &parts);
  85. if (nr_parts > 0) {
  86. add_mtd_partitions(mymtd, parts, nr_parts);
  87. return 0;
  88. }
  89. /* If all else fails... */
  90. add_mtd_device(mymtd);
  91. return 0;
  92. }
  93. static void __exit epxa_mtd_cleanup(void)
  94. {
  95. if (mymtd) {
  96. if (nr_parts)
  97. del_mtd_partitions(mymtd);
  98. else
  99. del_mtd_device(mymtd);
  100. map_destroy(mymtd);
  101. }
  102. if (epxa_map.virt) {
  103. iounmap((void *)epxa_map.virt);
  104. epxa_map.virt = 0;
  105. }
  106. }
  107. /*
  108. * This will do for now, once we decide which bootldr we're finally
  109. * going to use then we'll remove this function and do it properly
  110. *
  111. * Partions are currently (as offsets from base of flash):
  112. * 0x00000000 - 0x003FFFFF - bootloader (!)
  113. * 0x00400000 - 0x00FFFFFF - Flashdisk
  114. */
  115. static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts)
  116. {
  117. struct mtd_partition *parts;
  118. int ret, i;
  119. int npartitions = 0;
  120. char *names;
  121. const char *name = "jffs";
  122. printk("Using default partitions for %s\n",BOARD_NAME);
  123. npartitions=1;
  124. parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
  125. memzero(parts,npartitions*sizeof(*parts)+strlen(name));
  126. if (!parts) {
  127. ret = -ENOMEM;
  128. goto out;
  129. }
  130. i=0;
  131. names = (char *)&parts[npartitions];
  132. parts[i].name = names;
  133. names += strlen(name) + 1;
  134. strcpy(parts[i].name, name);
  135. #ifdef CONFIG_EPXA10DB
  136. parts[i].size = FLASH_SIZE-0x00400000;
  137. parts[i].offset = 0x00400000;
  138. #else
  139. parts[i].size = FLASH_SIZE-0x00180000;
  140. parts[i].offset = 0x00180000;
  141. #endif
  142. out:
  143. *pparts = parts;
  144. return npartitions;
  145. }
  146. module_init(epxa_mtd_init);
  147. module_exit(epxa_mtd_cleanup);
  148. MODULE_AUTHOR("Clive Davies");
  149. MODULE_DESCRIPTION("Altera epxa mtd flash map");
  150. MODULE_LICENSE("GPL");