Beispiel #1
0
/**
 * Decode TPM configuration.
 *
 * @param dev	Returns a configuration of TPM device
 * @return 0 if ok, -1 on error
 */
static int tpm_decode_config(struct tpm *dev)
{
#ifdef CONFIG_OF_CONTROL
	const void *blob = gd->fdt_blob;
	int node, parent;
	int i2c_bus;

	node = fdtdec_next_compatible(blob, 0, COMPAT_INFINEON_SLB9635_TPM);
	if (node < 0) {
		node = fdtdec_next_compatible(blob, 0,
					      COMPAT_INFINEON_SLB9645_TPM);
	}
	if (node < 0) {
		debug("%s: Node not found\n", __func__);
		return -1;
	}
	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -1;
	}
	i2c_bus = i2c_get_bus_num_fdt(blob, parent);
	if (i2c_bus < 0)
		return -1;
	dev->i2c_bus = i2c_bus;
	dev->slave_addr = fdtdec_get_addr(blob, node, "reg");
#else
	dev->i2c_bus = CONFIG_INFINEON_TPM_I2C_BUS;
	dev->slave_addr = CONFIG_INFINEON_TPM_I2C_ADDR;
#endif
	return 0;
}
Beispiel #2
0
static int tps65090_decode_config(struct tps65090_config *config)
{
#ifdef CONFIG_OF_CONTROL
	const void *blob = gd->fdt_blob;
	int node, parent;
	int i2c_bus;

	node = fdtdec_next_compatible(blob, 0, COMPAT_TI_TPS65090);
	if (node < 0) {
		debug("%s: Node not found\n", __func__);
		return -1;
	}
	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -1;
	}
	i2c_bus = i2c_get_bus_num_fdt(blob, parent);
	if (i2c_bus < 0)
		return -1;
	config->bus = i2c_bus;
	config->addr = fdtdec_get_addr(blob, node, "reg");
#else
	config->bus = CONFIG_TPS65090_I2C_BUS;
	config->addr = TPS65090_I2C_ADDR;
#endif
	return 0;
}
Beispiel #3
0
static int rk808_parse_dt(const void* blob)
{
	int node, parent, nd;
	u32 i2c_bus_addr, bus;
	int ret;
	fdt_addr_t addr;
	struct fdt_gpio_state gpios[2];
	node = fdt_node_offset_by_compatible(blob,
					0, COMPAT_ROCKCHIP_RK808);
	if (node < 0) {
		printf("can't find dts node for rk808\n");
		return -ENODEV;
	}

	if (!fdt_device_is_available(blob,node)) {
		debug("device rk808 is disabled\n");
		return -1;
	}
	
	addr = fdtdec_get_addr(blob, node, "reg");
	fdtdec_decode_gpios(blob, node, "gpios", gpios, 2);
	
	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -1;
	}
	i2c_bus_addr = fdtdec_get_addr(blob, parent, "reg");
	bus = i2c_get_bus_num_fdt(i2c_bus_addr);
	ret = rk808_i2c_probe(bus, addr);
	if (ret < 0) {
		debug("pmic rk808 i2c probe failed\n");
		return ret;
	}
	
	nd = fdt_get_regulator_node(blob, node);
	if (nd < 0)
		printf("%s: Cannot find regulators\n", __func__);
	else
		fdt_regulator_match(blob, nd, rk808_reg_matches,
					RK808_NUM_REGULATORS);
	rk808.pmic = pmic_alloc();
	rk808.node = node;
	rk808.pmic->hw.i2c.addr = addr;
	rk808.pmic->bus = bus;
	rk808.pwr_hold.gpio = rk_gpio_base_to_bank(gpios[1].gpio & RK_GPIO_BANK_MASK) | 
				(gpios[1].gpio & RK_GPIO_PIN_MASK);
	rk808.pwr_hold.flags = !(gpios[1].flags  & OF_GPIO_ACTIVE_LOW);
	debug("rk808 i2c_bus:%d addr:0x%02x\n", rk808.pmic->bus,
		rk808.pmic->hw.i2c.addr);
	return 0;
	 
}
int pmic_init(unsigned char bus)
{
	static const char name[] = "MAX77686_PMIC";
	
    //struct pmic *p = pmic_alloc();
#ifdef CONFIG_OF_CONTROL
	const void *blob = gd->fdt_blob;
	int node, parent, tmp;
#endif

	//if (!p) {
    //	printf("%s: POWER allocation error!\n", __func__);
	//	return -ENOMEM;
	//}

#ifdef CONFIG_OF_CONTROL
	node = fdtdec_next_compatible(blob, 0, COMPAT_MAXIM_MAX77686_PMIC);
	if (node < 0) {
		debug("PMIC: No node for PMIC Chip in device tree\n");
		debug("node = %d\n", node);
		return -1;
	}

	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -1;
	}

	/* tmp since p->bus is unsigned */
	tmp = i2c_get_bus_num_fdt(parent);
	if (tmp < 0) {
		debug("%s: Cannot find I2C bus\n", __func__);
		return -1;
	}
	//p->bus = tmp;
	//p->hw.i2c.addr = fdtdec_get_int(blob, node, "reg", 9);
	 fdtdec_get_int(blob, node, "reg", 9);
