devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: Karol Lewandowski <k.lewandowsk@samsung.com>
Cc: myungjoo.ham@samsung.com, kyungmin.park@samsung.com,
	m.szyprowski@samsung.com, devicetree-discuss@lists.ozlabs.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] max17042_battery: Make it possible to instantiate driver from DT
Date: Tue, 13 Mar 2012 23:22:33 +0400	[thread overview]
Message-ID: <20120313192233.GC2187@oksana.dev.rtsoft.ru> (raw)
In-Reply-To: <1329933982-2529-4-git-send-email-k.lewandowsk@samsung.com>

On Wed, Feb 22, 2012 at 07:06:22PM +0100, Karol Lewandowski wrote:
> Allow both device tree (preferred) and platform data-based driver
> instantiation.
> 
> Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> ---

Thanks for the patch!

I applied the following version:

commit 651bfc379546af756dc6abbc9ce678e4607220be
Author: Karol Lewandowski <k.lewandowsk@samsung.com>
Date:   Wed Feb 22 19:06:22 2012 +0100

    max17042_battery: Make it possible to instantiate driver from DT
    
    Allow both device tree (preferred) and platform data-based driver
    instantiation.
    
    Signed-off-by: Karol Lewandowski <k.lewandowsk@samsung.com>
    Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
    Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>

diff --git a/Documentation/devicetree/bindings/power_supply/max17042_battery.txt b/Documentation/devicetree/bindings/power_supply/max17042_battery.txt
new file mode 100644
index 0000000..5bc9b68
--- /dev/null
+++ b/Documentation/devicetree/bindings/power_supply/max17042_battery.txt
@@ -0,0 +1,18 @@
+max17042_battery
+~~~~~~~~~~~~~~~~
+
+Required properties :
+ - compatible : "maxim,max17042"
+
+Optional properties :
+ - maxim,rsns-microohm : Resistance of rsns resistor in micro Ohms
+                         (datasheet-recommended value is 10000).
+   Defining this property enables current-sense functionality.
+
+Example:
+
+	battery-charger@36 {
+		compatible = "maxim,max17042";
+		reg = <0x36>;
+		maxim,rsns-microohm = <10000>;
+	};
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 872e9b4..e36763a 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -31,6 +31,7 @@
 #include <linux/mod_devicetable.h>
 #include <linux/power_supply.h>
 #include <linux/power/max17042_battery.h>
+#include <linux/of.h>
 
 /* Status register bits */
 #define STATUS_POR_BIT         (1 << 1)
@@ -608,6 +609,40 @@ static void max17042_init_worker(struct work_struct *work)
 	chip->init_complete = 1;
 }
 
+#ifdef CONFIG_OF
+static struct max17042_platform_data *
+max17042_get_pdata(struct device *dev)
+{
+	struct device_node *np = dev->of_node;
+	u32 prop;
+	struct max17042_platform_data *pdata;
+
+	if (!np)
+		return dev->platform_data;
+
+	pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return NULL;
+
+	/*
+	 * Require current sense resistor value to be specified for
+	 * current-sense functionality to be enabled at all.
+	 */
+	if (of_property_read_u32(np, "maxim,rsns-microohm", &prop) == 0) {
+		pdata->r_sns = prop;
+		pdata->enable_current_sense = true;
+	}
+
+	return pdata;
+}
+#else
+static struct max17042_platform_data *
+max17042_get_pdata(struct device *dev)
+{
+	return dev->platform_data;
+}
+#endif
+
 static int __devinit max17042_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -624,7 +659,11 @@ static int __devinit max17042_probe(struct i2c_client *client,
 		return -ENOMEM;
 
 	chip->client = client;
-	chip->pdata = client->dev.platform_data;
+	chip->pdata = max17042_get_pdata(&client->dev);
+	if (!chip->pdata) {
+		dev_err(&client->dev, "no platform data provided\n");
+		return -EINVAL;
+	}
 
 	i2c_set_clientdata(client, chip);
 
@@ -689,6 +728,14 @@ static int __devexit max17042_remove(struct i2c_client *client)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id max17042_dt_match[] = {
+	{ .compatible = "maxim,max17042" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, max17042_dt_match);
+#endif
+
 static const struct i2c_device_id max17042_id[] = {
 	{ "max17042", 0 },
 	{ }
@@ -698,6 +745,7 @@ MODULE_DEVICE_TABLE(i2c, max17042_id);
 static struct i2c_driver max17042_i2c_driver = {
 	.driver	= {
 		.name	= "max17042",
+		.of_match_table = of_match_ptr(max17042_dt_match),
 	},
 	.probe		= max17042_probe,
 	.remove		= __devexit_p(max17042_remove),

  reply	other threads:[~2012-03-13 19:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-22 18:06 [PATCH 0/3] power: max17042_battery: Add DT bindings Karol Lewandowski
2012-02-22 18:06 ` [PATCH 1/3] max17042_battery: Use devm_kzalloc() where applicable Karol Lewandowski
     [not found]   ` <1329933982-2529-2-git-send-email-k.lewandowsk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2012-03-13 19:18     ` Anton Vorontsov
2012-02-22 18:06 ` [PATCH 2/3] max17042_battery: Preserve properties outside of platform data Karol Lewandowski
2012-03-13 19:21   ` Anton Vorontsov
2012-03-14  9:14     ` Karol Lewandowski
2012-02-22 18:06 ` [PATCH 3/3] max17042_battery: Make it possible to instantiate driver from DT Karol Lewandowski
2012-03-13 19:22   ` Anton Vorontsov [this message]
     [not found]     ` <20120313192233.GC2187-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org>
2012-03-14 12:29       ` Karol Lewandowski

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=20120313192233.GC2187@oksana.dev.rtsoft.ru \
    --to=cbouatmailru@gmail.com \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=k.lewandowsk@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=myungjoo.ham@samsung.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;
as well as URLs for NNTP newsgroup(s).