rsnd.h 5.4 KB

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