Skip to contentSkip to conversation

bcma: get & store info about flash type SoC booted from

PATCH Superseded Rafał Miłecki 1 participant 4 messages Aug 27, 2014 – Sep 3, 2014 Broadcom specific amba driver (bcma)

lore
Share & tools
lore

Rafał Miłecki

author maintainer
#0 lore raw

PATCH 1/1 bcma: get & store info about flash type SoC booted from

We need this info to know where to look for NVRAM.

---
 drivers/bcma/main.c            | 43 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/bcma/bcma.h      |  9 +++++++++
 include/linux/bcma/bcma_regs.h |  5 +++++
 3 files changed, 57 insertions(+)
drivers/bcma/main.c +43 -0
index 0ff8d58..0f48604 100644
@@ -110,6 +110,45 @@ bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
 	return false;
 }
 
+static enum bcma_boot_dev bcma_boot_dev(struct bcma_bus *bus)
+{
+	struct bcma_drv_cc *cc = &bus->drv_cc;
+	u8 cc_rev = cc->core->id.rev;
+
+	if (cc_rev == 42) {
+		struct bcma_device *core;
+
+		core = bcma_find_core(bus, BCMA_CORE_NS_ROM);
+		if (core) {
+			switch (bcma_aread32(core, BCMA_IOST) &
+				BCMA_NS_ROM_IOST_BOOT_DEV_MASK) {
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NOR:
+				return BCMA_BOOT_DEV_SERIAL;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NAND:
+				return BCMA_BOOT_DEV_NAND;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_ROM:
+			default:
+				return BCMA_BOOT_DEV_ROM;
+			}
+		}
+	} else {
+		if (cc_rev == 38) {
+			if (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)
+				return BCMA_BOOT_DEV_NAND;
+			else if (cc->status & BIT(5))
+				return BCMA_BOOT_DEV_ROM;
+		}
+
+		if ((cc->capabilities & BCMA_CC_CAP_FLASHT) ==
+		    BCMA_CC_FLASHT_PARA)
+			return BCMA_BOOT_DEV_PARALLEL;
+		else
+			return BCMA_BOOT_DEV_SERIAL;
+	}
+
+	return BCMA_BOOT_DEV_SERIAL;
+}
+
 static void bcma_release_core_dev(struct device *dev)
 {
 	struct bcma_device *core = container_of(dev, struct bcma_device, dev);
@@ -247,6 +286,10 @@ int bcma_bus_register(struct bcma_bus *bus)
 		bcma_core_chipcommon_early_init(&bus->drv_cc);
 	}
 
