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