Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp3825745ima; Tue, 23 Oct 2018 11:55:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV63KJSVFEBPH32jDxa2vnwKqjeF6qYPcY0GuzNOhTH2OnkXmknBEZPAi+JmO0LBYaQfOI7LG X-Received: by 2002:a62:1d16:: with SMTP id d22-v6mr32384487pfd.159.1540320902213; Tue, 23 Oct 2018 11:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540320902; cv=none; d=google.com; s=arc-20160816; b=NvBK5QUupzgomS3+z4w3Y7JYmLLkspdeKuj/wKNKRojnhF+dUNGKrCo/f06FEVr9Ew NOiGoBAUoeYf6ARkut5xBMjZKlSsb65mcj6MaORhZL43xpmBJW6N4zZM/ybn98dSxkSZ fImxwMiJIiuuRcQ0fWTtI5C8JXYzd8q7DGIj9SmQ4UE3xkNQ3QE5pubvoU3iUm9ygujl vRu3eZw3ObOqFhGgNq6tgpkXfHkVUpdokUP2CNu80AIN/1YFDQWFpz6s5anFTIQlU9++ QJ15VUR96sHU7QqenTOoXEbkGoQc4jn0IHMiKZDlPnR6RUiMjOSRuodiVN20vIpK2PCc ILFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=DbXAheJTbBLU4dlAYEYsAATNIgd33CMrlVL4ed1ed5I=; b=HnGBdY4qdTNfmRDWoWhlsu0uXiiYWuRv95LZrhWdBqADOFBFkz8R2oIrUdUm6CPJv6 +DNexak3RcxH9GryEWyyRBq6eIK1OAhcdHmNZ1u/SwsxmkwLxnB+8YtLtQ+RQTbI9dXR gwU3T/OCt+grxGg6V+gXWjGrwh8Xjqqqb0fVpHtZj5LZb+XHEHtbBtkpQaX1pru0E2OP YUOSTnYjOwA4w5dLBHqe+/l8R3hIMLWTkhu6oeYEZIFqtuoBrWSU6+q5ktskaTZ0by1e J33zSJXA/RWQ6ncciMwMtwuISZNzW7SuEh2wPwNoo2acrHdpA1WvTDnm9/U3g3WZpgFT nn3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lemmela.net header.s=dkim header.b=KoSrQYuy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o68-v6si2369684pfb.203.2018.10.23.11.54.44; Tue, 23 Oct 2018 11:55:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@lemmela.net header.s=dkim header.b=KoSrQYuy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729115AbeJXDSx (ORCPT + 99 others); Tue, 23 Oct 2018 23:18:53 -0400 Received: from mail1.kuutio.org ([92.222.216.83]:45920 "EHLO mail1.kuutio.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728553AbeJXDSw (ORCPT ); Tue, 23 Oct 2018 23:18:52 -0400 Received: from localhost (localhost [127.0.0.1]) by mail1.kuutio.org (Postfix) with ESMTP id 4DF481FBEA; Tue, 23 Oct 2018 20:54:12 +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=1540320851; x= 1542912852; bh=VTqnN3XdOSfhFJGNVAMrr6Pwli+yu6G7D3SxrMjYacw=; b=K oSrQYuyBAkQUcvFDaPNxf5QL7L2+VbuRuT+F0oIT9YHDdT+L1FEtsKr/yB4ETVtU jb2coSycX+QjxUHswCWKVR3HMhaJljlomesKJxCp2Os5JMnv/MNg2FEy5RMtESrK oVt5dlrKbm9St5p3s8W3JDUXwZcLA0hSQJk4TaNeMCWSWEqniuqC69zgwAF34Jun C7OgFyxQAvDcLyDT34HzpUqbcfhOnZnk/w56bteBqwKZOZMTheOgFoGOblKuWrxp ZTcF4T0LwNQT64xn44JOr7MlQHrTv4I1vUDT3EdPPZ6xfWRoY479mCIt7mNS12tS 57dO39D7r2ob7NriOMcCTmVlgMOu0I2XM+6vXmCSuXSEPKDcHLcTwIG/qx9PjGMz Bu8jDa6UUOD+07MWgbuMDt6RVw2pKgNDJiO/iiCC1XeHG3WXjuSt5QGMeyOKZUiZ ViabVs8JYKY2CG8DMwbKdLZJWT3n1NeQawd7b4hHSfoYRo3ZoAya0M0QY8QhsZn9 RIR22RXBmkinAZhNeOcoWR3ABby5o+lgv4N09Jf7LOqZTOh7nmPHfIUelRxzmnby InCOZkIKcAKtDtDvDY3kohqFCWeE2iTCXG5eTevkSl1DQK6vhlZLygNLdvCj2Jf7 n7lZdsZesfDnJxOMO4Qo+nbmKrsznWH/OhewmfyHhY= 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 fwaj7tHpKyBy; Tue, 23 Oct 2018 20:54:11 +0200 (CEST) Received: from build.kuutio.org (unknown [IPv6:2001:998:13:e4::69]) by mail1.kuutio.org (Postfix) with ESMTPSA id 73DAD1FBE8; Tue, 23 Oct 2018 20:54:10 +0200 (CEST) From: Oskari Lemmela To: Linus Walleij , Sebastian Reichel , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard , Jonathan Cameron Cc: Lee Jones , Hartmut Knaack , Lars-Peter Clausen , Vasily Khoruzhick , Quentin Schulz , Oskari Lemmela , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-gpio@vger.kernel.org, linux-iio@vger.kernel.org Subject: [PATCH v5 09/11] power: supply: add AC power supply driver for AXP813 Date: Tue, 23 Oct 2018 21:53:28 +0300 Message-Id: <20181023185330.10472-10-oskari@lemmela.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181023185330.10472-1-oskari@lemmela.net> References: <20181023185330.10472-1-oskari@lemmela.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org AXP813 and AXP803 PMICs can control input current and minimum voltage. Both of these values are configurable. Signed-off-by: Oskari Lemmela Reviewed-by: Quentin Schulz --- drivers/power/supply/axp20x_ac_power.c | 94 ++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 1 + 2 files changed, 95 insertions(+) diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index 0771f951b11f..59b4c8d3b961 100644 --- a/drivers/power/supply/axp20x_ac_power.c +++ b/drivers/power/supply/axp20x_ac_power.c @@ -27,6 +27,16 @@ #define AXP20X_PWR_STATUS_ACIN_PRESENT BIT(7) #define AXP20X_PWR_STATUS_ACIN_AVAIL BIT(6) +#define AXP813_VHOLD_MASK GENMASK(5, 3) +#define AXP813_VHOLD_UV_TO_BIT(x) ((((x) / 100000) - 40) << 3) +#define AXP813_VHOLD_REG_TO_UV(x) \ + (((((x) & AXP813_VHOLD_MASK) >> 3) + 40) * 100000) + +#define AXP813_CURR_LIMIT_MASK GENMASK(2, 0) +#define AXP813_CURR_LIMIT_UA_TO_BIT(x) (((x) / 500000) - 3) +#define AXP813_CURR_LIMIT_REG_TO_UA(x) \ + ((((x) & AXP813_CURR_LIMIT_MASK) + 3) * 500000) + #define DRVNAME "axp20x-ac-power-supply" struct axp20x_ac_power { @@ -102,6 +112,57 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, return 0; + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, ®); + if (ret) + return ret; + + val->intval = AXP813_VHOLD_REG_TO_UV(reg); + + return 0; + + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + ret = regmap_read(power->regmap, AXP813_ACIN_PATH_CTRL, ®); + if (ret) + return ret; + + val->intval = AXP813_CURR_LIMIT_REG_TO_UA(reg); + /* AXP813 datasheet defines values 11x as 4000mA */ + if (val->intval > 4000000) + val->intval = 4000000; + + return 0; + + default: + return -EINVAL; + } + + return -EINVAL; +} + +static int axp813_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); + + switch (psp) { + case POWER_SUPPLY_PROP_VOLTAGE_MIN: + if (val->intval < 4000000 || val->intval > 4700000) + return -EINVAL; + + return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, + AXP813_VHOLD_MASK, + AXP813_VHOLD_UV_TO_BIT(val->intval)); + + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + if (val->intval < 1500000 || val->intval > 4000000) + return -EINVAL; + + return regmap_update_bits(power->regmap, AXP813_ACIN_PATH_CTRL, + AXP813_CURR_LIMIT_MASK, + AXP813_CURR_LIMIT_UA_TO_BIT(val->intval)); + default: return -EINVAL; } @@ -109,6 +170,13 @@ static int axp20x_ac_power_get_property(struct power_supply *psy, return -EINVAL; } +static int axp813_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 +191,14 @@ static enum power_supply_property axp22x_ac_power_properties[] = { POWER_SUPPLY_PROP_ONLINE, }; +static enum power_supply_property axp813_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 +215,16 @@ static const struct power_supply_desc axp22x_ac_power_desc = { .get_property = axp20x_ac_power_get_property, }; +static const struct power_supply_desc axp813_ac_power_desc = { + .name = "axp813-ac", + .type = POWER_SUPPLY_TYPE_MAINS, + .properties = axp813_ac_power_properties, + .num_properties = ARRAY_SIZE(axp813_ac_power_properties), + .property_is_writeable = axp813_ac_power_prop_writeable, + .get_property = axp20x_ac_power_get_property, + .set_property = axp813_ac_power_set_property, +}; + struct axp_data { const struct power_supply_desc *power_desc; bool acin_adc; @@ -154,6 +240,11 @@ static const struct axp_data axp22x_data = { .acin_adc = false, }; +static const struct axp_data axp813_data = { + .power_desc = &axp813_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 +325,9 @@ static const struct of_device_id axp20x_ac_power_match[] = { }, { .compatible = "x-powers,axp221-ac-power-supply", .data = &axp22x_data, + }, { + .compatible = "x-powers,axp813-ac-power-supply", + .data = &axp813_data, }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, axp20x_ac_power_match); diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index 517e60eecbcb..2302b620d238 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 AXP813_ACIN_PATH_CTRL 0x3a #define AXP813_ADC_RATE 0x85 /* Fuel Gauge */ -- 2.17.1