Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Atheros Communication Bluetooth HCIATH3K UART protocol |
| 3 | * |
| 4 | * HCIATH3K (HCI Atheros AR300x Protocol) is a Atheros Communication's |
| 5 | * power management protocol extension to H4 to support AR300x Bluetooth Chip. |
| 6 | * |
| 7 | * Copyright (c) 2009-2010 Atheros Communications Inc. |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 8 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 9 | * |
| 10 | * Acknowledgements: |
| 11 | * This file is based on hci_h4.c, which was written |
| 12 | * by Maxim Krasnyansky and Marcel Holtmann. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/kernel.h> |
| 32 | |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/tty.h> |
| 36 | #include <linux/errno.h> |
| 37 | #include <linux/ioctl.h> |
| 38 | #include <linux/skbuff.h> |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 39 | #include <linux/platform_device.h> |
| 40 | #include <linux/gpio.h> |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 41 | |
| 42 | #include <net/bluetooth/bluetooth.h> |
| 43 | #include <net/bluetooth/hci_core.h> |
| 44 | |
| 45 | #include "hci_uart.h" |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 46 | #ifdef CONFIG_SERIAL_MSM_HS |
| 47 | #include <mach/msm_serial_hs.h> |
| 48 | #endif |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 49 | |
Ram Mohan Korukonda | eb530d19 | 2012-08-08 16:54:51 +0530 | [diff] [blame] | 50 | unsigned int enableuartsleep = 1; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 51 | module_param(enableuartsleep, uint, 0644); |
| 52 | /* |
| 53 | * Global variables |
| 54 | */ |
| 55 | /** Global state flags */ |
| 56 | static unsigned long flags; |
| 57 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 58 | /** Workqueue to respond to change in hostwake line */ |
| 59 | static void wakeup_host_work(struct work_struct *work); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 60 | |
| 61 | /** Transmission timer */ |
| 62 | static void bluesleep_tx_timer_expire(unsigned long data); |
| 63 | static DEFINE_TIMER(tx_timer, bluesleep_tx_timer_expire, 0, 0); |
| 64 | |
| 65 | /** Lock for state transitions */ |
| 66 | static spinlock_t rw_lock; |
| 67 | |
| 68 | #define POLARITY_LOW 0 |
| 69 | #define POLARITY_HIGH 1 |
| 70 | |
| 71 | struct bluesleep_info { |
| 72 | unsigned host_wake; /* wake up host */ |
| 73 | unsigned ext_wake; /* wake up device */ |
| 74 | unsigned host_wake_irq; |
| 75 | int irq_polarity; |
| 76 | }; |
| 77 | |
| 78 | /* 1 second timeout */ |
| 79 | #define TX_TIMER_INTERVAL 1 |
| 80 | |
| 81 | /* state variable names and bit positions */ |
| 82 | #define BT_TXEXPIRED 0x01 |
| 83 | #define BT_SLEEPENABLE 0x02 |
| 84 | #define BT_SLEEPCMD 0x03 |
| 85 | |
| 86 | /* global pointer to a single hci device. */ |
| 87 | static struct bluesleep_info *bsi; |
| 88 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 89 | struct ath_struct { |
| 90 | struct hci_uart *hu; |
| 91 | unsigned int cur_sleep; |
| 92 | |
| 93 | struct sk_buff_head txq; |
| 94 | struct work_struct ctxtsw; |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 95 | struct work_struct ws_sleep; |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 96 | }; |
| 97 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 98 | static void hsuart_serial_clock_on(struct tty_struct *tty) |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 99 | { |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 100 | struct uart_state *state = tty->driver_data; |
| 101 | struct uart_port *port = state->uart_port; |
| 102 | BT_DBG(""); |
| 103 | msm_hs_request_clock_on(port); |
| 104 | } |
| 105 | |
| 106 | static void hsuart_serial_clock_off(struct tty_struct *tty) |
| 107 | { |
| 108 | struct uart_state *state = tty->driver_data; |
| 109 | struct uart_port *port = state->uart_port; |
| 110 | BT_DBG(""); |
| 111 | msm_hs_request_clock_off(port); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | static void modify_timer_task(void) |
| 115 | { |
| 116 | spin_lock(&rw_lock); |
| 117 | mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ)); |
| 118 | clear_bit(BT_TXEXPIRED, &flags); |
| 119 | spin_unlock(&rw_lock); |
| 120 | |
| 121 | } |
| 122 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 123 | static int ath_wakeup_ar3k(struct tty_struct *tty) |
| 124 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 125 | int status = 0; |
| 126 | if (test_bit(BT_TXEXPIRED, &flags)) { |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 127 | hsuart_serial_clock_on(tty); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 128 | BT_INFO("wakeup device\n"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 129 | gpio_set_value(bsi->ext_wake, 0); |
Ram Mohan Korukonda | eb530d19 | 2012-08-08 16:54:51 +0530 | [diff] [blame] | 130 | msleep(20); |
| 131 | gpio_set_value(bsi->ext_wake, 1); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 132 | } |
| 133 | modify_timer_task(); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 134 | return status; |
| 135 | } |
| 136 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 137 | static void wakeup_host_work(struct work_struct *work) |
| 138 | { |
| 139 | struct ath_struct *ath = |
| 140 | container_of(work, struct ath_struct, ws_sleep); |
| 141 | |
| 142 | BT_INFO("wake up host"); |
| 143 | if (test_bit(BT_SLEEPENABLE, &flags)) { |
| 144 | if (test_bit(BT_TXEXPIRED, &flags)) |
| 145 | hsuart_serial_clock_on(ath->hu->tty); |
| 146 | } |
| 147 | modify_timer_task(); |
| 148 | } |
| 149 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 150 | static void ath_hci_uart_work(struct work_struct *work) |
| 151 | { |
| 152 | int status; |
| 153 | struct ath_struct *ath; |
| 154 | struct hci_uart *hu; |
| 155 | struct tty_struct *tty; |
| 156 | |
| 157 | ath = container_of(work, struct ath_struct, ctxtsw); |
| 158 | |
| 159 | hu = ath->hu; |
| 160 | tty = hu->tty; |
| 161 | |
| 162 | /* verify and wake up controller */ |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 163 | if (test_bit(BT_SLEEPENABLE, &flags)) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 164 | status = ath_wakeup_ar3k(tty); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 165 | /* Ready to send Data */ |
| 166 | clear_bit(HCI_UART_SENDING, &hu->tx_state); |
| 167 | hci_uart_tx_wakeup(hu); |
| 168 | } |
| 169 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 170 | static irqreturn_t bluesleep_hostwake_isr(int irq, void *dev_id) |
| 171 | { |
| 172 | /* schedule a tasklet to handle the change in the host wake line */ |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 173 | struct ath_struct *ath = (struct ath_struct *)dev_id; |
| 174 | |
| 175 | schedule_work(&ath->ws_sleep); |
| 176 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 177 | return IRQ_HANDLED; |
| 178 | } |
| 179 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 180 | static int ath_bluesleep_gpio_config(struct ath_struct *ath, int on) |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 181 | { |
| 182 | int ret = 0; |
| 183 | |
| 184 | BT_INFO("%s config: %d", __func__, on); |
| 185 | if (!on) { |
| 186 | if (disable_irq_wake(bsi->host_wake_irq)) |
| 187 | BT_ERR("Couldn't disable hostwake IRQ wakeup mode\n"); |
| 188 | goto free_host_wake_irq; |
| 189 | } |
| 190 | |
| 191 | ret = gpio_request(bsi->host_wake, "bt_host_wake"); |
| 192 | if (ret < 0) { |
| 193 | BT_ERR("failed to request gpio pin %d, error %d\n", |
| 194 | bsi->host_wake, ret); |
| 195 | goto gpio_config_failed; |
| 196 | } |
| 197 | |
| 198 | /* configure host_wake as input */ |
| 199 | ret = gpio_direction_input(bsi->host_wake); |
| 200 | if (ret < 0) { |
| 201 | BT_ERR("failed to config GPIO %d as input pin, err %d\n", |
| 202 | bsi->host_wake, ret); |
| 203 | goto gpio_host_wake; |
| 204 | } |
| 205 | |
| 206 | ret = gpio_request(bsi->ext_wake, "bt_ext_wake"); |
| 207 | if (ret < 0) { |
| 208 | BT_ERR("failed to request gpio pin %d, error %d\n", |
| 209 | bsi->ext_wake, ret); |
| 210 | goto gpio_host_wake; |
| 211 | } |
| 212 | |
| 213 | ret = gpio_direction_output(bsi->ext_wake, 1); |
| 214 | if (ret < 0) { |
| 215 | BT_ERR("failed to config GPIO %d as output pin, err %d\n", |
| 216 | bsi->ext_wake, ret); |
| 217 | goto gpio_ext_wake; |
| 218 | } |
| 219 | |
| 220 | gpio_set_value(bsi->ext_wake, 1); |
| 221 | |
| 222 | /* Initialize spinlock. */ |
| 223 | spin_lock_init(&rw_lock); |
| 224 | |
| 225 | /* Initialize timer */ |
| 226 | init_timer(&tx_timer); |
| 227 | tx_timer.function = bluesleep_tx_timer_expire; |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 228 | tx_timer.data = (u_long)ath->hu; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 229 | |
| 230 | if (bsi->irq_polarity == POLARITY_LOW) { |
| 231 | ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr, |
| 232 | IRQF_DISABLED | IRQF_TRIGGER_FALLING, |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 233 | "bluetooth hostwake", (void *)ath); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 234 | } else { |
| 235 | ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr, |
| 236 | IRQF_DISABLED | IRQF_TRIGGER_RISING, |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 237 | "bluetooth hostwake", (void *)ath); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 238 | } |
| 239 | if (ret < 0) { |
| 240 | BT_ERR("Couldn't acquire BT_HOST_WAKE IRQ"); |
| 241 | goto delete_timer; |
| 242 | } |
| 243 | |
| 244 | ret = enable_irq_wake(bsi->host_wake_irq); |
| 245 | if (ret < 0) { |
| 246 | BT_ERR("Couldn't enable BT_HOST_WAKE as wakeup interrupt"); |
| 247 | goto free_host_wake_irq; |
| 248 | } |
| 249 | |
| 250 | return 0; |
| 251 | |
| 252 | free_host_wake_irq: |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 253 | free_irq(bsi->host_wake_irq, (void *)ath); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 254 | delete_timer: |
| 255 | del_timer(&tx_timer); |
| 256 | gpio_ext_wake: |
| 257 | gpio_free(bsi->ext_wake); |
| 258 | gpio_host_wake: |
| 259 | gpio_free(bsi->host_wake); |
| 260 | gpio_config_failed: |
| 261 | return ret; |
| 262 | } |
| 263 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 264 | /* Initialize protocol */ |
| 265 | static int ath_open(struct hci_uart *hu) |
| 266 | { |
| 267 | struct ath_struct *ath; |
| 268 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 269 | BT_DBG("hu %p, bsi %p", hu, bsi); |
| 270 | |
| 271 | if (!bsi) |
| 272 | return -EIO; |
| 273 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 274 | ath = kzalloc(sizeof(*ath), GFP_ATOMIC); |
| 275 | if (!ath) |
| 276 | return -ENOMEM; |
| 277 | |
| 278 | skb_queue_head_init(&ath->txq); |
| 279 | |
| 280 | hu->priv = ath; |
| 281 | ath->hu = hu; |
| 282 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 283 | if (ath_bluesleep_gpio_config(ath, 1) < 0) { |
| 284 | BT_ERR("HCIATH3K GPIO Config failed"); |
| 285 | hu->priv = NULL; |
| 286 | kfree(ath); |
| 287 | return -EIO; |
| 288 | } |
| 289 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 290 | ath->cur_sleep = enableuartsleep; |
| 291 | if (ath->cur_sleep == 1) { |
| 292 | set_bit(BT_SLEEPENABLE, &flags); |
| 293 | modify_timer_task(); |
| 294 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 295 | INIT_WORK(&ath->ctxtsw, ath_hci_uart_work); |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 296 | INIT_WORK(&ath->ws_sleep, wakeup_host_work); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | /* Flush protocol data */ |
| 301 | static int ath_flush(struct hci_uart *hu) |
| 302 | { |
| 303 | struct ath_struct *ath = hu->priv; |
| 304 | |
| 305 | BT_DBG("hu %p", hu); |
| 306 | |
| 307 | skb_queue_purge(&ath->txq); |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | /* Close protocol */ |
| 313 | static int ath_close(struct hci_uart *hu) |
| 314 | { |
| 315 | struct ath_struct *ath = hu->priv; |
| 316 | |
| 317 | BT_DBG("hu %p", hu); |
| 318 | |
| 319 | skb_queue_purge(&ath->txq); |
| 320 | |
| 321 | cancel_work_sync(&ath->ctxtsw); |
| 322 | |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 323 | cancel_work_sync(&ath->ws_sleep); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 324 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 325 | if (bsi) |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 326 | ath_bluesleep_gpio_config(ath, 0); |
| 327 | |
| 328 | hu->priv = NULL; |
| 329 | kfree(ath); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 330 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | #define HCI_OP_ATH_SLEEP 0xFC04 |
| 335 | |
| 336 | /* Enqueue frame for transmittion */ |
| 337 | static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb) |
| 338 | { |
| 339 | struct ath_struct *ath = hu->priv; |
| 340 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 341 | BT_DBG(""); |
| 342 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 343 | if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) { |
Dan Carpenter | 4ebaa4e | 2010-07-23 12:11:04 +0200 | [diff] [blame] | 344 | kfree_skb(skb); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | * Update power management enable flag with parameters of |
| 350 | * HCI sleep enable vendor specific HCI command. |
| 351 | */ |
| 352 | if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { |
| 353 | struct hci_command_hdr *hdr = (void *)skb->data; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 354 | if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP) { |
| 355 | set_bit(BT_SLEEPCMD, &flags); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 356 | ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE]; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 357 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | BT_DBG("hu %p skb %p", hu, skb); |
| 361 | |
| 362 | /* Prepend skb with frame type */ |
| 363 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); |
| 364 | |
| 365 | skb_queue_tail(&ath->txq, skb); |
| 366 | set_bit(HCI_UART_SENDING, &hu->tx_state); |
| 367 | |
| 368 | schedule_work(&ath->ctxtsw); |
| 369 | |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | static struct sk_buff *ath_dequeue(struct hci_uart *hu) |
| 374 | { |
| 375 | struct ath_struct *ath = hu->priv; |
| 376 | |
| 377 | return skb_dequeue(&ath->txq); |
| 378 | } |
| 379 | |
| 380 | /* Recv data */ |
| 381 | static int ath_recv(struct hci_uart *hu, void *data, int count) |
| 382 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 383 | struct ath_struct *ath = hu->priv; |
| 384 | unsigned int type; |
Jiejing Zhang | 78b4a56 | 2011-04-07 20:37:06 +0800 | [diff] [blame] | 385 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 386 | BT_DBG(""); |
| 387 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 388 | if (hci_recv_stream_fragment(hu->hdev, data, count) < 0) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 389 | BT_ERR("Frame Reassembly Failed"); |
| 390 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 391 | if (count & test_bit(BT_SLEEPCMD, &flags)) { |
| 392 | struct sk_buff *skb = hu->hdev->reassembly[0]; |
| 393 | |
| 394 | if (!skb) { |
| 395 | struct { char type; } *pkt; |
| 396 | |
| 397 | /* Start of the frame */ |
| 398 | pkt = data; |
| 399 | type = pkt->type; |
| 400 | } else |
| 401 | type = bt_cb(skb)->pkt_type; |
| 402 | |
| 403 | if (type == HCI_EVENT_PKT) { |
| 404 | clear_bit(BT_SLEEPCMD, &flags); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 405 | BT_INFO("cur_sleep:%d\n", ath->cur_sleep); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 406 | if (ath->cur_sleep == 1) |
| 407 | set_bit(BT_SLEEPENABLE, &flags); |
| 408 | else |
| 409 | clear_bit(BT_SLEEPENABLE, &flags); |
| 410 | } |
| 411 | if (test_bit(BT_SLEEPENABLE, &flags)) |
| 412 | modify_timer_task(); |
| 413 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 414 | return count; |
| 415 | } |
| 416 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 417 | static void bluesleep_tx_timer_expire(unsigned long data) |
| 418 | { |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 419 | struct hci_uart *hu = (struct hci_uart *) data; |
| 420 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 421 | if (!test_bit(BT_SLEEPENABLE, &flags)) |
| 422 | return; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 423 | BT_INFO("Tx timer expired\n"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 424 | |
| 425 | set_bit(BT_TXEXPIRED, &flags); |
Ram Mohan Korukonda | eff0e07 | 2012-11-19 16:05:52 +0530 | [diff] [blame] | 426 | hsuart_serial_clock_off(hu->tty); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 427 | } |
| 428 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 429 | static struct hci_uart_proto athp = { |
| 430 | .id = HCI_UART_ATH3K, |
| 431 | .open = ath_open, |
| 432 | .close = ath_close, |
| 433 | .recv = ath_recv, |
| 434 | .enqueue = ath_enqueue, |
| 435 | .dequeue = ath_dequeue, |
| 436 | .flush = ath_flush, |
| 437 | }; |
| 438 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 439 | static int __init bluesleep_probe(struct platform_device *pdev) |
| 440 | { |
| 441 | int ret; |
| 442 | struct resource *res; |
| 443 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 444 | BT_DBG(""); |
| 445 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 446 | bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL); |
| 447 | if (!bsi) { |
| 448 | ret = -ENOMEM; |
| 449 | goto failed; |
| 450 | } |
| 451 | |
| 452 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, |
| 453 | "gpio_host_wake"); |
| 454 | if (!res) { |
| 455 | BT_ERR("couldn't find host_wake gpio\n"); |
| 456 | ret = -ENODEV; |
| 457 | goto free_bsi; |
| 458 | } |
| 459 | bsi->host_wake = res->start; |
| 460 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 461 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, |
| 462 | "gpio_ext_wake"); |
| 463 | if (!res) { |
| 464 | BT_ERR("couldn't find ext_wake gpio\n"); |
| 465 | ret = -ENODEV; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 466 | goto free_bsi; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 467 | } |
| 468 | bsi->ext_wake = res->start; |
| 469 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 470 | bsi->host_wake_irq = platform_get_irq_byname(pdev, "host_wake"); |
| 471 | if (bsi->host_wake_irq < 0) { |
| 472 | BT_ERR("couldn't find host_wake irq\n"); |
| 473 | ret = -ENODEV; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 474 | goto free_bsi; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | bsi->irq_polarity = POLARITY_LOW; /* low edge (falling edge) */ |
| 478 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 479 | return 0; |
| 480 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 481 | free_bsi: |
| 482 | kfree(bsi); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 483 | bsi = NULL; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 484 | failed: |
| 485 | return ret; |
| 486 | } |
| 487 | |
| 488 | static int bluesleep_remove(struct platform_device *pdev) |
| 489 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 490 | kfree(bsi); |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static struct platform_driver bluesleep_driver = { |
| 495 | .remove = bluesleep_remove, |
| 496 | .driver = { |
| 497 | .name = "bluesleep", |
| 498 | .owner = THIS_MODULE, |
| 499 | }, |
| 500 | }; |
| 501 | |
Gustavo F. Padovan | f2b94bb | 2010-07-24 02:04:44 -0300 | [diff] [blame] | 502 | int __init ath_init(void) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 503 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 504 | int ret; |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 505 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 506 | ret = hci_uart_register_proto(&athp); |
| 507 | |
| 508 | if (!ret) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 509 | BT_INFO("HCIATH3K protocol initialized"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 510 | else { |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 511 | BT_ERR("HCIATH3K protocol registration failed"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 512 | return ret; |
| 513 | } |
| 514 | ret = platform_driver_probe(&bluesleep_driver, bluesleep_probe); |
| 515 | if (ret) |
| 516 | return ret; |
| 517 | return 0; |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 518 | } |
| 519 | |
Gustavo F. Padovan | f2b94bb | 2010-07-24 02:04:44 -0300 | [diff] [blame] | 520 | int __exit ath_deinit(void) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 521 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 522 | platform_driver_unregister(&bluesleep_driver); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 523 | return hci_uart_unregister_proto(&athp); |
| 524 | } |