2021-02-24 12:54:45

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 2/2] drm/bridge: anx7625: disable regulators when power off

When suspending the driver, anx7625_power_standby() will be called to
turn off reset-gpios and enable-gpios. However, power supplies are not
disabled. To save power, the driver can get the power supply regulators
and turn off them in anx7625_power_standby().

Signed-off-by: Hsin-Yi Wang <[email protected]>
Reviewed-by: Robert Foss <[email protected]>
---
drivers/gpu/drm/bridge/analogix/anx7625.c | 34 +++++++++++++++++++++++
drivers/gpu/drm/bridge/analogix/anx7625.h | 1 +
2 files changed, 35 insertions(+)

diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
index 65cc05982f826..23283ba0c4f93 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.c
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
@@ -11,6 +11,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/workqueue.h>
@@ -875,12 +876,25 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
static void anx7625_power_on(struct anx7625_data *ctx)
{
struct device *dev = &ctx->client->dev;
+ int ret, i;

if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
return;
}

+ for (i = 0; i < ARRAY_SIZE(ctx->pdata.supplies); i++) {
+ ret = regulator_enable(ctx->pdata.supplies[i].consumer);
+ if (ret < 0) {
+ DRM_DEV_DEBUG_DRIVER(dev, "cannot enable supply %d: %d\n",
+ i, ret);
+ goto reg_err;
+ }
+ usleep_range(2000, 2100);
+ }
+
+ usleep_range(4000, 4100);
+
/* Power on pin enable */
gpiod_set_value(ctx->pdata.gpio_p_on, 1);
usleep_range(10000, 11000);
@@ -889,11 +903,16 @@ static void anx7625_power_on(struct anx7625_data *ctx)
usleep_range(10000, 11000);

DRM_DEV_DEBUG_DRIVER(dev, "power on !\n");
+ return;
+reg_err:
+ for (--i; i >= 0; i--)
+ regulator_disable(ctx->pdata.supplies[i].consumer);
}

static void anx7625_power_standby(struct anx7625_data *ctx)
{
struct device *dev = &ctx->client->dev;
+ int ret;

if (!ctx->pdata.low_power_mode) {
DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
@@ -904,6 +923,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx)
usleep_range(1000, 1100);
gpiod_set_value(ctx->pdata.gpio_p_on, 0);
usleep_range(1000, 1100);
+
+ ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies),
+ ctx->pdata.supplies);
+ if (ret < 0)
+ DRM_DEV_DEBUG_DRIVER(dev, "cannot disable supplies %d\n", ret);
+
DRM_DEV_DEBUG_DRIVER(dev, "power down\n");
}

@@ -1742,6 +1767,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
platform->client = client;
i2c_set_clientdata(client, platform);

+ pdata->supplies[0].supply = "vdd10";
+ pdata->supplies[1].supply = "vdd18";
+ pdata->supplies[2].supply = "vdd33";
+ ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies),
+ pdata->supplies);
+ if (ret) {
+ DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret);
+ return ret;
+ }
anx7625_init_gpio(platform);

