Пример #1
0
static int pwm_regulator_set_voltage(struct udevice *dev, int uvolt)
{
	struct pwm_regulator_info *priv = dev_get_priv(dev);
	int duty_cycle;
	int ret = 0;

	duty_cycle = pwm_voltage_to_duty_cycle_percentage(dev, uvolt);

	ret = pwm_set_invert(priv->pwm, priv->pwm_id, priv->polarity);
	if (ret) {
		dev_err(dev, "Failed to init PWM\n");
		return ret;
	}

	ret = pwm_set_config(priv->pwm, priv->pwm_id,
			priv->period_ns, (priv->period_ns / 100) * duty_cycle);
	if (ret) {
		dev_err(dev, "Failed to configure PWM\n");
		return ret;
	}

	priv->volt_uV = uvolt;

	return ret;
}
Пример #2
0
static int set_pwm(struct pwm_backlight_priv *priv)
{
	uint duty_cycle;
	int ret;

	duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) /
		(priv->max_level - priv->min_level + 1);
	ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
			     duty_cycle);
	if (ret)
		return log_ret(ret);

	ret = pwm_set_invert(priv->pwm, priv->channel, priv->polarity);
	return log_ret(ret);
}
Пример #3
0
/* Basic test of the pwm uclass */
static int dm_test_pwm_base(struct unit_test_state *uts)
{
	struct udevice *dev;

	ut_assertok(uclass_get_device(UCLASS_PWM, 0, &dev));
	ut_assertnonnull(dev);
	ut_assertok(pwm_set_config(dev, 0, 100, 50));
	ut_assertok(pwm_set_enable(dev, 0, true));
	ut_assertok(pwm_set_enable(dev, 1, true));
	ut_assertok(pwm_set_enable(dev, 2, true));
	ut_asserteq(-ENOSPC, pwm_set_enable(dev, 3, true));
	ut_assertok(pwm_set_invert(dev, 0, true));

	ut_assertok(uclass_get_device(UCLASS_PWM, 1, &dev));
	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_PWM, 2, &dev));

	return 0;
}