core.c 30 KB

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