From patchwork Thu Oct 4 19:34:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Oskari_Lemmel=C3=A4?= X-Patchwork-Id: 10626547 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 79C9D15A6 for ; Thu, 4 Oct 2018 19:37:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67124294C1 for ; Thu, 4 Oct 2018 19:37:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A6E72963B; Thu, 4 Oct 2018 19:37:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 880C1294C1 for ; Thu, 4 Oct 2018 19:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=keg+NLKtRp66U0hG6i6KQxIciYSX6swzCjZA3fGowq4=; b=hzSBZqDxEL4yzE5/6HVjF/Z2U7 5NHqrR8B08za4nh0F97vjxHKd/o3CDejbRR/2aN9nwdYvT+S3oeQeiciV7P+iEUEe265/hvy3WHkC SD+tm0erNe47/HGZFb3UdEIkgsiEw5pjbRvbEytRVsseupE6QnEi7TuvbRVTSCebzaG/C08+p2F5v 26F+nEjrEo0gmscgfl3vMK9uu8FWbZO1w4A2fxINTSHAn0Ovv2WPiu81hk7SxoKAI83PpnxVhEZQ7 Ni3xRbt2JpcIjj8tTF4WbYMQ9seS7lgRcs37OlMbBQ6Dr3zxyH33FnwQDq0M7Chr55nk8mFa09c1S 8JgWNSCA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g89RJ-0006aR-Fs; Thu, 04 Oct 2018 19:37:37 +0000 Received: from mail1.kuutio.org ([2001:41d0:401:3100::431a]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g89Ok-00046P-MI for linux-arm-kernel@lists.infradead.org; Thu, 04 Oct 2018 19:35:04 +0000 Received: from localhost (localhost [127.0.0.1]) by mail1.kuutio.org (Postfix) with ESMTP id 0734B1F99C; Thu, 4 Oct 2018 21:34:46 +0200 (CEST) Authentication-Results: mail1.kuutio.org (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=lemmela.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lemmela.net; h= references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=dkim; t=1538681684; x= 1541273685; bh=nH9jCOZMiAQffXTRDY0K3dj/dvc9nqOMIuTRGT/kQII=; b=n wDVyYnnghr9vuNsXK1c5b5qHjuRF3JxK6NVVaKTyYTVZ/Z3YIll9u9Y72HOLSATx MGC1o6Ng07odZuUGa+FoW6ijqAGEt3CvaceaXyJA8d3Fe7TjCdwdJVmDvrl9a6Kx ZfWR4Vuo1U+7c/KdLzZ6nJeudYLg+afNF6LqX+zt1q1rdU+V0hwQbWs0Nz7DoXH4 zyUxQdA4Lz+HIyKQuxkw+KURN/b7+sOUeilqEzTqMIepGhuCgLM3xcwsKkyugRaC eDnCqEggV1osDkjgL4ykSQkmW9iT1nV14l23WlaJBUcpVhDaT2vGIwV6p27seXK+ 6IDbmH/aSiiO3oLe1VE2w+t+ycno4ui6dz516OvdwSX1xFx8Pz7XvFJ7EkROf7v6 6SXhemnXqR88U2CUKFKQpgbXfXa4ZK7+l0ayKyNacU6IFjIfM2MweekcRuP1AaIu U84l6X13363NQno0p4TNjXmPS+z7/QzgIvc6CNkqDOtsMeGi8dF1KBp5Nvw4lK8s M7J0yrc2PRTRA1dMygwn3Q0pfZUz5eEJzsUT4KmHlOnPol+x3y8k6Z32lpJlOkZm ngiLL0lrqHWzTea6SQO9V0Agb1FEPy15jQ+0HYXsKMWKGgWhVy3hqoYZKT61cfQb 3L/plzddvr1aDA1sTz0zeKYX/mUwyoN0BnqppB8Bog= X-Virus-Scanned: amavisd-new at kuutio.org Received: from mail1.kuutio.org ([127.0.0.1]) by localhost (mail1.kuutio.org [127.0.0.1]) (amavisd-new, port 10024) with LMTP id BwkJ3V_T2fzg; Thu, 4 Oct 2018 21:34:44 +0200 (CEST) Received: from build.kuutio.org (unknown [IPv6:2001:998:13:e4::69]) by mail1.kuutio.org (Postfix) with ESMTPSA id 0EC8A1FBF3; Thu, 4 Oct 2018 21:34:44 +0200 (CEST) From: Oskari Lemmela To: Maxime Ripard , Sebastian Reichel , Jonathan Cameron , Chen-Yu Tsai , Mark Rutland , Rob Herring , Linus Walleij Subject: [PATCH 4/4] power: supply: add AXP803/AXP813 AC and battery power supply support Date: Thu, 4 Oct 2018 22:34:10 +0300 Message-Id: <20181004193410.7265-5-oskari@lemmela.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004193410.7265-1-oskari@lemmela.net> References: <20181004193410.7265-1-oskari@lemmela.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181004_123459_042331_CC29D475 X-CRM114-Status: GOOD ( 15.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Lars-Peter Clausen , linux-gpio@vger.kernel.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Quentin Schulz , Oskari Lemmela , Peter Meerwald-Stadler , Hartmut Knaack , Lee Jones , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP AXP803 PMIC is register compatible with AXP813. Added support for AXP803/AXP813 AC power supply. AXP8x3 is capable to limit input current and minimum input voltage. Both of these register values are writeable. Signed-off-by: Oskari Lemmela --- drivers/iio/adc/axp20x_adc.c | 1 + drivers/mfd/axp20x.c | 22 ++- drivers/pinctrl/pinctrl-axp209.c | 1 + drivers/power/supply/axp20x_ac_power.c | 194 +++++++++++++++++++++++++ drivers/power/supply/axp20x_battery.c | 3 + include/linux/mfd/axp20x.h | 1 + 6 files changed, 221 insertions(+), 1 deletion(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 5be789269353..f919a16a8533 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -641,6 +641,7 @@ static const struct axp_data axp813_data = { static const struct of_device_id axp20x_adc_of_match[] = { { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, }, { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, }, + { .compatible = "x-powers,axp803-adc", .data = (void *)&axp813_data, }, { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, }, { /* sentinel */ } }; diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index 0be511dd93d0..c540f17549d5 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -731,8 +731,23 @@ static const struct mfd_cell axp803_cells[] = { .name = "axp221-pek", .num_resources = ARRAY_SIZE(axp803_pek_resources), .resources = axp803_pek_resources, + }, { + .name = "axp20x-regulator" + }, { + .name = "axp20x-gpio", + .of_compatible = "x-powers,axp803-gpio", + }, { + .name = "axp813-adc", + .of_compatible = "x-powers,axp803-adc", + }, { + .name = "axp20x-battery-power-supply", + .of_compatible = "x-powers,axp803-battery-power-supply", + }, { + .name = "axp20x-ac-power-supply", + .of_compatible = "x-powers,axp803-ac-power-supply", + .num_resources = ARRAY_SIZE(axp20x_ac_power_supply_resources), + .resources = axp20x_ac_power_supply_resources, }, - { .name = "axp20x-regulator" }, }; static const struct mfd_cell axp806_self_working_cells[] = { @@ -778,6 +793,11 @@ static const struct mfd_cell axp813_cells[] = { }, { .name = "axp20x-battery-power-supply", .of_compatible = "x-powers,axp813-battery-power-supply", + }, { + .name = "axp20x-ac-power-supply", + .of_compatible = "x-powers,axp813-ac-power-supply", + .num_resources = ARRAY_SIZE(axp20x_ac_power_supply_resources), + .resources = axp20x_ac_power_supply_resources, }, }; diff --git a/drivers/pinctrl/pinctrl-axp209.c b/drivers/pinctrl/pinctrl-axp209.c index afd0b533c40a..21859579e0a2 100644 --- a/drivers/pinctrl/pinctrl-axp209.c +++ b/drivers/pinctrl/pinctrl-axp209.c @@ -387,6 +387,7 @@ static int axp20x_build_funcs_groups(struct platform_device *pdev) static const struct of_device_id axp20x_pctl_match[] = { { .compatible = "x-powers,axp209-gpio", .data = &axp20x_data, }, + { .compatible = "x-powers,axp803-gpio", .data = &axp813_data, }, { .compatible = "x-powers,axp813-gpio", .data = &axp813_data, }, { } }; diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index 0771f951b11f..3247efb81cd1 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -27,6 +27,23 @@ #define AXP20X_PWR_STATUS_ACIN_PRESENT BIT(7) #define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6) +#define AXP8X3_PWR_ACIN_VHOLD GENMASK(5, 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_0V (0 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_1V (1 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_2V (2 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_3V (3 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_4V (4 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_5V (5 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_6V (6 << 3) +#define AXP8X3_PWR_ACIN_VHOLD_4_7V (7 << 3) +#define AXP8X3_PWR_ACIN_CURR_LIMIT GENMASK(2, 0) +#define AXP8X3_PWR_ACIN_CURR_1_5A 0 +#define AXP8X3_PWR_ACIN_CURR_2_0A 1 +#define AXP8X3_PWR_ACIN_CURR_2_5A 2 +#define AXP8X3_PWR_ACIN_CURR_3_0A 3 +#define AXP8X3_PWR_ACIN_CURR_3_5A 4 +#define AXP8X3_PWR_ACIN_CURR_4_0A 5 + #define DRVNAME "axp20x-ac-power-supply" struct axp20x_ac_power { @@ -102,6 +119,72 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, return 0; + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + ret = regmap_read(power->regmap, AXP803_ACIN_PATH_CTRL, ®); + if (ret) + return ret; + + switch (reg & AXP8X3_PWR_ACIN_VHOLD) { + case AXP8X3_PWR_ACIN_VHOLD_4_0V: + val->intval = 4000000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_1V: + val->intval = 4100000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_2V: + val->intval = 4200000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_3V: + val->intval = 4300000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_4V: + val->intval = 4400000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_5V: + val->intval = 4500000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_6V: + val->intval = 4600000; + break; + case AXP8X3_PWR_ACIN_VHOLD_4_7V: + val->intval = 4700000; + break; + default: + return -EINVAL; + } + + return 0; + + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = regmap_read(power->regmap, AXP803_ACIN_PATH_CTRL, ®); + if (ret) + return ret; + + switch (reg & AXP8X3_PWR_ACIN_CURR_LIMIT) { + case AXP8X3_PWR_ACIN_CURR_1_5A: + val->intval = 1500000; + break; + case AXP8X3_PWR_ACIN_CURR_2_0A: + val->intval = 2000000; + break; + case AXP8X3_PWR_ACIN_CURR_2_5A: + val->intval = 2500000; + break; + case AXP8X3_PWR_ACIN_CURR_3_0A: + val->intval = 3000000; + break; + case AXP8X3_PWR_ACIN_CURR_3_5A: + val->intval = 3500000; + break; + case AXP8X3_PWR_ACIN_CURR_4_0A: + val->intval = 4000000; + break; + default: + return -EINVAL; + } + + return 0; + default: return -EINVAL; } @@ -109,6 +192,88 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, return -EINVAL; } +static int axp20x_ac_power_set_property(struct power_supply *psy, + enum power_supply_property psp, + const union power_supply_propval *val) +{ + struct axp20x_ac_power *power = power_supply_get_drvdata(psy); + int setval; + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + switch (val->intval) { + case 4000000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_0V; + break; + case 4100000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_1V; + break; + case 4200000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_2V; + break; + case 4300000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_3V; + break; + case 4400000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_4V; + break; + case 4500000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_5V; + break; + case 4600000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_6V; + break; + case 4700000: + setval = AXP8X3_PWR_ACIN_VHOLD_4_7V; + break; + + default: + return -EINVAL; + } + return regmap_update_bits(power->regmap, AXP803_ACIN_PATH_CTRL, + AXP8X3_PWR_ACIN_VHOLD, setval); + + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + + switch (val->intval) { + case 1500000: + setval = AXP8X3_PWR_ACIN_CURR_1_5A; + break; + case 2000000: + setval = AXP8X3_PWR_ACIN_CURR_2_0A; + break; + case 2500000: + setval = AXP8X3_PWR_ACIN_CURR_2_5A; + break; + case 3000000: + setval = AXP8X3_PWR_ACIN_CURR_3_0A; + break; + case 3500000: + setval = AXP8X3_PWR_ACIN_CURR_3_5A; + break; + case 4000000: + setval = AXP8X3_PWR_ACIN_CURR_4_0A; + break; + default: + return -EINVAL; + } + return regmap_update_bits(power->regmap, AXP803_ACIN_PATH_CTRL, + AXP8X3_PWR_ACIN_CURR_LIMIT, setval); + + default: + return -EINVAL; + } + + return -EINVAL; +} + +static int axp20x_ac_power_prop_writeable(struct power_supply *psy, + enum power_supply_property psp) +{ + return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || + psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; +} + static enum power_supply_property axp20x_ac_power_properties[] = { POWER_SUPPLY_PROP_HEALTH, POWER_SUPPLY_PROP_PRESENT, @@ -123,6 +288,14 @@ static enum power_supply_property axp22x_ac_power_properties[] = { POWER_SUPPLY_PROP_ONLINE, }; +static enum power_supply_property axp8x3_ac_power_properties[] = { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, +}; + static const struct power_supply_desc axp20x_ac_power_desc = { .name = "axp20x-ac", .type = POWER_SUPPLY_TYPE_MAINS, @@ -139,6 +312,16 @@ static const struct power_supply_desc axp22x_ac_power_desc = { .get_property = axp20x_ac_power_get_property, }; +static const struct power_supply_desc axp8x3_ac_power_desc = { + .name = "axp8x3-ac", + .type = POWER_SUPPLY_TYPE_MAINS, + .properties = axp8x3_ac_power_properties, + .num_properties = ARRAY_SIZE(axp8x3_ac_power_properties), + .property_is_writeable = axp20x_ac_power_prop_writeable, + .get_property = axp20x_ac_power_get_property, + .set_property = axp20x_ac_power_set_property, +}; + struct axp_data { const struct power_supply_desc *power_desc; bool acin_adc; @@ -154,6 +337,11 @@ static const struct axp_data axp22x_data = { .acin_adc = false, }; +static const struct axp_data axp8x3_data = { + .power_desc = &axp8x3_ac_power_desc, + .acin_adc = false, +}; + static int axp20x_ac_power_probe(struct platform_device *pdev) { struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); @@ -234,6 +422,12 @@ static const struct of_device_id axp20x_ac_power_match[] = { }, { .compatible = "x-powers,axp221-ac-power-supply", .data = &axp22x_data, + }, { + .compatible = "x-powers,axp803-ac-power-supply", + .data = &axp8x3_data, + }, { + .compatible = "x-powers,axp813-ac-power-supply", + .data = &axp8x3_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, axp20x_ac_power_match); diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index e84b6e4da14a..932027f4a993 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -537,6 +537,9 @@ static const struct of_device_id axp20x_battery_ps_id[] = { }, { .compatible = "x-powers,axp221-battery-power-supply", .data = (void *)&axp221_data, + }, { + .compatible = "x-powers,axp803-battery-power-supply", + .data = (void *)&axp813_data, }, { .compatible = "x-powers,axp813-battery-power-supply", .data = (void *)&axp813_data, diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index 517e60eecbcb..23d58e243d01 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -266,6 +266,7 @@ enum axp20x_variants { #define AXP288_RT_BATT_V_H 0xa0 #define AXP288_RT_BATT_V_L 0xa1 +#define AXP803_ACIN_PATH_CTRL 0x3a #define AXP813_ADC_RATE 0x85 /* Fuel Gauge */