btfm_slim.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef BTFM_SLIM_H
  13. #define BTFM_SLIM_H
  14. #include <linux/slimbus/slimbus.h>
  15. #define BTFMSLIM_DBG(fmt, arg...) pr_debug("%s: " fmt "\n", __func__, ## arg)
  16. #define BTFMSLIM_INFO(fmt, arg...) pr_info("%s: " fmt "\n", __func__, ## arg)
  17. #define BTFMSLIM_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
  18. /* Vendor specific defines
  19. * This should redefines in slimbus slave specific header
  20. */
  21. #define SLIM_SLAVE_COMPATIBLE_STR "btfmslim_slave"
  22. #define SLIM_SLAVE_REG_OFFSET 0x0000
  23. #define SLIM_SLAVE_RXPORT NULL
  24. #define SLIM_SLAVE_TXPORT NULL
  25. #define SLIM_SLAVE_INIT NULL
  26. #define SLIM_SLAVE_PORT_EN NULL
  27. /* Misc defines */
  28. #define SLIM_SLAVE_RW_MAX_TRIES 3
  29. #define SLIM_SLAVE_PRESENT_TIMEOUT 100
  30. #define PGD 1
  31. #define IFD 0
  32. /* Codec driver defines */
  33. enum {
  34. BTFM_FM_SLIM_TX = 0,
  35. BTFM_BT_SCO_SLIM_TX,
  36. BTFM_BT_SCO_A2DP_SLIM_RX,
  37. BTFM_BT_SPLIT_A2DP_SLIM_RX,
  38. BTFM_SLIM_NUM_CODEC_DAIS
  39. };
  40. /* Slimbus Port defines - This should be redefined in specific device file */
  41. #define BTFM_SLIM_PGD_PORT_LAST 0xFF
  42. struct btfmslim_ch {
  43. int id;
  44. char *name;
  45. uint32_t port_hdl; /* slimbus port handler */
  46. uint16_t port; /* slimbus port number */
  47. uint8_t ch; /* slimbus channel number */
  48. uint16_t ch_hdl; /* slimbus channel handler */
  49. uint16_t grph; /* slimbus group channel handler */
  50. };
  51. struct btfmslim {
  52. struct device *dev;
  53. struct slim_device *slim_pgd;
  54. struct slim_device slim_ifd;
  55. struct mutex io_lock;
  56. struct mutex xfer_lock;
  57. uint8_t enabled;
  58. uint32_t num_rx_port;
  59. uint32_t num_tx_port;
  60. uint32_t sample_rate;
  61. struct btfmslim_ch *rx_chs;
  62. struct btfmslim_ch *tx_chs;
  63. int (*vendor_init)(struct btfmslim *btfmslim);
  64. int (*vendor_port_en)(struct btfmslim *btfmslim, uint8_t port_num,
  65. uint8_t rxport, uint8_t enable);
  66. };
  67. extern int btfm_feedback_ch_setting;
  68. /**
  69. * btfm_slim_hw_init: Initialize slimbus slave device
  70. * Returns:
  71. * 0: Success
  72. * else: Fail
  73. */
  74. int btfm_slim_hw_init(struct btfmslim *btfmslim);
  75. /**
  76. * btfm_slim_hw_deinit: Deinitialize slimbus slave device
  77. * Returns:
  78. * 0: Success
  79. * else: Fail
  80. */
  81. int btfm_slim_hw_deinit(struct btfmslim *btfmslim);
  82. /**
  83. * btfm_slim_write: write value to pgd or ifd device
  84. * @btfmslim: slimbus slave device data pointer.
  85. * @reg: slimbus slave register address
  86. * @bytes: length of data
  87. * @src: data pointer to write
  88. * @pgd: selection for device: either PGD or IFD
  89. * Returns:
  90. * -EINVAL
  91. * -ETIMEDOUT
  92. * -ENOMEM
  93. */
  94. int btfm_slim_write(struct btfmslim *btfmslim,
  95. uint16_t reg, int bytes, void *src, uint8_t pgd);
  96. /**
  97. * btfm_slim_read: read value from pgd or ifd device
  98. * @btfmslim: slimbus slave device data pointer.
  99. * @reg: slimbus slave register address
  100. * @bytes: length of data
  101. * @dest: data pointer to read
  102. * @pgd: selection for device: either PGD or IFD
  103. * Returns:
  104. * -EINVAL
  105. * -ETIMEDOUT
  106. * -ENOMEM
  107. */
  108. int btfm_slim_read(struct btfmslim *btfmslim,
  109. uint16_t reg, int bytes, void *dest, uint8_t pgd);
  110. /**
  111. * btfm_slim_enable_ch: enable channel for slimbus slave port
  112. * @btfmslim: slimbus slave device data pointer.
  113. * @ch: slimbus slave channel pointer
  114. * @rxport: rxport or txport
  115. * Returns:
  116. * -EINVAL
  117. * -ETIMEDOUT
  118. * -ENOMEM
  119. */
  120. int btfm_slim_enable_ch(struct btfmslim *btfmslim,
  121. struct btfmslim_ch *ch, uint8_t rxport, uint32_t rates,
  122. uint8_t grp, uint8_t nchan);
  123. /**
  124. * btfm_slim_disable_ch: disable channel for slimbus slave port
  125. * @btfmslim: slimbus slave device data pointer.
  126. * @ch: slimbus slave channel pointer
  127. * @rxport: rxport or txport
  128. * Returns:
  129. * -EINVAL
  130. * -ETIMEDOUT
  131. * -ENOMEM
  132. */
  133. int btfm_slim_disable_ch(struct btfmslim *btfmslim,
  134. struct btfmslim_ch *ch, uint8_t rxport, uint8_t grp, uint8_t nchan);
  135. /**
  136. * btfm_slim_register_codec: Register codec driver in slimbus device node
  137. * @dev: device node
  138. * Returns:
  139. * -ENOMEM
  140. * 0
  141. */
  142. int btfm_slim_register_codec(struct device *dev);
  143. /**
  144. * btfm_slim_unregister_codec: Unregister codec driver in slimbus device node
  145. * @dev: device node
  146. * Returns:
  147. * VOID
  148. */
  149. void btfm_slim_unregister_codec(struct device *dev);
  150. #endif /* BTFM_SLIM_H */