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> |
| 10 | #include <panel.h> |
| 11 | #include <asm/gpio.h> |
| 12 | #include <power/regulator.h> |
| 13 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 14 | struct simple_panel_priv { |
| 15 | struct udevice *reg; |
| 16 | struct udevice *backlight; |
| 17 | struct gpio_desc enable; |
| 18 | }; |
| 19 | |
| 20 | static int simple_panel_enable_backlight(struct udevice *dev) |
| 21 | { |
| 22 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 23 | int ret; |
| 24 | |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 25 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 26 | dm_gpio_set_value(&priv->enable, 1); |
| 27 | ret = backlight_enable(priv->backlight); |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 28 | debug("%s: done, ret = %d\n", __func__, ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 29 | if (ret) |
| 30 | return ret; |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 35 | static int simple_panel_set_backlight(struct udevice *dev, int percent) |
| 36 | { |
| 37 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 38 | int ret; |
| 39 | |
| 40 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
| 41 | dm_gpio_set_value(&priv->enable, 1); |
| 42 | ret = backlight_set_brightness(priv->backlight, percent); |
| 43 | debug("%s: done, ret = %d\n", __func__, ret); |
| 44 | if (ret) |
| 45 | return ret; |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 50 | static int simple_panel_ofdata_to_platdata(struct udevice *dev) |
| 51 | { |
| 52 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 53 | int ret; |
| 54 | |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 55 | if (IS_ENABLED(CONFIG_DM_REGULATOR)) { |
| 56 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 57 | "power-supply", &priv->reg); |
| 58 | if (ret) { |
Marcel Ziswiler | 07e0c27 | 2016-09-28 11:24:06 +0200 | [diff] [blame] | 59 | debug("%s: Warning: cannot get power supply: ret=%d\n", |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 60 | __func__, ret); |
| 61 | if (ret != -ENOENT) |
| 62 | return ret; |
| 63 | } |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 64 | } |
| 65 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
| 66 | "backlight", &priv->backlight); |
| 67 | if (ret) { |
| 68 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 69 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 70 | } |
| 71 | ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, |
| 72 | GPIOD_IS_OUT); |
| 73 | if (ret) { |
| 74 | debug("%s: Warning: cannot get enable GPIO: ret=%d\n", |
| 75 | __func__, ret); |
| 76 | if (ret != -ENOENT) |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 77 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int simple_panel_probe(struct udevice *dev) |
| 84 | { |
| 85 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 86 | int ret; |
| 87 | |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 88 | if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) { |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 89 | debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name); |
| 90 | ret = regulator_set_enable(priv->reg, true); |
| 91 | if (ret) |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | static const struct panel_ops simple_panel_ops = { |
| 99 | .enable_backlight = simple_panel_enable_backlight, |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 100 | .set_backlight = simple_panel_set_backlight, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static const struct udevice_id simple_panel_ids[] = { |
| 104 | { .compatible = "simple-panel" }, |
Simon Glass | fad7218 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 105 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 106 | { .compatible = "auo,b116xw03" }, |
| 107 | { .compatible = "auo,b133htn01" }, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 108 | { } |
| 109 | }; |
| 110 | |
| 111 | U_BOOT_DRIVER(simple_panel) = { |
| 112 | .name = "simple_panel", |
| 113 | .id = UCLASS_PANEL, |
| 114 | .of_match = simple_panel_ids, |
| 115 | .ops = &simple_panel_ops, |
| 116 | .ofdata_to_platdata = simple_panel_ofdata_to_platdata, |
| 117 | .probe = simple_panel_probe, |
| 118 | .priv_auto_alloc_size = sizeof(struct simple_panel_priv), |
| 119 | }; |