The positive and negative bias supplies of an NT36672E panel, AVDD and
AVEE, are not exposed by the panel modules, which generate the bias on
the module itself.

Split the supplies into the required VDDI supply and the pair of AVDD
and AVEE bias supplies, which are either both described or both absent,
and get the bias supplies only if they are described.

Signed-off-by: Vladimir Zapolskiy <[email protected]>
---
 .../gpu/drm/panel/panel-novatek-nt36672e.c    | 69 +++++++++++++------
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-novatek-nt36672e.c 
b/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
index c5e00eb55722..80934c6bf250 100644
--- a/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
+++ b/drivers/gpu/drm/panel/panel-novatek-nt36672e.c
@@ -13,16 +13,13 @@
 
 #include <video/mipi_display.h>
 
-static const char * const regulator_names[] = {
-       "vddi",
-       "avdd",
-       "avee",
+static const struct regulator_bulk_data nt36672e_supplies[] = {
+       { .supply = "vddi", .init_load_uA = 62000 },
 };
 
-static const unsigned long regulator_enable_loads[] = {
-       62000,
-       100000,
-       100000,
+static const struct regulator_bulk_data nt36672e_bias_supplies[] = {
+       { .supply = "avdd", .init_load_uA = 100000 },
+       { .supply = "avee", .init_load_uA = 100000 },
 };
 
 struct panel_desc {
@@ -40,7 +37,8 @@ struct nt36672e_panel {
        struct drm_panel panel;
        struct mipi_dsi_device *dsi;
        struct gpio_desc *reset_gpio;
-       struct regulator_bulk_data supplies[3];
+       struct regulator_bulk_data *supplies;
+       struct regulator_bulk_data *bias_supplies;
        const struct panel_desc *desc;
 };
 
@@ -362,12 +360,23 @@ static int nt36672e_power_on(struct nt36672e_panel *ctx)
        struct mipi_dsi_device *dsi = ctx->dsi;
        int ret;
 
-       ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+       ret = regulator_bulk_enable(ARRAY_SIZE(nt36672e_supplies), 
ctx->supplies);
        if (ret < 0) {
                dev_err(&dsi->dev, "regulator bulk enable failed: %d\n", ret);
                return ret;
        }
 
+       if (ctx->bias_supplies) {
+               ret = regulator_bulk_enable(ARRAY_SIZE(nt36672e_bias_supplies),
+                                           ctx->bias_supplies);
+               if (ret < 0) {
+                       dev_err(&dsi->dev, "bias regulator enable failed: 
%d\n", ret);
+                       regulator_bulk_disable(ARRAY_SIZE(nt36672e_supplies),
+                                              ctx->supplies);
+                       return ret;
+               }
+       }
+
        /*
         * Reset sequence of nt36672e panel requires the panel to be out of 
reset
         * for 10ms, followed by being held in reset for 10ms and then out 
again.
@@ -389,7 +398,14 @@ static int nt36672e_power_off(struct nt36672e_panel *ctx)
 
        gpiod_set_value(ctx->reset_gpio, 0);
 
-       ret = regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
+       if (ctx->bias_supplies) {
+               ret = regulator_bulk_disable(ARRAY_SIZE(nt36672e_bias_supplies),
+                                            ctx->bias_supplies);
+               if (ret)
+                       dev_err(&dsi->dev, "bias regulator disable failed: 
%d\n", ret);
+       }
+
+       ret = regulator_bulk_disable(ARRAY_SIZE(nt36672e_supplies), 
ctx->supplies);
        if (ret)
                dev_err(&dsi->dev, "regulator bulk disable failed: %d\n", ret);
 
@@ -520,7 +536,8 @@ static int nt36672e_panel_probe(struct mipi_dsi_device *dsi)
 {
        struct device *dev = &dsi->dev;
        struct nt36672e_panel *ctx;
-       int i, ret = 0;
+       bool avdd, avee;
+       int ret = 0;
 
        ctx = devm_drm_panel_alloc(dev, struct nt36672e_panel, panel,
                                   &nt36672e_drm_funcs,
@@ -534,15 +551,27 @@ static int nt36672e_panel_probe(struct mipi_dsi_device 
*dsi)
                return -ENODEV;
        }
 
-       for (i = 0; i < ARRAY_SIZE(ctx->supplies); i++) {
-               ctx->supplies[i].supply = regulator_names[i];
-               ctx->supplies[i].init_load_uA = regulator_enable_loads[i];
-       }
-
-       ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
-                       ctx->supplies);
+       ret = devm_regulator_bulk_get_const(dev, ARRAY_SIZE(nt36672e_supplies),
+                                           nt36672e_supplies, &ctx->supplies);
        if (ret < 0)
-               return ret;
+               return dev_err_probe(dev, ret, "Failed to get regulators\n");
+
+       /* The bias supplies are either both described or generated on the 
module */
+       avdd = of_property_present(dev->of_node, "avdd-supply");
+       avee = of_property_present(dev->of_node, "avee-supply");
+       if (avdd != avee)
+               return dev_err_probe(dev, -EINVAL,
+                                    "avdd and avee supplies must be described 
together\n");
+
+       if (avdd) {
+               ret = devm_regulator_bulk_get_const(dev,
+                                                   
ARRAY_SIZE(nt36672e_bias_supplies),
+                                                   nt36672e_bias_supplies,
+                                                   &ctx->bias_supplies);
+               if (ret < 0)
+                       return dev_err_probe(dev, ret,
+                                            "Failed to get bias regulators\n");
+       }
 
        ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
        if (IS_ERR(ctx->reset_gpio))
-- 
2.51.0

Reply via email to