#else
	p->bus = bus;
	p->hw.i2c.addr = MAX77686_I2C_ADDR;
#endif

	//p->name = name;
	//p->interface = PMIC_I2C;
	//p->number_of_regs = PMIC_NUM_OF_REGS;
	//p->hw.i2c.tx_num = 1;

	puts("Board PMIC init\n");

	return 0;
}
int ricoh619_parse_dt(const void* blob)
{
	int node, parent, nd;
	u32 i2c_bus_addr, bus;
	int ret;
	fdt_addr_t addr;
	node = fdt_node_offset_by_compatible(blob, 0,
					COMPAT_RICOH_RICOH619);
	if (node < 0) {
		printf("can't find dts node for ricoh619\n");
		return -ENODEV;
	}

	if (!fdt_device_is_available(blob,node)) {
		debug("device ricoh619 is disabled\n");
		return -1;
	}
	
	addr = fdtdec_get_addr(blob, node, "reg");
	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -1;
	}
	i2c_bus_addr = fdtdec_get_addr(blob, parent, "reg");
	bus = i2c_get_bus_num_fdt(i2c_bus_addr);
	ret = ricoh619_i2c_probe(bus, addr);
	if (ret < 0) {
		debug("pmic ricoh619 i2c probe failed\n");
		return ret;
	}
	nd = fdt_get_regulator_node(blob, node);
	if (nd < 0)
		printf("%s: Cannot find regulators\n", __func__);
	else
		fdt_regulator_match(blob, nd, ricoh619_regulator_matches,
					RICOH619_NUM_REGULATORS);
	ricoh619.pmic = pmic_alloc();
	ricoh619.node = node;
	ricoh619.pmic->hw.i2c.addr = addr;
	ricoh619.pmic->bus = bus;
	debug("ricoh619 i2c_bus:%d addr:0x%02x\n", ricoh619.pmic->bus,
		ricoh619.pmic->hw.i2c.addr);
	return 0;
	 
}
Beispiel #6
0
int tps65090_init(void)
{
	struct pmic *p;
	int bus;
	int addr;
	const void *blob = gd->fdt_blob;
	int node, parent;

	node = fdtdec_next_compatible(blob, 0, COMPAT_TI_TPS65090);
	if (node < 0) {
		debug("PMIC: No node for PMIC Chip in device tree\n");
		debug("node = %d\n", node);
		return -ENODEV;
	}

	parent = fdt_parent_offset(blob, node);
	if (parent < 0) {
		debug("%s: Cannot find node parent\n", __func__);
		return -EINVAL;
	}

	bus = i2c_get_bus_num_fdt(parent);
	if (p->bus < 0) {
		debug("%s: Cannot find I2C bus\n", __func__);
		return -ENOENT;
	}
	addr = fdtdec_get_int(blob, node, "reg", TPS65090_I2C_ADDR);
	p = pmic_alloc();
	if (!p) {
		printf("%s: POWER allocation error!\n", __func__);
		return -ENOMEM;
	}

	p->name = TPS65090_NAME;
	p->bus = bus;
	p->interface = PMIC_I2C;
	p->number_of_regs = TPS65090_NUM_REGS;
	p->hw.i2c.addr = addr;
	p->hw.i2c.tx_num = 1;
	p->chrg = &power_chrg_pmic_ops;

	puts("TPS65090 PMIC init\n");

	return 0;
}
Beispiel #7
0
int cros_ec_i2c_decode_fdt(struct cros_ec_dev *dev, const void *blob)
{
	/* Decode interface-specific FDT params */
	dev->max_frequency = fdtdec_get_int(blob, dev->node,
					    "i2c-max-frequency", 100000);
	dev->bus_num = i2c_get_bus_num_fdt(dev->parent_node);
	if (dev->bus_num == -1) {
		debug("%s: Failed to read bus number\n", __func__);
		return -1;
	}
	dev->addr = fdtdec_get_int(blob, dev->node, "reg", -1);
	if (dev->addr == -1) {
		debug("%s: Failed to read device address\n", __func__);
		return -1;
	}

	return 0;
}