drivers/firmware/broadcom/bcm47xx_sprom.c

Source file repositories/reference/linux-study-clean/drivers/firmware/broadcom/bcm47xx_sprom.c

File Facts

System
Linux kernel
Corpus path
drivers/firmware/broadcom/bcm47xx_sprom.c
Extension
.c
Size
28072 bytes
Lines
728
Domain
Driver Families
Bucket
drivers/firmware
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (bcm47xx_is_valid_mac(mac)) {
			int err = bcm47xx_increase_mac_addr(mac, mac_addr_used);

			if (!err) {
				ether_addr_copy(sprom->il0mac, mac);
				mac_addr_used++;
			}
		}
	}
}

static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix,
				    bool fallback)
{
	nvram_read_u32_2(prefix, "boardflags", &sprom->boardflags_lo,
			 &sprom->boardflags_hi, fallback);
	nvram_read_u32_2(prefix, "boardflags2", &sprom->boardflags2_lo,
			 &sprom->boardflags2_hi, fallback);
}

void bcm47xx_fill_sprom(struct ssb_sprom *sprom, const char *prefix,
			bool fallback)
{
	bcm47xx_fill_sprom_ethernet(sprom, prefix, fallback);
	bcm47xx_fill_board_data(sprom, prefix, fallback);

	nvram_read_u8(prefix, NULL, "sromrev", &sprom->revision, 0, fallback);

	/* Entries requiring custom functions */
	nvram_read_alpha2(prefix, "ccode", sprom->alpha2, fallback);
	if (sprom->revision >= 3)
		nvram_read_leddc(prefix, "leddc", &sprom->leddc_on_time,
				 &sprom->leddc_off_time, fallback);

	switch (sprom->revision) {
	case 4:
	case 5:
		bcm47xx_fill_sprom_path_r4589(sprom, prefix, fallback);
		bcm47xx_fill_sprom_path_r45(sprom, prefix, fallback);
		break;
	case 8:
	case 9:
		bcm47xx_fill_sprom_path_r4589(sprom, prefix, fallback);
		break;
	}

	bcm47xx_sprom_fill_auto(sprom, prefix, fallback);
}

#if IS_BUILTIN(CONFIG_SSB) && IS_ENABLED(CONFIG_SSB_SPROM)
static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
{
	char prefix[10];

	switch (bus->bustype) {
	case SSB_BUSTYPE_SSB:
		bcm47xx_fill_sprom(out, NULL, false);
		return 0;
	case SSB_BUSTYPE_PCI:
		memset(out, 0, sizeof(struct ssb_sprom));
		snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
			 bus->host_pci->bus->number + 1,
			 PCI_SLOT(bus->host_pci->devfn));
		bcm47xx_fill_sprom(out, prefix, false);
		return 0;
	default:
		pr_warn("Unable to fill SPROM for given bustype.\n");
		return -EINVAL;
	}
}
#endif

#if IS_BUILTIN(CONFIG_BCMA)
/*
 * Having many NVRAM entries for PCI devices led to repeating prefixes like
 * pci/1/1/ all the time and wasting flash space. So at some point Broadcom
 * decided to introduce prefixes like 0: 1: 2: etc.
 * If we find e.g. devpath0=pci/2/1 or devpath0=pci/2/1/ we should use 0:
 * instead of pci/2/1/.
 */
static void bcm47xx_sprom_apply_prefix_alias(char *prefix, size_t prefix_size)
{
	size_t prefix_len = strlen(prefix);
	size_t short_len = prefix_len - 1;
	char nvram_var[10];
	char buf[20];
	int i;

	/* Passed prefix has to end with a slash */
	if (prefix_len <= 0 || prefix[prefix_len - 1] != '/')

Annotation

Implementation Notes