Skip to content

Commit

Permalink
Merge tag 'for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git…
Browse files Browse the repository at this point in the history
…/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
 "Core:
   - add HWMON compat layer
   - new properties:
       - input power limit
       - input voltage limit

  Drivers:
   - qcom-pon: add gen2 support
   - new driver for storing reboot move in NVMEM
   - new driver for Wilco EC charger configuration
   - simplify getting the adapter of a client"

* tag 'for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply:
  power: reset: nvmem-reboot-mode: add CONFIG_OF dependency
  power_supply: wilco_ec: Add charging config driver
  power: supply: cros: allow to set input voltage and current limit
  power: supply: add input power and voltage limit properties
  power: supply: fix semicolon.cocci warnings
  power: reset: nvmem-reboot-mode: use NVMEM as reboot mode write interface
  dt-bindings: power: reset: add document for NVMEM based reboot-mode
  reset: qcom-pon: Add support for gen2 pon
  dt-bindings: power: reset: qcom: Add qcom,pm8998-pon compatibility line
  power: supply: Add HWMON compatibility layer
  power: supply: sbs-manager: simplify getting the adapter of a client
  power: supply: rt9455_charger: simplify getting the adapter of a client
  power: supply: rt5033_battery: simplify getting the adapter of a client
  power: supply: max17042_battery: simplify getting the adapter of a client
  power: supply: max17040_battery: simplify getting the adapter of a client
  power: supply: max14656_charger_detector: simplify getting the adapter of a client
  power: supply: bq25890_charger: simplify getting the adapter of a client
  power: supply: bq24257_charger: simplify getting the adapter of a client
  power: supply: bq24190_charger: simplify getting the adapter of a client
  • Loading branch information
torvalds committed Jul 16, 2019
2 parents fb4da21 + caa2b55 commit 5fe7b60
Show file tree
Hide file tree
Showing 27 changed files with 908 additions and 13 deletions.
32 changes: 32 additions & 0 deletions Documentation/ABI/testing/sysfs-class-power
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,42 @@ Description:
supply. Normally this is configured based on the type of
connection made (e.g. A configured SDP should output a maximum
of 500mA so the input current limit is set to the same value).
Use preferably input_power_limit, and for problems that can be
solved using power limit use input_current_limit.

Access: Read, Write
Valid values: Represented in microamps

What: /sys/class/power_supply/<supply_name>/input_voltage_limit
Date: May 2019
Contact: [email protected]
Description:
This entry configures the incoming VBUS voltage limit currently
set in the supply. Normally this is configured based on
system-level knowledge or user input (e.g. This is part of the
Pixel C's thermal management strategy to effectively limit the
input power to 5V when the screen is on to meet Google's skin
temperature targets). Note that this feature should not be
used for safety critical things.
Use preferably input_power_limit, and for problems that can be
solved using power limit use input_voltage_limit.

Access: Read, Write
Valid values: Represented in microvolts

What: /sys/class/power_supply/<supply_name>/input_power_limit
Date: May 2019
Contact: [email protected]
Description:
This entry configures the incoming power limit currently set
in the supply. Normally this is configured based on
system-level knowledge or user input. Use preferably this
feature to limit the incoming power and use current/voltage
limit only for problems that can be solved using power limit.

Access: Read, Write
Valid values: Represented in microwatts

What: /sys/class/power_supply/<supply_name>/online,
Date: May 2007
Contact: [email protected]
Expand Down
30 changes: 30 additions & 0 deletions Documentation/ABI/testing/sysfs-class-power-wilco
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
What: /sys/class/power_supply/wilco-charger/charge_type
Date: April 2019
KernelVersion: 5.2
Description:
What charging algorithm to use:

Standard: Fully charges battery at a standard rate.
Adaptive: Battery settings adaptively optimized based on
typical battery usage pattern.
Fast: Battery charges over a shorter period.
Trickle: Extends battery lifespan, intended for users who
primarily use their Chromebook while connected to AC.
Custom: A low and high threshold percentage is specified.
Charging begins when level drops below
charge_control_start_threshold, and ceases when
level is above charge_control_end_threshold.

What: /sys/class/power_supply/wilco-charger/charge_control_start_threshold
Date: April 2019
KernelVersion: 5.2
Description:
Used when charge_type="Custom", as described above. Measured in
percentages. The valid range is [50, 95].

What: /sys/class/power_supply/wilco-charger/charge_control_end_threshold
Date: April 2019
KernelVersion: 5.2
Description:
Used when charge_type="Custom", as described above. Measured in
percentages. The valid range is [55, 100].
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
NVMEM reboot mode driver

This driver gets reboot mode magic value from reboot-mode driver
and stores it in a NVMEM cell named "reboot-mode". Then the bootloader
can read it and take different action according to the magic
value stored.

Required properties:
- compatible: should be "nvmem-reboot-mode".
- nvmem-cells: A phandle to the reboot mode provided by a nvmem device.
- nvmem-cell-names: Should be "reboot-mode".

The rest of the properties should follow the generic reboot-mode description
found in reboot-mode.txt

