2009-06-02 21:29:35

by Bing Zhao

[permalink] [raw]
Subject: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

This driver provides basic definitions and library functions to
support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
combo chip.

This patch incorporates a lot of comments given by
Nicolas Pitre <[email protected]>. Many thanks to Nicolas Pitre.

Signed-off-by: Rahul Tank <[email protected]>
Signed-off-by: Bing Zhao <[email protected]>
---
drivers/bluetooth/Kconfig | 12 +
drivers/bluetooth/Makefile | 3 +
drivers/bluetooth/btmrvl_drv.h | 138 ++++++++
drivers/bluetooth/btmrvl_main.c | 714 +++++++++++++++++++++++++++++++++++++++
4 files changed, 867 insertions(+), 0 deletions(-)
create mode 100644 drivers/bluetooth/btmrvl_drv.h
create mode 100644 drivers/bluetooth/btmrvl_main.c

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 1164837..b049a79 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -170,5 +170,17 @@ config BT_HCIVHCI
Say Y here to compile support for virtual HCI devices into the
kernel or say M to compile it as module (hci_vhci).

+config BT_MRVL
+ tristate "Marvell Bluetooth driver support"
+ select FW_LOADER
+ help
+ The core driver to support Marvell Bluetooth devices.
+
+ This driver is required if you want to support
+ Marvell Bluetooth devices, such as 8688.
+
+ Say Y here to compile Marvell Bluetooth driver
+ into the kernel or say M to compile it as module.
+
endmenu

diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 16930f9..3eff123 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -15,6 +15,9 @@ obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o

