Commit df132e40 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:

 - Add Spreadtrum SC2731 charger driver

 - bq25890-charger: Add BQ25896 support

 - bq27xxx-battery: Add support for BQ27411

 - qcom-pon: Add pms405 pon support

 - cros-charger: add support for dedicated port

 - misc fixes

* tag 'for-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (28 commits)
  power: max8925: mark expected switch fall-through
  power: supply: fix spelling mistake "Gauage" -> "Gauge"
  power: reset: qcom-pon: Add pms405 pon support
  power: supply: bq27xxx: Add support for BQ27411
  power: supply: Add Spreadtrum SC2731 charger support
  dt-bindings: power: Add Spreadtrum SC2731 charger documentation
  power: supply: twl4030_charger: disable eoc interrupt on linear charge
  power: supply: twl4030_charger: fix charging current out-of-bounds
  power: supply: bq25890_charger: fix semicolon.cocci warnings
  power: supply: max8998-charger: Fix platform data retrieval
  power: supply: cros: add support for dedicated port
  mfd: cros: add charger port count command definition
  power: reset: at91-poweroff: do not procede if at91_shdwc is allocated
  power: reset: at91-poweroff: rename at91_shdwc_base member of struct shdwc
  power: reset: at91-poweroff: make sclk part of struct shdwc
  power: reset: at91-poweroff: make mpddrc_base part of struct shdwc
  power: reset: at91-poweroff: use only one poweroff function
  power: reset: at91-poweroff: switch to slow clock before shutdown
  power: reset: convert to SPDX identifiers
  power: supply: ab8500_fg: silence uninitialized variable warnings
  ...
