aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth
diff options
context:
space:
mode:
authorBing Zhao <bzhao@marvell.com>2010-03-03 17:37:36 -0500
committerMarcel Holtmann <marcel@holtmann.org>2010-05-10 03:34:03 -0400
commit64061607eab7cb146115927cb596de123c542d45 (patch)
treec58015f5fc78f6cf553dd976304e0dcf978f7311 /drivers/bluetooth
parent903c843773a18e061817dd7a1a5c28dd41a3bf97 (diff)
Bluetooth: Separate btmrvl_register_hdev() from btmrvl_add_card()
Move btmrvl hdev registration code out of btmrvl_add_card(). New function btmrvl_register_hdev() is added. Signed-off-by: Bing Zhao <bzhao@marvell.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'drivers/bluetooth')
-rw-r--r--drivers/bluetooth/btmrvl_drv.h1
-rw-r--r--drivers/bluetooth/btmrvl_main.c75
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c7
3 files changed, 50 insertions, 33 deletions
diff --git a/drivers/bluetooth/btmrvl_drv.h b/drivers/bluetooth/btmrvl_drv.h
index da68c62a22cc..bf6d54fcbeaf 100644
--- a/drivers/bluetooth/btmrvl_drv.h
+++ b/drivers/bluetooth/btmrvl_drv.h
@@ -126,6 +126,7 @@ struct btmrvl_event {
126 126
127/* Prototype of global function */ 127/* Prototype of global function */
128 128
129int btmrvl_register_hdev(struct btmrvl_private *priv);
129struct btmrvl_private *btmrvl_add_card(void *card); 130struct btmrvl_private *btmrvl_add_card(void *card);
130int btmrvl_remove_card(struct btmrvl_private *priv); 131int btmrvl_remove_card(struct btmrvl_private *priv);
131 132
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 87d0d3d5ae54..ec48bfe9e279 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -524,47 +524,20 @@ static int btmrvl_service_main_thread(void *data)
524 return 0; 524 return 0;
525} 525}
526 526
527struct btmrvl_private *btmrvl_add_card(void *card) 527int btmrvl_register_hdev(struct btmrvl_private *priv)
528{ 528{
529 struct hci_dev *hdev = NULL; 529 struct hci_dev *hdev = NULL;
530 struct btmrvl_private *priv;
531 int ret; 530 int ret;
532 531
533 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
534 if (!priv) {
535 BT_ERR("Can not allocate priv");
536 goto err_priv;
537 }
538
539 priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
540 if (!priv->adapter) {
541 BT_ERR("Allocate buffer for btmrvl_adapter failed!");
542 goto err_adapter;
543 }
544
545 btmrvl_init_adapter(priv);
546
547 hdev = hci_alloc_dev(); 532 hdev = hci_alloc_dev();
548 if (!hdev) { 533 if (!hdev) {
549 BT_ERR("Can not allocate HCI device"); 534 BT_ERR("Can not allocate HCI device");
550 goto err_hdev; 535 goto err_hdev;
551 } 536 }
552 537
553 BT_DBG("Starting kthread...");
554 priv->main_thread.priv = priv;
555 spin_lock_init(&priv->driver_lock);
556
557 init_waitqueue_head(&priv->main_thread.wait_q);
558 priv->main_thread.task = kthread_run(btmrvl_service_main_thread,
559 &priv->main_thread, "btmrvl_main_service");
560
561 priv->btmrvl_dev.hcidev = hdev; 538 priv->btmrvl_dev.hcidev = hdev;
562 priv->btmrvl_dev.card = card;
563
564 hdev->driver_data = priv; 539 hdev->driver_data = priv;
565 540
566 priv->btmrvl_dev.tx_dnld_rdy = true;
567
568 hdev->bus = HCI_SDIO; 541 hdev->bus = HCI_SDIO;
569 hdev->open = btmrvl_open; 542 hdev->open = btmrvl_open;
570 hdev->close = btmrvl_close; 543 hdev->close = btmrvl_close;
@@ -574,6 +547,8 @@ struct btmrvl_private *btmrvl_add_card(void *card)
574 hdev->ioctl = btmrvl_ioctl; 547 hdev->ioctl = btmrvl_ioctl;
575 hdev->owner = THIS_MODULE; 548 hdev->owner = THIS_MODULE;
576 549
550 btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ);
551
577 ret = hci_register_dev(hdev); 552 ret = hci_register_dev(hdev);
578 if (ret < 0) { 553 if (ret < 0) {
579 BT_ERR("Can not register HCI device"); 554 BT_ERR("Can not register HCI device");
@@ -584,16 +559,52 @@ struct btmrvl_private *btmrvl_add_card(void *card)
584 btmrvl_debugfs_init(hdev); 559 btmrvl_debugfs_init(hdev);
585#endif 560#endif
586 561
587 return priv; 562 return 0;
588 563
589err_hci_register_dev: 564err_hci_register_dev:
590 /* Stop the thread servicing the interrupts */
591 kthread_stop(priv->main_thread.task);
592
593 hci_free_dev(hdev); 565 hci_free_dev(hdev);
594 566
595err_hdev: 567err_hdev:
568 /* Stop the thread servicing the interrupts */
569 kthread_stop(priv->main_thread.task);
570
596 btmrvl_free_adapter(priv); 571 btmrvl_free_adapter(priv);
572 kfree(priv);
573
574 return -ENOMEM;
575}
576EXPORT_SYMBOL_GPL(btmrvl_register_hdev);
577
578struct btmrvl_private *btmrvl_add_card(void *card)
579{
580 struct btmrvl_private *priv;
581
582 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
583 if (!priv) {
584 BT_ERR("Can not allocate priv");
585 goto err_priv;
586 }
587
588 priv->adapter = kzalloc(sizeof(*priv->adapter), GFP_KERNEL);
589 if (!priv->adapter) {
590 BT_ERR("Allocate buffer for btmrvl_adapter failed!");
591 goto err_adapter;
592 }
593
594 btmrvl_init_adapter(priv);
595
596 BT_DBG("Starting kthread...");
597 priv->main_thread.priv = priv;
598 spin_lock_init(&priv->driver_lock);
599
600 init_waitqueue_head(&priv->main_thread.wait_q);
601 priv->main_thread.task = kthread_run(btmrvl_service_main_thread,
602 &priv->main_thread, "btmrvl_main_service");
603
604 priv->btmrvl_dev.card = card;
605 priv->btmrvl_dev.tx_dnld_rdy = true;
606
607 return priv;
597 608
598err_adapter: 609err_adapter:
599 kfree(priv); 610 kfree(priv);
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index 0dba76aa2232..df0773ebd9e4 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -931,7 +931,12 @@ static int btmrvl_sdio_probe(struct sdio_func *func,
931 priv->hw_host_to_card = btmrvl_sdio_host_to_card; 931 priv->hw_host_to_card = btmrvl_sdio_host_to_card;
932 priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw; 932 priv->hw_wakeup_firmware = btmrvl_sdio_wakeup_fw;
933 933
934 btmrvl_send_module_cfg_cmd(priv, MODULE_BRINGUP_REQ); 934 if (btmrvl_register_hdev(priv)) {
935 BT_ERR("Register hdev failed!");
936 ret = -ENODEV;
937 goto disable_host_int;
938 }
939
935 priv->btmrvl_dev.psmode = 1; 940 priv->btmrvl_dev.psmode = 1;
936 btmrvl_enable_ps(priv); 941 btmrvl_enable_ps(priv);
937 942