Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6aa801b | 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 | 6aa801b | 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 | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 6aa801b | 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 | 6aa801b | 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 | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 26 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
Simon Glass | 6aa801b | 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 | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 29 | debug("%s: done, ret = %d\n", __func__, ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
Simon Glass | fe68a45 | 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 | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 51 | static int simple_panel_of_to_plat(struct udevice *dev) |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 52 | { |
| 53 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 54 | int ret; |
| 55 | |
Marek Vasut | bbdd135 | 2023-02-28 02:55:22 +0100 | [diff] [blame^] | 56 | if (CONFIG_IS_ENABLED(DM_REGULATOR)) { |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 57 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 58 | "power-supply", &priv->reg); |
| 59 | if (ret) { |
Marcel Ziswiler | 07e0c27 | 2016-09-28 11:24:06 +0200 | [diff] [blame] | 60 | debug("%s: Warning: cannot get power supply: ret=%d\n", |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 61 | __func__, ret); |
| 62 | if (ret != -ENOENT) |
| 63 | return ret; |
| 64 | } |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 65 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 66 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 67 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 68 | "backlight", &priv->backlight); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 69 | if (ret) { |
| 70 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 71 | if (ret != -ENOENT) |
| 72 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 73 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 74 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 75 | ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, |
| 76 | GPIOD_IS_OUT); |
| 77 | if (ret) { |
| 78 | debug("%s: Warning: cannot get enable GPIO: ret=%d\n", |
| 79 | __func__, ret); |
| 80 | if (ret != -ENOENT) |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 81 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | static int simple_panel_probe(struct udevice *dev) |
| 88 | { |
| 89 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 90 | int ret; |
| 91 | |
Marek Vasut | bbdd135 | 2023-02-28 02:55:22 +0100 | [diff] [blame^] | 92 | if (CONFIG_IS_ENABLED(DM_REGULATOR) && priv->reg) { |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 93 | debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name); |
| 94 | ret = regulator_set_enable(priv->reg, true); |
| 95 | if (ret) |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | static const struct panel_ops simple_panel_ops = { |
| 103 | .enable_backlight = simple_panel_enable_backlight, |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 104 | .set_backlight = simple_panel_set_backlight, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static const struct udevice_id simple_panel_ids[] = { |
| 108 | { .compatible = "simple-panel" }, |
Simon Glass | fad7218 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 109 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 110 | { .compatible = "auo,b116xw03" }, |
| 111 | { .compatible = "auo,b133htn01" }, |
Peter Robinson | 6a0e7a6 | 2020-04-20 20:27:32 +0100 | [diff] [blame] | 112 | { .compatible = "boe,nv140fhmn49" }, |
Heiko Schocher | 8ab5d50 | 2019-05-27 08:14:39 +0200 | [diff] [blame] | 113 | { .compatible = "lg,lb070wv8" }, |
Alper Nebi Yasak | 641c7a2 | 2020-10-28 00:41:54 +0300 | [diff] [blame] | 114 | { .compatible = "sharp,lq123p1jx31" }, |
Alper Nebi Yasak | 4cdbb25 | 2020-10-28 00:41:55 +0300 | [diff] [blame] | 115 | { .compatible = "boe,nv101wxmn51" }, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 116 | { } |
| 117 | }; |
| 118 | |
| 119 | U_BOOT_DRIVER(simple_panel) = { |
| 120 | .name = "simple_panel", |
| 121 | .id = UCLASS_PANEL, |
| 122 | .of_match = simple_panel_ids, |
| 123 | .ops = &simple_panel_ops, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 124 | .of_to_plat = simple_panel_of_to_plat, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 125 | .probe = simple_panel_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 126 | .priv_auto = sizeof(struct simple_panel_priv), |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 127 | }; |