swr-mstr-ctrl.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _SWR_WCD_CTRL_H
  7. #define _SWR_WCD_CTRL_H
  8. #include <linux/module.h>
  9. #include <soc/swr-wcd.h>
  10. #include <linux/pm_qos.h>
  11. #include <linux/pm.h>
  12. #include <soc/swr-common.h>
  13. #ifdef CONFIG_DEBUG_FS
  14. #include <linux/debugfs.h>
  15. #include <linux/uaccess.h>
  16. #define SWR_MSTR_MAX_REG_ADDR 0x60A8
  17. #define SWR_MSTR_START_REG_ADDR 0x00
  18. #define SWR_MSTR_MAX_BUF_LEN 32
  19. #define BYTES_PER_LINE 12
  20. #define SWR_MSTR_RD_BUF_LEN 8
  21. #define SWR_MSTR_WR_BUF_LEN 32
  22. #endif
  23. #define SWR_ROW_48 0
  24. #define SWR_ROW_50 1
  25. #define SWR_ROW_64 3
  26. #define SWR_COL_04 1 /* Cols = 4 */
  27. #define SWR_MAX_COL 7 /* Cols = 16 */
  28. #define SWR_MIN_COL 0 /* Cols = 2 */
  29. #define SWR_NAME "swr-mgr"
  30. #define SWR_MSTR_PORT_LEN 13 /* Number of master ports */
  31. #define SWRM_VERSION_1_0 0x01010000
  32. #define SWRM_VERSION_1_2 0x01030000
  33. #define SWRM_VERSION_1_3 0x01040000
  34. #define SWRM_VERSION_1_5 0x01050000
  35. #define SWRM_VERSION_1_5_1 0x01050001
  36. #define SWRM_VERSION_1_6 0x01060000
  37. #define SWRM_VERSION_1_7 0x01070000
  38. #define SWRM_VERSION_2_0 0x02000000
  39. #define SWR_MAX_CH_PER_PORT 8
  40. #define SWRM_NUM_AUTO_ENUM_SLAVES 11
  41. enum {
  42. SWR_MSTR_PAUSE,
  43. SWR_MSTR_RESUME,
  44. SWR_MSTR_UP,
  45. SWR_MSTR_DOWN,
  46. SWR_MSTR_SSR,
  47. SWR_MSTR_SSR_RESET,
  48. };
  49. enum swrm_pm_state {
  50. SWRM_PM_SLEEPABLE,
  51. SWRM_PM_AWAKE,
  52. SWRM_PM_ASLEEP,
  53. };
  54. enum {
  55. SWR_IRQ_FREE,
  56. SWR_IRQ_REGISTER,
  57. };
  58. enum {
  59. SWR_PDM = 0,
  60. SWR_PCM,
  61. SWR_PDM_32,
  62. };
  63. struct usecase {
  64. u8 num_port;
  65. u8 num_ch;
  66. u32 chrate;
  67. };
  68. struct swrm_mports {
  69. struct list_head port_req_list;
  70. bool port_en;
  71. u8 ch_en;
  72. u8 req_ch;
  73. u8 offset1;
  74. u8 offset2;
  75. u16 sinterval;
  76. u8 hstart;
  77. u8 hstop;
  78. u8 blk_grp_count;
  79. u8 blk_pack_mode;
  80. u8 word_length;
  81. u8 lane_ctrl;
  82. u8 dir;
  83. u8 stream_type;
  84. u32 ch_rate;
  85. };
  86. struct swrm_port_type {
  87. u8 port_type;
  88. u8 ch_mask;
  89. };
  90. struct swr_ctrl_platform_data {
  91. void *handle; /* holds priv data */
  92. int (*read)(void *handle, int reg);
  93. int (*write)(void *handle, int reg, int val);
  94. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  95. int (*clk)(void *handle, bool enable);
  96. int (*core_vote)(void *handle, bool enable);
  97. int (*reg_irq)(void *handle, irqreturn_t(*irq_handler)(int irq,
  98. void *data), void *swr_handle, int type);
  99. };
  100. struct swr_mstr_ctrl {
  101. struct swr_master master;
  102. struct device *dev;
  103. struct resource *supplies;
  104. struct clk *mclk;
  105. int clk_ref_count;
  106. struct completion clk_off_complete;
  107. struct completion reset;
  108. struct completion broadcast;
  109. struct mutex clklock;
  110. struct mutex iolock;
  111. struct mutex devlock;
  112. struct mutex mlock;
  113. struct mutex reslock;
  114. struct mutex pm_lock;
  115. struct mutex irq_lock;
  116. struct mutex runtime_lock;
  117. u32 swrm_base_reg;
  118. char __iomem *swrm_dig_base;
  119. char __iomem *swrm_hctl_reg;
  120. u8 rcmd_id;
  121. u8 wcmd_id;
  122. u8 cmd_id;
  123. u32 master_id;
  124. u32 ee_val;
  125. u32 dynamic_port_map_supported;
  126. void *handle; /* SWR Master handle from client for read and writes */
  127. int (*read)(void *handle, int reg);
  128. int (*write)(void *handle, int reg, int val);
  129. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  130. int (*clk)(void *handle, bool enable);
  131. int (*core_vote)(void *handle, bool enable);
  132. int (*reg_irq)(void *handle, irqreturn_t(*irq_handler)(int irq,
  133. void *data), void *swr_handle, int type);
  134. int irq;
  135. int wake_irq;
  136. int version;
  137. int mclk_freq;
  138. int bus_clk;
  139. u32 num_dev;
  140. int slave_status;
  141. struct swrm_mports mport_cfg[SWR_MAX_MSTR_PORT_NUM];
  142. struct list_head port_req_list;
  143. unsigned long port_req_pending;
  144. int state;
  145. struct platform_device *pdev;
  146. int num_rx_chs;
  147. u8 num_cfg_devs;
  148. struct mutex force_down_lock;
  149. int force_down_state;
  150. struct notifier_block event_notifier;
  151. struct work_struct dc_presence_work;
  152. u8 num_ports;
  153. struct swrm_port_type
  154. port_mapping[SWR_MSTR_PORT_LEN + 1][SWR_MAX_CH_PER_PORT];
  155. int swr_irq;
  156. u32 clk_stop_mode0_supp;
  157. struct work_struct wakeup_work;
  158. u32 ipc_wakeup;
  159. bool dev_up;
  160. bool ipc_wakeup_triggered;
  161. bool req_clk_switch;
  162. struct pm_qos_request pm_qos_req;
  163. enum swrm_pm_state pm_state;
  164. wait_queue_head_t pm_wq;
  165. int wlock_holders;
  166. u32 intr_mask;
  167. struct port_params **port_param;
  168. struct clk *lpass_core_hw_vote;
  169. struct clk *lpass_core_audio;
  170. u8 num_usecase;
  171. u32 swr_irq_wakeup_capable;
  172. int hw_core_clk_en;
  173. int aud_core_clk_en;
  174. int clk_src;
  175. u32 pcm_enable_count;
  176. u32 disable_div2_clk_switch;
  177. u32 rd_fifo_depth;
  178. u32 wr_fifo_depth;
  179. u32 num_auto_enum;
  180. bool enable_slave_irq;
  181. u32 is_always_on;
  182. bool clk_stop_wakeup;
  183. struct swr_port_params pp[SWR_UC_MAX][SWR_MAX_MSTR_PORT_NUM];/*max_devNum * max_ports 11 * 14 */
  184. #ifdef CONFIG_DEBUG_FS
  185. struct dentry *debugfs_swrm_dent;
  186. struct dentry *debugfs_peek;
  187. struct dentry *debugfs_poke;
  188. struct dentry *debugfs_reg_dump;
  189. unsigned int read_data;
  190. #endif
  191. };
  192. #endif /* _SWR_WCD_CTRL_H */