Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1169312imu; Tue, 20 Nov 2018 12:53:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/VB4Y/S5V5TIuK7jhYkXQrdbZcnFwMmvw1WvFqSA65y0QODobZ9loXfRIix6iuqykbS3jQo X-Received: by 2002:a17:902:2ec1:: with SMTP id r59-v6mr3819568plb.61.1542747215183; Tue, 20 Nov 2018 12:53:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542747215; cv=none; d=google.com; s=arc-20160816; b=kQ/MO5qbDJhbHXmbZVy1UCQyla1ida9l7rSWyVdDwHz0mM71Mt+uYBPMyczYQyYx92 odQrfewtSBEyrFCTMS0COtst8ycJNmilvxWiDD58Fb/iRDqO+trWWnYYtVCXN62hlMV4 valdphZqT79CiJGoVvBECTUbCGkiK4PdnJIeZjdKHkKO08qaiPmdWSJx8VDYbaJmCVty 9+ZaNhTXKjQjnLYnIUU6dafe+1bfzVl0GjSHLKCnRvro4Aq81FheCeBUChUCObZo3oot 6rR12mmaiM0Uf7NW3UtNbhGnrxPmHI6a8/rgOQZxrh87s1U+wXgO714tcdu1kFLknvQO Iyjg== 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=N4d9TmnaStUYg8DtSs7Z9dDmzAxdNZdiAtMyj9GuDKA=; b=xYnpAsdDfxfrKrQDYhcdssvdgjj5r7HmXKKjxAPsI16r4W96RWVAguKF65vlcyuzt1 A5YZ88wA/EVAoUm8lXrxJwN3+O7hkyvEE3eFi/MaCeZE1L9EjjVwEtWGDsApiQXLXKDJ jAiXdsNixweVEQ4A2e8H6YlyMfvvgDzZgYAkxJecArmkBjQUuuJmtN0S4+3B8NbDvX/4 tIvduZ4xk4mBL19pF1FNryBBhXwAoWP5vw/fbKQGIO1s8zVs9Px3ONs17WJ9UhsUuCn2 3WLJqxhdSbEo8/r4k8051xDq1Uo2zFAAp+FCAz66O7vG4zhU6JPXmPrfY8UyW27bNSkA 0mgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lemmela.net header.s=dkim header.b=pzZkF1Wk; 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 g9si22108814pfd.86.2018.11.20.12.53.19; Tue, 20 Nov 2018 12:53:35 -0800 (PST) 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=pzZkF1Wk; 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 S1730644AbeKUEXX (ORCPT + 99 others); Tue, 20 Nov 2018 23:23:23 -0500 Received: from mail1.kuutio.org ([92.222.216.83]:34466 "EHLO mail1.kuutio.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725828AbeKUEWy (ORCPT ); Tue, 20 Nov 2018 23:22:54 -0500 Received: from localhost (localhost [127.0.0.1]) by mail1.kuutio.org (Postfix) with ESMTP id 292E920791; Tue, 20 Nov 2018 18:52:31 +0100 (CET) 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=1542736350; x= 1545328351; bh=McHTmJfwqv5vT4ak3tr5W+9VZ0cs/KhRnl4KNDz2q2E=; b=p zZkF1WklDQo/6xhMiQjkiOFYPi6md2vt0MNYfTYA1xGFis2nklWby8iWH80Us0jS LoXoUstHkxihnhnulB6HHNCIXBM5sTuvCP3mPmZ/oURpnPBWuY7K2gYWbGT4LKxQ nNLNUHdQr4+uP1jlHFFfQN9YzlfatCUwq+b3ax7GwHcMQYRSwcOUoRuBNcV8+nrZ P7z/KSAb3MX2ItcFEKXaijZvVq5xQlcECQKhxC/MT4YNNPjamXFB1J043Jo9GadW Wdfi/s9fefOrghBGQ4owj/S+wuh/YDRYFkCSgmBoHepRiub6OkNdm29pkAOmBOhV sMS3pAOonQT+sX6NoRmv8cdSLEalVU97t5s1Xj34N88zAFsuTKPLdpRdF/Y7eT5S 7RtP+y2qtceWAcv8Q2F96xOIu0jXmFHi/Wyg+o6awJZvUPeFITlzEiAH9+X1FDEp Ge3MxnU9j3aclQbs4Km29FjBgUgC4OP7pvW7NVeHG7JMyyCZHdyw24dI37Gdx/9h lhQcK0GjuP9NtJYXN+ndQKTdFkdEPi0o88zIFIpEVzJVlb5wGgv4qiO6HVCmz7Hc olhHsyNSsKivXrHlE9PMpGx8myyMfRYNek8cpwwwqYu8yrj+lH3Sw3T82ArqG7JS baB+Qc4VHvYuGJCVBxB2l/Oo4JIv53kvg1nxleC7XA= 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 jhQKm35LsGka; Tue, 20 Nov 2018 18:52:30 +0100 (CET) Received: from build.kuutio.org (unknown [IPv6:2001:998:13:e4::69]) by mail1.kuutio.org (Postfix) with ESMTPSA id 2CC6820926; Tue, 20 Nov 2018 18:52:29 +0100 (CET) From: Oskari Lemmela To: Sebastian Reichel , Rob Herring , Mark Rutland , Chen-Yu Tsai , Maxime Ripard Cc: Lee Jones , Quentin Schulz , Vasily Khoruzhick , linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Oskari Lemmela Subject: [PATCH v6 6/8] power: supply: add AC power supply driver for AXP813 Date: Tue, 20 Nov 2018 19:52:09 +0200 Message-Id: <20181120175211.3913-7-oskari@lemmela.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181120175211.3913-1-oskari@lemmela.net> References: <20181120175211.3913-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 Reviewed-by: Chen-Yu Tsai Acked-by: Lee Jones --- 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