All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table
@ 2017-02-22 14:28 Javier Martinez Canillas
  2017-02-22 14:28 ` [PATCH 2/2] power: supply: max17040: " Javier Martinez Canillas
  2017-02-22 16:38   ` kbuild test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2017-02-22 14:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Javier Martinez Canillas, Sebastian Reichel, linux-pm

The driver doesn't have a struct of_device_id table but supported devices
are registered via Device Trees. This is working on the assumption that a
I2C device registered via OF will always match a legacy I2C device ID and
that the MODALIAS reported will always be of the form i2c:<device>.

But this could change in the future so the correct approach is to have an
OF device ID table if the devices are registered via OF.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---

 drivers/power/supply/ltc2941-battery-gauge.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/ltc2941-battery-gauge.c b/drivers/power/supply/ltc2941-battery-gauge.c
index 4adf2ba021ce..3b047f54c3b9 100644
--- a/drivers/power/supply/ltc2941-battery-gauge.c
+++ b/drivers/power/supply/ltc2941-battery-gauge.c
@@ -9,6 +9,7 @@
  */
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/swab.h>
@@ -387,7 +388,7 @@ static int ltc294x_i2c_probe(struct i2c_client *client,
 
 	np = of_node_get(client->dev.of_node);
 
-	info->num_regs = id->driver_data;
+	info->num_regs = (int)of_device_get_match_data(&client->dev);
 	info->supply_desc.name = np->name;
 
 	/* r_sense can be negative, when sense+ is connected to the battery
@@ -497,9 +498,23 @@ static const struct i2c_device_id ltc294x_i2c_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, ltc294x_i2c_id);
 
+static const struct of_device_id ltc294x_i2c_of_match[] = {
+	{
+		.compatible = "maxim,max17040",
+		.data = (void *)LTC2941_NUM_REGS
+	},
+	{
+		.compatible = "maxim,max77836-battery",
+		.data = (void *)LTC2941_NUM_REGS
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, ltc294x_i2c_of_match);
+
 static struct i2c_driver ltc294x_driver = {
 	.driver = {
 		.name	= "LTC2941",
+		.of_match_table = of_match_ptr(ltc294x_i2c_of_match),
 		.pm	= LTC294X_PM_OPS,
 	},
 	.probe		= ltc294x_i2c_probe,
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] power: supply: max17040: Add OF device ID table
  2017-02-22 14:28 [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table Javier Martinez Canillas
@ 2017-02-22 14:28 ` Javier Martinez Canillas
  2017-02-22 16:38   ` kbuild test robot
  1 sibling, 0 replies; 4+ messages in thread
From: Javier Martinez Canillas @ 2017-02-22 14:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Javier Martinez Canillas, Sebastian Reichel, linux-pm

The driver doesn't have a struct of_device_id table but supported devices
are registered via Device Trees. This is working on the assumption that a
I2C device registered via OF will always match a legacy I2C device ID and
that the MODALIAS reported will always be of the form i2c:<device>.

But this could change in the future so the correct approach is to have an
OF device ID table if the devices are registered via OF.

Signed-off-by: Javier Martinez Canillas <javier@osg.samsung.com>
---

 drivers/power/supply/max17040_battery.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index e7c3649b31a0..c7a907c27906 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -277,9 +277,17 @@ static const struct i2c_device_id max17040_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, max17040_id);
 
+static const struct of_device_id max17040_of_match[] = {
+	{ .compatible = "maxim,max17040" },
+	{ .compatible = "maxim,max77836-battery" },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, max17040_of_match);
+
 static struct i2c_driver max17040_i2c_driver = {
 	.driver	= {
 		.name	= "max17040",
+		.of_match_table = of_match_ptr(max17040_of_match),
 		.pm	= MAX17040_PM_OPS,
 	},
 	.probe		= max17040_probe,
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table
  2017-02-22 14:28 [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table Javier Martinez Canillas
@ 2017-02-22 16:38   ` kbuild test robot
  2017-02-22 16:38   ` kbuild test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-02-22 16:38 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: kbuild-all, linux-kernel, Javier Martinez Canillas,
	Sebastian Reichel, linux-pm

[-- Attachment #1: Type: text/plain, Size: 2064 bytes --]

Hi Javier,

[auto build test WARNING on battery/master]
[also build test WARNING on v4.10 next-20170221]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Javier-Martinez-Canillas/power-supply-ltc2941-battery-gauge-Add-OF-device-ID-table/20170222-223315
base:   git://git.infradead.org/battery-2.6.git master
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/power/supply/ltc2941-battery-gauge.c: In function 'ltc294x_i2c_probe':
>> drivers/power/supply/ltc2941-battery-gauge.c:391:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     info->num_regs = (int)of_device_get_match_data(&client->dev);
                      ^

vim +391 drivers/power/supply/ltc2941-battery-gauge.c

   375	{
   376		struct power_supply_config psy_cfg = {};
   377		struct ltc294x_info *info;
   378		int ret;
   379		u32 prescaler_exp;
   380		s32 r_sense;
   381		struct device_node *np;
   382	
   383		info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
   384		if (info == NULL)
   385			return -ENOMEM;
   386	
   387		i2c_set_clientdata(client, info);
   388	
   389		np = of_node_get(client->dev.of_node);
   390	
 > 391		info->num_regs = (int)of_device_get_match_data(&client->dev);
   392		info->supply_desc.name = np->name;
   393	
   394		/* r_sense can be negative, when sense+ is connected to the battery
   395		 * instead of the sense-. This results in reversed measurements. */
   396		ret = of_property_read_u32(np, "lltc,resistor-sense", &r_sense);
   397		if (ret < 0) {
   398			dev_err(&client->dev,
   399				"Could not find lltc,resistor-sense in devicetree\n");

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 55500 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table
@ 2017-02-22 16:38   ` kbuild test robot
  0 siblings, 0 replies; 4+ messages in thread
From: kbuild test robot @ 2017-02-22 16:38 UTC (permalink / raw)
  Cc: kbuild-all, linux-kernel, Javier Martinez Canillas,
	Sebastian Reichel, linux-pm

[-- Attachment #1: Type: text/plain, Size: 2064 bytes --]

Hi Javier,

[auto build test WARNING on battery/master]
[also build test WARNING on v4.10 next-20170221]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Javier-Martinez-Canillas/power-supply-ltc2941-battery-gauge-Add-OF-device-ID-table/20170222-223315
base:   git://git.infradead.org/battery-2.6.git master
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/power/supply/ltc2941-battery-gauge.c: In function 'ltc294x_i2c_probe':
>> drivers/power/supply/ltc2941-battery-gauge.c:391:19: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
     info->num_regs = (int)of_device_get_match_data(&client->dev);
                      ^

vim +391 drivers/power/supply/ltc2941-battery-gauge.c

   375	{
   376		struct power_supply_config psy_cfg = {};
   377		struct ltc294x_info *info;
   378		int ret;
   379		u32 prescaler_exp;
   380		s32 r_sense;
   381		struct device_node *np;
   382	
   383		info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
   384		if (info == NULL)
   385			return -ENOMEM;
   386	
   387		i2c_set_clientdata(client, info);
   388	
   389		np = of_node_get(client->dev.of_node);
   390	
 > 391		info->num_regs = (int)of_device_get_match_data(&client->dev);
   392		info->supply_desc.name = np->name;
   393	
   394		/* r_sense can be negative, when sense+ is connected to the battery
   395		 * instead of the sense-. This results in reversed measurements. */
   396		ret = of_property_read_u32(np, "lltc,resistor-sense", &r_sense);
   397		if (ret < 0) {
   398			dev_err(&client->dev,
   399				"Could not find lltc,resistor-sense in devicetree\n");

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 55500 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-02-22 16:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-22 14:28 [PATCH 1/2] power: supply: ltc2941-battery-gauge: Add OF device ID table Javier Martinez Canillas
2017-02-22 14:28 ` [PATCH 2/2] power: supply: max17040: " Javier Martinez Canillas
2017-02-22 16:38 ` [PATCH 1/2] power: supply: ltc2941-battery-gauge: " kbuild test robot
2017-02-22 16:38   ` kbuild test robot

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.