epxa10db-flash.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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.13 2004/11/04 13:24:14 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 <asm/io.h>
  30. #include <linux/mtd/mtd.h>
  31. #include <linux/mtd/map.h>
  32. #include <linux/mtd/partitions.h>
  33. #include <asm/hardware.h>
  34. #ifdef CONFIG_EPXA10DB
  35. #define BOARD_NAME "EPXA10DB"
  36. #else
  37. #define BOARD_NAME "EPXA1DB"
  38. #endif
  39. static int nr_parts = 0;
  40. static struct mtd_partition *parts;
  41. static struct mtd_info *mymtd;
  42. static int epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts);
  43. static struct map_info epxa_map = {
  44. .name = "EPXA flash",
  45. .size = FLASH_SIZE,
  46. .bankwidth = 2,
  47. .phys = FLASH_START,
  48. };
  49. static const char *probes[] = { "RedBoot", "afs", NULL };
  50. static int __init epxa_mtd_init(void)
  51. {
  52. int i;
  53. printk(KERN_NOTICE "%s flash device: 0x%x at 0x%x\n", BOARD_NAME, FLASH_SIZE, FLASH_START);
  54. epxa_map.virt = ioremap(FLASH_START, FLASH_SIZE);
  55. if (!epxa_map.virt) {
  56. printk("Failed to ioremap %s flash\n",BOARD_NAME);
  57. return -EIO;
  58. }
  59. simple_map_init(&epxa_map);
  60. mymtd = do_map_probe("cfi_probe", &epxa_map);
  61. if (!mymtd) {
  62. iounmap((void *)epxa_map.virt);
  63. return -ENXIO;
  64. }
  65. mymtd->owner = THIS_MODULE;
  66. /* Unlock the flash device. */
  67. if(mymtd->unlock){
  68. for (i=0; i<mymtd->numeraseregions;i++){
  69. int j;
  70. for(j=0;j<mymtd->eraseregions[i].numblocks;j++){
  71. mymtd->unlock(mymtd,mymtd->eraseregions[i].offset + j * mymtd->eraseregions[i].erasesize,mymtd->eraseregions[i].erasesize);
  72. }
  73. }
  74. }
  75. #ifdef CONFIG_MTD_PARTITIONS
  76. nr_parts = parse_mtd_partitions(mymtd, probes, &parts, 0);
  77. if (nr_parts > 0) {
  78. add_mtd_partitions(mymtd, parts, nr_parts);
  79. return 0;
  80. }
  81. #endif
  82. /* No recognised partitioning schemes found - use defaults */
  83. nr_parts = epxa_default_partitions(mymtd, &parts);
  84. if (nr_parts > 0) {
  85. add_mtd_partitions(mymtd, parts, nr_parts);
  86. return 0;
  87. }
  88. /* If all else fails... */
  89. add_mtd_device(mymtd);
  90. return 0;
  91. }
  92. static void __exit epxa_mtd_cleanup(void)
  93. {
  94. if (mymtd) {
  95. if (nr_parts)
  96. del_mtd_partitions(mymtd);
  97. else
  98. del_mtd_device(mymtd);
  99. map_destroy(mymtd);
  100. }
  101. if (epxa_map.virt) {
  102. iounmap((void *)epxa_map.virt);
  103. epxa_map.virt = 0;
  104. }
  105. }
  106. /*
  107. * This will do for now, once we decide which bootldr we're finally
  108. * going to use then we'll remove this function and do it properly
  109. *
  110. * Partions are currently (as offsets from base of flash):
  111. * 0x00000000 - 0x003FFFFF - bootloader (!)
  112. * 0x00400000 - 0x00FFFFFF - Flashdisk
  113. */
  114. static int __init epxa_default_partitions(struct mtd_info *master, struct mtd_partition **pparts)
  115. {
  116. struct mtd_partition *parts;
  117. int ret, i;
  118. int npartitions = 0;
  119. char *names;
  120. const char *name = "jffs";
  121. printk("Using default partitions for %s\n",BOARD_NAME);
  122. npartitions=1;
  123. parts = kmalloc(npartitions*sizeof(*parts)+strlen(name), GFP_KERNEL);
  124. memzero(parts,npartitions*sizeof(*parts)+strlen(name));
  125. if (!parts) {
  126. ret = -ENOMEM;
  127. goto out;
  128. }
  129. i=0;
  130. names = (char *)&parts[npartitions];
  131. parts[i].name = names;
  132. names += strlen(name) + 1;
  133. strcpy(parts[i].name, name);
  134. #ifdef CONFIG_EPXA10DB
  135. parts[i].size = FLASH_SIZE-0x00400000;
  136. parts[i].offset = 0x00400000;
  137. #else
  138. parts[i].size = FLASH_SIZE-0x00180000;
  139. parts[i].offset = 0x00180000;
  140. #endif
  141. out:
  142. *pparts = parts;
  143. return npartitions;
  144. }
  145. module_init(epxa_mtd_init);
  146. module_exit(epxa_mtd_cleanup);
  147. MODULE_AUTHOR("Clive Davies");
  148. MODULE_DESCRIPTION("Altera epxa mtd flash map");
  149. MODULE_LICENSE("GPL");