Esempio n. 1
0
static int axp20x_regulator_parse_dt(struct platform_device *pdev)
{
	struct device_node *np, *regulators;
	int ret;
	u32 dcdcfreq;

	np = of_node_get(pdev->dev.parent->of_node);
	if (!np)
		return 0;

	regulators = of_get_child_by_name(np, "regulators");
	if (!regulators) {
		dev_warn(&pdev->dev, "regulators node not found\n");
	} else {
		ret = of_regulator_match(&pdev->dev, regulators, axp20x_matches,
					 ARRAY_SIZE(axp20x_matches));
		if (ret < 0) {
			dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret);
			return ret;
		}

		dcdcfreq = 1500;
		of_property_read_u32(regulators, "x-powers,dcdc-freq", &dcdcfreq);
		ret = axp20x_set_dcdc_freq(pdev, dcdcfreq);
		if (ret < 0) {
			dev_err(&pdev->dev, "Error setting dcdc frequency: %d\n", ret);
			return ret;
		}

		of_node_put(regulators);
	}

	return 0;
}
static int ricoh619_regulator_dt_init(struct platform_device *pdev,
				    struct regulator_config *config,
				    int regidx)
{
	struct device_node *nproot, *np;
	int rcount;
	nproot = of_node_get(pdev->dev.parent->of_node);
	if (!nproot)
		return -ENODEV;
	np = of_find_node_by_name(nproot, "regulators");
	if (!np) {
		dev_err(&pdev->dev, "failed to find regulators node\n");
		return -ENODEV;
	}

	rcount = of_regulator_match(&pdev->dev, np,
				&ricoh619_regulator_matches[regidx], 1);
	of_node_put(np);
	if (rcount < 0)
		return -ENODEV;
	config->init_data = ricoh619_regulator_matches[regidx].init_data;
	config->of_node = ricoh619_regulator_matches[regidx].of_node;

	return 0;
}
static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev)
{
	struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent);
	struct device_node *node = tps->dev->of_node;
	struct tps65217_board *pdata;
	struct device_node *regs;
	int i, count;

	regs = of_get_child_by_name(node, "regulators");
	if (!regs)
		return NULL;

	count = of_regulator_match(&pdev->dev, regs, reg_matches,
				   TPS65217_NUM_REGULATOR);
	of_node_put(regs);
	if ((count < 0) || (count > TPS65217_NUM_REGULATOR))
		return NULL;

	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return NULL;

	for (i = 0; i < count; i++) {
		if (!reg_matches[i].of_node)
			continue;

		pdata->tps65217_init_data[i] = reg_matches[i].init_data;
		pdata->of_node[i] = reg_matches[i].of_node;
	}

	return pdata;
}
Esempio n. 4
0
static int pm800_regulator_dt_init(struct platform_device *pdev,
	struct of_regulator_match **regulator_matches, int *range)
{
	struct pm80x_chip *chip = dev_get_drvdata(pdev->dev.parent);
	struct device_node *np = pdev->dev.of_node;

	switch (chip->type) {
		case CHIP_PM800:
			*regulator_matches = pm800_regulator_matches;
			*range = PM800_ID_RG_MAX;
			break;
		case CHIP_PM822:
			*regulator_matches = pm822_regulator_matches;
			*range = PM822_ID_RG_MAX;
			break;
		case CHIP_PM86X:
			*regulator_matches = pm86x_regulator_matches;
			*range = PM86X_ID_RG_MAX;
			break;
		default:
			return -ENODEV;
	}

	return of_regulator_match(&pdev->dev, np, *regulator_matches, *range);
}
static int as3711_regulator_parse_dt(struct device *dev,
				struct device_node **of_node, const int count)
{
	struct as3711_regulator_pdata *pdata = dev_get_platdata(dev);
	struct device_node *regulators =
		of_find_node_by_name(dev->parent->of_node, "regulators");
	struct of_regulator_match *match;
	int ret, i;

	if (!regulators) {
		dev_err(dev, "regulator node not found\n");
		return -ENODEV;
	}

	ret = of_regulator_match(dev->parent, regulators,
				 as3711_regulator_matches, count);
	of_node_put(regulators);
	if (ret < 0) {
		dev_err(dev, "Error parsing regulator init data: %d\n", ret);
		return ret;
	}

	for (i = 0, match = as3711_regulator_matches; i < count; i++, match++)
		if (match->of_node) {
			pdata->init_data[i] = match->init_data;
			of_node[i] = match->of_node;
		}

	return 0;
}
Esempio n. 6
0
static struct syr82x_board *syr82x_parse_dt(struct syr82x *syr82x)
{
	struct syr82x_board *pdata;
	struct device_node *regs;
	struct device_node *syr82x_np;
	int count;
	DBG("%s,line=%d\n", __func__,__LINE__);	
	
