flash_setup.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Octeon Bootbus flash setup
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2007, 2008 Cavium Networks
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/module.h>
  12. #include <linux/semaphore.h>
  13. #include <linux/mtd/mtd.h>
  14. #include <linux/mtd/map.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/mtd/partitions.h>
  17. #include <asm/octeon/octeon.h>
  18. static struct map_info flash_map;
  19. static struct mtd_info *mymtd;
  20. static const char *part_probe_types[] = {
  21. "cmdlinepart",
  22. #ifdef CONFIG_MTD_REDBOOT_PARTS
  23. "RedBoot",
  24. #endif
  25. NULL
  26. };
  27. static map_word octeon_flash_map_read(struct map_info *map, unsigned long ofs)
  28. {
  29. map_word r;
  30. down(&octeon_bootbus_sem);
  31. r = inline_map_read(map, ofs);
  32. up(&octeon_bootbus_sem);
  33. return r;
  34. }
  35. static void octeon_flash_map_write(struct map_info *map, const map_word datum,
  36. unsigned long ofs)
  37. {
  38. down(&octeon_bootbus_sem);
  39. inline_map_write(map, datum, ofs);
  40. up(&octeon_bootbus_sem);
  41. }
  42. static void octeon_flash_map_copy_from(struct map_info *map, void *to,
  43. unsigned long from, ssize_t len)
  44. {
  45. down(&octeon_bootbus_sem);
  46. inline_map_copy_from(map, to, from, len);
  47. up(&octeon_bootbus_sem);
  48. }
  49. static void octeon_flash_map_copy_to(struct map_info *map, unsigned long to,
  50. const void *from, ssize_t len)
  51. {
  52. down(&octeon_bootbus_sem);
  53. inline_map_copy_to(map, to, from, len);
  54. up(&octeon_bootbus_sem);
  55. }
  56. /**
  57. * Module/ driver initialization.
  58. *
  59. * Returns Zero on success
  60. */
  61. static int octeon_flash_probe(struct platform_device *pdev)
  62. {
  63. union cvmx_mio_boot_reg_cfgx region_cfg;
  64. u32 cs;
  65. int r;
  66. struct device_node *np = pdev->dev.of_node;
  67. r = of_property_read_u32(np, "reg", &cs);
  68. if (r)
  69. return r;
  70. /*
  71. * Read the bootbus region 0 setup to determine the base
  72. * address of the flash.
  73. */
  74. region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(cs));
  75. if (region_cfg.s.en) {
  76. /*
  77. * The bootloader always takes the flash and sets its
  78. * address so the entire flash fits below
  79. * 0x1fc00000. This way the flash aliases to
  80. * 0x1fc00000 for booting. Software can access the
  81. * full flash at the true address, while core boot can
  82. * access 4MB.
  83. */
  84. /* Use this name so old part lines work */
  85. flash_map.name = "phys_mapped_flash";
  86. flash_map.phys = region_cfg.s.base << 16;
  87. flash_map.size = 0x1fc00000 - flash_map.phys;
  88. /* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */
  89. flash_map.bankwidth = region_cfg.s.width + 1;
  90. flash_map.virt = ioremap(flash_map.phys, flash_map.size);
  91. pr_notice("Bootbus flash: Setting flash for %luMB flash at "
  92. "0x%08llx\n", flash_map.size >> 20, flash_map.phys);
  93. WARN_ON(!map_bankwidth_supported(flash_map.bankwidth));
  94. flash_map.read = octeon_flash_map_read;
  95. flash_map.write = octeon_flash_map_write;
  96. flash_map.copy_from = octeon_flash_map_copy_from;
  97. flash_map.copy_to = octeon_flash_map_copy_to;
  98. mymtd = do_map_probe("cfi_probe", &flash_map);
  99. if (mymtd) {
  100. mymtd->owner = THIS_MODULE;
  101. mtd_device_parse_register(mymtd, part_probe_types,
  102. NULL, NULL, 0);
  103. } else {
  104. pr_err("Failed to register MTD device for flash\n");
  105. }
  106. }
  107. return 0;
  108. }
  109. static const struct of_device_id of_flash_match[] = {
  110. {
  111. .compatible = "cfi-flash",
  112. },
  113. { },
  114. };
  115. MODULE_DEVICE_TABLE(of, of_flash_match);
  116. static struct platform_driver of_flash_driver = {
  117. .driver = {
  118. .name = "octeon-of-flash",
  119. .of_match_table = of_flash_match,
  120. },
  121. .probe = octeon_flash_probe,
  122. };
  123. static int octeon_flash_init(void)
  124. {
  125. return platform_driver_register(&of_flash_driver);
  126. }
  127. late_initcall(octeon_flash_init);
  128. MODULE_LICENSE("GPL");