soc-component.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // soc-component.c
  4. //
  5. // Copyright 2009-2011 Wolfson Microelectronics PLC.
  6. // Copyright (C) 2019 Renesas Electronics Corp.
  7. //
  8. // Mark Brown <broonie@opensource.wolfsonmicro.com>
  9. // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  10. //
  11. #include <linux/module.h>
  12. #include <linux/pm_runtime.h>
  13. #include <sound/soc.h>
  14. #define soc_component_ret(dai, ret) _soc_component_ret(dai, __func__, ret)
  15. static inline int _soc_component_ret(struct snd_soc_component *component,
  16. const char *func, int ret)
  17. {
  18. /* Positive/Zero values are not errors */
  19. if (ret >= 0)
  20. return ret;
  21. /* Negative values might be errors */
  22. switch (ret) {
  23. case -EPROBE_DEFER:
  24. case -ENOTSUPP:
  25. break;
  26. default:
  27. dev_err(component->dev,
  28. "ASoC: error at %s on %s: %d\n",
  29. func, component->name, ret);
  30. }
  31. return ret;
  32. }
  33. /*
  34. * We might want to check substream by using list.
  35. * In such case, we can update these macros.
  36. */
  37. #define soc_component_mark_push(component, substream, tgt) ((component)->mark_##tgt = substream)
  38. #define soc_component_mark_pop(component, substream, tgt) ((component)->mark_##tgt = NULL)
  39. #define soc_component_mark_match(component, substream, tgt) ((component)->mark_##tgt == substream)
  40. void snd_soc_component_set_aux(struct snd_soc_component *component,
  41. struct snd_soc_aux_dev *aux)
  42. {
  43. component->init = (aux) ? aux->init : NULL;
  44. }
  45. int snd_soc_component_init(struct snd_soc_component *component)
  46. {
  47. int ret = 0;
  48. if (component->init)
  49. ret = component->init(component);
  50. return soc_component_ret(component, ret);
  51. }
  52. /**
  53. * snd_soc_component_set_sysclk - configure COMPONENT system or master clock.
  54. * @component: COMPONENT
  55. * @clk_id: DAI specific clock ID
  56. * @source: Source for the clock
  57. * @freq: new clock frequency in Hz
  58. * @dir: new clock direction - input/output.
  59. *
  60. * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
  61. */
  62. int snd_soc_component_set_sysclk(struct snd_soc_component *component,
  63. int clk_id, int source, unsigned int freq,
  64. int dir)
  65. {
  66. int ret = -ENOTSUPP;
  67. if (component->driver->set_sysclk)
  68. ret = component->driver->set_sysclk(component, clk_id, source,
  69. freq, dir);
  70. return soc_component_ret(component, ret);
  71. }
  72. EXPORT_SYMBOL_GPL(snd_soc_component_set_sysclk);
  73. /*
  74. * snd_soc_component_set_pll - configure component PLL.
  75. * @component: COMPONENT
  76. * @pll_id: DAI specific PLL ID
  77. * @source: DAI specific source for the PLL
  78. * @freq_in: PLL input clock frequency in Hz
  79. * @freq_out: requested PLL output clock frequency in Hz
  80. *
  81. * Configures and enables PLL to generate output clock based on input clock.
  82. */
  83. int snd_soc_component_set_pll(struct snd_soc_component *component, int pll_id,
  84. int source, unsigned int freq_in,
  85. unsigned int freq_out)
  86. {
  87. int ret = -EINVAL;
  88. if (component->driver->set_pll)
  89. ret = component->driver->set_pll(component, pll_id, source,
  90. freq_in, freq_out);
  91. return soc_component_ret(component, ret);
  92. }
  93. EXPORT_SYMBOL_GPL(snd_soc_component_set_pll);
  94. void snd_soc_component_seq_notifier(struct snd_soc_component *component,
  95. enum snd_soc_dapm_type type, int subseq)
  96. {
  97. if (component->driver->seq_notifier)
  98. component->driver->seq_notifier(component, type, subseq);
  99. }
  100. int snd_soc_component_stream_event(struct snd_soc_component *component,
  101. int event)
  102. {
  103. int ret = 0;
  104. if (component->driver->stream_event)
  105. ret = component->driver->stream_event(component, event);
  106. return soc_component_ret(component, ret);
  107. }
  108. int snd_soc_component_set_bias_level(struct snd_soc_component *component,
  109. enum snd_soc_bias_level level)
  110. {
  111. int ret = 0;
  112. if (component->driver->set_bias_level)
  113. ret = component->driver->set_bias_level(component, level);
  114. return soc_component_ret(component, ret);
  115. }
  116. int snd_soc_component_enable_pin(struct snd_soc_component *component,
  117. const char *pin)
  118. {
  119. struct snd_soc_dapm_context *dapm =
  120. snd_soc_component_get_dapm(component);
  121. return snd_soc_dapm_enable_pin(dapm, pin);
  122. }
  123. EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
  124. int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
  125. const char *pin)
  126. {
  127. struct snd_soc_dapm_context *dapm =
  128. snd_soc_component_get_dapm(component);
  129. return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
  130. }
  131. EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
  132. int snd_soc_component_disable_pin(struct snd_soc_component *component,
  133. const char *pin)
  134. {
  135. struct snd_soc_dapm_context *dapm =
  136. snd_soc_component_get_dapm(component);
  137. return snd_soc_dapm_disable_pin(dapm, pin);
  138. }
  139. EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
  140. int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
  141. const char *pin)
  142. {
  143. struct snd_soc_dapm_context *dapm =
  144. snd_soc_component_get_dapm(component);
  145. return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
  146. }
  147. EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
  148. int snd_soc_component_nc_pin(struct snd_soc_component *component,
  149. const char *pin)
  150. {
  151. struct snd_soc_dapm_context *dapm =
  152. snd_soc_component_get_dapm(component);
  153. return snd_soc_dapm_nc_pin(dapm, pin);
  154. }
  155. EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
  156. int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
  157. const char *pin)
  158. {
  159. struct snd_soc_dapm_context *dapm =
  160. snd_soc_component_get_dapm(component);
  161. return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
  162. }
  163. EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
  164. int snd_soc_component_get_pin_status(struct snd_soc_component *component,
  165. const char *pin)
  166. {
  167. struct snd_soc_dapm_context *dapm =
  168. snd_soc_component_get_dapm(component);
  169. return snd_soc_dapm_get_pin_status(dapm, pin);
  170. }
  171. EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
  172. int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
  173. const char *pin)
  174. {
  175. struct snd_soc_dapm_context *dapm =
  176. snd_soc_component_get_dapm(component);
  177. return snd_soc_dapm_force_enable_pin(dapm, pin);
  178. }
  179. EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
  180. int snd_soc_component_force_enable_pin_unlocked(
  181. struct snd_soc_component *component,
  182. const char *pin)
  183. {
  184. struct snd_soc_dapm_context *dapm =
  185. snd_soc_component_get_dapm(component);
  186. return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
  187. }
  188. EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);
  189. /**
  190. * snd_soc_component_set_jack - configure component jack.
  191. * @component: COMPONENTs
  192. * @jack: structure to use for the jack
  193. * @data: can be used if codec driver need extra data for configuring jack
  194. *
  195. * Configures and enables jack detection function.
  196. */
  197. int snd_soc_component_set_jack(struct snd_soc_component *component,
  198. struct snd_soc_jack *jack, void *data)
  199. {
  200. int ret = -ENOTSUPP;
  201. if (component->driver->set_jack)
  202. ret = component->driver->set_jack(component, jack, data);
  203. return soc_component_ret(component, ret);
  204. }
  205. EXPORT_SYMBOL_GPL(snd_soc_component_set_jack);
  206. int snd_soc_component_module_get(struct snd_soc_component *component,
  207. struct snd_pcm_substream *substream,
  208. int upon_open)
  209. {
  210. int ret = 0;
  211. if (component->driver->module_get_upon_open == !!upon_open &&
  212. !try_module_get(component->dev->driver->owner))
  213. ret = -ENODEV;
  214. /* mark substream if succeeded */
  215. if (ret == 0)
  216. soc_component_mark_push(component, substream, module);
  217. return soc_component_ret(component, ret);
  218. }
  219. void snd_soc_component_module_put(struct snd_soc_component *component,
  220. struct snd_pcm_substream *substream,
  221. int upon_open, int rollback)
  222. {
  223. if (rollback && !soc_component_mark_match(component, substream, module))
  224. return;
  225. if (component->driver->module_get_upon_open == !!upon_open)
  226. module_put(component->dev->driver->owner);
  227. /* remove marked substream */
  228. soc_component_mark_pop(component, substream, module);
  229. }
  230. int snd_soc_component_open(struct snd_soc_component *component,
  231. struct snd_pcm_substream *substream)
  232. {
  233. int ret = 0;
  234. if (component->driver->open)
  235. ret = component->driver->open(component, substream);
  236. /* mark substream if succeeded */
  237. if (ret == 0)
  238. soc_component_mark_push(component, substream, open);
  239. return soc_component_ret(component, ret);
  240. }
  241. int snd_soc_component_close(struct snd_soc_component *component,
  242. struct snd_pcm_substream *substream,
  243. int rollback)
  244. {
  245. int ret = 0;
  246. if (rollback && !soc_component_mark_match(component, substream, open))
  247. return 0;
  248. if (component->driver->close)
  249. ret = component->driver->close(component, substream);
  250. /* remove marked substream */
  251. soc_component_mark_pop(component, substream, open);
  252. return soc_component_ret(component, ret);
  253. }
  254. void snd_soc_component_suspend(struct snd_soc_component *component)
  255. {
  256. if (component->driver->suspend)
  257. component->driver->suspend(component);
  258. component->suspended = 1;
  259. }
  260. void snd_soc_component_resume(struct snd_soc_component *component)
  261. {
  262. if (component->driver->resume)
  263. component->driver->resume(component);
  264. component->suspended = 0;
  265. }
  266. int snd_soc_component_is_suspended(struct snd_soc_component *component)
  267. {
  268. return component->suspended;
  269. }
  270. int snd_soc_component_probe(struct snd_soc_component *component)
  271. {
  272. int ret = 0;
  273. if (component->driver->probe)
  274. ret = component->driver->probe(component);
  275. return soc_component_ret(component, ret);
  276. }
  277. void snd_soc_component_remove(struct snd_soc_component *component)
  278. {
  279. if (component->driver->remove)
  280. component->driver->remove(component);
  281. }
  282. int snd_soc_component_of_xlate_dai_id(struct snd_soc_component *component,
  283. struct device_node *ep)
  284. {
  285. int ret = -ENOTSUPP;
  286. if (component->driver->of_xlate_dai_id)
  287. ret = component->driver->of_xlate_dai_id(component, ep);
  288. return soc_component_ret(component, ret);
  289. }
  290. int snd_soc_component_of_xlate_dai_name(struct snd_soc_component *component,
  291. struct of_phandle_args *args,
  292. const char **dai_name)
  293. {
  294. if (component->driver->of_xlate_dai_name)
  295. return component->driver->of_xlate_dai_name(component,
  296. args, dai_name);
  297. /*
  298. * Don't use soc_component_ret here because we may not want to report
  299. * the error just yet. If a device has more than one component, the
  300. * first may not match and we don't want spam the log with this.
  301. */
  302. return -ENOTSUPP;
  303. }
  304. void snd_soc_component_setup_regmap(struct snd_soc_component *component)
  305. {
  306. int val_bytes = regmap_get_val_bytes(component->regmap);
  307. /* Errors are legitimate for non-integer byte multiples */
  308. if (val_bytes > 0)
  309. component->val_bytes = val_bytes;
  310. }
  311. #ifdef CONFIG_REGMAP
  312. /**
  313. * snd_soc_component_init_regmap() - Initialize regmap instance for the
  314. * component
  315. * @component: The component for which to initialize the regmap instance
  316. * @regmap: The regmap instance that should be used by the component
  317. *
  318. * This function allows deferred assignment of the regmap instance that is
  319. * associated with the component. Only use this if the regmap instance is not
  320. * yet ready when the component is registered. The function must also be called
  321. * before the first IO attempt of the component.
  322. */
  323. void snd_soc_component_init_regmap(struct snd_soc_component *component,
  324. struct regmap *regmap)
  325. {
  326. component->regmap = regmap;
  327. snd_soc_component_setup_regmap(component);
  328. }
  329. EXPORT_SYMBOL_GPL(snd_soc_component_init_regmap);
  330. /**
  331. * snd_soc_component_exit_regmap() - De-initialize regmap instance for the
  332. * component
  333. * @component: The component for which to de-initialize the regmap instance
  334. *
  335. * Calls regmap_exit() on the regmap instance associated to the component and
  336. * removes the regmap instance from the component.
  337. *
  338. * This function should only be used if snd_soc_component_init_regmap() was used
  339. * to initialize the regmap instance.
  340. */
  341. void snd_soc_component_exit_regmap(struct snd_soc_component *component)
  342. {
  343. regmap_exit(component->regmap);
  344. component->regmap = NULL;
  345. }
  346. EXPORT_SYMBOL_GPL(snd_soc_component_exit_regmap);
  347. #endif
  348. static unsigned int soc_component_read_no_lock(
  349. struct snd_soc_component *component,
  350. unsigned int reg)
  351. {
  352. int ret;
  353. unsigned int val = 0;
  354. if (component->regmap)
  355. ret = regmap_read(component->regmap, reg, &val);
  356. else if (component->driver->read) {
  357. ret = 0;
  358. val = component->driver->read(component, reg);
  359. }
  360. else
  361. ret = -EIO;
  362. if (ret < 0)
  363. return soc_component_ret(component, ret);
  364. return val;
  365. }
  366. /**
  367. * snd_soc_component_read() - Read register value
  368. * @component: Component to read from
  369. * @reg: Register to read
  370. *
  371. * Return: read value
  372. */
  373. unsigned int snd_soc_component_read(struct snd_soc_component *component,
  374. unsigned int reg)
  375. {
  376. unsigned int val;
  377. mutex_lock(&component->io_mutex);
  378. val = soc_component_read_no_lock(component, reg);
  379. mutex_unlock(&component->io_mutex);
  380. return val;
  381. }
  382. EXPORT_SYMBOL_GPL(snd_soc_component_read);
  383. static int soc_component_write_no_lock(
  384. struct snd_soc_component *component,
  385. unsigned int reg, unsigned int val)
  386. {
  387. int ret = -EIO;
  388. if (component->regmap)
  389. ret = regmap_write(component->regmap, reg, val);
  390. else if (component->driver->write)
  391. ret = component->driver->write(component, reg, val);
  392. return soc_component_ret(component, ret);
  393. }
  394. /**
  395. * snd_soc_component_write() - Write register value
  396. * @component: Component to write to
  397. * @reg: Register to write
  398. * @val: Value to write to the register
  399. *
  400. * Return: 0 on success, a negative error code otherwise.
  401. */
  402. int snd_soc_component_write(struct snd_soc_component *component,
  403. unsigned int reg, unsigned int val)
  404. {
  405. int ret;
  406. mutex_lock(&component->io_mutex);
  407. ret = soc_component_write_no_lock(component, reg, val);
  408. mutex_unlock(&component->io_mutex);
  409. return ret;
  410. }
  411. EXPORT_SYMBOL_GPL(snd_soc_component_write);
  412. static int snd_soc_component_update_bits_legacy(
  413. struct snd_soc_component *component, unsigned int reg,
  414. unsigned int mask, unsigned int val, bool *change)
  415. {
  416. unsigned int old, new;
  417. int ret = 0;
  418. mutex_lock(&component->io_mutex);
  419. old = soc_component_read_no_lock(component, reg);
  420. new = (old & ~mask) | (val & mask);
  421. *change = old != new;
  422. if (*change)
  423. ret = soc_component_write_no_lock(component, reg, new);
  424. mutex_unlock(&component->io_mutex);
  425. return soc_component_ret(component, ret);
  426. }
  427. /**
  428. * snd_soc_component_update_bits() - Perform read/modify/write cycle
  429. * @component: Component to update
  430. * @reg: Register to update
  431. * @mask: Mask that specifies which bits to update
  432. * @val: New value for the bits specified by mask
  433. *
  434. * Return: 1 if the operation was successful and the value of the register
  435. * changed, 0 if the operation was successful, but the value did not change.
  436. * Returns a negative error code otherwise.
  437. */
  438. int snd_soc_component_update_bits(struct snd_soc_component *component,
  439. unsigned int reg, unsigned int mask, unsigned int val)
  440. {
  441. bool change;
  442. int ret;
  443. if (component->regmap)
  444. ret = regmap_update_bits_check(component->regmap, reg, mask,
  445. val, &change);
  446. else
  447. ret = snd_soc_component_update_bits_legacy(component, reg,
  448. mask, val, &change);
  449. if (ret < 0)
  450. return soc_component_ret(component, ret);
  451. return change;
  452. }
  453. EXPORT_SYMBOL_GPL(snd_soc_component_update_bits);
  454. /**
  455. * snd_soc_component_update_bits_async() - Perform asynchronous
  456. * read/modify/write cycle
  457. * @component: Component to update
  458. * @reg: Register to update
  459. * @mask: Mask that specifies which bits to update
  460. * @val: New value for the bits specified by mask
  461. *
  462. * This function is similar to snd_soc_component_update_bits(), but the update
  463. * operation is scheduled asynchronously. This means it may not be completed
  464. * when the function returns. To make sure that all scheduled updates have been
  465. * completed snd_soc_component_async_complete() must be called.
  466. *
  467. * Return: 1 if the operation was successful and the value of the register
  468. * changed, 0 if the operation was successful, but the value did not change.
  469. * Returns a negative error code otherwise.
  470. */
  471. int snd_soc_component_update_bits_async(struct snd_soc_component *component,
  472. unsigned int reg, unsigned int mask, unsigned int val)
  473. {
  474. bool change;
  475. int ret;
  476. if (component->regmap)
  477. ret = regmap_update_bits_check_async(component->regmap, reg,
  478. mask, val, &change);
  479. else
  480. ret = snd_soc_component_update_bits_legacy(component, reg,
  481. mask, val, &change);
  482. if (ret < 0)
  483. return soc_component_ret(component, ret);
  484. return change;
  485. }
  486. EXPORT_SYMBOL_GPL(snd_soc_component_update_bits_async);
  487. /**
  488. * snd_soc_component_async_complete() - Ensure asynchronous I/O has completed
  489. * @component: Component for which to wait
  490. *
  491. * This function blocks until all asynchronous I/O which has previously been
  492. * scheduled using snd_soc_component_update_bits_async() has completed.
  493. */
  494. void snd_soc_component_async_complete(struct snd_soc_component *component)
  495. {
  496. if (component->regmap)
  497. regmap_async_complete(component->regmap);
  498. }
  499. EXPORT_SYMBOL_GPL(snd_soc_component_async_complete);
  500. /**
  501. * snd_soc_component_test_bits - Test register for change
  502. * @component: component
  503. * @reg: Register to test
  504. * @mask: Mask that specifies which bits to test
  505. * @value: Value to test against
  506. *
  507. * Tests a register with a new value and checks if the new value is
  508. * different from the old value.
  509. *
  510. * Return: 1 for change, otherwise 0.
  511. */
  512. int snd_soc_component_test_bits(struct snd_soc_component *component,
  513. unsigned int reg, unsigned int mask, unsigned int value)
  514. {
  515. unsigned int old, new;
  516. old = snd_soc_component_read(component, reg);
  517. new = (old & ~mask) | value;
  518. return old != new;
  519. }
  520. EXPORT_SYMBOL_GPL(snd_soc_component_test_bits);
  521. int snd_soc_pcm_component_pointer(struct snd_pcm_substream *substream)
  522. {
  523. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  524. struct snd_soc_component *component;
  525. int i;
  526. /* FIXME: use 1st pointer */
  527. for_each_rtd_components(rtd, i, component)
  528. if (component->driver->pointer)
  529. return component->driver->pointer(component, substream);
  530. return 0;
  531. }
  532. int snd_soc_pcm_component_ioctl(struct snd_pcm_substream *substream,
  533. unsigned int cmd, void *arg)
  534. {
  535. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  536. struct snd_soc_component *component;
  537. int i;
  538. /* FIXME: use 1st ioctl */
  539. for_each_rtd_components(rtd, i, component)
  540. if (component->driver->ioctl)
  541. return soc_component_ret(
  542. component,
  543. component->driver->ioctl(component,
  544. substream, cmd, arg));
  545. return snd_pcm_lib_ioctl(substream, cmd, arg);
  546. }
  547. int snd_soc_pcm_component_sync_stop(struct snd_pcm_substream *substream)
  548. {
  549. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  550. struct snd_soc_component *component;
  551. int i, ret;
  552. for_each_rtd_components(rtd, i, component) {
  553. if (component->driver->sync_stop) {
  554. ret = component->driver->sync_stop(component,
  555. substream);
  556. if (ret < 0)
  557. return soc_component_ret(component, ret);
  558. }
  559. }
  560. return 0;
  561. }
  562. int snd_soc_pcm_component_copy_user(struct snd_pcm_substream *substream,
  563. int channel, unsigned long pos,
  564. void __user *buf, unsigned long bytes)
  565. {
  566. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  567. struct snd_soc_component *component;
  568. int i;
  569. /* FIXME. it returns 1st copy now */
  570. for_each_rtd_components(rtd, i, component)
  571. if (component->driver->copy_user)
  572. return soc_component_ret(
  573. component,
  574. component->driver->copy_user(
  575. component, substream, channel,
  576. pos, buf, bytes));
  577. return -EINVAL;
  578. }
  579. struct page *snd_soc_pcm_component_page(struct snd_pcm_substream *substream,
  580. unsigned long offset)
  581. {
  582. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  583. struct snd_soc_component *component;
  584. struct page *page;
  585. int i;
  586. /* FIXME. it returns 1st page now */
  587. for_each_rtd_components(rtd, i, component) {
  588. if (component->driver->page) {
  589. page = component->driver->page(component,
  590. substream, offset);
  591. if (page)
  592. return page;
  593. }
  594. }
  595. return NULL;
  596. }
  597. int snd_soc_pcm_component_mmap(struct snd_pcm_substream *substream,
  598. struct vm_area_struct *vma)
  599. {
  600. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  601. struct snd_soc_component *component;
  602. int i;
  603. /* FIXME. it returns 1st mmap now */
  604. for_each_rtd_components(rtd, i, component)
  605. if (component->driver->mmap)
  606. return soc_component_ret(
  607. component,
  608. component->driver->mmap(component,
  609. substream, vma));
  610. return -EINVAL;
  611. }
  612. int snd_soc_pcm_component_new(struct snd_soc_pcm_runtime *rtd)
  613. {
  614. struct snd_soc_component *component;
  615. int ret;
  616. int i;
  617. for_each_rtd_components(rtd, i, component) {
  618. if (component->driver->pcm_construct) {
  619. ret = component->driver->pcm_construct(component, rtd);
  620. if (ret < 0)
  621. return soc_component_ret(component, ret);
  622. }
  623. }
  624. return 0;
  625. }
  626. void snd_soc_pcm_component_free(struct snd_soc_pcm_runtime *rtd)
  627. {
  628. struct snd_soc_component *component;
  629. int i;
  630. if (!rtd->pcm)
  631. return;
  632. for_each_rtd_components(rtd, i, component)
  633. if (component->driver->pcm_destruct)
  634. component->driver->pcm_destruct(component, rtd->pcm);
  635. }
  636. int snd_soc_pcm_component_prepare(struct snd_pcm_substream *substream)
  637. {
  638. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  639. struct snd_soc_component *component;
  640. int i, ret;
  641. for_each_rtd_components(rtd, i, component) {
  642. if (component->driver->prepare) {
  643. ret = component->driver->prepare(component, substream);
  644. if (ret < 0)
  645. return soc_component_ret(component, ret);
  646. }
  647. }
  648. return 0;
  649. }
  650. int snd_soc_pcm_component_hw_params(struct snd_pcm_substream *substream,
  651. struct snd_pcm_hw_params *params,
  652. struct snd_soc_component **last)
  653. {
  654. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  655. struct snd_soc_component *component;
  656. int i, ret;
  657. for_each_rtd_components(rtd, i, component) {
  658. if (component->driver->hw_params) {
  659. ret = component->driver->hw_params(component,
  660. substream, params);
  661. if (ret < 0) {
  662. *last = component;
  663. return soc_component_ret(component, ret);
  664. }
  665. }
  666. }
  667. *last = NULL;
  668. return 0;
  669. }
  670. void snd_soc_pcm_component_hw_free(struct snd_pcm_substream *substream,
  671. struct snd_soc_component *last)
  672. {
  673. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  674. struct snd_soc_component *component;
  675. int i, ret;
  676. for_each_rtd_components(rtd, i, component) {
  677. if (component == last)
  678. break;
  679. if (component->driver->hw_free) {
  680. ret = component->driver->hw_free(component, substream);
  681. if (ret < 0)
  682. soc_component_ret(component, ret);
  683. }
  684. }
  685. }
  686. int snd_soc_pcm_component_trigger(struct snd_pcm_substream *substream,
  687. int cmd)
  688. {
  689. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  690. struct snd_soc_component *component;
  691. int i, ret;
  692. for_each_rtd_components(rtd, i, component) {
  693. if (component->driver->trigger) {
  694. ret = component->driver->trigger(component, substream, cmd);
  695. if (ret < 0)
  696. return soc_component_ret(component, ret);
  697. }
  698. }
  699. return 0;
  700. }
  701. int snd_soc_pcm_component_pm_runtime_get(struct snd_soc_pcm_runtime *rtd,
  702. void *stream)
  703. {
  704. struct snd_soc_component *component;
  705. int i, ret;
  706. for_each_rtd_components(rtd, i, component) {
  707. ret = pm_runtime_get_sync(component->dev);
  708. if (ret < 0 && ret != -EACCES) {
  709. pm_runtime_put_noidle(component->dev);
  710. return soc_component_ret(component, ret);
  711. }
  712. /* mark stream if succeeded */
  713. soc_component_mark_push(component, stream, pm);
  714. }
  715. return 0;
  716. }
  717. void snd_soc_pcm_component_pm_runtime_put(struct snd_soc_pcm_runtime *rtd,
  718. void *stream, int rollback)
  719. {
  720. struct snd_soc_component *component;
  721. int i;
  722. for_each_rtd_components(rtd, i, component) {
  723. if (rollback && !soc_component_mark_match(component, stream, pm))
  724. continue;
  725. pm_runtime_mark_last_busy(component->dev);
  726. pm_runtime_put_autosuspend(component->dev);
  727. /* remove marked stream */
  728. soc_component_mark_pop(component, stream, pm);
  729. }
  730. }
  731. int snd_soc_pcm_component_ack(struct snd_pcm_substream *substream)
  732. {
  733. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  734. struct snd_soc_component *component;
  735. int i;
  736. /* FIXME: use 1st pointer */
  737. for_each_rtd_components(rtd, i, component)
  738. if (component->driver->ack)
  739. return component->driver->ack(component, substream);
  740. return 0;
  741. }