	syr82x_np = of_node_get(syr82x->dev->of_node);
	if (!syr82x_np) {
		printk("could not find pmic sub-node\n");
		return NULL;
	}
	
	regs = of_find_node_by_name(syr82x_np, "regulators");
	if (!regs)
		return NULL;
	count = of_regulator_match(syr82x->dev, regs, syr82x_reg_matches,
				   syr82x_NUM_REGULATORS);
	of_node_put(regs);
	pdata = devm_kzalloc(syr82x->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return NULL;
	pdata->syr82x_init_data[0] = syr82x_reg_matches[0].init_data;
	pdata->of_node[0] = syr82x_reg_matches[0].of_node;
	
	return pdata;
}
Esempio n. 7
0
static struct lp872x_platform_data
*lp872x_populate_pdata_from_dt(struct device *dev, enum lp872x_id which)
{
	struct device_node *np = dev->of_node;
	struct lp872x_platform_data *pdata;
	struct of_regulator_match *match;
	int num_matches;
	int count;
	int i;
	u8 dvs_state;

	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return ERR_PTR(-ENOMEM);

	of_property_read_u8(np, "ti,general-config", &pdata->general_config);
	if (of_find_property(np, "ti,update-config", NULL))
		pdata->update_config = true;

	pdata->dvs = devm_kzalloc(dev, sizeof(struct lp872x_dvs), GFP_KERNEL);
	if (!pdata->dvs)
		return ERR_PTR(-ENOMEM);

	pdata->dvs->gpio = of_get_named_gpio(np, "ti,dvs-gpio", 0);
	of_property_read_u8(np, "ti,dvs-vsel", (u8 *)&pdata->dvs->vsel);
	of_property_read_u8(np, "ti,dvs-state", &dvs_state);
	pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW;

	pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0);

	if (of_get_child_count(np) == 0)
		goto out;

	switch (which) {
	case LP8720:
		match = lp8720_matches;
		num_matches = ARRAY_SIZE(lp8720_matches);
		break;
	case LP8725:
		match = lp8725_matches;
		num_matches = ARRAY_SIZE(lp8725_matches);
		break;
	default:
		goto out;
	}

	count = of_regulator_match(dev, np, match, num_matches);
	if (count <= 0)
		goto out;

	for (i = 0; i < num_matches; i++) {
		pdata->regulator_data[i].id =
				(enum lp872x_regulator_id)match[i].driver_data;
		pdata->regulator_data[i].init_data = match[i].init_data;
	}
out:
	return pdata;
}
static int hi655x_regulator_probe(struct platform_device *pdev)
{
	unsigned int i;
	int ret;
	struct hi655x_regulator *regulator;
	struct hi655x_pmic *pmic;
	struct regulator_config config = { };
	struct device *dev = &pdev->dev;
	struct regulator_dev *rdev;
	struct device_node *np;

	np = of_get_child_by_name(dev->parent->of_node, "regulators");
	if (!np)
		return -ENODEV;

	ret = of_regulator_match(dev, np,
				 hi655x_regulator_match,
				 ARRAY_SIZE(hi655x_regulator_match));
	of_node_put(np);
	if (ret < 0) {
		dev_err(dev, "Error parsing regulator init data: %d\n", ret);
		return ret;
	}

	pmic = dev_get_drvdata(pdev->dev.parent);
	if (!pmic) {
		dev_err(dev, "no pmic in the regulator parent node\n");
		return -ENODEV;
	}

	regulator = devm_kzalloc(dev, sizeof(*regulator), GFP_KERNEL);
	if (!regulator)
		return -ENOMEM;

	platform_set_drvdata(pdev, regulator);

	for (i = 0; i < ARRAY_SIZE(regulators); i++) {
		config.dev = &pdev->dev;
		config.driver_data = regulator;
		config.regmap = pmic->regmap;
		config.of_node = hi655x_regulator_match[i].of_node;
		config.init_data = hi655x_regulator_match[i].init_data;

		/* register regulator with framework */
		rdev = devm_regulator_register(&pdev->dev,
					       &regulators[i].rdesc,
					       &config);
		if (IS_ERR(rdev)) {
			dev_err(&pdev->dev, "failed to register regulator %s\n",
				regulator->rdesc.name);
			return PTR_ERR(rdev);
		}
	}
	return 0;
}
Esempio n. 9
0
static int of_get_max1586_platform_data(struct device *dev,
				 struct max1586_platform_data *pdata)
{
	struct max1586_subdev_data *sub;
	struct of_regulator_match rmatch[ARRAY_SIZE(max1586_reg)] = { };
	struct device_node *np = dev->of_node;
	int i, matched;

