if (pb->enabled)
return;
- err = regulator_enable(pb->power_supply);
- if (err < 0)
- dev_err(pb->dev, "failed to enable power supply\n");
+ if (pb->power_supply) {
+ err = regulator_enable(pb->power_supply);
+ if (err < 0)
+ dev_err(pb->dev, "failed to enable power supply\n");
+ }
if (pb->post_pwm_on_delay)
msleep(pb->post_pwm_on_delay);
if (pb->pwm_off_delay)
msleep(pb->pwm_off_delay);
- regulator_disable(pb->power_supply);
+ if (pb->power_supply)
+ regulator_disable(pb->power_supply);
pb->enabled = false;
}
pwm_backlight_power_off(pb);
pwm_get_state(pb->pwm, &state);
- state.enabled = false;
state.duty_cycle = 0;
+ /*
+ * We cannot assume a disabled PWM to drive its output to the
+ * inactive state. If we have an enable GPIO and/or a regulator
+ * we assume that this isn't relevant and we can disable the PWM
+ * to save power. If however there is neither an enable GPIO nor
+ * a regulator keep the PWM on be sure to get a constant
+ * inactive output.
+ */
+ state.enabled = !pb->power_supply && !pb->enable_gpio;
pwm_apply_state(pb->pwm, &state);
}
if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0)
active = false;
- if (!regulator_is_enabled(pb->power_supply))
+ if (pb->power_supply && !regulator_is_enabled(pb->power_supply))
active = false;
if (!pwm_is_enabled(pb->pwm))
goto err_alloc;
}
- pb->power_supply = devm_regulator_get(&pdev->dev, "power");
+ pb->power_supply = devm_regulator_get_optional(&pdev->dev, "power");
if (IS_ERR(pb->power_supply)) {
ret = PTR_ERR(pb->power_supply);
- goto err_alloc;
+ if (ret == -ENODEV)
+ pb->power_supply = NULL;
+ else
+ goto err_alloc;
}
pb->pwm = devm_pwm_get(&pdev->dev, NULL);