panel: Expand the backlight support
At present the panel can be turned on but not off, and the brightness
cannot be controlled at run-time. Add a new API function to both the panel
and backlight uclasses to handle this. Enhance the PWM backlight driver
to deal with custom levels properly and allow the backlight to be turned
on and off.
Update the test to cover thes new features.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/video/simple_panel.c b/drivers/video/simple_panel.c
index 6c604f9..7a968e7 100644
--- a/drivers/video/simple_panel.c
+++ b/drivers/video/simple_panel.c
@@ -32,6 +32,21 @@
return 0;
}
+static int simple_panel_set_backlight(struct udevice *dev, int percent)
+{
+ struct simple_panel_priv *priv = dev_get_priv(dev);
+ int ret;
+
+ debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
+ dm_gpio_set_value(&priv->enable, 1);
+ ret = backlight_set_brightness(priv->backlight, percent);
+ debug("%s: done, ret = %d\n", __func__, ret);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
static int simple_panel_ofdata_to_platdata(struct udevice *dev)
{
struct simple_panel_priv *priv = dev_get_priv(dev);
@@ -51,7 +66,7 @@
"backlight", &priv->backlight);
if (ret) {
debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
- return ret;
+ return log_ret(ret);
}
ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
GPIOD_IS_OUT);
@@ -59,7 +74,7 @@
debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
__func__, ret);
if (ret != -ENOENT)
- return ret;
+ return log_ret(ret);
}
return 0;
@@ -82,6 +97,7 @@
static const struct panel_ops simple_panel_ops = {
.enable_backlight = simple_panel_enable_backlight,
+ .set_backlight = simple_panel_set_backlight,
};
static const struct udevice_id simple_panel_ids[] = {