	if (of_property_read_u32(np, "v3-gain",
				 &pdata->v3_gain) < 0) {
		dev_err(dev, "%pOF has no 'v3-gain' property\n", np);
		return -EINVAL;
	}

	np = of_get_child_by_name(np, "regulators");
	if (!np) {
		dev_err(dev, "missing 'regulators' subnode in DT\n");
		return -EINVAL;
	}

	for (i = 0; i < ARRAY_SIZE(rmatch); i++)
		rmatch[i].name = max1586_reg[i].name;

	matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(rmatch));
	of_node_put(np);
	/*
	 * If matched is 0, ie. neither Output_V3 nor Output_V6 have been found,
	 * return 0, which signals the normal situation where no subregulator is
	 * available. This is normal because the max1586 doesn't provide any
	 * readback support, so the subregulators can't report any status
	 * anyway.  If matched < 0, return the error.
	 */
	if (matched <= 0)
		return matched;

	pdata->subdevs = devm_kcalloc(dev,
				      matched,
				      sizeof(struct max1586_subdev_data),
				      GFP_KERNEL);
	if (!pdata->subdevs)
		return -ENOMEM;

	pdata->num_subdevs = matched;
	sub = pdata->subdevs;

	for (i = 0; i < matched; i++) {
		sub->id = i;
		sub->name = rmatch[i].of_node->name;
		sub->platform_data = rmatch[i].init_data;
		sub++;
	}

	return 0;
}
Esempio n. 10
0
static int pm800_regulator_dt_init(struct platform_device *pdev)
{
	struct device_node *np = pdev->dev.of_node;
	int ret;

	ret = of_regulator_match(&pdev->dev, np,
				 pm800_regulator_matches,
				 ARRAY_SIZE(pm800_regulator_matches));
	if (ret < 0)
		return ret;

	return 0;
}
static struct act8931_board *act8931_parse_dt(struct act8931 *act8931)
{
	struct act8931_board *pdata;
	struct device_node *regs;
	struct device_node *node;
	int i, count;

	node = of_node_get(act8931->dev->of_node);
	if (!node) {
		pr_err("%s: could not find pmic node\n", __func__);
		return NULL;
	}

	regs = of_get_child_by_name(node, "regulators");
	if (!regs)
		return NULL;

	count = of_regulator_match(act8931->dev, regs, act8931_reg_matches,
				   ACT8931_NUM_REGULATORS);
	of_node_put(regs);

	if ((count < 0) || (count > ACT8931_NUM_REGULATORS))
		return NULL;

	pdata = devm_kzalloc(act8931->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return NULL;

	for (i = 0; i < count; i++) {
		pdata->act8931_init_data[i] = act8931_reg_matches[i].init_data;
		pdata->of_node[i] = act8931_reg_matches[i].of_node;
	}

	pdata->irq_gpio = of_get_named_gpio(node, "gpios", 0);
	if (!gpio_is_valid(pdata->irq_gpio)) {
		pr_err("%s: invalid gpio: %d\n", __func__, pdata->irq_gpio);
		return NULL;
	}

	pdata->pwr_hold_gpio = of_get_named_gpio(node, "gpios", 1);
	if (!gpio_is_valid(pdata->pwr_hold_gpio)) {
		pr_err("%s: invalid gpio: %d\n", __func__,
		       pdata->pwr_hold_gpio);
		return NULL;
	}

	pdata->pm_off = of_property_read_bool(node,
					"act8931,system-power-controller");

	return pdata;
}
Esempio n. 12
0
static struct bcm590xx_board *bcm590xx_parse_dt_reg_data(
		struct platform_device *pdev,
		struct of_regulator_match **bcm590xx_reg_matches)
{
	struct bcm590xx_board *data;
	struct device_node *np = pdev->dev.parent->of_node;
	struct device_node *regulators;
	struct of_regulator_match *matches = bcm590xx_matches;
	int count = ARRAY_SIZE(bcm590xx_matches);
	int idx = 0;
	int ret;

	if (!np) {
		dev_err(&pdev->dev, "of node not found\n");
		return NULL;
	}

	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
	if (!data) {
		dev_err(&pdev->dev, "failed to allocate regulator board data\n");
		return NULL;
	}

	np = of_node_get(np);
	regulators = of_get_child_by_name(np, "regulators");
	if (!regulators) {
		dev_warn(&pdev->dev, "regulator node not found\n");
		return NULL;
	}

	ret = of_regulator_match(&pdev->dev, regulators, matches, count);
	of_node_put(regulators);
	if (ret < 0) {
		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
			ret);
		return NULL;
	}

	*bcm590xx_reg_matches = matches;

	for (idx = 0; idx < count; idx++) {
		if (!matches[idx].init_data || !matches[idx].of_node)
			continue;

		data->bcm590xx_pmu_init_data[idx] = matches[idx].init_data;
	}

