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