All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Stuebner <heiko@sntech.de>
To: broonie@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org,
	devicetree@vger.kernel.org, robh+dt@kernel.org,
	pawel.moll@arm.com, mark.rutland@arm.com,
	ijc+devicetree@hellion.org.uk, galak@codeaurora.org,
	Heiko Stuebner <heiko@sntech.de>
Subject: [PATCH 5/5] regulator: fan53555: add support for Silergy SYR82x regulators
Date: Sun, 14 Sep 2014 21:23:05 +0200	[thread overview]
Message-ID: <1410722585-13393-6-git-send-email-heiko@sntech.de> (raw)
In-Reply-To: <1410722585-13393-1-git-send-email-heiko@sntech.de>

Silergy SYR82x regulators share the exact same functionality and register layout
as the Fairchild FAN53555 regulators. Therefore extend the driver to add
support for them.

Both types use the same vendor id in their ID1 register, so it's not possible
to distinguish them automatically.

Similarly, the types also do not match. Type 8 used by the SYR827 and SYR828
start at 712.5mV and increment in 12.5mv steps, while the FAN53555 type 8
starts at 600mV and increments in 10mV steps.

Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
 .../devicetree/bindings/regulator/fan53555.txt     |   2 +-
 .../devicetree/bindings/vendor-prefixes.txt        |   1 +
 drivers/regulator/fan53555.c                       | 112 +++++++++++++++++----
 3 files changed, 95 insertions(+), 20 deletions(-)

diff --git a/Documentation/devicetree/bindings/regulator/fan53555.txt b/Documentation/devicetree/bindings/regulator/fan53555.txt
index 2484497..b26f278 100644
--- a/Documentation/devicetree/bindings/regulator/fan53555.txt
+++ b/Documentation/devicetree/bindings/regulator/fan53555.txt
@@ -1,7 +1,7 @@
 Binding for Fairchild FAN53555 regulators
 
 Required properties:
-  - compatible: "fairchild,fan53555"
+  - compatible: one of "fairchild,fan53555", "silergy,syr827", "silergy,syr828"
   - reg: I2C address
 
 Optional properties:
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 99da41b..9e34820 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -125,6 +125,7 @@ sil	Silicon Image
 silabs	Silicon Laboratories
 simtek
 sii	Seiko Instruments, Inc.
+silergy	Silergy Corp.
 sirf	SiRF Technology, Inc.
 smsc	Standard Microsystems Corporation
 snps 	Synopsys, Inc.
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index 0ec1762..89bfd0d 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -19,6 +19,7 @@
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
 #include <linux/regulator/of_regulator.h>
+#include <linux/of_device.h>
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/regmap.h>
@@ -51,6 +52,11 @@
 
 #define FAN53555_NVOLTAGES	64	/* Numbers of voltages */
 
