Simon Glass | cd9c207 | 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 | |
| 28 | dm_gpio_set_value(&priv->enable, 1); |
| 29 | ret = backlight_enable(priv->backlight); |
| 30 | if (ret) |
| 31 | return ret; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static int simple_panel_ofdata_to_platdata(struct udevice *dev) |
| 37 | { |
| 38 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 39 | int ret; |
| 40 | |
Simon Glass | e23c6c2 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 41 | if (IS_ENABLED(CONFIG_DM_REGULATOR)) { |
| 42 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 43 | "power-supply", &priv->reg); |
| 44 | if (ret) { |
| 45 | debug("%s: Warning: cnnot get power supply: ret=%d\n", |
| 46 | __func__, ret); |
| 47 | if (ret != -ENOENT) |
| 48 | return ret; |
| 49 | } |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 50 | } |
| 51 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
| 52 | "backlight", &priv->backlight); |
| 53 | if (ret) { |
| 54 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
| 55 | return ret; |
| 56 | } |
| 57 | ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, |
| 58 | GPIOD_IS_OUT); |
| 59 | if (ret) { |
| 60 | debug("%s: Warning: cannot get enable GPIO: ret=%d\n", |
| 61 | __func__, ret); |
| 62 | if (ret != -ENOENT) |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static int simple_panel_probe(struct udevice *dev) |
| 70 | { |
| 71 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 72 | int ret; |
| 73 | |
Simon Glass | e23c6c2 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 74 | if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) { |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 75 | debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name); |
| 76 | ret = regulator_set_enable(priv->reg, true); |
| 77 | if (ret) |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static const struct panel_ops simple_panel_ops = { |
| 85 | .enable_backlight = simple_panel_enable_backlight, |
| 86 | }; |
| 87 | |
| 88 | static const struct udevice_id simple_panel_ids[] = { |
| 89 | { .compatible = "simple-panel" }, |
Simon Glass | d765921 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 90 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | cd9c207 | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 91 | { } |
| 92 | }; |
| 93 | |
| 94 | U_BOOT_DRIVER(simple_panel) = { |
| 95 | .name = "simple_panel", |
| 96 | .id = UCLASS_PANEL, |
| 97 | .of_match = simple_panel_ids, |
| 98 | .ops = &simple_panel_ops, |
| 99 | .ofdata_to_platdata = simple_panel_ofdata_to_platdata, |
| 100 | .probe = simple_panel_probe, |
| 101 | .priv_auto_alloc_size = sizeof(struct simple_panel_priv), |
| 102 | }; |