cfi_flagadm.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright © 2001 Flaga hf. Medical Devices, Kári Davíðsson <kd@flaga.is>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  10. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  12. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  13. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  14. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  15. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  16. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  18. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. *
  20. * You should have received a copy of the GNU General Public License along
  21. * with this program; if not, write to the Free Software Foundation, Inc.,
  22. * 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <linux/module.h>
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <asm/io.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/map.h>
  31. #include <linux/mtd/partitions.h>
  32. /* We split the flash chip up into four parts.
  33. * 1: bootloader first 128k (0x00000000 - 0x0001FFFF) size 0x020000
  34. * 2: kernel 640k (0x00020000 - 0x000BFFFF) size 0x0A0000
  35. * 3: compressed 1536k root ramdisk (0x000C0000 - 0x0023FFFF) size 0x180000
  36. * 4: writeable diskpartition (jffs)(0x00240000 - 0x003FFFFF) size 0x1C0000
  37. */
  38. #define FLASH_PHYS_ADDR 0x40000000
  39. #define FLASH_SIZE 0x400000
  40. #define FLASH_PARTITION0_ADDR 0x00000000
  41. #define FLASH_PARTITION0_SIZE 0x00020000
  42. #define FLASH_PARTITION1_ADDR 0x00020000
  43. #define FLASH_PARTITION1_SIZE 0x000A0000
  44. #define FLASH_PARTITION2_ADDR 0x000C0000
  45. #define FLASH_PARTITION2_SIZE 0x00180000
  46. #define FLASH_PARTITION3_ADDR 0x00240000
  47. #define FLASH_PARTITION3_SIZE 0x001C0000
  48. static struct map_info flagadm_map = {
  49. .name = "FlagaDM flash device",
  50. .size = FLASH_SIZE,
  51. .bankwidth = 2,
  52. };
  53. static struct mtd_partition flagadm_parts[] = {
  54. {
  55. .name = "Bootloader",
  56. .offset = FLASH_PARTITION0_ADDR,
  57. .size = FLASH_PARTITION0_SIZE
  58. },
  59. {
  60. .name = "Kernel image",
  61. .offset = FLASH_PARTITION1_ADDR,
  62. .size = FLASH_PARTITION1_SIZE
  63. },
  64. {
  65. .name = "Initial ramdisk image",
  66. .offset = FLASH_PARTITION2_ADDR,
  67. .size = FLASH_PARTITION2_SIZE
  68. },
  69. {
  70. .name = "Persistent storage",
  71. .offset = FLASH_PARTITION3_ADDR,
  72. .size = FLASH_PARTITION3_SIZE
  73. }
  74. };
  75. #define PARTITION_COUNT ARRAY_SIZE(flagadm_parts)
  76. static struct mtd_info *mymtd;
  77. static int __init init_flagadm(void)
  78. {
  79. printk(KERN_NOTICE "FlagaDM flash device: %x at %x\n",
  80. FLASH_SIZE, FLASH_PHYS_ADDR);
  81. flagadm_map.phys = FLASH_PHYS_ADDR;
  82. flagadm_map.virt = ioremap(FLASH_PHYS_ADDR,
  83. FLASH_SIZE);
  84. if (!flagadm_map.virt) {
  85. printk("Failed to ioremap\n");
  86. return -EIO;
  87. }
  88. simple_map_init(&flagadm_map);
  89. mymtd = do_map_probe("cfi_probe", &flagadm_map);
  90. if (mymtd) {
  91. mymtd->owner = THIS_MODULE;
  92. mtd_device_register(mymtd, flagadm_parts, PARTITION_COUNT);
  93. printk(KERN_NOTICE "FlagaDM flash device initialized\n");
  94. return 0;
  95. }
  96. iounmap((void __iomem *)flagadm_map.virt);
  97. return -ENXIO;
  98. }
  99. static void __exit cleanup_flagadm(void)
  100. {
  101. if (mymtd) {
  102. mtd_device_unregister(mymtd);
  103. map_destroy(mymtd);
  104. }
  105. if (flagadm_map.virt) {
  106. iounmap((void __iomem *)flagadm_map.virt);
  107. flagadm_map.virt = NULL;
  108. }
  109. }
  110. module_init(init_flagadm);
  111. module_exit(cleanup_flagadm);
  112. MODULE_LICENSE("GPL");
  113. MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
  114. MODULE_DESCRIPTION("MTD map driver for Flaga digital module");