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