Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * HCI_SMD (HCI Shared Memory Driver) is Qualcomm's Shared memory driver |
| 3 | * for the BT HCI protocol. |
| 4 | * |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 5 | * Copyright (c) 2000-2001, 2011-2012 Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 6 | * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com> |
| 7 | * Copyright (C) 2004-2006 Marcel Holtmann <marcel@holtmann.org> |
| 8 | * |
| 9 | * This file is based on drivers/bluetooth/hci_vhci.c |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 |
| 13 | * as published by the Free Software Foundation |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/errno.h> |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 25 | #include <linux/semaphore.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
| 27 | #include <linux/skbuff.h> |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 28 | #include <linux/wakelock.h> |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 29 | #include <linux/workqueue.h> |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 30 | #include <linux/uaccess.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 32 | #include <net/bluetooth/bluetooth.h> |
| 33 | #include <net/bluetooth/hci_core.h> |
| 34 | #include <net/bluetooth/hci.h> |
| 35 | #include <mach/msm_smd.h> |
| 36 | |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 37 | #define EVENT_CHANNEL "APPS_RIVA_BT_CMD" |
| 38 | #define DATA_CHANNEL "APPS_RIVA_BT_ACL" |
Mallikarjuna GB | 215561d | 2012-01-23 13:20:38 +0530 | [diff] [blame] | 39 | /* release wakelock in 500ms, not immediately, because higher layers |
| 40 | * don't always take wakelocks when they should |
| 41 | * This is derived from the implementation for UART transport |
| 42 | */ |
| 43 | |
| 44 | #define RX_Q_MONITOR (500) /* 500 milli second */ |
Bhasker Neti | 6d353ee | 2012-07-04 19:24:23 +0530 | [diff] [blame] | 45 | #define HCI_REGISTER_SET 0 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 47 | /* SSR state machine to take care of back to back SSR requests |
| 48 | * and handling the incomming BT on/off,Airplane mode toggling and |
| 49 | * also spuriour SMD open notification while one SSr is in progress |
| 50 | */ |
| 51 | #define STATE_SSR_ON 0x1 |
| 52 | #define STATE_SSR_START 0x02 |
| 53 | #define STATE_SSR_CHANNEL_OPEN_PENDING 0x04 |
| 54 | #define STATE_SSR_PENDING_INIT 0x08 |
| 55 | #define STATE_SSR_COMPLETE 0x00 |
| 56 | #define STATE_SSR_OFF STATE_SSR_COMPLETE |
| 57 | |
| 58 | static int ssr_state = STATE_SSR_OFF; |
| 59 | |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 60 | |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 61 | static int hcismd_set; |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 62 | static DEFINE_SEMAPHORE(hci_smd_enable); |
| 63 | |
| 64 | static int restart_in_progress; |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 65 | |
| 66 | static int hcismd_set_enable(const char *val, struct kernel_param *kp); |
| 67 | module_param_call(hcismd_set, hcismd_set_enable, NULL, &hcismd_set, 0644); |
| 68 | |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 69 | static void hci_dev_smd_open(struct work_struct *worker); |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 70 | static void hci_dev_restart(struct work_struct *worker); |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 71 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | struct hci_smd_data { |
| 73 | struct hci_dev *hdev; |
Bhasker Neti | 6d353ee | 2012-07-04 19:24:23 +0530 | [diff] [blame] | 74 | unsigned long flags; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | struct smd_channel *event_channel; |
| 76 | struct smd_channel *data_channel; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 77 | struct wake_lock wake_lock_tx; |
| 78 | struct wake_lock wake_lock_rx; |
| 79 | struct timer_list rx_q_timer; |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 80 | struct tasklet_struct rx_task; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 81 | }; |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 82 | static struct hci_smd_data hs; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 83 | |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 84 | /* Rx queue monitor timer function */ |
| 85 | static int is_rx_q_empty(unsigned long arg) |
| 86 | { |
| 87 | struct hci_dev *hdev = (struct hci_dev *) arg; |
| 88 | struct sk_buff_head *list_ = &hdev->rx_q; |
| 89 | struct sk_buff *list = ((struct sk_buff *)list_)->next; |
| 90 | BT_DBG("%s Rx timer triggered", hdev->name); |
| 91 | |
| 92 | if (list == (struct sk_buff *)list_) { |
| 93 | BT_DBG("%s RX queue empty", hdev->name); |
| 94 | return 1; |
| 95 | } else{ |
| 96 | BT_DBG("%s RX queue not empty", hdev->name); |
| 97 | return 0; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | static void release_lock(void) |
| 102 | { |
| 103 | struct hci_smd_data *hsmd = &hs; |
| 104 | BT_DBG("Releasing Rx Lock"); |
| 105 | if (is_rx_q_empty((unsigned long)hsmd->hdev) && |
| 106 | wake_lock_active(&hs.wake_lock_rx)) |
| 107 | wake_unlock(&hs.wake_lock_rx); |
| 108 | } |
| 109 | |
| 110 | /* Rx timer callback function */ |
| 111 | static void schedule_timer(unsigned long arg) |
| 112 | { |
| 113 | struct hci_dev *hdev = (struct hci_dev *) arg; |
| 114 | struct hci_smd_data *hsmd = &hs; |
| 115 | BT_DBG("%s Schedule Rx timer", hdev->name); |
| 116 | |
| 117 | if (is_rx_q_empty(arg) && wake_lock_active(&hs.wake_lock_rx)) { |
| 118 | BT_DBG("%s RX queue empty", hdev->name); |
| 119 | /* |
| 120 | * Since the queue is empty, its ideal |
| 121 | * to release the wake lock on Rx |
| 122 | */ |
| 123 | wake_unlock(&hs.wake_lock_rx); |
| 124 | } else{ |
| 125 | BT_DBG("%s RX queue not empty", hdev->name); |
| 126 | /* |
| 127 | * Restart the timer to monitor whether the Rx queue is |
| 128 | * empty for releasing the Rx wake lock |
| 129 | */ |
| 130 | mod_timer(&hsmd->rx_q_timer, |
| 131 | jiffies + msecs_to_jiffies(RX_Q_MONITOR)); |
| 132 | } |
| 133 | } |
| 134 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 135 | static int hci_smd_open(struct hci_dev *hdev) |
| 136 | { |
| 137 | set_bit(HCI_RUNNING, &hdev->flags); |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | static int hci_smd_close(struct hci_dev *hdev) |
| 143 | { |
| 144 | if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags)) |
| 145 | return 0; |
| 146 | else |
| 147 | return -EPERM; |
| 148 | } |
| 149 | |
| 150 | |
| 151 | static void hci_smd_destruct(struct hci_dev *hdev) |
| 152 | { |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 153 | if (NULL != hdev->driver_data) |
| 154 | kfree(hdev->driver_data); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 157 | static void hci_smd_recv_data(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 158 | { |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 159 | int len = 0; |
| 160 | int rc = 0; |
| 161 | struct sk_buff *skb = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 162 | struct hci_smd_data *hsmd = &hs; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 163 | wake_lock(&hs.wake_lock_rx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 164 | |
| 165 | len = smd_read_avail(hsmd->data_channel); |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 166 | if (len > HCI_MAX_FRAME_SIZE) { |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 167 | BT_ERR("Frame larger than the allowed size, flushing frame"); |
| 168 | smd_read(hsmd->data_channel, NULL, len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 169 | goto out_data; |
| 170 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 171 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 172 | if (len <= 0) |
| 173 | goto out_data; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 175 | skb = bt_skb_alloc(len, GFP_ATOMIC); |
| 176 | if (!skb) { |
| 177 | BT_ERR("Error in allocating socket buffer"); |
| 178 | smd_read(hsmd->data_channel, NULL, len); |
| 179 | goto out_data; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 180 | } |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 181 | |
| 182 | rc = smd_read(hsmd->data_channel, skb_put(skb, len), len); |
| 183 | if (rc < len) { |
| 184 | BT_ERR("Error in reading from the channel"); |
| 185 | goto out_data; |
| 186 | } |
| 187 | |
| 188 | skb->dev = (void *)hsmd->hdev; |
| 189 | bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT; |
| 190 | skb_orphan(skb); |
| 191 | |
| 192 | rc = hci_recv_frame(skb); |
| 193 | if (rc < 0) { |
| 194 | BT_ERR("Error in passing the packet to HCI Layer"); |
| 195 | /* |
| 196 | * skb is getting freed in hci_recv_frame, making it |
| 197 | * to null to avoid multiple access |
| 198 | */ |
| 199 | skb = NULL; |
| 200 | goto out_data; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Start the timer to monitor whether the Rx queue is |
| 205 | * empty for releasing the Rx wake lock |
| 206 | */ |
| 207 | BT_DBG("Rx Timer is starting"); |
| 208 | mod_timer(&hsmd->rx_q_timer, |
| 209 | jiffies + msecs_to_jiffies(RX_Q_MONITOR)); |
| 210 | |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 211 | out_data: |
| 212 | release_lock(); |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 213 | if (rc) |
| 214 | kfree_skb(skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 217 | static void hci_smd_recv_event(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 218 | { |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 219 | int len = 0; |
| 220 | int rc = 0; |
| 221 | struct sk_buff *skb = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 222 | struct hci_smd_data *hsmd = &hs; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 223 | wake_lock(&hs.wake_lock_rx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | |
| 225 | len = smd_read_avail(hsmd->event_channel); |
| 226 | if (len > HCI_MAX_FRAME_SIZE) { |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 227 | BT_ERR("Frame larger than the allowed size, flushing frame"); |
| 228 | rc = smd_read(hsmd->event_channel, NULL, len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 229 | goto out_event; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | while (len > 0) { |
Ankur Nandwani | c815096 | 2011-08-24 13:06:23 -0700 | [diff] [blame] | 233 | skb = bt_skb_alloc(len, GFP_ATOMIC); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 234 | if (!skb) { |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 235 | BT_ERR("Error in allocating socket buffer"); |
| 236 | smd_read(hsmd->event_channel, NULL, len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 237 | goto out_event; |
| 238 | } |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 239 | |
| 240 | rc = smd_read(hsmd->event_channel, skb_put(skb, len), len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 241 | if (rc < len) { |
| 242 | BT_ERR("Error in reading from the event channel"); |
| 243 | goto out_event; |
| 244 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 245 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 246 | skb->dev = (void *)hsmd->hdev; |
| 247 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
| 248 | |
| 249 | skb_orphan(skb); |
| 250 | |
| 251 | rc = hci_recv_frame(skb); |
| 252 | if (rc < 0) { |
| 253 | BT_ERR("Error in passing the packet to HCI Layer"); |
Bhasker Neti | 44a792b | 2011-10-11 19:25:22 +0530 | [diff] [blame] | 254 | /* |
| 255 | * skb is getting freed in hci_recv_frame, making it |
| 256 | * to null to avoid multiple access |
| 257 | */ |
| 258 | skb = NULL; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 259 | goto out_event; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 262 | len = smd_read_avail(hsmd->event_channel); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 263 | /* |
| 264 | * Start the timer to monitor whether the Rx queue is |
| 265 | * empty for releasing the Rx wake lock |
| 266 | */ |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 267 | BT_DBG("Rx Timer is starting"); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 268 | mod_timer(&hsmd->rx_q_timer, |
| 269 | jiffies + msecs_to_jiffies(RX_Q_MONITOR)); |
| 270 | } |
| 271 | out_event: |
| 272 | release_lock(); |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 273 | if (rc) |
| 274 | kfree_skb(skb); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | static int hci_smd_send_frame(struct sk_buff *skb) |
| 278 | { |
| 279 | int len; |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 280 | int avail; |
| 281 | int ret = 0; |
| 282 | wake_lock(&hs.wake_lock_tx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 283 | |
| 284 | switch (bt_cb(skb)->pkt_type) { |
| 285 | case HCI_COMMAND_PKT: |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 286 | avail = smd_write_avail(hs.event_channel); |
| 287 | if (!avail) { |
| 288 | BT_ERR("No space available for smd frame"); |
| 289 | ret = -ENOSPC; |
| 290 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | len = smd_write(hs.event_channel, skb->data, skb->len); |
| 292 | if (len < skb->len) { |
| 293 | BT_ERR("Failed to write Command %d", len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 294 | ret = -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 295 | } |
| 296 | break; |
| 297 | case HCI_ACLDATA_PKT: |
| 298 | case HCI_SCODATA_PKT: |
Ankur Nandwani | 23abeb2 | 2011-10-26 16:35:22 -0700 | [diff] [blame] | 299 | avail = smd_write_avail(hs.data_channel); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 300 | if (!avail) { |
| 301 | BT_ERR("No space available for smd frame"); |
| 302 | ret = -ENOSPC; |
| 303 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 304 | len = smd_write(hs.data_channel, skb->data, skb->len); |
| 305 | if (len < skb->len) { |
| 306 | BT_ERR("Failed to write Data %d", len); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 307 | ret = -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 308 | } |
| 309 | break; |
| 310 | default: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 311 | BT_ERR("Uknown packet type"); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 312 | ret = -ENODEV; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 313 | break; |
| 314 | } |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 315 | |
Anubhav Gupta | ddf48ec | 2011-10-03 14:24:13 +0530 | [diff] [blame] | 316 | kfree_skb(skb); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 317 | wake_unlock(&hs.wake_lock_tx); |
| 318 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 321 | static void hci_smd_rx(unsigned long arg) |
| 322 | { |
| 323 | struct hci_smd_data *hsmd = &hs; |
| 324 | |
| 325 | while ((smd_read_avail(hsmd->event_channel) > 0) || |
| 326 | (smd_read_avail(hsmd->data_channel) > 0)) { |
| 327 | hci_smd_recv_event(); |
| 328 | hci_smd_recv_data(); |
| 329 | } |
| 330 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 331 | |
| 332 | static void hci_smd_notify_event(void *data, unsigned int event) |
| 333 | { |
| 334 | struct hci_dev *hdev = hs.hdev; |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 335 | struct hci_smd_data *hsmd = &hs; |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 336 | struct work_struct *reset_worker; |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 337 | struct work_struct *open_worker; |
| 338 | |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 339 | int len = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 340 | |
| 341 | if (!hdev) { |
| 342 | BT_ERR("Frame for unknown HCI device (hdev=NULL)"); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | switch (event) { |
| 347 | case SMD_EVENT_DATA: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 348 | len = smd_read_avail(hsmd->event_channel); |
| 349 | if (len > 0) |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 350 | tasklet_hi_schedule(&hs.rx_task); |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 351 | else if (len < 0) |
| 352 | BT_ERR("Failed to read event from smd %d", len); |
| 353 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 354 | break; |
| 355 | case SMD_EVENT_OPEN: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 356 | BT_INFO("opening HCI-SMD channel :%s", EVENT_CHANNEL); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 357 | BT_DBG("SSR state is : %x", ssr_state); |
| 358 | if ((ssr_state == STATE_SSR_OFF) || |
| 359 | (ssr_state == STATE_SSR_CHANNEL_OPEN_PENDING)) { |
| 360 | |
| 361 | hci_smd_open(hdev); |
| 362 | open_worker = kzalloc(sizeof(*open_worker), GFP_ATOMIC); |
| 363 | if (!open_worker) { |
| 364 | BT_ERR("Out of memory"); |
| 365 | break; |
| 366 | } |
| 367 | if (ssr_state == STATE_SSR_CHANNEL_OPEN_PENDING) { |
| 368 | ssr_state = STATE_SSR_PENDING_INIT; |
| 369 | BT_INFO("SSR state is : %x", ssr_state); |
| 370 | } |
| 371 | INIT_WORK(open_worker, hci_dev_smd_open); |
| 372 | schedule_work(open_worker); |
| 373 | |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 374 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 375 | break; |
| 376 | case SMD_EVENT_CLOSE: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 377 | BT_INFO("Closing HCI-SMD channel :%s", EVENT_CHANNEL); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 378 | BT_DBG("SSR state is : %x", ssr_state); |
| 379 | if ((ssr_state == STATE_SSR_OFF) || |
| 380 | (ssr_state == (STATE_SSR_PENDING_INIT))) { |
| 381 | |
| 382 | hci_smd_close(hdev); |
| 383 | reset_worker = kzalloc(sizeof(*reset_worker), |
| 384 | GFP_ATOMIC); |
| 385 | if (!reset_worker) { |
| 386 | BT_ERR("Out of memory"); |
| 387 | break; |
| 388 | } |
| 389 | ssr_state = STATE_SSR_ON; |
| 390 | BT_INFO("SSR state is : %x", ssr_state); |
| 391 | INIT_WORK(reset_worker, hci_dev_restart); |
| 392 | schedule_work(reset_worker); |
| 393 | |
| 394 | } else if (ssr_state & STATE_SSR_ON) { |
| 395 | BT_ERR("SSR state is : %x", ssr_state); |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 396 | } |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 397 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 398 | break; |
| 399 | default: |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | static void hci_smd_notify_data(void *data, unsigned int event) |
| 405 | { |
| 406 | struct hci_dev *hdev = hs.hdev; |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 407 | struct hci_smd_data *hsmd = &hs; |
| 408 | int len = 0; |
| 409 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 410 | if (!hdev) { |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 411 | BT_ERR("Frame for unknown HCI device (hdev=NULL)"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 412 | return; |
| 413 | } |
| 414 | |
| 415 | switch (event) { |
| 416 | case SMD_EVENT_DATA: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 417 | len = smd_read_avail(hsmd->data_channel); |
| 418 | if (len > 0) |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 419 | tasklet_hi_schedule(&hs.rx_task); |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 420 | else if (len < 0) |
| 421 | BT_ERR("Failed to read data from smd %d", len); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 422 | break; |
| 423 | case SMD_EVENT_OPEN: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 424 | BT_INFO("opening HCI-SMD channel :%s", DATA_CHANNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 425 | hci_smd_open(hdev); |
| 426 | break; |
| 427 | case SMD_EVENT_CLOSE: |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 428 | BT_INFO("Closing HCI-SMD channel :%s", DATA_CHANNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 429 | hci_smd_close(hdev); |
| 430 | break; |
| 431 | default: |
| 432 | break; |
| 433 | } |
| 434 | |
| 435 | } |
| 436 | |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 437 | static int hci_smd_hci_register_dev(struct hci_smd_data *hsmd) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 438 | { |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 439 | struct hci_dev *hdev; |
| 440 | |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 441 | if (hsmd->hdev) |
| 442 | hdev = hsmd->hdev; |
| 443 | else { |
| 444 | BT_ERR("hdev is NULL"); |
Bhasker Neti | 6d353ee | 2012-07-04 19:24:23 +0530 | [diff] [blame] | 445 | return 0; |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 446 | } |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 447 | /* Allow the incomming SSR even the prev one at PENDING INIT STATE |
| 448 | * since clenup need to be started again from the beging and ignore |
| 449 | * or bypass the prev one |
| 450 | */ |
| 451 | if ((ssr_state == STATE_SSR_OFF) || |
| 452 | (ssr_state == STATE_SSR_PENDING_INIT)) { |
| 453 | |
| 454 | if (test_and_set_bit(HCI_REGISTER_SET, &hsmd->flags)) { |
| 455 | BT_ERR("HCI device registered already"); |
| 456 | return 0; |
| 457 | } else |
| 458 | BT_INFO("HCI device registration is starting"); |
| 459 | if (hci_register_dev(hdev) < 0) { |
| 460 | BT_ERR("Can't register HCI device"); |
| 461 | hci_free_dev(hdev); |
| 462 | hsmd->hdev = NULL; |
| 463 | clear_bit(HCI_REGISTER_SET, &hsmd->flags); |
| 464 | return -ENODEV; |
| 465 | } |
| 466 | if (ssr_state == STATE_SSR_PENDING_INIT) { |
| 467 | ssr_state = STATE_SSR_COMPLETE; |
| 468 | BT_INFO("SSR state is : %x", ssr_state); |
| 469 | } |
| 470 | } else if (ssr_state) |
| 471 | BT_ERR("Registration called in invalid context"); |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 472 | return 0; |
| 473 | } |
| 474 | |
| 475 | static int hci_smd_register_smd(struct hci_smd_data *hsmd) |
| 476 | { |
| 477 | struct hci_dev *hdev; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 478 | int rc; |
| 479 | |
| 480 | /* Initialize and register HCI device */ |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 481 | hdev = hci_alloc_dev(); |
| 482 | if (!hdev) { |
| 483 | BT_ERR("Can't allocate HCI device"); |
| 484 | return -ENOMEM; |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 485 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 486 | |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 487 | hsmd->hdev = hdev; |
| 488 | hdev->bus = HCI_SMD; |
| 489 | hdev->driver_data = NULL; |
| 490 | hdev->open = hci_smd_open; |
| 491 | hdev->close = hci_smd_close; |
| 492 | hdev->send = hci_smd_send_frame; |
| 493 | hdev->destruct = hci_smd_destruct; |
| 494 | hdev->owner = THIS_MODULE; |
| 495 | |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 496 | |
| 497 | tasklet_init(&hsmd->rx_task, |
| 498 | hci_smd_rx, (unsigned long) hsmd); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 499 | /* |
| 500 | * Setup the timer to monitor whether the Rx queue is empty, |
| 501 | * to control the wake lock release |
| 502 | */ |
| 503 | setup_timer(&hsmd->rx_q_timer, schedule_timer, |
| 504 | (unsigned long) hsmd->hdev); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 505 | if (ssr_state == STATE_SSR_START) { |
| 506 | ssr_state = STATE_SSR_CHANNEL_OPEN_PENDING; |
| 507 | BT_INFO("SSR state is : %x", ssr_state); |
| 508 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 509 | /* Open the SMD Channel and device and register the callback function */ |
| 510 | rc = smd_named_open_on_edge(EVENT_CHANNEL, SMD_APPS_WCNSS, |
| 511 | &hsmd->event_channel, hdev, hci_smd_notify_event); |
| 512 | if (rc < 0) { |
| 513 | BT_ERR("Cannot open the command channel"); |
| 514 | hci_free_dev(hdev); |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 515 | hsmd->hdev = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 516 | return -ENODEV; |
| 517 | } |
| 518 | |
| 519 | rc = smd_named_open_on_edge(DATA_CHANNEL, SMD_APPS_WCNSS, |
| 520 | &hsmd->data_channel, hdev, hci_smd_notify_data); |
| 521 | if (rc < 0) { |
Bhasker Neti | 60734c0 | 2011-11-23 15:17:54 -0800 | [diff] [blame] | 522 | BT_ERR("Failed to open the Data channel"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 523 | hci_free_dev(hdev); |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 524 | hsmd->hdev = NULL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 525 | return -ENODEV; |
| 526 | } |
| 527 | |
| 528 | /* Disable the read interrupts on the channel */ |
| 529 | smd_disable_read_intr(hsmd->event_channel); |
| 530 | smd_disable_read_intr(hsmd->data_channel); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 534 | static void hci_smd_deregister_dev(struct hci_smd_data *hsmd) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 535 | { |
Bhasker Neti | aae6146 | 2012-01-12 19:14:25 +0530 | [diff] [blame] | 536 | tasklet_kill(&hs.rx_task); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 537 | if (ssr_state) |
| 538 | BT_DBG("SSR state is : %x", ssr_state); |
| 539 | /* Though the hci_smd driver is not registered with the hci |
| 540 | * need to close the opened channels as a part of cleaup |
| 541 | */ |
Bhasker Neti | 6d353ee | 2012-07-04 19:24:23 +0530 | [diff] [blame] | 542 | if (!test_and_clear_bit(HCI_REGISTER_SET, &hsmd->flags)) { |
| 543 | BT_ERR("HCI device un-registered already"); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 544 | } else { |
Bhasker Neti | 6d353ee | 2012-07-04 19:24:23 +0530 | [diff] [blame] | 545 | BT_INFO("HCI device un-registration going on"); |
Royston Rodrigues | eee6c96 | 2011-12-22 16:42:45 +0530 | [diff] [blame] | 546 | |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 547 | if (hsmd->hdev) { |
| 548 | if (hci_unregister_dev(hsmd->hdev) < 0) |
| 549 | BT_ERR("Can't unregister HCI device %s", |
| 550 | hsmd->hdev->name); |
| 551 | |
| 552 | hci_free_dev(hsmd->hdev); |
| 553 | hsmd->hdev = NULL; |
| 554 | } |
Royston Rodrigues | eee6c96 | 2011-12-22 16:42:45 +0530 | [diff] [blame] | 555 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 556 | smd_close(hs.event_channel); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 557 | smd_close(hs.data_channel); |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 558 | |
Ankur Nandwani | 327e050 | 2011-11-11 15:47:25 -0800 | [diff] [blame] | 559 | if (wake_lock_active(&hs.wake_lock_rx)) |
| 560 | wake_unlock(&hs.wake_lock_rx); |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 561 | if (wake_lock_active(&hs.wake_lock_tx)) |
| 562 | wake_unlock(&hs.wake_lock_tx); |
Ankur Nandwani | 327e050 | 2011-11-11 15:47:25 -0800 | [diff] [blame] | 563 | |
Bhasker Neti | d08d901 | 2011-09-05 19:37:54 +0530 | [diff] [blame] | 564 | /*Destroy the timer used to monitor the Rx queue for emptiness */ |
Royston Rodrigues | eee6c96 | 2011-12-22 16:42:45 +0530 | [diff] [blame] | 565 | if (hs.rx_q_timer.function) { |
| 566 | del_timer_sync(&hs.rx_q_timer); |
| 567 | hs.rx_q_timer.function = NULL; |
| 568 | hs.rx_q_timer.data = 0; |
| 569 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 572 | static void hci_dev_restart(struct work_struct *worker) |
| 573 | { |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 574 | down(&hci_smd_enable); |
| 575 | restart_in_progress = 1; |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 576 | BT_DBG("SSR state is : %x", ssr_state); |
| 577 | |
| 578 | if (ssr_state == STATE_SSR_ON) { |
| 579 | ssr_state = STATE_SSR_START; |
| 580 | BT_INFO("SSR state is : %x", ssr_state); |
| 581 | } else { |
| 582 | BT_ERR("restart triggered in wrong context"); |
| 583 | up(&hci_smd_enable); |
| 584 | kfree(worker); |
| 585 | return; |
| 586 | } |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 587 | hci_smd_deregister_dev(&hs); |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 588 | hci_smd_register_smd(&hs); |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 589 | up(&hci_smd_enable); |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 590 | kfree(worker); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 591 | |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static void hci_dev_smd_open(struct work_struct *worker) |
| 595 | { |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 596 | down(&hci_smd_enable); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 597 | if (ssr_state) |
| 598 | BT_DBG("SSR state is : %x", ssr_state); |
| 599 | |
| 600 | if ((ssr_state != STATE_SSR_OFF) && |
| 601 | (ssr_state != (STATE_SSR_PENDING_INIT))) { |
| 602 | up(&hci_smd_enable); |
| 603 | kfree(worker); |
| 604 | return; |
| 605 | } |
| 606 | |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 607 | if (restart_in_progress == 1) { |
| 608 | /* Allow wcnss to initialize */ |
| 609 | restart_in_progress = 0; |
| 610 | msleep(10000); |
| 611 | } |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 612 | |
Sunny Kapdi | d71fbed | 2012-03-15 18:20:55 -0700 | [diff] [blame] | 613 | hci_smd_hci_register_dev(&hs); |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 614 | up(&hci_smd_enable); |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 615 | kfree(worker); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 616 | |
Sunny Kapdi | 02eab14 | 2012-02-01 13:52:27 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 619 | static int hcismd_set_enable(const char *val, struct kernel_param *kp) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 620 | { |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 621 | int ret = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 622 | |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 623 | pr_err("hcismd_set_enable %d", hcismd_set); |
| 624 | |
| 625 | down(&hci_smd_enable); |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 626 | |
| 627 | ret = param_set_int(val, kp); |
| 628 | |
| 629 | if (ret) |
| 630 | goto done; |
| 631 | |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 632 | /* Ignore the all incomming register de-register requests in case of |
| 633 | * SSR is in-progress |
| 634 | */ |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 635 | switch (hcismd_set) { |
| 636 | |
| 637 | case 1: |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 638 | if ((hs.hdev == NULL) && (ssr_state == STATE_SSR_OFF)) |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 639 | hci_smd_register_smd(&hs); |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 640 | else if (ssr_state) |
| 641 | BT_ERR("SSR is in progress,state is : %x", ssr_state); |
| 642 | |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 643 | break; |
| 644 | case 0: |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 645 | if (ssr_state == STATE_SSR_OFF) |
| 646 | hci_smd_deregister_dev(&hs); |
| 647 | else if (ssr_state) |
| 648 | BT_ERR("SSR is in progress,state is : %x", ssr_state); |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 649 | break; |
| 650 | default: |
| 651 | ret = -EFAULT; |
| 652 | } |
| 653 | |
| 654 | done: |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 655 | up(&hci_smd_enable); |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 656 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 657 | } |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 658 | static int __init hci_smd_init(void) |
| 659 | { |
| 660 | wake_lock_init(&hs.wake_lock_rx, WAKE_LOCK_SUSPEND, |
| 661 | "msm_smd_Rx"); |
| 662 | wake_lock_init(&hs.wake_lock_tx, WAKE_LOCK_SUSPEND, |
| 663 | "msm_smd_Tx"); |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 664 | restart_in_progress = 0; |
Bhasker Neti | b54b0b7 | 2012-12-05 13:58:17 +0530 | [diff] [blame] | 665 | ssr_state = STATE_SSR_OFF; |
Sunny Kapdi | 2a39b80 | 2012-05-30 12:47:14 -0700 | [diff] [blame] | 666 | hs.hdev = NULL; |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 667 | return 0; |
| 668 | } |
| 669 | module_init(hci_smd_init); |
Ankur Nandwani | 8ffe4e7 | 2011-10-10 21:51:48 -0700 | [diff] [blame] | 670 | |
Bhasker Neti | 60576c6 | 2011-12-07 18:45:51 -0800 | [diff] [blame] | 671 | static void __exit hci_smd_exit(void) |
| 672 | { |
| 673 | wake_lock_destroy(&hs.wake_lock_rx); |
| 674 | wake_lock_destroy(&hs.wake_lock_tx); |
| 675 | } |
| 676 | module_exit(hci_smd_exit); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 677 | |
| 678 | MODULE_AUTHOR("Ankur Nandwani <ankurn@codeaurora.org>"); |
| 679 | MODULE_DESCRIPTION("Bluetooth SMD driver"); |
| 680 | MODULE_LICENSE("GPL v2"); |