linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 09/18] regulator: ab8500: Split up probe() into manageable pieces
Date: Thu, 17 May 2012 14:45:14 +0100	[thread overview]
Message-ID: <1337262323-27692-10-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1337262323-27692-1-git-send-email-lee.jones@linaro.org>

ab8500's probe() function is becoming quite large, so in the lead
up to Device Tree enablement which will fork the thread of execution
this patch splits it into 3 main areas; basic error checking will
remain in probe(), but regulator register initialisation and regulator
registration have been moved to their own functions which will
be called in sequence by probe() and the DT equivalent.

Cc: linux-kernel at vger.kernel.org
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/regulator/ab8500.c |  150 +++++++++++++++++++++++++-------------------
 1 file changed, 87 insertions(+), 63 deletions(-)

diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index d156390..3571b54 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -708,11 +708,92 @@ static struct ab8500_reg_init ab8500_reg_init[] = {
 	REG_INIT(AB8500_REGUCTRLDISCH2,		0x04, 0x44, 0x16),
 };
 
+static __devinit int
+ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value)
+{
+	int err;
+
+	if (value & ~ab8500_reg_init[id].mask) {
+		dev_err(&pdev->dev,
+			"Configuration error: value outside mask.\n");
+		return -EINVAL;
+	}
+
+	err = abx500_mask_and_set_register_interruptible(
+		&pdev->dev,
+		ab8500_reg_init[id].bank,
+		ab8500_reg_init[id].addr,
+		ab8500_reg_init[id].mask,
+		value);
+	if (err < 0) {
+		dev_err(&pdev->dev,
+			"Failed to initialize 0x%02x, 0x%02x.\n",
+			ab8500_reg_init[id].bank,
+			ab8500_reg_init[id].addr);
+		return err;
+	}
+
+	dev_vdbg(&pdev->dev,
+		"init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
+		ab8500_reg_init[id].bank,
+		ab8500_reg_init[id].addr,
+		ab8500_reg_init[id].mask,
+		value);
+
+	return 0;
+}
+
+static __devinit int ab8500_regulator_register(struct platform_device *pdev,
+					struct regulator_init_data *init_data,
+					int id,
+					struct device_node *np)
+{
+	struct ab8500_regulator_info *info = NULL;
+	struct regulator_config config = { };
+	int err;
+
+	/* assign per-regulator data */
+	info = &ab8500_regulator_info[id];
+	info->dev = &pdev->dev;
+
+	config.dev = &pdev->dev;
+	config.init_data = init_data;
+	config.driver_data = info;
+	config.of_node = np;
+
+	/* fix for hardware before ab8500v2.0 */
+	if (abx500_get_chip_id(info->dev) < 0x20) {
+		if (info->desc.id == AB8500_LDO_AUX3) {
+			info->desc.n_voltages =
+				ARRAY_SIZE(ldo_vauxn_voltages);
+			info->voltages = ldo_vauxn_voltages;
+			info->voltages_len =
+				ARRAY_SIZE(ldo_vauxn_voltages);
+			info->voltage_mask = 0xf;
+		}
+	}
+
+	/* register regulator with framework */
+	info->regulator = regulator_register(&info->desc, &config);
+	if (IS_ERR(info->regulator)) {
+		err = PTR_ERR(info->regulator);
+		dev_err(&pdev->dev, "failed to register regulator %s\n",
+			info->desc.name);
+		/* when we fail, un-register all earlier regulators */
+		while (--id >= 0) {
+			info = &ab8500_regulator_info[id];
+			regulator_unregister(info->regulator);
+		}
+		return err;
+	}
+
+	return 0;
+}
+
 static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
 {
 	struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
 	struct ab8500_platform_data *pdata;
-	struct regulator_config config = { };
 	int i, err;
 
 	if (!ab8500) {
@@ -733,8 +814,7 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
 
 	/* initialize registers */
 	for (i = 0; i < pdata->num_regulator_reg_init; i++) {
-		int id;
-		u8 value;
+		int id, value;
 
 		id = pdata->regulator_reg_init[i].id;
 		value = pdata->regulator_reg_init[i].value;
@@ -745,73 +825,17 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
 				"Configuration error: id outside range.\n");
 			return -EINVAL;
 		}
-		if (value & ~ab8500_reg_init[id].mask) {
-			dev_err(&pdev->dev,
-				"Configuration error: value outside mask.\n");
-			return -EINVAL;
-		}
 
-		/* initialize register */
-		err = abx500_mask_and_set_register_interruptible(&pdev->dev,
-			ab8500_reg_init[id].bank,
-			ab8500_reg_init[id].addr,
-			ab8500_reg_init[id].mask,
-			value);
-		if (err < 0) {
-			dev_err(&pdev->dev,
-				"Failed to initialize 0x%02x, 0x%02x.\n",
-				ab8500_reg_init[id].bank,
-				ab8500_reg_init[id].addr);
+		err = ab8500_regulator_init_registers(pdev, id, value);
+		if (err < 0)
 			return err;
-		}
-		dev_vdbg(&pdev->dev,
-			"  init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n",
-			ab8500_reg_init[id].bank,
-			ab8500_reg_init[id].addr,
-			ab8500_reg_init[id].mask,
-			value);
 	}
 
 	/* register all regulators */
 	for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) {
-		struct ab8500_regulator_info *info = NULL;
-
-		/* assign per-regulator data */
-		info = &ab8500_regulator_info[i];
-		info->dev = &pdev->dev;
-
-		config.dev = &pdev->dev;
-		config.init_data = &pdata->regulator[i];
-		config.driver_data = info;
-
-		/* fix for hardware before ab8500v2.0 */
-		if (abx500_get_chip_id(info->dev) < 0x20) {
-			if (info->desc.id == AB8500_LDO_AUX3) {
-				info->desc.n_voltages =
-					ARRAY_SIZE(ldo_vauxn_voltages);
-				info->voltages = ldo_vauxn_voltages;
-				info->voltages_len =
-					ARRAY_SIZE(ldo_vauxn_voltages);
-				info->voltage_mask = 0xf;
-			}
-		}
-
-		/* register regulator with framework */
-		info->regulator = regulator_register(&info->desc, &config);
-		if (IS_ERR(info->regulator)) {
-			err = PTR_ERR(info->regulator);
-			dev_err(&pdev->dev, "failed to register regulator %s\n",
-					info->desc.name);
-			/* when we fail, un-register all earlier regulators */
-			while (--i >= 0) {
-				info = &ab8500_regulator_info[i];
-				regulator_unregister(info->regulator);
-			}
+		err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL);
+		if (err < 0)
 			return err;
-		}
-
-		dev_vdbg(rdev_get_dev(info->regulator),
-			"%s-probed\n", info->desc.name);
 	}
 
 	return 0;
