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