Example:
reboot-mode {
compatible = "nvmem-reboot-mode";
nvmem-cells = <&reboot_mode>;
nvmem-cell-names = "reboot-mode";

mode-normal = <0xAAAA5501>;
mode-bootloader = <0xBBBB5500>;
mode-recovery = <0xCCCC5502>;
mode-test = <0xDDDD5503>;
};
1 change: 1 addition & 0 deletions Documentation/devicetree/bindings/power/reset/qcom,pon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Required Properties:
-compatible: Must be one of:
"qcom,pm8916-pon"
"qcom,pms405-pon"
"qcom,pm8998-pon"

-reg: Specifies the physical address of the pon register

Expand Down
6 changes: 6 additions & 0 deletions Documentation/power/power_supply_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ CONSTANT_CHARGE_VOLTAGE_MAX
INPUT_CURRENT_LIMIT
input current limit programmed by charger. Indicates
the current drawn from a charging source.
INPUT_VOLTAGE_LIMIT
input voltage limit programmed by charger. Indicates
the voltage limit from a charging source.
INPUT_POWER_LIMIT
input power limit programmed by charger. Indicates
the power limit from a charging source.

CHARGE_CONTROL_LIMIT
current charge control limit setting
Expand Down
10 changes: 10 additions & 0 deletions drivers/power/reset/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,15 @@ config POWER_RESET_SC27XX
PMICs includes the SC2720, SC2721, SC2723, SC2730
and SC2731 chips.

config NVMEM_REBOOT_MODE
tristate "Generic NVMEM reboot mode driver"
depends on OF
select REBOOT_MODE
help
Say y here will enable reboot mode driver. This will
get reboot mode arguments and store it in a NVMEM cell,
then the bootloader can read it and take different
action according to the mode.

endif

1 change: 1 addition & 0 deletions drivers/power/reset/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ obj-$(CONFIG_POWER_RESET_ZX) += zx-reboot.o
obj-$(CONFIG_REBOOT_MODE) += reboot-mode.o
obj-$(CONFIG_SYSCON_REBOOT_MODE) += syscon-reboot-mode.o
obj-$(CONFIG_POWER_RESET_SC27XX) += sc27xx-poweroff.o
obj-$(CONFIG_NVMEM_REBOOT_MODE) += nvmem-reboot-mode.o
76 changes: 76 additions & 0 deletions drivers/power/reset/nvmem-reboot-mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) Vaisala Oyj. All rights reserved.
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/of.h>
#include <linux/nvmem-consumer.h>
#include <linux/platform_device.h>
#include <linux/reboot-mode.h>

struct nvmem_reboot_mode {
struct reboot_mode_driver reboot;
struct nvmem_cell *cell;
};

static int nvmem_reboot_mode_write(struct reboot_mode_driver *reboot,
unsigned int magic)
{
int ret;
struct nvmem_reboot_mode *nvmem_rbm;

nvmem_rbm = container_of(reboot, struct nvmem_reboot_mode, reboot);

ret = nvmem_cell_write(nvmem_rbm->cell, &magic, sizeof(magic));
if (ret < 0)
dev_err(reboot->dev, "update reboot mode bits failed\n");

return ret;
}

static int nvmem_reboot_mode_probe(struct platform_device *pdev)
{
int ret;
struct nvmem_reboot_mode *nvmem_rbm;

nvmem_rbm = devm_kzalloc(&pdev->dev, sizeof(*nvmem_rbm), GFP_KERNEL);
if (!nvmem_rbm)
return -ENOMEM;

nvmem_rbm->reboot.dev = &pdev->dev;
nvmem_rbm->reboot.write = nvmem_reboot_mode_write;

nvmem_rbm->cell = devm_nvmem_cell_get(&pdev->dev, "reboot-mode");
if (IS_ERR(nvmem_rbm->cell)) {
dev_err(&pdev->dev, "failed to get the nvmem cell reboot-mode\n");
return PTR_ERR(nvmem_rbm->cell);
}

ret = devm_reboot_mode_register(&pdev->dev, &nvmem_rbm->reboot);
if (ret)
dev_err(&pdev->dev, "can't register reboot mode\n");

return ret;
}

static const struct of_device_id nvmem_reboot_mode_of_match[] = {
{ .compatible = "nvmem-reboot-mode" },
{}
};
MODULE_DEVICE_TABLE(of, nvmem_reboot_mode_of_match);

static struct platform_driver nvmem_reboot_mode_driver = {
.probe = nvmem_reboot_mode_probe,
.driver = {
.name = "nvmem-reboot-mode",
.of_match_table = nvmem_reboot_mode_of_match,
},
};
module_platform_driver(nvmem_reboot_mode_driver);

MODULE_AUTHOR("Nandor Han <[email protected]>");
MODULE_DESCRIPTION("NVMEM reboot mode driver");
MODULE_LICENSE("GPL");
12 changes: 9 additions & 3 deletions drivers/power/reset/qcom-pon.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@

#define PON_SOFT_RB_SPARE 0x8f

