src.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  1. /*
  2. * Renesas R-Car SRC support
  3. *
  4. * Copyright (C) 2013 Renesas Solutions Corp.
  5. * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include "rsnd.h"
  12. #define SRC_NAME "src"
  13. struct rsnd_src {
  14. struct rsnd_src_platform_info *info; /* rcar_snd.h */
  15. struct rsnd_mod mod;
  16. struct clk *clk;
  17. };
  18. #define RSND_SRC_NAME_SIZE 16
  19. #define rsnd_src_convert_rate(p) ((p)->info->convert_rate)
  20. #define rsnd_mod_to_src(_mod) \
  21. container_of((_mod), struct rsnd_src, mod)
  22. #define rsnd_src_dma_available(src) \
  23. rsnd_dma_available(rsnd_mod_to_dma(&(src)->mod))
  24. #define for_each_rsnd_src(pos, priv, i) \
  25. for ((i) = 0; \
  26. ((i) < rsnd_src_nr(priv)) && \
  27. ((pos) = (struct rsnd_src *)(priv)->src + i); \
  28. i++)
  29. /*
  30. * image of SRC (Sampling Rate Converter)
  31. *
  32. * 96kHz <-> +-----+ 48kHz +-----+ 48kHz +-------+
  33. * 48kHz <-> | SRC | <------> | SSI | <-----> | codec |
  34. * 44.1kHz <-> +-----+ +-----+ +-------+
  35. * ...
  36. *
  37. */
  38. /*
  39. * src.c is caring...
  40. *
  41. * Gen1
  42. *
  43. * [mem] -> [SRU] -> [SSI]
  44. * |--------|
  45. *
  46. * Gen2
  47. *
  48. * [mem] -> [SRC] -> [SSIU] -> [SSI]
  49. * |-----------------|
  50. */
  51. /*
  52. * How to use SRC bypass mode for debugging
  53. *
  54. * SRC has bypass mode, and it is useful for debugging.
  55. * In Gen2 case,
  56. * SRCm_MODE controls whether SRC is used or not
  57. * SSI_MODE0 controls whether SSIU which receives SRC data
  58. * is used or not.
  59. * Both SRCm_MODE/SSI_MODE0 settings are needed if you use SRC,
  60. * but SRC bypass mode needs SSI_MODE0 only.
  61. *
  62. * This driver request
  63. * struct rsnd_src_platform_info {
  64. * u32 convert_rate;
  65. * int dma_id;
  66. * }
  67. *
  68. * rsnd_src_convert_rate() indicates
  69. * above convert_rate, and it controls
  70. * whether SRC is used or not.
  71. *
  72. * ex) doesn't use SRC
  73. * static struct rsnd_dai_platform_info rsnd_dai = {
  74. * .playback = { .ssi = &rsnd_ssi[0], },
  75. * };
  76. *
  77. * ex) uses SRC
  78. * static struct rsnd_src_platform_info rsnd_src[] = {
  79. * RSND_SCU(48000, 0),
  80. * ...
  81. * };
  82. * static struct rsnd_dai_platform_info rsnd_dai = {
  83. * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
  84. * };
  85. *
  86. * ex) uses SRC bypass mode
  87. * static struct rsnd_src_platform_info rsnd_src[] = {
  88. * RSND_SCU(0, 0),
  89. * ...
  90. * };
  91. * static struct rsnd_dai_platform_info rsnd_dai = {
  92. * .playback = { .ssi = &rsnd_ssi[0], .src = &rsnd_src[0] },
  93. * };
  94. *
  95. */
  96. /*
  97. * Gen1/Gen2 common functions
  98. */
  99. int rsnd_src_ssiu_start(struct rsnd_mod *ssi_mod,
  100. struct rsnd_dai *rdai,
  101. int use_busif)
  102. {
  103. struct rsnd_dai_stream *io = rsnd_mod_to_io(ssi_mod);
  104. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  105. int ssi_id = rsnd_mod_id(ssi_mod);
  106. /*
  107. * SSI_MODE0
  108. */
  109. rsnd_mod_bset(ssi_mod, SSI_MODE0, (1 << ssi_id),
  110. !use_busif << ssi_id);
  111. /*
  112. * SSI_MODE1
  113. */
  114. if (rsnd_ssi_is_pin_sharing(ssi_mod)) {
  115. int shift = -1;
  116. switch (ssi_id) {
  117. case 1:
  118. shift = 0;
  119. break;
  120. case 2:
  121. shift = 2;
  122. break;
  123. case 4:
  124. shift = 16;
  125. break;
  126. }
  127. if (shift >= 0)
  128. rsnd_mod_bset(ssi_mod, SSI_MODE1,
  129. 0x3 << shift,
  130. rsnd_dai_is_clk_master(rdai) ?
  131. 0x2 << shift : 0x1 << shift);
  132. }
  133. /*
  134. * DMA settings for SSIU
  135. */
  136. if (use_busif) {
  137. u32 val = 0x76543210;
  138. u32 mask = ~0;
  139. rsnd_mod_write(ssi_mod, SSI_BUSIF_ADINR,
  140. rsnd_get_adinr(ssi_mod));
  141. rsnd_mod_write(ssi_mod, SSI_BUSIF_MODE, 1);
  142. rsnd_mod_write(ssi_mod, SSI_CTRL, 0x1);
  143. mask <<= runtime->channels * 4;
  144. val = val & mask;
  145. switch (runtime->sample_bits) {
  146. case 16:
  147. val |= 0x67452301 & ~mask;
  148. break;
  149. case 32:
  150. val |= 0x76543210 & ~mask;
  151. break;
  152. }
  153. rsnd_mod_write(ssi_mod, BUSIF_DALIGN, val);
  154. }
  155. return 0;
  156. }
  157. int rsnd_src_ssiu_stop(struct rsnd_mod *ssi_mod,
  158. struct rsnd_dai *rdai,
  159. int use_busif)
  160. {
  161. /*
  162. * DMA settings for SSIU
  163. */
  164. if (use_busif)
  165. rsnd_mod_write(ssi_mod, SSI_CTRL, 0);
  166. return 0;
  167. }
  168. int rsnd_src_enable_ssi_irq(struct rsnd_mod *ssi_mod,
  169. struct rsnd_dai *rdai)
  170. {
  171. struct rsnd_priv *priv = rsnd_mod_to_priv(ssi_mod);
  172. /* enable PIO interrupt if Gen2 */
  173. if (rsnd_is_gen2(priv))
  174. rsnd_mod_write(ssi_mod, INT_ENABLE, 0x0f000000);
  175. return 0;
  176. }
  177. unsigned int rsnd_src_get_ssi_rate(struct rsnd_priv *priv,
  178. struct rsnd_dai_stream *io,
  179. struct snd_pcm_runtime *runtime)
  180. {
  181. struct rsnd_mod *src_mod = rsnd_io_to_mod_src(io);
  182. struct rsnd_src *src;
  183. unsigned int rate = 0;
  184. if (src_mod) {
  185. src = rsnd_mod_to_src(src_mod);
  186. /*
  187. * return convert rate if SRC is used,
  188. * otherwise, return runtime->rate as usual
  189. */
  190. rate = rsnd_src_convert_rate(src);
  191. }
  192. if (!rate)
  193. rate = runtime->rate;
  194. return rate;
  195. }
  196. static int rsnd_src_set_convert_rate(struct rsnd_mod *mod,
  197. struct rsnd_dai *rdai)
  198. {
  199. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  200. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  201. struct rsnd_src *src = rsnd_mod_to_src(mod);
  202. u32 convert_rate = rsnd_src_convert_rate(src);
  203. u32 fsrate = 0;
  204. if (convert_rate)
  205. fsrate = 0x0400000 / convert_rate * runtime->rate;
  206. /* set/clear soft reset */
  207. rsnd_mod_write(mod, SRC_SWRSR, 0);
  208. rsnd_mod_write(mod, SRC_SWRSR, 1);
  209. /*
  210. * Initialize the operation of the SRC internal circuits
  211. * see rsnd_src_start()
  212. */
  213. rsnd_mod_write(mod, SRC_SRCIR, 1);
  214. /* Set channel number and output bit length */
  215. rsnd_mod_write(mod, SRC_ADINR, rsnd_get_adinr(mod));
  216. /* Enable the initial value of IFS */
  217. if (fsrate) {
  218. rsnd_mod_write(mod, SRC_IFSCR, 1);
  219. /* Set initial value of IFS */
  220. rsnd_mod_write(mod, SRC_IFSVR, fsrate);
  221. }
  222. /* use DMA transfer */
  223. rsnd_mod_write(mod, SRC_BUSIF_MODE, 1);
  224. return 0;
  225. }
  226. static int rsnd_src_init(struct rsnd_mod *mod,
  227. struct rsnd_dai *rdai)
  228. {
  229. struct rsnd_src *src = rsnd_mod_to_src(mod);
  230. clk_prepare_enable(src->clk);
  231. return 0;
  232. }
  233. static int rsnd_src_quit(struct rsnd_mod *mod,
  234. struct rsnd_dai *rdai)
  235. {
  236. struct rsnd_src *src = rsnd_mod_to_src(mod);
  237. clk_disable_unprepare(src->clk);
  238. return 0;
  239. }
  240. static int rsnd_src_start(struct rsnd_mod *mod,
  241. struct rsnd_dai *rdai)
  242. {
  243. struct rsnd_src *src = rsnd_mod_to_src(mod);
  244. /*
  245. * Cancel the initialization and operate the SRC function
  246. * see rsnd_src_set_convert_rate()
  247. */
  248. rsnd_mod_write(mod, SRC_SRCIR, 0);
  249. if (rsnd_src_convert_rate(src))
  250. rsnd_mod_write(mod, SRC_ROUTE_MODE0, 1);
  251. return 0;
  252. }
  253. static int rsnd_src_stop(struct rsnd_mod *mod,
  254. struct rsnd_dai *rdai)
  255. {
  256. struct rsnd_src *src = rsnd_mod_to_src(mod);
  257. if (rsnd_src_convert_rate(src))
  258. rsnd_mod_write(mod, SRC_ROUTE_MODE0, 0);
  259. return 0;
  260. }
  261. /*
  262. * Gen1 functions
  263. */
  264. static int rsnd_src_set_route_gen1(struct rsnd_mod *mod,
  265. struct rsnd_dai *rdai)
  266. {
  267. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  268. struct src_route_config {
  269. u32 mask;
  270. int shift;
  271. } routes[] = {
  272. { 0xF, 0, }, /* 0 */
  273. { 0xF, 4, }, /* 1 */
  274. { 0xF, 8, }, /* 2 */
  275. { 0x7, 12, }, /* 3 */
  276. { 0x7, 16, }, /* 4 */
  277. { 0x7, 20, }, /* 5 */
  278. { 0x7, 24, }, /* 6 */
  279. { 0x3, 28, }, /* 7 */
  280. { 0x3, 30, }, /* 8 */
  281. };
  282. u32 mask;
  283. u32 val;
  284. int id;
  285. id = rsnd_mod_id(mod);
  286. if (id < 0 || id >= ARRAY_SIZE(routes))
  287. return -EIO;
  288. /*
  289. * SRC_ROUTE_SELECT
  290. */
  291. val = rsnd_dai_is_play(rdai, io) ? 0x1 : 0x2;
  292. val = val << routes[id].shift;
  293. mask = routes[id].mask << routes[id].shift;
  294. rsnd_mod_bset(mod, SRC_ROUTE_SEL, mask, val);
  295. return 0;
  296. }
  297. static int rsnd_src_set_convert_timing_gen1(struct rsnd_mod *mod,
  298. struct rsnd_dai *rdai)
  299. {
  300. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  301. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  302. struct rsnd_src *src = rsnd_mod_to_src(mod);
  303. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  304. u32 convert_rate = rsnd_src_convert_rate(src);
  305. u32 mask;
  306. u32 val;
  307. int shift;
  308. int id = rsnd_mod_id(mod);
  309. int ret;
  310. /*
  311. * SRC_TIMING_SELECT
  312. */
  313. shift = (id % 4) * 8;
  314. mask = 0x1F << shift;
  315. /*
  316. * ADG is used as source clock if SRC was used,
  317. * then, SSI WS is used as destination clock.
  318. * SSI WS is used as source clock if SRC is not used
  319. * (when playback, source/destination become reverse when capture)
  320. */
  321. ret = 0;
  322. if (convert_rate) {
  323. /* use ADG */
  324. val = 0;
  325. ret = rsnd_adg_set_convert_clk_gen1(priv, mod,
  326. runtime->rate,
  327. convert_rate);
  328. } else if (8 == id) {
  329. /* use SSI WS, but SRU8 is special */
  330. val = id << shift;
  331. } else {
  332. /* use SSI WS */
  333. val = (id + 1) << shift;
  334. }
  335. if (ret < 0)
  336. return ret;
  337. switch (id / 4) {
  338. case 0:
  339. rsnd_mod_bset(mod, SRC_TMG_SEL0, mask, val);
  340. break;
  341. case 1:
  342. rsnd_mod_bset(mod, SRC_TMG_SEL1, mask, val);
  343. break;
  344. case 2:
  345. rsnd_mod_bset(mod, SRC_TMG_SEL2, mask, val);
  346. break;
  347. }
  348. return 0;
  349. }
  350. static int rsnd_src_set_convert_rate_gen1(struct rsnd_mod *mod,
  351. struct rsnd_dai *rdai)
  352. {
  353. int ret;
  354. ret = rsnd_src_set_convert_rate(mod, rdai);
  355. if (ret < 0)
  356. return ret;
  357. /* Select SRC mode (fixed value) */
  358. rsnd_mod_write(mod, SRC_SRCCR, 0x00010110);
  359. /* Set the restriction value of the FS ratio (98%) */
  360. rsnd_mod_write(mod, SRC_MNFSR,
  361. rsnd_mod_read(mod, SRC_IFSVR) / 100 * 98);
  362. /* no SRC_BFSSR settings, since SRC_SRCCR::BUFMD is 0 */
  363. return 0;
  364. }
  365. static int rsnd_src_probe_gen1(struct rsnd_mod *mod,
  366. struct rsnd_dai *rdai)
  367. {
  368. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  369. struct device *dev = rsnd_priv_to_dev(priv);
  370. dev_dbg(dev, "%s (Gen1) is probed\n", rsnd_mod_name(mod));
  371. return 0;
  372. }
  373. static int rsnd_src_init_gen1(struct rsnd_mod *mod,
  374. struct rsnd_dai *rdai)
  375. {
  376. int ret;
  377. ret = rsnd_src_init(mod, rdai);
  378. if (ret < 0)
  379. return ret;
  380. ret = rsnd_src_set_route_gen1(mod, rdai);
  381. if (ret < 0)
  382. return ret;
  383. ret = rsnd_src_set_convert_rate_gen1(mod, rdai);
  384. if (ret < 0)
  385. return ret;
  386. ret = rsnd_src_set_convert_timing_gen1(mod, rdai);
  387. if (ret < 0)
  388. return ret;
  389. return 0;
  390. }
  391. static int rsnd_src_start_gen1(struct rsnd_mod *mod,
  392. struct rsnd_dai *rdai)
  393. {
  394. int id = rsnd_mod_id(mod);
  395. rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), (1 << id));
  396. return rsnd_src_start(mod, rdai);
  397. }
  398. static int rsnd_src_stop_gen1(struct rsnd_mod *mod,
  399. struct rsnd_dai *rdai)
  400. {
  401. int id = rsnd_mod_id(mod);
  402. rsnd_mod_bset(mod, SRC_ROUTE_CTRL, (1 << id), 0);
  403. return rsnd_src_stop(mod, rdai);
  404. }
  405. static struct rsnd_mod_ops rsnd_src_gen1_ops = {
  406. .name = SRC_NAME,
  407. .probe = rsnd_src_probe_gen1,
  408. .init = rsnd_src_init_gen1,
  409. .quit = rsnd_src_quit,
  410. .start = rsnd_src_start_gen1,
  411. .stop = rsnd_src_stop_gen1,
  412. };
  413. /*
  414. * Gen2 functions
  415. */
  416. static int rsnd_src_set_convert_rate_gen2(struct rsnd_mod *mod,
  417. struct rsnd_dai *rdai)
  418. {
  419. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  420. struct device *dev = rsnd_priv_to_dev(priv);
  421. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  422. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  423. struct rsnd_src *src = rsnd_mod_to_src(mod);
  424. uint ratio;
  425. int ret;
  426. /* 6 - 1/6 are very enough ratio for SRC_BSDSR */
  427. if (!rsnd_src_convert_rate(src))
  428. ratio = 0;
  429. else if (rsnd_src_convert_rate(src) > runtime->rate)
  430. ratio = 100 * rsnd_src_convert_rate(src) / runtime->rate;
  431. else
  432. ratio = 100 * runtime->rate / rsnd_src_convert_rate(src);
  433. if (ratio > 600) {
  434. dev_err(dev, "FSO/FSI ratio error\n");
  435. return -EINVAL;
  436. }
  437. ret = rsnd_src_set_convert_rate(mod, rdai);
  438. if (ret < 0)
  439. return ret;
  440. rsnd_mod_write(mod, SRC_SRCCR, 0x00011110);
  441. switch (rsnd_mod_id(mod)) {
  442. case 5:
  443. case 6:
  444. case 7:
  445. case 8:
  446. rsnd_mod_write(mod, SRC_BSDSR, 0x02400000);
  447. break;
  448. default:
  449. rsnd_mod_write(mod, SRC_BSDSR, 0x01800000);
  450. break;
  451. }
  452. rsnd_mod_write(mod, SRC_BSISR, 0x00100060);
  453. return 0;
  454. }
  455. static int rsnd_src_set_convert_timing_gen2(struct rsnd_mod *mod,
  456. struct rsnd_dai *rdai)
  457. {
  458. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  459. struct snd_pcm_runtime *runtime = rsnd_io_to_runtime(io);
  460. struct rsnd_src *src = rsnd_mod_to_src(mod);
  461. u32 convert_rate = rsnd_src_convert_rate(src);
  462. int ret;
  463. if (convert_rate)
  464. ret = rsnd_adg_set_convert_clk_gen2(mod, rdai, io,
  465. runtime->rate,
  466. convert_rate);
  467. else
  468. ret = rsnd_adg_set_convert_timing_gen2(mod, rdai, io);
  469. return ret;
  470. }
  471. static int rsnd_src_probe_gen2(struct rsnd_mod *mod,
  472. struct rsnd_dai *rdai)
  473. {
  474. struct rsnd_priv *priv = rsnd_mod_to_priv(mod);
  475. struct rsnd_src *src = rsnd_mod_to_src(mod);
  476. struct device *dev = rsnd_priv_to_dev(priv);
  477. int ret;
  478. ret = rsnd_dma_init(priv,
  479. rsnd_mod_to_dma(mod),
  480. rsnd_info_is_playback(priv, src),
  481. src->info->dma_id);
  482. if (ret < 0)
  483. dev_err(dev, "SRC DMA failed\n");
  484. dev_dbg(dev, "%s (Gen2) is probed\n", rsnd_mod_name(mod));
  485. return ret;
  486. }
  487. static int rsnd_src_remove_gen2(struct rsnd_mod *mod,
  488. struct rsnd_dai *rdai)
  489. {
  490. rsnd_dma_quit(rsnd_mod_to_priv(mod), rsnd_mod_to_dma(mod));
  491. return 0;
  492. }
  493. static int rsnd_src_init_gen2(struct rsnd_mod *mod,
  494. struct rsnd_dai *rdai)
  495. {
  496. int ret;
  497. ret = rsnd_src_init(mod, rdai);
  498. if (ret < 0)
  499. return ret;
  500. ret = rsnd_src_set_convert_rate_gen2(mod, rdai);
  501. if (ret < 0)
  502. return ret;
  503. ret = rsnd_src_set_convert_timing_gen2(mod, rdai);
  504. if (ret < 0)
  505. return ret;
  506. return 0;
  507. }
  508. static int rsnd_src_start_gen2(struct rsnd_mod *mod,
  509. struct rsnd_dai *rdai)
  510. {
  511. struct rsnd_dai_stream *io = rsnd_mod_to_io(mod);
  512. struct rsnd_src *src = rsnd_mod_to_src(mod);
  513. u32 val = rsnd_io_to_mod_dvc(io) ? 0x01 : 0x11;
  514. rsnd_dma_start(rsnd_mod_to_dma(&src->mod));
  515. rsnd_mod_write(mod, SRC_CTRL, val);
  516. return rsnd_src_start(mod, rdai);
  517. }
  518. static int rsnd_src_stop_gen2(struct rsnd_mod *mod,
  519. struct rsnd_dai *rdai)
  520. {
  521. struct rsnd_src *src = rsnd_mod_to_src(mod);
  522. rsnd_mod_write(mod, SRC_CTRL, 0);
  523. rsnd_dma_stop(rsnd_mod_to_dma(&src->mod));
  524. return rsnd_src_stop(mod, rdai);
  525. }
  526. static struct rsnd_mod_ops rsnd_src_gen2_ops = {
  527. .name = SRC_NAME,
  528. .probe = rsnd_src_probe_gen2,
  529. .remove = rsnd_src_remove_gen2,
  530. .init = rsnd_src_init_gen2,
  531. .quit = rsnd_src_quit,
  532. .start = rsnd_src_start_gen2,
  533. .stop = rsnd_src_stop_gen2,
  534. };
  535. struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id)
  536. {
  537. if (WARN_ON(id < 0 || id >= rsnd_src_nr(priv)))
  538. id = 0;
  539. return &((struct rsnd_src *)(priv->src) + id)->mod;
  540. }
  541. static void rsnd_of_parse_src(struct platform_device *pdev,
  542. const struct rsnd_of_data *of_data,
  543. struct rsnd_priv *priv)
  544. {
  545. struct device_node *src_node;
  546. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  547. struct rsnd_src_platform_info *src_info;
  548. struct device *dev = &pdev->dev;
  549. int nr;
  550. if (!of_data)
  551. return;
  552. src_node = of_get_child_by_name(dev->of_node, "rcar_sound,src");
  553. if (!src_node)
  554. return;
  555. nr = of_get_child_count(src_node);
  556. if (!nr)
  557. goto rsnd_of_parse_src_end;
  558. src_info = devm_kzalloc(dev,
  559. sizeof(struct rsnd_src_platform_info) * nr,
  560. GFP_KERNEL);
  561. if (!src_info) {
  562. dev_err(dev, "src info allocation error\n");
  563. goto rsnd_of_parse_src_end;
  564. }
  565. info->src_info = src_info;
  566. info->src_info_nr = nr;
  567. rsnd_of_parse_src_end:
  568. of_node_put(src_node);
  569. }
  570. int rsnd_src_probe(struct platform_device *pdev,
  571. const struct rsnd_of_data *of_data,
  572. struct rsnd_priv *priv)
  573. {
  574. struct rcar_snd_info *info = rsnd_priv_to_info(priv);
  575. struct device *dev = rsnd_priv_to_dev(priv);
  576. struct rsnd_src *src;
  577. struct rsnd_mod_ops *ops;
  578. struct clk *clk;
  579. char name[RSND_SRC_NAME_SIZE];
  580. int i, nr;
  581. ops = NULL;
  582. if (rsnd_is_gen1(priv))
  583. ops = &rsnd_src_gen1_ops;
  584. if (rsnd_is_gen2(priv))
  585. ops = &rsnd_src_gen2_ops;
  586. if (!ops) {
  587. dev_err(dev, "unknown Generation\n");
  588. return -EIO;
  589. }
  590. rsnd_of_parse_src(pdev, of_data, priv);
  591. /*
  592. * init SRC
  593. */
  594. nr = info->src_info_nr;
  595. if (!nr)
  596. return 0;
  597. src = devm_kzalloc(dev, sizeof(*src) * nr, GFP_KERNEL);
  598. if (!src) {
  599. dev_err(dev, "SRC allocate failed\n");
  600. return -ENOMEM;
  601. }
  602. priv->src_nr = nr;
  603. priv->src = src;
  604. for_each_rsnd_src(src, priv, i) {
  605. snprintf(name, RSND_SRC_NAME_SIZE, "%s.%d",
  606. SRC_NAME, i);
  607. clk = devm_clk_get(dev, name);
  608. if (IS_ERR(clk))
  609. return PTR_ERR(clk);
  610. src->info = &info->src_info[i];
  611. src->clk = clk;
  612. rsnd_mod_init(priv, &src->mod, ops, RSND_MOD_SRC, i);
  613. dev_dbg(dev, "SRC%d probed\n", i);
  614. }
  615. return 0;
  616. }