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 4/5] regulator: fan53555: add devicetree support
Date: Sun, 14 Sep 2014 21:23:04 +0200 [thread overview]
Message-ID: <1410722585-13393-5-git-send-email-heiko@sntech.de> (raw)
In-Reply-To: <1410722585-13393-1-git-send-email-heiko@sntech.de>
Add the ability to parse regulator-data from the devicetree.
Signed-off-by: Heiko Stuebner <heiko@sntech.de>
---
drivers/regulator/fan53555.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/regulator/fan53555.c b/drivers/regulator/fan53555.c
index d143790..0ec1762 100644
--- a/drivers/regulator/fan53555.c
+++ b/drivers/regulator/fan53555.c
@@ -18,6 +18,7 @@
#include <linux/platform_device.h>
#include <linux/regulator/driver.h>
#include <linux/regulator/machine.h>
+#include <linux/regulator/of_regulator.h>
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/regmap.h>
@@ -233,9 +234,48 @@ static struct regmap_config fan53555_regmap_config = {
.val_bits = 8,
};
+static int slew_rates[] = {
+ 64000,
+ 32000,
+ 16000,
+ 8000,
+ 4000,
+ 2000,
+ 1000,
+ 500,
+};
+
+static struct fan53555_platform_data *fan53555_parse_dt(struct device *dev,
+ struct device_node *np)
+{
+ struct fan53555_platform_data *pdata;
+ int ret, i;
+ u32 tmp;
+
+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+ if (!pdata)
+ return NULL;
+
+ pdata->regulator = of_get_regulator_init_data(dev, np);
+
+ ret = of_property_read_u32(np, "fairchild,suspend-regulator", &tmp);
+ if (!ret)
+ pdata->sleep_vsel_id = tmp;
+
+ ret = of_property_read_u32(np, "fairchild,slew-rate-microvolt", &tmp);
+ if (!ret) {
+ for (i = 0; i < ARRAY_SIZE(slew_rates); i++)
+ if (slew_rates[i] == tmp)
+ pdata->slew_rate = i;
+ }
+
+ return pdata;
+}
+
static int fan53555_regulator_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
+ struct device_node *np = client->dev.of_node;
struct fan53555_device_info *di;
struct fan53555_platform_data *pdata;
struct regulator_config config = { };
@@ -243,6 +283,9 @@ static int fan53555_regulator_probe(struct i2c_client *client,
int ret;
pdata = dev_get_platdata(&client->dev);
+ if (!pdata)
+ pdata = fan53555_parse_dt(&client->dev, np);
+
if (!pdata || !pdata->regulator) {
dev_err(&client->dev, "Platform data not found!\n");
return -ENODEV;
@@ -283,11 +326,14 @@ static int fan53555_regulator_probe(struct i2c_client *client,
dev_err(&client->dev, "Failed to setup device!\n");
return ret;
}
+
/* Register regulator */
config.dev = di->dev;
config.init_data = di->regulator;
config.regmap = di->regmap;
config.driver_data = di;
+ config.of_node = np;
+
ret = fan53555_regulator_register(di, &config);
if (ret < 0)
dev_err(&client->dev, "Failed to register regulator!\n");
@@ -295,6 +341,12 @@ 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},
{ },
@@ -303,6 +355,7 @@ static const struct i2c_device_id fan53555_id[] = {
static struct i2c_driver fan53555_regulator_driver = {
.driver = {
.name = "fan53555-regulator",
+ .of_match_table = of_match_ptr(fan53555_dt_ids),
},
.probe = fan53555_regulator_probe,
.id_table = fan53555_id,
--
2.0.1
next prev parent reply other threads:[~2014-09-14 19:20 UTC|newest]
Thread overview: 14+ 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-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 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-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 ` Heiko Stuebner [this message]
2014-09-14 19:23 ` [PATCH 5/5] regulator: fan53555: add support for Silergy SYR82x regulators Heiko Stuebner
2014-09-15 22:27 ` 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-5-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 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).