Re: [PATCH 1/1] dt-bindings: power/supply/sbs_sbs-battery: Addition of force_load binding Add device tree binding documentation for addition of force_load boolean value to allow loading a battery duri

2019-08-18 Thread Richard Tresidder

There is a force load option when loading the driver as a module.
This adds the equivalent methodology for the binding path.
Though I suppose you could in fact just force load if the gpio detect 
isn't present.
Thats a good idea, just wasn't the existing driver flow. I can't think 
of any reason why we couldn't do that though.


I'll update the patch and resubmit V3
Will add a note about it in the docs

Please note I'd submitted this incorrectly when using our patch script 
last time, it's now correctly part of the combined patch


Regards
  Richard Tresidder
Richard Tresidder


**
On 17/08/2019 5:14 am, Rob Herring wrote:

On Thu, Jul 25, 2019 at 02:50:45PM +0800, Richard Tresidder wrote:

Signed-off-by: Richard Tresidder 
---

Notes:
 Add device tree binding documentation for addition of force_load
 boolean value to allow loading a battery during boot even if not
 present at that time.
 Accompanying patch to drivers/power/supply/sbs-battery.c submitted to 
linux...@vger.kernel.org

  Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt 
b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
index 4e78e51..187d7bb 100644
--- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
@@ -15,7 +15,8 @@ Optional properties :
 after an external change notification.
   - sbs,battery-detect-gpios : The gpio which signals battery detection and
 a flag specifying its polarity.
-
+ - sbs,force-load : Allow loading of a hot-pluggable battery when there is no
+   GPIO detect available and the module is statically built.

What's a module? That's Linux specific and nothing to do with the
binding.

Can't you just force load if sbs,battery-detect-gpios is not present?

Rob






[RESEND v2 0/2] power/supply/sbs-battery: Add ability to force load a battery via the devicetree

2019-07-30 Thread Richard Tresidder
Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Richard Tresidder (2):
  dt-binding docs: sbs_sbs-battery: Addition of force_load binding
  power/supply/sbs-battery: Add ability to force load a battery via the
devicetree

 Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt | 4 +++-
 drivers/power/supply/sbs-battery.c | 6 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

-- 
1.8.3.1



[RESEND v2 2/2] power/supply/sbs-battery: Add ability to force load a battery via the devicetree

