Advertisement
neochapay

Untitled

Oct 21st, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.80 KB | None | 0 0
  1. /*
  2.  *  HCI_SMD (HCI Shared Memory Driver) is Qualcomm's Shared memory driver
  3.  *  for the BT HCI protocol.
  4.  *
  5.  *  Copyright (c) 2000-2001, 2011-2012 The Linux Foundation. All rights reserved.
  6.  *  Copyright (C) 2002-2003  Maxim Krasnyansky <maxk@qualcomm.com>
  7.  *  Copyright (C) 2004-2006  Marcel Holtmann <marcel@holtmann.org>
  8.  *
  9.  *  This file is based on drivers/bluetooth/hci_vhci.c
  10.  *
  11.  *  This program is free software; you can redistribute it and/or modify
  12.  *  it under the terms of the GNU General Public License version 2
  13.  *  as published by the Free Software Foundation
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  */
  20.  
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/errno.h>
  25. #include <linux/semaphore.h>
  26. #include <linux/string.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/wakelock.h>
  29. #include <linux/workqueue.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/interrupt.h>
  32. #include <net/bluetooth/bluetooth.h>
  33. #include <net/bluetooth/hci_core.h>
  34. #include <net/bluetooth/hci.h>
  35. #include <soc/qcom/smd.h>
  36.  
  37. #define EVENT_CHANNEL       "APPS_RIVA_BT_CMD"
  38. #define DATA_CHANNEL        "APPS_RIVA_BT_ACL"
  39. /* release wakelock in 500ms, not immediately, because higher layers
  40.  * don't always take wakelocks when they should
  41.  * This is derived from the implementation for UART transport
  42.  */
  43.  
  44. #define RX_Q_MONITOR        (500)   /* 500 milli second */
  45. #define HCI_REGISTER_SET    0
  46.  
  47. /* SSR state machine to take care of back to back SSR requests
  48.  * and handling the incomming BT on/off,Airplane mode toggling and
  49.  * also spuriour SMD open notification while one SSr is in progress
  50.  */
  51. #define STATE_SSR_ON 0x1
  52. #define STATE_SSR_START 0x02
  53. #define STATE_SSR_CHANNEL_OPEN_PENDING 0x04
  54. #define STATE_SSR_PENDING_INIT  0x08
  55. #define STATE_SSR_COMPLETE 0x00
  56. #define STATE_SSR_OFF STATE_SSR_COMPLETE
  57.  
  58. static int ssr_state = STATE_SSR_OFF;
  59.  
  60.  
  61. static int hcismd_set;
  62. static DEFINE_SEMAPHORE(hci_smd_enable);
  63.  
  64. static int restart_in_progress;
  65.  
  66. static int hcismd_set_enable(const char *val, struct kernel_param *kp);
  67. module_param_call(hcismd_set, hcismd_set_enable, NULL, &hcismd_set, 0644);
  68.  
  69. static void hci_dev_smd_open(struct work_struct *worker);
  70. static void hci_dev_restart(struct work_struct *worker);
  71.  
  72. struct hci_smd_data {
  73.     struct hci_dev *hdev;
  74.     unsigned long flags;
  75.     struct smd_channel *event_channel;
  76.     struct smd_channel *data_channel;
  77.     struct wake_lock wake_lock_tx;
  78.     struct wake_lock wake_lock_rx;
  79.     struct timer_list rx_q_timer;
  80.     struct tasklet_struct rx_task;
  81. };
  82. static struct hci_smd_data hs;
  83.  
  84. /* Rx queue monitor timer function */
  85. static int is_rx_q_empty(unsigned long arg)
  86. {
  87.     struct hci_dev *hdev = (struct hci_dev *) arg;
  88.     struct sk_buff_head *list_ = &hdev->rx_q;
  89.     struct sk_buff *list = ((struct sk_buff *)list_)->next;
  90.     BT_DBG("%s Rx timer triggered", hdev->name);
  91.  
  92.     if (list == (struct sk_buff *)list_) {
  93.         BT_DBG("%s RX queue empty", hdev->name);
  94.         return 1;
  95.     } else{
  96.         BT_DBG("%s RX queue not empty", hdev->name);
  97.         return 0;
  98.     }
  99. }
  100.  
  101. static void release_lock(void)
  102. {
  103.     struct hci_smd_data *hsmd = &hs;
  104.     BT_DBG("Releasing Rx Lock");
  105.     if (is_rx_q_empty((unsigned long)hsmd->hdev) &&
  106.         wake_lock_active(&hs.wake_lock_rx))
  107.             wake_unlock(&hs.wake_lock_rx);
  108. }
  109.  
  110. /* Rx timer callback function */
  111. static void schedule_timer(unsigned long arg)
  112. {
  113.     struct hci_dev *hdev = (struct hci_dev *) arg;
  114.     struct hci_smd_data *hsmd = &hs;
  115.     BT_DBG("%s Schedule Rx timer", hdev->name);
  116.  
  117.     if (is_rx_q_empty(arg) && wake_lock_active(&hs.wake_lock_rx)) {
  118.         BT_DBG("%s RX queue empty", hdev->name);
  119.         /*
  120.          * Since the queue is empty, its ideal
  121.          * to release the wake lock on Rx
  122.          */
  123.         wake_unlock(&hs.wake_lock_rx);
  124.     } else{
  125.         BT_DBG("%s RX queue not empty", hdev->name);
  126.         /*
  127.          * Restart the timer to monitor whether the Rx queue is
  128.          * empty for releasing the Rx wake lock
  129.          */
  130.         mod_timer(&hsmd->rx_q_timer,
  131.             jiffies + msecs_to_jiffies(RX_Q_MONITOR));
  132.     }
  133. }
  134.  
  135. static int hci_smd_open(struct hci_dev *hdev)
  136. {
  137.     set_bit(HCI_RUNNING, &hdev->flags);
  138.     return 0;
  139. }
  140.  
  141.  
  142. static int hci_smd_close(struct hci_dev *hdev)
  143. {
  144.     if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
  145.         return 0;
  146.     else
  147.         return -EPERM;
  148. }
  149.  
  150.  
  151. static void hci_smd_destruct(struct hci_dev *hdev)
  152. {
  153.     if (NULL != hdev->driver_data)
  154.         kfree(hdev->driver_data);
  155. }
  156.  
  157. static void hci_smd_recv_data(void)
  158. {
  159.     int len = 0;
  160.     int rc = 0;
  161.     struct sk_buff *skb = NULL;
  162.     struct hci_smd_data *hsmd = &hs;
  163.     wake_lock(&hs.wake_lock_rx);
  164.  
  165.     len = smd_read_avail(hsmd->data_channel);
  166.     if (len > HCI_MAX_FRAME_SIZE) {
  167.         BT_ERR("Frame larger than the allowed size, flushing frame");
  168.         smd_read(hsmd->data_channel, NULL, len);
  169.         goto out_data;
  170.     }
  171.  
  172.     if (len <= 0)
  173.         goto out_data;
  174.  
  175.     skb = bt_skb_alloc(len, GFP_ATOMIC);
  176.     if (!skb) {
  177.         BT_ERR("Error in allocating socket buffer");
  178.         smd_read(hsmd->data_channel, NULL, len);
  179.         goto out_data;
  180.     }
  181.  
  182.     rc = smd_read(hsmd->data_channel, skb_put(skb, len), len);
  183.     if (rc < len) {
  184.         BT_ERR("Error in reading from the channel");
  185.         goto out_data;
  186.     }
  187.  
  188.     skb->dev = (void *)hsmd->hdev;
  189.     bt_cb(skb)->pkt_type = HCI_ACLDATA_PKT;
  190.     skb_orphan(skb);
  191.  
  192.     rc = hci_recv_frame(skb);
  193.     if (rc < 0) {
  194.         BT_ERR("Error in passing the packet to HCI Layer");
  195.         /*
  196.          * skb is getting freed in hci_recv_frame, making it
  197.          * to null to avoid multiple access
  198.          */
  199.         skb = NULL;
  200.         goto out_data;
  201.     }
  202.  
  203.     /*
  204.      * Start the timer to monitor whether the Rx queue is
  205.      * empty for releasing the Rx wake lock
  206.      */
  207.     BT_DBG("Rx Timer is starting");
  208.     mod_timer(&hsmd->rx_q_timer,
  209.             jiffies + msecs_to_jiffies(RX_Q_MONITOR));
  210.  
  211. out_data:
  212.     release_lock();
  213.     if (rc)
  214.         kfree_skb(skb);
  215. }
  216.  
  217. static void hci_smd_recv_event(void)
  218. {
  219.     int len = 0;
  220.     int rc = 0;
  221.     struct sk_buff *skb = NULL;
  222.     struct hci_smd_data *hsmd = &hs;
  223.     wake_lock(&hs.wake_lock_rx);
  224.  
  225.     len = smd_read_avail(hsmd->event_channel);
  226.     if (len > HCI_MAX_FRAME_SIZE) {
  227.         BT_ERR("Frame larger than the allowed size, flushing frame");
  228.         rc = smd_read(hsmd->event_channel, NULL, len);
  229.         goto out_event;
  230.     }
  231.  
  232.     while (len > 0) {
  233.         skb = bt_skb_alloc(len, GFP_ATOMIC);
  234.         if (!skb) {
  235.             BT_ERR("Error in allocating socket buffer");
  236.             smd_read(hsmd->event_channel, NULL, len);
  237.             goto out_event;
  238.         }
  239.  
  240.         rc = smd_read(hsmd->event_channel, skb_put(skb, len), len);
  241.         if (rc < len) {
  242.             BT_ERR("Error in reading from the event channel");
  243.             goto out_event;
  244.         }
  245.  
  246.         skb->dev = (void *)hsmd->hdev;
  247.         bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
  248.  
  249.         skb_orphan(skb);
  250.  
  251.         rc = hci_recv_frame(skb);
  252.         if (rc < 0) {
  253.             BT_ERR("Error in passing the packet to HCI Layer");
  254.             /*
  255.              * skb is getting freed in hci_recv_frame, making it
  256.              *  to null to avoid multiple access
  257.              */
  258.             skb = NULL;
  259.             goto out_event;
  260.         }
  261.  
  262.         len = smd_read_avail(hsmd->event_channel);
  263.         /*
  264.          * Start the timer to monitor whether the Rx queue is
  265.          * empty for releasing the Rx wake lock
  266.          */
  267.         BT_DBG("Rx Timer is starting");
  268.         mod_timer(&hsmd->rx_q_timer,
  269.                 jiffies + msecs_to_jiffies(RX_Q_MONITOR));
  270.     }
  271. out_event:
  272.     release_lock();
  273.     if (rc)
  274.         kfree_skb(skb);
  275. }
  276.  
  277. static int hci_smd_send_frame(struct sk_buff *skb)
  278. {
  279.     int len;
  280.     int avail;
  281.     int ret = 0;
  282.     wake_lock(&hs.wake_lock_tx);
  283.  
  284.     switch (bt_cb(skb)->pkt_type) {
  285.     case HCI_COMMAND_PKT:
  286.         avail = smd_write_avail(hs.event_channel);
  287.         if (!avail) {
  288.             BT_ERR("No space available for smd frame");
  289.             ret =  -ENOSPC;
  290.         }
  291.         len = smd_write(hs.event_channel, skb->data, skb->len);
  292.         if (len < skb->len) {
  293.             BT_ERR("Failed to write Command %d", len);
  294.             ret = -ENODEV;
  295.         }
  296.         break;
  297.     case HCI_ACLDATA_PKT:
  298.     case HCI_SCODATA_PKT:
  299.         avail = smd_write_avail(hs.data_channel);
  300.         if (!avail) {
  301.             BT_ERR("No space available for smd frame");
  302.             ret = -ENOSPC;
  303.         }
  304.         len = smd_write(hs.data_channel, skb->data, skb->len);
  305.         if (len < skb->len) {
  306.             BT_ERR("Failed to write Data %d", len);
  307.             ret = -ENODEV;
  308.         }
  309.         break;
  310.     default:
  311.         BT_ERR("Uknown packet type");
  312.         ret = -ENODEV;
  313.         break;
  314.     }
  315.  
  316.     kfree_skb(skb);
  317.     wake_unlock(&hs.wake_lock_tx);
  318.     return ret;
  319. }
  320.  
  321. static void hci_smd_rx(unsigned long arg)
  322. {
  323.     struct hci_smd_data *hsmd = &hs;
  324.  
  325.     while ((smd_read_avail(hsmd->event_channel) > 0) ||
  326.                 (smd_read_avail(hsmd->data_channel) > 0)) {
  327.         hci_smd_recv_event();
  328.         hci_smd_recv_data();
  329.     }
  330. }
  331.  
  332. static void hci_smd_notify_event(void *data, unsigned int event)
  333. {
  334.     struct hci_dev *hdev = hs.hdev;
  335.     struct hci_smd_data *hsmd = &hs;
  336.     struct work_struct *reset_worker;
  337.     struct work_struct *open_worker;
  338.  
  339.     int len = 0;
  340.  
  341.     if (!hdev) {
  342.         BT_ERR("Frame for unknown HCI device (hdev=NULL)");
  343.         return;
  344.     }
  345.  
  346.     switch (event) {
  347.     case SMD_EVENT_DATA:
  348.         len = smd_read_avail(hsmd->event_channel);
  349.         if (len > 0)
  350.             tasklet_hi_schedule(&hs.rx_task);
  351.         else if (len < 0)
  352.             BT_ERR("Failed to read event from smd %d", len);
  353.  
  354.         break;
  355.     case SMD_EVENT_OPEN:
  356.         BT_INFO("opening HCI-SMD channel :%s", EVENT_CHANNEL);
  357.         BT_DBG("SSR state is : %x", ssr_state);
  358.         if ((ssr_state == STATE_SSR_OFF) ||
  359.             (ssr_state == STATE_SSR_CHANNEL_OPEN_PENDING)) {
  360.  
  361.             hci_smd_open(hdev);
  362.             open_worker = kzalloc(sizeof(*open_worker), GFP_ATOMIC);
  363.             if (!open_worker) {
  364.                 BT_ERR("Out of memory");
  365.                 break;
  366.             }
  367.             if (ssr_state == STATE_SSR_CHANNEL_OPEN_PENDING) {
  368.                 ssr_state = STATE_SSR_PENDING_INIT;
  369.                 BT_INFO("SSR state is : %x", ssr_state);
  370.             }
  371.             INIT_WORK(open_worker, hci_dev_smd_open);
  372.             schedule_work(open_worker);
  373.  
  374.         }
  375.         break;
  376.     case SMD_EVENT_CLOSE:
  377.         BT_INFO("Closing HCI-SMD channel :%s", EVENT_CHANNEL);
  378.         BT_DBG("SSR state is : %x", ssr_state);
  379.         if ((ssr_state == STATE_SSR_OFF) ||
  380.             (ssr_state == (STATE_SSR_PENDING_INIT))) {
  381.  
  382.             hci_smd_close(hdev);
  383.             reset_worker = kzalloc(sizeof(*reset_worker),
  384.                             GFP_ATOMIC);
  385.             if (!reset_worker) {
  386.                 BT_ERR("Out of memory");
  387.                 break;
  388.             }
  389.             ssr_state = STATE_SSR_ON;
  390.             BT_INFO("SSR state is : %x", ssr_state);
  391.             INIT_WORK(reset_worker, hci_dev_restart);
  392.             schedule_work(reset_worker);
  393.  
  394.         } else if (ssr_state & STATE_SSR_ON) {
  395.                 BT_ERR("SSR state is : %x", ssr_state);
  396.         }
  397.  
  398.         break;
  399.     default:
  400.         break;
  401.     }
  402. }
  403.  
  404. static void hci_smd_notify_data(void *data, unsigned int event)
  405. {
  406.     struct hci_dev *hdev = hs.hdev;
  407.     struct hci_smd_data *hsmd = &hs;
  408.     int len = 0;
  409.  
  410.     if (!hdev) {
  411.         BT_ERR("Frame for unknown HCI device (hdev=NULL)");
  412.         return;
  413.     }
  414.  
  415.     switch (event) {
  416.     case SMD_EVENT_DATA:
  417.         len = smd_read_avail(hsmd->data_channel);
  418.         if (len > 0)
  419.             tasklet_hi_schedule(&hs.rx_task);
  420.         else if (len < 0)
  421.             BT_ERR("Failed to read data from smd %d", len);
  422.         break;
  423.     case SMD_EVENT_OPEN:
  424.         BT_INFO("opening HCI-SMD channel :%s", DATA_CHANNEL);
  425.         hci_smd_open(hdev);
  426.         break;
  427.     case SMD_EVENT_CLOSE:
  428.         BT_INFO("Closing HCI-SMD channel :%s", DATA_CHANNEL);
  429.         hci_smd_close(hdev);
  430.         break;
  431.     default:
  432.         break;
  433.     }
  434.  
  435. }
  436.  
  437. static int hci_smd_hci_register_dev(struct hci_smd_data *hsmd)
  438. {
  439.     struct hci_dev *hdev;
  440.  
  441.     if (hsmd->hdev)
  442.         hdev = hsmd->hdev;
  443.     else {
  444.         BT_ERR("hdev is NULL");
  445.         return 0;
  446.     }
  447.     /* Allow the incomming SSR even the prev one at PENDING INIT STATE
  448.      * since clenup need to be started again from the beging and ignore
  449.      *  or bypass the prev one
  450.      */
  451.     if ((ssr_state == STATE_SSR_OFF) ||
  452.             (ssr_state == STATE_SSR_PENDING_INIT)) {
  453.  
  454.         if (test_and_set_bit(HCI_REGISTER_SET, &hsmd->flags)) {
  455.             BT_ERR("HCI device registered already");
  456.             return 0;
  457.         } else
  458.             BT_INFO("HCI device registration is starting");
  459.         if (hci_register_dev(hdev) < 0) {
  460.             BT_ERR("Can't register HCI device");
  461.             hci_free_dev(hdev);
  462.             hsmd->hdev = NULL;
  463.             clear_bit(HCI_REGISTER_SET, &hsmd->flags);
  464.             return -ENODEV;
  465.         }
  466.         if (ssr_state == STATE_SSR_PENDING_INIT) {
  467.             ssr_state = STATE_SSR_COMPLETE;
  468.             BT_INFO("SSR state is : %x", ssr_state);
  469.         }
  470.     } else if (ssr_state)
  471.         BT_ERR("Registration called in invalid context");
  472.     return 0;
  473. }
  474.  
  475. static int hci_smd_register_smd(struct hci_smd_data *hsmd)
  476. {
  477.     struct hci_dev *hdev;
  478.     int rc;
  479.  
  480.     /* Initialize and register HCI device */
  481.     hdev = hci_alloc_dev();
  482.     if (!hdev) {
  483.         BT_ERR("Can't allocate HCI device");
  484.         return -ENOMEM;
  485.     }
  486.  
  487.     hsmd->hdev = hdev;
  488.     hdev->bus = HCI_SMD;
  489.     hdev->driver_data = NULL;
  490.     hdev->open  = hci_smd_open;
  491.     hdev->close = hci_smd_close;
  492.     hdev->send  = hci_smd_send_frame;
  493.     hdev->destruct = hci_smd_destruct;
  494.     hdev->owner = THIS_MODULE;
  495.  
  496.  
  497.     tasklet_init(&hsmd->rx_task,
  498.             hci_smd_rx, (unsigned long) hsmd);
  499.     /*
  500.      * Setup the timer to monitor whether the Rx queue is empty,
  501.      * to control the wake lock release
  502.      */
  503.     setup_timer(&hsmd->rx_q_timer, schedule_timer,
  504.             (unsigned long) hsmd->hdev);
  505.     if (ssr_state == STATE_SSR_START) {
  506.         ssr_state = STATE_SSR_CHANNEL_OPEN_PENDING;
  507.         BT_INFO("SSR state is : %x", ssr_state);
  508.     }
  509.     /* Open the SMD Channel and device and register the callback function */
  510.     rc = smd_named_open_on_edge(EVENT_CHANNEL, SMD_APPS_WCNSS,
  511.             &hsmd->event_channel, hdev, hci_smd_notify_event);
  512.     if (rc < 0) {
  513.         BT_ERR("Cannot open the command channel");
  514.         hci_free_dev(hdev);
  515.         hsmd->hdev = NULL;
  516.         return -ENODEV;
  517.     }
  518.  
  519.     rc = smd_named_open_on_edge(DATA_CHANNEL, SMD_APPS_WCNSS,
  520.             &hsmd->data_channel, hdev, hci_smd_notify_data);
  521.     if (rc < 0) {
  522.         BT_ERR("Failed to open the Data channel");
  523.         hci_free_dev(hdev);
  524.         hsmd->hdev = NULL;
  525.         return -ENODEV;
  526.     }
  527.  
  528.     /* Disable the read interrupts on the channel */
  529.     smd_disable_read_intr(hsmd->event_channel);
  530.     smd_disable_read_intr(hsmd->data_channel);
  531.     return 0;
  532. }
  533.  
  534. static void hci_smd_deregister_dev(struct hci_smd_data *hsmd)
  535. {
  536.     tasklet_kill(&hs.rx_task);
  537.     if (ssr_state)
  538.         BT_DBG("SSR state is : %x", ssr_state);
  539.     /* Though the hci_smd driver is not registered with the hci
  540.      * need to close the opened channels as a part of cleaup
  541.      */
  542.     if (!test_and_clear_bit(HCI_REGISTER_SET, &hsmd->flags)) {
  543.         BT_ERR("HCI device un-registered already");
  544.     } else {
  545.         BT_INFO("HCI device un-registration going on");
  546.  
  547.         if (hsmd->hdev) {
  548.             hci_unregister_dev(hsmd->hdev) ;
  549.             hci_free_dev(hsmd->hdev);
  550.             hsmd->hdev = NULL;
  551.         }
  552.     }
  553.     smd_close(hs.event_channel);
  554.     smd_close(hs.data_channel);
  555.  
  556.     if (wake_lock_active(&hs.wake_lock_rx))
  557.         wake_unlock(&hs.wake_lock_rx);
  558.     if (wake_lock_active(&hs.wake_lock_tx))
  559.         wake_unlock(&hs.wake_lock_tx);
  560.  
  561.     /*Destroy the timer used to monitor the Rx queue for emptiness */
  562.     if (hs.rx_q_timer.function) {
  563.         del_timer_sync(&hs.rx_q_timer);
  564.         hs.rx_q_timer.function = NULL;
  565.         hs.rx_q_timer.data = 0;
  566.     }
  567. }
  568.  
  569. static void hci_dev_restart(struct work_struct *worker)
  570. {
  571.     down(&hci_smd_enable);
  572.     restart_in_progress = 1;
  573.     BT_DBG("SSR state is : %x", ssr_state);
  574.  
  575.     if (ssr_state == STATE_SSR_ON) {
  576.         ssr_state = STATE_SSR_START;
  577.         BT_INFO("SSR state is : %x", ssr_state);
  578.     } else {
  579.         BT_ERR("restart triggered in wrong context");
  580.         up(&hci_smd_enable);
  581.         kfree(worker);
  582.         return;
  583.     }
  584.     hci_smd_deregister_dev(&hs);
  585.     hci_smd_register_smd(&hs);
  586.     up(&hci_smd_enable);
  587.     kfree(worker);
  588.  
  589. }
  590.  
  591. static void hci_dev_smd_open(struct work_struct *worker)
  592. {
  593.     down(&hci_smd_enable);
  594.     if (ssr_state)
  595.         BT_DBG("SSR state is : %x", ssr_state);
  596.  
  597.     if ((ssr_state != STATE_SSR_OFF) &&
  598.             (ssr_state  !=  (STATE_SSR_PENDING_INIT))) {
  599.         up(&hci_smd_enable);
  600.         kfree(worker);
  601.         return;
  602.     }
  603.  
  604.     if (restart_in_progress == 1) {
  605.         /* Allow wcnss to initialize */
  606.         restart_in_progress = 0;
  607.         msleep(10000);
  608.     }
  609.  
  610.     hci_smd_hci_register_dev(&hs);
  611.     up(&hci_smd_enable);
  612.     kfree(worker);
  613.  
  614. }
  615.  
  616. static int hcismd_set_enable(const char *val, struct kernel_param *kp)
  617. {
  618.     int ret = 0;
  619.  
  620.     pr_err("hcismd_set_enable %d", hcismd_set);
  621.  
  622.     down(&hci_smd_enable);
  623.  
  624.     ret = param_set_int(val, kp);
  625.  
  626.     if (ret)
  627.         goto done;
  628.  
  629.     /* Ignore the all incomming register de-register requests in case of
  630.      * SSR is in-progress
  631.      */
  632.     switch (hcismd_set) {
  633.  
  634.     case 1:
  635.         if ((hs.hdev == NULL) && (ssr_state == STATE_SSR_OFF))
  636.             hci_smd_register_smd(&hs);
  637.         else if (ssr_state)
  638.             BT_ERR("SSR is in progress,state is : %x", ssr_state);
  639.  
  640.     break;
  641.     case 0:
  642.         if (ssr_state == STATE_SSR_OFF)
  643.             hci_smd_deregister_dev(&hs);
  644.         else if (ssr_state)
  645.             BT_ERR("SSR is in progress,state is : %x", ssr_state);
  646.     break;
  647.     default:
  648.         ret = -EFAULT;
  649.     }
  650.  
  651. done:
  652.     up(&hci_smd_enable);
  653.     return ret;
  654. }
  655. static int  __init hci_smd_init(void)
  656. {
  657.     wake_lock_init(&hs.wake_lock_rx, WAKE_LOCK_SUSPEND,
  658.              "msm_smd_Rx");
  659.     wake_lock_init(&hs.wake_lock_tx, WAKE_LOCK_SUSPEND,
  660.              "msm_smd_Tx");
  661.     restart_in_progress = 0;
  662.     ssr_state = STATE_SSR_OFF;
  663.     hs.hdev = NULL;
  664.     return 0;
  665. }
  666. module_init(hci_smd_init);
  667.  
  668. static void __exit hci_smd_exit(void)
  669. {
  670.     wake_lock_destroy(&hs.wake_lock_rx);
  671.     wake_lock_destroy(&hs.wake_lock_tx);
  672. }
  673. module_exit(hci_smd_exit);
  674.  
  675. MODULE_AUTHOR("Ankur Nandwani <ankurn@codeaurora.org>");
  676. MODULE_DESCRIPTION("Bluetooth SMD driver");
  677. MODULE_LICENSE("GPL v2");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement