Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
Patrice Chotard | 0f8106f | 2020-12-02 18:47:30 +0100 | [diff] [blame] | 4 | * Author: Patrick Delaunay <patrick.delaunay@foss.st.com> |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <backlight.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 11 | #include <asm/gpio.h> |
| 12 | |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 13 | struct gpio_backlight_priv { |
| 14 | struct gpio_desc gpio; |
| 15 | bool def_value; |
| 16 | }; |
| 17 | |
| 18 | static int gpio_backlight_enable(struct udevice *dev) |
| 19 | { |
| 20 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 21 | |
| 22 | dm_gpio_set_value(&priv->gpio, 1); |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 27 | static int gpio_backlight_of_to_plat(struct udevice *dev) |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 28 | { |
| 29 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 30 | int ret; |
| 31 | |
| 32 | ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, |
| 33 | GPIOD_IS_OUT); |
| 34 | if (ret) { |
| 35 | debug("%s: Warning: cannot get GPIO: ret=%d\n", |
| 36 | __func__, ret); |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | priv->def_value = dev_read_bool(dev, "default-on"); |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int gpio_backlight_probe(struct udevice *dev) |
| 46 | { |
| 47 | struct gpio_backlight_priv *priv = dev_get_priv(dev); |
| 48 | |
| 49 | if (priv->def_value) |
| 50 | gpio_backlight_enable(dev); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | static const struct backlight_ops gpio_backlight_ops = { |
| 56 | .enable = gpio_backlight_enable, |
| 57 | }; |
| 58 | |
| 59 | static const struct udevice_id gpio_backlight_ids[] = { |
| 60 | { .compatible = "gpio-backlight" }, |
| 61 | { } |
| 62 | }; |
| 63 | |
| 64 | U_BOOT_DRIVER(gpio_backlight) = { |
| 65 | .name = "gpio_backlight", |
| 66 | .id = UCLASS_PANEL_BACKLIGHT, |
| 67 | .of_match = gpio_backlight_ids, |
| 68 | .ops = &gpio_backlight_ops, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 69 | .of_to_plat = gpio_backlight_of_to_plat, |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 70 | .probe = gpio_backlight_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 71 | .priv_auto = sizeof(struct gpio_backlight_priv), |
Patrick Delaunay | 5b6a6a9 | 2017-08-03 12:36:07 +0200 | [diff] [blame] | 72 | }; |