rsnd.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Renesas R-Car
  4. //
  5. // Copyright (C) 2013 Renesas Solutions Corp.
  6. // Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  7. #ifndef RSND_H
  8. #define RSND_H
  9. #include <linux/clk.h>
  10. #include <linux/device.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/io.h>
  13. #include <linux/list.h>
  14. #include <linux/module.h>
  15. #include <linux/of_device.h>
  16. #include <linux/of_graph.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/sh_dma.h>
  19. #include <linux/workqueue.h>
  20. #include <sound/soc.h>
  21. #include <sound/pcm_params.h>
  22. #define RSND_GEN1_SRU 0
  23. #define RSND_GEN1_ADG 1
  24. #define RSND_GEN1_SSI 2
  25. #define RSND_GEN2_SCU 0
  26. #define RSND_GEN2_ADG 1
  27. #define RSND_GEN2_SSIU 2
  28. #define RSND_GEN2_SSI 3
  29. #define RSND_BASE_MAX 4
  30. /*
  31. * pseudo register
  32. *
  33. * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
  34. * This driver uses pseudo register in order to hide it.
  35. * see gen1/gen2 for detail
  36. */
  37. enum rsnd_reg {
  38. /* SCU (MIX/CTU/DVC) */
  39. RSND_REG_SRC_I_BUSIF_MODE,
  40. RSND_REG_SRC_O_BUSIF_MODE,
  41. RSND_REG_SRC_ROUTE_MODE0,
  42. RSND_REG_SRC_SWRSR,
  43. RSND_REG_SRC_SRCIR,
  44. RSND_REG_SRC_ADINR,
  45. RSND_REG_SRC_IFSCR,
  46. RSND_REG_SRC_IFSVR,
  47. RSND_REG_SRC_SRCCR,
  48. RSND_REG_SRC_CTRL,
  49. RSND_REG_SRC_BSDSR,
  50. RSND_REG_SRC_BSISR,
  51. RSND_REG_SRC_INT_ENABLE0,
  52. RSND_REG_SRC_BUSIF_DALIGN,
  53. RSND_REG_SRCIN_TIMSEL0,
  54. RSND_REG_SRCIN_TIMSEL1,
  55. RSND_REG_SRCIN_TIMSEL2,
  56. RSND_REG_SRCIN_TIMSEL3,
  57. RSND_REG_SRCIN_TIMSEL4,
  58. RSND_REG_SRCOUT_TIMSEL0,
  59. RSND_REG_SRCOUT_TIMSEL1,
  60. RSND_REG_SRCOUT_TIMSEL2,
  61. RSND_REG_SRCOUT_TIMSEL3,
  62. RSND_REG_SRCOUT_TIMSEL4,
  63. RSND_REG_SCU_SYS_STATUS0,
  64. RSND_REG_SCU_SYS_STATUS1,
  65. RSND_REG_SCU_SYS_INT_EN0,
  66. RSND_REG_SCU_SYS_INT_EN1,
  67. RSND_REG_CMD_CTRL,
  68. RSND_REG_CMD_BUSIF_MODE,
  69. RSND_REG_CMD_BUSIF_DALIGN,
  70. RSND_REG_CMD_ROUTE_SLCT,
  71. RSND_REG_CMDOUT_TIMSEL,
  72. RSND_REG_CTU_SWRSR,
  73. RSND_REG_CTU_CTUIR,
  74. RSND_REG_CTU_ADINR,
  75. RSND_REG_CTU_CPMDR,
  76. RSND_REG_CTU_SCMDR,
  77. RSND_REG_CTU_SV00R,
  78. RSND_REG_CTU_SV01R,
  79. RSND_REG_CTU_SV02R,
  80. RSND_REG_CTU_SV03R,
  81. RSND_REG_CTU_SV04R,
  82. RSND_REG_CTU_SV05R,
  83. RSND_REG_CTU_SV06R,
  84. RSND_REG_CTU_SV07R,
  85. RSND_REG_CTU_SV10R,
  86. RSND_REG_CTU_SV11R,
  87. RSND_REG_CTU_SV12R,
  88. RSND_REG_CTU_SV13R,
  89. RSND_REG_CTU_SV14R,
  90. RSND_REG_CTU_SV15R,
  91. RSND_REG_CTU_SV16R,
  92. RSND_REG_CTU_SV17R,
  93. RSND_REG_CTU_SV20R,
  94. RSND_REG_CTU_SV21R,
  95. RSND_REG_CTU_SV22R,
  96. RSND_REG_CTU_SV23R,
  97. RSND_REG_CTU_SV24R,
  98. RSND_REG_CTU_SV25R,
  99. RSND_REG_CTU_SV26R,
  100. RSND_REG_CTU_SV27R,
  101. RSND_REG_CTU_SV30R,
  102. RSND_REG_CTU_SV31R,
  103. RSND_REG_CTU_SV32R,
  104. RSND_REG_CTU_SV33R,
  105. RSND_REG_CTU_SV34R,
  106. RSND_REG_CTU_SV35R,
  107. RSND_REG_CTU_SV36R,
  108. RSND_REG_CTU_SV37R,
  109. RSND_REG_MIX_SWRSR,
  110. RSND_REG_MIX_MIXIR,
  111. RSND_REG_MIX_ADINR,
  112. RSND_REG_MIX_MIXMR,
  113. RSND_REG_MIX_MVPDR,
  114. RSND_REG_MIX_MDBAR,
  115. RSND_REG_MIX_MDBBR,
  116. RSND_REG_MIX_MDBCR,
  117. RSND_REG_MIX_MDBDR,
  118. RSND_REG_MIX_MDBER,
  119. RSND_REG_DVC_SWRSR,
  120. RSND_REG_DVC_DVUIR,
  121. RSND_REG_DVC_ADINR,
  122. RSND_REG_DVC_DVUCR,
  123. RSND_REG_DVC_ZCMCR,
  124. RSND_REG_DVC_VOL0R,
  125. RSND_REG_DVC_VOL1R,
  126. RSND_REG_DVC_VOL2R,
  127. RSND_REG_DVC_VOL3R,
  128. RSND_REG_DVC_VOL4R,
  129. RSND_REG_DVC_VOL5R,
  130. RSND_REG_DVC_VOL6R,
  131. RSND_REG_DVC_VOL7R,
  132. RSND_REG_DVC_DVUER,
  133. RSND_REG_DVC_VRCTR,
  134. RSND_REG_DVC_VRPDR,
  135. RSND_REG_DVC_VRDBR,
  136. /* ADG */
  137. RSND_REG_BRRA,
  138. RSND_REG_BRRB,
  139. RSND_REG_BRGCKR,
  140. RSND_REG_DIV_EN,
  141. RSND_REG_AUDIO_CLK_SEL0,
  142. RSND_REG_AUDIO_CLK_SEL1,
  143. RSND_REG_AUDIO_CLK_SEL2,
  144. /* SSIU */
  145. RSND_REG_SSI_MODE,
  146. RSND_REG_SSI_MODE0,
  147. RSND_REG_SSI_MODE1,
  148. RSND_REG_SSI_MODE2,
  149. RSND_REG_SSI_CONTROL,
  150. RSND_REG_SSI_CTRL,
  151. RSND_REG_SSI_BUSIF_MODE,
  152. RSND_REG_SSI_BUSIF_ADINR,
  153. RSND_REG_SSI_BUSIF_DALIGN,
  154. RSND_REG_SSI_INT_ENABLE,
  155. RSND_REG_SSI_SYS_STATUS0,
  156. RSND_REG_SSI_SYS_STATUS1,
  157. RSND_REG_SSI_SYS_STATUS2,
  158. RSND_REG_SSI_SYS_STATUS3,
  159. RSND_REG_SSI_SYS_STATUS4,
  160. RSND_REG_SSI_SYS_STATUS5,
  161. RSND_REG_SSI_SYS_STATUS6,
  162. RSND_REG_SSI_SYS_STATUS7,
  163. RSND_REG_HDMI0_SEL,
  164. RSND_REG_HDMI1_SEL,
  165. /* SSI */
  166. RSND_REG_SSICR,
  167. RSND_REG_SSISR,
  168. RSND_REG_SSITDR,
  169. RSND_REG_SSIRDR,
  170. RSND_REG_SSIWSR,
  171. RSND_REG_MAX,
  172. };
  173. struct rsnd_priv;
  174. struct rsnd_mod;
  175. struct rsnd_dai;
  176. struct rsnd_dai_stream;
  177. /*
  178. * R-Car basic functions
  179. */
  180. #define rsnd_mod_read(m, r) \
  181. rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
  182. #define rsnd_mod_write(m, r, d) \
  183. rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
  184. #define rsnd_mod_bset(m, r, s, d) \
  185. rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
  186. u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
  187. void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
  188. enum rsnd_reg reg, u32 data);
  189. void rsnd_force_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
  190. enum rsnd_reg reg, u32 data);
  191. void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
  192. u32 mask, u32 data);
  193. u32 rsnd_get_adinr_bit(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
  194. u32 rsnd_get_dalign(struct rsnd_mod *mod, struct rsnd_dai_stream *io);
  195. u32 rsnd_get_busif_shift(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
  196. /*
  197. * R-Car DMA
  198. */
  199. int rsnd_dma_attach(struct rsnd_dai_stream *io,
  200. struct rsnd_mod *mod, struct rsnd_mod **dma_mod);
  201. int rsnd_dma_probe(struct rsnd_priv *priv);
  202. struct dma_chan *rsnd_dma_request_channel(struct device_node *of_node,
  203. struct rsnd_mod *mod, char *name);
  204. /*
  205. * R-Car sound mod
  206. */
  207. enum rsnd_mod_type {
  208. RSND_MOD_AUDMAPP,
  209. RSND_MOD_AUDMA,
  210. RSND_MOD_DVC,
  211. RSND_MOD_MIX,
  212. RSND_MOD_CTU,
  213. RSND_MOD_CMD,
  214. RSND_MOD_SRC,
  215. RSND_MOD_SSIM3, /* SSI multi 3 */
  216. RSND_MOD_SSIM2, /* SSI multi 2 */
  217. RSND_MOD_SSIM1, /* SSI multi 1 */
  218. RSND_MOD_SSIP, /* SSI parent */
  219. RSND_MOD_SSI,
  220. RSND_MOD_SSIU,
  221. RSND_MOD_MAX,
  222. };
  223. struct rsnd_mod_ops {
  224. char *name;
  225. struct dma_chan* (*dma_req)(struct rsnd_dai_stream *io,
  226. struct rsnd_mod *mod);
  227. int (*probe)(struct rsnd_mod *mod,
  228. struct rsnd_dai_stream *io,
  229. struct rsnd_priv *priv);
  230. int (*remove)(struct rsnd_mod *mod,
  231. struct rsnd_dai_stream *io,
  232. struct rsnd_priv *priv);
  233. int (*init)(struct rsnd_mod *mod,
  234. struct rsnd_dai_stream *io,
  235. struct rsnd_priv *priv);
  236. int (*quit)(struct rsnd_mod *mod,
  237. struct rsnd_dai_stream *io,
  238. struct rsnd_priv *priv);
  239. int (*start)(struct rsnd_mod *mod,
  240. struct rsnd_dai_stream *io,
  241. struct rsnd_priv *priv);
  242. int (*stop)(struct rsnd_mod *mod,
  243. struct rsnd_dai_stream *io,
  244. struct rsnd_priv *priv);
  245. int (*irq)(struct rsnd_mod *mod,
  246. struct rsnd_dai_stream *io,
  247. struct rsnd_priv *priv, int enable);
  248. int (*pcm_new)(struct rsnd_mod *mod,
  249. struct rsnd_dai_stream *io,
  250. struct snd_soc_pcm_runtime *rtd);
  251. int (*hw_params)(struct rsnd_mod *mod,
  252. struct rsnd_dai_stream *io,
  253. struct snd_pcm_substream *substream,
  254. struct snd_pcm_hw_params *hw_params);
  255. int (*pointer)(struct rsnd_mod *mod,
  256. struct rsnd_dai_stream *io,
  257. snd_pcm_uframes_t *pointer);
  258. int (*fallback)(struct rsnd_mod *mod,
  259. struct rsnd_dai_stream *io,
  260. struct rsnd_priv *priv);
  261. int (*nolock_start)(struct rsnd_mod *mod,
  262. struct rsnd_dai_stream *io,
  263. struct rsnd_priv *priv);
  264. int (*nolock_stop)(struct rsnd_mod *mod,
  265. struct rsnd_dai_stream *io,
  266. struct rsnd_priv *priv);
  267. int (*prepare)(struct rsnd_mod *mod,
  268. struct rsnd_dai_stream *io,
  269. struct rsnd_priv *priv);
  270. };
  271. struct rsnd_dai_stream;
  272. struct rsnd_mod {
  273. int id;
  274. enum rsnd_mod_type type;
  275. struct rsnd_mod_ops *ops;
  276. struct rsnd_priv *priv;
  277. struct clk *clk;
  278. u32 *(*get_status)(struct rsnd_dai_stream *io,
  279. struct rsnd_mod *mod,
  280. enum rsnd_mod_type type);
  281. u32 status;
  282. };
  283. /*
  284. * status
  285. *
  286. * 0xH0000CBA
  287. *
  288. * A 0: nolock_start 1: nolock_stop
  289. * B 0: init 1: quit
  290. * C 0: start 1: stop
  291. *
  292. * H is always called (see __rsnd_mod_call)
  293. * H 0: probe 1: remove
  294. * H 0: pcm_new
  295. * H 0: fallback
  296. * H 0: hw_params
  297. * H 0: pointer
  298. * H 0: prepare
  299. */
  300. #define __rsnd_mod_shift_nolock_start 0
  301. #define __rsnd_mod_shift_nolock_stop 0
  302. #define __rsnd_mod_shift_init 4
  303. #define __rsnd_mod_shift_quit 4
  304. #define __rsnd_mod_shift_start 8
  305. #define __rsnd_mod_shift_stop 8
  306. #define __rsnd_mod_shift_probe 28 /* always called */
  307. #define __rsnd_mod_shift_remove 28 /* always called */
  308. #define __rsnd_mod_shift_irq 28 /* always called */
  309. #define __rsnd_mod_shift_pcm_new 28 /* always called */
  310. #define __rsnd_mod_shift_fallback 28 /* always called */
  311. #define __rsnd_mod_shift_hw_params 28 /* always called */
  312. #define __rsnd_mod_shift_pointer 28 /* always called */
  313. #define __rsnd_mod_shift_prepare 28 /* always called */
  314. #define __rsnd_mod_add_probe 0
  315. #define __rsnd_mod_add_remove 0
  316. #define __rsnd_mod_add_nolock_start 1
  317. #define __rsnd_mod_add_nolock_stop -1
  318. #define __rsnd_mod_add_init 1
  319. #define __rsnd_mod_add_quit -1
  320. #define __rsnd_mod_add_start 1
  321. #define __rsnd_mod_add_stop -1
  322. #define __rsnd_mod_add_irq 0
  323. #define __rsnd_mod_add_pcm_new 0
  324. #define __rsnd_mod_add_fallback 0
  325. #define __rsnd_mod_add_hw_params 0
  326. #define __rsnd_mod_add_pointer 0
  327. #define __rsnd_mod_add_prepare 0
  328. #define __rsnd_mod_call_probe 0
  329. #define __rsnd_mod_call_remove 0
  330. #define __rsnd_mod_call_init 0
  331. #define __rsnd_mod_call_quit 1
  332. #define __rsnd_mod_call_start 0
  333. #define __rsnd_mod_call_stop 1
  334. #define __rsnd_mod_call_irq 0
  335. #define __rsnd_mod_call_pcm_new 0
  336. #define __rsnd_mod_call_fallback 0
  337. #define __rsnd_mod_call_hw_params 0
  338. #define __rsnd_mod_call_pointer 0
  339. #define __rsnd_mod_call_nolock_start 0
  340. #define __rsnd_mod_call_nolock_stop 1
  341. #define __rsnd_mod_call_prepare 0
  342. #define rsnd_mod_to_priv(mod) ((mod)->priv)
  343. #define rsnd_mod_name(mod) ((mod)->ops->name)
  344. #define rsnd_mod_id(mod) ((mod)->id)
  345. #define rsnd_mod_power_on(mod) clk_enable((mod)->clk)
  346. #define rsnd_mod_power_off(mod) clk_disable((mod)->clk)
  347. #define rsnd_mod_get(ip) (&(ip)->mod)
  348. int rsnd_mod_init(struct rsnd_priv *priv,
  349. struct rsnd_mod *mod,
  350. struct rsnd_mod_ops *ops,
  351. struct clk *clk,
  352. u32* (*get_status)(struct rsnd_dai_stream *io,
  353. struct rsnd_mod *mod,
  354. enum rsnd_mod_type type),
  355. enum rsnd_mod_type type,
  356. int id);
  357. void rsnd_mod_quit(struct rsnd_mod *mod);
  358. struct dma_chan *rsnd_mod_dma_req(struct rsnd_dai_stream *io,
  359. struct rsnd_mod *mod);
  360. void rsnd_mod_interrupt(struct rsnd_mod *mod,
  361. void (*callback)(struct rsnd_mod *mod,
  362. struct rsnd_dai_stream *io));
  363. u32 *rsnd_mod_get_status(struct rsnd_dai_stream *io,
  364. struct rsnd_mod *mod,
  365. enum rsnd_mod_type type);
  366. struct rsnd_mod *rsnd_mod_next(int *iterator,
  367. struct rsnd_dai_stream *io,
  368. enum rsnd_mod_type *array,
  369. int array_size);
  370. #define for_each_rsnd_mod(iterator, pos, io) \
  371. for (iterator = 0; \
  372. (pos = rsnd_mod_next(&iterator, io, NULL, 0)); iterator++)
  373. #define for_each_rsnd_mod_arrays(iterator, pos, io, array, size) \
  374. for (iterator = 0; \
  375. (pos = rsnd_mod_next(&iterator, io, array, size)); iterator++)
  376. #define for_each_rsnd_mod_array(iterator, pos, io, array) \
  377. for_each_rsnd_mod_arrays(iterator, pos, io, array, ARRAY_SIZE(array))
  378. void rsnd_parse_connect_common(struct rsnd_dai *rdai,
  379. struct rsnd_mod* (*mod_get)(struct rsnd_priv *priv, int id),
  380. struct device_node *node,
  381. struct device_node *playback,
  382. struct device_node *capture);
  383. #define rsnd_runtime_channel_original(io) \
  384. rsnd_runtime_channel_original_with_params(io, NULL)
  385. int rsnd_runtime_channel_original_with_params(struct rsnd_dai_stream *io,
  386. struct snd_pcm_hw_params *params);
  387. #define rsnd_runtime_channel_after_ctu(io) \
  388. rsnd_runtime_channel_after_ctu_with_params(io, NULL)
  389. int rsnd_runtime_channel_after_ctu_with_params(struct rsnd_dai_stream *io,
  390. struct snd_pcm_hw_params *params);
  391. #define rsnd_runtime_channel_for_ssi(io) \
  392. rsnd_runtime_channel_for_ssi_with_params(io, NULL)
  393. int rsnd_runtime_channel_for_ssi_with_params(struct rsnd_dai_stream *io,
  394. struct snd_pcm_hw_params *params);
  395. int rsnd_runtime_is_ssi_multi(struct rsnd_dai_stream *io);
  396. int rsnd_runtime_is_ssi_tdm(struct rsnd_dai_stream *io);
  397. /*
  398. * DT
  399. */
  400. #define rsnd_parse_of_node(priv, node) \
  401. of_get_child_by_name(rsnd_priv_to_dev(priv)->of_node, node)
  402. #define RSND_NODE_DAI "rcar_sound,dai"
  403. #define RSND_NODE_SSI "rcar_sound,ssi"
  404. #define RSND_NODE_SRC "rcar_sound,src"
  405. #define RSND_NODE_CTU "rcar_sound,ctu"
  406. #define RSND_NODE_MIX "rcar_sound,mix"
  407. #define RSND_NODE_DVC "rcar_sound,dvc"
  408. /*
  409. * R-Car sound DAI
  410. */
  411. #define RSND_DAI_NAME_SIZE 16
  412. struct rsnd_dai_stream {
  413. char name[RSND_DAI_NAME_SIZE];
  414. struct snd_pcm_substream *substream;
  415. struct rsnd_mod *mod[RSND_MOD_MAX];
  416. struct rsnd_mod *dma;
  417. struct rsnd_dai *rdai;
  418. struct device *dmac_dev; /* for IPMMU */
  419. u32 parent_ssi_status;
  420. };
  421. #define rsnd_io_to_mod(io, i) ((i) < RSND_MOD_MAX ? (io)->mod[(i)] : NULL)
  422. #define rsnd_io_to_mod_ssi(io) rsnd_io_to_mod((io), RSND_MOD_SSI)
  423. #define rsnd_io_to_mod_ssiu(io) rsnd_io_to_mod((io), RSND_MOD_SSIU)
  424. #define rsnd_io_to_mod_ssip(io) rsnd_io_to_mod((io), RSND_MOD_SSIP)
  425. #define rsnd_io_to_mod_src(io) rsnd_io_to_mod((io), RSND_MOD_SRC)
  426. #define rsnd_io_to_mod_ctu(io) rsnd_io_to_mod((io), RSND_MOD_CTU)
  427. #define rsnd_io_to_mod_mix(io) rsnd_io_to_mod((io), RSND_MOD_MIX)
  428. #define rsnd_io_to_mod_dvc(io) rsnd_io_to_mod((io), RSND_MOD_DVC)
  429. #define rsnd_io_to_mod_cmd(io) rsnd_io_to_mod((io), RSND_MOD_CMD)
  430. #define rsnd_io_to_rdai(io) ((io)->rdai)
  431. #define rsnd_io_to_priv(io) (rsnd_rdai_to_priv(rsnd_io_to_rdai(io)))
  432. #define rsnd_io_is_play(io) (&rsnd_io_to_rdai(io)->playback == io)
  433. #define rsnd_io_to_runtime(io) ((io)->substream ? \
  434. (io)->substream->runtime : NULL)
  435. int rsnd_io_is_working(struct rsnd_dai_stream *io);
  436. struct rsnd_dai {
  437. char name[RSND_DAI_NAME_SIZE];
  438. struct rsnd_dai_stream playback;
  439. struct rsnd_dai_stream capture;
  440. struct rsnd_priv *priv;
  441. struct snd_pcm_hw_constraint_list constraint;
  442. int max_channels; /* 2ch - 16ch */
  443. int ssi_lane; /* 1lane - 4lane */
  444. unsigned int clk_master:1;
  445. unsigned int bit_clk_inv:1;
  446. unsigned int frm_clk_inv:1;
  447. unsigned int sys_delay:1;
  448. unsigned int data_alignment:1;
  449. };
  450. #define rsnd_rdai_nr(priv) ((priv)->rdai_nr)
  451. #define rsnd_rdai_is_clk_master(rdai) ((rdai)->clk_master)
  452. #define rsnd_rdai_to_priv(rdai) ((rdai)->priv)
  453. #define for_each_rsnd_dai(rdai, priv, i) \
  454. for (i = 0; \
  455. (i < rsnd_rdai_nr(priv)) && \
  456. ((rdai) = rsnd_rdai_get(priv, i)); \
  457. i++)
  458. struct rsnd_dai *rsnd_rdai_get(struct rsnd_priv *priv, int id);
  459. #define rsnd_rdai_channels_set(rdai, max_channels) \
  460. rsnd_rdai_channels_ctrl(rdai, max_channels)
  461. #define rsnd_rdai_channels_get(rdai) \
  462. rsnd_rdai_channels_ctrl(rdai, 0)
  463. int rsnd_rdai_channels_ctrl(struct rsnd_dai *rdai,
  464. int max_channels);
  465. #define rsnd_rdai_ssi_lane_set(rdai, ssi_lane) \
  466. rsnd_rdai_ssi_lane_ctrl(rdai, ssi_lane)
  467. #define rsnd_rdai_ssi_lane_get(rdai) \
  468. rsnd_rdai_ssi_lane_ctrl(rdai, 0)
  469. int rsnd_rdai_ssi_lane_ctrl(struct rsnd_dai *rdai,
  470. int ssi_lane);
  471. void rsnd_dai_period_elapsed(struct rsnd_dai_stream *io);
  472. int rsnd_dai_connect(struct rsnd_mod *mod,
  473. struct rsnd_dai_stream *io,
  474. enum rsnd_mod_type type);
  475. /*
  476. * R-Car Gen1/Gen2
  477. */
  478. int rsnd_gen_probe(struct rsnd_priv *priv);
  479. void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
  480. struct rsnd_mod *mod,
  481. enum rsnd_reg reg);
  482. phys_addr_t rsnd_gen_get_phy_addr(struct rsnd_priv *priv, int reg_id);
  483. /*
  484. * R-Car ADG
  485. */
  486. int rsnd_adg_clk_query(struct rsnd_priv *priv, unsigned int rate);
  487. int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
  488. int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
  489. int rsnd_adg_probe(struct rsnd_priv *priv);
  490. void rsnd_adg_remove(struct rsnd_priv *priv);
  491. int rsnd_adg_set_src_timesel_gen2(struct rsnd_mod *src_mod,
  492. struct rsnd_dai_stream *io,
  493. unsigned int in_rate,
  494. unsigned int out_rate);
  495. int rsnd_adg_set_cmd_timsel_gen2(struct rsnd_mod *mod,
  496. struct rsnd_dai_stream *io);
  497. #define rsnd_adg_clk_enable(priv) rsnd_adg_clk_control(priv, 1)
  498. #define rsnd_adg_clk_disable(priv) rsnd_adg_clk_control(priv, 0)
  499. void rsnd_adg_clk_control(struct rsnd_priv *priv, int enable);
  500. /*
  501. * R-Car sound priv
  502. */
  503. struct rsnd_priv {
  504. struct platform_device *pdev;
  505. spinlock_t lock;
  506. unsigned long flags;
  507. #define RSND_GEN_MASK (0xF << 0)
  508. #define RSND_GEN1 (1 << 0)
  509. #define RSND_GEN2 (2 << 0)
  510. #define RSND_GEN3 (3 << 0)
  511. /*
  512. * below value will be filled on rsnd_gen_probe()
  513. */
  514. void *gen;
  515. /*
  516. * below value will be filled on rsnd_adg_probe()
  517. */
  518. void *adg;
  519. /*
  520. * below value will be filled on rsnd_dma_probe()
  521. */
  522. void *dma;
  523. /*
  524. * below value will be filled on rsnd_ssi_probe()
  525. */
  526. void *ssi;
  527. int ssi_nr;
  528. /*
  529. * below value will be filled on rsnd_ssiu_probe()
  530. */
  531. void *ssiu;
  532. int ssiu_nr;
  533. /*
  534. * below value will be filled on rsnd_src_probe()
  535. */
  536. void *src;
  537. int src_nr;
  538. /*
  539. * below value will be filled on rsnd_ctu_probe()
  540. */
  541. void *ctu;
  542. int ctu_nr;
  543. /*
  544. * below value will be filled on rsnd_mix_probe()
  545. */
  546. void *mix;
  547. int mix_nr;
  548. /*
  549. * below value will be filled on rsnd_dvc_probe()
  550. */
  551. void *dvc;
  552. int dvc_nr;
  553. /*
  554. * below value will be filled on rsnd_cmd_probe()
  555. */
  556. void *cmd;
  557. int cmd_nr;
  558. /*
  559. * below value will be filled on rsnd_dai_probe()
  560. */
  561. struct snd_soc_dai_driver *daidrv;
  562. struct rsnd_dai *rdai;
  563. int rdai_nr;
  564. };
  565. #define rsnd_priv_to_pdev(priv) ((priv)->pdev)
  566. #define rsnd_priv_to_dev(priv) (&(rsnd_priv_to_pdev(priv)->dev))
  567. #define rsnd_is_gen1(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN1)
  568. #define rsnd_is_gen2(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN2)
  569. #define rsnd_is_gen3(priv) (((priv)->flags & RSND_GEN_MASK) == RSND_GEN3)
  570. #define rsnd_flags_has(p, f) ((p)->flags & (f))
  571. #define rsnd_flags_set(p, f) ((p)->flags |= (f))
  572. #define rsnd_flags_del(p, f) ((p)->flags &= ~(f))
  573. /*
  574. * rsnd_kctrl
  575. */
  576. struct rsnd_kctrl_cfg {
  577. unsigned int max;
  578. unsigned int size;
  579. u32 *val;
  580. const char * const *texts;
  581. int (*accept)(struct rsnd_dai_stream *io);
  582. void (*update)(struct rsnd_dai_stream *io, struct rsnd_mod *mod);
  583. struct rsnd_dai_stream *io;
  584. struct snd_card *card;
  585. struct snd_kcontrol *kctrl;
  586. struct rsnd_mod *mod;
  587. };
  588. #define RSND_MAX_CHANNELS 8
  589. struct rsnd_kctrl_cfg_m {
  590. struct rsnd_kctrl_cfg cfg;
  591. u32 val[RSND_MAX_CHANNELS];
  592. };
  593. struct rsnd_kctrl_cfg_s {
  594. struct rsnd_kctrl_cfg cfg;
  595. u32 val;
  596. };
  597. #define rsnd_kctrl_size(x) ((x).cfg.size)
  598. #define rsnd_kctrl_max(x) ((x).cfg.max)
  599. #define rsnd_kctrl_valm(x, i) ((x).val[i]) /* = (x).cfg.val[i] */
  600. #define rsnd_kctrl_vals(x) ((x).val) /* = (x).cfg.val[0] */
  601. int rsnd_kctrl_accept_anytime(struct rsnd_dai_stream *io);
  602. int rsnd_kctrl_accept_runtime(struct rsnd_dai_stream *io);
  603. struct rsnd_kctrl_cfg *rsnd_kctrl_init_m(struct rsnd_kctrl_cfg_m *cfg);
  604. struct rsnd_kctrl_cfg *rsnd_kctrl_init_s(struct rsnd_kctrl_cfg_s *cfg);
  605. int rsnd_kctrl_new(struct rsnd_mod *mod,
  606. struct rsnd_dai_stream *io,
  607. struct snd_soc_pcm_runtime *rtd,
  608. const unsigned char *name,
  609. int (*accept)(struct rsnd_dai_stream *io),
  610. void (*update)(struct rsnd_dai_stream *io,
  611. struct rsnd_mod *mod),
  612. struct rsnd_kctrl_cfg *cfg,
  613. const char * const *texts,
  614. int size,
  615. u32 max);
  616. #define rsnd_kctrl_new_m(mod, io, rtd, name, accept, update, cfg, size, max) \
  617. rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_m(cfg), \
  618. NULL, size, max)
  619. #define rsnd_kctrl_new_s(mod, io, rtd, name, accept, update, cfg, max) \
  620. rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
  621. NULL, 1, max)
  622. #define rsnd_kctrl_new_e(mod, io, rtd, name, accept, update, cfg, texts, size) \
  623. rsnd_kctrl_new(mod, io, rtd, name, accept, update, rsnd_kctrl_init_s(cfg), \
  624. texts, 1, size)
  625. extern const char * const volume_ramp_rate[];
  626. #define VOLUME_RAMP_MAX_DVC (0x17 + 1)
  627. #define VOLUME_RAMP_MAX_MIX (0x0a + 1)
  628. /*
  629. * R-Car SSI
  630. */
  631. int rsnd_ssi_probe(struct rsnd_priv *priv);
  632. void rsnd_ssi_remove(struct rsnd_priv *priv);
  633. struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
  634. int rsnd_ssi_is_dma_mode(struct rsnd_mod *mod);
  635. int rsnd_ssi_use_busif(struct rsnd_dai_stream *io);
  636. u32 rsnd_ssi_multi_slaves_runtime(struct rsnd_dai_stream *io);
  637. #define RSND_SSI_HDMI_PORT0 0xf0
  638. #define RSND_SSI_HDMI_PORT1 0xf1
  639. int rsnd_ssi_hdmi_port(struct rsnd_dai_stream *io);
  640. void rsnd_ssi_parse_hdmi_connection(struct rsnd_priv *priv,
  641. struct device_node *endpoint,
  642. int dai_i);
  643. #define rsnd_ssi_is_pin_sharing(io) \
  644. __rsnd_ssi_is_pin_sharing(rsnd_io_to_mod_ssi(io))
  645. int __rsnd_ssi_is_pin_sharing(struct rsnd_mod *mod);
  646. #define rsnd_ssi_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SSI)
  647. void rsnd_parse_connect_ssi(struct rsnd_dai *rdai,
  648. struct device_node *playback,
  649. struct device_node *capture);
  650. unsigned int rsnd_ssi_clk_query(struct rsnd_priv *priv,
  651. int param1, int param2, int *idx);
  652. /*
  653. * R-Car SSIU
  654. */
  655. int rsnd_ssiu_attach(struct rsnd_dai_stream *io,
  656. struct rsnd_mod *mod);
  657. int rsnd_ssiu_probe(struct rsnd_priv *priv);
  658. void rsnd_ssiu_remove(struct rsnd_priv *priv);
  659. /*
  660. * R-Car SRC
  661. */
  662. int rsnd_src_probe(struct rsnd_priv *priv);
  663. void rsnd_src_remove(struct rsnd_priv *priv);
  664. struct rsnd_mod *rsnd_src_mod_get(struct rsnd_priv *priv, int id);
  665. #define rsnd_src_get_in_rate(priv, io) rsnd_src_get_rate(priv, io, 1)
  666. #define rsnd_src_get_out_rate(priv, io) rsnd_src_get_rate(priv, io, 0)
  667. unsigned int rsnd_src_get_rate(struct rsnd_priv *priv,
  668. struct rsnd_dai_stream *io,
  669. int is_in);
  670. #define rsnd_src_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_SRC)
  671. #define rsnd_parse_connect_src(rdai, playback, capture) \
  672. rsnd_parse_connect_common(rdai, rsnd_src_mod_get, \
  673. rsnd_src_of_node(rsnd_rdai_to_priv(rdai)), \
  674. playback, capture)
  675. /*
  676. * R-Car CTU
  677. */
  678. int rsnd_ctu_probe(struct rsnd_priv *priv);
  679. void rsnd_ctu_remove(struct rsnd_priv *priv);
  680. int rsnd_ctu_converted_channel(struct rsnd_mod *mod);
  681. struct rsnd_mod *rsnd_ctu_mod_get(struct rsnd_priv *priv, int id);
  682. #define rsnd_ctu_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_CTU)
  683. #define rsnd_parse_connect_ctu(rdai, playback, capture) \
  684. rsnd_parse_connect_common(rdai, rsnd_ctu_mod_get, \
  685. rsnd_ctu_of_node(rsnd_rdai_to_priv(rdai)), \
  686. playback, capture)
  687. /*
  688. * R-Car MIX
  689. */
  690. int rsnd_mix_probe(struct rsnd_priv *priv);
  691. void rsnd_mix_remove(struct rsnd_priv *priv);
  692. struct rsnd_mod *rsnd_mix_mod_get(struct rsnd_priv *priv, int id);
  693. #define rsnd_mix_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_MIX)
  694. #define rsnd_parse_connect_mix(rdai, playback, capture) \
  695. rsnd_parse_connect_common(rdai, rsnd_mix_mod_get, \
  696. rsnd_mix_of_node(rsnd_rdai_to_priv(rdai)), \
  697. playback, capture)
  698. /*
  699. * R-Car DVC
  700. */
  701. int rsnd_dvc_probe(struct rsnd_priv *priv);
  702. void rsnd_dvc_remove(struct rsnd_priv *priv);
  703. struct rsnd_mod *rsnd_dvc_mod_get(struct rsnd_priv *priv, int id);
  704. #define rsnd_dvc_of_node(priv) rsnd_parse_of_node(priv, RSND_NODE_DVC)
  705. #define rsnd_parse_connect_dvc(rdai, playback, capture) \
  706. rsnd_parse_connect_common(rdai, rsnd_dvc_mod_get, \
  707. rsnd_dvc_of_node(rsnd_rdai_to_priv(rdai)), \
  708. playback, capture)
  709. /*
  710. * R-Car CMD
  711. */
  712. int rsnd_cmd_probe(struct rsnd_priv *priv);
  713. void rsnd_cmd_remove(struct rsnd_priv *priv);
  714. int rsnd_cmd_attach(struct rsnd_dai_stream *io, int id);
  715. void rsnd_mod_make_sure(struct rsnd_mod *mod, enum rsnd_mod_type type);
  716. #ifdef DEBUG
  717. #define rsnd_mod_confirm_ssi(mssi) rsnd_mod_make_sure(mssi, RSND_MOD_SSI)
  718. #define rsnd_mod_confirm_src(msrc) rsnd_mod_make_sure(msrc, RSND_MOD_SRC)
  719. #define rsnd_mod_confirm_dvc(mdvc) rsnd_mod_make_sure(mdvc, RSND_MOD_DVC)
  720. #else
  721. #define rsnd_mod_confirm_ssi(mssi)
  722. #define rsnd_mod_confirm_src(msrc)
  723. #define rsnd_mod_confirm_dvc(mdvc)
  724. #endif
  725. /*
  726. * If you don't need interrupt status debug message,
  727. * define RSND_DEBUG_NO_IRQ_STATUS as 1 on top of src.c/ssi.c
  728. *
  729. * #define RSND_DEBUG_NO_IRQ_STATUS 1
  730. */
  731. #define rsnd_dbg_irq_status(dev, param...) \
  732. if (!IS_BUILTIN(RSND_DEBUG_NO_IRQ_STATUS)) \
  733. dev_dbg(dev, param)
  734. /*
  735. * If you don't need rsnd_dai_call debug message,
  736. * define RSND_DEBUG_NO_DAI_CALL as 1 on top of core.c
  737. *
  738. * #define RSND_DEBUG_NO_DAI_CALL 1
  739. */
  740. #define rsnd_dbg_dai_call(dev, param...) \
  741. if (!IS_BUILTIN(RSND_DEBUG_NO_DAI_CALL)) \
  742. dev_dbg(dev, param)
  743. #endif