From patchwork Sat Feb 18 20:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 654862 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15F55C6379F for ; Sat, 18 Feb 2023 20:49:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229699AbjBRUt5 (ORCPT ); Sat, 18 Feb 2023 15:49:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjBRUt4 (ORCPT ); Sat, 18 Feb 2023 15:49:56 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A21914203; Sat, 18 Feb 2023 12:49:54 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m22-20020a7bcb96000000b003e21e018039so354329wmi.3; Sat, 18 Feb 2023 12:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=R1tUd+v3AgC5rEmN1z0CLTt+c2Ip3+6zTXGdLmF/kHw=; b=dwFJETju9IHoSilXKf3xnJT/UUz3P9fv5rW0+7nBP2vUVJQuRUftowkg9NmmD+SI1r 5pB71mFrHJXvMJ1mu+hBpOCfD9fm3Cx3dGnCITkme4JNune8R5SjcTMpkDVd5D3o8OHC pgNDJW83J++B4EAtP01s7VgieslJsE3vDh1/nJWixcdbv9sDFK6+DG9IURsShtC7XDbZ lT3QX4+gZTAWoirEmjMVqAE/DX/7RuZrtKKT2rmSGO1LF0hU5P80nZDAVvGhxdsgFmD/ hy+XNCxJ0H5mvFswoOeKTds+8vtdfN/PXT2NSPJdKI+gIp5XMbfxYKnOg60LsUcLdIec Yg4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=R1tUd+v3AgC5rEmN1z0CLTt+c2Ip3+6zTXGdLmF/kHw=; b=Yqm7eWCcYeBoiOwEQgROe4H2K1G2FAWXq9f7c6PnRrOCLYVRNkg1N6urVC3PbefUie kqXoFt1Sljc8KEFGBSfEspnkiDK9hUGFYComgrHj4APCnEwmcCvVzSFKCjm6TO6ASDt4 6xPbblq8cPAXk49MISUzaGdY+m9g3X8hFdR2GhUdFN3xGD9Q3cyx8qrmcgq2LKRieppe iQDVUX/hvyvCEp5+9dMyA3cJEDhm6PwgiRO/chhRmppIe2r7++Ir+1swBCYtm8S5X34+ P1asw2kjqC/Sfr4wZ13/InteH0xaPQtZCdaQ5ChzwFzcu80rDmeOdmaVmsikRi9s9km7 jqHw== X-Gm-Message-State: AO0yUKWsps3GANxuE3ngRafzbURj8HaEDF2rYCcFG9jPdeLN76lCYEUW nt00xNdNgyuC2nXyVeZQgRA= X-Google-Smtp-Source: AK7set+AIt6KJNo+pOLuBkEdpngdT57pvmpEsaqeTZBQ2H0ByfoxYfvM+yhJ5H5x3T+pz1murZ06lA== X-Received: by 2002:a05:600c:2b46:b0:3e0:1ab:cf2a with SMTP id e6-20020a05600c2b4600b003e001abcf2amr3529420wmf.39.1676753392757; Sat, 18 Feb 2023 12:49:52 -0800 (PST) Received: from localhost (94.197.47.81.threembb.co.uk. [94.197.47.81]) by smtp.gmail.com with ESMTPSA id ip24-20020a05600ca69800b003e223fe0a3asm5676563wmb.27.2023.02.18.12.49.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:49:52 -0800 (PST) From: Aidan MacDonald To: sre@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/5] power: supply: axp20x_usb_power: Simplify USB current limit handling Date: Sat, 18 Feb 2023 20:49:42 +0000 Message-Id: <20230218204946.106316-2-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> References: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Handle the USB current limit with a lookup table and regmap field, which minimizes code duplication. Invalid or unlimited values are denoted by -1 entries, and can't be selected from userspace. Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 172 ++++++++---------------- 1 file changed, 57 insertions(+), 115 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index a1e6d1d44808..67998fba702a 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -37,16 +37,6 @@ #define AXP20X_VBUS_VHOLD_uV(b) (4000000 + (((b) >> 3) & 7) * 100000) #define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3) #define AXP20X_VBUS_VHOLD_OFFSET 3 -#define AXP20X_VBUS_CLIMIT_MASK 3 -#define AXP20X_VBUS_CLIMIT_900mA 0 -#define AXP20X_VBUS_CLIMIT_500mA 1 -#define AXP20X_VBUS_CLIMIT_100mA 2 -#define AXP20X_VBUS_CLIMIT_NONE 3 - -#define AXP813_VBUS_CLIMIT_900mA 0 -#define AXP813_VBUS_CLIMIT_1500mA 1 -#define AXP813_VBUS_CLIMIT_2000mA 2 -#define AXP813_VBUS_CLIMIT_2500mA 3 #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) @@ -61,10 +51,21 @@ */ #define DEBOUNCE_TIME msecs_to_jiffies(50) +struct axp_data { + const struct power_supply_desc *power_desc; + const char * const *irq_names; + unsigned int num_irq_names; + enum axp20x_variants axp20x_id; + const int *curr_lim_table; + struct reg_field curr_lim_fld; +}; + struct axp20x_usb_power { struct regmap *regmap; + struct regmap_field *curr_lim_fld; struct power_supply *supply; enum axp20x_variants axp20x_id; + const struct axp_data *axp_data; struct iio_channel *vbus_v; struct iio_channel *vbus_i; struct delayed_work vbus_detect; @@ -121,60 +122,6 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); } -static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) -{ - unsigned int v; - int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); - - if (ret) - return ret; - - switch (v & AXP20X_VBUS_CLIMIT_MASK) { - case AXP20X_VBUS_CLIMIT_100mA: - if (power->axp20x_id == AXP221_ID) - *val = -1; /* No 100mA limit */ - else - *val = 100000; - break; - case AXP20X_VBUS_CLIMIT_500mA: - *val = 500000; - break; - case AXP20X_VBUS_CLIMIT_900mA: - *val = 900000; - break; - case AXP20X_VBUS_CLIMIT_NONE: - *val = -1; - break; - } - - return 0; -} - -static int axp813_get_current_max(struct axp20x_usb_power *power, int *val) -{ - unsigned int v; - int ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); - - if (ret) - return ret; - - switch (v & AXP20X_VBUS_CLIMIT_MASK) { - case AXP813_VBUS_CLIMIT_900mA: - *val = 900000; - break; - case AXP813_VBUS_CLIMIT_1500mA: - *val = 1500000; - break; - case AXP813_VBUS_CLIMIT_2000mA: - *val = 2000000; - break; - case AXP813_VBUS_CLIMIT_2500mA: - *val = 2500000; - break; - } - return 0; -} - static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -213,9 +160,12 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = ret * 1700; /* 1 step = 1.7 mV */ return 0; case POWER_SUPPLY_PROP_CURRENT_MAX: - if (power->axp20x_id == AXP813_ID) - return axp813_get_current_max(power, &val->intval); - return axp20x_get_current_max(power, &val->intval); + ret = regmap_field_read(power->curr_lim_fld, &v); + if (ret) + return ret; + + val->intval = power->axp_data->curr_lim_table[v]; + return 0; case POWER_SUPPLY_PROP_CURRENT_NOW: if (IS_ENABLED(CONFIG_AXP20X_ADC)) { ret = iio_read_channel_processed(power->vbus_i, @@ -316,50 +266,17 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, return -EINVAL; } -static int axp813_usb_power_set_current_max(struct axp20x_usb_power *power, - int intval) +static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, int intval) { - int val; + const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, + power->axp_data->curr_lim_fld.lsb); - switch (intval) { - case 900000: - return regmap_update_bits(power->regmap, - AXP20X_VBUS_IPSOUT_MGMT, - AXP20X_VBUS_CLIMIT_MASK, - AXP813_VBUS_CLIMIT_900mA); - case 1500000: - case 2000000: - case 2500000: - val = (intval - 1000000) / 500000; - return regmap_update_bits(power->regmap, - AXP20X_VBUS_IPSOUT_MGMT, - AXP20X_VBUS_CLIMIT_MASK, val); - default: + if (intval == -1) return -EINVAL; - } - return -EINVAL; -} - -static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, - int intval) -{ - int val; - - switch (intval) { - case 100000: - if (power->axp20x_id == AXP221_ID) - return -EINVAL; - fallthrough; - case 500000: - case 900000: - val = (900000 - intval) / 400000; - return regmap_update_bits(power->regmap, - AXP20X_VBUS_IPSOUT_MGMT, - AXP20X_VBUS_CLIMIT_MASK, val); - default: - return -EINVAL; - } + for (unsigned int i = 0; i <= max; ++i) + if (power->axp_data->curr_lim_table[i] == intval) + return regmap_field_write(power->curr_lim_fld, i); return -EINVAL; } @@ -380,9 +297,6 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, return axp20x_usb_power_set_voltage_min(power, val->intval); case POWER_SUPPLY_PROP_CURRENT_MAX: - if (power->axp20x_id == AXP813_ID) - return axp813_usb_power_set_current_max(power, - val->intval); return axp20x_usb_power_set_current_max(power, val->intval); default: @@ -461,11 +375,25 @@ static const char * const axp22x_irq_names[] = { "VBUS_REMOVAL", }; -struct axp_data { - const struct power_supply_desc *power_desc; - const char * const *irq_names; - unsigned int num_irq_names; - enum axp20x_variants axp20x_id; +static int axp20x_usb_curr_lim_table[] = { + 900000, + 500000, + 100000, + -1, +}; + +static int axp221_usb_curr_lim_table[] = { + 900000, + 500000, + -1, + -1, +}; + +static int axp813_usb_curr_lim_table[] = { + 900000, + 1500000, + 2000000, + 2500000, }; static const struct axp_data axp202_data = { @@ -473,6 +401,8 @@ static const struct axp_data axp202_data = { .irq_names = axp20x_irq_names, .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .axp20x_id = AXP202_ID, + .curr_lim_table = axp20x_usb_curr_lim_table, + .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), }; static const struct axp_data axp221_data = { @@ -480,6 +410,8 @@ static const struct axp_data axp221_data = { .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP221_ID, + .curr_lim_table = axp221_usb_curr_lim_table, + .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), }; static const struct axp_data axp223_data = { @@ -487,6 +419,8 @@ static const struct axp_data axp223_data = { .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP223_ID, + .curr_lim_table = axp20x_usb_curr_lim_table, + .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), }; static const struct axp_data axp813_data = { @@ -494,6 +428,8 @@ static const struct axp_data axp813_data = { .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .axp20x_id = AXP813_ID, + .curr_lim_table = axp813_usb_curr_lim_table, + .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), }; #ifdef CONFIG_PM_SLEEP @@ -592,9 +528,15 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) platform_set_drvdata(pdev, power); power->axp20x_id = axp_data->axp20x_id; + power->axp_data = axp_data; power->regmap = axp20x->regmap; power->num_irqs = axp_data->num_irq_names; + power->curr_lim_fld = devm_regmap_field_alloc(&pdev->dev, power->regmap, + axp_data->curr_lim_fld); + if (IS_ERR(power->curr_lim_fld)) + return PTR_ERR(power->curr_lim_fld); + ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, axp20x_usb_power_poll_vbus); if (ret) From patchwork Sat Feb 18 20:49:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 655000 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE828C636CC for ; Sat, 18 Feb 2023 20:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229737AbjBRUuA (ORCPT ); Sat, 18 Feb 2023 15:50:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229681AbjBRUt7 (ORCPT ); Sat, 18 Feb 2023 15:49:59 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6854F14200; Sat, 18 Feb 2023 12:49:55 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id k3-20020a05600c1c8300b003e1f5f2a29cso1065282wms.4; Sat, 18 Feb 2023 12:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=pN2mbhhRwU/XXivi0isPSjAJELATakPrcNi/RQdW9Lg=; b=MmvtPHyQ6AUYjlWORkjFWTlD0S09Nfwj6e8TcyHkeP0sUNuDu2PZGMWhwB/bybPQbq /41IR7w5+SmBZuI/3odnfLsJZixszvPyKzSzLNblsLp5TB6+x5PYqzeh+L1T6irGJPkR rKBEWrQGlDdg5R0zavsG4voCO7uJfbb5FMqzIZOS3MZ2eSNtbNdkeSXPjAh8Rbh/Q/XL pMEOqxfho/eG4+qB5yGMrbQHrCKFFr4TLrmJ6LcuZuVODhQydOQJIYED/IzrFRPI3Hse 6B4bu78NBDvCIcodcqFm69XFCTS/vzXhZw6nX19UaAfs4I99F6yVxYfXgJA2x6HllsLZ hb6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pN2mbhhRwU/XXivi0isPSjAJELATakPrcNi/RQdW9Lg=; b=sNxz4AgaKD0J7TwXrF6c56r4ZXsP4QtiZSJDeEHIMU0mLubsHrv6jUnlV9kME54fGZ YZRAAHClDnRtO49yDgaOIS+RQ7vgT1YkAXksH6TkP/Tqsb1Zfa7KE2Fai7OzeIYVP1PH H1p9dc2rqHsnBeRtSqP+X7jZkr84z08SeDoEa1EZ+LsBb5fWYGWGftfBQjAE2EBGmAr7 uMG0Q5LLLyXyv0EAJdd+eGGj7nz97qvsGXnGb6VFN64SUKJcJyEGsn4dOlG2nvXe+rs4 At0Yc57qPT4/JhABQ6TNS07QevwS9UhjAi37kxd8YUBacVIxJ3LPe5cPap0380ZvpKKm rmCQ== X-Gm-Message-State: AO0yUKWwWVwnpmZSiarf4r2kWUL2fIJ6y9L+Jeo4RSDW0C51zkxT9lG8 3y3qkcfadG/Kh/NbJY94/Cw= X-Google-Smtp-Source: AK7set/cDhFYn3Ldi3u0ekRdMRy2n0lT9BF1caXQUvyxDUsFwnkY0QuAXh8NlSLxvMOhaRVRBPvbbQ== X-Received: by 2002:a05:600c:2b45:b0:3df:85d2:c768 with SMTP id e5-20020a05600c2b4500b003df85d2c768mr3952547wmf.26.1676753393905; Sat, 18 Feb 2023 12:49:53 -0800 (PST) Received: from localhost (94.197.47.81.threembb.co.uk. [94.197.47.81]) by smtp.gmail.com with ESMTPSA id 9-20020a05600c22c900b003e224ff61a8sm5617947wmg.43.2023.02.18.12.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:49:53 -0800 (PST) From: Aidan MacDonald To: sre@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/5] power: supply: axp20x_usb_power: Use regmap fields for VBUS monitor feature Date: Sat, 18 Feb 2023 20:49:43 +0000 Message-Id: <20230218204946.106316-3-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> References: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use regmap fields to describe the VBUS valid bit and VBUS monitor enable bit. This allows the driver to easily support other chips, eg. the AXP192, that have the VBUS valid bit in a different register. Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 57 +++++++++++++++++++------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 67998fba702a..b2049b7d95fe 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -41,8 +41,6 @@ #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) -#define AXP20X_VBUS_MON_VBUS_VALID BIT(3) - #define AXP813_BC_EN BIT(0) /* @@ -58,11 +56,15 @@ struct axp_data { enum axp20x_variants axp20x_id; const int *curr_lim_table; struct reg_field curr_lim_fld; + struct reg_field vbus_valid_bit; + struct reg_field vbus_mon_bit; }; struct axp20x_usb_power { struct regmap *regmap; struct regmap_field *curr_lim_fld; + struct regmap_field *vbus_valid_bit; + struct regmap_field *vbus_mon_bit; struct power_supply *supply; enum axp20x_variants axp20x_id; const struct axp_data *axp_data; @@ -206,16 +208,15 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_HEALTH_GOOD; - if (power->axp20x_id == AXP202_ID) { - ret = regmap_read(power->regmap, - AXP20X_USB_OTG_STATUS, &v); + if (power->vbus_valid_bit) { + ret = regmap_field_read(power->vbus_valid_bit, &v); if (ret) return ret; - if (!(v & AXP20X_USB_STATUS_VBUS_VALID)) - val->intval = - POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; + if (v == 0) + val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; } + break; case POWER_SUPPLY_PROP_PRESENT: val->intval = !!(input & AXP20X_PWR_STATUS_VBUS_PRESENT); @@ -403,6 +404,8 @@ static const struct axp_data axp202_data = { .axp20x_id = AXP202_ID, .curr_lim_table = axp20x_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2), + .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), }; static const struct axp_data axp221_data = { @@ -501,6 +504,26 @@ static int configure_adc_registers(struct axp20x_usb_power *power) AXP20X_ADC_EN1_VBUS_VOLT); } +static int axp20x_regmap_field_alloc_optional(struct device *dev, + struct regmap *regmap, + struct reg_field fdesc, + struct regmap_field **fieldp) +{ + struct regmap_field *field; + + if (fdesc.reg == 0) { + *fieldp = NULL; + return 0; + } + + field = devm_regmap_field_alloc(dev, regmap, fdesc); + if (IS_ERR(field)) + return PTR_ERR(field); + + *fieldp = field; + return 0; +} + static int axp20x_usb_power_probe(struct platform_device *pdev) { struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); @@ -537,16 +560,26 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (IS_ERR(power->curr_lim_fld)) return PTR_ERR(power->curr_lim_fld); + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->vbus_valid_bit, + &power->vbus_valid_bit); + if (ret) + return ret; + + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->vbus_mon_bit, + &power->vbus_mon_bit); + if (ret) + return ret; + ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, axp20x_usb_power_poll_vbus); if (ret) return ret; - if (power->axp20x_id == AXP202_ID) { + if (power->vbus_mon_bit) { /* Enable vbus valid checking */ - ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON, - AXP20X_VBUS_MON_VBUS_VALID, - AXP20X_VBUS_MON_VBUS_VALID); + ret = regmap_field_write(power->vbus_mon_bit, 1); if (ret) return ret; From patchwork Sat Feb 18 20:49:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 654861 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11B48C64EC4 for ; Sat, 18 Feb 2023 20:50:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229716AbjBRUt6 (ORCPT ); Sat, 18 Feb 2023 15:49:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjBRUt5 (ORCPT ); Sat, 18 Feb 2023 15:49:57 -0500 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB7C1420D; Sat, 18 Feb 2023 12:49:56 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id j27so1052671wms.3; Sat, 18 Feb 2023 12:49:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iWpn+xWGvtGBH62qOXih/XCmqiF9B5PS3ayiTGHqtfM=; b=UKuBerBaLV/EDCGvEVXWrIxbbQtQBHoiC5Kvd5FYL1vS2r2L5WSq3oC3SbFEXZI5GC z3DMGF+lSkKgIn3Ng2qpFHIL9Be/eCset6N+xFPhGHB6zMRwEvMqso1RxzsFwSIhjgy5 xd0bttjAQziQW16ecEvcRhgqaiWimYtL8GN8OKXOYgOUyO2kXJvUzNSr681fMZeGtH0f AXxfewAPLbmB5cQh8hitmQOfCTQT5s8l3EQiZO7GKJa8kCaUyexP8taA+cy0a77fG/fr BEjKpWVHPEKoXy5Dlow/PdnIfurtkAqrnKvEoj7HRqriPUKZ/bn9ytYCsE16Z9Qybu3y bNQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iWpn+xWGvtGBH62qOXih/XCmqiF9B5PS3ayiTGHqtfM=; b=TMrIqW/slk0DBtiOKikd2WclBA9DIvtsi9ttmQOg/vAHT5bWQTUrUtcUnx+HAcAaIf yHiVui4ydPdpDcIoZeGCg+EuSPhpg6uMgaLTINJRQK/fr979YOnFS56r2jcpF8pAsDFD yl+hXfXGJZV16+6uZC+V7NRdaPZ3oKGh+vhZKjLyruBkV45TS7Zzb8gawgl9BB9lu+V5 5jSk7AUCKD57q+thS19V9iw7WcoZx2FgqYRO2RRzvSPQSFUIDXiMFaROvVYJT+p1eGvo SbDlZPD1P9KOQNmQogfDZ8zlDCycyEqr5i4m/Mxv6Pjt4DwSW77zzWK+VjV/4Qj9VDdK g/3g== X-Gm-Message-State: AO0yUKW7v/+/nFOANt41H67wGP6po7KyUlkSkrGXYtECCkPQV2ZD3/Hv Y2GpDALamy1CmA48d5pUH/0= X-Google-Smtp-Source: AK7set+zzA0ivuueg4C6yt+gQFMPyg5ZmE5h3MeaycUFJwdOUvSuTGG3hi93P5oOug719WWzZVmTLg== X-Received: by 2002:a05:600c:4b29:b0:3e2:147f:ac1a with SMTP id i41-20020a05600c4b2900b003e2147fac1amr6993905wmp.21.1676753395078; Sat, 18 Feb 2023 12:49:55 -0800 (PST) Received: from localhost (94.197.47.81.threembb.co.uk. [94.197.47.81]) by smtp.gmail.com with ESMTPSA id o2-20020a05600c4fc200b003e2059c7978sm10160847wmq.36.2023.02.18.12.49.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:49:54 -0800 (PST) From: Aidan MacDonald To: sre@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/5] power: supply: axp20x_usb_power: Use regmap fields for USB BC feature Date: Sat, 18 Feb 2023 20:49:44 +0000 Message-Id: <20230218204946.106316-4-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> References: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Replace the use of variant IDs with a regmap field, to reduce dependence on variant IDs. Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index b2049b7d95fe..20a76c19cfad 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -41,8 +41,6 @@ #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) -#define AXP813_BC_EN BIT(0) - /* * Note do not raise the debounce time, we must report Vusb high within * 100ms otherwise we get Vbus errors in musb. @@ -58,6 +56,7 @@ struct axp_data { struct reg_field curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; + struct reg_field usb_bc_en_bit; }; struct axp20x_usb_power { @@ -65,6 +64,7 @@ struct axp20x_usb_power { struct regmap_field *curr_lim_fld; struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; + struct regmap_field *usb_bc_en_bit; struct power_supply *supply; enum axp20x_variants axp20x_id; const struct axp_data *axp_data; @@ -433,6 +433,7 @@ static const struct axp_data axp813_data = { .axp20x_id = AXP813_ID, .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), }; #ifdef CONFIG_PM_SLEEP @@ -572,6 +573,12 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->usb_bc_en_bit, + &power->usb_bc_en_bit); + if (ret) + return ret; + ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, axp20x_usb_power_poll_vbus); if (ret) @@ -592,10 +599,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; } - if (power->axp20x_id == AXP813_ID) { + if (power->usb_bc_en_bit) { /* Enable USB Battery Charging specification detection */ - ret = regmap_update_bits(axp20x->regmap, AXP288_BC_GLOBAL, - AXP813_BC_EN, AXP813_BC_EN); + ret = regmap_field_write(power->usb_bc_en_bit, 1); if (ret) return ret; } From patchwork Sat Feb 18 20:49:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 654860 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47914C64ED8 for ; Sat, 18 Feb 2023 20:50:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbjBRUuC (ORCPT ); Sat, 18 Feb 2023 15:50:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229752AbjBRUuB (ORCPT ); Sat, 18 Feb 2023 15:50:01 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23A614203; Sat, 18 Feb 2023 12:49:57 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id 2so1119918wrz.9; Sat, 18 Feb 2023 12:49:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=r+e0WO9314+22bYk2/c0IG6PriU+XsPi5/aWiGwjMuE=; b=f/q2/34THR9pa5fDB9GLXMRJsOU1d0u+06pzMTnvLm0bY8B20k0aeobEJs8G+JD5Dz YFRqqSV3tfv7kae+1eDRvZUCuUpjtqoslWqLR+srWXn3RGXvgpIv5qBwSXbxVxvI0AON 0P/j48nqCviABLqLz875C8znhcnqzywiwSi3tXTyK6SF+epyZCMJACIyWxLpjo/LaSlC kTJwHns4Gz9DMVRPmRFpoqnyiTtKPARFjmfba1ekkg4ME0KZ8zkjgaSn5dcoY8d3VVpR 9yKCzFHc2+g/SGQqm8KF+QlRf+PJPSr5OHItbslscFEwf9Kn+sqENBAqi2+nZDIFz15c BWyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=r+e0WO9314+22bYk2/c0IG6PriU+XsPi5/aWiGwjMuE=; b=edxBbMFm7IV1yTDyrEUQvhSz0+GFkZNatnkcfor6LII5OVER28g3dR2PFOXNOPNQ1w 4fRu3mcR8LWMnqP6bKt19KiSlTxdctchAH5tdZ15EZBSI2YtTGAf2w/ty451VSP1hMTG m1QVIFSXsZRvA83suna4ffCuAipZC/VYraKGzTSXeulDnZLzBV00TVm/9yJtio8DSFmr NXasTwmY3iteXYT5+RtiC5xQ5nAEm2x96TU/PJrGllEShNNh62KS1qslppdb2F91dH+H QfBvVgqdOR5SGPMIlTGSQ4kA/wlMOqD+j97kF4X15fbRjYnfSvrebHV2QVvCn6USum57 LUEA== X-Gm-Message-State: AO0yUKWjeG6G66QM7ymXyB5fgy7ybIS8v1sLKN6uivmcRGeJkYosUkUU a3zwgdYxRuLyb7iux6RSwziGvPcJLQ0= X-Google-Smtp-Source: AK7set/eyQGENHOJzGaq7pr/BSJsfv75n2FujnAvn9JaepKYwNOkwAJqtTHMO7pJ4h4+a+WTKRjVwA== X-Received: by 2002:a5d:4ecd:0:b0:2c5:4fde:7716 with SMTP id s13-20020a5d4ecd000000b002c54fde7716mr2512784wrv.24.1676753396153; Sat, 18 Feb 2023 12:49:56 -0800 (PST) Received: from localhost (94.197.47.81.threembb.co.uk. [94.197.47.81]) by smtp.gmail.com with ESMTPSA id b5-20020adfee85000000b002c559626a50sm772305wro.13.2023.02.18.12.49.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:49:55 -0800 (PST) From: Aidan MacDonald To: sre@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/5] power: supply: axp20x_usb_power: Use regmap field for VBUS disabling Date: Sat, 18 Feb 2023 20:49:45 +0000 Message-Id: <20230218204946.106316-5-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> References: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The POWER_SUPPLY_PROP_ONLINE property allows controlling the VBUS enable state on supported PMICs. Switch to regmap fields to reduce dependence on variant IDs. Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 29 +++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 20a76c19cfad..89f076615d2e 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -31,9 +31,6 @@ #define AXP20X_USB_STATUS_VBUS_VALID BIT(2) -#define AXP20X_VBUS_PATH_SEL BIT(7) -#define AXP20X_VBUS_PATH_SEL_OFFSET 7 - #define AXP20X_VBUS_VHOLD_uV(b) (4000000 + (((b) >> 3) & 7) * 100000) #define AXP20X_VBUS_VHOLD_MASK GENMASK(5, 3) #define AXP20X_VBUS_VHOLD_OFFSET 3 @@ -57,6 +54,7 @@ struct axp_data { struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; + struct reg_field vbus_disable_bit; }; struct axp20x_usb_power { @@ -65,6 +63,7 @@ struct axp20x_usb_power { struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; struct regmap_field *usb_bc_en_bit; + struct regmap_field *vbus_disable_bit; struct power_supply *supply; enum axp20x_variants axp20x_id; const struct axp_data *axp_data; @@ -231,16 +230,6 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, return 0; } -static int axp813_usb_power_set_online(struct axp20x_usb_power *power, - int intval) -{ - int val = !intval << AXP20X_VBUS_PATH_SEL_OFFSET; - - return regmap_update_bits(power->regmap, - AXP20X_VBUS_IPSOUT_MGMT, - AXP20X_VBUS_PATH_SEL, val); -} - static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, int intval) { @@ -290,9 +279,10 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_ONLINE: - if (power->axp20x_id != AXP813_ID) + if (!power->vbus_disable_bit) return -EINVAL; - return axp813_usb_power_set_online(power, val->intval); + + return regmap_field_write(power->vbus_disable_bit, !val->intval); case POWER_SUPPLY_PROP_VOLTAGE_MIN: return axp20x_usb_power_set_voltage_min(power, val->intval); @@ -320,7 +310,7 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy, * the VBUS input offline. */ if (psp == POWER_SUPPLY_PROP_ONLINE) - return power->axp20x_id == AXP813_ID; + return power->vbus_disable_bit != NULL; return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || psp == POWER_SUPPLY_PROP_CURRENT_MAX; @@ -434,6 +424,7 @@ static const struct axp_data axp813_data = { .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), + .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), }; #ifdef CONFIG_PM_SLEEP @@ -579,6 +570,12 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->vbus_disable_bit, + &power->vbus_disable_bit); + if (ret) + return ret; + ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, axp20x_usb_power_poll_vbus); if (ret) From patchwork Sat Feb 18 20:49:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 654999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEDE8C6379F for ; Sat, 18 Feb 2023 20:50:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229759AbjBRUuB (ORCPT ); Sat, 18 Feb 2023 15:50:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBRUuA (ORCPT ); Sat, 18 Feb 2023 15:50:00 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4B614EA9; Sat, 18 Feb 2023 12:49:58 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id k14-20020a05600c1c8e00b003e22107b7ccso814639wms.0; Sat, 18 Feb 2023 12:49:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sdCsH2d8zg6wheMJGk9jqr1Puc+kcdg3d/O4BTVakwc=; b=Il5L5cPlhAHrh4Ia3DeD4zTlMK3BeZCon21HTwzfeskwaSTUGEV1jKUzcIAPj0Mj23 MCE1Q+aweforLcOWJAobIWXh6UxedaTKYxldG5hlOzSv7T7VsgYPszTdAL2pkqMiV4Fm 0KnpmtOq3K+pbMI+5SNUdm2QgKpZuiylL0gFs8h5esoEvfra0Qjyv2p2hkhempxFnCs1 TF8wzTcFajRF9pMCZECGPBFt4mUOiIs32rdZyvdmJRnO1MxsoyjOToQeCam1oCg53MNG CpOyqH3XgDnWBG7C65TJ0TvaxWZY9pyJnoVt92ExvkwxfRWhGUskWyHNtmjVXyfjDfiU JfwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sdCsH2d8zg6wheMJGk9jqr1Puc+kcdg3d/O4BTVakwc=; b=rV1CeYr+mTD64ZLKJ3HRq4G5N4jckI0nDCsQ1RtTOU4Y/ixdo4kKZBDriT1772JKVP vxAjY8Zj1a9ShI/mLPwnczKwrjJOS2Ts356opOGeTreUBkEFbNlh/1pOJUJdNb0Rg3qu +J59z8cqWnNrrRz2Dx/LKbR1gTMgHMP+ukFmnhZ5heyEVHH4LhfTsKDHIUMu9mvUt1a7 Y9dqRoQbXWrbzxxcx0xC8BujyJbsOztyIOGn4IJu74AxFq4dEBmNRDSgne3URxV3KqDx V7XwXu40Eu/M5y64FpSRKtAfbh81mz7aoWK7aHlo9bf63voeEfSW21dC2aY5RqUzYzCZ YsdQ== X-Gm-Message-State: AO0yUKXTMsBnm3G1iKuPGlmr92x5/PXOlaBWS8QJRSWK+cIQ0gcBT/b4 qm8lCFiInUz1dGZEBYnZJHXMRBsx3s8= X-Google-Smtp-Source: AK7set+mexdiUZcpqfmOs9RlSu3rmMnyr9ejrMNHzIhZEfso0t0zrx7T4QrQ5F4R6w+7HUGfMtpLTA== X-Received: by 2002:a05:600c:1695:b0:3e2:6dc:4d6e with SMTP id k21-20020a05600c169500b003e206dc4d6emr9508359wmn.31.1676753397393; Sat, 18 Feb 2023 12:49:57 -0800 (PST) Received: from localhost (94.197.47.81.threembb.co.uk. [94.197.47.81]) by smtp.gmail.com with ESMTPSA id s10-20020a7bc38a000000b003dc1a525f22sm8866551wmj.25.2023.02.18.12.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Feb 2023 12:49:57 -0800 (PST) From: Aidan MacDonald To: sre@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/5] power: supply: axp20x_usb_power: Remove variant IDs from VBUS polling check Date: Sat, 18 Feb 2023 20:49:46 +0000 Message-Id: <20230218204946.106316-6-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> References: <20230218204946.106316-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Use an explicit boolean flag instead of a check based on the variant ID. Since this is the last use of variant IDs in the driver, also remove the IDs. Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 89f076615d2e..089fe837a4b2 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -48,13 +48,13 @@ struct axp_data { const struct power_supply_desc *power_desc; const char * const *irq_names; unsigned int num_irq_names; - enum axp20x_variants axp20x_id; const int *curr_lim_table; struct reg_field curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; struct reg_field vbus_disable_bit; + bool vbus_needs_polling: 1; }; struct axp20x_usb_power { @@ -65,7 +65,6 @@ struct axp20x_usb_power { struct regmap_field *usb_bc_en_bit; struct regmap_field *vbus_disable_bit; struct power_supply *supply; - enum axp20x_variants axp20x_id; const struct axp_data *axp_data; struct iio_channel *vbus_v; struct iio_channel *vbus_i; @@ -83,7 +82,7 @@ static bool axp20x_usb_vbus_needs_polling(struct axp20x_usb_power *power) * present->absent transition implies an online->offline transition * and will trigger the VBUS_REMOVAL IRQ. */ - if (power->axp20x_id >= AXP221_ID && !power->online) + if (power->axp_data->vbus_needs_polling && !power->online) return true; return false; @@ -391,7 +390,6 @@ static const struct axp_data axp202_data = { .power_desc = &axp20x_usb_power_desc, .irq_names = axp20x_irq_names, .num_irq_names = ARRAY_SIZE(axp20x_irq_names), - .axp20x_id = AXP202_ID, .curr_lim_table = axp20x_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_valid_bit = REG_FIELD(AXP20X_USB_OTG_STATUS, 2, 2), @@ -402,29 +400,29 @@ static const struct axp_data axp221_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), - .axp20x_id = AXP221_ID, .curr_lim_table = axp221_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .vbus_needs_polling = true, }; static const struct axp_data axp223_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), - .axp20x_id = AXP223_ID, .curr_lim_table = axp20x_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .vbus_needs_polling = true, }; static const struct axp_data axp813_data = { .power_desc = &axp22x_usb_power_desc, .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), - .axp20x_id = AXP813_ID, .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), + .vbus_needs_polling = true, }; #ifdef CONFIG_PM_SLEEP @@ -542,7 +540,6 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) platform_set_drvdata(pdev, power); - power->axp20x_id = axp_data->axp20x_id; power->axp_data = axp_data; power->regmap = axp20x->regmap; power->num_irqs = axp_data->num_irq_names;