flash_setup.c 1.9 KB

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