+btmrvl-objs := btmrvl_main.o
+obj-$(CONFIG_BT_MRVL) += btmrvl.o
+
hci_uart-y := hci_ldisc.o
hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o
hci_uart-$(CONFIG_BT_HCIUART_BCSP) += hci_bcsp.o
diff --git a/drivers/bluetooth/btmrvl_drv.h b/drivers/bluetooth/btmrvl_drv.h
new file mode 100644
index 0000000..9ad71f4
--- /dev/null
+++ b/drivers/bluetooth/btmrvl_drv.h
@@ -0,0 +1,138 @@
+/*
+ * Marvell Bluetooth driver: global definitions & declarations
+ *
+ * Copyright (C) 2009, Marvell International Ltd.
+ *
+ * This software file (the "File") is distributed by Marvell International
+ * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ * (the "License"). You may use, redistribute and/or modify this File in
+ * accordance with the terms and conditions of the License, a copy of which
+ * is available by writing to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+ * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ *
+ * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
+ * this warranty disclaimer.
+ *
+ */
+
+#ifndef _BTMRVL_DRV_H_
+#define _BTMRVL_DRV_H_
+
+#include <linux/kthread.h>
+#include <linux/bitops.h>
+#include <net/bluetooth/bluetooth.h>
+
+#define BTM_HEADER_LEN 4
+#define BTM_DEV_NAME_LEN 32
+#define BTM_UPLD_SIZE 2312
+
+/* Time to wait until Host Sleep state change in millisecond */
+#define WAIT_UNTIL_HS_STATE_CHANGED 5000
+/* Time to wait for command response in millisecond */
+#define WAIT_UNTIL_CMD_RESP 5000
+
+struct btmrvl_thread {
+ struct task_struct *task;
+ wait_queue_head_t wait_q;
+ void *priv;
+};
+
+struct btmrvl_device {
+ char name[BTM_DEV_NAME_LEN];
+ void *card;
+ struct hci_dev *hcidev;
+
+ u8 tx_dnld_rdy;
+
+ u8 psmode;
+ u8 pscmd;
+ u8 hsmode;
+ u8 hscmd;
+
+ /* Low byte is gap, high byte is GPIO */
+ u16 gpio_gap;
+
+ u8 hscfgcmd;
+ u8 sendcmdflag;
+};
+
+struct btmrvl_adapter {
+ u32 int_count;
+ struct sk_buff_head tx_queue;
+ u8 psmode;
+ u8 ps_state;
+ u8 hs_state;
+ u8 wakeup_tries;
+ wait_queue_head_t cmd_wait_q;
+ u8 cmd_complete;
+};
+
+struct btmrvl_private {
+ struct btmrvl_device btmrvl_dev;
+ struct btmrvl_adapter *adapter;
+ struct btmrvl_thread main_thread;
+ int (*hw_host_to_card) (struct btmrvl_private *priv,
+ u8 *payload, u16 nb);
+ int (*hw_wakeup_firmware) (struct btmrvl_private *priv);
+ spinlock_t driver_lock; /* spinlock used by driver */
+};
+
+#define MRVL_VENDOR_PKT 0xFE
+
+/* Bluetooth commands */
+#define BT_CMD_AUTO_SLEEP_MODE 0x23
+#define BT_CMD_HOST_SLEEP_CONFIG 0x59
+#define BT_CMD_HOST_SLEEP_ENABLE 0x5A
+#define BT_CMD_MODULE_CFG_REQ 0x5B
+
+/* Sub-commands: Module Bringup/Shutdown Request */
+#define MODULE_BRINGUP_REQ 0xF1
+#define MODULE_SHUTDOWN_REQ 0xF2
+
+#define BT_EVENT_POWER_STATE 0x20
+
+/* Bluetooth Power States */
+#define BT_PS_ENABLE 0x02
+#define BT_PS_DISABLE 0x03
+#define BT_PS_SLEEP 0x01
+
+#define OGF 0x3F
+
+/* Host Sleep states */
+#define HS_ACTIVATED 0x01
+#define HS_DEACTIVATED 0x00
+
+/* Power Save modes */
+#define PS_SLEEP 0x01
+#define PS_AWAKE 0x00
+
+struct btmrvl_cmd {
+ __le16 ocf_ogf;
+ u8 length;
+ u8 data[4];
+} __attribute__ ((packed));
+
+struct btmrvl_event {
+ u8 ec; /* event counter */
+ u8 length;
+ u8 data[4];
+} __attribute__ ((packed));
+
+/* Prototype of global function */
+
+struct btmrvl_private *btmrvl_add_card(void *card);
+int btmrvl_remove_card(struct btmrvl_private *priv);
+
+void btmrvl_interrupt(struct btmrvl_private *priv);
+
+void btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb);
+int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb);
+
+int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd);
+int btmrvl_prepare_command(struct btmrvl_private *priv);
+
+#endif /* _BTMRVL_DRV_H_ */
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
new file mode 100644
index 0000000..11c2f2c
--- /dev/null
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -0,0 +1,714 @@
+/**
+ * Marvell Bluetooth driver
+ *
+ * Copyright (C) 2009, Marvell International Ltd.
+ *
+ * This software file (the "File") is distributed by Marvell International
+ * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ * (the "License"). You may use, redistribute and/or modify this File in
+ * accordance with the terms and conditions of the License, a copy of which
+ * is available by writing to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+ * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ *
+ * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
+ * this warranty disclaimer.
+ **/
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+
+#include "btmrvl_drv.h"
+
+#define VERSION "1.0"
+
+/*
+ * This function is called by interface specific interrupt handler.
+ * It updates Power Save & Host Sleep states, and wakes up the main
+ * thread.
+ */
+void btmrvl_interrupt(struct btmrvl_private *priv)
+{
+ BT_DBG("Enter");
+
+ priv->adapter->ps_state = PS_AWAKE;
+
+ priv->adapter->wakeup_tries = 0;
+
+ priv->adapter->int_count++;
+
+ wake_up_interruptible(&priv->main_thread.wait_q);
+
+ BT_DBG("Leave");
+}
+EXPORT_SYMBOL_GPL(btmrvl_interrupt);
+
+void btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb)
+{
+ struct hci_event_hdr *hdr = (struct hci_event_hdr *)skb->data;
+ struct hci_ev_cmd_complete *ec;
+ u16 opcode, ocf;
+
+ BT_DBG("Enter");
+
+ if (hdr->evt == HCI_EV_CMD_COMPLETE) {
+ ec = (struct hci_ev_cmd_complete *)(skb->data +
+ HCI_EVENT_HDR_SIZE);
+ opcode = __le16_to_cpu(ec->opcode);
+ ocf = hci_opcode_ocf(opcode);
+ if ((ocf == BT_CMD_MODULE_CFG_REQ) &&
+ (priv->btmrvl_dev.sendcmdflag)) {
+ priv->btmrvl_dev.sendcmdflag = false;
+ priv->adapter->cmd_complete = true;
+ wake_up_interruptible(&priv->adapter->cmd_wait_q);
+ }
+ }
+
+ BT_DBG("Leave");
+}
+EXPORT_SYMBOL_GPL(btmrvl_check_evtpkt);
+
+int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb)
+{
+ struct btmrvl_adapter *adapter = priv->adapter;
+ u8 ret = 0;
+ struct btmrvl_event *event;
+
+ BT_DBG("Enter");
+
+ event = (struct btmrvl_event *) skb->data;
+ if (event->ec != 0xff) {
+ BT_DBG("Not Marvell Event=%x", event->ec);
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ switch (event->data[0]) {
+ case BT_CMD_AUTO_SLEEP_MODE:
+ if (!event->data[2]) {
+ if (event->data[1] == BT_PS_ENABLE)
+ adapter->psmode = 1;
+ else
+ adapter->psmode = 0;
+ BT_DBG("PS Mode:%s",
+ (adapter->psmode) ? "Enable" : "Disable");
+ } else {
+ BT_DBG("PS Mode command failed");
+ }
+ break;
+
+ case BT_CMD_HOST_SLEEP_CONFIG:
+ if (!event->data[3])
+ BT_DBG("gpio=%x, gap=%x", event->data[1],
+ event->data[2]);
+ else
+ BT_DBG("HSCFG command failed");
+ break;
+
+ case BT_CMD_HOST_SLEEP_ENABLE:
+ if (!event->data[1]) {
+ adapter->hs_state = HS_ACTIVATED;
+ if (adapter->psmode)
+ adapter->ps_state = PS_SLEEP;
+ wake_up_interruptible(&adapter->cmd_wait_q);
+ BT_DBG("HS ACTIVATED!");
+ } else {
+ BT_DBG("HS Enable failed");
+ }
+ break;
+
+ case BT_CMD_MODULE_CFG_REQ:
+ if ((priv->btmrvl_dev.sendcmdflag) &&
+ (event->data[1] == MODULE_BRINGUP_REQ)) {
+ BT_DBG("EVENT:%s", (event->data[2]) ?
+ "Bring-up failed" : "Bring-up succeed");
+ } else if ((priv->btmrvl_dev.sendcmdflag) &&
+ (event->data[1] == MODULE_SHUTDOWN_REQ)) {
+ BT_DBG("EVENT:%s", (event->data[2]) ?
+ "Shutdown failed" : "Shutdown succeed");
+ } else {
+ BT_DBG("BT_CMD_MODULE_CFG_REQ resp for APP");
+ ret = -EINVAL;
+ }
+ break;
+
+ case BT_EVENT_POWER_STATE:
+ if (event->data[1] == BT_PS_SLEEP)
+ adapter->ps_state = PS_SLEEP;
+ BT_DBG("EVENT:%s",
+ (adapter->ps_state) ? "PS_SLEEP" : "PS_AWAKE");
+ break;
+
+ default:
+ BT_DBG("Unknown Event=%d", event->data[0]);
+ ret = -EINVAL;
+ break;
+ }
+
+exit:
+ if (!ret)
+ kfree_skb(skb);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(btmrvl_process_event);
+
+int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btmrvl_cmd *cmd;
+
+ BT_DBG("Enter");
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ BT_ERR("No free skb");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btmrvl_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) | BT_CMD_MODULE_CFG_REQ);
+ cmd->length = 1;
+ cmd->data[0] = subcmd;
+
+ bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
+
+ skb_put(skb, sizeof(*cmd));
+ skb->dev = (void *)priv->btmrvl_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ priv->btmrvl_dev.sendcmdflag = true;
+
+ priv->adapter->cmd_complete = false;
+
+ BT_DBG("Queue module cfg Command");
+
+ wake_up_interruptible(&priv->main_thread.wait_q);
+
+ if (!wait_event_interruptible_timeout(
+ priv->adapter->cmd_wait_q,
+ priv->adapter->cmd_complete,
+ msecs_to_jiffies(WAIT_UNTIL_CMD_RESP))) {
+ ret = -ETIMEDOUT;
+ BT_ERR("module_cfg_cmd(%x): timeout: %d",
+ subcmd, priv->btmrvl_dev.sendcmdflag);
+ }
+
+ BT_DBG("module cfg Command done");
+
+exit:
+ BT_DBG("Leave");
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(btmrvl_send_module_cfg_cmd);
+
+static int btmrvl_enable_hs(struct btmrvl_private *priv)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btmrvl_cmd *cmd;
+
+ BT_DBG("Enter");
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ BT_ERR("No free skb");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btmrvl_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) | BT_CMD_HOST_SLEEP_ENABLE);
+ cmd->length = 0;
+
+ bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
+
+ skb_put(skb, sizeof(*cmd));
+ skb->dev = (void *)priv->btmrvl_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ BT_DBG("Queue hs enable Command");
+
+ wake_up_interruptible(&priv->main_thread.wait_q);
+
+ if (!wait_event_interruptible_timeout(
+ priv->adapter->cmd_wait_q,
+ priv->adapter->hs_state,
+ msecs_to_jiffies(WAIT_UNTIL_HS_STATE_CHANGED))) {
+ ret = -ETIMEDOUT;
+ BT_ERR("timeout: %d, %d,%d",
+ priv->adapter->hs_state,
+ priv->adapter->ps_state,
+ priv->adapter->wakeup_tries);
+ }
+
+exit:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+int btmrvl_prepare_command(struct btmrvl_private *priv)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btmrvl_cmd *cmd;
+
+ BT_DBG("Enter");
+
+ if (priv->btmrvl_dev.hscfgcmd) {
+ priv->btmrvl_dev.hscfgcmd = 0;
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ BT_ERR("No free skb");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btmrvl_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) |
+ BT_CMD_HOST_SLEEP_CONFIG);
+ cmd->length = 2;
+ cmd->data[0] = (priv->btmrvl_dev.gpio_gap & 0xff00) >> 8;
+ cmd->data[1] = (u8) (priv->btmrvl_dev.gpio_gap & 0x00ff);
+
+ bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
+
+ skb_put(skb, sizeof(*cmd));
+ skb->dev = (void *)priv->btmrvl_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ BT_DBG("Queue HSCFG Command, gpio=0x%x, gap=0x%x",
+ cmd->data[0], cmd->data[1]);
+ }
+
+ if (priv->btmrvl_dev.pscmd) {
+ priv->btmrvl_dev.pscmd = 0;
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ BT_ERR("No free skb");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btmrvl_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) |
+ BT_CMD_AUTO_SLEEP_MODE);
+ cmd->length = 1;
+
+ if (priv->btmrvl_dev.psmode)
+ cmd->data[0] = BT_PS_ENABLE;
+ else
+ cmd->data[0] = BT_PS_DISABLE;
+
+ bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
+
+ skb_put(skb, sizeof(*cmd));
+ skb->dev = (void *)priv->btmrvl_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ BT_DBG("Queue PSMODE Command:%d", cmd->data[0]);
+ }
+
+ if (priv->btmrvl_dev.hscmd) {
+ priv->btmrvl_dev.hscmd = 0;
+
+ if (priv->btmrvl_dev.hsmode) {
+ ret = btmrvl_enable_hs(priv);
+ } else {
+ ret = priv->hw_wakeup_firmware(priv);
+ priv->adapter->hs_state = HS_DEACTIVATED;
+ }
+ }
+
+exit:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_tx_pkt(struct btmrvl_private *priv, struct sk_buff *skb)
+{
+ u8 ret = 0;
+
+ BT_DBG("Enter");
+
+ if (!skb || !skb->data) {
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ if (!skb->len || ((skb->len + BTM_HEADER_LEN) > BTM_UPLD_SIZE)) {
+ BT_ERR("Tx Error: Bad skb length %d : %d",
+ skb->len, BTM_UPLD_SIZE);
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ if (skb_headroom(skb) < BTM_HEADER_LEN) {
+ struct sk_buff *tmp = skb;
+
+ skb = skb_realloc_headroom(skb, BTM_HEADER_LEN);
+ if (!skb) {
+ BT_ERR("Tx Error: realloc_headroom failed %d",
+ BTM_HEADER_LEN);
+ skb = tmp;
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ kfree_skb(tmp);
+ }
+
+ skb_push(skb, BTM_HEADER_LEN);
+
+ /* header type: byte[3]
+ * HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor
+ * header length: byte[2][1][0]
+ */
+
+ skb->data[0] = (skb->len & 0x0000ff);
+ skb->data[1] = (skb->len & 0x00ff00) >> 8;
+ skb->data[2] = (skb->len & 0xff0000) >> 16;
+ skb->data[3] = bt_cb(skb)->pkt_type;
+
+ if (priv->hw_host_to_card)
+ ret = priv->hw_host_to_card(priv, skb->data, skb->len);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static void btmrvl_init_adapter(struct btmrvl_private *priv)
+{
+ BT_DBG("Enter");
+
+ skb_queue_head_init(&priv->adapter->tx_queue);
+
+ priv->adapter->ps_state = PS_AWAKE;
+
+ init_waitqueue_head(&priv->adapter->cmd_wait_q);
+
+ BT_DBG("Leave");
+}
+
+static void btmrvl_free_adapter(struct btmrvl_private *priv)
+{
+ BT_DBG("Enter");
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ kfree(priv->adapter);
+
+ priv->adapter = NULL;
+
+ BT_DBG("Leave");
+}
+
+static int
+btmrvl_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
+{
+ BT_DBG("Enter");
+
+ BT_DBG("Leave");
+
+ return -ENOIOCTLCMD;
+}
+
+static void btmrvl_destruct(struct hci_dev *hdev)
+{
+ BT_DBG("Enter");
+
+ BT_DBG("Leave");
+}
+
+static int btmrvl_send_frame(struct sk_buff *skb)
+{
+ struct hci_dev *hdev = (struct hci_dev *)skb->dev;
+ struct btmrvl_private *priv = NULL;
+
+ BT_DBG("Enter: type=%d, len=%d", skb->pkt_type, skb->len);
+
+ if (!hdev || !hdev->driver_data) {
+ BT_ERR("Frame for unknown HCI device");
+ BT_DBG("Leave");
+ return -ENODEV;
+ }
+
+ priv = (struct btmrvl_private *)hdev->driver_data;
+ if (!test_bit(HCI_RUNNING, &hdev->flags)) {
+ BT_ERR("Failed testing HCI_RUNING, flags=%lx", hdev->flags);
+ print_hex_dump_bytes("data: ", DUMP_PREFIX_OFFSET,
+ skb->data, skb->len);
+ BT_DBG("Leave");
+ return -EBUSY;
+ }
+
+ switch (bt_cb(skb)->pkt_type) {
+ case HCI_COMMAND_PKT:
+ hdev->stat.cmd_tx++;
+ break;
+
+ case HCI_ACLDATA_PKT:
+ hdev->stat.acl_tx++;
+ break;
+
+ case HCI_SCODATA_PKT:
+ hdev->stat.sco_tx++;
+ break;
+ }
+
+ skb_queue_tail(&priv->adapter->tx_queue, skb);
+
+ wake_up_interruptible(&priv->main_thread.wait_q);
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static int btmrvl_flush(struct hci_dev *hdev)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) hdev->driver_data;
+
+ BT_DBG("Enter");
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static int btmrvl_close(struct hci_dev *hdev)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) hdev->driver_data;
+
+ BT_DBG("Enter");
+
+ if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) {
+ BT_DBG("Leave");
+ return 0;
+ }
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static int btmrvl_open(struct hci_dev *hdev)
+{
+ BT_DBG("Enter");
+
+ set_bit(HCI_RUNNING, &hdev->flags);
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+/*
+ * This function handles the event generated by firmware, rx data
+ * received from firmware, and tx data sent from kernel.
+ */
+static int btmrvl_service_main_thread(void *data)
+{
+ struct btmrvl_thread *thread = data;
+ struct btmrvl_private *priv = thread->priv;
+ struct btmrvl_adapter *adapter = priv->adapter;
+ wait_queue_t wait;
+ struct sk_buff *skb;
+ ulong flags;
+
+ BT_DBG("Enter");
+
+ init_waitqueue_entry(&wait, current);
+
+ current->flags |= PF_NOFREEZE;
+
+ for (;;) {
+ add_wait_queue(&thread->wait_q, &wait);
+
+ set_current_state(TASK_INTERRUPTIBLE);
+
+ if (adapter->wakeup_tries ||
+ ((!adapter->int_count) &&
+ (!priv->btmrvl_dev.tx_dnld_rdy ||
+ skb_queue_empty(&adapter->tx_queue)))) {
+ BT_DBG("main_thread is sleeping...");
+ schedule();
+ }
+
+ set_current_state(TASK_RUNNING);
+
+ remove_wait_queue(&thread->wait_q, &wait);
+
+ BT_DBG("main_thread woke up");
+
+ if (kthread_should_stop()) {
+ BT_DBG("main_thread: break from main thread");
+ break;
+ }
+
+ spin_lock_irqsave(&priv->driver_lock, flags);
+ if (adapter->int_count) {
+ adapter->int_count = 0;
+ } else if ((adapter->ps_state == PS_SLEEP) &&
+ !skb_queue_empty(&adapter->tx_queue)) {
+ spin_unlock_irqrestore(&priv->driver_lock, flags);
+ adapter->wakeup_tries++;
+ priv->hw_wakeup_firmware(priv);
+ continue;
+ }
+ spin_unlock_irqrestore(&priv->driver_lock, flags);
+
+ if (adapter->ps_state == PS_SLEEP)
+ continue;
+
+ if (!priv->btmrvl_dev.tx_dnld_rdy)
+ continue;
+
+ skb = skb_dequeue(&adapter->tx_queue);
+ if (skb) {
+ if (btmrvl_tx_pkt(priv, skb))
+ priv->btmrvl_dev.hcidev->stat.err_tx++;
+ else
+ priv->btmrvl_dev.hcidev->stat.byte_tx
+ += skb->len;
+
+ kfree_skb(skb);
+ }
+ }
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+struct btmrvl_private *btmrvl_add_card(void *card)
+{
+ struct hci_dev *hdev = NULL;
+ struct btmrvl_private *priv = NULL;
+ int ret;
+
+ BT_DBG("Enter");
+
+ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv) {
+ BT_ERR("Can not allocate priv");
+ goto err_priv;
+ }
+
+ priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
+ if (!priv->adapter) {
+ BT_ERR("Allocate buffer for btmrvl_adapter failed!");
+ goto err_adapter;
+ }
+
+ btmrvl_init_adapter(priv);
+
+ hdev = hci_alloc_dev();
+ if (!hdev) {
+ BT_ERR("Can not allocate HCI device");
+ goto err_hdev;
+ }
+
+ BT_DBG("Starting kthread...");
+ priv->main_thread.priv = priv;
+ spin_lock_init(&priv->driver_lock);
+
+ init_waitqueue_head(&priv->main_thread.wait_q);
+ priv->main_thread.task = kthread_run(btmrvl_service_main_thread,
+ &priv->main_thread, "btmrvl_main_service");
+
+ priv->btmrvl_dev.hcidev = hdev;
+ priv->btmrvl_dev.card = card;
+
+ hdev->driver_data = priv;
+
+ priv->btmrvl_dev.tx_dnld_rdy = true;
+
+ hdev->type = HCI_SDIO;
+ hdev->open = btmrvl_open;
+ hdev->close = btmrvl_close;
+ hdev->flush = btmrvl_flush;
+ hdev->send = btmrvl_send_frame;
+ hdev->destruct = btmrvl_destruct;
+ hdev->ioctl = btmrvl_ioctl;
+ hdev->owner = THIS_MODULE;
+
+ ret = hci_register_dev(hdev);
+ if (ret < 0) {
+ BT_ERR("Can not register HCI device");
+ goto err_hci_register_dev;
+ }
+
+ BT_DBG("Leave");
+ return priv;
+
+err_hci_register_dev:
+ /* Stop the thread servicing the interrupts */
+ kthread_stop(priv->main_thread.task);
+
+ hci_free_dev(hdev);
+
+err_hdev:
+ btmrvl_free_adapter(priv);
+
+err_adapter:
+ kfree(priv);
+
+err_priv:
+ BT_DBG("Leave");
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(btmrvl_add_card);
+
+int btmrvl_remove_card(struct btmrvl_private *priv)
+{
+ struct hci_dev *hdev;
+
+ BT_DBG("Enter");
+
+ hdev = priv->btmrvl_dev.hcidev;
+
+ wake_up_interruptible(&priv->adapter->cmd_wait_q);
+
+ kthread_stop(priv->main_thread.task);
+
+ hci_unregister_dev(hdev);
+
+ hci_free_dev(hdev);
+
+ priv->btmrvl_dev.hcidev = NULL;
+
+ btmrvl_free_adapter(priv);
+
+ kfree(priv);
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(btmrvl_remove_card);
+
+MODULE_AUTHOR("Marvell International Ltd.");
+MODULE_DESCRIPTION("Marvell Bluetooth Driver v" VERSION);
+MODULE_VERSION(VERSION);
+MODULE_LICENSE("GPL v2");
--
1.5.3.6



2009-06-16 00:02:19

by Bing Zhao

[permalink] [raw]
Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Marcel,

> -----Original Message-----
> From: Marcel Holtmann [mailto:[email protected]]
> Sent: Friday, June 12, 2009 11:24 PM
> To: Bing Zhao
> Cc: [email protected]
> Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marve=
ll bluetooth devices
>=20
> Hi Bing,
>=20
> > > > > > This driver provides basic definitions and library functions to
> > > > > > support Marvell Bluetooth enabled devices, such as 88W8688 WLAN=
/BT
> > > > > > combo chip.
> > > > >
> > > > > so I created a bluetooth-mrvl-2.6 tree with your patches and alre=
ady a
> > > > > major collection of cleanup patches.
> > > >
> > > > Thanks for the cleanups.
> > > >
> > > > > The biggest problem right now is that your driver spits out casti=
ng
> > > > > warnings like crazy. This is not acceptable. So please send me a =
patch
> > > > > to fix these based on bluetooth-mrvl-2.6.
> > > >
> > > > Could you please let me know how to catch these casting warnings? I=
'm using GCC 4.3.2 with
> sparse
> > > on x86 laptop (Fedora 8) but I couldn't get the warnings.
> > >
> > > let me guess, you are running a 32-bit kernel. Just run a 64-bit kern=
el
> > > and you will see them. I am using Fedora 10.
> >
> > Yes, I'm running 32-bit kernel. I'll try to install a 64-bit system and=
fix those warnings.
>=20
> seriously don't do that. There is so many 32-bit stuff in the code that
> I am afraid it will fall over on 64-bit machines. I have cleaned up
> almost everything, but in btmrvl_sdio.c you have some nasty alignment
> thing going on. Please fix that and test it on 64-bit systems since it
> looks really scary.

Thanks for the code cleanup. I'm ordering a new laptop for 64-bit developme=
nt/debugging. I'll work on the alignment issues once my 64-bit system is re=
ady.

> Can you explain how the firmware loading process is suppose to work. The
> code looks way too complicated for what I can make out of it. We have to
> make this more readable.

There are two steps involving firmware downloading.
1) helper downloading; 2) firmware downloading through helper.

The helper is small size of image that needs to be downloaded first. The wh=
ole image data is cut to multiple trunks which will be written (CMD53) to c=
ard consecutively. Each trunk has fixed size of 124 bytes of helper image p=
lus 4 bytes of header (totaling 128 bytes or 2 blocks with block size 64). =
After all image data is downloaded an EOF block (1 block) is written to car=
d to finish the helper downloading. The helper gets initialized afterwards.

After helper is downloaded, firmware downloading process starts. The firmwa=
re image data is also cut to multiple trunks for CMD53. But the size of eve=
ry trunk is not fixed. Each trunk size is determined by the helper. The dri=
ver communicates with helper to get the trunk size and then download the re=
quested image to the card.

> > The whole btmrvl driver was ported from Marvell SD8688 Bluetooth refere=
nce driver. The Enter/Leave
> debug messages have been in there since very beginning. Sometimes these E=
nter/Leave things are useful
> for customers to debug when our reference driver is ported onto their own=
platform/OS.
> >
> >
> > To make it easier to upstream kernel, I'm sending a patch to remove all=
Enter/Leave debug messages
> except for an Enter message with parameters passed in.
>=20
> I removed them by myself since your patch was breaking with my cleanups.
> It is pushed now and to please test the latest bluetooth-mrvl-2.6.git
> tree.

Thanks. I'll pull the latest code.

> > > And again, after that you are not done since the whole driver needs m=
ore
> > > cleanups. That is just in a shape I consider merging it upstream so w=
e
> > > can start fixing it there. I still consider it a little bit too
> > > complicated for what is really needed to drive your hardware.
> >
> > That's understood. Several items are remaining:
> >
> > 1) Proper handling of vendor commands/events
> > 2) "rmmod" flag in exit_module()
> > 3) more cleanups
> >
> > Should you have any suggestions on any of these, I'd be happy to try.
>=20
> I will work with you on them, but first we have to fix this alignment
> mess. So please go through your SDIO code and run it also on a 64-bit
> system.

