Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-usb
[u-boot.git] / drivers / video / backlight_gpio.c
blobb26fa9a8acf1515876dd3728aaeb7e6d08bcb68d
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author: Patrick Delaunay <patrick.delaunay@foss.st.com>
5 */
7 #include <dm.h>
8 #include <backlight.h>
9 #include <log.h>
10 #include <asm/gpio.h>
12 struct gpio_backlight_priv {
13 struct gpio_desc gpio;
14 bool def_value;
17 static int gpio_backlight_enable(struct udevice *dev)
19 struct gpio_backlight_priv *priv = dev_get_priv(dev);
21 dm_gpio_set_value(&priv->gpio, 1);
23 return 0;
26 static int gpio_backlight_of_to_plat(struct udevice *dev)
28 struct gpio_backlight_priv *priv = dev_get_priv(dev);
29 int ret;
31 ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio,
32 GPIOD_IS_OUT);
33 if (ret) {
34 debug("%s: Warning: cannot get GPIO: ret=%d\n",
35 __func__, ret);
36 return ret;
39 priv->def_value = dev_read_bool(dev, "default-on");
41 return 0;
44 static int gpio_backlight_probe(struct udevice *dev)
46 struct gpio_backlight_priv *priv = dev_get_priv(dev);
48 if (priv->def_value)
49 gpio_backlight_enable(dev);
51 return 0;
54 static const struct backlight_ops gpio_backlight_ops = {
55 .enable = gpio_backlight_enable,
58 static const struct udevice_id gpio_backlight_ids[] = {
59 { .compatible = "gpio-backlight" },
60 { }
63 U_BOOT_DRIVER(gpio_backlight) = {
64 .name = "gpio_backlight",
65 .id = UCLASS_PANEL_BACKLIGHT,
66 .of_match = gpio_backlight_ids,
67 .ops = &gpio_backlight_ops,
68 .of_to_plat = gpio_backlight_of_to_plat,
69 .probe = gpio_backlight_probe,
70 .priv_auto = sizeof(struct gpio_backlight_priv),