Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 1 | /** |
| 2 | * Marvell Bluetooth driver |
| 3 | * |
| 4 | * Copyright (C) 2009, Marvell International Ltd. |
| 5 | * |
| 6 | * This software file (the "File") is distributed by Marvell International |
| 7 | * Ltd. under the terms of the GNU General Public License Version 2, June 1991 |
| 8 | * (the "License"). You may use, redistribute and/or modify this File in |
| 9 | * accordance with the terms and conditions of the License, a copy of which |
| 10 | * is available by writing to the Free Software Foundation, Inc., |
| 11 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the |
| 12 | * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. |
| 13 | * |
| 14 | * |
| 15 | * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE |
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE |
| 17 | * ARE EXPRESSLY DISCLAIMED. The License provides additional details about |
| 18 | * this warranty disclaimer. |
| 19 | **/ |
| 20 | |
Paul Gortmaker | a59b968 | 2011-08-29 16:44:23 -0400 | [diff] [blame] | 21 | #include <linux/module.h> |
| 22 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 23 | #include <net/bluetooth/bluetooth.h> |
| 24 | #include <net/bluetooth/hci_core.h> |
| 25 | |
| 26 | #include "btmrvl_drv.h" |
| 27 | |
| 28 | #define VERSION "1.0" |
| 29 | |
| 30 | /* |
| 31 | * This function is called by interface specific interrupt handler. |
| 32 | * It updates Power Save & Host Sleep states, and wakes up the main |
| 33 | * thread. |
| 34 | */ |
| 35 | void btmrvl_interrupt(struct btmrvl_private *priv) |
| 36 | { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 37 | priv->adapter->ps_state = PS_AWAKE; |
| 38 | |
| 39 | priv->adapter->wakeup_tries = 0; |
| 40 | |
| 41 | priv->adapter->int_count++; |
| 42 | |
| 43 | wake_up_interruptible(&priv->main_thread.wait_q); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 44 | } |
| 45 | EXPORT_SYMBOL_GPL(btmrvl_interrupt); |
| 46 | |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 47 | bool btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 48 | { |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 49 | struct hci_event_hdr *hdr = (void *) skb->data; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 50 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 51 | if (hdr->evt == HCI_EV_CMD_COMPLETE) { |
Andrei Emeltchenko | 2c2453f | 2012-07-09 13:57:18 +0300 | [diff] [blame] | 52 | struct hci_ev_cmd_complete *ec; |
| 53 | u16 opcode, ocf, ogf; |
| 54 | |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 55 | ec = (void *) (skb->data + HCI_EVENT_HDR_SIZE); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 56 | opcode = __le16_to_cpu(ec->opcode); |
| 57 | ocf = hci_opcode_ocf(opcode); |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 58 | ogf = hci_opcode_ogf(opcode); |
| 59 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 60 | if (priv->btmrvl_dev.sendcmdflag) { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 61 | priv->btmrvl_dev.sendcmdflag = false; |
| 62 | priv->adapter->cmd_complete = true; |
| 63 | wake_up_interruptible(&priv->adapter->cmd_wait_q); |
| 64 | } |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 65 | |
| 66 | if (ogf == OGF) { |
Andrei Emeltchenko | 2c2453f | 2012-07-09 13:57:18 +0300 | [diff] [blame] | 67 | BT_DBG("vendor event skipped: ogf 0x%4.4x ocf 0x%4.4x", |
| 68 | ogf, ocf); |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 69 | kfree_skb(skb); |
| 70 | return false; |
| 71 | } |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 72 | } |
Andrei Emeltchenko | ea1e76a | 2012-06-13 13:35:44 +0300 | [diff] [blame] | 73 | |
| 74 | return true; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 75 | } |
| 76 | EXPORT_SYMBOL_GPL(btmrvl_check_evtpkt); |
| 77 | |
| 78 | int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb) |
| 79 | { |
| 80 | struct btmrvl_adapter *adapter = priv->adapter; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 81 | struct btmrvl_event *event; |
Dan Carpenter | 31f085f | 2010-03-08 15:15:59 +0300 | [diff] [blame] | 82 | int ret = 0; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 83 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 84 | event = (struct btmrvl_event *) skb->data; |
| 85 | if (event->ec != 0xff) { |
| 86 | BT_DBG("Not Marvell Event=%x", event->ec); |
| 87 | ret = -EINVAL; |
| 88 | goto exit; |
| 89 | } |
| 90 | |
| 91 | switch (event->data[0]) { |
| 92 | case BT_CMD_AUTO_SLEEP_MODE: |
| 93 | if (!event->data[2]) { |
| 94 | if (event->data[1] == BT_PS_ENABLE) |
| 95 | adapter->psmode = 1; |
| 96 | else |
| 97 | adapter->psmode = 0; |
| 98 | BT_DBG("PS Mode:%s", |
| 99 | (adapter->psmode) ? "Enable" : "Disable"); |
| 100 | } else { |
| 101 | BT_DBG("PS Mode command failed"); |
| 102 | } |
| 103 | break; |
| 104 | |
| 105 | case BT_CMD_HOST_SLEEP_CONFIG: |
| 106 | if (!event->data[3]) |
| 107 | BT_DBG("gpio=%x, gap=%x", event->data[1], |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 108 | event->data[2]); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 109 | else |
| 110 | BT_DBG("HSCFG command failed"); |
| 111 | break; |
| 112 | |
| 113 | case BT_CMD_HOST_SLEEP_ENABLE: |
| 114 | if (!event->data[1]) { |
| 115 | adapter->hs_state = HS_ACTIVATED; |
| 116 | if (adapter->psmode) |
| 117 | adapter->ps_state = PS_SLEEP; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 118 | BT_DBG("HS ACTIVATED!"); |
| 119 | } else { |
| 120 | BT_DBG("HS Enable failed"); |
| 121 | } |
| 122 | break; |
| 123 | |
| 124 | case BT_CMD_MODULE_CFG_REQ: |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 125 | if (priv->btmrvl_dev.sendcmdflag && |
| 126 | event->data[1] == MODULE_BRINGUP_REQ) { |
Bing Zhao | 903c843 | 2010-03-03 14:37:35 -0800 | [diff] [blame] | 127 | BT_DBG("EVENT:%s", |
| 128 | ((event->data[2] == MODULE_BROUGHT_UP) || |
| 129 | (event->data[2] == MODULE_ALREADY_UP)) ? |
| 130 | "Bring-up succeed" : "Bring-up failed"); |
Bing Zhao | f120c6b | 2010-03-03 14:37:37 -0800 | [diff] [blame] | 131 | |
David Vrabel | 8f1e174 | 2010-08-09 17:38:10 -0400 | [diff] [blame] | 132 | if (event->length > 3 && event->data[3]) |
| 133 | priv->btmrvl_dev.dev_type = HCI_AMP; |
Bing Zhao | f120c6b | 2010-03-03 14:37:37 -0800 | [diff] [blame] | 134 | else |
| 135 | priv->btmrvl_dev.dev_type = HCI_BREDR; |
| 136 | |
| 137 | BT_DBG("dev_type: %d", priv->btmrvl_dev.dev_type); |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 138 | } else if (priv->btmrvl_dev.sendcmdflag && |
| 139 | event->data[1] == MODULE_SHUTDOWN_REQ) { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 140 | BT_DBG("EVENT:%s", (event->data[2]) ? |
| 141 | "Shutdown failed" : "Shutdown succeed"); |
| 142 | } else { |
| 143 | BT_DBG("BT_CMD_MODULE_CFG_REQ resp for APP"); |
| 144 | ret = -EINVAL; |
| 145 | } |
| 146 | break; |
| 147 | |
| 148 | case BT_EVENT_POWER_STATE: |
| 149 | if (event->data[1] == BT_PS_SLEEP) |
| 150 | adapter->ps_state = PS_SLEEP; |
| 151 | BT_DBG("EVENT:%s", |
| 152 | (adapter->ps_state) ? "PS_SLEEP" : "PS_AWAKE"); |
| 153 | break; |
| 154 | |
| 155 | default: |
| 156 | BT_DBG("Unknown Event=%d", event->data[0]); |
| 157 | ret = -EINVAL; |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | exit: |
| 162 | if (!ret) |
| 163 | kfree_skb(skb); |
| 164 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 165 | return ret; |
| 166 | } |
| 167 | EXPORT_SYMBOL_GPL(btmrvl_process_event); |
| 168 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 169 | static int btmrvl_send_sync_cmd(struct btmrvl_private *priv, u16 cmd_no, |
| 170 | const void *param, u8 len) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 171 | { |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 172 | struct sk_buff *skb; |
Amitkumar Karwar | 7d5b400 | 2013-10-01 12:19:13 -0700 | [diff] [blame] | 173 | struct hci_command_hdr *hdr; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 174 | |
Amitkumar Karwar | 7d5b400 | 2013-10-01 12:19:13 -0700 | [diff] [blame] | 175 | skb = bt_skb_alloc(HCI_COMMAND_HDR_SIZE + len, GFP_ATOMIC); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 176 | if (skb == NULL) { |
| 177 | BT_ERR("No free skb"); |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 178 | return -ENOMEM; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Amitkumar Karwar | 7d5b400 | 2013-10-01 12:19:13 -0700 | [diff] [blame] | 181 | hdr = (struct hci_command_hdr *)skb_put(skb, HCI_COMMAND_HDR_SIZE); |
| 182 | hdr->opcode = cpu_to_le16(hci_opcode_pack(OGF, cmd_no)); |
| 183 | hdr->plen = len; |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 184 | |
| 185 | if (len) |
Amitkumar Karwar | 7d5b400 | 2013-10-01 12:19:13 -0700 | [diff] [blame] | 186 | memcpy(skb_put(skb, len), param, len); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 187 | |
| 188 | bt_cb(skb)->pkt_type = MRVL_VENDOR_PKT; |
| 189 | |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 190 | skb->dev = (void *) priv->btmrvl_dev.hcidev; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 191 | skb_queue_head(&priv->adapter->tx_queue, skb); |
| 192 | |
| 193 | priv->btmrvl_dev.sendcmdflag = true; |
| 194 | |
| 195 | priv->adapter->cmd_complete = false; |
| 196 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 197 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 198 | |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 199 | if (!wait_event_interruptible_timeout(priv->adapter->cmd_wait_q, |
| 200 | priv->adapter->cmd_complete, |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 201 | msecs_to_jiffies(WAIT_UNTIL_CMD_RESP))) |
| 202 | return -ETIMEDOUT; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 203 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, int subcmd) |
| 208 | { |
| 209 | int ret; |
| 210 | |
| 211 | ret = btmrvl_send_sync_cmd(priv, BT_CMD_MODULE_CFG_REQ, &subcmd, 1); |
| 212 | if (ret) |
| 213 | BT_ERR("module_cfg_cmd(%x) failed\n", subcmd); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 214 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 215 | return ret; |
| 216 | } |
| 217 | EXPORT_SYMBOL_GPL(btmrvl_send_module_cfg_cmd); |
| 218 | |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 219 | int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv) |
| 220 | { |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 221 | int ret; |
| 222 | u8 param[2]; |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 223 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 224 | param[0] = (priv->btmrvl_dev.gpio_gap & 0xff00) >> 8; |
| 225 | param[1] = (u8) (priv->btmrvl_dev.gpio_gap & 0x00ff); |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 226 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 227 | BT_DBG("Sending HSCFG Command, gpio=0x%x, gap=0x%x", |
| 228 | param[0], param[1]); |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 229 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 230 | ret = btmrvl_send_sync_cmd(priv, BT_CMD_HOST_SLEEP_CONFIG, param, 2); |
| 231 | if (ret) |
| 232 | BT_ERR("HSCFG command failed\n"); |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 233 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 234 | return ret; |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 235 | } |
| 236 | EXPORT_SYMBOL_GPL(btmrvl_send_hscfg_cmd); |
| 237 | |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 238 | int btmrvl_enable_ps(struct btmrvl_private *priv) |
| 239 | { |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 240 | int ret; |
| 241 | u8 param; |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 242 | |
| 243 | if (priv->btmrvl_dev.psmode) |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 244 | param = BT_PS_ENABLE; |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 245 | else |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 246 | param = BT_PS_DISABLE; |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 247 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 248 | ret = btmrvl_send_sync_cmd(priv, BT_CMD_AUTO_SLEEP_MODE, ¶m, 1); |
| 249 | if (ret) |
| 250 | BT_ERR("PSMODE command failed\n"); |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | EXPORT_SYMBOL_GPL(btmrvl_enable_ps); |
| 255 | |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 256 | int btmrvl_enable_hs(struct btmrvl_private *priv) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 257 | { |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 258 | int ret; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 259 | |
Amitkumar Karwar | c037874 | 2013-10-01 12:19:12 -0700 | [diff] [blame] | 260 | ret = btmrvl_send_sync_cmd(priv, BT_CMD_HOST_SLEEP_ENABLE, NULL, 0); |
| 261 | if (ret) |
| 262 | BT_ERR("Host sleep enable command failed\n"); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 263 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 264 | return ret; |
| 265 | } |
Amitkumar Karwar | ba54a16 | 2012-04-25 11:43:54 -0700 | [diff] [blame] | 266 | EXPORT_SYMBOL_GPL(btmrvl_enable_hs); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 267 | |
| 268 | int btmrvl_prepare_command(struct btmrvl_private *priv) |
| 269 | { |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 270 | int ret = 0; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 271 | |
| 272 | if (priv->btmrvl_dev.hscfgcmd) { |
| 273 | priv->btmrvl_dev.hscfgcmd = 0; |
Amitkumar Karwar | 2a8ff61 | 2012-04-24 16:31:40 -0700 | [diff] [blame] | 274 | btmrvl_send_hscfg_cmd(priv); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | if (priv->btmrvl_dev.pscmd) { |
| 278 | priv->btmrvl_dev.pscmd = 0; |
Amitkumar Karwar | 32fd639 | 2009-09-30 11:18:30 -0700 | [diff] [blame] | 279 | btmrvl_enable_ps(priv); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | if (priv->btmrvl_dev.hscmd) { |
| 283 | priv->btmrvl_dev.hscmd = 0; |
| 284 | |
| 285 | if (priv->btmrvl_dev.hsmode) { |
| 286 | ret = btmrvl_enable_hs(priv); |
| 287 | } else { |
| 288 | ret = priv->hw_wakeup_firmware(priv); |
| 289 | priv->adapter->hs_state = HS_DEACTIVATED; |
| 290 | } |
| 291 | } |
| 292 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 293 | return ret; |
| 294 | } |
| 295 | |
| 296 | static int btmrvl_tx_pkt(struct btmrvl_private *priv, struct sk_buff *skb) |
| 297 | { |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 298 | int ret = 0; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 299 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 300 | if (!skb || !skb->data) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 301 | return -EINVAL; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 302 | |
| 303 | if (!skb->len || ((skb->len + BTM_HEADER_LEN) > BTM_UPLD_SIZE)) { |
| 304 | BT_ERR("Tx Error: Bad skb length %d : %d", |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 305 | skb->len, BTM_UPLD_SIZE); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 306 | return -EINVAL; |
| 307 | } |
| 308 | |
| 309 | if (skb_headroom(skb) < BTM_HEADER_LEN) { |
| 310 | struct sk_buff *tmp = skb; |
| 311 | |
| 312 | skb = skb_realloc_headroom(skb, BTM_HEADER_LEN); |
| 313 | if (!skb) { |
| 314 | BT_ERR("Tx Error: realloc_headroom failed %d", |
| 315 | BTM_HEADER_LEN); |
| 316 | skb = tmp; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 317 | return -EINVAL; |
| 318 | } |
| 319 | |
| 320 | kfree_skb(tmp); |
| 321 | } |
| 322 | |
| 323 | skb_push(skb, BTM_HEADER_LEN); |
| 324 | |
| 325 | /* header type: byte[3] |
| 326 | * HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, 0xFE = Vendor |
| 327 | * header length: byte[2][1][0] |
| 328 | */ |
| 329 | |
| 330 | skb->data[0] = (skb->len & 0x0000ff); |
| 331 | skb->data[1] = (skb->len & 0x00ff00) >> 8; |
| 332 | skb->data[2] = (skb->len & 0xff0000) >> 16; |
| 333 | skb->data[3] = bt_cb(skb)->pkt_type; |
| 334 | |
| 335 | if (priv->hw_host_to_card) |
| 336 | ret = priv->hw_host_to_card(priv, skb->data, skb->len); |
| 337 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 338 | return ret; |
| 339 | } |
| 340 | |
| 341 | static void btmrvl_init_adapter(struct btmrvl_private *priv) |
| 342 | { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 343 | skb_queue_head_init(&priv->adapter->tx_queue); |
| 344 | |
| 345 | priv->adapter->ps_state = PS_AWAKE; |
| 346 | |
| 347 | init_waitqueue_head(&priv->adapter->cmd_wait_q); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | static void btmrvl_free_adapter(struct btmrvl_private *priv) |
| 351 | { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 352 | skb_queue_purge(&priv->adapter->tx_queue); |
| 353 | |
| 354 | kfree(priv->adapter); |
| 355 | |
| 356 | priv->adapter = NULL; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 359 | static int btmrvl_ioctl(struct hci_dev *hdev, |
| 360 | unsigned int cmd, unsigned long arg) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 361 | { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 362 | return -ENOIOCTLCMD; |
| 363 | } |
| 364 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 365 | static int btmrvl_send_frame(struct sk_buff *skb) |
| 366 | { |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 367 | struct hci_dev *hdev = (struct hci_dev *) skb->dev; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 368 | struct btmrvl_private *priv = NULL; |
| 369 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 370 | BT_DBG("type=%d, len=%d", skb->pkt_type, skb->len); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 371 | |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 372 | if (!hdev) { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 373 | BT_ERR("Frame for unknown HCI device"); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 374 | return -ENODEV; |
| 375 | } |
| 376 | |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 377 | priv = hci_get_drvdata(hdev); |
| 378 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 379 | if (!test_bit(HCI_RUNNING, &hdev->flags)) { |
| 380 | BT_ERR("Failed testing HCI_RUNING, flags=%lx", hdev->flags); |
| 381 | print_hex_dump_bytes("data: ", DUMP_PREFIX_OFFSET, |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 382 | skb->data, skb->len); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 383 | return -EBUSY; |
| 384 | } |
| 385 | |
| 386 | switch (bt_cb(skb)->pkt_type) { |
| 387 | case HCI_COMMAND_PKT: |
| 388 | hdev->stat.cmd_tx++; |
| 389 | break; |
| 390 | |
| 391 | case HCI_ACLDATA_PKT: |
| 392 | hdev->stat.acl_tx++; |
| 393 | break; |
| 394 | |
| 395 | case HCI_SCODATA_PKT: |
| 396 | hdev->stat.sco_tx++; |
| 397 | break; |
| 398 | } |
| 399 | |
| 400 | skb_queue_tail(&priv->adapter->tx_queue, skb); |
| 401 | |
| 402 | wake_up_interruptible(&priv->main_thread.wait_q); |
| 403 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | static int btmrvl_flush(struct hci_dev *hdev) |
| 408 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 409 | struct btmrvl_private *priv = hci_get_drvdata(hdev); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 410 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 411 | skb_queue_purge(&priv->adapter->tx_queue); |
| 412 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | static int btmrvl_close(struct hci_dev *hdev) |
| 417 | { |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 418 | struct btmrvl_private *priv = hci_get_drvdata(hdev); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 419 | |
Marcel Holtmann | 9374253 | 2009-06-13 07:40:18 +0200 | [diff] [blame] | 420 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 421 | return 0; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 422 | |
| 423 | skb_queue_purge(&priv->adapter->tx_queue); |
| 424 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int btmrvl_open(struct hci_dev *hdev) |
| 429 | { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 430 | set_bit(HCI_RUNNING, &hdev->flags); |
| 431 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 432 | return 0; |
| 433 | } |
| 434 | |
Amitkumar Karwar | 2cc8689 | 2013-10-01 12:19:15 -0700 | [diff] [blame] | 435 | /* |
| 436 | * This function parses provided calibration data input. It should contain |
| 437 | * hex bytes separated by space or new line character. Here is an example. |
| 438 | * 00 1C 01 37 FF FF FF FF 02 04 7F 01 |
| 439 | * CE BA 00 00 00 2D C6 C0 00 00 00 00 |
| 440 | * 00 F0 00 00 |
| 441 | */ |
| 442 | static int btmrvl_parse_cal_cfg(const u8 *src, u32 len, u8 *dst, u32 dst_size) |
| 443 | { |
| 444 | const u8 *s = src; |
| 445 | u8 *d = dst; |
| 446 | int ret; |
| 447 | u8 tmp[3]; |
| 448 | |
| 449 | tmp[2] = '\0'; |
| 450 | while ((s - src) <= len - 2) { |
| 451 | if (isspace(*s)) { |
| 452 | s++; |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | if (isxdigit(*s)) { |
| 457 | if ((d - dst) >= dst_size) { |
| 458 | BT_ERR("calibration data file too big!!!"); |
| 459 | return -EINVAL; |
| 460 | } |
| 461 | |
| 462 | memcpy(tmp, s, 2); |
| 463 | |
| 464 | ret = kstrtou8(tmp, 16, d++); |
| 465 | if (ret < 0) |
| 466 | return ret; |
| 467 | |
| 468 | s += 2; |
| 469 | } else { |
| 470 | return -EINVAL; |
| 471 | } |
| 472 | } |
| 473 | if (d == dst) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | static int btmrvl_load_cal_data(struct btmrvl_private *priv, |
| 480 | u8 *config_data) |
| 481 | { |
| 482 | int i, ret; |
| 483 | u8 data[BT_CMD_DATA_SIZE]; |
| 484 | |
| 485 | data[0] = 0x00; |
| 486 | data[1] = 0x00; |
| 487 | data[2] = 0x00; |
| 488 | data[3] = BT_CMD_DATA_SIZE - 4; |
| 489 | |
| 490 | /* Swap cal-data bytes. Each four bytes are swapped. Considering 4 |
| 491 | * byte SDIO header offset, mapping of input and output bytes will be |
| 492 | * {3, 2, 1, 0} -> {0+4, 1+4, 2+4, 3+4}, |
| 493 | * {7, 6, 5, 4} -> {4+4, 5+4, 6+4, 7+4} */ |
| 494 | for (i = 4; i < BT_CMD_DATA_SIZE; i++) |
| 495 | data[i] = config_data[(i / 4) * 8 - 1 - i]; |
| 496 | |
| 497 | print_hex_dump_bytes("Calibration data: ", |
| 498 | DUMP_PREFIX_OFFSET, data, BT_CMD_DATA_SIZE); |
| 499 | |
| 500 | ret = btmrvl_send_sync_cmd(priv, BT_CMD_LOAD_CONFIG_DATA, data, |
| 501 | BT_CMD_DATA_SIZE); |
| 502 | if (ret) |
| 503 | BT_ERR("Failed to download caibration data\n"); |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | static int |
| 509 | btmrvl_process_cal_cfg(struct btmrvl_private *priv, u8 *data, u32 size) |
| 510 | { |
| 511 | u8 cal_data[BT_CAL_DATA_SIZE]; |
| 512 | int ret; |
| 513 | |
| 514 | ret = btmrvl_parse_cal_cfg(data, size, cal_data, sizeof(cal_data)); |
| 515 | if (ret) |
| 516 | return ret; |
| 517 | |
| 518 | ret = btmrvl_load_cal_data(priv, cal_data); |
| 519 | if (ret) { |
| 520 | BT_ERR("Fail to load calibrate data"); |
| 521 | return ret; |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | static int btmrvl_cal_data_config(struct btmrvl_private *priv) |
| 528 | { |
| 529 | const struct firmware *cfg; |
| 530 | int ret; |
| 531 | const char *cal_data = priv->btmrvl_dev.cal_data; |
| 532 | |
| 533 | if (!cal_data) |
| 534 | return 0; |
| 535 | |
| 536 | ret = request_firmware(&cfg, cal_data, priv->btmrvl_dev.dev); |
| 537 | if (ret < 0) { |
| 538 | BT_DBG("Failed to get %s file, skipping cal data download", |
| 539 | cal_data); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | ret = btmrvl_process_cal_cfg(priv, (u8 *)cfg->data, cfg->size); |
| 544 | release_firmware(cfg); |
| 545 | return ret; |
| 546 | } |
| 547 | |
Amitkumar Karwar | 4b24572 | 2013-10-01 12:19:14 -0700 | [diff] [blame] | 548 | static int btmrvl_setup(struct hci_dev *hdev) |
| 549 | { |
| 550 | struct btmrvl_private *priv = hci_get_drvdata(hdev); |
| 551 | |
| 552 | btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ); |
| 553 | |
Amitkumar Karwar | 2cc8689 | 2013-10-01 12:19:15 -0700 | [diff] [blame] | 554 | if (btmrvl_cal_data_config(priv)) |
| 555 | BT_ERR("Set cal data failed"); |
| 556 | |
Amitkumar Karwar | 4b24572 | 2013-10-01 12:19:14 -0700 | [diff] [blame] | 557 | priv->btmrvl_dev.psmode = 1; |
| 558 | btmrvl_enable_ps(priv); |
| 559 | |
| 560 | priv->btmrvl_dev.gpio_gap = 0xffff; |
| 561 | btmrvl_send_hscfg_cmd(priv); |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 566 | /* |
| 567 | * This function handles the event generated by firmware, rx data |
| 568 | * received from firmware, and tx data sent from kernel. |
| 569 | */ |
| 570 | static int btmrvl_service_main_thread(void *data) |
| 571 | { |
| 572 | struct btmrvl_thread *thread = data; |
| 573 | struct btmrvl_private *priv = thread->priv; |
| 574 | struct btmrvl_adapter *adapter = priv->adapter; |
| 575 | wait_queue_t wait; |
| 576 | struct sk_buff *skb; |
| 577 | ulong flags; |
| 578 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 579 | init_waitqueue_entry(&wait, current); |
| 580 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 581 | for (;;) { |
| 582 | add_wait_queue(&thread->wait_q, &wait); |
| 583 | |
| 584 | set_current_state(TASK_INTERRUPTIBLE); |
Daniel Drake | ea05fea | 2013-06-11 15:40:20 -0400 | [diff] [blame] | 585 | if (kthread_should_stop()) { |
| 586 | BT_DBG("main_thread: break from main thread"); |
| 587 | break; |
| 588 | } |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 589 | |
| 590 | if (adapter->wakeup_tries || |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 591 | ((!adapter->int_count) && |
| 592 | (!priv->btmrvl_dev.tx_dnld_rdy || |
| 593 | skb_queue_empty(&adapter->tx_queue)))) { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 594 | BT_DBG("main_thread is sleeping..."); |
| 595 | schedule(); |
| 596 | } |
| 597 | |
| 598 | set_current_state(TASK_RUNNING); |
| 599 | |
| 600 | remove_wait_queue(&thread->wait_q, &wait); |
| 601 | |
| 602 | BT_DBG("main_thread woke up"); |
| 603 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 604 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 605 | if (adapter->int_count) { |
| 606 | adapter->int_count = 0; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 607 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 608 | priv->hw_process_int_status(priv); |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 609 | } else if (adapter->ps_state == PS_SLEEP && |
| 610 | !skb_queue_empty(&adapter->tx_queue)) { |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 611 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 612 | adapter->wakeup_tries++; |
| 613 | priv->hw_wakeup_firmware(priv); |
| 614 | continue; |
Amitkumar Karwar | d1d10d7 | 2010-05-27 16:38:37 -0700 | [diff] [blame] | 615 | } else { |
| 616 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 617 | } |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 618 | |
| 619 | if (adapter->ps_state == PS_SLEEP) |
| 620 | continue; |
| 621 | |
| 622 | if (!priv->btmrvl_dev.tx_dnld_rdy) |
| 623 | continue; |
| 624 | |
| 625 | skb = skb_dequeue(&adapter->tx_queue); |
| 626 | if (skb) { |
| 627 | if (btmrvl_tx_pkt(priv, skb)) |
| 628 | priv->btmrvl_dev.hcidev->stat.err_tx++; |
| 629 | else |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 630 | priv->btmrvl_dev.hcidev->stat.byte_tx += skb->len; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 631 | |
| 632 | kfree_skb(skb); |
| 633 | } |
| 634 | } |
| 635 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 636 | return 0; |
| 637 | } |
| 638 | |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 639 | int btmrvl_register_hdev(struct btmrvl_private *priv) |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 640 | { |
| 641 | struct hci_dev *hdev = NULL; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 642 | int ret; |
| 643 | |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 644 | hdev = hci_alloc_dev(); |
| 645 | if (!hdev) { |
| 646 | BT_ERR("Can not allocate HCI device"); |
| 647 | goto err_hdev; |
| 648 | } |
| 649 | |
| 650 | priv->btmrvl_dev.hcidev = hdev; |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 651 | hci_set_drvdata(hdev, priv); |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 652 | |
| 653 | hdev->bus = HCI_SDIO; |
| 654 | hdev->open = btmrvl_open; |
| 655 | hdev->close = btmrvl_close; |
| 656 | hdev->flush = btmrvl_flush; |
| 657 | hdev->send = btmrvl_send_frame; |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 658 | hdev->ioctl = btmrvl_ioctl; |
Amitkumar Karwar | 4b24572 | 2013-10-01 12:19:14 -0700 | [diff] [blame] | 659 | hdev->setup = btmrvl_setup; |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 660 | |
Bing Zhao | f120c6b | 2010-03-03 14:37:37 -0800 | [diff] [blame] | 661 | hdev->dev_type = priv->btmrvl_dev.dev_type; |
| 662 | |
Bing Zhao | 6406160 | 2010-03-03 14:37:36 -0800 | [diff] [blame] | 663 | ret = hci_register_dev(hdev); |
| 664 | if (ret < 0) { |
| 665 | BT_ERR("Can not register HCI device"); |
| 666 | goto err_hci_register_dev; |
| 667 | } |
| 668 | |
| 669 | #ifdef CONFIG_DEBUG_FS |
| 670 | btmrvl_debugfs_init(hdev); |
| 671 | #endif |
| 672 | |
| 673 | return 0; |
| 674 | |
| 675 | err_hci_register_dev: |
| 676 | hci_free_dev(hdev); |
| 677 | |
| 678 | err_hdev: |
| 679 | /* Stop the thread servicing the interrupts */ |
| 680 | kthread_stop(priv->main_thread.task); |
| 681 | |
| 682 | btmrvl_free_adapter(priv); |
| 683 | kfree(priv); |
| 684 | |
| 685 | return -ENOMEM; |
| 686 | } |
| 687 | EXPORT_SYMBOL_GPL(btmrvl_register_hdev); |
| 688 | |
| 689 | struct btmrvl_private *btmrvl_add_card(void *card) |
| 690 | { |
| 691 | struct btmrvl_private *priv; |
| 692 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 693 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
| 694 | if (!priv) { |
| 695 | BT_ERR("Can not allocate priv"); |
| 696 | goto err_priv; |
| 697 | } |
| 698 | |
| 699 | priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL); |
| 700 | if (!priv->adapter) { |
| 701 | BT_ERR("Allocate buffer for btmrvl_adapter failed!"); |
| 702 | goto err_adapter; |
| 703 | } |
| 704 | |
| 705 | btmrvl_init_adapter(priv); |
| 706 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 707 | BT_DBG("Starting kthread..."); |
| 708 | priv->main_thread.priv = priv; |
| 709 | spin_lock_init(&priv->driver_lock); |
| 710 | |
| 711 | init_waitqueue_head(&priv->main_thread.wait_q); |
| 712 | priv->main_thread.task = kthread_run(btmrvl_service_main_thread, |
Marcel Holtmann | 4271e08 | 2009-06-09 16:00:22 +0200 | [diff] [blame] | 713 | &priv->main_thread, "btmrvl_main_service"); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 714 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 715 | priv->btmrvl_dev.card = card; |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 716 | priv->btmrvl_dev.tx_dnld_rdy = true; |
| 717 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 718 | return priv; |
| 719 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 720 | err_adapter: |
| 721 | kfree(priv); |
| 722 | |
| 723 | err_priv: |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 724 | return NULL; |
| 725 | } |
| 726 | EXPORT_SYMBOL_GPL(btmrvl_add_card); |
| 727 | |
| 728 | int btmrvl_remove_card(struct btmrvl_private *priv) |
| 729 | { |
| 730 | struct hci_dev *hdev; |
| 731 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 732 | hdev = priv->btmrvl_dev.hcidev; |
| 733 | |
| 734 | wake_up_interruptible(&priv->adapter->cmd_wait_q); |
| 735 | |
| 736 | kthread_stop(priv->main_thread.task); |
| 737 | |
Bing Zhao | fb784f0 | 2009-06-02 14:29:37 -0700 | [diff] [blame] | 738 | #ifdef CONFIG_DEBUG_FS |
| 739 | btmrvl_debugfs_remove(hdev); |
| 740 | #endif |
| 741 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 742 | hci_unregister_dev(hdev); |
| 743 | |
| 744 | hci_free_dev(hdev); |
| 745 | |
| 746 | priv->btmrvl_dev.hcidev = NULL; |
| 747 | |
| 748 | btmrvl_free_adapter(priv); |
| 749 | |
| 750 | kfree(priv); |
| 751 | |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 752 | return 0; |
| 753 | } |
| 754 | EXPORT_SYMBOL_GPL(btmrvl_remove_card); |
| 755 | |
| 756 | MODULE_AUTHOR("Marvell International Ltd."); |
Marcel Holtmann | 9666fb3 | 2009-06-09 21:45:04 +0200 | [diff] [blame] | 757 | MODULE_DESCRIPTION("Marvell Bluetooth driver ver " VERSION); |
Bing Zhao | 132ff4e | 2009-06-02 14:29:35 -0700 | [diff] [blame] | 758 | MODULE_VERSION(VERSION); |
| 759 | MODULE_LICENSE("GPL v2"); |