core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /*
  2. * Renesas R-Car SRU/SCU/SSIU/SSI support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * Based on fsi.c
  8. * Kuninori Morimoto <morimoto.kuninori@renesas.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. /*
  15. * Renesas R-Car sound device structure
  16. *
  17. * Gen1
  18. *
  19. * SRU : Sound Routing Unit
  20. * - SRC : Sampling Rate Converter
  21. * - CMD
  22. * - CTU : Channel Count Conversion Unit
  23. * - MIX : Mixer
  24. * - DVC : Digital Volume and Mute Function
  25. * - SSI : Serial Sound Interface
  26. *
  27. * Gen2
  28. *
  29. * SCU : Sampling Rate Converter Unit
  30. * - SRC : Sampling Rate Converter
  31. * - CMD
  32. * - CTU : Channel Count Conversion Unit
  33. * - MIX : Mixer
  34. * - DVC : Digital Volume and Mute Function
  35. * SSIU : Serial Sound Interface Unit
  36. * - SSI : Serial Sound Interface
  37. */
  38. /*
  39. * driver data Image
  40. *
  41. * rsnd_priv
  42. * |
  43. * | ** this depends on Gen1/Gen2
  44. * |
  45. * +- gen
  46. * |
  47. * | ** these depend on data path
  48. * | ** gen and platform data control it
  49. * |
  50. * +- rdai[0]
  51. * | | sru ssiu ssi
  52. * | +- playback -> [mod] -> [mod] -> [mod] -> ...
  53. * | |
  54. * | | sru ssiu ssi
  55. * | +- capture -> [mod] -> [mod] -> [mod] -> ...
  56. * |
  57. * +- rdai[1]
  58. * | | sru ssiu ssi
  59. * | +- playback -> [mod] -> [mod] -> [mod] -> ...
  60. * | |
  61. * | | sru ssiu ssi
  62. * | +- capture -> [mod] -> [mod] -> [mod] -> ...
  63. * ...
  64. * |
  65. * | ** these control ssi
  66. * |
  67. * +- ssi
  68. * | |
  69. * | +- ssi[0]
  70. * | +- ssi[1]
  71. * | +- ssi[2]
  72. * | ...
  73. * |
  74. * | ** these control scu
  75. * |
  76. * +- scu
  77. * |
  78. * +- scu[0]
  79. * +- scu[1]
  80. * +- scu[2]
  81. * ...
  82. *
  83. *
  84. * for_each_rsnd_dai(xx, priv, xx)
  85. * rdai[0] => rdai[1] => rdai[2] => ...
  86. *
  87. * for_each_rsnd_mod(xx, rdai, xx)
  88. * [mod] => [mod] => [mod] => ...
  89. *
  90. * rsnd_dai_call(xxx, fn )
  91. * [mod]->fn() -> [mod]->fn() -> [mod]->fn()...
  92. *
  93. */
  94. #include <linux/pm_runtime.h>
  95. #include "rsnd.h"
  96. #define RSND_RATES SNDRV_PCM_RATE_8000_96000
  97. #define RSND_FMTS (SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S16_LE)
  98. /*
  99. * rsnd_platform functions
  100. */
  101. #define rsnd_platform_call(priv, dai, func, param...) \
  102. (!(priv->info->func) ? 0 : \
  103. priv->info->func(param))
  104. /*
  105. * rsnd_mod functions
  106. */
  107. char *rsnd_mod_name(struct rsnd_mod *mod)
  108. {
  109. if (!mod || !mod->ops)
  110. return "unknown";
  111. return mod->ops->name;
  112. }
  113. void rsnd_mod_init(struct rsnd_priv *priv,
  114. struct rsnd_mod *mod,
  115. struct rsnd_mod_ops *ops,
  116. int id)
  117. {
  118. mod->priv = priv;
  119. mod->id = id;
  120. mod->ops = ops;
  121. INIT_LIST_HEAD(&mod->list);
  122. }
  123. /*
  124. * rsnd_dma functions
  125. */
  126. static void rsnd_dma_continue(struct rsnd_dma *dma)
  127. {
  128. /* push next A or B plane */
  129. dma->submit_loop = 1;
  130. schedule_work(&dma->work);
  131. }
  132. void rsnd_dma_start(struct rsnd_dma *dma)
  133. {
  134. /* push both A and B plane*/
  135. dma->submit_loop = 2;
  136. schedule_work(&dma->work);
  137. }
  138. void rsnd_dma_stop(struct rsnd_dma *dma)
  139. {
  140. dma->submit_loop = 0;
  141. cancel_work_sync(&dma->work);
  142. dmaengine_terminate_all(dma->chan);
  143. }
  144. static void rsnd_dma_complete(void *data)
  145. {
  146. struct rsnd_dma *dma = (struct rsnd_dma *)data;
  147. struct rsnd_priv *priv = dma->priv;
  148. unsigned long flags;
  149. rsnd_lock(priv, flags);
  150. dma->complete(dma);
  151. if (dma->submit_loop)
  152. rsnd_dma_continue(dma);
  153. rsnd_unlock(priv, flags);
  154. }
  155. static void rsnd_dma_do_work(struct work_struct *work)
  156. {
  157. struct rsnd_dma *dma = container_of(work, struct rsnd_dma, work);
  158. struct rsnd_priv *priv = dma->priv;
  159. struct device *dev = rsnd_priv_to_dev(priv);
  160. struct dma_async_tx_descriptor *desc;
  161. dma_addr_t buf;
  162. size_t len;
  163. int i;
  164. for (i = 0; i < dma->submit_loop; i++) {
  165. if (dma->inquiry(dma, &buf, &len) < 0)
  166. return;
  167. desc = dmaengine_prep_slave_single(
  168. dma->chan, buf, len, dma->dir,
  169. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  170. if (!desc) {
  171. dev_err(dev, "dmaengine_prep_slave_sg() fail\n");
  172. return;
  173. }
  174. desc->callback = rsnd_dma_complete;
  175. desc->callback_param = dma;
  176. if (dmaengine_submit(desc) < 0) {
  177. dev_err(dev, "dmaengine_submit() fail\n");
  178. return;
  179. }
  180. dma_async_issue_pending(dma->chan);
  181. }
  182. }
  183. int rsnd_dma_available(struct rsnd_dma *dma)
  184. {
  185. return !!dma->chan;
  186. }
  187. static bool rsnd_dma_filter(struct dma_chan *chan, void *param)
  188. {
  189. chan->private = param;
  190. return true;
  191. }
  192. int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
  193. int is_play, int id,
  194. int (*inquiry)(struct rsnd_dma *dma,
  195. dma_addr_t *buf, int *len),
  196. int (*complete)(struct rsnd_dma *dma))
  197. {
  198. struct device *dev = rsnd_priv_to_dev(priv);
  199. dma_cap_mask_t mask;
  200. if (dma->chan) {
  201. dev_err(dev, "it already has dma channel\n");
  202. return -EIO;
  203. }
  204. dma_cap_zero(mask);
  205. dma_cap_set(DMA_SLAVE, mask);
  206. dma->slave.shdma_slave.slave_id = id;
  207. dma->chan = dma_request_channel(mask, rsnd_dma_filter,
  208. &dma->slave.shdma_slave);
  209. if (!dma->chan) {
  210. dev_err(dev, "can't get dma channel\n");
  211. return -EIO;
  212. }
  213. dma->dir = is_play ? DMA_TO_DEVICE : DMA_FROM_DEVICE;
  214. dma->priv = priv;
  215. dma->inquiry = inquiry;
  216. dma->complete = complete;
  217. INIT_WORK(&dma->work, rsnd_dma_do_work);
  218. return 0;
  219. }
  220. void rsnd_dma_quit(struct rsnd_priv *priv,
  221. struct rsnd_dma *dma)
  222. {
  223. if (dma->chan)
  224. dma_release_channel(dma->chan);
  225. dma->chan = NULL;
  226. }
  227. /*
  228. * rsnd_dai functions
  229. */
  230. #define rsnd_dai_call(rdai, io, fn) \
  231. ({ \
  232. struct rsnd_mod *mod, *n; \
  233. int ret = 0; \
  234. for_each_rsnd_mod(mod, n, io) { \
  235. ret = rsnd_mod_call(mod, fn, rdai, io); \
  236. if (ret < 0) \
  237. break; \
  238. } \
  239. ret; \
  240. })
  241. int rsnd_dai_connect(struct rsnd_dai *rdai,
  242. struct rsnd_mod *mod,
  243. struct rsnd_dai_stream *io)
  244. {
  245. if (!mod)
  246. return -EIO;
  247. if (!list_empty(&mod->list)) {
  248. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  249. struct device *dev = rsnd_priv_to_dev(priv);
  250. dev_err(dev, "%s%d is not empty\n",
  251. rsnd_mod_name(mod),
  252. rsnd_mod_id(mod));
  253. return -EIO;
  254. }
  255. list_add_tail(&mod->list, &io->head);
  256. return 0;
  257. }
  258. int rsnd_dai_disconnect(struct rsnd_mod *mod)
  259. {
  260. list_del_init(&mod->list);
  261. return 0;
  262. }
  263. int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai)
  264. {
  265. int id = rdai - priv->rdai;
  266. if ((id < 0) || (id >= rsnd_dai_nr(priv)))
  267. return -EINVAL;
  268. return id;
  269. }
  270. struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id)
  271. {
  272. if ((id < 0) || (id >= rsnd_dai_nr(priv)))
  273. return NULL;
  274. return priv->rdai + id;
  275. }
  276. static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
  277. {
  278. struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
  279. return rsnd_dai_get(priv, dai->id);
  280. }
  281. int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io)
  282. {
  283. return &rdai->playback == io;
  284. }
  285. /*
  286. * rsnd_soc_dai functions
  287. */
  288. int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
  289. {
  290. struct snd_pcm_substream *substream = io->substream;
  291. struct snd_pcm_runtime *runtime = substream->runtime;
  292. int pos = io->byte_pos + additional;
  293. pos %= (runtime->periods * io->byte_per_period);
  294. return pos;
  295. }
  296. void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
  297. {
  298. io->byte_pos += byte;
  299. if (io->byte_pos >= io->next_period_byte) {
  300. struct snd_pcm_substream *substream = io->substream;
  301. struct snd_pcm_runtime *runtime = substream->runtime;
  302. io->period_pos++;
  303. io->next_period_byte += io->byte_per_period;
  304. if (io->period_pos >= runtime->periods) {
  305. io->byte_pos = 0;
  306. io->period_pos = 0;
  307. io->next_period_byte = io->byte_per_period;
  308. }
  309. snd_pcm_period_elapsed(substream);
  310. }
  311. }
  312. static int rsnd_dai_stream_init(struct rsnd_dai_stream *io,
  313. struct snd_pcm_substream *substream)
  314. {
  315. struct snd_pcm_runtime *runtime = substream->runtime;
  316. if (!list_empty(&io->head))
  317. return -EIO;
  318. INIT_LIST_HEAD(&io->head);
  319. io->substream = substream;
  320. io->byte_pos = 0;
  321. io->period_pos = 0;
  322. io->byte_per_period = runtime->period_size *
  323. runtime->channels *
  324. samples_to_bytes(runtime, 1);
  325. io->next_period_byte = io->byte_per_period;
  326. return 0;
  327. }
  328. static
  329. struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
  330. {
  331. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  332. return rtd->cpu_dai;
  333. }
  334. static
  335. struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
  336. struct snd_pcm_substream *substream)
  337. {
  338. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  339. return &rdai->playback;
  340. else
  341. return &rdai->capture;
  342. }
  343. static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  344. struct snd_soc_dai *dai)
  345. {
  346. struct rsnd_priv *priv = snd_soc_dai_get_drvdata(dai);
  347. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  348. struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
  349. struct rsnd_mod *mod = rsnd_ssi_mod_get_frm_dai(priv,
  350. rsnd_dai_id(priv, rdai),
  351. rsnd_dai_is_play(rdai, io));
  352. int ssi_id = rsnd_mod_id(mod);
  353. int ret;
  354. unsigned long flags;
  355. rsnd_lock(priv, flags);
  356. switch (cmd) {
  357. case SNDRV_PCM_TRIGGER_START:
  358. ret = rsnd_dai_stream_init(io, substream);
  359. if (ret < 0)
  360. goto dai_trigger_end;
  361. ret = rsnd_platform_call(priv, dai, start, ssi_id);
  362. if (ret < 0)
  363. goto dai_trigger_end;
  364. ret = rsnd_gen_path_init(priv, rdai, io);
  365. if (ret < 0)
  366. goto dai_trigger_end;
  367. ret = rsnd_dai_call(rdai, io, init);
  368. if (ret < 0)
  369. goto dai_trigger_end;
  370. ret = rsnd_dai_call(rdai, io, start);
  371. if (ret < 0)
  372. goto dai_trigger_end;
  373. break;
  374. case SNDRV_PCM_TRIGGER_STOP:
  375. ret = rsnd_dai_call(rdai, io, stop);
  376. if (ret < 0)
  377. goto dai_trigger_end;
  378. ret = rsnd_dai_call(rdai, io, quit);
  379. if (ret < 0)
  380. goto dai_trigger_end;
  381. ret = rsnd_gen_path_exit(priv, rdai, io);
  382. if (ret < 0)
  383. goto dai_trigger_end;
  384. ret = rsnd_platform_call(priv, dai, stop, ssi_id);
  385. if (ret < 0)
  386. goto dai_trigger_end;
  387. break;
  388. default:
  389. ret = -EINVAL;
  390. }
  391. dai_trigger_end:
  392. rsnd_unlock(priv, flags);
  393. return ret;
  394. }
  395. static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  396. {
  397. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  398. /* set master/slave audio interface */
  399. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  400. case SND_SOC_DAIFMT_CBM_CFM:
  401. rdai->clk_master = 1;
  402. break;
  403. case SND_SOC_DAIFMT_CBS_CFS:
  404. rdai->clk_master = 0;
  405. break;
  406. default:
  407. return -EINVAL;
  408. }
  409. /* set clock inversion */
  410. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  411. case SND_SOC_DAIFMT_NB_IF:
  412. rdai->bit_clk_inv = 0;
  413. rdai->frm_clk_inv = 1;
  414. break;
  415. case SND_SOC_DAIFMT_IB_NF:
  416. rdai->bit_clk_inv = 1;
  417. rdai->frm_clk_inv = 0;
  418. break;
  419. case SND_SOC_DAIFMT_IB_IF:
  420. rdai->bit_clk_inv = 1;
  421. rdai->frm_clk_inv = 1;
  422. break;
  423. case SND_SOC_DAIFMT_NB_NF:
  424. default:
  425. rdai->bit_clk_inv = 0;
  426. rdai->frm_clk_inv = 0;
  427. break;
  428. }
  429. /* set format */
  430. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  431. case SND_SOC_DAIFMT_I2S:
  432. rdai->sys_delay = 0;
  433. rdai->data_alignment = 0;
  434. break;
  435. case SND_SOC_DAIFMT_LEFT_J:
  436. rdai->sys_delay = 1;
  437. rdai->data_alignment = 0;
  438. break;
  439. case SND_SOC_DAIFMT_RIGHT_J:
  440. rdai->sys_delay = 1;
  441. rdai->data_alignment = 1;
  442. break;
  443. }
  444. return 0;
  445. }
  446. static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
  447. .trigger = rsnd_soc_dai_trigger,
  448. .set_fmt = rsnd_soc_dai_set_fmt,
  449. };
  450. static int rsnd_dai_probe(struct platform_device *pdev,
  451. struct rcar_snd_info *info,
  452. struct rsnd_priv *priv)
  453. {
  454. struct snd_soc_dai_driver *drv;
  455. struct rsnd_dai *rdai;
  456. struct rsnd_mod *pmod, *cmod;
  457. struct device *dev = rsnd_priv_to_dev(priv);
  458. int dai_nr;
  459. int i;
  460. /* get max dai nr */
  461. for (dai_nr = 0; dai_nr < 32; dai_nr++) {
  462. pmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 1);
  463. cmod = rsnd_ssi_mod_get_frm_dai(priv, dai_nr, 0);
  464. if (!pmod && !cmod)
  465. break;
  466. }
  467. if (!dai_nr) {
  468. dev_err(dev, "no dai\n");
  469. return -EIO;
  470. }
  471. drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL);
  472. rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
  473. if (!drv || !rdai) {
  474. dev_err(dev, "dai allocate failed\n");
  475. return -ENOMEM;
  476. }
  477. for (i = 0; i < dai_nr; i++) {
  478. pmod = rsnd_ssi_mod_get_frm_dai(priv, i, 1);
  479. cmod = rsnd_ssi_mod_get_frm_dai(priv, i, 0);
  480. /*
  481. * init rsnd_dai
  482. */
  483. INIT_LIST_HEAD(&rdai[i].playback.head);
  484. INIT_LIST_HEAD(&rdai[i].capture.head);
  485. snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
  486. /*
  487. * init snd_soc_dai_driver
  488. */
  489. drv[i].name = rdai[i].name;
  490. drv[i].ops = &rsnd_soc_dai_ops;
  491. if (pmod) {
  492. drv[i].playback.rates = RSND_RATES;
  493. drv[i].playback.formats = RSND_FMTS;
  494. drv[i].playback.channels_min = 2;
  495. drv[i].playback.channels_max = 2;
  496. }
  497. if (cmod) {
  498. drv[i].capture.rates = RSND_RATES;
  499. drv[i].capture.formats = RSND_FMTS;
  500. drv[i].capture.channels_min = 2;
  501. drv[i].capture.channels_max = 2;
  502. }
  503. dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
  504. pmod ? "play" : " -- ",
  505. cmod ? "capture" : " -- ");
  506. }
  507. priv->dai_nr = dai_nr;
  508. priv->daidrv = drv;
  509. priv->rdai = rdai;
  510. return 0;
  511. }
  512. static void rsnd_dai_remove(struct platform_device *pdev,
  513. struct rsnd_priv *priv)
  514. {
  515. }
  516. /*
  517. * pcm ops
  518. */
  519. static struct snd_pcm_hardware rsnd_pcm_hardware = {
  520. .info = SNDRV_PCM_INFO_INTERLEAVED |
  521. SNDRV_PCM_INFO_MMAP |
  522. SNDRV_PCM_INFO_MMAP_VALID |
  523. SNDRV_PCM_INFO_PAUSE,
  524. .formats = RSND_FMTS,
  525. .rates = RSND_RATES,
  526. .rate_min = 8000,
  527. .rate_max = 192000,
  528. .channels_min = 2,
  529. .channels_max = 2,
  530. .buffer_bytes_max = 64 * 1024,
  531. .period_bytes_min = 32,
  532. .period_bytes_max = 8192,
  533. .periods_min = 1,
  534. .periods_max = 32,
  535. .fifo_size = 256,
  536. };
  537. static int rsnd_pcm_open(struct snd_pcm_substream *substream)
  538. {
  539. struct snd_pcm_runtime *runtime = substream->runtime;
  540. int ret = 0;
  541. snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
  542. ret = snd_pcm_hw_constraint_integer(runtime,
  543. SNDRV_PCM_HW_PARAM_PERIODS);
  544. return ret;
  545. }
  546. static int rsnd_hw_params(struct snd_pcm_substream *substream,
  547. struct snd_pcm_hw_params *hw_params)
  548. {
  549. return snd_pcm_lib_malloc_pages(substream,
  550. params_buffer_bytes(hw_params));
  551. }
  552. static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
  553. {
  554. struct snd_pcm_runtime *runtime = substream->runtime;
  555. struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
  556. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  557. struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
  558. return bytes_to_frames(runtime, io->byte_pos);
  559. }
  560. static struct snd_pcm_ops rsnd_pcm_ops = {
  561. .open = rsnd_pcm_open,
  562. .ioctl = snd_pcm_lib_ioctl,
  563. .hw_params = rsnd_hw_params,
  564. .hw_free = snd_pcm_lib_free_pages,
  565. .pointer = rsnd_pointer,
  566. };
  567. /*
  568. * snd_soc_platform
  569. */
  570. #define PREALLOC_BUFFER (32 * 1024)
  571. #define PREALLOC_BUFFER_MAX (32 * 1024)
  572. static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
  573. {
  574. return snd_pcm_lib_preallocate_pages_for_all(
  575. rtd->pcm,
  576. SNDRV_DMA_TYPE_DEV,
  577. rtd->card->snd_card->dev,
  578. PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
  579. }
  580. static void rsnd_pcm_free(struct snd_pcm *pcm)
  581. {
  582. snd_pcm_lib_preallocate_free_for_all(pcm);
  583. }
  584. static struct snd_soc_platform_driver rsnd_soc_platform = {
  585. .ops = &rsnd_pcm_ops,
  586. .pcm_new = rsnd_pcm_new,
  587. .pcm_free = rsnd_pcm_free,
  588. };
  589. static const struct snd_soc_component_driver rsnd_soc_component = {
  590. .name = "rsnd",
  591. };
  592. /*
  593. * rsnd probe
  594. */
  595. static int rsnd_probe(struct platform_device *pdev)
  596. {
  597. struct rcar_snd_info *info;
  598. struct rsnd_priv *priv;
  599. struct device *dev = &pdev->dev;
  600. int ret;
  601. info = pdev->dev.platform_data;
  602. if (!info) {
  603. dev_err(dev, "driver needs R-Car sound information\n");
  604. return -ENODEV;
  605. }
  606. /*
  607. * init priv data
  608. */
  609. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  610. if (!priv) {
  611. dev_err(dev, "priv allocate failed\n");
  612. return -ENODEV;
  613. }
  614. priv->dev = dev;
  615. priv->info = info;
  616. spin_lock_init(&priv->lock);
  617. /*
  618. * init each module
  619. */
  620. ret = rsnd_gen_probe(pdev, info, priv);
  621. if (ret < 0)
  622. return ret;
  623. ret = rsnd_scu_probe(pdev, info, priv);
  624. if (ret < 0)
  625. return ret;
  626. ret = rsnd_adg_probe(pdev, info, priv);
  627. if (ret < 0)
  628. return ret;
  629. ret = rsnd_ssi_probe(pdev, info, priv);
  630. if (ret < 0)
  631. return ret;
  632. ret = rsnd_dai_probe(pdev, info, priv);
  633. if (ret < 0)
  634. return ret;
  635. /*
  636. * asoc register
  637. */
  638. ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
  639. if (ret < 0) {
  640. dev_err(dev, "cannot snd soc register\n");
  641. return ret;
  642. }
  643. ret = snd_soc_register_component(dev, &rsnd_soc_component,
  644. priv->daidrv, rsnd_dai_nr(priv));
  645. if (ret < 0) {
  646. dev_err(dev, "cannot snd dai register\n");
  647. goto exit_snd_soc;
  648. }
  649. dev_set_drvdata(dev, priv);
  650. pm_runtime_enable(dev);
  651. dev_info(dev, "probed\n");
  652. return ret;
  653. exit_snd_soc:
  654. snd_soc_unregister_platform(dev);
  655. return ret;
  656. }
  657. static int rsnd_remove(struct platform_device *pdev)
  658. {
  659. struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
  660. pm_runtime_disable(&pdev->dev);
  661. /*
  662. * remove each module
  663. */
  664. rsnd_ssi_remove(pdev, priv);
  665. rsnd_adg_remove(pdev, priv);
  666. rsnd_scu_remove(pdev, priv);
  667. rsnd_dai_remove(pdev, priv);
  668. rsnd_gen_remove(pdev, priv);
  669. return 0;
  670. }
  671. static struct platform_driver rsnd_driver = {
  672. .driver = {
  673. .name = "rcar_sound",
  674. },
  675. .probe = rsnd_probe,
  676. .remove = rsnd_remove,
  677. };
  678. module_platform_driver(rsnd_driver);
  679. MODULE_LICENSE("GPL");
  680. MODULE_DESCRIPTION("Renesas R-Car audio driver");
  681. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
  682. MODULE_ALIAS("platform:rcar-pcm-audio");