Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1255507rdb; Tue, 30 Jan 2024 12:39:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEm1oil8Xnj2SxZxEHRdhdLo/mRzhN+YrC55pXmd6iL1X6k6MPs+h2Jj+HgUHeh1ZeNSrfd X-Received: by 2002:a05:6a20:3184:b0:19c:b0a4:16fa with SMTP id x4-20020a056a20318400b0019cb0a416famr2317537pza.12.1706647159816; Tue, 30 Jan 2024 12:39:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647159; cv=pass; d=google.com; s=arc-20160816; b=W/E2oupfc4uxyyB+2wpqYpAN24eJ/FXkZvJDcJzYBYe+bJJmKxmfs8kT32GOtkZSO4 fybKiRu9hSvGoOGDlqF5YzFu9csdd3SGuQL4wmtTwbxL85Er0vH6pDJ+dxH9woA2XjCs uJj7sb2Nu2IO8SD/C0PZ2W6ofG7Z53MYtVB4HYDKDDTfjaU68Q0suzlS24/yT6VoU52M ZxX47QkescPtAOO/+gnZQiEiT3lURynh181y1RqN1DVAg7uzThAyvXaDd/9nnTF+1+pL w73wCSNQNgszShfZVjND9Be+qcSkkdUUkLSpqfFIL+3176aladfW1CDfdOxFIrzIgSuZ EB0Q== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45278-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bo11-20020a056a02038b00b005d14ca08256si8326347pgb.819.2024.01.30.12.39.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:39:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45278-linux.lists.archive=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="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-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45278-linux.lists.archive=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 4696328B1AF for ; Tue, 30 Jan 2024 20:38:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2467B762E4; Tue, 30 Jan 2024 20:38:00 +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=20Jirman?= , 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 Content-Transfer-Encoding: 8bit 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= 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; -- 2.43.0