public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yadwinder Singh Brar <yadi.brar@samsung.com>
To: linux-kernel@vger.kernel.org
Cc: yadi.brar01@gmail.com, sbkim73@samsung.com, broonie@kernel.org,
	lgirdwood@gmail.com, sameo@linux.intel.com,
	rob.herring@calxeda.com, grant.likely@linaro.org,
	Yadwinder Singh Brar <yadi.brar@samsung.com>
Subject: [PATCH 4/4] regulator: s2mps11: Add device tree support
Date: Mon, 24 Jun 2013 16:50:58 +0530	[thread overview]
Message-ID: <1372072858-6559-5-git-send-email-yadi.brar@samsung.com> (raw)
In-Reply-To: <1372072858-6559-1-git-send-email-yadi.brar@samsung.com>

This patch adds device tree support. It parses parent's node to get regulator
constraints. This patch also rearrange code little bit.

Signed-off-by: Yadwinder Singh Brar <yadi.brar@samsung.com>
---
 drivers/regulator/s2mps11.c |  116 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 104 insertions(+), 12 deletions(-)

diff --git a/drivers/regulator/s2mps11.c b/drivers/regulator/s2mps11.c
index d42ad2a..559ad7b 100644
--- a/drivers/regulator/s2mps11.c
+++ b/drivers/regulator/s2mps11.c
@@ -20,9 +20,12 @@
 #include <linux/platform_device.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
 #include <linux/mfd/samsung/core.h>
 #include <linux/mfd/samsung/s2mps11.h>
 
