rsnd.h 20 KB

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