Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp40372pxx; Mon, 26 Oct 2020 02:46:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlgEr6Y5AhhCAuz0CoCfkLG1vKAv1j/3XCEunFGBUL4xig2OUtiGc7QuxDSrYypwa6N2Lq X-Received: by 2002:aa7:d948:: with SMTP id l8mr14992139eds.159.1603705605678; Mon, 26 Oct 2020 02:46:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603705605; cv=none; d=google.com; s=arc-20160816; b=gXetytzij6XGA/oiRs+EfsufmY0zPgETnIGeKxPDiT3sp/KgymanYbk1w9Ww4hYT/F sZdsjeaPTw3c7pjNsjq1VNw1Fzm+hNqBL1Oz09rREl0RMrAvux++QfhBwnwenCCoK2T9 1O+LQ5FEBTqNyI4/Up90Sbc0xkmaO8lP7zLB6snymfM1onFnHGrNTyrhQRfZLrWVYlxT aKYLl1+RJcm9PQ2dNCkEJb8o0YeE06PyY261unY8r9W0468hIWu+xaBVMflf+O0unpBc MJ39nEMA2H1eL/6ezpKrOu4K2qSbOU/haUwIBn0qeRTpBi0JkqIVjWz9foh/3XFAxCV4 o4aw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=YpgqvNNriEWLFAnDbHTFlmSpxcTIzbPH3A8YFX8ufRc=; b=tgW5pNFHaDbjBCCj3BLt66PtNHFtDk4XS/nd1s6REzscPIgBdYDRsxES0FTdlSgSuf 0VPb8bGpObPgVyFZmGGt8LKcKtywjWBYfeYKef/O1MJtIZCmipMytatC8ak2m0MqT7lN ibj1VJwEdccsYIMg7Tb8uBciXbUAeuyoZsrB6/IYj/6OH6M+wYVarqcX1DidPJPbQC2m 0gRNStyt90EeIgj3br7iCRGiSKVIuzJvBXYa4Fkbn4jB/zKyDxVRrn2wx3AUEWBR3hhX rM2/gXchr4f0HLl3DMFZ5NOUaLh9zP91xmfzG6vQ6y6Xxp4T5Od8kWLKQ6zKEp8rwaXz rXag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qn8si6944269ejb.74.2020.10.26.02.46.09; Mon, 26 Oct 2020 02:46:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1771720AbgJZI2z (ORCPT + 99 others); Mon, 26 Oct 2020 04:28:55 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:44716 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1771719AbgJZI2z (ORCPT ); Mon, 26 Oct 2020 04:28:55 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kWxrz-0005Rg-Ks; Mon, 26 Oct 2020 08:28:48 +0000 From: Kai-Heng Feng To: marcel@holtmann.org, johan.hedberg@gmail.com Cc: max.chou@realtek.com, alex_lu@realsil.com.cn, Kai-Heng Feng , linux-bluetooth@vger.kernel.org (open list:BLUETOOTH DRIVERS), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] Bluetooth: btrtl: Ask 8821C to drop old firmware Date: Mon, 26 Oct 2020 16:28:38 +0800 Message-Id: <20201026082838.26532-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Some platforms keep USB power even when they are powered off and in S5, this makes Realtek 8821C keep its firmware even after a cold boot, and make 8821C never load new firmware. So use vendor specific HCI command to ask 8821C drop its firmware after system shutdown. Newer firmware doesn't have this issue so we only use this trick for old 8821C firmware version. Suggested-by: Max Chou Signed-off-by: Kai-Heng Feng --- v2: - Fix incorrect parAnthesis on le16_to_cpu. - Ensure firmware gets re-uploaded in initialization. drivers/bluetooth/btrtl.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/bluetooth/btrtl.c b/drivers/bluetooth/btrtl.c index 3a9afc905f24..37e24bbb2eb4 100644 --- a/drivers/bluetooth/btrtl.c +++ b/drivers/bluetooth/btrtl.c @@ -55,6 +55,7 @@ struct btrtl_device_info { int fw_len; u8 *cfg_data; int cfg_len; + bool drop_fw; }; static const struct id_table ic_id_table[] = { @@ -563,6 +564,8 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev, u16 hci_rev, lmp_subver; u8 hci_ver; int ret; + u16 opcode; + u8 cmd[2]; btrtl_dev = kzalloc(sizeof(*btrtl_dev), GFP_KERNEL); if (!btrtl_dev) { @@ -584,6 +587,49 @@ struct btrtl_device_info *btrtl_initialize(struct hci_dev *hdev, hci_ver = resp->hci_ver; hci_rev = le16_to_cpu(resp->hci_rev); lmp_subver = le16_to_cpu(resp->lmp_subver); + + if (resp->hci_ver == 0x8 && le16_to_cpu(resp->hci_rev) == 0x826c && + resp->lmp_ver == 0x8 && le16_to_cpu(resp->lmp_subver) == 0xa99e) + btrtl_dev->drop_fw = true; + + if (btrtl_dev->drop_fw) { + opcode = hci_opcode_pack(0x3f, 0x66); + cmd[0] = opcode & 0xff; + cmd[1] = opcode >> 8; + + skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL); + if (IS_ERR(skb)) + goto out_free; + + skb_put_data(skb, cmd, sizeof(cmd)); + hci_skb_pkt_type(skb) = HCI_COMMAND_PKT; + + hdev->send(hdev, skb); + + /* Ensure the above vendor command is sent to controller and + * process has done. + */ + msleep(200); + + /* Read the local version again. Expect to have the vanilla + * version as cold boot. + */ + skb = btrtl_read_local_version(hdev); + if (IS_ERR(skb)) { + ret = PTR_ERR(skb); + goto err_free; + } + + resp = (struct hci_rp_read_local_version *)skb->data; + rtl_dev_info(hdev, "examining hci_ver=%02x hci_rev=%04x lmp_ver=%02x lmp_subver=%04x", + resp->hci_ver, resp->hci_rev, + resp->lmp_ver, resp->lmp_subver); + + hci_ver = resp->hci_ver; + hci_rev = le16_to_cpu(resp->hci_rev); + lmp_subver = le16_to_cpu(resp->lmp_subver); + } +out_free: kfree_skb(skb); btrtl_dev->ic_info = btrtl_match_ic(lmp_subver, hci_rev, hci_ver, -- 2.17.1