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