From patchwork Tue Jan 30 20:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 194316 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1483076dyb; Tue, 30 Jan 2024 12:38:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCOIpYFoEtuMaI0ocvuSsWtb0SmShRLyIkaHn2Z1QMjtAjMTr05Aj0I1nr5x5PWySu5P4m X-Received: by 2002:a17:906:3c5b:b0:a31:818d:4927 with SMTP id i27-20020a1709063c5b00b00a31818d4927mr6870771ejg.42.1706647095905; Tue, 30 Jan 2024 12:38:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647095; cv=pass; d=google.com; s=arc-20160816; b=ylsCpJADsV0FM3uQ1mz4G1piV1UUyGvlNVYE+kur7lbF5YAZG1GAmJyqbi0Iqrs4bg vGMu0s0DZ6WJjp5Yb5D58pP/hcuA59aB1+MjoNKQKL+nhfgvlekW+PgyN80f+91xBgf/ rpSPHjPQvJVPuK1xynMdBzbVNFLPAjs82cw2LsIMsb1yAjUw97YzpC/uiljlEaJxV+Xa RQeP/dXwpqklsYhHWE/x5XN0e7CCocGKapr4rsvlvbS1lQCiJhdY9sGAxHkINQgzT+0s eWx9GMVFmz3mYxHHtSqsd65CM4Su4+KDAMW5rrhpDzVzLkpDllr3u8UKsGVKsAMXE61N 8Yyw== 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=NAxGv9qMri1hf0JDQHUznnkmw1bSeEqz6JkBTbreKjQ=; fh=sI67x+ipElJed0sOOYzyBdcuxcM6IP/SOkMgKk0PWRk=; b=BLThefOTtDN+JutiCbkSIE+V95ffK0nQ9XI11ac16+Kyth4t8/Jyr9cCI59X9e6sM3 ITK/QN0KXfft8GO1WleuMtc5Ufl0Zp9OegOoyuw5Jz5Bv3dqoFcLVNWiosruaf5y9ekE ulwLNnBiErpoDqG7JtZSODnoCNvbb//GVUYQgQN7XunajI3y0wCmgdnjfyq33Mmplrlr qkUeUR5eIe/tPXtBZ6ULkYQongdo5tScF1NXPrFNbnt7KhdmD6d/8BLjUvPA5E1ul9yP +0VZB124e5Twv1SM0sMLP/acGyPHNSCTsJirXdcUp+3f9+OzaGdum9il2EhFLyRe5Hit Fa6w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=OLUhxc3O; 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-45276-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45276-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 a16-20020a17090680d000b00a352eafa349si3974945ejx.111.2024.01.30.12.38.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:38:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45276-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=OLUhxc3O; 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-45276-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45276-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 5D7141F24D2F for ; Tue, 30 Jan 2024 20:38:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4A83A5B1F6; Tue, 30 Jan 2024 20:37:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="OLUhxc3O" 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 9D44571B2C; Tue, 30 Jan 2024 20:37:45 +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=1706647067; cv=none; b=KPwGgNcAmFQe5Sv6cqlwoT+6HKftMvx7/MF5K5f48gwuVvu4z5xpprTZpsScjvr8QFslJd1snirSR3X5ilOcDSqnqpBj800J+Kx1hZ6+1LNAFcB8mjRTjNffZ12QpxALpisV99aSO2N/iueOdsbiBzjiZNiQrryon05myHsgdvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647067; c=relaxed/simple; bh=s8gDv1BRbZ4lq/K0LWRSztHuSeHvlnMI3UYO7zLzfo8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=daD2+zszvr250mvjYAc8mCM0MNIZZkbcAYKo3WVJyMEN4LDkiVKZeFb3CmD2L7FjL/m+TeEd6z47bPkq9On8HYI3YNH0rFNeZ2ecYrimSo3Arakh2/3wEqA8tKyQbM7LvZb4tWKt/OYRP3g8T2O2Tsym1XyAlT5Hj0jU0HoPlAU= 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=OLUhxc3O; 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 B03E14661E; Tue, 30 Jan 2024 20:37:43 +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 1/5] power: supply: axp20x_usb_power: replace current_max with input_current_limit Date: Tue, 30 Jan 2024 15:27:57 -0500 Message-ID: <20240130203714.3020464-2-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=1706647064; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=NAxGv9qMri1hf0JDQHUznnkmw1bSeEqz6JkBTbreKjQ=; b=OLUhxc3OTR3e4qs7eMABcduOJHq7KXwvnRR8iPxFsdEXZ4NX+B1gzVzDk2Qqm2xp9fdlzO MJUTRvNGYohFGLGU8kTiMzEcsVg5V3imJotjTz++QWNpa2xHRoSrqb2UxC4ns2B1zJ5mBu LieV+Y1RT8VDeszaAEmhY+rH2caESaI= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549185430172837 X-GMAIL-MSGID: 1789549185430172837 The current_max property is supposed to be read-only, and represent the maximum current the supply can provide. input_current_limit is the limit that is currently set, which is what we have here. When determining what value to write to the register, we need to pick a reasonable value if the requested limit doesn't exactly match one supported by the hardware. If the requested limit is less than the lowest value we can set, round up to the lowest value. Otherwise round down to the nearest value supported by hardware. 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 --- Changes in v2: - Values less than the lowest supported limit are rounded up instead of returning -EINVAL when setting the input current limit. drivers/power/supply/axp20x_usb_power.c | 29 +++++++++++++++---------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index e23308ad4cc7..f7f2ac2b7dae 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -59,6 +59,7 @@ struct axp_data { }; struct axp20x_usb_power { + struct device *dev; struct regmap *regmap; struct regmap_field *curr_lim_fld; struct regmap_field *vbus_valid_bit; @@ -160,7 +161,7 @@ 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: + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: ret = regmap_field_read(power->curr_lim_fld, &v); if (ret) return ret; @@ -256,19 +257,24 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, return -EINVAL; } -static int axp20x_usb_power_set_current_max(struct axp20x_usb_power *power, int intval) +static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, + int intval) { + unsigned int reg; const unsigned int max = GENMASK(power->axp_data->curr_lim_fld.msb, power->axp_data->curr_lim_fld.lsb); if (intval == -1) 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); + for (reg = max - 1; reg > 0; reg--) + if (power->axp_data->curr_lim_table[reg] <= intval) + break; - return -EINVAL; + dev_dbg(power->dev, "setting input current limit reg to %d (%d uA), requested %d uA", + reg, power->axp_data->curr_lim_table[reg], intval); + + return regmap_field_write(power->curr_lim_fld, reg); } static int axp20x_usb_power_set_property(struct power_supply *psy, @@ -287,8 +293,8 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, case POWER_SUPPLY_PROP_VOLTAGE_MIN: return axp20x_usb_power_set_voltage_min(power, val->intval); - 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 +319,7 @@ 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_INPUT_CURRENT_LIMIT; } static enum power_supply_property axp20x_usb_power_properties[] = { @@ -322,7 +328,7 @@ static enum power_supply_property axp20x_usb_power_properties[] = { POWER_SUPPLY_PROP_ONLINE, POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_VOLTAGE_NOW, - POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, POWER_SUPPLY_PROP_CURRENT_NOW, }; @@ -331,7 +337,7 @@ static enum power_supply_property axp22x_usb_power_properties[] = { 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 = { @@ -558,6 +564,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; 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, From patchwork Tue Jan 30 20:27:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 194318 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1484069dyb; Tue, 30 Jan 2024 12:40:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDnvOpNhWFIXam54tiz2D/TFFRV1zSI0h/wiXj2BNoTHOYbJy5aWI27TYoTm76USfLhe5M X-Received: by 2002:a17:90a:b015:b0:290:f821:8e5c with SMTP id x21-20020a17090ab01500b00290f8218e5cmr2650599pjq.38.1706647234579; Tue, 30 Jan 2024 12:40:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647234; cv=pass; d=google.com; s=arc-20160816; b=GL8tEJVY2j/bYERaTy0OXyvldZgOu5WCFrpXNAvmGjwd2sVOLbw01ss5K8zoHLljI9 NCI11vePO6adtfE6Ckt4OKP2unH5v14qjiwqg/zM6BouBgn/zHZtiknjJFnxV+Qa79rZ JiUgRUsY0Vs3zRpOVoz1WcB22G/2iw+0sfr/y8bT/zZjiNebdEnLMubC5xvA1/Fz27lm SCe8RWZsUlCkqScVk5t+SXnd7LxSf4SBPZTNzzqhVq5x+XVN1LbJi7dpdDiDYWCny6Uq CbAfAel2GqHsrTxraFO9fvwsWBKw+vSjoSuXlKjUQ02TzeIrkDqIVF5VckDvRLqssgPW k8Ug== 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=Qh62TYzJLJF3IVftKmbgHbTDldqXGopKOhOQHQ3kQso=; fh=sI67x+ipElJed0sOOYzyBdcuxcM6IP/SOkMgKk0PWRk=; b=GziHPk4I4M8ukpaeK5SJty7NAJdQ5tR2QdNz6iX2DKILgpF1IJRPQH4OM9zr9KLs75 582kQI17CtXK4GaWwVcgfpspeCSiPTP90IwxxdU7UTOQwl4PtucS0Ke9t3w+g6sRClSa ksfCUN0tTw8YqbNbYO7jcpstQXYVsLdvhJtSw0aBUuknIYiy2J0DcFwmTILz++5wbusG vP3f6MPaD92K5GqTajPaVUGfB5TNc57A7DOSavk95ytJcwR5nJsxozoJJVHxXl1iCPN/ a2iaP87nraUV2SaroMk+CrjsKaFuR9kRW9O16Azjm/k4tFAnIfEU3+5Yt4aj3tthdpFT Wx4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="U+/RvjVy"; 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-45278-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45278-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s3-20020a17090a5d0300b0028e88453568si10004999pji.161.2024.01.30.12.40.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:40:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45278-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="U+/RvjVy"; 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-45278-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45278-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 910C2B26890 for ; Tue, 30 Jan 2024 20:38:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 04F2971B53; Tue, 30 Jan 2024 20:38:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="U+/RvjVy" 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 B4285762E3; Tue, 30 Jan 2024 20:37:57 +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=1706647079; cv=none; b=n1khRLRVbXefZss6W3M2X+9hVg7im29sO8OxHw8MGCZD/JmT3upED5G/Xr5G95oC2dOAnbgU2LZ0+zOESbuiM3Yt82H40cxhHuMbqD4i6e6Rb4zmqzyGwZL9AZ4rz+HSK7TtzpvML8mGQMw2pomkBwqtyLPNJZMzjejql58LvQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647079; c=relaxed/simple; bh=5wkPN+b1GbrWti66iOp/WvMt1+CJTyRFqQ9LVlL8Vbg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mL4UoaMK/V/TOEhNuLQsHOES8E70IFGSugX71ObtZ7gI+mXroIjCdt6Eu3X8ExEgikDWjYibZ2oYmeNn0JxNFkU6+YfayDvSTWm+dxpSBAYJQrc2+YrJSMlI1Yjsa7fhZIamYa/7My8sFZMc3vScxjpQvK1NaizjsEYjm4ulVws= 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=U+/RvjVy; 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 34C324661E; Tue, 30 Jan 2024 20:37:56 +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 3/5] power: supply: axp20x_usb_power: fix race condition with usb bc Date: Tue, 30 Jan 2024 15:27:59 -0500 Message-ID: <20240130203714.3020464-4-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=1706647076; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=Qh62TYzJLJF3IVftKmbgHbTDldqXGopKOhOQHQ3kQso=; b=U+/RvjVyLg9rgo6Oo3xomEgxwmZY4yPcXiiG5NSEHVPEGGvkIh7KC08MSXFRMuYPUBjLfm pAbKcOHABZ0sew05lCJqlptrUvklUCjBX/HtAA1DkoLGoEzcJUlH1IZggCEbQh//6TIo06 gB9uo4oy3n2R9pYmuiNPvWBQ1SL2eGA= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549330748428998 X-GMAIL-MSGID: 1789549330748428998 When input_current_limit is set while USB BC is in progress, the BC module will overwrite the value that was set when it finishes detection. Signed-off-by: Aren Moynihan --- Changes in v2: - Split into sepereate commit, it was part of addig the input current limit before. drivers/power/supply/axp20x_usb_power.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 923121b23d5f..ac5a3f126df6 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -117,6 +117,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; @@ -265,12 +274,26 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, static int axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, int intval) { + int ret; unsigned int reg; const unsigned int max = power->axp_data->curr_lim_table_size; if (intval == -1) 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 = max - 1; reg > 0; reg--) if (power->axp_data->curr_lim_table[reg] <= intval) break; From patchwork Tue Jan 30 20:28:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 194319 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1484212dyb; Tue, 30 Jan 2024 12:40:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IFPROpomSdD52oluiz44S7+CBUGvvsO2Ml8nM4v8FPEEq3Th6hEFRycppHx2sIiK5n56ZY2 X-Received: by 2002:aa7:98c3:0:b0:6da:c7ce:ef53 with SMTP id e3-20020aa798c3000000b006dac7ceef53mr7605669pfm.3.1706647252394; Tue, 30 Jan 2024 12:40:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647252; cv=pass; d=google.com; s=arc-20160816; b=S2QMTtWmvyDkkHAid5Li0meugC8hErG0DHCRFou7qlvuPNuQ1Jf71+BJWODnsh7iBF dyE3S+ta5f96UKueW2CWWbl+PvTg0Fd/EXbUKLPXs7bj5uRlq90UhLT9rTgKMjwDg6C9 nHV2Ouww6JOKUWHoFM1V6cu/rrbyrgGGaqrIrcA+DpB7Q04rLcIfv2jy7rIaiYunrjeQ LEP4KMH+AUVOQpLt4okYYzK/nGVUT0B4bRIG/LAiV/tIql9kHtk6du6eIHcGJ6n/l1Xn 3gyAapUfsOR2lnE4J0UoYKqaDW/eRkP2KVwxK/9nndYMlc1s7NRxEU+ZG0DrXXV+9xE5 YeZg== 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=6G0YmOD50/3sb0eb05V/Ra/p+656o7Ad1EWSfIxoCZI=; fh=sI67x+ipElJed0sOOYzyBdcuxcM6IP/SOkMgKk0PWRk=; b=hUaXUip7HVGdi+C1JIAYxoeQpHH/4lEry8C+m3CRexV5iUCQI9FGjfwWiKJYE2Tcyz o6dVocV6qWX8zKMiXhu/dc69lxmf1jMoLYvLlp4deSZ1/7KR7e9dV4vRLBYoolc0Wku3 QHlr12/0aeE3DmGoOXtE+r3OnOVu16Z/ECVwLGP8oiLLAWn7Es4KVBF2XkdRNWqFDdVl 7nM1aqyHJHqAIGCGugE8KIy2o6fsRCXs1DYzfedvWDrt3m1pCs55g6iW+iuXqzGS+glt wDgsIsxbXcIa+4DF1oQ5fsj9snSx3IL3kC5bZU9iTF/gqWDEFOyjEZ6k8+U8kgCMSiJT DOZg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=RdZPi4ul; 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-45279-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45279-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id d3-20020a056a00198300b006dddf873cf0si7960297pfl.336.2024.01.30.12.40.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:40:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45279-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=RdZPi4ul; 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-45279-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45279-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 259B7B21692 for ; Tue, 30 Jan 2024 20:39:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 61B9E78B73; Tue, 30 Jan 2024 20:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="RdZPi4ul" 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 BEA02762EE; Tue, 30 Jan 2024 20:38:00 +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=1706647082; cv=none; b=Q0NP8BhjHThBBxFGE0scZv6Qkf1JKb0rn2XOSL9jCXgKb8rQ0tOEwyJpTrU8lHbwcFMLwxLf+h1mo+0QLiGuj07VeRs63RWtZCG2e/CncHW+xFDeFTr9x0abC7zgnh1w5pWLY9gty7BzeOFiABwA5dk/nYU56cdD5V4Mr72/paM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647082; c=relaxed/simple; bh=zXXGsJFbgiYzogwaULyPk2kphg0Ch0Uphvq2gjdcWj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hAmqZXpsxL3Ei1wKw9b0staiwk6HVozx6Sm6XHA07Z7DeYgjC7KQ+T/rzXiYxI4uhkWQDAQgNwUrOgNYA+1xL3OHC+8/JEWaWxUsriOzn0pjk3+JfQeGCqyuKISa7u1tK+AMmP4BF/d5yXKnOnRGKD7KTOiFtNhqudlp5SlPecs= 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=RdZPi4ul; 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 2EA8046B74; Tue, 30 Jan 2024 20:37:59 +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 4/5] power: supply: axp20x_usb_power: enable usb_type reporting Date: Tue, 30 Jan 2024 15:28:00 -0500 Message-ID: <20240130203714.3020464-5-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=1706647079; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=6G0YmOD50/3sb0eb05V/Ra/p+656o7Ad1EWSfIxoCZI=; b=RdZPi4ul39i/V1pJazsVpkPeFOvR3+beShpiRU91OnRSd+nbRXbU2OYXRw/0MrUjD5TZ9+ Qk6gvexMDXB+HIAp73g+/9Zsll64rkCaDMYD60kWRN8MkMorrj9J7sJj1ktlveT36DRvZ+ VbgZPODoGJrA9lrmOvGmfjBzPvT6Hos= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549349048813558 X-GMAIL-MSGID: 1789549349048813558 The axp803 and axp813 chips can report the detected USB BC mode. SDP, CDP, and DCP are supported. Signed-off-by: Aren Moynihan --- (no changes since v1) drivers/power/supply/axp20x_usb_power.c | 73 ++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index ac5a3f126df6..dae7e5cfc54e 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -55,6 +55,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; }; @@ -66,6 +67,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; @@ -134,6 +136,37 @@ 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_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) { @@ -204,6 +237,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_USB_TYPE: + return axp20x_get_usb_type(power, val); default: break; } @@ -367,6 +403,22 @@ static enum power_supply_property axp22x_usb_power_properties[] = { POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, }; +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_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 = { .name = "axp20x-usb", .type = POWER_SUPPLY_TYPE_USB, @@ -387,6 +439,18 @@ 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, + .usb_types = axp813_usb_types, + .num_usb_types = ARRAY_SIZE(axp813_usb_types), +}; + static const char * const axp20x_irq_names[] = { "VBUS_PLUGIN", "VBUS_REMOVAL", @@ -475,13 +539,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_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), + .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, }; @@ -629,6 +694,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 Tue Jan 30 20:28:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aren X-Patchwork-Id: 194320 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1484330dyb; Tue, 30 Jan 2024 12:41:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhwOvDD/AbLN+e2OjwonDoa0TCrW8pEHs9lIXxzlCgDa6+sRWKeyImECFYOZthAwOF6gm7 X-Received: by 2002:a05:6a20:9c8b:b0:19c:b19d:547a with SMTP id mj11-20020a056a209c8b00b0019cb19d547amr5702126pzb.33.1706647268892; Tue, 30 Jan 2024 12:41:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647268; cv=pass; d=google.com; s=arc-20160816; b=n3/VQXDFIoBT+xGN/8R0Xlw2KaJwBeVw2vtK4rJ+uzfCL7b7gI1vWV1rUj9HjHK4vp lH6xJSy5ND/GWAHBzAjrppfZQsHE1cLxvV3DTTpNecuSgzyZeOfRIdLXROPML45rE/Y+ bXmvo47z9P8Susnsy6wf3kSXXy9w06T7lpC4nkLnpTEhb08qphOuhlY/GE0XqULiLFth O6S3k5AORaJQAsV0l7aSehPeizsKWbTHocaOFyplx2zKFLiesffSOdz9/KUFyYNx1czp 5X2dBzZOjvwD/MX8KR3ArC/Ed9LIbD0D4PXa0URF3yU/Jjs+n1AwLZvcb3fwqdro10Mm rcXw== 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=eZlM22aJvF3MR5EwxjV3X6ckVSfAYjgJvEHp2kxoO6k=; fh=CS8UjFWQd4C89aVAWtaFYgKrfPFQKsOq4yc2cb5p77k=; b=KQsiGqsvCw6Oh9m7EFm9/3gZX6t98o22HtLpvmfN0hWoJfCasHcybUgTjR3B3OZxpS TkOs5klGkGs+wDwIjZEwwBy3FYS7ropgf3XTlFwM9OT8uJFi3MkXUmm+yFDQMEhRNGKI TKmHiMqy/3Z1P71fQdhC8jmySh39ZB0j+DyUcYLMJfU7AHSrglsFJ4jNXWISJzyE7H7v zgA6917LWeuFteU+gqf2GpbanaYui5ROTqV+c8zLU+pd5J/3Hf53z7ZLrKTUl6MAPCHp N0UwmJwsuLOF5CgZKRva6QU5drFPpn1BCwPRiFay7Vg+v+cTEhR4IrUIMnb4MfvptLfd YjUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="M/8nUGKs"; 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-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m17-20020a056a00081100b006d9a6f39e36si8102698pfk.252.2024.01.30.12.41.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:41:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="M/8nUGKs"; 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-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45280-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id CBB1BB24886 for ; Tue, 30 Jan 2024 20:39:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D45BC79941; Tue, 30 Jan 2024 20:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="M/8nUGKs" 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 8F6AB78B7B; Tue, 30 Jan 2024 20:38:05 +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=1706647087; cv=none; b=Tvbyb7xDcMU+d9gtm190sWumB/wGJ6JHwTV851UDbs02EHAa/Zg2bHFfoY8FomvydBnL4qeX+/sTQ9bycLKLlp5xk5M366IpDXbG841Q1i7TSUJ7w2eo7COUplMMCqwX+37nmXdrRV+RHoZIsvV5j1dVYbEiflbeyXGnmp+k4+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647087; c=relaxed/simple; bh=ItXbRSSuRULGHehgAkFOPt/p0MSJUvWQ3KbcLpvFS5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F7pkK2zK2fS251z62x+ZlkNlbQpr/vdbrqmktPSRtedBZs1aFKgdnGVOsHGXt15m3nm0TCYTusrq/d+YEFFP+mmg4J0TrTMutW3IG//EWjvOlyMR+uMDHWwPIhBlOj0JUrfccdJFINIPv4QpzBP9+5LpqUWuDa5DyuBhhtoh4PM= 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=M/8nUGKs; 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 D42EA4661E; Tue, 30 Jan 2024 20:38:03 +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 , Quentin Schulz , Sebastian Reichel Subject: [PATCH v2 5/5] power: supply: axp20x_usb_power: set input current limit in probe Date: Tue, 30 Jan 2024 15:28:01 -0500 Message-ID: <20240130203714.3020464-6-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 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=1706647084; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=eZlM22aJvF3MR5EwxjV3X6ckVSfAYjgJvEHp2kxoO6k=; b=M/8nUGKsclChSRKnGxLzS4IoO1E9Nt8BRog8y+x/fzhn6ORnN4xP84cIDZ4K93ex/n0XjY sD0Rk0yEGcDFyekb7xdkqxCLD6MFP4pqDTHf/vJ+e919wrUuYmGdFDYTggTOVkjv4d5JsR fizhJ0M8fVYbAy4RwiCrGadYlLng8SQ= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549366960032685 X-GMAIL-MSGID: 1789549366960032685 axp803 sets the current limit to 3A by default if it doesn't detect a battery. The datasheet says that register 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. Waiting for USB BC detection doesn't work either, because (as far as I can tell) USB BC detection isn't performed when there isn't a battery detected. 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. (no changes since v1) 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 dae7e5cfc54e..751b9f02d36f 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -51,6 +51,7 @@ struct axp_data { unsigned int num_irq_names; const int *curr_lim_table; int curr_lim_table_size; + int force_curr_lim; struct reg_field curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; @@ -545,6 +546,7 @@ static const struct axp_data axp813_data = { .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), + .force_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), @@ -726,6 +728,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; } + if (power->axp_data->force_curr_lim) { + /* + * Some 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_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);