	return data;
}
Esempio n. 13
0
static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
		struct platform_device *pdev,
		struct of_regulator_match **da9063_reg_matches)
{
	struct da9063_regulators_pdata *pdata;
	struct da9063_regulator_data *rdata;
	struct device_node *node;
	int i, n, num;

	node = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
	if (!node) {
		dev_err(&pdev->dev, "Regulators device node not found\n");
		return ERR_PTR(-ENODEV);
	}

	num = of_regulator_match(&pdev->dev, node, da9063_matches,
				 ARRAY_SIZE(da9063_matches));
	of_node_put(node);
	if (num < 0) {
		dev_err(&pdev->dev, "Failed to match regulators\n");
		return ERR_PTR(-EINVAL);
	}

	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return ERR_PTR(-ENOMEM);

	pdata->regulator_data = devm_kzalloc(&pdev->dev,
					num * sizeof(*pdata->regulator_data),
					GFP_KERNEL);
	if (!pdata->regulator_data)
		return ERR_PTR(-ENOMEM);
	pdata->n_regulators = num;

	n = 0;
	for (i = 0; i < ARRAY_SIZE(da9063_matches); i++) {
		if (!da9063_matches[i].init_data)
			continue;

		rdata = &pdata->regulator_data[n];
		rdata->id = i;
		rdata->initdata = da9063_matches[i].init_data;

		n++;
	}

	*da9063_reg_matches = da9063_matches;
	return pdata;
}
static int tps65132_get_regulator_dt_data(struct device *dev,
		struct tps65132_regulator *tps65132_regs)
{
	struct tps65132_regulator_pdata *rpdata;
	struct device_node *rnode;
	int id;
	int ret;

	ret = of_regulator_match(dev, dev->of_node, tps65132_regulator_matches,
			ARRAY_SIZE(tps65132_regulator_matches));
	if (ret < 0) {
		dev_err(dev, "node parsing for regulator failed: %d\n", ret);
		return ret;
	}

	for (id = 0; id < ARRAY_SIZE(tps65132_regulator_matches); ++id) {
		rpdata = &tps65132_regs->reg_pdata[id];
		rnode = tps65132_regulator_matches[id].of_node;
		if (!rnode)
			continue;

		rpdata->ridata = tps65132_regulator_matches[id].init_data;
		rpdata->enable_gpio = of_get_named_gpio(rnode,
						"ti,enable-gpio", 0);
		if (rpdata->enable_gpio == -EPROBE_DEFER)
			return -EPROBE_DEFER;

		rpdata->disable_active_discharge = of_property_read_bool(rnode,
						"ti,disable-active-discharge");

		rpdata->active_discharge_gpio = of_get_named_gpio(rnode,
						"ti,active-discharge-gpio", 0);
		if (rpdata->active_discharge_gpio == -EPROBE_DEFER) {
			return -EPROBE_DEFER;
		} else if (gpio_is_valid(rpdata->active_discharge_gpio)) {
			ret = of_property_read_u32(rnode,
				"ti,active-discharge-time",
				&rpdata->active_discharge_time);
			if (ret < 0) {
				dev_err(dev, "Discharge time read failed: %d\n",
					ret);
				return ret;
			}
		}
	}

	return 0;
}
Esempio n. 15
0
static struct tps6586x_platform_data *tps6586x_parse_regulator_dt(
		struct platform_device *pdev,
		struct of_regulator_match **tps6586x_reg_matches)
{
	const unsigned int num = ARRAY_SIZE(tps6586x_matches);
	struct device_node *np = pdev->dev.parent->of_node;
	struct device_node *regs;
	const char *sys_rail = NULL;
	unsigned int i;
	struct tps6586x_platform_data *pdata;
	int err;

	regs = of_find_node_by_name(np, "regulators");
	if (!regs) {
		dev_err(&pdev->dev, "regulator node not found\n");
		return NULL;
	}

	err = of_regulator_match(&pdev->dev, regs, tps6586x_matches, num);
	of_node_put(regs);
	if (err < 0) {
		dev_err(&pdev->dev, "Regulator match failed, e %d\n", err);
		return NULL;
	}

	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata) {
		dev_err(&pdev->dev, "Memory alloction failed\n");
		return NULL;
	}

	for (i = 0; i < num; i++) {
		int id;
		if (!tps6586x_matches[i].init_data)
			continue;

		pdata->reg_init_data[i] = tps6586x_matches[i].init_data;
		id = (int)tps6586x_matches[i].driver_data;
		if (id == TPS6586X_ID_SYS)
			sys_rail = pdata->reg_init_data[i]->constraints.name;

		if ((id == TPS6586X_ID_LDO_5) || (id == TPS6586X_ID_LDO_RTC))
			pdata->reg_init_data[i]->supply_regulator = sys_rail;
	}
	*tps6586x_reg_matches = tps6586x_matches;
	return pdata;
}
Esempio n. 16
0
static int s2mps11_pmic_dt_parse(struct platform_device *pdev,
                                 struct of_regulator_match *rdata, struct s2mps11_info *s2mps11)
{
    struct device_node *reg_np;