Will do.

Thanks,

Bing

> Regards
>=20
> Marcel
>=20

2009-06-13 06:24:03

by Marcel Holtmann

[permalink] [raw]
Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Bing,

> > > > > This driver provides basic definitions and library functions to
> > > > > support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
> > > > > combo chip.
> > > >
> > > > so I created a bluetooth-mrvl-2.6 tree with your patches and already a
> > > > major collection of cleanup patches.
> > >
> > > Thanks for the cleanups.
> > >
> > > > The biggest problem right now is that your driver spits out casting
> > > > warnings like crazy. This is not acceptable. So please send me a patch
> > > > to fix these based on bluetooth-mrvl-2.6.
> > >
> > > Could you please let me know how to catch these casting warnings? I'm using GCC 4.3.2 with sparse
> > on x86 laptop (Fedora 8) but I couldn't get the warnings.
> >
> > let me guess, you are running a 32-bit kernel. Just run a 64-bit kernel
> > and you will see them. I am using Fedora 10.
>
> Yes, I'm running 32-bit kernel. I'll try to install a 64-bit system and fix those warnings.

seriously don't do that. There is so many 32-bit stuff in the code that
I am afraid it will fall over on 64-bit machines. I have cleaned up
almost everything, but in btmrvl_sdio.c you have some nasty alignment
thing going on. Please fix that and test it on 64-bit systems since it
looks really scary.

Can you explain how the firmware loading process is suppose to work. The
code looks way too complicated for what I can make out of it. We have to
make this more readable.

> The whole btmrvl driver was ported from Marvell SD8688 Bluetooth reference driver. The Enter/Leave debug messages have been in there since very beginning. Sometimes these Enter/Leave things are useful for customers to debug when our reference driver is ported onto their own platform/OS.
>
>
> To make it easier to upstream kernel, I'm sending a patch to remove all Enter/Leave debug messages except for an Enter message with parameters passed in.

I removed them by myself since your patch was breaking with my cleanups.
It is pushed now and to please test the latest bluetooth-mrvl-2.6.git
tree.

> > And again, after that you are not done since the whole driver needs more
> > cleanups. That is just in a shape I consider merging it upstream so we
> > can start fixing it there. I still consider it a little bit too
> > complicated for what is really needed to drive your hardware.
>
> That's understood. Several items are remaining:
>
> 1) Proper handling of vendor commands/events
> 2) "rmmod" flag in exit_module()
> 3) more cleanups
>
> Should you have any suggestions on any of these, I'd be happy to try.

I will work with you on them, but first we have to fix this alignment
mess. So please go through your SDIO code and run it also on a 64-bit
system.

Regards

Marcel



2009-06-10 21:18:30

by Bing Zhao

[permalink] [raw]
Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Marcel,

> -----Original Message-----
> From: Marcel Holtmann [mailto:[email protected]]
> Sent: Wednesday, June 10, 2009 12:07 AM
> To: Bing Zhao
> Cc: [email protected]
> Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marve=
ll bluetooth devices
>
> Hi Bing,
>
> > > > This driver provides basic definitions and library functions to
> > > > support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
> > > > combo chip.
> > >
> > > so I created a bluetooth-mrvl-2.6 tree with your patches and already =
a
> > > major collection of cleanup patches.
> >
> > Thanks for the cleanups.
> >
> > > The biggest problem right now is that your driver spits out casting
> > > warnings like crazy. This is not acceptable. So please send me a patc=
h
> > > to fix these based on bluetooth-mrvl-2.6.
> >
> > Could you please let me know how to catch these casting warnings? I'm u=
sing GCC 4.3.2 with sparse
> on x86 laptop (Fedora 8) but I couldn't get the warnings.
>
> let me guess, you are running a 32-bit kernel. Just run a 64-bit kernel
> and you will see them. I am using Fedora 10.

Yes, I'm running 32-bit kernel. I'll try to install a 64-bit system and fix=
those warnings.

> I also have to compile this at least on one big endian machine. Will use
> my Quad G5 once I get home.
>
> > > I did fix the firmware non-sense you had in there, but I haven't had
> > > time to test it with real hardware. So please do so.
> >
> > Thanks for the fix and it works well.
>
> Good. I wasn't sure I did this right. Stupid driver_data is unsigned
> long and that requires casting :(
>
> > > Also I am considering to just remove all this Enter/Leave debug
> > > non-sense since it makes the code really hard to read.
> >
> > I can remove those Enter/Leave debug, if you prefer.
>
> Tell me what you need them for. I don't mind having the Enter part with
> BT_DBG since we are using that anyway to print debug information about
> the parameters we give to a function, but the Leave part is cluttering
> the code. Can you just follow the style the other drivers are using.

The whole btmrvl driver was ported from Marvell SD8688 Bluetooth reference =
driver. The Enter/Leave debug messages have been in there since very beginn=
ing. Sometimes these Enter/Leave things are useful for customers to debug w=
hen our reference driver is ported onto their own platform/OS.


To make it easier to upstream kernel, I'm sending a patch to remove all Ent=
er/Leave debug messages except for an Enter message with parameters passed =
in.

> And again, after that you are not done since the whole driver needs more
> cleanups. That is just in a shape I consider merging it upstream so we
> can start fixing it there. I still consider it a little bit too
> complicated for what is really needed to drive your hardware.

That's understood. Several items are remaining:

1) Proper handling of vendor commands/events
2) "rmmod" flag in exit_module()
3) more cleanups

Should you have any suggestions on any of these, I'd be happy to try.

> Regards
>
> Marcel
>


patch against bluetooth-mrvl-2.6.git tree:

>From 638a2d6f2dba0e1e23d2e2a61a15c48c36fd6b25 Mon Sep 17 00:00:00 2001
From: Bing Zhao <[email protected]>
Date: Tue, 9 Jun 2009 19:20:19 -0700
Subject: [PATCH] Bluetooth: Remove Enter/Leave debug messages for Marvell d=
river

Signed-off-by: Bing Zhao <[email protected]>
---

drivers/bluetooth/btmrvl_main.c | 84 +----------------------------
drivers/bluetooth/btmrvl_sdio.c | 110 +----------------------------------=
---
2 files changed, 6 insertions(+), 188 deletions(-)

diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_mai=
n.c
index 61168ec..c344300 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -32,8 +32,6 @@
*/
void btmrvl_interrupt(struct btmrvl_private *priv)
{
- BT_DBG("Enter");
-
priv->adapter->ps_state =3D PS_AWAKE;

priv->adapter->wakeup_tries =3D 0;
@@ -41,8 +39,6 @@ void btmrvl_interrupt(struct btmrvl_private *priv)
priv->adapter->int_count++;

wake_up_interruptible(&priv->main_thread.wait_q);
-
- BT_DBG("Leave");
}
EXPORT_SYMBOL_GPL(btmrvl_interrupt);

@@ -52,8 +48,6 @@ void btmrvl_check_evtpkt(struct btmrvl_private *priv, str=
uct sk_buff *skb)
struct hci_ev_cmd_complete *ec;
u16 opcode, ocf;

- BT_DBG("Enter");
-
if (hdr->evt =3D=3D HCI_EV_CMD_COMPLETE) {
ec =3D (void *) (skb->data + HCI_EVENT_HDR_SIZE);
opcode =3D __le16_to_cpu(ec->opcode);
@@ -65,8 +59,6 @@ void btmrvl_check_evtpkt(struct btmrvl_private *priv, str=
uct sk_buff *skb)
wake_up_interruptible(&priv->adapter->cmd_wait_q);
}
}
-
- BT_DBG("Leave");
}
EXPORT_SYMBOL_GPL(btmrvl_check_evtpkt);

@@ -76,8 +68,6 @@ int btmrvl_process_event(struct btmrvl_private *priv, str=
uct sk_buff *skb)
struct btmrvl_event *event;
u8 ret =3D 0;

- BT_DBG("Enter");
-
event =3D (struct btmrvl_event *) skb->data;
if (event->ec !=3D 0xff) {
BT_DBG("Not Marvell Event=3D%x", event->ec);
@@ -151,8 +141,6 @@ exit:
if (!ret)
kfree_skb(skb);

- BT_DBG("Leave");
-
return ret;
}
EXPORT_SYMBOL_GPL(btmrvl_process_event);
@@ -163,8 +151,6 @@ int btmrvl_send_module_cfg_cmd(struct btmrvl_private *p=
riv, int subcmd)
struct btmrvl_cmd *cmd;
u8 ret =3D 0;

- BT_DBG("Enter");
-
skb =3D bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
if (skb =3D=3D NULL) {
BT_ERR("No free skb");
@@ -202,8 +188,6 @@ int btmrvl_send_module_cfg_cmd(struct btmrvl_private *p=
riv, int subcmd)
BT_DBG("module cfg Command done");

exit:
- BT_DBG("Leave");
-
return ret;
}
EXPORT_SYMBOL_GPL(btmrvl_send_module_cfg_cmd);
@@ -214,8 +198,6 @@ static int btmrvl_enable_hs(struct btmrvl_private *priv=
)
struct btmrvl_cmd *cmd;
u8 ret =3D 0;

- BT_DBG("Enter");
-
skb =3D bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
if (skb =3D=3D NULL) {
BT_ERR("No free skb");
@@ -247,8 +229,6 @@ static int btmrvl_enable_hs(struct btmrvl_private *priv=
)
}

exit:
- BT_DBG("Leave");
-
return ret;
}

@@ -258,8 +238,6 @@ int btmrvl_prepare_command(struct btmrvl_private *priv)
struct btmrvl_cmd *cmd;
u8 ret =3D 0;

- BT_DBG("Enter");
-
if (priv->btmrvl_dev.hscfgcmd) {
priv->btmrvl_dev.hscfgcmd =3D 0;

@@ -328,8 +306,6 @@ int btmrvl_prepare_command(struct btmrvl_private *priv)
}

exit:
- BT_DBG("Leave");
-
return ret;
}

@@ -337,17 +313,12 @@ static int btmrvl_tx_pkt(struct btmrvl_private *priv,=
struct sk_buff *skb)
{
u8 ret =3D 0;

- BT_DBG("Enter");
-
- if (!skb || !skb->data) {
- BT_DBG("Leave");
+ if (!skb || !skb->data)
return -EINVAL;
- }

if (!skb->len || ((skb->len + BTM_HEADER_LEN) > BTM_UPLD_SIZE)) {
BT_ERR("Tx Error: Bad skb length %d : %d",
skb->len, BTM_UPLD_SIZE);
- BT_DBG("Leave");
return -EINVAL;
}

@@ -359,7 +330,6 @@ static int btmrvl_tx_pkt(struct btmrvl_private *priv, s=
truct sk_buff *skb)
BT_ERR("Tx Error: realloc_headroom failed %d",
BTM_HEADER_LEN);
skb =3D tmp;
- BT_DBG("Leave");
return -EINVAL;
}

@@ -381,52 +351,35 @@ static int btmrvl_tx_pkt(struct btmrvl_private *priv,=
struct sk_buff *skb)
if (priv->hw_host_to_card)
ret =3D priv->hw_host_to_card(priv, skb->data, skb->len);

- BT_DBG("Leave");
-
return ret;
}

static void btmrvl_init_adapter(struct btmrvl_private *priv)
{
- BT_DBG("Enter");
-
skb_queue_head_init(&priv->adapter->tx_queue);

priv->adapter->ps_state =3D PS_AWAKE;

init_waitqueue_head(&priv->adapter->cmd_wait_q);
-
- BT_DBG("Leave");
}

static void btmrvl_free_adapter(struct btmrvl_private *priv)
{
- BT_DBG("Enter");
-
skb_queue_purge(&priv->adapter->tx_queue);

kfree(priv->adapter);

priv->adapter =3D NULL;
-
- BT_DBG("Leave");
}

static int btmrvl_ioctl(struct hci_dev *hdev,
unsigned int cmd, unsigned long arg)
{
- BT_DBG("Enter");
-
- BT_DBG("Leave");
-
return -ENOIOCTLCMD;
}

static void btmrvl_destruct(struct hci_dev *hdev)
{
- BT_DBG("Enter");
-
- BT_DBG("Leave");
}

static int btmrvl_send_frame(struct sk_buff *skb)
@@ -434,11 +387,10 @@ static int btmrvl_send_frame(struct sk_buff *skb)
struct hci_dev *hdev =3D (struct hci_dev *) skb->dev;
struct btmrvl_private *priv =3D NULL;

- BT_DBG("Enter: type=3D%d, len=3D%d", skb->pkt_type, skb->len);
+ BT_DBG("packet type=3D%d, len=3D%d", skb->pkt_type, skb->len);

if (!hdev || !hdev->driver_data) {
BT_ERR("Frame for unknown HCI device");
- BT_DBG("Leave");
return -ENODEV;
}

@@ -447,7 +399,6 @@ static int btmrvl_send_frame(struct sk_buff *skb)
BT_ERR("Failed testing HCI_RUNING, flags=3D%lx", hdev->flag=
s);
print_hex_dump_bytes("data: ", DUMP_PREFIX_OFFSET,
skb->data, skb->len=
);
- BT_DBG("Leave");
return -EBUSY;
}

@@ -469,8 +420,6 @@ static int btmrvl_send_frame(struct sk_buff *skb)

wake_up_interruptible(&priv->main_thread.wait_q);

- BT_DBG("Leave");
-
return 0;
}

@@ -478,12 +427,8 @@ static int btmrvl_flush(struct hci_dev *hdev)
{
struct btmrvl_private *priv =3D hdev->driver_data;

- BT_DBG("Enter");
-
skb_queue_purge(&priv->adapter->tx_queue);

- BT_DBG("Leave");
-
return 0;
}

