Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp323512lqo; Wed, 15 May 2024 16:16:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVK90WlxadoJB3lIjuvBi27bzU1MZJH+fMQRJiCs0zbOURpA5pVU1Mo9F4VA2DgHJORWe3S5VgOEH1lreDQ944pZxevC2qexwtibmfUrg== X-Google-Smtp-Source: AGHT+IE0Txli/VFW8omr5mD2R23O/uhapAew87+2VeoEZyk3XiRAEXoqWe5DDtOEsSkSx4UVgTZl X-Received: by 2002:a5b:1c2:0:b0:df4:736f:263b with SMTP id 3f1490d57ef6-df4736f2f0cmr4320276.37.1715814989668; Wed, 15 May 2024 16:16:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715814989; cv=pass; d=google.com; s=arc-20160816; b=G/pkFvIdysfXUXC+IsDQ9+8NB/eGFmFVc54D2xi7hsDsOES00UDqALeF7EWAXLgeps 4BdJmdhFxNkye04coEsyRWNlvYkxRbN0cwivVTnr/HXKTQ7ZjdnSX86C2C8Tuv1MiIS7 ko36Abq5pVcXXP0NgM7hDW6bVTaP2EoYa73seoBLaObAb5mzFFXWjonZa7w62p+j2OR/ esVx/gJ4mdDI/VX3jH4QFYkt/WkEZp7FybHqxT9Zrm716aT45p6P+McLnPH+hrbuZx6e zUYv6wnAmjiLCiGa5fwvVQfa3lO8POV3HP/BGfrTAQVGAaLj6BMtGfSAynDycuFHbcJ2 Kefg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=2gZhkoZh+996W2MlO/z0y0kus/aLno+FBdFhG28ujRw=; fh=VRNXYmEw8ijHq57lb75JmdkpiLKcAiJpCv/M/3yoTDY=; b=XfC9KRqVpWUfENrsoUz3nk/pdipifYIDYmn4XaxkxUdkxyx2gfLtwcvTbq1FsKjWWI fT0w+aOLfMdVIiK1vGf4+DE47EWGKXdAUl7eRb2SSBt1BBXyToQu1ag4ybnavG8NNQbS tvnjfqFXd+2iY9WpaxLiXwXQ6XXNIhziknGcT39B93afyN1cHk279Xt0ZC4rcw99McVr 2FZ0YTDzIazsnti6zzqVEXrd8WnfIpw/Ijh2/8ktqSXMXodsGtXG6KvvbUI83ednkT+q /wIbLu/dwrn9IYp7rgO4x3MWLEt1AqnDUcSUE2YuPwYC6I/7ALDUole2FKynQCciBmCD Sk2w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6a15f307885si156338036d6.582.2024.05.15.16.16.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:16:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180477-linux.lists.archive=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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-180477-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180477-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 4DC721C21F5B for ; Wed, 15 May 2024 23:16:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C476E15CD47; Wed, 15 May 2024 23:15:41 +0000 (UTC) Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9ECD15B97E; Wed, 15 May 2024 23:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814941; cv=none; b=aAnGzowI+pmYjcHa8tBLmQDfuRHhYDweh4Aa/zSrAZn0VBFxAH/GpqUKKDkerCisUa5e0JrBJyNECzboBVJGmoNcN13tsuEPgBmw03VY4qkk45wzQ+7C6yfAFnVp1UC1DHl2cD+2uls1BN3TqYnoNfsre/oK9V7tq9qBAwuXs2Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814941; c=relaxed/simple; bh=J8svAqNhHH545H/TdjwK4kk3WFNcNp93EwVHK7qP0ko=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ezRx2R+bi7rnOWX46DXbTYae/oZQ1Thd5jq236aNOYgOOh/Q/7AvX+29TNTdRkMATN15u7n06C3HKPEONrL6HquRHIB2zB5OhVYFB3jM9V78IssD35t6n0uTp998Mw2cWSxZNzXRcafKouLzbqaeNQIor6tnnFLuQlO/E27vJ44= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-6f0e6a32754so18760a34.0; Wed, 15 May 2024 16:15:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814939; x=1716419739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2gZhkoZh+996W2MlO/z0y0kus/aLno+FBdFhG28ujRw=; b=sIAK6EBoPk3H0Tqz9qoQb9F13HX+HHApmwLL5JvMU00+KrbIhlQXKC8RzCVTgLZ8MK g93XmmPtaiOORc0MTx1akSTia01fQoV5Y3fplKouzh17+C5XLe3Gp0LmbyQuOQtw/kqZ RKejCxTj9i++b8c+x4mzrXMfOnTUswr7bT00rMLV/9kGoE9FVbepgPQAVfPF5wPxOZ0s we7TUFlmAfSYtuhtsZdO/IUyCA0YVxMX4A0A0j2veFTipRe6s5OPaRV5n5Rz4FgnFIQ8 IqmEXDTeZzn307bnTm6zgrMDfMX+tfcVj2/7y7UA9c8BzZwhLCdYcHFaFyg52iTPLORt Xu+w== X-Forwarded-Encrypted: i=1; AJvYcCVMsnNz97/vZ0zA/GcOtnEbD/Sxw1e3il9iJi3vWN3nGTPREqILgeZvlAdtoM1OCLAjsIaEwFtQOFInQGFUqAPkv7/sTi8JeCc2ical X-Gm-Message-State: AOJu0YyTDmwvsoU9oMJHrtlFUoym4gMq7d97wke0cs1aX4aQOGT/bX1+ 6+OivHui6EzD5TI0oaJxgGGOVSeQfQF5ih/5Wm+cHWH9GJJ37hea X-Received: by 2002:a9d:400c:0:b0:6f0:52fb:c693 with SMTP id 46e09a7af769-6f0e90f24camr18546313a34.1.1715814938820; Wed, 15 May 2024 16:15:38 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f0ec2e566dsm2032159a34.15.2024.05.15.16.15.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:37 -0700 (PDT) From: sean.wang@kernel.org To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Hao Qin , Sean Wang , Chris Lu Subject: [PATCH v5 4/5] Bluetooth: btusb: mediatek: reset the controller before downloading the fw Date: Wed, 15 May 2024 16:15:20 -0700 Message-Id: <38805679fd6abf8fec46224fa8edb81152adb6dc.1715813148.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Hao Qin Reset the controller before downloading the firmware to improve its reliability. This includes situations like cold or warm reboots, ensuring the controller is in its initial state before starting the firmware download. Co-developed-by: Sean Wang Signed-off-by: Sean Wang Co-developed-by: Chris Lu Signed-off-by: Chris Lu Signed-off-by: Hao Qin --- v3: split from the v2 to make the patch do one thing in a patch and ensure the reset the controller only when we actually need it to avoid the regression on the time spent in opening the controller. v4: rebase onto the latest code v5: no change --- drivers/bluetooth/btusb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 602456e94fdb..ddd5ca7596e5 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3175,6 +3175,13 @@ static int btusb_mtk_setup(struct hci_dev *hdev) case 0x7922: case 0x7961: case 0x7925: + /* Reset the device to ensure it's in the initial state before + * downloading the firmware to ensure. + */ + + if (!test_bit(BTUSB_FIRMWARE_LOADED, &data->flags)) + btusb_mtk_subsys_reset(hdev, dev_id); + btmtk_fw_get_filename(fw_bin_name, sizeof(fw_bin_name), dev_id, fw_version, fw_flavor); @@ -3182,9 +3189,12 @@ static int btusb_mtk_setup(struct hci_dev *hdev) btusb_mtk_hci_wmt_sync); if (err < 0) { bt_dev_err(hdev, "Failed to set up firmware (%d)", err); + clear_bit(BTUSB_FIRMWARE_LOADED, &data->flags); return err; } + set_bit(BTUSB_FIRMWARE_LOADED, &data->flags); + /* It's Device EndPoint Reset Option Register */ btusb_mtk_uhw_reg_write(data, MTK_EP_RST_OPT, MTK_EP_RST_IN_OUT_OPT); -- 2.25.1