msm_sdw.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 MSM_SDW_H
  13. #define MSM_SDW_H
  14. #include <sound/soc.h>
  15. #include <dsp/q6afe-v2.h>
  16. #include "msm_sdw_registers.h"
  17. #define MSM_SDW_MAX_REGISTER 0x400
  18. #define MSM_SDW_CHILD_DEVICES_MAX 1
  19. extern const struct regmap_config msm_sdw_regmap_config;
  20. extern const u8 msm_sdw_page_map[MSM_SDW_MAX_REGISTER];
  21. extern const u8 msm_sdw_reg_readable[MSM_SDW_MAX_REGISTER];
  22. extern const u8 msm_sdw_reg_writeable[MSM_SDW_MAX_REGISTER];
  23. enum {
  24. MSM_SDW_RX4 = 0,
  25. MSM_SDW_RX5,
  26. MSM_SDW_RX_MAX,
  27. };
  28. enum {
  29. MSM_SDW_TX0 = 0,
  30. MSM_SDW_TX1,
  31. MSM_SDW_TX_MAX,
  32. };
  33. enum {
  34. COMP1, /* SPK_L */
  35. COMP2, /* SPK_R */
  36. COMP_MAX
  37. };
  38. /*
  39. * Structure used to update codec
  40. * register defaults after reset
  41. */
  42. struct msm_sdw_reg_mask_val {
  43. u16 reg;
  44. u8 mask;
  45. u8 val;
  46. };
  47. /*
  48. * Selects compander and smart boost settings
  49. * for a given speaker mode
  50. */
  51. enum {
  52. SPKR_MODE_DEFAULT,
  53. SPKR_MODE_1, /* COMP Gain = 12dB, Smartboost Max = 5.5V */
  54. };
  55. /* Rx path gain offsets */
  56. enum {
  57. RX_GAIN_OFFSET_M1P5_DB,
  58. RX_GAIN_OFFSET_0_DB,
  59. };
  60. struct msm_sdw_reg_val {
  61. unsigned short reg; /* register address */
  62. u8 *buf; /* buffer to be written to reg. addr */
  63. int bytes; /* number of bytes to be written */
  64. };
  65. /* Hold instance to soundwire platform device */
  66. struct msm_sdw_ctrl_data {
  67. struct platform_device *sdw_pdev;
  68. };
  69. struct wcd_sdw_ctrl_platform_data {
  70. void *handle; /* holds codec private data */
  71. int (*read)(void *handle, int reg);
  72. int (*write)(void *handle, int reg, int val);
  73. int (*bulk_write)(void *handle, u32 *reg, u32 *val, size_t len);
  74. int (*clk)(void *handle, bool enable);
  75. int (*handle_irq)(void *handle,
  76. irqreturn_t (*swrm_irq_handler)(int irq,
  77. void *data),
  78. void *swrm_handle,
  79. int action);
  80. };
  81. struct msm_sdw_priv {
  82. struct device *dev;
  83. struct mutex io_lock;
  84. int (*read_dev)(struct msm_sdw_priv *msm_sdw, unsigned short reg,
  85. int bytes, void *dest);
  86. int (*write_dev)(struct msm_sdw_priv *msm_sdw, unsigned short reg,
  87. int bytes, void *src);
  88. int (*multi_reg_write)(struct msm_sdw_priv *msm_sdw, const void *data,
  89. size_t count);
  90. struct snd_soc_codec *codec;
  91. struct device_node *sdw_gpio_p; /* used by pinctrl API */
  92. /* SoundWire data structure */
  93. struct msm_sdw_ctrl_data *sdw_ctrl_data;
  94. int nr;
  95. /* compander */
  96. int comp_enabled[COMP_MAX];
  97. int ear_spkr_gain;
  98. /* to track the status */
  99. unsigned long status_mask;
  100. struct work_struct msm_sdw_add_child_devices_work;
  101. struct wcd_sdw_ctrl_platform_data sdw_plat_data;
  102. unsigned int vi_feed_value;
  103. struct mutex sdw_read_lock;
  104. struct mutex sdw_write_lock;
  105. struct mutex sdw_clk_lock;
  106. int sdw_clk_users;
  107. int sdw_mclk_users;
  108. int sdw_irq;
  109. int int_mclk1_rsc_ref;
  110. bool int_mclk1_enabled;
  111. bool sdw_npl_clk_enabled;
  112. struct mutex cdc_int_mclk1_mutex;
  113. struct mutex sdw_npl_clk_mutex;
  114. struct delayed_work disable_int_mclk1_work;
  115. struct afe_clk_set sdw_cdc_core_clk;
  116. struct afe_clk_set sdw_npl_clk;
  117. struct notifier_block service_nb;
  118. int (*sdw_cdc_gpio_fn)(bool enable, struct snd_soc_codec *codec);
  119. bool dev_up;
  120. int spkr_gain_offset;
  121. int spkr_mode;
  122. struct mutex codec_mutex;
  123. int rx_4_count;
  124. int rx_5_count;
  125. u32 mclk_rate;
  126. struct regmap *regmap;
  127. bool prev_pg_valid;
  128. u8 prev_pg;
  129. u32 sdw_base_addr;
  130. char __iomem *sdw_base;
  131. u32 version;
  132. /* Entry for version info */
  133. struct snd_info_entry *entry;
  134. struct snd_info_entry *version_entry;
  135. struct platform_device *pdev_child_devices
  136. [MSM_SDW_CHILD_DEVICES_MAX];
  137. int child_count;
  138. };
  139. #if IS_ENABLED(CONFIG_SND_SOC_MSM_SDW)
  140. extern int msm_sdw_set_spkr_mode(struct snd_soc_codec *codec, int mode);
  141. extern int msm_sdw_set_spkr_gain_offset(struct snd_soc_codec *codec,
  142. int offset);
  143. extern void msm_sdw_gpio_cb(
  144. int (*sdw_cdc_gpio_fn)(bool enable, struct snd_soc_codec *codec),
  145. struct snd_soc_codec *codec);
  146. extern struct regmap *msm_sdw_regmap_init(struct device *dev,
  147. const struct regmap_config *config);
  148. extern int msm_sdw_codec_info_create_codec_entry(
  149. struct snd_info_entry *codec_root,
  150. struct snd_soc_codec *codec);
  151. #else /* CONFIG_SND_SOC_MSM_SDW */
  152. static inline int msm_sdw_set_spkr_mode(struct snd_soc_codec *codec, int mode)
  153. {
  154. return 0;
  155. }
  156. static inline int msm_sdw_set_spkr_gain_offset(struct snd_soc_codec *codec,
  157. int offset);
  158. {
  159. return 0;
  160. }
  161. static inline void msm_sdw_gpio_cb(
  162. int (*sdw_cdc_gpio_fn)(bool enable, struct snd_soc_codec *codec),
  163. struct snd_soc_codec *codec);
  164. {
  165. }
  166. static inline struct regmap *msm_sdw_regmap_init(struct device *dev,
  167. const struct regmap_config *config);
  168. {
  169. return NULL;
  170. }
  171. static inline int msm_sdw_codec_info_create_codec_entry(
  172. struct snd_info_entry *codec_root,
  173. struct snd_soc_codec *codec)
  174. {
  175. return 0;
  176. }
  177. #endif /* CONFIG_SND_SOC_MSM_SDW */
  178. #endif