Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp68901lqo; Tue, 7 May 2024 12:22:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWAb4yqEOlU5foDdt1UdD+YpLWJFgSAX8jToVzKrzLqwX2wr6CtGaDifWxWKpFN7IGhSdvBV3B9DpLZ3bCIDXDC4RwrdSoVlrxrOVJDFQ== X-Google-Smtp-Source: AGHT+IEGPklc0+5AaE+4GJWH67slA5+R9vmCeg8MT2r3nNGeG40Du0/rT4oFAytif304uGRJzM2g X-Received: by 2002:a05:6a21:819e:b0:1af:ac7e:fba3 with SMTP id adf61e73a8af0-1afc8d393e8mr649608637.14.1715109768433; Tue, 07 May 2024 12:22:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715109768; cv=pass; d=google.com; s=arc-20160816; b=vUimlUHr5aMMZ6Ah6C3vKEBYXzJfHUjZLqXWPkNgslkMdGQaGLBLbZtablmZZgWSOi vmww8k31gTdHSUjI06flGEMvKL6R2B16yADUDEKwbRjMxsSgETqqJ21gr9P9ZU0UQcGY fXkoXkpO8n4XpVNq+xKzKmJHSbzaIRK0jzSVkh3u6GzNnaumwfqOrFbirSV1D/oqqPtY XQ9yQxcWBHxvzmNgCzTv70syilN073UHzcl50p6QUjNoB/O/H2nXqQO5waZODWrp/bmu ilVEytB4fEVOdrgB2JSg/wlyAIeOmET0pYr6O5IM43EOWRTQS1UjPZ68COz8q82kZepw IT+w== 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=eyGlXVbcuOBmT6INVyvYbqSZy7NpTaBdxh15HEARP+o=; fh=bFC6HBgh7gSGaliGrv+FhIdA8LQbCZbvhi4yW9tzoPs=; b=b3II5nd9YRBWP4xOTvH9BnT2S2C88WpTz0v75IjlQNfbU3XNSFQDNldTRpGX9fiyzO jMrhcXDZ53pk2rpzAwCZSaAVtsYaWMZGDNiHMSI2zW4z7+l7JUTO4UJXfk+KNGv0ZWUk UozklrXefR24avDb+JgD3B3sdIDITptSaOynVdmvQzg3uYwOyNOQUNmHNZgNzDWqwbHp U6X1FBvvxkbrK2InrhDvNUkvFALnmOI9AefQunDyx74ACYSZAGkWoQcD4uUybaPhZEXM 2z+/YIlaqt01zsdCza1M4iz4imH6UmMNJIlxxXbMMCa6LZAzPdfGWmnY7nVxMHV3Wz1U MheQ==; 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-172056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172056-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l190-20020a6391c7000000b005f77b2c36bdsi10404975pge.514.2024.05.07.12.22.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-172056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-172056-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-172056-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id E510328A4AB for ; Tue, 7 May 2024 19:22:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1DBE116EC1E; Tue, 7 May 2024 19:22:11 +0000 (UTC) Received: from mail-ot1-f54.google.com (mail-ot1-f54.google.com [209.85.210.54]) (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 3FC7516E89B; Tue, 7 May 2024 19:22:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109730; cv=none; b=aBUprHEDHq0Ql0D7uXgEd/I9tgzymhrSo6t1+u3+mFafnh6sD56dho7DtCfmPXXbZlDC3rcbuFmhjN4/m1Yj/FfMGXBoZysCykOza1h3Y3mHiVFosxAt5NgM/5EUbPvA/FWhp+8Ix/1m4mc4FvC+3uSM/l902Pyrkj1WTB76IXY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715109730; c=relaxed/simple; bh=aQ9zB0CP0QI6bN2ZiPhiwNsW9sXlvmMqsyyaMqc13nY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uHe04fzF1DTLY/1SvvHvRY9CtONa/7qaT4BxXXUxs1RNkzb+cW3+W5gEUgSs9ndOVX01DzNGq3o7yjpxRCAxN79J37kyRErbhe8qUqAKZjGuocJR5AnLhgRw+i8QcDorGJf+KdANbjH+FCt/CyasAkcq3Bj7m+bFf+ShkGp4bRc= 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.54 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-f54.google.com with SMTP id 46e09a7af769-6f0471efe4cso66795a34.1; Tue, 07 May 2024 12:22:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715109728; x=1715714528; 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=eyGlXVbcuOBmT6INVyvYbqSZy7NpTaBdxh15HEARP+o=; b=EBx62FHebC781rgLp/m27RZ1jC5UYzYCoVXt5TGdYr2du93DR6euCH9Biyd4LAvT4r LyRyU+gr8wX15jQ8yAwn0s6dkwkY3hpGUPCbgQLrdWy6GnAeT9OlA2orvtoDJPGtM+pm maT92GEPX5Yaju5dI/cUitydG+90MhIJd5cmN3titQXqGpuZOUTxArIuDncrscgt95oc FTFIf7QMY/2H801d3202X2qgfqg0yO79NfP3AC6rxBNYuYufWlKXc+FeXulr4x2ky4C3 g7RjH9KhELdNSD1V1CtDuVJ16ShgPsgRuPLrCpMvGgTW4FezxCsjMGp5r7ppDblgUwsq VO5w== X-Forwarded-Encrypted: i=1; AJvYcCXICL9MIEIEg1dQHk7Scb1EayfA9vvDB/6Q0GhF97ZCfjHMOrzFWyq0z6xbvd4bU3I1jBsRPqXvBddLy7iLNwcpjyst0nfUBah/qcyW X-Gm-Message-State: AOJu0YxH2Qp/YqZYMeSKNeMvuh3YRXfJ1rWlwP+7u5dlRUO7rtd18aOX 8hxOPzjay1H+8YGnUnuZwHci9N7LydIkbOTm887Oxoch1R63fbxw X-Received: by 2002:a05:6808:2008:b0:3c8:4964:cc9d with SMTP id 5614622812f47-3c9851ea36amr575921b6e.0.1715109728245; Tue, 07 May 2024 12:22:08 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 12:22:07 -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 Subject: [PATCH v4 3/5] Bluetooth: btusb: mediatek: refactor the function btusb_mtk_reset Date: Tue, 7 May 2024 12:21:59 -0700 Message-Id: <457c7be3bbbeda1241e097e99056d9c5e2a734bb.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 Extract the function btusb_mtk_subsys_reset from the btusb_mtk_reset for the future handling of resetting bluetooth controller without the USB reset. Co-developed-by: Sean Wang Signed-off-by: Sean Wang Signed-off-by: Hao Qin --- v3: refine the git message v4: rebase onto the latest code --- drivers/bluetooth/btusb.c | 45 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 1603e97f0d7c..76c52f2fe917 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -3033,28 +3033,13 @@ static u32 btusb_mtk_reset_done(struct hci_dev *hdev) return val & MTK_BT_RST_DONE; } -static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) +static int btusb_mtk_subsys_reset(struct hci_dev *hdev, u32 dev_id) { struct btusb_data *data = hci_get_drvdata(hdev); - struct btmediatek_data *mediatek; u32 val; int err; - /* It's MediaTek specific bluetooth reset mechanism via USB */ - if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { - bt_dev_err(hdev, "last reset failed? Not resetting again"); - return -EBUSY; - } - - err = usb_autopm_get_interface(data->intf); - if (err < 0) - return err; - - btusb_stop_traffic(data); - usb_kill_anchored_urbs(&data->tx_anchor); - mediatek = hci_get_priv(hdev); - - if (mediatek->dev_id == 0x7925) { + if (dev_id == 0x7925) { btusb_mtk_uhw_reg_read(data, MTK_BT_RESET_REG_CONNV3, &val); val |= (1 << 5); btusb_mtk_uhw_reg_write(data, MTK_BT_RESET_REG_CONNV3, val); @@ -3098,8 +3083,32 @@ static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) if (!val) bt_dev_err(hdev, "Can't get device id, subsys reset fail."); - usb_queue_reset_device(data->intf); + return err; +} +static int btusb_mtk_reset(struct hci_dev *hdev, void *rst_data) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + struct btmediatek_data *mtk_data; + int err; + + /* It's MediaTek specific bluetooth reset mechanism via USB */ + if (test_and_set_bit(BTUSB_HW_RESET_ACTIVE, &data->flags)) { + bt_dev_err(hdev, "last reset failed? Not resetting again"); + return -EBUSY; + } + + err = usb_autopm_get_interface(data->intf); + if (err < 0) + return err; + + btusb_stop_traffic(data); + usb_kill_anchored_urbs(&data->tx_anchor); + mtk_data = hci_get_priv(hdev); + + err = btusb_mtk_subsys_reset(hdev, mtk_data->dev_id); + + usb_queue_reset_device(data->intf); clear_bit(BTUSB_HW_RESET_ACTIVE, &data->flags); return err; -- 2.25.1