aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/bluetooth/btmrvl_main.c
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/btmrvl_main.c
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/btmrvl_main.c')
-rw-r--r--drivers/bluetooth/btmrvl_main.c75
1 files changed, 43 insertions, 32 deletions
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);