rsnd.h 6.5 KB

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