atomic_set(&platform->power_status, 0);
diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h
index 193ad86c54503..e4a086b3a3d7b 100644
--- a/drivers/gpu/drm/bridge/analogix/anx7625.h
+++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
@@ -350,6 +350,7 @@ struct s_edid_data {
struct anx7625_platform_data {
struct gpio_desc *gpio_p_on;
struct gpio_desc *gpio_reset;
+ struct regulator_bulk_data supplies[3];
struct drm_bridge *panel_bridge;
int intp_irq;
u32 low_power_mode;
--
2.30.1.766.gb4fecdf3b7-goog


2021-03-18 04:35:01

by Hsin-Yi Wang

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] drm/bridge: anx7625: disable regulators when power off

On Wed, Feb 24, 2021 at 2:14 PM Hsin-Yi Wang <[email protected]> wrote:
>
> When suspending the driver, anx7625_power_standby() will be called to
> turn off reset-gpios and enable-gpios. However, power supplies are not
> disabled. To save power, the driver can get the power supply regulators
> and turn off them in anx7625_power_standby().
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> Reviewed-by: Robert Foss <[email protected]>
> ---

Ping on the thread, thanks.

> drivers/gpu/drm/bridge/analogix/anx7625.c | 34 +++++++++++++++++++++++
> drivers/gpu/drm/bridge/analogix/anx7625.h | 1 +
> 2 files changed, 35 insertions(+)
>
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
> index 65cc05982f826..23283ba0c4f93 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> @@ -11,6 +11,7 @@
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/mutex.h>
> +#include <linux/regulator/consumer.h>
> #include <linux/slab.h>
> #include <linux/types.h>
> #include <linux/workqueue.h>
> @@ -875,12 +876,25 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
> static void anx7625_power_on(struct anx7625_data *ctx)
> {
> struct device *dev = &ctx->client->dev;
> + int ret, i;
>
> if (!ctx->pdata.low_power_mode) {
> DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
> return;
> }
>
> + for (i = 0; i < ARRAY_SIZE(ctx->pdata.supplies); i++) {
> + ret = regulator_enable(ctx->pdata.supplies[i].consumer);
> + if (ret < 0) {
> + DRM_DEV_DEBUG_DRIVER(dev, "cannot enable supply %d: %d\n",
> + i, ret);
> + goto reg_err;
> + }
> + usleep_range(2000, 2100);
> + }
> +
> + usleep_range(4000, 4100);
> +
> /* Power on pin enable */
> gpiod_set_value(ctx->pdata.gpio_p_on, 1);
> usleep_range(10000, 11000);
> @@ -889,11 +903,16 @@ static void anx7625_power_on(struct anx7625_data *ctx)
> usleep_range(10000, 11000);
>
> DRM_DEV_DEBUG_DRIVER(dev, "power on !\n");
> + return;
> +reg_err:
> + for (--i; i >= 0; i--)
> + regulator_disable(ctx->pdata.supplies[i].consumer);
> }
>
> static void anx7625_power_standby(struct anx7625_data *ctx)
> {
> struct device *dev = &ctx->client->dev;
> + int ret;
>
> if (!ctx->pdata.low_power_mode) {
> DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
> @@ -904,6 +923,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx)
> usleep_range(1000, 1100);
> gpiod_set_value(ctx->pdata.gpio_p_on, 0);
> usleep_range(1000, 1100);
> +
> + ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies),
> + ctx->pdata.supplies);
> + if (ret < 0)
> + DRM_DEV_DEBUG_DRIVER(dev, "cannot disable supplies %d\n", ret);
> +
> DRM_DEV_DEBUG_DRIVER(dev, "power down\n");
> }
>
> @@ -1742,6 +1767,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
> platform->client = client;
> i2c_set_clientdata(client, platform);
>
> + pdata->supplies[0].supply = "vdd10";
> + pdata->supplies[1].supply = "vdd18";
> + pdata->supplies[2].supply = "vdd33";
> + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies),
> + pdata->supplies);
> + if (ret) {
> + DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret);
> + return ret;
> + }
> anx7625_init_gpio(platform);
>
> atomic_set(&platform->power_status, 0);
> diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h
> index 193ad86c54503..e4a086b3a3d7b 100644
> --- a/drivers/gpu/drm/bridge/analogix/anx7625.h
> +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
> @@ -350,6 +350,7 @@ struct s_edid_data {
> struct anx7625_platform_data {
> struct gpio_desc *gpio_p_on;
> struct gpio_desc *gpio_reset;
> + struct regulator_bulk_data supplies[3];
> struct drm_bridge *panel_bridge;
> int intp_irq;
> u32 low_power_mode;
> --
> 2.30.1.766.gb4fecdf3b7-goog
>

2021-03-19 02:51:26

by Xin Ji

[permalink] [raw]
Subject: Re: [PATCH v4 2/2] drm/bridge: anx7625: disable regulators when power off

On Thu, Mar 18, 2021 at 12:26:25PM +0800, Hsin-Yi Wang wrote:
> On Wed, Feb 24, 2021 at 2:14 PM Hsin-Yi Wang <[email protected]> wrote:
> >
> > When suspending the driver, anx7625_power_standby() will be called to
> > turn off reset-gpios and enable-gpios. However, power supplies are not
> > disabled. To save power, the driver can get the power supply regulators
> > and turn off them in anx7625_power_standby().
> >
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > Reviewed-by: Robert Foss <[email protected]>
> > ---
Hi Hsin-Yi, it's OK for me, please add my r-b.
Reviewed-by: Xin Ji <[email protected]>

Thanks,
Xin
>
> Ping on the thread, thanks.
>
> > drivers/gpu/drm/bridge/analogix/anx7625.c | 34 +++++++++++++++++++++++
> > drivers/gpu/drm/bridge/analogix/anx7625.h | 1 +
> > 2 files changed, 35 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.c b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > index 65cc05982f826..23283ba0c4f93 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.c
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.c
> > @@ -11,6 +11,7 @@
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/mutex.h>
> > +#include <linux/regulator/consumer.h>
> > #include <linux/slab.h>
> > #include <linux/types.h>
> > #include <linux/workqueue.h>
> > @@ -875,12 +876,25 @@ static int sp_tx_edid_read(struct anx7625_data *ctx,
> > static void anx7625_power_on(struct anx7625_data *ctx)
> > {
> > struct device *dev = &ctx->client->dev;
> > + int ret, i;
> >
> > if (!ctx->pdata.low_power_mode) {
> > DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
> > return;
> > }
> >
> > + for (i = 0; i < ARRAY_SIZE(ctx->pdata.supplies); i++) {
> > + ret = regulator_enable(ctx->pdata.supplies[i].consumer);
> > + if (ret < 0) {
> > + DRM_DEV_DEBUG_DRIVER(dev, "cannot enable supply %d: %d\n",
> > + i, ret);
> > + goto reg_err;
> > + }
> > + usleep_range(2000, 2100);
> > + }
> > +
> > + usleep_range(4000, 4100);
> > +
> > /* Power on pin enable */
> > gpiod_set_value(ctx->pdata.gpio_p_on, 1);
> > usleep_range(10000, 11000);
> > @@ -889,11 +903,16 @@ static void anx7625_power_on(struct anx7625_data *ctx)
> > usleep_range(10000, 11000);
> >
> > DRM_DEV_DEBUG_DRIVER(dev, "power on !\n");
> > + return;
> > +reg_err:
> > + for (--i; i >= 0; i--)
> > + regulator_disable(ctx->pdata.supplies[i].consumer);
> > }
> >
> > static void anx7625_power_standby(struct anx7625_data *ctx)
> > {
> > struct device *dev = &ctx->client->dev;
> > + int ret;
> >
> > if (!ctx->pdata.low_power_mode) {
> > DRM_DEV_DEBUG_DRIVER(dev, "not low power mode!\n");
> > @@ -904,6 +923,12 @@ static void anx7625_power_standby(struct anx7625_data *ctx)
> > usleep_range(1000, 1100);
> > gpiod_set_value(ctx->pdata.gpio_p_on, 0);
> > usleep_range(1000, 1100);
> > +
> > + ret = regulator_bulk_disable(ARRAY_SIZE(ctx->pdata.supplies),
> > + ctx->pdata.supplies);
> > + if (ret < 0)
> > + DRM_DEV_DEBUG_DRIVER(dev, "cannot disable supplies %d\n", ret);
> > +
> > DRM_DEV_DEBUG_DRIVER(dev, "power down\n");
> > }
> >
> > @@ -1742,6 +1767,15 @@ static int anx7625_i2c_probe(struct i2c_client *client,
> > platform->client = client;
> > i2c_set_clientdata(client, platform);
> >
> > + pdata->supplies[0].supply = "vdd10";
> > + pdata->supplies[1].supply = "vdd18";
> > + pdata->supplies[2].supply = "vdd33";
> > + ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(pdata->supplies),
> > + pdata->supplies);
> > + if (ret) {
> > + DRM_DEV_ERROR(dev, "fail to get power supplies: %d\n", ret);
> > + return ret;
> > + }
> > anx7625_init_gpio(platform);
> >
> > atomic_set(&platform->power_status, 0);
> > diff --git a/drivers/gpu/drm/bridge/analogix/anx7625.h b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > index 193ad86c54503..e4a086b3a3d7b 100644
> > --- a/drivers/gpu/drm/bridge/analogix/anx7625.h
> > +++ b/drivers/gpu/drm/bridge/analogix/anx7625.h
> > @@ -350,6 +350,7 @@ struct s_edid_data {
> > struct anx7625_platform_data {
> > struct gpio_desc *gpio_p_on;
> > struct gpio_desc *gpio_reset;
> > + struct regulator_bulk_data supplies[3];
> > struct drm_bridge *panel_bridge;
> > int intp_irq;
> > u32 low_power_mode;
> > --
> > 2.30.1.766.gb4fecdf3b7-goog
> >