soc-component.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * soc-component.h
  4. *
  5. * Copyright (C) 2019 Renesas Electronics Corp.
  6. * Kuninori Morimoto <[email protected]>
  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_tstamp *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. /* DT */
  92. int (*of_xlate_dai_name)(struct snd_soc_component *component,
  93. const struct of_phandle_args *args,
  94. const char **dai_name);
  95. int (*of_xlate_dai_id)(struct snd_soc_component *comment,
  96. struct device_node *endpoint);
  97. void (*seq_notifier)(struct snd_soc_component *component,
  98. enum snd_soc_dapm_type type, int subseq);
  99. int (*stream_event)(struct snd_soc_component *component, int event);
  100. int (*set_bias_level)(struct snd_soc_component *component,
  101. enum snd_soc_bias_level level);
  102. int (*open)(struct snd_soc_component *component,
  103. struct snd_pcm_substream *substream);
  104. int (*close)(struct snd_soc_component *component,
  105. struct snd_pcm_substream *substream);
  106. int (*ioctl)(struct snd_soc_component *component,
  107. struct snd_pcm_substream *substream,
  108. unsigned int cmd, void *arg);
  109. int (*hw_params)(struct snd_soc_component *component,
  110. struct snd_pcm_substream *substream,
  111. struct snd_pcm_hw_params *params);
  112. int (*hw_free)(struct snd_soc_component *component,
  113. struct snd_pcm_substream *substream);
  114. int (*prepare)(struct snd_soc_component *component,
  115. struct snd_pcm_substream *substream);
  116. int (*trigger)(struct snd_soc_component *component,
  117. struct snd_pcm_substream *substream, int cmd);
  118. int (*sync_stop)(struct snd_soc_component *component,
  119. struct snd_pcm_substream *substream);
  120. snd_pcm_uframes_t (*pointer)(struct snd_soc_component *component,
  121. struct snd_pcm_substream *substream);
  122. int (*get_time_info)(struct snd_soc_component *component,
  123. struct snd_pcm_substream *substream, struct timespec64 *system_ts,
  124. struct timespec64 *audio_ts,
  125. struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
  126. struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
  127. int (*copy_user)(struct snd_soc_component *component,
  128. struct snd_pcm_substream *substream, int channel,
  129. unsigned long pos, void __user *buf,
  130. unsigned long bytes);
  131. struct page *(*page)(struct snd_soc_component *component,
  132. struct snd_pcm_substream *substream,
  133. unsigned long offset);
  134. int (*mmap)(struct snd_soc_component *component,
  135. struct snd_pcm_substream *substream,
  136. struct vm_area_struct *vma);
  137. int (*ack)(struct snd_soc_component *component,
  138. struct snd_pcm_substream *substream);
  139. snd_pcm_sframes_t (*delay)(struct snd_soc_component *component,
  140. struct snd_pcm_substream *substream);
  141. const struct snd_compress_ops *compress_ops;
  142. /* probe ordering - for components with runtime dependencies */
  143. int probe_order;
  144. int remove_order;
  145. /*
  146. * signal if the module handling the component should not be removed
  147. * if a pcm is open. Setting this would prevent the module
  148. * refcount being incremented in probe() but allow it be incremented
  149. * when a pcm is opened and decremented when it is closed.
  150. */
  151. unsigned int module_get_upon_open:1;
  152. /* bits */
  153. unsigned int idle_bias_on:1;
  154. unsigned int suspend_bias_off:1;
  155. unsigned int use_pmdown_time:1; /* care pmdown_time at stop */
  156. /*
  157. * Indicates that the component does not care about the endianness of
  158. * PCM audio data and the core will ensure that both LE and BE variants
  159. * of each used format are present. Typically this is because the
  160. * component sits behind a bus that abstracts away the endian of the
  161. * original data, ie. one for which the transmission endian is defined
  162. * (I2S/SLIMbus/SoundWire), or the concept of endian doesn't exist (PDM,
  163. * analogue).
  164. */
  165. unsigned int endianness:1;
  166. unsigned int legacy_dai_naming:1;
  167. /* this component uses topology and ignore machine driver FEs */
  168. const char *ignore_machine;
  169. const char *topology_name_prefix;
  170. int (*be_hw_params_fixup)(struct snd_soc_pcm_runtime *rtd,
  171. struct snd_pcm_hw_params *params);
  172. bool use_dai_pcm_id; /* use DAI link PCM ID as PCM device number */
  173. int be_pcm_base; /* base device ID for all BE PCMs */
  174. #ifdef CONFIG_DEBUG_FS
  175. const char *debugfs_prefix;
  176. #endif
  177. };
  178. struct snd_soc_component {
  179. const char *name;
  180. int id;
  181. const char *name_prefix;
  182. struct device *dev;
  183. struct snd_soc_card *card;
  184. unsigned int active;
  185. unsigned int suspended:1; /* is in suspend PM state */
  186. struct list_head list;
  187. struct list_head card_aux_list; /* for auxiliary bound components */
  188. struct list_head card_list;
  189. const struct snd_soc_component_driver *driver;
  190. struct list_head dai_list;
  191. int num_dai;
  192. struct regmap *regmap;
  193. int val_bytes;
  194. struct mutex io_mutex;
  195. /* attached dynamic objects */
  196. struct list_head dobj_list;
  197. /*
  198. * DO NOT use any of the fields below in drivers, they are temporary and
  199. * are going to be removed again soon. If you use them in driver code
  200. * the driver will be marked as BROKEN when these fields are removed.
  201. */
  202. /* Don't use these, use snd_soc_component_get_dapm() */
  203. struct snd_soc_dapm_context dapm;
  204. /* machine specific init */
  205. int (*init)(struct snd_soc_component *component);
  206. /* function mark */
  207. void *mark_module;
  208. struct snd_pcm_substream *mark_open;
  209. struct snd_pcm_substream *mark_hw_params;
  210. struct snd_pcm_substream *mark_trigger;
  211. struct snd_compr_stream *mark_compr_open;
  212. void *mark_pm;
  213. struct dentry *debugfs_root;
  214. const char *debugfs_prefix;
  215. };
  216. #define for_each_component_dais(component, dai)\
  217. list_for_each_entry(dai, &(component)->dai_list, list)
  218. #define for_each_component_dais_safe(component, dai, _dai)\
  219. list_for_each_entry_safe(dai, _dai, &(component)->dai_list, list)
  220. /**
  221. * snd_soc_dapm_to_component() - Casts a DAPM context to the component it is
  222. * embedded in
  223. * @dapm: The DAPM context to cast to the component
  224. *
  225. * This function must only be used on DAPM contexts that are known to be part of
  226. * a component (e.g. in a component driver). Otherwise the behavior is
  227. * undefined.
  228. */
  229. static inline struct snd_soc_component *snd_soc_dapm_to_component(
  230. struct snd_soc_dapm_context *dapm)
  231. {
  232. return container_of(dapm, struct snd_soc_component, dapm);
  233. }
  234. /**
  235. * snd_soc_component_get_dapm() - Returns the DAPM context associated with a
  236. * component
  237. * @component: The component for which to get the DAPM context
  238. */
  239. static inline struct snd_soc_dapm_context *snd_soc_component_get_dapm(
  240. struct snd_soc_component *component)
  241. {
  242. return &component->dapm;
  243. }
  244. /**
  245. * snd_soc_component_init_bias_level() - Initialize COMPONENT DAPM bias level
  246. * @component: The COMPONENT for which to initialize the DAPM bias level
  247. * @level: The DAPM level to initialize to
  248. *
  249. * Initializes the COMPONENT DAPM bias level. See snd_soc_dapm_init_bias_level()
  250. */
  251. static inline void
  252. snd_soc_component_init_bias_level(struct snd_soc_component *component,
  253. enum snd_soc_bias_level level)
  254. {
  255. snd_soc_dapm_init_bias_level(
  256. snd_soc_component_get_dapm(component), level);
  257. }
  258. /**
  259. * snd_soc_component_get_bias_level() - Get current COMPONENT DAPM bias level
  260. * @component: The COMPONENT for which to get the DAPM bias level
  261. *
  262. * Returns: The current DAPM bias level of the COMPONENT.
  263. */
  264. static inline enum snd_soc_bias_level
  265. snd_soc_component_get_bias_level(struct snd_soc_component *component)
  266. {
  267. return snd_soc_dapm_get_bias_level(
  268. snd_soc_component_get_dapm(component));
  269. }
  270. /**
  271. * snd_soc_component_force_bias_level() - Set the COMPONENT DAPM bias level
  272. * @component: The COMPONENT for which to set the level
  273. * @level: The level to set to
  274. *
  275. * Forces the COMPONENT bias level to a specific state. See
  276. * snd_soc_dapm_force_bias_level().
  277. */
  278. static inline int
  279. snd_soc_component_force_bias_level(struct snd_soc_component *component,
  280. enum snd_soc_bias_level level)
  281. {
  282. return snd_soc_dapm_force_bias_level(
  283. snd_soc_component_get_dapm(component),
  284. level);
  285. }
  286. /**
  287. * snd_soc_dapm_kcontrol_component() - Returns the component associated to a
  288. * kcontrol
  289. * @kcontrol: The kcontrol
  290. *
  291. * This function must only be used on DAPM contexts that are known to be part of
  292. * a COMPONENT (e.g. in a COMPONENT driver). Otherwise the behavior is undefined
  293. */
  294. static inline struct snd_soc_component *snd_soc_dapm_kcontrol_component(
  295. struct snd_kcontrol *kcontrol)
  296. {
  297. return snd_soc_dapm_to_component(snd_soc_dapm_kcontrol_dapm(kcontrol));
  298. }
  299. /**
  300. * snd_soc_component_cache_sync() - Sync the register cache with the hardware
  301. * @component: COMPONENT to sync
  302. *
  303. * Note: This function will call regcache_sync()
  304. */
  305. static inline int snd_soc_component_cache_sync(
  306. struct snd_soc_component *component)
  307. {
  308. return regcache_sync(component->regmap);
  309. }
  310. void snd_soc_component_set_aux(struct snd_soc_component *component,
  311. struct snd_soc_aux_dev *aux);
  312. int snd_soc_component_init(struct snd_soc_component *component);
  313. int snd_soc_component_is_dummy(struct snd_soc_component *component);
  314. /* component IO */
  315. unsigned int snd_soc_component_read(struct snd_soc_component *component,
  316. unsigned int reg);
  317. int snd_soc_component_write(struct snd_soc_component *component,
  318. unsigned int reg, unsigned int val);
  319. int snd_soc_component_update_bits(struct snd_soc_component *component,
  320. unsigned int reg, unsigned int mask,
  321. unsigned int val);
  322. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  323. unsigned int reg, unsigned int mask,
  324. unsigned int val);
  325. void snd_soc_component_async_complete(struct snd_soc_component *component);
  326. int snd_soc_component_test_bits(struct snd_soc_component *component,
  327. unsigned int reg, unsigned int mask,
  328. unsigned int value);
  329. unsigned int snd_soc_component_read_field(struct snd_soc_component *component,
  330. unsigned int reg, unsigned int mask);
  331. int snd_soc_component_write_field(struct snd_soc_component *component,
  332. unsigned int reg, unsigned int mask,
  333. unsigned int val);
  334. /* component wide operations */
  335. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  336. int clk_id, int source,
  337. unsigned int freq, int dir);
  338. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  339. int source, unsigned int freq_in,
  340. unsigned int freq_out);
  341. int snd_soc_component_set_jack(struct snd_soc_component *component,
  342. struct snd_soc_jack *jack, void *data);
  343. void snd_soc_component_seq_notifier(struct snd_soc_component *component,
  344. enum snd_soc_dapm_type type, int subseq);
  345. int snd_soc_component_stream_event(struct snd_soc_component *component,
  346. int event);
  347. int snd_soc_component_set_bias_level(struct snd_soc_component *component,
  348. enum snd_soc_bias_level level);
  349. void snd_soc_component_setup_regmap(struct snd_soc_component *component);
  350. #ifdef CONFIG_REGMAP
  351. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  352. struct regmap *regmap);
  353. void snd_soc_component_exit_regmap(struct snd_soc_component *component);
  354. #endif
  355. #define snd_soc_component_module_get_when_probe(component)\
  356. snd_soc_component_module_get(component, NULL, 0)
  357. #define snd_soc_component_module_get_when_open(component, substream) \
  358. snd_soc_component_module_get(component, substream, 1)
  359. int snd_soc_component_module_get(struct snd_soc_component *component,
  360. void *mark, int upon_open);
  361. #define snd_soc_component_module_put_when_remove(component) \
  362. snd_soc_component_module_put(component, NULL, 0, 0)
  363. #define snd_soc_component_module_put_when_close(component, substream, rollback) \
  364. snd_soc_component_module_put(component, substream, 1, rollback)
  365. void snd_soc_component_module_put(struct snd_soc_component *component,
  366. void *mark, int upon_open, int rollback);
  367. static inline void snd_soc_component_set_drvdata(struct snd_soc_component *c,
  368. void *data)
  369. {
  370. dev_set_drvdata(c->dev, data);
  371. }
  372. static inline void *snd_soc_component_get_drvdata(struct snd_soc_component *c)
  373. {
  374. return dev_get_drvdata(c->dev);
  375. }
  376. static inline unsigned int
  377. snd_soc_component_active(struct snd_soc_component *component)
  378. {
  379. return component->active;
  380. }
  381. /* component pin */
  382. int snd_soc_component_enable_pin(struct snd_soc_component *component,
  383. const char *pin);
  384. int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
  385. const char *pin);
  386. int snd_soc_component_disable_pin(struct snd_soc_component *component,
  387. const char *pin);
  388. int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
  389. const char *pin);
  390. int snd_soc_component_nc_pin(struct snd_soc_component *component,
  391. const char *pin);
  392. int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
  393. const char *pin);
  394. int snd_soc_component_get_pin_status(struct snd_soc_component *component,
  395. const char *pin);
  396. int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
  397. const char *pin);
  398. int snd_soc_component_force_enable_pin_unlocked(
  399. struct snd_soc_component *component,
  400. const char *pin);
  401. /* component driver ops */
  402. int snd_soc_component_open(struct snd_soc_component *component,
  403. struct snd_pcm_substream *substream);
  404. int snd_soc_component_close(struct snd_soc_component *component,
  405. struct snd_pcm_substream *substream,
  406. int rollback);
  407. void snd_soc_component_suspend(struct snd_soc_component *component);
  408. void snd_soc_component_resume(struct snd_soc_component *component);
  409. int snd_soc_component_is_suspended(struct snd_soc_component *component);
  410. int snd_soc_component_probe(struct snd_soc_component *component);
  411. void snd_soc_component_remove(struct snd_soc_component *component);
  412. int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
  413. struct device_node *ep);
  414. int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
  415. const struct of_phandle_args *args,
  416. const char **dai_name);
  417. int snd_soc_component_compr_open(struct snd_soc_component *component,
  418. struct snd_compr_stream *cstream);
  419. void snd_soc_component_compr_free(struct snd_soc_component *component,
  420. struct snd_compr_stream *cstream,
  421. int rollback);
  422. int snd_soc_component_compr_trigger(struct snd_compr_stream *cstream, int cmd);
  423. int snd_soc_component_compr_set_params(struct snd_compr_stream *cstream,
  424. struct snd_compr_params *params);
  425. int snd_soc_component_compr_get_params(struct snd_compr_stream *cstream,
  426. struct snd_codec *params);
  427. int snd_soc_component_compr_get_caps(struct snd_compr_stream *cstream,
  428. struct snd_compr_caps *caps);
  429. int snd_soc_component_compr_get_codec_caps(struct snd_compr_stream *cstream,
  430. struct snd_compr_codec_caps *codec);
  431. int snd_soc_component_compr_ack(struct snd_compr_stream *cstream, size_t bytes);
  432. int snd_soc_component_compr_pointer(struct snd_compr_stream *cstream,
  433. struct snd_compr_tstamp *tstamp);
  434. int snd_soc_component_compr_copy(struct snd_compr_stream *cstream,
  435. char __user *buf, size_t count);
  436. int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,
  437. struct snd_compr_metadata *metadata);
  438. int snd_soc_component_compr_get_metadata(struct snd_compr_stream *cstream,
  439. struct snd_compr_metadata *metadata);
  440. int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream);
  441. int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
  442. unsigned int cmd, void *arg);
  443. int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream);
  444. int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
  445. int channel, unsigned long pos,
  446. void __user *buf, unsigned long bytes);
  447. struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
  448. unsigned long offset);
  449. int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
  450. struct vm_area_struct *vma);
  451. int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd);
  452. void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd);
  453. int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream);
  454. int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
  455. struct snd_pcm_hw_params *params);
  456. void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
  457. int rollback);
  458. int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
  459. int cmd, int rollback);
  460. int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
  461. void *stream);
  462. void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
  463. void *stream, int rollback);
  464. int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream);
  465. void snd_soc_pcm_component_delay(struct snd_pcm_substream *substream,
  466. snd_pcm_sframes_t *cpu_delay, snd_pcm_sframes_t *codec_delay);
  467. #endif /* __SOC_COMPONENT_H */