+#define S2MPS11_REGULATOR_CNT ARRAY_SIZE(regulators)
+
 struct s2mps11_info {
 	struct regulator_dev *rdev[S2MPS11_REGULATOR_MAX];
 
@@ -287,26 +290,107 @@ static struct regulator_desc regulators[] = {
 	regulator_desc_buck10,
 };
 
+static void s2mps11_pmic_set_buck_ramp(struct regulator_init_data *init_data,
+					struct s2mps11_info *s2mps11, int id)
+{
+	unsigned int ramp_rate;
+
+	if (!init_data)
+		return;
+
+	ramp_rate = init_data->constraints.ramp_delay;
+
+	switch (id) {
+	case S2MPS11_BUCK2:
+		s2mps11->ramp_delay2 = ramp_rate;
+		break;
+	case S2MPS11_BUCK3:
+	case S2MPS11_BUCK4:
+		if (ramp_rate > s2mps11->ramp_delay34)
+			s2mps11->ramp_delay34 = ramp_rate;
+		break;
+	case S2MPS11_BUCK5:
+		s2mps11->ramp_delay5 = ramp_rate;
+		break;
+	case S2MPS11_BUCK1:
+	case S2MPS11_BUCK6:
+		if (ramp_rate > s2mps11->ramp_delay16)
+			s2mps11->ramp_delay16 = ramp_rate;
+		break;
+	case S2MPS11_BUCK7:
+	case S2MPS11_BUCK8:
+	case S2MPS11_BUCK10:
+		if (ramp_rate > s2mps11->ramp_delay7810)
+			s2mps11->ramp_delay7810 = ramp_rate;
+		break;
+	case S2MPS11_BUCK9:
+		s2mps11->ramp_delay9 = ramp_rate;
+	}
+}
+
+static void s2mps11_pmic_parse_dt(struct of_regulator_match *rdata,
+					struct s2mps11_info *s2mps11)
+{
+	if (!of_find_property(rdata[S2MPS11_BUCK2].of_node,
+				"regulator-ramp-disable", NULL))
+		s2mps11->buck2_ramp = true;
+
+	if (!of_find_property(rdata[S2MPS11_BUCK3].of_node,
+				"regulator-ramp-disable", NULL))
+		s2mps11->buck3_ramp = true;
+
+	if (!of_find_property(rdata[S2MPS11_BUCK4].of_node,
+				"regulator-ramp-disable", NULL))
+		s2mps11->buck4_ramp = true;
+
+	if (!of_find_property(rdata[S2MPS11_BUCK6].of_node,
+				"regulator-ramp-disable", NULL))
+		s2mps11->buck6_ramp = true;
+}
+
 static int s2mps11_pmic_probe(struct platform_device *pdev)
 {
 	struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);
 	struct sec_platform_data *pdata = dev_get_platdata(iodev->dev);
+	struct of_regulator_match rdata[S2MPS11_REGULATOR_MAX];
+	struct device_node *reg_np = NULL;
 	struct regulator_config config = { };
 	struct s2mps11_info *s2mps11;
-	int i, ret;
+	int i, id, ret;
 	unsigned char ramp_enable, ramp_reg = 0;
 
-	if (!pdata) {
-		dev_err(pdev->dev.parent, "Platform data not supplied\n");
-		return -ENODEV;
-	}
-
 	s2mps11 = devm_kzalloc(&pdev->dev, sizeof(struct s2mps11_info),
 				GFP_KERNEL);
 	if (!s2mps11)
 		return -ENOMEM;
 
-	platform_set_drvdata(pdev, s2mps11);
+	if (iodev->dev->of_node)
+		goto p_data;
+
+	for (i = 0; i < S2MPS11_REGULATOR_CNT; i++) {
+		id = regulators[i].id;
+		rdata[id].name = regulators[i].name;
+	}
+
+	reg_np = of_find_node_by_name(iodev->dev->of_node, "regulators");
+	if (!reg_np) {
+		dev_err(&pdev->dev, "could not find regulators sub-node\n");
+		return -EINVAL;
+	}
+
+	of_regulator_match(&pdev->dev, reg_np, rdata, S2MPS11_REGULATOR_MAX);
+
+	s2mps11_pmic_parse_dt(rdata, s2mps11);
+
+	for (id = S2MPS11_BUCK1; id <= S2MPS11_BUCK9; id++)
+		s2mps11_pmic_set_buck_ramp(rdata[id].init_data, s2mps11, id);
+
+	goto set_ramp;
+p_data:
+	if (!pdata) {
+		dev_err(pdev->dev.parent, "Platform data not supplied\n");
+		return -ENODEV;
+	}
 
 	s2mps11->ramp_delay2 = pdata->buck2_ramp_delay;
 	s2mps11->ramp_delay34 = pdata->buck34_ramp_delay;
@@ -320,6 +404,7 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 	s2mps11->buck3_ramp = pdata->buck3_ramp_enable;
 	s2mps11->buck4_ramp = pdata->buck4_ramp_enable;
 
+set_ramp:
 	ramp_enable = (s2mps11->buck2_ramp << 3) | (s2mps11->buck3_ramp << 2) |
 		(s2mps11->buck4_ramp << 1) | s2mps11->buck6_ramp ;
 
@@ -338,12 +423,19 @@ static int s2mps11_pmic_probe(struct platform_device *pdev)
 	ramp_reg |= get_ramp_delay(s2mps11->ramp_delay9);
 	sec_reg_write(iodev, S2MPS11_REG_RAMP_BUCK, ramp_reg);
 
-	for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
+	platform_set_drvdata(pdev, s2mps11);
 
-		config.dev = &pdev->dev;
-		config.regmap = iodev->regmap;
-		config.init_data = pdata->regulators[i].initdata;
-		config.driver_data = s2mps11;
+	config.dev = &pdev->dev;
+	config.regmap = iodev->regmap;
+	config.driver_data = s2mps11;
+	for (i = 0; i < S2MPS11_REGULATOR_MAX; i++) {
+		if (reg_np) {
+			config.init_data = pdata->regulators[i].initdata;
+		} else {
+			id = regulators[i].id;
+			config.init_data = rdata[id].init_data;
+			config.of_node = rdata[id].of_node;
+		}
 
 		s2mps11->rdev[i] = regulator_register(&regulators[i], &config);
 		if (IS_ERR(s2mps11->rdev[i])) {
-- 
1.7.0.4


  parent reply	other threads:[~2013-07-03 11:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-24 11:20 [PATCH 0/4] Add DT support for s2mps11 Yadwinder Singh Brar
2013-06-24 11:20 ` [PATCH 1/4] regulator: s2mps11: Convert ramp rate to uV/us and set default ramp rate Yadwinder Singh Brar
2013-07-03 17:51   ` Mark Brown
2013-06-24 11:20 ` [PATCH 2/4] regulator: s2mps11: Implement set_voltage_time_sel() ops for bucks Yadwinder Singh Brar
2013-07-03 11:55   ` Sachin Kamat
2013-07-03 12:31     ` Yadwinder Singh Brar
2013-07-03 17:55   ` Mark Brown
2013-06-24 11:20 ` [PATCH 3/4] mfd: s2mps11: Add device tree support Yadwinder Singh Brar
2013-07-03 11:46   ` Sachin Kamat
2013-07-03 18:05   ` Mark Brown
2013-07-04  5:07     ` Yadwinder Singh Brar
2013-07-04  9:22       ` Mark Brown
2013-07-04 11:43         ` Yadwinder Singh Brar
2013-07-04 14:51           ` Mark Brown
2013-06-24 11:20 ` Yadwinder Singh Brar [this message]
2013-07-03 11:53   ` [PATCH 4/4] regulator: " Sachin Kamat
2013-07-03 12:45     ` Yadwinder Singh Brar
2013-07-03 18:00   ` Mark Brown
2013-07-04  5:14     ` Yadwinder Singh Brar
2013-07-04  9:23       ` Mark Brown

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=1372072858-6559-5-git-send-email-yadi.brar@samsung.com \
    --to=yadi.brar@samsung.com \
    --cc=broonie@kernel.org \
    --cc=grant.likely@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rob.herring@calxeda.com \
    --cc=sameo@linux.intel.com \
    --cc=sbkim73@samsung.com \
    --cc=yadi.brar01@gmail.com \
    /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