linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] bluetooth: add uart h4 devices via serdev/devicetree
@ 2018-11-10 23:20 Andreas Kemnade
  2018-11-11  2:46 ` Sebastian Reichel
  0 siblings, 1 reply; 16+ messages in thread
From: Andreas Kemnade @ 2018-11-10 23:20 UTC (permalink / raw)
  To: marcel, johan.hedberg, linux-bluetooth, linux-kernel, devicetree,
	letux-kernel
  Cc: Andreas Kemnade

This is a first try to be able to use h4 devices specified in
the devicetree, so you do not need to call hciattach and
it can be automatically probed.

Of course, proper devicetree bindings documentation is
missing. And also you would extend that by regulator/
enable gpio settings.

But before proceeding further it should be checked if the
general way of doing things is right.

Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
 drivers/bluetooth/hci_h4.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)

diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index fb97a3bf069b..8df0611d976c 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -39,6 +39,8 @@
 #include <linux/string.h>
 #include <linux/signal.h>
 #include <linux/ioctl.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
 #include <linux/skbuff.h>
 #include <asm/unaligned.h>
 
@@ -47,6 +49,11 @@
 
 #include "hci_uart.h"
 
+struct h4_device {
+	struct hci_uart hu;
+	bool flow;
+};
+
 struct h4_struct {
 	struct sk_buff *rx_skb;
 	struct sk_buff_head txq;
@@ -146,9 +153,76 @@ static struct sk_buff *h4_dequeue(struct hci_uart *hu)
 	return skb_dequeue(&h4->txq);
 }
 
+#if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)
+static int h4_setup(struct hci_uart *hu)
+{
+	struct h4_device *h4dev;
+	struct serdev_device *serdev = hu->serdev;
+
+	if (!serdev)
+		return 0;
+
+	h4dev = serdev_device_get_drvdata(serdev);
+
+	serdev_device_set_flow_control(serdev, h4dev->flow);
+
+	return 0;
+}
+
+static const struct hci_uart_proto h4p;
+
+static int hci_h4_probe(struct serdev_device *serdev)
+{
+	struct hci_uart *hu;
+	struct h4_device *h4dev;
+	u32 speed = 3000000;
+
+	h4dev = devm_kzalloc(&serdev->dev, sizeof(struct h4_device),
+			     GFP_KERNEL);
+	if (!h4dev)
+		return -ENOMEM;
+	hu = &h4dev->hu;
+
+	serdev_device_set_drvdata(serdev, h4dev);
+	hu->serdev = serdev;
+
+	h4dev->flow = of_property_read_bool(serdev->dev.of_node, "flow");
+
+	of_property_read_u32(serdev->dev.of_node, "speed", &speed);
+	hci_uart_set_speeds(hu, speed, speed);
+
+	return hci_uart_register_device(hu, &h4p);
+}
+
+static void hci_h4_remove(struct serdev_device *serdev)
+{
+	struct h4_device *h4dev = serdev_device_get_drvdata(serdev);
+
+	hci_uart_unregister_device(&h4dev->hu);
+}
+
+static const struct of_device_id hci_h4_of_match[] = {
+	{ .compatible = "wi2wi,w2cbw003-bluetooth"},
+	{},
+};
+MODULE_DEVICE_TABLE(of, hci_h4_of_match);
+
+static struct serdev_device_driver hci_h4_drv = {
+	.driver		= {
+		.name	= "hci-h4",
+		.of_match_table = of_match_ptr(hci_h4_of_match),
+	},
+	.probe = hci_h4_probe,
+	.remove = hci_h4_remove
+};
+#else
+#define h4_setup NULL
+#endif
+
 static const struct hci_uart_proto h4p = {
 	.id		= HCI_UART_H4,
 	.name		= "H4",
+	.setup		= h4_setup,
 	.open		= h4_open,
 	.close		= h4_close,
 	.recv		= h4_recv,
@@ -159,11 +233,15 @@ static const struct hci_uart_proto h4p = {
 
 int __init h4_init(void)
 {
+	serdev_device_driver_register(&hci_h4_drv);
+
 	return hci_uart_register_proto(&h4p);
 }
 
 int __exit h4_deinit(void)
 {
+	serdev_device_driver_unregister(&hci_h4_drv);
+
 	return hci_uart_unregister_proto(&h4p);
 }
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-01-12 12:15 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-10 23:20 [PATCH RFC] bluetooth: add uart h4 devices via serdev/devicetree Andreas Kemnade
2018-11-11  2:46 ` Sebastian Reichel
2018-11-12 20:59   ` Andreas Kemnade
2018-11-12 21:19     ` [Letux-kernel] " H. Nikolaus Schaller
2018-11-12 22:27       ` Sebastian Reichel
2018-11-13  0:17         ` Rob Herring
2018-11-13 16:01           ` Andreas Kemnade
2018-11-14  7:51             ` Marcel Holtmann
2018-11-14 11:13               ` Andreas Kemnade
2018-11-16 19:46               ` Andreas Kemnade
2018-11-16 19:58                 ` Marcel Holtmann
2019-01-04  5:44                   ` Andreas Kemnade
2019-01-04  9:07                     ` Marcel Holtmann
2019-01-04 19:57                       ` Andreas Kemnade
2019-01-12 11:16                         ` Jon Nettleton
2019-01-12 12:15                           ` H. Nikolaus Schaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).