    reg_np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators");
    if (!reg_np) {
        dev_err(&pdev->dev, "could not find regulators sub-node\n");
        return -EINVAL;
    }

    of_regulator_match(&pdev->dev, reg_np, rdata, s2mps11->rdev_num);
    if (s2mps11->dev_type == S2MPS14X)
        s2mps14_pmic_dt_parse_ext_control_gpio(pdev, rdata, s2mps11);

    of_node_put(reg_np);

    return 0;
}
Esempio n. 17
0
static int rk808_regulator_probe(struct platform_device *pdev)
{
	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
	struct i2c_client *client = rk808->i2c;
	struct device_node *reg_np;
	struct regulator_config config = {};
	struct regulator_dev *rk808_rdev;
	int ret, i;

	reg_np = of_get_child_by_name(client->dev.of_node, "regulators");
	if (!reg_np)
		return -ENXIO;

	ret = of_regulator_match(&pdev->dev, reg_np, rk808_reg_matches,
				 RK808_NUM_REGULATORS);
	of_node_put(reg_np);
	if (ret < 0)
		return ret;

	/* Instantiate the regulators */
	for (i = 0; i < RK808_NUM_REGULATORS; i++) {
		if (!rk808_reg_matches[i].init_data ||
		    !rk808_reg_matches[i].of_node)
			continue;

		config.dev = &client->dev;
		config.driver_data = rk808;
		config.regmap = rk808->regmap;
		config.of_node = rk808_reg_matches[i].of_node;
		config.init_data = rk808_reg_matches[i].init_data;

		rk808_rdev = devm_regulator_register(&pdev->dev,
						     &rk808_reg[i], &config);
		if (IS_ERR(rk808_rdev)) {
			dev_err(&client->dev,
				"failed to register %d regulator\n", i);
			return PTR_ERR(rk808_rdev);
		}
	}

	return 0;
}
Esempio n. 18
0
static int max77693_pmic_dt_parse_rdata(struct device *dev,
					struct max77693_regulator_data **rdata)
{
	struct device_node *np;
	struct of_regulator_match *rmatch;
	struct max77693_regulator_data *tmp;
	int i, matched = 0;

	np = of_get_child_by_name(dev->parent->of_node, "regulators");
	if (!np)
		return -EINVAL;

	rmatch = devm_kzalloc(dev,
		 sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL);
	if (!rmatch) {
		of_node_put(np);
		return -ENOMEM;
	}

	for (i = 0; i < ARRAY_SIZE(regulators); i++)
		rmatch[i].name = regulators[i].name;

	matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators));
	of_node_put(np);
	if (matched <= 0)
		return matched;
	*rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL);
	if (!(*rdata))
		return -ENOMEM;

	tmp = *rdata;

	for (i = 0; i < matched; i++) {
		tmp->initdata = rmatch[i].init_data;
		tmp->of_node = rmatch[i].of_node;
		tmp->id = regulators[i].id;
		tmp++;
	}

	return matched;
}
Esempio n. 19
0
static int hi6421_regulator_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct device_node *np;
	struct hi6421_pmic *pmic;
	struct hi6421_regulator_pdata *pdata;
	int i, ret = 0;

	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return -ENOMEM;
	mutex_init(&pdata->lock);
	platform_set_drvdata(pdev, pdata);

	np = of_get_child_by_name(dev->parent->of_node, "regulators");
	if (!np)
		return -ENODEV;

	ret = of_regulator_match(dev, np,
				 hi6421_regulator_match,
				 ARRAY_SIZE(hi6421_regulator_match));
	of_node_put(np);
	if (ret < 0) {
		dev_err(dev, "Error parsing regulator init data: %d\n", ret);
		return ret;
	}

	pmic = dev_get_drvdata(dev->parent);

	for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) {
		ret = hi6421_regulator_register(pdev, pmic->regmap,
			hi6421_regulator_match[i].init_data, i,
			hi6421_regulator_match[i].of_node);
		if (ret)
			return ret;
	}

	return 0;
}
Esempio n. 20
0
static int max77686_pmic_dt_parse_pdata(struct platform_device *pdev,
					struct max77686_platform_data *pdata)
{
	struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
	struct device_node *pmic_np, *regulators_np;
	struct max77686_regulator_data *rdata;
	struct of_regulator_match rmatch;
	unsigned int i;

