Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp307900imm; Tue, 15 May 2018 01:53:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqmdU8Ltl1eOByPzAIbYMAoNkiWvDIM0u/e+8D2IKGwFf1zYVUWUsO13B0iVtqdTDpcl73W X-Received: by 2002:a17:902:bd84:: with SMTP id q4-v6mr13823138pls.254.1526374415600; Tue, 15 May 2018 01:53:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526374415; cv=none; d=google.com; s=arc-20160816; b=Gz5k8SS27oSEbOA0LWS5Qc00UhEPui3yJaQZBpaBkj18gL6xn9vmTJh4Cdk7DMaNj+ pg4vszawESdMWA+7eNvEc48G9IIpejQRlj9qkXTybXtQJYvWlh4NS+ev7x2yt30q4+Xk 7FG0ya5FPysXeBOQrpbrkCmCCY0DDvhD0oRHA9c5fsZsdLYzzzoqeCGak9FYi02dEmx4 fqN+yj7aCYl7Oeg1se2vh8PV7DTPwnxpKovl4BTWaoSbnlkvwwER7j5L0tUSjTbd3XeZ 1MuxAVx0GMpFoMSUr7YsEdsByFtApsCo8ZAXE0joH/fSoe0gtCkP0yMWJFBzkaoKF+EQ 6S7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=wcdtO1k/rEmisq2N9HXoe+One8YFInb0J9k/SHd+q20=; b=VITR2rvK9jzPKZtQ2/ZoYsi899u5NEmR4iHRZp2lc8nQBiqIE1bQNg3AyC5BZMxSrY yBLhzlfctlqT98tXS1UN9mClWpRxrti3XZIQGrfXX3Q9mGSPJx8R63aKRWZMce3pvBGj Tmmc4ZyLS/uEgKVJIGFy1vD6nEB20WyJ6vY+wIjmBt6rMNrcHIU8QxwsbPoQGYANAYCO Rn+jVjXlaIAAafNePiu2OQlt7eS6USoY5BLCQ5/hznvyRkXx3XNhA7qcVc+DNX09wmnI xRznZT0ftVACWrDQgqPX9EHrjPjjUQfx3JsCMfNIYbEuNC7JE9lCA2B4FbticwAb45jp RLWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e18-v6si9257444pgt.3.2018.05.15.01.53.21; Tue, 15 May 2018 01:53:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752594AbeEOIwn (ORCPT + 99 others); Tue, 15 May 2018 04:52:43 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:5583 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752414AbeEOIwg (ORCPT ); Tue, 15 May 2018 04:52:36 -0400 X-UUID: 9167e1c3025a4b1cbf31da8911ffdabf-20180515 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2037901974; Tue, 15 May 2018 16:52:33 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 15 May 2018 16:52:32 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1210.3 via Frontend Transport; Tue, 15 May 2018 16:52:33 +0800 From: To: , , , CC: , , , , , Sean Wang Subject: [PATCH v2 5/7] Bluetooth: Extend btuart driver for join more vendor devices Date: Tue, 15 May 2018 16:52:20 +0800 Message-ID: <968e1361c99b892232d6777b776f4346b66cd8b8.1526374087.git.sean.wang@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Wang Adding an independent btuart.h header allows these essential definitions can be reused in vendor driver. Also, struct btuart_vnd is extended with additional callbacks such as .init initializing vendor data, .shtudown, .recv and .send supporting SoC specific framing for that btuart can simply adapt to various Bluetooth uart-based devices. Signed-off-by: Sean Wang --- drivers/bluetooth/btuart.c | 73 ++++++++++++++++++++++++---------------------- drivers/bluetooth/btuart.h | 30 +++++++++++++++++++ 2 files changed, 68 insertions(+), 35 deletions(-) create mode 100644 drivers/bluetooth/btuart.h diff --git a/drivers/bluetooth/btuart.c b/drivers/bluetooth/btuart.c index 03e980f..ab7f836 100644 --- a/drivers/bluetooth/btuart.c +++ b/drivers/bluetooth/btuart.c @@ -33,35 +33,11 @@ #include #include "h4_recv.h" +#include "btuart.h" #include "btbcm.h" #define VERSION "1.0" -struct btuart_vnd { - const struct h4_recv_pkt *recv_pkts; - int recv_pkts_cnt; - unsigned int manufacturer; - int (*open)(struct hci_dev *hdev); - int (*close)(struct hci_dev *hdev); - int (*setup)(struct hci_dev *hdev); -}; - -struct btuart_dev { - struct hci_dev *hdev; - struct serdev_device *serdev; - - struct work_struct tx_work; - unsigned long tx_state; - struct sk_buff_head txq; - - struct sk_buff *rx_skb; - - const struct btuart_vnd *vnd; -}; - -#define BTUART_TX_STATE_ACTIVE 1 -#define BTUART_TX_STATE_WAKEUP 2 - static void btuart_tx_work(struct work_struct *work) { struct btuart_dev *bdev = container_of(work, struct btuart_dev, @@ -187,13 +163,27 @@ static int btuart_setup(struct hci_dev *hdev) return 0; } +static int btuart_shutdown(struct hci_dev *hdev) +{ + struct btuart_dev *bdev = hci_get_drvdata(hdev); + + if (bdev->vnd->shutdown) + return bdev->vnd->shutdown(hdev); + + return 0; +} + static int btuart_send_frame(struct hci_dev *hdev, struct sk_buff *skb) { struct btuart_dev *bdev = hci_get_drvdata(hdev); - /* Prepend skb with frame type */ - memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); - skb_queue_tail(&bdev->txq, skb); + if (bdev->vnd->send) { + bdev->vnd->send(hdev, skb); + } else { + /* Prepend skb with frame type */ + memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1); + skb_queue_tail(&bdev->txq, skb); + } btuart_tx_wakeup(bdev); return 0; @@ -204,14 +194,23 @@ static int btuart_receive_buf(struct serdev_device *serdev, const u8 *data, { struct btuart_dev *bdev = serdev_device_get_drvdata(serdev); const struct btuart_vnd *vnd = bdev->vnd; + int err; - bdev->rx_skb = h4_recv_buf(bdev->hdev, bdev->rx_skb, data, count, - vnd->recv_pkts, vnd->recv_pkts_cnt); - if (IS_ERR(bdev->rx_skb)) { - int err = PTR_ERR(bdev->rx_skb); - bt_dev_err(bdev->hdev, "Frame reassembly failed (%d)", err); - bdev->rx_skb = NULL; - return err; + if (bdev->vnd->recv) { + err = bdev->vnd->recv(bdev->hdev, data, count); + if (err < 0) + return err; + } else { + bdev->rx_skb = h4_recv_buf(bdev->hdev, bdev->rx_skb, + data, count, vnd->recv_pkts, + vnd->recv_pkts_cnt); + if (IS_ERR(bdev->rx_skb)) { + err = PTR_ERR(bdev->rx_skb); + bt_dev_err(bdev->hdev, + "Frame reassembly failed (%d)", err); + bdev->rx_skb = NULL; + return err; + } } bdev->hdev->stat.byte_rx += count; @@ -429,6 +428,9 @@ static int btuart_probe(struct serdev_device *serdev) if (!bdev->vnd) bdev->vnd = &default_vnd; + if (bdev->vnd->init) + bdev->data = bdev->vnd->init(&serdev->dev); + bdev->serdev = serdev; serdev_device_set_drvdata(serdev, bdev); @@ -460,6 +462,7 @@ static int btuart_probe(struct serdev_device *serdev) hdev->close = btuart_close; hdev->flush = btuart_flush; hdev->setup = btuart_setup; + hdev->shutdown = btuart_shutdown; hdev->send = btuart_send_frame; SET_HCIDEV_DEV(hdev, &serdev->dev); diff --git a/drivers/bluetooth/btuart.h b/drivers/bluetooth/btuart.h new file mode 100644 index 0000000..6c1fe31 --- /dev/null +++ b/drivers/bluetooth/btuart.h @@ -0,0 +1,30 @@ +struct btuart_vnd { + const struct h4_recv_pkt *recv_pkts; + int recv_pkts_cnt; + unsigned int manufacturer; + void *(*init)(struct device *dev); + + int (*open)(struct hci_dev *hdev); + int (*close)(struct hci_dev *hdev); + int (*setup)(struct hci_dev *hdev); + int (*shutdown)(struct hci_dev *hdev); + int (*send)(struct hci_dev *hdev, struct sk_buff *skb); + int (*recv)(struct hci_dev *hdev, const u8 *data, size_t count); +}; + +struct btuart_dev { + struct hci_dev *hdev; + struct serdev_device *serdev; + + struct work_struct tx_work; + unsigned long tx_state; + struct sk_buff_head txq; + + struct sk_buff *rx_skb; + + const struct btuart_vnd *vnd; + void *data; +}; + +#define BTUART_TX_STATE_ACTIVE 1 +#define BTUART_TX_STATE_WAKEUP 2 -- 2.7.4