devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: Frans Klaver <frans.klaver@xsens.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Rob Herring <robh+dt@kernel.org>, Pawel Moll <Pawel.Moll@arm.com>,
	Ian Campbell <ijc+devicetree@hellion.org.uk>,
	Kumar Gala <galak@codeaurora.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [RFC PATCH 1/2] sbs-battery: add forced instantiation from device tree
Date: Wed, 24 Sep 2014 14:16:55 +0100	[thread overview]
Message-ID: <20140924131655.GG5729@leverpostej> (raw)
In-Reply-To: <1411564278-17207-2-git-send-email-frans.klaver@xsens.com>

On Wed, Sep 24, 2014 at 02:11:17PM +0100, Frans Klaver wrote:
> In some cases you want to instantiate a battery even before it is
> attached; it is perfectly reasonable for a device to start up on
> wall-power and be connected to a battery later. The current advice is to
> instantiate a device explicitly in the kernel, or probe for the device
> from userspace. The downside of these approaches is that the user needs
> to keep the information related to the i2c battery in different places,
> which is inconvenient.

This really sounds like a Linux policy issue rather than something that
should be described in dt.

Presumably there's a reason we sanity cehck this in the first place.
What happens while the battery isn't plugged in? What can fail, and how?

Mark.

> Add the "sbs,always-present" option to the device tree. If set, the
> battery is instantiated without sanity checking the connection.

>From the description above, this name is incorrect. You're adding this
property to work around the battery _not_ being present at probe-time.
>From a binding point of view, "instantiated" is somewhat meaningless --
that's an OS level detail rather than a contract detail.

Mark.

> 
> Signed-off-by: Frans Klaver <frans.klaver@xsens.com>
> ---
>  drivers/power/sbs-battery.c       | 11 +++++++++--
>  include/linux/power/sbs-battery.h |  3 +++
>  2 files changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c
> index b5f2a76..5d327b5 100644
> --- a/drivers/power/sbs-battery.c
> +++ b/drivers/power/sbs-battery.c
> @@ -651,6 +651,9 @@ static struct sbs_platform_data *sbs_of_populate_pdata(
>  	if (!rc)
>  		pdata->poll_retry_count = prop;
>  
> +	pdata->always_present = of_property_read_bool(of_node,
> +						      "sbs,always-present");
> +
>  	if (!of_get_property(of_node, "sbs,battery-detect-gpios", NULL)) {
>  		pdata->battery_detect = -1;
>  		goto of_out;
> @@ -761,10 +764,14 @@ static int sbs_probe(struct i2c_client *client,
>  
>  skip_gpio:
>  	/*
> -	 * Before we register, we need to make sure we can actually talk
> +	 * Before we register, we might need to make sure we can actually talk
>  	 * to the battery.
>  	 */
> -	rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
> +	if (!pdata->always_present)
> +		rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
> +	else
> +		rc = 0;
> +
>  	if (rc < 0) {
>  		dev_err(&client->dev, "%s: Failed to get device status\n",
>  			__func__);
> diff --git a/include/linux/power/sbs-battery.h b/include/linux/power/sbs-battery.h
> index 2b0a9d9..724bd9b 100644
> --- a/include/linux/power/sbs-battery.h
> +++ b/include/linux/power/sbs-battery.h
> @@ -31,12 +31,15 @@
>   * @i2c_retry_count:		# of times to retry on i2c IO failure
>   * @poll_retry_count:		# of times to retry looking for new status after
>   *				external change notification
> + * @always_present:		the device is instantiated even if the battery
> + *				is not physically present
>   */
>  struct sbs_platform_data {
>  	int battery_detect;
>  	int battery_detect_present;
>  	int i2c_retry_count;
>  	int poll_retry_count;
> +	bool always_present;
>  };
>  
>  #endif
> -- 
> 2.1.0
> 
> 

  reply	other threads:[~2014-09-24 13:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24 13:11 [RFC PATCH 0/2] explicitly instantiate battery from device tree Frans Klaver
2014-09-24 13:11 ` [RFC PATCH 1/2] sbs-battery: add forced instantiation " Frans Klaver
2014-09-24 13:16   ` Mark Rutland [this message]
2014-09-24 14:22     ` Frans Klaver
2014-09-24 14:38       ` Mark Rutland
2014-09-24 15:14         ` Frans Klaver
2014-09-24 15:34           ` Mark Rutland
2014-09-24 18:59             ` Frans Klaver
2014-09-25  9:27               ` Mark Rutland
2014-09-25  9:32                 ` Frans Klaver
     [not found]                   ` <CAH6sp9O=Hb3uGk3=5Gc+bb+AAZVZu=xHqNnUBHPG8BJUn==ZzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-10-07 12:37                     ` Frans Klaver
2014-09-24 13:11 ` [PATCH 2/2] sbs-battery: dts: document always-present property Frans Klaver

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=20140924131655.GG5729@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=Pawel.Moll@arm.com \
    --cc=dbaryshkov@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=frans.klaver@xsens.com \
    --cc=galak@codeaurora.org \
    --cc=ijc+devicetree@hellion.org.uk \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rdunlap@infradead.org \
    --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).