Skip to content

Commit

Permalink
Merge tag 'for-v4.8' 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:
 - introduce reboot mode driver
 - add DT support to max8903
 - add power supply support for axp221
 - misc fixes

* tag 'for-v4.8' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply:
  power: reset: add reboot mode driver
  dt-bindings: power: reset: add document for reboot-mode driver
  power_supply: fix return value of get_property
  power: qcom_smbb: Make an extcon for usb cable detection
  max8903: adds support for initiation via device tree
  max8903: adds documentation for device tree bindings.
  max8903: remove unnecessary 'out of memory' error message.
  max8903: removes non zero validity checks on gpios.
  max8903: adds requesting of gpios.
  max8903: cleans up confusing relationship between dc_valid, dok and dcm.
  max8903: store pointer to pdata instead of copying it.
  power_supply: bq27xxx_battery: Group register mappings into one table
  docs: Move brcm,bcm21664-resetmgr.txt
  power/reset: make syscon_poweroff() static
  power: axp20x_usb: Add support for usb power-supply on axp22x pmics
  power_supply: bq27xxx_battery: Index register numbers by enum
  power_supply: bq27xxx_battery: Fix copy/paste error in header comment
  MAINTAINERS: Add file patterns for power supply device tree bindings
  power: reset: keystone: Enable COMPILE_TEST
  • Loading branch information
torvalds committed Jul 27, 2016
2 parents 6097d55 + 4fcd504 commit f7816ad
Show file tree
Hide file tree
Showing 22 changed files with 775 additions and 243 deletions.
25 changes: 25 additions & 0 deletions Documentation/devicetree/bindings/power/max8903-charger.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Maxim Semiconductor MAX8903 Battery Charger bindings

Required properties:
- compatible: "maxim,max8903" for MAX8903 Battery Charger
- dok-gpios: Valid DC power has been detected (active low, input), optional if uok-gpios is provided
- uok-gpios: Valid USB power has been detected (active low, input), optional if dok-gpios is provided

Optional properties:
- cen-gpios: Charge enable pin (active low, output)
- chg-gpios: Charger status pin (active low, input)
- flt-gpios: Fault pin (active low, output)
- dcm-gpios: Current limit mode setting (DC=1 or USB=0, output)
- usus-gpios: USB suspend pin (active high, output)


Example:

max8903-charger {
compatible = "maxim,max8903";
dok-gpios = <&gpio2 3 GPIO_ACTIVE_LOW>;
flt-gpios = <&gpio2 2 GPIO_ACTIVE_LOW>;
chg-gpios = <&gpio3 15 GPIO_ACTIVE_LOW>;
cen-gpios = <&gpio2 5 GPIO_ACTIVE_LOW>;
status = "okay";
};
25 changes: 25 additions & 0 deletions Documentation/devicetree/bindings/power/reset/reboot-mode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Generic reboot mode core map driver

This driver get reboot mode arguments and call the write
interface to store the magic value in special register
or ram. Then the bootloader can read it and take different
action according to the argument stored.

All mode properties are vendor specific, it is a indication to tell
the bootloader what to do when the system reboots, and should be named
as mode-xxx = <magic> (xxx is mode name, magic should be a none-zero value).

For example modes common on Android platform:
- mode-normal: Normal reboot mode, system reboot with command "reboot".
- mode-recovery: Android Recovery mode, it is a mode to format the device or update a new image.
- mode-bootloader: Android fastboot mode, it's a mode to re-flash partitions on the Android based device.
- mode-loader: A bootloader mode, it's a mode used to download image on Rockchip platform,
usually used in development.

