rsnd.h 7.6 KB

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