btfm_codec.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 BTFMCODEC_DBG(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  14. #define BTFMCODEC_INFO(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  15. #define BTFMCODEC_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  16. #define BTFMCODEC_WARN(fmt, arg...) pr_warn("%s: " fmt "\n", __func__, ## arg)
  17. #define DEVICE_NAME_MAX_LEN 64
  18. typedef enum btfmcodec_states {
  19. /*Default state of kernel proxy driver */
  20. IDLE = 0,
  21. /* Waiting for BT bearer indication after configuring HW ports */
  22. BT_Connecting = 1,
  23. /* When BT is active transport */
  24. BT_Connected = 2,
  25. /* Waiting for BTADV Audio bearer switch indications */
  26. BTADV_AUDIO_Connecting = 3,
  27. /* When BTADV audio is active transport */
  28. BTADV_AUDIO_Connected = 4
  29. } btfmcodec_state;
  30. enum btfm_pkt_type {
  31. BTM_PKT_TYPE_PREPARE_REQ = 0,
  32. BTM_PKT_TYPE_MASTER_CONFIG_RSP,
  33. BTM_PKT_TYPE_MASTER_SHUTDOWN_RSP,
  34. BTM_PKT_TYPE_BEARER_SWITCH_IND,
  35. BTM_PKT_TYPE_HWEP_SHUTDOWN,
  36. BTM_PKT_TYPE_HWEP_CONFIG,
  37. BTM_PKT_TYPE_MAX,
  38. };
  39. char *coverttostring(enum btfmcodec_states);
  40. struct btfmcodec_state_machine {
  41. struct mutex state_machine_lock;
  42. btfmcodec_state prev_state;
  43. btfmcodec_state current_state;
  44. btfmcodec_state next_state;
  45. };
  46. struct btfmcodec_char_device {
  47. struct cdev cdev;
  48. refcount_t active_clients;
  49. struct mutex lock;
  50. int reuse_minor;
  51. char dev_name[DEVICE_NAME_MAX_LEN];
  52. struct workqueue_struct *workqueue;
  53. struct sk_buff_head rxq;
  54. struct work_struct rx_work;
  55. struct work_struct wq_hwep_shutdown;
  56. struct work_struct wq_prepare_bearer;
  57. struct work_struct wq_hwep_configure;
  58. wait_queue_head_t readq;
  59. spinlock_t tx_queue_lock;
  60. struct sk_buff_head txq;
  61. wait_queue_head_t rsp_wait_q[BTM_PKT_TYPE_MAX];
  62. uint8_t status[BTM_PKT_TYPE_MAX];
  63. void *btfmcodec;
  64. };
  65. struct btfmcodec_data {
  66. struct device dev;
  67. struct btfmcodec_state_machine states;
  68. struct btfmcodec_char_device *btfmcodec_dev;
  69. struct hwep_data *hwep_info;
  70. struct list_head config_head;
  71. };
  72. struct btfmcodec_data *btfm_get_btfmcodec(void);
  73. #endif /*__LINUX_BTFM_CODEC_H */