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