rsnd.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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/sh_dma.h>
  20. #include <linux/workqueue.h>
  21. #include <sound/rcar_snd.h>
  22. #include <sound/soc.h>
  23. #include <sound/pcm_params.h>
  24. /*
  25. * pseudo register
  26. *
  27. * The register address offsets SRU/SCU/SSIU on Gen1/Gen2 are very different.
  28. * This driver uses pseudo register in order to hide it.
  29. * see gen1/gen2 for detail
  30. */
  31. enum rsnd_reg {
  32. /* SRU/SCU */
  33. RSND_REG_SRC_ROUTE_SEL,
  34. RSND_REG_SRC_TMG_SEL0,
  35. RSND_REG_SRC_TMG_SEL1,
  36. RSND_REG_SRC_TMG_SEL2,
  37. RSND_REG_SRC_CTRL,
  38. RSND_REG_SSI_MODE0,
  39. RSND_REG_SSI_MODE1,
  40. RSND_REG_BUSIF_MODE,
  41. RSND_REG_BUSIF_ADINR,
  42. /* ADG */
  43. RSND_REG_BRRA,
  44. RSND_REG_BRRB,
  45. RSND_REG_SSICKR,
  46. RSND_REG_AUDIO_CLK_SEL0,
  47. RSND_REG_AUDIO_CLK_SEL1,
  48. RSND_REG_AUDIO_CLK_SEL2,
  49. RSND_REG_AUDIO_CLK_SEL3,
  50. RSND_REG_AUDIO_CLK_SEL4,
  51. RSND_REG_AUDIO_CLK_SEL5,
  52. /* SSI */
  53. RSND_REG_SSICR,
  54. RSND_REG_SSISR,
  55. RSND_REG_SSITDR,
  56. RSND_REG_SSIRDR,
  57. RSND_REG_SSIWSR,
  58. RSND_REG_MAX,
  59. };
  60. struct rsnd_priv;
  61. struct rsnd_mod;
  62. struct rsnd_dai;
  63. struct rsnd_dai_stream;
  64. /*
  65. * R-Car basic functions
  66. */
  67. #define rsnd_mod_read(m, r) \
  68. rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
  69. #define rsnd_mod_write(m, r, d) \
  70. rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
  71. #define rsnd_mod_bset(m, r, s, d) \
  72. rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
  73. #define rsnd_priv_read(p, r) rsnd_read(p, NULL, RSND_REG_##r)
  74. #define rsnd_priv_write(p, r, d) rsnd_write(p, NULL, RSND_REG_##r, d)
  75. #define rsnd_priv_bset(p, r, s, d) rsnd_bset(p, NULL, RSND_REG_##r, s, d)
  76. u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
  77. void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
  78. enum rsnd_reg reg, u32 data);
  79. void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
  80. u32 mask, u32 data);
  81. /*
  82. * R-Car DMA
  83. */
  84. struct rsnd_dma {
  85. struct rsnd_priv *priv;
  86. struct sh_dmae_slave slave;
  87. struct work_struct work;
  88. struct dma_chan *chan;
  89. enum dma_data_direction dir;
  90. int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len);
  91. int (*complete)(struct rsnd_dma *dma);
  92. int submit_loop;
  93. };
  94. void rsnd_dma_start(struct rsnd_dma *dma);
  95. void rsnd_dma_stop(struct rsnd_dma *dma);
  96. int rsnd_dma_available(struct rsnd_dma *dma);
  97. int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
  98. int is_play, int id,
  99. int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len),
  100. int (*complete)(struct rsnd_dma *dma));
  101. void rsnd_dma_quit(struct rsnd_priv *priv,
  102. struct rsnd_dma *dma);
  103. /*
  104. * R-Car sound mod
  105. */
  106. struct rsnd_mod_ops {
  107. char *name;
  108. int (*init)(struct rsnd_mod *mod,
  109. struct rsnd_dai *rdai,
  110. struct rsnd_dai_stream *io);
  111. int (*quit)(struct rsnd_mod *mod,
  112. struct rsnd_dai *rdai,
  113. struct rsnd_dai_stream *io);
  114. int (*start)(struct rsnd_mod *mod,
  115. struct rsnd_dai *rdai,
  116. struct rsnd_dai_stream *io);
  117. int (*stop)(struct rsnd_mod *mod,
  118. struct rsnd_dai *rdai,
  119. struct rsnd_dai_stream *io);
  120. };
  121. struct rsnd_mod {
  122. int id;
  123. struct rsnd_priv *priv;
  124. struct rsnd_mod_ops *ops;
  125. struct list_head list; /* connect to rsnd_dai playback/capture */
  126. struct rsnd_dma dma;
  127. };
  128. #define rsnd_mod_to_priv(mod) ((mod)->priv)
  129. #define rsnd_mod_to_dma(mod) (&(mod)->dma)
  130. #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
  131. #define rsnd_mod_id(mod) ((mod)->id)
  132. #define for_each_rsnd_mod(pos, n, io) \
  133. list_for_each_entry_safe(pos, n, &(io)->head, list)
  134. #define rsnd_mod_call(mod, func, rdai, io) \
  135. (!(mod) ? -ENODEV : \
  136. !((mod)->ops->func) ? 0 : \
  137. (mod)->ops->func(mod, rdai, io))
  138. void rsnd_mod_init(struct rsnd_priv *priv,
  139. struct rsnd_mod *mod,
  140. struct rsnd_mod_ops *ops,
  141. int id);
  142. char *rsnd_mod_name(struct rsnd_mod *mod);
  143. /*
  144. * R-Car sound DAI
  145. */
  146. #define RSND_DAI_NAME_SIZE 16
  147. struct rsnd_dai_stream {
  148. struct list_head head; /* head of rsnd_mod list */
  149. struct snd_pcm_substream *substream;
  150. int byte_pos;
  151. int period_pos;
  152. int byte_per_period;
  153. int next_period_byte;
  154. };
  155. struct rsnd_dai {
  156. char name[RSND_DAI_NAME_SIZE];
  157. struct rsnd_dai_platform_info *info; /* rcar_snd.h */
  158. struct rsnd_dai_stream playback;
  159. struct rsnd_dai_stream capture;
  160. int clk_master:1;
  161. int bit_clk_inv:1;
  162. int frm_clk_inv:1;
  163. int sys_delay:1;
  164. int data_alignment:1;
  165. };
  166. #define rsnd_dai_nr(priv) ((priv)->dai_nr)
  167. #define for_each_rsnd_dai(rdai, priv, i) \
  168. for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
  169. i < rsnd_dai_nr(priv); \
  170. i++, (rdai) = rsnd_dai_get(priv, i))
  171. struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
  172. int rsnd_dai_disconnect(struct rsnd_mod *mod);
  173. int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
  174. struct rsnd_dai_stream *io);
  175. int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
  176. int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
  177. #define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
  178. #define rsnd_io_to_runtime(io) ((io)->substream->runtime)
  179. void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
  180. int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
  181. /*
  182. * R-Car Gen1/Gen2
  183. */
  184. int rsnd_gen_probe(struct platform_device *pdev,
  185. struct rcar_snd_info *info,
  186. struct rsnd_priv *priv);
  187. void rsnd_gen_remove(struct platform_device *pdev,
  188. struct rsnd_priv *priv);
  189. int rsnd_gen_path_init(struct rsnd_priv *priv,
  190. struct rsnd_dai *rdai,
  191. struct rsnd_dai_stream *io);
  192. int rsnd_gen_path_exit(struct rsnd_priv *priv,
  193. struct rsnd_dai *rdai,
  194. struct rsnd_dai_stream *io);
  195. void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
  196. struct rsnd_mod *mod,
  197. enum rsnd_reg reg);
  198. #define rsnd_is_gen1(s) ((s)->info->flags & RSND_GEN1)
  199. #define rsnd_is_gen2(s) ((s)->info->flags & RSND_GEN2)
  200. /*
  201. * R-Car ADG
  202. */
  203. int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
  204. int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
  205. int rsnd_adg_probe(struct platform_device *pdev,
  206. struct rcar_snd_info *info,
  207. struct rsnd_priv *priv);
  208. void rsnd_adg_remove(struct platform_device *pdev,
  209. struct rsnd_priv *priv);
  210. /*
  211. * R-Car sound priv
  212. */
  213. struct rsnd_priv {
  214. struct device *dev;
  215. struct rcar_snd_info *info;
  216. spinlock_t lock;
  217. /*
  218. * below value will be filled on rsnd_gen_probe()
  219. */
  220. void *gen;
  221. /*
  222. * below value will be filled on rsnd_scu_probe()
  223. */
  224. void *scu;
  225. int scu_nr;
  226. /*
  227. * below value will be filled on rsnd_adg_probe()
  228. */
  229. void *adg;
  230. /*
  231. * below value will be filled on rsnd_ssi_probe()
  232. */
  233. void *ssiu;
  234. /*
  235. * below value will be filled on rsnd_dai_probe()
  236. */
  237. struct snd_soc_dai_driver *daidrv;
  238. struct rsnd_dai *rdai;
  239. int dai_nr;
  240. };
  241. #define rsnd_priv_to_dev(priv) ((priv)->dev)
  242. #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
  243. #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
  244. /*
  245. * R-Car SCU
  246. */
  247. int rsnd_scu_probe(struct platform_device *pdev,
  248. struct rcar_snd_info *info,
  249. struct rsnd_priv *priv);
  250. void rsnd_scu_remove(struct platform_device *pdev,
  251. struct rsnd_priv *priv);
  252. struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
  253. #define rsnd_scu_nr(priv) ((priv)->scu_nr)
  254. /*
  255. * R-Car SSI
  256. */
  257. int rsnd_ssi_probe(struct platform_device *pdev,
  258. struct rcar_snd_info *info,
  259. struct rsnd_priv *priv);
  260. void rsnd_ssi_remove(struct platform_device *pdev,
  261. struct rsnd_priv *priv);
  262. struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
  263. struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
  264. int dai_id, int is_play);
  265. #endif