diff mbox series

[v4,3/3] Bluetooth: btqcomsmd: retieve BD address from DT

Message ID 1504607164-12645-3-git-send-email-loic.poulain@linaro.org
State New
Headers show
Series None | expand

Commit Message

Loic Poulain Sept. 5, 2017, 10:26 a.m. UTC
Retrieve BD address from the DT local-bd-address property.
This address must be unique and is usually added in the DT
by the bootloader which has access to the provisioned data.

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

---
 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
 v4: Add dt-bindings documentation
     split patch in two parts (setup, dt prop)
     use local-bd-address name instead of local-mac-address

 drivers/bluetooth/btqcomsmd.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

-- 
2.13.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Marcel Holtmann Sept. 5, 2017, 12:13 p.m. UTC | #1
Hi Loic,

> Retrieve BD address from the DT local-bd-address property.

> This address must be unique and is usually added in the DT

> by the bootloader which has access to the provisioned data.

> 

> Signed-off-by: Loic Poulain <loic.poulain@linaro.org>

> ---

> 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

> v4: Add dt-bindings documentation

>     split patch in two parts (setup, dt prop)

>     use local-bd-address name instead of local-mac-address

> 

> drivers/bluetooth/btqcomsmd.c | 15 +++++++++++++++

> 1 file changed, 15 insertions(+)

> 

> diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c

> index c70fae75c4ad..08a83cb30af6 100644

> --- a/drivers/bluetooth/btqcomsmd.c

> +++ b/drivers/bluetooth/btqcomsmd.c

> @@ -15,6 +15,8 @@

> #include <linux/module.h>

> #include <linux/slab.h>

> #include <linux/rpmsg.h>

> +#include <linux/of.h>

> +

> #include <linux/soc/qcom/wcnss_ctrl.h>

> #include <linux/platform_device.h>

> 

> @@ -126,6 +128,7 @@ static int btqcomsmd_setup(struct hci_dev *hdev)

> 

> static int btqcomsmd_probe(struct platform_device *pdev)

