rsnd.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
  74. void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
  75. enum rsnd_reg reg, u32 data);
  76. void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
  77. u32 mask, u32 data);
  78. /*
  79. * R-Car DMA
  80. */
  81. struct rsnd_dma {
  82. struct rsnd_priv *priv;
  83. struct sh_dmae_slave slave;
  84. struct work_struct work;
  85. struct dma_chan *chan;
  86. enum dma_data_direction dir;
  87. int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len);
  88. int (*complete)(struct rsnd_dma *dma);
  89. int submit_loop;
  90. };
  91. void rsnd_dma_start(struct rsnd_dma *dma);
  92. void rsnd_dma_stop(struct rsnd_dma *dma);
  93. int rsnd_dma_available(struct rsnd_dma *dma);
  94. int rsnd_dma_init(struct rsnd_priv *priv, struct rsnd_dma *dma,
  95. int is_play, int id,
  96. int (*inquiry)(struct rsnd_dma *dma, dma_addr_t *buf, int *len),
  97. int (*complete)(struct rsnd_dma *dma));
  98. void rsnd_dma_quit(struct rsnd_priv *priv,
  99. struct rsnd_dma *dma);
  100. /*
  101. * R-Car sound mod
  102. */
  103. struct rsnd_mod_ops {
  104. char *name;
  105. int (*init)(struct rsnd_mod *mod,
  106. struct rsnd_dai *rdai,
  107. struct rsnd_dai_stream *io);
  108. int (*quit)(struct rsnd_mod *mod,
  109. struct rsnd_dai *rdai,
  110. struct rsnd_dai_stream *io);
  111. int (*start)(struct rsnd_mod *mod,
  112. struct rsnd_dai *rdai,
  113. struct rsnd_dai_stream *io);
  114. int (*stop)(struct rsnd_mod *mod,
  115. struct rsnd_dai *rdai,
  116. struct rsnd_dai_stream *io);
  117. };
  118. struct rsnd_mod {
  119. int id;
  120. struct rsnd_priv *priv;
  121. struct rsnd_mod_ops *ops;
  122. struct list_head list; /* connect to rsnd_dai playback/capture */
  123. struct rsnd_dma dma;
  124. };
  125. #define rsnd_mod_to_priv(mod) ((mod)->priv)
  126. #define rsnd_mod_to_dma(mod) (&(mod)->dma)
  127. #define rsnd_dma_to_mod(_dma) container_of((_dma), struct rsnd_mod, dma)
  128. #define rsnd_mod_id(mod) ((mod)->id)
  129. #define for_each_rsnd_mod(pos, n, io) \
  130. list_for_each_entry_safe(pos, n, &(io)->head, list)
  131. #define rsnd_mod_call(mod, func, rdai, io) \
  132. (!(mod) ? -ENODEV : \
  133. !((mod)->ops->func) ? 0 : \
  134. (mod)->ops->func(mod, rdai, io))
  135. void rsnd_mod_init(struct rsnd_priv *priv,
  136. struct rsnd_mod *mod,
  137. struct rsnd_mod_ops *ops,
  138. int id);
  139. char *rsnd_mod_name(struct rsnd_mod *mod);
  140. /*
  141. * R-Car sound DAI
  142. */
  143. #define RSND_DAI_NAME_SIZE 16
  144. struct rsnd_dai_stream {
  145. struct list_head head; /* head of rsnd_mod list */
  146. struct snd_pcm_substream *substream;
  147. int byte_pos;
  148. int period_pos;
  149. int byte_per_period;
  150. int next_period_byte;
  151. };
  152. struct rsnd_dai {
  153. char name[RSND_DAI_NAME_SIZE];
  154. struct rsnd_dai_platform_info *info; /* rcar_snd.h */
  155. struct rsnd_dai_stream playback;
  156. struct rsnd_dai_stream capture;
  157. int clk_master:1;
  158. int bit_clk_inv:1;
  159. int frm_clk_inv:1;
  160. int sys_delay:1;
  161. int data_alignment:1;
  162. };
  163. #define rsnd_dai_nr(priv) ((priv)->dai_nr)
  164. #define for_each_rsnd_dai(rdai, priv, i) \
  165. for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
  166. i < rsnd_dai_nr(priv); \
  167. i++, (rdai) = rsnd_dai_get(priv, i))
  168. struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
  169. int rsnd_dai_disconnect(struct rsnd_mod *mod);
  170. int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
  171. struct rsnd_dai_stream *io);
  172. int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
  173. int rsnd_dai_id(struct rsnd_priv *priv, struct rsnd_dai *rdai);
  174. #define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
  175. #define rsnd_io_to_runtime(io) ((io)->substream->runtime)
  176. void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
  177. int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
  178. /*
  179. * R-Car Gen1/Gen2
  180. */
  181. int rsnd_gen_probe(struct platform_device *pdev,
  182. struct rcar_snd_info *info,
  183. struct rsnd_priv *priv);
  184. void rsnd_gen_remove(struct platform_device *pdev,
  185. struct rsnd_priv *priv);
  186. int rsnd_gen_path_init(struct rsnd_priv *priv,
  187. struct rsnd_dai *rdai,
  188. struct rsnd_dai_stream *io);
  189. int rsnd_gen_path_exit(struct rsnd_priv *priv,
  190. struct rsnd_dai *rdai,
  191. struct rsnd_dai_stream *io);
  192. void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
  193. struct rsnd_mod *mod,
  194. enum rsnd_reg reg);
  195. #define rsnd_is_gen1(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN1)
  196. #define rsnd_is_gen2(s) (((s)->info->flags & RSND_GEN_MASK) == RSND_GEN2)
  197. /*
  198. * R-Car ADG
  199. */
  200. int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
  201. int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
  202. int rsnd_adg_probe(struct platform_device *pdev,
  203. struct rcar_snd_info *info,
  204. struct rsnd_priv *priv);
  205. void rsnd_adg_remove(struct platform_device *pdev,
  206. struct rsnd_priv *priv);
  207. /*
  208. * R-Car sound priv
  209. */
  210. struct rsnd_priv {
  211. struct device *dev;
  212. struct rcar_snd_info *info;
  213. spinlock_t lock;
  214. /*
  215. * below value will be filled on rsnd_gen_probe()
  216. */
  217. void *gen;
  218. /*
  219. * below value will be filled on rsnd_scu_probe()
  220. */
  221. void *scu;
  222. int scu_nr;
  223. /*
  224. * below value will be filled on rsnd_adg_probe()
  225. */
  226. void *adg;
  227. /*
  228. * below value will be filled on rsnd_ssi_probe()
  229. */
  230. void *ssiu;
  231. /*
  232. * below value will be filled on rsnd_dai_probe()
  233. */
  234. struct snd_soc_dai_driver *daidrv;
  235. struct rsnd_dai *rdai;
  236. int dai_nr;
  237. };
  238. #define rsnd_priv_to_dev(priv) ((priv)->dev)
  239. #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
  240. #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
  241. /*
  242. * R-Car SCU
  243. */
  244. int rsnd_scu_probe(struct platform_device *pdev,
  245. struct rcar_snd_info *info,
  246. struct rsnd_priv *priv);
  247. void rsnd_scu_remove(struct platform_device *pdev,
  248. struct rsnd_priv *priv);
  249. struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
  250. bool rsnd_scu_hpbif_is_enable(struct rsnd_mod *mod);
  251. #define rsnd_scu_nr(priv) ((priv)->scu_nr)
  252. /*
  253. * R-Car SSI
  254. */
  255. int rsnd_ssi_probe(struct platform_device *pdev,
  256. struct rcar_snd_info *info,
  257. struct rsnd_priv *priv);
  258. void rsnd_ssi_remove(struct platform_device *pdev,
  259. struct rsnd_priv *priv);
  260. struct rsnd_mod *rsnd_ssi_mod_get(struct rsnd_priv *priv, int id);
  261. struct rsnd_mod *rsnd_ssi_mod_get_frm_dai(struct rsnd_priv *priv,
  262. int dai_id, int is_play);
  263. #endif