From patchwork Mon Sep 4 10:43:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 9936985 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8D5946038C for ; Mon, 4 Sep 2017 10:43:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7E0C3287C0 for ; Mon, 4 Sep 2017 10:43:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71676287C6; Mon, 4 Sep 2017 10:43:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C64A5287C0 for ; Mon, 4 Sep 2017 10:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753485AbdIDKnK (ORCPT ); Mon, 4 Sep 2017 06:43:10 -0400 Received: from mail-wm0-f42.google.com ([74.125.82.42]:38313 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753483AbdIDKnJ (ORCPT ); Mon, 4 Sep 2017 06:43:09 -0400 Received: by mail-wm0-f42.google.com with SMTP id 187so910892wmn.1 for ; Mon, 04 Sep 2017 03:43:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=rE2og6fuMU3DhQHSDHkAtCXddJMg4hh4oJTTVlfGc+w=; b=TORZJz+yKK+mtDdivm34knSjLJUZisjYiiU62SEVfiHRFkmE1+aXNEzhCtbVos872b VMUPjMzmPDD+2cBPppP2+A1rH2DmKFpshW1dTcwBNumpc1TaMtnkKXAoc/xvgERg0D6C 1JmsD487KTizyi2uiB/4f/uVIhOzk7NBwAwuk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rE2og6fuMU3DhQHSDHkAtCXddJMg4hh4oJTTVlfGc+w=; b=TuhHlvIQRCcWEon7w1JXz8EDlcAfLGmenyzGQsnd6rgMgVdv8Tln7h7VDfUsJI/bLt V7DYI2FGX7x9LDumEfbeMlAzAMxUTl0wpv91s/EOOAjRAab4HEkviWq8yZu6vWqWbF3+ T2iXVdz7eanzSYJ7hGvmJOCvlV6+iS0K8Z37QM++IuugGdmnccfaWMaC2WsTD8SfW7Ja rNYLSMF0S6VSzgZW/v6BED8s7jfdPNHYeC9RPq/zt8dVeYXVbY3FFqSInD8zYtrNScCw lSTbjjGmAuEftNKFEvKwU96TzWH2LTOHuGrdsinjbpxqCWuTcIOBH/FWub2AgJ1gTtqw twxA== X-Gm-Message-State: AHPjjUhyyFywYJoz2h17Ji/+A0JlpziYcMV1bI6bEt1US7A5a2SvrlSd n5lIizkE6O82q9tJ X-Google-Smtp-Source: ADKCNb5ln5ljZMua6sT8fkRjDiudkfHQHoWEgOVVE9KFrXNA2w446cGqLGVx8ZDTov4nNWER/Oekcw== X-Received: by 10.28.74.89 with SMTP id x86mr2614wma.57.1504521788172; Mon, 04 Sep 2017 03:43:08 -0700 (PDT) Received: from localhost.localdomain ([80.12.59.80]) by smtp.gmail.com with ESMTPSA id p87sm205297wmf.22.2017.09.04.03.43.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Sep 2017 03:43:07 -0700 (PDT) From: Loic Poulain To: marcel@holtmann.org Cc: linux-bluetooth@vger.kernel.org, linux-arm-msm@vger.kernel.org, bjorn.andersson@linaro.org, robh@kernel.org, Loic Poulain Subject: [PATCH v3] Bluetooth: btqcomsmd: BD address setup Date: Mon, 4 Sep 2017 12:43:04 +0200 Message-Id: <1504521784-9766-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Bluetooth BD address can be retrieved in the same way as for wcnss-wlan MAC address. This patch mainly stores the local-mac-address property and sets the BD address during hci device setup. If there is no such property, mark the device as unconfigured. Signed-off-by: Loic Poulain --- drivers/bluetooth/btqcomsmd.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) v2: Set device as unconfigured if default address detected Add warning if BD addr retrieved from DT v3: if no addr retrieved from DT, unconditionally set the invalid BD addr flag. swap and set bdaddr in the platform probe diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c index ef730c173d4b..37406a6aa1b5 100644 --- a/drivers/bluetooth/btqcomsmd.c +++ b/drivers/bluetooth/btqcomsmd.c @@ -15,6 +15,8 @@ #include #include #include +#include + #include #include @@ -26,6 +28,7 @@ struct btqcomsmd { struct hci_dev *hdev; + bdaddr_t bdaddr; struct rpmsg_endpoint *acl_channel; struct rpmsg_endpoint *cmd_channel; }; @@ -100,8 +103,35 @@ static int btqcomsmd_close(struct hci_dev *hdev) return 0; } +static int btqcomsmd_setup(struct hci_dev *hdev) +{ + struct btqcomsmd *btq = hci_get_drvdata(hdev); + struct sk_buff *skb; + + skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) + return PTR_ERR(skb); + kfree_skb(skb); + + /* Device does not have persistent storage for BD address. + * Mark the device with invalid BD addr flag if no address + * retrieved from DT. + */ + if (!bacmp(&btq->bdaddr, BDADDR_ANY)) { + bt_dev_err(hdev, "No BD address configured"); + set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); + return 0; + } + + bt_dev_info(hdev, "BD address %pMR retrieved from device-tree", + &btq->bdaddr); + + return qca_set_bdaddr_rome(hdev, &btq->bdaddr); +} + static int btqcomsmd_probe(struct platform_device *pdev) { + const bdaddr_t *local_addr; struct btqcomsmd *btq; struct hci_dev *hdev; void *wcnss; @@ -123,6 +153,17 @@ static int btqcomsmd_probe(struct platform_device *pdev) if (IS_ERR(btq->cmd_channel)) return PTR_ERR(btq->cmd_channel); + /* Having a unique BD address is critical. + * Usually, the local-mac-address property is injected by + * the bootloader which has access to the provisioned data. + */ + local_addr = of_get_property(pdev->dev.of_node, "local-mac-address", + &ret); + if (local_addr && ret == sizeof(bdaddr_t)) { + /* local-mac-address stored with most significant byte first */ + baswap(&btq->bdaddr, local_addr); + } + hdev = hci_alloc_dev(); if (!hdev) return -ENOMEM; @@ -135,6 +176,7 @@ static int btqcomsmd_probe(struct platform_device *pdev) hdev->open = btqcomsmd_open; hdev->close = btqcomsmd_close; hdev->send = btqcomsmd_send; + hdev->setup = btqcomsmd_setup; hdev->set_bdaddr = qca_set_bdaddr_rome; ret = hci_register_dev(hdev);