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