omap-toto-flash.c 3.1 KB

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