	pmic_np = iodev->dev->of_node;
	regulators_np = of_find_node_by_name(pmic_np, "voltage-regulators");
	if (!regulators_np) {
		dev_err(&pdev->dev, "could not find regulators sub-node\n");
		return -EINVAL;
	}

	pdata->num_regulators = ARRAY_SIZE(regulators);
	rdata = devm_kzalloc(&pdev->dev, sizeof(*rdata) *
			     pdata->num_regulators, GFP_KERNEL);
	if (!rdata) {
		dev_err(&pdev->dev,
			"could not allocate memory for regulator data\n");
		return -ENOMEM;
	}

	for (i = 0; i < pdata->num_regulators; i++) {
		rmatch.name = regulators[i].name;
		rmatch.init_data = NULL;
		rmatch.of_node = NULL;
		of_regulator_match(&pdev->dev, regulators_np, &rmatch, 1);
		rdata[i].initdata = rmatch.init_data;
		rdata[i].of_node = rmatch.of_node;
	}

	pdata->regulators = rdata;

	return 0;
}
Esempio n. 21
0
static int db8500_regulator_probe(struct platform_device *pdev)
{
	struct regulator_init_data *db8500_init_data =
					dev_get_platdata(&pdev->dev);
	struct device_node *np = pdev->dev.of_node;
	int i, err;

	/* register all regulators */
	if (np) {
		err = of_regulator_match(&pdev->dev, np,
					db8500_regulator_matches,
					ARRAY_SIZE(db8500_regulator_matches));
		if (err < 0) {
			dev_err(&pdev->dev,
				"Error parsing regulator init data: %d\n", err);
			return err;
		}

		err = db8500_regulator_of_probe(pdev, np);
		if (err)
			return err;
	} else {
		for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
			err = db8500_regulator_register(pdev,
							&db8500_init_data[i],
							i, NULL);
			if (err)
				return err;
		}
	}

	err = ux500_regulator_debug_init(pdev,
					 dbx500_regulator_info,
					 ARRAY_SIZE(dbx500_regulator_info));
	return 0;
}
Esempio n. 22
0
static int ab8500_ext_regulator_probe(struct platform_device *pdev)
{
	struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
	struct ab8500_platform_data *ppdata;
	struct ab8500_regulator_platform_data *pdata;
	struct device_node *np = pdev->dev.of_node;
	struct regulator_config config = { };
	int i, err;

	if (np) {
		err = of_regulator_match(&pdev->dev, np,
					 ab8500_ext_regulator_match,
					 ARRAY_SIZE(ab8500_ext_regulator_match));
		if (err < 0) {
			dev_err(&pdev->dev,
				"Error parsing regulator init data: %d\n", err);
			return err;
		}
	}

	if (!ab8500) {
		dev_err(&pdev->dev, "null mfd parent\n");
		return -EINVAL;
	}

	ppdata = dev_get_platdata(ab8500->dev);
	if (!ppdata) {
		dev_err(&pdev->dev, "null parent pdata\n");
		return -EINVAL;
	}

	pdata = ppdata->regulator;
	if (!pdata) {
		dev_err(&pdev->dev, "null pdata\n");
		return -EINVAL;
	}

	/* make sure the platform data has the correct size */
	if (pdata->num_ext_regulator != ARRAY_SIZE(ab8500_ext_regulator_info)) {
		dev_err(&pdev->dev, "Configuration error: size mismatch.\n");
		return -EINVAL;
	}

	/* check for AB8500 2.x */
	if (is_ab8500_2p0_or_earlier(ab8500)) {
		struct ab8500_ext_regulator_info *info;

		/* VextSupply3LPn is inverted on AB8500 2.x */
		info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3];
		info->update_val = 0x30;
		info->update_val_hp = 0x30;
		info->update_val_lp = 0x10;
	}

	/* register all regulators */
	for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) {
		struct ab8500_ext_regulator_info *info = NULL;

		/* assign per-regulator data */
		info = &ab8500_ext_regulator_info[i];
		info->dev = &pdev->dev;
		info->cfg = (struct ab8500_ext_regulator_cfg *)
			pdata->ext_regulator[i].driver_data;

		config.dev = &pdev->dev;
		config.driver_data = info;
		config.of_node = ab8500_ext_regulator_match[i].of_node;
		config.init_data = (np) ?
			ab8500_ext_regulator_match[i].init_data :
			&pdata->ext_regulator[i];

		/* register regulator with framework */
		info->rdev = devm_regulator_register(&pdev->dev, &info->desc,
						     &config);
		if (IS_ERR(info->rdev)) {
			err = PTR_ERR(info->rdev);
			dev_err(&pdev->dev, "failed to register regulator %s\n",
					info->desc.name);
			return err;
		}

		dev_dbg(rdev_get_dev(info->rdev),
			"%s-probed\n", info->desc.name);
	}

	return 0;
}
static struct pwm_regulator_board *pwm_regulator_parse_dt(
		struct platform_device *pdev,
		struct of_regulator_match **pwm_reg_matches)
{
	struct pwm_regulator_board *pwm_plat_data;
	struct device_node *np, *regulators;
	struct of_regulator_match *matches;
	int idx = 0, ret, count;
	struct property *prop;
	int length;
	const __be32 *init_vol, *max_vol, *min_vol, *suspend_vol, *coefficient, *id;

