flash_setup.c 2.0 KB

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