core.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  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 src
  75. * |
  76. * +- src
  77. * |
  78. * +- src[0]
  79. * +- src[1]
  80. * +- src[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. static const struct rsnd_of_data rsnd_of_data_gen1 = {
  99. .flags = RSND_GEN1,
  100. };
  101. static const struct rsnd_of_data rsnd_of_data_gen2 = {
  102. .flags = RSND_GEN2,
  103. };
  104. static const struct of_device_id rsnd_of_match[] = {
  105. { .compatible = "renesas,rcar_sound-gen1", .data = &rsnd_of_data_gen1 },
  106. { .compatible = "renesas,rcar_sound-gen2", .data = &rsnd_of_data_gen2 },
  107. {},
  108. };
  109. MODULE_DEVICE_TABLE(of, rsnd_of_match);
  110. /*
  111. * rsnd_platform functions
  112. */
  113. #define rsnd_platform_call(priv, dai, func, param...) \
  114. (!(priv->info->func) ? 0 : \
  115. priv->info->func(param))
  116. #define rsnd_is_enable_path(io, name) \
  117. ((io)->info ? (io)->info->name : NULL)
  118. #define rsnd_info_id(priv, io, name) \
  119. ((io)->info->name - priv->info->name##_info)
  120. /*
  121. * rsnd_mod functions
  122. */
  123. char *rsnd_mod_name(struct rsnd_mod *mod)
  124. {
  125. if (!mod || !mod->ops)
  126. return "unknown";
  127. return mod->ops->name;
  128. }
  129. struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
  130. struct rsnd_mod *mod)
  131. {
  132. if (!mod || !mod->ops || !mod->ops->dma_req)
  133. return NULL;
  134. return mod->ops->dma_req(io, mod);
  135. }
  136. int rsnd_mod_init(struct rsnd_priv *priv,
  137. struct rsnd_mod *mod,
  138. struct rsnd_mod_ops *ops,
  139. struct clk *clk,
  140. enum rsnd_mod_type type,
  141. int id)
  142. {
  143. int ret = clk_prepare(clk);
  144. if (ret)
  145. return ret;
  146. mod->id = id;
  147. mod->ops = ops;
  148. mod->type = type;
  149. mod->clk = clk;
  150. mod->priv = priv;
  151. return ret;
  152. }
  153. void rsnd_mod_quit(struct rsnd_mod *mod)
  154. {
  155. if (mod->clk)
  156. clk_unprepare(mod->clk);
  157. }
  158. void rsnd_mod_interrupt(struct rsnd_mod *mod,
  159. void (*callback)(struct rsnd_mod *mod,
  160. struct rsnd_dai_stream *io))
  161. {
  162. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  163. struct rsnd_dai_stream *io;
  164. struct rsnd_dai *rdai;
  165. int i, j;
  166. for_each_rsnd_dai(rdai, priv, j) {
  167. for (i = 0; i < RSND_MOD_MAX; i++) {
  168. io = &rdai->playback;
  169. if (mod == io->mod[i])
  170. callback(mod, io);
  171. io = &rdai->capture;
  172. if (mod == io->mod[i])
  173. callback(mod, io);
  174. }
  175. }
  176. }
  177. int rsnd_io_is_working(struct rsnd_dai_stream *io)
  178. {
  179. /* see rsnd_dai_stream_init/quit() */
  180. return !!io->substream;
  181. }
  182. /*
  183. * ADINR function
  184. */
  185. u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
  186. {
  187. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  188. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  189. struct device *dev = rsnd_priv_to_dev(priv);
  190. u32 adinr = runtime->channels;
  191. switch (runtime->sample_bits) {
  192. case 16:
  193. adinr |= (8 << 16);
  194. break;
  195. case 32:
  196. adinr |= (0 << 16);
  197. break;
  198. default:
  199. dev_warn(dev, "not supported sample bits\n");
  200. return 0;
  201. }
  202. return adinr;
  203. }
  204. u32 rsnd_get_adinr_chan(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
  205. {
  206. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  207. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  208. struct device *dev = rsnd_priv_to_dev(priv);
  209. u32 chan = runtime->channels;
  210. switch (chan) {
  211. case 1:
  212. case 2:
  213. case 4:
  214. case 6:
  215. case 8:
  216. break;
  217. default:
  218. dev_warn(dev, "not supported channel\n");
  219. chan = 0;
  220. break;
  221. }
  222. return chan;
  223. }
  224. /*
  225. * DALIGN function
  226. */
  227. u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io)
  228. {
  229. struct rsnd_mod *src = rsnd_io_to_mod_src(io);
  230. struct rsnd_mod *ssi = rsnd_io_to_mod_ssi(io);
  231. struct rsnd_mod *target = src ? src : ssi;
  232. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  233. u32 val = 0x76543210;
  234. u32 mask = ~0;
  235. mask <<= runtime->channels * 4;
  236. val = val & mask;
  237. switch (runtime->sample_bits) {
  238. case 16:
  239. val |= 0x67452301 & ~mask;
  240. break;
  241. case 32:
  242. val |= 0x76543210 & ~mask;
  243. break;
  244. }
  245. /*
  246. * exchange channeles on SRC if possible,
  247. * otherwise, R/L volume settings on DVC
  248. * changes inverted channels
  249. */
  250. if (mod == target)
  251. return val;
  252. else
  253. return 0x76543210;
  254. }
  255. /*
  256. * rsnd_dai functions
  257. */
  258. #define __rsnd_mod_call(mod, io, func, param...) \
  259. ({ \
  260. struct rsnd_priv *priv = rsnd_mod_to_priv(mod); \
  261. struct device *dev = rsnd_priv_to_dev(priv); \
  262. u32 mask = 0xF << __rsnd_mod_shift_##func; \
  263. u8 val = (mod->status >> __rsnd_mod_shift_##func) & 0xF; \
  264. u8 add = ((val + __rsnd_mod_add_##func) & 0xF); \
  265. int ret = 0; \
  266. int called = 0; \
  267. if (val == __rsnd_mod_call_##func) { \
  268. called = 1; \
  269. ret = (mod)->ops->func(mod, io, param); \
  270. } \
  271. mod->status = (mod->status & ~mask) + \
  272. (add << __rsnd_mod_shift_##func); \
  273. dev_dbg(dev, "%s[%d] 0x%08x %s\n", \
  274. rsnd_mod_name(mod), rsnd_mod_id(mod), mod->status, \
  275. called ? #func : ""); \
  276. ret; \
  277. })
  278. #define rsnd_mod_call(mod, io, func, param...) \
  279. (!(mod) ? -ENODEV : \
  280. !((mod)->ops->func) ? 0 : \
  281. __rsnd_mod_call(mod, io, func, param))
  282. #define rsnd_dai_call(fn, io, param...) \
  283. ({ \
  284. struct rsnd_mod *mod; \
  285. int ret = 0, i; \
  286. for (i = 0; i < RSND_MOD_MAX; i++) { \
  287. mod = (io)->mod[i]; \
  288. if (!mod) \
  289. continue; \
  290. ret = rsnd_mod_call(mod, io, fn, param); \
  291. if (ret < 0) \
  292. break; \
  293. } \
  294. ret; \
  295. })
  296. static int rsnd_dai_connect(struct rsnd_mod *mod,
  297. struct rsnd_dai_stream *io)
  298. {
  299. struct rsnd_priv *priv;
  300. struct device *dev;
  301. if (!mod)
  302. return -EIO;
  303. priv = rsnd_mod_to_priv(mod);
  304. dev = rsnd_priv_to_dev(priv);
  305. io->mod[mod->type] = mod;
  306. dev_dbg(dev, "%s[%d] is connected to io (%s)\n",
  307. rsnd_mod_name(mod), rsnd_mod_id(mod),
  308. rsnd_io_is_play(io) ? "Playback" : "Capture");
  309. return 0;
  310. }
  311. static void rsnd_dai_disconnect(struct rsnd_mod *mod,
  312. struct rsnd_dai_stream *io)
  313. {
  314. io->mod[mod->type] = NULL;
  315. }
  316. struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id)
  317. {
  318. if ((id < 0) || (id >= rsnd_rdai_nr(priv)))
  319. return NULL;
  320. return priv->rdai + id;
  321. }
  322. #define rsnd_dai_to_priv(dai) snd_soc_dai_get_drvdata(dai)
  323. static struct rsnd_dai *rsnd_dai_to_rdai(struct snd_soc_dai *dai)
  324. {
  325. struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
  326. return rsnd_rdai_get(priv, dai->id);
  327. }
  328. /*
  329. * rsnd_soc_dai functions
  330. */
  331. int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional)
  332. {
  333. struct snd_pcm_substream *substream = io->substream;
  334. struct snd_pcm_runtime *runtime = substream->runtime;
  335. int pos = io->byte_pos + additional;
  336. pos %= (runtime->periods * io->byte_per_period);
  337. return pos;
  338. }
  339. bool rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int byte)
  340. {
  341. io->byte_pos += byte;
  342. if (io->byte_pos >= io->next_period_byte) {
  343. struct snd_pcm_substream *substream = io->substream;
  344. struct snd_pcm_runtime *runtime = substream->runtime;
  345. io->period_pos++;
  346. io->next_period_byte += io->byte_per_period;
  347. if (io->period_pos >= runtime->periods) {
  348. io->byte_pos = 0;
  349. io->period_pos = 0;
  350. io->next_period_byte = io->byte_per_period;
  351. }
  352. return true;
  353. }
  354. return false;
  355. }
  356. void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io)
  357. {
  358. struct snd_pcm_substream *substream = io->substream;
  359. /*
  360. * this function should be called...
  361. *
  362. * - if rsnd_dai_pointer_update() returns true
  363. * - without spin lock
  364. */
  365. snd_pcm_period_elapsed(substream);
  366. }
  367. static void rsnd_dai_stream_init(struct rsnd_dai_stream *io,
  368. struct snd_pcm_substream *substream)
  369. {
  370. struct snd_pcm_runtime *runtime = substream->runtime;
  371. io->substream = substream;
  372. io->byte_pos = 0;
  373. io->period_pos = 0;
  374. io->byte_per_period = runtime->period_size *
  375. runtime->channels *
  376. samples_to_bytes(runtime, 1);
  377. io->next_period_byte = io->byte_per_period;
  378. }
  379. static void rsnd_dai_stream_quit(struct rsnd_dai_stream *io)
  380. {
  381. io->substream = NULL;
  382. }
  383. static
  384. struct snd_soc_dai *rsnd_substream_to_dai(struct snd_pcm_substream *substream)
  385. {
  386. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  387. return rtd->cpu_dai;
  388. }
  389. static
  390. struct rsnd_dai_stream *rsnd_rdai_to_io(struct rsnd_dai *rdai,
  391. struct snd_pcm_substream *substream)
  392. {
  393. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  394. return &rdai->playback;
  395. else
  396. return &rdai->capture;
  397. }
  398. static int rsnd_soc_dai_trigger(struct snd_pcm_substream *substream, int cmd,
  399. struct snd_soc_dai *dai)
  400. {
  401. struct rsnd_priv *priv = rsnd_dai_to_priv(dai);
  402. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  403. struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
  404. int ssi_id = rsnd_mod_id(rsnd_io_to_mod_ssi(io));
  405. int ret;
  406. unsigned long flags;
  407. spin_lock_irqsave(&priv->lock, flags);
  408. switch (cmd) {
  409. case SNDRV_PCM_TRIGGER_START:
  410. rsnd_dai_stream_init(io, substream);
  411. ret = rsnd_platform_call(priv, dai, start, ssi_id);
  412. if (ret < 0)
  413. goto dai_trigger_end;
  414. ret = rsnd_dai_call(init, io, priv);
  415. if (ret < 0)
  416. goto dai_trigger_end;
  417. ret = rsnd_dai_call(start, io, priv);
  418. if (ret < 0)
  419. goto dai_trigger_end;
  420. break;
  421. case SNDRV_PCM_TRIGGER_STOP:
  422. ret = rsnd_dai_call(stop, io, priv);
  423. if (ret < 0)
  424. goto dai_trigger_end;
  425. ret = rsnd_dai_call(quit, io, priv);
  426. if (ret < 0)
  427. goto dai_trigger_end;
  428. ret = rsnd_platform_call(priv, dai, stop, ssi_id);
  429. if (ret < 0)
  430. goto dai_trigger_end;
  431. rsnd_dai_stream_quit(io);
  432. break;
  433. default:
  434. ret = -EINVAL;
  435. }
  436. dai_trigger_end:
  437. spin_unlock_irqrestore(&priv->lock, flags);
  438. return ret;
  439. }
  440. static int rsnd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  441. {
  442. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  443. /* set master/slave audio interface */
  444. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  445. case SND_SOC_DAIFMT_CBM_CFM:
  446. rdai->clk_master = 0;
  447. break;
  448. case SND_SOC_DAIFMT_CBS_CFS:
  449. rdai->clk_master = 1; /* codec is slave, cpu is master */
  450. break;
  451. default:
  452. return -EINVAL;
  453. }
  454. /* set format */
  455. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  456. case SND_SOC_DAIFMT_I2S:
  457. rdai->sys_delay = 0;
  458. rdai->data_alignment = 0;
  459. rdai->frm_clk_inv = 0;
  460. break;
  461. case SND_SOC_DAIFMT_LEFT_J:
  462. rdai->sys_delay = 1;
  463. rdai->data_alignment = 0;
  464. rdai->frm_clk_inv = 1;
  465. break;
  466. case SND_SOC_DAIFMT_RIGHT_J:
  467. rdai->sys_delay = 1;
  468. rdai->data_alignment = 1;
  469. rdai->frm_clk_inv = 1;
  470. break;
  471. }
  472. /* set clock inversion */
  473. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  474. case SND_SOC_DAIFMT_NB_IF:
  475. rdai->bit_clk_inv = rdai->bit_clk_inv;
  476. rdai->frm_clk_inv = !rdai->frm_clk_inv;
  477. break;
  478. case SND_SOC_DAIFMT_IB_NF:
  479. rdai->bit_clk_inv = !rdai->bit_clk_inv;
  480. rdai->frm_clk_inv = rdai->frm_clk_inv;
  481. break;
  482. case SND_SOC_DAIFMT_IB_IF:
  483. rdai->bit_clk_inv = !rdai->bit_clk_inv;
  484. rdai->frm_clk_inv = !rdai->frm_clk_inv;
  485. break;
  486. case SND_SOC_DAIFMT_NB_NF:
  487. default:
  488. break;
  489. }
  490. return 0;
  491. }
  492. static const struct snd_soc_dai_ops rsnd_soc_dai_ops = {
  493. .trigger = rsnd_soc_dai_trigger,
  494. .set_fmt = rsnd_soc_dai_set_fmt,
  495. };
  496. #define rsnd_path_add(priv, io, type) \
  497. ({ \
  498. struct rsnd_mod *mod; \
  499. int ret = 0; \
  500. int id = -1; \
  501. \
  502. if (rsnd_is_enable_path(io, type)) { \
  503. id = rsnd_info_id(priv, io, type); \
  504. if (id >= 0) { \
  505. mod = rsnd_##type##_mod_get(priv, id); \
  506. ret = rsnd_dai_connect(mod, io); \
  507. } \
  508. } \
  509. ret; \
  510. })
  511. #define rsnd_path_remove(priv, io, type) \
  512. { \
  513. struct rsnd_mod *mod; \
  514. int id = -1; \
  515. \
  516. if (rsnd_is_enable_path(io, type)) { \
  517. id = rsnd_info_id(priv, io, type); \
  518. if (id >= 0) { \
  519. mod = rsnd_##type##_mod_get(priv, id); \
  520. rsnd_dai_disconnect(mod, io); \
  521. } \
  522. } \
  523. }
  524. void rsnd_path_parse(struct rsnd_priv *priv,
  525. struct rsnd_dai_stream *io)
  526. {
  527. struct rsnd_mod *dvc = rsnd_io_to_mod_dvc(io);
  528. struct rsnd_mod *mix = rsnd_io_to_mod_mix(io);
  529. struct rsnd_mod *src = rsnd_io_to_mod_src(io);
  530. struct rsnd_mod *cmd;
  531. struct device *dev = rsnd_priv_to_dev(priv);
  532. u32 data;
  533. /* Gen1 is not supported */
  534. if (rsnd_is_gen1(priv))
  535. return;
  536. if (!mix && !dvc)
  537. return;
  538. if (mix) {
  539. struct rsnd_dai *rdai;
  540. int i;
  541. u32 path[] = {
  542. [0] = 0,
  543. [1] = 1 << 0,
  544. [2] = 0,
  545. [3] = 0,
  546. [4] = 0,
  547. [5] = 1 << 8
  548. };
  549. /*
  550. * it is assuming that integrater is well understanding about
  551. * data path. Here doesn't check impossible connection,
  552. * like src2 + src5
  553. */
  554. data = 0;
  555. for_each_rsnd_dai(rdai, priv, i) {
  556. io = &rdai->playback;
  557. if (mix == rsnd_io_to_mod_mix(io))
  558. data |= path[rsnd_mod_id(src)];
  559. io = &rdai->capture;
  560. if (mix == rsnd_io_to_mod_mix(io))
  561. data |= path[rsnd_mod_id(src)];
  562. }
  563. /*
  564. * We can't use ctu = rsnd_io_ctu() here.
  565. * Since, ID of dvc/mix are 0 or 1 (= same as CMD number)
  566. * but ctu IDs are 0 - 7 (= CTU00 - CTU13)
  567. */
  568. cmd = mix;
  569. } else {
  570. u32 path[] = {
  571. [0] = 0x30000,
  572. [1] = 0x30001,
  573. [2] = 0x40000,
  574. [3] = 0x10000,
  575. [4] = 0x20000,
  576. [5] = 0x40100
  577. };
  578. data = path[rsnd_mod_id(src)];
  579. cmd = dvc;
  580. }
  581. dev_dbg(dev, "ctu/mix path = 0x%08x", data);
  582. rsnd_mod_write(cmd, CMD_ROUTE_SLCT, data);
  583. rsnd_mod_write(cmd, CMD_CTRL, 0x10);
  584. }
  585. static int rsnd_path_init(struct rsnd_priv *priv,
  586. struct rsnd_dai *rdai,
  587. struct rsnd_dai_stream *io)
  588. {
  589. int ret;
  590. /*
  591. * Gen1 is created by SRU/SSI, and this SRU is base module of
  592. * Gen2's SCU/SSIU/SSI. (Gen2 SCU/SSIU came from SRU)
  593. *
  594. * Easy image is..
  595. * Gen1 SRU = Gen2 SCU + SSIU + etc
  596. *
  597. * Gen2 SCU path is very flexible, but, Gen1 SRU (SCU parts) is
  598. * using fixed path.
  599. */
  600. /* SSI */
  601. ret = rsnd_path_add(priv, io, ssi);
  602. if (ret < 0)
  603. return ret;
  604. /* SRC */
  605. ret = rsnd_path_add(priv, io, src);
  606. if (ret < 0)
  607. return ret;
  608. /* CTU */
  609. ret = rsnd_path_add(priv, io, ctu);
  610. if (ret < 0)
  611. return ret;
  612. /* MIX */
  613. ret = rsnd_path_add(priv, io, mix);
  614. if (ret < 0)
  615. return ret;
  616. /* DVC */
  617. ret = rsnd_path_add(priv, io, dvc);
  618. if (ret < 0)
  619. return ret;
  620. return ret;
  621. }
  622. static void rsnd_of_parse_dai(struct platform_device *pdev,
  623. const struct rsnd_of_data *of_data,
  624. struct rsnd_priv *priv)
  625. {
  626. struct device_node *dai_node, *dai_np;
  627. struct device_node *ssi_node, *ssi_np;
  628. struct device_node *src_node, *src_np;
  629. struct device_node *ctu_node, *ctu_np;
  630. struct device_node *mix_node, *mix_np;
  631. struct device_node *dvc_node, *dvc_np;
  632. struct device_node *playback, *capture;
  633. struct rsnd_dai_platform_info *dai_info;
  634. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  635. struct device *dev = &pdev->dev;
  636. int nr, i;
  637. int dai_i, ssi_i, src_i, ctu_i, mix_i, dvc_i;
  638. if (!of_data)
  639. return;
  640. dai_node = of_get_child_by_name(dev->of_node, "rcar_sound,dai");
  641. if (!dai_node)
  642. return;
  643. nr = of_get_child_count(dai_node);
  644. if (!nr)
  645. return;
  646. dai_info = devm_kzalloc(dev,
  647. sizeof(struct rsnd_dai_platform_info) * nr,
  648. GFP_KERNEL);
  649. if (!dai_info) {
  650. dev_err(dev, "dai info allocation error\n");
  651. return;
  652. }
  653. info->dai_info_nr = nr;
  654. info->dai_info = dai_info;
  655. ssi_node = of_get_child_by_name(dev->of_node, "rcar_sound,ssi");
  656. src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
  657. ctu_node = of_get_child_by_name(dev->of_node, "rcar_sound,ctu");
  658. mix_node = of_get_child_by_name(dev->of_node, "rcar_sound,mix");
  659. dvc_node = of_get_child_by_name(dev->of_node, "rcar_sound,dvc");
  660. #define mod_parse(name) \
  661. if (name##_node) { \
  662. struct rsnd_##name##_platform_info *name##_info; \
  663. \
  664. name##_i = 0; \
  665. for_each_child_of_node(name##_node, name##_np) { \
  666. name##_info = info->name##_info + name##_i; \
  667. \
  668. if (name##_np == playback) \
  669. dai_info->playback.name = name##_info; \
  670. if (name##_np == capture) \
  671. dai_info->capture.name = name##_info; \
  672. \
  673. name##_i++; \
  674. } \
  675. }
  676. /*
  677. * parse all dai
  678. */
  679. dai_i = 0;
  680. for_each_child_of_node(dai_node, dai_np) {
  681. dai_info = info->dai_info + dai_i;
  682. for (i = 0;; i++) {
  683. playback = of_parse_phandle(dai_np, "playback", i);
  684. capture = of_parse_phandle(dai_np, "capture", i);
  685. if (!playback && !capture)
  686. break;
  687. mod_parse(ssi);
  688. mod_parse(src);
  689. mod_parse(ctu);
  690. mod_parse(mix);
  691. mod_parse(dvc);
  692. of_node_put(playback);
  693. of_node_put(capture);
  694. }
  695. dai_i++;
  696. }
  697. }
  698. static int rsnd_dai_probe(struct platform_device *pdev,
  699. const struct rsnd_of_data *of_data,
  700. struct rsnd_priv *priv)
  701. {
  702. struct snd_soc_dai_driver *drv;
  703. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  704. struct rsnd_dai *rdai;
  705. struct rsnd_ssi_platform_info *pmod, *cmod;
  706. struct device *dev = rsnd_priv_to_dev(priv);
  707. int dai_nr;
  708. int i;
  709. rsnd_of_parse_dai(pdev, of_data, priv);
  710. dai_nr = info->dai_info_nr;
  711. if (!dai_nr) {
  712. dev_err(dev, "no dai\n");
  713. return -EIO;
  714. }
  715. drv = devm_kzalloc(dev, sizeof(*drv) * dai_nr, GFP_KERNEL);
  716. rdai = devm_kzalloc(dev, sizeof(*rdai) * dai_nr, GFP_KERNEL);
  717. if (!drv || !rdai) {
  718. dev_err(dev, "dai allocate failed\n");
  719. return -ENOMEM;
  720. }
  721. priv->rdai_nr = dai_nr;
  722. priv->daidrv = drv;
  723. priv->rdai = rdai;
  724. for (i = 0; i < dai_nr; i++) {
  725. pmod = info->dai_info[i].playback.ssi;
  726. cmod = info->dai_info[i].capture.ssi;
  727. /*
  728. * init rsnd_dai
  729. */
  730. snprintf(rdai[i].name, RSND_DAI_NAME_SIZE, "rsnd-dai.%d", i);
  731. rdai[i].priv = priv;
  732. /*
  733. * init snd_soc_dai_driver
  734. */
  735. drv[i].name = rdai[i].name;
  736. drv[i].ops = &rsnd_soc_dai_ops;
  737. if (pmod) {
  738. snprintf(rdai[i].playback.name, RSND_DAI_NAME_SIZE,
  739. "DAI%d Playback", i);
  740. drv[i].playback.rates = RSND_RATES;
  741. drv[i].playback.formats = RSND_FMTS;
  742. drv[i].playback.channels_min = 2;
  743. drv[i].playback.channels_max = 2;
  744. drv[i].playback.stream_name = rdai[i].playback.name;
  745. rdai[i].playback.info = &info->dai_info[i].playback;
  746. rdai[i].playback.rdai = rdai + i;
  747. rsnd_path_init(priv, &rdai[i], &rdai[i].playback);
  748. }
  749. if (cmod) {
  750. snprintf(rdai[i].capture.name, RSND_DAI_NAME_SIZE,
  751. "DAI%d Capture", i);
  752. drv[i].capture.rates = RSND_RATES;
  753. drv[i].capture.formats = RSND_FMTS;
  754. drv[i].capture.channels_min = 2;
  755. drv[i].capture.channels_max = 2;
  756. drv[i].capture.stream_name = rdai[i].capture.name;
  757. rdai[i].capture.info = &info->dai_info[i].capture;
  758. rdai[i].capture.rdai = rdai + i;
  759. rsnd_path_init(priv, &rdai[i], &rdai[i].capture);
  760. }
  761. dev_dbg(dev, "%s (%s/%s)\n", rdai[i].name,
  762. pmod ? "play" : " -- ",
  763. cmod ? "capture" : " -- ");
  764. }
  765. return 0;
  766. }
  767. /*
  768. * pcm ops
  769. */
  770. static struct snd_pcm_hardware rsnd_pcm_hardware = {
  771. .info = SNDRV_PCM_INFO_INTERLEAVED |
  772. SNDRV_PCM_INFO_MMAP |
  773. SNDRV_PCM_INFO_MMAP_VALID,
  774. .buffer_bytes_max = 64 * 1024,
  775. .period_bytes_min = 32,
  776. .period_bytes_max = 8192,
  777. .periods_min = 1,
  778. .periods_max = 32,
  779. .fifo_size = 256,
  780. };
  781. static int rsnd_pcm_open(struct snd_pcm_substream *substream)
  782. {
  783. struct snd_pcm_runtime *runtime = substream->runtime;
  784. int ret = 0;
  785. snd_soc_set_runtime_hwparams(substream, &rsnd_pcm_hardware);
  786. ret = snd_pcm_hw_constraint_integer(runtime,
  787. SNDRV_PCM_HW_PARAM_PERIODS);
  788. return ret;
  789. }
  790. static int rsnd_hw_params(struct snd_pcm_substream *substream,
  791. struct snd_pcm_hw_params *hw_params)
  792. {
  793. struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
  794. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  795. struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
  796. int ret;
  797. ret = rsnd_dai_call(hw_params, io, substream, hw_params);
  798. if (ret)
  799. return ret;
  800. return snd_pcm_lib_malloc_pages(substream,
  801. params_buffer_bytes(hw_params));
  802. }
  803. static snd_pcm_uframes_t rsnd_pointer(struct snd_pcm_substream *substream)
  804. {
  805. struct snd_pcm_runtime *runtime = substream->runtime;
  806. struct snd_soc_dai *dai = rsnd_substream_to_dai(substream);
  807. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  808. struct rsnd_dai_stream *io = rsnd_rdai_to_io(rdai, substream);
  809. return bytes_to_frames(runtime, io->byte_pos);
  810. }
  811. static struct snd_pcm_ops rsnd_pcm_ops = {
  812. .open = rsnd_pcm_open,
  813. .ioctl = snd_pcm_lib_ioctl,
  814. .hw_params = rsnd_hw_params,
  815. .hw_free = snd_pcm_lib_free_pages,
  816. .pointer = rsnd_pointer,
  817. };
  818. /*
  819. * snd_kcontrol
  820. */
  821. #define kcontrol_to_cfg(kctrl) ((struct rsnd_kctrl_cfg *)kctrl->private_value)
  822. static int rsnd_kctrl_info(struct snd_kcontrol *kctrl,
  823. struct snd_ctl_elem_info *uinfo)
  824. {
  825. struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
  826. if (cfg->texts) {
  827. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  828. uinfo->count = cfg->size;
  829. uinfo->value.enumerated.items = cfg->max;
  830. if (uinfo->value.enumerated.item >= cfg->max)
  831. uinfo->value.enumerated.item = cfg->max - 1;
  832. strlcpy(uinfo->value.enumerated.name,
  833. cfg->texts[uinfo->value.enumerated.item],
  834. sizeof(uinfo->value.enumerated.name));
  835. } else {
  836. uinfo->count = cfg->size;
  837. uinfo->value.integer.min = 0;
  838. uinfo->value.integer.max = cfg->max;
  839. uinfo->type = (cfg->max == 1) ?
  840. SNDRV_CTL_ELEM_TYPE_BOOLEAN :
  841. SNDRV_CTL_ELEM_TYPE_INTEGER;
  842. }
  843. return 0;
  844. }
  845. static int rsnd_kctrl_get(struct snd_kcontrol *kctrl,
  846. struct snd_ctl_elem_value *uc)
  847. {
  848. struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
  849. int i;
  850. for (i = 0; i < cfg->size; i++)
  851. if (cfg->texts)
  852. uc->value.enumerated.item[i] = cfg->val[i];
  853. else
  854. uc->value.integer.value[i] = cfg->val[i];
  855. return 0;
  856. }
  857. static int rsnd_kctrl_put(struct snd_kcontrol *kctrl,
  858. struct snd_ctl_elem_value *uc)
  859. {
  860. struct rsnd_mod *mod = snd_kcontrol_chip(kctrl);
  861. struct rsnd_kctrl_cfg *cfg = kcontrol_to_cfg(kctrl);
  862. int i, change = 0;
  863. for (i = 0; i < cfg->size; i++) {
  864. if (cfg->texts) {
  865. change |= (uc->value.enumerated.item[i] != cfg->val[i]);
  866. cfg->val[i] = uc->value.enumerated.item[i];
  867. } else {
  868. change |= (uc->value.integer.value[i] != cfg->val[i]);
  869. cfg->val[i] = uc->value.integer.value[i];
  870. }
  871. }
  872. if (change)
  873. cfg->update(cfg->io, mod);
  874. return change;
  875. }
  876. static int __rsnd_kctrl_new(struct rsnd_mod *mod,
  877. struct rsnd_dai_stream *io,
  878. struct snd_soc_pcm_runtime *rtd,
  879. const unsigned char *name,
  880. struct rsnd_kctrl_cfg *cfg,
  881. void (*update)(struct rsnd_dai_stream *io,
  882. struct rsnd_mod *mod))
  883. {
  884. struct snd_soc_card *soc_card = rtd->card;
  885. struct snd_card *card = rtd->card->snd_card;
  886. struct snd_kcontrol *kctrl;
  887. struct snd_kcontrol_new knew = {
  888. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  889. .name = name,
  890. .info = rsnd_kctrl_info,
  891. .index = rtd - soc_card->rtd,
  892. .get = rsnd_kctrl_get,
  893. .put = rsnd_kctrl_put,
  894. .private_value = (unsigned long)cfg,
  895. };
  896. int ret;
  897. kctrl = snd_ctl_new1(&knew, mod);
  898. if (!kctrl)
  899. return -ENOMEM;
  900. ret = snd_ctl_add(card, kctrl);
  901. if (ret < 0) {
  902. snd_ctl_free_one(kctrl);
  903. return ret;
  904. }
  905. cfg->update = update;
  906. cfg->card = card;
  907. cfg->kctrl = kctrl;
  908. cfg->io = io;
  909. return 0;
  910. }
  911. void _rsnd_kctrl_remove(struct rsnd_kctrl_cfg *cfg)
  912. {
  913. snd_ctl_remove(cfg->card, cfg->kctrl);
  914. }
  915. int rsnd_kctrl_new_m(struct rsnd_mod *mod,
  916. struct rsnd_dai_stream *io,
  917. struct snd_soc_pcm_runtime *rtd,
  918. const unsigned char *name,
  919. void (*update)(struct rsnd_dai_stream *io,
  920. struct rsnd_mod *mod),
  921. struct rsnd_kctrl_cfg_m *_cfg,
  922. u32 max)
  923. {
  924. _cfg->cfg.max = max;
  925. _cfg->cfg.size = RSND_DVC_CHANNELS;
  926. _cfg->cfg.val = _cfg->val;
  927. return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
  928. }
  929. int rsnd_kctrl_new_s(struct rsnd_mod *mod,
  930. struct rsnd_dai_stream *io,
  931. struct snd_soc_pcm_runtime *rtd,
  932. const unsigned char *name,
  933. void (*update)(struct rsnd_dai_stream *io,
  934. struct rsnd_mod *mod),
  935. struct rsnd_kctrl_cfg_s *_cfg,
  936. u32 max)
  937. {
  938. _cfg->cfg.max = max;
  939. _cfg->cfg.size = 1;
  940. _cfg->cfg.val = &_cfg->val;
  941. return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
  942. }
  943. int rsnd_kctrl_new_e(struct rsnd_mod *mod,
  944. struct rsnd_dai_stream *io,
  945. struct snd_soc_pcm_runtime *rtd,
  946. const unsigned char *name,
  947. struct rsnd_kctrl_cfg_s *_cfg,
  948. void (*update)(struct rsnd_dai_stream *io,
  949. struct rsnd_mod *mod),
  950. const char * const *texts,
  951. u32 max)
  952. {
  953. _cfg->cfg.max = max;
  954. _cfg->cfg.size = 1;
  955. _cfg->cfg.val = &_cfg->val;
  956. _cfg->cfg.texts = texts;
  957. return __rsnd_kctrl_new(mod, io, rtd, name, &_cfg->cfg, update);
  958. }
  959. /*
  960. * snd_soc_platform
  961. */
  962. #define PREALLOC_BUFFER (32 * 1024)
  963. #define PREALLOC_BUFFER_MAX (32 * 1024)
  964. static int rsnd_pcm_new(struct snd_soc_pcm_runtime *rtd)
  965. {
  966. struct snd_soc_dai *dai = rtd->cpu_dai;
  967. struct rsnd_dai *rdai = rsnd_dai_to_rdai(dai);
  968. int ret;
  969. ret = rsnd_dai_call(pcm_new, &rdai->playback, rtd);
  970. if (ret)
  971. return ret;
  972. ret = rsnd_dai_call(pcm_new, &rdai->capture, rtd);
  973. if (ret)
  974. return ret;
  975. return snd_pcm_lib_preallocate_pages_for_all(
  976. rtd->pcm,
  977. SNDRV_DMA_TYPE_DEV,
  978. rtd->card->snd_card->dev,
  979. PREALLOC_BUFFER, PREALLOC_BUFFER_MAX);
  980. }
  981. static struct snd_soc_platform_driver rsnd_soc_platform = {
  982. .ops = &rsnd_pcm_ops,
  983. .pcm_new = rsnd_pcm_new,
  984. };
  985. static const struct snd_soc_component_driver rsnd_soc_component = {
  986. .name = "rsnd",
  987. };
  988. static int rsnd_rdai_continuance_probe(struct rsnd_priv *priv,
  989. struct rsnd_dai_stream *io)
  990. {
  991. int ret;
  992. ret = rsnd_dai_call(probe, io, priv);
  993. if (ret == -EAGAIN) {
  994. /*
  995. * Fallback to PIO mode
  996. */
  997. /*
  998. * call "remove" for SSI/SRC/DVC
  999. * SSI will be switch to PIO mode if it was DMA mode
  1000. * see
  1001. * rsnd_dma_init()
  1002. * rsnd_ssi_fallback()
  1003. */
  1004. rsnd_dai_call(remove, io, priv);
  1005. /*
  1006. * remove SRC/DVC from DAI,
  1007. */
  1008. rsnd_path_remove(priv, io, src);
  1009. rsnd_path_remove(priv, io, dvc);
  1010. /*
  1011. * fallback
  1012. */
  1013. rsnd_dai_call(fallback, io, priv);
  1014. /*
  1015. * retry to "probe".
  1016. * DAI has SSI which is PIO mode only now.
  1017. */
  1018. ret = rsnd_dai_call(probe, io, priv);
  1019. }
  1020. return ret;
  1021. }
  1022. /*
  1023. * rsnd probe
  1024. */
  1025. static int rsnd_probe(struct platform_device *pdev)
  1026. {
  1027. struct rcar_snd_info *info;
  1028. struct rsnd_priv *priv;
  1029. struct device *dev = &pdev->dev;
  1030. struct rsnd_dai *rdai;
  1031. const struct of_device_id *of_id = of_match_device(rsnd_of_match, dev);
  1032. const struct rsnd_of_data *of_data;
  1033. int (*probe_func[])(struct platform_device *pdev,
  1034. const struct rsnd_of_data *of_data,
  1035. struct rsnd_priv *priv) = {
  1036. rsnd_gen_probe,
  1037. rsnd_dma_probe,
  1038. rsnd_ssi_probe,
  1039. rsnd_src_probe,
  1040. rsnd_ctu_probe,
  1041. rsnd_mix_probe,
  1042. rsnd_dvc_probe,
  1043. rsnd_adg_probe,
  1044. rsnd_dai_probe,
  1045. };
  1046. int ret, i;
  1047. info = NULL;
  1048. of_data = NULL;
  1049. if (of_id) {
  1050. info = devm_kzalloc(&pdev->dev,
  1051. sizeof(struct rcar_snd_info), GFP_KERNEL);
  1052. of_data = of_id->data;
  1053. } else {
  1054. info = pdev->dev.platform_data;
  1055. }
  1056. if (!info) {
  1057. dev_err(dev, "driver needs R-Car sound information\n");
  1058. return -ENODEV;
  1059. }
  1060. /*
  1061. * init priv data
  1062. */
  1063. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  1064. if (!priv) {
  1065. dev_err(dev, "priv allocate failed\n");
  1066. return -ENODEV;
  1067. }
  1068. priv->pdev = pdev;
  1069. priv->info = info;
  1070. spin_lock_init(&priv->lock);
  1071. /*
  1072. * init each module
  1073. */
  1074. for (i = 0; i < ARRAY_SIZE(probe_func); i++) {
  1075. ret = probe_func[i](pdev, of_data, priv);
  1076. if (ret)
  1077. return ret;
  1078. }
  1079. for_each_rsnd_dai(rdai, priv, i) {
  1080. ret = rsnd_rdai_continuance_probe(priv, &rdai->playback);
  1081. if (ret)
  1082. goto exit_snd_probe;
  1083. ret = rsnd_rdai_continuance_probe(priv, &rdai->capture);
  1084. if (ret)
  1085. goto exit_snd_probe;
  1086. }
  1087. dev_set_drvdata(dev, priv);
  1088. /*
  1089. * asoc register
  1090. */
  1091. ret = snd_soc_register_platform(dev, &rsnd_soc_platform);
  1092. if (ret < 0) {
  1093. dev_err(dev, "cannot snd soc register\n");
  1094. return ret;
  1095. }
  1096. ret = snd_soc_register_component(dev, &rsnd_soc_component,
  1097. priv->daidrv, rsnd_rdai_nr(priv));
  1098. if (ret < 0) {
  1099. dev_err(dev, "cannot snd dai register\n");
  1100. goto exit_snd_soc;
  1101. }
  1102. pm_runtime_enable(dev);
  1103. dev_info(dev, "probed\n");
  1104. return ret;
  1105. exit_snd_soc:
  1106. snd_soc_unregister_platform(dev);
  1107. exit_snd_probe:
  1108. for_each_rsnd_dai(rdai, priv, i) {
  1109. rsnd_dai_call(remove, &rdai->playback, priv);
  1110. rsnd_dai_call(remove, &rdai->capture, priv);
  1111. }
  1112. return ret;
  1113. }
  1114. static int rsnd_remove(struct platform_device *pdev)
  1115. {
  1116. struct rsnd_priv *priv = dev_get_drvdata(&pdev->dev);
  1117. struct rsnd_dai *rdai;
  1118. void (*remove_func[])(struct platform_device *pdev,
  1119. struct rsnd_priv *priv) = {
  1120. rsnd_ssi_remove,
  1121. rsnd_src_remove,
  1122. rsnd_ctu_remove,
  1123. rsnd_mix_remove,
  1124. rsnd_dvc_remove,
  1125. };
  1126. int ret = 0, i;
  1127. pm_runtime_disable(&pdev->dev);
  1128. for_each_rsnd_dai(rdai, priv, i) {
  1129. ret |= rsnd_dai_call(remove, &rdai->playback, priv);
  1130. ret |= rsnd_dai_call(remove, &rdai->capture, priv);
  1131. }
  1132. for (i = 0; i < ARRAY_SIZE(remove_func); i++)
  1133. remove_func[i](pdev, priv);
  1134. snd_soc_unregister_component(&pdev->dev);
  1135. snd_soc_unregister_platform(&pdev->dev);
  1136. return ret;
  1137. }
  1138. static struct platform_driver rsnd_driver = {
  1139. .driver = {
  1140. .name = "rcar_sound",
  1141. .of_match_table = rsnd_of_match,
  1142. },
  1143. .probe = rsnd_probe,
  1144. .remove = rsnd_remove,
  1145. };
  1146. module_platform_driver(rsnd_driver);
  1147. MODULE_LICENSE("GPL");
  1148. MODULE_DESCRIPTION("Renesas R-Car audio driver");
  1149. MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");
  1150. MODULE_ALIAS("platform:rcar-pcm-audio");