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. |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 8 | * Copyright (c) 2012, Code Aurora Forum. 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" |
| 46 | |
Ram Mohan Korukonda | eb530d19 | 2012-08-08 16:54:51 +0530 | [diff] [blame] | 47 | unsigned int enableuartsleep = 1; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 48 | module_param(enableuartsleep, uint, 0644); |
| 49 | /* |
| 50 | * Global variables |
| 51 | */ |
| 52 | /** Global state flags */ |
| 53 | static unsigned long flags; |
| 54 | |
| 55 | /** Tasklet to respond to change in hostwake line */ |
| 56 | static struct tasklet_struct hostwake_task; |
| 57 | |
| 58 | /** Transmission timer */ |
| 59 | static void bluesleep_tx_timer_expire(unsigned long data); |
| 60 | static DEFINE_TIMER(tx_timer, bluesleep_tx_timer_expire, 0, 0); |
| 61 | |
| 62 | /** Lock for state transitions */ |
| 63 | static spinlock_t rw_lock; |
| 64 | |
| 65 | #define POLARITY_LOW 0 |
| 66 | #define POLARITY_HIGH 1 |
| 67 | |
| 68 | struct bluesleep_info { |
| 69 | unsigned host_wake; /* wake up host */ |
| 70 | unsigned ext_wake; /* wake up device */ |
| 71 | unsigned host_wake_irq; |
| 72 | int irq_polarity; |
| 73 | }; |
| 74 | |
| 75 | /* 1 second timeout */ |
| 76 | #define TX_TIMER_INTERVAL 1 |
| 77 | |
| 78 | /* state variable names and bit positions */ |
| 79 | #define BT_TXEXPIRED 0x01 |
| 80 | #define BT_SLEEPENABLE 0x02 |
| 81 | #define BT_SLEEPCMD 0x03 |
| 82 | |
| 83 | /* global pointer to a single hci device. */ |
| 84 | static struct bluesleep_info *bsi; |
| 85 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 86 | struct ath_struct { |
| 87 | struct hci_uart *hu; |
| 88 | unsigned int cur_sleep; |
| 89 | |
| 90 | struct sk_buff_head txq; |
| 91 | struct work_struct ctxtsw; |
| 92 | }; |
| 93 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 94 | static void hostwake_interrupt(unsigned long data) |
| 95 | { |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 96 | BT_INFO(" wakeup host\n"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void modify_timer_task(void) |
| 100 | { |
| 101 | spin_lock(&rw_lock); |
| 102 | mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ)); |
| 103 | clear_bit(BT_TXEXPIRED, &flags); |
| 104 | spin_unlock(&rw_lock); |
| 105 | |
| 106 | } |
| 107 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 108 | static int ath_wakeup_ar3k(struct tty_struct *tty) |
| 109 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 110 | int status = 0; |
| 111 | if (test_bit(BT_TXEXPIRED, &flags)) { |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 112 | BT_INFO("wakeup device\n"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 113 | gpio_set_value(bsi->ext_wake, 0); |
Ram Mohan Korukonda | eb530d19 | 2012-08-08 16:54:51 +0530 | [diff] [blame] | 114 | msleep(20); |
| 115 | gpio_set_value(bsi->ext_wake, 1); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 116 | } |
| 117 | modify_timer_task(); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 118 | return status; |
| 119 | } |
| 120 | |
| 121 | static void ath_hci_uart_work(struct work_struct *work) |
| 122 | { |
| 123 | int status; |
| 124 | struct ath_struct *ath; |
| 125 | struct hci_uart *hu; |
| 126 | struct tty_struct *tty; |
| 127 | |
| 128 | ath = container_of(work, struct ath_struct, ctxtsw); |
| 129 | |
| 130 | hu = ath->hu; |
| 131 | tty = hu->tty; |
| 132 | |
| 133 | /* verify and wake up controller */ |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 134 | if (test_bit(BT_SLEEPENABLE, &flags)) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 135 | status = ath_wakeup_ar3k(tty); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 136 | /* Ready to send Data */ |
| 137 | clear_bit(HCI_UART_SENDING, &hu->tx_state); |
| 138 | hci_uart_tx_wakeup(hu); |
| 139 | } |
| 140 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 141 | static irqreturn_t bluesleep_hostwake_isr(int irq, void *dev_id) |
| 142 | { |
| 143 | /* schedule a tasklet to handle the change in the host wake line */ |
| 144 | tasklet_schedule(&hostwake_task); |
| 145 | return IRQ_HANDLED; |
| 146 | } |
| 147 | |
| 148 | static int ath_bluesleep_gpio_config(int on) |
| 149 | { |
| 150 | int ret = 0; |
| 151 | |
| 152 | BT_INFO("%s config: %d", __func__, on); |
| 153 | if (!on) { |
| 154 | if (disable_irq_wake(bsi->host_wake_irq)) |
| 155 | BT_ERR("Couldn't disable hostwake IRQ wakeup mode\n"); |
| 156 | goto free_host_wake_irq; |
| 157 | } |
| 158 | |
| 159 | ret = gpio_request(bsi->host_wake, "bt_host_wake"); |
| 160 | if (ret < 0) { |
| 161 | BT_ERR("failed to request gpio pin %d, error %d\n", |
| 162 | bsi->host_wake, ret); |
| 163 | goto gpio_config_failed; |
| 164 | } |
| 165 | |
| 166 | /* configure host_wake as input */ |
| 167 | ret = gpio_direction_input(bsi->host_wake); |
| 168 | if (ret < 0) { |
| 169 | BT_ERR("failed to config GPIO %d as input pin, err %d\n", |
| 170 | bsi->host_wake, ret); |
| 171 | goto gpio_host_wake; |
| 172 | } |
| 173 | |
| 174 | ret = gpio_request(bsi->ext_wake, "bt_ext_wake"); |
| 175 | if (ret < 0) { |
| 176 | BT_ERR("failed to request gpio pin %d, error %d\n", |
| 177 | bsi->ext_wake, ret); |
| 178 | goto gpio_host_wake; |
| 179 | } |
| 180 | |
| 181 | ret = gpio_direction_output(bsi->ext_wake, 1); |
| 182 | if (ret < 0) { |
| 183 | BT_ERR("failed to config GPIO %d as output pin, err %d\n", |
| 184 | bsi->ext_wake, ret); |
| 185 | goto gpio_ext_wake; |
| 186 | } |
| 187 | |
| 188 | gpio_set_value(bsi->ext_wake, 1); |
| 189 | |
| 190 | /* Initialize spinlock. */ |
| 191 | spin_lock_init(&rw_lock); |
| 192 | |
| 193 | /* Initialize timer */ |
| 194 | init_timer(&tx_timer); |
| 195 | tx_timer.function = bluesleep_tx_timer_expire; |
| 196 | tx_timer.data = 0; |
| 197 | |
| 198 | /* initialize host wake tasklet */ |
| 199 | tasklet_init(&hostwake_task, hostwake_interrupt, 0); |
| 200 | |
| 201 | if (bsi->irq_polarity == POLARITY_LOW) { |
| 202 | ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr, |
| 203 | IRQF_DISABLED | IRQF_TRIGGER_FALLING, |
| 204 | "bluetooth hostwake", NULL); |
| 205 | } else { |
| 206 | ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr, |
| 207 | IRQF_DISABLED | IRQF_TRIGGER_RISING, |
| 208 | "bluetooth hostwake", NULL); |
| 209 | } |
| 210 | if (ret < 0) { |
| 211 | BT_ERR("Couldn't acquire BT_HOST_WAKE IRQ"); |
| 212 | goto delete_timer; |
| 213 | } |
| 214 | |
| 215 | ret = enable_irq_wake(bsi->host_wake_irq); |
| 216 | if (ret < 0) { |
| 217 | BT_ERR("Couldn't enable BT_HOST_WAKE as wakeup interrupt"); |
| 218 | goto free_host_wake_irq; |
| 219 | } |
| 220 | |
| 221 | return 0; |
| 222 | |
| 223 | free_host_wake_irq: |
| 224 | free_irq(bsi->host_wake_irq, NULL); |
| 225 | delete_timer: |
| 226 | del_timer(&tx_timer); |
| 227 | gpio_ext_wake: |
| 228 | gpio_free(bsi->ext_wake); |
| 229 | gpio_host_wake: |
| 230 | gpio_free(bsi->host_wake); |
| 231 | gpio_config_failed: |
| 232 | return ret; |
| 233 | } |
| 234 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 235 | /* Initialize protocol */ |
| 236 | static int ath_open(struct hci_uart *hu) |
| 237 | { |
| 238 | struct ath_struct *ath; |
| 239 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 240 | BT_DBG("hu %p, bsi %p", hu, bsi); |
| 241 | |
| 242 | if (!bsi) |
| 243 | return -EIO; |
| 244 | |
| 245 | if (ath_bluesleep_gpio_config(1) < 0) { |
| 246 | BT_ERR("HCIATH3K GPIO Config failed"); |
| 247 | return -EIO; |
| 248 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 249 | |
| 250 | ath = kzalloc(sizeof(*ath), GFP_ATOMIC); |
| 251 | if (!ath) |
| 252 | return -ENOMEM; |
| 253 | |
| 254 | skb_queue_head_init(&ath->txq); |
| 255 | |
| 256 | hu->priv = ath; |
| 257 | ath->hu = hu; |
| 258 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 259 | ath->cur_sleep = enableuartsleep; |
| 260 | if (ath->cur_sleep == 1) { |
| 261 | set_bit(BT_SLEEPENABLE, &flags); |
| 262 | modify_timer_task(); |
| 263 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 264 | INIT_WORK(&ath->ctxtsw, ath_hci_uart_work); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | /* Flush protocol data */ |
| 270 | static int ath_flush(struct hci_uart *hu) |
| 271 | { |
| 272 | struct ath_struct *ath = hu->priv; |
| 273 | |
| 274 | BT_DBG("hu %p", hu); |
| 275 | |
| 276 | skb_queue_purge(&ath->txq); |
| 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | /* Close protocol */ |
| 282 | static int ath_close(struct hci_uart *hu) |
| 283 | { |
| 284 | struct ath_struct *ath = hu->priv; |
| 285 | |
| 286 | BT_DBG("hu %p", hu); |
| 287 | |
| 288 | skb_queue_purge(&ath->txq); |
| 289 | |
| 290 | cancel_work_sync(&ath->ctxtsw); |
| 291 | |
| 292 | hu->priv = NULL; |
| 293 | kfree(ath); |
| 294 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 295 | if (bsi) |
| 296 | ath_bluesleep_gpio_config(0); |
| 297 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | #define HCI_OP_ATH_SLEEP 0xFC04 |
| 302 | |
| 303 | /* Enqueue frame for transmittion */ |
| 304 | static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb) |
| 305 | { |
| 306 | struct ath_struct *ath = hu->priv; |
| 307 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 308 | BT_DBG(""); |
| 309 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 310 | if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) { |
Dan Carpenter | 4ebaa4e | 2010-07-23 12:11:04 +0200 | [diff] [blame] | 311 | kfree_skb(skb); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * Update power management enable flag with parameters of |
| 317 | * HCI sleep enable vendor specific HCI command. |
| 318 | */ |
| 319 | if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) { |
| 320 | struct hci_command_hdr *hdr = (void *)skb->data; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 321 | if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP) { |
| 322 | set_bit(BT_SLEEPCMD, &flags); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 323 | ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE]; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 324 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | BT_DBG("hu %p skb %p", hu, skb); |
| 328 | |
| 329 | /* Prepend skb with frame type */ |
| 330 | memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1); |
| 331 | |
| 332 | skb_queue_tail(&ath->txq, skb); |
| 333 | set_bit(HCI_UART_SENDING, &hu->tx_state); |
| 334 | |
| 335 | schedule_work(&ath->ctxtsw); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static struct sk_buff *ath_dequeue(struct hci_uart *hu) |
| 341 | { |
| 342 | struct ath_struct *ath = hu->priv; |
| 343 | |
| 344 | return skb_dequeue(&ath->txq); |
| 345 | } |
| 346 | |
| 347 | /* Recv data */ |
| 348 | static int ath_recv(struct hci_uart *hu, void *data, int count) |
| 349 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 350 | struct ath_struct *ath = hu->priv; |
| 351 | unsigned int type; |
Jiejing Zhang | 78b4a56 | 2011-04-07 20:37:06 +0800 | [diff] [blame] | 352 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 353 | BT_DBG(""); |
| 354 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 355 | if (hci_recv_stream_fragment(hu->hdev, data, count) < 0) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 356 | BT_ERR("Frame Reassembly Failed"); |
| 357 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 358 | if (count & test_bit(BT_SLEEPCMD, &flags)) { |
| 359 | struct sk_buff *skb = hu->hdev->reassembly[0]; |
| 360 | |
| 361 | if (!skb) { |
| 362 | struct { char type; } *pkt; |
| 363 | |
| 364 | /* Start of the frame */ |
| 365 | pkt = data; |
| 366 | type = pkt->type; |
| 367 | } else |
| 368 | type = bt_cb(skb)->pkt_type; |
| 369 | |
| 370 | if (type == HCI_EVENT_PKT) { |
| 371 | clear_bit(BT_SLEEPCMD, &flags); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 372 | BT_INFO("cur_sleep:%d\n", ath->cur_sleep); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 373 | if (ath->cur_sleep == 1) |
| 374 | set_bit(BT_SLEEPENABLE, &flags); |
| 375 | else |
| 376 | clear_bit(BT_SLEEPENABLE, &flags); |
| 377 | } |
| 378 | if (test_bit(BT_SLEEPENABLE, &flags)) |
| 379 | modify_timer_task(); |
| 380 | } |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 381 | return count; |
| 382 | } |
| 383 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 384 | static void bluesleep_tx_timer_expire(unsigned long data) |
| 385 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 386 | if (!test_bit(BT_SLEEPENABLE, &flags)) |
| 387 | return; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 388 | BT_INFO("Tx timer expired\n"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 389 | |
| 390 | set_bit(BT_TXEXPIRED, &flags); |
| 391 | } |
| 392 | |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 393 | static struct hci_uart_proto athp = { |
| 394 | .id = HCI_UART_ATH3K, |
| 395 | .open = ath_open, |
| 396 | .close = ath_close, |
| 397 | .recv = ath_recv, |
| 398 | .enqueue = ath_enqueue, |
| 399 | .dequeue = ath_dequeue, |
| 400 | .flush = ath_flush, |
| 401 | }; |
| 402 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 403 | static int __init bluesleep_probe(struct platform_device *pdev) |
| 404 | { |
| 405 | int ret; |
| 406 | struct resource *res; |
| 407 | |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 408 | BT_DBG(""); |
| 409 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 410 | bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL); |
| 411 | if (!bsi) { |
| 412 | ret = -ENOMEM; |
| 413 | goto failed; |
| 414 | } |
| 415 | |
| 416 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, |
| 417 | "gpio_host_wake"); |
| 418 | if (!res) { |
| 419 | BT_ERR("couldn't find host_wake gpio\n"); |
| 420 | ret = -ENODEV; |
| 421 | goto free_bsi; |
| 422 | } |
| 423 | bsi->host_wake = res->start; |
| 424 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 425 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, |
| 426 | "gpio_ext_wake"); |
| 427 | if (!res) { |
| 428 | BT_ERR("couldn't find ext_wake gpio\n"); |
| 429 | ret = -ENODEV; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 430 | goto free_bsi; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 431 | } |
| 432 | bsi->ext_wake = res->start; |
| 433 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 434 | bsi->host_wake_irq = platform_get_irq_byname(pdev, "host_wake"); |
| 435 | if (bsi->host_wake_irq < 0) { |
| 436 | BT_ERR("couldn't find host_wake irq\n"); |
| 437 | ret = -ENODEV; |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 438 | goto free_bsi; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | bsi->irq_polarity = POLARITY_LOW; /* low edge (falling edge) */ |
| 442 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 443 | return 0; |
| 444 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 445 | free_bsi: |
| 446 | kfree(bsi); |
Ram Mohan Korukonda | e359d86 | 2012-08-18 21:12:17 +0530 | [diff] [blame] | 447 | bsi = NULL; |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 448 | failed: |
| 449 | return ret; |
| 450 | } |
| 451 | |
| 452 | static int bluesleep_remove(struct platform_device *pdev) |
| 453 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 454 | kfree(bsi); |
| 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static struct platform_driver bluesleep_driver = { |
| 459 | .remove = bluesleep_remove, |
| 460 | .driver = { |
| 461 | .name = "bluesleep", |
| 462 | .owner = THIS_MODULE, |
| 463 | }, |
| 464 | }; |
| 465 | |
Gustavo F. Padovan | f2b94bb | 2010-07-24 02:04:44 -0300 | [diff] [blame] | 466 | int __init ath_init(void) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 467 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 468 | int ret; |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 469 | |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 470 | ret = hci_uart_register_proto(&athp); |
| 471 | |
| 472 | if (!ret) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 473 | BT_INFO("HCIATH3K protocol initialized"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 474 | else { |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 475 | BT_ERR("HCIATH3K protocol registration failed"); |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 476 | return ret; |
| 477 | } |
| 478 | ret = platform_driver_probe(&bluesleep_driver, bluesleep_probe); |
| 479 | if (ret) |
| 480 | return ret; |
| 481 | return 0; |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 482 | } |
| 483 | |
Gustavo F. Padovan | f2b94bb | 2010-07-24 02:04:44 -0300 | [diff] [blame] | 484 | int __exit ath_deinit(void) |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 485 | { |
Santosh Sajjan | 55efc7f | 2012-06-27 19:10:49 +0530 | [diff] [blame] | 486 | platform_driver_unregister(&bluesleep_driver); |
Suraj Sumangala | b3190df | 2010-07-19 12:34:07 +0530 | [diff] [blame] | 487 | return hci_uart_unregister_proto(&athp); |
| 488 | } |