#define GEN1_REASON_SHIFT 2
#define GEN2_REASON_SHIFT 1

struct pm8916_pon {
struct device *dev;
struct regmap *regmap;
u32 baseaddr;
struct reboot_mode_driver reboot_mode;
long reason_shift;
};

static int pm8916_reboot_mode_write(struct reboot_mode_driver *reboot,
Expand All @@ -30,7 +34,7 @@ static int pm8916_reboot_mode_write(struct reboot_mode_driver *reboot,

ret = regmap_update_bits(pon->regmap,
pon->baseaddr + PON_SOFT_RB_SPARE,
0xfc, magic << 2);
0xfc, magic << pon->reason_shift);
if (ret < 0)
dev_err(pon->dev, "update reboot mode bits failed\n");

Expand Down Expand Up @@ -60,6 +64,7 @@ static int pm8916_pon_probe(struct platform_device *pdev)
return error;

pon->reboot_mode.dev = &pdev->dev;
pon->reason_shift = (long)of_device_get_match_data(&pdev->dev);
pon->reboot_mode.write = pm8916_reboot_mode_write;
error = devm_reboot_mode_register(&pdev->dev, &pon->reboot_mode);
if (error) {
Expand All @@ -73,8 +78,9 @@ static int pm8916_pon_probe(struct platform_device *pdev)
}

static const struct of_device_id pm8916_pon_id_table[] = {
{ .compatible = "qcom,pm8916-pon" },
{ .compatible = "qcom,pms405-pon" },
{ .compatible = "qcom,pm8916-pon", .data = (void *)GEN1_REASON_SHIFT },
{ .compatible = "qcom,pms405-pon", .data = (void *)GEN1_REASON_SHIFT },
{ .compatible = "qcom,pm8998-pon", .data = (void *)GEN2_REASON_SHIFT },
{ }
};
MODULE_DEVICE_TABLE(of, pm8916_pon_id_table);
Expand Down
23 changes: 23 additions & 0 deletions drivers/power/supply/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ config POWER_SUPPLY_DEBUG
Say Y here to enable debugging messages for power supply class
and drivers.

config POWER_SUPPLY_HWMON
bool
prompt "Expose power supply sensors as hwmon device"
depends on HWMON=y || HWMON=POWER_SUPPLY
default y
help
This options enables API that allows sensors found on a
power supply device (current, voltage, temperature) to be
exposed as a hwmon device.

Say 'Y' here if you want power supplies to
have hwmon sysfs interface too.


config PDA_POWER
tristate "Generic PDA/phone power driver"
depends on !S390
Expand Down Expand Up @@ -698,4 +712,13 @@ config CHARGER_BD70528
information and altering charger configurations from charger
block of the ROHM BD70528 Power Management IC.

config CHARGER_WILCO
tristate "Wilco EC based charger for ChromeOS"
depends on WILCO_EC
help
Say Y here to enable control of the charging routines performed
by the Embedded Controller on the Chromebook named Wilco. Further
information can be found in
Documentation/ABI/testing/sysfs-class-power-wilco

endif # POWER_SUPPLY
2 changes: 2 additions & 0 deletions drivers/power/supply/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ power_supply-$(CONFIG_SYSFS) += power_supply_sysfs.o
power_supply-$(CONFIG_LEDS_TRIGGERS) += power_supply_leds.o

obj-$(CONFIG_POWER_SUPPLY) += power_supply.o
obj-$(CONFIG_POWER_SUPPLY_HWMON) += power_supply_hwmon.o
obj-$(CONFIG_GENERIC_ADC_BATTERY) += generic-adc-battery.o

obj-$(CONFIG_PDA_POWER) += pda_power.o
Expand Down Expand Up @@ -91,3 +92,4 @@ obj-$(CONFIG_CHARGER_SC2731) += sc2731_charger.o
obj-$(CONFIG_FUEL_GAUGE_SC27XX) += sc27xx_fuel_gauge.o
obj-$(CONFIG_CHARGER_UCS1002) += ucs1002_power.o
obj-$(CONFIG_CHARGER_BD70528) += bd70528-charger.o
obj-$(CONFIG_CHARGER_WILCO) += wilco-charger.o
2 changes: 1 addition & 1 deletion drivers/power/supply/bq24190_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ static int bq24190_get_config(struct bq24190_dev_info *bdi)
static int bq24190_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
struct power_supply_config charger_cfg = {}, battery_cfg = {};
struct bq24190_dev_info *bdi;
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/supply/bq24257_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ static int bq24257_fw_probe(struct bq24257_device *bq)
static int bq24257_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
const struct acpi_device_id *acpi_id;
struct bq24257_device *bq;
Expand Down
2 changes: 1 addition & 1 deletion drivers/power/supply/bq25890_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ static int bq25890_fw_probe(struct bq25890_device *bq)
static int bq25890_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct i2c_adapter *adapter = client->adapter;
struct device *dev = &client->dev;
struct bq25890_device *bq;
int ret;
Expand Down
Loading

0 comments on commit 5fe7b60

Please sign in to comment.