Example:
reboot-mode {
mode-normal = <BOOT_NORMAL>;
mode-recovery = <BOOT_RECOVERY>;
mode-bootloader = <BOOT_FASTBOOT>;
mode-loader = <BOOT_BL_DOWNLOAD>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
SYSCON reboot mode driver

This driver gets reboot mode magic value form reboot-mode driver
and stores it in a SYSCON mapped register. Then the bootloader
can read it and take different action according to the magic
value stored.

This DT node should be represented as a sub-node of a "syscon", "simple-mfd"
node.

Required properties:
- compatible: should be "syscon-reboot-mode"
- offset: offset in the register map for the storage register (in bytes)

Optional property:
- mask: bits mask of the bits in the register to store the reboot mode magic value,
default set to 0xffffffff if missing.

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

Example:
pmu: pmu@20004000 {
compatible = "rockchip,rk3066-pmu", "syscon", "simple-mfd";
reg = <0x20004000 0x100>;

reboot-mode {
compatible = "syscon-reboot-mode";
offset = <0x40>;
mode-normal = <BOOT_NORMAL>;
mode-recovery = <BOOT_RECOVERY>;
mode-bootloader = <BOOT_FASTBOOT>;
mode-loader = <BOOT_BL_DOWNLOAD>;
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
AXP20x USB power supply

Required Properties:
-compatible: "x-powers,axp202-usb-power-supply"
-compatible: One of: "x-powers,axp202-usb-power-supply"
"x-powers,axp221-usb-power-supply"

This node is a subnode of the axp20x PMIC.

Expand Down
2 changes: 2 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -9169,6 +9169,8 @@ M: David Woodhouse <[email protected]>
L: [email protected]
T: git git://git.infradead.org/battery-2.6.git
S: Maintained
F: Documentation/devicetree/bindings/power/
F: Documentation/devicetree/bindings/power_supply/
F: include/linux/power_supply.h
F: drivers/power/
X: drivers/power/avs/
Expand Down
1 change: 1 addition & 0 deletions drivers/power/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ config CHARGER_QCOM_SMBB
tristate "Qualcomm Switch-Mode Battery Charger and Boost"
depends on MFD_SPMI_PMIC || COMPILE_TEST
depends on OF
depends on EXTCON
help
Say Y to include support for the Switch-Mode Battery Charger and
Boost (SMBB) hardware found in Qualcomm PM8941 PMICs. The charger
Expand Down
92 changes: 69 additions & 23 deletions drivers/power/axp20x_usb_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define AXP20X_VBUS_MON_VBUS_VALID BIT(3)

struct axp20x_usb_power {
struct device_node *np;
struct regmap *regmap;
struct power_supply *supply;
};
Expand Down Expand Up @@ -85,7 +86,12 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,

switch (v & AXP20X_VBUS_CLIMIT_MASK) {
case AXP20X_VBUC_CLIMIT_100mA:
val->intval = 100000;
if (of_device_is_compatible(power->np,
"x-powers,axp202-usb-power-supply")) {
val->intval = 100000;
} else {
val->intval = -1; /* No 100mA limit */
}
break;
case AXP20X_VBUC_CLIMIT_500mA:
val->intval = 500000;
Expand Down Expand Up @@ -122,16 +128,19 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
break;
}

ret = regmap_read(power->regmap, AXP20X_USB_OTG_STATUS, &v);
if (ret)
return ret;
val->intval = POWER_SUPPLY_HEALTH_GOOD;

if (!(v & AXP20X_USB_STATUS_VBUS_VALID)) {
val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
break;
}
if (of_device_is_compatible(power->np,
"x-powers,axp202-usb-power-supply")) {
ret = regmap_read(power->regmap,
AXP20X_USB_OTG_STATUS, &v);
if (ret)
return ret;

val->intval = POWER_SUPPLY_HEALTH_GOOD;
if (!(v & AXP20X_USB_STATUS_VBUS_VALID))
val->intval =
POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
}
break;
case POWER_SUPPLY_PROP_PRESENT:
val->intval = !!(input & AXP20X_PWR_STATUS_VBUS_PRESENT);
Expand All @@ -156,6 +165,14 @@ static enum power_supply_property axp20x_usb_power_properties[] = {
POWER_SUPPLY_PROP_CURRENT_NOW,
};

static enum power_supply_property axp22x_usb_power_properties[] = {
POWER_SUPPLY_PROP_HEALTH,
POWER_SUPPLY_PROP_PRESENT,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_VOLTAGE_MIN,
POWER_SUPPLY_PROP_CURRENT_MAX,
};

static const struct power_supply_desc axp20x_usb_power_desc = {
.name = "axp20x-usb",
.type = POWER_SUPPLY_TYPE_USB,
Expand All @@ -164,13 +181,25 @@ static const struct power_supply_desc axp20x_usb_power_desc = {
.get_property = axp20x_usb_power_get_property,
};

static const struct power_supply_desc axp22x_usb_power_desc = {
.name = "axp20x-usb",
.type = POWER_SUPPLY_TYPE_USB,
.properties = axp22x_usb_power_properties,
.num_properties = ARRAY_SIZE(axp22x_usb_power_properties),
.get_property = axp20x_usb_power_get_property,
};

static int axp20x_usb_power_probe(struct platform_device *pdev)
{
struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent);
struct power_supply_config psy_cfg = {};
struct axp20x_usb_power *power;
static const char * const irq_names[] = { "VBUS_PLUGIN",
"VBUS_REMOVAL", "VBUS_VALID", "VBUS_NOT_VALID" };
static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN",
"VBUS_REMOVAL", "VBUS_VALID", "VBUS_NOT_VALID", NULL };
static const char * const axp22x_irq_names[] = {
"VBUS_PLUGIN", "VBUS_REMOVAL", NULL };
static const char * const *irq_names;
const struct power_supply_desc *usb_power_desc;
int i, irq, ret;

if (!of_device_is_available(pdev->dev.of_node))
Expand All @@ -185,31 +214,47 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)
if (!power)
return -ENOMEM;

power->np = pdev->dev.of_node;
power->regmap = axp20x->regmap;

/* Enable vbus valid checking */
ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON,
AXP20X_VBUS_MON_VBUS_VALID, AXP20X_VBUS_MON_VBUS_VALID);
if (ret)
return ret;
if (of_device_is_compatible(power->np,
"x-powers,axp202-usb-power-supply")) {
/* Enable vbus valid checking */
ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON,
AXP20X_VBUS_MON_VBUS_VALID,
AXP20X_VBUS_MON_VBUS_VALID);
if (ret)
return ret;

/* Enable vbus voltage and current measurement */
ret = regmap_update_bits(power->regmap, AXP20X_ADC_EN1,
/* Enable vbus voltage and current measurement */
ret = regmap_update_bits(power->regmap, AXP20X_ADC_EN1,
AXP20X_ADC_EN1_VBUS_CURR | AXP20X_ADC_EN1_VBUS_VOLT,
AXP20X_ADC_EN1_VBUS_CURR | AXP20X_ADC_EN1_VBUS_VOLT);
if (ret)
return ret;
if (ret)
return ret;

usb_power_desc = &axp20x_usb_power_desc;
irq_names = axp20x_irq_names;
} else if (of_device_is_compatible(power->np,
"x-powers,axp221-usb-power-supply")) {
usb_power_desc = &axp22x_usb_power_desc;
irq_names = axp22x_irq_names;
} else {
dev_err(&pdev->dev, "Unsupported AXP variant: %ld\n",
axp20x->variant);
return -EINVAL;
}

psy_cfg.of_node = pdev->dev.of_node;
psy_cfg.drv_data = power;

power->supply = devm_power_supply_register(&pdev->dev,
&axp20x_usb_power_desc, &psy_cfg);
power->supply = devm_power_supply_register(&pdev->dev, usb_power_desc,
&psy_cfg);
if (IS_ERR(power->supply))
return PTR_ERR(power->supply);

/* Request irqs after registering, as irqs may trigger immediately */
for (i = 0; i < ARRAY_SIZE(irq_names); i++) {
for (i = 0; irq_names[i]; i++) {
irq = platform_get_irq_byname(pdev, irq_names[i]);
if (irq < 0) {
dev_warn(&pdev->dev, "No IRQ for %s: %d\n",
Expand All @@ -229,6 +274,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev)

static const struct of_device_id axp20x_usb_power_match[] = {
{ .compatible = "x-powers,axp202-usb-power-supply" },
{ .compatible = "x-powers,axp221-usb-power-supply" },
{ }
};
MODULE_DEVICE_TABLE(of, axp20x_usb_power_match);
Expand Down
Loading

0 comments on commit f7816ad

Please sign in to comment.