Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp69041lqo; Tue, 7 May 2024 12:23:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwVXswrfyLKFF1uOSygdngJp6QOIKyco1Ki9YeWVfT3VsfIjfM7yDO4QEoDzazUET5qtEIw1m+5BqPBkd4v9vUmMOx6gcqsl+djkOSHw== X-Google-Smtp-Source: AGHT+IHNHMkABx1RNVxP5vMo1BwBSUYnjy/0Wv/AM6kX2vSGhTsGWCj29Q8IhwJaxZAzZqIgArN0 X-Received: by 2002:a5b:781:0:b0:dc2:5553:ca12 with SMTP id 3f1490d57ef6-debb9cfad44mr674615276.14.1715109784727; Tue, 07 May 2024 12:23:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715109784; cv=pass; d=google.com; s=arc-20160816; b=WJB+fKS3j9y1uZFtrxVq42gw9oXcg45PfkwZmeHpIYLyzcNLVkMVt/X92ZJIM0G09R s2fAu9o6YUFnUpdRXIYSm5oTKleoSbd08zWh2DLA6PRtBETTpejFzw1WUGs5JQYSb/Uy ulQRvn/tu9HsgQxhmi2QGQ/UFWZgDqgaEXpj72yCW7ehXvLSRKeJi6xNZQdWPyiRjjnw xbWBYuEE9/V17i8ghW84TVfm/j9S6ekngIud672sOibp+Itii10sdYG9+23zPzESnkQd f5Zl9XUdk4eazpWTmEDw7fGatyRorQK3KJQ3WncaJPHEU3DXnUHa/U7bTBs9X1eJpXHG BpxQ== 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=SlonihVk5HXWq/ZpBp4yUpJHwD260ZA8CaexGXiG9rQ=; fh=TvSZpPadZr4ZSCiiCrDEW1pfh96reZeBI+seE7AgYyw=; b=curklYPUPJXSopacPx8qKugid6l9UeSCp22Ag9PzwYcHTOkNGs4LWMVZ8RgbziPrVl 6BfBXlOZGohZiczbilgMTaUUN0Crbkgi5TNDot0vmKtyLeShvNQwCvbpcSVSBxJ86bYk IuClU/2UwWaLnH6WSJIKUvPCj/Sm6RbgBcPj0dzF5EWaahBuhbuEBVR0vEaax9pAx4U3 2ojmpVm4nx69bsZVk9Dgj6TseovcaMymjL0lUNfV88gWQGFViP2Sbo+erZUR77bIWNKj zNu4GlFhsD6rD1Yk0MEBjADRXNI3MpMKCT7w/xx2kD8UrZJY5IxhAD6ELs76rBCVuAWT L6kA==; 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-172057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172057-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. [147.75.199.223]) by mx.google.com with ESMTPS id n18-20020a05622a041200b00431513700c7si12440735qtx.554.2024.05.07.12.23.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:23:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172057-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172057-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 0A1441C24B40 for ; Tue, 7 May 2024 19:22:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9B5DE16E89B; Tue, 7 May 2024 19:22:12 +0000 (UTC) Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (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 BEBD016EC11; Tue, 7 May 2024 19:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109732; cv=none; b=hE89LkTM5VR7VeP8hwdER5iYiw1Ows+iCBAaV/pvFNiiRdAU0580BlSK0DUzUMtTSDg75iUHr39R9+7mKWtoWtrs2ens+aeHp95pWvVR1quiykU/E6pvcG4YlGcV64DplGag0I/vldXMixb+RjGzqw2I132gbxnrYMruC25D66E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109732; c=relaxed/simple; bh=zeX93PqWQJOMUqO7tMUXpYKyT0p2tqeT0oe7g6GyVJY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=udnTPGixs82Y2o4P7RwSdeKVj/zuUCqNIJO/7qvyBPV63KWDcFasBVqTZDWC4hr7Ty0vbjvP00lF+bREb7numyIJJyRvyhGcUvQxMQG63QuCOUIsDS4nDOgzwFY3tl0XR47akAmv2ZV5V1MHlSJUNJoMzfD4P/4/aVBRfPueDmQ= 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.161.44 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-oo1-f44.google.com with SMTP id 006d021491bc7-5af12f48b72so734988eaf.3; Tue, 07 May 2024 12:22:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109730; x=1715714530; 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=SlonihVk5HXWq/ZpBp4yUpJHwD260ZA8CaexGXiG9rQ=; b=let7ueCbXut993voTs7aTJyQF0BFhsIXTmP6vKK1z1iXnavXh2Zfr1rT4/0rD7uFA1 nY+exWTgzhC5RXa9J9L4sYc+mo2vKiG6+zj4FGylYHzG2mTCUMzaN22yfKnvoqhunRD4 /VK26KHrn4qplKLusZDymLDzax+o4ShjsXo3XBq3xRE3Juu9WPj4OND5hI6BYggzoKpu ljYCFw4k6BpOLAlQJZELGpjKO3D0XIFrBRCjXTd+uLsrA5YQ5U7eWcanHytUpoivKHU9 pD1OerGFPWwaL3dTwZdQS+JrmVL6WesYMNJAPfefDtyRrm2OyVU8NT0+cVGXYlAUrTxP Lepw== X-Forwarded-Encrypted: i=1; AJvYcCUxdz/IBSZU6Z82NJxb5M6DbHlzolR8w63WP8qwyIcULyc/cbGzDCUvdH9UeSqWxG8HyD5S4833UX/dtrOUiZVXBtb1s+i/2QywywmY X-Gm-Message-State: AOJu0YyOr8/23rBQR0Zq1phG7w/HZhNqPiRj3W508B8eh9S9UNCtz2Hd uiQDm3YKopGaaxHXRc3K41lQXnVyoTNKabEvIoT63NPauODJSCPU X-Received: by 2002:a05:6808:181a:b0:3c8:4de7:6736 with SMTP id 5614622812f47-3c98543850bmr542210b6e.4.1715109729785; Tue, 07 May 2024 12:22:09 -0700 (PDT) Received: from sean-ThinkPad-T450s.lan ([207.191.35.252]) by smtp.gmail.com with ESMTPSA id ec18-20020a056808639200b003c8643f0e5csm1937839oib.16.2024.05.07.12.22.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:08 -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 v4 4/5] Bluetooth: btusb: mediatek: reset the controller before downloading the fw Date: Tue, 7 May 2024 12:22:00 -0700 Message-Id: <3c3dfe8efc70af04794035537c7c40a52f2266d5.1715109394.git.sean.wang@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.org> References: <965cd14922aea67e2750ff2c2ecad773f8ba485a.1715109394.git.sean.wang@kernel.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 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 --- drivers/bluetooth/btusb.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 76c52f2fe917..054e8c06bcf3 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