2009-05-21 00:35:38

by Bing Zhao

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

This driver, bt_mrvl, 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 | 2 +
drivers/bluetooth/Makefile | 2 +
drivers/bluetooth/bt_mrvl/Kconfig | 12 +
drivers/bluetooth/bt_mrvl/Makefile | 7 +
drivers/bluetooth/bt_mrvl/btm_drv.h | 223 +++++++++++
drivers/bluetooth/bt_mrvl/btm_main.c | 728 ++++++++++++++++++++++++++++++++++
6 files changed, 974 insertions(+), 0 deletions(-)
create mode 100644 drivers/bluetooth/bt_mrvl/Kconfig
create mode 100644 drivers/bluetooth/bt_mrvl/Makefile
create mode 100644 drivers/bluetooth/bt_mrvl/btm_drv.h
create mode 100644 drivers/bluetooth/bt_mrvl/btm_main.c

diff --git a/drivers/bluetooth/Kconfig b/drivers/bluetooth/Kconfig
index 1164837..6e4b9b5 100644
--- a/drivers/bluetooth/Kconfig
+++ b/drivers/bluetooth/Kconfig
@@ -170,5 +170,7 @@ 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).

+source "drivers/bluetooth/bt_mrvl/Kconfig"
+
endmenu

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

+obj-$(CONFIG_BT_MRVL) += bt_mrvl/
+
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/bt_mrvl/Kconfig b/drivers/bluetooth/bt_mrvl/Kconfig
new file mode 100644
index 0000000..9b6202b
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/Kconfig
@@ -0,0 +1,12 @@
+config BT_MRVL
+ tristate "Marvell Bluetooth driver support"
+ depends on BT
+ 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.
diff --git a/drivers/bluetooth/bt_mrvl/Makefile b/drivers/bluetooth/bt_mrvl/Makefile
new file mode 100644
index 0000000..88b457b
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for Marvell Bluetooth driver
+#
+
+bt_mrvl-objs := btm_main.o
+
+obj-$(CONFIG_BT_MRVL) += bt_mrvl.o
diff --git a/drivers/bluetooth/bt_mrvl/btm_drv.h b/drivers/bluetooth/bt_mrvl/btm_drv.h
new file mode 100644
index 0000000..68a74cc
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/btm_drv.h
@@ -0,0 +1,223 @@
+/*
+ * 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 _BTM_DRV_H_
+#define _BTM_DRV_H_
+
+#include <linux/kthread.h>
+#include <linux/bitops.h>
+
+#define BTM_HEADER_LEN 4
+
+#define DBG_MSG BIT(0) /* Message */
+#define DBG_FATAL BIT(1) /* Fatal */
+#define DBG_ERROR BIT(2) /* Error */
+#define DBG_CMD BIT(3) /* Command */
+#define DBG_DATA BIT(27) /* Data */
+#define DBG_ENTRY BIT(28) /* Entry */
+#define DBG_WARN BIT(29) /* Warning */
+#define DBG_INFO BIT(30) /* Informative */
+
+#ifdef CONFIG_BT_MRVL_DEBUG
+extern u32 btm_drvdbg;
+
+#define PRINTM_INFO(msg...) do {if (btm_drvdbg & DBG_INFO) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_WARN(msg...) do {if (btm_drvdbg & DBG_WARN) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_ENTRY(msg...) do {if (btm_drvdbg & DBG_ENTRY) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_CMD(msg...) do {if (btm_drvdbg & DBG_CMD) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_ERROR(msg...) do {if (btm_drvdbg & DBG_ERROR) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_FATAL(msg...) do {if (btm_drvdbg & DBG_FATAL) \
+ printk(KERN_DEBUG msg); } while (0)
+
+#define PRINTM_MSG(msg...) do {if (btm_drvdbg & DBG_MSG) \
+ printk(KERN_ALERT msg); } while (0)
+
+/* Print message with required level */
+#define PRINTM(level, msg...) PRINTM_##level(msg)
+
+#define ENTER() PRINTM(ENTRY, "Enter: %s, %s:%i\n", \
+ __func__, __FILE__, __LINE__)
+#define LEAVE() PRINTM(ENTRY, "Leave: %s, %s:%i\n", \
+ __func__, __FILE__, __LINE__)
+
+#define DBG_DUMP_BUF_LEN 64
+#define MAX_DUMP_PER_LINE 16
+
+static inline void btm_hexdump(char *prompt, u8 *buf, int len)
+{
+ int i;
+ char dbgdumpbuf[DBG_DUMP_BUF_LEN];
+ char *ptr = dbgdumpbuf;
+
+ printk(KERN_DEBUG "%s: len=%d\n", prompt, len);
+
+ for (i = 1; i <= len; i++) {
+ ptr += sprintf(ptr, "%02x ", *buf);
+ buf++;
+ if (i % MAX_DUMP_PER_LINE == 0) {
+ *ptr = 0;
+ printk(KERN_DEBUG "%s\n", dbgdumpbuf);
+ ptr = dbgdumpbuf;
+ }
+ }
+
+ if (len % MAX_DUMP_PER_LINE) {
+ *ptr = 0;
+ printk(KERN_DEBUG "%s\n", dbgdumpbuf);
+ }
+}
+
+#define DBG_HEXDUMP_DBG_DATA(x, y, z) do {if (btm_drvdbg & DBG_DATA) \
+ btm_hexdump(x, y, z); \
+ } while (0)
+
+#define DBG_HEXDUMP(level, x, y, z) DBG_HEXDUMP_##level(x, y, z)
+
+#else
+
+/* Do nothing */
+#define PRINTM(level, msg...) do {} while (0)
+#define DBG_HEXDUMP(level, x, y, z) do {} while (0)
+#define ENTER() do {} while (0)
+#define LEAVE() do {} while (0)
+
+#endif /* CONFIG_BT_MRVL_DEBUG */
+
+#define BT_DEV_NAME_LEN 32
+#define BT_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 btm_thread {
+ struct task_struct *task;
+ wait_queue_head_t wait_q;
+ pid_t pid;
+ void *priv;
+};
+
+struct btm_device {
+ char name[BT_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 btm_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 btm_private {
+ struct btm_device btm_dev;
+ struct btm_adapter *adapter;
+ struct btm_thread main_thread;
+ int (*hw_host_to_card) (struct btm_private *priv,
+ u8 *payload, u16 nb);
+ int (*hw_wakeup_firmware) (struct btm_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 btm_cmd {
+ __le16 ocf_ogf;
+ u8 length;
+ u8 data[4];
+} __attribute__ ((packed));
+
+struct btm_event {
+ u8 ec; /* event counter */
+ u8 length;
+ u8 data[4];
+} __attribute__ ((packed));
+
+/* Prototype of global function */
+
+struct btm_private *btm_add_card(void *card);
+int btm_remove_card(struct btm_private *priv);
+
+void btm_interrupt(struct btm_private *priv);
+
+void btm_check_evtpkt(struct btm_private *priv, struct sk_buff *skb);
+int btm_process_event(struct btm_private *priv, struct sk_buff *skb);
+
+int btm_send_module_cfg_cmd(struct btm_private *priv, int subcmd);
+int btm_prepare_command(struct btm_private *priv);
+
+#endif /* _BTM_DRV_H_ */
diff --git a/drivers/bluetooth/bt_mrvl/btm_main.c b/drivers/bluetooth/bt_mrvl/btm_main.c
new file mode 100644
index 0000000..0bdd297
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/btm_main.c
@@ -0,0 +1,728 @@
+/**
+ * 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 "btm_drv.h"
+
+#define VERSION "1.0"
+
+#ifdef CONFIG_BT_MRVL_DEBUG
+u32 btm_drvdbg = DBG_MSG | DBG_FATAL | DBG_ERROR;
+EXPORT_SYMBOL_GPL(btm_drvdbg);
+#endif
+
+/*
+ * This function is called by interface specific interrupt handler.
+ * It updates Power Save & Host Sleep states, and wakes up the main
+ * thread.
+ */
+void btm_interrupt(struct btm_private *priv)
+{
+ ENTER();
+
+ priv->adapter->ps_state = PS_AWAKE;
+
+ priv->adapter->wakeup_tries = 0;
+
+ priv->adapter->int_count++;
+
+ wake_up_interruptible(&priv->main_thread.wait_q);
+
+ LEAVE();
+}
+EXPORT_SYMBOL_GPL(btm_interrupt);
+
+void btm_check_evtpkt(struct btm_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;
+
+ 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->btm_dev.sendcmdflag)) {
+ priv->btm_dev.sendcmdflag = false;
+ priv->adapter->cmd_complete = true;
+ wake_up_interruptible(&priv->adapter->cmd_wait_q);
+ }
+ }
+
+ LEAVE();
+}
+EXPORT_SYMBOL_GPL(btm_check_evtpkt);
+
+int btm_process_event(struct btm_private *priv, struct sk_buff *skb)
+{
+ struct btm_adapter *adapter = priv->adapter;
+ u8 ret = 0;
+ struct btm_event *event;
+
+ ENTER();
+
+ event = (struct btm_event *) skb->data;
+ if (event->ec != 0xff) {
+ PRINTM(CMD, "Not Marvell Event=%x\n", 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;
+ PRINTM(CMD, "PS Mode:%s\n",
+ (adapter->psmode) ? "Enable" : "Disable");
+ } else {
+ PRINTM(CMD, "PS Mode command failed\n");
+ }
+ break;
+
+ case BT_CMD_HOST_SLEEP_CONFIG:
+ if (!event->data[3])
+ PRINTM(CMD, "gpio=%x, gap=%x\n",
+ event->data[1],
+ event->data[2]);
+ else
+ PRINTM(CMD, "HSCFG command failed\n");
+ 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);
+ PRINTM(CMD, "HS ACTIVATED!\n");
+ } else {
+ PRINTM(CMD, "HS Enable failed\n");
+ }
+ break;
+
+ case BT_CMD_MODULE_CFG_REQ:
+ if ((priv->btm_dev.sendcmdflag) &&
+ (event->data[1] == MODULE_BRINGUP_REQ)) {
+ PRINTM(CMD, "EVENT:%s\n",
+ (event->data[2]) ?
+ "Bring-up failed" :
+ "Bring-up succeed");
+ } else if ((priv->btm_dev.sendcmdflag) &&
+ (event->data[1] == MODULE_SHUTDOWN_REQ)) {
+ PRINTM(CMD, "EVENT:%s\n",
+ (event->data[2]) ?
+ "Shutdown failed" :
+ "Shutdown succeed");
+ } else {
+ PRINTM(CMD, "BT_CMD_MODULE_CFG_REQ resp for APP\n");
+ ret = -EINVAL;
+ }
+ break;
+
+ case BT_EVENT_POWER_STATE:
+ if (event->data[1] == BT_PS_SLEEP)
+ adapter->ps_state = PS_SLEEP;
+ PRINTM(CMD, "EVENT:%s\n",
+ (adapter->ps_state) ? "PS_SLEEP" : "PS_AWAKE");
+ break;
+
+ default:
+ PRINTM(CMD, "Unknown Event=%d\n", event->data[0]);
+ ret = -EINVAL;
+ break;
+ }
+
+exit:
+ if (!ret)
+ kfree_skb(skb);
+
+ LEAVE();
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(btm_process_event);
+
+int btm_send_module_cfg_cmd(struct btm_private *priv, int subcmd)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btm_cmd *cmd;
+
+ ENTER();
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ PRINTM(WARN, "No free skb\n");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btm_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->btm_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ priv->btm_dev.sendcmdflag = true;
+
+ priv->adapter->cmd_complete = false;
+
+ PRINTM(CMD, "Queue module cfg Command\n");
+
+ 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;
+ PRINTM(MSG, "module_cfg_cmd(%x): timeout: %d\n",
+ subcmd, priv->btm_dev.sendcmdflag);
+ }
+
+ PRINTM(CMD, "module cfg Command done\n");
+
+exit:
+ LEAVE();
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(btm_send_module_cfg_cmd);
+
+static int btm_enable_hs(struct btm_private *priv)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btm_cmd *cmd;
+
+ ENTER();
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ PRINTM(WARN, "No free skb\n");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btm_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->btm_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ PRINTM(CMD, "Queue hs enable Command\n");
+
+ 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;
+ PRINTM(MSG, "btm_enable_hs: timeout: %d, %d,%d\n",
+ priv->adapter->hs_state,
+ priv->adapter->ps_state,
+ priv->adapter->wakeup_tries);
+ }
+
+exit:
+ LEAVE();
+
+ return ret;
+}
+
+int btm_prepare_command(struct btm_private *priv)
+{
+ struct sk_buff *skb = NULL;
+ u8 ret = 0;
+ struct btm_cmd *cmd;
+
+ ENTER();
+
+ if (priv->btm_dev.hscfgcmd) {
+ priv->btm_dev.hscfgcmd = 0;
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ PRINTM(WARN, "No free skb\n");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btm_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) |
+ BT_CMD_HOST_SLEEP_CONFIG);
+ cmd->length = 2;
+ cmd->data[0] = (priv->btm_dev.gpio_gap & 0xff00) >> 8;
+ cmd->data[1] = (u8) (priv->btm_dev.gpio_gap & 0x00ff);
+
+ bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT;
+
+ skb_put(skb, sizeof(*cmd));
+ skb->dev = (void *)priv->btm_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ PRINTM(CMD, "Queue HSCFG Command, gpio=0x%x, gap=0x%x\n",
+ cmd->data[0], cmd->data[1]);
+ }
+
+ if (priv->btm_dev.pscmd) {
+ priv->btm_dev.pscmd = 0;
+
+ skb = bt_skb_alloc(sizeof(*cmd), GFP_ATOMIC);
+ if (skb == NULL) {
+ PRINTM(WARN, "No free skb\n");
+ ret = -ENOMEM;
+ goto exit;
+ }
+
+ cmd = (struct btm_cmd *) skb->tail;
+ cmd->ocf_ogf = cpu_to_le16((OGF << 10) |
+ BT_CMD_AUTO_SLEEP_MODE);
+ cmd->length = 1;
+
+ if (priv->btm_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->btm_dev.hcidev;
+ skb_queue_head(&priv->adapter->tx_queue, skb);
+
+ PRINTM(CMD, "Queue PSMODE Command:%d\n", cmd->data[0]);
+ }
+
+ if (priv->btm_dev.hscmd) {
+ priv->btm_dev.hscmd = 0;
+
+ if (priv->btm_dev.hsmode) {
+ ret = btm_enable_hs(priv);
+ } else {
+ ret = priv->hw_wakeup_firmware(priv);
+ priv->adapter->hs_state = HS_DEACTIVATED;
+ }
+ }
+
+exit:
+ LEAVE();
+
+ return ret;
+}
+
+static int btm_tx_pkt(struct btm_private *priv, struct sk_buff *skb)
+{
+ u8 ret = 0;
+
+ ENTER();
+
+ if (!skb || !skb->data) {
+ LEAVE();
+ return -EINVAL;
+ }
+
+ if (!skb->len || ((skb->len + BTM_HEADER_LEN) > BT_UPLD_SIZE)) {
+ PRINTM(ERROR, "Tx Error: Bad skb length %d : %d\n",
+ skb->len, BT_UPLD_SIZE);
+ 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) {
+ PRINTM(ERROR, "Tx Error: realloc_headroom failed %d\n",
+ BTM_HEADER_LEN);
+ skb = tmp;
+ 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);
+
+ LEAVE();
+
+ return ret;
+}
+
+static void btm_init_adapter(struct btm_private *priv)
+{
+ ENTER();
+
+ skb_queue_head_init(&priv->adapter->tx_queue);
+
+ priv->adapter->ps_state = PS_AWAKE;
+
+ init_waitqueue_head(&priv->adapter->cmd_wait_q);
+
+ LEAVE();
+}
+
+static void btm_free_adapter(struct btm_private *priv)
+{
+ ENTER();
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ kfree(priv->adapter);
+
+ priv->adapter = NULL;
+
+ LEAVE();
+}
+
+static int
+btm_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg)
+{
+ ENTER();
+
+ LEAVE();
+
+ return -ENOIOCTLCMD;
+}
+
+static void btm_destruct(struct hci_dev *hdev)
+{
+ ENTER();
+
+ LEAVE();
+}
+
+static int btm_send_frame(struct sk_buff *skb)
+{
+ struct hci_dev *hdev = (struct hci_dev *)skb->dev;
+ struct btm_private *priv = NULL;
+
+ ENTER();
+
+ PRINTM(INFO, "btm_send_frame: Type=%d, len=%d\n", skb->pkt_type,
+ skb->len);
+
+ DBG_HEXDUMP(DBG_DATA, "btm_send_frame", skb->data, skb->len);
+
+ if (!hdev || !hdev->driver_data) {
+ PRINTM(ERROR, "Frame for unknown HCI device (hdev=NULL)\n");
+ LEAVE();
+ return -ENODEV;
+ }
+
+ priv = (struct btm_private *)hdev->driver_data;
+ if (!test_bit(HCI_RUNNING, &hdev->flags)) {
+ PRINTM(ERROR, "Fail test HCI_RUNING,flag=%lx\n", hdev->flags);
+ 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);
+
+ LEAVE();
+
+ return 0;
+}
+
+static int btm_flush(struct hci_dev *hdev)
+{
+ struct btm_private *priv = (struct btm_private *)hdev->driver_data;
+
+ ENTER();
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ LEAVE();
+
+ return 0;
+}
+
+static int btm_close(struct hci_dev *hdev)
+{
+ struct btm_private *priv = (struct btm_private *)hdev->driver_data;
+
+ ENTER();
+
+ if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) {
+ LEAVE();
+ return 0;
+ }
+
+ skb_queue_purge(&priv->adapter->tx_queue);
+
+ LEAVE();
+
+ return 0;
+}
+
+static int btm_open(struct hci_dev *hdev)
+{
+ ENTER();
+
+ set_bit(HCI_RUNNING, &hdev->flags);
+
+ LEAVE();
+
+ return 0;
+}
+
+/*
+ * This function handles the event generated by firmware, rx data
+ * received from firmware, and tx data sent from kernel.
+ */
+static int btm_service_main_thread(void *data)
+{
+ struct btm_thread *thread = data;
+ struct btm_private *priv = thread->priv;
+ struct btm_adapter *adapter = priv->adapter;
+ wait_queue_t wait;
+ struct sk_buff *skb;
+ ulong flags;
+
+ ENTER();
+
+ thread->pid = current->pid;
+
+ 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->btm_dev.tx_dnld_rdy ||
+ skb_queue_empty(&adapter->tx_queue)))) {
+ PRINTM(INFO, "main_thread is sleeping...\n");
+ schedule();
+ }
+
+ set_current_state(TASK_RUNNING);
+
+ remove_wait_queue(&thread->wait_q, &wait);
+
+ PRINTM(INFO, "main_thread woke up\n");
+
+ if (kthread_should_stop()) {
+ PRINTM(INFO, "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->btm_dev.tx_dnld_rdy)
+ continue;
+
+ skb = skb_dequeue(&adapter->tx_queue);
+ if (skb) {
+ if (btm_tx_pkt(priv, skb))
+ priv->btm_dev.hcidev->stat.err_tx++;
+ else
+ priv->btm_dev.hcidev->stat.byte_tx += skb->len;
+
+ kfree_skb(skb);
+ }
+ }
+
+ thread->pid = 0;
+
+ LEAVE();
+
+ return 0;
+}
+
+struct btm_private *btm_add_card(void *card)
+{
+ struct hci_dev *hdev = NULL;
+ struct btm_private *priv = NULL;
+ int ret;
+
+ ENTER();
+
+ priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ if (!priv) {
+ PRINTM(FATAL, "Can not allocate priv\n");
+ goto err_priv;
+ }
+
+ priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
+ if (!priv->adapter) {
+ PRINTM(FATAL, "Allocate buffer for btm_adapter failed!\n");
+ goto err_adapter;
+ }
+
+ btm_init_adapter(priv);
+
+ hdev = hci_alloc_dev();
+ if (!hdev) {
+ PRINTM(FATAL, "Can not allocate HCI device\n");
+ goto err_hdev;
+ }
+
+ PRINTM(INFO, "Starting kthread...\n");
+ 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(btm_service_main_thread,
+ &priv->main_thread, "btm_main_service");
+
+ priv->btm_dev.hcidev = hdev;
+ priv->btm_dev.card = card;
+
+ hdev->driver_data = priv;
+
+ priv->btm_dev.tx_dnld_rdy = true;
+
+ hdev->type = HCI_SDIO;
+ hdev->open = btm_open;
+ hdev->close = btm_close;
+ hdev->flush = btm_flush;
+ hdev->send = btm_send_frame;
+ hdev->destruct = btm_destruct;
+ hdev->ioctl = btm_ioctl;
+ hdev->owner = THIS_MODULE;
+
+ ret = hci_register_dev(hdev);
+ if (ret < 0) {
+ PRINTM(FATAL, "Can not register HCI device\n");
+ goto err_hci_register_dev;
+ }
+
+ 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:
+ btm_free_adapter(priv);
+
+err_adapter:
+ kfree(priv);
+
+err_priv:
+ LEAVE();
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(btm_add_card);
+
+int btm_remove_card(struct btm_private *priv)
+{
+ struct hci_dev *hdev;
+
+ ENTER();
+
+ hdev = priv->btm_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->btm_dev.hcidev = NULL;
+
+ btm_free_adapter(priv);
+
+ kfree(priv);
+
+ LEAVE();
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(btm_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-05-21 00:45:54

by Marcel Holtmann

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

Hi Bing,

> This driver, bt_mrvl, 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 | 2 +
> drivers/bluetooth/Makefile | 2 +
> drivers/bluetooth/bt_mrvl/Kconfig | 12 +
> drivers/bluetooth/bt_mrvl/Makefile | 7 +
> drivers/bluetooth/bt_mrvl/btm_drv.h | 223 +++++++++++
> drivers/bluetooth/bt_mrvl/btm_main.c | 728 ++++++++++++++++++++++++++++++++++
> 6 files changed, 974 insertions(+), 0 deletions(-)
> create mode 100644 drivers/bluetooth/bt_mrvl/Kconfig
> create mode 100644 drivers/bluetooth/bt_mrvl/Makefile
> create mode 100644 drivers/bluetooth/bt_mrvl/btm_drv.h
> create mode 100644 drivers/bluetooth/bt_mrvl/btm_main.c

the first thing that I need from you is to remove this vendor specific
debug mess. You can use dynamic debug and hex dump infrastructure
already present in the upstream kernel.

For the driver name please do btmrvl.ko and btmrvl_sdio.ko or use the
chipset specific code number. And I prefer not to have it in a
subdirectory. So just prefix all your files with btmrvl_

Then please resend them and I do a detailed review.

Regards

Marcel



2009-05-21 00:35:40

by Bing Zhao

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

/debug/bt_mrvl/config/
/debug/bt_mrvl/status/

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/bt_mrvl/Kconfig | 6 +
drivers/bluetooth/bt_mrvl/Makefile | 4 +-
drivers/bluetooth/bt_mrvl/btm_debugfs.c | 492 +++++++++++++++++++++++++++++++
drivers/bluetooth/bt_mrvl/btm_drv.h | 8 +
drivers/bluetooth/bt_mrvl/btm_main.c | 8 +
5 files changed, 517 insertions(+), 1 deletions(-)
create mode 100644 drivers/bluetooth/bt_mrvl/btm_debugfs.c

diff --git a/drivers/bluetooth/bt_mrvl/Kconfig b/drivers/bluetooth/bt_mrvl/Kconfig
index 9f7a24a..e18e6fd 100644
--- a/drivers/bluetooth/bt_mrvl/Kconfig
+++ b/drivers/bluetooth/bt_mrvl/Kconfig
@@ -23,3 +23,9 @@ config BT_MRVL_SDIO

Say Y here to compile support for Marvell BT-over-SDIO driver
into the kernel or say M to compile it as module.
+
+config BT_MRVL_DEBUG
+ bool "Enable debug in Marvell Bluetooth driver"
+ depends on BT_MRVL && DEBUG_FS
+ help
+ Say Y here to enable debug messages
diff --git a/drivers/bluetooth/bt_mrvl/Makefile b/drivers/bluetooth/bt_mrvl/Makefile
index 8c8cb94..4ae953d 100644
--- a/drivers/bluetooth/bt_mrvl/Makefile
+++ b/drivers/bluetooth/bt_mrvl/Makefile
@@ -2,7 +2,9 @@
# Makefile for Marvell Bluetooth driver
#

-bt_mrvl-objs := btm_main.o
+bt_mrvl-y := btm_main.o
+bt_mrvl-$(CONFIG_DEBUG_FS) += btm_debugfs.o
+
bt_mrvl_sdio-objs := btm_sdio.o

obj-$(CONFIG_BT_MRVL) += bt_mrvl.o
diff --git a/drivers/bluetooth/bt_mrvl/btm_debugfs.c b/drivers/bluetooth/bt_mrvl/btm_debugfs.c
new file mode 100644
index 0000000..ef09f06
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/btm_debugfs.c
@@ -0,0 +1,492 @@
+/**
+ * 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 "btm_drv.h"
+
+struct btm_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 btm_open_generic(struct inode *inode, struct file *file)
+{
+ file->private_data = inode->i_private;
+ return 0;
+}
+
+#ifdef CONFIG_BT_MRVL_DEBUG
+static ssize_t btm_drvdbg_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ 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);
+
+ btm_drvdbg = result;
+
+ return count;
+}
+
+static ssize_t btm_drvdbg_read(struct file *file, char __user *userbuf,
+ size_t count, loff_t *ppos)
+{
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n", btm_drvdbg);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_drvdbg_fops = {
+ .read = btm_drvdbg_read,
+ .write = btm_drvdbg_write,
+ .open = btm_open_generic,
+};
+#endif
+
+static ssize_t btm_hscfgcmd_write(struct file *file,
+ const char __user *ubuf,
+ size_t count,
+ loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.hscfgcmd = result;
+
+ if (priv->btm_dev.hscfgcmd) {
+ btm_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+}
+
+static ssize_t btm_hscfgcmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btm_dev.hscfgcmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_hscfgcmd_fops = {
+ .read = btm_hscfgcmd_read,
+ .write = btm_hscfgcmd_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_psmode_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.psmode = result;
+
+ return count;
+}
+
+static ssize_t btm_psmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btm_dev.psmode);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_psmode_fops = {
+ .read = btm_psmode_read,
+ .write = btm_psmode_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_pscmd_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.pscmd = result;
+
+ if (priv->btm_dev.pscmd) {
+ btm_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+
+}
+
+static ssize_t btm_pscmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btm_dev.pscmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_pscmd_fops = {
+ .read = btm_pscmd_read,
+ .write = btm_pscmd_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_gpiogap_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.gpio_gap = result;
+
+ return count;
+}
+
+static ssize_t btm_gpiogap_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "0x%x\n", priv->btm_dev.gpio_gap);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_gpiogap_fops = {
+ .read = btm_gpiogap_read,
+ .write = btm_gpiogap_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_hscmd_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.hscmd = result;
+ if (priv->btm_dev.hscmd) {
+ btm_prepare_command(priv);
+ wake_up_interruptible(&priv->main_thread.wait_q);
+ }
+
+ return count;
+}
+
+static ssize_t btm_hscmd_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btm_dev.hscmd);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_hscmd_fops = {
+ .read = btm_hscmd_read,
+ .write = btm_hscmd_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_hsmode_write(struct file *file, const char __user *ubuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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->btm_dev.hsmode = result;
+
+ return count;
+}
+
+static ssize_t btm_hsmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n", priv->btm_dev.hsmode);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_hsmode_fops = {
+ .read = btm_hsmode_read,
+ .write = btm_hsmode_write,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_curpsmode_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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 btm_curpsmode_fops = {
+ .read = btm_curpsmode_read,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_psstate_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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 btm_psstate_fops = {
+ .read = btm_psstate_read,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_hsstate_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_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 btm_hsstate_fops = {
+ .read = btm_hsstate_read,
+ .open = btm_open_generic,
+};
+
+static ssize_t btm_txdnldready_read(struct file *file, char __user * userbuf,
+ size_t count, loff_t *ppos)
+{
+ struct btm_private *priv = (struct btm_private *) file->private_data;
+ int ret;
+ char buf[16];
+
+ ret = snprintf(buf, sizeof(buf) - 1, "%d\n",
+ priv->btm_dev.tx_dnld_rdy);
+
+ return simple_read_from_buffer(userbuf, count, ppos, buf, ret);
+}
+
+static const struct file_operations btm_txdnldready_fops = {
+ .read = btm_txdnldready_read,
+ .open = btm_open_generic,
+};
+
+void btm_debugfs_init(struct hci_dev *hdev)
+{
+ struct btm_private *priv = (struct btm_private *) hdev->driver_data;
+ struct btm_debugfs_data *dbg;
+
+ dbg = kzalloc(sizeof(*dbg), GFP_KERNEL);
+ priv->debugfs_data = dbg;
+
+ if (!dbg) {
+ PRINTM(ERROR, "Can not allocate memory "
+ "for btm_debugfs_data\n");
+ return;
+ }
+
+ dbg->root_dir = debugfs_create_dir("bt_mrvl", NULL);
+
+ dbg->config_dir = debugfs_create_dir("config", dbg->root_dir);
+
+#ifdef CONFIG_BT_MRVL_DEBUG
+ dbg->drvdbg = debugfs_create_file("drvdbg", 0644, dbg->config_dir,
+ hdev, &btm_drvdbg_fops);
+#endif
+
+ dbg->psmode = debugfs_create_file("psmode", 0644, dbg->config_dir,
+ hdev->driver_data,
+ &btm_psmode_fops);
+ dbg->pscmd =
+ debugfs_create_file("pscmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btm_pscmd_fops);
+ dbg->gpiogap =
+ debugfs_create_file("gpiogap", 0644, dbg->config_dir,
+ hdev->driver_data, &btm_gpiogap_fops);
+ dbg->hsmode =
+ debugfs_create_file("hsmode", 0644, dbg->config_dir,
+ hdev->driver_data, &btm_hsmode_fops);
+ dbg->hscmd =
+ debugfs_create_file("hscmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btm_hscmd_fops);
+ dbg->hscfgcmd =
+ debugfs_create_file("hscfgcmd", 0644, dbg->config_dir,
+ hdev->driver_data, &btm_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,
+ &btm_curpsmode_fops);
+ dbg->psstate =
+ debugfs_create_file("psstate", 0444, dbg->status_dir,
+ hdev->driver_data, &btm_psstate_fops);
+ dbg->hsstate =
+ debugfs_create_file("hsstate", 0444, dbg->status_dir,
+ hdev->driver_data, &btm_hsstate_fops);
+ dbg->txdnldready =
+ debugfs_create_file("txdnldready", 0444, dbg->status_dir,
+ hdev->driver_data, &btm_txdnldready_fops);
+}
+
+void btm_debugfs_remove(struct hci_dev *hdev)
+{
+ struct btm_private *priv = (struct btm_private *) hdev->driver_data;
+ struct btm_debugfs_data *dbg = priv->debugfs_data;
+
+ if (!dbg)
+ return;
+
+#ifdef CONFIG_BT_MRVL_DEBUG
+ debugfs_remove(dbg->drvdbg);
+#endif
+ 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/bt_mrvl/btm_drv.h b/drivers/bluetooth/bt_mrvl/btm_drv.h
index 68a74cc..ed019d2 100644
--- a/drivers/bluetooth/bt_mrvl/btm_drv.h
+++ b/drivers/bluetooth/bt_mrvl/btm_drv.h
@@ -164,6 +164,9 @@ struct btm_private {
u8 *payload, u16 nb);
int (*hw_wakeup_firmware) (struct btm_private *priv);
spinlock_t driver_lock; /* spinlock used by driver */
+#ifdef CONFIG_DEBUG_FS
+ void *debugfs_data;
+#endif
};

#define MRVL_VENDOR_PKT 0xFE
@@ -220,4 +223,9 @@ int btm_process_event(struct btm_private *priv, struct sk_buff *skb);
int btm_send_module_cfg_cmd(struct btm_private *priv, int subcmd);
int btm_prepare_command(struct btm_private *priv);

+#ifdef CONFIG_DEBUG_FS
+void btm_debugfs_init(struct hci_dev *hdev);
+void btm_debugfs_remove(struct hci_dev *hdev);
+#endif
+
#endif /* _BTM_DRV_H_ */
diff --git a/drivers/bluetooth/bt_mrvl/btm_main.c b/drivers/bluetooth/bt_mrvl/btm_main.c
index 0bdd297..354fed8 100644
--- a/drivers/bluetooth/bt_mrvl/btm_main.c
+++ b/drivers/bluetooth/bt_mrvl/btm_main.c
@@ -672,6 +672,10 @@ struct btm_private *btm_add_card(void *card)
goto err_hci_register_dev;
}

+#ifdef CONFIG_DEBUG_FS
+ btm_debugfs_init(hdev);
+#endif
+
LEAVE();
return priv;

@@ -706,6 +710,10 @@ int btm_remove_card(struct btm_private *priv)

kthread_stop(priv->main_thread.task);

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

hci_free_dev(hdev);
--
1.5.3.6


2009-05-21 00:35:39

by Bing Zhao

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

This driver, bt_mrvl_sdio, supports Marvell Bluetooth enabled devices
with SDIO interface, Currently only SD8688 is supported. New chipsets
can be added in future.

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/bt_mrvl/Kconfig | 13 +
drivers/bluetooth/bt_mrvl/Makefile | 2 +
drivers/bluetooth/bt_mrvl/btm_sdio.c | 1124 ++++++++++++++++++++++++++++++++++
drivers/bluetooth/bt_mrvl/btm_sdio.h | 113 ++++
4 files changed, 1252 insertions(+), 0 deletions(-)
create mode 100644 drivers/bluetooth/bt_mrvl/btm_sdio.c
create mode 100644 drivers/bluetooth/bt_mrvl/btm_sdio.h

diff --git a/drivers/bluetooth/bt_mrvl/Kconfig b/drivers/bluetooth/bt_mrvl/Kconfig
index 9b6202b..9f7a24a 100644
--- a/drivers/bluetooth/bt_mrvl/Kconfig
+++ b/drivers/bluetooth/bt_mrvl/Kconfig
@@ -10,3 +10,16 @@ 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.
diff --git a/drivers/bluetooth/bt_mrvl/Makefile b/drivers/bluetooth/bt_mrvl/Makefile
index 88b457b..8c8cb94 100644
--- a/drivers/bluetooth/bt_mrvl/Makefile
+++ b/drivers/bluetooth/bt_mrvl/Makefile
@@ -3,5 +3,7 @@
#

bt_mrvl-objs := btm_main.o
+bt_mrvl_sdio-objs := btm_sdio.o

obj-$(CONFIG_BT_MRVL) += bt_mrvl.o
+obj-$(CONFIG_BT_MRVL_SDIO) += bt_mrvl_sdio.o
diff --git a/drivers/bluetooth/bt_mrvl/btm_sdio.c b/drivers/bluetooth/bt_mrvl/btm_sdio.c
new file mode 100644
index 0000000..e4def9f
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/btm_sdio.c
@@ -0,0 +1,1124 @@
+/**
+ * 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 "btm_drv.h"
+#include "btm_sdio.h"
+
+#define VERSION "1.0"
+
+#ifndef SDIO_DEVICE_ID_MARVELL_8688BT
+#define SDIO_DEVICE_ID_MARVELL_8688BT 0x9105
+#endif
+
+static const struct sdio_device_id btsdio_ids[] = {
+ {SDIO_DEVICE(SDIO_VENDOR_ID_MARVELL, SDIO_DEVICE_ID_MARVELL_8688BT)},
+ {0, 0, 0, 0}
+};
+
+MODULE_DEVICE_TABLE(sdio, btsdio_ids);
+
+static struct btsdio_device btsdio_devices[] = {
+ {
+ .dev_id = SDIO_DEVICE_ID_MARVELL_8688BT,
+ .helper = "sd8688_helper.bin",
+ .firmware = "sd8688.bin",
+ .card = NULL,
+ },
+};
+
+static int btsdio_get_rx_unit(struct btsdio_card *card)
+{
+ u8 reg;
+ int ret;
+
+ ENTER();
+
+ reg = sdio_readb(card->func, CARD_RX_UNIT_REG, &ret);
+ if (!ret)
+ card->rx_unit = reg;
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_read_firmware_status(struct btsdio_card *card, u16 *dat)
+{
+ int ret;
+ u8 fws0, fws1;
+
+ 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) {
+ LEAVE();
+ return -EIO;
+ }
+
+ *dat = (((u16) fws1) << 8) | fws0;
+
+ LEAVE();
+
+ return 0;
+}
+
+static int btsdio_read_rx_len(struct btsdio_card *card, u16 *dat)
+{
+ int ret;
+ u8 reg;
+
+ ENTER();
+
+ reg = sdio_readb(card->func, CARD_RX_LEN_REG, &ret);
+ if (!ret)
+ *dat = (u16) reg << card->rx_unit;
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_enable_host_int_mask(struct btsdio_card *card, u8 mask)
+{
+ int ret;
+
+ ENTER();
+
+ sdio_writeb(card->func, mask, HOST_INT_MASK_REG, &ret);
+ if (ret) {
+ PRINTM(WARN, "Unable to enable the host interrupt!\n");
+ ret = -EIO;
+ }
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_disable_host_int_mask(struct btsdio_card *card, u8 mask)
+{
+ int ret;
+ u8 host_int_mask;
+
+ 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) {
+ PRINTM(WARN, "Unable to disable the host interrupt!\n");
+ ret = -EIO;
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_poll_card_status(struct btsdio_card *card, u8 bits)
+{
+ unsigned int tries;
+ int ret;
+ u8 status;
+
+ 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:
+ PRINTM(WARN, "%s: FAILED! ret=%d\n", __func__, ret);
+
+done:
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_verify_fw_download(struct btsdio_card *card, int pollnum)
+{
+ int ret = -ETIMEDOUT;
+ u16 firmwarestat;
+ unsigned int tries;
+
+ ENTER();
+
+ /* Wait for firmware to become ready */
+ for (tries = 0; tries < pollnum; tries++) {
+ if (btsdio_read_firmware_status(card, &firmwarestat) < 0)
+ continue;
+
+ if (firmwarestat == FIRMWARE_READY) {
+ ret = 0;
+ break;
+ } else {
+ msleep(10);
+ }
+ }
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_download_helper(struct btsdio_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;
+
+ ENTER();
+
+ ret = request_firmware(&fw_helper, card->helper,
+ &card->func->dev);
+ if ((ret < 0) || !fw_helper) {
+ PRINTM(FATAL, "request_firmware(helper) failed, "
+ "error code = %d\n", ret);
+ ret = -ENOENT;
+ goto done;
+ }
+
+ helper = fw_helper->data;
+ helperlen = fw_helper->size;
+
+ PRINTM(INFO, "Downloading helper image (%d bytes), block size"
+ " %d bytes\n", helperlen, SDIO_BLOCK_SIZE);
+
+ tmphlprbufsz = ALIGN_SZ(BT_UPLD_SIZE, BTSDIO_DMA_ALIGN);
+
+ tmphlprbuf = kmalloc(tmphlprbufsz, GFP_KERNEL);
+ if (!tmphlprbuf) {
+ PRINTM(ERROR, "Unable to allocate buffer for helper."
+ " Terminating download\n");
+ 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 = btsdio_poll_card_status(card,
+ CARD_IO_READY | DN_LD_CARD_RDY);
+ if (ret < 0) {
+ PRINTM(FATAL, "Helper download poll status "
+ "timeout @ %d\n", 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);
+
+ PRINTM(INFO, ".");
+
+ /* Now send the data */
+ ret = sdio_writesb(card->func, card->ioport,
+ helperbuf,
+ FIRMWARE_TRANSFER_NBLOCK *
+ SDIO_BLOCK_SIZE);
+ if (ret < 0) {
+ PRINTM(FATAL, "IO error during helper download @ %d\n",
+ hlprblknow);
+ goto done;
+ }
+
+ hlprblknow += tx_len;
+ } while (true);
+
+ PRINTM(INFO, "\nTransferring helper image EOF block\n");
+
+ memset(helperbuf, 0x0, SDIO_BLOCK_SIZE);
+
+ ret = sdio_writesb(card->func, card->ioport, helperbuf,
+ SDIO_BLOCK_SIZE);
+ if (ret < 0) {
+ PRINTM(FATAL, "IO error in writing helper image EOF block\n");
+ goto done;
+ }
+
+ ret = 0;
+
+done:
+ kfree(tmphlprbuf);
+ if (fw_helper)
+ release_firmware(fw_helper);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_download_firmware_w_helper(struct btsdio_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;
+
+ ENTER();
+
+ ret = request_firmware(&fw_firmware, card->firmware,
+ &card->func->dev);
+ if ((ret < 0) || !fw_firmware) {
+ PRINTM(FATAL, "request_firmware(firmware) failed, "
+ "error code = %d\n", ret);
+ ret = -ENOENT;
+ goto done;
+ }
+
+ firmware = fw_firmware->data;
+ firmwarelen = fw_firmware->size;
+
+ PRINTM(INFO, "Downloading FW image (%d bytes)\n", firmwarelen);
+
+ tmpfwbufsz = ALIGN_SZ(BT_UPLD_SIZE, BTSDIO_DMA_ALIGN);
+ tmpfwbuf = kmalloc(tmpfwbufsz, GFP_KERNEL);
+ if (!tmpfwbuf) {
+ PRINTM(ERROR, "Unable to allocate buffer for firmware."
+ " Terminating download\n");
+ 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 = btsdio_poll_card_status(card,
+ CARD_IO_READY | DN_LD_CARD_RDY);
+ if (ret < 0) {
+ PRINTM(FATAL,
+ "FW download with helper poll status"
+ " timeout @ %d\n", 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) {
+ PRINTM(WARN, "BASE0 register read failed:"
+ " base0 = 0x%04X(%d)."
+ " Terminating download\n",
+ base0, base0);
+ ret = -EIO;
+ goto done;
+ }
+ base1 = sdio_readb(card->func,
+ SQ_READ_BASE_ADDRESS_A1_REG, &ret);
+ if (ret) {
+ PRINTM(WARN, "BASE1 register read failed:"
+ " base1 = 0x%04X(%d)."
+ " Terminating download\n",
+ base1, base1);
+ ret = -EIO;
+ goto done;
+ }
+
+ len = (((u16) base1) << 8) | base0;
+ if (len)
+ break;
+
+ udelay(10);
+ }
+
+ if (!len)
+ break;
+ else if (len > BT_UPLD_SIZE) {
+ PRINTM(FATAL, "FW download failure @ %d,"
+ "invalid length %d\n", offset, len);
+ ret = -EINVAL;
+ goto done;
+ }
+
+ txlen = len;
+
+ if (len & BIT(0)) {
+ count++;
+ if (count > MAX_WRITE_IOMEM_RETRY) {
+ PRINTM(FATAL, "FW download failure @ %d,"
+ "over max retry count\n", offset);
+ ret = -EIO;
+ goto done;
+ }
+ PRINTM(ERROR, "FW CRC error indicated by the helper:"
+ " len = 0x%04X, txlen = %d\n", 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;
+
+ PRINTM(INFO, ".");
+
+ 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) {
+ PRINTM(ERROR, "FW download, writesb(%d) failed"
+ " @%d\n", count, offset);
+ sdio_writeb(card->func, 0x04, CONFIGURATION_REG, &ret);
+ if (ret)
+ PRINTM(ERROR, "writeb failed (CFG)\n");
+ }
+
+ offset += txlen;
+ } while (true);
+
+ PRINTM(INFO, "\nFW download over, size %d bytes\n", offset);
+
+ ret = 0;
+
+done:
+ kfree(tmpfwbuf);
+
+ if (fw_firmware)
+ release_firmware(fw_firmware);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_card_to_host(struct btm_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->btm_dev.hcidev;
+ struct btsdio_card *card = priv->btm_dev.card;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ PRINTM(ERROR, "%s: card or function is NULL!\n", __func__);
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ /* Read the length of data to be transferred */
+ ret = btsdio_read_rx_len(card, &buf_len);
+ if (ret < 0) {
+ PRINTM(ERROR, "%s: read rx_len failed\n", __func__);
+ 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) {
+ PRINTM(ERROR, "%s: invalid packet length: %d\n", __func__,
+ buf_len);
+ ret = -EINVAL;
+ goto exit;
+ }
+
+ /* Allocate buffer */
+ skb = bt_skb_alloc(buf_block_len * blksz + BTSDIO_DMA_ALIGN,
+ GFP_ATOMIC);
+ if (skb == NULL) {
+ PRINTM(WARN, "%s: No free skb\n", __func__);
+ 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) {
+ PRINTM(ERROR, "%s: readsb failed: %d\n", __func__, ret);
+ ret = -EIO;
+ goto exit;
+ }
+
+ DBG_HEXDUMP(DBG_DATA, "SDIO Blk Rd", payload, blksz * buf_block_len);
+
+ /* 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)
+ btm_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 (btm_process_event(priv, skb))
+ hci_recv_frame(skb);
+
+ hdev->stat.byte_rx += buf_len;
+ break;
+
+ default:
+ PRINTM(INFO, "%s: Unknow packet type:%d\n", __func__, type);
+ kfree_skb(skb);
+ skb = NULL;
+ break;
+ }
+
+exit:
+ if (ret) {
+ hdev->stat.err_rx++;
+ if (skb)
+ kfree_skb(skb);
+ }
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_get_int_status(struct btm_private *priv, u8 * ireg)
+{
+ int ret;
+ u8 sdio_ireg = 0;
+ struct btsdio_card *card = priv->btm_dev.card;
+
+ ENTER();
+
+ *ireg = 0;
+
+ sdio_ireg = sdio_readb(card->func, HOST_INTSTATUS_REG, &ret);
+ if (ret) {
+ PRINTM(WARN, "sdio_readb: read int status "
+ "register failed\n");
+ 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.
+ */
+ PRINTM(INFO, "sdio_ireg = 0x%x\n", sdio_ireg);
+
+ sdio_writeb(card->func, ~(sdio_ireg) & (DN_LD_HOST_INT_STATUS |
+ UP_LD_HOST_INT_STATUS),
+ HOST_INTSTATUS_REG, &ret);
+ if (ret) {
+ PRINTM(WARN, "sdio_writeb: clear int status "
+ "register failed\n");
+ ret = -EIO;
+ goto done;
+ }
+ }
+
+ if (sdio_ireg & DN_LD_HOST_INT_STATUS) {
+ if (priv->btm_dev.tx_dnld_rdy)
+ PRINTM(WARN, "tx_done already received: "
+ " int_status=0x%x\n", sdio_ireg);
+ else
+ priv->btm_dev.tx_dnld_rdy = true;
+ }
+
+ if (sdio_ireg & UP_LD_HOST_INT_STATUS)
+ btsdio_card_to_host(priv);
+
+ *ireg = sdio_ireg;
+
+ ret = 0;
+
+done:
+ LEAVE();
+
+ return ret;
+}
+
+static void btsdio_interrupt(struct sdio_func *func)
+{
+ struct btm_private *priv;
+ struct hci_dev *hcidev;
+ struct btsdio_card *card;
+ u8 ireg = 0;
+
+ ENTER();
+
+ card = sdio_get_drvdata(func);
+ if (card && card->priv) {
+ priv = card->priv;
+ hcidev = priv->btm_dev.hcidev;
+
+ if (btsdio_get_int_status(priv, &ireg))
+ PRINTM(ERROR, "%s:reading HOST_INT_STATUS_REG failed\n",
+ __func__);
+ else
+ PRINTM(INFO, "%s: HOST_INT_STATUS_REG %#x\n",
+ __func__, ireg);
+
+ btm_interrupt(priv);
+ }
+
+ LEAVE();
+}
+
+static int btsdio_register_dev(struct btsdio_card *card)
+{
+ int ret = 0, i;
+ u8 reg;
+ struct sdio_func *func;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ PRINTM(ERROR, "Error: card or function is NULL!\n");
+ ret = -EINVAL;
+ goto failed;
+ }
+
+ func = card->func;
+
+ for (i = 0; i < ARRAY_SIZE(btsdio_devices); i++) {
+ if (func->device == btsdio_devices[i].dev_id)
+ break;
+ }
+
+ if (i == ARRAY_SIZE(btsdio_devices)) {
+ PRINTM(ERROR, "Error: unknown device id 0x%x\n",
+ func->device);
+ ret = -EINVAL;
+ goto failed;
+ }
+
+ btsdio_devices[i].card = card;
+
+ card->helper = btsdio_devices[i].helper;
+ card->firmware = btsdio_devices[i].firmware;
+
+ sdio_claim_host(func);
+
+ ret = sdio_enable_func(func);
+ if (ret) {
+ PRINTM(FATAL, "sdio_enable_func() failed: ret=%d\n", ret);
+ ret = -EIO;
+ goto release_host;
+ }
+
+ ret = sdio_claim_irq(func, btsdio_interrupt);
+ if (ret) {
+ PRINTM(FATAL, "sdio_claim_irq failed: ret=%d\n", ret);
+ ret = -EIO;
+ goto disable_func;
+ }
+
+ ret = sdio_set_block_size(card->func, SDIO_BLOCK_SIZE);
+ if (ret) {
+ PRINTM(FATAL, "%s: cannot set SDIO block size\n", __func__);
+ 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);
+
+ PRINTM(INFO, "SDIO FUNC%d IO port: 0x%x\n", func->num, card->ioport);
+
+ sdio_set_drvdata(func, card);
+
+ sdio_release_host(func);
+
+ LEAVE();
+ return 0;
+
+release_irq:
+ sdio_release_irq(func);
+
+disable_func:
+ sdio_disable_func(func);
+
+release_host:
+ sdio_release_host(func);
+
+failed:
+ LEAVE();
+ return ret;
+}
+
+static int btsdio_unregister_dev(struct btsdio_card *card)
+{
+ int i;
+
+ 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);
+ for (i = 0; i < ARRAY_SIZE(btsdio_devices); i++) {
+ if (card->func->device == btsdio_devices[i].dev_id) {
+ btsdio_devices[i].card = NULL;
+ break;
+ }
+ }
+ }
+
+ LEAVE();
+ return 0;
+}
+
+static int btsdio_enable_host_int(struct btsdio_card *card)
+{
+ int ret;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ LEAVE();
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ ret = btsdio_enable_host_int_mask(card, HIM_ENABLE);
+
+ btsdio_get_rx_unit(card);
+
+ sdio_release_host(card->func);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_disable_host_int(struct btsdio_card *card)
+{
+ int ret;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ LEAVE();
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ ret = btsdio_disable_host_int_mask(card, HIM_DISABLE);
+
+ sdio_release_host(card->func);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_host_to_card(struct btm_private *priv, u8 *payload, u16 nb)
+{
+ struct btsdio_card *card = priv->btm_dev.card;
+ int ret = 0;
+ int buf_block_len;
+ int blksz;
+ int i = 0;
+ u8 *buf = NULL;
+ void *tmpbuf = NULL;
+ int tmpbufsz;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ PRINTM(ERROR, "card or function is NULL!\n");
+ 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++;
+ PRINTM(ERROR, "%s: i=%d writesb failed: %d\n",
+ __func__, i, ret);
+ ret = -EIO;
+ if (i > MAX_WRITE_IOMEM_RETRY)
+ goto exit;
+ } else {
+ DBG_HEXDUMP(DBG_DATA, "SDIO Blk Wr", payload, nb);
+ }
+ } while (ret);
+
+ priv->btm_dev.tx_dnld_rdy = false;
+
+exit:
+ sdio_release_host(card->func);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_download_fw(struct btsdio_card *card)
+{
+ int ret = 0;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ PRINTM(ERROR, "card or function is NULL!\n");
+ LEAVE();
+ return -EINVAL;
+ }
+ sdio_claim_host(card->func);
+
+ if (!btsdio_verify_fw_download(card, 1)) {
+ PRINTM(INFO, "Firmware already downloaded!\n");
+ goto done;
+ }
+
+ ret = btsdio_download_helper(card);
+ if (ret) {
+ PRINTM(ERROR, "Failed to download helper!\n");
+ ret = -EIO;
+ goto done;
+ }
+
+ if (btsdio_download_firmware_w_helper(card)) {
+ PRINTM(ERROR, "Failed to download firmware!\n");
+ ret = -EIO;
+ goto done;
+ }
+
+ if (btsdio_verify_fw_download(card, MAX_POLL_TRIES)) {
+ PRINTM(ERROR, "FW failed to be active in time!\n");
+ ret = -ETIMEDOUT;
+ goto done;
+ }
+
+done:
+ sdio_release_host(card->func);
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_wakeup_firmware(struct btm_private *priv)
+{
+ struct btsdio_card *card = priv->btm_dev.card;
+ int ret = 0;
+
+ ENTER();
+
+ if (!card || !card->func) {
+ PRINTM(ERROR, "card or function is NULL!\n");
+ LEAVE();
+ return -EINVAL;
+ }
+
+ sdio_claim_host(card->func);
+
+ sdio_writeb(card->func, HOST_POWER_UP, CONFIGURATION_REG, &ret);
+
+ sdio_release_host(card->func);
+
+ PRINTM(CMD, "wake up firmware\n");
+
+ LEAVE();
+
+ return ret;
+}
+
+static int btsdio_probe_card(struct sdio_func *func,
+ const struct sdio_device_id *id)
+{
+ int ret = 0;
+ struct btm_private *priv = NULL;
+ struct btsdio_card *card = NULL;
+
+ ENTER();
+
+ PRINTM(INFO, "vendor=0x%x, device=0x%x, class=%d, fn=%d\n",
+ id->vendor, id->device, id->class, func->num);
+
+ card = kzalloc(sizeof(*card), GFP_KERNEL);
+ if (!card) {
+ ret = -ENOMEM;
+ goto done;
+ }
+
+ card->func = func;
+
+ if (btsdio_register_dev(card) < 0) {
+ PRINTM(FATAL, "Failed to register BT device!\n");
+ ret = -ENODEV;
+ goto free_card;
+ }
+
+ /* Disable the interrupts on the card */
+ btsdio_disable_host_int(card);
+
+ if (btsdio_download_fw(card)) {
+ PRINTM(FATAL, "Downloading firmware failed!\n");
+ ret = -ENODEV;
+ goto unreg_dev;
+ }
+
+ msleep(100);
+
+ btsdio_enable_host_int(card);
+
+ priv = btm_add_card(card);
+ if (!priv) {
+ PRINTM(FATAL, "Initializing card failed!\n");
+ ret = -ENODEV;
+ goto disable_host_int;
+ }
+
+ card->priv = priv;
+
+ /* Initialize the interface specific function pointers */
+ priv->hw_host_to_card = btsdio_host_to_card;
+ priv->hw_wakeup_firmware = btsdio_wakeup_firmware;
+
+ strncpy(priv->btm_dev.name, "bt_mrvl_sdio0",
+ sizeof(priv->btm_dev.name));
+
+ btm_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
+
+ LEAVE();
+
+ return 0;
+
+disable_host_int:
+ btsdio_disable_host_int(card);
+unreg_dev:
+ btsdio_unregister_dev(card);
+free_card:
+ kfree(card);
+done:
+ LEAVE();
+
+ return ret;
+}
+
+static void btsdio_remove_card(struct sdio_func *func)
+{
+ struct btsdio_card *card;
+
+ ENTER();
+
+ if (func) {
+ card = sdio_get_drvdata(func);
+ if (card) {
+ btsdio_disable_host_int(card);
+ PRINTM(INFO, "unregester dev\n");
+ btsdio_unregister_dev(card);
+ btm_remove_card(card->priv);
+ kfree(card);
+ }
+ }
+
+ LEAVE();
+}
+
+static struct sdio_driver bt_mrvl_sdio = {
+ .name = "bt_mrvl_sdio",
+ .id_table = btsdio_ids,
+ .probe = btsdio_probe_card,
+ .remove = btsdio_remove_card,
+};
+
+static int btsdio_init_module(void)
+{
+ ENTER();
+
+ if (sdio_register_driver(&bt_mrvl_sdio) != 0) {
+ PRINTM(FATAL, "SDIO Driver Registration Failed\n");
+ LEAVE();
+ return -ENODEV;
+ }
+
+ LEAVE();
+
+ return 0;
+}
+
+static void btsdio_exit_module(void)
+{
+ int i;
+ struct btsdio_card *card;
+
+ ENTER();
+
+ for (i = 0; i < ARRAY_SIZE(btsdio_devices); i++) {
+ card = btsdio_devices[i].card;
+ if (card && card->priv)
+ btm_send_module_cfg_cmd(card->priv,
+ MODULE_SHUTDOWN_REQ);
+ }
+
+ sdio_unregister_driver(&bt_mrvl_sdio);
+
+ LEAVE();
+}
+
+module_init(btsdio_init_module);
+module_exit(btsdio_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/bt_mrvl/btm_sdio.h b/drivers/bluetooth/bt_mrvl/btm_sdio.h
new file mode 100644
index 0000000..c4e6863
--- /dev/null
+++ b/drivers/bluetooth/bt_mrvl/btm_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 _BTM_SDIO_H_
+#define _BTM_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 CONFIGURATION_REG 0x03
+#define HOST_POWER_UP BIT(1)
+
+#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 btsdio_card {
+ struct sdio_func *func;
+ u32 ioport;
+ const char *helper;
+ const char *firmware;
+ u8 rx_unit;
+ struct btm_private *priv;
+};
+
+struct btsdio_device {
+ unsigned short dev_id;
+ const char *helper;
+ const char *firmware;
+ struct btsdio_card *card;
+};
+
+
+/* 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 /* _BTM_SDIO_H_ */
--
1.5.3.6


2009-05-21 00:35:41

by Bing Zhao

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

add bt_mrvl.txt to Documentation/bluetooth

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/bluetooth/00-INDEX | 4 +
Documentation/bluetooth/bt_mrvl.txt | 135 +++++++++++++++++++++++++++++++++++
2 files changed, 139 insertions(+), 0 deletions(-)
create mode 100644 Documentation/bluetooth/00-INDEX
create mode 100644 Documentation/bluetooth/bt_mrvl.txt

diff --git a/Documentation/bluetooth/00-INDEX b/Documentation/bluetooth/00-INDEX
new file mode 100644
index 0000000..2d39fa3
--- /dev/null
+++ b/Documentation/bluetooth/00-INDEX
@@ -0,0 +1,4 @@
+00-INDEX
+ - this file
+bt_mrvl.txt
+ - info on Marvell Bluetooth driver usage.
diff --git a/Documentation/bluetooth/bt_mrvl.txt b/Documentation/bluetooth/bt_mrvl.txt
new file mode 100644
index 0000000..d8ca36e
--- /dev/null
+++ b/Documentation/bluetooth/bt_mrvl.txt
@@ -0,0 +1,135 @@
+=======================================================================
+ README for bt_mrvl driver
+=======================================================================
+
+
+All commands are used via debugfs interface.
+
+=====================
+Set/get driver configurations:
+
+Path: /debug/bt_mrvl/config/
+
+drvdbg=[n]
+ This command is used to set the bit masks of driver debug messages.
+
+ bit 0: MSG PRINTM(MSG,...)
+ bit 1: FATAL PRINTM(FATAL,...)
+ bit 2: ERROR PRINTM(ERROR,...)
+ bit 3: CMD PRINTM(CMD,...)
+ bit 27: DATA DBG_HEXDUMP(DBG_DATA,...)
+ bit 28: ENTRY PRINTM(ENTRY,...), ENTER(), LEAVE()
+ bit 29: WARN PRINTM(WARN,...)
+ bit 30: INFO PRINTM(INFO,...)
+
+ Usage:
+ # Enable MSG, FATAL, ERROR debug messages:
+ echo 0x7 > /debug/bt_mrvl/config/drvdbg
+
+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/bt_mrvl/config/gpiogap
+ echo 1 > /debug/bt_mrvl/config/hscfgcmd
+
+ # Use GPIO pin #3 to wake up the host and set GAP to 0xff:
+ echo 0x03ff > /debug/bt_mrvl/config/gpiogap
+ echo 1 > /debug/bt_mrvl/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/bt_mrvl/config/psmode
+ echo 1 > /debug/bt_mrvl/config/pscmd
+
+ # Disable auto sleep mode
+ echo 0 > /debug/bt_mrvl/config/psmode
+ echo 1 > /debug/bt_mrvl/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/bt_mrvl/config/hsmode
+ echo 1 > /debug/bt_mrvl/config/hscmd
+
+ # Wake up firmware
+ echo 0 > /debug/bt_mrvl/config/hsmode
+ echo 1 > /debug/bt_mrvl/config/hscmd
+
+
+======================
+Get driver status:
+
+Path: /debug/bt_mrvl/status/
+
+Usage:
+ cat /debug/bt_mrvl/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