Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <backlight.h> |
| 9 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 11 | #include <panel.h> |
| 12 | #include <asm/gpio.h> |
| 13 | #include <power/regulator.h> |
| 14 | |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 15 | struct simple_panel_priv { |
| 16 | struct udevice *reg; |
| 17 | struct udevice *backlight; |
| 18 | struct gpio_desc enable; |
| 19 | }; |
| 20 | |
| 21 | static int simple_panel_enable_backlight(struct udevice *dev) |
| 22 | { |
| 23 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 24 | int ret; |
| 25 | |
Simon Glass | 1a9f3da | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 26 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 27 | dm_gpio_set_value(&priv->enable, 1); |
| 28 | ret = backlight_enable(priv->backlight); |
Simon Glass | 1a9f3da | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 29 | debug("%s: done, ret = %d\n", __func__, ret); |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
Simon Glass | a4f737a | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 36 | static int simple_panel_set_backlight(struct udevice *dev, int percent) |
| 37 | { |
| 38 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 39 | int ret; |
| 40 | |
| 41 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
| 42 | dm_gpio_set_value(&priv->enable, 1); |
| 43 | ret = backlight_set_brightness(priv->backlight, percent); |
| 44 | debug("%s: done, ret = %d\n", __func__, ret); |
| 45 | if (ret) |
| 46 | return ret; |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 51 | static int simple_panel_of_to_plat(struct udevice *dev) |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 52 | { |
| 53 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 54 | int ret; |
| 55 | |
Simon Glass | e23c6c2 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 56 | if (IS_ENABLED(CONFIG_DM_REGULATOR)) { |
| 57 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 58 | "power-supply", &priv->reg); |
| 59 | if (ret) { |
Marcel Ziswiler | 28c694c | 2016-09-28 11:24:06 +0200 | [diff] [blame] | 60 | debug("%s: Warning: cannot get power supply: ret=%d\n", |
Simon Glass | e23c6c2 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 61 | __func__, ret); |
| 62 | if (ret != -ENOENT) |
| 63 | return ret; |
| 64 | } |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 65 | } |
| 66 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
| 67 | "backlight", &priv->backlight); |
| 68 | if (ret) { |
| 69 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
Simon Glass | a4f737a | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 70 | return log_ret(ret); |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 71 | } |
| 72 | ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, |
| 73 | GPIOD_IS_OUT); |
| 74 | if (ret) { |
| 75 | debug("%s: Warning: cannot get enable GPIO: ret=%d\n", |
| 76 | __func__, ret); |
| 77 | if (ret != -ENOENT) |
Simon Glass | a4f737a | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 78 | return log_ret(ret); |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static int simple_panel_probe(struct udevice *dev) |
| 85 | { |
| 86 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 87 | int ret; |
| 88 | |
Simon Glass | e23c6c2 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 89 | if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) { |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 90 | debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name); |
| 91 | ret = regulator_set_enable(priv->reg, true); |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static const struct panel_ops simple_panel_ops = { |
| 100 | .enable_backlight = simple_panel_enable_backlight, |
Simon Glass | a4f737a | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 101 | .set_backlight = simple_panel_set_backlight, |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | static const struct udevice_id simple_panel_ids[] = { |
| 105 | { .compatible = "simple-panel" }, |
Simon Glass | d765921 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 106 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | bb5930d | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 107 | { .compatible = "auo,b116xw03" }, |
| 108 | { .compatible = "auo,b133htn01" }, |
Peter Robinson | ea16637 | 2020-04-20 20:27:32 +0100 | [diff] [blame] | 109 | { .compatible = "boe,nv140fhmn49" }, |
Heiko Schocher | 85288ff | 2019-05-27 08:14:39 +0200 | [diff] [blame] | 110 | { .compatible = "lg,lb070wv8" }, |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 111 | { } |
| 112 | }; |
| 113 | |
| 114 | U_BOOT_DRIVER(simple_panel) = { |
| 115 | .name = "simple_panel", |
| 116 | .id = UCLASS_PANEL, |
| 117 | .of_match = simple_panel_ids, |
| 118 | .ops = &simple_panel_ops, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 119 | .of_to_plat = simple_panel_of_to_plat, |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 120 | .probe = simple_panel_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 121 | .priv_auto = sizeof(struct simple_panel_priv), |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 122 | }; |