2019-07-30 Thread Richard Tresidder
Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Signed-off-by: Richard Tresidder 
---
 drivers/power/supply/sbs-battery.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..b55721d 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -816,6 +816,7 @@ static int sbs_probe(struct i2c_client *client,
struct power_supply_config psy_cfg = {};
int rc;
int irq;
+   bool dt_force_load;
 
sbs_desc = devm_kmemdup(>dev, _default_desc,
sizeof(*sbs_desc), GFP_KERNEL);
@@ -852,6 +853,9 @@ static int sbs_probe(struct i2c_client *client,
if (rc)
chip->poll_retry_count = 0;
 
+   dt_force_load = of_property_read_bool(client->dev.of_node,
+   "sbs,force-load");
+
if (pdata) {
chip->poll_retry_count = pdata->poll_retry_count;
chip->i2c_retry_count  = pdata->i2c_retry_count;
@@ -890,7 +894,7 @@ static int sbs_probe(struct i2c_client *client,
 * Before we register, we might need to make sure we can actually talk
 * to the battery.
 */
-   if (!(force_load || chip->gpio_detect)) {
+   if (!(force_load || chip->gpio_detect || dt_force_load)) {
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
 
if (rc < 0) {
-- 
1.8.3.1



[RESEND v2 1/2] dt-binding docs: sbs_sbs-battery: Addition of force_load binding

2019-07-30 Thread Richard Tresidder
Add device tree binding documentation for addition of force_load boolean value
to allow loading a battery during boot even if notpresent at that time.

Signed-off-by: Richard Tresidder 
---
 Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt 
b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
index 4e78e51..187d7bb 100644
--- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
@@ -15,7 +15,8 @@ Optional properties :
after an external change notification.
  - sbs,battery-detect-gpios : The gpio which signals battery detection and
a flag specifying its polarity.
-
+ - sbs,force-load : Allow loading of a hot-pluggable battery when there is no
+   GPIO detect available and the module is statically built.
 Example:
 
battery@b {
@@ -24,4 +25,5 @@ Example:
sbs,i2c-retry-count = <2>;
sbs,poll-retry-count = <10>;
sbs,battery-detect-gpios = < 122 1>;
+   sbs,force-load;
}
-- 
1.8.3.1



[PATCH v2 1/1] power/supply/sbs-battery: Add ability to force load a battery via the devicetree

2019-07-30 Thread Richard Tresidder
Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Signed-off-by: Richard Tresidder 
---

Notes:
sbs_battery: Add ability to force load from devicetree

Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

v2: move forceload variable to a local in probe.
merge device tree documentation into this patch

 drivers/power/supply/sbs-battery.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..b55721d 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -816,6 +816,7 @@ static int sbs_probe(struct i2c_client *client,
struct power_supply_config psy_cfg = {};
int rc;
int irq;
+   bool dt_force_load;
 
sbs_desc = devm_kmemdup(>dev, _default_desc,
sizeof(*sbs_desc), GFP_KERNEL);
@@ -852,6 +853,9 @@ static int sbs_probe(struct i2c_client *client,
if (rc)
chip->poll_retry_count = 0;
 
+   dt_force_load = of_property_read_bool(client->dev.of_node,
+   "sbs,force-load");
+
if (pdata) {
chip->poll_retry_count = pdata->poll_retry_count;
chip->i2c_retry_count  = pdata->i2c_retry_count;
@@ -890,7 +894,7 @@ static int sbs_probe(struct i2c_client *client,
 * Before we register, we might need to make sure we can actually talk
 * to the battery.
 */
-   if (!(force_load || chip->gpio_detect)) {
+   if (!(force_load || chip->gpio_detect || dt_force_load)) {
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
 
if (rc < 0) {
-- 
1.8.3.1



Re: [PATCH 1/1] power: supply: sbs-battery: Add ability to force load a battery via the devicetree

2019-07-29 Thread Richard Tresidder

Hi Guenter
  See below
Richard Tresidder

Cheers

  Richard Tresidder

**
On 30/07/2019 12:09 pm, Guenter Roeck wrote:

On Mon, Jul 29, 2019 at 8:02 PM Richard Tresidder
 wrote:

Hi Nick and Guenter
Just adding you to this one also seeing as you're looking at that other
sbs_battery patch for me.
Not sure why the get maintainers didn't list you for this one.

Cheers
 Richard Tresidder

Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Signed-off-by: Richard Tresidder 
---

Notes:
  Add the ability to force load a hot pluggable battery during boot where
  there is no gpio detect method available and the module is statically
  built. Normal polling will then occur on that battery when it is inserted.

   drivers/power/supply/sbs-battery.c | 6 +-
   1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..ea8ba3e 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -161,6 +161,7 @@ struct sbs_info {
   int poll_time;
   u32 i2c_retry_count;
   u32 poll_retry_count;
+ boolforce_load;
   struct delayed_work work;
   struct mutexmode_lock;
   u32 flags;
@@ -852,6 +853,9 @@ static int sbs_probe(struct i2c_client *client,
   if (rc)
   chip->poll_retry_count = 0;

+ chip->force_load = of_property_read_bool(client->dev.of_node,
+ "sbs,force-load");
+

Maybe it is documented in another patch, which I have not seen. If it
isn't, it will have to be documented and reviewed by a devicetree
maintainer. Either case, I don't immediately see why the variable
needs to reside in struct sbs_info; it seems to be used only in the
probe function.
Good point, we don't actually need to store the value, it can just be a 
local.
Yep I had done a device tree documentation patch, but confused myself 
when submitting due to it having to be in a separate patch
I think I need to create 2 different patches but submit in the same 
email via send-patch as a multipart patch..

I'll try to fix that when I send it in again.



   if (pdata) {
   chip->poll_retry_count = pdata->poll_retry_count;
   chip->i2c_retry_count  = pdata->i2c_retry_count;
@@ -890,7 +894,7 @@ static int sbs_probe(struct i2c_client *client,
* Before we register, we might need to make sure we can actually talk
* to the battery.
*/
- if (!(force_load || chip->gpio_detect)) {
+ if (!(force_load || chip->gpio_detect || chip->force_load)) {
   rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);

   if (rc < 0) {






Re: [PATCH 1/1] power: supply: sbs-battery: Add ability to force load a battery via the devicetree

2019-07-29 Thread Richard Tresidder

Hi Nick and Guenter
Just adding you to this one also seeing as you're looking at that other 
sbs_battery patch for me.

Not sure why the get maintainers didn't list you for this one.

Cheers
   Richard Tresidder

Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Signed-off-by: Richard Tresidder 
---

Notes:
 Add the ability to force load a hot pluggable battery during boot where
 there is no gpio detect method available and the module is statically
 built. Normal polling will then occur on that battery when it is inserted.

  drivers/power/supply/sbs-battery.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..ea8ba3e 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -161,6 +161,7 @@ struct sbs_info {
int poll_time;
u32 i2c_retry_count;
u32 poll_retry_count;
+   boolforce_load;
struct delayed_work work;
struct mutexmode_lock;
u32 flags;
@@ -852,6 +853,9 @@ static int sbs_probe(struct i2c_client *client,
if (rc)
chip->poll_retry_count = 0;
  
+	chip->force_load = of_property_read_bool(client->dev.of_node,

+   "sbs,force-load");
+
if (pdata) {
chip->poll_retry_count = pdata->poll_retry_count;
chip->i2c_retry_count  = pdata->i2c_retry_count;
@@ -890,7 +894,7 @@ static int sbs_probe(struct i2c_client *client,
 * Before we register, we might need to make sure we can actually talk
 * to the battery.
 */
-   if (!(force_load || chip->gpio_detect)) {
+   if (!(force_load || chip->gpio_detect || chip->force_load)) {
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
  
  		if (rc < 0) {




[PATCH v4 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty

2019-07-29 Thread Richard Tresidder
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as NOT CHARGING.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

Signed-off-by: Richard Tresidder 
---

Notes:
power/supply/sbs-battery: Fix confusing battery status when idle or empty

When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as NOT CHARGING.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

v2: Missed a later merge that should have been included in original patch
v3: Refactor the sbs_status_correct function to capture all the states for
normal operation rather than being spread across multile functions.
v4: Remove unnecessary brackets, rename sbs_status_correct to
sbs_correct_battery_status

 drivers/power/supply/power_supply_sysfs.c |  2 +-
 drivers/power/supply/sbs-battery.c| 46 ---
 include/linux/power_supply.h  |  1 +
 3 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index f37ad4e..305e833 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,7 @@
 };
 
 static const char * const power_supply_status_text[] = {
-   "Unknown", "Charging", "Discharging", "Not charging", "Full"
+   "Unknown", "Charging", "Discharging", "Not charging", "Full", "Empty"
 };
 
 static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..3ed70d4 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -283,7 +283,7 @@ static int sbs_write_word_data(struct i2c_client *client, 
u8 address,
return 0;
 }
 
-static int sbs_status_correct(struct i2c_client *client, int *intval)
+static int sbs_correct_battery_status(struct i2c_client *client, int *status)
 {
int ret;
 
@@ -293,16 +293,18 @@ static int sbs_status_correct(struct i2c_client *client, 
int *intval)
 
ret = (s16)ret;
 
-   /* Not drawing current means full (cannot be not charging) */
-   if (ret == 0)
-   *intval = POWER_SUPPLY_STATUS_FULL;
-
-   if (*intval == POWER_SUPPLY_STATUS_FULL) {
-   /* Drawing or providing current when full */
-   if (ret > 0)
-   *intval = POWER_SUPPLY_STATUS_CHARGING;
-   else if (ret < 0)
-   *intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   if (ret > 0)
+   *status = POWER_SUPPLY_STATUS_CHARGING;
+   else if (ret < 0)
+   *status = POWER_SUPPLY_STATUS_DISCHARGING;
+   else {
+   /* Current is 0, so how full is the battery? */
+   if (*status & BATTERY_FULL_CHARGED)
+   *status = POWER_SUPPLY_STATUS_FULL;
+   else if (*status & BATTERY_FULL_DISCHARGED)
+   *status = POWER_SUPPLY_STATUS_EMPTY;
+   else
+   *status = POWER_SUPPLY_STATUS_NOT_CHARGING;
}
 
return 0;
@@ -421,14 +423,9 @@ static int sbs_get_battery_property(struct i2c_client 
*client,
return 0;
}
 
-   if (ret & BATTERY_FULL_CHARGED)
-   val->intval = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
-   val->intval = POWER_SUPPLY_STATUS_CHARGING;
-
-   sbs_status_correct(client, >intval);
+   ret = sbs_correct_battery_status(client, >intval);
+   if (ret < 0)
+   return ret;
 
if (chip->poll_time == 0)
chip->last_state = val->intval;
@@ -773,20 +770,11 @@ static void sbs_delayed_work(struct work_struct *work)
 
ret = sbs_read_word_data(chip->client, sbs_data[REG_STATUS].addr);
/* if the read failed, give up on this work */
-   if (ret < 0) {
+   if (ret < 0 || sbs_correct_battery_status(chip->client, ) < 0) {
chip-&g

[PATCH v3 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty

2019-07-29 Thread Richard Tresidder
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as NOT CHARGING.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

Signed-off-by: Richard Tresidder 
---

Notes:
power/supply/sbs-battery: Fix confusing battery status when idle or empty

When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as NOT CHARGING.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

v2: Missed a later merge that should have been included in original patch
v3: Refactor the sbs_status_correct function to capture all the states for
normal operation rather than being spread across multile functions.

 drivers/power/supply/power_supply_sysfs.c |  2 +-
 drivers/power/supply/sbs-battery.c| 44 +++
 include/linux/power_supply.h  |  1 +
 3 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index f37ad4e..305e833 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,7 @@
 };
 
 static const char * const power_supply_status_text[] = {
-   "Unknown", "Charging", "Discharging", "Not charging", "Full"
+   "Unknown", "Charging", "Discharging", "Not charging", "Full", "Empty"
 };
 
 static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..b28402d 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -293,16 +293,18 @@ static int sbs_status_correct(struct i2c_client *client, 
int *intval)
 
ret = (s16)ret;
 
-   /* Not drawing current means full (cannot be not charging) */
-   if (ret == 0)
-   *intval = POWER_SUPPLY_STATUS_FULL;
-
-   if (*intval == POWER_SUPPLY_STATUS_FULL) {
-   /* Drawing or providing current when full */
-   if (ret > 0)
-   *intval = POWER_SUPPLY_STATUS_CHARGING;
-   else if (ret < 0)
-   *intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   if (ret > 0)
+   *intval = POWER_SUPPLY_STATUS_CHARGING;
+   else if (ret < 0)
+   *intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   else {
+   /* Current is 0, so how full is the battery? */
+   if (*intval & BATTERY_FULL_CHARGED)
+   *intval = POWER_SUPPLY_STATUS_FULL;
+   else if (*intval & BATTERY_FULL_DISCHARGED)
+   *intval = POWER_SUPPLY_STATUS_EMPTY;
+   else
+   *intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
}
 
return 0;
@@ -421,14 +423,9 @@ static int sbs_get_battery_property(struct i2c_client 
*client,
return 0;
}
 
-   if (ret & BATTERY_FULL_CHARGED)
-   val->intval = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
-   val->intval = POWER_SUPPLY_STATUS_CHARGING;
-
-   sbs_status_correct(client, >intval);
+   ret = sbs_status_correct(client, >intval);
+   if (ret < 0)
+   return ret;
 
if (chip->poll_time == 0)
chip->last_state = val->intval;
@@ -773,20 +770,11 @@ static void sbs_delayed_work(struct work_struct *work)
 
ret = sbs_read_word_data(chip->client, sbs_data[REG_STATUS].addr);
/* if the read failed, give up on this work */
-   if (ret < 0) {
+   if ((ret < 0) || (sbs_status_correct(chip->client, ) < 0)) {
chip->poll_time = 0;
return;
}
 
-   if (ret & BATTERY_FULL_CHARGED)
-   ret = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   ret = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
-   ret = POWER_SUPPLY_STATUS_CHARGING;
-
-   sbs_status_correct(chip->client, );
-
if (chip->last_state != ret) {

Re: [PATCH 1/1] power/supply/powersupply_sysfs: Add of_node name to uevent message if available

2019-07-25 Thread Richard Tresidder

Hi David
  That it would be. I wasn't aware of that call.
I'll give it a crack and send in a new version of the patch.

Cheers
  Richard Tresidder

Richard Tresidder
On 25/07/2019 10:08 pm, David Lechner wrote:

On 7/25/19 2:47 AM, Richard Tresidder wrote:
If the of_node name of the supply is available from the devicetree 
binding

then include it under the var POWER_SUPPLY_OF_NODE_NAME.
This helps where a consistent name is known via the device tree binding
but it is hard to identify based on the usual enumeration process.



Would it be possible to use of_device_uevent() instead of introducing 
a new

property?







Re: [PATCH 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty

2019-07-25 Thread Richard Tresidder

Hi Guenter
   Yep sorry there was a merge that I missed during that initial send 
of the patch.

I sent a version 2 shortly after.

Regards
   Richard Tresidder

On 25/07/2019 9:39 pm, Guenter Roeck wrote:

On Thu, Jul 25, 2019 at 1:25 AM Richard Tresidder
 wrote:

When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect
status indication of FULL for the battery simply because it wasn't
discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

Signed-off-by: Richard Tresidder 
---

Notes:
 power/supply/sbs-battery: Fix confusing battery status when idle or empty

 When a battery or batteries in a system are in parallel then one or more
 may not be providing any current to the system.
 This fixes an incorrect
 status indication of FULL for the battery simply because it wasn't
 discharging at that point in time.
 The battery will now be flagged as IDLE.
 Have also added the additional check for the battery FULL DISCHARGED flag
 which will now flag a status of EMPTY.

  drivers/power/supply/power_supply_sysfs.c |  3 ++-
  drivers/power/supply/sbs-battery.c| 28 ++--
  include/linux/power_supply.h  |  2 ++
  3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index ce6671c..68ec49d 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,8 @@
  };

  static const char * const power_supply_status_text[] = {
-   "Unknown", "Charging", "Discharging", "Not charging", "Full"
+   "Unknown", "Charging", "Discharging", "Not charging", "Full",
+   "Empty", "Idle"
  };

  static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index ea8ba3e..e6c636c 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -294,14 +294,10 @@ static int sbs_status_correct(struct i2c_client *client, 
int *intval)

 ret = (s16)ret;

-   /* Not drawing current means full (cannot be not charging) */
-   if (ret == 0)
-   *intval = POWER_SUPPLY_STATUS_FULL;
-
-   if (*intval == POWER_SUPPLY_STATUS_FULL) {
-   /* Drawing or providing current when full */
-   if (ret > 0)
-   *intval = POWER_SUPPLY_STATUS_CHARGING;
+   if (*intval == POWER_SUPPLY_STATUS_DISCHARGING) {
+   /* Charging indicator not set in battery */
+   if (ret == 0)
+   *intval = POWER_SUPPLY_STATUS_IDLE;

But doesn't the above already indicate that it _is_ discharging ?


 else if (ret < 0)
 *intval = POWER_SUPPLY_STATUS_DISCHARGING;

This doesn't make sense. *intval is already set to
POWER_SUPPLY_STATUS_DISCHARGING
in this situation.


 }
@@ -424,10 +420,12 @@ static int sbs_get_battery_property(struct i2c_client 
*client,

 if (ret & BATTERY_FULL_CHARGED)
 val->intval = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   val->intval = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
 val->intval = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;

 sbs_status_correct(client, >intval);

@@ -781,10 +779,12 @@ static void sbs_delayed_work(struct work_struct *work)

 if (ret & BATTERY_FULL_CHARGED)
 ret = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   ret = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   ret = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
 ret = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   ret = POWER_SUPPLY_STATUS_DISCHARGING;

 sbs_status_correct(chip->client, );

diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 28413f7..c9f3347 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -37,6 +37,8 @@ enum {
 POWER_SUPPLY_STATUS_DISCHARGING,
 POWER_SUPPLY_STATUS_NOT_CHARGING,
 POWER_SUPPLY_STATUS_FULL,
+   POWER_SUPPLY_STATUS_EMPTY,
+   POWER_SUPPLY_STATUS_IDLE,
  };

  /* What algorithm is the charger using? */
--
1.8.3.1







[RESEND v2 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty

2019-07-25 Thread Richard Tresidder
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect status indication of FULL for the battery simply
because it wasn't discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

Signed-off-by: Richard Tresidder 
---

Notes:
power/supply/sbs-battery: Fix confusing battery status when idle or empty

When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect
status indication of FULL for the battery simply because it wasn't
discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

v2: missed a later merge that should have been included in original patch

 drivers/power/supply/power_supply_sysfs.c |  3 ++-
 drivers/power/supply/sbs-battery.c| 32 +++
 include/linux/power_supply.h  |  2 ++
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index ce6671c..68ec49d 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,8 @@
 };
 
 static const char * const power_supply_status_text[] = {
-   "Unknown", "Charging", "Discharging", "Not charging", "Full"
+   "Unknown", "Charging", "Discharging", "Not charging", "Full",
+   "Empty", "Idle"
 };
 
 static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index ea8ba3e..664c317 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -294,16 +294,12 @@ static int sbs_status_correct(struct i2c_client *client, 
int *intval)
 
ret = (s16)ret;
 
-   /* Not drawing current means full (cannot be not charging) */
-   if (ret == 0)
-   *intval = POWER_SUPPLY_STATUS_FULL;
-
-   if (*intval == POWER_SUPPLY_STATUS_FULL) {
-   /* Drawing or providing current when full */
-   if (ret > 0)
-   *intval = POWER_SUPPLY_STATUS_CHARGING;
-   else if (ret < 0)
-   *intval = POWER_SUPPLY_STATUS_DISCHARGING;
+   if ((*intval == POWER_SUPPLY_STATUS_DISCHARGING && (ret == 0)) {
+   /* Charging indicator not set in battery */
+   *intval = POWER_SUPPLY_STATUS_IDLE;
+   } else if ((*intval == POWER_SUPPLY_STATUS_FULL) && (ret < 0)) {
+   /* Full Flag set but we are discharging */
+   *intval = POWER_SUPPLY_STATUS_DISCHARGING;
}
 
return 0;
@@ -424,10 +420,12 @@ static int sbs_get_battery_property(struct i2c_client 
*client,
 
if (ret & BATTERY_FULL_CHARGED)
val->intval = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   val->intval = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
 
sbs_status_correct(client, >intval);
 
@@ -781,10 +779,12 @@ static void sbs_delayed_work(struct work_struct *work)
 
if (ret & BATTERY_FULL_CHARGED)
ret = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   ret = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   ret = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
ret = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   ret = POWER_SUPPLY_STATUS_DISCHARGING;
 
sbs_status_correct(chip->client, );
 
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 28413f7..c9f3347 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -37,6 +37,8 @@ enum {
POWER_SUPPLY_STATUS_DISCHARGING,
POWER_SUPPLY_STATUS_NOT_CHARGING,
POWER_SUPPLY_STATUS_FULL,
+   POWER_SUPPLY_STATUS_EMPTY,
+   POWER_SUPPLY_STATUS_IDLE,
 };
 
 /* What algorithm is the charger using? */
-- 
1.8.3.1



[PATCH 1/1] power/supply/sbs-battery: Fix confusing battery status when idle or empty

2019-07-25 Thread Richard Tresidder
When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect
status indication of FULL for the battery simply because it wasn't
discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

Signed-off-by: Richard Tresidder 
---

Notes:
power/supply/sbs-battery: Fix confusing battery status when idle or empty

When a battery or batteries in a system are in parallel then one or more
may not be providing any current to the system.
This fixes an incorrect
status indication of FULL for the battery simply because it wasn't
discharging at that point in time.
The battery will now be flagged as IDLE.
Have also added the additional check for the battery FULL DISCHARGED flag
which will now flag a status of EMPTY.

 drivers/power/supply/power_supply_sysfs.c |  3 ++-
 drivers/power/supply/sbs-battery.c| 28 ++--
 include/linux/power_supply.h  |  2 ++
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index ce6671c..68ec49d 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -51,7 +51,8 @@
 };
 
 static const char * const power_supply_status_text[] = {
-   "Unknown", "Charging", "Discharging", "Not charging", "Full"
+   "Unknown", "Charging", "Discharging", "Not charging", "Full",
+   "Empty", "Idle"
 };
 
 static const char * const power_supply_charge_type_text[] = {
diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index ea8ba3e..e6c636c 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -294,14 +294,10 @@ static int sbs_status_correct(struct i2c_client *client, 
int *intval)
 
ret = (s16)ret;
 
-   /* Not drawing current means full (cannot be not charging) */
-   if (ret == 0)
-   *intval = POWER_SUPPLY_STATUS_FULL;
-
-   if (*intval == POWER_SUPPLY_STATUS_FULL) {
-   /* Drawing or providing current when full */
-   if (ret > 0)
-   *intval = POWER_SUPPLY_STATUS_CHARGING;
+   if (*intval == POWER_SUPPLY_STATUS_DISCHARGING) {
+   /* Charging indicator not set in battery */
+   if (ret == 0)
+   *intval = POWER_SUPPLY_STATUS_IDLE;
else if (ret < 0)
*intval = POWER_SUPPLY_STATUS_DISCHARGING;
}
@@ -424,10 +420,12 @@ static int sbs_get_battery_property(struct i2c_client 
*client,
 
if (ret & BATTERY_FULL_CHARGED)
val->intval = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   val->intval = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
val->intval = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
 
sbs_status_correct(client, >intval);
 
@@ -781,10 +779,12 @@ static void sbs_delayed_work(struct work_struct *work)
 
if (ret & BATTERY_FULL_CHARGED)
ret = POWER_SUPPLY_STATUS_FULL;
-   else if (ret & BATTERY_DISCHARGING)
-   ret = POWER_SUPPLY_STATUS_DISCHARGING;
-   else
+   else if (ret & BATTERY_FULL_DISCHARGED)
+   ret = POWER_SUPPLY_STATUS_EMPTY;
+   else if (!(ret & BATTERY_DISCHARGING))
ret = POWER_SUPPLY_STATUS_CHARGING;
+   else
+   ret = POWER_SUPPLY_STATUS_DISCHARGING;
 
sbs_status_correct(chip->client, );
 
diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h
index 28413f7..c9f3347 100644
--- a/include/linux/power_supply.h
+++ b/include/linux/power_supply.h
@@ -37,6 +37,8 @@ enum {
POWER_SUPPLY_STATUS_DISCHARGING,
POWER_SUPPLY_STATUS_NOT_CHARGING,
POWER_SUPPLY_STATUS_FULL,
+   POWER_SUPPLY_STATUS_EMPTY,
+   POWER_SUPPLY_STATUS_IDLE,
 };
 
 /* What algorithm is the charger using? */
-- 
1.8.3.1



[PATCH 1/1] power/supply/powersupply_sysfs: Add of_node name to uevent message if available

2019-07-25 Thread Richard Tresidder
If the of_node name of the supply is available from the devicetree binding
then include it under the var POWER_SUPPLY_OF_NODE_NAME.
This helps where a consistent name is known via the device tree binding
but it is hard to identify based on the usual enumeration process.

Signed-off-by: Richard Tresidder 
---

Notes:
power/supply/powersupply_sysfs: Add of_node name to uevent message if 
available

If the of_node name of the supply is available from the devicetree binding
then include it under the var POWER_SUPPLY_OF_NODE_NAME.
This helps where a consistent name is known via the device tree binding
but it is hard to identify based on the usual enumeration process.

 drivers/power/supply/power_supply_sysfs.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/power/supply/power_supply_sysfs.c 
b/drivers/power/supply/power_supply_sysfs.c
index f37ad4e..ce6671c 100644
--- a/drivers/power/supply/power_supply_sysfs.c
+++ b/drivers/power/supply/power_supply_sysfs.c
@@ -395,6 +395,13 @@ int power_supply_uevent(struct device *dev, struct 
kobj_uevent_env *env)
if (ret)
return ret;
 
+   if (psy->of_node) {
+   ret = add_uevent_var(env, "POWER_SUPPLY_OF_NODE_NAME=%s",
+psy->of_node->name);
+   if (ret)
+   return ret;
+   }
+
prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
if (!prop_buf)
return -ENOMEM;
-- 
1.8.3.1



[PATCH 1/1] dt-bindings: power/supply/sbs_sbs-battery: Addition of force_load binding Add device tree binding documentation for addition of force_load boolean value to allow loading a battery during b

2019-07-25 Thread Richard Tresidder
Signed-off-by: Richard Tresidder 
---

Notes:
Add device tree binding documentation for addition of force_load
boolean value to allow loading a battery during boot even if not
present at that time.
Accompanying patch to drivers/power/supply/sbs-battery.c submitted to 
linux...@vger.kernel.org

 Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt 
b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
index 4e78e51..187d7bb 100644
--- a/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
+++ b/Documentation/devicetree/bindings/power/supply/sbs_sbs-battery.txt
@@ -15,7 +15,8 @@ Optional properties :
after an external change notification.
  - sbs,battery-detect-gpios : The gpio which signals battery detection and
a flag specifying its polarity.
-
+ - sbs,force-load : Allow loading of a hot-pluggable battery when there is no
+   GPIO detect available and the module is statically built.
 Example:
 
battery@b {
@@ -24,4 +25,5 @@ Example:
sbs,i2c-retry-count = <2>;
sbs,poll-retry-count = <10>;
sbs,battery-detect-gpios = < 122 1>;
+   sbs,force-load;
}
-- 
1.8.3.1



[PATCH 1/1] power: supply: sbs-battery: Add ability to force load a battery via the devicetree

2019-07-24 Thread Richard Tresidder
Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

Signed-off-by: Richard Tresidder 
---

Notes:
Add the ability to force load a hot pluggable battery during boot where
there is no gpio detect method available and the module is statically
built. Normal polling will then occur on that battery when it is inserted.

 drivers/power/supply/sbs-battery.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/sbs-battery.c 
b/drivers/power/supply/sbs-battery.c
index 048d205..ea8ba3e 100644
--- a/drivers/power/supply/sbs-battery.c
+++ b/drivers/power/supply/sbs-battery.c
@@ -161,6 +161,7 @@ struct sbs_info {
int poll_time;
u32 i2c_retry_count;
u32 poll_retry_count;
+   boolforce_load;
struct delayed_work work;
struct mutexmode_lock;
u32 flags;
@@ -852,6 +853,9 @@ static int sbs_probe(struct i2c_client *client,
if (rc)
chip->poll_retry_count = 0;
 
+   chip->force_load = of_property_read_bool(client->dev.of_node,
+   "sbs,force-load");
+
if (pdata) {
chip->poll_retry_count = pdata->poll_retry_count;
chip->i2c_retry_count  = pdata->i2c_retry_count;
@@ -890,7 +894,7 @@ static int sbs_probe(struct i2c_client *client,
 * Before we register, we might need to make sure we can actually talk
 * to the battery.
 */
-   if (!(force_load || chip->gpio_detect)) {
+   if (!(force_load || chip->gpio_detect || chip->force_load)) {
rc = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
 
if (rc < 0) {
-- 
1.8.3.1