2021-05-07 17:35:13

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [RFT PATCH 1/3] power: supply: max17040: remove non-working POWER_SUPPLY_PROP_STATUS

The driver was reporting POWER_SUPPLY_PROP_STATUS via platform data
functions. Without platform data, the max17040_get_status() functions
returns early with POWER_SUPPLY_STATUS_UNKNOWN. Since there are no
platforms using the driver with platform data (no board files with the
driver), the status property was always unknown.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/power/supply/max17040_battery.c | 32 +++----------------------
1 file changed, 3 insertions(+), 29 deletions(-)

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 1aab868adabf..12854c87df53 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -147,8 +147,6 @@ struct max17040_chip {

/* battery capacity */
int soc;
- /* State Of Charge */
- int status;
/* Low alert threshold from 32% to 1% of the State of Charge */
u32 low_soc_alert;
/* some devices return twice the capacity */
@@ -225,24 +223,6 @@ static int max17040_get_online(struct max17040_chip *chip)
chip->pdata->battery_online() : 1;
}

-static int max17040_get_status(struct max17040_chip *chip)
-{
- if (!chip->pdata || !chip->pdata->charger_online
- || !chip->pdata->charger_enable)
- return POWER_SUPPLY_STATUS_UNKNOWN;
-
- if (max17040_get_soc(chip) > MAX17040_BATTERY_FULL)
- return POWER_SUPPLY_STATUS_FULL;
-
- if (chip->pdata->charger_online())
- if (chip->pdata->charger_enable())
- return POWER_SUPPLY_STATUS_CHARGING;
- else
- return POWER_SUPPLY_STATUS_NOT_CHARGING;
- else
- return POWER_SUPPLY_STATUS_DISCHARGING;
-}
-
static int max17040_get_of_data(struct max17040_chip *chip)
{
struct device *dev = &chip->client->dev;
@@ -283,7 +263,6 @@ static int max17040_get_of_data(struct max17040_chip *chip)
static void max17040_check_changes(struct max17040_chip *chip)
{
chip->soc = max17040_get_soc(chip);
- chip->status = max17040_get_status(chip);
}

static void max17040_queue_work(struct max17040_chip *chip)
@@ -302,17 +281,16 @@ static void max17040_stop_work(void *data)
static void max17040_work(struct work_struct *work)
{
struct max17040_chip *chip;
- int last_soc, last_status;
+ int last_soc;

chip = container_of(work, struct max17040_chip, work.work);

- /* store SOC and status to check changes */
+ /* store SOC to check changes */
last_soc = chip->soc;
- last_status = chip->status;
max17040_check_changes(chip);

/* check changes and send uevent */
- if (last_soc != chip->soc || last_status != chip->status)
+ if (last_soc != chip->soc)
power_supply_changed(chip->battery);

max17040_queue_work(chip);
@@ -415,9 +393,6 @@ static int max17040_get_property(struct power_supply *psy,
struct max17040_chip *chip = power_supply_get_drvdata(psy);

switch (psp) {
- case POWER_SUPPLY_PROP_STATUS:
- val->intval = max17040_get_status(chip);
- break;
case POWER_SUPPLY_PROP_ONLINE:
val->intval = max17040_get_online(chip);
break;
@@ -444,7 +419,6 @@ static const struct regmap_config max17040_regmap = {
};

static enum power_supply_property max17040_battery_props[] = {
- POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
POWER_SUPPLY_PROP_CAPACITY,
--
2.25.1


2021-05-07 17:36:10

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [RFT PATCH 2/3] power: supply: max17040: simplify POWER_SUPPLY_PROP_ONLINE

The driver was reporting POWER_SUPPLY_PROP_ONLINE via platform data
functions or '1' if no platform data was provided. Since there are no
platforms using the driver with platform data (no board files with the
driver), the online property can be simplified to always return '1'.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/power/supply/max17040_battery.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 12854c87df53..d51c3443d732 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -219,8 +219,7 @@ static int max17040_get_version(struct max17040_chip *chip)

static int max17040_get_online(struct max17040_chip *chip)
{
- return chip->pdata && chip->pdata->battery_online ?
- chip->pdata->battery_online() : 1;
+ return 1;
}

static int max17040_get_of_data(struct max17040_chip *chip)
--
2.25.1

2021-05-07 17:37:43

by Krzysztof Kozlowski

[permalink] [raw]
Subject: [RFT PATCH 3/3] power: supply: max17040: drop unused platform data support

There are no platforms using the driver with platform data (no board
files with the driver), so the dead code can be dropped.

Signed-off-by: Krzysztof Kozlowski <[email protected]>
---
drivers/power/supply/max17040_battery.c | 3 ---
include/linux/max17040_battery.h | 16 ----------------
2 files changed, 19 deletions(-)
delete mode 100644 include/linux/max17040_battery.h

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index d51c3443d732..a8ba2c305034 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -16,7 +16,6 @@
#include <linux/interrupt.h>
#include <linux/power_supply.h>
#include <linux/of_device.h>
-#include <linux/max17040_battery.h>
#include <linux/regmap.h>
#include <linux/slab.h>

@@ -142,7 +141,6 @@ struct max17040_chip {
struct regmap *regmap;
struct delayed_work work;
struct power_supply *battery;
- struct max17040_platform_data *pdata;
struct chip_data data;

/* battery capacity */
@@ -453,7 +451,6 @@ static int max17040_probe(struct i2c_client *client,

chip->client = client;
chip->regmap = devm_regmap_init_i2c(client, &max17040_regmap);
- chip->pdata = client->dev.platform_data;
chip_id = (enum chip_id) id->driver_data;
if (client->dev.of_node) {
ret = max17040_get_of_data(chip);
diff --git a/include/linux/max17040_battery.h b/include/linux/max17040_battery.h
deleted file mode 100644
index 593602fc9317..000000000000
--- a/include/linux/max17040_battery.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2009 Samsung Electronics
- * Minkyu Kang <[email protected]>
- */
-
-#ifndef __MAX17040_BATTERY_H_
-#define __MAX17040_BATTERY_H_
-
-struct max17040_platform_data {
- int (*battery_online)(void);
- int (*charger_online)(void);
- int (*charger_enable)(void);
-};
-
-#endif
--
2.25.1

2021-06-04 12:06:08

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [RFT PATCH 1/3] power: supply: max17040: remove non-working POWER_SUPPLY_PROP_STATUS

Hi,

On Fri, May 07, 2021 at 12:19:25PM -0400, Krzysztof Kozlowski wrote:
> The driver was reporting POWER_SUPPLY_PROP_STATUS via platform data
> functions. Without platform data, the max17040_get_status() functions
> returns early with POWER_SUPPLY_STATUS_UNKNOWN. Since there are no
> platforms using the driver with platform data (no board files with the
> driver), the status property was always unknown.
>
> Signed-off-by: Krzysztof Kozlowski <[email protected]>
> ---

Thanks, I queued the series.

-- Sebastian

> drivers/power/supply/max17040_battery.c | 32 +++----------------------
> 1 file changed, 3 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
> index 1aab868adabf..12854c87df53 100644
> --- a/drivers/power/supply/max17040_battery.c
> +++ b/drivers/power/supply/max17040_battery.c
> @@ -147,8 +147,6 @@ struct max17040_chip {
>
> /* battery capacity */
> int soc;
> - /* State Of Charge */
> - int status;
> /* Low alert threshold from 32% to 1% of the State of Charge */
> u32 low_soc_alert;
> /* some devices return twice the capacity */
> @@ -225,24 +223,6 @@ static int max17040_get_online(struct max17040_chip *chip)
> chip->pdata->battery_online() : 1;
> }
>
> -static int max17040_get_status(struct max17040_chip *chip)
> -{
> - if (!chip->pdata || !chip->pdata->charger_online
> - || !chip->pdata->charger_enable)
> - return POWER_SUPPLY_STATUS_UNKNOWN;
> -
> - if (max17040_get_soc(chip) > MAX17040_BATTERY_FULL)
> - return POWER_SUPPLY_STATUS_FULL;
> -
> - if (chip->pdata->charger_online())
> - if (chip->pdata->charger_enable())
> - return POWER_SUPPLY_STATUS_CHARGING;
> - else
> - return POWER_SUPPLY_STATUS_NOT_CHARGING;
> - else
> - return POWER_SUPPLY_STATUS_DISCHARGING;
> -}
> -
> static int max17040_get_of_data(struct max17040_chip *chip)
> {
> struct device *dev = &chip->client->dev;
> @@ -283,7 +263,6 @@ static int max17040_get_of_data(struct max17040_chip *chip)
> static void max17040_check_changes(struct max17040_chip *chip)
> {
> chip->soc = max17040_get_soc(chip);
> - chip->status = max17040_get_status(chip);
> }
>
> static void max17040_queue_work(struct max17040_chip *chip)
> @@ -302,17 +281,16 @@ static void max17040_stop_work(void *data)
> static void max17040_work(struct work_struct *work)
> {
> struct max17040_chip *chip;
> - int last_soc, last_status;
> + int last_soc;
>
> chip = container_of(work, struct max17040_chip, work.work);
>
> - /* store SOC and status to check changes */
> + /* store SOC to check changes */
> last_soc = chip->soc;
> - last_status = chip->status;
> max17040_check_changes(chip);
>
> /* check changes and send uevent */
> - if (last_soc != chip->soc || last_status != chip->status)
> + if (last_soc != chip->soc)
> power_supply_changed(chip->battery);
>
> max17040_queue_work(chip);
> @@ -415,9 +393,6 @@ static int max17040_get_property(struct power_supply *psy,
> struct max17040_chip *chip = power_supply_get_drvdata(psy);
>
> switch (psp) {
> - case POWER_SUPPLY_PROP_STATUS:
> - val->intval = max17040_get_status(chip);
> - break;
> case POWER_SUPPLY_PROP_ONLINE:
> val->intval = max17040_get_online(chip);
> break;
> @@ -444,7 +419,6 @@ static const struct regmap_config max17040_regmap = {
> };
>
> static enum power_supply_property max17040_battery_props[] = {
> - POWER_SUPPLY_PROP_STATUS,
> POWER_SUPPLY_PROP_ONLINE,
> POWER_SUPPLY_PROP_VOLTAGE_NOW,
> POWER_SUPPLY_PROP_CAPACITY,
> --
> 2.25.1
>


Attachments:
(No filename) (3.61 kB)
signature.asc (849.00 B)
Download all attachments