From patchwork Sun Jan 21 01:40:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 189784 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1878522dyb; Sat, 20 Jan 2024 17:44:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHronwbcSdj9dQ+a/FF8vXa7n9SAG2ycAdSSzDDAB/+cai9TFl2qxQ8j8SSLvx7/Tkf5DmY X-Received: by 2002:a05:600c:45d2:b0:40e:8d4d:1716 with SMTP id s18-20020a05600c45d200b0040e8d4d1716mr1100026wmo.37.1705801476250; Sat, 20 Jan 2024 17:44:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801476; cv=pass; d=google.com; s=arc-20160816; b=Wmj3GIjyHNtIjDoHJ3/qlY5O8Vv+WKKxmcmRwM6sE/MSP4C0MGrFuJ5ArmAEZ2sH7M 14C7Jasay5x/2WL6850NyYMtNaYWO94qKsNUQQJQmMVEew8dm0+RfX3tJ0XJuycoYjp4 goeUWPJFDKpp+HAYAZvzv8PXisgfVXBj/stN4cJ0WEGfbVH+8CCebyJQ/YPrtjEi7vkr iVSn13Ypi+qhY2nXDma9hPTBGo3Z54AR4waS5QSYsKzhE3liaOUtnJmTEnP4S6IuD+OZ aPbia6TFQG/Y23yRIZ9N/X16rnXvJ51OLUDgaA0ehIFYnN0zqBubAuBhDWUzKdTpf96V sdjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=mTTqhJZ+TXCTAU2v1OkBw9B/XAxQraalT4JO8XnSZII=; fh=eFCTS4Ca+qpaFRwPKpEidZ8XXzB0gM774/68c0nALYA=; b=PUCJRzIxTkaRnHHH52g+alrx9JwvaKJgJMfjolMKNbkncsEQWLvdp5RTrmtENuAlO+ TfCuyhr07/XEuxZjogB97avI3oQAp0J2mVce1R6hGTY4B6Z3RTHPPdC3DwAuFang6W4E eLQxAfdRiiubRM+WFaYuP0RC8cIM0WFvL1lKXXLNG8K5pRUcQe3ZLAxPYKHEVqeRInV1 gyVL5CQzzDopSlAh/cfxj1QDpsvLnDBGJ13ragXM2atfv49+1xam7wxLCh1ZsCxuoeBs TQwYtTvaDBFS6Z2ZW8BlmzHawPdlnKjzsZ+k0jvriEUMXU0m6J0Hjk5edGf0PYyCaWnD l7Vw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=lMtAffAy; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31947-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id h10-20020a17090634ca00b00a2f0df8c70fsi3431801ejb.935.2024.01.20.17.44.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:44:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=lMtAffAy; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31947-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31947-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AF2AD1F229AB for ; Sun, 21 Jan 2024 01:44:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C82735285; Sun, 21 Jan 2024 01:44:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="lMtAffAy" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C21434180; Sun, 21 Jan 2024 01:44:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801457; cv=none; b=QTFXMCBdMzvdEFpNuT23E10Q6azli9KjTIXPOOheCiZBCDLqozCxea6ejfDM6I5xg2j5Vdd2k19MsD4Zj2yfM2mRIj94CyEQo/X+A3n69WOagru4/iSKhv3OJ2S/WMMloWMMgA7K6gwBbtlJ/EnvFqjPQvcCXKZ5bpitN4QXvIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801457; c=relaxed/simple; bh=DPa+Nkb0JVfgtnAuyOILFcJ3GBwfuVrctlhfHFq+TEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j18usTzS6BeG5Y1XOldf8EhOt2SsPhotizUIIRm6Mw5pmVqweKN16nLOmFhb+Gt1ZEzAbMW6DyNtthisa5ss3uFbDGcWpQ2eS73uXBWYgB9DQo2psoGh7iPObT9qBdN6V0UOXFIknxgTdrbmOa4GSKe/7ocnpGhEG1XWD4xxpdY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=lMtAffAy; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id A6DAC4620D; Sun, 21 Jan 2024 01:44:13 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?utf-8?q?Ond=C5=99ej_Ji?= =?utf-8?q?rman?= , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH 1/3] power: supply: axp20x_usb_power: add input current limit Date: Sat, 20 Jan 2024 20:40:00 -0500 Message-ID: <20240121014057.1042466-3-aren@peacevolution.org> In-Reply-To: <20240121014057.1042466-1-aren@peacevolution.org> References: <20240121014057.1042466-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705801454; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=mTTqhJZ+TXCTAU2v1OkBw9B/XAxQraalT4JO8XnSZII=; b=lMtAffAyNqtnakbBvalpNJNZCjKVCYzo1SnhFulzJ6j5l0GvqTznjjHx0OjR+7ZlrQXSED S6UNgd+Wl5jGT1DiZW3RIfJM0F9G0A2cZNIRq9oJ3gfLhSIeQbQ3gjkVkWtVxtdINQCs2i Cax7oMSGnjbdQEAUTSRkPbODXFBKvhA= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788662488832524692 X-GMAIL-MSGID: 1788662488832524692 Add properties for setting the maximum current that will be drawn from the usb connection. These changes don't apply to all axp20x chips, so we need to add new power_desc and power supply property objects for axp813 specifically. These are copied from the axp22x variants that were used before, with extra fields added. Also add a dev field to the axp20x_usb_power struct, so we can use dev_dbg and dev_err in more places. Signed-off-by: Aren Moynihan Reviewed-By: Ondrej Jirman --- drivers/power/supply/axp20x_usb_power.c | 127 +++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index e23308ad4cc7..8c0c2c25565f 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -50,7 +50,10 @@ struct axp_data { const char * const *irq_names; unsigned int num_irq_names; const int *curr_lim_table; + int input_curr_lim_table_size; + const int *input_curr_lim_table; struct reg_field curr_lim_fld; + struct reg_field input_curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; @@ -59,7 +62,9 @@ struct axp_data { }; struct axp20x_usb_power { + struct device *dev; struct regmap *regmap; + struct regmap_field *input_curr_lim_fld; struct regmap_field *curr_lim_fld; struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; @@ -115,6 +120,15 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) if (val != power->old_status) power_supply_changed(power->supply); + if (power->usb_bc_en_bit && (val & AXP20X_PWR_STATUS_VBUS_PRESENT) != + (power->old_status & AXP20X_PWR_STATUS_VBUS_PRESENT)) { + dev_dbg(power->dev, "Cable status changed, re-enabling USB BC"); + ret = regmap_field_write(power->usb_bc_en_bit, 1); + if (ret) + dev_err(power->dev, "failed to enable USB BC: errno %d", + ret); + } + power->old_status = val; power->online = val & AXP20X_PWR_STATUS_VBUS_USED; @@ -123,6 +137,66 @@ 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_usb_power_set_input_current_limit(struct axp20x_usb_power *power, + int limit) +{ + int ret; + unsigned int reg; + + if (!power->axp_data->input_curr_lim_table) + return -EINVAL; + + if (limit < power->axp_data->input_curr_lim_table[0]) + return -EINVAL; + + /* + * BC1.2 detection can cause a race condition if we try to set a current + * limit while it's in progress. When it finishes it will overwrite the + * current limit we just set. + */ + if (power->usb_bc_en_bit) { + dev_dbg(power->dev, + "disabling BC1.2 detection because current limit was set"); + ret = regmap_field_write(power->usb_bc_en_bit, 0); + if (ret) + return ret; + } + + for (reg = power->axp_data->input_curr_lim_table_size - 1; reg > 0; reg--) { + if (limit >= power->axp_data->input_curr_lim_table[reg]) + break; + } + + dev_dbg(power->dev, "setting input current limit reg to %d (%d uA), requested %d uA", + reg, power->axp_data->input_curr_lim_table[reg], limit); + + return regmap_field_write(power->input_curr_lim_fld, reg); +} + +static int +axp20x_usb_power_get_input_current_limit(struct axp20x_usb_power *power, + int *intval) +{ + int ret; + unsigned int v; + + if (!power->axp_data->input_curr_lim_table) + return -EINVAL; + + ret = regmap_field_read(power->input_curr_lim_fld, &v); + if (ret) + return ret; + + if (v < power->axp_data->input_curr_lim_table_size) + *intval = power->axp_data->input_curr_lim_table[v]; + else + *intval = power->axp_data->input_curr_lim_table[ + power->axp_data->input_curr_lim_table_size - 1]; + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -189,6 +263,9 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = ret * 375; /* 1 step = 0.375 mA */ return 0; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return axp20x_usb_power_get_input_current_limit(power, + &val->intval); default: break; } @@ -290,6 +367,10 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CURRENT_MAX: return axp20x_usb_power_set_current_max(power, val->intval); + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return axp20x_usb_power_set_input_current_limit(power, + val->intval); + default: return -EINVAL; } @@ -313,7 +394,8 @@ static int axp20x_usb_power_prop_writeable(struct power_supply *psy, return power->vbus_disable_bit != NULL; return psp == POWER_SUPPLY_PROP_VOLTAGE_MIN || - psp == POWER_SUPPLY_PROP_CURRENT_MAX; + psp == POWER_SUPPLY_PROP_CURRENT_MAX || + psp == POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; } static enum power_supply_property axp20x_usb_power_properties[] = { @@ -334,6 +416,15 @@ static enum power_supply_property axp22x_usb_power_properties[] = { POWER_SUPPLY_PROP_CURRENT_MAX, }; +static enum power_supply_property axp813_usb_power_properties[] = { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, +}; + static const struct power_supply_desc axp20x_usb_power_desc = { .name = "axp20x-usb", .type = POWER_SUPPLY_TYPE_USB, @@ -354,6 +445,16 @@ static const struct power_supply_desc axp22x_usb_power_desc = { .set_property = axp20x_usb_power_set_property, }; +static const struct power_supply_desc axp813_usb_power_desc = { + .name = "axp20x-usb", + .type = POWER_SUPPLY_TYPE_USB, + .properties = axp813_usb_power_properties, + .num_properties = ARRAY_SIZE(axp813_usb_power_properties), + .property_is_writeable = axp20x_usb_power_prop_writeable, + .get_property = axp20x_usb_power_get_property, + .set_property = axp20x_usb_power_set_property, +}; + static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN", "VBUS_REMOVAL", @@ -394,6 +495,18 @@ static int axp813_usb_curr_lim_table[] = { 2500000, }; +static int axp_813_usb_input_curr_lim_table[] = { + 100000, + 500000, + 900000, + 1500000, + 2000000, + 2500000, + 3000000, + 3500000, + 4000000, +}; + static const struct axp_data axp192_data = { .power_desc = &axp20x_usb_power_desc, .irq_names = axp20x_irq_names, @@ -433,11 +546,14 @@ static const struct axp_data axp223_data = { }; static const struct axp_data axp813_data = { - .power_desc = &axp22x_usb_power_desc, + .power_desc = &axp813_usb_power_desc, .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .input_curr_lim_table_size = ARRAY_SIZE(axp_813_usb_input_curr_lim_table), + .input_curr_lim_table = axp_813_usb_input_curr_lim_table, + .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), .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, @@ -558,6 +674,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) platform_set_drvdata(pdev, power); + power->dev = &pdev->dev; power->axp_data = axp_data; power->regmap = axp20x->regmap; power->num_irqs = axp_data->num_irq_names; @@ -567,6 +684,12 @@ 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->input_curr_lim_fld, + &power->input_curr_lim_fld); + if (ret) + return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_valid_bit, &power->vbus_valid_bit); From patchwork Sun Jan 21 01:40:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 189785 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1878677dyb; Sat, 20 Jan 2024 17:45:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhMU6tUYTg03aZehe8UcXIC+Q4YJiYvZGQZDpnjgf7GdPNrgwK6Y8l00PXrygFjPUsyjfN X-Received: by 2002:a05:6e02:523:b0:361:9509:27b6 with SMTP id h3-20020a056e02052300b00361950927b6mr3187886ils.41.1705801513132; Sat, 20 Jan 2024 17:45:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801513; cv=pass; d=google.com; s=arc-20160816; b=Pqt6IcIjg/4zKg7ufYpc+aHW8awumP94jIy3dQavIJ977xnF9law7efFrYq1trgwBH ZNmM8mmI/n5lNbR1sAJ/uSETge6u6G3A9OPDQCMZwNYA3ojLrTDpTVmYC93wDeH4Bvz6 T7SRjWFq05Rwrs+sM3f0Qf+KMFz+uJuOnyypkOyw4SrZ9FCO5uZeTJcA2SnytF56Zeti MjckV+OprqL1S12jTtT1uFsd/TYtAnxuajUeCltV3ChajMFpxectVw292nJr/hXox/ZI Z3lvCuK6HF09lpTV6hEK7WruW3sNZNBllymj670sCL3ycLJkyG78I1RSGNhu8cliwgNo yvUQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=1Ryn10C70a9eu2vzgWK/233iIVPb5X5KUoLMJ9eT+QI=; fh=eFCTS4Ca+qpaFRwPKpEidZ8XXzB0gM774/68c0nALYA=; b=yelPtFFSIY1DfSkbgAFf8EJWUFe29vOYRmG3YzAojiyyDJY2vMGwNAoBYXWnzWhMga hOCy8wDc3XWL2E4SwszB672L5SJPlUwUH41aUKUkyPjfU3NfE3ngCUsBe+rdaDs2CyiD d+UyQUJfSkdXTYHs6Hnqp2fWRqqW5HJSzMd04H1B5QZiDn4C5P1QT6Z5Bj2MRAXiOwPW x6SEzQKJOhuH+MHmowW6E6ixuW7FY7AufKXoXvD94IAXhfMneyPd4BaVjysxkLGh5DqM gY9NX9/pY/bmOXM+IopC5UDzTWbGN7Nux6yw/ZM+yRQCIAh2DCMgKZucDf59dnHVClVS G9/g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=bY6eYvsB; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k17-20020a170902c41100b001d51f3acb68si6028949plk.280.2024.01.20.17.45.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:45:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=bY6eYvsB; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31948-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D5BD32831C0 for ; Sun, 21 Jan 2024 01:45:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D86B63529F; Sun, 21 Jan 2024 01:44:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="bY6eYvsB" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B279134180; Sun, 21 Jan 2024 01:44:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801495; cv=none; b=t28BSom9w3FvXnGJYNhwVAmCMUoQSaQzwNqfGDgdj9koJUNkR4Qs2YSXjZhq0QVorH3fT4Fto2HqcpFSJBeAVAuxIaI0ts5dBRa0tRVu5Y0w0O1K4A+0/7/qQgRcNQ4bABwl9gTsu36t7dEd8grebmmJaJdE/lAD/l7+VrsBfTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801495; c=relaxed/simple; bh=uXkUwCYq0H2JtLAC7JcuuDcFZ0QN3QO/RdNy0mw0xvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJ5HZC1zRhMtJ6gXMcB3uV70j3kusff6CKT7bE95jxzG8Nr+vROGXcbAyV/elcypHcJVr0POzT4HKZIJsT1RJKjXZ4hGpkA6/uTjaVS1gj3gU2cL92UvHfL94MFthtneg2oenfnCqaf6t6JxNQF+h/d6J9ynHH2lT+KAstlZZig= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=bY6eYvsB; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 8560743C8C; Sun, 21 Jan 2024 01:44:52 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?utf-8?q?Ond=C5=99ej_Ji?= =?utf-8?q?rman?= , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH 2/3] power: supply: axp20x_usb_power: enable usb_type reporting Date: Sat, 20 Jan 2024 20:40:02 -0500 Message-ID: <20240121014057.1042466-5-aren@peacevolution.org> In-Reply-To: <20240121014057.1042466-1-aren@peacevolution.org> References: <20240121014057.1042466-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705801493; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=1Ryn10C70a9eu2vzgWK/233iIVPb5X5KUoLMJ9eT+QI=; b=bY6eYvsBWw7PD/Q1sl8IgYA0nY9CiwfYHPli59OymCdke/XL10mFB3Nt3C5EPOg0fMfS8B TUfHmMXrWbbP0RvNqZLcvMul3Nysk4SYW9TgT+Z0JtqjCU0vEkDMvmF0BAwKrVCSGTRpDm +oiKXDRhR3D4hqOs0rh4yqn2DFxfkA8= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788662527384485114 X-GMAIL-MSGID: 1788662527384485114 Axp803 and axp813 can report the detected usb bc mode. SDP, CDP, and DCP are supported. Signed-off-by: Aren Moynihan --- drivers/power/supply/axp20x_usb_power.c | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 8c0c2c25565f..5656f6e57d54 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -57,6 +57,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 usb_bc_det_fld; struct reg_field vbus_disable_bit; bool vbus_needs_polling: 1; }; @@ -69,6 +70,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 *usb_bc_det_fld; struct regmap_field *vbus_disable_bit; struct power_supply *supply; const struct axp_data *axp_data; @@ -197,6 +199,37 @@ axp20x_usb_power_get_input_current_limit(struct axp20x_usb_power *power, return 0; } +static int axp20x_get_usb_type(struct axp20x_usb_power *power, + union power_supply_propval *val) +{ + unsigned int reg; + int ret; + + if (!power->usb_bc_det_fld) + return -EINVAL; + + ret = regmap_field_read(power->usb_bc_det_fld, ®); + if (ret) + return ret; + + switch (reg) { + case 1: + val->intval = POWER_SUPPLY_USB_TYPE_SDP; + break; + case 2: + val->intval = POWER_SUPPLY_USB_TYPE_CDP; + break; + case 3: + val->intval = POWER_SUPPLY_USB_TYPE_DCP; + break; + default: + val->intval = POWER_SUPPLY_USB_TYPE_UNKNOWN; + break; + } + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -266,6 +299,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return axp20x_usb_power_get_input_current_limit(power, &val->intval); + case POWER_SUPPLY_PROP_USB_TYPE: + return axp20x_get_usb_type(power, val); default: break; } @@ -423,6 +458,14 @@ static enum power_supply_property axp813_usb_power_properties[] = { POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_USB_TYPE, +}; + +static enum power_supply_usb_type axp813_usb_types[] = { + POWER_SUPPLY_USB_TYPE_SDP, + POWER_SUPPLY_USB_TYPE_DCP, + POWER_SUPPLY_USB_TYPE_CDP, + POWER_SUPPLY_USB_TYPE_UNKNOWN, }; static const struct power_supply_desc axp20x_usb_power_desc = { @@ -453,6 +496,8 @@ static const struct power_supply_desc axp813_usb_power_desc = { .property_is_writeable = axp20x_usb_power_prop_writeable, .get_property = axp20x_usb_power_get_property, .set_property = axp20x_usb_power_set_property, + .usb_types = axp813_usb_types, + .num_usb_types = ARRAY_SIZE(axp813_usb_types), }; static const char * const axp20x_irq_names[] = { @@ -555,6 +600,7 @@ static const struct axp_data axp813_data = { .input_curr_lim_table = axp_813_usb_input_curr_lim_table, .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), + .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_needs_polling = true, }; @@ -708,6 +754,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_det_fld, + &power->usb_bc_det_fld); + if (ret) + return ret; + ret = axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_disable_bit, &power->vbus_disable_bit); From patchwork Sun Jan 21 01:40:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 189786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1879125dyb; Sat, 20 Jan 2024 17:46:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEbkCnuZZxnpyOuinSLNANtFAWgE6+jmhHo3FXyrNUuASwMndLW9y53JFyw4qFW+77ykyX X-Received: by 2002:a05:620a:2725:b0:783:9afd:f8b6 with SMTP id b37-20020a05620a272500b007839afdf8b6mr251260qkp.37.1705801617593; Sat, 20 Jan 2024 17:46:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801617; cv=pass; d=google.com; s=arc-20160816; b=aeF14hppfJbu3QnIV1xG5vyb4Osg15o5Fa/rNIK3fhru9EMLI5K9O5/bdwv4VYQTU7 GYWMGdxlxVXHa8/Qw7HDEGt76IA4yW/gN4c0SDAhFLH8GlgnQYHD4rvH/7qdpLuE0UIS yU2frzEuYv4uD3MtUdyViPCaA5s63VIyTLhIbN4UypfN0RVMfqwQQT5NDc/ygGHf357l vluiYpVxbFAo9Z966dzmLRr0wT+dSJh6mqX+rFwI59xFjD9lIw464K0wBgSZ0ETjd7kM mDrmYTnPoex2cczSqpe0nrDCMm9Orkrv912l+zxjAq7bU8v/a1n30U4/KhJNAlntK0xR pRVw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=vMyg+vwFP4scpXStIE0uQ3xwlw79VXW+sqgg112o19M=; fh=wEdsi57ruOXwzZ0+QCfz/ydvXnF8YJmkhQf9OA42hCQ=; b=gb7GQzIq5sGZ3UOsYJ/qwK6hsvYdbqUFSU8SgFAWjnv8y4zjAejLI6REfOyBn8IDbC D9PBPvtFgZHlikXZRWRVMIZJME09XNKeARGWdha9ebaqhtYod8yVkCR2c2O1jiaQHu4t 42WSIftKVJ1066TA/F5ZuDt0Qb5HmQIqc4UHXK/epnykq5ahaHfxKUNovUQc5Zc5GnjF B8TXGREMuRRz2aS6LndekPkFZHsaP2tr6oFX/6zOX/nh+w7av3soy1HbxbllIUB/G6tG KO7BOBB1eKnRowhZRbuyQ0a5mWYsw7Rb3a/nwNqQAn0DKCooyj9FVBiZKLXyHlUNQy4t nMMg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=go2unihH; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k23-20020a05620a0b9700b0078364281171si2630872qkh.178.2024.01.20.17.46.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:46:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=go2unihH; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 64DA51C215EE for ; Sun, 21 Jan 2024 01:46:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1306F358AD; Sun, 21 Jan 2024 01:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="go2unihH" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CE0035292; Sun, 21 Jan 2024 01:46:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801600; cv=none; b=PLhNikp2n+s4i3bxBoh8636mDV7FeL9C023JBLU4g1z/AFbwEWiZ0HiOmUuRknX8sOuuqOP43+DvY2ETeMJP7LVfxUcQmTSCiw0VJ2cUafqeuzZmhsDzlFULSv7GqLZRRuc7u4f/bJ9eDbq+yGOh8zkLwpKdkAO/SOi8Sau6HnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801600; c=relaxed/simple; bh=0Qorkd0LmlFqn728SoPqMwhcM8AsRBxN+sCmP8incD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mlfblFpd5wERXzRTnX4IV/0lE610A5IS4Z/p9WqI7UUtfFwL/iNUSNSxjoBypYYjI4jfRonaHuYHrfYMj170qaSvB1hJoHFMEgPzbrsflaqOwL5LxpZPDForlSKv6esxKId1Ko9RsL/N857Tq6OtF4EFWzUJNA0LTZY2PYosqJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=go2unihH; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 43C8843C8C; Sun, 21 Jan 2024 01:46:37 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?utf-8?q?Ond=C5=99ej_Ji?= =?utf-8?q?rman?= , Aren Moynihan , Chen-Yu Tsai , Quentin Schulz , Sebastian Reichel Subject: [PATCH 3/3] power: supply: axp20x_usb_power: set input current limit in probe Date: Sat, 20 Jan 2024 20:40:04 -0500 Message-ID: <20240121014057.1042466-7-aren@peacevolution.org> In-Reply-To: <20240121014057.1042466-1-aren@peacevolution.org> References: <20240121014057.1042466-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spamd-Bar: - Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705801597; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=vMyg+vwFP4scpXStIE0uQ3xwlw79VXW+sqgg112o19M=; b=go2unihHUCDvGf2rxNqpJZFRHUG8yq9g6DqT05V4XXvHkiOAeC62icrSsw5zD6zKqgEu9p rW1cfQ9sfWZI5h2wyuFI0DSHVYyAExSRlOEJo8fP8bgHxWH+xeTIcWMsB2JqnnXdqAUZbd oX+HI1vYliv8Z4UQisDZfm487TbMvak= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788662636836747170 X-GMAIL-MSGID: 1788662636836747170 axp803 sets the current limit to 3A by default if it doesn't detect a battery. The datasheet says that reg 0x2D bit 6 is used to indicate first power on status. According to it, if that bit is 0 and the battery is not detected, it will set the input current limit to 3A, however setting that bit to 1 doesn't to prevent the pmic from setting the current limit to 3A. Fixes: c279adafe6ab ("power: supply: axp20x_usb_power: add support for AXP813") Signed-off-by: Aren Moynihan --- I'm not sure if the pmic simply ignores the first power on field, or if it needs to be set in a specific way / at a specific time. I tried setting it in arm-trusted-firmware, and the pmic still set the input current limit to 3A. The datasheet for axp813 says it has the same first power on bit, but I don't have hardware to test if it behaves the same way. This driver uses the same platform data for axp803 and axp813. drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 5656f6e57d54..95b136ee20f2 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -52,6 +52,7 @@ struct axp_data { const int *curr_lim_table; int input_curr_lim_table_size; const int *input_curr_lim_table; + int force_input_curr_lim; struct reg_field curr_lim_fld; struct reg_field input_curr_lim_fld; struct reg_field vbus_valid_bit; @@ -599,6 +600,7 @@ static const struct axp_data axp813_data = { .input_curr_lim_table_size = ARRAY_SIZE(axp_813_usb_input_curr_lim_table), .input_curr_lim_table = axp_813_usb_input_curr_lim_table, .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), + .force_input_curr_lim = 500000, .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), @@ -786,6 +788,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; } + if (power->axp_data->force_input_curr_lim) { + /* + * Certain chips set the input current limit to 3A when there is + * no battery connected. Normally the default is 500mA. + */ + ret = axp20x_usb_power_set_input_current_limit(power, + power->axp_data->force_input_curr_lim); + if (ret) + return ret; + } + if (power->usb_bc_en_bit) { /* Enable USB Battery Charging specification detection */ ret = regmap_field_write(power->usb_bc_en_bit, 1);