diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-25 06:28:08 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-10-25 06:28:08 -0700 |
commit | df132e4062afe06ddc9938802243d704906a884a (patch) | |
tree | d7fd08f6bea2c431440fb965f7c43335ce12c391 /drivers | |
parent | 96f2f66a985699d201b3a84222b8dd42262a71fe (diff) | |
parent | cfb347979e71d3ce6be59a988b3357f541c9eacf (diff) |
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
...
Diffstat (limited to 'drivers')
23 files changed, 855 insertions, 212 deletions
diff --git a/drivers/power/reset/at91-sama5d2_shdwc.c b/drivers/power/reset/at91-sama5d2_shdwc.c index 0206cce328b3..2b686c55b717 100644 --- a/drivers/power/reset/at91-sama5d2_shdwc.c +++ b/drivers/power/reset/at91-sama5d2_shdwc.c @@ -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); @@ -108,12 +110,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 */ ".balign 32\n\t" @@ -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; } diff --git a/drivers/power/reset/qcom-pon.c b/drivers/power/reset/qcom-pon.c index 0c4caaa7e88f..3fa1642d4c54 100644 --- a/drivers/power/reset/qcom-pon.c +++ b/drivers/power/reset/qcom-pon.c @@ -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); diff --git a/drivers/power/reset/rmobile-reset.c b/drivers/power/reset/rmobile-reset.c index e6569df76941..bd3b396558e0 100644 --- a/drivers/power/reset/rmobile-reset.c +++ b/drivers/power/reset/rmobile-reset.c @@ -1,11 +1,8 @@ +// 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> diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index ff6dab0bf0dd..f27cf0709500 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -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 diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index a26b402c45d9..767105b88d00 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -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 diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 02356f9b5f22..776102c31305 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -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, ®_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, ®_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, ®_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, ®_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, ®_value)) + goto fail; + if (reg_value > 0x7) { dev_err(dev, "Incorrect parameter, echo 0 to 7 for debounce setting\n"); goto fail; diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index 8e2c41ded171..70b90db5ae38 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -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; } diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c index f022e1b550df..6dbbe95844a3 100644 --- a/drivers/power/supply/bq27xxx_battery.c +++ b/drivers/power/supply/bq27xxx_battery.c @@ -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), diff --git a/drivers/power/supply/bq27xxx_battery_i2c.c b/drivers/power/supply/bq27xxx_battery_i2c.c index 40069128ad44..2677c38a8a42 100644 --- a/drivers/power/supply/bq27xxx_battery_i2c.c +++ b/drivers/power/supply/bq27xxx_battery_i2c.c @@ -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" }, diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 688a16bacfbb..7e9c3984ef6a 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -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[] = { + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_VOLTAGE_NOW, +}; + static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = { POWER_SUPPLY_USB_TYPE_UNKNOWN, POWER_SUPPLY_USB_TYPE_SDP, @@ -69,6 +80,11 @@ static enum power_supply_usb_type cros_usbpd_charger_usb_types[] = { POWER_SUPPLY_USB_TYPE_APPLE_BRICK_ID }; +static bool cros_usbpd_charger_port_is_dedicated(struct port_data *port) +{ + return port->port_number >= port->charger->num_usbpd_ports; +} + static int cros_usbpd_charger_ec_command(struct charger_data *charger, unsigned int version, unsigned int command, @@ -103,6 +119,23 @@ static int cros_usbpd_charger_ec_command(struct charger_data *charger, static int cros_usbpd_charger_get_num_ports(struct charger_data *charger) { + struct ec_response_charge_port_count resp; + int ret; + + ret = cros_usbpd_charger_ec_command(charger, 0, + EC_CMD_CHARGE_PORT_COUNT, + NULL, 0, &resp, sizeof(resp)); + if (ret < 0) { + dev_err(charger->dev, + "Unable to get the number of ports (err:0x%x)\n", ret); + return ret; + } + + return resp.port_count; +} + +static int cros_usbpd_charger_get_usbpd_num_ports(struct charger_data *charger) +{ struct ec_response_usb_pd_ports resp; int ret; @@ -246,7 +279,10 @@ static int cros_usbpd_charger_get_power_info(struct port_data *port) port->psy_usb_type = POWER_SUPPLY_USB_TYPE_SDP; } - port->psy_desc.type = POWER_SUPPLY_TYPE_USB; + if (cros_usbpd_charger_port_is_dedicated(port)) + port->psy_desc.type = POWER_SUPPLY_TYPE_MAINS; + else + port->psy_desc.type = POWER_SUPPLY_TYPE_USB; dev_dbg(dev, "Port %d: type=%d vmax=%d vnow=%d cmax=%d clim=%d pmax=%d\n", @@ -281,7 +317,8 @@ static int cros_usbpd_charger_get_port_status(struct port_data *port, if (ret < 0) return ret; - ret = cros_usbpd_charger_get_discovery_info(port); + if (!cros_usbpd_charger_port_is_dedicated(port)) + ret = cros_usbpd_charger_get_discovery_info(port); port->last_update = jiffies; return ret; @@ -378,12 +415,10 @@ static int cros_usbpd_charger_ec_event(struct notifier_block *nb, { struct cros_ec_device *ec_device; struct charger_data *charger; - struct device *dev; u32 host_event; charger = container_of(nb, struct charger_data, notifier); ec_device = charger->ec_device; - dev = charger->dev; host_event = cros_ec_get_host_event(ec_device); if (host_event & EC_HOST_EVENT_MASK(EC_HOST_EVENT_PD_MCU)) { @@ -426,17 +461,56 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) platform_set_drvdata(pd, charger); + /* + * We need to know the number of USB PD ports in order to know whether + * there is a dedicated port. The dedicated port will always be + * after the USB PD ports, and there should be only one. + */ + charger->num_usbpd_ports = + cros_usbpd_charger_get_usbpd_num_ports(charger); + if (charger->num_usbpd_ports <= 0) { + /* + * This can happen on a system that doesn't support USB PD. + * Log a message, but no need to warn. + */ + dev_info(dev, "No USB PD charging ports found\n"); + } + charger->num_charger_ports = cros_usbpd_charger_get_num_ports(charger); - if (charger->num_charger_ports <= 0) { + if (charger->num_charger_ports < 0) { /* * This can happen on a system that doesn't support USB PD. * Log a message, but no need to warn. + * Older ECs do not support the above command, in that case + * let's set up the number of charger ports equal to the number + * of USB PD ports + */ + dev_info(dev, "Could not get charger port count\n"); + charger->num_charger_ports = charger->num_usbpd_ports; + } + + if (charger->num_charger_ports <= 0) { + /* + * This can happen on a system that doesn't support USB PD and + * doesn't have a dedicated port. + * Log a message, but no need to warn. */ dev_info(dev, "No charging ports found\n"); ret = -ENODEV; goto fail_nowarn; } + /* + * Sanity checks on the number of ports: + * there should be at most 1 dedicated port + */ + if (charger->num_charger_ports < charger->num_usbpd_ports || + charger->num_charger_ports > (charger->num_usbpd_ports + 1)) { + dev_err(dev, "Unexpected number of charge port count\n"); + ret = -EPROTO; + goto fail_nowarn; + } + for (i = 0; i < charger->num_charger_ports; i++) { struct power_supply_config psy_cfg = {}; @@ -448,22 +522,33 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) port->charger = charger; port->port_number = i; - sprintf(port->name, CHARGER_DIR_NAME, i); psy_desc = &port->psy_desc; - psy_desc->name = port->name; - psy_desc->type = POWER_SUPPLY_TYPE_USB; psy_desc->get_property = cros_usbpd_charger_get_prop; psy_desc->external_power_changed = cros_usbpd_charger_power_changed; - psy_desc->properties = cros_usbpd_charger_props; - psy_desc->num_properties = - ARRAY_SIZE(cros_usbpd_charger_props); - psy_desc->usb_types = cros_usbpd_charger_usb_types; - psy_desc->num_usb_types = - ARRAY_SIZE(cros_u |