parents 96f2f66a cfb34797
......@@ -6,7 +6,10 @@ and resin along with the Android reboot-mode.
This DT node has pwrkey and resin as sub nodes.
Required Properties:
-compatible: "qcom,pm8916-pon"
-compatible: Must be one of:
"qcom,pm8916-pon"
"qcom,pms405-pon"
-reg: Specifies the physical address of the pon register
Optional subnode:
......
Binding for TI bq25890 Li-Ion Charger
This driver will support the bq25896 and the bq25890. There are other ICs
in the same family but those have not been tested.
Required properties:
- compatible: Should contain one of the following:
* "ti,bq25890"
......
......@@ -23,6 +23,7 @@ Required properties:
* "ti,bq27546" - BQ27546
* "ti,bq27742" - BQ27742
* "ti,bq27545" - BQ27545
* "ti,bq27411" - BQ27411
* "ti,bq27421" - BQ27421
* "ti,bq27425" - BQ27425
* "ti,bq27426" - BQ27426
......
Spreadtrum SC2731 PMIC battery charger binding
Required properties:
- compatible: Should be "sprd,sc2731-charger".
- reg: Address offset of charger register.
- phys: Contains a phandle to the USB phy.
Optional Properties:
- monitored-battery: phandle of battery characteristics devicetree node.
The charger uses the following battery properties:
- charge-term-current-microamp: current for charge termination phase.
- constant-charge-voltage-max-microvolt: maximum constant input voltage.
See Documentation/devicetree/bindings/power/supply/battery.txt
Example:
bat: battery {
compatible = "simple-battery";
charge-term-current-microamp = <120000>;
constant-charge-voltage-max-microvolt = <4350000>;
......
};
sc2731_pmic: pmic@0 {
compatible = "sprd,sc2731";
reg = <0>;
spi-max-frequency = <26000000>;
interrupts = <GIC_SPI 31 IRQ_TYPE_LEVEL_HIGH>;
interrupt-controller;
#interrupt-cells = <2>;
#address-cells = <1>;
#size-cells = <0>;
charger@0 {
compatible = "sprd,sc2731-charger";
reg = <0x0>;
phys = <&ssphy>;
monitored-battery = <&bat>;
};
};
......@@ -149,6 +149,14 @@ exit_suspend:
ENDPROC(at91_pm_suspend_in_sram)
ENTRY(at91_backup_mode)
/* Switch the master clock source to slow clock. */
ldr pmc, .pmc_base
ldr tmp1, [pmc, #AT91_PMC_MCKR]
bic tmp1, tmp1, #AT91_PMC_CSS
str tmp1, [pmc, #AT91_PMC_MCKR]
wait_mckrdy
/*BUMEN*/
ldr r0, .sfr
mov tmp1, #0x1
......
......@@ -19,6 +19,7 @@
*/
#include <linux/clk.h>
#include <linux/clk/at91_pmc.h>
#include <linux/io.h>
#include <linux/module.h>
#include <linux/of.h>
......@@ -69,7 +70,10 @@ struct shdwc_config {
struct shdwc {
const struct shdwc_config *cfg;
void __iomem *at91_shdwc_base;
struct clk *sclk;
void __iomem *shdwc_base;
void __iomem *mpddrc_base;
void __iomem *pmc_base;
};
/*
......@@ -77,8 +81,6 @@ struct shdwc {
* since pm_power_off itself is global.
*/
static struct shdwc *at91_shdwc;
static struct clk *sclk;
static void __iomem *mpddrc_base;
static const unsigned long long sdwc_dbc_period[] = {
0, 3, 32, 512, 4096, 32768,
......@@ -90,7 +92,7 @@ static void __init at91_wakeup_status(struct platform_device *pdev)
u32 reg;
char *reason = "unknown";
reg = readl(shdw->at91_shdwc_base + AT91_SHDW_SR);
reg = readl(shdw->shdwc_base + AT91_SHDW_SR);
dev_dbg(&pdev->dev, "%s: status = %#x\n", __func__, reg);
......@@ -107,12 +109,6 @@ static void __init at91_wakeup_status(struct platform_device *pdev)
}
static void at91_poweroff(void)
{
writel(AT91_SHDW_KEY | AT91_SHDW_SHDW,
at91_shdwc->at91_shdwc_base + AT91_SHDW_CR);
}
static void at91_lpddr_poweroff(void)
{
asm volatile(
/* Align to cache lines */
......@@ -122,16 +118,29 @@ static void at91_lpddr_poweroff(void)
" ldr r6, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t"
/* Power down SDRAM0 */
" tst %0, #0\n\t"
" beq 1f\n\t"
" str %1, [%0, #" __stringify(AT91_DDRSDRC_LPR) "]\n\t"
/* Switch the master clock source to slow clock. */
"1: ldr r6, [%4, #" __stringify(AT91_PMC_MCKR) "]\n\t"
" bic r6, r6, #" __stringify(AT91_PMC_CSS) "\n\t"
" str r6, [%4, #" __stringify(AT91_PMC_MCKR) "]\n\t"
/* Wait for clock switch. */
"2: ldr r6, [%4, #" __stringify(AT91_PMC_SR) "]\n\t"
" tst r6, #" __stringify(AT91_PMC_MCKRDY) "\n\t"
" beq 2b\n\t"
/* Shutdown CPU */
" str %3, [%2, #" __stringify(AT91_SHDW_CR) "]\n\t"
" b .\n\t"
:
: "r" (mpddrc_base),
: "r" (at91_shdwc->mpddrc_base),
"r" cpu_to_le32(AT91_DDRSDRC_LPDDR2_PWOFF),
"r" (at91_shdwc->at91_shdwc_base),
"r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW)
"r" (at91_shdwc->shdwc_base),
"r" cpu_to_le32(AT91_SHDW_KEY | AT91_SHDW_SHDW),
"r" (at91_shdwc->pmc_base)
: "r6");
}
......@@ -213,10 +222,10 @@ static void at91_shdwc_dt_configure(struct platform_device *pdev)
mode |= SHDW_RTCWKEN(shdw->cfg);
dev_dbg(&pdev->dev, "%s: mode = %#x\n", __func__, mode);
writel(mode, shdw->at91_shdwc_base + AT91_SHDW_MR);
writel(mode, shdw->shdwc_base + AT91_SHDW_MR);
input = at91_shdwc_get_wakeup_input(pdev, np);
writel(input, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
writel(input, shdw->shdwc_base + AT91_SHDW_WUIR);
}
static const struct shdwc_config sama5d2_shdwc_config = {
......@@ -246,6 +255,9 @@ static int __init at91_shdwc_probe(struct platform_device *pdev)
if (!pdev->dev.of_node)
return -ENODEV;
if (at91_shdwc)
return -EBUSY;
at91_shdwc = devm_kzalloc(&pdev->dev, sizeof(*at91_shdwc), GFP_KERNEL);
if (!at91_shdwc)
return -ENOMEM;
......@@ -253,20 +265,20 @@ static int __init at91_shdwc_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, at91_shdwc);
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
at91_shdwc->at91_shdwc_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(at91_shdwc->at91_shdwc_base)) {
at91_shdwc->shdwc_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(at91_shdwc->shdwc_base)) {
dev_err(&pdev->dev, "Could not map reset controller address\n");
return PTR_ERR(at91_shdwc->at91_shdwc_base);
return PTR_ERR(at91_shdwc->shdwc_base);
}
match = of_match_node(at91_shdwc_of_match, pdev->dev.of_node);
at91_shdwc->cfg = match->data;
sclk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(sclk))
return PTR_ERR(sclk);
at91_shdwc->sclk = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(at91_shdwc->sclk))
return PTR_ERR(at91_shdwc->sclk);
ret = clk_prepare_enable(sclk);
ret = clk_prepare_enable(at91_shdwc->sclk);
if (ret) {
dev_err(&pdev->dev, "Could not enable slow clock\n");
return ret;
......@@ -276,41 +288,70 @@ static int __init at91_shdwc_probe(struct platform_device *pdev)
at91_shdwc_dt_configure(pdev);
pm_power_off = at91_poweroff;
np = of_find_compatible_node(NULL, NULL, "atmel,sama5d2-pmc");
if (!np) {
ret = -ENODEV;
goto clk_disable;
}
at91_shdwc->pmc_base = of_iomap(np, 0);
of_node_put(np);
if (!at91_shdwc->pmc_base) {
ret = -ENOMEM;
goto clk_disable;
}
np = of_find_compatible_node(NULL, NULL, "atmel,sama5d3-ddramc");
if (!np)
return 0;
if (!np) {
ret = -ENODEV;
goto unmap;
}
mpddrc_base = of_iomap(np, 0);
at91_shdwc->mpddrc_base = of_iomap(np, 0);
of_node_put(np);
if (!mpddrc_base)
return 0;
if (!at91_shdwc->mpddrc_base) {
ret = -ENOMEM;
goto unmap;
}
ddr_type = readl(mpddrc_base + AT91_DDRSDRC_MDR) & AT91_DDRSDRC_MD;
if ((ddr_type == AT91_DDRSDRC_MD_LPDDR2) ||
(ddr_type == AT91_DDRSDRC_MD_LPDDR3))
pm_power_off = at91_lpddr_poweroff;
else
iounmap(mpddrc_base);
pm_power_off = at91_poweroff;
ddr_type = readl(at91_shdwc->mpddrc_base + AT91_DDRSDRC_MDR) &
AT91_DDRSDRC_MD;
if (ddr_type != AT91_DDRSDRC_MD_LPDDR2 &&
ddr_type != AT91_DDRSDRC_MD_LPDDR3) {
iounmap(at91_shdwc->mpddrc_base);
at91_shdwc->mpddrc_base = NULL;
}
return 0;
unmap:
iounmap(at91_shdwc->pmc_base);
clk_disable:
clk_disable_unprepare(at91_shdwc->sclk);
return ret;
}
static int __exit at91_shdwc_remove(struct platform_device *pdev)
{
struct shdwc *shdw = platform_get_drvdata(pdev);
if (pm_power_off == at91_poweroff ||
pm_power_off == at91_lpddr_poweroff)
if (pm_power_off == at91_poweroff)
pm_power_off = NULL;
/* Reset values to disable wake-up features */
writel(0, shdw->at91_shdwc_base + AT91_SHDW_MR);
writel(0, shdw->at91_shdwc_base + AT91_SHDW_WUIR);
writel(0, shdw->shdwc_base + AT91_SHDW_MR);
writel(0, shdw->shdwc_base + AT91_SHDW_WUIR);
if (shdw->mpddrc_base)
iounmap(shdw->mpddrc_base);
iounmap(shdw->pmc_base);
clk_disable_unprepare(sclk);
clk_disable_unprepare(shdw->sclk);
return 0;
}
......
......@@ -74,6 +74,7 @@ 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" },
{ }
};
MODULE_DEVICE_TABLE(of, pm8916_pon_id_table);
......
// SPDX-License-Identifier: GPL-2.0
/*
* Renesas R-Mobile Reset Driver
*
* Copyright (C) 2014 Glider bvba
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <linux/io.h>
......
......@@ -645,4 +645,11 @@ config CHARGER_CROS_USBPD
what is connected to USB PD ports from the EC and converts
that into power_supply properties.
config CHARGER_SC2731
tristate "Spreadtrum SC2731 charger driver"
depends on MFD_SC27XX_PMIC || COMPILE_TEST
help
Say Y here to enable support for battery charging with SC2731
PMIC chips.
endif # POWER_SUPPLY
......@@ -85,3 +85,4 @@ obj-$(CONFIG_CHARGER_TPS65217) += tps65217_charger.o
obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o
obj-$(CONFIG_AXP288_CHARGER) += axp288_charger.o
obj-$(CONFIG_CHARGER_CROS_USBPD) += cros_usbpd-charger.o
obj-$(CONFIG_CHARGER_SC2731) += sc2731_charger.o
......@@ -2433,17 +2433,14 @@ static ssize_t charge_full_store(struct ab8500_fg *di, const char *buf,
size_t count)
{
unsigned long charge_full;
ssize_t ret;
int ret;
ret = kstrtoul(buf, 10, &charge_full);
if (ret)
return ret;
dev_dbg(di->dev, "Ret %zd charge_full %lu", ret, charge_full);
if (!ret) {
di->bat_cap.max_mah = (int) charge_full;
ret = count;
}
return ret;
di->bat_cap.max_mah = (int) charge_full;
return count;
}
static ssize_t charge_now_show(struct ab8500_fg *di, char *buf)
......@@ -2455,20 +2452,16 @@ static ssize_t charge_now_store(struct ab8500_fg *di, const char *buf,
size_t count)
{
unsigned long charge_now;
ssize_t ret;
int ret;
ret = kstrtoul(buf, 10, &charge_now);
if (ret)
return ret;
dev_dbg(di->dev, "Ret %zd charge_now %lu was %d",
ret, charge_now, di->bat_cap.prev_mah);
if (!ret) {
di->bat_cap.user_mah = (int) charge_now;
di->flags.user_cap = true;
ret = count;
queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0);
}
return ret;
di->bat_cap.user_mah = (int) charge_now;
di->flags.user_cap = true;
queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0);
return count;
}
static struct ab8500_fg_sysfs_entry charge_full_attr =
......@@ -2582,11 +2575,12 @@ static ssize_t ab8505_powercut_flagtime_write(struct device *dev,
const char *buf, size_t count)
{
int ret;
long unsigned reg_value;
int reg_value;
struct power_supply *psy = dev_get_drvdata(dev);
struct ab8500_fg *di = power_supply_get_drvdata(psy);
reg_value = simple_strtoul(buf, NULL, 10);
if (kstrtoint(buf, 10, &reg_value))
goto fail;
if (reg_value > 0x7F) {
dev_err(dev, "Incorrect parameter, echo 0 (1.98s) - 127 (15.625ms) for flagtime\n");
......@@ -2636,7 +2630,9 @@ static ssize_t ab8505_powercut_maxtime_write(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
struct ab8500_fg *di = power_supply_get_drvdata(psy);
reg_value = simple_strtoul(buf, NULL, 10);
if (kstrtoint(buf, 10, &reg_value))
goto fail;
if (reg_value > 0x7F) {
dev_err(dev, "Incorrect parameter, echo 0 (0.0s) - 127 (1.98s) for maxtime\n");
goto fail;
......@@ -2684,7 +2680,9 @@ static ssize_t ab8505_powercut_restart_write(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
struct ab8500_fg *di = power_supply_get_drvdata(psy);
reg_value = simple_strtoul(buf, NULL, 10);
if (kstrtoint(buf, 10, &reg_value))
goto fail;
if (reg_value > 0xF) {
dev_err(dev, "Incorrect parameter, echo 0 - 15 for number of restart\n");
goto fail;
......@@ -2777,7 +2775,9 @@ static ssize_t ab8505_powercut_write(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
struct ab8500_fg *di = power_supply_get_drvdata(psy);
reg_value = simple_strtoul(buf, NULL, 10);
if (kstrtoint(buf, 10, &reg_value))
goto fail;
if (reg_value > 0x1) {
dev_err(dev, "Incorrect parameter, echo 0/1 to disable/enable Pcut feature\n");
goto fail;
......@@ -2849,7 +2849,9 @@ static ssize_t ab8505_powercut_debounce_write(struct device *dev,
struct power_supply *psy = dev_get_drvdata(dev);
struct ab8500_fg *di = power_supply_get_drvdata(psy);
reg_value = simple_strtoul(buf, NULL, 10);
if (kstrtoint(buf, 10, &reg_value))
goto fail;
if (reg_value > 0x7) {
dev_err(dev, "Incorrect parameter, echo 0 to 7 for debounce setting\n");
goto fail;
......
......@@ -32,6 +32,7 @@
#define BQ25890_IRQ_PIN "bq25890_irq"
#define BQ25890_ID 3
#define BQ25896_ID 0
enum bq25890_fields {
F_EN_HIZ, F_EN_ILIM, F_IILIM, /* Reg00 */
......@@ -153,8 +154,8 @@ static const struct reg_field bq25890_reg_fields[] = {
[F_CONV_RATE] = REG_FIELD(0x02, 6, 6),
[F_BOOSTF] = REG_FIELD(0x02, 5, 5),
[F_ICO_EN] = REG_FIELD(0x02, 4, 4),
[F_HVDCP_EN] = REG_FIELD(0x02, 3, 3),
[F_MAXC_EN] = REG_FIELD(0x02, 2, 2),
[F_HVDCP_EN] = REG_FIELD(0x02, 3, 3), // reserved on BQ25896
[F_MAXC_EN] = REG_FIELD(0x02, 2, 2), // reserved on BQ25896
[F_FORCE_DPM] = REG_FIELD(0x02, 1, 1),
[F_AUTO_DPDM_EN] = REG_FIELD(0x02, 0, 0),
/* REG03 */
......@@ -163,6 +164,7 @@ static const struct reg_field bq25890_reg_fields[] = {
[F_OTG_CFG] = REG_FIELD(0x03, 5, 5),
[F_CHG_CFG] = REG_FIELD(0x03, 4, 4),
[F_SYSVMIN] = REG_FIELD(0x03, 1, 3),
/* MIN_VBAT_SEL on BQ25896 */
/* REG04 */
[F_PUMPX_EN] = REG_FIELD(0x04, 7, 7),
[F_ICHG] = REG_FIELD(0x04, 0, 6),
......@@ -181,7 +183,7 @@ static const struct reg_field bq25890_reg_fields[] = {
[F_CHG_TMR] = REG_FIELD(0x07, 1, 2),
[F_JEITA_ISET] = REG_FIELD(0x07, 0, 0),
/* REG08 */
[F_BATCMP] = REG_FIELD(0x08, 6, 7),
[F_BATCMP] = REG_FIELD(0x08, 6, 7), // 5-7 on BQ25896
[F_VCLAMP] = REG_FIELD(0x08, 2, 4),
[F_TREG] = REG_FIELD(0x08, 0, 1),
/* REG09 */
......@@ -195,12 +197,13 @@ static const struct reg_field bq25890_reg_fields[] = {
[F_PUMPX_DN] = REG_FIELD(0x09, 0, 0),
/* REG0A */
[F_BOOSTV] = REG_FIELD(0x0A, 4, 7),
/* PFM_OTG_DIS 3 on BQ25896 */
[F_BOOSTI] = REG_FIELD(0x0A, 0, 2),
/* REG0B */
[F_VBUS_STAT] = REG_FIELD(0x0B, 5, 7),
[F_CHG_STAT] = REG_FIELD(0x0B, 3, 4),
[F_PG_STAT] = REG_FIELD(0x0B, 2, 2),
[F_SDP_STAT] = REG_FIELD(0x0B, 1, 1),
[F_SDP_STAT] = REG_FIELD(0x0B, 1, 1), // reserved on BQ25896
[F_VSYS_STAT] = REG_FIELD(0x0B, 0, 0),
/* REG0C */
[F_WD_FAULT] = REG_FIELD(0x0C, 7, 7),
......@@ -244,10 +247,7 @@ enum bq25890_table_ids {
/* range tables */
TBL_ICHG,
TBL_ITERM,
TBL_IPRECHG,
TBL_VREG,
TBL_BATCMP,
TBL_VCLAMP,
TBL_BOOSTV,
TBL_SYSVMIN,
......@@ -287,8 +287,6 @@ static const union {
[TBL_ICHG] = { .rt = {0, 5056000, 64000} }, /* uA */
[TBL_ITERM] = { .rt = {64000, 1024000, 64000} }, /* uA */
[TBL_VREG] = { .rt = {3840000, 4608000, 16000} }, /* uV */
[TBL_BATCMP] = { .rt = {0, 140, 20} }, /* mOhm */
[TBL_VCLAMP] = { .rt = {0, 224000, 32000} }, /* uV */
[TBL_BOOSTV] = { .rt = {4550000, 5510000, 64000} }, /* uV */
[TBL_SYSVMIN] = { .rt = {3000000, 3700000, 100000} }, /* uV */
......@@ -401,6 +399,16 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
val->strval = BQ25890_MANUFACTURER;
break;
case POWER_SUPPLY_PROP_MODEL_NAME:
if (bq->chip_id == BQ25890_ID)
val->strval = "BQ25890";
else if (bq->chip_id == BQ25896_ID)
val->strval = "BQ25896";
else
val->strval = "UNKNOWN";
break;
case POWER_SUPPLY_PROP_ONLINE:
val->intval = state.online;
break;
......@@ -453,6 +461,15 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
val->intval = bq25890_find_val(bq->init_data.iterm, TBL_ITERM);
break;
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
if (ret < 0)
return ret;
/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
val->intval = 2304000 + ret * 20000;
break;
default:
return -EINVAL;
}
......@@ -608,30 +625,40 @@ static int bq25890_hw_init(struct bq25890_device *bq)
};
ret = bq25890_chip_reset(bq);
if (ret < 0)
if (ret < 0) {
dev_dbg(bq->dev, "Reset failed %d\n", ret);
return ret;
}
/* disable watchdog */
ret = bq25890_field_write(bq, F_WD, 0);
if (ret < 0)
if (ret < 0) {
dev_dbg(bq->dev, "Disabling watchdog failed %d\n", ret);
return ret;
}
/* initialize currents/voltages and other parameters */
for (i = 0; i < ARRAY_SIZE(init_data); i++) {
ret = bq25890_field_write(bq, init_data[i].id,
init_data[i].value);
if (ret < 0)
if (ret < 0) {
dev_dbg(bq->dev, "Writing init data failed %d\n", ret);
return ret;
}
}
/* Configure ADC for continuous conversions. This does not enable it. */
ret = bq25890_field_write(bq, F_CONV_RATE, 1);
if (ret < 0)
if (ret < 0) {
dev_dbg(bq->dev, "Config ADC failed %d\n", ret);
return ret;
}
ret = bq25890_get_chip_state(bq, &state);
if (ret < 0)
if (ret < 0) {
dev_dbg(bq->dev, "Get state failed %d\n", ret);
return ret;
}
mutex_lock(&bq->lock);
bq->state = state;
......@@ -642,6 +669,7 @@ static int bq25890_hw_init(struct bq25890_device *bq)
static enum power_supply_property bq25890_power_supply_props[] = {
POWER_SUPPLY_PROP_MANUFACTURER,
POWER_SUPPLY_PROP_MODEL_NAME,
POWER_SUPPLY_PROP_STATUS,
POWER_SUPPLY_PROP_ONLINE,
POWER_SUPPLY_PROP_HEALTH,
......@@ -650,6 +678,7 @@ static enum power_supply_property bq25890_power_supply_props[] = {
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
POWER_SUPPLY_PROP_VOLTAGE_NOW,
};
static char *bq25890_charger_supplied_to[] = {
......@@ -767,6 +796,9 @@ static int bq25890_fw_read_u32_props(struct bq25890_device *bq)
if (props[i].optional)
continue;
dev_err(bq->dev, "Unable to read property %d %s\n", ret,
props[i].name);
return ret;
}
......@@ -840,7 +872,7 @@ static int bq25890_probe(struct i2c_client *client,
return bq->chip_id;
}
if (bq->chip_id != BQ25890_ID) {
if ((bq->chip_id != BQ25890_ID) && (bq->chip_id != BQ25896_ID)) {
dev_err(dev, "Chip with ID=%d, not supported!\n", bq->chip_id);
return -ENODEV;
}
......
......@@ -432,6 +432,7 @@ static u8
[BQ27XXX_REG_AP] = 0x18,
BQ27XXX_DM_REG_ROWS,
};
#define bq27411_regs bq27421_regs
#define bq27425_regs bq27421_regs
#define bq27426_regs bq27421_regs
#define bq27441_regs bq27421_regs
......@@ -665,6 +666,7 @@ static enum power_supply_property bq27421_props[] = {
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
POWER_SUPPLY_PROP_MANUFACTURER,
};
#define bq27411_props bq27421_props
#define bq27425_props bq27421_props
#define bq27426_props bq27421_props
#define bq27441_props bq27421_props
......@@ -725,6 +727,12 @@ static struct bq27xxx_dm_reg bq27545_dm_regs[] = {
#define bq27545_dm_regs 0
#endif
static struct bq27xxx_dm_reg bq27411_dm_regs[] = {
[BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 10, 2, 0, 32767 },
[BQ27XXX_DM_DESIGN_ENERGY] = { 82, 12, 2, 0, 32767 },
[BQ27XXX_DM_TERMINATE_VOLTAGE] = { 82, 16, 2, 2800, 3700 },
};
static struct bq27xxx_dm_reg bq27421_dm_regs[] = {
[BQ27XXX_DM_DESIGN_CAPACITY] = { 82, 10, 2, 0, 8000 },
[BQ27XXX_DM_DESIGN_ENERGY] = { 82, 12, 2, 0, 32767 },
......@@ -802,6 +810,7 @@ static struct {
[BQ27546] = BQ27XXX_DATA(bq27546, 0 , BQ27XXX_O_OTDC),
[BQ27742] = BQ27XXX_DATA(bq27742, 0 , BQ27XXX_O_OTDC),
[BQ27545] = BQ27XXX_DATA(bq27545, 0x04143672, BQ27XXX_O_OTDC),
[BQ27411] = BQ27XXX_DATA(bq27411, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM),
[BQ27421] = BQ27XXX_DATA(bq27421, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM),
[BQ27425] = BQ27XXX_DATA(bq27425, 0x04143672, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP),
[BQ27426] = BQ27XXX_DATA(bq27426, 0x80008000, BQ27XXX_O_UTOT | BQ27XXX_O_CFGUP | BQ27XXX_O_RAM),
......
......@@ -247,6 +247,7 @@ static const struct i2c_device_id bq27xxx_i2c_id_table[] = {
{ "bq27546", BQ27546 },
{ "bq27742", BQ27742 },
{ "bq27545", BQ27545 },
{ "bq27411", BQ27411 },
{ "bq27421", BQ27421 },
{ "bq27425", BQ27425 },
{ "bq27426", BQ27426 },
......@@ -279,6 +280,7 @@ static const struct of_device_id bq27xxx_battery_i2c_of_match_table[] = {
{ .compatible = "ti,bq27546" },
{ .compatible = "ti,bq27742" },
{ .compatible = "ti,bq27545" },
{ .compatible = "ti,bq27411" },
{ .compatible = "ti,bq27421" },
{ .compatible = "ti,bq27425" },
{ .compatible = "ti,bq27426" },
......
......@@ -12,8 +12,12 @@
#include <linux/power_supply.h>
#include <linux/slab.h>
#define CHARGER_DIR_NAME "CROS_USBPD_CHARGER%d"
#define CHARGER_DIR_NAME_LENGTH sizeof(CHARGER_DIR_NAME)
#define CHARGER_USBPD_DIR_NAME "CROS_USBPD_CHARGER%d"
#define CHARGER_DEDICATED_DIR_NAME "CROS_DEDICATED_CHARGER"
#define CHARGER_DIR_NAME_LENGTH (sizeof(CHARGER_USBPD_DIR_NAME) >= \
sizeof(CHARGER_DEDICATED_DIR_NAME) ? \
sizeof(CHARGER_USBPD_DIR_NAME) : \
sizeof(CHARGER_DEDICATED_DIR_NAME))
#define CHARGER_CACHE_UPDATE_DELAY msecs_to_jiffies(500)
#define CHARGER_MANUFACTURER_MODEL_LENGTH 32
......@@ -42,6 +46,7 @@ struct charger_data {
struct cros_ec_dev *ec_dev;
struct cros_ec_device *ec_device;
int num_charger_ports;
int num_usbpd_ports;
int num_registered_psy;
struct port_data *ports[EC_USB_PD_MAX_PORTS];
struct notifier_block notifier;
......@@ -58,6 +63,12 @@ static enum power_supply_property cros_usbpd_charger_props[] = {
POWER_SUPPLY_PROP_USB_TYPE
};
static enum power_supply_property cros_usbpd_dedicated_charger_props[] = {