btmrvl_drv.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Marvell Bluetooth driver: global definitions & declarations
  4. *
  5. * Copyright (C) 2009, Marvell International Ltd.
  6. */
  7. #include <linux/kthread.h>
  8. #include <linux/bitops.h>
  9. #include <linux/slab.h>
  10. #include <net/bluetooth/bluetooth.h>
  11. #include <linux/err.h>
  12. #include <linux/gfp.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm_runtime.h>
  18. #include <linux/of_irq.h>
  19. #define BTM_HEADER_LEN 4
  20. #define BTM_UPLD_SIZE 2312
  21. /* Time to wait until Host Sleep state change in millisecond */
  22. #define WAIT_UNTIL_HS_STATE_CHANGED msecs_to_jiffies(5000)
  23. /* Time to wait for command response in millisecond */
  24. #define WAIT_UNTIL_CMD_RESP msecs_to_jiffies(5000)
  25. enum rdwr_status {
  26. RDWR_STATUS_SUCCESS = 0,
  27. RDWR_STATUS_FAILURE = 1,
  28. RDWR_STATUS_DONE = 2
  29. };
  30. #define FW_DUMP_MAX_NAME_LEN 8
  31. #define FW_DUMP_HOST_READY 0xEE
  32. #define FW_DUMP_DONE 0xFF
  33. #define FW_DUMP_READ_DONE 0xFE
  34. struct memory_type_mapping {
  35. u8 mem_name[FW_DUMP_MAX_NAME_LEN];
  36. u8 *mem_ptr;
  37. u32 mem_size;
  38. u8 done_flag;
  39. };
  40. struct btmrvl_thread {
  41. struct task_struct *task;
  42. wait_queue_head_t wait_q;
  43. void *priv;
  44. };
  45. struct btmrvl_device {
  46. void *card;
  47. struct hci_dev *hcidev;
  48. u8 dev_type;
  49. u8 tx_dnld_rdy;
  50. u8 psmode;
  51. u8 pscmd;
  52. u8 hsmode;
  53. u8 hscmd;
  54. /* Low byte is gap, high byte is GPIO */
  55. u16 gpio_gap;
  56. u8 hscfgcmd;
  57. u8 sendcmdflag;
  58. };
  59. struct btmrvl_adapter {
  60. void *hw_regs_buf;
  61. u8 *hw_regs;
  62. u32 int_count;
  63. struct sk_buff_head tx_queue;
  64. u8 psmode;
  65. u8 ps_state;
  66. u8 hs_state;
  67. u8 wakeup_tries;
  68. wait_queue_head_t cmd_wait_q;
  69. wait_queue_head_t event_hs_wait_q;
  70. u8 cmd_complete;
  71. bool is_suspended;
  72. bool is_suspending;
  73. };
  74. struct btmrvl_private {
  75. struct btmrvl_device btmrvl_dev;
  76. struct btmrvl_adapter *adapter;
  77. struct btmrvl_thread main_thread;
  78. int (*hw_host_to_card)(struct btmrvl_private *priv,
  79. u8 *payload, u16 nb);
  80. int (*hw_wakeup_firmware)(struct btmrvl_private *priv);
  81. int (*hw_process_int_status)(struct btmrvl_private *priv);
  82. spinlock_t driver_lock; /* spinlock used by driver */
  83. #ifdef CONFIG_DEBUG_FS
  84. void *debugfs_data;
  85. #endif
  86. bool surprise_removed;
  87. };
  88. #define MRVL_VENDOR_PKT 0xFE
  89. /* Vendor specific Bluetooth commands */
  90. #define BT_CMD_PSCAN_WIN_REPORT_ENABLE 0xFC03
  91. #define BT_CMD_ROUTE_SCO_TO_HOST 0xFC1D
  92. #define BT_CMD_SET_BDADDR 0xFC22
  93. #define BT_CMD_AUTO_SLEEP_MODE 0xFC23
  94. #define BT_CMD_HOST_SLEEP_CONFIG 0xFC59
  95. #define BT_CMD_HOST_SLEEP_ENABLE 0xFC5A
  96. #define BT_CMD_MODULE_CFG_REQ 0xFC5B
  97. #define BT_CMD_LOAD_CONFIG_DATA 0xFC61
  98. /* Sub-commands: Module Bringup/Shutdown Request/Response */
  99. #define MODULE_BRINGUP_REQ 0xF1
  100. #define MODULE_BROUGHT_UP 0x00
  101. #define MODULE_ALREADY_UP 0x0C
  102. #define MODULE_SHUTDOWN_REQ 0xF2
  103. /* Vendor specific Bluetooth events */
  104. #define BT_EVENT_AUTO_SLEEP_MODE 0x23
  105. #define BT_EVENT_HOST_SLEEP_CONFIG 0x59
  106. #define BT_EVENT_HOST_SLEEP_ENABLE 0x5A
  107. #define BT_EVENT_MODULE_CFG_REQ 0x5B
  108. #define BT_EVENT_POWER_STATE 0x20
  109. /* Bluetooth Power States */
  110. #define BT_PS_ENABLE 0x02
  111. #define BT_PS_DISABLE 0x03
  112. #define BT_PS_SLEEP 0x01
  113. /* Host Sleep states */
  114. #define HS_ACTIVATED 0x01
  115. #define HS_DEACTIVATED 0x00
  116. /* Power Save modes */
  117. #define PS_SLEEP 0x01
  118. #define PS_AWAKE 0x00
  119. #define BT_CAL_HDR_LEN 4
  120. #define BT_CAL_DATA_SIZE 28
  121. struct btmrvl_event {
  122. u8 ec; /* event counter */
  123. u8 length;
  124. u8 data[4];
  125. } __packed;
  126. /* Prototype of global function */
  127. int btmrvl_register_hdev(struct btmrvl_private *priv);
  128. struct btmrvl_private *btmrvl_add_card(void *card);
  129. int btmrvl_remove_card(struct btmrvl_private *priv);
  130. void btmrvl_interrupt(struct btmrvl_private *priv);
  131. bool btmrvl_check_evtpkt(struct btmrvl_private *priv, struct sk_buff *skb);
  132. int btmrvl_process_event(struct btmrvl_private *priv, struct sk_buff *skb);
  133. int btmrvl_send_module_cfg_cmd(struct btmrvl_private *priv, u8 subcmd);
  134. int btmrvl_pscan_window_reporting(struct btmrvl_private *priv, u8 subcmd);
  135. int btmrvl_send_hscfg_cmd(struct btmrvl_private *priv);
  136. int btmrvl_enable_ps(struct btmrvl_private *priv);
  137. int btmrvl_prepare_command(struct btmrvl_private *priv);
  138. int btmrvl_enable_hs(struct btmrvl_private *priv);
  139. #ifdef CONFIG_DEBUG_FS
  140. void btmrvl_debugfs_init(struct hci_dev *hdev);
  141. void btmrvl_debugfs_remove(struct hci_dev *hdev);
  142. #endif