	DBG("%s,line=%d\n", __func__, __LINE__);

	pwm_plat_data = devm_kzalloc(&pdev->dev, sizeof(*pwm_plat_data),
					GFP_KERNEL);

	if (!pwm_plat_data) {
		dev_err(&pdev->dev, "Failure to alloc pdata for regulators.\n");
		return NULL;
	}

	np = of_node_get(pdev->dev.of_node);
	regulators = of_find_node_by_name(np, "regulators");
	if (!regulators) {
		dev_err(&pdev->dev, "regulator node not found\n");
		return NULL;
	}
	count = ARRAY_SIZE(pwm_matches);
	matches = pwm_matches;
	ret = of_regulator_match(&pdev->dev, regulators, matches, count);
	of_node_put(regulators);
	if (ret < 0) {
		dev_err(&pdev->dev, "Error parsing regulator init data: %d\n",
			ret);
		return NULL;
	}

	pwm_plat_data->num_regulators = count;
	*pwm_reg_matches = matches;

	for (idx = 0; idx < count; idx++) {
		if (!matches[idx].init_data || !matches[idx].of_node)
			continue;
		pwm_plat_data->pwm_init_data[idx] = matches[idx].init_data;
		pwm_plat_data->of_node[idx] = matches[idx].of_node;
	}

	init_vol = of_get_property(np, "rockchip,pwm_voltage", NULL);
	if (init_vol)
		pwm_plat_data->pwm_init_vol = be32_to_cpu(*init_vol);

	max_vol = of_get_property(np, "rockchip,pwm_max_voltage", NULL);
	if (max_vol)
		pwm_plat_data->pwm_max_vol = be32_to_cpu(*max_vol);

	min_vol = of_get_property(np, "rockchip,pwm_min_voltage", NULL);
	if (min_vol)
		pwm_plat_data->pwm_min_vol = be32_to_cpu(*min_vol);

	suspend_vol = of_get_property(np, "rockchip,pwm_suspend_voltage", NULL);
	if (suspend_vol)
		pwm_plat_data->pwm_suspend_vol = be32_to_cpu(*suspend_vol);

	coefficient  = of_get_property(np, "rockchip,pwm_coefficient", NULL);
	if (coefficient)
		pwm_plat_data->pwm_coefficient = be32_to_cpu(*coefficient);

	id  = of_get_property(np, "rockchip,pwm_id", NULL);
	if (id)
		pwm_plat_data->pwm_id = be32_to_cpu(*id);

	prop = of_find_property(np, "rockchip,pwm_voltage_map", &length);
	if (!prop)
		return NULL;
	pwm_plat_data->pwm_vol_map_count = length / sizeof(u32);
	if (pwm_plat_data->pwm_vol_map_count > 0) {
		size_t size = sizeof(*pwm_plat_data->pwm_voltage_map) * pwm_plat_data->pwm_vol_map_count;

	pwm_plat_data->pwm_voltage_map = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
	if (!pwm_plat_data->pwm_voltage_map)
		return NULL;
	ret = of_property_read_u32_array(np, "rockchip,pwm_voltage_map",
		pwm_plat_data->pwm_voltage_map, pwm_plat_data->pwm_vol_map_count);
	if (ret < 0)
		printk("pwm voltage map not specified\n");
	}
	return pwm_plat_data;
}
Esempio n. 24
0
static void palmas_dt_to_pdata(struct device *dev,
			       struct device_node *node,
			       struct palmas_pmic_platform_data *pdata,
			       struct palmas_pmic_driver_data *ddata)
{
	struct device_node *regulators;
	u32 prop;
	int idx, ret;

	regulators = of_get_child_by_name(node, "regulators");
	if (!regulators) {
		dev_info(dev, "regulator node not found\n");
		return;
	}

	ret = of_regulator_match(dev, regulators, ddata->palmas_matches,
				 ddata->max_reg);
	of_node_put(regulators);
	if (ret < 0) {
		dev_err(dev, "Error parsing regulator init data: %d\n", ret);
		return;
	}

