flash_setup.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/export.h>
  12. #include <linux/mtd/mtd.h>
  13. #include <linux/mtd/map.h>
  14. #include <linux/mtd/partitions.h>
  15. #include <asm/octeon/octeon.h>
  16. static struct map_info flash_map;
  17. static struct mtd_info *mymtd;
  18. static int nr_parts;
  19. static struct mtd_partition *parts;
  20. static const char *part_probe_types[] = {
  21. "cmdlinepart",
  22. #ifdef CONFIG_MTD_REDBOOT_PARTS
  23. "RedBoot",
  24. #endif
  25. NULL
  26. };
  27. /**
  28. * Module/ driver initialization.
  29. *
  30. * Returns Zero on success
  31. */
  32. static int __init flash_init(void)
  33. {
  34. /*
  35. * Read the bootbus region 0 setup to determine the base
  36. * address of the flash.
  37. */
  38. union cvmx_mio_boot_reg_cfgx region_cfg;
  39. region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(0));
  40. if (region_cfg.s.en) {
  41. /*
  42. * The bootloader always takes the flash and sets its
  43. * address so the entire flash fits below
  44. * 0x1fc00000. This way the flash aliases to
  45. * 0x1fc00000 for booting. Software can access the
  46. * full flash at the true address, while core boot can
  47. * access 4MB.
  48. */
  49. /* Use this name so old part lines work */
  50. flash_map.name = "phys_mapped_flash";
  51. flash_map.phys = region_cfg.s.base << 16;
  52. flash_map.size = 0x1fc00000 - flash_map.phys;
  53. flash_map.bankwidth = 1;
  54. flash_map.virt = ioremap(flash_map.phys, flash_map.size);
  55. pr_notice("Bootbus flash: Setting flash for %luMB flash at "
  56. "0x%08llx\n", flash_map.size >> 20, flash_map.phys);
  57. simple_map_init(&flash_map);
  58. mymtd = do_map_probe("cfi_probe", &flash_map);
  59. if (mymtd) {
  60. mymtd->owner = THIS_MODULE;
  61. nr_parts = parse_mtd_partitions(mymtd,
  62. part_probe_types,
  63. &parts, 0);
  64. mtd_device_register(mymtd, parts, nr_parts);
  65. } else {
  66. pr_err("Failed to register MTD device for flash\n");
  67. }
  68. }
  69. return 0;
  70. }
  71. late_initcall(flash_init);