linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Archit Taneja <architt@codeaurora.org>
To: laurent.pinchart@ideasonboard.com
Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	Archit Taneja <architt@codeaurora.org>
Subject: [PATCH v5 2/2] drm/bridge: adv7511: Initialize regulators
Date: Wed, 11 Jan 2017 12:22:27 +0530	[thread overview]
Message-ID: <1484117547-26417-3-git-send-email-architt@codeaurora.org> (raw)
In-Reply-To: <1484117547-26417-1-git-send-email-architt@codeaurora.org>

Maintain a table of regulator names expected by ADV7511 and ADV7533.
Use regulator_bulk_* api to configure these.

Initialize and enable the regulators during probe itself. Controlling
these dynamically is left for later.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Archit Taneja <architt@codeaurora.org>
---
 drivers/gpu/drm/bridge/adv7511/adv7511.h     |  4 ++
 drivers/gpu/drm/bridge/adv7511/adv7511_drv.c | 86 +++++++++++++++++++++++++---
 2 files changed, 81 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511.h b/drivers/gpu/drm/bridge/adv7511/adv7511.h
index 0396791..fe18a5d 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511.h
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511.h
@@ -12,6 +12,7 @@
 #include <linux/hdmi.h>
 #include <linux/i2c.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 
 #include <drm/drm_crtc_helper.h>
 #include <drm/drm_mipi_dsi.h>
