btfm_codec.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #define BTM_CP_UPDATE 0xbfaf
  31. typedef enum btfmcodec_states {
  32. /*Default state of kernel proxy driver */
  33. IDLE = 0,
  34. /* Waiting for BT bearer indication after configuring HW ports */
  35. BT_Connecting = 1,
  36. /* When BT is active transport */
  37. BT_Connected = 2,
  38. /* Waiting for BTADV Audio bearer switch indications */
  39. BTADV_AUDIO_Connecting = 3,
  40. /* When BTADV audio is active transport */
  41. BTADV_AUDIO_Connected = 4
  42. } btfmcodec_state;
  43. enum btfm_pkt_type {
  44. BTM_PKT_TYPE_PREPARE_REQ = 0,
  45. BTM_PKT_TYPE_MASTER_CONFIG_RSP,
  46. BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP,
  47. BTM_PKT_TYPE_BEARER_SWITCH_IND,
  48. BTM_PKT_TYPE_HWEP_SHUTDOWN,
  49. BTM_PKT_TYPE_HWEP_CONFIG,
  50. BTM_PKT_TYPE_DMA_CONFIG_RSP,
  51. BTM_PKT_TYPE_MAX,
  52. };
  53. char *coverttostring(enum btfmcodec_states);
  54. struct btfmcodec_state_machine {
  55. struct mutex state_machine_lock;
  56. btfmcodec_state prev_state;
  57. btfmcodec_state current_state;
  58. btfmcodec_state next_state;
  59. };
  60. struct btfmcodec_char_device {
  61. struct cdev cdev;
  62. refcount_t active_clients;
  63. struct mutex lock;
  64. int reuse_minor;
  65. char dev_name[DEVICE_NAME_MAX_LEN];
  66. struct workqueue_struct *workqueue;
  67. struct sk_buff_head rxq;
  68. struct work_struct rx_work;
  69. struct work_struct wq_hwep_shutdown;
  70. struct work_struct wq_prepare_bearer;
  71. struct work_struct wq_hwep_configure;
  72. wait_queue_head_t readq;
  73. spinlock_t tx_queue_lock;
  74. struct sk_buff_head txq;
  75. wait_queue_head_t rsp_wait_q[BTM_PKT_TYPE_MAX];
  76. uint8_t status[BTM_PKT_TYPE_MAX];
  77. void *btfmcodec;
  78. };
  79. struct adsp_notifier {
  80. void *notifier;
  81. struct notifier_block nb;
  82. };
  83. struct btfmcodec_data {
  84. struct device dev;
  85. struct btfmcodec_state_machine states;
  86. struct btfmcodec_char_device *btfmcodec_dev;
  87. struct hwep_data *hwep_info;
  88. struct list_head config_head;
  89. struct adsp_notifier notifier;
  90. struct mutex hwep_drv_lock;
  91. };
  92. struct btfmcodec_data *btfm_get_btfmcodec(void);
  93. bool isCpSupported(void);
  94. #endif /*__LINUX_BTFM_CODEC_H */