> {

> +	const bdaddr_t *local_bd_addr;

> 	struct btqcomsmd *btq;

> 	struct hci_dev *hdev;

> 	void *wcnss;

> @@ -147,6 +150,18 @@ static int btqcomsmd_probe(struct platform_device *pdev)

> 	if (IS_ERR(btq->cmd_channel))

> 		return PTR_ERR(btq->cmd_channel);

> 

> +	/* The local-bd-address DT property is usually injected by the

> +	 * bootloader which has access to the allocated BD address.

> +	 */

> +	local_bd_addr = of_get_property(pdev->dev.of_node, "local-mac-address",

> +					&ret);

> +	if (local_bd_addr && ret == sizeof(bdaddr_t)) {

> +		/* local-bd-address stored with most significant byte first */

> +		baswap(&btq->bdaddr, local_bd_addr);


actually my preference would be really that the address is coming from DT in the right order. We are defining what local-bd-address means. So lets do that in Bluetooth specified order and not confuse people even more.

And btw. I am fine if you just use const bdaddr_t *bdaddr here as temporary variable name.

Regards

Marcel

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
kernel test robot Sept. 8, 2017, 3:54 a.m. UTC | #2
Hi Loic,

[auto build test WARNING on robh/for-next]
[also build test WARNING on v4.13]
[cannot apply to bluetooth-next/master next-20170907]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Loic-Poulain/dt-bindings-soc-qcom-Add-local-bd-address-property-to-WCNSS-BT/20170908-102410
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 4.9.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # save the attached .config to linux build tree
        make.cross ARCH=xtensa 

All warnings (new ones prefixed by >>):

   drivers//bluetooth/btqcomsmd.c: In function 'btqcomsmd_probe':
>> drivers//bluetooth/btqcomsmd.c:160:3: warning: passing argument 2 of 'baswap' discards 'const' qualifier from pointer target type

      baswap(&btq->bdaddr, local_bd_addr);
      ^
   In file included from drivers//bluetooth/btqcomsmd.c:23:0:
   include/net/bluetooth/bluetooth.h:236:6: note: expected 'struct bdaddr_t *' but argument is of type 'const struct bdaddr_t *'
    void baswap(bdaddr_t *dst, bdaddr_t *src);
         ^

vim +160 drivers//bluetooth/btqcomsmd.c

   128	
   129	static int btqcomsmd_probe(struct platform_device *pdev)
   130	{
   131		const bdaddr_t *local_bd_addr;
   132		struct btqcomsmd *btq;
   133		struct hci_dev *hdev;
   134		void *wcnss;
   135		int ret;
   136	
   137		btq = devm_kzalloc(&pdev->dev, sizeof(*btq), GFP_KERNEL);
   138		if (!btq)
   139			return -ENOMEM;
   140	
   141		wcnss = dev_get_drvdata(pdev->dev.parent);
   142	
   143		btq->acl_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_ACL",
   144							   btqcomsmd_acl_callback, btq);
   145		if (IS_ERR(btq->acl_channel))
   146			return PTR_ERR(btq->acl_channel);
   147	
   148		btq->cmd_channel = qcom_wcnss_open_channel(wcnss, "APPS_RIVA_BT_CMD",
   149							   btqcomsmd_cmd_callback, btq);
   150		if (IS_ERR(btq->cmd_channel))
   151			return PTR_ERR(btq->cmd_channel);
   152	
   153		/* The local-bd-address DT property is usually injected by the
   154		 * bootloader which has access to the allocated BD address.
   155		 */
   156		local_bd_addr = of_get_property(pdev->dev.of_node, "local-mac-address",
   157						&ret);
   158		if (local_bd_addr && ret == sizeof(bdaddr_t)) {
   159			/* local-bd-address stored with most significant byte first */
 > 160			baswap(&btq->bdaddr, local_bd_addr);

   161			BT_INFO("BD address %pMR retrieved from device-tree",
   162				&btq->bdaddr);
   163		}
   164	
   165		hdev = hci_alloc_dev();
   166		if (!hdev)
   167			return -ENOMEM;
   168	
   169		hci_set_drvdata(hdev, btq);
   170		btq->hdev = hdev;
   171		SET_HCIDEV_DEV(hdev, &pdev->dev);
   172	
   173		hdev->bus = HCI_SMD;
   174		hdev->open = btqcomsmd_open;
   175		hdev->close = btqcomsmd_close;
   176		hdev->send = btqcomsmd_send;
   177		hdev->setup = btqcomsmd_setup;
   178		hdev->set_bdaddr = qca_set_bdaddr_rome;
   179	
   180		ret = hci_register_dev(hdev);
   181		if (ret < 0) {
   182			hci_free_dev(hdev);
   183			return ret;
   184		}
   185	
   186		platform_set_drvdata(pdev, btq);
   187	
   188		return 0;
   189	}
   190	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
diff mbox series

Patch

diff --git a/drivers/bluetooth/btqcomsmd.c b/drivers/bluetooth/btqcomsmd.c
index c70fae75c4ad..08a83cb30af6 100644
--- a/drivers/bluetooth/btqcomsmd.c
+++ b/drivers/bluetooth/btqcomsmd.c
@@ -15,6 +15,8 @@ 
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/rpmsg.h>
+#include <linux/of.h>
+
 #include <linux/soc/qcom/wcnss_ctrl.h>
 #include <linux/platform_device.h>
 
@@ -126,6 +128,7 @@  static int btqcomsmd_setup(struct hci_dev *hdev)
 
 static int btqcomsmd_probe(struct platform_device *pdev)
 {
+	const bdaddr_t *local_bd_addr;
 	struct btqcomsmd *btq;
 	struct hci_dev *hdev;
 	void *wcnss;
@@ -147,6 +150,18 @@  static int btqcomsmd_probe(struct platform_device *pdev)
 	if (IS_ERR(btq->cmd_channel))
 		return PTR_ERR(btq->cmd_channel);
 
+	/* The local-bd-address DT property is usually injected by the
+	 * bootloader which has access to the allocated BD address.
+	 */
+	local_bd_addr = of_get_property(pdev->dev.of_node, "local-mac-address",
+					&ret);
+	if (local_bd_addr && ret == sizeof(bdaddr_t)) {
+		/* local-bd-address stored with most significant byte first */
+		baswap(&btq->bdaddr, local_bd_addr);
+		BT_INFO("BD address %pMR retrieved from device-tree",
+			&btq->bdaddr);
+	}
+
 	hdev = hci_alloc_dev();
 	if (!hdev)
 		return -ENOMEM;