+	/* Determine flash type this SoC boots from */
+	if (bus->hosttype == BCMA_HOSTTYPE_SOC)
+		bus->boot_dev = bcma_boot_dev(bus);
+
 	/* Try to get SPROM */
 	err = bcma_sprom_get(bus);
 	if (err == -ENOENT) {
include/linux/bcma/bcma.h +9 -0
index 0272e49..d871568 100644
@@ -22,6 +22,14 @@ enum bcma_hosttype {
 	BCMA_HOSTTYPE_SOC,
 };
 
+enum bcma_boot_dev {
+	BCMA_BOOT_DEV_UNK = 0,
+	BCMA_BOOT_DEV_ROM,
+	BCMA_BOOT_DEV_PARALLEL,
+	BCMA_BOOT_DEV_SERIAL,
+	BCMA_BOOT_DEV_NAND,
+};
+
 struct bcma_chipinfo {
 	u16 id;
 	u8 rev;
@@ -335,6 +343,7 @@ struct bcma_bus {
 	u8 init_done:1;
 	u8 num;
 
+	enum bcma_boot_dev boot_dev;
 	struct bcma_drv_cc drv_cc;
 	struct bcma_drv_pci drv_pci[2];
 	struct bcma_drv_pcie2 drv_pcie2;
include/linux/bcma/bcma_regs.h +5 -0
index 917dcd7..e64ae7b 100644
@@ -39,6 +39,11 @@
 #define  BCMA_RESET_CTL_RESET		0x0001
 #define BCMA_RESET_ST			0x0804
 
+#define BCMA_NS_ROM_IOST_BOOT_DEV_MASK	0x0003
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NOR	0x0000
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NAND	0x0001
+#define BCMA_NS_ROM_IOST_BOOT_DEV_ROM	0x0002
+
 /* BCMA PCI config space registers. */
 #define BCMA_PCI_PMCSR			0x44
 #define  BCMA_PCI_PE			0x100
Signature · 1 line
1.8.4.5
author maintainer
#1 lore raw
Quoted 1 line · Rafał Miłecki

We need this info to know where to look for NVRAM.

John: can you DROP it for now, please?
We have some big bcm47xx vs. bcm53xx vs. nvram discussion going on ;)

author maintainer
#2 lore raw

PATCH v2 1/1 bcma: get info about flash type SoC booted from

In reply to Rafał Miłecki

There is an ongoing work on cleaning MIPS's nvram support so it could be re-used on other platforms (bcm53xx to say precisely).
This will require a bit of extra logic in bcma this patch implements.

---
After some extra discussion it seems my initial idea was correct. It is not possible on bcm47xx to use anything like a platform device/driver to handle NVRAM.

V2: We don't use info about boot_dev anywhere else, so don't store it.
Move the code to the bcma_bus_early_register as we need NVRAM early.

---
 drivers/bcma/main.c            | 64 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/bcma/bcma_regs.h |  5 ++++
 2 files changed, 69 insertions(+)
drivers/bcma/main.c +64 -0
index 9f6b0cb..70cec2b 100644
@@ -14,6 +14,14 @@
 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
 MODULE_LICENSE("GPL");
 
+enum bcma_boot_dev {
+	BCMA_BOOT_DEV_UNK = 0,
+	BCMA_BOOT_DEV_ROM,
+	BCMA_BOOT_DEV_PARALLEL,
+	BCMA_BOOT_DEV_SERIAL,
+	BCMA_BOOT_DEV_NAND,
+};
+
 /* contains the number the next bus should get. */
 static unsigned int bcma_bus_next_num = 0;
 
@@ -110,6 +118,45 @@ bool bcma_wait_value(struct bcma_device *core, u16 reg, u32 mask, u32 value,
 	return false;
 }
 
+static enum bcma_boot_dev bcma_boot_dev(struct bcma_bus *bus)
+{
+	struct bcma_drv_cc *cc = &bus->drv_cc;
+	u8 cc_rev = cc->core->id.rev;
+
+	if (cc_rev == 42) {
+		struct bcma_device *core;
+
+		core = bcma_find_core(bus, BCMA_CORE_NS_ROM);
+		if (core) {
+			switch (bcma_aread32(core, BCMA_IOST) &
+				BCMA_NS_ROM_IOST_BOOT_DEV_MASK) {
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NOR:
+				return BCMA_BOOT_DEV_SERIAL;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NAND:
+				return BCMA_BOOT_DEV_NAND;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_ROM:
+			default:
+				return BCMA_BOOT_DEV_ROM;
+			}
+		}
+	} else {
+		if (cc_rev == 38) {
+			if (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)
+				return BCMA_BOOT_DEV_NAND;
+			else if (cc->status & BIT(5))
+				return BCMA_BOOT_DEV_ROM;
+		}
+
+		if ((cc->capabilities & BCMA_CC_CAP_FLASHT) ==
+		    BCMA_CC_FLASHT_PARA)
+			return BCMA_BOOT_DEV_PARALLEL;
+		else
+			return BCMA_BOOT_DEV_SERIAL;
+	}
+
+	return BCMA_BOOT_DEV_SERIAL;
+}
+
 static void bcma_release_core_dev(struct device *dev)
 {
 	struct bcma_device *core = container_of(dev, struct bcma_device, dev);
@@ -372,6 +419,23 @@ int __init bcma_bus_early_register(struct bcma_bus *bus,
 		bcma_core_mips_early_init(&bus->drv_mips);
 	}
 
+	/* Determine flash type this SoC boots from */
+	if (bus->hosttype == BCMA_HOSTTYPE_SOC) {
+		enum bcma_boot_dev boot_dev = bcma_boot_dev(bus);
+
+		switch (boot_dev) {
+		case BCMA_BOOT_DEV_PARALLEL:
+		case BCMA_BOOT_DEV_SERIAL:
+			/* TODO: Init NVRAM using BCMA_SOC_FLASH2 window */
+			break;
+		case BCMA_BOOT_DEV_NAND:
+			/* TODO: Init NVRAM using BCMA_SOC_FLASH1 window */
+			break;
+		default:
+			break;
+		}
+	}
+
 	bcma_info(bus, "Early bus registered\n");
 
 	return 0;
include/linux/bcma/bcma_regs.h +5 -0
index 917dcd7..e64ae7b 100644
@@ -39,6 +39,11 @@
 #define  BCMA_RESET_CTL_RESET		0x0001
 #define BCMA_RESET_ST			0x0804
 
+#define BCMA_NS_ROM_IOST_BOOT_DEV_MASK	0x0003
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NOR	0x0000
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NAND	0x0001
+#define BCMA_NS_ROM_IOST_BOOT_DEV_ROM	0x0002
+
 /* BCMA PCI config space registers. */
 #define BCMA_PCI_PMCSR			0x44
 #define  BCMA_PCI_PE			0x100
Signature · 1 line
1.8.4.5
author maintainer
#3 lore raw

PATCH v3 1/1 bcma: get info about flash type SoC booted from

There is an ongoing work on cleaning MIPS's nvram support so it could be re-used on other platforms (bcm53xx to say precisely).
This will require a bit of extra logic in bcma this patch implements.

---
After some extra discussion it seems my initial idea was correct. It is not possible on bcm47xx to use anything like a platform device/driver to handle NVRAM.

V2: We don't use info about boot_dev anywhere else, so don't store it.
Move the code to the bcma_bus_early_register as we need NVRAM early.
V3: Move this code to the driver_mips.c, it won't be needed on other
hosts / archs.

---
 drivers/bcma/driver_mips.c     | 62 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/bcma/bcma_regs.h |  5 ++++
 2 files changed, 67 insertions(+)
drivers/bcma/driver_mips.c +62 -0
index 11115bb..004d6aa 100644
@@ -21,6 +21,14 @@
 #include <linux/serial_reg.h>
 #include <linux/time.h>
 
+enum bcma_boot_dev {
+	BCMA_BOOT_DEV_UNK = 0,
+	BCMA_BOOT_DEV_ROM,
+	BCMA_BOOT_DEV_PARALLEL,
+	BCMA_BOOT_DEV_SERIAL,
+	BCMA_BOOT_DEV_NAND,
+};
+
 static const char * const part_probes[] = { "bcm47xxpart", NULL };
 
 static struct physmap_flash_data bcma_pflash_data = {
@@ -229,11 +237,51 @@ u32 bcma_cpu_clock(struct bcma_drv_mips *mcore)
 }
 EXPORT_SYMBOL(bcma_cpu_clock);
 
+static enum bcma_boot_dev bcma_boot_dev(struct bcma_bus *bus)
+{
+	struct bcma_drv_cc *cc = &bus->drv_cc;
+	u8 cc_rev = cc->core->id.rev;
+
+	if (cc_rev == 42) {
+		struct bcma_device *core;
+
+		core = bcma_find_core(bus, BCMA_CORE_NS_ROM);
+		if (core) {
+			switch (bcma_aread32(core, BCMA_IOST) &
+				BCMA_NS_ROM_IOST_BOOT_DEV_MASK) {
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NOR:
+				return BCMA_BOOT_DEV_SERIAL;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_NAND:
+				return BCMA_BOOT_DEV_NAND;
+			case BCMA_NS_ROM_IOST_BOOT_DEV_ROM:
+			default:
+				return BCMA_BOOT_DEV_ROM;
+			}
+		}
+	} else {
+		if (cc_rev == 38) {
+			if (cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)
+				return BCMA_BOOT_DEV_NAND;
+			else if (cc->status & BIT(5))
+				return BCMA_BOOT_DEV_ROM;
+		}
+
+		if ((cc->capabilities & BCMA_CC_CAP_FLASHT) ==
+		    BCMA_CC_FLASHT_PARA)
+			return BCMA_BOOT_DEV_PARALLEL;
+		else
+			return BCMA_BOOT_DEV_SERIAL;
+	}
+
+	return BCMA_BOOT_DEV_SERIAL;
+}
+
 static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
 {
 	struct bcma_bus *bus = mcore->core->bus;
 	struct bcma_drv_cc *cc = &bus->drv_cc;
 	struct bcma_pflash *pflash = &cc->pflash;
+	enum bcma_boot_dev boot_dev;
 
 	switch (cc->capabilities & BCMA_CC_CAP_FLASHT) {
 	case BCMA_CC_FLASHT_STSER:
@@ -269,6 +317,20 @@ static void bcma_core_mips_flash_detect(struct bcma_drv_mips *mcore)
 			bcma_nflash_init(cc);
 		}
 	}
+
+	/* Determine flash type this SoC boots from */
+	boot_dev = bcma_boot_dev(bus);
+	switch (boot_dev) {
+	case BCMA_BOOT_DEV_PARALLEL:
+	case BCMA_BOOT_DEV_SERIAL:
+		/* TODO: Init NVRAM using BCMA_SOC_FLASH2 window */
+		break;
+	case BCMA_BOOT_DEV_NAND:
+		/* TODO: Init NVRAM using BCMA_SOC_FLASH1 window */
+		break;
+	default:
+		break;
+	}
 }
 
 void bcma_core_mips_early_init(struct bcma_drv_mips *mcore)
include/linux/bcma/bcma_regs.h +5 -0
index 917dcd7..e64ae7b 100644
@@ -39,6 +39,11 @@
 #define  BCMA_RESET_CTL_RESET		0x0001
 #define BCMA_RESET_ST			0x0804
 
+#define BCMA_NS_ROM_IOST_BOOT_DEV_MASK	0x0003
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NOR	0x0000
+#define BCMA_NS_ROM_IOST_BOOT_DEV_NAND	0x0001
+#define BCMA_NS_ROM_IOST_BOOT_DEV_ROM	0x0002
+
 /* BCMA PCI config space registers. */
 #define BCMA_PCI_PMCSR			0x44
 #define  BCMA_PCI_PE			0x100
Signature · 1 line
1.8.4.5