@@ -491,28 +436,18 @@ static int btmrvl_close(struct hci_dev *hdev)
{
struct btmrvl_private *priv =3D hdev->driver_data;

- BT_DBG("Enter");
-
- if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) {
- BT_DBG("Leave");
+ if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
return 0;
- }

skb_queue_purge(&priv->adapter->tx_queue);

- BT_DBG("Leave");
-
return 0;
}

static int btmrvl_open(struct hci_dev *hdev)
{
- BT_DBG("Enter");
-
set_bit(HCI_RUNNING, &hdev->flags);

- BT_DBG("Leave");
-
return 0;
}

@@ -529,8 +464,6 @@ static int btmrvl_service_main_thread(void *data)
struct sk_buff *skb;
ulong flags;

- BT_DBG("Enter");
-
init_waitqueue_entry(&wait, current);

current->flags |=3D PF_NOFREEZE;
@@ -588,8 +521,6 @@ static int btmrvl_service_main_thread(void *data)
}
}

- BT_DBG("Leave");
-
return 0;
}

@@ -599,8 +530,6 @@ struct btmrvl_private *btmrvl_add_card(void *card)
struct btmrvl_private *priv;
int ret;

- BT_DBG("Enter");
-
priv =3D kzalloc(sizeof(*priv), GFP_KERNEL);
if (!priv) {
BT_ERR("Can not allocate priv");
@@ -655,7 +584,6 @@ struct btmrvl_private *btmrvl_add_card(void *card)
btmrvl_debugfs_init(hdev);
#endif

- BT_DBG("Leave");
return priv;

err_hci_register_dev:
@@ -671,8 +599,6 @@ err_adapter:
kfree(priv);

err_priv:
- BT_DBG("Leave");
-
return NULL;
}
EXPORT_SYMBOL_GPL(btmrvl_add_card);
@@ -681,8 +607,6 @@ int btmrvl_remove_card(struct btmrvl_private *priv)
{
struct hci_dev *hdev;

- BT_DBG("Enter");
-
hdev =3D priv->btmrvl_dev.hcidev;

wake_up_interruptible(&priv->adapter->cmd_wait_q);
@@ -703,8 +627,6 @@ int btmrvl_remove_card(struct btmrvl_private *priv)

kfree(priv);

- BT_DBG("Leave");
-
return 0;
}
EXPORT_SYMBOL_GPL(btmrvl_remove_card);
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdi=
o.c
index 0dea23e..9fc973f 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -67,14 +67,10 @@ static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_c=
ard *card)
u8 reg;
int ret;

- BT_DBG("Enter");
-
reg =3D sdio_readb(card->func, CARD_RX_UNIT_REG, &ret);
if (!ret)
card->rx_unit =3D reg;

- BT_DBG("Leave");
-
return ret;
}

@@ -83,8 +79,6 @@ static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_=
card *card, u16 *dat)
int ret;
u8 fws0, fws1;

- BT_DBG("Enter");
-
*dat =3D 0;

fws0 =3D sdio_readb(card->func, CARD_FW_STATUS0_REG, &ret);
@@ -92,15 +86,11 @@ static int btmrvl_sdio_read_fw_status(struct btmrvl_sdi=
o_card *card, u16 *dat)
if (!ret)
fws1 =3D sdio_readb(card->func, CARD_FW_STATUS1_REG, &ret);

- if (ret) {
- BT_DBG("Leave");
+ if (ret)
return -EIO;
- }

*dat =3D (((u16) fws1) << 8) | fws0;

- BT_DBG("Leave");
-
return 0;
}

@@ -109,14 +99,10 @@ static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_=
card *card, u16 *dat)
int ret;
u8 reg;

- BT_DBG("Enter");
-
reg =3D sdio_readb(card->func, CARD_RX_LEN_REG, &ret);
if (!ret)
*dat =3D (u16) reg << card->rx_unit;

- BT_DBG("Leave");
-
return ret;
}

@@ -125,16 +111,12 @@ static int btmrvl_sdio_enable_host_int_mask(struct bt=
mrvl_sdio_card *card,
{
int ret;

- BT_DBG("Enter");
-
sdio_writeb(card->func, mask, HOST_INT_MASK_REG, &ret);
if (ret) {
BT_ERR("Unable to enable the host interrupt!");
ret =3D -EIO;
}

- BT_DBG("Leave");
-
return ret;
}

@@ -144,8 +126,6 @@ static int btmrvl_sdio_disable_host_int_mask(struct btm=
rvl_sdio_card *card,
int ret;
u8 host_int_mask;

- BT_DBG("Enter");
-
host_int_mask =3D sdio_readb(card->func, HOST_INT_MASK_REG, &ret);
if (ret) {
ret =3D -EIO;
@@ -164,8 +144,6 @@ static int btmrvl_sdio_disable_host_int_mask(struct btm=
rvl_sdio_card *card,
ret =3D 0;

done:
- BT_DBG("Leave");
-
return ret;
}

@@ -175,8 +153,6 @@ static int btmrvl_sdio_poll_card_status(struct btmrvl_s=
dio_card *card, u8 bits)
int ret;
u8 status;

- BT_DBG("Enter");
-
for (tries =3D 0; tries < MAX_POLL_TRIES * 1000; tries++) {
status =3D sdio_readb(card->func, CARD_STATUS_REG, &ret);
if (ret)
@@ -193,8 +169,6 @@ failed:
BT_ERR("FAILED! ret=3D%d", ret);

done:
- BT_DBG("Leave");
-
return ret;
}

@@ -205,8 +179,6 @@ static int btmrvl_sdio_verify_fw_download(struct btmrvl=
_sdio_card *card,
u16 firmwarestat;
unsigned int tries;

- BT_DBG("Enter");
-
/* Wait for firmware to become ready */
for (tries =3D 0; tries < pollnum; tries++) {
if (btmrvl_sdio_read_fw_status(card, &firmwarestat) < 0)
@@ -220,8 +192,6 @@ static int btmrvl_sdio_verify_fw_download(struct btmrvl=
_sdio_card *card,
}
}

- BT_DBG("Leave");
-
return ret;
}

@@ -235,8 +205,6 @@ static int btmrvl_sdio_download_helper(struct btmrvl_sd=
io_card *card)
u8 *helperbuf;
u32 tx_len;

- BT_DBG("Enter");
-
ret =3D request_firmware(&fw_helper, card->helper,
&card->func->dev);
if ((ret < 0) || !fw_helper) {
@@ -326,8 +294,6 @@ done:
if (fw_helper)
release_firmware(fw_helper);

- BT_DBG("Leave");
-
return ret;
}

@@ -343,8 +309,6 @@ static int btmrvl_sdio_download_fw_w_helper(struct btmr=
vl_sdio_card *card)
u16 len;
int txlen =3D 0, tx_blocks =3D 0, count =3D 0;

- BT_DBG("Enter");
-
ret =3D request_firmware(&fw_firmware, card->firmware,
&card->func->dev);
if ((ret < 0) || !fw_firmware) {
@@ -479,8 +443,6 @@ done:
if (fw_firmware)
release_firmware(fw_firmware);

- BT_DBG("Leave");
-
return ret;
}

@@ -494,8 +456,6 @@ static int btmrvl_sdio_card_to_host(struct btmrvl_priva=
te *priv)
struct hci_dev *hdev =3D priv->btmrvl_dev.hcidev;
struct btmrvl_sdio_card *card =3D priv->btmrvl_dev.card;

- BT_DBG("Enter");
-
if (!card || !card->func) {
BT_ERR("card or function is NULL!");
ret =3D -EINVAL;
@@ -596,8 +556,6 @@ exit:
kfree_skb(skb);
}

- BT_DBG("Leave");
-
return ret;
}

@@ -607,8 +565,6 @@ static int btmrvl_sdio_get_int_status(struct btmrvl_pri=
vate *priv, u8 * ireg)
u8 sdio_ireg =3D 0;
struct btmrvl_sdio_card *card =3D priv->btmrvl_dev.card;

- BT_DBG("Enter");
-
*ireg =3D 0;

sdio_ireg =3D sdio_readb(card->func, HOST_INTSTATUS_REG, &ret);
@@ -653,8 +609,6 @@ static int btmrvl_sdio_get_int_status(struct btmrvl_pri=
vate *priv, u8 * ireg)
ret =3D 0;

done:
- BT_DBG("Leave");
-
return ret;
}

@@ -665,8 +619,6 @@ static void btmrvl_sdio_interrupt(struct sdio_func *fun=
c)
struct btmrvl_sdio_card *card;
u8 ireg =3D 0;

- BT_DBG("Enter");
-
card =3D sdio_get_drvdata(func);
if (card && card->priv) {
priv =3D card->priv;
@@ -679,8 +631,6 @@ static void btmrvl_sdio_interrupt(struct sdio_func *fun=
c)

btmrvl_interrupt(priv);
}
-
- BT_DBG("Leave");
}

static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
@@ -689,8 +639,6 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_=
card *card)
u8 reg;
int ret =3D 0;

- BT_DBG("Enter");
-
if (!card || !card->func) {
BT_ERR("Error: card or function is NULL!");
ret =3D -EINVAL;
@@ -752,7 +700,6 @@ static int btmrvl_sdio_register_dev(struct btmrvl_sdio_=
card *card)

sdio_release_host(func);

- BT_DBG("Leave");
return 0;

release_irq:
@@ -765,14 +712,11 @@ release_host:
sdio_release_host(func);

failed:
- BT_DBG("Leave");
return ret;
}

static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card *card)
{
- BT_DBG("Enter");
-
if (card && card->func) {
sdio_claim_host(card->func);
sdio_release_irq(card->func);
@@ -781,8 +725,6 @@ static int btmrvl_sdio_unregister_dev(struct btmrvl_sdi=
o_card *card)
sdio_set_drvdata(card->func, NULL);
}

- BT_DBG("Leave");
-
return 0;
}

@@ -790,12 +732,8 @@ static int btmrvl_sdio_enable_host_int(struct btmrvl_s=
dio_card *card)
{
int ret;

- BT_DBG("Enter");
-
- if (!card || !card->func) {
- BT_DBG("Leave");
+ if (!card || !card->func)
return -EINVAL;
- }

sdio_claim_host(card->func);

@@ -805,8 +743,6 @@ static int btmrvl_sdio_enable_host_int(struct btmrvl_sd=
io_card *card)

sdio_release_host(card->func);

- BT_DBG("Leave");
-
return ret;
}

@@ -814,12 +750,8 @@ static int btmrvl_sdio_disable_host_int(struct btmrvl_=
sdio_card *card)
{
int ret;

- BT_DBG("Enter");
-
- if (!card || !card->func) {
- BT_DBG("Leave");
+ if (!card || !card->func)
return -EINVAL;
- }

sdio_claim_host(card->func);

@@ -827,8 +759,6 @@ static int btmrvl_sdio_disable_host_int(struct btmrvl_s=
dio_card *card)

sdio_release_host(card->func);

- BT_DBG("Leave");
-
return ret;
}

@@ -844,11 +774,8 @@ static int btmrvl_sdio_host_to_card(struct btmrvl_priv=
ate *priv,
void *tmpbuf =3D NULL;
int tmpbufsz;

- BT_DBG("Enter");
-
if (!card || !card->func) {
BT_ERR("card or function is NULL!");
- BT_DBG("Leave");
return -EINVAL;
}

@@ -886,8 +813,6 @@ static int btmrvl_sdio_host_to_card(struct btmrvl_priva=
te *priv,
exit:
sdio_release_host(card->func);

- BT_DBG("Leave");
-
return ret;
}

@@ -895,11 +820,8 @@ static int btmrvl_sdio_download_fw(struct btmrvl_sdio_=
card *card)
{
int ret =3D 0;

- BT_DBG("Enter");
-
if (!card || !card->func) {
BT_ERR("card or function is NULL!");
- BT_DBG("Leave");
return -EINVAL;
}
sdio_claim_host(card->func);
@@ -931,8 +853,6 @@ static int btmrvl_sdio_download_fw(struct btmrvl_sdio_c=
ard *card)
done:
sdio_release_host(card->func);

- BT_DBG("Leave");
-
return ret;
}

@@ -941,11 +861,8 @@ static int btmrvl_sdio_wakeup_fw(struct btmrvl_private=
*priv)
struct btmrvl_sdio_card *card =3D priv->btmrvl_dev.card;
int ret =3D 0;

- BT_DBG("Enter");
-
if (!card || !card->func) {
BT_ERR("card or function is NULL!");
- BT_DBG("Leave");
return -EINVAL;
}

@@ -957,8 +874,6 @@ static int btmrvl_sdio_wakeup_fw(struct btmrvl_private =
*priv)

BT_DBG("wake up firmware");

- BT_DBG("Leave");
-
return ret;
}

@@ -969,8 +884,6 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
struct btmrvl_private *priv =3D NULL;
struct btmrvl_sdio_card *card =3D NULL;

- BT_DBG("Enter");
-
BT_INFO("vendor=3D0x%x, device=3D0x%x, class=3D%d, fn=3D%d",
id->vendor, id->device, id->class, func->num);

@@ -1025,8 +938,6 @@ static int btmrvl_sdio_probe(struct sdio_func *func,

btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);

- BT_DBG("Leave");
-
return 0;

disable_host_int:
@@ -1036,8 +947,6 @@ unreg_dev:
free_card:
kfree(card);
done:
- BT_DBG("Leave");
-
return ret;
}

@@ -1045,8 +954,6 @@ static void btmrvl_sdio_remove(struct sdio_func *func)
{
struct btmrvl_sdio_card *card;

- BT_DBG("Enter");
-
if (func) {
card =3D sdio_get_drvdata(func);
if (card) {
@@ -1064,8 +971,6 @@ static void btmrvl_sdio_remove(struct sdio_func *func)
kfree(card);
}
}
-
- BT_DBG("Leave");
}

