swr-mstr-ctrl.h 4.7 KB

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