From patchwork Tue Jan 30 20:27:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 194317 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1483478dyb; Tue, 30 Jan 2024 12:39:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIGxPzk3oV1FwH6+1wD+29+2B8kwcVMglgYdWaKLC1GNkmNAl/rrSFsF/J3iaYezAKGFdT X-Received: by 2002:a17:902:c948:b0:1d7:617f:6dea with SMTP id i8-20020a170902c94800b001d7617f6deamr611592pla.59.1706647154732; Tue, 30 Jan 2024 12:39:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647154; cv=pass; d=google.com; s=arc-20160816; b=NHHJbBVWsmt/N21wLTk1pa1bZWq3fZdCkhzCR8t7R8uJDSw9kH93mhOO9zy/wjasHy R02KYbitzoV81yFtI+eZboEl1zCHloMQxhk4GxjnSGoroy19Rx/FNgJvHnzoGQgojclW dgG3gP4JiZtrtnM8LvKqkdzRRKQjIR98CoGnBpbrTEsJJKF+4vkDvpaCtgJW5Kfzu4VO c6+UgLNm/5OXCIZptzsjDBfeCTGY4YWoxa1bjjHzxhhrlXnYj8i36GhUoKTpu9sM1cAV AXuLcDGPfy6KVHXn6wcT1bBk/gNAYJK28cNKrvaPqR96Df2Q8aLDNmZ/9n/9RYrE3/8H dkHw== 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=ivPm1WNR8FbrvYRzWgVfDM6fYhcsm1TJs7pHZ7Ec81E=; fh=sI67x+ipElJed0sOOYzyBdcuxcM6IP/SOkMgKk0PWRk=; b=QzimqxkpLE82t8Kbgm/GZu7jo4uvIn45/wUXSPNuVMHf8F8EMfw/IuPnLzo5BRby1M oOI9iT2XAU+6N2ocqGvZcxpm+rl5GEY36/z3aejo4vLSh1/Mk3x/uySoF8UwL4i13wwg EDvZJIenhh5+iVsJWeZeD8FQGVo721DOfkAT7Ic9UotTO2vrjfCfIzP/OlsoLe8D8OVT UHmuLFu6XJYy+wFiBGNjqgb5cfThRsXrPat1SI1WrdvWRtAQmPrcmjmayNOPGfBv4kUu hAylpO4iapVc78KIFircloqdCR9eV51PHG06GF2JGtcmCdVn89fdiHPI5B9HHmLKAzQX GN3w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=peh0abvS; 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-45277-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45277-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 o20-20020a170902779400b001d750d8945dsi8042446pll.179.2024.01.30.12.39.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:39:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45277-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=peh0abvS; 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-45277-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45277-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 A985728AF14 for ; Tue, 30 Jan 2024 20:38:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 235E0762E8; Tue, 30 Jan 2024 20:37:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="peh0abvS" 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 974CC5F555; Tue, 30 Jan 2024 20:37: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=1706647075; cv=none; b=XCoWMkl/v4hm3SdymA+GstQweqwlmVP3USp0Ni2LRMWtWo1sPbC7AG/2GPMLRK30WSinMjuUC6c3YTecj9y944axtPpa5wLwycHnhlAXgwthsiF9+gHmQG8DAaOEBkMV55GqZuN+uRuOJHs3LLNBP2XqBamxmBHUPhrd3ag3iZE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647075; c=relaxed/simple; bh=GIUIG7+EEVMTtkYD8ypmqtjqn29llrcgXCn39fpUmBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LCcwests+099a+gZUoptKTeQwDFgrHvaNT3jjzHer1Ttj+e/V9JBlrvoKOCgWMwS8YFGZ/yiqvWmZvqqUO7Jrq5I4Ob6vfr8ClTcaEUnNhnp6cMK6K06oE/K5+a/JzPib2ZjAbTcGuPxECPT/alIw1kU9T9L+Y0tnrGzWGmtlxY= 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=peh0abvS; 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 5F6304661E; Tue, 30 Jan 2024 20:37:52 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ond=C5=99ej_Jirman?= , Hans de Goede , Aidan MacDonald , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH v2 2/5] power: supply: axp20x_usb_power: use correct register for input current limit Date: Tue, 30 Jan 2024 15:27:58 -0500 Message-ID: <20240130203714.3020464-3-aren@peacevolution.org> In-Reply-To: <20240130203714.3020464-1-aren@peacevolution.org> References: <20240130203714.3020464-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=1706647072; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=ivPm1WNR8FbrvYRzWgVfDM6fYhcsm1TJs7pHZ7Ec81E=; b=peh0abvSNH8vlLhCN6FjDCVIefhI1lavzA6yZ4ePRVf9uszqJQl7pvbQas7VjPk5ltE059 H8xonDx9V+IngLtipZw7Wa0I/Sg/CThpmn/REyWvz4ZO1WjXMNaR9Vh2jYfcT2wg4ky8rk kkW4T9Lxmb5VrFDjvmmhqu1SPF3Tsis= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549246898056572 X-GMAIL-MSGID: 1789549246898056572 On the axp803 and axp813 chips register 0x30 bits 0-1 is the default current limit that gets applied after the pmic detects a CDP or DCP port. The correct field to set is 0x35 bits 4-7. This field only has nine values (out of the 16 possible if it used all the bits), so introduce a field size variable to take that into account. Signed-off-by: Aren Moynihan --- Changes in v2: - Inline get input current logic. It's not that complicated and this helps to illustrate what changed more clearly. - Split into separate commit, it was part of adding the input current limit before. drivers/power/supply/axp20x_usb_power.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index f7f2ac2b7dae..923121b23d5f 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -50,6 +50,7 @@ struct axp_data { const char * const *irq_names; unsigned int num_irq_names; const int *curr_lim_table; + int curr_lim_table_size; struct reg_field curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; @@ -166,7 +167,11 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, if (ret) return ret; - val->intval = power->axp_data->curr_lim_table[v]; + if (v < power->axp_data->curr_lim_table_size) + val->intval = power->axp_data->curr_lim_table[v]; + else + val->intval = power->axp_data->curr_lim_table[ + power->axp_data->curr_lim_table_size - 1]; return 0; case POWER_SUPPLY_PROP_CURRENT_NOW: if (IS_ENABLED(CONFIG_AXP20X_ADC)) { @@ -261,8 +266,7 @@ static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *pow int intval) { unsigned int reg; - const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, - power->axp_data->curr_lim_fld.lsb); + const unsigned int max = power->axp_data->curr_lim_table_size; if (intval == -1) return -EINVAL; @@ -394,10 +398,15 @@ static int axp221_usb_curr_lim_table[] = { }; static int axp813_usb_curr_lim_table[] = { + 100000, + 500000, 900000, 1500000, 2000000, 2500000, + 3000000, + 3500000, + 4000000, }; static const struct axp_data axp192_data = { @@ -405,6 +414,7 @@ static const struct axp_data axp192_data = { .irq_names = axp20x_irq_names, .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .curr_lim_table = axp192_usb_curr_lim_table, + .curr_lim_table_size = ARRAY_SIZE(axp192_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_valid_bit = REG_FIELD(AXP192_USB_OTG_STATUS, 2, 2), .vbus_mon_bit = REG_FIELD(AXP20X_VBUS_MON, 3, 3), @@ -415,6 +425,7 @@ static const struct axp_data axp202_data = { .irq_names = axp20x_irq_names, .num_irq_names = ARRAY_SIZE(axp20x_irq_names), .curr_lim_table = axp20x_usb_curr_lim_table, + .curr_lim_table_size = ARRAY_SIZE(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), @@ -425,6 +436,7 @@ static const struct axp_data axp221_data = { .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .curr_lim_table = axp221_usb_curr_lim_table, + .curr_lim_table_size = ARRAY_SIZE(axp221_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_needs_polling = true, }; @@ -434,6 +446,7 @@ static const struct axp_data axp223_data = { .irq_names = axp22x_irq_names, .num_irq_names = ARRAY_SIZE(axp22x_irq_names), .curr_lim_table = axp20x_usb_curr_lim_table, + .curr_lim_table_size = ARRAY_SIZE(axp20x_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), .vbus_needs_polling = true, }; @@ -443,7 +456,8 @@ static const struct axp_data axp813_data = { .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), + .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), + .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,