uclinux.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************/
  2. /*
  3. * uclinux.c -- generic memory mapped MTD driver for uclinux
  4. *
  5. * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
  6. */
  7. /****************************************************************************/
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/init.h>
  11. #include <linux/kernel.h>
  12. #include <linux/fs.h>
  13. #include <linux/major.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/map.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/io.h>
  18. /****************************************************************************/
  19. struct map_info uclinux_ram_map = {
  20. .name = "RAM",
  21. };
  22. struct mtd_info *uclinux_ram_mtdinfo;
  23. /****************************************************************************/
  24. struct mtd_partition uclinux_romfs[] = {
  25. { .name = "ROMfs" }
  26. };
  27. #define NUM_PARTITIONS ARRAY_SIZE(uclinux_romfs)
  28. /****************************************************************************/
  29. int uclinux_point(struct mtd_info *mtd, loff_t from, size_t len,
  30. size_t *retlen, void **virt, resource_size_t *phys)
  31. {
  32. struct map_info *map = mtd->priv;
  33. *virt = map->virt + from;
  34. if (phys)
  35. *phys = map->phys + from;
  36. *retlen = len;
  37. return(0);
  38. }
  39. /****************************************************************************/
  40. int __init uclinux_mtd_init(void)
  41. {
  42. struct mtd_info *mtd;
  43. struct map_info *mapp;
  44. extern char _ebss;
  45. unsigned long addr = (unsigned long) &_ebss;
  46. mapp = &uclinux_ram_map;
  47. mapp->phys = addr;
  48. mapp->size = PAGE_ALIGN(ntohl(*((unsigned long *)(addr + 8))));
  49. mapp->bankwidth = 4;
  50. printk("uclinux[mtd]: RAM probe address=0x%x size=0x%x\n",
  51. (int) mapp->phys, (int) mapp->size);
  52. mapp->virt = ioremap_nocache(mapp->phys, mapp->size);
  53. if (mapp->virt == 0) {
  54. printk("uclinux[mtd]: ioremap_nocache() failed\n");
  55. return(-EIO);
  56. }
  57. simple_map_init(mapp);
  58. mtd = do_map_probe("map_ram", mapp);
  59. if (!mtd) {
  60. printk("uclinux[mtd]: failed to find a mapping?\n");
  61. iounmap(mapp->virt);
  62. return(-ENXIO);
  63. }
  64. mtd->owner = THIS_MODULE;
  65. mtd->point = uclinux_point;
  66. mtd->priv = mapp;
  67. uclinux_ram_mtdinfo = mtd;
  68. add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
  69. return(0);
  70. }
  71. /****************************************************************************/
  72. void __exit uclinux_mtd_cleanup(void)
  73. {
  74. if (uclinux_ram_mtdinfo) {
  75. del_mtd_partitions(uclinux_ram_mtdinfo);
  76. map_destroy(uclinux_ram_mtdinfo);
  77. uclinux_ram_mtdinfo = NULL;
  78. }
  79. if (uclinux_ram_map.virt) {
  80. iounmap((void *) uclinux_ram_map.virt);
  81. uclinux_ram_map.virt = 0;
  82. }
  83. }
  84. /****************************************************************************/
  85. module_init(uclinux_mtd_init);
  86. module_exit(uclinux_mtd_cleanup);
  87. MODULE_LICENSE("GPL");
  88. MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
  89. MODULE_DESCRIPTION("Generic RAM based MTD for uClinux");
  90. /****************************************************************************/