Skip to content

Commit

Permalink
Bluetooth: hci_h5: Add vendor setup, open, and close callbacks
Browse files Browse the repository at this point in the history
Allow vendor-specific setup, open, and close functions to be defined.

Signed-off-by: Jeremy Cline <jeremy@jcline.org>
[hdegoede@redhat.com: Port from bt3wire.c to hci_h5.c, drop dt support]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
  • Loading branch information
Jeremy Cline authored and Marcel Holtmann committed Aug 3, 2018
1 parent ce94555 commit 4eb3cbc
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion drivers/bluetooth/hci_h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
*
*/

#include <linux/kernel.h>
#include <linux/acpi.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/mod_devicetable.h>
#include <linux/serdev.h>
#include <linux/skbuff.h>

Expand Down Expand Up @@ -99,6 +101,15 @@ struct h5 {
H5_SLEEPING,
H5_WAKING_UP,
} sleep;

const struct h5_vnd *vnd;
const char *id;
};

struct h5_vnd {
int (*setup)(struct h5 *h5);
void (*open)(struct h5 *h5);
void (*close)(struct h5 *h5);
};

static void h5_reset_rx(struct h5 *h5);
Expand Down Expand Up @@ -218,6 +229,9 @@ static int h5_open(struct hci_uart *hu)

h5->tx_win = H5_TX_WIN_MAX;

if (h5->vnd && h5->vnd->open)
h5->vnd->open(h5);

set_bit(HCI_UART_INIT_PENDING, &hu->hdev_flags);

/* Send initial sync request */
Expand All @@ -237,12 +251,25 @@ static int h5_close(struct hci_uart *hu)
skb_queue_purge(&h5->rel);
skb_queue_purge(&h5->unrel);

if (h5->vnd && h5->vnd->close)
h5->vnd->close(h5);

if (!hu->serdev)
kfree(h5);

return 0;
}

static int h5_setup(struct hci_uart *hu)
{
struct h5 *h5 = hu->priv;

if (h5->vnd && h5->vnd->setup)
return h5->vnd->setup(h5);

return 0;
}

static void h5_pkt_cull(struct h5 *h5)
{
struct sk_buff *skb, *tmp;
Expand Down Expand Up @@ -753,6 +780,7 @@ static const struct hci_uart_proto h5p = {
.name = "Three-wire (H5)",
.open = h5_open,
.close = h5_close,
.setup = h5_setup,
.recv = h5_recv,
.enqueue = h5_enqueue,
.dequeue = h5_dequeue,
Expand All @@ -761,6 +789,7 @@ static const struct hci_uart_proto h5p = {

static int h5_serdev_probe(struct serdev_device *serdev)
{
const struct acpi_device_id *match;
struct device *dev = &serdev->dev;
struct h5 *h5;

Expand All @@ -774,6 +803,15 @@ static int h5_serdev_probe(struct serdev_device *serdev)
h5->serdev_hu.serdev = serdev;
serdev_device_set_drvdata(serdev, h5);

if (has_acpi_companion(dev)) {
match = acpi_match_device(dev->driver->acpi_match_table, dev);
if (!match)
return -ENODEV;

h5->vnd = (const struct h5_vnd *)match->driver_data;
h5->id = (char *)match->id;
}

return hci_uart_register_device(&h5->serdev_hu, &h5p);
}

Expand Down

0 comments on commit 4eb3cbc

Please sign in to comment.