linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sbs-battery: probe should try talking to the device
@ 2012-09-06 18:32 Olof Johansson
  2012-09-06 18:35 ` Rhyland Klein
  0 siblings, 1 reply; 3+ messages in thread
From: Olof Johansson @ 2012-09-06 18:32 UTC (permalink / raw)
  To: Anton Vorontsov
  Cc: Rhyland Klein, David Woodhouse, linux-kernel, Olof Johansson

Turns out this driver doesn't actually try talking to the device at
probe time, so if it's incorrectly configured in the device tree or
platform data (or if the battery has been removed from the system), then
probe will succeed and every access will sit there and time out. The
end result is a possibly laggy system that thinks it has a battery but
can never read status, which isn't very useful.

Instead, just read any register (I chose status) at probe, and if that
fails, don't register the device.

Signed-off-by: Olof Johansson <olof@lixom.net>
---
 drivers/power/sbs-battery.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
index a65e8f5..2f24253 100644
--- a/drivers/power/sbs-battery.c
+++ b/drivers/power/sbs-battery.c
@@ -760,6 +760,16 @@ static int __devinit sbs_probe(struct i2c_client *client,
 
 skip_gpio:
 
+	/* Before we register, we need to make sure we can actually talk
+	 * to the battery.
+	 */
+	rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
+	if (rc < 0) {
+		dev_err(&client->dev, "%s: Failed to get device status\n",
+			__func__);
+		goto exit_psupply;
+	}
+
 	rc = power_supply_register(&client->dev, &chip->power_supply);
 	if (rc) {
 		dev_err(&client->dev,
-- 
1.7.10.1.488.g05fbf7a


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

* Re: [PATCH] sbs-battery: probe should try talking to the device
  2012-09-06 18:32 [PATCH] sbs-battery: probe should try talking to the device Olof Johansson
@ 2012-09-06 18:35 ` Rhyland Klein
  2012-09-20 21:59   ` Anton Vorontsov
  0 siblings, 1 reply; 3+ messages in thread
From: Rhyland Klein @ 2012-09-06 18:35 UTC (permalink / raw)
  To: Olof Johansson; +Cc: Anton Vorontsov, David Woodhouse, linux-kernel

On 09/06/2012 02:32 PM, Olof Johansson wrote:
> Turns out this driver doesn't actually try talking to the device at
> probe time, so if it's incorrectly configured in the device tree or
> platform data (or if the battery has been removed from the system), then
> probe will succeed and every access will sit there and time out. The
> end result is a possibly laggy system that thinks it has a battery but
> can never read status, which isn't very useful.
>
> Instead, just read any register (I chose status) at probe, and if that
> fails, don't register the device.
>
> Signed-off-by: Olof Johansson <olof@lixom.net>
> ---
>   drivers/power/sbs-battery.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
>
> diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
> index a65e8f5..2f24253 100644
> --- a/drivers/power/sbs-battery.c
> +++ b/drivers/power/sbs-battery.c
> @@ -760,6 +760,16 @@ static int __devinit sbs_probe(struct i2c_client *client,
>
>   skip_gpio:
>
> +	/* Before we register, we need to make sure we can actually talk
> +	 * to the battery.
> +	 */
> +	rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
> +	if (rc < 0) {
> +		dev_err(&client->dev, "%s: Failed to get device status\n",
> +			__func__);
> +		goto exit_psupply;
> +	}
> +
>   	rc = power_supply_register(&client->dev, &chip->power_supply);
>   	if (rc) {
>   		dev_err(&client->dev,
>

Acked-by: Rhyland Klein <rklein@nvidia.com>

-- 
nvpublic

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

* Re: [PATCH] sbs-battery: probe should try talking to the device
  2012-09-06 18:35 ` Rhyland Klein
@ 2012-09-20 21:59   ` Anton Vorontsov
  0 siblings, 0 replies; 3+ messages in thread
From: Anton Vorontsov @ 2012-09-20 21:59 UTC (permalink / raw)
  To: Rhyland Klein; +Cc: Olof Johansson, David Woodhouse, linux-kernel

On Thu, Sep 06, 2012 at 02:35:30PM -0400, Rhyland Klein wrote:
> On 09/06/2012 02:32 PM, Olof Johansson wrote:
> >Turns out this driver doesn't actually try talking to the device at
> >probe time, so if it's incorrectly configured in the device tree or
> >platform data (or if the battery has been removed from the system), then
> >probe will succeed and every access will sit there and time out. The
> >end result is a possibly laggy system that thinks it has a battery but
> >can never read status, which isn't very useful.
> >
> >Instead, just read any register (I chose status) at probe, and if that
> >fails, don't register the device.
> >
> >Signed-off-by: Olof Johansson <olof@lixom.net>
[...]
> Acked-by: Rhyland Klein <rklein@nvidia.com>

Applied, thank you folks!

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

end of thread, other threads:[~2012-09-20 22:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-06 18:32 [PATCH] sbs-battery: probe should try talking to the device Olof Johansson
2012-09-06 18:35 ` Rhyland Klein
2012-09-20 21:59   ` Anton Vorontsov

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