rsnd.h 21 KB

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