blob: 2557983f16739b9cc188bae97d7d77b95e4dc0ae [file] [log] [blame]
Suraj Sumangalab3190df2010-07-19 12:34:07 +05301/*
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.
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +05308 * Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
Suraj Sumangalab3190df2010-07-19 12:34:07 +05309 *
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 Sajjan55efc7f2012-06-27 19:10:49 +053039#include <linux/platform_device.h>
40#include <linux/gpio.h>
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +053041#include <linux/of_gpio.h>
Suraj Sumangalab3190df2010-07-19 12:34:07 +053042#include <net/bluetooth/bluetooth.h>
43#include <net/bluetooth/hci_core.h>
44
45#include "hci_uart.h"
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +053046#ifdef CONFIG_SERIAL_MSM_HS
47#include <mach/msm_serial_hs.h>
48#endif
Suraj Sumangalab3190df2010-07-19 12:34:07 +053049
Ram Mohan Korukondaeb530d192012-08-08 16:54:51 +053050unsigned int enableuartsleep = 1;
Santosh Sajjan55efc7f2012-06-27 19:10:49 +053051module_param(enableuartsleep, uint, 0644);
52/*
53 * Global variables
54 */
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +053055
56/** Device table */
57static struct of_device_id bluesleep_match_table[] = {
58 { .compatible = "qca,ar3002_bluesleep" },
59 {}
60};
61
Santosh Sajjan55efc7f2012-06-27 19:10:49 +053062/** Global state flags */
63static unsigned long flags;
64
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +053065/** Workqueue to respond to change in hostwake line */
66static void wakeup_host_work(struct work_struct *work);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +053067
68/** Transmission timer */
69static void bluesleep_tx_timer_expire(unsigned long data);
70static DEFINE_TIMER(tx_timer, bluesleep_tx_timer_expire, 0, 0);
71
72/** Lock for state transitions */
73static spinlock_t rw_lock;
74
75#define POLARITY_LOW 0
76#define POLARITY_HIGH 1
77
78struct bluesleep_info {
79 unsigned host_wake; /* wake up host */
80 unsigned ext_wake; /* wake up device */
81 unsigned host_wake_irq;
82 int irq_polarity;
83};
84
85/* 1 second timeout */
86#define TX_TIMER_INTERVAL 1
87
88/* state variable names and bit positions */
89#define BT_TXEXPIRED 0x01
90#define BT_SLEEPENABLE 0x02
91#define BT_SLEEPCMD 0x03
92
93/* global pointer to a single hci device. */
94static struct bluesleep_info *bsi;
95
Suraj Sumangalab3190df2010-07-19 12:34:07 +053096struct ath_struct {
97 struct hci_uart *hu;
98 unsigned int cur_sleep;
99
100 struct sk_buff_head txq;
101 struct work_struct ctxtsw;
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530102 struct work_struct ws_sleep;
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530103};
104
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530105static void hsuart_serial_clock_on(struct tty_struct *tty)
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530106{
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530107 struct uart_state *state = tty->driver_data;
108 struct uart_port *port = state->uart_port;
109 BT_DBG("");
110 msm_hs_request_clock_on(port);
111}
112
113static void hsuart_serial_clock_off(struct tty_struct *tty)
114{
115 struct uart_state *state = tty->driver_data;
116 struct uart_port *port = state->uart_port;
117 BT_DBG("");
118 msm_hs_request_clock_off(port);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530119}
120
121static void modify_timer_task(void)
122{
123 spin_lock(&rw_lock);
124 mod_timer(&tx_timer, jiffies + (TX_TIMER_INTERVAL * HZ));
125 clear_bit(BT_TXEXPIRED, &flags);
126 spin_unlock(&rw_lock);
127
128}
129
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530130static int ath_wakeup_ar3k(struct tty_struct *tty)
131{
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530132 int status = 0;
133 if (test_bit(BT_TXEXPIRED, &flags)) {
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530134 hsuart_serial_clock_on(tty);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530135 BT_INFO("wakeup device\n");
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530136 gpio_set_value(bsi->ext_wake, 0);
Ram Mohan Korukondaeb530d192012-08-08 16:54:51 +0530137 msleep(20);
138 gpio_set_value(bsi->ext_wake, 1);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530139 }
140 modify_timer_task();
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530141 return status;
142}
143
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530144static void wakeup_host_work(struct work_struct *work)
145{
146 struct ath_struct *ath =
147 container_of(work, struct ath_struct, ws_sleep);
148
149 BT_INFO("wake up host");
150 if (test_bit(BT_SLEEPENABLE, &flags)) {
151 if (test_bit(BT_TXEXPIRED, &flags))
152 hsuart_serial_clock_on(ath->hu->tty);
153 }
154 modify_timer_task();
155}
156
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530157static void ath_hci_uart_work(struct work_struct *work)
158{
159 int status;
160 struct ath_struct *ath;
161 struct hci_uart *hu;
162 struct tty_struct *tty;
163
164 ath = container_of(work, struct ath_struct, ctxtsw);
165
166 hu = ath->hu;
167 tty = hu->tty;
168
169 /* verify and wake up controller */
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530170 if (test_bit(BT_SLEEPENABLE, &flags))
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530171 status = ath_wakeup_ar3k(tty);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530172 /* Ready to send Data */
173 clear_bit(HCI_UART_SENDING, &hu->tx_state);
174 hci_uart_tx_wakeup(hu);
175}
176
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530177static irqreturn_t bluesleep_hostwake_isr(int irq, void *dev_id)
178{
179 /* schedule a tasklet to handle the change in the host wake line */
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530180 struct ath_struct *ath = (struct ath_struct *)dev_id;
181
182 schedule_work(&ath->ws_sleep);
183
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530184 return IRQ_HANDLED;
185}
186
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530187static int ath_bluesleep_gpio_config(struct ath_struct *ath, int on)
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530188{
189 int ret = 0;
190
191 BT_INFO("%s config: %d", __func__, on);
192 if (!on) {
193 if (disable_irq_wake(bsi->host_wake_irq))
194 BT_ERR("Couldn't disable hostwake IRQ wakeup mode\n");
195 goto free_host_wake_irq;
196 }
197
198 ret = gpio_request(bsi->host_wake, "bt_host_wake");
199 if (ret < 0) {
200 BT_ERR("failed to request gpio pin %d, error %d\n",
201 bsi->host_wake, ret);
202 goto gpio_config_failed;
203 }
204
205 /* configure host_wake as input */
206 ret = gpio_direction_input(bsi->host_wake);
207 if (ret < 0) {
208 BT_ERR("failed to config GPIO %d as input pin, err %d\n",
209 bsi->host_wake, ret);
210 goto gpio_host_wake;
211 }
212
213 ret = gpio_request(bsi->ext_wake, "bt_ext_wake");
214 if (ret < 0) {
215 BT_ERR("failed to request gpio pin %d, error %d\n",
216 bsi->ext_wake, ret);
217 goto gpio_host_wake;
218 }
219
220 ret = gpio_direction_output(bsi->ext_wake, 1);
221 if (ret < 0) {
222 BT_ERR("failed to config GPIO %d as output pin, err %d\n",
223 bsi->ext_wake, ret);
224 goto gpio_ext_wake;
225 }
226
227 gpio_set_value(bsi->ext_wake, 1);
228
229 /* Initialize spinlock. */
230 spin_lock_init(&rw_lock);
231
232 /* Initialize timer */
233 init_timer(&tx_timer);
234 tx_timer.function = bluesleep_tx_timer_expire;
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530235 tx_timer.data = (u_long)ath->hu;
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530236
237 if (bsi->irq_polarity == POLARITY_LOW) {
238 ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr,
239 IRQF_DISABLED | IRQF_TRIGGER_FALLING,
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530240 "bluetooth hostwake", (void *)ath);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530241 } else {
242 ret = request_irq(bsi->host_wake_irq, bluesleep_hostwake_isr,
243 IRQF_DISABLED | IRQF_TRIGGER_RISING,
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530244 "bluetooth hostwake", (void *)ath);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530245 }
246 if (ret < 0) {
247 BT_ERR("Couldn't acquire BT_HOST_WAKE IRQ");
248 goto delete_timer;
249 }
250
251 ret = enable_irq_wake(bsi->host_wake_irq);
252 if (ret < 0) {
253 BT_ERR("Couldn't enable BT_HOST_WAKE as wakeup interrupt");
254 goto free_host_wake_irq;
255 }
256
257 return 0;
258
259free_host_wake_irq:
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530260 free_irq(bsi->host_wake_irq, (void *)ath);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530261delete_timer:
262 del_timer(&tx_timer);
263gpio_ext_wake:
264 gpio_free(bsi->ext_wake);
265gpio_host_wake:
266 gpio_free(bsi->host_wake);
267gpio_config_failed:
268 return ret;
269}
270
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530271/* Initialize protocol */
272static int ath_open(struct hci_uart *hu)
273{
274 struct ath_struct *ath;
275
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530276 BT_DBG("hu %p, bsi %p", hu, bsi);
277
278 if (!bsi)
279 return -EIO;
280
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530281 ath = kzalloc(sizeof(*ath), GFP_ATOMIC);
282 if (!ath)
283 return -ENOMEM;
284
285 skb_queue_head_init(&ath->txq);
286
287 hu->priv = ath;
288 ath->hu = hu;
289
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530290 if (ath_bluesleep_gpio_config(ath, 1) < 0) {
291 BT_ERR("HCIATH3K GPIO Config failed");
292 hu->priv = NULL;
293 kfree(ath);
294 return -EIO;
295 }
296
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530297 ath->cur_sleep = enableuartsleep;
298 if (ath->cur_sleep == 1) {
299 set_bit(BT_SLEEPENABLE, &flags);
300 modify_timer_task();
301 }
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530302 INIT_WORK(&ath->ctxtsw, ath_hci_uart_work);
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530303 INIT_WORK(&ath->ws_sleep, wakeup_host_work);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530304 return 0;
305}
306
307/* Flush protocol data */
308static int ath_flush(struct hci_uart *hu)
309{
310 struct ath_struct *ath = hu->priv;
311
312 BT_DBG("hu %p", hu);
313
314 skb_queue_purge(&ath->txq);
315
316 return 0;
317}
318
319/* Close protocol */
320static int ath_close(struct hci_uart *hu)
321{
322 struct ath_struct *ath = hu->priv;
323
324 BT_DBG("hu %p", hu);
325
326 skb_queue_purge(&ath->txq);
327
328 cancel_work_sync(&ath->ctxtsw);
329
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530330 cancel_work_sync(&ath->ws_sleep);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530331
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530332 if (bsi)
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530333 ath_bluesleep_gpio_config(ath, 0);
334
335 hu->priv = NULL;
336 kfree(ath);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530337
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530338 return 0;
339}
340
341#define HCI_OP_ATH_SLEEP 0xFC04
342
343/* Enqueue frame for transmittion */
344static int ath_enqueue(struct hci_uart *hu, struct sk_buff *skb)
345{
346 struct ath_struct *ath = hu->priv;
347
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530348 BT_DBG("");
349
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530350 if (bt_cb(skb)->pkt_type == HCI_SCODATA_PKT) {
Dan Carpenter4ebaa4e2010-07-23 12:11:04 +0200351 kfree_skb(skb);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530352 return 0;
353 }
354
355 /*
356 * Update power management enable flag with parameters of
357 * HCI sleep enable vendor specific HCI command.
358 */
359 if (bt_cb(skb)->pkt_type == HCI_COMMAND_PKT) {
360 struct hci_command_hdr *hdr = (void *)skb->data;
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530361 if (__le16_to_cpu(hdr->opcode) == HCI_OP_ATH_SLEEP) {
362 set_bit(BT_SLEEPCMD, &flags);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530363 ath->cur_sleep = skb->data[HCI_COMMAND_HDR_SIZE];
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530364 }
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530365 }
366
367 BT_DBG("hu %p skb %p", hu, skb);
368
369 /* Prepend skb with frame type */
370 memcpy(skb_push(skb, 1), &bt_cb(skb)->pkt_type, 1);
371
372 skb_queue_tail(&ath->txq, skb);
373 set_bit(HCI_UART_SENDING, &hu->tx_state);
374
375 schedule_work(&ath->ctxtsw);
376
377 return 0;
378}
379
380static struct sk_buff *ath_dequeue(struct hci_uart *hu)
381{
382 struct ath_struct *ath = hu->priv;
383
384 return skb_dequeue(&ath->txq);
385}
386
387/* Recv data */
388static int ath_recv(struct hci_uart *hu, void *data, int count)
389{
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530390 struct ath_struct *ath = hu->priv;
391 unsigned int type;
Jiejing Zhang78b4a562011-04-07 20:37:06 +0800392
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530393 BT_DBG("");
394
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530395 if (hci_recv_stream_fragment(hu->hdev, data, count) < 0)
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530396 BT_ERR("Frame Reassembly Failed");
397
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530398 if (count & test_bit(BT_SLEEPCMD, &flags)) {
399 struct sk_buff *skb = hu->hdev->reassembly[0];
400
401 if (!skb) {
402 struct { char type; } *pkt;
403
404 /* Start of the frame */
405 pkt = data;
406 type = pkt->type;
407 } else
408 type = bt_cb(skb)->pkt_type;
409
410 if (type == HCI_EVENT_PKT) {
411 clear_bit(BT_SLEEPCMD, &flags);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530412 BT_INFO("cur_sleep:%d\n", ath->cur_sleep);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530413 if (ath->cur_sleep == 1)
414 set_bit(BT_SLEEPENABLE, &flags);
415 else
416 clear_bit(BT_SLEEPENABLE, &flags);
417 }
418 if (test_bit(BT_SLEEPENABLE, &flags))
419 modify_timer_task();
420 }
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530421 return count;
422}
423
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530424static void bluesleep_tx_timer_expire(unsigned long data)
425{
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530426 struct hci_uart *hu = (struct hci_uart *) data;
427
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530428 if (!test_bit(BT_SLEEPENABLE, &flags))
429 return;
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530430 BT_INFO("Tx timer expired\n");
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530431
432 set_bit(BT_TXEXPIRED, &flags);
Ram Mohan Korukondaeff0e072012-11-19 16:05:52 +0530433 hsuart_serial_clock_off(hu->tty);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530434}
435
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530436static struct hci_uart_proto athp = {
437 .id = HCI_UART_ATH3K,
438 .open = ath_open,
439 .close = ath_close,
440 .recv = ath_recv,
441 .enqueue = ath_enqueue,
442 .dequeue = ath_dequeue,
443 .flush = ath_flush,
444};
445
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530446
447static int bluesleep_populate_dt_pinfo(struct platform_device *pdev)
448{
449 BT_DBG("");
450
451 if (!bsi)
452 return -ENOMEM;
453
454 bsi->host_wake = of_get_named_gpio(pdev->dev.of_node,
455 "host-wake-gpio", 0);
456 if (bsi->host_wake < 0) {
457 BT_ERR("couldn't find host_wake gpio\n");
458 return -ENODEV;
459 }
460
461 bsi->ext_wake = of_get_named_gpio(pdev->dev.of_node,
462 "ext-wake-gpio", 0);
463 if (bsi->ext_wake < 0) {
464 BT_ERR("couldn't find ext_wake gpio\n");
465 return -ENODEV;
466 }
467
468 return 0;
469}
470
471static int bluesleep_populate_pinfo(struct platform_device *pdev)
472{
473 struct resource *res;
474
475 BT_DBG("");
476
477 res = platform_get_resource_byname(pdev, IORESOURCE_IO,
478 "gpio_host_wake");
479 if (!res) {
480 BT_ERR("couldn't find host_wake gpio\n");
481 return -ENODEV;
482 }
483 bsi->host_wake = res->start;
484
485 res = platform_get_resource_byname(pdev, IORESOURCE_IO,
486 "gpio_ext_wake");
487 if (!res) {
488 BT_ERR("couldn't find ext_wake gpio\n");
489 return -ENODEV;
490 }
491 bsi->ext_wake = res->start;
492
493 return 0;
494}
495
496static int __devinit bluesleep_probe(struct platform_device *pdev)
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530497{
498 int ret;
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530499
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530500 BT_DBG("");
501
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530502 bsi = kzalloc(sizeof(struct bluesleep_info), GFP_KERNEL);
503 if (!bsi) {
504 ret = -ENOMEM;
505 goto failed;
506 }
507
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530508 if (pdev->dev.of_node) {
509 ret = bluesleep_populate_dt_pinfo(pdev);
510 if (ret < 0) {
511 BT_ERR("Failed to populate device tree info");
512 goto free_bsi;
513 }
514 } else {
515 ret = bluesleep_populate_pinfo(pdev);
516 if (ret < 0) {
517 BT_ERR("Failed to populate device info");
518 goto free_bsi;
519 }
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530520 }
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530521
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530522 BT_DBG("host_wake_gpio: %d ext_wake_gpio: %d",
523 bsi->host_wake, bsi->ext_wake);
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530524
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530525 bsi->host_wake_irq = platform_get_irq_byname(pdev, "host_wake");
526 if (bsi->host_wake_irq < 0) {
527 BT_ERR("couldn't find host_wake irq\n");
528 ret = -ENODEV;
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530529 goto free_bsi;
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530530 }
531
532 bsi->irq_polarity = POLARITY_LOW; /* low edge (falling edge) */
533
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530534 return 0;
535
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530536free_bsi:
537 kfree(bsi);
Ram Mohan Korukondae359d862012-08-18 21:12:17 +0530538 bsi = NULL;
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530539failed:
540 return ret;
541}
542
543static int bluesleep_remove(struct platform_device *pdev)
544{
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530545 kfree(bsi);
546 return 0;
547}
548
549static struct platform_driver bluesleep_driver = {
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530550 .probe = bluesleep_probe,
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530551 .remove = bluesleep_remove,
552 .driver = {
553 .name = "bluesleep",
554 .owner = THIS_MODULE,
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530555 .of_match_table = bluesleep_match_table,
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530556 },
557};
558
Gustavo F. Padovanf2b94bb2010-07-24 02:04:44 -0300559int __init ath_init(void)
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530560{
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530561 int ret;
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530562
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530563 ret = hci_uart_register_proto(&athp);
564
565 if (!ret)
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530566 BT_INFO("HCIATH3K protocol initialized");
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530567 else {
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530568 BT_ERR("HCIATH3K protocol registration failed");
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530569 return ret;
570 }
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530571
572 ret = platform_driver_register(&bluesleep_driver);
573 if (ret) {
574 BT_ERR("Failed to register bluesleep driver");
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530575 return ret;
Ram Mohan Korukonda0eadc592013-03-19 22:29:45 +0530576 }
577
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530578 return 0;
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530579}
580
Gustavo F. Padovanf2b94bb2010-07-24 02:04:44 -0300581int __exit ath_deinit(void)
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530582{
Santosh Sajjan55efc7f2012-06-27 19:10:49 +0530583 platform_driver_unregister(&bluesleep_driver);
Suraj Sumangalab3190df2010-07-19 12:34:07 +0530584 return hci_uart_unregister_proto(&athp);
585}