soc-component.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * soc-component.h
  4. *
  5. * Copyright (C) 2019 Renesas Electronics Corp.
  6. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  7. */
  8. #ifndef __SOC_COMPONENT_H
  9. #define __SOC_COMPONENT_H
  10. #include <sound/soc.h>
  11. /*
  12. * Component probe and remove ordering levels for components with runtime
  13. * dependencies.
  14. */
  15. #define SND_SOC_COMP_ORDER_FIRST -2
  16. #define SND_SOC_COMP_ORDER_EARLY -1
  17. #define SND_SOC_COMP_ORDER_NORMAL 0
  18. #define SND_SOC_COMP_ORDER_LATE 1
  19. #define SND_SOC_COMP_ORDER_LAST 2
  20. #define for_each_comp_order(order) \
  21. for (order = SND_SOC_COMP_ORDER_FIRST; \
  22. order <= SND_SOC_COMP_ORDER_LAST; \
  23. order++)
  24. /* component interface */
  25. struct snd_compress_ops {
  26. int (*open)(struct snd_soc_component *component,
  27. struct snd_compr_stream *stream);
  28. int (*free)(struct snd_soc_component *component,
  29. struct snd_compr_stream *stream);
  30. int (*set_params)(struct snd_soc_component *component,
  31. struct snd_compr_stream *stream,
  32. struct snd_compr_params *params);
  33. int (*get_params)(struct snd_soc_component *component,
  34. struct snd_compr_stream *stream,
  35. struct snd_codec *params);
  36. int (*set_metadata)(struct snd_soc_component *component,
  37. struct snd_compr_stream *stream,
  38. struct snd_compr_metadata *metadata);
  39. int (*get_metadata)(struct snd_soc_component *component,
  40. struct snd_compr_stream *stream,
  41. struct snd_compr_metadata *metadata);
  42. int (*trigger)(struct snd_soc_component *component,
  43. struct snd_compr_stream *stream, int cmd);
  44. int (*pointer)(struct snd_soc_component *component,
  45. struct snd_compr_stream *stream,
  46. struct snd_compr_tstamp64 *tstamp);
  47. int (*copy)(struct snd_soc_component *component,
  48. struct snd_compr_stream *stream, char __user *buf,
  49. size_t count);
  50. int (*mmap)(struct snd_soc_component *component,
  51. struct snd_compr_stream *stream,
  52. struct vm_area_struct *vma);
  53. int (*ack)(struct snd_soc_component *component,
  54. struct snd_compr_stream *stream, size_t bytes);
  55. int (*get_caps)(struct snd_soc_component *component,
  56. struct snd_compr_stream *stream,
  57. struct snd_compr_caps *caps);
  58. int (*get_codec_caps)(struct snd_soc_component *component,
  59. struct snd_compr_stream *stream,
  60. struct snd_compr_codec_caps *codec);
  61. };
  62. struct snd_soc_component_driver {
  63. const char *name;
  64. /* Default control and setup, added after probe() is run */
  65. const struct snd_kcontrol_new *controls;
  66. unsigned int num_controls;
  67. const struct snd_soc_dapm_widget *dapm_widgets;
  68. unsigned int num_dapm_widgets;
  69. const struct snd_soc_dapm_route *dapm_routes;
  70. unsigned int num_dapm_routes;
  71. int (*probe)(struct snd_soc_component *component);
  72. void (*remove)(struct snd_soc_component *component);
  73. int (*suspend)(struct snd_soc_component *component);
  74. int (*resume)(struct snd_soc_component *component);
  75. unsigned int (*read)(struct snd_soc_component *component,
  76. unsigned int reg);
  77. int (*write)(struct snd_soc_component *component,
  78. unsigned int reg, unsigned int val);
  79. /* pcm creation and destruction */
  80. int (*pcm_construct)(struct snd_soc_component *component,
  81. struct snd_soc_pcm_runtime *rtd);
  82. void (*pcm_destruct)(struct snd_soc_component *component,
  83. struct snd_pcm *pcm);
  84. /* component wide operations */
  85. int (*set_sysclk)(struct snd_soc_component *component,
  86. int clk_id, int source, unsigned int freq, int dir);
  87. int (*set_pll)(struct snd_soc_component *component, int pll_id,
  88. int source, unsigned int freq_in, unsigned int freq_out);
  89. int (*set_jack)(struct snd_soc_component *component,
  90. struct snd_soc_jack *jack, void *data);
  91. int (*get_jack_type)(struct snd_soc_component *component);
  92. /* DT */
  93. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  94. const struct of_phandle_args *args,
  95. const char **dai_name);
  96. int (*of_xlate_dai_id)(struct snd_soc_component *comment,
  97. struct device_node *endpoint);
  98. void (*seq_notifier)(struct snd_soc_component *component,
  99. enum snd_soc_dapm_type type, int subseq);
  100. int (*stream_event)(struct snd_soc_component *component, int event);
  101. int (*set_bias_level)(struct snd_soc_component *component,
  102. enum snd_soc_bias_level level);
  103. int (*open)(struct snd_soc_component *component,
  104. struct snd_pcm_substream *substream);
  105. int (*close)(struct snd_soc_component *component,
  106. struct snd_pcm_substream *substream);
  107. int (*ioctl)(struct snd_soc_component *component,
  108. struct snd_pcm_substream *substream,
  109. unsigned int cmd, void *arg);
  110. int (*hw_params)(struct snd_soc_component *component,
  111. struct snd_pcm_substream *substream,
  112. struct snd_pcm_hw_params *params);
  113. int (*hw_free)(struct snd_soc_component *component,
  114. struct snd_pcm_substream *substream);
  115. int (*prepare)(struct snd_soc_component *component,
  116. struct snd_pcm_substream *substream);
  117. int (*trigger)(struct snd_soc_component *component,
  118. struct snd_pcm_substream *substream, int cmd);
  119. int (*sync_stop)(struct snd_soc_component *component,
  120. struct snd_pcm_substream *substream);
  121. snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
  122. struct snd_pcm_substream *substream);
  123. int (*get_time_info)(struct snd_soc_component *component,
  124. struct snd_pcm_substream *substream, struct timespec64 *system_ts,
  125. struct timespec64 *audio_ts,
  126. struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
  127. struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
  128. int (*copy)(struct snd_soc_component *component,
  129. struct snd_pcm_substream *substream, int channel,
  130. unsigned long pos, struct iov_iter *iter,
  131. unsigned long bytes);
  132. struct page *(*page)(struct snd_soc_component *component,
  133. struct snd_pcm_substream *substream,
  134. unsigned long offset);
  135. int (*mmap)(struct snd_soc_component *component,
  136. struct snd_pcm_substream *substream,
  137. struct vm_area_struct *vma);
  138. int (*ack)(struct snd_soc_component *component,
  139. struct snd_pcm_substream *substream);
  140. snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
  141. struct snd_pcm_substream *substream);
  142. const struct snd_compress_ops *compress_ops;
  143. /* probe ordering - for components with runtime dependencies */
  144. int probe_order;
  145. int remove_order;
  146. /*
  147. * soc_pcm_trigger() start/stop sequence.
  148. * see also
  149. * snd_soc_dai_link
  150. * soc_pcm_trigger()
  151. */
  152. enum snd_soc_trigger_order trigger_start;
  153. enum snd_soc_trigger_order trigger_stop;
  154. /*
  155. * signal if the module handling the component should not be removed
  156. * if a pcm is open. Setting this would prevent the module
  157. * refcount being incremented in probe() but allow it be incremented
  158. * when a pcm is opened and decremented when it is closed.
  159. */
  160. unsigned int module_get_upon_open:1;
  161. /* bits */
  162. unsigned int idle_bias_on:1;
  163. unsigned int suspend_bias_off:1;
  164. unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
  165. /*
  166. * Indicates that the component does not care about the endianness of
  167. * PCM audio data and the core will ensure that both LE and BE variants
  168. * of each used format are present. Typically this is because the
  169. * component sits behind a bus that abstracts away the endian of the
  170. * original data, ie. one for which the transmission endian is defined
  171. * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM,
  172. * analogue).
  173. */
  174. unsigned int endianness:1;
  175. unsigned int legacy_dai_naming:1;
  176. /* this component uses topology and ignore machine driver FEs */
  177. const char *ignore_machine;
  178. const char *topology_name_prefix;
  179. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  180. struct snd_pcm_hw_params *params);
  181. bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
  182. int be_pcm_base; /* base device ID for all BE PCMs */
  183. #ifdef CONFIG_DEBUG_FS
  184. const char *debugfs_prefix;
  185. #endif
  186. };
  187. struct snd_soc_component {
  188. const char *name;
  189. const char *name_prefix;
  190. struct device *dev;
  191. struct snd_soc_card *card;
  192. unsigned int active;
  193. unsigned int suspended:1; /* is in suspend PM state */
  194. struct list_head list;
  195. struct list_head card_aux_list; /* for auxiliary bound components */
  196. struct list_head card_list;
  197. const struct snd_soc_component_driver *driver;
  198. struct list_head dai_list;
  199. int num_dai;
  200. struct regmap *regmap;
  201. int val_bytes;
  202. struct mutex io_mutex;
  203. /* attached dynamic objects */
  204. struct list_head dobj_list;
  205. /*
  206. * DO NOT use any of the fields below in drivers, they are temporary and
  207. * are going to be removed again soon. If you use them in driver code
  208. * the driver will be marked as BROKEN when these fields are removed.
  209. */
  210. struct snd_soc_dapm_context *dapm;
  211. /* machine specific init */
  212. int (*init)(struct snd_soc_component *component);
  213. /* function mark */
  214. void *mark_module;
  215. struct snd_pcm_substream *mark_open;
  216. struct snd_pcm_substream *mark_hw_params;
  217. struct snd_pcm_substream *mark_trigger;
  218. struct snd_compr_stream *mark_compr_open;
  219. void *mark_pm;
  220. struct dentry *debugfs_root;
  221. const char *debugfs_prefix;
  222. };
  223. #define for_each_component_dais(component, dai)\
  224. list_for_each_entry(dai, &(component)->dai_list, list)
  225. #define for_each_component_dais_safe(component, dai, _dai)\
  226. list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
  227. /**
  228. * snd_soc_component_to_dapm() - Returns the DAPM context associated with a
  229. * component
  230. * @component: The component for which to get the DAPM context
  231. */
  232. static inline struct snd_soc_dapm_context *snd_soc_component_to_dapm(
  233. struct snd_soc_component *component)
  234. {
  235. return component->dapm;
  236. }
  237. /**
  238. * snd_soc_component_cache_sync() - Sync the register cache with the hardware
  239. * @component: COMPONENT to sync
  240. *
  241. * Note: This function will call regcache_sync()
  242. */
  243. static inline int snd_soc_component_cache_sync(
  244. struct snd_soc_component *component)
  245. {
  246. return regcache_sync(component->regmap);
  247. }
  248. void snd_soc_component_set_aux(struct snd_soc_component *component,
  249. struct snd_soc_aux_dev *aux);
  250. int snd_soc_component_init(struct snd_soc_component *component);
  251. int snd_soc_component_is_dummy(struct snd_soc_component *component);
  252. /* component IO */
  253. unsigned int snd_soc_component_read(struct snd_soc_component *component,
  254. unsigned int reg);
  255. int snd_soc_component_write(struct snd_soc_component *component,
  256. unsigned int reg, unsigned int val);
  257. int snd_soc_component_update_bits(struct snd_soc_component *component,
  258. unsigned int reg, unsigned int mask,
  259. unsigned int val);
  260. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  261. unsigned int reg, unsigned int mask,
  262. unsigned int val);
  263. void snd_soc_component_async_complete(struct snd_soc_component *component);
  264. int snd_soc_component_test_bits(struct snd_soc_component *component,
  265. unsigned int reg, unsigned int mask,
  266. unsigned int value);
  267. unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
  268. unsigned int reg, unsigned int mask);
  269. int snd_soc_component_write_field(struct snd_soc_component *component,
  270. unsigned int reg, unsigned int mask,
  271. unsigned int val);
  272. /* component wide operations */
  273. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  274. int clk_id, int source,
  275. unsigned int freq, int dir);
  276. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  277. int source, unsigned int freq_in,
  278. unsigned int freq_out);
  279. int snd_soc_component_set_jack(struct snd_soc_component *component,
  280. struct snd_soc_jack *jack, void *data);
  281. int snd_soc_component_get_jack_type(struct snd_soc_component *component);
  282. void snd_soc_component_seq_notifier(struct snd_soc_component *component,
  283. enum snd_soc_dapm_type type, int subseq);
  284. int snd_soc_component_stream_event(struct snd_soc_component *component,
  285. int event);
  286. int snd_soc_component_set_bias_level(struct snd_soc_component *component,
  287. enum snd_soc_bias_level level);
  288. void snd_soc_component_setup_regmap(struct snd_soc_component *component);
  289. #ifdef CONFIG_REGMAP
  290. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  291. struct regmap *regmap);
  292. void snd_soc_component_exit_regmap(struct snd_soc_component *component);
  293. #endif
  294. #define snd_soc_component_module_get_when_probe(component)\
  295. snd_soc_component_module_get(component, NULL, 0)
  296. #define snd_soc_component_module_get_when_open(component, substream) \
  297. snd_soc_component_module_get(component, substream, 1)
  298. int snd_soc_component_module_get(struct snd_soc_component *component,
  299. void *mark, int upon_open);
  300. #define snd_soc_component_module_put_when_remove(component) \
  301. snd_soc_component_module_put(component, NULL, 0, 0)
  302. #define snd_soc_component_module_put_when_close(component, substream, rollback) \
  303. snd_soc_component_module_put(component, substream, 1, rollback)
  304. void snd_soc_component_module_put(struct snd_soc_component *component,
  305. void *mark, int upon_open, int rollback);
  306. static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
  307. void *data)
  308. {
  309. dev_set_drvdata(c->dev, data);
  310. }
  311. static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
  312. {
  313. return dev_get_drvdata(c->dev);
  314. }
  315. static inline unsigned int
  316. snd_soc_component_active(struct snd_soc_component *component)
  317. {
  318. return component->active;
  319. }
  320. /* component controls */
  321. struct snd_kcontrol *snd_soc_component_get_kcontrol(struct snd_soc_component *component,
  322. const char * const ctl);
  323. int snd_soc_component_notify_control(struct snd_soc_component *component,
  324. const char * const ctl);
  325. /* component driver ops */
  326. int snd_soc_component_open(struct snd_soc_component *component,
  327. struct snd_pcm_substream *substream);
  328. int snd_soc_component_close(struct snd_soc_component *component,
  329. struct snd_pcm_substream *substream,
  330. int rollback);
  331. void snd_soc_component_suspend(struct snd_soc_component *component);
  332. void snd_soc_component_resume(struct snd_soc_component *component);
  333. int snd_soc_component_is_suspended(struct snd_soc_component *component);
  334. int snd_soc_component_probe(struct snd_soc_component *component);
  335. void snd_soc_component_remove(struct snd_soc_component *component);
  336. int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
  337. struct device_node *ep);
  338. int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
  339. const struct of_phandle_args *args,
  340. const char **dai_name);
  341. int snd_soc_component_compr_open(struct snd_soc_component *component,
  342. struct snd_compr_stream *cstream);
  343. void snd_soc_component_compr_free(struct snd_soc_component *component,
  344. struct snd_compr_stream *cstream,
  345. int rollback);
  346. int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
  347. int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
  348. struct snd_compr_params *params);
  349. int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
  350. struct snd_codec *params);
  351. int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
  352. struct snd_compr_caps *caps);
  353. int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
  354. struct snd_compr_codec_caps *codec);
  355. int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
  356. int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
  357. struct snd_compr_tstamp64 *tstamp);
  358. int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
  359. char __user *buf, size_t count);
  360. int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
  361. struct snd_compr_metadata *metadata);
  362. int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
  363. struct snd_compr_metadata *metadata);
  364. int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
  365. int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
  366. unsigned int cmd, void *arg);
  367. int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
  368. int snd_soc_pcm_component_copy(struct snd_pcm_substream *substream,
  369. int channel, unsigned long pos,
  370. struct iov_iter *iter, unsigned long bytes);
  371. struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
  372. unsigned long offset);
  373. int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
  374. struct vm_area_struct *vma);
  375. int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
  376. void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
  377. int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
  378. int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
  379. struct snd_pcm_hw_params *params);
  380. void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
  381. int rollback);
  382. int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
  383. int cmd, int rollback);
  384. int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
  385. void *stream);
  386. void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
  387. void *stream, int rollback);
  388. int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
  389. void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
  390. snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
  391. #endif /* __SOC_COMPONENT_H */