[Letux-kernel] [PATCH letux 2/3] bluetooth: add regulators for h4 serdevs
Andreas Kemnade
andreas at kemnade.info
Sun Nov 11 20:49:06 CET 2018
This gives the possibility to add a regulator to h4-compatible
serdevs
Signed-off-by: Andreas Kemnade <andreas at kemnade.info>
---
drivers/bluetooth/hci_h4.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/bluetooth/hci_h4.c b/drivers/bluetooth/hci_h4.c
index 8df0611d976c..1ee466170902 100644
--- a/drivers/bluetooth/hci_h4.c
+++ b/drivers/bluetooth/hci_h4.c
@@ -40,6 +40,7 @@
#include <linux/signal.h>
#include <linux/ioctl.h>
#include <linux/of.h>
+#include <linux/regulator/consumer.h>
#include <linux/serdev.h>
#include <linux/skbuff.h>
#include <asm/unaligned.h>
@@ -52,6 +53,7 @@
struct h4_device {
struct hci_uart hu;
bool flow;
+ struct regulator *supply;
};
struct h4_struct {
@@ -175,6 +177,7 @@ static int hci_h4_probe(struct serdev_device *serdev)
{
struct hci_uart *hu;
struct h4_device *h4dev;
+ int ret;
u32 speed = 3000000;
h4dev = devm_kzalloc(&serdev->dev, sizeof(struct h4_device),
@@ -183,6 +186,10 @@ static int hci_h4_probe(struct serdev_device *serdev)
return -ENOMEM;
hu = &h4dev->hu;
+ h4dev->supply = devm_regulator_get(&serdev->dev, "vdd");
+ if (IS_ERR(h4dev->supply))
+ return PTR_ERR(h4dev->supply);
+
serdev_device_set_drvdata(serdev, h4dev);
hu->serdev = serdev;
@@ -191,7 +198,15 @@ static int hci_h4_probe(struct serdev_device *serdev)
of_property_read_u32(serdev->dev.of_node, "speed", &speed);
hci_uart_set_speeds(hu, speed, speed);
- return hci_uart_register_device(hu, &h4p);
+ ret = regulator_enable(h4dev->supply);
+ if (ret)
+ return ret;
+
+ ret = hci_uart_register_device(hu, &h4p);
+ if (ret)
+ regulator_disable(h4dev->supply);
+
+ return ret;
}
static void hci_h4_remove(struct serdev_device *serdev)
@@ -199,6 +214,7 @@ static void hci_h4_remove(struct serdev_device *serdev)
struct h4_device *h4dev = serdev_device_get_drvdata(serdev);
hci_uart_unregister_device(&h4dev->hu);
+ regulator_disable(h4dev->supply);
}
static const struct of_device_id hci_h4_of_match[] = {
--
2.11.0
More information about the Letux-kernel
mailing list