linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
@ 2012-04-19  4:30 Ramakrishna Pallala
  2012-04-19 19:08 ` Mika Westerberg
  0 siblings, 1 reply; 5+ messages in thread
From: Ramakrishna Pallala @ 2012-04-19  4:30 UTC (permalink / raw)
  To: linux-kernel
  Cc: Anton Vorontsov, Anton Vorontsov, Ramakrishna Pallala, Mika Westerberg

This patch checks if the usb or mains charging is enabled by the
platform before registering with the power supply class.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
---
 drivers/power/smb347-charger.c |   70 +++++++++++++++++++++++-----------------
 1 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/drivers/power/smb347-charger.c b/drivers/power/smb347-charger.c
index ce1694d..3e9df6e 100644
--- a/drivers/power/smb347-charger.c
+++ b/drivers/power/smb347-charger.c
@@ -816,8 +816,10 @@ static irqreturn_t smb347_interrupt(int irq, void *data)
 	if (irqstat_e & (IRQSTAT_E_USBIN_UV_IRQ | IRQSTAT_E_DCIN_UV_IRQ)) {
 		if (smb347_update_status(smb) > 0) {
 			smb347_update_online(smb);
-			power_supply_changed(&smb->mains);
-			power_supply_changed(&smb->usb);
+			if (smb->pdata->use_mains)
+				power_supply_changed(&smb->mains);
+			if (smb->pdata->use_usb)
+				power_supply_changed(&smb->usb);
 		}
 		ret = IRQ_HANDLED;
 	}
@@ -1185,21 +1187,34 @@ static int smb347_probe(struct i2c_client *client,
 	if (ret < 0)
 		return ret;
 
-	smb->mains.name = "smb347-mains";
-	smb->mains.type = POWER_SUPPLY_TYPE_MAINS;
-	smb->mains.get_property = smb347_mains_get_property;
-	smb->mains.properties = smb347_mains_properties;
-	smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
-	smb->mains.supplied_to = battery;
-	smb->mains.num_supplicants = ARRAY_SIZE(battery);
-
-	smb->usb.name = "smb347-usb";
-	smb->usb.type = POWER_SUPPLY_TYPE_USB;
-	smb->usb.get_property = smb347_usb_get_property;
-	smb->usb.properties = smb347_usb_properties;
-	smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
-	smb->usb.supplied_to = battery;
-	smb->usb.num_supplicants = ARRAY_SIZE(battery);
+	if (smb->pdata->use_mains) {
+		smb->mains.name = "smb347-mains";
+		smb->mains.type = POWER_SUPPLY_TYPE_MAINS;
+		smb->mains.get_property = smb347_mains_get_property;
+		smb->mains.properties = smb347_mains_properties;
+		smb->mains.num_properties = ARRAY_SIZE(smb347_mains_properties);
+		smb->mains.supplied_to = battery;
+		smb->mains.num_supplicants = ARRAY_SIZE(battery);
+		ret = power_supply_register(dev, &smb->mains);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (smb->pdata->use_usb) {
+		smb->usb.name = "smb347-usb";
+		smb->usb.type = POWER_SUPPLY_TYPE_USB;
+		smb->usb.get_property = smb347_usb_get_property;
+		smb->usb.properties = smb347_usb_properties;
+		smb->usb.num_properties = ARRAY_SIZE(smb347_usb_properties);
+		smb->usb.supplied_to = battery;
+		smb->usb.num_supplicants = ARRAY_SIZE(battery);
+		ret = power_supply_register(dev, &smb->usb);
+		if (ret < 0) {
+			if (smb->pdata->use_mains)
+				power_supply_unregister(&smb->mains);
+			return ret;
+		}
+	}
 
 	smb->battery.name = "smb347-battery";
 	smb->battery.type = POWER_SUPPLY_TYPE_BATTERY;
@@ -1207,20 +1222,13 @@ static int smb347_probe(struct i2c_client *client,
 	smb->battery.properties = smb347_battery_properties;
 	smb->battery.num_properties = ARRAY_SIZE(smb347_battery_properties);
 
-	ret = power_supply_register(dev, &smb->mains);
-	if (ret < 0)
-		return ret;
-
-	ret = power_supply_register(dev, &smb->usb);
-	if (ret < 0) {
-		power_supply_unregister(&smb->mains);
-		return ret;
-	}
 
 	ret = power_supply_register(dev, &smb->battery);
 	if (ret < 0) {
-		power_supply_unregister(&smb->usb);
-		power_supply_unregister(&smb->mains);
+		if (smb->pdata->use_usb)
+			power_supply_unregister(&smb->usb);
+		if (smb->pdata->use_mains)
+			power_supply_unregister(&smb->mains);
 		return ret;
 	}
 
@@ -1255,8 +1263,10 @@ static int smb347_remove(struct i2c_client *client)
 	}
 
 	power_supply_unregister(&smb->battery);
-	power_supply_unregister(&smb->usb);
-	power_supply_unregister(&smb->mains);
+	if (smb->pdata->use_usb)
+		power_supply_unregister(&smb->usb);
+	if (smb->pdata->use_mains)
+		power_supply_unregister(&smb->mains);
 	return 0;
 }
 
-- 
1.7.0.4


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

* Re: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
  2012-04-19  4:30 [PATCH v2] smb347_charger: Cleanup power supply registration code in probe Ramakrishna Pallala
@ 2012-04-19 19:08 ` Mika Westerberg
  2012-04-20  3:48   ` Pallala, Ramakrishna
  2012-05-05 10:42   ` Pallala, Ramakrishna
  0 siblings, 2 replies; 5+ messages in thread
