From patchwork Wed May 10 11:50:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 680675 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 B8783C7EE26 for ; Wed, 10 May 2023 11:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237018AbjEJLvu (ORCPT ); Wed, 10 May 2023 07:51:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236935AbjEJLvs (ORCPT ); Wed, 10 May 2023 07:51:48 -0400 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 059D11725; Wed, 10 May 2023 04:51:47 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f42d937d2eso9930785e9.2; Wed, 10 May 2023 04:51:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683719505; x=1686311505; 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=UavLsZCmhV/UqjGQKMpLAepZc1rNomzLV6CrY6y8QkMjTWPgIrRON+cNcQtfAZ31z2 Ol4UyEKsZUmRxh/1R+4qU92z2Mo79oZGgLJoYKza+PWqq8AUFajSRY66Bmf6lZS8R/2l aUjvUaiZjeAWp7SiDACTwPTg/MLSR/TyzMPjC55KK6eKFHQM/Mza+tjsvbZ/JovWn/UH smXfzHB0BYWvX3qUAeob7LTxPuc3AaBfuNBgPJ16BuwyTDH3nxoWGTNxOO9DwZOX+vCO 31gXXFAUh5X73LOsLcFe9oqsL1m+BPWgai2GkDJhO+fHuUsUSJ8oS/oCL8aD9lcVwUhR g+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683719505; x=1686311505; 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=PYwuV8a2lc/waXl/U2TbFOZ0V6kBaZ/RDuLlYgFypxneZgbYiZxQBvVtaVoWnbL+5I anfEEuDsOosaMOsFyVQOMbyKPutvBy6LEsKRd7OkwiEdNCq1XIJuf1LInmZQRAONgq0f DagJtRvyz48k6VCuaIrfE5o3IJCAl06ZMQxFB4387kIrzaFHYQO13Z61Gm1TAZhz1N/9 o9ex7J8iW5Pd/Pd1xLftJMX8fpxziMosaZB1tmIlFMvWRx1ruJi1w9H0UcaJDeb7AtfN e3X+ObRRJNgNovTU4HNMItY/HgmcRAWA9AKNUBe5NH3qHAdvJPzWlef3befnut0aPYYP A8Sw== X-Gm-Message-State: AC+VfDznXGhDIPxyQDUmF1QzZFaYFYwBhDJc2C0KMM1/V/INMDQ96Yjn jbuMZJncFLr9m9ZvZEEcV9w= X-Google-Smtp-Source: ACHHUZ5niuw3oceMYqnvTSOw3iuU0t2n7iE9CRPOg6Qv31XA9gdKiEZTy0Ntjwu3IpSxxV8MXTIi4w== X-Received: by 2002:adf:ee49:0:b0:306:2701:5346 with SMTP id w9-20020adfee49000000b0030627015346mr13146778wro.39.1683719505398; Wed, 10 May 2023 04:51:45 -0700 (PDT) Received: from localhost ([167.98.27.226]) by smtp.gmail.com with ESMTPSA id r15-20020a5d694f000000b00306415ac69asm17124236wrw.15.2023.05.10.04.51.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 04:51:45 -0700 (PDT) From: Aidan MacDonald To: sre@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/7] power: supply: axp20x_usb_power: Use regmap fields for VBUS monitor feature Date: Wed, 10 May 2023 12:50:41 +0100 Message-Id: <20230510115046.963432-3-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> References: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Wed May 10 11:50: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: 680674 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 94284C7EE2D for ; Wed, 10 May 2023 11:51:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237025AbjEJLvw (ORCPT ); Wed, 10 May 2023 07:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237021AbjEJLvu (ORCPT ); Wed, 10 May 2023 07:51:50 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F5A435A3; Wed, 10 May 2023 04:51:49 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-2f27a9c7970so6730361f8f.2; Wed, 10 May 2023 04:51:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683719507; x=1686311507; 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=Q/E/T1aHHQGd8tG4pCXUPk93NhLvFH0M+pemyAz0J37e8tRIPpFC1XoJprjPtlpkXx VxZudODg3w+OZnbq2u2Of/01KfEKLKU4S74UnmRlcUs1iwoyp9bZHa2xXoaewgkF3K8C UFFitLWAWJK3BHODRC8x4qlXLNsHW/l9T3PiWqHBkS2yHAPXzjlLgOincgaq9x9YyHni jQzdkT9iTlaqlJ16zFl5/VQqJRRybTyE5kmsJracyG7MCl2P2Yw8lZvD+wSU2jzl+M2U PtSZ6xX+JCzRsl5+gZQqO+iG1ekHSS1GsM/iaJKHx28obrCPfUdo1rcyz6X+Y4yRK4Yk GR0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683719507; x=1686311507; 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=BpU1LAVJ8Npw00rMXXB6T41jM0mg+wlbe93CkHa79lPXi/H/3GfL9lX7hAi49FlhEb n1wDtUIilS0R1bf+dcLtAxZ0uTLCf3TDsE9NllRpqEQS3Cus/y8I0623X7uI5Xl51wtz NrtQ0P7YZ6YUrKyDyXKG2siY6NztNbFPK2DdpVYLwREk27jjyL3W3u5Jk5t1CH/+WCwU dgie97n2rlYHYg0HUPI4u2YCHVQTqnefO0ECnri6Dkp2BtsYJbijwJB1GSSXbsIHuJZv Qm5dNL/ztqZ1KTH3b727MiDdlVyqT7OQxMXxfqHgu4HsHtI3QL2SNScozNKlVRqUPeSp bQNQ== X-Gm-Message-State: AC+VfDx+y30mbFbUp0bcB+WiATkXNb42ZCmEAjzD1G1G5ejwCghbDOEa PYx4uHpyIxCsqTCixOJ9yCEtD++30r4= X-Google-Smtp-Source: ACHHUZ76W1o5twe5boP7VQFqcPUI3XuQokY+zIZjQqirKHxWQkYMhOO3YpVV+xMQhQBXNIN+otcDUg== X-Received: by 2002:a5d:6d4d:0:b0:306:2927:b581 with SMTP id k13-20020a5d6d4d000000b003062927b581mr11419223wri.46.1683719507494; Wed, 10 May 2023 04:51:47 -0700 (PDT) Received: from localhost ([167.98.27.226]) by smtp.gmail.com with ESMTPSA id z8-20020adfec88000000b003062675d4c9sm17094885wrn.39.2023.05.10.04.51.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 04:51:47 -0700 (PDT) From: Aidan MacDonald To: sre@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 4/7] power: supply: axp20x_usb_power: Use regmap field for VBUS disabling Date: Wed, 10 May 2023 12:50:43 +0100 Message-Id: <20230510115046.963432-5-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> References: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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 Wed May 10 11:50: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: 680673 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 23F28C7EE26 for ; Wed, 10 May 2023 11:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237029AbjEJLvx (ORCPT ); Wed, 10 May 2023 07:51:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237026AbjEJLvw (ORCPT ); Wed, 10 May 2023 07:51:52 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4995FC2; Wed, 10 May 2023 04:51:50 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-3f42bcf5df1so18708735e9.3; Wed, 10 May 2023 04:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683719509; x=1686311509; 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=JMVjlHpkletbHyZMVIVo5SEiHVHe9HN5MHzA6s1NqWsBobJl97afhQnQWXnGWBbumW K1h8dMYJQqGP6mr5vJIlU/MfVEjkth194lBHpUWzmLV3qmMipBh8Lfrz4yLfoQnvl5SD VIc/cBxOlHOVtd4TrM/rhLDlaSKhyN8SExIy4OI3Nr1GBLskVJZjER9Fbw41GCtTqDj6 UXWRoGRESgBJ2HqgwJuETWdJg7mJtD2/oL/aU0BjIrU2Jc2agJsHy2VpPdn6E7ozEuCC /XVK8wF6Bik/Up5iI2fd8PYRPeRUhHzsv7MEGsGl2wcNtrr2Bs4CgE2Hz6FdQ6NUhbP1 Y5iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683719509; x=1686311509; 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=V85DZPZW/T0Eoe7zUCSWecaQc6CwCArqKZed4MIYvMlvoY6u+JLM1hE1/MVdZfxgrw Hwwbh2U6WZRPgcSk6c9y5HX8nw0K2PgZXtYE0Vo6fNVW1MyZRA5aD9bjURF5zNEiEWwm dBxamJ/6Q8HvsDCjHve2GiF1hKY49eiSRUv4yO9ljQE1HXtprFXWudKYZPdA2xvHmGCY +hEdPZnJpA+HERHQ3Ra140TZsr13ZWHoBvTMBgQSEmRMBe3z89k818XGh+6o6HAwrELW ghho1dnKYEefa0LuplndnNRIxi18kTeU86rw2iR9WCqySjfq4zLJ/5toaz3yyZaU/Z/9 5Yeg== X-Gm-Message-State: AC+VfDyOKJzDMjXnawGhRHV3d7KIohydNeE0TFCaB4xuZ0d5B+SRje3A +JzuOrmbFnBBpBhEmJw1Yc8= X-Google-Smtp-Source: ACHHUZ4Xj7OSSzHMiupaFmcG2/P/M2LWRb3mUD1jUUBwSqCYQNP4LMoFCFZXnVflVgZt4hflenhjXg== X-Received: by 2002:a7b:c449:0:b0:3f4:2d04:f3f0 with SMTP id l9-20020a7bc449000000b003f42d04f3f0mr3102760wmi.39.1683719508505; Wed, 10 May 2023 04:51:48 -0700 (PDT) Received: from localhost ([167.98.27.226]) by smtp.gmail.com with ESMTPSA id 2-20020a05600c22c200b003f42328b5d9sm10525514wmg.39.2023.05.10.04.51.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 04:51:48 -0700 (PDT) From: Aidan MacDonald To: sre@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org, wens@csie.org Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 5/7] power: supply: axp20x_usb_power: Remove variant IDs from VBUS polling check Date: Wed, 10 May 2023 12:50:44 +0100 Message-Id: <20230510115046.963432-6-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> References: <20230510115046.963432-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: devicetree@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;