rsnd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. RSND_REG_MAX,
  43. };
  44. struct rsnd_priv;
  45. struct rsnd_mod;
  46. struct rsnd_dai;
  47. struct rsnd_dai_stream;
  48. /*
  49. * R-Car basic functions
  50. */
  51. #define rsnd_mod_read(m, r) \
  52. rsnd_read(rsnd_mod_to_priv(m), m, RSND_REG_##r)
  53. #define rsnd_mod_write(m, r, d) \
  54. rsnd_write(rsnd_mod_to_priv(m), m, RSND_REG_##r, d)
  55. #define rsnd_mod_bset(m, r, s, d) \
  56. rsnd_bset(rsnd_mod_to_priv(m), m, RSND_REG_##r, s, d)
  57. #define rsnd_priv_read(p, r) rsnd_read(p, NULL, RSND_REG_##r)
  58. #define rsnd_priv_write(p, r, d) rsnd_write(p, NULL, RSND_REG_##r, d)
  59. #define rsnd_priv_bset(p, r, s, d) rsnd_bset(p, NULL, RSND_REG_##r, s, d)
  60. u32 rsnd_read(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg);
  61. void rsnd_write(struct rsnd_priv *priv, struct rsnd_mod *mod,
  62. enum rsnd_reg reg, u32 data);
  63. void rsnd_bset(struct rsnd_priv *priv, struct rsnd_mod *mod, enum rsnd_reg reg,
  64. u32 mask, u32 data);
  65. /*
  66. * R-Car sound mod
  67. */
  68. struct rsnd_mod_ops {
  69. char *name;
  70. int (*init)(struct rsnd_mod *mod,
  71. struct rsnd_dai *rdai,
  72. struct rsnd_dai_stream *io);
  73. int (*quit)(struct rsnd_mod *mod,
  74. struct rsnd_dai *rdai,
  75. struct rsnd_dai_stream *io);
  76. int (*start)(struct rsnd_mod *mod,
  77. struct rsnd_dai *rdai,
  78. struct rsnd_dai_stream *io);
  79. int (*stop)(struct rsnd_mod *mod,
  80. struct rsnd_dai *rdai,
  81. struct rsnd_dai_stream *io);
  82. };
  83. struct rsnd_mod {
  84. int id;
  85. struct rsnd_priv *priv;
  86. struct rsnd_mod_ops *ops;
  87. struct list_head list; /* connect to rsnd_dai playback/capture */
  88. };
  89. #define rsnd_mod_to_priv(mod) ((mod)->priv)
  90. #define rsnd_mod_id(mod) ((mod)->id)
  91. #define for_each_rsnd_mod(pos, n, io) \
  92. list_for_each_entry_safe(pos, n, &(io)->head, list)
  93. #define rsnd_mod_call(mod, func, rdai, io) \
  94. (!(mod) ? -ENODEV : \
  95. !((mod)->ops->func) ? 0 : \
  96. (mod)->ops->func(mod, rdai, io))
  97. void rsnd_mod_init(struct rsnd_priv *priv,
  98. struct rsnd_mod *mod,
  99. struct rsnd_mod_ops *ops,
  100. int id);
  101. char *rsnd_mod_name(struct rsnd_mod *mod);
  102. /*
  103. * R-Car sound DAI
  104. */
  105. #define RSND_DAI_NAME_SIZE 16
  106. struct rsnd_dai_stream {
  107. struct list_head head; /* head of rsnd_mod list */
  108. struct snd_pcm_substream *substream;
  109. int byte_pos;
  110. int period_pos;
  111. int byte_per_period;
  112. int next_period_byte;
  113. };
  114. struct rsnd_dai {
  115. char name[RSND_DAI_NAME_SIZE];
  116. struct rsnd_dai_platform_info *info; /* rcar_snd.h */
  117. struct rsnd_dai_stream playback;
  118. struct rsnd_dai_stream capture;
  119. int clk_master:1;
  120. int bit_clk_inv:1;
  121. int frm_clk_inv:1;
  122. int sys_delay:1;
  123. int data_alignment:1;
  124. };
  125. #define rsnd_dai_nr(priv) ((priv)->dai_nr)
  126. #define for_each_rsnd_dai(rdai, priv, i) \
  127. for (i = 0, (rdai) = rsnd_dai_get(priv, i); \
  128. i < rsnd_dai_nr(priv); \
  129. i++, (rdai) = rsnd_dai_get(priv, i))
  130. struct rsnd_dai *rsnd_dai_get(struct rsnd_priv *priv, int id);
  131. int rsnd_dai_disconnect(struct rsnd_mod *mod);
  132. int rsnd_dai_connect(struct rsnd_dai *rdai, struct rsnd_mod *mod,
  133. struct rsnd_dai_stream *io);
  134. int rsnd_dai_is_play(struct rsnd_dai *rdai, struct rsnd_dai_stream *io);
  135. #define rsnd_dai_get_platform_info(rdai) ((rdai)->info)
  136. void rsnd_dai_pointer_update(struct rsnd_dai_stream *io, int cnt);
  137. int rsnd_dai_pointer_offset(struct rsnd_dai_stream *io, int additional);
  138. /*
  139. * R-Car Gen1/Gen2
  140. */
  141. int rsnd_gen_probe(struct platform_device *pdev,
  142. struct rcar_snd_info *info,
  143. struct rsnd_priv *priv);
  144. void rsnd_gen_remove(struct platform_device *pdev,
  145. struct rsnd_priv *priv);
  146. int rsnd_gen_path_init(struct rsnd_priv *priv,
  147. struct rsnd_dai *rdai,
  148. struct rsnd_dai_stream *io);
  149. int rsnd_gen_path_exit(struct rsnd_priv *priv,
  150. struct rsnd_dai *rdai,
  151. struct rsnd_dai_stream *io);
  152. void __iomem *rsnd_gen_reg_get(struct rsnd_priv *priv,
  153. struct rsnd_mod *mod,
  154. enum rsnd_reg reg);
  155. /*
  156. * R-Car ADG
  157. */
  158. int rsnd_adg_ssi_clk_stop(struct rsnd_mod *mod);
  159. int rsnd_adg_ssi_clk_try_start(struct rsnd_mod *mod, unsigned int rate);
  160. int rsnd_adg_probe(struct platform_device *pdev,
  161. struct rcar_snd_info *info,
  162. struct rsnd_priv *priv);
  163. void rsnd_adg_remove(struct platform_device *pdev,
  164. struct rsnd_priv *priv);
  165. /*
  166. * R-Car sound priv
  167. */
  168. struct rsnd_priv {
  169. struct device *dev;
  170. struct rcar_snd_info *info;
  171. spinlock_t lock;
  172. /*
  173. * below value will be filled on rsnd_gen_probe()
  174. */
  175. void *gen;
  176. /*
  177. * below value will be filled on rsnd_scu_probe()
  178. */
  179. void *scu;
  180. int scu_nr;
  181. /*
  182. * below value will be filled on rsnd_adg_probe()
  183. */
  184. void *adg;
  185. /*
  186. * below value will be filled on rsnd_dai_probe()
  187. */
  188. struct snd_soc_dai_driver *daidrv;
  189. struct rsnd_dai *rdai;
  190. int dai_nr;
  191. };
  192. #define rsnd_priv_to_dev(priv) ((priv)->dev)
  193. #define rsnd_lock(priv, flags) spin_lock_irqsave(&priv->lock, flags)
  194. #define rsnd_unlock(priv, flags) spin_unlock_irqrestore(&priv->lock, flags)
  195. /*
  196. * R-Car SCU
  197. */
  198. int rsnd_scu_probe(struct platform_device *pdev,
  199. struct rcar_snd_info *info,
  200. struct rsnd_priv *priv);
  201. void rsnd_scu_remove(struct platform_device *pdev,
  202. struct rsnd_priv *priv);
  203. struct rsnd_mod *rsnd_scu_mod_get(struct rsnd_priv *priv, int id);
  204. #define rsnd_scu_nr(priv) ((priv)->scu_nr)
  205. #endif