rsnd.h 4.9 KB

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