omap-toto-flash.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * NOR Flash memory access on TI Toto board
  3. *
  4. * jzhang@ti.com (C) 2003 Texas Instruments.
  5. *
  6. * (C) 2002 MontVista Software, Inc.
  7. */
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <linux/kernel.h>
  11. #include <linux/errno.h>
  12. #include <linux/init.h>
  13. #include <linux/slab.h>
  14. #include <linux/mtd/mtd.h>
  15. #include <linux/mtd/map.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/hardware.h>
  18. #include <asm/io.h>
  19. #ifndef CONFIG_ARCH_OMAP
  20. #error This is for OMAP architecture only
  21. #endif
  22. //these lines need be moved to a hardware header file
  23. #define OMAP_TOTO_FLASH_BASE 0xd8000000
  24. #define OMAP_TOTO_FLASH_SIZE 0x80000
  25. static struct map_info omap_toto_map_flash = {
  26. .name = "OMAP Toto flash",
  27. .bankwidth = 2,
  28. .virt = (void __iomem *)OMAP_TOTO_FLASH_BASE,
  29. };
  30. static struct mtd_partition toto_flash_partitions[] = {
  31. {
  32. .name = "BootLoader",
  33. .size = 0x00040000, /* hopefully u-boot will stay 128k + 128*/
  34. .offset = 0,
  35. .mask_flags = MTD_WRITEABLE, /* force read-only */
  36. }, {
  37. .name = "ReservedSpace",
  38. .size = 0x00030000,
  39. .offset = MTDPART_OFS_APPEND,
  40. //mask_flags: MTD_WRITEABLE, /* force read-only */
  41. }, {
  42. .name = "EnvArea", /* bottom 64KiB for env vars */
  43. .size = MTDPART_SIZ_FULL,
  44. .offset = MTDPART_OFS_APPEND,
  45. }
  46. };
  47. static struct mtd_partition *parsed_parts;
  48. static struct mtd_info *flash_mtd;
  49. static int __init init_flash (void)
  50. {
  51. struct mtd_partition *parts;
  52. int nb_parts = 0;
  53. int parsed_nr_parts = 0;
  54. const char *part_type;
  55. /*
  56. * Static partition definition selection
  57. */
  58. part_type = "static";
  59. parts = toto_flash_partitions;
  60. nb_parts = ARRAY_SIZE(toto_flash_partitions);
  61. omap_toto_map_flash.size = OMAP_TOTO_FLASH_SIZE;
  62. omap_toto_map_flash.phys = virt_to_phys(OMAP_TOTO_FLASH_BASE);
  63. simple_map_init(&omap_toto_map_flash);
  64. /*
  65. * Now let's probe for the actual flash. Do it here since
  66. * specific machine settings might have been set above.
  67. */
  68. printk(KERN_NOTICE "OMAP toto flash: probing %d-bit flash bus\n",
  69. omap_toto_map_flash.bankwidth*8);
  70. flash_mtd = do_map_probe("jedec_probe", &omap_toto_map_flash);
  71. if (!flash_mtd)
  72. return -ENXIO;
  73. if (parsed_nr_parts > 0) {
  74. parts = parsed_parts;
  75. nb_parts = parsed_nr_parts;
  76. }
  77. if (nb_parts == 0) {
  78. printk(KERN_NOTICE "OMAP toto flash: no partition info available,"
  79. "registering whole flash at once\n");
  80. if (add_mtd_device(flash_mtd)){
  81. return -ENXIO;
  82. }
  83. } else {
  84. printk(KERN_NOTICE "Using %s partition definition\n",
  85. part_type);
  86. return add_mtd_partitions(flash_mtd, parts, nb_parts);
  87. }
  88. return 0;
  89. }
  90. int __init omap_toto_mtd_init(void)
  91. {
  92. int status;
  93. if (status = init_flash()) {
  94. printk(KERN_ERR "OMAP Toto Flash: unable to init map for toto flash\n");
  95. }
  96. return status;
  97. }
  98. static void __exit omap_toto_mtd_cleanup(void)
  99. {
  100. if (flash_mtd) {
  101. del_mtd_partitions(flash_mtd);
  102. map_destroy(flash_mtd);
  103. kfree(parsed_parts);
  104. }
  105. }
  106. module_init(omap_toto_mtd_init);
  107. module_exit(omap_toto_mtd_cleanup);
  108. MODULE_AUTHOR("Jian Zhang");
  109. MODULE_DESCRIPTION("OMAP Toto board map driver");
  110. MODULE_LICENSE("GPL");