static struct sdio_driver bt_mrvl_sdio =3D {
@@ -1077,32 +982,23 @@ static struct sdio_driver bt_mrvl_sdio =3D {

static int btmrvl_sdio_init_module(void)
{
- BT_DBG("Enter");
-
if (sdio_register_driver(&bt_mrvl_sdio) !=3D 0) {
BT_ERR("SDIO Driver Registration Failed");
- BT_DBG("Leave");
return -ENODEV;
}

/* Clear the flag in case user removes the card. */
user_rmmod =3D 0;

- BT_DBG("Leave");
-
return 0;
}

static void btmrvl_sdio_exit_module(void)
{
- BT_DBG("Enter");
-
/* Set the flag as user is removing this module. */
user_rmmod =3D 1;

sdio_unregister_driver(&bt_mrvl_sdio);
-
- BT_DBG("Leave");
}

module_init(btmrvl_sdio_init_module);
--
1.5.3.6




Thanks,

Bing

2009-06-10 07:07:23

by Marcel Holtmann

[permalink] [raw]
Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Bing,

> > > This driver provides basic definitions and library functions to
> > > support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
> > > combo chip.
> >
> > so I created a bluetooth-mrvl-2.6 tree with your patches and already a
> > major collection of cleanup patches.
>
> Thanks for the cleanups.
>
> > The biggest problem right now is that your driver spits out casting
> > warnings like crazy. This is not acceptable. So please send me a patch
> > to fix these based on bluetooth-mrvl-2.6.
>
> Could you please let me know how to catch these casting warnings? I'm using GCC 4.3.2 with sparse on x86 laptop (Fedora 8) but I couldn't get the warnings.

let me guess, you are running a 32-bit kernel. Just run a 64-bit kernel
and you will see them. I am using Fedora 10.

I also have to compile this at least on one big endian machine. Will use
my Quad G5 once I get home.

> > I did fix the firmware non-sense you had in there, but I haven't had
> > time to test it with real hardware. So please do so.
>
> Thanks for the fix and it works well.

Good. I wasn't sure I did this right. Stupid driver_data is unsigned
long and that requires casting :(

> > Also I am considering to just remove all this Enter/Leave debug
> > non-sense since it makes the code really hard to read.
>
> I can remove those Enter/Leave debug, if you prefer.

Tell me what you need them for. I don't mind having the Enter part with
BT_DBG since we are using that anyway to print debug information about
the parameters we give to a function, but the Leave part is cluttering
the code. Can you just follow the style the other drivers are using.

And again, after that you are not done since the whole driver needs more
cleanups. That is just in a shape I consider merging it upstream so we
can start fixing it there. I still consider it a little bit too
complicated for what is really needed to drive your hardware.

Regards

Marcel



2009-06-09 23:39:23

by Bing Zhao

[permalink] [raw]
Subject: RE: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Marcel,

> -----Original Message-----
> From: Marcel Holtmann [mailto:[email protected]]
> Sent: Tuesday, June 09, 2009 8:20 AM
> To: Bing Zhao
> Cc: [email protected]
> Subject: Re: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marve=
ll bluetooth devices
>=20
> Hi Bing,
>=20
> > This driver provides basic definitions and library functions to
> > support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
> > combo chip.
>=20
> so I created a bluetooth-mrvl-2.6 tree with your patches and already a
> major collection of cleanup patches.

Thanks for the cleanups.

> The biggest problem right now is that your driver spits out casting
> warnings like crazy. This is not acceptable. So please send me a patch
> to fix these based on bluetooth-mrvl-2.6.

Could you please let me know how to catch these casting warnings? I'm using=
GCC 4.3.2 with sparse on x86 laptop (Fedora 8) but I couldn't get the warn=
ings.

> I did fix the firmware non-sense you had in there, but I haven't had
> time to test it with real hardware. So please do so.

Thanks for the fix and it works well.

> Also I am considering to just remove all this Enter/Leave debug
> non-sense since it makes the code really hard to read.

I can remove those Enter/Leave debug, if you prefer.

> Regards
>=20
> Marcel
>=20

Thanks,

Bing

2009-06-09 15:20:07

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH 1/4 v3] bluetooth: add btmrvl driver to support Marvell bluetooth devices

Hi Bing,

> This driver provides basic definitions and library functions to
> support Marvell Bluetooth enabled devices, such as 88W8688 WLAN/BT
> combo chip.

so I created a bluetooth-mrvl-2.6 tree with your patches and already a
major collection of cleanup patches.

The biggest problem right now is that your driver spits out casting
warnings like crazy. This is not acceptable. So please send me a patch
to fix these based on bluetooth-mrvl-2.6.

I did fix the firmware non-sense you had in there, but I haven't had
time to test it with real hardware. So please do so.

Also I am considering to just remove all this Enter/Leave debug
non-sense since it makes the code really hard to read.

Regards

Marcel



2009-06-02 21:29:36

by Bing Zhao

[permalink] [raw]
Subject: [PATCH 2/4 v3] bluetooth: btmrvl_sdio: Marvell BT-over-SDIO driver

This driver supports Marvell Bluetooth enabled devices with SDIO
interface. Currently only SD8688 chip is supported.

The helper/firmware images of SD8688 can be downloaded from this tree:
git://git.infradead.org/users/dwmw2/linux-firmware.git

This patch incorporates a lot of comments given by
Nicolas Pitre <[email protected]>. Many thanks to Nicolas Pitre.

Signed-off-by: Rahul Tank <[email protected]>
Signed-off-by: Bing Zhao <[email protected]>
---
drivers/bluetooth/Kconfig | 13 +
drivers/bluetooth/Makefile | 1 +
drivers/bluetooth/btmrvl_sdio.c | 1128 +++++++++++++++++++++++++++++++++++++++
drivers/bluetooth/btmrvl_sdio.h | 113 ++++
4 files changed, 1255 insertions(+), 0 deletions(-)
create mode 100644 drivers/bluetooth/btmrvl_sdio.c
create mode 100644 drivers/bluetooth/btmrvl_sdio.h

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index b049a79..8c89bd4 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -182,5 +182,18 @@ config BT_MRVL
Say Y here to compile Marvell Bluetooth driver
into the kernel or say M to compile it as module.

+config BT_MRVL_SDIO
+ tristate "Marvell BT-over-SDIO driver"
+ depends on BT_MRVL && MMC
+ help
+ The driver for Marvell Bluetooth chipsets with SDIO interface.
+
+ This driver is required if you want to use Marvell Bluetooth
+ devices with SDIO interface. Currently only SD8688 chipset is
+ supported.
+
+ Say Y here to compile support for Marvell BT-over-SDIO driver
+ into the kernel or say M to compile it as module.
+
endmenu

diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 3eff123..2dc12e7 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o

btmrvl-objs := btmrvl_main.o
obj-$(CONFIG_BT_MRVL) += btmrvl.o
+obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o

hci_uart-y := hci_ldisc.o
hci_uart-$(CONFIG_BT_HCIUART_H4) += hci_h4.o
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
new file mode 100644
index 0000000..8f13e7b
--- /dev/null
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -0,0 +1,1128 @@
+/**
+ * Marvell BT-over-SDIO driver: SDIO interface related functions.
+ *
+ * Copyright (C) 2009, Marvell International Ltd.
+ *
+ * This software file (the "File") is distributed by Marvell International
+ * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ * (the "License"). You may use, redistribute and/or modify this File in
+ * accordance with the terms and conditions of the License, a copy of which
+ * is available by writing to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+ * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ *
+ * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
+ * this warranty disclaimer.
+ **/
+
+#include <linux/firmware.h>
+
+#include <linux/mmc/sdio_ids.h>
+#include <linux/mmc/sdio_func.h>
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+
+#include "btmrvl_drv.h"
+#include "btmrvl_sdio.h"
+
+#define VERSION "1.0"
+
+#ifndef SDIO_DEVICE_ID_MARVELL_8688BT
+#define SDIO_DEVICE_ID_MARVELL_8688BT 0x9105
+#endif
+
+/* The btmrvl_sdio_remove() callback function is called
+ * when user removes this module from kernel space or ejects
+ * the card from the slot. The driver handles these 2 cases
+ * differently.
+ * If the user is removing the module, a MODULE_SHUTDOWN_REQ
+ * command is sent to firmware and interrupt will be disabled.
+ * If the card is removed, there is no need to send command
+ * or disable interrupt.
+ *
+ * The variable 'user_rmmod' is used to distinguish these two
+ * scenarios. This flag is initialized as FALSE in case the card
+ * is removed, and will be set to TRUE for module removal when
+ * module_exit function is called.
+ */
+static u8 user_rmmod;
+
+static const struct sdio_device_id btmrvl_sdio_ids[] = {
+ {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8688BT)},
+ {0, 0, 0, 0}
+};
+
+MODULE_DEVICE_TABLE(sdio, btmrvl_sdio_ids);
+
+static struct btmrvl_sdio_device btmrvl_sdio_devices[] = {
+ {
+ .dev_id = SDIO_DEVICE_ID_MARVELL_8688BT,
+ .helper = "sd8688_helper.bin",
+ .firmware = "sd8688.bin",
+ },
+};
+
+static int btmrvl_sdio_get_rx_unit(struct btmrvl_sdio_card *card)
+{
+ u8 reg;
+ int ret;
+
+ BT_DBG("Enter");
+
+ reg = sdio_readb(card->func, CARD_RX_UNIT_REG, &ret);
+ if (!ret)
+ card->rx_unit = reg;
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_read_fw_status(struct btmrvl_sdio_card *card, u16 *dat)
+{
+ int ret;
+ u8 fws0, fws1;
+
+ BT_DBG("Enter");
+
+ *dat = 0;
+
+ fws0 = sdio_readb(card->func, CARD_FW_STATUS0_REG, &ret);
+
+ if (!ret)
+ fws1 = sdio_readb(card->func, CARD_FW_STATUS1_REG, &ret);
+
+ if (ret) {
+ BT_DBG("Leave");
+ return -EIO;
+ }
+
+ *dat = (((u16) fws1) << 8) | fws0;
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static int btmrvl_sdio_read_rx_len(struct btmrvl_sdio_card *card, u16 *dat)
+{
+ int ret;
+ u8 reg;
+
+ BT_DBG("Enter");
+
+ reg = sdio_readb(card->func, CARD_RX_LEN_REG, &ret);
+ if (!ret)
+ *dat = (u16) reg << card->rx_unit;
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_enable_host_int_mask(struct btmrvl_sdio_card *card,
+ u8 mask)
+{
+ int ret;
+
+ BT_DBG("Enter");
+
+ sdio_writeb(card->func, mask, HOST_INT_MASK_REG, &ret);
+ if (ret) {
+ BT_ERR("Unable to enable the host interrupt!");
+ ret = -EIO;
+ }
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_disable_host_int_mask(struct btmrvl_sdio_card *card,
+ u8 mask)
+{
+ int ret;
+ u8 host_int_mask;
+
+ BT_DBG("Enter");
+
+ host_int_mask = sdio_readb(card->func, HOST_INT_MASK_REG, &ret);
+ if (ret) {
+ ret = -EIO;
+ goto done;
+ }
+
+ host_int_mask &= ~mask;
+
+ sdio_writeb(card->func, host_int_mask, HOST_INT_MASK_REG, &ret);
+ if (ret < 0) {
+ BT_ERR("Unable to disable the host interrupt!");
+ ret = -EIO;
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_poll_card_status(struct btmrvl_sdio_card *card, u8 bits)
+{
+ unsigned int tries;
+ int ret;
+ u8 status;
+
+ BT_DBG("Enter");
+
+ for (tries = 0; tries < MAX_POLL_TRIES * 1000; tries++) {
+ status = sdio_readb(card->func, CARD_STATUS_REG, &ret);
+ if (ret)
+ goto failed;
+ if ((status & bits) == bits)
+ goto done;
+
+ udelay(1);
+ }
+
+ ret = -ETIMEDOUT;
+
+failed:
+ BT_ERR("FAILED! ret=%d", ret);
+
+done:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_verify_fw_download(struct btmrvl_sdio_card *card,
+ int pollnum)
+{
+ int ret = -ETIMEDOUT;
+ u16 firmwarestat;
+ unsigned int tries;
+
+ BT_DBG("Enter");
+
+ /* Wait for firmware to become ready */
+ for (tries = 0; tries < pollnum; tries++) {
+ if (btmrvl_sdio_read_fw_status(card, &firmwarestat) < 0)
+ continue;
+
+ if (firmwarestat == FIRMWARE_READY) {
+ ret = 0;
+ break;
+ } else {
+ msleep(10);
+ }
+ }
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_download_helper(struct btmrvl_sdio_card *card)
+{
+ const struct firmware *fw_helper = NULL;
+ const u8 *helper = NULL;
+ int ret;
+ void *tmphlprbuf = NULL;
+ int tmphlprbufsz, hlprblknow, helperlen;
+ u8 *helperbuf;
+ u32 tx_len;
+
+ BT_DBG("Enter");
+
+ ret = request_firmware(&fw_helper, card->helper,
+ &card->func->dev);
+ if ((ret < 0) || !fw_helper) {
+ BT_ERR("request_firmware(helper) failed, error code = %d",
+ ret);
+ ret = -ENOENT;
+ goto done;
+ }
+
+ helper = fw_helper->data;
+ helperlen = fw_helper->size;
+
+ BT_DBG("Downloading helper image (%d bytes), block size %d bytes",
+ helperlen, SDIO_BLOCK_SIZE);
+
+ tmphlprbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN);
+
+ tmphlprbuf = kmalloc(tmphlprbufsz, GFP_KERNEL);
+ if (!tmphlprbuf) {
+ BT_ERR("Unable to allocate buffer for helper."
+ " Terminating download");
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ memset(tmphlprbuf, 0, tmphlprbufsz);
+
+ helperbuf = (u8 *) ALIGN_ADDR(tmphlprbuf, BTSDIO_DMA_ALIGN);
+
+ /* Perform helper data transfer */
+ tx_len = (FIRMWARE_TRANSFER_NBLOCK * SDIO_BLOCK_SIZE)
+ - SDIO_HEADER_LEN;
+ hlprblknow = 0;
+
+ do {
+ ret = btmrvl_sdio_poll_card_status(card,
+ CARD_IO_READY | DN_LD_CARD_RDY);
+ if (ret < 0) {
+ BT_ERR("Helper download poll status timeout @ %d",
+ hlprblknow);
+ goto done;
+ }
+
+ /* Check if there is more data? */
+ if (hlprblknow >= helperlen)
+ break;
+
+ if (helperlen - hlprblknow < tx_len)
+ tx_len = helperlen - hlprblknow;
+
+ /* Little-endian */
+ helperbuf[0] = ((tx_len & 0x000000ff) >> 0);
+ helperbuf[1] = ((tx_len & 0x0000ff00) >> 8);
+ helperbuf[2] = ((tx_len & 0x00ff0000) >> 16);
+ helperbuf[3] = ((tx_len & 0xff000000) >> 24);
+
+ memcpy(&helperbuf[SDIO_HEADER_LEN], &helper[hlprblknow],
+ tx_len);
+
+ /* Now send the data */
+ ret = sdio_writesb(card->func, card->ioport,
+ helperbuf,
+ FIRMWARE_TRANSFER_NBLOCK *
+ SDIO_BLOCK_SIZE);
+ if (ret < 0) {
+ BT_ERR("IO error during helper download @ %d",
+ hlprblknow);
+ goto done;
+ }
+
+ hlprblknow += tx_len;
+ } while (true);
+
+ BT_DBG("Transferring helper image EOF block");
+
+ memset(helperbuf, 0x0, SDIO_BLOCK_SIZE);
+
+ ret = sdio_writesb(card->func, card->ioport, helperbuf,
+ SDIO_BLOCK_SIZE);
+ if (ret < 0) {
+ BT_ERR("IO error in writing helper image EOF block");
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ kfree(tmphlprbuf);
+ if (fw_helper)
+ release_firmware(fw_helper);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_download_fw_w_helper(struct btmrvl_sdio_card *card)
+{
+ const struct firmware *fw_firmware = NULL;
+ const u8 *firmware = NULL;
+ int firmwarelen, tmpfwbufsz, ret;
+ unsigned int tries, offset;
+ u8 base0, base1;
+ void *tmpfwbuf = NULL;
+ u8 *fwbuf;
+ u16 len;
+ int txlen = 0, tx_blocks = 0, count = 0;
+
+ BT_DBG("Enter");
+
+ ret = request_firmware(&fw_firmware, card->firmware,
+ &card->func->dev);
+ if ((ret < 0) || !fw_firmware) {
+ BT_ERR("request_firmware(firmware) failed, error code = %d",
+ ret);
+ ret = -ENOENT;
+ goto done;
+ }
+
+ firmware = fw_firmware->data;
+ firmwarelen = fw_firmware->size;
+
+ BT_DBG("Downloading FW image (%d bytes)", firmwarelen);
+
+ tmpfwbufsz = ALIGN_SZ(BTM_UPLD_SIZE, BTSDIO_DMA_ALIGN);
+ tmpfwbuf = kmalloc(tmpfwbufsz, GFP_KERNEL);
+ if (!tmpfwbuf) {
+ BT_ERR("Unable to allocate buffer for firmware."
+ " Terminating download");
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ memset(tmpfwbuf, 0, tmpfwbufsz);
+
+ /* Ensure aligned firmware buffer */
+ fwbuf = (u8 *) ALIGN_ADDR(tmpfwbuf, BTSDIO_DMA_ALIGN);
+
+ /* Perform firmware data transfer */
+ offset = 0;
+ do {
+ ret = btmrvl_sdio_poll_card_status(card,
+ CARD_IO_READY | DN_LD_CARD_RDY);
+ if (ret < 0) {
+ BT_ERR("FW download with helper poll status"
+ " timeout @ %d", offset);
+ goto done;
+ }
+
+ /* Check if there is more data ? */
+ if (offset >= firmwarelen)
+ break;
+
+ for (tries = 0; tries < MAX_POLL_TRIES; tries++) {
+ base0 = sdio_readb(card->func,
+ SQ_READ_BASE_ADDRESS_A0_REG, &ret);
+ if (ret) {
+ BT_ERR("BASE0 register read failed:"
+ " base0 = 0x%04X(%d)."
+ " Terminating download",
+ base0, base0);
+ ret = -EIO;
+ goto done;
+ }
+ base1 = sdio_readb(card->func,
+ SQ_READ_BASE_ADDRESS_A1_REG, &ret);
+ if (ret) {
+ BT_ERR("BASE1 register read failed:"
+ " base1 = 0x%04X(%d)."
+ " Terminating download",
+ base1, base1);
+ ret = -EIO;
+ goto done;
+ }
+
+ len = (((u16) base1) << 8) | base0;
+ if (len)
+ break;
+
+ udelay(10);
+ }
+
+ if (!len)
+ break;
+ else if (len > BTM_UPLD_SIZE) {
+ BT_ERR("FW download failure @%d, invalid length %d",
+ offset, len);
+ ret = -EINVAL;
+ goto done;
+ }
+
+ txlen = len;
+
+ if (len & BIT(0)) {
+ count++;
+ if (count > MAX_WRITE_IOMEM_RETRY) {
+ BT_ERR("FW download failure @%d, "
+ "over max retry count", offset);
+ ret = -EIO;
+ goto done;
+ }
+ BT_ERR("FW CRC error indicated by the helper: "
+ "len = 0x%04X, txlen = %d", len, txlen);
+ len &= ~BIT(0);
+ /* Set txlen to 0 so as to resend from same offset */
+ txlen = 0;
+ } else {
+ count = 0;
+
+ /* Last block ? */
+ if (firmwarelen - offset < txlen)
+ txlen = firmwarelen - offset;
+
+ tx_blocks =
+ (txlen + SDIO_BLOCK_SIZE - 1) / SDIO_BLOCK_SIZE;
+
+ memcpy(fwbuf, &firmware[offset], txlen);
+ }
+
+ ret = sdio_writesb(card->func, card->ioport, fwbuf,
+ tx_blocks * SDIO_BLOCK_SIZE);
+
+ if (ret < 0) {
+ BT_ERR("FW download, writesb(%d) failed @%d",
+ count, offset);
+ sdio_writeb(card->func, HOST_CMD53_FIN, CONFIG_REG,
+ &ret);
+ if (ret)
+ BT_ERR("writeb failed (CFG)");
+ }
+
+ offset += txlen;
+ } while (true);
+
+ BT_DBG("FW download over, size %d bytes", offset);
+
+ ret = 0;
+
+done:
+ kfree(tmpfwbuf);
+
+ if (fw_firmware)
+ release_firmware(fw_firmware);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_card_to_host(struct btmrvl_private *priv)
+{
+ u16 buf_len = 0;
+ int ret, buf_block_len, blksz;
+ struct sk_buff *skb = NULL;
+ u32 type;
+ u8 *payload = NULL;
+ struct hci_dev *hdev = priv->btmrvl_dev.hcidev;
+ struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_ERR("card or function is NULL!");
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ /* Read the length of data to be transferred */
+ ret = btmrvl_sdio_read_rx_len(card, &buf_len);
+ if (ret < 0) {
+ BT_ERR("read rx_len failed");
+ ret = -EIO;
+ goto exit;
+ }
+
+ blksz = SDIO_BLOCK_SIZE;
+ buf_block_len = (buf_len + blksz - 1) / blksz;
+
+ if (buf_len <= SDIO_HEADER_LEN
+ || (buf_block_len * blksz) > ALLOC_BUF_SIZE) {
+ BT_ERR("invalid packet length: %d", buf_len);
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ /* Allocate buffer */
+ skb = bt_skb_alloc(buf_block_len * blksz + BTSDIO_DMA_ALIGN,
+ GFP_ATOMIC);
+ if (skb == NULL) {
+ BT_ERR("No free skb");
+ goto exit;
+ }
+
+ if ((u32) skb->data & (BTSDIO_DMA_ALIGN - 1)) {
+ skb_put(skb, (u32) skb->data & (BTSDIO_DMA_ALIGN - 1));
+ skb_pull(skb, (u32) skb->data & (BTSDIO_DMA_ALIGN - 1));
+ }
+
+ payload = skb->tail;
+
+ ret = sdio_readsb(card->func, payload, card->ioport,
+ buf_block_len * blksz);
+ if (ret < 0) {
+ BT_ERR("readsb failed: %d", ret);
+ ret = -EIO;
+ goto exit;
+ }
+
+ /* This is SDIO specific header length: byte[2][1][0], type: byte[3]
+ * (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor)
+ */
+
+ buf_len = payload[0];
+ buf_len |= (u16) payload[1] << 8;
+ type = payload[3];
+
+ switch (type) {
+ case HCI_ACLDATA_PKT:
+ case HCI_SCODATA_PKT:
+ case HCI_EVENT_PKT:
+ bt_cb(skb)->pkt_type = type;
+ skb->dev = (void *)hdev;
+ skb_put(skb, buf_len);
+ skb_pull(skb, SDIO_HEADER_LEN);
+
+ if (type == HCI_EVENT_PKT)
+ btmrvl_check_evtpkt(priv, skb);
+
+ hci_recv_frame(skb);
+ hdev->stat.byte_rx += buf_len;
+ break;
+
+ case MRVL_VENDOR_PKT:
+ bt_cb(skb)->pkt_type = HCI_VENDOR_PKT;
+ skb->dev = (void *)hdev;
+ skb_put(skb, buf_len);
+ skb_pull(skb, SDIO_HEADER_LEN);
+
+ if (btmrvl_process_event(priv, skb))
+ hci_recv_frame(skb);
+
+ hdev->stat.byte_rx += buf_len;
+ break;
+
+ default:
+ BT_ERR("Unknow packet type:%d", type);
+ print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, payload,
+ blksz * buf_block_len);
+
+ kfree_skb(skb);
+ skb = NULL;
+ break;
+ }
+
+exit:
+ if (ret) {
+ hdev->stat.err_rx++;
+ if (skb)
+ kfree_skb(skb);
+ }
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_get_int_status(struct btmrvl_private *priv, u8 * ireg)
+{
+ int ret;
+ u8 sdio_ireg = 0;
+ struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
+
+ BT_DBG("Enter");
+
+ *ireg = 0;
+
+ sdio_ireg = sdio_readb(card->func, HOST_INTSTATUS_REG, &ret);
+ if (ret) {
+ BT_ERR("sdio_readb: read int status register failed");
+ ret = -EIO;
+ goto done;
+ }
+
+ if (sdio_ireg != 0) {
+ /*
+ * DN_LD_HOST_INT_STATUS and/or UP_LD_HOST_INT_STATUS
+ * Clear the interrupt status register and re-enable the
+ * interrupt.
+ */
+ BT_DBG("sdio_ireg = 0x%x", sdio_ireg);
+
+ sdio_writeb(card->func, ~(sdio_ireg) & (DN_LD_HOST_INT_STATUS |
+ UP_LD_HOST_INT_STATUS),
+ HOST_INTSTATUS_REG, &ret);
+ if (ret) {
+ BT_ERR("sdio_writeb: clear int status register "
+ "failed");
+ ret = -EIO;
+ goto done;
+ }
+ }
+
+ if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
+ if (priv->btmrvl_dev.tx_dnld_rdy)
+ BT_DBG("tx_done already received: "
+ " int_status=0x%x", sdio_ireg);
+ else
+ priv->btmrvl_dev.tx_dnld_rdy = true;
+ }
+
+ if (sdio_ireg & UP_LD_HOST_INT_STATUS)
+ btmrvl_sdio_card_to_host(priv);
+
+ *ireg = sdio_ireg;
+
+ ret = 0;
+
+done:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static void btmrvl_sdio_interrupt(struct sdio_func *func)
+{
+ struct btmrvl_private *priv;
+ struct hci_dev *hcidev;
+ struct btmrvl_sdio_card *card;
+ u8 ireg = 0;
+
+ BT_DBG("Enter");
+
+ card = sdio_get_drvdata(func);
+ if (card && card->priv) {
+ priv = card->priv;
+ hcidev = priv->btmrvl_dev.hcidev;
+
+ if (btmrvl_sdio_get_int_status(priv, &ireg))
+ BT_ERR("reading HOST_INT_STATUS_REG failed");
+ else
+ BT_DBG("HOST_INT_STATUS_REG %#x", ireg);
+
+ btmrvl_interrupt(priv);
+ }
+
+ BT_DBG("Leave");
+}
+
+static int btmrvl_sdio_register_dev(struct btmrvl_sdio_card *card)
+{
+ int ret = 0, i;
+ u8 reg;
+ struct sdio_func *func;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_ERR("Error: card or function is NULL!");
+ ret = -EINVAL;
+ goto failed;
+ }
+
+ func = card->func;
+
+ for (i = 0; i < ARRAY_SIZE(btmrvl_sdio_devices); i++) {
+ if (func->device == btmrvl_sdio_devices[i].dev_id)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(btmrvl_sdio_devices)) {
+ BT_ERR("Error: unknown device id 0x%x", func->device);
+ ret = -EINVAL;
+ goto failed;
+ }
+
+ card->helper = btmrvl_sdio_devices[i].helper;
+ card->firmware = btmrvl_sdio_devices[i].firmware;
+
+ sdio_claim_host(func);
+
+ ret = sdio_enable_func(func);
+ if (ret) {
+ BT_ERR("sdio_enable_func() failed: ret=%d", ret);
+ ret = -EIO;
+ goto release_host;
+ }
+
+ ret = sdio_claim_irq(func, btmrvl_sdio_interrupt);
+ if (ret) {
+ BT_ERR("sdio_claim_irq failed: ret=%d", ret);
+ ret = -EIO;
+ goto disable_func;
+ }
+
+ ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE);
+ if (ret) {
+ BT_ERR("cannot set SDIO block size");
+ ret = -EIO;
+ goto release_irq;
+ }
+
+ reg = sdio_readb(func, IO_PORT_0_REG, &ret);
+ if (ret < 0) {
+ ret = -EIO;
+ goto release_irq;
+ }
+
+ card->ioport = reg;
+
+ reg = sdio_readb(func, IO_PORT_1_REG, &ret);
+ if (ret < 0) {
+ ret = -EIO;
+ goto release_irq;
+ }
+
+ card->ioport |= (reg << 8);
+
+ reg = sdio_readb(func, IO_PORT_2_REG, &ret);
+ if (ret < 0) {
+ ret = -EIO;
+ goto release_irq;
+ }
+
+ card->ioport |= (reg << 16);
+
+ BT_DBG("SDIO FUNC%d IO port: 0x%x", func->num, card->ioport);
+
+ sdio_set_drvdata(func, card);
+
+ sdio_release_host(func);
+
+ BT_DBG("Leave");
+ return 0;
+
+release_irq:
+ sdio_release_irq(func);
+
+disable_func:
+ sdio_disable_func(func);
+
+release_host:
+ sdio_release_host(func);
+
+failed:
+ BT_DBG("Leave");
+ return ret;
+}
+
+static int btmrvl_sdio_unregister_dev(struct btmrvl_sdio_card *card)
+{
+ BT_DBG("Enter");
+
+ if (card && card->func) {
+ sdio_claim_host(card->func);
+ sdio_release_irq(card->func);
+ sdio_disable_func(card->func);
+ sdio_release_host(card->func);
+ sdio_set_drvdata(card->func, NULL);
+ }
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static int btmrvl_sdio_enable_host_int(struct btmrvl_sdio_card *card)
+{
+ int ret;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ ret = btmrvl_sdio_enable_host_int_mask(card, HIM_ENABLE);
+
+ btmrvl_sdio_get_rx_unit(card);
+
+ sdio_release_host(card->func);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_disable_host_int(struct btmrvl_sdio_card *card)
+{
+ int ret;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ ret = btmrvl_sdio_disable_host_int_mask(card, HIM_DISABLE);
+
+ sdio_release_host(card->func);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_host_to_card(struct btmrvl_private *priv,
+ u8 *payload, u16 nb)
+{
+ struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
+ int ret = 0;
+ int buf_block_len;
+ int blksz;
+ int i = 0;
+ u8 *buf = NULL;
+ void *tmpbuf = NULL;
+ int tmpbufsz;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_ERR("card or function is NULL!");
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ buf = payload;
+ if ((u32) payload & (BTSDIO_DMA_ALIGN - 1)) {
+ tmpbufsz = ALIGN_SZ(nb, BTSDIO_DMA_ALIGN);
+ tmpbuf = kmalloc(tmpbufsz, GFP_KERNEL);
+ memset(tmpbuf, 0, tmpbufsz);
+ buf = (u8 *) ALIGN_ADDR(tmpbuf, BTSDIO_DMA_ALIGN);
+ memcpy(buf, payload, nb);
+ }
+
+ blksz = SDIO_BLOCK_SIZE;
+ buf_block_len = (nb + blksz - 1) / blksz;
+
+ sdio_claim_host(card->func);
+
+ do {
+ /* Transfer data to card */
+ ret = sdio_writesb(card->func, card->ioport, buf,
+ buf_block_len * blksz);
+ if (ret < 0) {
+ i++;
+ BT_ERR("i=%d writesb failed: %d", i, ret);
+ print_hex_dump_bytes("", DUMP_PREFIX_OFFSET,
+ payload, nb);
+ ret = -EIO;
+ if (i > MAX_WRITE_IOMEM_RETRY)
+ goto exit;
+ }
+ } while (ret);
+
+ priv->btmrvl_dev.tx_dnld_rdy = false;
+
+exit:
+ sdio_release_host(card->func);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_download_fw(struct btmrvl_sdio_card *card)
+{
+ int ret = 0;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_ERR("card or function is NULL!");
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+ sdio_claim_host(card->func);
+
+ if (!btmrvl_sdio_verify_fw_download(card, 1)) {
+ BT_DBG("Firmware already downloaded!");
+ goto done;
+ }
+
+ ret = btmrvl_sdio_download_helper(card);
+ if (ret) {
+ BT_ERR("Failed to download helper!");
+ ret = -EIO;
+ goto done;
+ }
+
+ if (btmrvl_sdio_download_fw_w_helper(card)) {
+ BT_ERR("Failed to download firmware!");
+ ret = -EIO;
+ goto done;
+ }
+
+ if (btmrvl_sdio_verify_fw_download(card, MAX_POLL_TRIES)) {
+ BT_ERR("FW failed to be active in time!");
+ ret = -ETIMEDOUT;
+ goto done;
+ }
+
+done:
+ sdio_release_host(card->func);
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_wakeup_fw(struct btmrvl_private *priv)
+{
+ struct btmrvl_sdio_card *card = priv->btmrvl_dev.card;
+ int ret = 0;
+
+ BT_DBG("Enter");
+
+ if (!card || !card->func) {
+ BT_ERR("card or function is NULL!");
+ BT_DBG("Leave");
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ sdio_writeb(card->func, HOST_POWER_UP, CONFIG_REG, &ret);
+
+ sdio_release_host(card->func);
+
+ BT_DBG("wake up firmware");
+
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static int btmrvl_sdio_probe(struct sdio_func *func,
+ const struct sdio_device_id *id)
+{
+ int ret = 0;
+ struct btmrvl_private *priv = NULL;
+ struct btmrvl_sdio_card *card = NULL;
+
+ BT_DBG("Enter");
+
+ BT_INFO("vendor=0x%x, device=0x%x, class=%d, fn=%d",
+ id->vendor, id->device, id->class, func->num);
+
+ card = kzalloc(sizeof(*card), GFP_KERNEL);
+ if (!card) {
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ card->func = func;
+
+ if (btmrvl_sdio_register_dev(card) < 0) {
+ BT_ERR("Failed to register BT device!");
+ ret = -ENODEV;
+ goto free_card;
+ }
+
+ /* Disable the interrupts on the card */
+ btmrvl_sdio_disable_host_int(card);
+
+ if (btmrvl_sdio_download_fw(card)) {
+ BT_ERR("Downloading firmware failed!");
+ ret = -ENODEV;
+ goto unreg_dev;
+ }
+
+ msleep(100);
+
+ btmrvl_sdio_enable_host_int(card);
+
+ priv = btmrvl_add_card(card);
+ if (!priv) {
+ BT_ERR("Initializing card failed!");
+ ret = -ENODEV;
+ goto disable_host_int;
+ }
+
+ card->priv = priv;
+
+ /* Initialize the interface specific function pointers */
+ priv->hw_host_to_card = btmrvl_sdio_host_to_card;
+ priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw;
+
+ strncpy(priv->btmrvl_dev.name, "btmrvl_sdio0",
+ sizeof(priv->btmrvl_dev.name));
+
+ btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
+
+ BT_DBG("Leave");
+
+ return 0;
+
+disable_host_int:
+ btmrvl_sdio_disable_host_int(card);
+unreg_dev:
+ btmrvl_sdio_unregister_dev(card);
+free_card:
+ kfree(card);
+done:
+ BT_DBG("Leave");
+
+ return ret;
+}
+
+static void btmrvl_sdio_remove(struct sdio_func *func)
+{
+ struct btmrvl_sdio_card *card;
+
+ BT_DBG("Enter");
+
+ if (func) {
+ card = sdio_get_drvdata(func);
+ if (card) {
+ /* Send SHUTDOWN command & disable interrupt
+ * if user removes the module.
+ */
+ if (user_rmmod) {
+ btmrvl_send_module_cfg_cmd(card->priv,
+ MODULE_SHUTDOWN_REQ);
+ btmrvl_sdio_disable_host_int(card);
+ }
+ BT_DBG("unregester dev");
+ btmrvl_sdio_unregister_dev(card);
+ btmrvl_remove_card(card->priv);
+ kfree(card);
+ }
+ }
+
+ BT_DBG("Leave");
+}
+
+static struct sdio_driver bt_mrvl_sdio = {
+ .name = "btmrvl_sdio",
+ .id_table = btmrvl_sdio_ids,
+ .probe = btmrvl_sdio_probe,
+ .remove = btmrvl_sdio_remove,
+};
+
+static int btmrvl_sdio_init_module(void)
+{
+ BT_DBG("Enter");
+
+ if (sdio_register_driver(&bt_mrvl_sdio) != 0) {
+ BT_ERR("SDIO Driver Registration Failed");
+ BT_DBG("Leave");
+ return -ENODEV;
+ }
+
+ /* Clear the flag in case user removes the card. */
+ user_rmmod = 0;
+
+ BT_DBG("Leave");
+
+ return 0;
+}
+
+static void btmrvl_sdio_exit_module(void)
+{
+ BT_DBG("Enter");
+
+ /* Set the flag as user is removing this module. */
+ user_rmmod = 1;
+
+ sdio_unregister_driver(&bt_mrvl_sdio);
+
+ BT_DBG("Leave");
+}
+
+module_init(btmrvl_sdio_init_module);
+module_exit(btmrvl_sdio_exit_module);
+
+MODULE_AUTHOR("Marvell International Ltd.");
+MODULE_DESCRIPTION("Marvell BT-over-SDIO Driver v" VERSION);
+MODULE_VERSION(VERSION);
+MODULE_LICENSE("GPL v2");
diff --git a/drivers/bluetooth/btmrvl_sdio.h b/drivers/bluetooth/btmrvl_sdio.h
new file mode 100644
index 0000000..08bef33
--- /dev/null
+++ b/drivers/bluetooth/btmrvl_sdio.h
@@ -0,0 +1,113 @@
+/**
+ * Marvell BT-over-SDIO driver: SDIO interface related definitions
+ *
+ * Copyright (C) 2009, Marvell International Ltd.
+ *
+ * This software file (the "File") is distributed by Marvell International
+ * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ * (the "License"). You may use, redistribute and/or modify this File in
+ * accordance with the terms and conditions of the License, a copy of which
+ * is available by writing to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+ * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ *
+ * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
+ * this warranty disclaimer.
+ *
+ **/
+
+#ifndef _BTMRVL_SDIO_H_
+#define _BTMRVL_SDIO_H_
+
+#define SDIO_HEADER_LEN 4
+
+/* SD block size can not bigger than 64 due to buf size limit in firmware */
+/* define SD block size for data Tx/Rx */
+#define SDIO_BLOCK_SIZE 64
+
+/* Number of blocks for firmware transfer */
+#define FIRMWARE_TRANSFER_NBLOCK 2
+
+/* This is for firmware specific length */
+#define FW_EXTRA_LEN 36
+
+#define MRVDRV_SIZE_OF_CMD_BUFFER (2 * 1024)
+
+#define MRVDRV_BT_RX_PACKET_BUFFER_SIZE \
+ (HCI_MAX_FRAME_SIZE + FW_EXTRA_LEN)
+
+#define ALLOC_BUF_SIZE (((max_t (int, MRVDRV_BT_RX_PACKET_BUFFER_SIZE, \
+ MRVDRV_SIZE_OF_CMD_BUFFER) + SDIO_HEADER_LEN \
+ + SDIO_BLOCK_SIZE - 1) / SDIO_BLOCK_SIZE) \
+ * SDIO_BLOCK_SIZE)
+
+/* The number of times to try when polling for status */
+#define MAX_POLL_TRIES 100
+
+/* Max retry number of CMD53 write */
+#define MAX_WRITE_IOMEM_RETRY 2
+
+/* Host Control Registers */
+#define IO_PORT_0_REG 0x00
+#define IO_PORT_1_REG 0x01
+#define IO_PORT_2_REG 0x02
+
+#define CONFIG_REG 0x03
+#define HOST_POWER_UP BIT(1)
+#define HOST_CMD53_FIN BIT(2)
+
+#define HOST_INT_MASK_REG 0x04
+#define HIM_DISABLE 0xff
+#define HIM_ENABLE (BIT(0) | BIT(1))
+
+#define HOST_INTSTATUS_REG 0x05
+#define UP_LD_HOST_INT_STATUS BIT(0)
+#define DN_LD_HOST_INT_STATUS BIT(1)
+
+/* Card Control Registers */
+#define SQ_READ_BASE_ADDRESS_A0_REG 0x10
+#define SQ_READ_BASE_ADDRESS_A1_REG 0x11
+
+#define CARD_STATUS_REG 0x20
+#define DN_LD_CARD_RDY BIT(0)
+#define CARD_IO_READY BIT(3)
+
+#define CARD_FW_STATUS0_REG 0x40
+#define CARD_FW_STATUS1_REG 0x41
+#define FIRMWARE_READY 0xfedc
+
+#define CARD_RX_LEN_REG 0x42
+#define CARD_RX_UNIT_REG 0x43
+
+
+struct btmrvl_sdio_card {
+ struct sdio_func *func;
+ u32 ioport;
+ const char *helper;
+ const char *firmware;
+ u8 rx_unit;
+ struct btmrvl_private *priv;
+};
+
+struct btmrvl_sdio_device {
+ unsigned short dev_id;
+ const char *helper;
+ const char *firmware;
+};
+
+
+/* Platform specific DMA alignment */
+#define BTSDIO_DMA_ALIGN 8
+
+/* Macros for Data Alignment : size */
+#define ALIGN_SZ(p, a) \
+ (((p) + ((a) - 1)) & ~((a) - 1))
+
+/* Macros for Data Alignment : address */
+#define ALIGN_ADDR(p, a) \
+ ((((u32)(p)) + (((u32)(a)) - 1)) & ~(((u32)(a)) - 1))
+
+#endif /* _BTMRVL_SDIO_H_ */
--
1.5.3.6


2009-06-02 21:29:37

by Bing Zhao

[permalink] [raw]
Subject: [PATCH 3/4 v3] bluetooth: Add debugfs support to btmrvl driver

/debug/btmrvl/config/
/debug/btmrvl/status/

See Documentation/btmrvl.txt for details.

This patch incorporates a lot of comments given by
Nicolas Pitre <[email protected]>. Many thanks to Nicolas Pitre.

Signed-off-by: Rahul Tank <[email protected]>
Signed-off-by: Bing Zhao <[email protected]>
---
drivers/bluetooth/Kconfig | 1 +
drivers/bluetooth/Makefile | 2 +-
drivers/bluetooth/btmrvl_debugfs.c | 469 ++++++++++++++++++++++++++++++++++++
drivers/bluetooth/btmrvl_drv.h | 8 +
drivers/bluetooth/btmrvl_main.c | 8 +
5 files changed, 487 insertions(+), 1 deletions(-)
create mode 100644 drivers/bluetooth/btmrvl_debugfs.c

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 8c89bd4..5f04014 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -173,6 +173,7 @@ config BT_HCIVHCI
config BT_MRVL
tristate "Marvell Bluetooth driver support"
select FW_LOADER
+ select DEBUG_FS
help
The core driver to support Marvell Bluetooth devices.

diff --git a/drivers/bluetooth/Makefile b/drivers/bluetooth/Makefile
index 2dc12e7..75f70e0 100644
--- a/drivers/bluetooth/Makefile
+++ b/drivers/bluetooth/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_BT_HCIBTUART) += btuart_cs.o
obj-$(CONFIG_BT_HCIBTUSB) += btusb.o
obj-$(CONFIG_BT_HCIBTSDIO) += btsdio.o

-btmrvl-objs := btmrvl_main.o
+btmrvl-objs := btmrvl_main.o btmrvl_debugfs.o
obj-$(CONFIG_BT_MRVL) += btmrvl.o
obj-$(CONFIG_BT_MRVL_SDIO) += btmrvl_sdio.o

diff --git a/drivers/bluetooth/btmrvl_debugfs.c b/drivers/bluetooth/btmrvl_debugfs.c
new file mode 100644
index 0000000..747bb0c
--- /dev/null
+++ b/drivers/bluetooth/btmrvl_debugfs.c
@@ -0,0 +1,469 @@
+/**
+ * Marvell Bluetooth driver: debugfs related functions
+ *
+ * Copyright (C) 2009, Marvell International Ltd.
+ *
+ * This software file (the "File") is distributed by Marvell International
+ * Ltd. under the terms of the GNU General Public License Version 2, June 1991
+ * (the "License"). You may use, redistribute and/or modify this File in
+ * accordance with the terms and conditions of the License, a copy of which
+ * is available by writing to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
+ * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ *
+ * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
+ * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
+ * this warranty disclaimer.
+ **/
+
+#include <linux/debugfs.h>
+
+#include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
+
+#include "btmrvl_drv.h"
+
+struct btmrvl_debugfs_data {
+ struct dentry *root_dir, *config_dir, *status_dir;
+
+ /* config */
+ struct dentry *drvdbg;
+ struct dentry *psmode;
+ struct dentry *pscmd;
+ struct dentry *hsmode;
+ struct dentry *hscmd;
+ struct dentry *gpiogap;
+ struct dentry *hscfgcmd;
+
+ /* status */
+ struct dentry *curpsmode;
+ struct dentry *hsstate;
+ struct dentry *psstate;
+ struct dentry *txdnldready;
+};
+
+static int btmrvl_open_generic(struct inode *inode, struct file *file)
+{
+ file->private_data = inode->i_private;
+ return 0;
+}
+
+static ssize_t btmrvl_hscfgcmd_write(struct file *file,
+ const char __user *ubuf,
+ size_t count,
+ loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 10, &result);
+
+ priv->btmrvl_dev.hscfgcmd = result;
+
+ if (priv->btmrvl_dev.hscfgcmd) {
+ btmrvl_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+}
+
+static ssize_t btmrvl_hscfgcmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->btmrvl_dev.hscfgcmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_hscfgcmd_fops = {
+ .read = btmrvl_hscfgcmd_read,
+ .write = btmrvl_hscfgcmd_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_psmode_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 10, &result);
+
+ priv->btmrvl_dev.psmode = result;
+
+ return count;
+}
+
+static ssize_t btmrvl_psmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->btmrvl_dev.psmode);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_psmode_fops = {
+ .read = btmrvl_psmode_read,
+ .write = btmrvl_psmode_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_pscmd_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 10, &result);
+
+ priv->btmrvl_dev.pscmd = result;
+
+ if (priv->btmrvl_dev.pscmd) {
+ btmrvl_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+
+}
+
+static ssize_t btmrvl_pscmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.pscmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_pscmd_fops = {
+ .read = btmrvl_pscmd_read,
+ .write = btmrvl_pscmd_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_gpiogap_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 16, &result);
+
+ priv->btmrvl_dev.gpio_gap = result;
+
+ return count;
+}
+
+static ssize_t btmrvl_gpiogap_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n",
+ priv->btmrvl_dev.gpio_gap);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_gpiogap_fops = {
+ .read = btmrvl_gpiogap_read,
+ .write = btmrvl_gpiogap_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_hscmd_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 10, &result);
+
+ priv->btmrvl_dev.hscmd = result;
+ if (priv->btmrvl_dev.hscmd) {
+ btmrvl_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+}
+
+static ssize_t btmrvl_hscmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btmrvl_dev.hscmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_hscmd_fops = {
+ .read = btmrvl_hscmd_read,
+ .write = btmrvl_hscmd_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_hsmode_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ long result, ret;
+ char buf[16];
+
+ memset(buf, 0, sizeof(buf));
+
+ if (copy_from_user(&buf, ubuf,
+ min_t(size_t, sizeof(buf) - 1, count)))
+ return -EFAULT;
+
+ ret = strict_strtol(buf, 10, &result);
+
+ priv->btmrvl_dev.hsmode = result;
+
+ return count;
+}
+
+static ssize_t btmrvl_hsmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->btmrvl_dev.hsmode);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_hsmode_fops = {
+ .read = btmrvl_hsmode_read,
+ .write = btmrvl_hsmode_write,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_curpsmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->adapter->psmode);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_curpsmode_fops = {
+ .read = btmrvl_curpsmode_read,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_psstate_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->adapter->ps_state);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_psstate_fops = {
+ .read = btmrvl_psstate_read,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_hsstate_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->adapter->hs_state);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_hsstate_fops = {
+ .read = btmrvl_hsstate_read,
+ .open = btmrvl_open_generic,
+};
+
+static ssize_t btmrvl_txdnldready_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->btmrvl_dev.tx_dnld_rdy);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btmrvl_txdnldready_fops = {
+ .read = btmrvl_txdnldready_read,
+ .open = btmrvl_open_generic,
+};
+
+void btmrvl_debugfs_init(struct hci_dev *hdev)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) hdev->driver_data;
+ struct btmrvl_debugfs_data *dbg;
+
+ dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
+ priv->debugfs_data = dbg;
+
+ if (!dbg) {
+ BT_ERR("Can not allocate memory for btmrvl_debugfs_data.");
+ return;
+ }
+
+ dbg->root_dir = debugfs_create_dir("btmrvl", NULL);
+
+ dbg->config_dir = debugfs_create_dir("config", dbg->root_dir);
+
+ dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir,
+ hdev->driver_data,
+ &btmrvl_psmode_fops);
+ dbg->pscmd =
+ debugfs_create_file("pscmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btmrvl_pscmd_fops);
+ dbg->gpiogap =
+ debugfs_create_file("gpiogap", 0644, dbg->config_dir,
+ hdev->driver_data, &btmrvl_gpiogap_fops);
+ dbg->hsmode =
+ debugfs_create_file("hsmode", 0644, dbg->config_dir,
+ hdev->driver_data, &btmrvl_hsmode_fops);
+ dbg->hscmd =
+ debugfs_create_file("hscmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btmrvl_hscmd_fops);
+ dbg->hscfgcmd =
+ debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btmrvl_hscfgcmd_fops);
+
+ dbg->status_dir = debugfs_create_dir("status", dbg->root_dir);
+ dbg->curpsmode = debugfs_create_file("curpsmode", 0444,
+ dbg->status_dir,
+ hdev->driver_data,
+ &btmrvl_curpsmode_fops);
+ dbg->psstate =
+ debugfs_create_file("psstate", 0444, dbg->status_dir,
+ hdev->driver_data, &btmrvl_psstate_fops);
+ dbg->hsstate =
+ debugfs_create_file("hsstate", 0444, dbg->status_dir,
+ hdev->driver_data, &btmrvl_hsstate_fops);
+ dbg->txdnldready =
+ debugfs_create_file("txdnldready", 0444, dbg->status_dir,
+ hdev->driver_data, &btmrvl_txdnldready_fops);
+}
+
+void btmrvl_debugfs_remove(struct hci_dev *hdev)
+{
+ struct btmrvl_private *priv =
+ (struct btmrvl_private *) hdev->driver_data;
+ struct btmrvl_debugfs_data *dbg = priv->debugfs_data;
+
+ if (!dbg)
+ return;
+
+ debugfs_remove(dbg->psmode);
+ debugfs_remove(dbg->pscmd);
+ debugfs_remove(dbg->gpiogap);
+ debugfs_remove(dbg->hsmode);
+ debugfs_remove(dbg->hscmd);
+ debugfs_remove(dbg->hscfgcmd);
+ debugfs_remove(dbg->config_dir);
+
+ debugfs_remove(dbg->curpsmode);
+ debugfs_remove(dbg->psstate);
+ debugfs_remove(dbg->hsstate);
+ debugfs_remove(dbg->txdnldready);
+ debugfs_remove(dbg->status_dir);
+
+ debugfs_remove(dbg->root_dir);
+
+ kfree(dbg);
+}
diff --git a/drivers/bluetooth/btmrvl_drv.h b/drivers/bluetooth/btmrvl_drv.h
index 9ad71f4..7a12f68 100644
--- a/drivers/bluetooth/btmrvl_drv.h
+++ b/drivers/bluetooth/btmrvl_drv.h
@@ -79,6 +79,9 @@ struct btmrvl_private {
u8 *payload, u16 nb);
int (*hw_wakeup_firmware) (struct btmrvl_private *priv);
spinlock_t driver_lock; /* spinlock used by driver */
+#ifdef CONFIG_DEBUG_FS
+ void *debugfs_data;
+#endif
};

#define MRVL_VENDOR_PKT 0xFE
@@ -135,4 +138,9 @@ int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb);
int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd);
int btmrvl_prepare_command(struct btmrvl_private *priv);

+#ifdef CONFIG_DEBUG_FS
+void btmrvl_debugfs_init(struct hci_dev *hdev);
+void btmrvl_debugfs_remove(struct hci_dev *hdev);
+#endif
+
#endif /* _BTMRVL_DRV_H_ */
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 11c2f2c..b4f4445 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -658,6 +658,10 @@ struct btmrvl_private *btmrvl_add_card(void *card)
goto err_hci_register_dev;
}

+#ifdef CONFIG_DEBUG_FS
+ btmrvl_debugfs_init(hdev);
+#endif
+
BT_DBG("Leave");
return priv;

@@ -692,6 +696,10 @@ int btmrvl_remove_card(struct btmrvl_private *priv)

kthread_stop(priv->main_thread.task);

+#ifdef CONFIG_DEBUG_FS
+ btmrvl_debugfs_remove(hdev);
+#endif
+
hci_unregister_dev(hdev);

hci_free_dev(hdev);
--
1.5.3.6


2009-06-02 21:29:38

by Bing Zhao

[permalink] [raw]
Subject: [PATCH 4/4 v3] bluetooth: Documentation for Marvell Bluetooth driver

add btmrvl.txt to Documentation/

This patch incorporates a lot of comments given by
Nicolas Pitre <[email protected]>. Many thanks to Nicolas Pitre.

Signed-off-by: Rahul Tank <[email protected]>
Signed-off-by: Bing Zhao <[email protected]>
---
Documentation/00-INDEX | 2 +
Documentation/btmrvl.txt | 119 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 121 insertions(+), 0 deletions(-)
create mode 100644 Documentation/btmrvl.txt

diff --git a/Documentation/00-INDEX b/Documentation/00-INDEX
index d05737a..06b982a 100644
--- a/Documentation/00-INDEX
+++ b/Documentation/00-INDEX
@@ -82,6 +82,8 @@ block/
- info on the Block I/O (BIO) layer.
blockdev/
- info on block devices & drivers
+btmrvl.txt
+ - info on Marvell Bluetooth driver usage.
cachetlb.txt
- describes the cache/TLB flushing interfaces Linux uses.
cdrom/
diff --git a/Documentation/btmrvl.txt b/Documentation/btmrvl.txt
new file mode 100644
index 0000000..34916a4
--- /dev/null
+++ b/Documentation/btmrvl.txt
@@ -0,0 +1,119 @@
+=======================================================================
+ README for btmrvl driver
+=======================================================================
+
+
+All commands are used via debugfs interface.
+
+=====================
+Set/get driver configurations:
+
+Path: /debug/btmrvl/config/
+
+gpiogap=[n]
+hscfgcmd
+ These commands are used to configure the host sleep parameters.
+ bit 8:0 -- Gap
+ bit 16:8 -- GPIO
+
+ where GPIO is the pin number of GPIO used to wake up the host.
+ It could be any valid GPIO pin# (e.g. 0-7) or 0xff (SDIO interface
+ wakeup will be used instead).
+
+ where Gap is the gap in milli seconds between wakeup signal and
+ wakeup event, or 0xff for special host sleep setting.
+
+ Usage:
+ # Use SDIO interface to wake up the host and set GAP to 0x80:
+ echo 0xff80 > /debug/btmrvl/config/gpiogap
+ echo 1 > /debug/btmrvl/config/hscfgcmd
+
+ # Use GPIO pin #3 to wake up the host and set GAP to 0xff:
+ echo 0x03ff > /debug/btmrvl/config/gpiogap
+ echo 1 > /debug/btmrvl/config/hscfgcmd
+
+psmode=[n]
+pscmd
+ These commands are used to enable/disable auto sleep mode
+
+ where the option is:
+ 1 -- Enable auto sleep mode
+ 0 -- Disable auto sleep mode
+
+ Usage:
+ # Enable auto sleep mode
+ echo 1 > /debug/btmrvl/config/psmode
+ echo 1 > /debug/btmrvl/config/pscmd
+
+ # Disable auto sleep mode
+ echo 0 > /debug/btmrvl/config/psmode
+ echo 1 > /debug/btmrvl/config/pscmd
+
+
+hsmode=[n]
+hscmd
+ These commands are used to enable host sleep or wake up firmware
+
+ where the option is:
+ 1 -- Enable host sleep
+ 0 -- Wake up firmware
+
+ Usage:
+ # Enable host sleep
+ echo 1 > /debug/btmrvl/config/hsmode
+ echo 1 > /debug/btmrvl/config/hscmd
+
+ # Wake up firmware
+ echo 0 > /debug/btmrvl/config/hsmode
+ echo 1 > /debug/btmrvl/config/hscmd
+
+
+======================
+Get driver status:
+
+Path: /debug/btmrvl/status/
+
+Usage:
+ cat /debug/btmrvl/status/<args>
+
+where the args are:
+
+curpsmode
+ This command displays current auto sleep status.
+
+psstate
+ This command display the power save state.
+
+hsstate
+ This command display the host sleep state.
+
+txdnldrdy
+ This command displays the value of Tx download ready flag.
+
+
+=====================
+
+Use hcitool to issue raw hci command, refer to hcitool manual
+
+ Usage: Hcitool cmd <ogf> <ocf> [Parameters]
+
+ Interface Control Command
+ hcitool cmd 0x3f 0x5b 0xf5 0x01 0x00 --Enable All interface
+ hcitool cmd 0x3f 0x5b 0xf5 0x01 0x01 --Enable Wlan interface
+ hcitool cmd 0x3f 0x5b 0xf5 0x01 0x02 --Enable BT interface
+ hcitool cmd 0x3f 0x5b 0xf5 0x00 0x00 --Disable All interface
+ hcitool cmd 0x3f 0x5b 0xf5 0x00 0x01 --Disable Wlan interface
+ hcitool cmd 0x3f 0x5b 0xf5 0x00 0x02 --Disable BT interface
+
+=======================================================================
+
+
+SD8688 firmware:
+
+/lib/firmware/sd8688_helper.bin
+/lib/firmware/sd8688.bin
+
+
+The images can be downloaded from:
+
+git.infradead.org/users/dwmw2/linux-firmware.git/libertas/
--
1.5.3.6