Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3898964imm; Mon, 8 Oct 2018 11:20:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV63+e8JuctOEqyA2SPMrQASSkVHLIJRRum3ufWIEX2nid12PNh3dNtj0GAt/KTsQGrb55FU7 X-Received: by 2002:a62:71c4:: with SMTP id m187-v6mr26088754pfc.232.1539022848004; Mon, 08 Oct 2018 11:20:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539022847; cv=none; d=google.com; s=arc-20160816; b=fr+wFXOSdU4F5ckwd7JTW6aknM0lPQEgMRYPpel06dpT6M8tf6p+wR+DPz7Leovgtz pI4BFsNgUcuLcYX7TrsNe1RO4N1WGqlCssGU5/kSbYtOnQCUQ247Jh7MGvrHRdZxN2IP es5VZnmsovIbeQns83RZJPnOGysrFZWNty5JX1OBjQURihbMuh0ey6j9KxQE5YUHv5w0 L16s2OqYpnSa1e3F0+mQSDiJJqq3NQ3YPDjGWEMYV6SPfbVO9tIDlRWL+/NjxvUbHUXN HhIkF2pzOw/9tnSL4m/JpBmQbIFQp1ZnrsM5+dIsm9N2140DARXITKgn4kR/BoDZ/WUN MNHg== 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=YoM0gJV5FtP9PfPOmX50lYIWtkydKKAvOBNqQc1pmgU=; b=ftsxfj9eAb9moEYrZSeTt5g9bQ6Fgq95n4VKgq3rtYboG+hKQW2Ha9PZJPTS+SDYQN pFfZ8Csx4pF5LmbDNT9vj1TencL4apmzHVWg9N6PoiwG2QEnRko00PnyHXFsXVcm/wys rFyrv8CvInpG/EOcYjuVfpM4QvN6avf0JTcml6sJ2jw4K0PHufUoBBgahq6hrWmp97Xs BC8fl042PtSNOg6bFWnKHTeCVwJrTg3wPUJ/hAiSMr9tGX8Pyp2dyJxADSAsal9oetRE FxZO0sDgO914cLDiUaRL5sxPPZ4C5OPqgg5bkYdjr5bmicftm9bQh4TM+iekwK16NvD8 +caw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lemmela.net header.s=dkim header.b=UYYw9czs; 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 14-v6si14093482ple.236.2018.10.08.11.20.33; Mon, 08 Oct 2018 11:20:47 -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=UYYw9czs; 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 S1726828AbeJIBdP (ORCPT + 99 others); Mon, 8 Oct 2018 21:33:15 -0400 Received: from mail1.kuutio.org ([92.222.216.83]:59464 "EHLO mail1.kuutio.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbeJIBdE (ORCPT ); Mon, 8 Oct 2018 21:33:04 -0400 Received: from localhost (localhost [127.0.0.1]) by mail1.kuutio.org (Postfix) with ESMTP id 9870920FED; Mon, 8 Oct 2018 20:20:03 +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=1539022802; x= 1541614803; bh=m8uhR3p38SRaJ+jBsn68IC3GU1eRDxR95szIsgGCzJw=; b=U YYw9czs4GlcqNYz8OROOFAoX6SZRLUAuwbmE2UzjfVdylrrVoy7nnZ+SqIFiP3Hy OwBuodvVeNxAHAjOgtrRVZwaNFFpQ/XqcsSJNQ4ovkduflXdvcIwh70xpHMiOFnU zilElUYPL/YNtod5oizum82GshiWfookuv1Puifx7n8+NXGILstdLHY/LdZipSLs bUGtwR6Q+MLE1xFVBXUFoC3CNB7iP1W8K5G+I0U6UCO4TqLLSQptu0EnIT/oEWci jAsfbpJ4P7jkesQl1Enh7ac1K4SSNngU+qpYqy6E6Zass5Z19ql2Bf44pjxpa6j1 txRHW68NpRT6sXWyvH6OztsI1bKwf0a2T4W8YfJbyHu0oLegSApoBmoHw9xf3Co6 XXVbJqknaHqZXu1TsNY7CcT9pNy/QYF82axle12HhTEPOAB5hJdnqGtR6kNnpaPL PbyZd8LktogVrLzuFSOr2qQnez6S/TKJ5AplvLOVT1xDZvi0dvquFdnlz+KQo1B3 o4K/p74mR3z+Tzval2OfbNPJTz/JiPFqPIv4aqvogfxK5x9pU2CA8G327I48wiC/ 9oIhHMmnAK95EwhJS5fiNQ4Ui1IoVU5T6FCpADTnhXCTfeO7Rji8X4FpoH11XPlR pcTuVWy0fGaZcLcRJ7HSDuT4ZaE/Dwf87anEAJ4oK0= 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 2M61cE4KCNHi; Mon, 8 Oct 2018 20:20:02 +0200 (CEST) Received: from build.kuutio.org (unknown [IPv6:2001:998:13:e4::69]) by mail1.kuutio.org (Postfix) with ESMTPSA id 0F60120929; Mon, 8 Oct 2018 20:20:02 +0200 (CEST) From: Oskari Lemmela To: Sebastian Reichel , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard Cc: Lee Jones , Quentin Schulz , Oskari Lemmela , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 5/7] power: supply: add AC power supply driver for AXP813 Date: Mon, 8 Oct 2018 21:19:06 +0300 Message-Id: <20181008181908.9456-6-oskari@lemmela.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181008181908.9456-1-oskari@lemmela.net> References: <20181008181908.9456-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 | 92 ++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 1 + 2 files changed, 93 insertions(+) diff --git a/drivers/power/supply/axp20x_ac_power.c b/drivers/power/supply/axp20x_ac_power.c index 0771f951b11f..059a97d6e14c 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,55 @@ 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); + + 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 +168,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 +189,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 +213,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 +238,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 +323,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