From: Mika Westerberg @ 2012-04-19 19:08 UTC (permalink / raw)
  To: Ramakrishna Pallala; +Cc: linux-kernel, Anton Vorontsov, Anton Vorontsov

On Thu, Apr 19, 2012 at 10:00:18AM +0530, Ramakrishna Pallala wrote:
> This patch checks if the usb or mains charging is enabled by the
> platform before registering with the power supply class.

I still don't like the idea of having the power-supplies registered
conditionally. Now you need to check in every place whether the corresponding
power-supply is registered or not which makes the code uglier and more prone
to errors.

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

* RE: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
  2012-04-19 19:08 ` Mika Westerberg
@ 2012-04-20  3:48   ` Pallala, Ramakrishna
  2012-05-05 12:51     ` Anton Vorontsov
  2012-05-05 10:42   ` Pallala, Ramakrishna
  1 sibling, 1 reply; 5+ messages in thread
From: Pallala, Ramakrishna @ 2012-04-20  3:48 UTC (permalink / raw)
  To: Mika Westerberg; +Cc: linux-kernel, Anton Vorontsov, Anton Vorontsov

> Subject: Re: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
> 
> On Thu, Apr 19, 2012 at 10:00:18AM +0530, Ramakrishna Pallala wrote:
> > This patch checks if the usb or mains charging is enabled by the
> > platform before registering with the power supply class.
> 
> I still don't like the idea of having the power-supplies registered conditionally. Now
> you need to check in every place whether the corresponding power-supply is registered or
> not which makes the code uglier and more prone to errors.

These are the reasons behind this patch submission:
1. if we don't support USB/AC charging don't enable it, saves
	kernel resources and don't give user wrong idea about charging capabilities.
2. if a platform driver or any other chip can do USB/AC charging they will register with PS and
	user/userspace will not get confused b/w two sysfs interfaces.

I will leave the decision the Anton.

Thanks,
Ram

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

* RE: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
  2012-04-19 19:08 ` Mika Westerberg
  2012-04-20  3:48   ` Pallala, Ramakrishna
@ 2012-05-05 10:42   ` Pallala, Ramakrishna
  1 sibling, 0 replies; 5+ messages in thread
From: Pallala, Ramakrishna @ 2012-05-05 10:42 UTC (permalink / raw)
  To: Anton Vorontsov; +Cc: linux-kernel, Mika Westerberg

Hi Anton,

> Subject: Re: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
> 
> On Thu, Apr 19, 2012 at 10:00:18AM +0530, Ramakrishna Pallala wrote:
> > This patch checks if the usb or mains charging is enabled by the
> > platform before registering with the power supply class.
> 
> I still don't like the idea of having the power-supplies registered conditionally. Now
> you need to check in every place whether the corresponding power-supply is registered or
> not which makes the code uglier and more prone to errors.

This patch needs your attention.

Thanks,
Ram

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

* Re: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
  2012-04-20  3:48   ` Pallala, Ramakrishna
@ 2012-05-05 12:51     ` Anton Vorontsov
  0 siblings, 0 replies; 5+ messages in thread
From: Anton Vorontsov @ 2012-05-05 12:51 UTC (permalink / raw)
  To: Pallala, Ramakrishna; +Cc: Mika Westerberg, linux-kernel

On Fri, Apr 20, 2012 at 03:48:35AM +0000, Pallala, Ramakrishna wrote:
> > Subject: Re: [PATCH v2] smb347_charger: Cleanup power supply registration code in probe
> > 
> > On Thu, Apr 19, 2012 at 10:00:18AM +0530, Ramakrishna Pallala wrote:
> > > This patch checks if the usb or mains charging is enabled by the
> > > platform before registering with the power supply class.
> > 
> > I still don't like the idea of having the power-supplies registered conditionally. Now
> > you need to check in every place whether the corresponding power-supply is registered or
> > not which makes the code uglier and more prone to errors.

Yes, I understand. There's a bit more code in the kernel,
true. But it saves tons of code in userland and makes things
more reliable for the latter.

> These are the reasons behind this patch submission:
> 1. if we don't support USB/AC charging don't enable it, saves
> 	kernel resources and don't give user wrong idea about charging capabilities.
> 2. if a platform driver or any other chip can do USB/AC charging they will register with PS and
> 	user/userspace will not get confused b/w two sysfs interfaces.
> 
> I will leave the decision the Anton.

Well, as I always said, it was somewhat a mistake to introduce
'present' property. It was supposed to be something like 'battery
cells present, if hot-swappable' property.

If the device itself doesn't have a feature (i.e. no USB
socket), you should not register it, otherwise userland
will have to bother detecting actual information (because
the kernel literally lies to the userland if it registers
absent hw features).

So, I'm all for this patch -- it is now applied.

Thank you!

-- 
Anton Vorontsov
Email: cbouatmailru@gmail.com

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

end of thread, other threads:[~2012-05-05 12:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19  4:30 [PATCH v2] smb347_charger: Cleanup power supply registration code in probe Ramakrishna Pallala
2012-04-19 19:08 ` Mika Westerberg
2012-04-20  3:48   ` Pallala, Ramakrishna
2012-05-05 12:51     ` Anton Vorontsov
2012-05-05 10:42   ` Pallala, Ramakrishna

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).