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> |
Paul Gortmaker | cae39d1 | 2011-07-28 18:46:31 -0400 | [diff] [blame] | 11 | #include <linux/export.h> |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 12 | #include <linux/mtd/mtd.h> |
| 13 | #include <linux/mtd/map.h> |
| 14 | #include <linux/mtd/partitions.h> |
| 15 | |
| 16 | #include <asm/octeon/octeon.h> |
| 17 | |
| 18 | static struct map_info flash_map; |
| 19 | static struct mtd_info *mymtd; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 20 | static const char *part_probe_types[] = { |
| 21 | "cmdlinepart", |
| 22 | #ifdef CONFIG_MTD_REDBOOT_PARTS |
| 23 | "RedBoot", |
| 24 | #endif |
| 25 | NULL |
| 26 | }; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Module/ driver initialization. |
| 30 | * |
| 31 | * Returns Zero on success |
| 32 | */ |
| 33 | static int __init flash_init(void) |
| 34 | { |
| 35 | /* |
| 36 | * Read the bootbus region 0 setup to determine the base |
| 37 | * address of the flash. |
| 38 | */ |
| 39 | union cvmx_mio_boot_reg_cfgx region_cfg; |
| 40 | region_cfg.u64 = cvmx_read_csr(CVMX_MIO_BOOT_REG_CFGX(0)); |
| 41 | if (region_cfg.s.en) { |
| 42 | /* |
| 43 | * The bootloader always takes the flash and sets its |
| 44 | * address so the entire flash fits below |
| 45 | * 0x1fc00000. This way the flash aliases to |
| 46 | * 0x1fc00000 for booting. Software can access the |
| 47 | * full flash at the true address, while core boot can |
| 48 | * access 4MB. |
| 49 | */ |
| 50 | /* Use this name so old part lines work */ |
| 51 | flash_map.name = "phys_mapped_flash"; |
| 52 | flash_map.phys = region_cfg.s.base << 16; |
| 53 | flash_map.size = 0x1fc00000 - flash_map.phys; |
Charles Hardin | 0f73171 | 2012-09-05 19:19:48 +0000 | [diff] [blame] | 54 | /* 8-bit bus (0 + 1) or 16-bit bus (1 + 1) */ |
| 55 | flash_map.bankwidth = region_cfg.s.width + 1; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 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; |
David Daney | b2f9094 | 2011-11-10 17:59:45 +0000 | [diff] [blame] | 63 | mtd_device_parse_register(mymtd, part_probe_types, |
Artem Bityutskiy | 42d7fbe | 2012-03-09 19:24:26 +0200 | [diff] [blame] | 64 | NULL, NULL, 0); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 65 | } else { |
| 66 | pr_err("Failed to register MTD device for flash\n"); |
| 67 | } |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | late_initcall(flash_init); |