@@ -331,6 +332,9 @@ struct adv7511 {
 
 	struct gpio_desc *gpio_pd;
 
+	struct regulator_bulk_data *supplies;
+	unsigned int num_supplies;
+
 	/* ADV7533 DSI RX related params */
 	struct device_node *host_node;
 	struct mipi_dsi_device *dsi;
diff --git a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
index 24573e0..2f1aae7 100644
--- a/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
+++ b/drivers/gpu/drm/bridge/adv7511/adv7511_drv.c
@@ -859,6 +859,58 @@ static int adv7511_bridge_attach(struct drm_bridge *bridge)
  * Probe & remove
  */
 
+static const char * const adv7511_supply_names[] = {
+	"avdd",
+	"dvdd",
+	"pvdd",
+	"bgvdd",
+	"dvdd-3v",
+};
+
+static const char * const adv7533_supply_names[] = {
+	"avdd",
+	"dvdd",
+	"pvdd",
+	"a2vdd",
+	"v3p3",
+	"v1p2",
+};
+
+static int adv7511_init_regulators(struct adv7511 *adv)
+{
+	struct device *dev = &adv->i2c_main->dev;
+	const char * const *supply_names;
+	unsigned int i;
+	int ret;
+
+	if (adv->type == ADV7511) {
+		supply_names = adv7511_supply_names;
+		adv->num_supplies = ARRAY_SIZE(adv7511_supply_names);
+	} else {
+		supply_names = adv7533_supply_names;
+		adv->num_supplies = ARRAY_SIZE(adv7533_supply_names);
+	}
+
+	adv->supplies = devm_kcalloc(dev, adv->num_supplies,
+				     sizeof(*adv->supplies), GFP_KERNEL);
+	if (!adv->supplies)
+		return -ENOMEM;
+
+	for (i = 0; i < adv->num_supplies; i++)
+		adv->supplies[i].supply = supply_names[i];
+
+	ret = devm_regulator_bulk_get(dev, adv->num_supplies, adv->supplies);
+	if (ret)
+		return ret;
+
+	return regulator_bulk_enable(adv->num_supplies, adv->supplies);
+}
+
+static void adv7511_uninit_regulators(struct adv7511 *adv)
+{
+	regulator_bulk_disable(adv->num_supplies, adv->supplies);
+}
+
 static int adv7511_parse_dt(struct device_node *np,
 			    struct adv7511_link_config *config)
 {
@@ -959,6 +1011,7 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	if (!adv7511)
 		return -ENOMEM;
 
+	adv7511->i2c_main = i2c;
 	adv7511->powered = false;
 	adv7511->status = connector_status_disconnected;
 
@@ -976,13 +1029,21 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	if (ret)
 		return ret;
 
+	ret = adv7511_init_regulators(adv7511);
+	if (ret) {
+		dev_err(dev, "failed to init regulators\n");
+		return ret;
+	}
+
 	/*
 	 * The power down GPIO is optional. If present, toggle it from active to
 	 * inactive to wake up the encoder.
 	 */
 	adv7511->gpio_pd = devm_gpiod_get_optional(dev, "pd", GPIOD_OUT_HIGH);
-	if (IS_ERR(adv7511->gpio_pd))
-		return PTR_ERR(adv7511->gpio_pd);
+	if (IS_ERR(adv7511->gpio_pd)) {
+		ret = PTR_ERR(adv7511->gpio_pd);
+		goto uninit_regulators;
+	}
 
 	if (adv7511->gpio_pd) {
 		mdelay(5);
@@ -990,12 +1051,14 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	}
 
 	adv7511->regmap = devm_regmap_init_i2c(i2c, &adv7511_regmap_config);
-	if (IS_ERR(adv7511->regmap))
-		return PTR_ERR(adv7511->regmap);
+	if (IS_ERR(adv7511->regmap)) {
+		ret = PTR_ERR(adv7511->regmap);
+		goto uninit_regulators;
+	}
 
 	ret = regmap_read(adv7511->regmap, ADV7511_REG_CHIP_REVISION, &val);
 	if (ret)
-		return ret;
+		goto uninit_regulators;
 	dev_dbg(dev, "Rev. %d\n", val);
 
 	if (adv7511->type == ADV7511)
@@ -1005,7 +1068,7 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	else
 		ret = adv7533_patch_registers(adv7511);
 	if (ret)
-		return ret;
+		goto uninit_regulators;
 
 	regmap_write(adv7511->regmap, ADV7511_REG_EDID_I2C_ADDR, edid_i2c_addr);
 	regmap_write(adv7511->regmap, ADV7511_REG_PACKET_I2C_ADDR,
@@ -1015,10 +1078,11 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 
 	adv7511_packet_disable(adv7511, 0xffff);
 
-	adv7511->i2c_main = i2c;
 	adv7511->i2c_edid = i2c_new_dummy(i2c->adapter, edid_i2c_addr >> 1);
-	if (!adv7511->i2c_edid)
-		return -ENOMEM;
+	if (!adv7511->i2c_edid) {
+		ret = -ENOMEM;
+		goto uninit_regulators;
+	}
 
 	if (adv7511->type == ADV7533) {
 		ret = adv7533_init_cec(adv7511);
@@ -1067,6 +1131,8 @@ static int adv7511_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
 	adv7533_uninit_cec(adv7511);
 err_i2c_unregister_edid:
 	i2c_unregister_device(adv7511->i2c_edid);
+uninit_regulators:
+	adv7511_uninit_regulators(adv7511);
 
 	return ret;
 }
@@ -1080,6 +1146,8 @@ static int adv7511_remove(struct i2c_client *i2c)
 		adv7533_uninit_cec(adv7511);
 	}
 
+	adv7511_uninit_regulators(adv7511);
+
 	drm_bridge_remove(&adv7511->bridge);
 
 	adv7511_audio_exit(adv7511);
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

      parent reply	other threads:[~2017-01-11  6:52 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-31 10:52 [PATCH 0/3] arm64: apq8016-sbc: Enable regulators for ADV7533 Archit Taneja
     [not found] ` <1472640730-24326-1-git-send-email-architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-08-31 10:52   ` [PATCH 1/3] dt-bindings: drm/bridge: adv7511: Add " Archit Taneja
2016-09-02 15:56     ` Rob Herring
2016-09-06  4:22       ` Archit Taneja
2016-08-31 10:52 ` [PATCH 2/3] drm/bridge: adv7533: Initialize regulators Archit Taneja
2016-08-31 15:53   ` Laurent Pinchart
2016-08-31 16:54     ` Archit Taneja
2016-08-31 20:30       ` Laurent Pinchart
2016-09-01 10:09         ` Archit Taneja
2016-08-31 10:52 ` [PATCH 3/3] arm64: dts: apq8016-sbc: Set up LDO2, LDO6 and LDO17 regulator voltage ranges Archit Taneja
2016-08-31 20:54   ` Stephen Boyd
2016-09-01  6:12     ` Archit Taneja
2016-09-02  3:47     ` Bjorn Andersson
2016-09-23  9:20 ` [PATCH v2 0/4] arm64: apq8016-sbc: Enable regulators for ADV7533 Archit Taneja
2016-09-23  9:20   ` [PATCH v2 1/4] dt-bindings: drm/bridge: adv7511: Add regulator bindings Archit Taneja
2016-09-23 22:31     ` Rob Herring
     [not found]     ` <1474622430-6704-2-git-send-email-architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-09-25 17:28       ` Laurent Pinchart
2016-09-26  6:40         ` Archit Taneja
2016-09-26  8:12           ` Laurent Pinchart
2016-10-14  5:40             ` Archit Taneja
2016-11-10  1:34               ` Rob Herring
     [not found]                 ` <CAL_Jsq+KMPoyWvh1U3OKL6pX8D4QByqVFgcMks8myDfZEYeFCg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-11-15  3:35                   ` Archit Taneja
2016-09-23  9:20   ` [PATCH v2 2/4] drm/bridge: adv7511: Initialize regulators Archit Taneja
2016-09-25 17:35     ` Laurent Pinchart
2016-09-26  6:40       ` Archit Taneja
2016-09-23  9:20   ` [PATCH v2 3/4] arm64: dts: apq8016-sbc: Add some missing regulator supplies for ADV7533 Archit Taneja
2016-09-23  9:20   ` [PATCH v2 4/4] arm64: dts: apq8016-sbc: Set up LDO2, LDO6 and LDO17 regulator voltage ranges Archit Taneja
2016-11-29  6:07   ` [PATCH v3 0/2] drm/bridge: adv7511: Enable regulators Archit Taneja
     [not found]     ` <1480399662-8858-1-git-send-email-architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-29  6:07       ` [PATCH v3 1/2] dt-bindings: drm/bridge: adv7511: Add regulator bindings Archit Taneja
     [not found]         ` <1480399662-8858-2-git-send-email-architt-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2016-11-29  6:33           ` Laurent Pinchart
2016-11-29  8:11             ` Archit Taneja
2016-11-29  9:11               ` Laurent Pinchart
2016-11-29 11:01                 ` Mark Brown
2016-11-29 19:37                   ` Laurent Pinchart
2016-11-30 16:14                     ` Mark Brown
2016-12-05 21:11                 ` Bjorn Andersson
2016-12-05 21:16                   ` Laurent Pinchart
2016-12-06 10:05                     ` Mark Brown
2016-12-06 12:46                       ` Laurent Pinchart
2016-12-06 13:20                         ` Mark Brown
2016-12-06 16:08                           ` Laurent Pinchart
2016-12-06 16:11                             ` Mark Brown
2016-11-29  6:07     ` [PATCH v3 2/2] drm/bridge: adv7511: Initialize regulators Archit Taneja
2016-11-29  6:28       ` Laurent Pinchart
2016-12-05  7:53     ` [PATCH v4 0/2] drm/bridge: adv7511: Enable regulators Archit Taneja
2016-12-05  7:53       ` [PATCH v4 1/2] dt-bindings: drm/bridge: adv7511: Add regulator bindings Archit Taneja
2016-12-09 22:11         ` Rob Herring
2016-12-18 11:17           ` Archit Taneja
2016-12-05  7:53       ` [PATCH v4 2/2] drm/bridge: adv7511: Initialize regulators Archit Taneja
2017-01-11  6:52       ` [PATCH v5 0/2] drm/bridge: adv7511: Enable regulators Archit Taneja
2017-01-11  6:52         ` [PATCH v5 1/2] dt-bindings: drm/bridge: adv7511: Add regulator bindings Archit Taneja
2017-01-11  6:52         ` Archit Taneja [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1484117547-26417-3-git-send-email-architt@codeaurora.org \
    --to=architt@codeaurora.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-msm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).