Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
Patrice Chotard | 5d9950d | 2020-12-02 18:47:30 +0100 | [diff] [blame] | 4 | * Author: Patrick Delaunay <patrick.delaunay@foss.st.com> |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <backlight.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 10 | #include <asm/gpio.h> |
| 11 | |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 12 | struct gpio_backlight_priv { |
| 13 | struct gpio_desc gpio; |
| 14 | bool def_value; |
| 15 | }; |
| 16 | |
| 17 | static int gpio_backlight_enable(struct udevice *dev) |
| 18 | { |
| 19 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 20 | |
| 21 | dm_gpio_set_value(&priv->gpio, 1); |
| 22 | |
| 23 | return 0; |
| 24 | } |
| 25 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 26 | static int gpio_backlight_of_to_plat(struct udevice *dev) |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 27 | { |
| 28 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 29 | int ret; |
| 30 | |
| 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; |
| 37 | } |
| 38 | |
| 39 | priv->def_value = dev_read_bool(dev, "default-on"); |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | static int gpio_backlight_probe(struct udevice *dev) |
| 45 | { |
| 46 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 47 | |
| 48 | if (priv->def_value) |
| 49 | gpio_backlight_enable(dev); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | static const struct backlight_ops gpio_backlight_ops = { |
| 55 | .enable = gpio_backlight_enable, |
| 56 | }; |
| 57 | |
| 58 | static const struct udevice_id gpio_backlight_ids[] = { |
| 59 | { .compatible = "gpio-backlight" }, |
| 60 | { } |
| 61 | }; |
| 62 | |
| 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, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 68 | .of_to_plat = gpio_backlight_of_to_plat, |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 69 | .probe = gpio_backlight_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 70 | .priv_auto = sizeof(struct gpio_backlight_priv), |
Patrick Delaunay | a3c046f | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 71 | }; |