btfm_slim.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef BTFM_SLIM_H
  7. #define BTFM_SLIM_H
  8. #include <linux/slimbus.h>
  9. #define BTFMSLIM_DBG(fmt, arg...) pr_debug("%s: " fmt "\n", __func__, ## arg)
  10. #define BTFMSLIM_INFO(fmt, arg...) pr_info("%s: " fmt "\n", __func__, ## arg)
  11. #define BTFMSLIM_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  12. /* Vendor specific defines
  13. * This should redefines in slimbus slave specific header
  14. */
  15. #define SLIM_SLAVE_COMPATIBLE_STR "btfmslim_slave"
  16. #define SLIM_SLAVE_REG_OFFSET 0x0000
  17. #define SLIM_SLAVE_RXPORT NULL
  18. #define SLIM_SLAVE_TXPORT NULL
  19. #define SLIM_SLAVE_INIT NULL
  20. #define SLIM_SLAVE_PORT_EN NULL
  21. /* Misc defines */
  22. #define SLIM_SLAVE_RW_MAX_TRIES 3
  23. #define SLIM_SLAVE_PRESENT_TIMEOUT 100
  24. #define PGD 1
  25. #define IFD 0
  26. #if IS_ENABLED(CONFIG_BTFM_SLIM)
  27. #define BTFMSLIM_DEV_NAME "btfmslim_slave"
  28. #else
  29. #define BTFMSLIM_DEV_NAME "btfmslim"
  30. #endif
  31. /* Codec driver defines */
  32. enum {
  33. BTFM_FM_SLIM_TX = 0,
  34. BTFM_BT_SCO_SLIM_TX,
  35. BTFM_BT_SCO_A2DP_SLIM_RX,
  36. BTFM_BT_SPLIT_A2DP_SLIM_RX,
  37. BTFM_SLIM_NUM_CODEC_DAIS
  38. };
  39. struct btfm_slim_codec_dai_data {
  40. struct slim_stream_config sconfig;
  41. struct slim_stream_runtime *sruntime;
  42. };
  43. struct btfmslim_ch {
  44. int id;
  45. char *name;
  46. uint16_t port; /* slimbus port number */
  47. uint8_t ch; /* slimbus channel number */
  48. struct btfm_slim_codec_dai_data dai;
  49. };
  50. /* Slimbus Port defines - This should be redefined in specific device file */
  51. #define BTFM_SLIM_PGD_PORT_LAST 0xFF
  52. struct btfmslim {
  53. struct device *dev;
  54. struct slim_device *slim_pgd; //Physical address
  55. struct slim_device slim_ifd; //Interface address
  56. struct mutex io_lock;
  57. struct mutex xfer_lock;
  58. uint8_t enabled;
  59. uint32_t num_rx_port;
  60. uint32_t num_tx_port;
  61. uint32_t sample_rate;
  62. uint32_t bps;
  63. uint16_t direction;
  64. struct btfmslim_ch *rx_chs;
  65. struct btfmslim_ch *tx_chs;
  66. int (*vendor_init)(struct btfmslim *btfmslim);
  67. int (*vendor_port_en)(struct btfmslim *btfmslim, uint8_t port_num,
  68. uint8_t rxport, uint8_t enable);
  69. #if IS_ENABLED(CONFIG_SLIM_BTFM_CODEC)
  70. int device_id;
  71. #endif
  72. };
  73. extern int btfm_feedback_ch_setting;
  74. /**
  75. * btfm_slim_hw_init: Initialize slimbus slave device
  76. * Returns:
  77. * 0: Success
  78. * else: Fail
  79. */
  80. int btfm_slim_hw_init(struct btfmslim *btfmslim);
  81. /**
  82. * btfm_slim_hw_deinit: Deinitialize slimbus slave device
  83. * Returns:
  84. * 0: Success
  85. * else: Fail
  86. */
  87. int btfm_slim_hw_deinit(struct btfmslim *btfmslim);
  88. /**
  89. * btfm_slim_write: write value to pgd or ifd device
  90. * @btfmslim: slimbus slave device data pointer.
  91. * @reg: slimbus slave register address
  92. * @reg_val: value to write at register address
  93. * @pgd: selection for device: either PGD or IFD
  94. * Returns:
  95. No of bytes written
  96. -1
  97. */
  98. int btfm_slim_write(struct btfmslim *btfmslim,
  99. uint16_t reg, uint8_t reg_val, uint8_t pgd);
  100. /**
  101. * btfm_slim_read: read value from pgd or ifd device
  102. * @btfmslim: slimbus slave device data pointer.
  103. * @reg: slimbus slave register address
  104. * @dest: data pointer to read
  105. * @pgd: selection for device: either PGD or IFD
  106. * Returns:
  107. No of bytes read
  108. -1
  109. */
  110. int btfm_slim_read(struct btfmslim *btfmslim,
  111. uint32_t reg, uint8_t pgd);
  112. /**
  113. * btfm_slim_enable_ch: enable channel for slimbus slave port
  114. * @btfmslim: slimbus slave device data pointer.
  115. * @ch: slimbus slave channel pointer
  116. * @rxport: rxport or txport
  117. * Returns:
  118. * -EINVAL
  119. * -ETIMEDOUT
  120. * -ENOMEM
  121. */
  122. int btfm_slim_enable_ch(struct btfmslim *btfmslim,
  123. struct btfmslim_ch *ch, uint8_t rxport, uint32_t rates,
  124. uint8_t nchan);
  125. /**
  126. * btfm_slim_disable_ch: disable channel for slimbus slave port
  127. * @btfmslim: slimbus slave device data pointer.
  128. * @ch: slimbus slave channel pointer
  129. * @rxport: rxport or txport
  130. * @nChan: number of chaneels.
  131. * Returns:
  132. * -EINVAL
  133. * -ETIMEDOUT
  134. * -ENOMEM
  135. */
  136. int btfm_slim_disable_ch(struct btfmslim *btfmslim,
  137. struct btfmslim_ch *ch, uint8_t rxport, uint8_t nchan);
  138. /**
  139. * btfm_slim_register_codec: Register codec driver in slimbus device node
  140. * @btfmslim: slimbus slave device data pointer.
  141. * Returns:
  142. * -ENOMEM
  143. * 0
  144. */
  145. int btfm_slim_register_codec(struct btfmslim *btfmslim);
  146. /**
  147. * btfm_slim_unregister_codec: Unregister codec driver in slimbus device node
  148. * @dev: device node
  149. * Returns:
  150. * VOID
  151. */
  152. void btfm_slim_unregister_codec(struct device *dev);
  153. #endif /* BTFM_SLIM_H */