Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp323422lqo; Wed, 15 May 2024 16:16:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXVEUFulIv8LDJ49JM7YTtB+B6Ik0G/AaYgDOBmqauVfpems5nTEokuL1krjeDgSeHYMQhwHEvO4lGjd7QsY8m1zcwPKEWP7PGtqK4UEA== X-Google-Smtp-Source: AGHT+IEGpiteGuue801+4QcsOPFjtGO/07sCDXv6NoopiGRHUb3sNAJN/6gDBmnN52k9DeFh90Ht X-Received: by 2002:a05:6a20:431a:b0:1af:6911:ddf3 with SMTP id adf61e73a8af0-1afde0af0bbmr19543330637.7.1715814976002; Wed, 15 May 2024 16:16:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715814975; cv=pass; d=google.com; s=arc-20160816; b=FEWZCIDJ8tplR312XbNeGvyt155jeVD50y3mmmnUShBSYav5Dl8VsPIbV2zLc8PaxT Cm9xrGDim/oxYCscM41gqLpzVy3Go3CBPmk/Bpd8sfq8vJ91jb3L6VeNvLfCCjzgID/v 4uWIuGdfu8UWknjcY1pyNjF9tj+ycxd9BmGyPgDBIanWDpOEuhWSzBPcve2raHgin1eb iEO752OLHWVN48cqNML4RhPg5BM3TnUM7QEAmzEgVKqA3P64V7RO4KWTOom7MM+0j35A UnQDZXUh89gRpGKv/edanKNhJutBty8a3teKolxSb2rvp4Nk4Kgj/2UOs1KvfCOzVLb+ szxA== 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=FFGLv+/W/92QSc/vAIXNlWmURdmlafsCOBe70BkQWmk=; fh=AqRDF6hWyXqabfdzl+kLtbGqm+BBfPN18NrB30pCD4U=; b=HhXb2JBp+oIVaV8gLKVo/JLh/rrbalNsNC83rF8T+F02z2Br856cOjkUuLT+DDxQVR QpOFoTh4YVRw5c5pvGandTgkz7mDGsUh1FUc8w/OLHjpxUAeES7PmGnlVEZdFjLOKejK C7cYvDo9a6j9m1vIPSs6MbfUVRgVAlzkIR4PvIuZjfyHfvYl0SVYJDU82zRCllJvBcc9 3sSOYudDmXOiSUttOEC0GDn2FPYYHjnWNmLWlZu80E5clt4CEDvdvl3ebKUvEM9Un5Xg rvi6WBQDetshsf4buOsHGprayyZeZLTHjddK0GjdOomRJ+c2RZyr/UB6dMB/2LDeJvs7 P/mg==; 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-bluetooth+bounces-4673-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4673-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6340b395157si13089035a12.203.2024.05.15.16.16.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:16:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4673-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-bluetooth+bounces-4673-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4673-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 88846B20881 for ; Wed, 15 May 2024 23:16:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8958D15B974; Wed, 15 May 2024 23:15:39 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 B818815B541; Wed, 15 May 2024 23:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814939; cv=none; b=ZC0aQHr4+wlj/c6XPMR33p463j1VJlGvAXVrCoJ//LXoRqBY0y0WUZUDqgmMSy+c2UlNqYSrQrfI2rF+bE40V9PTJa6/3m2rgrRUEUlbiMPBwCrBol1XO3kFWdkKNCnzK5Upf8Cpa1Ri6SzKNxlZ7OI4NTs5VKX8h5vfs4BYY/I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715814939; c=relaxed/simple; bh=l7qaEhv18i07jkg7QgeZLvVfGZZI+7PyNiWrqAvRAG8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eso5wLJqYzKaq5HtALesc+WOL83tbu6oBPs1Oe/no8xQH/afRbtrC/3rO7cCwBY7v53FmtZ96/wfNFkt2j/FC5+vD0sVp4V9nMXqtc7G79F53yWl0j3MtOW+jLFfxf/uQptJqByhziiW/e6M6jjHtamJHKyMeuILzmgPYWESnPo= 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.167.169 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-oi1-f169.google.com with SMTP id 5614622812f47-3c998b36c6bso1208060b6e.3; Wed, 15 May 2024 16:15:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715814937; x=1716419737; 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=FFGLv+/W/92QSc/vAIXNlWmURdmlafsCOBe70BkQWmk=; b=MMA/FL+uAenozHTrKmLgrwkS5eyzTMkF1yXsGZFSQ09aIaRK2kQA6KTn/FcmVXUjQC 5LWrO0VvF5YJQdChvRLzam6VBWPivse2YXqz9FLBYanG5dl46nY8zV1/r9H9P9hhg5Gq TI5Pw/iZ9hQ73VfTsFdJFtNyUbEHhReigaAoJQ5PmXAa8zs9h1vdSGUB67EXfemnSpgE RGHYk9BfA2I1QDzexUm1kgp14YqfLhUQUcW6+i9T9pfu52uwNNSyqWWAbc4t6mGPV+Qt TJU73oQmYvuCuSEA5k6iqBu0RXEzShOnuEwAox7bet0KI1dVGAIZ9+RPpd3fGk2X2iFi tBOQ== X-Forwarded-Encrypted: i=1; AJvYcCUU+0eB9WTLv6WR60muFw5RL2CDGC7IpkRUFbMqY+MtVh6R3s2IRGeFmsgeqEArRsWcNcw33vbMyqU+c2gJiGzRNhnmOYSNqoNx8aYj X-Gm-Message-State: AOJu0YyVXdAZOU/g9bfjePd9NVg3Eo6PI6mSw+BDne1MauU/l19SYOJV JFbAWNygHJH6MV7T9TmWfkvBDgHqv7zbDiW7Try5qfHYpl5G1l0U X-Received: by 2002:a05:6830:14cd:b0:6f0:e2aa:ea49 with SMTP id 46e09a7af769-6f0e92ce674mr19960426a34.3.1715814936703; Wed, 15 May 2024 16:15:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 16:15:36 -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 v5 3/5] Bluetooth: btusb: mediatek: refactor the function btusb_mtk_reset Date: Wed, 15 May 2024 16:15:19 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@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 v5: no change --- 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 611135d1ce01..602456e94fdb 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