-- 
1.7.9.5

  parent reply	other threads:[~2012-05-17 13:45 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 13:45 [PATCH 00/18] DT enablement for Snowball Lee Jones
2012-05-17 13:45 ` [PATCH 01/18] i2c: Add Device Tree support to the Nomadik I2C driver Lee Jones
2012-05-20 20:53   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 02/18] ARM: ux500: Remove unused i2c platform_data initialisation code Lee Jones
2012-05-17 13:45 ` [PATCH 03/18] ARM: ux500: Provide auxdata to be used as name base clock search for nmk-i2c Lee Jones
2012-05-17 13:45 ` [PATCH 04/18] ARM: ux500: CONFIG: Compile in support for leds-gpio Lee Jones
2012-05-17 13:45 ` [PATCH 05/18] ARM: ux500: Enable the user LED on Snowball via Device Tree Lee Jones
2012-05-17 13:45 ` [PATCH 06/18] mfd: ab8500: Remove confusing ab8500-i2c file and merge into ab8500-core Lee Jones
2012-05-20 20:58   ` Linus Walleij
2012-05-21  7:52     ` Lee Jones
2012-05-17 13:45 ` [PATCH 07/18] ARM: ux500: PRCMU related configuration and layout corrections for Device Tree Lee Jones
2012-05-17 13:45 ` [PATCH 08/18] mfd: Enable Device Tree for ab8500-core driver Lee Jones
2012-05-17 13:45 ` Lee Jones [this message]
2012-05-18  7:36   ` [PATCH 09/18] regulator: ab8500: Split up probe() into manageable pieces Mark Brown
2012-05-18  7:53     ` Lee Jones
2012-05-20 21:15   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 10/18] ARM: ux500: Add support for ab8500 regulators into the Device Tree Lee Jones
2012-05-17 13:45 ` [PATCH 11/18] regulator: Enable the ab8500 for " Lee Jones
2012-05-18  7:36   ` Mark Brown
2012-05-18  7:52     ` Lee Jones
2012-05-20 21:14   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 12/18] ARM: ux500: Disable platform setup of the ab8500 when DT is enabled Lee Jones
2012-05-17 21:22   ` Arnd Bergmann
2012-05-17 21:58     ` Lee Jones
2012-05-18 10:38       ` Arnd Bergmann
2012-05-18 11:00         ` Lee Jones
2012-05-18 11:12           ` Arnd Bergmann
2012-05-18 12:36             ` Lee Jones
2012-05-18 20:38               ` Arnd Bergmann
2012-05-17 13:45 ` [PATCH 13/18] ARM: ux500: Apply ab8500-debug node do the db8500 DT structure Lee Jones
2012-05-20 21:00   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 14/18] mfd: Enable ab8500-debug when Device Tree is enabled Lee Jones
2012-05-20 21:00   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 15/18] mfd: Prevent unassigned pointer from being used in ab8500-gpadc driver Lee Jones
2012-05-20 21:02   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 16/18] ARM: ux500: Add a ab8500-gpadc node to the db8500 Device Tree Lee Jones
2012-05-20 21:01   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 17/18] mfd: Enable ab8500-gpadc driver for " Lee Jones
2012-05-20 21:02   ` Linus Walleij
2012-05-17 13:45 ` [PATCH 18/18] ARM: ux500: Add support for input/ponkey into the db8500's " Lee Jones
2012-05-20 21:03   ` Linus Walleij
2012-05-17 21:25 ` [PATCH 00/18] DT enablement for Snowball Arnd Bergmann
2012-05-17 21:41   ` Mark Brown
2012-05-17 21:49     ` Lee Jones
2012-05-19 15:25 ` Samuel Ortiz

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=1337262323-27692-10-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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).