	for (idx = 0; idx < ddata->max_reg; idx++) {
		if (!ddata->palmas_matches[idx].init_data ||
		    !ddata->palmas_matches[idx].of_node)
			continue;

		pdata->reg_data[idx] = ddata->palmas_matches[idx].init_data;

		pdata->reg_init[idx] = devm_kzalloc(dev,
				sizeof(struct palmas_reg_init), GFP_KERNEL);

		pdata->reg_init[idx]->warm_reset =
			of_property_read_bool(ddata->palmas_matches[idx].of_node,
					      "ti,warm-reset");

		ret = of_property_read_u32(ddata->palmas_matches[idx].of_node,
					   "ti,roof-floor", &prop);
		/* EINVAL: Property not found */
		if (ret != -EINVAL) {
			int econtrol;

			/* use default value, when no value is specified */
			econtrol = PALMAS_EXT_CONTROL_NSLEEP;
			if (!ret) {
				switch (prop) {
				case 1:
					econtrol = PALMAS_EXT_CONTROL_ENABLE1;
					break;
				case 2:
					econtrol = PALMAS_EXT_CONTROL_ENABLE2;
					break;
				case 3:
					econtrol = PALMAS_EXT_CONTROL_NSLEEP;
					break;
				default:
					WARN_ON(1);
					dev_warn(dev,
						 "%s: Invalid roof-floor option: %u\n",
					     palmas_matches[idx].name, prop);
					break;
				}
			}
			pdata->reg_init[idx]->roof_floor = econtrol;
		}

		ret = of_property_read_u32(ddata->palmas_matches[idx].of_node,
					   "ti,mode-sleep", &prop);
		if (!ret)
			pdata->reg_init[idx]->mode_sleep = prop;

		ret = of_property_read_bool(ddata->palmas_matches[idx].of_node,
					    "ti,smps-range");
		if (ret)
			pdata->reg_init[idx]->vsel =
				PALMAS_SMPS12_VOLTAGE_RANGE;

		if (idx == PALMAS_REG_LDO8)
			pdata->enable_ldo8_tracking = of_property_read_bool(
						ddata->palmas_matches[idx].of_node,
						"ti,enable-ldo8-tracking");
	}

	pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator");
}
Esempio n. 25
0
static struct act8846_board *act8846_parse_dt(struct act8846 *act8846)
{
//	struct act8846 *act8846 = i2c->dev.parent;
	struct act8846_board *pdata;
	struct device_node *regs;
	struct device_node *act8846_pmic_np;
	int i, count;
	int gpio;
	printk("%s,line=%d\n", __func__,__LINE__);	
	
	act8846_pmic_np = of_node_get(act8846->dev->of_node);
	if (!act8846_pmic_np) {
		printk("could not find pmic sub-node\n");
		return NULL;
	}
	
	regs = of_find_node_by_name(act8846_pmic_np, "regulators");
	if (!regs)
		return NULL;
	
	count = of_regulator_match(act8846->dev, regs, act8846_reg_matches,act8846_NUM_REGULATORS);
	of_node_put(regs);

	if ((count < 0) || (count > act8846_NUM_REGULATORS))
		return NULL;

	pdata = devm_kzalloc(act8846->dev, sizeof(*pdata), GFP_KERNEL);
	if (!pdata)
		return NULL;
	for (i = 0; i < count; i++) {
		if (!act8846_reg_matches[i].init_data || !act8846_reg_matches[i].of_node)
			continue;
		pdata->act8846_init_data[i] = act8846_reg_matches[i].init_data;
		pdata->of_node[i] = act8846_reg_matches[i].of_node;
	}
	pdata->irq = act8846->chip_irq;
	pdata->irq_base = -1;

	gpio = of_get_named_gpio(act8846_pmic_np,"gpios", 0);
		if (!gpio_is_valid(gpio)) 
			printk("invalid gpio: %d\n",gpio);
	pdata->pmic_sleep_gpio = gpio;	
	pdata->pmic_sleep = true;
	
	gpio = of_get_named_gpio(act8846_pmic_np,"gpios", 1);
		if (!gpio_is_valid(gpio)) 
			printk("invalid gpio: %d\n",gpio);
	pdata->pmic_hold_gpio = gpio;	
	pdata->pm_off = of_property_read_bool(act8846_pmic_np,"act8846,system-power-controller");

    gpio = of_get_named_gpio(act8846_pmic_np,"cpu_det_gpio", 0);
        if (!gpio_is_valid(gpio))
                printk("invalid gpio: %d\n",gpio);
    pdata->pmic_cpu_det_gpio = gpio;
    
    gpio = of_get_named_gpio(act8846_pmic_np,"usb_hub_reset_gpio", 0);
        if (!gpio_is_valid(gpio))
                printk("lhm invalid gpio: %d\n",gpio);
    pdata->pmic_usb_hub_reset_gpio = gpio;

	return pdata;
}