2 * Broadcom BCM63xx flash registration
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
8 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
9 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
10 * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/platform_device.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/mtd/physmap.h>
20 #include <bcm63xx_cpu.h>
21 #include <bcm63xx_dev_flash.h>
22 #include <bcm63xx_regs.h>
23 #include <bcm63xx_io.h>
25 static struct mtd_partition mtd_partitions[] = {
33 static const char *bcm63xx_part_types[] = { "bcm63xxpart", NULL };
35 static struct physmap_flash_data flash_data = {
37 .parts = mtd_partitions,
38 .part_probe_types = bcm63xx_part_types,
41 static struct resource mtd_resources[] = {
43 .start = 0, /* filled at runtime */
44 .end = 0, /* filled at runtime */
45 .flags = IORESOURCE_MEM,
49 static struct platform_device mtd_dev = {
50 .name = "physmap-flash",
51 .resource = mtd_resources,
52 .num_resources = ARRAY_SIZE(mtd_resources),
54 .platform_data = &flash_data,
58 static int __init bcm63xx_detect_flash_type(void)
62 switch (bcm63xx_get_cpu_id()) {
64 val = bcm_misc_readl(MISC_STRAPBUS_6328_REG);
65 if (val & STRAPBUS_6328_BOOT_SEL_SERIAL)
66 return BCM63XX_FLASH_TYPE_SERIAL;
68 return BCM63XX_FLASH_TYPE_NAND;
72 /* no way to auto detect so assume parallel */
73 return BCM63XX_FLASH_TYPE_PARALLEL;
76 val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
77 if (val & STRAPBUS_6358_BOOT_SEL_PARALLEL)
78 return BCM63XX_FLASH_TYPE_PARALLEL;
80 return BCM63XX_FLASH_TYPE_SERIAL;
82 val = bcm_misc_readl(MISC_STRAPBUS_6362_REG);
83 if (val & STRAPBUS_6362_BOOT_SEL_SERIAL)
84 return BCM63XX_FLASH_TYPE_SERIAL;
86 return BCM63XX_FLASH_TYPE_NAND;
88 val = bcm_gpio_readl(GPIO_STRAPBUS_REG);
89 switch (val & STRAPBUS_6368_BOOT_SEL_MASK) {
90 case STRAPBUS_6368_BOOT_SEL_NAND:
91 return BCM63XX_FLASH_TYPE_NAND;
92 case STRAPBUS_6368_BOOT_SEL_SERIAL:
93 return BCM63XX_FLASH_TYPE_SERIAL;
94 case STRAPBUS_6368_BOOT_SEL_PARALLEL:
95 return BCM63XX_FLASH_TYPE_PARALLEL;
102 int __init bcm63xx_flash_register(void)
107 flash_type = bcm63xx_detect_flash_type();
109 switch (flash_type) {
110 case BCM63XX_FLASH_TYPE_PARALLEL:
111 /* read base address of boot chip select (0) */
112 val = bcm_mpi_readl(MPI_CSBASE_REG(0));
113 val &= MPI_CSBASE_BASE_MASK;
115 mtd_resources[0].start = val;
116 mtd_resources[0].end = 0x1FFFFFFF;
118 return platform_device_register(&mtd_dev);
119 case BCM63XX_FLASH_TYPE_SERIAL:
120 pr_warn("unsupported serial flash detected\n");
122 case BCM63XX_FLASH_TYPE_NAND:
123 pr_warn("unsupported NAND flash detected\n");
126 pr_err("flash detection failed for BCM%x: %d\n",
127 bcm63xx_get_cpu_id(), flash_type);