btfm_codec.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __LINUX_BTFM_CODEC_H
  6. #define __LINUX_BTFM_CODEC_H
  7. #include <linux/kernel.h>
  8. #include <linux/bitops.h>
  9. #include <linux/printk.h>
  10. #include <linux/cdev.h>
  11. #include <linux/skbuff.h>
  12. #include "btfm_codec_hw_interface.h"
  13. #define BTM_BTFMCODEC_DEFAULT_LOG_LVL 0x03
  14. #define BTM_BTFMCODEC_DEBUG_LOG_LVL 0x04
  15. #define BTM_BTFMCODEC_INFO_LOG_LVL 0x08
  16. static uint8_t log_lvl = BTM_BTFMCODEC_DEFAULT_LOG_LVL;
  17. #define BTFMCODEC_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  18. #define BTFMCODEC_WARN(fmt, arg...) pr_warn("%s: " fmt "\n", __func__, ## arg)
  19. #define BTFMCODEC_DBG(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_DEBUG_LOG_LVL) \
  20. pr_err("%s: " fmt "\n", __func__, ## arg); \
  21. else \
  22. pr_debug("%s: " fmt "\n", __func__, ## arg); \
  23. }
  24. #define BTFMCODEC_INFO(fmt, arg...) { if(log_lvl >= BTM_BTFMCODEC_INFO_LOG_LVL) \
  25. pr_err("%s: " fmt "\n", __func__, ## arg);\
  26. else \
  27. pr_info("%s: " fmt "\n", __func__, ## arg);\
  28. }
  29. #define DEVICE_NAME_MAX_LEN 64
  30. typedef enum btfmcodec_states {
  31. /*Default state of kernel proxy driver */
  32. IDLE = 0,
  33. /* Waiting for BT bearer indication after configuring HW ports */
  34. BT_Connecting = 1,
  35. /* When BT is active transport */
  36. BT_Connected = 2,
  37. /* Waiting for BTADV Audio bearer switch indications */
  38. BTADV_AUDIO_Connecting = 3,
  39. /* When BTADV audio is active transport */
  40. BTADV_AUDIO_Connected = 4
  41. } btfmcodec_state;
  42. enum btfm_pkt_type {
  43. BTM_PKT_TYPE_PREPARE_REQ = 0,
  44. BTM_PKT_TYPE_MASTER_CONFIG_RSP,
  45. BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP,
  46. BTM_PKT_TYPE_BEARER_SWITCH_IND,
  47. BTM_PKT_TYPE_HWEP_SHUTDOWN,
  48. BTM_PKT_TYPE_HWEP_CONFIG,
  49. BTM_PKT_TYPE_MAX,
  50. };
  51. char *coverttostring(enum btfmcodec_states);
  52. struct btfmcodec_state_machine {
  53. struct mutex state_machine_lock;
  54. btfmcodec_state prev_state;
  55. btfmcodec_state current_state;
  56. btfmcodec_state next_state;
  57. };
  58. struct btfmcodec_char_device {
  59. struct cdev cdev;
  60. refcount_t active_clients;
  61. struct mutex lock;
  62. int reuse_minor;
  63. char dev_name[DEVICE_NAME_MAX_LEN];
  64. struct workqueue_struct *workqueue;
  65. struct sk_buff_head rxq;
  66. struct work_struct rx_work;
  67. struct work_struct wq_hwep_shutdown;
  68. struct work_struct wq_prepare_bearer;
  69. struct work_struct wq_hwep_configure;
  70. wait_queue_head_t readq;
  71. spinlock_t tx_queue_lock;
  72. struct sk_buff_head txq;
  73. wait_queue_head_t rsp_wait_q[BTM_PKT_TYPE_MAX];
  74. uint8_t status[BTM_PKT_TYPE_MAX];
  75. void *btfmcodec;
  76. };
  77. struct btfmcodec_data {
  78. struct device dev;
  79. struct btfmcodec_state_machine states;
  80. struct btfmcodec_char_device *btfmcodec_dev;
  81. struct hwep_data *hwep_info;
  82. struct list_head config_head;
  83. };
  84. struct btfmcodec_data *btfm_get_btfmcodec(void);
  85. #endif /*__LINUX_BTFM_CODEC_H */