+enum fan53555_vendor {
+	FAN53555_VENDOR_FAIRCHILD = 0,
+	FAN53555_VENDOR_SILERGY,
+};
+
 /* IC Type */
 enum {
 	FAN53555_CHIP_ID_00 = 0,
@@ -61,7 +67,12 @@ enum {
 	FAN53555_CHIP_ID_05,
 };
 
+enum {
+	SILERGY_SYR82X = 8,
+};
+
 struct fan53555_device_info {
+	enum fan53555_vendor vendor;
 	struct regmap *regmap;
 	struct device *dev;
 	struct regulator_desc desc;
@@ -149,6 +160,47 @@ static struct regulator_ops fan53555_regulator_ops = {
 	.get_mode = fan53555_get_mode,
 };
 
+static int fan53555_voltages_setup_fairchild(struct fan53555_device_info *di)
+{
+	/* Init voltage range and step */
+	switch (di->chip_id) {
+	case FAN53555_CHIP_ID_00:
+	case FAN53555_CHIP_ID_01:
+	case FAN53555_CHIP_ID_03:
+	case FAN53555_CHIP_ID_05:
+		di->vsel_min = 600000;
+		di->vsel_step = 10000;
+		break;
+	case FAN53555_CHIP_ID_04:
+		di->vsel_min = 603000;
+		di->vsel_step = 12826;
+		break;
+	default:
+		dev_err(di->dev,
+			"Chip ID[%d]\n not supported!\n", di->chip_id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int fan53555_voltages_setup_silergy(struct fan53555_device_info *di)
+{
+	/* Init voltage range and step */
+	switch (di->chip_id) {
+	case SILERGY_SYR82X:
+		di->vsel_min = 712500;
+		di->vsel_step = 12500;
+		break;
+	default:
+		dev_err(di->dev,
+			"Chip ID[%d]\n not supported!\n", di->chip_id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /* For 00,01,03,05 options:
  * VOUT = 0.60V + NSELx * 10mV, from 0.60 to 1.23V.
  * For 04 option:
@@ -158,6 +210,7 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
 				struct fan53555_platform_data *pdata)
 {
 	unsigned int reg, data, mask;
+	int ret = 0;
 
 	/* Setup voltage control register */
 	switch (pdata->sleep_vsel_id) {
@@ -173,24 +226,22 @@ static int fan53555_device_setup(struct fan53555_device_info *di,
 		dev_err(di->dev, "Invalid VSEL ID!\n");
 		return -EINVAL;
 	}
-	/* Init voltage range and step */
-	switch (di->chip_id) {
-	case FAN53555_CHIP_ID_00:
-	case FAN53555_CHIP_ID_01:
-	case FAN53555_CHIP_ID_03:
-	case FAN53555_CHIP_ID_05:
-		di->vsel_min = 600000;
-		di->vsel_step = 10000;
+
+	switch (di->vendor) {
+	case FAN53555_VENDOR_FAIRCHILD:
+		ret = fan53555_voltages_setup_fairchild(di);
 		break;
-	case FAN53555_CHIP_ID_04:
-		di->vsel_min = 603000;
-		di->vsel_step = 12826;
+	case FAN53555_VENDOR_SILERGY:
+		ret = fan53555_voltages_setup_silergy(di);
 		break;
 	default:
 		dev_err(di->dev,
-			"Chip ID[%d]\n not supported!\n", di->chip_id);
+			"vendor %d not supported!\n", di->chip_id);
 		return -EINVAL;
 	}
+	if (ret < 0)
+		return ret;
+
 	/* Init slew rate */
 	if (pdata->slew_rate & 0x7)
 		di->slew_rate = pdata->slew_rate;
@@ -272,6 +323,21 @@ static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
 	return pdata;
 }
 
+static const struct of_device_id fan53555_dt_ids[] = {
+	{
+		.compatible = "fairchild,fan53555",
+		.data = (void *)FAN53555_VENDOR_FAIRCHILD
+	}, {
+		.compatible = "silergy,syr827",
+		.data = (void *)FAN53555_VENDOR_SILERGY,
+	}, {
+		.compatible = "silergy,syr828",
+		.data = (void *)FAN53555_VENDOR_SILERGY,
+	},
+	{ }
+};
+MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
+
 static int fan53555_regulator_probe(struct i2c_client *client,
 				const struct i2c_device_id *id)
 {
@@ -296,6 +362,19 @@ static int fan53555_regulator_probe(struct i2c_client *client,
 	if (!di)
 		return -ENOMEM;
 
+	if (client->dev.of_node) {
+		const struct of_device_id *match;
+
+		match = of_match_device(of_match_ptr(fan53555_dt_ids),
+					&client->dev);
+		if (!match)
+			return -ENODEV;
+
+		di->vendor = (int) match->data;
+	} else {
+		di->vendor = id->driver_data;
+	}
+
 	di->regmap = devm_regmap_init_i2c(client, &fan53555_regmap_config);
 	if (IS_ERR(di->regmap)) {
 		dev_err(&client->dev, "Failed to allocate regmap!\n");
@@ -341,14 +420,9 @@ static int fan53555_regulator_probe(struct i2c_client *client,
 
 }
 
-static const struct of_device_id fan53555_dt_ids[] = {
-	{ .compatible = "fairchild,fan53555" },
-	{ }
-};
-MODULE_DEVICE_TABLE(of, fan53555_dt_ids);
-
 static const struct i2c_device_id fan53555_id[] = {
-	{"fan53555", -1},
+	{ .name = "fan53555", .driver_data = FAN53555_VENDOR_FAIRCHILD },
+	{ .name = "syr82x", .driver_data = FAN53555_VENDOR_SILERGY },
 	{ },
 };
 
-- 
2.0.1


  parent reply	other threads:[~2014-09-14 19:22 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-14 19:23 [PATCH 0/5] regulator: add support for syr82x to fan53555 Heiko Stuebner
2014-09-14 19:23 ` [PATCH 1/5] regulator: fan53555: enable vin supply Heiko Stuebner
2014-09-15 21:49   ` Mark Brown
2014-09-15 21:49     ` Mark Brown
2014-09-14 19:23 ` [PATCH 2/5] regulator: fan53555: set regulator name from constraints name Heiko Stuebner
2014-09-15 16:59   ` Mark Brown
2014-09-15 16:59     ` Mark Brown
2014-09-15 22:08     ` Heiko Stübner
2014-09-15 22:36       ` Mark Brown
2014-09-14 19:23 ` [PATCH 3/5] dt-bindings: add devicetree bindings for Fairchild FAN53555 regulators Heiko Stuebner
2014-09-14 19:23   ` Heiko Stuebner
2014-09-15 21:54   ` Mark Brown
2014-09-15 22:14     ` Heiko Stübner
2014-09-15 22:25       ` Mark Brown
2014-09-14 19:23 ` [PATCH 4/5] regulator: fan53555: add devicetree support Heiko Stuebner
2014-09-14 19:23 ` Heiko Stuebner [this message]
2014-09-15 22:27   ` [PATCH 5/5] regulator: fan53555: add support for Silergy SYR82x regulators 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=1410722585-13393-6-git-send-email-heiko@sntech.de \
    --to=heiko@sntech.de \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=pawel.moll@arm.com \
    --cc=robh+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.