uclinux.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /****************************************************************************/
  2. /*
  3. * uclinux.c -- generic memory mapped MTD driver for uclinux
  4. *
  5. * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
  6. *
  7. * License: GPL
  8. */
  9. /****************************************************************************/
  10. #include <linux/moduleparam.h>
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/fs.h>
  15. #include <linux/mm.h>
  16. #include <linux/major.h>
  17. #include <linux/mtd/mtd.h>
  18. #include <linux/mtd/map.h>
  19. #include <linux/mtd/partitions.h>
  20. #include <asm/io.h>
  21. #include <asm/sections.h>
  22. /****************************************************************************/
  23. #ifdef CONFIG_MTD_ROM
  24. #define MAP_NAME "rom"
  25. #else
  26. #define MAP_NAME "ram"
  27. #endif
  28. /*
  29. * Blackfin uses uclinux_ram_map during startup, so it must not be static.
  30. * Provide a dummy declaration to make sparse happy.
  31. */
  32. extern struct map_info uclinux_ram_map;
  33. struct map_info uclinux_ram_map = {
  34. .name = MAP_NAME,
  35. .size = 0,
  36. };
  37. static unsigned long physaddr = -1;
  38. module_param(physaddr, ulong, S_IRUGO);
  39. static struct mtd_info *uclinux_ram_mtdinfo;
  40. /****************************************************************************/
  41. static struct mtd_partition uclinux_romfs[] = {
  42. { .name = "ROMfs" }
  43. };
  44. #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
  45. /****************************************************************************/
  46. static int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  47. size_t *retlen, void **virt, resource_size_t *phys)
  48. {
  49. struct map_info *map = mtd->priv;
  50. *virt = map->virt + from;
  51. if (phys)
  52. *phys = map->phys + from;
  53. *retlen = len;
  54. return(0);
  55. }
  56. /****************************************************************************/
  57. static int __init uclinux_mtd_init(void)
  58. {
  59. struct mtd_info *mtd;
  60. struct map_info *mapp;
  61. mapp = &uclinux_ram_map;
  62. if (physaddr == -1)
  63. mapp->phys = (resource_size_t)__bss_stop;
  64. else
  65. mapp->phys = physaddr;
  66. if (!mapp->size)
  67. mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(mapp->phys + 8))));
  68. mapp->bankwidth = 4;
  69. printk("uclinux[mtd]: probe address=0x%x size=0x%x\n",
  70. (int) mapp->phys, (int) mapp->size);
  71. /*
  72. * The filesystem is guaranteed to be in direct mapped memory. It is
  73. * directly following the kernels own bss region. Following the same
  74. * mechanism used by architectures setting up traditional initrds we
  75. * use phys_to_virt to get the virtual address of its start.
  76. */
  77. mapp->virt = phys_to_virt(mapp->phys);
  78. if (mapp->virt == 0) {
  79. printk("uclinux[mtd]: no virtual mapping?\n");
  80. return(-EIO);
  81. }
  82. simple_map_init(mapp);
  83. mtd = do_map_probe("map_" MAP_NAME, mapp);
  84. if (!mtd) {
  85. printk("uclinux[mtd]: failed to find a mapping?\n");
  86. return(-ENXIO);
  87. }
  88. mtd->owner = THIS_MODULE;
  89. mtd->_point = uclinux_point;
  90. mtd->priv = mapp;
  91. uclinux_ram_mtdinfo = mtd;
  92. mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
  93. return(0);
  94. }
  95. device_initcall(uclinux_mtd_init);
  96. /****************************************************************************/