Ejemplo n.º 1
0
/**
 * overlay_phandle_add_offset - Increases a phandle by an offset
 * @fdt: Base device tree blob
 * @node: Device tree overlay blob
 * @name: Name of the property to modify (phandle or linux,phandle)
 * @delta: offset to apply
 *
 * overlay_phandle_add_offset() increments a node phandle by a given
 * offset.
 *
 * returns:
 *      0 on success.
 *      Negative error code on error
 */
static int overlay_phandle_add_offset(void *fdt, int node,
				      const char *name, uint32_t delta)
{
	const fdt32_t *val;
	uint32_t adj_val;
	int len;

	val = fdt_getprop(fdt, node, name, &len);
	if (!val)
		return len;

	if (len != sizeof(*val))
		return -FDT_ERR_BADPHANDLE;

	adj_val = fdt32_to_cpu(*val);
	if ((adj_val + delta) < adj_val)
		return -FDT_ERR_NOPHANDLES;

	adj_val += delta;
	if (adj_val == (uint32_t)-1)
		return -FDT_ERR_NOPHANDLES;

	return fdt_setprop_inplace_u32(fdt, node, name, adj_val);
}
Ejemplo n.º 2
0
/**
 * Modify the device tree to remove all unused interface types.
 */
int board_fixup_fdt(void)
{
	const char *fdt_key;
	int val;
	int rc;

	val = pca953x_get_val(0, 0x20);
	if (val & 4)
		fdt_key = "2,sata";
	else
		fdt_key = "2,pcie";
	octeon_fdt_patch(working_fdt, fdt_key, NULL);


	if (val & 1)
		fdt_key = "0,xaui";
	else
		fdt_key = "0,qsgmii";

	debug("%s: Patching DLM 0 for %s\n", __func__, fdt_key);
	octeon_fdt_patch(working_fdt, fdt_key, NULL);

	if (val & 8) {
		debug("PCM mode detected, disabling SPI NOR\n");
		octeon_fdt_patch(working_fdt, "0,pcm", "cavium,pcm-trim");
	} else {
		debug("SPI NOR mode selected\n");
		octeon_fdt_patch(working_fdt, "0,not-pcm", "cavium,pcm-trim");
	}

	/* Check if we need to swap the MMC slots or not. */
	if (val & 0x10) {
		int s0_offset, s1_offset, offset;

		debug("%s: Swapping mmc slots 0 and 1\n", __func__);
		/* Swap slot 0 and slot 1 in device tree */
		offset = fdt_path_offset(gd->fdt_blob, "/soc/mmc");
		if (offset < 0) {
			puts("Error accessing /soc/mmc in device tree\n");
			return -1;
		}
		s0_offset = fdt_subnode_offset(gd->fdt_blob, offset,
					       "mmc-slot@0");
		s1_offset = fdt_subnode_offset(gd->fdt_blob, offset,
					       "mmc-slot@1");
		debug("  slot 0 offset: %d, slot 1 offset: %d\n",
		      s0_offset, s1_offset);
		if (s0_offset < 0 || s1_offset < 0) {
			puts("Error accessing MMC in device tree\n");
			return -1;
		}
		rc = fdt_setprop_inplace_u32(gd->fdt_blob, s0_offset, "reg", 1);
		rc |= fdt_setprop_inplace_u32(gd->fdt_blob, s1_offset, "reg", 0);
		if (rc) {
			puts("Error changing reg property in mmc slot\n");
			return -1;
		}

		rc = fdt_set_name(gd->fdt_blob, s0_offset, "mmc-slot@1");
		rc |= fdt_set_name(gd->fdt_blob, s1_offset, "mmc-slot@0");
		if (rc) {
			puts("Error renaming MMC slot names\n");
			return -1;
		}
	}


	return 0;
}